From 2043d4bd3c2b174fbf653e6e2b61697ea1947297 Mon Sep 17 00:00:00 2001 From: tikir Date: Sat, 18 Mar 2000 21:53:58 +0000 Subject: [PATCH] Addition of Control Flow Graph related implementation. Some small modification in implementation of LineInformation stuff. Addition includes control flow graph, basi blocks and basic block loops and source block implemetation --- dyninstAPI/h/BPatch_function.h | 13 +++++++--- dyninstAPI/h/BPatch_module.h | 3 ++- dyninstAPI/h/BPatch_sourceObj.h | 2 +- dyninstAPI/make.module.tmpl | 6 ++++- dyninstAPI/nmake.module.tmpl | 10 +++++++- dyninstAPI/src/BPatch_function.C | 35 +++++++++++++++++++++++--- dyninstAPI/src/BPatch_templates.C | 25 ++++++++++++++++++- dyninstAPI/src/LineInformation.C | 52 +++++++++++++++++++++------------------ dyninstAPI/src/LineInformation.h | 3 +++ dyninstAPI/src/templates0.C | 14 +---------- dyninstAPI/src/templates1.C | 13 +++++++++- 11 files changed, 127 insertions(+), 49 deletions(-) diff --git a/dyninstAPI/h/BPatch_function.h b/dyninstAPI/h/BPatch_function.h index 283b4f7..fe021bf 100644 --- a/dyninstAPI/h/BPatch_function.h +++ b/dyninstAPI/h/BPatch_function.h @@ -53,12 +53,18 @@ class process; class BPatch_localVarCollection; class BPatch_function; class BPatch_point; +class BPatch_flowGraph; class BPatch_function: public BPatch_sourceObj { + friend class BPatch_flowGraph; + process *proc; BPatch_type * retType; BPatch_Vector params; BPatch_module *mod; + BPatch_flowGraph* cfg; + + void *getBaseAddrRelative(); public: virtual ~BPatch_function(); @@ -95,12 +101,13 @@ public: BPatch_localVar * findLocalVar( const char * name); BPatch_localVar * findLocalParam(const char * name); - //method to retrieve addresses corresponding a line in the function +//method to retrieve addresses corresponding a line in the function bool getLineToAddr (unsigned short lineNo, BPatch_Vector& buffer, bool exactMatch = true); -}; - +//method to create the control flow graph for the function + BPatch_flowGraph* getCFG(); +}; #endif /* _BPatch_function_h_ */ diff --git a/dyninstAPI/h/BPatch_module.h b/dyninstAPI/h/BPatch_module.h index aac57e3..c2bd39c 100644 --- a/dyninstAPI/h/BPatch_module.h +++ b/dyninstAPI/h/BPatch_module.h @@ -60,6 +60,7 @@ class BPatch_module: public BPatch_sourceObj { friend class BPatch_function; friend class BPatch_image; friend class BPatch_thread; + friend class BPatch_flowGraph; process *proc; pdmodule *mod; @@ -95,7 +96,7 @@ public: char *parseStabStringSymbol(int line, char *stabstr, void *stabptr); - //function to get addresses for a line of the module +//function to get addresses for a line of the module bool getLineToAddr(unsigned short lineNo, BPatch_Vector& buffer, bool exactMatch = true); diff --git a/dyninstAPI/h/BPatch_sourceObj.h b/dyninstAPI/h/BPatch_sourceObj.h index 2b9f813..c5b643d 100644 --- a/dyninstAPI/h/BPatch_sourceObj.h +++ b/dyninstAPI/h/BPatch_sourceObj.h @@ -67,7 +67,7 @@ typedef enum BPatch_sourceType { BPatch_sourceFunction, BPatch_sourceOuterLoop, BPatch_sourceLoop, - BPatch_sourceBlock, + BPatch_srcBlock, BPatch_sourceStatement } BPatch_sourceType; diff --git a/dyninstAPI/make.module.tmpl b/dyninstAPI/make.module.tmpl index fe87684..ba80b13 100644 --- a/dyninstAPI/make.module.tmpl +++ b/dyninstAPI/make.module.tmpl @@ -3,7 +3,7 @@ # intended to be a useful Makefile in isolation; instead, it should be # included from within an architecture-specific Makefile. # -# $Id: make.module.tmpl,v 1.20 2000/03/14 22:33:53 tikir Exp $ +# $Id: make.module.tmpl,v 1.21 2000/03/18 21:53:58 tikir Exp $ # SUITE_NAME = Dyninst @@ -46,6 +46,10 @@ SRCS += ../src/BPatch.C \ ../src/BPatch_module.C \ ../src/BPatch_point.C \ ../src/BPatch_collections.C \ + ../src/BPatch_sourceBlock.C \ + ../src/BPatch_basicBlock.C \ + ../src/BPatch_basicBlockLoop.C \ + ../src/BPatch_flowGraph.C \ ../src/Object.C \ ../src/dummy.C \ ../src/api_showerror.C \ diff --git a/dyninstAPI/nmake.module.tmpl b/dyninstAPI/nmake.module.tmpl index abe0a1d..565c709 100644 --- a/dyninstAPI/nmake.module.tmpl +++ b/dyninstAPI/nmake.module.tmpl @@ -3,7 +3,7 @@ # intended to be a useful Makefile in isolation; instead, it should be # included from within an architecture-specific Makefile. # -# $Id: nmake.module.tmpl,v 1.11 2000/03/15 22:14:29 tikir Exp $ +# $Id: nmake.module.tmpl,v 1.12 2000/03/18 21:53:58 tikir Exp $ # SUITE_NAME = Dyninst @@ -30,6 +30,10 @@ SRCS = $(SRCS) BPatch.C \ BPatch_point.C \ BPatch_collections.C \ LineInformation.C \ + BPatch_sourceBlock.C \ + BPatch_basicBlock.C \ + BPatch_basicBlockLoop.C \ + BPatch_flowGraph.C \ dummy.C \ api_showerror.C \ ast.C \ @@ -56,6 +60,10 @@ OBJS = $(OBJS) BPatch.obj \ BPatch_point.obj \ BPatch_collections.obj \ LineInformation.obj \ + BPatch_sourceBlock.obj \ + BPatch_basicBlock.obj \ + BPatch_basicBlockLoop.obj \ + BPatch_flowGraph.obj \ dummy.obj \ api_showerror.obj \ ast.obj \ diff --git a/dyninstAPI/src/BPatch_function.C b/dyninstAPI/src/BPatch_function.C index 164b925..865f866 100644 --- a/dyninstAPI/src/BPatch_function.C +++ b/dyninstAPI/src/BPatch_function.C @@ -39,7 +39,7 @@ * incur to third parties resulting from your use of Paradyn. */ -// $Id: BPatch_function.C,v 1.3 2000/03/14 22:31:25 tikir Exp $ +// $Id: BPatch_function.C,v 1.4 2000/03/18 21:53:59 tikir Exp $ #include #include "symtab.h" @@ -50,6 +50,7 @@ #include "BPatch_type.h" #include "BPatch_collections.h" #include "BPatch_Vector.h" +#include "BPatch_flowGraph.h" #include "LineInformation.h" /* XXX Should be in a dyninst API include file (right now in perfStream.h) */ @@ -67,7 +68,7 @@ extern double cyclesPerSecond; */ BPatch_function::BPatch_function(process *_proc, function_base *_func, BPatch_module *_mod) : - proc(_proc), mod(_mod), func(_func) + proc(_proc), mod(_mod), func(_func),cfg(NULL) { // there should be at most one BPatch_func for each function_base per process @@ -90,7 +91,7 @@ BPatch_function::BPatch_function(process *_proc, function_base *_func, */ BPatch_function::BPatch_function(process *_proc, function_base *_func, BPatch_type * _retType, BPatch_module *_mod) : - proc(_proc), mod(_mod), func(_func) + proc(_proc), mod(_mod), func(_func),cfg(NULL) { _srcType = BPatch_sourceFunction; localVariables = new BPatch_localVarCollection; @@ -105,6 +106,7 @@ BPatch_function::~BPatch_function() // removeAst(ast); if (localVariables) delete localVariables; if (funcParameters) delete funcParameters; + if (cfg) delete cfg; } /* @@ -160,6 +162,17 @@ void *BPatch_function::getBaseAddr() return (void *)func->getEffectiveAddress(proc); } +/* +* BPatch_function::getBaseAddrRelative +* +* Returns the starting address of the function in the module, relative +* to the module. +*/ +void *BPatch_function::getBaseAddrRelative() +{ + return (void *)func->addr(); +} + /* * BPatch_function::getSize @@ -352,3 +365,19 @@ bool BPatch_function::getLineToAddr(unsigned short lineNo, return true; } + + +BPatch_flowGraph* BPatch_function::getCFG(){ + if(cfg) + return cfg; + +#if defined(sparc_sun_solaris2_4) + cfg = new BPatch_flowGraph((BPatch_function*)this); +#else + cerr << "WARNING : BPatch_function::getCFG is not implemented"; + cerr << " for this platform\n"; +#endif + + return cfg; +} + diff --git a/dyninstAPI/src/BPatch_templates.C b/dyninstAPI/src/BPatch_templates.C index 852dde3..ad97aab 100644 --- a/dyninstAPI/src/BPatch_templates.C +++ b/dyninstAPI/src/BPatch_templates.C @@ -39,7 +39,7 @@ * incur to third parties resulting from your use of Paradyn. */ -// $Id: BPatch_templates.C,v 1.10 2000/03/14 22:31:31 tikir Exp $ +// $Id: BPatch_templates.C,v 1.11 2000/03/18 21:53:59 tikir Exp $ #include @@ -49,10 +49,16 @@ #include "BPatch_Vector.h" #if !defined(i386_unknown_nt4_0) +#pragma implementation "BPatch_Set.h" +#endif +#include "BPatch_Set.h" + +#if !defined(i386_unknown_nt4_0) #pragma implementation "refCounter.h" #endif #include "util/h/refCounter.h" #include "util/h/String.h" +#include "util/h/Types.h" class BPatch_point; class BPatch_field; @@ -80,3 +86,20 @@ template class BPatch_Vector; template class BPatch_Vector; template class BPatch_Vector; template class BPatch_Vector; + +template struct comparison; +template class BPatch_Set; +template struct comparison
; +template class BPatch_Set
; +template class BPatch_Vector; + +class BPatch_basicBlock; +class BPatch_basicBlockLoop; + +template class BPatch_Vector; +template class BPatch_Vector; + +template struct comparison; +template class BPatch_Set; +template struct comparison; +template class BPatch_Set; diff --git a/dyninstAPI/src/LineInformation.C b/dyninstAPI/src/LineInformation.C index 4d14219..4c8a5ae 100644 --- a/dyninstAPI/src/LineInformation.C +++ b/dyninstAPI/src/LineInformation.C @@ -336,22 +336,6 @@ bool FileLineInformation::getAddrFromLine(string name, return true; } -//temporary function to print info about line information -void FileLineInformation::print(){ - cerr << "LINE TO ADDRESS :\n"; - for(int j=0;j " << hex << lineToAddr[j].codeAddress << "\n"; - for(int i=0;ivalidInfo) - continue; - cerr << dec << lineToAddr[funcinfo->startLinePtr].lineNo ; - cerr << " --- " << dec << lineToAddr[funcinfo->endLinePtr].lineNo << "\n"; - } - -} - //constructor whose argument is the name of the module name LineInformation::LineInformation(string mName) : moduleName(mName), @@ -520,14 +504,34 @@ bool LineInformation::findFunction(string functionName){ return ret; } -//print the line information kept in the map -void LineInformation::print(){ - cerr << "**********************************************\n"; - cerr << "MODULE : " << moduleName << "\n"; - cerr << "**********************************************\n"; - for(int i=0;iprint(); +ostream& operator<<(ostream& os,FileLineInformation& linfo){ + + cerr << "LINE TO ADDRESS :\n"; + for(int j=0;j "; + os << hex << linfo.lineToAddr[j].codeAddress << "\n"; + } + for(int i=0;ivalidInfo) + continue; + os << dec << linfo.lineToAddr[funcinfo->startLinePtr].lineNo << " --- "; + os << dec << linfo.lineToAddr[funcinfo->endLinePtr].lineNo << "\n"; + } + return os; + +} + +ostream& operator<<(ostream& os,LineInformation& linfo){ + os << "**********************************************\n"; + os << "MODULE : " << linfo.moduleName << "\n"; + os << "**********************************************\n"; + for(int i=0;i; template class vector; template class vector; #endif - -#ifdef BPATCH_LIBRARY -template struct comparison; -template class BPatch_Set; -template struct comparison
; -template class BPatch_Set
; -#endif diff --git a/dyninstAPI/src/templates1.C b/dyninstAPI/src/templates1.C index 1019986..05113d9 100644 --- a/dyninstAPI/src/templates1.C +++ b/dyninstAPI/src/templates1.C @@ -39,13 +39,15 @@ * incur to third parties resulting from your use of Paradyn. */ -// $Id: templates1.C,v 1.31 2000/02/15 23:48:01 hollings Exp $ +// $Id: templates1.C,v 1.32 2000/03/18 21:53:59 tikir Exp $ #pragma implementation "Dictionary.h" #include "util/src/Dictionary.C" #include "util/h/String.h" +#include "BPatch_Set.h" + #include "dyninstAPI/src/symtab.h" #include "dyninstAPI/src/process.h" #include "dyninstAPI/src/inst.h" @@ -235,3 +237,12 @@ template class vector; template class vector::entry>; + +#if defined(BPATCH_LIBRARY) + +class BPatch_basicBlock; + +template class dictionary_hash; +template class vector::entry>; + +#endif -- 1.8.3.1