1package gdb; 2 3use strict; 4use shell; 5 6require Vile::Exporter; 7 8use vars qw(@ISA %REGISTRY); 9 10@ISA = 'Vile::Exporter'; 11%REGISTRY = ( 12 'gdb' => [ \&gdb_session, 'start or rejoin an interactive gdb session' ], 13 'gdb-break' => [ \&gdb_break, 'set a breakpoint in gdb' ], 14 'gdb-step' => [ \&gdb_step, 'single step in gdb' ], 15 'gdb-next' => [ \&gdb_next, 'next in gdb' ], 16 'gdb-cont' => [ \&gdb_cont, 'continue in gdb' ], 17); 18 19{ 20 my $gdbid; 21 my $old_gdb_cmd = "gdb --fullname "; 22 23 sub find_gdb_session { 24 return $gdbid if !shell::dead($gdbid); 25 for ( my $i = 0 ; my $w = Vile::window_at($i) ; $i++ ) { 26 if ( !shell::dead( shell::buffer_name_internal( $w->buffer ) ) ) { 27 my $buffername = $w->buffer->buffername; 28 print "Join $buffername as a gdb session? "; 29 my $c = Vile::keystroke; 30 if ( $c == ord('y') || $c == ord('Y') ) { 31 $gdbid = shell::buffer_name_internal( $w->buffer ); 32 return $gdbid; 33 } 34 } 35 } 36 my $gdb_cmd = Vile::mlreply_shell( "gdb command line: ", $old_gdb_cmd ); 37 return undef if !defined($gdb_cmd); 38 if ( $gdb_cmd !~ /\s--fullname\b/ ) { 39 print "``--fullname'' option missing. Shall I add it? "; 40 my $c = Vile::keystroke; 41 if ( $c == ord('y') || $c == ord('Y') ) { 42 $gdb_cmd =~ s/^(\s*\S+)(.*)$/$1 --fullname$2/; 43 } 44 } 45 $old_gdb_cmd = $gdb_cmd; 46 $gdbid = shell::shell($gdb_cmd); 47 } 48} 49 50sub gdb_session { 51 my $gdbid = find_gdb_session() or return; 52 my $curwin = Vile::current_window; 53 shell::resume_shell($gdbid); 54 $curwin->current_window; 55} 56 57sub gdb_break { 58 my $b = Vile::current_buffer; 59 my $filename = $b->filename; 60 $filename =~ s#.*/##; # Better chance of working with 61 # just the filename. 62 my $lineno = $b->dotq; 63 my $gdbid = find_gdb_session() or return; 64 shell::send_chars( $gdbid, "break $filename:$lineno\n" ); 65} 66 67sub gdb_step { 68 my $gdbid = find_gdb_session() or return; 69 shell::send_chars( $gdbid, "step\n" ); 70} 71 72sub gdb_next { 73 my $gdbid = find_gdb_session() or return; 74 shell::send_chars( $gdbid, "next\n" ); 75} 76 77sub gdb_cont { 78 my $gdbid = find_gdb_session() or return; 79 shell::send_chars( $gdbid, "continue\n" ); 80} 81 82sub gdb_interrupt { 83 my $gdbid = find_gdb_session() or return; 84 shell::send_chars( $gdbid, "\003" ); 85} 86 871; 88 89__DATA__ 90 91=head1 NAME 92 93gdb - run gdb in a vile window 94 95=head1 SYNOPSIS 96 97In .vilerc: 98 99 perl "use gdb" 100 101In [x]vile: 102 103 :gdb 104 :gdb-break 105 :gdb-step 106 :gdb-next 107 :gdb-cont 108 109=head1 DESCRIPTION 110 111The B<gdb> module runs C<gdb> in a vile window and tracks changes in the editor. 112This must be used with the C<shell.pm> module. 113 114=head2 gdb 115 116Start or rejoin an interactive gdb session. 117 118=head2 gdb-break 119 120Set a breakpoint in gdb. 121 122=head2 gdb-step 123 124Single step in gdb. 125 126=head2 gdb-next 127 128Next in gdb. 129 130=head2 gdb-cont 131 132Continue in gdb. 133 134=head1 AUTHOR 135 136Kevin Buettner 137 138=cut 139