Callstack.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
  5. <title>EACallstack</title>
  6. <link type="text/css" rel="stylesheet" href="UTFDoc.css">
  7. <meta name="author" content="Paul Schlegel">
  8. <style type="text/css">
  9. <!--
  10. .style1 {color: #0033CC}
  11. -->
  12. </style>
  13. </head>
  14. <body bgcolor="#FFFFFF">
  15. <h1>EACallstack</h1>
  16. <h2>Introduction</h2>
  17. <p>The EACallstack package includes functionality to retrieve callstacks at runtime, convert callstacks to symbol names, locations, or source code, disassemble code, read PS3 (eventually other platform) crash dumps, read machine thread contexts, and related functionality. It supports code in DLLs (or other platform equivalents).</p>
  18. <p>EACallstack works on the following platforms:
  19. <ul>
  20. <li>PS3</li>
  21. <li>XBox 360</li>
  22. <li>Wii</li>
  23. <li>Windows / x86, x64</li>
  24. <li>Macintosh / x86, x64</li>
  25. <li>Linux / x86, x64</li>
  26. <li>Mobile / ARM</li>
  27. <li>PS2</li>
  28. </ul>
  29. </p>
  30. <p>The Callstack namespace is the primary namespace of the EACallstack package.
  31. It defines the methods used to initialize and shut down EACallstack, and it
  32. defines methods for the following functions that are fundamental to all
  33. EACallstack operations:</p>
  34. <ul>
  35. <li>To get the value of the current instruction pointer</li>
  36. <li>To get the callstack, expressed as an array of instruction pointers, for
  37. any thread</li>
  38. </ul>
  39. <p>All of these functions return instruction pointers. In order to obtain
  40. human-readable debugging information, an instruction pointer can be passed to
  41. other classes within EACallstack, such as <a href="EAAddressRep.html">
  42. EAAddressRep</a> or <a href="EADasm.html">EADasm</a>.
  43. <a href="EAAddressRep.html">EAAddressRep</a> can be used for looking up symbol
  44. information such as the function name, source file, line number, and source code
  45. text associated with a program address. <a href="EADasm.html">EADasm</a> can be used
  46. for disassembling machine code at a program address.</p>
  47. <p>By using the functions defined in the Callstack namespace in conjunction
  48. with other classes defined in EACallstack, it is possible for an executable
  49. running on a console platform to construct failure reports with a wide variety
  50. of debugging information that can be immediately useful to a developer, without
  51. the need for external symbol lookup tools or other translation steps.</p>
  52. <h2>Example usage </h2>
  53. <p>Here's example usage for how to use GetCallstack:</p>
  54. <pre class="code-example">void YourApp::Initialize()
  55. {
  56. #ifdef EA_DEBUG // EACallstack is likely for debug-only configurations.
  57. <span class="style1"> Callstack::InitCallstack();
  58. <font color="#000000"> #endif</font></span>
  59. }
  60. void YourApp::OutputCallstack()
  61. {
  62. void* pCallstack[32];
  63. size_t nCallstackDepth = <font color="#0033CC">GetCallstack(pCallstack, 32, NULL); </font>// NULL == use current thread context
  64. for(size_t i = 0; i &lt; nCallstackDepth; ++i)
  65. {
  66. const void* const pCallstackAddress = pCallstack[i];
  67. // Get the symbol information for pCallstackAddress via GetAddressRep here.
  68. // See the documentation for <a href="EAAddressRep.html">EAAddressRep</a>.
  69. //
  70. // ... and/or ...
  71. //
  72. // Get the machine code disassembly for pCallstackAddress via EADasm here.
  73. // See the documentation for <a href="EADasm.html">EADasm</a>.
  74. }
  75. }
  76. void YourApp::Shutdown()
  77. {
  78. #ifdef EA_DEBUG
  79. <span class="style1"> Callstack::ShutdownCallstack();
  80. <font color="#000000"> #endif</font></span>
  81. }</pre>
  82. <h2>Interface</h2>
  83. <p>Methods for the initialization and shutdown of the EACallstack package,
  84. defined in the EACallstack.h header file:</p>
  85. <pre class="code-example"><span class="code-example-comment">/// InitCallstack
  86. ///
  87. /// Allows the user to explicitly initialize the callstack mechanism.
  88. /// Only the first call to InitCallstack will have effect. Calls to
  89. /// InitCallstack must be matched by calls to ShutdownCallstack.
  90. ///
  91. </span>void InitCallstack();
  92. <span class="code-example-comment">/// ShutdownCallstack
  93. ///
  94. /// Allows the user to explicitly shutdown the callstack mechanism.
  95. /// Calls to InitCallstack must be matched by calls to ShutdownCallstack.
  96. /// The last call to ShutdownCallstack will shutdown and free the callstack mechanism.
  97. ///
  98. </span>void ShutdownCallstack();</pre>
  99. <p>The GetCallstack function:</p>
  100. <pre class="code-example"><span class="code-example-comment">/// GetCallstack
  101. ///
  102. /// Gets the addresses of the calling instructions of a call stack.
  103. /// If the CallstackContext parameter is used, then that execution context is used;
  104. /// otherwise the current execution context is used.
  105. /// The return value is the number of entries written to the callstack array.
  106. /// The item at callstack[0] is always the address of the instruction calling the
  107. /// GetCallstack function. This is conceptually identical to placing a breakpoint in
  108. /// a debugger at the point where the GetCallstack function is called.
  109. /// The maxDepth parameter must be at least one.
  110. ///
  111. </span>size_t GetCallstack(void* callstack[], size_t maxDepth, CallstackContext* pContext = NULL);</pre>
  112. <p>The GetCallstackContext function, for use when obtaining the callstack of a
  113. particular thread:</p>
  114. <pre class="code-example"><span class="code-example-comment">/// GetCallstackContext
  115. ///
  116. /// Gets the CallstackContext associated with the given thread.
  117. /// The thread must be in a non-running state.
  118. /// If the threadID is EAThread::kThreadIdInvalid, the current thread context is retrieved.
  119. /// The threadId parameter is the same type as an EAThread ThreadId. It is important to
  120. /// note that an EAThread ThreadId under Microsoft platforms is a thread handle and not what
  121. /// Microsoft calls a thread id. This is by design as Microsoft thread ids are second class
  122. /// citizens and likely wouldn't exist if it not were for quirks in the Windows API evolution.
  123. ///
  124. </span>bool GetCallstackContext(CallstackContext&amp; context, intptr_t threadId = 0);</pre>
  125. <p>The EAGetInstructionPointer macro:</p>
  126. <pre class="code-example"><span class="code-example-comment">/// EAGetInstructionPointer
  127. ///
  128. /// Returns the current instruction pointer (a.k.a. program counter).
  129. /// This function is implemented as a macro, it acts as if its declaration
  130. /// were like so:
  131. /// void EAGetInstructionPointer(void*&amp; p);
  132. ///
  133. /// For portability, this function should only be used as a standalone
  134. /// statement on its own line.
  135. ///
  136. /// Example usage:
  137. /// void* pInstruction;
  138. /// EAGetInstructionPointer(pInstruction);
  139. ///
  140. </span>&lt;... implementation not shown ...&gt;</pre>
  141. <hr>
  142. <p>&nbsp;</p>
  143. <p>&nbsp;</p>
  144. <p>&nbsp;</p>
  145. <p>&nbsp;</p>
  146. <p>&nbsp;</p>
  147. <p>&nbsp;</p>
  148. <p>&nbsp;</p>
  149. <p></p>
  150. </body>
  151. </html>