Next: , Previous: , Up: Python API   [Contents][Index] Objfiles In Python

GDB loads symbols for an inferior from various symbol-containing files (see Files). These include the primary executable file, any shared libraries used by the inferior, and any separate debug info files (see Separate Debug Files). GDB calls these symbol-containing files objfiles.

The following objfile-related functions are available in the gdb module:

Function: gdb.current_objfile ()

When auto-loading a Python script (see Python Auto-loading), GDB sets the “current objfile” to the corresponding objfile. This function returns the current objfile. If there is no current objfile, this function returns None.

Function: gdb.objfiles ()

Return a sequence of all the objfiles current known to GDB. See Objfiles In Python.

Each objfile is represented by an instance of the gdb.Objfile class.

Variable: Objfile.filename

The file name of the objfile as a string.

Variable: Objfile.progspace

The containing program space of the objfile as a gdb.Progspace object. See Progspaces In Python.

Variable: Objfile.pretty_printers

The pretty_printers attribute is a list of functions. It is used to look up pretty-printers. A Value is passed to each function in order; if the function returns None, then the search continues. Otherwise, the return value should be an object which is used to format the value. See Pretty Printing API, for more information.

Variable: Objfile.type_printers

The type_printers attribute is a list of type printer objects. See Type Printing API, for more information.

Variable: Objfile.frame_filters

The frame_filters attribute is a dictionary of frame filter objects. See Frame Filter API, for more information.

One may add arbitrary attributes to gdb.Objfile objects in the usual Python way. This is useful if, for example, one needs to do some extra record keeping associated with the objfile.

In this contrived example we record the time when GDB loaded the objfile.

(gdb) python
import datetime
def new_objfile_handler(event):
    # Set the time_loaded attribute of the new objfile.
    event.new_objfile.time_loaded =
(gdb) file ./hello
Reading symbols from ./hello...done.
(gdb) python print gdb.objfiles()[0].time_loaded
2014-10-09 11:41:36.770345

A gdb.Objfile object has the following methods:

Function: Objfile.is_valid ()

Returns True if the gdb.Objfile object is valid, False if not. A gdb.Objfile object can become invalid if the object file it refers to is not loaded in GDB any longer. All other gdb.Objfile methods will throw an exception if it is invalid at the time the method is called.

Next: , Previous: , Up: Python API   [Contents][Index]