A program space, or progspace, represents a symbolic view of an address space. It consists of all of the objfiles of the program. See Objfiles In Python. See program spaces, for more details about program spaces.
The following progspace-related functions are available in the
gdb.selected_inferior().progspace(see Inferiors In Python) and is included for historical compatibility.
Each progspace is represented by an instance of the
pretty_printersattribute is a list of functions. It is used to look up pretty-printers. A
Valueis 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.
type_printersattribute is a list of type printer objects. See Type Printing API, for more information.
frame_filtersattribute is a dictionary of frame filter objects. See Frame Filter API, for more information.
A program space has the following methods:
gdb.Blockcontaining the given
pcvalue. If the block cannot be found for the
pcvalue specified, the function will return
gdb.Symtab_and_lineobject corresponding to the
pcvalue. See Symbol Tables In Python. If an invalid value of
pcis passed as an argument, then the
lineattributes of the returned
gdb.Symtab_and_lineobject will be
Noneand 0 respectively.
gdb.Progspaceobject is valid,
Falseif not. A
gdb.Progspaceobject can become invalid if the program space file it refers to is not referenced by any inferior. All other
gdb.Progspacemethods will throw an exception if it is invalid at the time the method is called.
addressas a string, or
One may add arbitrary attributes to
in the usual Python way.
This is useful if, for example, one needs to do some extra record keeping
associated with the program space.
In this contrived example, we want to perform some processing when an objfile with a certain symbol is loaded, but we only want to do this once because it is expensive. To achieve this we record the results with the program space because we can’t predict when the desired objfile will be loaded.
(gdb) python def clear_objfiles_handler(event): event.progspace.expensive_computation = None def expensive(symbol): """A mock routine to perform an "expensive" computation on symbol.""" print "Computing the answer to the ultimate question ..." return 42 def new_objfile_handler(event): objfile = event.new_objfile progspace = objfile.progspace if not hasattr(progspace, 'expensive_computation') or \ progspace.expensive_computation is None: # We use 'main' for the symbol to keep the example simple. # Note: There's no current way to constrain the lookup # to one objfile. symbol = gdb.lookup_global_symbol('main') if symbol is not None: progspace.expensive_computation = expensive(symbol) gdb.events.clear_objfiles.connect(clear_objfiles_handler) gdb.events.new_objfile.connect(new_objfile_handler) end (gdb) file /tmp/hello Reading symbols from /tmp/hello... Computing the answer to the ultimate question ... (gdb) python print gdb.current_progspace().expensive_computation 42 (gdb) run Starting program: /tmp/hello Hello. [Inferior 1 (process 4242) exited normally]