Skip to content

Commit

Permalink
Lots of refactoring and some optimizations. We're not saving space or…
Browse files Browse the repository at this point in the history
… time anymore but at least it's clean and we're only missing ~10k entries (down from ~100k) on nwchem.
  • Loading branch information
wrwilliams committed Oct 31, 2016
1 parent 96203ba commit 0dee1c8
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 264 deletions.
3 changes: 2 additions & 1 deletion symtabAPI/h/LineInformation.h
Expand Up @@ -94,7 +94,8 @@ class SYMTAB_EXPORT LineInformation :
(in the destructor). Note that it speeds and simplifies things
to have the string pointers be the same. */

unsigned size_;
int wasted_compares;
int num_queries;
}; /* end class LineInformation */

}//namespace SymtabAPI
Expand Down
28 changes: 16 additions & 12 deletions symtabAPI/h/Module.h
Expand Up @@ -53,7 +53,7 @@ class localVar;
class Symtab;


class SYMTAB_EXPORT Statement : public AnnotatableSparse, public Serializable
class SYMTAB_EXPORT Statement// : public AnnotatableSparse, public Serializable
{
friend class Module;
friend class std::vector<Statement>;
Expand Down Expand Up @@ -101,7 +101,6 @@ class SYMTAB_EXPORT Statement : public AnnotatableSparse, public Serializable
unsigned int getColumn() const{return column;}
AddressRange addressRange( ) const { return AddressRange(*this); }
bool contains(Offset addr) const { return addressRange().contains(addr); }
Serializable *serialize_impl(SerializerBase *sb, const char *tag = "Statement") THROW_SPEC (SerializerError);

// Does dyninst really need these?
void setLine(unsigned int l) {line_ = l;}
Expand All @@ -118,14 +117,14 @@ typedef Statement LineNoTuple;

class SYMTAB_EXPORT Module : public LookupInterface
{
friend class Symtab;

public:
#if defined(cap_dwarf)
typedef Dwarf_Die DebugInfoT;
#else
typedef void* DebugInfoT;
#endif
friend class Symtab;

public:

Module();
Module(supportedLanguages lang, Offset adr, std::string fullNm,
Expand Down Expand Up @@ -198,8 +197,8 @@ typedef Statement LineNoTuple;
bool getStatements(std::vector<Statement::ConstPtr> &statements);
LineInformation *getLineInformation();
LineInformation* parseLineInformation();
bool hasLineInformation();
bool setDefaultNamespacePrefix(std::string str);

bool setDefaultNamespacePrefix(std::string str);


// Super secret private methods that aren't really private
Expand All @@ -212,13 +211,12 @@ typedef Statement LineNoTuple;
bool setLineInfo(Dyninst::SymtabAPI::LineInformation *lineInfo);
void addRange(Dyninst::Address low, Dyninst::Address high);

void setDebugInfo(Module::DebugInfoT info) {info_is_valid_ = true; info_ = info; }
Module::DebugInfoT getDebugInfo();
private:
void setDebugInfo(Module::DebugInfoT info);

private:
Dyninst::SymtabAPI::LineInformation* lineInfo_;
typeCollection* typeInfo_;
bool info_is_valid_;
Module::DebugInfoT info_;
std::vector<Module::DebugInfoT> info_;


std::string fileName_; // short file
Expand All @@ -233,6 +231,12 @@ typedef Statement LineNoTuple;
os << m.fileName() << ": " << m.addr();
return os;
}
template <typename OS>
OS& operator<<(OS& os, Module* m)
{
os << m->fileName() << ": " << m->addr();
return os;
}


struct ModRange : public interval<Offset>
Expand Down
24 changes: 19 additions & 5 deletions symtabAPI/h/RangeLookup.h
Expand Up @@ -61,14 +61,19 @@ namespace Dyninst {
first = t;
second = t;
}
AddressRange(Offset start, Offset end)
{
first = start;
second = end;
}
bool operator==(const AddressRange& rhs) const {
return first == rhs.first && second == rhs.second;
return (first == rhs.first) && (second == rhs.second);
}
bool operator<(const AddressRange& rhs) const {
return first < rhs.first || (first == rhs.first && second < rhs.second);
return (first < rhs.first) || ((first == rhs.first) && (second < rhs.second));
}
bool contains(Offset off) const {
return first <= off && off < second;
return (first <= off) && (off < second);
}

};
Expand All @@ -77,19 +82,28 @@ namespace Dyninst {
{
struct addr_range {};
struct line_info {};
typedef typename boost::multi_index::const_mem_fun<Value, AddressRange, &Value::addressRange> addr_range_key;
struct upper_bound {};
typedef typename boost::multi_index::const_mem_fun<Value, AddressRange, &Value::addressRange>
addr_range_key;
typedef typename boost::multi_index::composite_key<Value,
boost::multi_index::const_mem_fun<Value, Offset, &Value::endAddr>,
boost::multi_index::const_mem_fun<Value, Offset, &Value::startAddr> >
upper_bound_key;
typedef typename boost::multi_index::composite_key<Value,
boost::multi_index::const_mem_fun<Value, std::string, &Value::getFile>,
boost::multi_index::const_mem_fun<Value, unsigned int, &Value::getLine> > line_info_key;
boost::multi_index::const_mem_fun<Value, unsigned int, &Value::getLine> >
line_info_key;
typedef typename boost::multi_index_container
<
typename Value::ConstPtr,
boost::multi_index::indexed_by<
boost::multi_index::ordered_unique< boost::multi_index::tag<addr_range>, addr_range_key>,
boost::multi_index::ordered_non_unique< boost::multi_index::tag<upper_bound>, upper_bound_key>,
boost::multi_index::ordered_non_unique< boost::multi_index::tag<line_info>, line_info_key >
>
> type;
typedef typename boost::multi_index::index<type, addr_range>::type addr_range_index;
typedef typename boost::multi_index::index<type, upper_bound>::type upper_bound_index;
typedef typename boost::multi_index::index<type, line_info>::type line_info_index;
typedef typename type::value_type value_type;

Expand Down
41 changes: 33 additions & 8 deletions symtabAPI/src/LineInformation.C
Expand Up @@ -37,14 +37,15 @@
#include "Serialization.h"

#include <functional>
#include <iostream>

using namespace Dyninst;
using namespace Dyninst::SymtabAPI;
using std::vector;

#include "LineInformation.h"

LineInformation::LineInformation()
LineInformation::LineInformation() : wasted_compares(0), num_queries(0)
{
} /* end LineInformation constructor */

Expand Down Expand Up @@ -84,16 +85,35 @@ bool LineInformation::addAddressRange( Offset lowInclusiveAddr,
return addLine( lineSource, lineNo, lineOffset, lowInclusiveAddr, highExclusiveAddr );
} /* end setAddressRangeToLineMapping() */


std::string print(const Dyninst::SymtabAPI::Statement& stmt)
{
std::stringstream stream;
stream << "Statement: < [" << stmt.startAddr() << ", " << stmt.endAddr() << "): " << stmt.getFile() << ":" << stmt.getLine() << " >";
return stream.str();
}


bool LineInformation::getSourceLines(Offset addressInRange,
vector<Statement_t> &lines)
{
using namespace std::placeholders;
auto start_addr_valid = lower_bound(addressInRange + 1);
std::copy_if(begin(),
start_addr_valid,
std::back_inserter(lines),
std::bind(&Statement::contains, std::placeholders::_1, addressInRange));
return start_addr_valid != begin();
++num_queries;
const_iterator start_addr_valid = project<traits::addr_range>(get<traits::upper_bound>().upper_bound(addressInRange ));
const_iterator end_addr_valid = impl_t::upper_bound(addressInRange + 1);
while(start_addr_valid != end_addr_valid)
{
if((*start_addr_valid)->contains(addressInRange))
{
lines.push_back(*start_addr_valid);
}
else
{
std::cout << print(**start_addr_valid) << " does not contain " << addressInRange << std::endl;
++wasted_compares;
}
++start_addr_valid;
}
return true;
} /* end getLinesFromAddress() */

bool LineInformation::getSourceLines( Offset addressInRange,
Expand Down Expand Up @@ -146,6 +166,11 @@ unsigned LineInformation::getSize() const

LineInformation::~LineInformation()
{
if(num_queries)
{
std::cout << "Line information with " << getSize() << " entries queried " << num_queries << " times with "
<< wasted_compares << " extra compares (" << (float)(wasted_compares) / (num_queries) << " per query)" << std::endl;
}
}

LineInformation::const_line_info_iterator LineInformation::begin_by_source() const {
Expand Down
47 changes: 23 additions & 24 deletions symtabAPI/src/Module.C
Expand Up @@ -29,6 +29,8 @@
*/

#include <string.h>
#include <common/src/debug_common.h>
#include "debug.h"

#include "Annotatable.h"
#include "Module.h"
Expand All @@ -42,6 +44,7 @@

#include "common/src/pathName.h"
#include "common/src/serialize.h"
#include "Object.h"

#if defined(cap_dwarf)
#include "dwarfWalker.h"
Expand Down Expand Up @@ -118,11 +121,6 @@ supportedLanguages Module::language() const
return language_;
}

bool Module::hasLineInformation()
{
return lineInfo_ && lineInfo_->getSize();
}

bool Module::getAddressRanges(std::vector<AddressRange >&ranges,
std::string lineSource, unsigned int lineNo)
{
Expand All @@ -143,7 +141,6 @@ bool Module::getSourceLines(std::vector<Statement::ConstPtr> &lines, Offset addr
unsigned int originalSize = lines.size();

LineInformation *lineInformation = parseLineInformation();
// cout << "Module " << fileName() << " searching for line info in " << lineInformation << endl;
if (lineInformation)
lineInformation->getSourceLines( addressInRange, lines );

Expand All @@ -170,13 +167,20 @@ bool Module::getSourceLines(std::vector<LineNoTuple> &lines, Offset addressInRan
}

LineInformation *Module::parseLineInformation() {
LineInformation *lineInformation = getLineInformation();
if (!lineInformation)
// if non-null, we're fine
if (!lineInfo_)
{
exec_->parseLineInformation();
lineInformation = getLineInformation();
return lineInformation;
lineInfo_ = new LineInformation;
}
// cout << "Parsing line info for module:" << *this << " with " << info_.size() << " CU entries set" << endl;
for(auto cu = info_.begin();
cu != info_.end();
++cu)
{
exec()->getObject()->parseLineInfoForCU(*cu, lineInfo_);
}
info_.clear();
return lineInfo_;
}

bool Module::getStatements(std::vector<LineInformation::Statement_t> &statements)
Expand Down Expand Up @@ -245,8 +249,10 @@ bool Module::findVariableType(Type *&type, std::string name)

bool Module::setLineInfo(LineInformation *lineInfo)
{
lineInfo_ = lineInfo;
return true;
assert(!lineInfo_);
//delete lineInfo_;
lineInfo_ = lineInfo;
return true;
}

LineInformation *Module::getLineInformation()
Expand Down Expand Up @@ -295,9 +301,7 @@ Module::Module() :
fullName_(""),
language_(lang_Unknown),
addr_(0),
exec_(NULL),
info_is_valid_(false),
info_(NULL) // not a default constructed whatever!
exec_(NULL)
{
}

Expand All @@ -310,7 +314,6 @@ Module::Module(const Module &mod) :
language_(mod.language_),
addr_(mod.addr_),
exec_(mod.exec_),
info_is_valid_(false),
info_(mod.info_)
{
}
Expand Down Expand Up @@ -417,14 +420,10 @@ bool Module::findVariablesByName(std::vector<Variable *> &ret, const std::string

void Module::addRange(Dyninst::Address low, Dyninst::Address high)
{

exec_->mod_lookup()->insert(new ModRange(low, high, this));
}

Module::DebugInfoT Module::getDebugInfo()
{
if(!info_is_valid_) {
exec_->parseTypesNow();
}
return info_;
void Module::setDebugInfo(Module::DebugInfoT info) {
// cout << "Adding DIE to module:" << *this << endl;
info_.push_back(info);
}

0 comments on commit 0dee1c8

Please sign in to comment.