callgraph

runtime callgraph generator
git clone git://git.2f30.org/callgraph.git
Log | Files | Refs | README

commit 0387a0f15d12374ad70a18db01594a835345fd47
parent cfa67f131264dad5f192ef5092660eb9dd078286
Author: lostd <lostd@2f30.org>
Date:   Thu Nov 14 22:58:35 +0200

Use callgraph.dot by default, CGRAPH_OUT otherwise

Diffstat:
README | 7++++++-
libcallgraph.c | 7++++++-
symbolize.sh | 3++-
3 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/README b/README @@ -18,8 +18,13 @@ to be in the library path. LD_LIBRARY_PATH=$PWD ./prog [ARGS] +This generates a callgraph.dot file by default. If you want another +output filename just set the CGRAPH_OUT environment variable. + + CGRAPH_OUT=prog.dot + Once the program terminates, you may want to replace addresses in the -generated callgraph.dot file with function names, using the symbolizer. +generated .dot file with function names, using the symbolizer. ./symbolize.sh ./prog diff --git a/libcallgraph.c b/libcallgraph.c @@ -65,7 +65,12 @@ writelog(int fildes, const void *buf, size_t nbyte) __attribute__ ((constructor)) static void init_logging(void) { - fd = open("callgraph.dot", O_WRONLY | O_CREAT | O_EXCL, 0644); + char *f; + + f = getenv("CGRAPH_OUT"); + if (f == NULL) + f = "callgraph.dot"; + fd = open(f, O_WRONLY | O_CREAT | O_EXCL, 0644); if (fd == -1) { perror("cgraph"); _Exit(EXIT_FAILURE); diff --git a/symbolize.sh b/symbolize.sh @@ -7,7 +7,8 @@ if [ ! -n "$1" ]; then exit 1 fi -CGRAPH_OUT=callgraph.dot +CGRAPH_OUT=$(test -n "$CGRAPH_OUT" && echo $CGRAPH_OUT || \ + echo callgraph.dot) if [ ! -f "$CGRAPH_OUT" ]; then echo "$CGRAPH_OUT does not exist!" 1>&2