blob: 562f7d3f78f2d639ac35e148548f616ea61a5107 [file] [log] [blame]
<html lang="en">
<head>
<title>Objfiles In Python - Debugging with GDB</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Debugging with GDB">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Python-API.html#Python-API" title="Python API">
<link rel="prev" href="Progspaces-In-Python.html#Progspaces-In-Python" title="Progspaces In Python">
<link rel="next" href="Frames-In-Python.html#Frames-In-Python" title="Frames In Python">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
Copyright (C) 1988-2019 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being ``Free Software'' and ``Free Software Needs
Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
and with the Back-Cover Texts as in (a) below.
(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
this GNU Manual. Buying copies from GNU Press supports the FSF in
developing GNU and promoting software freedom.''
-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="Objfiles-In-Python"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Frames-In-Python.html#Frames-In-Python">Frames In Python</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Progspaces-In-Python.html#Progspaces-In-Python">Progspaces In Python</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Python-API.html#Python-API">Python API</a>
<hr>
</div>
<h5 class="subsubsection">23.2.2.24 Objfiles In Python</h5>
<p><a name="index-objfiles-in-python-2245"></a><a name="index-gdb_002eObjfile-2246"></a><a name="index-Objfile-2247"></a><span class="sc">gdb</span> loads symbols for an inferior from various
symbol-containing files (see <a href="Files.html#Files">Files</a>). These include the primary
executable file, any shared libraries used by the inferior, and any
separate debug info files (see <a href="Separate-Debug-Files.html#Separate-Debug-Files">Separate Debug Files</a>).
<span class="sc">gdb</span> calls these symbol-containing files <dfn>objfiles</dfn>.
<p>The following objfile-related functions are available in the
<code>gdb</code> module:
<p><a name="index-gdb_002ecurrent_005fobjfile-2248"></a>
<div class="defun">
&mdash; Function: <b>gdb.current_objfile</b> ()<var><a name="index-gdb_002ecurrent_005fobjfile-2249"></a></var><br>
<blockquote><p>When auto-loading a Python script (see <a href="Python-Auto_002dloading.html#Python-Auto_002dloading">Python Auto-loading</a>), <span class="sc">gdb</span>
sets the &ldquo;current objfile&rdquo; to the corresponding objfile. This
function returns the current objfile. If there is no current objfile,
this function returns <code>None</code>.
</p></blockquote></div>
<p><a name="index-gdb_002eobjfiles-2250"></a>
<div class="defun">
&mdash; Function: <b>gdb.objfiles</b> ()<var><a name="index-gdb_002eobjfiles-2251"></a></var><br>
<blockquote><p>Return a sequence of objfiles referenced by the current program space.
See <a href="Objfiles-In-Python.html#Objfiles-In-Python">Objfiles In Python</a>, and <a href="Progspaces-In-Python.html#Progspaces-In-Python">Progspaces In Python</a>. This is identical
to <code>gdb.selected_inferior().progspace.objfiles()</code> and is included for
historical compatibility.
</p></blockquote></div>
<p><a name="index-gdb_002elookup_005fobjfile-2252"></a>
<div class="defun">
&mdash; Function: <b>gdb.lookup_objfile</b> (<var>name </var><span class="roman">[</span><var>, by_build_id</var>])<var><a name="index-gdb_002elookup_005fobjfile-2253"></a></var><br>
<blockquote><p>Look up <var>name</var>, a file name or build ID, in the list of objfiles
for the current program space (see <a href="Progspaces-In-Python.html#Progspaces-In-Python">Progspaces In Python</a>).
If the objfile is not found throw the Python <code>ValueError</code> exception.
<p>If <var>name</var> is a relative file name, then it will match any
source file name with the same trailing components. For example, if
<var>name</var> is &lsquo;<samp><span class="samp">gcc/expr.c</span></samp>&rsquo;, then it will match source file
name of <samp><span class="file">/build/trunk/gcc/expr.c</span></samp>, but not
<samp><span class="file">/build/trunk/libcpp/expr.c</span></samp> or <samp><span class="file">/build/trunk/gcc/x-expr.c</span></samp>.
<p>If <var>by_build_id</var> is provided and is <code>True</code> then <var>name</var>
is the build ID of the objfile. Otherwise, <var>name</var> is a file name.
This is supported only on some operating systems, notably those which use
the ELF format for binary files and the <span class="sc">gnu</span> Binutils. For more details
about this feature, see the description of the <samp><span class="option">--build-id</span></samp>
command-line option in <a href="../ld/Options.html#Options">Command Line Options</a>.
</p></blockquote></div>
<p>Each objfile is represented by an instance of the <code>gdb.Objfile</code>
class.
<div class="defun">
&mdash; Variable: <b>Objfile.filename</b><var><a name="index-Objfile_002efilename-2254"></a></var><br>
<blockquote><p>The file name of the objfile as a string, with symbolic links resolved.
<p>The value is <code>None</code> if the objfile is no longer valid.
See the <code>gdb.Objfile.is_valid</code> method, described below.
</p></blockquote></div>
<div class="defun">
&mdash; Variable: <b>Objfile.username</b><var><a name="index-Objfile_002eusername-2255"></a></var><br>
<blockquote><p>The file name of the objfile as specified by the user as a string.
<p>The value is <code>None</code> if the objfile is no longer valid.
See the <code>gdb.Objfile.is_valid</code> method, described below.
</p></blockquote></div>
<div class="defun">
&mdash; Variable: <b>Objfile.owner</b><var><a name="index-Objfile_002eowner-2256"></a></var><br>
<blockquote><p>For separate debug info objfiles this is the corresponding <code>gdb.Objfile</code>
object that debug info is being provided for.
Otherwise this is <code>None</code>.
Separate debug info objfiles are added with the
<code>gdb.Objfile.add_separate_debug_file</code> method, described below.
</p></blockquote></div>
<div class="defun">
&mdash; Variable: <b>Objfile.build_id</b><var><a name="index-Objfile_002ebuild_005fid-2257"></a></var><br>
<blockquote><p>The build ID of the objfile as a string.
If the objfile does not have a build ID then the value is <code>None</code>.
<p>This is supported only on some operating systems, notably those which use
the ELF format for binary files and the <span class="sc">gnu</span> Binutils. For more details
about this feature, see the description of the <samp><span class="option">--build-id</span></samp>
command-line option in <a href="../ld/Options.html#Options">Command Line Options</a>.
</p></blockquote></div>
<div class="defun">
&mdash; Variable: <b>Objfile.progspace</b><var><a name="index-Objfile_002eprogspace-2258"></a></var><br>
<blockquote><p>The containing program space of the objfile as a <code>gdb.Progspace</code>
object. See <a href="Progspaces-In-Python.html#Progspaces-In-Python">Progspaces In Python</a>.
</p></blockquote></div>
<div class="defun">
&mdash; Variable: <b>Objfile.pretty_printers</b><var><a name="index-Objfile_002epretty_005fprinters-2259"></a></var><br>
<blockquote><p>The <code>pretty_printers</code> attribute is a list of functions. It is
used to look up pretty-printers. A <code>Value</code> is passed to each
function in order; if the function returns <code>None</code>, then the
search continues. Otherwise, the return value should be an object
which is used to format the value. See <a href="Pretty-Printing-API.html#Pretty-Printing-API">Pretty Printing API</a>, for more
information.
</p></blockquote></div>
<div class="defun">
&mdash; Variable: <b>Objfile.type_printers</b><var><a name="index-Objfile_002etype_005fprinters-2260"></a></var><br>
<blockquote><p>The <code>type_printers</code> attribute is a list of type printer objects.
See <a href="Type-Printing-API.html#Type-Printing-API">Type Printing API</a>, for more information.
</p></blockquote></div>
<div class="defun">
&mdash; Variable: <b>Objfile.frame_filters</b><var><a name="index-Objfile_002eframe_005ffilters-2261"></a></var><br>
<blockquote><p>The <code>frame_filters</code> attribute is a dictionary of frame filter
objects. See <a href="Frame-Filter-API.html#Frame-Filter-API">Frame Filter API</a>, for more information.
</p></blockquote></div>
<p>One may add arbitrary attributes to <code>gdb.Objfile</code> objects
in the usual Python way.
This is useful if, for example, one needs to do some extra record keeping
associated with the objfile.
<p>In this contrived example we record the time when <span class="sc">gdb</span>
loaded the objfile.
<pre class="smallexample"> (gdb) python
import datetime
def new_objfile_handler(event):
# Set the time_loaded attribute of the new objfile.
event.new_objfile.time_loaded = datetime.datetime.today()
gdb.events.new_objfile.connect(new_objfile_handler)
end
(gdb) file ./hello
Reading symbols from ./hello...done.
(gdb) python print gdb.objfiles()[0].time_loaded
2014-10-09 11:41:36.770345
</pre>
<p>A <code>gdb.Objfile</code> object has the following methods:
<div class="defun">
&mdash; Function: <b>Objfile.is_valid</b> ()<var><a name="index-Objfile_002eis_005fvalid-2262"></a></var><br>
<blockquote><p>Returns <code>True</code> if the <code>gdb.Objfile</code> object is valid,
<code>False</code> if not. A <code>gdb.Objfile</code> object can become invalid
if the object file it refers to is not loaded in <span class="sc">gdb</span> any
longer. All other <code>gdb.Objfile</code> methods will throw an exception
if it is invalid at the time the method is called.
</p></blockquote></div>
<div class="defun">
&mdash; Function: <b>Objfile.add_separate_debug_file</b> (<var>file</var>)<var><a name="index-Objfile_002eadd_005fseparate_005fdebug_005ffile-2263"></a></var><br>
<blockquote><p>Add <var>file</var> to the list of files that <span class="sc">gdb</span> will search for
debug information for the objfile.
This is useful when the debug info has been removed from the program
and stored in a separate file. <span class="sc">gdb</span> has built-in support for
finding separate debug info files (see <a href="Separate-Debug-Files.html#Separate-Debug-Files">Separate Debug Files</a>), but if
the file doesn't live in one of the standard places that <span class="sc">gdb</span>
searches then this function can be used to add a debug info file
from a different place.
</p></blockquote></div>
</body></html>