]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Callgrind: Improve self-hosting with outer callgrind tool
authorJosef Weidendorfer <Josef.Weidendorfer@gmx.de>
Mon, 1 May 2006 00:55:54 +0000 (00:55 +0000)
committerJosef Weidendorfer <Josef.Weidendorfer@gmx.de>
Mon, 1 May 2006 00:55:54 +0000 (00:55 +0000)
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

callgrind/clo.c
callgrind/fn.c
callgrind/global.h

index bd6d02a63df2ae8ae2caded3cd66a64fc52118e5..16738c68ecdbc5368c742783a440ec9448dc7249 100644 (file)
@@ -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;
index a786c5097adfe52fb07f4cdee1ea7861d73dc3cd..ad951827b263114116b75f49604ce9375249de19 100644 (file)
@@ -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;
index abef4c9fce4abeb894ea0ba948182ba7325f45a7..f6190a206c7785bd874221901d084078ab8ab6b3 100644 (file)
@@ -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;