From: Josef Weidendorfer Date: Mon, 1 May 2006 00:55:54 +0000 (+0000) Subject: Callgrind: Improve self-hosting with outer callgrind tool X-Git-Tag: svn/VALGRIND_3_2_0~90 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4906b8a95835940a69e78345ec6fbb6c474a1b67;p=thirdparty%2Fvalgrind.git Callgrind: Improve self-hosting with outer callgrind tool This adds an option to change the default handling of jumps between functions. Usually, a jump between functions is interpreted as call, because such jumps are typically generated by compilers on tail recursion optimization, and we want to present this as call to the user. Thus, such a jump pushes a call onto callgrinds shadow stack. The option "--pop-on-jump" changes this to pop+push the shadow callstack: then, a jump between functions is seen as a return to the caller and a new call. The default behaviour is _bad_ for using callgrind with self-hosting. Valgrinds inner loop VG_(run_innerloop) jumps to generated code, and this code jumps back to the inner loop. Thus, every executed BB adds 2 calls to an ever increasing shadow call stack, leading to memory consumption increasing with runtime :-( So: For self-hosting valgrind with an outer callgrind, always use option "--pop-on-jump" for the outer callgrind. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@5869 --- diff --git a/callgrind/clo.c b/callgrind/clo.c index bd6d02a63d..16738c68ec 100644 --- a/callgrind/clo.c +++ b/callgrind/clo.c @@ -527,7 +527,10 @@ Bool CLG_(process_cmd_line_option)(Char* arg) else if (0 == VG_(strncmp)(arg, "--separate-recs=", 16)) CLG_(clo).separate_recursions = (Int)VG_(atoll)(&arg[16]); - /* workaround to find runtime_resolve (needs special handling) */ + /* change handling of a jump between functions to ret+call */ + else if (0 == VG_(strcmp)(arg, "--pop-on-jump")) { + CLG_(clo).pop_on_jump = True; + } else if (0 == VG_(strncmp)(arg, "--pop-on-jump=", 14)) { fn_config* fnc = get_fnc(arg+14); fnc->pop_on_jump = CONFIG_TRUE; @@ -758,6 +761,9 @@ void CLG_(set_clo_defaults)(void) CLG_(clo).instrument_atstart = True; CLG_(clo).simulate_cache = False; + /* Call graph */ + CLG_(clo).pop_on_jump = False; + #if CLG_ENABLE_DEBUG CLG_(clo).verbose = 0; CLG_(clo).verbose_start = 0; diff --git a/callgrind/fn.c b/callgrind/fn.c index a786c5097a..ad951827b2 100644 --- a/callgrind/fn.c +++ b/callgrind/fn.c @@ -295,7 +295,7 @@ fn_node* new_fn_node(Char fnname[FILENAME_LEN], new->zero_before = False; new->toggle_collect = False; new->skip = False; - new->pop_on_jump = False; + new->pop_on_jump = CLG_(clo).pop_on_jump; new->is_malloc = False; new->is_realloc = False; new->is_free = False; diff --git a/callgrind/global.h b/callgrind/global.h index abef4c9fce..f6190a206c 100644 --- a/callgrind/global.h +++ b/callgrind/global.h @@ -89,6 +89,9 @@ struct _CommandLineOptions { Bool instrument_atstart; /* Instrument at start? */ Bool simulate_cache; /* Call into cache simulator ? */ + /* Call graph generation */ + Bool pop_on_jump; /* Handle a jump between functions as ret+call */ + #if CLG_ENABLE_DEBUG Int verbose; ULong verbose_start;