package Devel::GDB; use 5.006; use strict; use warnings; use Devel::GDB::LowLevel; use threads::shared; use Thread::Semaphore; use B qw( cstring ); =head1 NAME Devel::GDB - Open and communicate a gdb session =head1 SYNOPSIS use Devel::GDB; $gdb = new Devel::GDB(); print $gdb->send_cmd('-environment-path'); print $gdb->get('info functions'); The old C syntax (of C) has been deprecated and will not be supported in future versions. See the documentation of the C function for an explanation of why. If you really want to use the old syntax, set $Devel::GDB::DEPRECATED to true: use Devel::GDB ; $Devel::GDB::DEPRECATED = 1; $gdb = new Devel::GDB(); print $gdb->get('info functions', $timeout, $prompt, $notyet, $alldone); =head1 DESCRIPTION The C package provides an interface for communicating with GDB. Internally, it uses the I interpreter (see L), which accurately informs the caller of the program state and, through the use of tokens, guarantees that the results returned actually correspond to the request sent. By contrast, GDB's I interpreter returns all responses on C, and thus there is no way to ensure that a particular response corresponds to a particular request. Therefore, it is obviously preferable to use GDB/MI when programmatically interacting with GDB. This can be done via the C family of functions (C, C, and C). There are, however, some cases when there is no GDB/MI command corresponding to a particular console command, or it has not yet been implemented (for example, C<-symbol-type>, corresponding to the console command C, is not yet implemented as of GDB 6.6). In this case, the C function provides a workaround by capturing all output sent to the console stream. =cut our $VERSION = '2.02'; our $DEBUG; our $DEPRECATED; =head1 CONSTRUCTOR =head2 new $gdb = new Devel::GDB( '-use-threads' => 1 ); '-params' => $extra_gdb_params ); Spawns a new GDB process. In I mode, this also spawns a listening thread that asynchronously processes responses from GDB; in I mode, the caller is responsible for handling asynchronous output (that is, output from GDB that is not directly solicited by a request). See C, C, and the L example for further discussion. The parameters to the constructor are passed in hash form. The following parameters control how GDB is invoked: =over =item C<-execfile> The GDB binary to execute; defaults to C<"gdb">. =item C<-params> Pass additional parameters to GDB. The value can be an array reference (preferred) or a string. =back The following parameters control how to handle interaction with the I, the program being debugged. The default behavior is to give the inferior process control of the terminal while it is running, returning control to perl when the program is suspended or stopped (emulating the behavior of gdb). However, this only works when C is associated with a tty. Two other (mutually exclusive) options are available: =over =item C<-use-tty> Specify the name of the tty that the inferior process should use for its I/O. Note that this is the path to a tty (e.g. C<"/dev/pts/123">) and not an C object. See the example L. =item C<-create-expect> If this value is non-zero, create an C object (which can be subsequently retrieved by calling C); this is useful if you want to programmatically interact with the inferior process. See the example L. =back Miscellaneous parameters: =over =item C<-use-threads> Operate in threaded (1) or non-threaded (0) mode. The default behavior is to enable threaded mode if the C module has been loaded and disable it otherwise. Note that if C<-use-threads> is enabled, the caller B call C, but C<-use-threads> can be disabled whether or not C has been loaded. Threaded mode is the easiest to deal with, as it does not require the caller to interact with the GDB filehandles directly; for a simple non-threaded example, see the L example. =item C<-readline-fn> Probably only useful in non-threaded mode, this lets the user specify a callback function $fn to be called when waiting for a response from GDB. It is invoked with one parameter, the C instance, and is expected to return one full line of output (or C if EOF was reached). The default implementation uses buffered I/O: $fn = sub { return readline($_[0]->get_reader); } Typically, in non-threaded mode, the caller will be using C