| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Devel::DebugInit::GDB; |
|
2
|
1
|
|
|
1
|
|
1377
|
use Devel::DebugInit; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require Exporter; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
@Devel::DebugInit::GDB::ISA = (Exporter, Devel::DebugInit); |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use strict; |
|
8
|
|
|
|
|
|
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
|
11
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
|
12
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
|
13
|
|
|
|
|
|
|
@EXPORT = qw( |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
); |
|
16
|
|
|
|
|
|
|
$VERSION = '0.1'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Devel::DebugInit::GDB - Perl extension for creating .gdbinit file from |
|
21
|
|
|
|
|
|
|
C header file macros |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use Devel::DebugInit::GDB; |
|
26
|
|
|
|
|
|
|
use Config; |
|
27
|
|
|
|
|
|
|
my $g = new Devel::DebugInit::GDB "filename => $Config{'archlib'}/CORE/perl.h"; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$g->write("~/perl5.00403/.gdbinit"); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
This module is a backend for the GNU debugger, gdb, that is used |
|
34
|
|
|
|
|
|
|
together with the generic Devel::DebugInit front end to produce an |
|
35
|
|
|
|
|
|
|
initialization file for gdb. This module provides the output routines |
|
36
|
|
|
|
|
|
|
that are specific for gdb. See L for more information. |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Preloaded methods go here. |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 METHODS |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 write() |
|
45
|
|
|
|
|
|
|
=head2 write($filename) |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
This method outputs the macros to $filename, which defaults to |
|
48
|
|
|
|
|
|
|
"./gdbinit". It first writes out any macros without arguments (if |
|
49
|
|
|
|
|
|
|
enabled, see L for more info), and |
|
50
|
|
|
|
|
|
|
then it writes any macros with arguments. |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub write { |
|
55
|
|
|
|
|
|
|
my ($gdb,$outfile) = @_; |
|
56
|
|
|
|
|
|
|
my ($key,$defines,$file); |
|
57
|
|
|
|
|
|
|
$outfile = ".gdbinit" unless defined $outfile; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
open(INIT, ">$outfile") or die "Couldn't open $outfile for output"; |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $time = scalar gmtime; |
|
62
|
|
|
|
|
|
|
print INIT "# This file auto generated by GDBinit v$VERSION, ", $time, "\n"; |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
foreach $file (@{$gdb}) { |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# first print out the simple macros (ones without arguments) |
|
67
|
|
|
|
|
|
|
$defines = $file->get_no_args(); |
|
68
|
|
|
|
|
|
|
if (defined $defines) { |
|
69
|
|
|
|
|
|
|
print INIT "# macros with no arguments\n\n"; |
|
70
|
|
|
|
|
|
|
# sort keys to print them in alphabetical order |
|
71
|
|
|
|
|
|
|
foreach $key (sort keys %{$defines}) { |
|
72
|
|
|
|
|
|
|
my $macro = $defines->{$key}; |
|
73
|
|
|
|
|
|
|
# The follow lines filter what to print |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# don't print bad macros |
|
76
|
|
|
|
|
|
|
next unless $gdb->scan($key,$macro); |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#don't print symbol renames, e.g. #define sv_grow Perl_sv_grow |
|
79
|
|
|
|
|
|
|
if ($macro =~ /^\s*\w+\s*$/) { |
|
80
|
|
|
|
|
|
|
# it's just a single token, skip it if it's not a number |
|
81
|
|
|
|
|
|
|
next unless $macro =~ /^\s*\d+\s*$/ || $macro =~ /^\s*0x\d+\s*$/; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# print the rest |
|
85
|
|
|
|
|
|
|
print INIT "define $key\n"; |
|
86
|
|
|
|
|
|
|
print INIT " print $macro\n"; |
|
87
|
|
|
|
|
|
|
print INIT "end\n\n"; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# then print out the macros with arguments |
|
92
|
|
|
|
|
|
|
$defines = $file->get_args(); |
|
93
|
|
|
|
|
|
|
if (defined $defines) { |
|
94
|
|
|
|
|
|
|
print INIT "\n\n# macros with arguments\n\n"; |
|
95
|
|
|
|
|
|
|
# sort keys to print them in alphabetical order |
|
96
|
|
|
|
|
|
|
foreach $key (sort keys %{$defines}) { |
|
97
|
|
|
|
|
|
|
my $args = $defines->{$key}->[0]; # first slot is the arg list |
|
98
|
|
|
|
|
|
|
my $macro = $defines->{$key}->[1]; # second slot is the macro |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# don't print bad macros |
|
101
|
|
|
|
|
|
|
next unless $gdb->scan($key,$macro); |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# substitue $arg0, $arg1, etc for the arguments to the macro |
|
104
|
|
|
|
|
|
|
my $print_arg = 0; |
|
105
|
|
|
|
|
|
|
foreach my $arg (@{$args}) { |
|
106
|
|
|
|
|
|
|
$macro =~ s/\b$arg\b/\$arg$print_arg/g; |
|
107
|
|
|
|
|
|
|
$print_arg++; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# print 'em out... |
|
111
|
|
|
|
|
|
|
print INIT "define $key\n"; |
|
112
|
|
|
|
|
|
|
print INIT " print $macro\n"; |
|
113
|
|
|
|
|
|
|
print INIT "end\n\n"; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
close(INIT); |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 scan($name,$macro) |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This is used by the print function to determine if $macro should be |
|
123
|
|
|
|
|
|
|
printed or not. It returns 0 if the macro should NOT be |
|
124
|
|
|
|
|
|
|
printed. Currently, the method rejects undefined macros (this is |
|
125
|
|
|
|
|
|
|
possible if the user specified printing of local macros only), empty |
|
126
|
|
|
|
|
|
|
macros (typical compiler flags like -DDEBUG, or #define linux), macros |
|
127
|
|
|
|
|
|
|
whose names begin with '_', as well as any macro whose name is a |
|
128
|
|
|
|
|
|
|
built-in GDB command. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This function can be overloaded by the user to more rigidly restrict |
|
131
|
|
|
|
|
|
|
the output of print. For example: |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
package myGDB; |
|
134
|
|
|
|
|
|
|
use Devel::DebugInit::GDB; |
|
135
|
|
|
|
|
|
|
@myGDB::ISA = (Devel::DebugInit::GDB); |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub scan { |
|
138
|
|
|
|
|
|
|
my ($gdb,$key,$macro) = @_; |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
#first give the superclass scan a chance |
|
141
|
|
|
|
|
|
|
return 0 unless $gdb->SUPER::scan(@_); |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# dont' print out any macros beginning with 'rfsf_' |
|
144
|
|
|
|
|
|
|
return 0 if $macro =~ /^rfsf_/; |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# print the rest |
|
147
|
|
|
|
|
|
|
return 1; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub scan { |
|
153
|
|
|
|
|
|
|
my ($gdb,$key,$macro) = @_; |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# if the user is printing only the local macros, it is possible for |
|
156
|
|
|
|
|
|
|
# some to be undefined. |
|
157
|
|
|
|
|
|
|
return 0 unless defined $macro; |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# don't print flags, e.g. #define VMS |
|
160
|
|
|
|
|
|
|
return 0 if $macro eq ""; |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# get ready to do some regexp'ing on $key |
|
163
|
|
|
|
|
|
|
study $key; |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# don't print macros with names that begin with '_' |
|
166
|
|
|
|
|
|
|
return 0 if $key =~ /^_/; |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# don't redefine any builtin GDB commands |
|
169
|
|
|
|
|
|
|
return 0 if $key =~ /\b |
|
170
|
|
|
|
|
|
|
(kill| |
|
171
|
|
|
|
|
|
|
target| |
|
172
|
|
|
|
|
|
|
handle| |
|
173
|
|
|
|
|
|
|
run| |
|
174
|
|
|
|
|
|
|
jump| |
|
175
|
|
|
|
|
|
|
step| |
|
176
|
|
|
|
|
|
|
next| |
|
177
|
|
|
|
|
|
|
finish| |
|
178
|
|
|
|
|
|
|
nexti| |
|
179
|
|
|
|
|
|
|
stepi| |
|
180
|
|
|
|
|
|
|
continue| |
|
181
|
|
|
|
|
|
|
signal| |
|
182
|
|
|
|
|
|
|
detach| |
|
183
|
|
|
|
|
|
|
attach| |
|
184
|
|
|
|
|
|
|
unset| |
|
185
|
|
|
|
|
|
|
tty| |
|
186
|
|
|
|
|
|
|
thread| |
|
187
|
|
|
|
|
|
|
apply| |
|
188
|
|
|
|
|
|
|
bt| |
|
189
|
|
|
|
|
|
|
backtrace| |
|
190
|
|
|
|
|
|
|
select\-frame| |
|
191
|
|
|
|
|
|
|
frame| |
|
192
|
|
|
|
|
|
|
down| |
|
193
|
|
|
|
|
|
|
up| |
|
194
|
|
|
|
|
|
|
return| |
|
195
|
|
|
|
|
|
|
whatis| |
|
196
|
|
|
|
|
|
|
ptype| |
|
197
|
|
|
|
|
|
|
inspect| |
|
198
|
|
|
|
|
|
|
print| |
|
199
|
|
|
|
|
|
|
call| |
|
200
|
|
|
|
|
|
|
set| |
|
201
|
|
|
|
|
|
|
output| |
|
202
|
|
|
|
|
|
|
printf| |
|
203
|
|
|
|
|
|
|
display| |
|
204
|
|
|
|
|
|
|
undisplay| |
|
205
|
|
|
|
|
|
|
disassemble| |
|
206
|
|
|
|
|
|
|
x| |
|
207
|
|
|
|
|
|
|
delete| |
|
208
|
|
|
|
|
|
|
disable| |
|
209
|
|
|
|
|
|
|
enable| |
|
210
|
|
|
|
|
|
|
awatch| |
|
211
|
|
|
|
|
|
|
rwatch| |
|
212
|
|
|
|
|
|
|
watch| |
|
213
|
|
|
|
|
|
|
catch| |
|
214
|
|
|
|
|
|
|
break| |
|
215
|
|
|
|
|
|
|
clear| |
|
216
|
|
|
|
|
|
|
thbreak| |
|
217
|
|
|
|
|
|
|
hbreak| |
|
218
|
|
|
|
|
|
|
tbreak| |
|
219
|
|
|
|
|
|
|
condition| |
|
220
|
|
|
|
|
|
|
commands| |
|
221
|
|
|
|
|
|
|
ignore| |
|
222
|
|
|
|
|
|
|
cd| |
|
223
|
|
|
|
|
|
|
pwd| |
|
224
|
|
|
|
|
|
|
core\-file| |
|
225
|
|
|
|
|
|
|
section| |
|
226
|
|
|
|
|
|
|
exec\-file| |
|
227
|
|
|
|
|
|
|
file| |
|
228
|
|
|
|
|
|
|
sharedlibrary| |
|
229
|
|
|
|
|
|
|
path| |
|
230
|
|
|
|
|
|
|
load| |
|
231
|
|
|
|
|
|
|
symbol\-file| |
|
232
|
|
|
|
|
|
|
list| |
|
233
|
|
|
|
|
|
|
reversed\-search| |
|
234
|
|
|
|
|
|
|
search| |
|
235
|
|
|
|
|
|
|
forward\-search| |
|
236
|
|
|
|
|
|
|
directory| |
|
237
|
|
|
|
|
|
|
show| |
|
238
|
|
|
|
|
|
|
info| |
|
239
|
|
|
|
|
|
|
up\-silently| |
|
240
|
|
|
|
|
|
|
down\-silently| |
|
241
|
|
|
|
|
|
|
define| |
|
242
|
|
|
|
|
|
|
ni| |
|
243
|
|
|
|
|
|
|
si| |
|
244
|
|
|
|
|
|
|
where| |
|
245
|
|
|
|
|
|
|
complete| |
|
246
|
|
|
|
|
|
|
remote| |
|
247
|
|
|
|
|
|
|
maintenance)\b/ix; |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
# Looks OK |
|
250
|
|
|
|
|
|
|
return 1; |
|
251
|
|
|
|
|
|
|
} |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
1; |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
__END__ |