callgraph

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

commit cfa67f131264dad5f192ef5092660eb9dd078286
parent 6eedc7c9a0c90735f0edfb1092b731bff5ccfe3d
Author: lostd <lostd@2f30.org>
Date:   Thu, 14 Nov 2013 22:35:29 +0200

Use a fixed callgraph.dot output file and don't overwrite it

Diffstat:
MREADME | 7++-----
Mlibcallgraph.c | 12++----------
Msymbolize.sh | 7++++---
3 files changed, 8 insertions(+), 18 deletions(-)

diff --git a/README b/README @@ -13,16 +13,13 @@ example, modify its Makefile to include: make -Set the environment variable CGRAPH_OUT to the name of the .dot file. - - export CGRAPH_OUT=callgraph.dot - At this point you just run the program taking care for the library file to be in the library path. LD_LIBRARY_PATH=$PWD ./prog [ARGS] -Once the program terminates, you have to feed it to the symbolizer. +Once the program terminates, you may want to replace addresses in the +generated callgraph.dot file with function names, using the symbolizer. ./symbolize.sh ./prog diff --git a/libcallgraph.c b/libcallgraph.c @@ -65,16 +65,8 @@ writelog(int fildes, const void *buf, size_t nbyte) __attribute__ ((constructor)) static void init_logging(void) { - char *f; - - f = getenv("CGRAPH_OUT"); - if (!f) { - fprintf(stderr, "cgraph: CGRAPH_OUT is not set!\n"); - _Exit(EXIT_FAILURE); - } - - fd = open(f, O_WRONLY | O_CREAT, 0644); - if (fd < 0 || ftruncate(fd, 0) < 0) { + fd = open("callgraph.dot", O_WRONLY | O_CREAT | O_EXCL, 0644); + if (fd == -1) { perror("cgraph"); _Exit(EXIT_FAILURE); } diff --git a/symbolize.sh b/symbolize.sh @@ -7,9 +7,10 @@ if [ ! -n "$1" ]; then exit 1 fi -env | grep CGRAPH_OUT= &>/dev/null -if [ ! "$?" -eq 0 -o "$CGRAPH_OUT" = "" ]; then - echo "CGRAPH_OUT is not set!" 1>&2 +CGRAPH_OUT=callgraph.dot + +if [ ! -f "$CGRAPH_OUT" ]; then + echo "$CGRAPH_OUT does not exist!" 1>&2 exit 1 fi