Aliases and Debugger macros written in via Ruby Procs

r edited this page Feb 27, 2011 · 1 revision

The simplest form of macro, an “alias” is a debugger command. You can use it to define a short command name to an existing command. There are a number of built-in aliases such as “s” for step or “c” for continue. But beware: there are some hard-coded hacked suffixes to stepping commands like ‘>’, and ‘+’. Use unalias to remove any alias, even the built-in ones that come with trepan.

gdb has a more more complicated and general macro command for making new debugger commands. But Ruby is already a nice programming language, so why invent another? So instead in trepan we let you create your own expansion command in Ruby. The expansion occurs via a Proc which you create.

Here is an example of a macro. The below creates a macro called
finish+ which issues two debugger commands finish followed by step:

macro fin+{|*args| %w(finish step)}

Macros should return either a String or an Array of Strings. These is substituted for the original command string. If the return value is a String, that gets tokenized by a simple String#split . But ote that macro processing is done right after splitting on “;;” so if the macro returns a string containing “;;” this will not be handled on the string returned.

If instead of a String an Array of Strings is returned, the first string is unshifted from the array and executed. The remaning strings are pushed onto the command queue. In contrast to the first string, subsequent strings can contain other macros, and “;;” in those strings will be split into separate commands.