Reputation: 523
Is there a cleaner (preferably gdb only) way to do the following (Setting breakpoints on every line in the code where a certain pattern appears),
grep ~/work/proj some_var_or_pattern -Irni| cut –f1,2 –d":" | sed –e 's/^/b /' > ~/moo.txt
and load the results with
(gdb) source ~/moo.txt
Upvotes: 2
Views: 216
Reputation: 10271
gdb doesn't do that by itself, but you can put your grep and break command generating code into a shell script and call it from gdb with a single command.
Put this in a file in your $PATH as, say, greptobp
:
#!/bin/sh
# usage: greptobp pattern dir outputfile
pattern="$1"
dir="$2"
outputfile="$3"
if [ "${dir#/}" = "$dir" ]
then
# if dir isn't absolute, make it absolute, as requested by OP
dir="$PWD/$dir"
fi
grep -HIirn "$pattern" "$dir" |
awk -F: '{ print "break \"" $1 "\":" $2; }' > "$outputfile"
and add this to gdb:
(gdb) define patbreak
Type commands for definition of "patbreak".
End with a line saying just "end".
>shell greptobp $arg0 $arg1 /tmp/gdbtmp
>source /tmp/gdbtmp
>shell rm /tmp/gdbtmp
>end
(gdb) document patbreak
Type documentation for "patbreak".
End with a line saying just "end".
>Set breakpoints at lines matching specified pattern in a specified directory.
>Usage: patbreak pattern dir
>end
Upvotes: 1
Reputation: 5685
Unfortunately there is no build in command for setting breakpoints on all lines matching certain pattern. But there are build in commands for seting breakpoints on all functions matching the regular expressions:
rbreak regex
and rbreak file:regex
(short tutorial).
Upvotes: 2