Skip to content

Commit

Permalink
Line info fixes: nwchem is now running clean. There's a good bit of r…
Browse files Browse the repository at this point in the history
…oom for performance improvements (notably in ensuring that we don't have redundant module intervals).
  • Loading branch information
wrwilliams committed Oct 31, 2016
1 parent 0dee1c8 commit 4e4a375
Show file tree
Hide file tree
Showing 18 changed files with 524 additions and 273 deletions.
2 changes: 1 addition & 1 deletion cmake/warnings.cmake
@@ -1,6 +1,6 @@
if (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_C_COMPILER_ID} MATCHES INTEL)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W -Wall -Wpointer-arith -Wcast-qual -Wcast-align")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wpointer-arith -Wcast-qual -Woverloaded-virtual -Wcast-align -Wno-non-template-friend -Wno-unused-local-typedefs")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wpointer-arith -Wcast-qual -Woverloaded-virtual -Wcast-align -Wno-non-template-friend -Wno-unused-local-typedefs -Wno-deprecated-declarations")
elseif (${CMAKE_C_COMPILER_ID} MATCHES Clang)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W -Wall -Wpointer-arith -Wcast-qual")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -Wpointer-arith -Wcast-qual -Woverloaded-virtual")
Expand Down
4 changes: 2 additions & 2 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::ConstPtr> lines_ll;
std::vector<Statement::Ptr> lines_ll;

Module *stmod = mod->pmod()->mod();
assert(stmod);
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::ConstPtr> statements_ll;
std::vector<SymtabAPI::Statement::Ptr> statements_ll;

if (!stmod->getStatements(statements_ll))
{
Expand Down
24 changes: 19 additions & 5 deletions symtabAPI/h/LineInformation.h
Expand Up @@ -45,8 +45,7 @@ namespace SymtabAPI{
class SYMTAB_EXPORT LineInformation :
private RangeLookupTypes< Statement >::type
{
bool addItem_impl(Statement);
public:
public:
typedef RangeLookupTypes< Statement> traits;
typedef RangeLookupTypes< Statement >::type impl_t;
typedef traits::addr_range_index::const_iterator const_iterator;
Expand All @@ -55,11 +54,16 @@ class SYMTAB_EXPORT LineInformation :
LineInformation();

/* You MAY freely deallocate the lineSource strings you pass in. */
bool addLine( const char * lineSource,
bool addLine( std::string lineSource,
unsigned int lineNo,
unsigned int lineOffset,
Offset lowInclusiveAddr,
Offset highExclusiveAddr );
bool addLine( unsigned int fileIndex,
unsigned int lineNo,
unsigned int lineOffset,
Offset lowInclusiveAddr,
Offset highExclusiveAddr );

void addLineInfo(LineInformation *lineInfo);

Expand Down Expand Up @@ -94,9 +98,19 @@ class SYMTAB_EXPORT LineInformation :
(in the destructor). Note that it speeds and simplifies things
to have the string pointers be the same. */

int wasted_compares;
StringTablePtr strings_;
public:
StringTablePtr getStrings() ;

void setStrings(StringTablePtr strings_);

protected:
int wasted_compares;
int num_queries;
}; /* end class LineInformation */
};


/* end class LineInformation */

}//namespace SymtabAPI
}//namespace Dyninst
Expand Down
88 changes: 59 additions & 29 deletions symtabAPI/h/Module.h
Expand Up @@ -44,6 +44,8 @@
#include <boost/shared_ptr.hpp>
#include "RangeLookup.h"

#include "StringTable.h"

