Devel-GDB-2.02/0000755000152000047740000000000010747444340012075 5ustar jezraucodeDevel-GDB-2.02/META.yml0000644000152000047740000000101510747444340013343 0ustar jezraucode--- #YAML:1.0 name: Devel-GDB version: 2.02 abstract: Open and communicate a gdb session license: ~ generated_by: ExtUtils::MakeMaker version 6.31 distribution_type: module requires: Test::More: 0 Thread::Semaphore: 0 threads::shared: 0 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.2.html version: 1.2 author: - Antal Novak , Josef Ezra Devel-GDB-2.02/Changes0000644000152000047740000000277610747444062013405 0ustar jezraucodeRevision history for Perl extension Devel::GDB. 0.01 Mon Oct 15 14:04:09 2001 - original version; created by h2xs 1.21 with options -X -n Devel::GDB 1.0 Mon Oct 15 14:30 2001 jezra - modified as part of creation 1.1 Thu Oct 18 10:42 2001 jezra - more exmaples and documentation 1.2 Wed Oct 24 11:52 2001 jezra - Makefile.PL fix 1.21 Thu Nov 15 16:00 2001 jezra - documentation .. 1.22 Sat Nov 24 14:00 2001 Srebrenko Sehic - example fix 1.23 Fri Oct 22 14:00 2004 jezra - fixed regular expression to support gdb's "> " prompt 2.0 Tue Feb 20 14:59 2007 Antal Novak - This is (almost) a complete rewrite of the codebase, so many things have changed. - New features: - Devel::GDB now uses the GDB/MI interpreter (rather than the console interpreter) to communicate with GDB. - Added send_cmd() family of functions to support GDB/MI commands. - Added support for threads. - Deprecated the old get() syntax; callers wishing to use this must explicitly set $Devel::GDB::DEPRECATED = 1. 2.01 Sun Jan 20 13:32 2008 Geert De Peuter - bug fix in _unescape function 2.02 Mon Jan 28 16:22:38 2008 Josef Ezra - fixed t/expect.t example after it failed on darwin 8.10.1 Devel-GDB-2.02/README0000644000152000047740000000205010575627374012763 0ustar jezraucodeDevel-GDB version 2.0 ===================== The Devel::GDB package provides an interface for communicating with GDB, the GNU debugger. Complete documentation is available on the CPAN site: http://search.cpan.org/~JEZRA/Devel-GDB/GDB.pm INSTALLATION ------------ To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES ------------ This module requires these other modules and libraries, which should be part of most standard Perl instalations: Test::More threads::shared Thread::Semaphore The following modules are also recommended: threads (i.e. Perl compiled with -Dusethreads) Expect IO::BufferedSelect In addition, for the module to be useful, you should have gdb installed :-) COPYRIGHT AND LICENSE --------------------- Copyright (C) 2007 by Antal Novak & Josef Ezra This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available. Devel-GDB-2.02/lib/0000755000152000047740000000000010747444340012643 5ustar jezraucodeDevel-GDB-2.02/lib/Devel/0000755000152000047740000000000010747444340013702 5ustar jezraucodeDevel-GDB-2.02/lib/Devel/GDB/0000755000152000047740000000000010747444340014276 5ustar jezraucodeDevel-GDB-2.02/lib/Devel/GDB/LowLevel.pm0000644000152000047740000001156410575606363016400 0ustar jezraucodepackage Devel::GDB::LowLevel; use 5.006; use strict; use warnings; use FileHandle; use IPC::Open2; use POSIX; use threads::shared; =head1 NAME Devel::GDB::LowLevel - Low-level interface for communicating with GDB =head1 DESCRIPTION This module is used internally by L. It handles the low-level I/O of communicating with the GDB process. =cut our $VERSION = '2.0'; our $DEBUG; our %PARAMS; =head1 CONSTRUCTOR =over =item new Spawns a GDB process. Because this class only facilitates communication with GDB (I with the inferior process being debugged), you have to decide what to do with the C, C, and C of that process. There are a few options available: =over =item * If STDIN is a tty, we can have the inferior process communicate directly with the controlling tty (emulating the default behavior of gdb): $gdb = new Devel::GDB::LowLevel( '-execfile' => $path_to_gdb, '-params' => $extra_gdb_params ); =item * Or, we can create an C object to communicate with the inferior process: $gdb = new Devel::GDB::LowLevel( '-create-expect' => 1 ); $expect = $gdb->get_expect_obj(); =item * Or, we can create our own tty and use that: $gdb = new Devel::GDB::LowLevel( '-use-tty' => '/dev/pts/123' ); =back =back =cut sub new { my $class = shift or die "Who am I? no class provided. please read the manual\n" ; # Load parameters my $self = bless { '-execfile' => 'gdb', # gdb executable '-params' => '' , # additional parameters @_ }, $class ; # Complain about any invalid parameters foreach (keys %$self) { die "$class: Invalid parameter $_" unless /^-(execfile|params|use-tty|create-expect)$/; } die "Cannot use both -use-tty and -create-expect!" if $self->{'-use-tty'} && $self->{'-create-expect'}; # Create the TX lock $self->{LOCK_tx} = &share(\my $tmp); # Create a tty if necessary my $tty = $self->{'-use-tty'} || $self->{'-create-expect'} && $self->_new_expect() || ttyname(0) or die "$class: STDIN must be a tty when neither -use-tty nor -create-expect are specified"; # Build the parameter list my @params = (ref $self->{'-params'} eq 'ARRAY') ? @{$self->{'-params'}} : split(/\s+/, $self->{'-params'}); unshift @params, '--interpreter=mi'; unshift @params, "--tty=$tty"; # Open the GDB pipe (Note that open2 will die if the fork() fails, but if # exec() fails, we'll just get a SIGPIPE later.) @{$self}{qw/PID IN OUT/} = $self->_pipe_open( $self->{'-execfile'}, @params ); return $self; } =head1 METHODS =over =item send Sends a raw line of text to GDB. This should not contain any newlines (they will be stripped). This method only sends a request, and does not wait for a response. =cut sub send { my $self = shift; my ($line) = @_; $line =~ s/[\r\n]//s; { local $\ = "\n"; lock $self->{LOCK_tx}; my $fh = $self->{OUT}; print $fh $line; print STDERR ">>> $line" if $DEBUG; } } =item get_reader Returns the file handle from which to read GDB responses. =cut sub get_reader { my $self = shift; return $self->{IN}; } =item get_expect_obj Returns the C object created in the constructor. Dies if C<'-create-expect'> was not passed to C. =cut sub get_expect_obj { my $self = shift; $self->{expect_obj} or die; } =item interrupt Send SIGINT to the GDB session, interrupting the inferior process (if any). =cut sub interrupt { my $self = shift; kill 2, $self->{PID}; } sub _new_expect { require Expect; my $self = shift; $self->{expect_obj} = new Expect; $self->{expect_obj}->log_stdout(0); # Disable echo on the pty my $fd = fileno($self->{expect_obj}); my $termios = new POSIX::Termios; $termios->getattr($fd); $termios->setlflag($termios->getlflag & ~&POSIX::ECHO); $termios->setattr($fd); return $self->{expect_obj}->slave->ttyname; } sub _pipe_open { my $self = shift; my @cmd = @_; $SIG{PIPE} = sub { $self->_pipe_sig(); }; my ($in, $out) = (new FileHandle, new FileHandle) ; my $pid = open2($in, $out, @cmd) ; ($pid, $in, $out) } sub _pipe_sig { my $self = shift; # Check if $self->{PID} is really dead? die "SIGPIPE: GDB terminated unexpectedly?"; } 1; __END__ =back =head1 SEE ALSO L =head1 AUTHORS Antal Novak Eafn@cpan.orgE, Josef Ezra Ejezra@cpan.orgE =head1 COPYRIGHT AND LICENSE Copyright (C) 2007 by Antal Novak & Josef Ezra This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available. =cut Devel-GDB-2.02/lib/Devel/GDB.pm0000644000152000047740000007066010747443546014654 0ustar jezraucodepackage 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