From 0198534ac9fca5ac2ba9c0f9c4c5788849db6b41 Mon Sep 17 00:00:00 2001 From: Rainer Schuetze Date: Wed, 18 Jul 2018 08:34:20 +0200 Subject: DWARF: fix line info translation for pointer_size 8 do not assert for "Block" in DW_AT_upper_bound (but not supported) --- src/cv2pdb.vcxproj | 6 +++--- src/dwarflines.cpp | 24 +++++++++++++++--------- src/readDwarf.cpp | 4 ++-- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/cv2pdb.vcxproj b/src/cv2pdb.vcxproj index 2842e7c..d79bdc2 100644 --- a/src/cv2pdb.vcxproj +++ b/src/cv2pdb.vcxproj @@ -32,18 +32,18 @@ Application - v120_xp + $(DefaultPlatformToolset) Unicode true Application - v120_xp + $(DefaultPlatformToolset) Unicode Application - v120_xp + $(DefaultPlatformToolset) Unicode diff --git a/src/dwarflines.cpp b/src/dwarflines.cpp index 4a1b2d5..5c18575 100644 --- a/src/dwarflines.cpp +++ b/src/dwarflines.cpp @@ -31,7 +31,7 @@ static int cmpAdr(const void* s1, const void* s2) } -bool printLines(char const *fname, unsigned short sec, char const *secname, +bool printLines(char const *fname, unsigned short sec, char const *secname, mspdb::LineInfoEntry* pLineInfo, long numLineInfo) { printf("Sym: %s\n", secname ? secname : ""); @@ -71,8 +71,8 @@ bool _flushDWARFLines(const PEImage& img, mspdb::Mod* mod, DWARF_LineState& stat else return false; std::string fname = dfn->file_name; - - if(isRelativePath(fname) && + + if(isRelativePath(fname) && dfn->dir_index > 0 && dfn->dir_index <= state.include_dirs.size()) { std::string dir = state.include_dirs[dfn->dir_index - 1]; @@ -115,7 +115,7 @@ bool _flushDWARFLines(const PEImage& img, mspdb::Mod* mod, DWARF_LineState& stat if(dump) printf("AddLines(%08x+%04x, Line=%4d+%3d, %s)\n", firstAddr, length, firstLine, entry - firstEntry, fname.c_str()); rc = mod->AddLines(fname.c_str(), segIndex + 1, firstAddr, length, firstAddr, firstLine, - (unsigned char*) &state.lineInfo[firstEntry], + (unsigned char*) &state.lineInfo[firstEntry], (ln - firstEntry) * sizeof(state.lineInfo[0])); firstLine = state.lineInfo[ln].line; firstAddr = state.lineInfo[ln].offset; @@ -132,7 +132,7 @@ bool _flushDWARFLines(const PEImage& img, mspdb::Mod* mod, DWARF_LineState& stat if(dump) printf("AddLines(%08x+%04x, Line=%4d+%3d, %s)\n", firstAddr, length, firstLine, entry - firstEntry, fname.c_str()); rc = mod->AddLines(fname.c_str(), segIndex + 1, firstAddr, length, firstAddr, firstLine, - (unsigned char*) &state.lineInfo[firstEntry], + (unsigned char*) &state.lineInfo[firstEntry], (entry - firstEntry) * sizeof(state.lineInfo[0])); #else @@ -148,6 +148,9 @@ bool _flushDWARFLines(const PEImage& img, mspdb::Mod* mod, DWARF_LineState& stat bool interpretDWARFLines(const PEImage& img, mspdb::Mod* mod) { + DWARF_CompilationUnit* cu = (DWARF_CompilationUnit*)img.debug_info; + int ptrsize = cu ? cu->address_size : 4; + for(unsigned long off = 0; off < img.debug_line_length; ) { DWARF_LineNumberProgramHeader* hdr = (DWARF_LineNumberProgramHeader*) (img.debug_line + off); @@ -232,16 +235,19 @@ bool interpretDWARFLines(const PEImage& img, mspdb::Mod* mod) state.init(hdr); break; case DW_LNE_set_address: - if (!mod && state.section == -1) - state.section = img.getRelocationInLineSegment((char*)p - img.debug_line); - if(unsigned long adr = RD4(p)) + { + if (!mod && state.section == -1) + state.section = img.getRelocationInLineSegment((char*)p - img.debug_line); + unsigned long adr = ptrsize == 8 ? RD8(p) : RD4(p); + if(adr) state.address = adr; else if (!mod) state.address = adr; - else + else state.address = state.last_addr; // strange adr 0 for templates? state.op_index = 0; break; + } case DW_LNE_define_file: fname.read(p); state.file_ptr = &fname; diff --git a/src/readDwarf.cpp b/src/readDwarf.cpp index 6f5d04d..01544eb 100644 --- a/src/readDwarf.cpp +++ b/src/readDwarf.cpp @@ -47,7 +47,7 @@ Location decodeLocation(const PEImage& img, const DWARF_Attribute& attr, const L if (attr.type != ExprLoc && attr.type != Block) // same memory layout return invalid; - + byte*p = attr.expr.ptr; byte*end = attr.expr.ptr + attr.expr.len; @@ -488,7 +488,7 @@ bool DIECursor::readNext(DWARF_InfoData& id, bool stopAtNull) case DW_AT_inline: assert(a.type == Const); id.inlined = a.cons; break; case DW_AT_external: assert(a.type == Flag); id.external = a.flag; break; case DW_AT_upper_bound: - assert(a.type == Const || a.type == Ref || a.type == ExprLoc); + assert(a.type == Const || a.type == Ref || a.type == ExprLoc || a.type == Block); if (a.type == Const) // TODO: other types not supported yet id.upper_bound = a.cons; break; -- cgit v0.12