From 9c9b909cbfbc36156c366b4829be09f015a63474 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 26 Feb 2021 02:34:32 +0100 Subject: [PATCH] Make the dwarf3 reader more robust and less chatty when things go wrong Skip some stuff when seeing an unknown language, be less chatty about parser issues. All the issues seem to come from the multi-file, that is the shared (supplementary or alt) file containing debuginfo shared by all the gcc/runtime libraries. There are a couple of issues that this patch works around: - The multifile contains entries for the 'D' language, which has some constructs we don't expect. - We don't read partial units correctly, which means we often don't know the language we are looking at. - The parser is very chatty about issues it didn't expect (even if they are ignored, it will still output something) It only shows up with --read-var-info=yes which some tests enable, but which is disabled by default. Also increate the timeout of drd/tests/pth_cleanup_handler.c because DWARF reading is so slow. https://bugs.kde.org/show_bug.cgi?id=433500 --- NEWS | 3 ++- coregrind/m_debuginfo/readdwarf3.c | 16 ++++++++++++++-- coregrind/m_debuginfo/storage.c | 2 +- drd/tests/pth_cleanup_handler.c | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 3a34269869..adcb852486 100644 --- a/NEWS +++ b/NEWS @@ -118,6 +118,7 @@ where XXXXXX is the bug number as listed below. 428648 s390_emit_load_mem panics due to 20-bit offset for vector load 428716 cppcheck detects potential leak in VEX/useful/smchash.c 428909 helgrind: need to intercept duplicate libc definitions for Fedora 33 +429352 PPC ISA 3.1 support is missing, part 7 429692 unhandled ppc64le-linux syscall: 147 (getsid) 429864 s390x: C++ atomic test_and_set yields false-positive memcheck diagnostics @@ -132,8 +133,8 @@ where XXXXXX is the bug number as listed below. 432809 VEX should support REX.W + POPF 432861 PPC modsw and modsd give incorrect results for 1 mod 12 432215 Add debuginfod functionality +433500 DRD regtest faulures when libstdc++ and libgcc debuginfo are installed n-i-bz helgrind: If hg_cli__realloc fails, return NULL. -429352 PPC ISA 3.1 support is missing, part 7 Release 3.16.1 (22 June 2020) diff --git a/coregrind/m_debuginfo/readdwarf3.c b/coregrind/m_debuginfo/readdwarf3.c index 60fc402447..52c27d4bb4 100644 --- a/coregrind/m_debuginfo/readdwarf3.c +++ b/coregrind/m_debuginfo/readdwarf3.c @@ -3416,6 +3416,9 @@ static void typestack_push ( const CUConst* cc, static Bool subrange_type_denotes_array_bounds ( const D3TypeParser* parser, DW_TAG dtag ) { vg_assert(dtag == DW_TAG_subrange_type); + /* If we don't know the language, assume false. */ + if (parser->language == '?') + return False; /* For most languages, a subrange_type dtag always gives the bounds of an array. For Ada, there are additional conditions as a subrange_type @@ -3916,6 +3919,7 @@ static void parse_type_DIE ( /*MOD*/XArray* /* of TyEnt */ tyents, members must have a DW_AT_data_member_location expression whereas union members must not. */ Bool parent_is_struct; + Bool is_artificial = False; VG_(memset)( &fieldE, 0, sizeof(fieldE) ); fieldE.cuOff = posn; fieldE.tag = Te_Field; @@ -3952,7 +3956,12 @@ static void parse_type_DIE ( /*MOD*/XArray* /* of TyEnt */ tyents, (SizeT)fieldE.Te.Field.nLoc, "di.readdwarf3.ptD.member.2" ); } + if (attr == DW_AT_artificial && cts.u.val == 1) + is_artificial = True; } + /* Skip artificial members, they might not behave as expected. */ + if (is_artificial) + goto no_location; /* Do we have a plausible parent? */ if (typestack_is_empty(parser)) goto_bad_DIE; vg_assert(ML_(TyEnt__is_type)(&parser->qparentE[parser->sp])); @@ -3995,6 +4004,7 @@ static void parse_type_DIE ( /*MOD*/XArray* /* of TyEnt */ tyents, const members in C++ code which are compile time constants that do no exist in the class. They're not of any interest to us so we ignore them. */ + no_location: ML_(TyEnt__make_EMPTY)(&fieldE); } } @@ -4132,7 +4142,8 @@ static void parse_type_DIE ( /*MOD*/XArray* /* of TyEnt */ tyents, || (dtag == DW_TAG_subrange_type && !subrange_type_denotes_array_bounds(parser, dtag))) { /* subrange_type other than array bound is only for Ada. */ - vg_assert (dtag == DW_TAG_typedef || parser->language == 'A'); + vg_assert (dtag == DW_TAG_typedef || (parser->language == 'A' + || parser->language == '?')); /* We can pick up a new typedef/subrange_type any time. */ VG_(memset)(&typeE, 0, sizeof(typeE)); typeE.cuOff = D3_INVALID_CUOFF; @@ -4300,7 +4311,8 @@ static UWord chase_cuOff ( Bool* changed, ent = ML_(TyEnts__index_by_cuOff)( ents, ents_cache, cuOff ); if (!ent) { - VG_(printf)("chase_cuOff: no entry for 0x%05lx\n", cuOff); + if (VG_(clo_verbosity) > 1) + VG_(printf)("chase_cuOff: no entry for 0x%05lx\n", cuOff); *changed = False; return cuOff; } diff --git a/coregrind/m_debuginfo/storage.c b/coregrind/m_debuginfo/storage.c index 2a975dccc3..8667d123ff 100644 --- a/coregrind/m_debuginfo/storage.c +++ b/coregrind/m_debuginfo/storage.c @@ -1299,7 +1299,7 @@ void ML_(addVar)( struct _DebugInfo* di, ML_(read_elf_debug_info). */ vg_assert(di->fsm.have_rx_map && di->fsm.have_rw_map); if (level > 0 && ML_(find_rx_mapping)(di, aMin, aMax) == NULL) { - if (VG_(clo_verbosity) >= 0) { + if (VG_(clo_verbosity) > 1) { VG_(message)(Vg_DebugMsg, "warning: addVar: in range %#lx .. %#lx outside " "all rx mapped areas (%s)\n", diff --git a/drd/tests/pth_cleanup_handler.c b/drd/tests/pth_cleanup_handler.c index 0fb3d073d6..e441fa3a41 100644 --- a/drd/tests/pth_cleanup_handler.c +++ b/drd/tests/pth_cleanup_handler.c @@ -39,7 +39,7 @@ int main() pthread_t pt1, pt2; // Make sure the program exits in case a deadlock has been triggered. - alarm(20); + alarm(60); if (pthread_mutex_init(&s_mutex, NULL) != 0) { -- 2.47.2