Non_002ddebug-DLL-Symbols.html 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Free Software" and "Free Software Needs
  8. Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
  9. and with the Back-Cover Texts as in (a) below.
  10. (a) The FSF's Back-Cover Text is: "You are free to copy and modify
  11. this GNU Manual. Buying copies from GNU Press supports the FSF in
  12. developing GNU and promoting software freedom." -->
  13. <!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>Debugging with GDB: Non-debug DLL Symbols</title>
  16. <meta name="description" content="Debugging with GDB: Non-debug DLL Symbols">
  17. <meta name="keywords" content="Debugging with GDB: Non-debug DLL Symbols">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  22. <link href="index.html#Top" rel="start" title="Top">
  23. <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
  24. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  25. <link href="Cygwin-Native.html#Cygwin-Native" rel="up" title="Cygwin Native">
  26. <link href="Hurd-Native.html#Hurd-Native" rel="next" title="Hurd Native">
  27. <link href="Cygwin-Native.html#Cygwin-Native" rel="previous" title="Cygwin Native">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.indentedblock {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  39. div.smalllisp {margin-left: 3.2em}
  40. kbd {font-style:oblique}
  41. pre.display {font-family: inherit}
  42. pre.format {font-family: inherit}
  43. pre.menu-comment {font-family: serif}
  44. pre.menu-preformatted {font-family: serif}
  45. pre.smalldisplay {font-family: inherit; font-size: smaller}
  46. pre.smallexample {font-size: smaller}
  47. pre.smallformat {font-family: inherit; font-size: smaller}
  48. pre.smalllisp {font-size: smaller}
  49. span.nocodebreak {white-space:nowrap}
  50. span.nolinebreak {white-space:nowrap}
  51. span.roman {font-family:serif; font-weight:normal}
  52. span.sansserif {font-family:sans-serif; font-weight:normal}
  53. ul.no-bullet {list-style: none}
  54. -->
  55. </style>
  56. </head>
  57. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  58. <a name="Non_002ddebug-DLL-Symbols"></a>
  59. <div class="header">
  60. <p>
  61. Up: <a href="Cygwin-Native.html#Cygwin-Native" accesskey="u" rel="up">Cygwin Native</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
  62. </div>
  63. <hr>
  64. <a name="Support-for-DLLs-without-Debugging-Symbols"></a>
  65. <h4 class="subsubsection">21.1.4.1 Support for DLLs without Debugging Symbols</h4>
  66. <a name="index-DLLs-with-no-debugging-symbols"></a>
  67. <a name="index-Minimal-symbols-and-DLLs"></a>
  68. <p>Very often on windows, some of the DLLs that your program relies on do
  69. not include symbolic debugging information (for example,
  70. <samp>kernel32.dll</samp>). When <small>GDB</small> doesn&rsquo;t recognize any debugging
  71. symbols in a DLL, it relies on the minimal amount of symbolic
  72. information contained in the DLL&rsquo;s export table. This section
  73. describes working with such symbols, known internally to <small>GDB</small> as
  74. &ldquo;minimal symbols&rdquo;.
  75. </p>
  76. <p>Note that before the debugged program has started execution, no DLLs
  77. will have been loaded. The easiest way around this problem is simply to
  78. start the program &mdash; either by setting a breakpoint or letting the
  79. program run once to completion.
  80. </p>
  81. <a name="DLL-Name-Prefixes"></a>
  82. <h4 class="subsubsection">21.1.4.2 DLL Name Prefixes</h4>
  83. <p>In keeping with the naming conventions used by the Microsoft debugging
  84. tools, DLL export symbols are made available with a prefix based on the
  85. DLL name, for instance <code>KERNEL32!CreateFileA</code>. The plain name is
  86. also entered into the symbol table, so <code>CreateFileA</code> is often
  87. sufficient. In some cases there will be name clashes within a program
  88. (particularly if the executable itself includes full debugging symbols)
  89. necessitating the use of the fully qualified name when referring to the
  90. contents of the DLL. Use single-quotes around the name to avoid the
  91. exclamation mark (&ldquo;!&rdquo;) being interpreted as a language operator.
  92. </p>
  93. <p>Note that the internal name of the DLL may be all upper-case, even
  94. though the file name of the DLL is lower-case, or vice-versa. Since
  95. symbols within <small>GDB</small> are <em>case-sensitive</em> this may cause
  96. some confusion. If in doubt, try the <code>info functions</code> and
  97. <code>info variables</code> commands or even <code>maint print msymbols</code>
  98. (see <a href="Symbols.html#Symbols">Symbols</a>). Here&rsquo;s an example:
  99. </p>
  100. <div class="smallexample">
  101. <pre class="smallexample">(gdb) info function CreateFileA
  102. All functions matching regular expression &quot;CreateFileA&quot;:
  103. Non-debugging symbols:
  104. 0x77e885f4 CreateFileA
  105. 0x77e885f4 KERNEL32!CreateFileA
  106. </pre></div>
  107. <div class="smallexample">
  108. <pre class="smallexample">(gdb) info function !
  109. All functions matching regular expression &quot;!&quot;:
  110. Non-debugging symbols:
  111. 0x6100114c cygwin1!__assert
  112. 0x61004034 cygwin1!_dll_crt0@0
  113. 0x61004240 cygwin1!dll_crt0(per_process *)
  114. [etc...]
  115. </pre></div>
  116. <a name="Working-with-Minimal-Symbols"></a>
  117. <h4 class="subsubsection">21.1.4.3 Working with Minimal Symbols</h4>
  118. <p>Symbols extracted from a DLL&rsquo;s export table do not contain very much
  119. type information. All that <small>GDB</small> can do is guess whether a symbol
  120. refers to a function or variable depending on the linker section that
  121. contains the symbol. Also note that the actual contents of the memory
  122. contained in a DLL are not available unless the program is running. This
  123. means that you cannot examine the contents of a variable or disassemble
  124. a function within a DLL without a running program.
  125. </p>
  126. <p>Variables are generally treated as pointers and dereferenced
  127. automatically. For this reason, it is often necessary to prefix a
  128. variable name with the address-of operator (&ldquo;&amp;&rdquo;) and provide explicit
  129. type information in the command. Here&rsquo;s an example of the type of
  130. problem:
  131. </p>
  132. <div class="smallexample">
  133. <pre class="smallexample">(gdb) print 'cygwin1!__argv'
  134. 'cygwin1!__argv' has unknown type; cast it to its declared type
  135. </pre></div>
  136. <div class="smallexample">
  137. <pre class="smallexample">(gdb) x 'cygwin1!__argv'
  138. 'cygwin1!__argv' has unknown type; cast it to its declared type
  139. </pre></div>
  140. <p>And two possible solutions:
  141. </p>
  142. <div class="smallexample">
  143. <pre class="smallexample">(gdb) print ((char **)'cygwin1!__argv')[0]
  144. $2 = 0x22fd98 &quot;/cygdrive/c/mydirectory/myprogram&quot;
  145. </pre></div>
  146. <div class="smallexample">
  147. <pre class="smallexample">(gdb) x/2x &amp;'cygwin1!__argv'
  148. 0x610c0aa8 &lt;cygwin1!__argv&gt;: 0x10021608 0x00000000
  149. (gdb) x/x 0x10021608
  150. 0x10021608: 0x0022fd98
  151. (gdb) x/s 0x0022fd98
  152. 0x22fd98: &quot;/cygdrive/c/mydirectory/myprogram&quot;
  153. </pre></div>
  154. <p>Setting a break point within a DLL is possible even before the program
  155. starts execution. However, under these circumstances, <small>GDB</small> can&rsquo;t
  156. examine the initial instructions of the function in order to skip the
  157. function&rsquo;s frame set-up code. You can work around this by using &ldquo;*&amp;&rdquo;
  158. to set the breakpoint at a raw memory address:
  159. </p>
  160. <div class="smallexample">
  161. <pre class="smallexample">(gdb) break *&amp;'python22!PyOS_Readline'
  162. Breakpoint 1 at 0x1e04eff0
  163. </pre></div>
  164. <p>The author of these extensions is not entirely convinced that setting a
  165. break point within a shared DLL like <samp>kernel32.dll</samp> is completely
  166. safe.
  167. </p>
  168. <hr>
  169. <div class="header">
  170. <p>
  171. Up: <a href="Cygwin-Native.html#Cygwin-Native" accesskey="u" rel="up">Cygwin Native</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
  172. </div>
  173. </body>
  174. </html>