Skip to content

Commit

Permalink
Some initial DWARF parallelism
Browse files Browse the repository at this point in the history
  • Loading branch information
wrwilliams committed Sep 27, 2017
1 parent 9157d8a commit a8def5c
Show file tree
Hide file tree
Showing 13 changed files with 178 additions and 211 deletions.
21 changes: 4 additions & 17 deletions common/src/linuxKludges.C
Expand Up @@ -199,26 +199,23 @@ unsigned long long PDYN_mulMillion(unsigned long long in) {
return result;
}

#if defined(cap_gnu_demangler)
#include <cxxabi.h>
using namespace abi;
#endif

char * P_cplus_demangle( const char * symbol, bool nativeCompiler,
bool includeTypes )
{
static char* last_symbol = NULL;
static bool last_native = false;
static bool last_typed = false;
static char* last_demangled = NULL;
static __thread char* last_symbol = NULL;
static __thread bool last_native = false;
static __thread bool last_typed = false;
static __thread char* last_demangled = NULL;

if(last_symbol && last_demangled && (nativeCompiler == last_native)
&& (includeTypes == last_typed) && (strcmp(symbol, last_symbol) == 0))
{
return strdup(last_demangled);
}

#if defined(cap_gnu_demangler)
int status;
char *demangled = __cxa_demangle(symbol, NULL, NULL, &status);
if (status == -1) {
Expand All @@ -230,16 +227,6 @@ char * P_cplus_demangle( const char * symbol, bool nativeCompiler,
return NULL;
}
assert(status == 0); //Success
#else
int opts = 0;
opts |= includeTypes ? DMGL_PARAMS | DMGL_ANSI : 0;
// [ pgcc/CC are the "native" compilers on Linux. Go figure. ]
// pgCC's mangling scheme most closely resembles that of the Annotated
// C++ Reference Manual, only with "some exceptions" (to quote the PGI
// documentation). I guess we'll demangle names with "some exceptions".
opts |= nativeCompiler ? DMGL_ARM : 0;
char * demangled = cplus_demangle( const_cast< char *>(symbol), opts);
#endif

if( demangled == NULL ) { return NULL; }

Expand Down
2 changes: 1 addition & 1 deletion dyninstAPI/CMakeLists.txt
Expand Up @@ -194,7 +194,7 @@ endif ()

dyninst_library(dyninstAPI common instructionAPI stackwalk pcontrol patchAPI parseAPI symtabAPI)

target_link_private_libraries(dyninstAPI ${Boost_LIBRARIES})
target_link_private_libraries(dyninstAPI ${Boost_LIBRARIES} ${TBB_LIBRARIES})
if (UNIX)
# Boost auto-links on Windows; don't double-link
target_link_private_libraries (dyninstAPI pthread)
Expand Down
8 changes: 4 additions & 4 deletions dyninstAPI/src/BPatch.C
Expand Up @@ -1400,7 +1400,7 @@ BPatch_type * BPatch::createEnum( const char * name,
return NULL;
}
string typeName = name;
vector<pair<string, int> *>elements;
tbb::concurrent_vector<pair<string, int> *>elements;
for (unsigned int i=0; i < elementNames.size(); i++)
elements.push_back(new pair<string, int>(elementNames[i], elementIds[i]));

Expand Down Expand Up @@ -1429,7 +1429,7 @@ BPatch_type * BPatch::createEnum( const char * name,
BPatch_Vector<char *> &elementNames)
{
string typeName = name;
vector<pair<string, int> *>elements;
tbb::concurrent_vector<pair<string, int> *>elements;
for (unsigned int i=0; i < elementNames.size(); i++)
elements.push_back(new pair<string, int>(elementNames[i], i));

Expand Down Expand Up @@ -1465,7 +1465,7 @@ BPatch_type * BPatch::createStruct( const char * name,
}

string typeName = name;
vector<pair<string, Type *> *> fields;
tbb::concurrent_vector<pair<string, Type *> *> fields;
for(i=0; i<fieldNames.size(); i++)
{
if(!fieldTypes[i])
Expand Down Expand Up @@ -1505,7 +1505,7 @@ BPatch_type * BPatch::createUnion( const char * name,
}

string typeName = name;
vector<pair<string, Type *> *> fields;
tbb::concurrent_vector<pair<string, Type *> *> fields;
for(i=0; i<fieldNames.size(); i++)
{
if(!fieldTypes[i])
Expand Down
3 changes: 1 addition & 2 deletions dyninstAPI/src/BPatch_snippet.C
Expand Up @@ -341,12 +341,11 @@ AstNodePtr generateFieldRef(const BPatch_snippet &lOperand,
return AstNodePtr();
}

vector<Field *> *fields;
Field *field = NULL;

// check that the name of the right operand is a field of the left operand

fields = structType->getComponents();
auto fields = structType->getComponents();

unsigned int i;

Expand Down
10 changes: 5 additions & 5 deletions dyninstAPI/src/BPatch_type.C
Expand Up @@ -229,7 +229,7 @@ BPatch_Vector<BPatch_field *> *BPatch_type::getComponents() const{
return NULL;
BPatch_Vector<BPatch_field *> *components = new BPatch_Vector<BPatch_field *>();
if(fieldlisttype) {
vector<Field *> *comps = fieldlisttype->getComponents();
auto comps = fieldlisttype->getComponents();
if(!comps){
delete components;
return NULL;
Expand All @@ -241,7 +241,7 @@ BPatch_Vector<BPatch_field *> *BPatch_type::getComponents() const{

if (enumtype)
{
vector<pair<string, int> > &constants = enumtype->getConstants();
auto constants = enumtype->getConstants();
for (unsigned i = 0; i < constants.size(); i++)
{
Field *fld = new Field(constants[i].first.c_str(), NULL);
Expand All @@ -262,7 +262,7 @@ BPatch_Vector<BPatch_cblock *> *BPatch_type::getCblocks() const
if (!commontype)
return NULL;

std::vector<CBlock *> *cblocks = commontype->getCblocks();
auto cblocks = commontype->getCblocks();

if (!cblocks)
return NULL;
Expand Down Expand Up @@ -612,7 +612,7 @@ void BPatch_cblock::fixupUnknowns(BPatch_module *module) {
BPatch_Vector<BPatch_field *> *BPatch_cblock::getComponents()
{
BPatch_Vector<BPatch_field *> *components = new BPatch_Vector<BPatch_field *>;
std::vector<Field *> *vars = cBlk->getComponents();
auto vars = cBlk->getComponents();

if (!vars)
return NULL;
Expand All @@ -639,7 +639,7 @@ BPatch_Vector<BPatch_field *> *BPatch_cblock::getComponents()

BPatch_Vector<BPatch_function *> *BPatch_cblock::getFunctions()
{
std::vector<Symbol *> *funcs = cBlk->getFunctions();
auto funcs = cBlk->getFunctions();
if(!funcs)
return NULL;
assert(0);
Expand Down
2 changes: 1 addition & 1 deletion symtabAPI/CMakeLists.txt
Expand Up @@ -109,7 +109,7 @@ else()
endif()

dyninst_library(symtabAPI ${DEPS})
target_link_private_libraries(symtabAPI ${Boost_LIBRARIES})
target_link_private_libraries(symtabAPI ${Boost_LIBRARIES} ${TBB_LIBRARIES})

if (USE_COTIRE)
cotire(symtabAPI)
Expand Down
12 changes: 9 additions & 3 deletions symtabAPI/h/Collections.h
Expand Up @@ -31,6 +31,7 @@
#ifndef _Collections_h_
#define _Collections_h_

#include <tbb/concurrent_hash_map.h>
#include "Type.h"
#include "Variable.h"
#include "Serialization.h"
Expand Down Expand Up @@ -82,9 +83,9 @@ class SYMTAB_EXPORT typeCollection : public Serializable//, public AnnotatableSp
friend class Type;
friend class DwarfWalker;

dyn_hash_map<std::string, Type *> typesByName;
dyn_hash_map<std::string, Type *> globalVarsByName;
dyn_hash_map<int, Type *> typesByID;
tbb::concurrent_hash_map<std::string, Type *> typesByName;
tbb::concurrent_hash_map<std::string, Type *> globalVarsByName;
tbb::concurrent_hash_map<int, Type *> typesByID;


// DWARF:
Expand Down Expand Up @@ -119,6 +120,7 @@ class SYMTAB_EXPORT typeCollection : public Serializable//, public AnnotatableSp
Type *findTypeLocal(std::string name);
Type *findTypeLocal(const int ID);
void addType(Type *type);
void addType(Type *type, boost::lock_guard<boost::mutex>&);
void addGlobalVariable(std::string &name, Type *type);

/* Some debug formats allow forward references. Rather than
Expand All @@ -135,6 +137,10 @@ class SYMTAB_EXPORT typeCollection : public Serializable//, public AnnotatableSp
std::vector<Type *> *getAllTypes();
std::vector<std::pair<std::string, Type *> > *getAllGlobalVariables();
void clearNumberedTypes();
private:
boost::mutex placeholder_mutex; // The only intermodule contention should be around
// typedefs/other placeholders, but we'll go ahead and lock around type add operations
// to be safe
};

/*
Expand Down
45 changes: 23 additions & 22 deletions symtabAPI/h/Type.h
Expand Up @@ -34,6 +34,7 @@
#include "Serialization.h"
#include "Annotatable.h"
#include "symutil.h"
#include <tbb/concurrent_vector.h>

namespace Dyninst{
namespace SymtabAPI{
Expand Down Expand Up @@ -230,7 +231,7 @@ class SYMTAB_EXPORT Type : public Serializable, public TYPE_ANNOTATABLE_CLASS
class SYMTAB_EXPORT fieldListInterface {
public:
virtual ~fieldListInterface() {};
virtual std::vector<Field *> *getComponents() const = 0;
virtual tbb::concurrent_vector<Field *> *getComponents() const = 0;
};

class SYMTAB_EXPORT rangedInterface {
Expand All @@ -253,17 +254,17 @@ class SYMTAB_EXPORT fieldListType : public Type, public fieldListInterface
private:
void fixupComponents();
protected:
std::vector<Field *> fieldList;
std::vector<Field *> *derivedFieldList;
tbb::concurrent_vector<Field *> fieldList;
tbb::concurrent_vector<Field *> *derivedFieldList;
fieldListType(std::string &name, typeId_t ID, dataClass typeDes);
/* Each subclass may need to update its size after adding a field */
public:
fieldListType();
~fieldListType();
bool operator==(const Type &) const;
std::vector<Field *> *getComponents() const;
tbb::concurrent_vector<Dyninst::SymtabAPI::Field*> *getComponents() const;

std::vector<Field *> *getFields() const;
tbb::concurrent_vector<Dyninst::SymtabAPI::Field*> *getFields() const;

virtual void postFieldInsert(int nsize) = 0;

Expand Down Expand Up @@ -316,16 +317,16 @@ class SYMTAB_EXPORT derivedType : public Type, public derivedInterface {

class SYMTAB_EXPORT typeEnum : public Type {
private:
std::vector<std::pair<std::string, int> > consts;
tbb::concurrent_vector<std::pair<std::string, int> > consts;
public:
typeEnum();
typeEnum(typeId_t ID, std::string name = "");
typeEnum(std::string name);
static typeEnum *create(std::string &name, std::vector<std::pair<std::string, int> *>&elements,
static typeEnum *create(std::string &name, tbb::concurrent_vector<std::pair<std::string, int> *>&elements,
Symtab *obj = NULL);
static typeEnum *create(std::string &name, std::vector<std::string> &constNames, Symtab *obj);
static typeEnum *create(std::string &name, tbb::concurrent_vector<std::string> &constNames, Symtab *obj);
bool addConstant(const std::string &fieldname,int value);
std::vector<std::pair<std::string, int> > &getConstants();
tbb::concurrent_vector<std::pair<std::string, int> > &getConstants();
bool setName(const char *name);
bool isCompatible(Type *otype);
void serialize_specific(SerializerBase *) THROW_SPEC(SerializerError);
Expand All @@ -336,19 +337,19 @@ class SYMTAB_EXPORT typeFunction : public Type {
void fixupUnknowns(Module *);
private:
Type *retType_; /* Return type of the function */
std::vector<Type *> params_;
tbb::concurrent_vector<Type *> params_;
public:
typeFunction();
typeFunction(typeId_t ID, Type *retType, std::string name = "");
typeFunction(Type *retType, std::string name = "");
static typeFunction *create(std::string &name, Type *retType,
std::vector<Type *> &paramTypes, Symtab *obj = NULL);
tbb::concurrent_vector<Type *> &paramTypes, Symtab *obj = NULL);
~typeFunction();
bool addParam( Type *type);
Type *getReturnType() const;
bool setRetType(Type *rtype);

std::vector<Type *> &getParams();
tbb::concurrent_vector<Type *> &getParams();
bool isCompatible(Type *otype);
void serialize_specific(SerializerBase *) THROW_SPEC(SerializerError);
};
Expand All @@ -368,7 +369,7 @@ class SYMTAB_EXPORT typeScalar : public Type {

class SYMTAB_EXPORT typeCommon : public fieldListType {
private:
std::vector<CBlock *> cblocks;
tbb::concurrent_vector<CBlock *> cblocks;
protected:
void postFieldInsert(int nsize) { size_ += nsize; }
//void postFieldInsert(int offset, int nsize) { if ((unsigned int) (offset + nsize) > size_) size_ = offset + nsize; }
Expand All @@ -378,7 +379,7 @@ class SYMTAB_EXPORT typeCommon : public fieldListType {
typeCommon(typeId_t ID, std::string name = "");
typeCommon(std::string name);
static typeCommon *create(std::string &name, Symtab *obj = NULL);
std::vector<CBlock *> *getCblocks() const;
tbb::concurrent_vector<CBlock *> *getCblocks() const;
void beginCommonBlock();
void endCommonBlock(Symbol *, void *baseAddr);
void serialize_specific(SerializerBase *) THROW_SPEC(SerializerError);
Expand All @@ -389,15 +390,15 @@ class SYMTAB_EXPORT CBlock : public Serializable, public AnnotatableSparse
friend class typeCommon;
private:
// the list of fields
std::vector<Field *> fieldList;
tbb::concurrent_vector<Field *> fieldList;

// which functions use this list
// Should probably be updated to use aggregates
std::vector<Symbol *> functions;
tbb::concurrent_vector<Symbol *> functions;

public:
std::vector<Field *> *getComponents();
std::vector<Symbol *> *getFunctions();
tbb::concurrent_vector<Field *> *getComponents();
tbb::concurrent_vector<Symbol *> *getFunctions();

void fixupUnknowns(Module *);

Expand All @@ -415,10 +416,10 @@ class SYMTAB_EXPORT typeStruct : public fieldListType {
typeStruct();
typeStruct(typeId_t ID, std::string name = "");
typeStruct(std::string name);
static typeStruct *create(std::string &name, std::vector< std::pair<std::string, Type *> *> &flds,
static typeStruct *create(std::string &name, tbb::concurrent_vector< std::pair<std::string, Type *> *> &flds,

Symtab *obj = NULL);
static typeStruct *create(std::string &name, std::vector<Field *> &fields,
static typeStruct *create(std::string &name, tbb::concurrent_vector<Field *> &fields,
Symtab *obj = NULL);

bool isCompatible(Type *otype);
Expand All @@ -435,9 +436,9 @@ class SYMTAB_EXPORT typeUnion : public fieldListType {
typeUnion();
typeUnion(typeId_t ID, std::string name = "");
typeUnion(std::string name);
static typeUnion *create(std::string &name, std::vector<std::pair<std::string, Type *> *> &fieldNames,
static typeUnion *create(std::string &name, tbb::concurrent_vector<std::pair<std::string, Type *> *> &fieldNames,
Symtab *obj = NULL);
static typeUnion *create(std::string &name, std::vector<Field *> &fields,
static typeUnion *create(std::string &name, tbb::concurrent_vector<Field *> &fields,
Symtab *obj = NULL);
bool isCompatible(Type *otype);
void serialize_specific(SerializerBase *) THROW_SPEC(SerializerError);
Expand Down

0 comments on commit a8def5c

Please sign in to comment.