Toolbox package

Catchpointing

class mcgdb.toolbox.Catchable[source]

Bases: object

ALL_ENTITIES = <object object>
static activate(name, entity)[source]
static addRemove(name, entity, do_add)[source]
catch = {}
static is_set(name, entity=None)[source]
static keys()[source]
static register(name)[source]
static remove(name, entity)[source]
static values()[source]
toolbox.catchable = <mcgdb.toolbox.Catchable object>

My gdb module

Module with usefil extensions to GDB's default Python functionalities.

class mcgdb.toolbox.my_gdb.AllInfBreakpoint(spec, internal=True)[source]

Bases: gdb.Breakpoint

Subclass of gdb.Breakpoint that spreads itself to all the existing and future inferiors.

Set them with command break_spread (communication.cli.my_gdb.cmd_AllInfBreakpoint).

breakpoints = []
static handler_new_objfile(event)[source]

To connect to gdb.events.new_objfile. Spreads AllInfBreakpoints to new interiors.

static spread_to_other_inferiors()[source]

Tries to spread all the AllInfBreakpoint to new inferiors, and remove the dead ones from the lists.

class mcgdb.toolbox.my_gdb.DefaultTaskManager[source]

Bases: object

Internal function. Default task manager implementation, simply relying on GDB's inferior+threads.

get_mark(task)[source]
Returns:"*" if infthr task is currently selected or " "
get_selected_task()[source]
Returns:the current infthr.
is_selected_task(task)[source]
Returns:True if infthr task is valid and currently selected.
switch_to(task)[source]

Tries to switch to infthr task. :returns: True if it succeeded, False otherwise.

class mcgdb.toolbox.my_gdb.Prompt(old_prompt)[source]

Bases: object

Internal function. Extended prompt.

Variables:
  • hooks -- set of callable, triggered before returning the local prompt.
  • prompts -- set of callable, applied recursively (next_prompt(previous)) to compte the prompt displayed by GDB.
Parameters:

old_prompt -- the inner most prompt, (eg (gdb) or None)

popPrompt(prompt)[source]
pushPrompt(prompt)[source]
registerHook(hook)[source]
unregisterHook(hook)[source]
class mcgdb.toolbox.my_gdb.SiblingBreakpoint(referent)[source]

Bases: gdb.Breakpoint

Copy of breakpoint referent in another program space. Registers itself in referent.siblings list.

Parameters:referent (AllInfBreakpoint) -- the original breakpoint.
Variables:inf_id -- the inferior in which this breakpoint was set.
stop()[source]

Overides gdb.Breakpoint.stop. :returns: False is the current inferior is not self.inf_id :returns: Delegates to referent.stop()

class mcgdb.toolbox.my_gdb.StrongNextBreakpoint(spec, keyword=None)[source]

Bases: gdb.Breakpoint

Internal function. Breakpoint extension used to implent strong_next command. :param keyword: optional description (mnemonic) of the strong_next startpoint. :type keyword: str

stop()[source]
mcgdb.toolbox.my_gdb.active_thread(thread)[source]
mcgdb.toolbox.my_gdb.addr2num(addr)[source]
mcgdb.toolbox.my_gdb.address_to_variable(addr, frame)[source]
mcgdb.toolbox.my_gdb.attach(pid, name=None, comeback=False, silent=False)[source]

Tries to attach GDB to pid process.

Parameters:
  • comeback -- if true, switch back to the initial inferior. Otherwise, stay on the newly attached inferior.
  • silent -- print information on screen or not. Default: False.
Returns:

the newly attached inferior object, or None if it failed.

Return type:

gdb.Inferior

mcgdb.toolbox.my_gdb.attach_all(pids)[source]

Tries to attach GDB to the processes described by [pids].

Parameters:pids (list) -- list of PIDs
Returns:the newly attached inferior objects, or [] if all failed.
Return type:list(gdb.Inferior)
mcgdb.toolbox.my_gdb.before_prompt(fct)[source]
mcgdb.toolbox.my_gdb.blocks_equal(a, b)[source]
mcgdb.toolbox.my_gdb.catch(what)[source]
mcgdb.toolbox.my_gdb.current_infthr()[source]

Returns GDB's currently selected inferior+thread.

List them with command info infthreads (communication.cli.my_gdb.cmd_info_infthread).

Returns:#1 GDB's selected inferior
Returns:#2 GDB's selected thread
mcgdb.toolbox.my_gdb.defaultPrompt(old)[source]

Internal function. Returns GDB's default prompt: (gdb) :param old: unused

mcgdb.toolbox.my_gdb.delete_bp(num)[source]

Deprecated function. Wrapper around GDB's delete command. Use Breakpoint.delete instead.

mcgdb.toolbox.my_gdb.exec_on_sharedlibrary(to_call, soname)[source]
mcgdb.toolbox.my_gdb.extend_env(varname, value, join=':')[source]
mcgdb.toolbox.my_gdb.find_type(orig, name)[source]

