From cd274061af6dbd54aac1677e57c369bb307ad307 Mon Sep 17 00:00:00 2001 From: Sasha Nicolas Date: Fri, 24 Feb 2017 17:45:36 -0600 Subject: [PATCH] Adaptations done, but remain to be fixed at some points. Dyninst is compiling. --- dwarf/h/dwarfExprParser.h | 2 +- dwarf/h/dwarfFrameParser.h | 2 +- dwarf/h/dwarfHandle.h | 2 +- dwarf/h/dwarfResult.h | 2 +- dwarf/src/dwarfExprParser.C | 2 +- dwarf/src/dwarfFrameParser.C | 2 +- dwarf/src/dwarfHandle.C | 4 +- dwarf/src/dwarfResult.C | 2 +- stackwalk/src/dbginfo-stepper.C | 2 +- stackwalk/src/dbgstepper-impl.h | 4 +- symtabAPI/src/Function.C | 6 +- symtabAPI/src/Object-elf.C | 2 +- symtabAPI/src/Object-elf.h | 4 +- symtabAPI/src/dwarfWalker.C | 478 ++++++++++++++++++-------------- symtabAPI/src/dwarfWalker.h | 4 +- symtabAPI/src/parseDwarf.C | 2 +- 16 files changed, 291 insertions(+), 229 deletions(-) diff --git a/dwarf/h/dwarfExprParser.h b/dwarf/h/dwarfExprParser.h index 0a6c1e589f..0674a3d2f8 100644 --- a/dwarf/h/dwarfExprParser.h +++ b/dwarf/h/dwarfExprParser.h @@ -42,7 +42,7 @@ namespace Dyninst { class VariableLocation; class ProcessReader; -namespace Dwarf { +namespace DwarfDyninst{ class DwarfResult; diff --git a/dwarf/h/dwarfFrameParser.h b/dwarf/h/dwarfFrameParser.h index 50ab4048b0..5491abe7c8 100644 --- a/dwarf/h/dwarfFrameParser.h +++ b/dwarf/h/dwarfFrameParser.h @@ -43,7 +43,7 @@ namespace Dyninst { class VariableLocation; -namespace Dwarf { +namespace DwarfDyninst { class DwarfResult; diff --git a/dwarf/h/dwarfHandle.h b/dwarf/h/dwarfHandle.h index d3f38afdc4..6d054c140e 100644 --- a/dwarf/h/dwarfHandle.h +++ b/dwarf/h/dwarfHandle.h @@ -39,7 +39,7 @@ namespace Dyninst { class Elf_X; -namespace Dwarf { +namespace DwarfDyninst { class DwarfFrameParser; typedef boost::shared_ptr DwarfFrameParserPtr; diff --git a/dwarf/h/dwarfResult.h b/dwarf/h/dwarfResult.h index bb793f8311..51bed706e6 100644 --- a/dwarf/h/dwarfResult.h +++ b/dwarf/h/dwarfResult.h @@ -41,7 +41,7 @@ namespace Dyninst { class VariableLocation; class ProcessReader; -namespace Dwarf { +namespace DwarfDyninst { class DYNDWARF_EXPORT DwarfResult { // An interface for building representations of Dwarf expressions. diff --git a/dwarf/src/dwarfExprParser.C b/dwarf/src/dwarfExprParser.C index 44c8ef2f73..bceae3136f 100644 --- a/dwarf/src/dwarfExprParser.C +++ b/dwarf/src/dwarfExprParser.C @@ -41,7 +41,7 @@ using namespace std; namespace Dyninst { -namespace Dwarf { +namespace DwarfDyninst { bool decodeDwarfExpression(Dwarf_Op * expr, Dwarf_Sword listlen, diff --git a/dwarf/src/dwarfFrameParser.C b/dwarf/src/dwarfFrameParser.C index 6359b45941..ed0b9a8d93 100644 --- a/dwarf/src/dwarfFrameParser.C +++ b/dwarf/src/dwarfFrameParser.C @@ -41,7 +41,7 @@ #define DW_FRAME_CFA_COL3 ((Dwarf_Half) -1) using namespace Dyninst; -using namespace Dwarf; +using namespace DwarfDyninst; using namespace std; struct frameParser_key diff --git a/dwarf/src/dwarfHandle.C b/dwarf/src/dwarfHandle.C index 27881ecabb..e26379795c 100644 --- a/dwarf/src/dwarfHandle.C +++ b/dwarf/src/dwarfHandle.C @@ -36,7 +36,7 @@ #include using namespace Dyninst; -using namespace Dwarf; +using namespace DwarfDyninst; using namespace std; // Add definitions that may not be in all elf.h files @@ -162,7 +162,7 @@ bool DwarfHandle::init_dbg() assert(0 && "Unsupported archiecture in ELF file."); return false; } - sw = Dwarf::DwarfFrameParser::create(*frame_data, arch); + sw = DwarfDyninst::DwarfFrameParser::create(*frame_data, arch); init_dwarf_status = dwarf_status_ok; return true; diff --git a/dwarf/src/dwarfResult.C b/dwarf/src/dwarfResult.C index 1231bb59cf..4a29a0c14a 100644 --- a/dwarf/src/dwarfResult.C +++ b/dwarf/src/dwarfResult.C @@ -40,7 +40,7 @@ #include "debug_common.h" using namespace Dyninst; -using namespace Dwarf; +using namespace DwarfDyninst; using namespace std; #define CHECK_OPER(n) if (operands.size() < n) { error = true; break; } diff --git a/stackwalk/src/dbginfo-stepper.C b/stackwalk/src/dbginfo-stepper.C index 9127e43d48..f960dbe148 100644 --- a/stackwalk/src/dbginfo-stepper.C +++ b/stackwalk/src/dbginfo-stepper.C @@ -49,7 +49,7 @@ using namespace Dyninst; using namespace Stackwalker; -using namespace Dwarf; +using namespace DwarfDyninst; static std::map dwarf_info; diff --git a/stackwalk/src/dbgstepper-impl.h b/stackwalk/src/dbgstepper-impl.h index b0921ef92a..10bc5c62f4 100644 --- a/stackwalk/src/dbgstepper-impl.h +++ b/stackwalk/src/dbgstepper-impl.h @@ -36,7 +36,7 @@ namespace Dyninst { -namespace Dwarf { +namespace DwarfDyninst { class DwarfFrameParser; typedef boost::shared_ptr DwarfFrameParserPtr; }; @@ -81,7 +81,7 @@ class DebugStepperImpl : public FrameStepper, public Dyninst::ProcessReader { virtual const char *getName() const; protected: gcframe_ret_t getCallerFrameArch(Address pc, const Frame &in, Frame &out, - Dwarf::DwarfFrameParserPtr dinfo, bool isVsyscallPage); + DwarfDyninst::DwarfFrameParserPtr dinfo, bool isVsyscallPage); bool isFrameRegister(MachRegister reg); bool isStackRegister(MachRegister reg); }; diff --git a/symtabAPI/src/Function.C b/symtabAPI/src/Function.C index 9942c729b2..9373f7871c 100644 --- a/symtabAPI/src/Function.C +++ b/symtabAPI/src/Function.C @@ -231,12 +231,12 @@ void FunctionBase::expandLocation(const VariableLocation &loc, return; } - Dyninst::Dwarf::DwarfFrameParser::Ptr frameParser = - Dyninst::Dwarf::DwarfFrameParser::create(*getModule()->exec()->getObject()->dwarf->frame_dbg(), + Dyninst::DwarfDyninst::DwarfFrameParser::Ptr frameParser = + Dyninst::DwarfDyninst::DwarfFrameParser::create(*getModule()->exec()->getObject()->dwarf->frame_dbg(), getModule()->exec()->getObject()->getArch()); std::vector FDEs; - Dyninst::Dwarf::FrameErrors_t err; + Dyninst::DwarfDyninst::FrameErrors_t err; frameParser->getRegsForFunction(getOffset(), Dyninst::CFA, FDEs, diff --git a/symtabAPI/src/Object-elf.C b/symtabAPI/src/Object-elf.C index 0771dca7b2..34128424e7 100644 --- a/symtabAPI/src/Object-elf.C +++ b/symtabAPI/src/Object-elf.C @@ -47,7 +47,7 @@ using namespace Dyninst; using namespace Dyninst::SymtabAPI; -using namespace Dyninst::Dwarf; +using namespace Dyninst::DwarfDyninst; using namespace std; #if !defined(_Object_elf_h_) diff --git a/symtabAPI/src/Object-elf.h b/symtabAPI/src/Object-elf.h index 6f6246d4c5..9f3a783424 100644 --- a/symtabAPI/src/Object-elf.h +++ b/symtabAPI/src/Object-elf.h @@ -66,7 +66,7 @@ namespace Dyninst{ -namespace Dwarf { +namespace DwarfDyninst { class DwarfFrameParser; typedef boost::shared_ptr DwarfFrameParserPtr; } @@ -474,7 +474,7 @@ class Object; std::map TOC_table_; public: - Dyninst::Dwarf::DwarfHandle::ptr dwarf; + Dyninst::DwarfDyninst::DwarfHandle::ptr dwarf; private: bool EEL; // true if EEL rewritten diff --git a/symtabAPI/src/dwarfWalker.C b/symtabAPI/src/dwarfWalker.C index 5c3b333055..d4bddb754b 100644 --- a/symtabAPI/src/dwarfWalker.C +++ b/symtabAPI/src/dwarfWalker.C @@ -45,7 +45,7 @@ #include using namespace Dyninst; using namespace SymtabAPI; -using namespace Dwarf; +using namespace DwarfDyninst; using namespace std; #define DWARF_FAIL_RET_VAL(x, v) { \ @@ -142,7 +142,7 @@ bool DwarfWalker::parse() { compile_offset = next_cu_header; } */ - size_t cu_header_size; + size_t cu_header_size = 0; for(Dwarf_Off cu_off = 0, next_cu_off; dwarf_nextcu(dbg(), cu_off, &next_cu_off, &cu_header_size, NULL, NULL, NULL) == 0; @@ -775,38 +775,50 @@ vector DwarfWalker::getDieRanges(::Dwarf * dbg, Dwarf_Die die, Off auto highlow = parseHighPCLowPC(dbg, die); if(highlow.second) newRanges.push_back(highlow.first); - Address range_offset; - if (findConstant(DW_AT_ranges, range_offset, die, dbg)) - { - Dwarf_Aranges *ranges = NULL; - size_t ranges_length = 0; - dwarf_printf("calling ranges_a, offset 0x%lx, die %p\n", range_offset, die); - //int status = (dwarf_get_ranges_a(dbg, (Dwarf_Off) range_offset, die, - // &ranges, &ranges_length, NULL, NULL)); - int status = (dwarf_getaranges(dbg, &ranges, &ranges_length)); - bool done = (status != 0); - for (unsigned i = 0; i < ranges_length && !done; i++) { - Dwarf_Arange *cur = dwarf_onearange(ranges,i); - Address cur_base = range_base; - switch (cur.dwr_type) { - case DW_RANGES_ENTRY: { - Address low = cur.dwr_addr1 + cur_base; - Address high = cur.dwr_addr2 + cur_base; - dwarf_printf("Lexical block from 0x%lx to 0x%lx\n", low, high); - newRanges.push_back(AddressRange(low, high)); - // mod()->addRange(low, high); - break; - } - case DW_RANGES_ADDRESS_SELECTION: - cur_base = cur.dwr_addr2; - break; - case DW_RANGES_END: - done = true; - break; - } - } - //dwarf_ranges_dealloc(dbg, ranges, ranges_length); - } + Address range_offset; + if (findConstant(DW_AT_ranges, range_offset, die, dbg)) + { + Dwarf_Aranges *ranges = NULL; + size_t ranges_length = 0; + dwarf_printf("calling ranges_a, offset 0x%lx, die %p\n", range_offset, die); + //int status = (dwarf_get_ranges_a(dbg, (Dwarf_Off) range_offset, die, + // &ranges, &ranges_length, NULL, NULL)); + int status = (dwarf_getaranges(dbg, &ranges, &ranges_length)); + bool done = (status != 0); + for (unsigned i = 0; i < ranges_length && !done; i++) { + Dwarf_Arange *cur = dwarf_onearange(ranges,i); + Address cur_base = range_base; + /*old code + switch (cur.dwr_type) { + case DW_RANGES_ENTRY: + { + Address low = cur.dwr_addr1 + cur_base; + Address high = cur.dwr_addr2 + cur_base; + dwarf_printf("Lexical block from 0x%lx to 0x%lx\n", low, high); + newRanges.push_back(AddressRange(low, high)); + // mod()->addRange(low, high); + break; + } + case DW_RANGES_ADDRESS_SELECTION: + cur_base = cur.dwr_addr2; + break; + case DW_RANGES_END: + done = true; + break; + }*/ + Dwarf_Addr address; + Dwarf_Word length; + Dwarf_Off offset; + if(!dwarf_getarangeinfo(cur, &address, &length, &offset)) + continue; + Address low = address + offset + cur_base; + Address high = low + length; + dwarf_printf("Lexical block from 0x%lx to 0x%lx\n", low, high); + newRanges.push_back(AddressRange(low, high)); + + } + //dwarf_ranges_dealloc(dbg, ranges, ranges_length); + } return newRanges; } @@ -1438,8 +1450,16 @@ bool DwarfWalker::handleAbstractOrigin(bool &isAbstract) { //bool is_info = dwarf_get_die_infotypes_flag(entry()); bool is_info = !dwarf_hasattr_integrate(&e, DW_TAG_type_unit); - DWARF_FAIL_RET(dwarf_offdie_b( dbg(), abstractOffset, is_info, & absE, NULL)); - + //DWARF_FAIL_RET(dwarf_offdie_b( dbg(), abstractOffset, is_info, & absE, NULL)); + Dwarf_Die * cu_die_p = 0; + if(is_info){ + cu_die_p = dwarf_offdie(dbg(), abstractOffset, &absE); + }else{ + cu_die_p = dwarf_offdie_types(dbg(), abstractOffset, &absE); + } + if (cu_die_p == 0) { + return false; + } //dwarf_dealloc( dbg() , abstractAttribute, DW_DLA_ATTR ); setAbstractEntry(absE); @@ -1473,8 +1493,16 @@ bool DwarfWalker::handleSpecification(bool &hasSpec) { //bool is_info = dwarf_get_die_infotypes_flag(entry()); bool is_info = !dwarf_hasattr_integrate(&e, DW_TAG_type_unit); - DWARF_FAIL_RET(dwarf_offdie_b( dbg(), specOffset, is_info, &specE, NULL )); - + //DWARF_FAIL_RET(dwarf_offdie_b( dbg(), specOffset, is_info, &specE, NULL )); + Dwarf_Die * cu_die_p = 0; + if(is_info){ + cu_die_p = dwarf_offdie(dbg(), specOffset, &specE); + }else{ + cu_die_p = dwarf_offdie_types(dbg(), specOffset, &specE); + } + if (cu_die_p == 0) { + return false; + } //dwarf_dealloc( dbg(), specAttribute, DW_DLA_ATTR ); // cout << "Set spec entry" << endl; @@ -1522,7 +1550,8 @@ bool DwarfWalker::findFuncName() { DWARF_CHECK_RET(status == 0); // previously ==1 if ( status != 0 ) { // previously ==1 const char *dwarfName = dwarf_formstring(&linkageNameAttr); - DWARF_FAIL_RET(dwarfName); + //DWARF_FAIL_RET(dwarfName); + if(dwarfName==NULL) return false; curName() = dwarfName; setMangledName(true); dwarf_printf("(0x%lx) Found mangled name of %s, using\n", id(), curName().c_str()); @@ -1677,7 +1706,8 @@ bool DwarfWalker::findDieOffset(Dwarf_Attribute attr, Dwarf_Off &offset) { case DW_FORM_data4: case DW_FORM_data8: { - DWARF_FAIL_RET(dwarf_global_formref(&attr, &offset)); + //DWARF_FAIL_RET(dwarf_global_formref(&attr, &offset)); + DWARF_FAIL_RET(dwarf_formref(&attr, &offset)); return true; } /* Then there's DW_FORM_sec_offset which refer other sections, or @@ -1698,7 +1728,10 @@ bool DwarfWalker::findAnyType(Dwarf_Attribute typeAttribute, if (form == DW_FORM_ref_sig8) { Dwarf_Sig8 signature; //char signature[8]; - DWARF_FAIL_RET(dwarf_formsig8(typeAttribute, &signature, NULL)); + //DWARF_FAIL_RET(dwarf_formsig8(typeAttribute, &signature, NULL)); + const char * sig = dwarf_formstring(&typeAttribute); + if(!sig) return false; + memcpy(signature.signature, sig, 8); return findSig8Type(&signature, type); } @@ -1722,9 +1755,7 @@ bool DwarfWalker::findAnyType(Dwarf_Attribute typeAttribute, so the Type look-ups by it rather than name. */ type = tc()->findOrCreateType( type_id ); dwarf_printf("(0x%lx) Returning type %p / %s for id 0x%x\n", - id(), - type, type->getName().c_str(), - type_id); + id(), type, type->getName().c_str(), type_id); return true; } @@ -1769,8 +1800,9 @@ bool DwarfWalker::getLineInformation(Dwarf_Word &variableLineNo, } bool DwarfWalker::decodeLocationList(Dwarf_Half attr, - Address *initialStackValue, - std::vector &locs) { + Address * /*initialStackValue*/, + std::vector &locs) +{ dwarf_printf("(0x%lx) decodeLocationList for attr %d\n", id(), attr); bool hasAttr = false; @@ -1807,6 +1839,7 @@ bool DwarfWalker::decodeLocationList(Dwarf_Half attr, } else { dwarf_printf("(0x%lx) Decoding loclist location\n", id()); + /* FIXME Dwarf_Op* **locationList; Dwarf_Sword listLength; int status = dwarf_loclist_n( locationAttribute, & locationList, & listLength, NULL ); @@ -1814,8 +1847,6 @@ bool DwarfWalker::decodeLocationList(Dwarf_Half attr, //dwarf_dealloc( dbg(), locationAttribute, DW_DLA_ATTR ); if (status != 0) { - - dwarf_printf("(0x%lx) Failed loclist decode: %d\n", id(), status); return true; } @@ -1828,19 +1859,17 @@ bool DwarfWalker::decodeLocationList(Dwarf_Half attr, initialStackValue)) { deallocateLocationList( locationList, listLength ); return false; - } - - - deallocateLocationList( locationList, listLength ); + }*/ + //deallocateLocationList( locationList, listLength ); } return true; } -bool DwarfWalker::checkForConstantOrExpr(Dwarf_Half attr, +bool DwarfWalker::checkForConstantOrExpr(Dwarf_Half /*attr*/, Dwarf_Attribute &locationAttribute, bool &constant, - bool &expr, + bool & /*expr*/, Dwarf_Half &form) { constant = false; @@ -1849,6 +1878,7 @@ bool DwarfWalker::checkForConstantOrExpr(Dwarf_Half attr, DWARF_FAIL_RET(form); // And see if it's a constant + /*FIXME Dwarf_Form_Class formtype = dwarf_get_form_class(version, attr, offset_size, form); dwarf_printf("(0x%lx) Checking for constant, formtype is 0x%x looking for 0x%x\n", id(), formtype, DW_FORM_CLASS_CONSTANT); @@ -1858,7 +1888,7 @@ bool DwarfWalker::checkForConstantOrExpr(Dwarf_Half attr, } else if (formtype == DW_FORM_CLASS_EXPRLOC) { expr = true; - } + }*/ return true; } @@ -1897,7 +1927,7 @@ bool DwarfWalker::findString(Dwarf_Half attr, case DW_FORM_string: { const char *s = dwarf_formstring(&strattr); - DWARF_FAIL_RET(s); + if(!s) return false; // cout << "findString found " << s << " in DW_FORM_string" << endl; str = s; result = true; @@ -1910,7 +1940,7 @@ bool DwarfWalker::findString(Dwarf_Half attr, { Dwarf_Block *block = NULL; DWARF_FAIL_RET(dwarf_formblock(&strattr, block)); - str = (char *) block->bl_data; + str = (char *) block->data; //dwarf_dealloc(dbg(), block, DW_DLA_BLOCK); // cout << "findString found " << str << " in DW_FORM_block" << endl; result = !str.empty(); @@ -1944,40 +1974,41 @@ bool DwarfWalker::findConstant(Dwarf_Half attr, Address &value, Dwarf_Die entry, } bool DwarfWalker::findConstantWithForm(Dwarf_Attribute &locationAttribute, - Dwarf_Half form, - Address &value) { - value = 0; - - switch(form) { - case DW_FORM_addr: - Dwarf_Addr addr; - DWARF_FAIL_RET(dwarf_formaddr(&locationAttribute, &addr)); - value = (Address) addr; - return true; - case DW_FORM_sdata: - Dwarf_Sword s_tmp; - DWARF_FAIL_RET(dwarf_formsdata(&locationAttribute, &s_tmp)); - value = (Address) s_tmp; - dwarf_printf("Decoded data of form %x to 0x%lx\n", - form, value); - return true; - case DW_FORM_data1: - case DW_FORM_data2: - case DW_FORM_data4: - case DW_FORM_data8: - case DW_FORM_udata: - Dwarf_Word u_tmp; - DWARF_FAIL_RET(dwarf_formudata(&locationAttribute, &u_tmp)); - value = (Address) u_tmp; - return true; - case DW_FORM_sec_offset: - DWARF_FAIL_RET(dwarf_global_formref(locationAttribute, &u_tmp, NULL)); - value = (Address)(u_tmp); - return true; - default: - dwarf_printf("Unhandled form 0x%x for constant decode\n", (unsigned) form); - return false; - } + Dwarf_Half form, + Address &value) { + value = 0; + + switch(form) { + case DW_FORM_addr: + Dwarf_Addr addr; + DWARF_FAIL_RET(dwarf_formaddr(&locationAttribute, &addr)); + value = (Address) addr; + return true; + case DW_FORM_sdata: + Dwarf_Sword s_tmp; + DWARF_FAIL_RET(dwarf_formsdata(&locationAttribute, &s_tmp)); + value = (Address) s_tmp; + dwarf_printf("Decoded data of form %x to 0x%lx\n", + form, value); + return true; + case DW_FORM_data1: + case DW_FORM_data2: + case DW_FORM_data4: + case DW_FORM_data8: + case DW_FORM_udata: + Dwarf_Word u_tmp; + DWARF_FAIL_RET(dwarf_formudata(&locationAttribute, &u_tmp)); + value = (Address) u_tmp; + return true; + case DW_FORM_sec_offset: + //DWARF_FAIL_RET(dwarf_global_formref(locationAttribute, &u_tmp, NULL)); + DWARF_FAIL_RET(dwarf_formref(&locationAttribute, &u_tmp)); + value = (Address)(u_tmp); + return true; + default: + dwarf_printf("Unhandled form 0x%x for constant decode\n", (unsigned) form); + return false; + } } bool DwarfWalker::decodeConstantLocation(Dwarf_Attribute &attr, Dwarf_Half form, @@ -2295,106 +2326,117 @@ typeArray *DwarfWalker::parseMultiDimensionalArray(Dwarf_Die range, } /* end parseMultiDimensionalArray() */ bool DwarfWalker::decipherBound(Dwarf_Attribute boundAttribute, bool is_info, - std::string &boundString ) + std::string &boundString ) { - Dwarf_Half boundForm = dwarf_whatform(&boundAttribute); - DWARF_FAIL_RET(boundForm); - - switch( boundForm ) { - case DW_FORM_data1: - case DW_FORM_data2: - case DW_FORM_data4: - case DW_FORM_data8: - case DW_FORM_udata: - { - dwarf_printf("(0x%lx) Decoding form %d with formudata\n", - id(), boundForm); - - Dwarf_Word constantBound; - DWARF_FAIL_RET(dwarf_formudata( &boundAttribute, & constantBound)); - char bString[40]; - sprintf(bString, "%llu", (unsigned long long)constantBound); - boundString = bString; - return true; - } break; + Dwarf_Half boundForm = dwarf_whatform(&boundAttribute); + DWARF_FAIL_RET(boundForm); - case DW_FORM_sdata: - { - dwarf_printf("(0x%lx) Decoding form %d with formsdata\n", - id(), boundForm); - - Dwarf_Sword constantBound; - DWARF_FAIL_RET(dwarf_formsdata( &boundAttribute, & constantBound)); - char bString[40]; - sprintf(bString, "%lld", (long long)constantBound); - boundString = bString; - return true; - } break; - - case DW_FORM_ref_addr: - case DW_FORM_ref1: - case DW_FORM_ref2: - case DW_FORM_ref4: - case DW_FORM_ref8: - case DW_FORM_ref_udata: - { - /* Acquire the referenced DIE. */ - Dwarf_Off boundOffset; - DWARF_FAIL_RET(dwarf_global_formref( &boundAttribute, & boundOffset)); + switch( boundForm ) { + case DW_FORM_data1: + case DW_FORM_data2: + case DW_FORM_data4: + case DW_FORM_data8: + case DW_FORM_udata: + { + dwarf_printf("(0x%lx) Decoding form %d with formudata\n", + id(), boundForm); + + Dwarf_Word constantBound; + DWARF_FAIL_RET(dwarf_formudata( &boundAttribute, & constantBound)); + char bString[40]; + sprintf(bString, "%llu", (unsigned long long)constantBound); + boundString = bString; + return true; + } break; - Dwarf_Die boundEntry; - DWARF_FAIL_RET(dwarf_offdie_b( dbg(), boundOffset, is_info, & boundEntry, NULL )); + case DW_FORM_sdata: + { + dwarf_printf("(0x%lx) Decoding form %d with formsdata\n", + id(), boundForm); + + Dwarf_Sword constantBound; + DWARF_FAIL_RET(dwarf_formsdata( &boundAttribute, & constantBound)); + char bString[40]; + sprintf(bString, "%lld", (long long)constantBound); + boundString = bString; + return true; + } break; - /* Does it have a name? */ - if (findDieName(dbg(), boundEntry, boundString) - && !boundString.empty()) - return true; + case DW_FORM_ref_addr: + case DW_FORM_ref1: + case DW_FORM_ref2: + case DW_FORM_ref4: + case DW_FORM_ref8: + case DW_FORM_ref_udata: + { + /* Acquire the referenced DIE. */ + Dwarf_Off boundOffset; + //DWARF_FAIL_RET(dwarf_global_formref( &boundAttribute, & boundOffset)); + DWARF_FAIL_RET(dwarf_formref(&boundAttribute, &boundOffset)); + + Dwarf_Die boundEntry; + //DWARF_FAIL_RET(dwarf_offdie_b( dbg(), boundOffset, is_info, &boundEntry, NULL )); + Dwarf_Die * cu_die_p = 0; + if(is_info){ + cu_die_p = dwarf_offdie(dbg(), boundOffset, &boundEntry); + }else{ + cu_die_p = dwarf_offdie_types(dbg(), boundOffset, &boundEntry); + } + if (cu_die_p == 0) { + return false; + } - /* Does it describe a nameless constant? */ - Dwarf_Attribute constBoundAttribute; - auto status = dwarf_attr(&boundEntry, DW_AT_const_value, &constBoundAttribute); - DWARF_CHECK_RET(status == 0); + /* Does it have a name? */ + if (findDieName(dbg(), boundEntry, boundString) + && !boundString.empty()) + return true; - if ( status == 0 ) { - Dwarf_Word constBoundValue; - DWARF_FAIL_RET(dwarf_formudata( &constBoundAttribute, & constBoundValue)); + /* Does it describe a nameless constant? */ + Dwarf_Attribute constBoundAttribute; + auto status = dwarf_attr(&boundEntry, DW_AT_const_value, &constBoundAttribute); + DWARF_CHECK_RET(status == 0); - char bString[40]; - sprintf(bString, "%lu", (unsigned long)constBoundValue); - boundString = bString; + if ( status == 0 ) { + Dwarf_Word constBoundValue; + DWARF_FAIL_RET(dwarf_formudata( &constBoundAttribute, & constBoundValue)); - //dwarf_dealloc( dbg(), boundEntry, DW_DLA_DIE ); - //dwarf_dealloc( dbg(), constBoundAttribute, DW_DLA_ATTR ); - return true; - } + char bString[40]; + sprintf(bString, "%lu", (unsigned long)constBoundValue); + boundString = bString; - return false; - } break; - case DW_FORM_block: - case DW_FORM_block1: - { - /* PGI extends DWARF to allow some bounds to be location lists. Since we can't - do anything sane with them, ignore them. */ - // Dwarf_Op* * locationList; - // Dwarf_Sword listLength; - // status = dwarf_loclist( boundAttribute, & locationList, & listLength, NULL ); - boundString = "{PGI extension}"; - return false; - } break; + //dwarf_dealloc( dbg(), boundEntry, DW_DLA_DIE ); + //dwarf_dealloc( dbg(), constBoundAttribute, DW_DLA_ATTR ); + return true; + } - default: - //bperr ( "Invalid bound form 0x%x\n", boundForm ); - boundString = "{invalid bound form}"; - return false; - break; - } /* end boundForm switch */ - return true; + return false; + } break; + case DW_FORM_block: + case DW_FORM_block1: + { + /* PGI extends DWARF to allow some bounds to be location lists. Since we can't + do anything sane with them, ignore them. */ + // Dwarf_Op* * locationList; + // Dwarf_Sword listLength; + // status = dwarf_loclist( boundAttribute, & locationList, & listLength, NULL ); + boundString = "{PGI extension}"; + return false; + } break; + + default: + //bperr ( "Invalid bound form 0x%x\n", boundForm ); + boundString = "{invalid bound form}"; + return false; + break; + } /* end boundForm switch */ + return true; } -bool DwarfWalker::decodeExpression(Dwarf_Attribute &attr, +//FIXME whole function +bool DwarfWalker::decodeExpression(Dwarf_Attribute & /*attr*/, std::vector &locs) { - Dwarf_Word expr_len; - Dwarf_Ptr expr_ptr; + //Dwarf_Word expr_len; + /*Dwarf_Ptr expr_ptr; DWARF_FAIL_RET(dwarf_formexprloc(attr, &expr_len, &expr_ptr)); unsigned char *bitstream = (unsigned char *) expr_ptr; @@ -2404,13 +2446,13 @@ bool DwarfWalker::decodeExpression(Dwarf_Attribute &attr, dwarf_printf("(0x%lx) bitstream for expr has len %d\n", id(), expr_len); for (unsigned i = 0; i < expr_len; ++i) { dwarf_printf("(0x%lx) \t %#hhx\n", id(), bitstream[i]); - } + }*/ - Dwarf_Sword cnt; + Dwarf_Sword cnt = 1; Dwarf_Op* *descs; - DWARF_FAIL_RET(dwarf_loclist_from_expr_a(dbg(), expr_ptr, expr_len, addr_size, - &descs, &cnt, NULL)); + //DWARF_FAIL_RET(dwarf_loclist_from_expr_a(dbg(), expr_ptr, expr_len, addr_size, + // &descs, &cnt, NULL)); assert(cnt == 1); bool ret = decodeLocationListForStaticOffsetOrAddress(&descs, cnt, locs, NULL); @@ -2608,29 +2650,48 @@ typeId_t DwarfWalker::type_id() void DwarfWalker::findAllSig8Types() { - /* First .debug_types (0), then .debug_info (1). - * In DWARF4, only .debug_types contains DW_TAG_type_unit, - * but DWARF5 is considering them for .debug_info too.*/ - for (int i = 0; i < 2; ++i) { - bool is_info = i; - Dwarf_Error err; - compile_offset = next_cu_header = 0; - - /* Iterate over the compilation-unit headers. */ - while (dwarf_next_cu_header_c(dbg(), is_info, - &cu_header_length, - &version, - &abbrev_offset, - &addr_size, - &offset_size, - &extension_size, - &signature, - &typeoffset, - &next_cu_header, &err) == 0 ) { - parseModuleSig8(is_info); - compile_offset = next_cu_header; - } - } + /* First .debug_types (0), then .debug_info (1). + * In DWARF4, only .debug_types contains DW_TAG_type_unit, + * but DWARF5 is considering them for .debug_info too.*/ + for (int i = 0; i < 2; ++i) { + //bool is_info = i; + //Dwarf_Error err; + compile_offset = next_cu_header = 0; + + /* Iterate over the compilation-unit headers. */ + /*while (dwarf_next_cu_header_c(dbg(), is_info, + &cu_header_length, + &version, + &abbrev_offset, + &addr_size, + &offset_size, + &extension_size, + &signature, + &typeoffset, + &next_cu_header, &err) == 0 ) { + parseModuleSig8(is_info); + compile_offset = next_cu_header; + }*/ + + size_t cu_header_size = 0; + for(Dwarf_Off cu_off = 0; + dwarf_nextcu(dbg(), cu_off, &next_cu_header, &cu_header_length, + &abbrev_offset, &addr_size, &offset_size) == 0; + cu_off = next_cu_header) + { + Dwarf_Off cu_die_off = cu_off + cu_header_size; + Dwarf_Die cu_die, *cu_die_p; + if(i==0){ //.debug_types + cu_die_p = dwarf_offdie_types(dbg(), cu_die_off, &cu_die); + }else{ + cu_die_p = dwarf_offdie(dbg(), cu_die_off, &cu_die); + } + assert(cu_die_p == NULL); + + parseModuleSig8(i); + compile_offset = next_cu_header; + } + } } bool DwarfWalker::parseModuleSig8(bool is_info) @@ -2656,11 +2717,12 @@ bool DwarfWalker::parseModuleSig8(bool is_info) return false; /* typeoffset is relative to the type unit; we want the global offset. */ - Dwarf_Off cu_off, cu_length; - DWARF_FAIL_RET(dwarf_die_CU_offset_range( typeDIE, &cu_off, &cu_length, NULL )); + //FIXME + //Dwarf_Off cu_off, cu_length; + //DWARF_FAIL_RET(dwarf_die_CU_offset_range(typeDIE, &cu_off, &cu_length, NULL )); uint64_t sig8 = * reinterpret_cast(&signature); - typeId_t type_id = get_type_id(cu_off + typeoffset, is_info); + typeId_t type_id = get_type_id(/*cu_off +*/ typeoffset, is_info); sig8_type_ids_[sig8] = type_id; dwarf_printf("Mapped Sig8 {%016llx} to type id 0x%x\n", (long long) sig8, type_id); diff --git a/symtabAPI/src/dwarfWalker.h b/symtabAPI/src/dwarfWalker.h index e5b99d5489..d51b448861 100644 --- a/symtabAPI/src/dwarfWalker.h +++ b/symtabAPI/src/dwarfWalker.h @@ -327,8 +327,8 @@ class DwarfWalker : public DwarfParseActions { Dwarf_Word cu_header_length; Dwarf_Half version; Dwarf_Word abbrev_offset; - Dwarf_Half addr_size; - Dwarf_Half offset_size; + uint8_t /*Dwarf_Half*/ addr_size; + uint8_t /*Dwarf_Half*/ offset_size; Dwarf_Half extension_size; typedef struct{ diff --git a/symtabAPI/src/parseDwarf.C b/symtabAPI/src/parseDwarf.C index abcee1905e..8f9d0d6123 100644 --- a/symtabAPI/src/parseDwarf.C +++ b/symtabAPI/src/parseDwarf.C @@ -109,7 +109,7 @@ bool Object::getRegValueAtFrame(Address pc, Dyninst::MachRegisterVal ®_result, MemRegReader *reader) { - Dwarf::FrameErrors_t frame_error = Dwarf::FE_No_Error; + DwarfDyninst::FrameErrors_t frame_error = DwarfDyninst::FE_No_Error; bool result; dwarf->frame_dbg();