Skip to content

Commit

Permalink
Correctly propagate pc ranges for blocks and local variables (#1226)
Browse files Browse the repository at this point in the history
- fix valid pc address ranges for local variables that are declared in a
  sub-block (brace, try and catch blocks) of their function
- fix Context class's constructors so they correctly initialize and copy
  all member (use in-class initialize and default constructors)
  • Loading branch information
kupsch authored Mar 21, 2022
1 parent 0a0ff09 commit 8454ff5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
16 changes: 16 additions & 0 deletions symtabAPI/src/dwarfWalker.C
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,12 @@ bool DwarfWalker::parse_int(Dwarf_Die e, bool parseSib, bool dissociate_context)
case DW_TAG_lexical_block:
ret = parseLexicalBlock();
break;
case DW_TAG_try_block:
ret = parseTryBlock();
break;
case DW_TAG_catch_block:
ret = parseCatchBlock();
break;
case DW_TAG_common_block:
ret = parseCommonBlock();
break;
Expand Down Expand Up @@ -859,6 +865,16 @@ bool DwarfWalker::parseLexicalBlock() {
return parseRangeTypes(dbg(), entry());
}

bool DwarfWalker::parseTryBlock() {
dwarf_printf("(0x%lx) Parsing try block ranges\n", id());
return parseRangeTypes(dbg(), entry());
}

bool DwarfWalker::parseCatchBlock() {
dwarf_printf("(0x%lx) Parsing catch block ranges\n", id());
return parseRangeTypes(dbg(), entry());
}

bool DwarfWalker::parseCommonBlock() {
dwarf_printf("(0x%lx) Parsing common block\n", id());

Expand Down
45 changes: 14 additions & 31 deletions symtabAPI/src/dwarfWalker.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,37 +98,18 @@ class DwarfParseActions {
typedef boost::shared_ptr<std::vector<std::pair<Address, Address> > > range_set_ptr;
private:
struct Context {
FunctionBase *func;
boost::shared_ptr<Type> commonBlock;
boost::shared_ptr<Type> enumType;
boost::shared_ptr<Type> enclosure;
bool parseSibling;
bool parseChild;
Dwarf_Die offset;
Dwarf_Die specEntry;
Dwarf_Die abstractEntry;
unsigned int tag;
Address base;
range_set_ptr ranges;
Context() :
func(NULL), commonBlock(NULL),
enumType(NULL), enclosure(NULL),
parseSibling(true), parseChild(true),
tag(0), base(0) {
}
Context(const Context& o) noexcept :
func(o.func),
commonBlock(o.commonBlock),
enumType(o.enumType),
enclosure(o.enclosure),
parseSibling(o.parseSibling),
parseChild(o.parseChild),
offset(o.offset),
specEntry(o.specEntry),
abstractEntry(o.specEntry),
tag(o.tag),
base(o.base)
{}
FunctionBase *func{};
boost::shared_ptr<Type> commonBlock{};
boost::shared_ptr<Type> enumType{};
boost::shared_ptr<Type> enclosure{};
bool parseSibling{true};
bool parseChild{true};
Dwarf_Die offset{};
Dwarf_Die specEntry{};
Dwarf_Die abstractEntry{};
unsigned int tag{};
Address base{};
range_set_ptr ranges{};
};

std::stack<Context> c;
Expand Down Expand Up @@ -290,6 +271,8 @@ class DwarfWalker : public DwarfParseActions {

bool parseSubprogram(inline_t func_type);
bool parseLexicalBlock();
bool parseTryBlock();
bool parseCatchBlock();
bool parseRangeTypes(Dwarf* dbg, Dwarf_Die die);
bool parseCommonBlock();
bool parseConstant();
Expand Down

0 comments on commit 8454ff5

Please sign in to comment.