Skip to content

Commit

Permalink
Many fixes and optimizations--mostly, moving the interval trees for m…
Browse files Browse the repository at this point in the history
…odule ranges from one per module to one per symtab with a pointer to the module.
  • Loading branch information
wrwilliams committed Oct 19, 2016
1 parent c7a3943 commit d6d77ef
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 48 deletions.
44 changes: 38 additions & 6 deletions common/h/IBSTree-fast.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,53 @@
/*
* See the dyninst/COPYRIGHT file for copyright information.
*
* We provide the Paradyn Tools (below described as "Paradyn")
* on an AS IS basis, and do not warrant its validity or performance.
* We reserve the right to update, modify, or discontinue this
* software at any time. We shall have no obligation to supply such
* updates or modifications or any other form of support to you.
*
* By your use of Paradyn, you understand and agree that we (or any
* other person or entity with proprietary rights in Paradyn) are
* under no obligation to provide either maintenance services,
* update services, notices of latent defects, or correction of
* defects for Paradyn.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#if !defined(IBSTREE_FAST_H)
#define IBSTREE_FAST_H
#include "IBSTree.h"
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/mem_fun.hpp>
#include <boost/multi_index/identity.hpp>

namespace Dyninst
namespace Dyninst
{
template <typename ITYPE = interval<> >
class IBSTree_fast
{
typedef typename ITYPE::type interval_type;



IBSTree<ITYPE> overlapping_intervals;
typedef boost::multi_index_container<ITYPE*,
indexed_by<
ordered_unique<const_mem_fun<ITYPE, interval_type, &ITYPE::high> >
typedef boost::multi_index_container<ITYPE*,
boost::multi_index::indexed_by<
boost::multi_index::ordered_unique<
boost::multi_index::const_mem_fun<ITYPE, interval_type, &ITYPE::high> >
> > interval_set;

//typedef std::set<ITYPE*, order_by_lower<ITYPE> > interval_set;
Expand Down Expand Up @@ -153,3 +184,4 @@ namespace Dyninst


}
#endif
2 changes: 1 addition & 1 deletion common/h/IBSTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class SimpleInterval : public interval<int> {
virtual int low() const { return low_; }
virtual int high() const { return high_; }

private:
protected:
int low_;
int high_;
void * id_; // some arbitrary unique identifier
Expand Down
4 changes: 2 additions & 2 deletions dyninstAPI/src/image.C
Original file line number Diff line number Diff line change
Expand Up @@ -1699,10 +1699,10 @@ parse_func *image::addFunction(Address functionEntryAddr, const char *fName)
}
region = *(regions.begin()); // XXX pick one, throwing up hands.

Module* st_mod;
std::set<Module*> st_mod;
linkedFile->findModuleByOffset(st_mod, functionEntryAddr);

pdmodule *mod = getOrCreateModule(st_mod);
pdmodule *mod = getOrCreateModule(*(st_mod.begin()));

// copy or create function name
char funcName[32];
Expand Down
19 changes: 15 additions & 4 deletions symtabAPI/h/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "Annotatable.h"
#include "Serialization.h"
#include "IBSTree.h"
#include "IBSTree-fast.h"
#if defined(cap_dwarf)
#include "libdwarf.h"
#endif
Expand Down Expand Up @@ -203,13 +204,12 @@ typedef Statement LineNoTuple;

bool setLineInfo(Dyninst::SymtabAPI::LineInformation *lineInfo);
void addRange(Dyninst::Address low, Dyninst::Address high);
bool containsOffset(Dyninst::Offset offset) const;
void setDebugInfo(Module::DebugInfoT info) {info_is_valid_ = true; info_ = info; }

void setDebugInfo(Module::DebugInfoT info) {info_is_valid_ = true; info_ = info; }
Module::DebugInfoT getDebugInfo();
private:
Dyninst::SymtabAPI::LineInformation* lineInfo_;
typeCollection* typeInfo_;
IBSTree<SimpleInterval> ranges;
bool info_is_valid_;
Module::DebugInfoT info_;

Expand All @@ -228,7 +228,18 @@ typedef Statement LineNoTuple;
}



struct ModRange : public interval<Offset>
{
ModRange(Offset l, Offset h, Module* m) :
low_(l), high_(h), mod_(m)
{}
Offset low() const { return low_; }
Offset high() const { return high_; }
Module* mod() const { return mod_;}
Offset low_;
Offset high_;
Module* mod_;
};


}//namespace SymtabAPI
Expand Down
6 changes: 5 additions & 1 deletion symtabAPI/h/Symtab.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ class relocationEntry;
class Type;
class FunctionBase;
class FuncRange;
class ModRange;

typedef IBSTree_fast<ModRange> ModRangeLookup;
typedef IBSTree<FuncRange> FuncRangeLookup;
typedef Dyninst::ProcessReader MemRegReader;

Expand Down Expand Up @@ -198,7 +200,7 @@ class SYMTAB_EXPORT Symtab : public LookupInterface,
// Module

bool getAllModules(std::vector<Module *>&ret);
bool findModuleByOffset(Module *&ret, Offset off);
bool findModuleByOffset(std::set<Module *>& ret, Offset off);
bool findModuleByName(Module *&ret, const std::string name);
Module *getDefaultModule();

Expand Down Expand Up @@ -593,10 +595,12 @@ class SYMTAB_EXPORT Symtab : public LookupInterface,
bool isDefensiveBinary_;

FuncRangeLookup *func_lookup;
ModRangeLookup *mod_lookup_;

//Don't use obj_private, use getObject() instead.
public:
Object *getObject();
ModRangeLookup* mod_lookup();
private:
Object *obj_private;

Expand Down
6 changes: 1 addition & 5 deletions symtabAPI/src/Module.C
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,8 @@ bool Module::findVariablesByName(std::vector<Variable *> &ret, const std::string

void Module::addRange(Dyninst::Address low, Dyninst::Address high)
{
ranges.insert(new SimpleInterval(low, high, this));
}

bool Module::containsOffset(Dyninst::Offset offset) const {
std::set<SimpleInterval*> found_entries;
return ranges.find(offset, found_entries) > 0;
exec_->mod_lookup()->insert(new ModRange(low, high, this));
}

Module::DebugInfoT Module::getDebugInfo()
Expand Down
17 changes: 10 additions & 7 deletions symtabAPI/src/Object-elf.C
Original file line number Diff line number Diff line change
Expand Up @@ -4447,20 +4447,23 @@ void Object::parseLineInfoForAddr(Symtab* obj, Offset addr_to_find)
Dwarf_Debug *dbg_ptr = dwarf->line_dbg();
if (!dbg_ptr)
return;
Module* mod_for_offset = NULL;
std::set<Module*> mod_for_offset;
obj->findModuleByOffset(mod_for_offset, addr_to_find);
if(mod_for_offset)
for(auto mod = mod_for_offset.begin();
mod != mod_for_offset.end();
++mod)
{
if(mod_for_offset->hasLineInformation()) // already parsed
if((*mod)->hasLineInformation()) // already parsed
{
return;
continue;
}
Dwarf_Die cuDIE = mod_for_offset->getDebugInfo();
LineInformation* li_for_module = mod_for_offset->getLineInformation();
Dwarf_Die cuDIE = ((*mod)->getDebugInfo());
if(!cuDIE) return; // stashed DIE was null, so we never set it...
LineInformation* li_for_module = ((*mod)->getLineInformation());
if(!li_for_module)
{
li_for_module = new LineInformation;
mod_for_offset->setLineInfo(li_for_module);
((*mod)->setLineInfo(li_for_module));
}

parseLineInfoForCU(cuDIE, li_for_module);
Expand Down
30 changes: 20 additions & 10 deletions symtabAPI/src/Symtab-lookup.C
Original file line number Diff line number Diff line change
Expand Up @@ -387,19 +387,29 @@ bool module_less(Module* lhs, Module* rhs)
}


bool Symtab::findModuleByOffset(Module *&ret, Offset off)
bool Symtab::findModuleByOffset(std::set<Module *>&ret, Offset off)
{
// this should be a hash, really
for(size_t i = 0; i < _mods.size(); i++)
std::set<ModRange*> mods;
ret.clear();
mod_lookup()->find(off, mods);
for(auto i = mods.begin();
i != mods.end();
++i)
{
if(_mods[i]->containsOffset(off))
{
ret = _mods[i];
return true;
}
ret.insert((*i)->mod());
}
ret = NULL;
return false;
return ret.empty();
// // this should be a hash, really
// for(int i = 0; i < _mods.size(); i++)
// {
// if(_mods[i]->containsOffset(off))
// {
// ret = _mods[i];
// return true;
// }
// }
// ret = NULL;
// return false;
}

bool Symtab::findModuleByName(Module *&ret, const std::string name)
Expand Down
25 changes: 14 additions & 11 deletions symtabAPI/src/Symtab.C
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ SYMTAB_EXPORT Symtab::Symtab(MappedFile *mf_) :
hasReladyn_(false), hasRelplt_(false), hasRelaplt_(false),
isStaticBinary_(false), isDefensiveBinary_(false),
func_lookup(NULL),
mod_lookup_(NULL),
obj_private(NULL),
_ref_cnt(1)
{
Expand Down Expand Up @@ -434,6 +435,7 @@ SYMTAB_EXPORT Symtab::Symtab() :
hasReladyn_(false), hasRelplt_(false), hasRelaplt_(false),
isStaticBinary_(false), isDefensiveBinary_(false),
func_lookup(NULL),
mod_lookup_(NULL),
obj_private(NULL),
_ref_cnt(1)
{
Expand Down Expand Up @@ -1277,6 +1279,7 @@ Symtab::Symtab(std::string filename, bool defensive_bin, bool &err) :
hasReladyn_(false), hasRelplt_(false), hasRelaplt_(false),
isStaticBinary_(false), isDefensiveBinary_(defensive_bin),
func_lookup(NULL),
mod_lookup_(NULL),
obj_private(NULL),
_ref_cnt(1)
{
Expand Down Expand Up @@ -1350,6 +1353,7 @@ Symtab::Symtab(unsigned char *mem_image, size_t image_size,
isStaticBinary_(false),
isDefensiveBinary_(defensive_bin),
func_lookup(NULL),
mod_lookup_(NULL),
obj_private(NULL),
_ref_cnt(1)
{
Expand Down Expand Up @@ -1665,6 +1669,7 @@ Symtab::Symtab(const Symtab& obj) :
hasReladyn_(false), hasRelplt_(false), hasRelaplt_(false),
isStaticBinary_(false), isDefensiveBinary_(obj.isDefensiveBinary_),
func_lookup(NULL),
mod_lookup_(NULL),
obj_private(NULL),
_ref_cnt(1)
{
Expand Down Expand Up @@ -1862,15 +1867,7 @@ Symtab::~Symtab()
// Symbols are copied from linkedFile, and NOT deleted
everyDefinedSymbol.clear();
undefDynSyms.clear();
//undefDynSymsByMangledName.clear();
//undefDynSymsByPrettyName.clear();
//undefDynSymsByTypedName.clear();

// TODO make annotation
//symsByOffset.clear();
//symsByMangledName.clear();
//symsByPrettyName.clear();
//symsByTypedName.clear();

for (unsigned i = 0; i < everyFunction.size(); i++)
{
Expand Down Expand Up @@ -1910,12 +1907,12 @@ Symtab::~Symtab()
allSymtabs.erase(allSymtabs.begin()+i);
}

if (func_lookup)
delete func_lookup;
delete func_lookup;
delete mod_lookup_;

// Make sure to free the underlying Object as it doesn't have a factory
// open method
if( obj_private ) delete obj_private;
delete obj_private;

if (mf) MappedFile::closeMappedFile(mf);

Expand Down Expand Up @@ -3802,3 +3799,9 @@ void Symtab::rebase(Offset loadOff)
getObject()->rebase(loadOff);
load_address_ = loadOff;
}

ModRangeLookup *Symtab::mod_lookup() {
if(!mod_lookup_) mod_lookup_ = new ModRangeLookup;
return mod_lookup_;

}
5 changes: 4 additions & 1 deletion symtabAPI/src/dwarfWalker.C
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,10 @@ bool DwarfWalker::parse_int(Dwarf_Die e, bool p) {
DWARF_CHECK_RET(status == DW_DLV_ERROR);

/* Deallocate the entry we just parsed. */
dwarf_dealloc( dbg(), entry(), DW_DLA_DIE );
if(tag() != DW_TAG_compile_unit)
{
dwarf_dealloc( dbg(), entry(), DW_DLA_DIE );
}

if (status != DW_DLV_OK) {
break;
Expand Down

0 comments on commit d6d77ef

Please sign in to comment.