Internal function.

mcgdb.toolbox.my_gdb.get_confirm()[source]

Wrapper around gdb.parameter("confirm")

mcgdb.toolbox.my_gdb.get_current_executable()[source]
Returns:the name of the current executable, if any.
Return type:str
mcgdb.toolbox.my_gdb.get_env(varname)[source]
mcgdb.toolbox.my_gdb.get_function_fname_and_lines(fct_symb)[source]
mcgdb.toolbox.my_gdb.get_src(filename, lstart, lstop)[source]
mcgdb.toolbox.my_gdb.initialize()[source]

Internal function.

mcgdb.toolbox.my_gdb.kill_current_inferior(silent=True)[source]

Wrapper around GDB's kill command.

Parameters:silent -- print information on screen or not. Default: True
Returns:the GDB's kill string if silent was True.
mcgdb.toolbox.my_gdb.late_function_breakpoint_execution(fct=None)[source]
mcgdb.toolbox.my_gdb.main_thread(inferior=None)[source]
mcgdb.toolbox.my_gdb.may_start_threads()[source]
mcgdb.toolbox.my_gdb.new_inferior(silent=False)[source]

Wrapper around GDB's add-inferior command.

Parameters:silent -- print information on screen or not. Default: True
Returns:the newly created inferior object, or None if it failed.
Return type:gdb.Inferior
mcgdb.toolbox.my_gdb.num_to_inf_obj(num)[source]
Returns:the inferior whose identifier is num, None otherwise.
Return type:gdb.Inferior
mcgdb.toolbox.my_gdb.oldest_frame()[source]
mcgdb.toolbox.my_gdb.parse_newprocess(where)[source]

Parses the PID of a new process in where.

Parameters:where -- GDB process creation string
Raises:gdb.Error -- if the where doesn't contain the GDB's process creation pattern.
Returns:the PID found
Return type:int
mcgdb.toolbox.my_gdb.pid_to_inf_obj(pid)[source]
Returns:the inferior whose PID is pid, None otherwise.
Return type:gdb.Inferior
mcgdb.toolbox.my_gdb.primitive_type(typ)[source]
mcgdb.toolbox.my_gdb.print_and_execute(command, to_string=False)[source]

Logs the command and pass it to GDB for execution. :param to_string: passed to gdb.execute. Default: False :returns: The execution string if to_string was True, None otherwise.

mcgdb.toolbox.my_gdb.remove_inferior(inf, silent=True)[source]

Wrapper around GDB's add-inferior command.

Parameters:silent -- print information on screen or not. Default: True
Returns:the GDB's remove string if silent was True.
mcgdb.toolbox.my_gdb.reprint_prompt()[source]
mcgdb.toolbox.my_gdb.safe_finish(to_string=True)[source]

Tries to stop the selected thread first of al, then execute GDB's finish command.

Returns:the output of the finish command.
mcgdb.toolbox.my_gdb.set_confirm(val)[source]

Sets GDB confirm parameter to val.

mcgdb.toolbox.my_gdb.set_env(varname, value)[source]
mcgdb.toolbox.my_gdb.set_parameter(name, value)[source]
mcgdb.toolbox.my_gdb.set_prompt_hook(prompt)[source]
mcgdb.toolbox.my_gdb.signal_handler(signal, frame)[source]

Handler for C^c process interuption. Pushes a stop request in mcGDB.

Connect it with signal.signal(signal.SIGINT, signal_handler).

Parameters:
  • signal -- not used
  • frame -- not used
mcgdb.toolbox.my_gdb.start_or_continue(to_string=False)[source]
mcgdb.toolbox.my_gdb.strong_next(keyword=None)[source]

Internal function. Performes a "strong next" on the currently selected inferior: steps forward, and if we're one step deeper in the callstack, sets a StrongNextBreakpoint on the return point of the frame.

This function is usefull the next commands goes over a runtime function call that switches the current user-level thread. As GDB is not aware of that, it gets lost in its next and the execution never stops again.

Set it with command sn (communication.cli.my_gdb.cmd_sn).

Parameters:keyword -- A message to be displayed when the strop next finishes.
Returns:True if a simple step was not enough to complete the next command.
mcgdb.toolbox.my_gdb.switch_to_inferior(inferior, silent=True)[source]

Switches to another inferior.

Parameters:
  • inferior -- the inferior to switch to.
  • silent -- print information on screen or not. Default: True
Returns:

True if we did the switch.

mcgdb.toolbox.my_gdb.switch_to_infthr(infthr, silent=True)[source]

Switches to another inferior+thread.

Parameters:
  • infthr -- the inferior+thread to switch to.
  • silent -- print information on screen or not. Default: True
Returns:

True if we did the switch.

mcgdb.toolbox.my_gdb.try_to_stop()[source]

Tries to stop the thread currently selected.

Trick: creates another inferior to trick GDB, and gets rid of it.

