Backtrace trees
I did a hack the other day I thought came out well. I had a large program, and I wanted to know the call tree for those function that used the low-level I/O routines.
The call trees generated by Doxygen were kind of useless, because they had too much detail and couldn't tell you which call paths are the normal paths. I really just wanted to know the call trees of those functions called the low-level I/O routines when the program was run on typical input data.
So, GDB will allow you to load a file of commands using the "-x" option. I wrote a command file that set up some breakpoints and requested backtraces for those breakpoints. I also added commands so that GDB ran non-interactively. I captured the backtraces in a typescript. The command file looked something like this.
##################
set pagination off
set breakpoint pending on
## Print call tree when "open" is called
break open
command
bt 10
cont
end
run
quit
##################
The first line keeps GDB from running its "more" command. The second line tells GDB not to worry if the functions I'm trying to break on aren't loaded yet. The middle section between "break" and "end" tells GDB to print a backtrace 10 levels deep when "open" is called. I end up with a file that contains a lot of GDB backtraces.
In the above I only showed the "open" command, but, I added similar backtrace requests for open, close, read, lseek, and write.
From there I coerced the output from the run into a graphviz-friendly file with a little bit of awk. Text that looked like this
#1 0x12345678 in foo (...
#2 0x12345678 in bar (...
#3 0x12345678 in baz (...
became this
bar -> for
baz -> bar
Using a simple awk script like this
###################
BEGIN { parent = ""; child = ""; }
{
child = parent;
if ($1 == "#0") {
if ($3 == "in") parent = $4; else parent = $2;
} else if (match($1, /\#[0-9]/) != 0) {
if ($3 == "in") parent = $4; else parent = $2;
print parent " -> " child;
}
}
#############
Yeah I know, you could have done it in perl in 18 characters. So what.
I finished off making my graphviz file with a bit of shell. This generated the correct Graphviz file as "test.gv" and then created the plot as "test.png".
#############
echo "digraph call {" > test.gv
echo "node [rank=sink, shape=box]; open close read write lseek __libc_open64;" >> test.gv
echo "{rank=sink; open close read write lseek __libc_open64;}" >> test.gv
echo "node [shape=ellipse];" >> test.gv
cat test.out | awk -f split.awk | sort | uniq >> test.gv
echo "}" >> test.gv
dot -Tpng test.gv -o test.png
#############
And that got me my result.

5 Comments:
bad side effects of viagra cialis v s viagra buy viagra in london england generic soft tab viagra viagra facts cheapest uk supplier viagra cheapest viagra prices cialis vs viagra buy viagra soft online mexican viagra viagra commercial canyon filmed pfizer viagra how to buy viagra viagra substitute
[color=#488][url=http://kunstkamera.grusla.com]grundik+slava[/url]: one more mantra on the order of...[/color]
[URL=http://www.radikal.ru][IMG]http://i064.radikal.ru/1001/8b/0f61bce16f42.jpg[/IMG][/URL]
Исполнитель: Melodium
Альбом: Cerebro Spin
Год выхода: 2008
Жанр: Electronic Experimental
Кол-во треков:11
Формат|Качество: FLAC
Продолжительность: 50.42
Размер:266 Mb
Tреклист:
1. Choanal Imperforation (6:33)
2. Eustachian Tube (5:52)
3. Not Yet 1 (1:56)
4. Kissing Disease (4:17)
5. Meniere's Vertigo (5:45)
6. Not Yet 2 (2:07)
7. Social Phobia (7:14)
8. Vocal Cord Polypus (5:54)
9. Not Yet 3 (1:36)
10. Panic Disorder (3:54)
11. Scoliosis + Astigmatism (5:31)
Скачать
http://rapidshare.com/files/334301395/melodium_-_2008_-_cerebro_spin.part1.rar.html
http://rapidshare.com/files/334324976/melodium_-_2008_-_cerebro_spin.part2.rar.html
http://rapidshare.com/files/334342115/melodium_-_2008_-_cerebro_spin.part3.rar.html
I just discovered the website who writes about
many
home business reviews
If you want to know more here it is
home based business opportunity
www.home-businessreviews.com
Today is my lucky day :)
Apple is giving review copies of iPad to 100 lucky person. Go to http://bit.ly/cmmVr7 and apply for it.
Post a Comment
Links to this post:
Create a Link
<< Home