namespace Dyninst{
namespace SymtabAPI{

Expand All @@ -53,64 +55,78 @@ class localVar;
class Symtab;


class SYMTAB_EXPORT Statement// : public AnnotatableSparse, public Serializable
class SYMTAB_EXPORT Statement
{
friend class Module;
friend class std::vector<Statement>;
friend class LineInformation;
Statement(const char *file, unsigned int line, unsigned int col = 0,
Statement(int file_index, unsigned int line, unsigned int col = 0,
Offset start_addr = (Offset) -1L, Offset end_addr = (Offset) -1L) :
file_(file),
file_index_(file_index),
line_(line),
column_(col),
start_addr_(start_addr),
end_addr_(end_addr),
first(file_),
second(line_),
column(col)
end_addr_(end_addr)
{
}

const char* file_; // Maybe this should be module?
unsigned int file_index_; // Maybe this should be module?
unsigned int line_;
unsigned int column_;
Offset start_addr_;
Offset end_addr_;
StringTablePtr strings_;
public:
StringTablePtr getStrings_() const;

public:
// DEPRECATED. First and second need to die, and column should become an accessor.
// Duplication of data is both bad and stupid, okay?
const char *first;
unsigned int second;
unsigned int column;
void setStrings_(StringTablePtr strings_);

Statement() : first(NULL), second(0) {}
public:

Statement() : file_index_(0), line_(0), column_(0), start_addr_(0), end_addr_(0) {}
struct StatementLess {
bool operator () ( const Statement &lhs, const Statement &rhs ) const;
};

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(); }
// bool operator==(const char* file) const {return strcmp(file, first) == 0; }
bool operator==(Offset addr) const {
if(startAddr() == endAddr()) {
return addr == startAddr();
}
return (startAddr() <= addr) && (addr < endAddr());
}
~Statement() {}

Offset startAddr() const { return start_addr_;}
Offset endAddr() const {return end_addr_;}
std::string getFile() const { return file_;}
std::string getFile() const;
unsigned int getFileIndex() const { return file_index_; }
unsigned int getLine()const {return line_;}
unsigned int getColumn() const{return column;}
unsigned int getColumn() const { return column_; }
AddressRange addressRange( ) const { return AddressRange(*this); }
bool contains(Offset addr) const { return addressRange().contains(addr); }

// Does dyninst really need these?
void setLine(unsigned int l) {line_ = l;}
void setColumn(unsigned int l) {column = l;}
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;

};
template <typename OS>
OS& operator<<(OS& os, const Statement& s)
{
os << "<statement>: [" << s.startAddr() << ", " << s.endAddr() << ") @ " << s.getFile()
<< " (" << s.getFileIndex() << "): " << s.getLine();
return os;
}
template <typename OS>
OS& operator<<(OS& os, Statement* s)
{
os << "<statement>: [" << s->startAddr() << ", " << s->endAddr() << ") @ " << s->getFile()
<< " (" << s->getFileIndex() << "): " << s->getLine();
return os;
}


typedef Statement LineNoTuple;
#define MODULE_ANNOTATABLE_CLASS AnnotatableSparse
Expand Down Expand Up @@ -190,11 +206,11 @@ typedef Statement LineNoTuple;
/***** Line Number Information *****/
bool getAddressRanges(std::vector<AddressRange >&ranges,
std::string lineSource, unsigned int LineNo);
bool getSourceLines(std::vector<Statement::ConstPtr> &lines,
bool getSourceLines(std::vector<Statement::Ptr> &lines,
Offset addressInRange);
bool getSourceLines(std::vector<LineNoTuple> &lines,
Offset addressInRange);
bool getStatements(std::vector<Statement::ConstPtr> &statements);
bool getStatements(std::vector<Statement::Ptr> &statements);
LineInformation *getLineInformation();
LineInformation* parseLineInformation();

Expand All @@ -212,7 +228,7 @@ typedef Statement LineNoTuple;
void addRange(Dyninst::Address low, Dyninst::Address high);

void setDebugInfo(Module::DebugInfoT info);

void finalizeRanges();
private:
Dyninst::SymtabAPI::LineInformation* lineInfo_;
typeCollection* typeInfo_;
Expand All @@ -224,6 +240,8 @@ typedef Statement LineNoTuple;
supportedLanguages language_;
Offset addr_; // starting address of module
Symtab *exec_;
std::vector<std::pair< Dyninst::Address, Dyninst::Address> > ranges;
bool ranges_finalized;
};
template <typename OS>
OS& operator<<(OS& os, const Module& m)
Expand Down Expand Up @@ -252,6 +270,18 @@ struct ModRange : public interval<Offset>
Module* mod_;
};

template <typename OS>
OS& operator<<(OS& os, const ModRange& m)
{
os << m.mod() << ": [" << m.low() << ", " << m.high() << ")";
return os;
}
template <typename OS>
OS& operator<<(OS& os, ModRange* m)
{
os << *m;
return os;
}

}//namespace SymtabAPI

Expand Down
4 changes: 2 additions & 2 deletions symtabAPI/h/RangeLookup.h
Expand Up @@ -90,12 +90,12 @@ namespace Dyninst {
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::getFileIndex>,
boost::multi_index::const_mem_fun<Value, unsigned int, &Value::getLine> >
line_info_key;
typedef typename boost::multi_index_container
<
typename Value::ConstPtr,
typename Value::Ptr,
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>,
Expand Down
41 changes: 41 additions & 0 deletions symtabAPI/h/StringTable.h
@@ -0,0 +1,41 @@
//
// Created by bill on 8/29/16.
//

#ifndef DYNINST_STRINGTABLE_H
#define DYNINST_STRINGTABLE_H

#include <boost/shared_ptr.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/random_access_index.hpp>
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/ordered_index.hpp>

namespace Dyninst {
namespace SymtabAPI {
struct StringTableEntry {
std::string str;
StringTableEntry(const char* s) : str(s) {}
StringTableEntry(std::string s) : str(s) {}
bool operator==(std::string s) const {
return s == str ||
s == str.substr(str.rfind("/"));
}
};
typedef boost::multi_index_container<StringTableEntry,
boost::multi_index::indexed_by<
boost::multi_index::random_access<>,
boost::multi_index::ordered_non_unique<
boost::multi_index::member<StringTableEntry, const std::string, &StringTableEntry::str>
>
>
> StringTable;

typedef boost::shared_ptr<StringTable> StringTablePtr;

}
}



#endif //DYNINST_STRINGTABLE_H
2 changes: 1 addition & 1 deletion symtabAPI/h/Symtab.h
Expand Up @@ -255,7 +255,7 @@ class SYMTAB_EXPORT Symtab : public LookupInterface,
/***** Line Number Information *****/
bool getAddressRanges(std::vector<AddressRange> &ranges,
std::string lineSource, unsigned int LineNo);
bool getSourceLines(std::vector<Statement::ConstPtr> &lines,
bool getSourceLines(std::vector<Statement::Ptr> &lines,
Offset addressInRange);
bool getSourceLines(std::vector<LineNoTuple> &lines,
Offset addressInRange);
Expand Down

0 comments on commit 4e4a375

Please sign in to comment.