]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
When --show-below-main=no, search main from the outermost stackframe
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sat, 12 Nov 2016 20:11:25 +0000 (20:11 +0000)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Sat, 12 Nov 2016 20:11:25 +0000 (20:11 +0000)
* main is more likely to be an outermost frame rather than an innermost
  frame. So, searching from the outermost frame will more quickly find it.

* Also, in case the stacktrace contains twice the main functionn, this
  ensures we only removes the functions below the outermost main.
  Having 2 mains in a stacktrace does not happen normally.
  However, this prepares for some future commit that improves
  the outer/inner setup: the outer will append the inner guest stack trace.
  The inner stack trace sometimes already contains main.
  Searching from outermost frame main allows to keep the interesting
  part of the stacktrace.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16135

coregrind/m_stacktrace.c

index ef4984c3a2689517d830672e6dc6c4a000c9ba65..0dbe09ffdbec0e390d391427db9ebbfec671492f 100644 (file)
@@ -1797,28 +1797,25 @@ void VG_(apply_StackTrace)(
         StackTrace ips, UInt n_ips
      )
 {
-   Bool main_done = False;
-   Int i = 0;
+   Int i;
 
    vg_assert(n_ips > 0);
-   do {
-      Addr ip = ips[i];
-
-      // Stop after the first appearance of "main" or one of the other names
-      // (the appearance of which is a pretty good sign that we've gone past
-      // main without seeing it, for whatever reason)
-      if ( ! VG_(clo_show_below_main) ) {
-         Vg_FnNameKind kind = VG_(get_fnname_kind_from_IP)(ip);
-         if (Vg_FnNameMain == kind || Vg_FnNameBelowMain == kind) {
-            main_done = True;
-         }
+   if ( ! VG_(clo_show_below_main) ) {
+      // Search (from the outer frame onwards) the appearance of "main"
+      // or the last appearance of a below main function.
+      // Then decrease n_ips so as to not call action for the below main
+      for (i = n_ips - 1; i >= 0; i--) {
+         Vg_FnNameKind kind = VG_(get_fnname_kind_from_IP)(ips[i]);
+         if (Vg_FnNameMain == kind || Vg_FnNameBelowMain == kind)
+            n_ips = i + 1;
+         if (Vg_FnNameMain == kind)
+            break;
       }
+   }
 
+   for (i = 0; i < n_ips; i++)
       // Act on the ip
-      action(i, ip, opaque);
-
-      i++;
-   } while (i < n_ips && !main_done);
+      action(i, ips[i], opaque);
 }