Skip to content

Commit

Permalink
Gut RangeLookup and replace with boost::multi_index_container as our …
Browse files Browse the repository at this point in the history
…line information implementation. Still has some obvious performance problems, but appears to work.
  • Loading branch information
wrwilliams committed Oct 31, 2016
1 parent 1e603c4 commit 96203ba
Show file tree
Hide file tree
Showing 15 changed files with 263 additions and 604 deletions.
3 changes: 2 additions & 1 deletion dyninstAPI/h/BPatch_addressSpace.h
Expand Up @@ -63,6 +63,7 @@ namespace Dyninst {
};
namespace SymtabAPI {
class Symbol;
class AddressRange;
};
}

Expand Down Expand Up @@ -318,7 +319,7 @@ class BPATCH_DLL_EXPORT BPatch_addressSpace {
//
// Method that retrieves address range(s) for a given filename and line number.

bool getAddressRanges(const char * fileName, unsigned int lineNo, std::vector< std::pair< unsigned long, unsigned long > > & ranges );
bool getAddressRanges(const char * fileName, unsigned int lineNo, std::vector< Dyninst::SymtabAPI::AddressRange> & ranges );

typedef std::vector<std::pair<unsigned long, unsigned long> >::const_iterator arange_iter;
statement_iter getAddressRanges_begin(const char* file, unsigned long line);
Expand Down
5 changes: 4 additions & 1 deletion dyninstAPI/h/BPatch_image.h
Expand Up @@ -65,6 +65,9 @@ class BPatch_image;
class BPatch_object_getMod;

namespace Dyninst {
namespace SymtabAPI {
class AddressRange;
}
namespace PatchAPI {
class PatchMgr;
typedef boost::shared_ptr<PatchMgr> PatchMgrPtr;
Expand Down Expand Up @@ -242,7 +245,7 @@ class BPATCH_DLL_EXPORT BPatch_image: public BPatch_sourceObj {
// method to retrieve addresses corresponding to a line in a file

bool getAddressRanges( const char * fileName, unsigned int lineNo,
std::vector<std::pair<unsigned long, unsigned long> > & ranges );
std::vector<Dyninst::SymtabAPI::AddressRange > & ranges );

bool getSourceLines( unsigned long addr, BPatch_Vector<BPatch_statement> & lines );

Expand Down
4 changes: 3 additions & 1 deletion dyninstAPI/h/BPatch_module.h
Expand Up @@ -62,6 +62,7 @@ class BPatch_object;
namespace Dyninst {
namespace SymtabAPI {
class Module;
class AddressRange;
BPATCH_DLL_EXPORT Module *convert(const BPatch_module *);
}
namespace PatchAPI {
Expand Down Expand Up @@ -230,7 +231,8 @@ class BPATCH_DLL_EXPORT BPatch_module: public BPatch_sourceObj{
// function to get addresses for a line of the module
// if fileName is NULL, uses the name of the module

bool getAddressRanges( const char * fileName, unsigned int lineNo, std::vector< std::pair< unsigned long, unsigned long > > & ranges );
bool getAddressRanges(const char *fileName, unsigned int lineNo,
std::vector<Dyninst::SymtabAPI::AddressRange > &ranges);

// BPatch_module::getSourceLines
//
Expand Down
6 changes: 4 additions & 2 deletions dyninstAPI/h/BPatch_statement.h
Expand Up @@ -32,12 +32,14 @@
#define _BPATCH_STATEMENT_H_

#include "BPatch_dll.h"
#include <boost/shared_ptr.hpp>

class BPatch_module;

namespace Dyninst {
namespace SymtabAPI {
class Statement;
typedef boost::shared_ptr<const Statement> StatementConstPtr;
}
}

Expand Down Expand Up @@ -79,10 +81,10 @@ class BPATCH_DLL_EXPORT BPatch_statement
private:

// Full parameter ctor -- can only built by friend classes
BPatch_statement(BPatch_module *mod, Dyninst::SymtabAPI::Statement *s);
BPatch_statement(BPatch_module *mod, Dyninst::SymtabAPI::StatementConstPtr s);

BPatch_module *module_;
Dyninst::SymtabAPI::Statement *statement;
Dyninst::SymtabAPI::StatementConstPtr statement;
};

#endif
Expand Down
2 changes: 1 addition & 1 deletion dyninstAPI/src/BPatch_addressSpace.C
Expand Up @@ -538,7 +538,7 @@ bool BPatch_addressSpace::revertWrapFunction(BPatch_function *original)

bool BPatch_addressSpace::getAddressRanges( const char * fileName,
unsigned int lineNo,
std::vector< std::pair< unsigned long, unsigned long > > & ranges )
std::vector< SymtabAPI::AddressRange > & ranges )
{
unsigned int originalSize = ranges.size();
image->getAddressRanges(fileName, lineNo, ranges);
Expand Down
2 changes: 1 addition & 1 deletion dyninstAPI/src/BPatch_image.C
Expand Up @@ -872,7 +872,7 @@ bool BPatch_image::getSourceLines(unsigned long addr,

bool BPatch_image::getAddressRanges( const char * lineSource,
unsigned int lineNo,
std::vector< std::pair<unsigned long, unsigned long> > & ranges )
std::vector< SymtabAPI::AddressRange > & ranges )
{
unsigned int originalSize = ranges.size();

Expand Down
12 changes: 6 additions & 6 deletions dyninstAPI/src/BPatch_module.C
Expand Up @@ -678,7 +678,7 @@ bool BPatch_module::getSourceLines(unsigned long addr,
}

unsigned int originalSize = lines.size();
std::vector<Statement *> lines_ll;
std::vector<Statement::ConstPtr> lines_ll;

Module *stmod = mod->pmod()->mod();
assert(stmod);
Expand All @@ -690,7 +690,7 @@ bool BPatch_module::getSourceLines(unsigned long addr,

for (unsigned int j = 0; j < lines_ll.size(); ++j)
{
Statement *t = lines_ll[j];
Statement::ConstPtr t = lines_ll[j];
lines.push_back(BPatch_statement(this, t));
}

Expand All @@ -702,7 +702,7 @@ bool BPatch_module::getStatements(BPatch_Vector<BPatch_statement> &statements)
// Iterate over each address range in the line information
SymtabAPI::Module *stmod = mod->pmod()->mod();
assert(stmod);
std::vector<SymtabAPI::Statement *> statements_ll;
std::vector<SymtabAPI::Statement::ConstPtr> statements_ll;

if (!stmod->getStatements(statements_ll))
{
Expand All @@ -714,7 +714,7 @@ bool BPatch_module::getStatements(BPatch_Vector<BPatch_statement> &statements)
// Form a BPatch_statement object for this entry
// Note: Line information stores offsets, so we need to adjust to
// addresses
SymtabAPI::Statement *stm = statements_ll[i];
SymtabAPI::Statement::ConstPtr stm = statements_ll[i];
BPatch_statement statement(this, stm);

// Add this statement
Expand All @@ -725,8 +725,8 @@ bool BPatch_module::getStatements(BPatch_Vector<BPatch_statement> &statements)

}

bool BPatch_module::getAddressRanges( const char * fileName,
unsigned int lineNo, std::vector< std::pair< Address, Address > > & ranges )
bool BPatch_module::getAddressRanges(const char *fileName,
unsigned int lineNo, std::vector<SymtabAPI::AddressRange > &ranges)
{
unsigned int starting_size = ranges.size();

Expand Down
2 changes: 1 addition & 1 deletion dyninstAPI/src/BPatch_statement.C
Expand Up @@ -33,7 +33,7 @@
#include "Module.h"
#include "mapped_object.h"
#include "mapped_module.h"
BPatch_statement::BPatch_statement(BPatch_module *mod, Dyninst::SymtabAPI::Statement *s) :
BPatch_statement::BPatch_statement(BPatch_module *mod, Dyninst::SymtabAPI::Statement::ConstPtr s) :
module_(mod),
statement(s)
{
Expand Down
24 changes: 16 additions & 8 deletions symtabAPI/h/LineInformation.h
Expand Up @@ -43,13 +43,15 @@ namespace Dyninst{
namespace SymtabAPI{

class SYMTAB_EXPORT LineInformation :
private RangeLookup< Statement, Statement::StatementLess >
private RangeLookupTypes< Statement >::type
{
bool addItem_impl(Statement);
public:
typedef RangeLookup< Statement, Statement::StatementLess >::const_iterator const_iterator;
typedef RangeLookup< Statement, Statement::StatementLess >::AddressRange AddressRange;

typedef RangeLookupTypes< Statement> traits;
typedef RangeLookupTypes< Statement >::type impl_t;
typedef traits::addr_range_index::const_iterator const_iterator;
typedef traits::line_info_index::const_iterator const_line_info_iterator;
typedef traits::value_type Statement_t;
LineInformation();

/* You MAY freely deallocate the lineSource strings you pass in. */
Expand All @@ -68,13 +70,19 @@ class SYMTAB_EXPORT LineInformation :
unsigned int lineOffset = 0 );

/* You MUST NOT deallocate the strings returned. */
bool getSourceLines( Offset addressInRange, std::vector< Statement *> & lines );
bool getSourceLines( Offset addressInRange, std::vector< LineNoTuple > & lines);
bool getSourceLines(Offset addressInRange, std::vector<Statement_t> &lines);
bool getSourceLines(Offset addressInRange, std::vector<Statement> &lines);

bool getAddressRanges( const char * lineSource, unsigned int LineNo, std::vector< AddressRange > & ranges );
const_line_info_iterator begin_by_source() const;
const_line_info_iterator end_by_source() const;
std::pair<const_line_info_iterator, const_line_info_iterator> equal_range(std::string file,
const unsigned int lineNo) const;
std::pair<const_line_info_iterator, const_line_info_iterator> equal_range(std::string file) const;
const_iterator begin() const;
const_iterator end() const;
const_iterator find(Offset addressInRange) const;

virtual const_iterator begin() const;
virtual const_iterator end() const;
unsigned getSize() const;

virtual ~LineInformation();
Expand Down
29 changes: 18 additions & 11 deletions symtabAPI/h/Module.h
Expand Up @@ -41,6 +41,8 @@
#if defined(cap_dwarf)
#include "libdwarf.h"
#endif
#include <boost/shared_ptr.hpp>
#include "RangeLookup.h"

namespace Dyninst{
namespace SymtabAPI{
Expand All @@ -50,12 +52,12 @@ class LineInformation;
class localVar;
class Symtab;


class SYMTAB_EXPORT Statement : public AnnotatableSparse, public Serializable
{
friend class Module;
friend class std::vector<Statement>;
friend class LineInformation;

Statement(const char *file, unsigned int line, unsigned int col = 0,
Offset start_addr = (Offset) -1L, Offset end_addr = (Offset) -1L) :
file_(file),
Expand Down Expand Up @@ -88,14 +90,17 @@ class SYMTAB_EXPORT Statement : public AnnotatableSparse, public Serializable
typedef StatementLess LineNoTupleLess;

bool operator==(const Statement &cmp) const;
bool operator==(const char* file) const {return strcmp(file, first) == 0; }
bool operator==(Offset addr) const {return startAddr() <= addr && addr < endAddr(); }
~Statement() {}

Offset startAddr() { return start_addr_;}
Offset endAddr() {return end_addr_;}
std::string getFile() { return file_;}
unsigned int getLine() {return line_;}
unsigned int getColumn() {return column;}

Offset startAddr() const { return start_addr_;}
Offset endAddr() const {return end_addr_;}
std::string getFile() const { return file_;}
unsigned int getLine()const {return line_;}
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?
Expand All @@ -104,6 +109,8 @@ class SYMTAB_EXPORT Statement : public AnnotatableSparse, public Serializable
void setFile(const char * l) {file_ = l; first = file_;}
void setStartAddr(Offset l) {start_addr_ = l;}
void setEndAddr(Offset l) {end_addr_ = l;}
typedef boost::shared_ptr<Statement> Ptr;
typedef boost::shared_ptr<const Statement> ConstPtr;
};

typedef Statement LineNoTuple;
Expand Down Expand Up @@ -182,15 +189,15 @@ typedef Statement LineNoTuple;
bool findLocalVariable(std::vector<localVar *>&vars, std::string name);

/***** Line Number Information *****/
bool getAddressRanges(std::vector<std::pair<Offset, Offset> >&ranges,
bool getAddressRanges(std::vector<AddressRange >&ranges,
std::string lineSource, unsigned int LineNo);
bool getSourceLines(std::vector<Statement *> &lines,
bool getSourceLines(std::vector<Statement::ConstPtr> &lines,
Offset addressInRange);
bool getSourceLines(std::vector<LineNoTuple> &lines,
Offset addressInRange);
bool getStatements(std::vector<Statement *> &statements);
bool getStatements(std::vector<Statement::ConstPtr> &statements);
LineInformation *getLineInformation();

LineInformation* parseLineInformation();
bool hasLineInformation();
bool setDefaultNamespacePrefix(std::string str);

Expand Down

0 comments on commit 96203ba

Please sign in to comment.