From padb at googlecode.com Wed Mar 30 19:50:15 2011 From: padb at googlecode.com (padb at googlecode.com) Date: Wed, 30 Mar 2011 18:50:15 +0000 Subject: [padb] r433 committed - Revert to using attach rather than -target-attach as some versions... Message-ID: <20cf300fb311bc4949049fb7a557@google.com> Revision: 433 Author: apittman at gmail.com Date: Wed Mar 30 11:49:32 2011 Log: Revert to using attach rather than -target-attach as some versions of gdb don't like using the documentated method. http://code.google.com/p/padb/source/detail?r=433 Modified: /trunk/src/padb ======================================= --- /trunk/src/padb Sat Feb 19 13:58:31 2011 +++ /trunk/src/padb Wed Mar 30 11:49:32 2011 @@ -6177,7 +6177,7 @@ } send_cont_signal($pid); - my %p = gdb_n_send( $gdb, "-target-attach $pid" ); + my %p = gdb_n_send( $gdb, "attach $pid" ); if ( not defined $p{status} ) { $gdb->{error} = 'Failed to attach to process'; @@ -6249,7 +6249,7 @@ send_cont_signal($pid); - _gdb_send_real_async_start( $gdb, "-target-attach $pid" ); + _gdb_send_real_async_start( $gdb, "attach $pid" ); return; } @@ -6257,7 +6257,7 @@ sub gdb_attach_async_end { my ( $gdb, $pid ) = @_; - my %p = _gdb_send_real_async_wait( $gdb, "-target-attach $pid" ); + my %p = _gdb_send_real_async_wait( $gdb, "attach $pid" ); if ( not defined $p{status} ) { $gdb->{error} = 'Failed to attach to process'; From padb at googlecode.com Wed Mar 30 20:49:00 2011 From: padb at googlecode.com (padb at googlecode.com) Date: Wed, 30 Mar 2011 19:49:00 +0000 Subject: [padb] r434 committed - Attempt to use the new -stack-list-variables MI command and if that... Message-ID: <0016367b6fb6d9dd1f049fb877f8@google.com> Revision: 434 Author: apittman at gmail.com Date: Wed Mar 30 12:48:12 2011 Log: Attempt to use the new -stack-list-variables MI command and if that doesn't work revert back to the deprecated -stack-list-locals http://code.google.com/p/padb/source/detail?r=434 Modified: /trunk/src/padb ======================================= --- /trunk/src/padb Wed Mar 30 11:49:32 2011 +++ /trunk/src/padb Wed Mar 30 12:48:12 2011 @@ -7806,12 +7806,33 @@ $arg->{value} = $value; } } + + return; +} + +# As gdb_expand_vars but takes $vars as provided by gdb and populates the two +# arrays from that. +sub gdb_expand_vars_raw { + my ( $gdb, $frame, $vars ) = @_; + + foreach my $arg ( @{$vars} ) { + + my $value = gdb_expand_var( $gdb, $arg ); + if ( defined $arg->{arg} ) { + push @{ $frame->{'params'} }, $arg; + } else { + push @{ $frame->{'locals'} }, $arg; + } + if ( defined $value ) { + $arg->{value} = $value; + } + } return; } sub gdb_dump_frames { - my ( $gdb, $detail ) = @_; + my ( $gdb, $detail, $thread ) = @_; my %result = gdb_n_send( $gdb, '-stack-list-frames' ); my $data = gdb_parse_reason( $result{reason}, 'frame' ); if ( not defined $data->{stack} ) { @@ -7819,6 +7840,19 @@ } if ( defined $detail ) { foreach my $frame ( @{ $data->{stack} } ) { + + # Try the new way first, and if that works then great, if not then + # revert back to the old method. + + my %all_vars = gdb_send_addr( $gdb, +"-stack-list-variables --thread $thread --frame $frame->{level} 2" + ); + if ( $all_vars{status} eq 'done' ) { + my $args = gdb_parse_reason( $all_vars{reason} ); + gdb_expand_vars_raw( $gdb, $frame, $args->{variables} ); + next; + } + gdb_send( $gdb, "-stack-select-frame $frame->{level}" ); my %r = gdb_send_addr( $gdb, @@ -7863,7 +7897,7 @@ # code here however. if ( $data->{'number-of-threads'} == 0 ) { my %t = ( id => 0 ); - @{ $t{frames} } = gdb_dump_frames( $gdb, $detail ); + @{ $t{frames} } = gdb_dump_frames( $gdb, $detail, 0 ); push @th, \%t; return @th; } @@ -7888,7 +7922,7 @@ if ( $data->{'number-of-threads'} != 1 ) { gdb_send( $gdb, "-thread-select $id" ); } - @{ $t{frames} } = gdb_dump_frames( $gdb, $detail ); + @{ $t{frames} } = gdb_dump_frames( $gdb, $detail, $t{id} ); push @th, \%t; } return @th; From padb at googlecode.com Wed Mar 30 21:13:14 2011 From: padb at googlecode.com (padb at googlecode.com) Date: Wed, 30 Mar 2011 20:13:14 +0000 Subject: [padb] r435 committed - When attaching to a process try the correct -target-attach first... Message-ID: <0015175cdbdc81afca049fb8ce98@google.com> Revision: 435 Author: apittman at gmail.com Date: Wed Mar 30 13:12:35 2011 Log: When attaching to a process try the correct -target-attach first and if that does not work back off to plain attach. http://code.google.com/p/padb/source/detail?r=435 Modified: /trunk/src/padb ======================================= --- /trunk/src/padb Wed Mar 30 12:48:12 2011 +++ /trunk/src/padb Wed Mar 30 13:12:35 2011 @@ -6177,7 +6177,11 @@ } send_cont_signal($pid); - my %p = gdb_n_send( $gdb, "attach $pid" ); + my %p = gdb_n_send( $gdb, "-target-attach $pid" ); + + if ( not defined $p{status} or $p{status} eq 'error' ) { + %p = gdb_n_send( $gdb, "attach $pid" ); + } if ( not defined $p{status} ) { $gdb->{error} = 'Failed to attach to process'; @@ -6249,7 +6253,7 @@ send_cont_signal($pid); - _gdb_send_real_async_start( $gdb, "attach $pid" ); + _gdb_send_real_async_start( $gdb, "-target-attach $pid" ); return; } @@ -6257,8 +6261,11 @@ sub gdb_attach_async_end { my ( $gdb, $pid ) = @_; - my %p = _gdb_send_real_async_wait( $gdb, "attach $pid" ); - + my %p = _gdb_send_real_async_wait( $gdb, "-target-attach $pid" ); + + if ( not defined $p{status} or $p{status} eq 'error' ) { + %p = gdb_n_send( $gdb, "attach $pid" ); + } if ( not defined $p{status} ) { $gdb->{error} = 'Failed to attach to process'; if ( not find_exe('gdb') ) { From padb at googlecode.com Wed Mar 30 23:11:42 2011 From: padb at googlecode.com (padb at googlecode.com) Date: Wed, 30 Mar 2011 22:11:42 +0000 Subject: [padb] r436 committed - Initial support for using idb over gdb as a backend debugger.... Message-ID: <20cf300faf753106be049fba7605@google.com> Revision: 436 Author: apittman at gmail.com Date: Wed Mar 30 15:10:37 2011 Log: Initial support for using idb over gdb as a backend debugger. Enable this with the -Obackend-debugger=idb option, this is not ready for widespread use however as the mi interface to idb is flaky and in some places completely different from that of gdb. In particular this doesn't work for MPI queues, only shows one thread per program and doesn't show variables or paramaters for any functions. Basically right now all it shows is function names in stack traces. http://code.google.com/p/padb/source/detail?r=436 Modified: /trunk/src/padb ======================================= --- /trunk/src/padb Wed Mar 30 13:12:35 2011 +++ /trunk/src/padb Wed Mar 30 15:10:37 2011 @@ -407,7 +407,7 @@ # Config options the inner knows about, only forward options if they are in # this list. my @inner_conf = - qw(edb edbopt rmgr scripts slurm_job_step pbs_server lsf_mode lsfmpi_server lsfmpi_mpirpid lsfmpi_port); + qw(edb edbopt rmgr scripts slurm_job_step pbs_server lsf_mode lsfmpi_server lsfmpi_mpirpid lsfmpi_port backend_debugger); # More options the inner knows about, these are forwarded on the # command line rather than over the sockets. @@ -601,6 +601,9 @@ $conf{pbs_server} = undef; +# Backend debugger to use, can be either idb or gdb. +$conf{backend_debugger} = 'gdb'; + # These settings are passed onto inner only. $conf{edbopt} = undef; @@ -6125,6 +6128,9 @@ }; my $cmd = 'gdb --interpreter=mi -q'; + if ( $inner_conf{backend_debugger} eq 'idb' ) { + $cmd = 'idb --interpreter=mi2 -q'; + } if ( defined $core ) { $cmd .= " $exe $core"; } @@ -6234,8 +6240,10 @@ $gdb->{runtime}{mpich2} = 1; } - gdb_n_send( $gdb, '-gdb-set print address off' ); - gdb_n_send( $gdb, '-gdb-set language auto' ); + if ( $inner_conf{backend_debugger} ne 'idb' ) { + gdb_n_send( $gdb, '-gdb-set print address off' ); + gdb_n_send( $gdb, '-gdb-set language auto' ); + } return; } @@ -6263,6 +6271,10 @@ my %p = _gdb_send_real_async_wait( $gdb, "-target-attach $pid" ); + if ( $inner_conf{backend_debugger} eq 'idb' ) { + gdb_attach_post( $gdb, $pid ); + return $pid; + } if ( not defined $p{status} or $p{status} eq 'error' ) { %p = gdb_n_send( $gdb, "attach $pid" ); } @@ -6302,7 +6314,7 @@ my ($gdb) = @_; my $result = gdb_send( $gdb, '-target-detach' ); - return if ( $result eq 'error' ); + return if ( not defined $result or $result eq 'error' ); $gdb->{attached} = 0; @@ -6334,7 +6346,10 @@ print { $gdb->{debugfd} } "$seq$cmd\n"; } my %r = gdb_n_next_result( $gdb, $seq ); - if ( $gdb->{attached} and $r{seq} ne $seq ) { + if ( $inner_conf{backend_debugger} ne 'idb' + and $gdb->{attached} + and $r{seq} ne $seq ) + { croak( "Invalid sequence number from gdb, expecting $seq got $r{seq} cmd=\"$cmd\"" ); @@ -6361,6 +6376,9 @@ sub _gdb_send_real_async_wait { my ( $gdb, $cmd ) = @_; my $seq = $gdb->{seq}; + if ( $inner_conf{backend_debugger} eq 'idb' ) { + return; + } my %r = gdb_n_next_result( $gdb, $seq ); if ( $gdb->{attached} and $r{seq} ne $seq ) { croak( @@ -6380,6 +6398,10 @@ if ( $flag == $gdb->{pa} ) { return; } + + if ( $inner_conf{backend_debugger} eq 'idb' ) { + return; + } $gdb->{pa} = $flag; @@ -6397,6 +6419,10 @@ if ( $lang eq $gdb->{lang} ) { return; } + + if ( $inner_conf{backend_debugger} eq 'idb' ) { + return; + } $gdb->{lang} = $lang; @@ -6734,6 +6760,12 @@ # $res{debug} =~ s/\\n/\n/g; # chomp $res{debug}; #} + + # As idb doesn't confirm that it's attached properly it's impossible + # to do this test correctly here. + if ( $inner_conf{backend_debugger} eq 'idb' ) { + return %res; + } if ( $gdb->{attached} ) { croak("Unexpected EOF from gdb"); @@ -7862,8 +7894,13 @@ gdb_send( $gdb, "-stack-select-frame $frame->{level}" ); + my $print_cmd = '2'; + if ( $inner_conf{backend_debugger} eq 'idb' ) { + $print_cmd = '1'; + } my %r = gdb_send_addr( $gdb, - "-stack-list-arguments 2 $frame->{level} $frame->{level}" ); +"-stack-list-arguments $print_cmd $frame->{level} $frame->{level}" + ); my $args = gdb_parse_reason( $r{reason} ); if ( defined $args->{'stack-args'}[0]{frame}{args} ) { @@ -7873,7 +7910,7 @@ gdb_expand_vars( $gdb, $frame, 'params' ); } - my %s = gdb_n_send( $gdb, '-stack-list-locals --simple-values' ); + my %s = gdb_n_send( $gdb, '-stack-list-locals 2' ); if ( $s{status} eq 'done' ) { my $flocals = gdb_parse_reason( $s{reason} ); if ( defined $flocals->{locals} ) {