From eec7606c5ba8a25fe377200eba354495b0744f09 Mon Sep 17 00:00:00 2001 From: Philippe Waroquiers Date: Mon, 31 Jul 2017 20:43:43 +0000 Subject: [PATCH] Fix 382515 - valgrind: "Assertion 'di->have_dinfo' failed." on wine's dlls/mscoree/tests/mscoree.c * produce (more) user messages when valgrind cannot read a pdb file. * recover properly from an invalid/unsupported pdb file. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16465 --- NEWS | 2 +- coregrind/m_debuginfo/debuginfo.c | 23 +++++++++++++---------- coregrind/m_debuginfo/readpdb.c | 28 ++++++++++++++++++++++------ 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index 47ddc77ba1..9b39447cab 100644 --- a/NEWS +++ b/NEWS @@ -44,7 +44,7 @@ where XXXXXX is the bug number as listed below. 381805 arm32 needs ld.so index hardwire for new glibc security fixes 382256 gz compiler flag test doesn't work for gold 382407 vg_perf needs "--terse" command line option - +382515 "Assertion 'di->have_dinfo' failed." on wine's dlls/mscoree/tests/mscoree.c Release 3.13.0 (15 June 2017) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/coregrind/m_debuginfo/debuginfo.c b/coregrind/m_debuginfo/debuginfo.c index cd191dd847..e01f19a7cb 100644 --- a/coregrind/m_debuginfo/debuginfo.c +++ b/coregrind/m_debuginfo/debuginfo.c @@ -1404,19 +1404,22 @@ void VG_(di_notify_pdb_debuginfo)( Int fd_obj, Addr avma_obj, /* don't set up any of the di-> fields; let ML_(read_pdb_debug_info) do it. */ - ML_(read_pdb_debug_info)( di, avma_obj, bias_obj, - pdbimage, n_pdbimage, pdbname, pdb_mtime ); - // JRS fixme: take notice of return value from read_pdb_debug_info, - // and handle failure - vg_assert(di->have_dinfo); // fails if PDB read failed + if (ML_(read_pdb_debug_info)( di, avma_obj, bias_obj, + pdbimage, n_pdbimage, pdbname, pdb_mtime )) { + vg_assert(di->have_dinfo); // fails if PDB read failed + if (VG_(clo_verbosity) > 0) { + VG_(message)(Vg_UserMsg, "LOAD_PDB_DEBUGINFO: done: " + "%lu syms, %lu src locs, %lu fpo recs\n", + di->symtab_used, di->loctab_used, di->fpo_size); + } + } else { + VG_(message)(Vg_UserMsg, "LOAD_PDB_DEBUGINFO: failed loading info " + "from %s\n", pdbname); + discard_DebugInfo (di); + } VG_(am_munmap_valgrind)( (Addr)pdbimage, n_pdbimage ); VG_(close)(fd_pdbimage); - if (VG_(clo_verbosity) > 0) { - VG_(message)(Vg_UserMsg, "LOAD_PDB_DEBUGINFO: done: " - "%lu syms, %lu src locs, %lu fpo recs\n", - di->symtab_used, di->loctab_used, di->fpo_size); - } } out: diff --git a/coregrind/m_debuginfo/readpdb.c b/coregrind/m_debuginfo/readpdb.c index b01a8cb6a9..5506dde2b3 100644 --- a/coregrind/m_debuginfo/readpdb.c +++ b/coregrind/m_debuginfo/readpdb.c @@ -1019,10 +1019,17 @@ static void* find_pdb_header( void* pdbimage, { static const HChar pdbtxt[]= "Microsoft C/C++"; HChar* txteof = VG_(strchr)(pdbimage, '\032'); - if (! txteof) + if (! txteof) { + VG_(umsg)("LOAD_PDB_DEBUGINFO: \\032 header character not found. " + " possible invalid/unsupported pdb file format?\n"); return NULL; - if (0!=VG_(strncmp)(pdbimage, pdbtxt, -1+ sizeof(pdbtxt))) + } + if (0!=VG_(strncmp)(pdbimage, pdbtxt, -1+ sizeof(pdbtxt))) { + VG_(umsg)("LOAD_PDB_DEBUGINFO: %s header string not found. " + " possible invalid/unsupported pdb file format?\n", + pdbtxt);; return NULL; + } *signature = *(unsigned*)(1+ txteof); HChar *img_addr = pdbimage; // so we can do address arithmetic @@ -2270,13 +2277,19 @@ Bool ML_(read_pdb_debug_info)( VG_(umsg)("LOAD_PDB_DEBUGINFO: Processing PDB file %s\n", pdbname ); dos_avma = (IMAGE_DOS_HEADER *)obj_avma; - if (dos_avma->e_magic != IMAGE_DOS_SIGNATURE) - return False; + if (dos_avma->e_magic != IMAGE_DOS_SIGNATURE) { + VG_(umsg)("LOAD_PDB_DEBUGINFO: IMAGE_DOS_SIGNATURE not found. " + " possible invalid/unsupported pdb file format?\n"); + return False; + } ntheaders_avma = (IMAGE_NT_HEADERS *)((Char*)dos_avma + dos_avma->e_lfanew); - if (ntheaders_avma->Signature != IMAGE_NT_SIGNATURE) + if (ntheaders_avma->Signature != IMAGE_NT_SIGNATURE) { + VG_(umsg)("LOAD_PDB_DEBUGINFO: IMAGE_NT_SIGNATURE not found. " + " possible invalid/unsupported pdb file format?\n"); return False; + } sectp_avma = (IMAGE_SECTION_HEADER *)( @@ -2412,8 +2425,11 @@ Bool ML_(read_pdb_debug_info)( */ signature = 0; hdr = find_pdb_header( pdbimage, &signature ); - if (0==hdr) + if (0==hdr) { + VG_(umsg)("LOAD_PDB_DEBUGINFO: find_pdb_header found no hdr. " + " possible invalid/unsupported pdb file format?\n"); return False; /* JRS: significance? no pdb header? */ + } VG_(memset)(&reader, 0, sizeof(reader)); reader.u.jg.header = hdr; -- 2.47.2