Objfiles-In-Python.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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: Objfiles In Python</title>
  16. <meta name="description" content="Debugging with GDB: Objfiles In Python">
  17. <meta name="keywords" content="Debugging with GDB: Objfiles In Python">
  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="Python-API.html#Python-API" rel="up" title="Python API">
  26. <link href="Frames-In-Python.html#Frames-In-Python" rel="next" title="Frames In Python">
  27. <link href="Progspaces-In-Python.html#Progspaces-In-Python" rel="previous" title="Progspaces In Python">
  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="Objfiles-In-Python"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="Frames-In-Python.html#Frames-In-Python" accesskey="n" rel="next">Frames In Python</a>, Previous: <a href="Progspaces-In-Python.html#Progspaces-In-Python" accesskey="p" rel="previous">Progspaces In Python</a>, Up: <a href="Python-API.html#Python-API" accesskey="u" rel="up">Python API</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="Objfiles-In-Python-1"></a>
  65. <h4 class="subsubsection">23.2.2.24 Objfiles In Python</h4>
  66. <a name="index-objfiles-in-python"></a>
  67. <a name="index-gdb_002eObjfile"></a>
  68. <a name="index-Objfile"></a>
  69. <p><small>GDB</small> loads symbols for an inferior from various
  70. symbol-containing files (see <a href="Files.html#Files">Files</a>). These include the primary
  71. executable file, any shared libraries used by the inferior, and any
  72. separate debug info files (see <a href="Separate-Debug-Files.html#Separate-Debug-Files">Separate Debug Files</a>).
  73. <small>GDB</small> calls these symbol-containing files <em>objfiles</em>.
  74. </p>
  75. <p>The following objfile-related functions are available in the
  76. <code>gdb</code> module:
  77. </p>
  78. <a name="index-gdb_002ecurrent_005fobjfile"></a>
  79. <dl>
  80. <dt><a name="index-gdb_002ecurrent_005fobjfile-1"></a>Function: <strong>gdb.current_objfile</strong> <em>()</em></dt>
  81. <dd><p>When auto-loading a Python script (see <a href="Python-Auto_002dloading.html#Python-Auto_002dloading">Python Auto-loading</a>), <small>GDB</small>
  82. sets the &ldquo;current objfile&rdquo; to the corresponding objfile. This
  83. function returns the current objfile. If there is no current objfile,
  84. this function returns <code>None</code>.
  85. </p></dd></dl>
  86. <a name="index-gdb_002eobjfiles"></a>
  87. <dl>
  88. <dt><a name="index-gdb_002eobjfiles-1"></a>Function: <strong>gdb.objfiles</strong> <em>()</em></dt>
  89. <dd><p>Return a sequence of objfiles referenced by the current program space.
  90. See <a href="#Objfiles-In-Python">Objfiles In Python</a>, and <a href="Progspaces-In-Python.html#Progspaces-In-Python">Progspaces In Python</a>. This is identical
  91. to <code>gdb.selected_inferior().progspace.objfiles()</code> and is included for
  92. historical compatibility.
  93. </p></dd></dl>
  94. <a name="index-gdb_002elookup_005fobjfile"></a>
  95. <dl>
  96. <dt><a name="index-gdb_002elookup_005fobjfile-1"></a>Function: <strong>gdb.lookup_objfile</strong> <em>(name <span class="roman">[</span>, by_build_id])</em></dt>
  97. <dd><p>Look up <var>name</var>, a file name or build ID, in the list of objfiles
  98. for the current program space (see <a href="Progspaces-In-Python.html#Progspaces-In-Python">Progspaces In Python</a>).
  99. If the objfile is not found throw the Python <code>ValueError</code> exception.
  100. </p>
  101. <p>If <var>name</var> is a relative file name, then it will match any
  102. source file name with the same trailing components. For example, if
  103. <var>name</var> is &lsquo;<samp>gcc/expr.c</samp>&rsquo;, then it will match source file
  104. name of <samp>/build/trunk/gcc/expr.c</samp>, but not
  105. <samp>/build/trunk/libcpp/expr.c</samp> or <samp>/build/trunk/gcc/x-expr.c</samp>.
  106. </p>
  107. <p>If <var>by_build_id</var> is provided and is <code>True</code> then <var>name</var>
  108. is the build ID of the objfile. Otherwise, <var>name</var> is a file name.
  109. This is supported only on some operating systems, notably those which use
  110. the ELF format for binary files and the <small>GNU</small> Binutils. For more details
  111. about this feature, see the description of the <samp>--build-id</samp>
  112. command-line option in <a href="http://sourceware.org/binutils/docs/ld/Options.html#Options">Command Line Options</a> in <cite>The GNU Linker</cite>.
  113. </p></dd></dl>
  114. <p>Each objfile is represented by an instance of the <code>gdb.Objfile</code>
  115. class.
  116. </p>
  117. <dl>
  118. <dt><a name="index-Objfile_002efilename"></a>Variable: <strong>Objfile.filename</strong></dt>
  119. <dd><p>The file name of the objfile as a string, with symbolic links resolved.
  120. </p>
  121. <p>The value is <code>None</code> if the objfile is no longer valid.
  122. See the <code>gdb.Objfile.is_valid</code> method, described below.
  123. </p></dd></dl>
  124. <dl>
  125. <dt><a name="index-Objfile_002eusername"></a>Variable: <strong>Objfile.username</strong></dt>
  126. <dd><p>The file name of the objfile as specified by the user as a string.
  127. </p>
  128. <p>The value is <code>None</code> if the objfile is no longer valid.
  129. See the <code>gdb.Objfile.is_valid</code> method, described below.
  130. </p></dd></dl>
  131. <dl>
  132. <dt><a name="index-Objfile_002eowner"></a>Variable: <strong>Objfile.owner</strong></dt>
  133. <dd><p>For separate debug info objfiles this is the corresponding <code>gdb.Objfile</code>
  134. object that debug info is being provided for.
  135. Otherwise this is <code>None</code>.
  136. Separate debug info objfiles are added with the
  137. <code>gdb.Objfile.add_separate_debug_file</code> method, described below.
  138. </p></dd></dl>
  139. <dl>
  140. <dt><a name="index-Objfile_002ebuild_005fid"></a>Variable: <strong>Objfile.build_id</strong></dt>
  141. <dd><p>The build ID of the objfile as a string.
  142. If the objfile does not have a build ID then the value is <code>None</code>.
  143. </p>
  144. <p>This is supported only on some operating systems, notably those which use
  145. the ELF format for binary files and the <small>GNU</small> Binutils. For more details
  146. about this feature, see the description of the <samp>--build-id</samp>
  147. command-line option in <a href="http://sourceware.org/binutils/docs/ld/Options.html#Options">Command Line Options</a> in <cite>The GNU Linker</cite>.
  148. </p></dd></dl>
  149. <dl>
  150. <dt><a name="index-Objfile_002eprogspace"></a>Variable: <strong>Objfile.progspace</strong></dt>
  151. <dd><p>The containing program space of the objfile as a <code>gdb.Progspace</code>
  152. object. See <a href="Progspaces-In-Python.html#Progspaces-In-Python">Progspaces In Python</a>.
  153. </p></dd></dl>
  154. <dl>
  155. <dt><a name="index-Objfile_002epretty_005fprinters"></a>Variable: <strong>Objfile.pretty_printers</strong></dt>
  156. <dd><p>The <code>pretty_printers</code> attribute is a list of functions. It is
  157. used to look up pretty-printers. A <code>Value</code> is passed to each
  158. function in order; if the function returns <code>None</code>, then the
  159. search continues. Otherwise, the return value should be an object
  160. which is used to format the value. See <a href="Pretty-Printing-API.html#Pretty-Printing-API">Pretty Printing API</a>, for more
  161. information.
  162. </p></dd></dl>
  163. <dl>
  164. <dt><a name="index-Objfile_002etype_005fprinters"></a>Variable: <strong>Objfile.type_printers</strong></dt>
  165. <dd><p>The <code>type_printers</code> attribute is a list of type printer objects.
  166. See <a href="Type-Printing-API.html#Type-Printing-API">Type Printing API</a>, for more information.
  167. </p></dd></dl>
  168. <dl>
  169. <dt><a name="index-Objfile_002eframe_005ffilters"></a>Variable: <strong>Objfile.frame_filters</strong></dt>
  170. <dd><p>The <code>frame_filters</code> attribute is a dictionary of frame filter
  171. objects. See <a href="Frame-Filter-API.html#Frame-Filter-API">Frame Filter API</a>, for more information.
  172. </p></dd></dl>
  173. <p>One may add arbitrary attributes to <code>gdb.Objfile</code> objects
  174. in the usual Python way.
  175. This is useful if, for example, one needs to do some extra record keeping
  176. associated with the objfile.
  177. </p>
  178. <p>In this contrived example we record the time when <small>GDB</small>
  179. loaded the objfile.
  180. </p>
  181. <div class="smallexample">
  182. <pre class="smallexample">(gdb) python
  183. import datetime
  184. def new_objfile_handler(event):
  185. # Set the time_loaded attribute of the new objfile.
  186. event.new_objfile.time_loaded = datetime.datetime.today()
  187. gdb.events.new_objfile.connect(new_objfile_handler)
  188. end
  189. (gdb) file ./hello
  190. Reading symbols from ./hello...
  191. (gdb) python print gdb.objfiles()[0].time_loaded
  192. 2014-10-09 11:41:36.770345
  193. </pre></div>
  194. <p>A <code>gdb.Objfile</code> object has the following methods:
  195. </p>
  196. <dl>
  197. <dt><a name="index-Objfile_002eis_005fvalid"></a>Function: <strong>Objfile.is_valid</strong> <em>()</em></dt>
  198. <dd><p>Returns <code>True</code> if the <code>gdb.Objfile</code> object is valid,
  199. <code>False</code> if not. A <code>gdb.Objfile</code> object can become invalid
  200. if the object file it refers to is not loaded in <small>GDB</small> any
  201. longer. All other <code>gdb.Objfile</code> methods will throw an exception
  202. if it is invalid at the time the method is called.
  203. </p></dd></dl>
  204. <dl>
  205. <dt><a name="index-Objfile_002eadd_005fseparate_005fdebug_005ffile"></a>Function: <strong>Objfile.add_separate_debug_file</strong> <em>(file)</em></dt>
  206. <dd><p>Add <var>file</var> to the list of files that <small>GDB</small> will search for
  207. debug information for the objfile.
  208. This is useful when the debug info has been removed from the program
  209. and stored in a separate file. <small>GDB</small> has built-in support for
  210. finding separate debug info files (see <a href="Separate-Debug-Files.html#Separate-Debug-Files">Separate Debug Files</a>), but if
  211. the file doesn&rsquo;t live in one of the standard places that <small>GDB</small>
  212. searches then this function can be used to add a debug info file
  213. from a different place.
  214. </p></dd></dl>
  215. <dl>
  216. <dt><a name="index-Objfile_002elookup_005fglobal_005fsymbol"></a>Function: <strong>Objfile.lookup_global_symbol</strong> <em>(name <span class="roman">[</span>, domain<span class="roman">]</span>)</em></dt>
  217. <dd><p>Search for a global symbol named <var>name</var> in this objfile. Optionally, the
  218. search scope can be restricted with the <var>domain</var> argument.
  219. The <var>domain</var> argument must be a domain constant defined in the <code>gdb</code>
  220. module and described in <a href="Symbols-In-Python.html#Symbols-In-Python">Symbols In Python</a>. This function is similar to
  221. <code>gdb.lookup_global_symbol</code>, except that the search is limited to this
  222. objfile.
  223. </p>
  224. <p>The result is a <code>gdb.Symbol</code> object or <code>None</code> if the symbol
  225. is not found.
  226. </p></dd></dl>
  227. <dl>
  228. <dt><a name="index-Objfile_002elookup_005fstatic_005fsymbol"></a>Function: <strong>Objfile.lookup_static_symbol</strong> <em>(name <span class="roman">[</span>, domain<span class="roman">]</span>)</em></dt>
  229. <dd><p>Like <code>Objfile.lookup_global_symbol</code>, but searches for a global
  230. symbol with static linkage named <var>name</var> in this objfile.
  231. </p></dd></dl>
  232. <hr>
  233. <div class="header">
  234. <p>
  235. Next: <a href="Frames-In-Python.html#Frames-In-Python" accesskey="n" rel="next">Frames In Python</a>, Previous: <a href="Progspaces-In-Python.html#Progspaces-In-Python" accesskey="p" rel="previous">Progspaces In Python</a>, Up: <a href="Python-API.html#Python-API" accesskey="u" rel="up">Python API</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>
  236. </div>
  237. </body>
  238. </html>