mcgdb.toolbox.my_gdb.up_before_prompt()[source]
mcgdb.toolbox.my_gdb.value_to_methodNameAddr(meth_value)[source]

Paje module

Module proving Paje trace generation capabilities.

class mcgdb.toolbox.paje.Event(bp, params, do_finish=False, before=False)[source]

Bases: object

Internal function.

static feed_paje(no_header=False, tids=[])[source]
static feed_raw(to_file, tids=[])[source]
static get_ts(init=False)[source]
mcgdb.toolbox.paje.after(bp, params)[source]

Creates finish function call event bp with parameters params.

Parameters:
  • bp -- Breakpoint that generated the event.
  • params (dict) -- dictionnary of the parameters of the event.
mcgdb.toolbox.paje.before(bp, params, do_finish)[source]

Creates an function call event bp with parameters params.

Parameters:
  • bp -- Breakpoint that generated the event.
  • params (dict) -- dictionnary of the parameters of the event.
  • do_finish -- True we can expect an after event.
class mcgdb.toolbox.paje.cmd_printPaje(limited=False)[source]

Bases: gdb.Command

invoke(args, from_tty)[source]
invoke_limited(to_screen, to_file, tids)[source]
invoke_paje(to_screen, to_file, tids)[source]
mcgdb.toolbox.paje.initialize()[source]

Internal function.

Python utils module

Module with Python utility functions.

mcgdb.toolbox.python_utils.Dicted(clazz)[source]

Adds dictionnary capabilities to the class. See dicted_example.

class mcgdb.toolbox.python_utils.Enum[source]

Bases: set

Internal function.

class mcgdb.toolbox.python_utils.Events[source]

Bases: object

Internal function.

bp_stop = <mcgdb.toolbox.python_utils.Observer object>
cont = <mcgdb.toolbox.python_utils.Observer object>
mcgdb.toolbox.python_utils.Listed(clazz)[source]

Adds a listing capability to the class. See listed_example.

mcgdb.toolbox.python_utils.Numbered(clazz)[source]

Gives a unique number identifier to class instances. See numbered_example.

class mcgdb.toolbox.python_utils.Observer[source]

Bases: object

Internal function.

connect(handler)[source]
disconnect(handler)[source]
trigger(arg=None)[source]
class mcgdb.toolbox.python_utils.SimpleClass(*args, **kws)[source]

Bases: dict

Internal function. A simple class / advanced dictionnary class that provided its elements through named parameters.

last_number = 0
mcgdb.toolbox.python_utils.Switchable(clazz)[source]

Adds generic switching capability to the class. See switchable_example.

mcgdb.toolbox.python_utils.class_decorator(deco)[source]
mcgdb.toolbox.python_utils.colored(string, color)[source]

Internal function. Colorize a string.

Parameters:
  • string -- the text to colorize.
  • color -- the color to apply to the text.
Returns:

the colored string if we managed to, or the original string.

mcgdb.toolbox.python_utils.deprecated(decoratee)
class mcgdb.toolbox.python_utils.dicted_example[source]

Bases: object

dict_ = {}
classmethod init_dict(key, self)

Add the current object to its class dictionnary (in __init__).

Parameters:
  • key -- Unique id of this object instance.
  • self -- Object instance put in the dict.
classmethod key_to_value(key)

Get object identified with key key.

Parameters:key -- key to lookup.
mcgdb.toolbox.python_utils.docstring_extension(doc_ext)[source]
mcgdb.toolbox.python_utils.error(msg)[source]

Raise a GDB error.

Parameters:msg -- Reason of the error.
mcgdb.toolbox.python_utils.fct_decorator(decoratee)
mcgdb.toolbox.python_utils.generator(decoratee)
mcgdb.toolbox.python_utils.hugly(decoratee)
mcgdb.toolbox.python_utils.info(_type, value, tb)[source]

Internal function.

mcgdb.toolbox.python_utils.initializeModule(mod)[source]

Internal function.

mcgdb.toolbox.python_utils.initializePackage(pkg)[source]
mcgdb.toolbox.python_utils.initializeSubmodules(currentModule)[source]

Internal function.

mcgdb.toolbox.python_utils.internal(decoratee)
class mcgdb.toolbox.python_utils.listed_example(*args, **kws)[source]

Bases: object

list_ = []
class mcgdb.toolbox.python_utils.numbered_example(*args, **kws)[source]

Bases: object

last_number = 0
mcgdb.toolbox.python_utils.print_args(function)[source]

Decorator. Prints all the arguments of the decorated function.

mcgdb.toolbox.python_utils.profile(*args, **kw)[source]
mcgdb.toolbox.python_utils.refer_to(obj)[source]
class mcgdb.toolbox.python_utils.switchable_example[source]

Bases: object

is_current()

Virtual method. :returns: True if the entity is active in the context.

switch(force=False)

Virtual method. Switch context to this entity.

mcgdb.toolbox.python_utils.virtual(decoratee)