Skip to content
/ calltrace Public

calltrace is a gdb plugin to track flow of function calls and returns in a style similar to DTrace flowindent, but with an output that can be manipulated using (emacs) orgmode.

License

Notifications You must be signed in to change notification settings

bx/calltrace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

calltrace is a gdb plugin to track flow of function calls and returns in a style similar to DTrace flowindent, but with an output that can be manipulated using (emacs) orgmode. It requires gdb with python2, and an unstripped executable (with symbol information).


USAGE
> gdb -ex 'python execfile("<path/to/calltrace.py>")' <path/to/executable>

to save output to a file:
(gdb) calltrace log <path/to/logfile.org>

to tell calltrace to print source code path/line number information:
(gdb) calltrace sourceinfo

to tell calltrace not to print return addresses or source code information
(gdb) calltrace minimal

to execute:
(gdb) r <your arguments>
OR
(gdb) calltrace

Results are printed in a way so they can be easily manipulated via emacs orgmode.


EXAMPLE

Suppose you have build an executable called hello from the following source:
"""
#include <stdio.h>

void say_hello() {
  printf("hello, world!\n");
}

int main() {
  say_hello();
  return 0;
}
"""

You can then get the call trace via:
> gdb -ex 'python execfile("path/to/calltrace.py")' hello
GNU gdb 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from hello...(no debugging symbols found)...done.
found FUNC deregister_tm_clones at 0000000000400460
found FUNC register_tm_clones at 00000000004004a0
found FUNC __do_global_dtors_aux at 00000000004004e0
found FUNC frame_dummy at 0000000000400500
found FUNC __libc_csu_fini at 00000000004005c0
found FUNC _fini at 00000000004005c4
found FUNC __libc_csu_init at 0000000000400550
found FUNC _start at 0000000000400430
found FUNC main at 0000000000400537
found FUNC say_hello at 0000000000400526
found FUNC _init at 00000000004003c8
(gdb) calltrace log out.org
setting log to out.org
(gdb) r
Starting program: hello
Cannot set FinishBreakpoint for _start
Cannot set FinishBreakpoint for main
hello, world!
[Inferior 1 (process 1915) exited normally]
Execution finished, exit code 0.
results written to out.org
(gdb) q
> cat out.org # out.org contains:
* > _init
* < _init@0x7ffff7de74aa
* > _start
** > __libc_csu_init
*** > _init
*** < _init@0x400581
*** > frame_dummy
**** > register_tm_clones
**** < frame_dummy@0x40059d
*** < register_tm_clones@0x40059d
** < __libc_csu_init@0x7ffff7a2e7bf
** > main
*** > say_hello
*** < say_hello@0x400545
*** > __do_global_dtors_aux
**** > deregister_tm_clones
**** < deregister_tm_clones@0x4004f2
*** < __do_global_dtors_aux@0x7ffff7de7c17
*** > _fini
*** < _fini@0x7ffff7de7c35


EMACS SUPPORT

You can view the script's output with any text editor, but it is best viewed with emacs org-mode and the calltrace.el elisp file loaded.

calltrace.el provides functions to help you better understand the call
trace output by hiding duplicate adjacent function calls. It does not
(yet) check to see that the subcalls of any two matching adjacent
function calls have the same structure, but it should not be hard to
add that feature.

To hide and merge matching adjacent function calls (note: this may take a while and emacs may appear to freeze while it is running):
M-x ct-collapse-dups-until-none

Matching adjacent function calls are marked with an ARCHIVE tag in
order to harness org-mode's automatic hiding of subtrees of nodes
marked with the tag ARCHIVE.  You can save the file so you don't have
to run any tagging stripts in the future.  Emacs will not remember the
visibility state of everything in future sessions, but you can execute
the expression (ct-collapse-dups-until-none t) in order to instruct
emacs to more thoroughly hide duplicate adjacent function calls.

M-: (ct-collapse-dups-until-none t) [Enter]


If you wish to remove all of the ARCHIVE tags:
M-x (ct-remove-all-hide-tags)

Hidden headlines are collapsed into a {hidden} tag. You can use the tab key to toggle visibility and C+tab to toggle visibility of ARCHIVe subtrees.

These scripts try not to mess with any extra notes or annotations you have added to the file (beside ARCHIVE tags), but this claim has yet to be tested.

Enjoy at your own risk!

About

calltrace is a gdb plugin to track flow of function calls and returns in a style similar to DTrace flowindent, but with an output that can be manipulated using (emacs) orgmode.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published