From: Philippe Waroquiers Date: Sat, 12 Nov 2016 20:11:25 +0000 (+0000) Subject: When --show-below-main=no, search main from the outermost stackframe X-Git-Tag: svn/VALGRIND_3_13_0~286 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a340ec0c643b1f69ddcbf49508ee84401061ee3;p=thirdparty%2Fvalgrind.git When --show-below-main=no, search main from the outermost stackframe * 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 --- diff --git a/coregrind/m_stacktrace.c b/coregrind/m_stacktrace.c index ef4984c3a2..0dbe09ffdb 100644 --- a/coregrind/m_stacktrace.c +++ b/coregrind/m_stacktrace.c @@ -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); }