Next: Commands In Python, Previous: Threads In Python, Up: Python API [Contents][Index]
The following recordings-related functions
(see Process Record and Replay) are available in the gdb
module:
Start a recording using the given method and format. If
no format is given, the default format for the recording method
is used. If no method is given, the default method will be used.
Returns a gdb.Record
object on success. Throw an exception on
failure.
The following strings can be passed as method:
"full"
"btrace"
: Possible values for format: "pt"
,
"bts"
or leave out for default format.
Access a currently running recording. Return a gdb.Record
object on success. Return None
if no recording is currently
active.
Stop the current recording. Throw an exception if no recording is currently active. All record objects become invalid after this call.
A gdb.Record
object has the following attributes:
A string with the current recording method, e.g. full
or
btrace
.
A string with the current recording format, e.g. bt
, pts
or
None
.
A method specific instruction object representing the first instruction in this recording.
A method specific instruction object representing the current instruction, that is not actually part of the recording.
The instruction representing the current replay position. If there is
no replay active, this will be None
.
A list with all recorded instructions.
A list with all recorded function call segments.
A gdb.Record
object has the following methods:
Move the replay position to the given instruction.
The common gdb.Instruction
class that recording method specific
instruction objects inherit from, has the following attributes:
An integer representing this instruction’s address.
A buffer with the raw instruction data. In Python 3, the return value is a
memoryview
object.
A human readable string with the disassembled instruction.
The size of the instruction in bytes.
Additionally gdb.RecordInstruction
has the following attributes:
An integer identifying this instruction. number
corresponds to
the numbers seen in record instruction-history
(see Process Record and Replay).
A gdb.Symtab_and_line
object representing the associated symtab
and line of this instruction. May be None
if no debug information is
available.
A boolean indicating whether the instruction was executed speculatively.
If an error occured during recording or decoding a recording, this error is
represented by a gdb.RecordGap
object in the instruction list. It has
the following attributes:
An integer identifying this gap. number
corresponds to the numbers seen
in record instruction-history
(see Process Record and Replay).
A numerical representation of the reason for the gap. The value is specific to the current recording method.
A human readable string with the reason for the gap.
A gdb.RecordFunctionSegment
object has the following attributes:
An integer identifying this function segment. number
corresponds to
the numbers seen in record function-call-history
(see Process Record and Replay).
A gdb.Symbol
object representing the associated symbol. May be
None
if no debug information is available.
An integer representing the function call’s stack level. May be
None
if the function call is a gap.
A list of gdb.RecordInstruction
or gdb.RecordGap
objects
associated with this function call.
A gdb.RecordFunctionSegment
object representing the caller’s
function segment. If the call has not been recorded, this will be the
function segment to which control returns. If neither the call nor the
return have been recorded, this will be None
.
A gdb.RecordFunctionSegment
object representing the previous
segment of this function call. May be None
.
A gdb.RecordFunctionSegment
object representing the next segment of
this function call. May be None
.
The following example demonstrates the usage of these objects and functions to create a function that will rewind a record to the last time a function in a different file was executed. This would typically be used to track the execution of user provided callback functions in a library which typically are not visible in a back trace.
def bringback (): rec = gdb.current_recording () if not rec: return insn = rec.instruction_history if len (insn) == 0: return try: position = insn.index (rec.replay_position) except: position = -1 try: filename = insn[position].sal.symtab.fullname () except: filename = None for i in reversed (insn[:position]): try: current = i.sal.symtab.fullname () except: current = None if filename == current: continue rec.goto (i) return
Another possible application is to write a function that counts the number of code executions in a given line range. This line range can contain parts of functions or span across several functions and is not limited to be contiguous.
def countrange (filename, linerange): count = 0 def filter_only (file_name): for call in gdb.current_recording ().function_call_history: try: if file_name in call.symbol.symtab.fullname (): yield call except: pass for c in filter_only (filename): for i in c.instructions: try: if i.sal.line in linerange: count += 1 break; except: pass return count
Next: Commands In Python, Previous: Threads In Python, Up: Python API [Contents][Index]