[GHC] #9395: Debug.Trace should not use %s for format string

#9395: Debug.Trace should not use %s for format string -------------------------------------+------------------------------------- Reporter: ezyang | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.8.2 Keywords: | Operating System: Architecture: Unknown/Multiple | Unknown/Multiple Difficulty: Unknown | Type of failure: Incorrect Blocked By: | result at runtime Related Tickets: | Test Case: | Blocking: | Differential Revisions: -------------------------------------+------------------------------------- The current implementation of traceIO in Debug.Trace is as follows: {{{ traceIO :: String -> IO () traceIO msg = do withCString "%s\n" $ \cfmt -> withCString msg $ \cmsg -> debugBelch cfmt cmsg }}} This is bad news: it means if the String has a null in it, the string will be silently truncated. For example, in GHC, this means that you cannot pretty-print FastString uniques, since the default printing algorithm often results in a null. Probably the proper thing to do here is to also pass a length indicator for the CString. We should also fix unique pretty-printing to never generate nulls. A good test case would be: {{{ main = trace "\0foo" (return ()) }}} which should have non-empty output. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9395 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9395: Debug.Trace should not use %s for format string -------------------------------------+------------------------------------- Reporter: ezyang | Owner: ezyang Type: bug | Status: new Priority: normal | Milestone: Component: | Version: 7.8.2 libraries/base | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: Incorrect | Related Tickets: result at runtime | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by ezyang): * owner: => ezyang -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9395#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9395: Debug.Trace should not use %s for format string -------------------------------------+------------------------------------- Reporter: ezyang | Owner: ezyang Type: bug | Status: new Priority: normal | Milestone: Component: | Version: 7.8.2 libraries/base | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: Incorrect | Related Tickets: result at runtime | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by ezyang): OK, it's a little trickier than just specifying a new format string; I forgot that {{{ #include "stdio.h" int main() { printf("%.*s", 4, "AA\0B"); return 0; } }}} only outputs AA, even with the length description. So we can't use debugBelch. This raises the question, why are we using debugBelch at all? Some archaeology later: {{{ [project @ 2005-01-28 23:33:57 by krasimir] - The output from uncaught exceptions handler is redirected to RTS's errorBelch. - The output from Debug.Trace is redirected to RTS's debugBelch - Usually errorBelch and debugBelch messages go to stderr except for Windows GUI applications. For GUI applications the Debug.Trace output is redirected to debug console and the exceptions message is displayed in message box. }}} It also seems like a good idea generally to bypass Haskell-lands buffering. Unfortunately, printf style output is a hard-coded assumption for `RtsMsgFunction`, so we can't easily swap it out without introducing another function for raw output. Maybe, alternately, Debug.Trace should munge out null bytes? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9395#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9395: Debug.Trace should not use %s for format string
-------------------------------------+-------------------------------------
Reporter: ezyang | Owner: ezyang
Type: bug | Status: new
Priority: normal | Milestone:
Component: | Version: 7.8.2
libraries/base | Keywords:
Resolution: | Architecture: Unknown/Multiple
Operating System: | Difficulty: Unknown
Unknown/Multiple | Blocked By:
Type of failure: Incorrect | Related Tickets:
result at runtime |
Test Case: |
Blocking: |
Differential Revisions: |
-------------------------------------+-------------------------------------
Comment (by Edward Z. Yang

#9395: Debug.Trace should not use %s for format string -------------------------------------+------------------------------------- Reporter: ezyang | Owner: ezyang Type: bug | Status: merge Priority: normal | Milestone: Component: | Version: 7.8.2 libraries/base | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: Incorrect | Related Tickets: result at runtime | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by ezyang): * status: new => merge -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9395#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9395: Debug.Trace should not use %s for format string -------------------------------------+------------------------------------- Reporter: ezyang | Owner: ezyang Type: bug | Status: closed Priority: normal | Milestone: Component: Core | Version: 7.8.2 Libraries | Keywords: Resolution: fixed | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: Type of failure: Incorrect | Related Tickets: result at runtime | Test Case: | Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Changes (by thoughtpolice): * cc: core-libraries-committee@… (added) * status: merge => closed * resolution: => fixed Comment: Merged to `ghc-7.8`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9395#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9395: Debug.Trace should not use %s for format string
-------------------------------------+-------------------------------------
Reporter: ezyang | Owner: ezyang
Type: bug | Status: closed
Priority: normal | Milestone:
Component: Core Libraries | Version: 7.8.2
Resolution: fixed | Keywords:
Operating System: Unknown/Multiple | Architecture:
Type of failure: Incorrect result | Unknown/Multiple
at runtime | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions:
-------------------------------------+-------------------------------------
Comment (by Austin Seipp
participants (1)
-
GHC