printStackTrace.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <head>
  2. <title>printStackTrace</title>
  3. </head>
  4. <html>
  5. <body>
  6. <h2>void printStackTrace( char* buffer, int bufferSize )</h2>
  7. <b>(printStackTrace.h)</b>
  8. <h3>Motivation</h3>
  9. Assertion failed in some string function while your client was testing the
  10. application. Well, the string function got some wrong input. The function is
  11. used in couple of other functions, which, in turn, are used in couple of
  12. other functions... At the end you have no idea what caused the problem
  13. without the help of debugger. Which isnt always available, especially while
  14. beta testing something.
  15. <h3>Description</h3>
  16. <p>
  17. printStackTrace prints formatted call stack to the user defined buffer,
  18. always terminating the buffer with 0. Uses stack frame to find out the
  19. caller function address and the map file to find out the function name.
  20. </p>
  21. <h3>Install</h3>
  22. MSVC: Just open the stacktrace.dsw and compile the test project. The test
  23. project shows how the library can be used to boost simple assert macro. To
  24. use the library in a new project, create a workspace and insert
  25. stacktrace.dsp to the workspace. Be sure to use (Debug) Multithreaded DLL
  26. runtime (or just modify the library options if you prefer Single-Threaded or
  27. plain Multithreaded runtimes)
  28. <h3>Map Files</h3>
  29. <p>
  30. Library requires that the executable has proper map file. The map file
  31. must be in the same directory as the exe and the map file must have
  32. <code>.map</code> extension. From MS Visual Studio map file creation can
  33. be enabled by checking 'Generate mapfile' box from 'Link' tab of 'Project
  34. Settings' dialog (ALT+F7).
  35. </p>
  36. <h3>About Output</h3>
  37. <p>
  38. The output is printed only in debug build (_DEBUG is defined). In release
  39. build the user buffer receives only terminating 0, or error message if the
  40. map file is missing. The library could be used also in release build, but
  41. as it requires special options (frame pointer omission optimization must
  42. be disabled) the release build usage is not currently enabled.
  43. </p>
  44. <p>
  45. Namespaces and other scopes get printed as they appear in a map file (a
  46. bit cleanup is done tho), so for example class name and namespaces get
  47. printed after the function name.
  48. </p>
  49. <p>Example output:</p>
  50. <pre>
  51. _mainCRTStartup (403fa9)
  52. _main (4011ff)
  53. testfunc1 (4011b1)
  54. testfunc2.nspace (401161)
  55. testfunc3.MyClass.nspace (40110a)
  56. internalError (40105f)
  57. printStackTrace (401360)
  58. </pre
  59. >
  60. <h3>Known issues</h3>
  61. <ul>
  62. <li>
  63. Local functions dont get reported correctly. Local functions are not
  64. listed in the map file and the end points of the functions are not
  65. known, so the preceding public function will be reported when the stack
  66. is printed.
  67. </li>
  68. <li>
  69. Template name output formatting isnt too pretty. If you happen to
  70. implement proper MSVC mangled name parser feel free put it in this
  71. library. :)
  72. </li>
  73. </ul>
  74. <br />
  75. <p>
  76. Copyright (c) 2001 <a href="mailto:jani@sumea.com">Jani Kajala</a><br />
  77. Permission to use, copy, modify, distribute and sell this software and its
  78. documentation for any purpose is hereby granted without fee, provided that
  79. the above copyright notice appear in all copies and that both that
  80. copyright notice and this permission notice appear in supporting
  81. documentation. Jani Kajala makes no representations about the suitability
  82. of this software for any purpose. It is provided "as is" without express
  83. or implied warranty.
  84. </p>
  85. </body>
  86. </html>