You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

264 lines
13KB

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