From 6c979f844fd0696dfa773f4497cadceb77b2a45e Mon Sep 17 00:00:00 2001 From: Philippe Waroquiers Date: Wed, 21 Mar 2018 23:24:09 +0100 Subject: [PATCH] Fix 391861 - Massif Assertion 'n_ips >= 1 && n_ips <= VG_(clo_backtrace_size)' Sometimes, at least on arm platforms, we get a stack trace with only one function. When this happens and massif removes the top fn, we end up trying to create an execontext of 0 ips, as the only fn is removed, and an execontext of 0 ips causes the assert in m_execontext.c So, do whatever to avoid to crash when having a single fn stacktrace. The whatever means use a null execontext, which is an execontext of one single address 0x0. Note that this is just to bypass the crash. What is shown by massif is not very nice (but what could we show ?). Note that instead of using such a null execontext, we could rather just keep the single ips. But that might create a lot of single fn entries in the xtree and/or show undesired functions. So, we the null execontext, which is shown as 0xFFFFFFFFFFFFFFFF ??? in the massif output. Tested on amd64 by artificially creating stacktrace of one fn. --- massif/ms_main.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/massif/ms_main.c b/massif/ms_main.c index a2c1f39..58656ee 100644 --- a/massif/ms_main.c +++ b/massif/ms_main.c @@ -573,11 +573,17 @@ static ExeContext* make_ec(ThreadId tid, Bool exclude_first_entry) NULL/*array to dump SP values in*/, NULL/*array to dump FP values in*/, 0/*first_ip_delta*/ ); - if (exclude_first_entry && n_ips > 0) { - const HChar *fnname; - VERB(4, "removing top fn %s from stacktrace\n", - VG_(get_fnname)(ips[0], &fnname) ? fnname : "???"); - return VG_(make_ExeContext_from_StackTrace)(ips+1, n_ips-1); + if (exclude_first_entry) { + if (n_ips > 1) { + const HChar *fnname; + VERB(4, "removing top fn %s from stacktrace\n", + VG_(get_fnname)(ips[0], &fnname) + ? fnname : "???"); + return VG_(make_ExeContext_from_StackTrace)(ips+1, n_ips-1); + } else { + VERB(4, "null execontext as removing top fn with n_ips %d\n", n_ips); + return VG_(null_ExeContext) (); + } } else return VG_(make_ExeContext_from_StackTrace)(ips, n_ips); } -- 2.3.3.199.g52cae64