Skip to content

Commit

Permalink
Added interface for line info find-with-hint.
Browse files Browse the repository at this point in the history
Fixed dwarfWalker bug where we doubled up on compensating for one-based indexing.
dwarfWalker now uses/fills a Module's stringtable directly.
StringTables now streamable for debugging.
Inlines use string table entries for filenames.
  • Loading branch information
wrwilliams committed Oct 19, 2016
1 parent 8697646 commit 5a8fac5
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 76 deletions.
2 changes: 1 addition & 1 deletion common/src/debug_common.h
Expand Up @@ -34,7 +34,7 @@
#include <string>
#include "util.h"

extern int common_debug_dwarf;
COMMON_EXPORT extern int common_debug_dwarf;
extern int common_debug_addrtranslate;

#if defined(__GNUC__)
Expand Down
3 changes: 2 additions & 1 deletion symtabAPI/h/Function.h
Expand Up @@ -198,8 +198,9 @@ class SYMTAB_EXPORT InlinedFunction : public FunctionBase
virtual std::string getName() const;
virtual Offset getOffset() const;
virtual unsigned getSize() const;
void setFile(std::string filename);
private:
const char* callsite_file;
int callsite_file_number;
Dyninst::Offset callsite_line;
std::string name_;
Module* module_;
Expand Down
10 changes: 2 additions & 8 deletions symtabAPI/h/LineInformation.h
Expand Up @@ -86,19 +86,13 @@ class SYMTAB_EXPORT LineInformation :
const_iterator begin() const;
const_iterator end() const;
const_iterator find(Offset addressInRange) const;
const_iterator find(Offset addressInRange, const_iterator hint) const;

unsigned getSize() const;

virtual ~LineInformation();

StringTablePtr strings_;
protected:
/* We maintain internal copies of all the source file names. Because
both directions of the mapping include pointers to these names,
maintain a separate list of them, and only ever deallocate those
(in the destructor). Note that it speeds and simplifies things
to have the string pointers be the same. */

StringTablePtr strings_;
public:
StringTablePtr getStrings() ;

Expand Down
14 changes: 13 additions & 1 deletion symtabAPI/h/Module.h
Expand Up @@ -96,6 +96,12 @@ class SYMTAB_EXPORT Statement
return addr == startAddr();
}
return (startAddr() <= addr) && (addr < endAddr());
}
bool operator<(Offset addr) const {
return startAddr() <= addr;
}
bool operator>(Offset addr) const {
return !((*this) < addr || (*this == addr));
}
~Statement() {}

Expand Down Expand Up @@ -229,7 +235,7 @@ typedef Statement LineNoTuple;

void setDebugInfo(Module::DebugInfoT info);
void finalizeRanges();
private:
private:
Dyninst::SymtabAPI::LineInformation* lineInfo_;
typeCollection* typeInfo_;
std::vector<Module::DebugInfoT> info_;
Expand All @@ -241,6 +247,12 @@ typedef Statement LineNoTuple;
Offset addr_; // starting address of module
Symtab *exec_;
std::set<AddressRange > ranges;

StringTablePtr strings_;
public:
StringTablePtr & getStrings() ;

private:
bool ranges_finalized;

void finalizeOneRange(Address ext_s, Address ext_e) const;
Expand Down
18 changes: 18 additions & 0 deletions symtabAPI/h/StringTable.h
Expand Up @@ -32,6 +32,24 @@ namespace Dyninst {
> StringTable;

typedef boost::shared_ptr<StringTable> StringTablePtr;
template <typename os>
os& operator<<(os& s, StringTableEntry e)
{
s << e.str;
return s;
}

template <typename os>
os& operator<<(os& stream, const StringTable& tbl)
{
for(int i = 0; i < tbl.size(); ++i)
{
stream << tbl[i] << " @ " << i << std::endl;
}
return stream;
}



}
}
Expand Down
18 changes: 14 additions & 4 deletions symtabAPI/src/Function.C
Expand Up @@ -209,10 +209,11 @@ bool FunctionBase::setFramePtr(vector<VariableLocation> *locs)

