pygdbmi package

Submodules

pygdbmi.StringStream module

class pygdbmi.StringStream.StringStream(raw_text, debug=False)

Bases: object

A simple class to hold text so that when passed between functions, the object is passed by reference and memory does not need to be repeatedly allocated for the string.

This class was written here to avoid adding a dependency to the project.

advance_past_chars(chars)

Advance the index past specific chars Args chars (list): list of characters to advance past

Return substring that was advanced past

advance_past_string_with_gdb_escapes(chars_to_remove_gdb_escape=None)

characters that gdb escapes that should not be escaped by this parser

read(count)

Read count characters starting at self.index, and return those characters as a string

seek(offset)

Advance the index of this StringStream by offset characters

pygdbmi.gdbcontroller module

GdbController class to programatically run gdb and get structured output

class pygdbmi.gdbcontroller.GdbController(gdb_path='gdb', gdb_args=None, time_to_check_for_additional_output_sec=0.2, rr=False, verbose=False)

Bases: object

Run gdb as a subprocess. Send commands and receive structured output. Create new object, along with a gdb subprocess

Args:
gdb_path (str): Command to run in shell to spawn new gdb subprocess gdb_args (list): Arguments to pass to shell when spawning new gdb subprocess time_to_check_for_additional_output_sec (float): When parsing responses, wait this amout of time before exiting (exits before timeout is reached to save time). If <= 0, full timeout time is used. rr (bool): Use the rr replay command instead of gdb. See rr-project.org for more info. verbose (bool): Print verbose output if True
Returns:
New GdbController object
exit()

Terminate gdb process Returns: None

get_gdb_response(timeout_sec=1, raise_error_on_timeout=True)

Get response from GDB, and block while doing so. If GDB does not have any response ready to be read by timeout_sec, an exception is raised.

Args:
timeout_sec (float): Maximum time to wait for reponse. Must be >= 0. Will return after raise_error_on_timeout (bool): Whether an exception should be raised if no response was found after timeout_sec
Returns:
List of parsed GDB responses, returned from gdbmiparser.parse_response, with the additional key ‘stream’ which is either ‘stdout’ or ‘stderr’
Raises:
GdbTimeoutError if response is not received within timeout_sec ValueError if select returned unexpected file number NoGdbProcessError if there is no gdb subprocess running
get_subprocess_cmd()

Returns the shell-escaped string used to invoke the gdb subprocess. This is a string that can be executed directly in a shell.

interrupt_gdb()

Send SIGINT (interrupt signal) to the gdb subprocess

send_signal_to_gdb(signal_input)

Send signal name (case insensitive) or number to gdb subprocess gdbmi.send_signal_to_gdb(2) # valid gdbmi.send_signal_to_gdb(‘sigint’) # also valid gdbmi.send_signal_to_gdb(‘SIGINT’) # also valid

raises ValueError if signal_input is invalie raises NoGdbProcessError if there is no gdb process to send a signal to

spawn_new_gdb_subprocess()

Spawn a new gdb subprocess with the arguments supplied to the object during initialization. If gdb subprocess already exists, terminate it before spanwing a new one. Return int: gdb process id

verify_valid_gdb_subprocess()

Verify there is a process object, and that it is still running. Raise NoGdbProcessError if either of the above are not true.

write(mi_cmd_to_write, timeout_sec=1, raise_error_on_timeout=True, read_response=True)

Write to gdb process. Block while parsing responses from gdb for a maximum of timeout_sec.

Args:
mi_cmd_to_write (str or list): String to write to gdb. If list, it is joined by newlines. timeout_sec (float): Maximum number of seconds to wait for response before exiting. Must be >= 0. raise_error_on_timeout (bool): If read_response is True, raise error if no response is received read_response (bool): Block and read response. If there is a separate thread running, this can be false, and the reading thread read the output.
Returns:
List of parsed gdb responses if read_response is True, otherwise []
Raises:
NoGdbProcessError if there is no gdb subprocess running TypeError if mi_cmd_to_write is not valid
exception pygdbmi.gdbcontroller.GdbTimeoutError

Bases: ValueError

Raised when no response is recieved from gdb after the timeout has been triggered

exception pygdbmi.gdbcontroller.NoGdbProcessError

Bases: ValueError

Raise when trying to interact with gdb subprocess, but it does not exist. It may have been killed and removed, or failed to initialize for some reason.

pygdbmi.gdbmiparser module

Python parser for gdb’s machine interface interpreter.

Parses string output from gdb with the “–interpreter=mi2” flag into structured objects.

See more at https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI.html#GDB_002fMI

pygdbmi.gdbmiparser.assert_match(actual_char_or_str, expected_char_or_str)

If values don’t match, print them and raise a ValueError, otherwise, continue Raises: ValueError if argumetns do not match

pygdbmi.gdbmiparser.parse_response(gdb_mi_text)

Parse gdb mi text and turn it into a dictionary.

See https://sourceware.org/gdb/onlinedocs/gdb/GDB_002fMI-Stream-Records.html#GDB_002fMI-Stream-Records for details on types of gdb mi output.

Args:
gdb_mi_text (str): String output from gdb
Returns:
dict with the following keys: type (either ‘notify’, ‘result’, ‘console’, ‘log’, ‘target’, ‘done’), message (str or None), payload (str, list, dict, or None)
pygdbmi.gdbmiparser.response_is_finished(gdb_mi_text)

Return true if the gdb mi response is ending Returns: True if gdb response is finished

Module contents