AnyEvent-GDB
view release on metacpan or search on metacpan
ddx $gdb->cmd_sync (break_insert => "_exit");
ddx $gdb->cmd_sync ("exec_run");
AE::cv->recv;
PROTOCOL QUIRKS
Minus vs. underscores
The MI protocol uses "-" to separate name components, while in Perl, you
use "_" for this purpose.
This module usually accepts either form as input, and always converts
names with "-" to names with "_", so the "library-loaded" notify might
become "notify_library_loaded", and the "host-name" result in that event
is stored in the "host_name" hash element in Perl.
Output redirection
Unfortunately, GDB has no (portable) provision to separate GDB
input/output from program input/output. Obviously, without a distinction
between program I/O and GDB I/O it becomes impossible to safely control
GDB.
There are two ways for you around it: redirect stdin/stdout yourself, or
set a tty (eg. with the "inferior_set_tty" command).
Unfortunately, the MI interface does not seem to support any kind of I/O
redirection, so this module helps you a bit, by setting the
"exec-wrapper" variable with a console "set" commmand. That is, this
module does soeQmthing like the following for you, providing proper file
descriptors for your actual stdin and stdout:
set exec-wrapper <&5 >&6
The actual I/O redirection operators are also stored in "$gdb->{stdio}",
so you can even do it yourself, e.g. when providing your own wrapper:
$self->cmd_raw ("set exec-wrapper $self->{stdio}", sub { });
(You need to use a raw command, as the "correct" "gdb_set" MI command
silently ignores any "exec-wrapper" setting).
METHODS
$gdb = new AnyEvent::GDB key => value...
Create a new GDB object using the given named parameters.
For initial experiments, it is highly recommended to run with
tracing or at least "verbose" enabled. And don't forget to provide
an "on_eof" callback.
my $gdb = new AnyEvent::GDB
on_eof => sub {
print "We are done.\n";
},
trace => 1; # or verbose => 1, for less output
exec => $path (default: "gdb")
The path of the GDB executable.
args => [$string...] (default: ["-n"])
An optional array of parameters to pass to GDB. This should not
be used to load a program executable, use the
"file_exec_and_symbols", "target_attach" or similar MI commands
instead.
trace => $boolean (default: 0)
If true, then all commands sent to GDB are printed to STDOUT
prefixed with "> ", and all replies received from GDB are
printed to STDOUT prefixed with "< ".
verbose => $boolean (default: true if trace is enabled, false
otherwise)
If true, then log output and possibly other information is
printed to STDOUT.
on_xxxx => $callback->(...)
This specifies a callback for a specific event - see the EVENTS
section later in this document.
$gdb->cmd_raw ($command, $cb->($class, $results, $console))
Execute a raw command: $command is sent unchanged to GDB. See "cmd_"
for a description of the callback arguments.
Example: execute a CLI command and print its output.
$gdb->cmd_raw ("info sh", sub {
print "$_[3]\n";
});
$gdb->cmd ($command => [$option...], $parameter..., $cb->($class,
$results, $console))
Execute a MI command and invoke the callback with the results.
$command is a MI command name. The leading minus sign can be
omitted, and instead of minus signs, you can use underscores, i.e.
all the following command names are equivalent:
"-break-insert" # as documented in the GDB manual
-break_insert # using underscores and _ to avoid having to quote
break_insert # ditto, when e.g. used to the left of a =>
"break-insert" # no leading minus
The second argument is an optional array reference with options
(i.e. it can simply be missing). Each $option is either an option
name (similar rules as with command names, i.e. no initial "--") or
an array reference with the first element being the option name, and
the remaining elements being parameters: [$option, $parameter...].
The remaining arguments, excluding the last one, are simply the
parameters passed to GDB.
All options and parameters will be properly quoted.
When the command is done, the callback $cb will be invoked with
$class being one of "done", "connected", "error" or "exit" (note:
not "running"), $results being a has reference with all the
"variable=value" pairs from the result list.
$console is an array reference with all the GDB console messages
written while command executes (for MI commands, this should always
be "undef" and can be ignored).
Example: #todo#
( run in 0.954 second using v1.01-cache-2.11-cpan-e1769b4cff6 )