std::pair<std::string, Dyninst::Offset> InlinedFunction::getCallsite()
{
if(callsite_file) {
return make_pair(callsite_file, callsite_line);
std::string callsite_file = "<unknown>";
if(callsite_file_number > 0 && callsite_file_number < module_->getStrings()->size()) {
callsite_file = (*module_->getStrings())[callsite_file_number].str;
}
return make_pair("<UNKNOWN FILE>", callsite_line);
return make_pair(callsite_file, callsite_line);
}

void FunctionBase::expandLocation(const VariableLocation &loc,
Expand Down Expand Up @@ -431,7 +432,7 @@ bool FunctionBase::operator==(const FunctionBase &f)

InlinedFunction::InlinedFunction(FunctionBase *parent) :
FunctionBase(),
callsite_file(NULL),
callsite_file_number(0),
callsite_line(0),
module_(parent->getModule())
{
Expand Down Expand Up @@ -476,6 +477,15 @@ unsigned InlinedFunction::getSize() const
return functionSize_;//inline_parent->getSize();
}

void InlinedFunction::setFile(string filename) {
StringTablePtr strs = module_->getStrings();
// This looks gross, but here's what it does:
// Get index 1 (unique by name). Insert the filename on that index (which defaults to push_back if empty).
// Returns an <iterator, bool>; get the iterator (we don't care if it's new). Project to random access (index 0).
// Difference from begin == array index in string table.
callsite_file_number = strs->project<0>(strs->get<1>().insert(filename).first) - strs->begin();
}

Module* Function::getModule() const {
return module_;
}
10 changes: 10 additions & 0 deletions symtabAPI/src/LineInformation.C
Expand Up @@ -217,5 +217,15 @@ void LineInformation::setStrings(StringTablePtr strings_) {
LineInformation::strings_ = strings_;
}

LineInformation::const_iterator LineInformation::find(Offset addressInRange, const_iterator hint) const {
while(hint != end())
{
if((**hint) == addressInRange) return hint;
if((**hint) > addressInRange) break;
++hint;
}
return find(addressInRange);
}

/* end LineInformation destructor */

16 changes: 13 additions & 3 deletions symtabAPI/src/Module.C
Expand Up @@ -193,6 +193,8 @@ LineInformation *Module::parseLineInformation() {
if (!lineInfo_)
{
lineInfo_ = new LineInformation;
// share our string table
lineInfo_->setStrings(strings_);
}
// Parse any CUs that have been added to our list
if(!info_.empty()) {
Expand Down Expand Up @@ -321,7 +323,8 @@ Module::Module(supportedLanguages lang, Offset adr,
language_(lang),
addr_(adr),
exec_(img),
ranges_finalized(false)
ranges_finalized(false),
strings_(new StringTable)
{
fileName_ = extract_pathname_tail(fullNm);
}
Expand All @@ -334,7 +337,8 @@ Module::Module() :
language_(lang_Unknown),
addr_(0),
exec_(NULL),
ranges_finalized(false)
ranges_finalized(false),
strings_(new StringTable)
{
}

Expand All @@ -348,7 +352,8 @@ Module::Module(const Module &mod) :
addr_(mod.addr_),
exec_(mod.exec_),
info_(mod.info_),
ranges_finalized(mod.ranges_finalized)
ranges_finalized(mod.ranges_finalized),
strings_(mod.strings_)

{
}
Expand Down Expand Up @@ -524,3 +529,8 @@ void Module::finalizeOneRange(Address ext_s, Address ext_e) const {
void Module::setDebugInfo(Module::DebugInfoT info) {
info_.push_back(info);
}

StringTablePtr & Module::getStrings() {
return strings_;
}

2 changes: 0 additions & 2 deletions symtabAPI/src/Object-elf.C
Expand Up @@ -4485,8 +4485,6 @@ void Object::parseTypeInfo()
if(!typeInfo) return;
DwarfWalker walker(associated_symtab, *typeInfo);
walker.parse();
freeList.push_back(walker.getFreeList());
// freeList = walker.getFreeList();
#if defined(TIMED_PARSE)
struct timeval endtime;
gettimeofday(&endtime, NULL);
Expand Down

0 comments on commit 5a8fac5

Please sign in to comment.