From 01072f21d121dd8fa5398b90aafafc8d84150479 Mon Sep 17 00:00:00 2001 From: hollings Date: Sun, 12 Mar 2000 23:26:04 +0000 Subject: [PATCH] Added srcObject and fork/exec/exit callbacks. --- dyninstAPI/h/BPatch.h | 27 ++++++++++-- dyninstAPI/h/BPatch_function.h | 12 +++++- dyninstAPI/h/BPatch_image.h | 7 +++- dyninstAPI/h/BPatch_module.h | 20 ++++++--- dyninstAPI/h/BPatch_point.h | 2 +- dyninstAPI/h/BPatch_snippet.h | 1 + dyninstAPI/h/BPatch_sourceObj.h | 93 +++++++++++++++++++++++++++++++++++++++++ dyninstAPI/h/BPatch_thread.h | 13 +++++- 8 files changed, 160 insertions(+), 15 deletions(-) create mode 100644 dyninstAPI/h/BPatch_sourceObj.h diff --git a/dyninstAPI/h/BPatch.h b/dyninstAPI/h/BPatch.h index d2d1135..44967c9 100644 --- a/dyninstAPI/h/BPatch.h +++ b/dyninstAPI/h/BPatch.h @@ -63,14 +63,24 @@ typedef void (*BPatchDynLibraryCallback)(BPatch_thread *thr, BPatch_module *mod, bool load); +typedef void (*BPatchForkCallback)(BPatch_thread *parent, BPatch_thread *child); + +typedef void (*BPatchExecCallback)(BPatch_thread *proc); + +typedef void (*BPatchExitCallback)(BPatch_thread *proc, int code); + class BPatch { friend class BPatch_thread; friend class process; BPatch_libInfo *info; - BPatchErrorCallback errorHandler; - BPatchDynLibraryCallback dynLibraryCallback; + BPatchErrorCallback errorHandler; + BPatchDynLibraryCallback dynLibraryCallback; + BPatchForkCallback postForkCallback; + BPatchForkCallback preForkCallback; + BPatchExecCallback execCallback; + BPatchExitCallback exitCallback; bool typeCheckOn; int lastError; bool debugParseOn; @@ -91,12 +101,15 @@ public: BPatch_type *type_Error; BPatch_type *type_Untyped; - // The following are only to be called by the library: bool isTypeChecked() { return typeCheckOn; } bool parseDebugInfo() { return debugParseOn; } bool isTrampRecursive() { return trampRecursiveOn; } + // The following are only to be called by the library: void registerProvisionalThread(int pid); + void registerForkedThread(int parentPid, int childPid, process *proc); + void registerExec(BPatch_thread *thread); + void registerExit(BPatch_thread *thread, int code); void registerThread(BPatch_thread *thread); void unRegisterThread(int pid); @@ -116,13 +129,19 @@ public: const char *fmt, const char **params); BPatchErrorCallback registerErrorCallback(BPatchErrorCallback function); BPatchDynLibraryCallback registerDynLibraryCallback(BPatchDynLibraryCallback function); + BPatchForkCallback registerPostForkCallback(BPatchForkCallback func); + BPatchForkCallback registerPreForkCallback(BPatchForkCallback func); + BPatchExecCallback registerExecCallback(BPatchExecCallback func); + BPatchExitCallback registerExitCallback(BPatchExitCallback func); + BPatch_Vector *getThreads(); void setDebugParsing(bool x) { debugParseOn = x; } void setTypeChecking(bool x) { typeCheckOn = x; } void setTrampRecursive(bool x) { trampRecursiveOn = x; } - BPatch_thread *createProcess(char *path, char *argv[], char *envp[] = NULL); + BPatch_thread *createProcess(char *path, char *argv[], + char *envp[] = NULL, int stdin_fd=0, int stdout_fd=1, int stderr_fd=2); BPatch_thread *attachProcess(char *path, int pid); // Create Enum types. diff --git a/dyninstAPI/h/BPatch_function.h b/dyninstAPI/h/BPatch_function.h index e766d9b..c40c283 100644 --- a/dyninstAPI/h/BPatch_function.h +++ b/dyninstAPI/h/BPatch_function.h @@ -54,19 +54,26 @@ class BPatch_localVarCollection; class BPatch_function; class BPatch_point; -class BPatch_function { +class BPatch_function: public BPatch_sourceObj { process *proc; BPatch_type * retType; BPatch_Vector params; BPatch_module *mod; - + public: + virtual ~BPatch_function(); + // The following are for internal use by the library only: function_base *func; + process *getProc() { return proc; } + // No longer inline but defined in .C file BPatch_function(process *_proc, function_base *_func, BPatch_module *); BPatch_function(process *_proc, function_base *_func, BPatch_type * _retType, BPatch_module *); + + BPatch_Vector *getSourceObj(); + BPatch_sourceObj *getObjParent(); BPatch_localVarCollection * localVariables; BPatch_localVarCollection * funcParameters; void setReturnType( BPatch_type * _retType){ @@ -90,4 +97,5 @@ public: }; + #endif /* _BPatch_function_h_ */ diff --git a/dyninstAPI/h/BPatch_image.h b/dyninstAPI/h/BPatch_image.h index cd3483b..bb2b2e3 100644 --- a/dyninstAPI/h/BPatch_image.h +++ b/dyninstAPI/h/BPatch_image.h @@ -42,6 +42,7 @@ #ifndef _BPatch_image_h_ #define _BPatch_image_h_ +#include "BPatch_sourceObj.h" #include "BPatch_Vector.h" #include "BPatch_point.h" #include "BPatch_snippet.h" @@ -53,13 +54,17 @@ class image; class AddrToVarExprHash; -class BPatch_image { +class BPatch_image: public BPatch_sourceObj { process *proc; public: // The following functions are for internal use by the library only: BPatch_image(process *_proc); BPatch_image(); + virtual ~BPatch_image(); + + BPatch_Vector *getSourceObj(); + BPatch_sourceObj *getObjParent(); bool ModuleListExist(); void addModuleIfExist(BPatch_module *bpmod); diff --git a/dyninstAPI/h/BPatch_module.h b/dyninstAPI/h/BPatch_module.h index 384393c..ebaef99 100644 --- a/dyninstAPI/h/BPatch_module.h +++ b/dyninstAPI/h/BPatch_module.h @@ -43,8 +43,10 @@ #define _BPatch_module_h_ #include +#include class pdmodule; +class BPatch_image; class BPatch_function; class BPatch_typeCollection; class BPatch_builtInTypeCollection; @@ -52,15 +54,23 @@ class BPatch_builtInTypeCollection; extern BPatch_builtInTypeCollection * builtInTypes; -class BPatch_module { - process *proc; - pdmodule *mod; +class BPatch_module: public BPatch_sourceObj { + process *proc; + pdmodule *mod; + BPatch_image *img; BPatch_Vector * BPfuncs; public: // The following functions are for internal use by the library only: - BPatch_module(process *_proc, pdmodule *_mod); - BPatch_module() : mod(NULL), BPfuncs(NULL) {}; + BPatch_module(process *_proc, pdmodule *_mod, BPatch_image *img); + BPatch_module() : mod(NULL), img(NULL), BPfuncs(NULL) { + _srcType = BPatch_sourceModule; + }; + + virtual ~BPatch_module(); + + BPatch_Vector *getSourceObj(); + BPatch_sourceObj *getObjParent(); BPatch_typeCollection *moduleTypes; diff --git a/dyninstAPI/h/BPatch_point.h b/dyninstAPI/h/BPatch_point.h index 75ce00f..87345b6 100644 --- a/dyninstAPI/h/BPatch_point.h +++ b/dyninstAPI/h/BPatch_point.h @@ -59,7 +59,7 @@ typedef enum { BPatch_subroutine, BPatch_longJump, BPatch_allLocations, - BPatch_address + BPatch_instruction } BPatch_procedureLocation; diff --git a/dyninstAPI/h/BPatch_snippet.h b/dyninstAPI/h/BPatch_snippet.h index e5e8734..4f7e5d3 100644 --- a/dyninstAPI/h/BPatch_snippet.h +++ b/dyninstAPI/h/BPatch_snippet.h @@ -43,6 +43,7 @@ #define _BPatch_snippet_h_ #include "BPatch_Vector.h" +#include "BPatch_sourceObj.h" #include "BPatch_point.h" #include "BPatch_type.h" #include "BPatch_module.h" diff --git a/dyninstAPI/h/BPatch_sourceObj.h b/dyninstAPI/h/BPatch_sourceObj.h new file mode 100644 index 0000000..492c49f --- /dev/null +++ b/dyninstAPI/h/BPatch_sourceObj.h @@ -0,0 +1,93 @@ +/* + * Copyright (c) 1996 Barton P. Miller + * + * We provide the Paradyn Parallel Performance 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. + * + * This license is for research uses. For such uses, there is no + * charge. We define "research use" to mean you may freely use it + * inside your organization for whatever purposes you see fit. But you + * may not re-distribute Paradyn or parts of Paradyn, in any form + * source or binary (including derivatives), electronic or otherwise, + * to any other organization or entity without our permission. + * + * (for other uses, please contact us at paradyn@cs.wisc.edu) + * + * All warranties, including without limitation, any warranty of + * merchantability or fitness for a particular purpose, are hereby + * excluded. + * + * 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. + * + * Even if advised of the possibility of such damages, under no + * circumstances shall we (or any other person or entity with + * proprietary rights in the software licensed hereunder) be liable + * to you or any third party for direct, indirect, or consequential + * damages of any character regardless of type of action, including, + * without limitation, loss of profits, loss of use, loss of good + * will, or computer failure or malfunction. You agree to indemnify + * us (and any other person or entity with proprietary rights in the + * software licensed hereunder) for any and all liability it may + * incur to third parties resulting from your use of Paradyn. + */ + +#ifndef _BPatch_sourceObj_h_ +#define _BPatch_sourceObj_h_ + +#include + +class BPatch_type; +class BPatch_variableExpr; + +typedef enum BPatch_language { + BPatch_c, + BPatch_cPlusPlus, + BPatch_fortran, + BPatch_fortran77, + BPatch_fortran90, + BPatch_assembly, + BPatch_mixed, + BPatch_hpf, + BPatch_java, + BPatch_unknownLanguage +}; + +typedef enum BPatch_sourceType { + BPatch_sourceUnknown_type, + BPatch_sourceProgram, + BPatch_sourceModule, + BPatch_sourceFunction, + BPatch_sourceOuterLoop, + BPatch_sourceLoop, + BPatch_sourceBlock, + BPatch_sourceStatement +}; + +class BPatch_sourceObj { + public: + BPatch_sourceType getSrcType() { return _srcType; } + virtual BPatch_Vector *getSourceObj() = 0; + virtual BPatch_sourceObj *getObjParent() = 0; + + BPatch_Vector *findVariable(const char *name); + BPatch_language getLanguage(); + BPatch_type *getType(char *name); + BPatch_Vector *getVariables(); + bool getLineNumbers(int &start, int &end); + BPatch_Vector *getLoadedFileNames(); + char *programName(char *buf, unsigned int len); + int programNameLen(); + + protected: + enum BPatch_sourceType _srcType; +}; + +#endif diff --git a/dyninstAPI/h/BPatch_thread.h b/dyninstAPI/h/BPatch_thread.h index ec082d9..5616a8d 100644 --- a/dyninstAPI/h/BPatch_thread.h +++ b/dyninstAPI/h/BPatch_thread.h @@ -103,6 +103,9 @@ public: */ class BPatch_thread { friend class BPatch; + friend class BPatch_image; + friend class BPatch_function; + friend class process; friend bool pollForStatusChange(); process *proc; @@ -141,8 +144,14 @@ class BPatch_thread { void *oneTimeCodeInternal(const BPatch_snippet &expr); protected: - BPatch_thread(char *path, char *argv[], char *envp[] = NULL); - BPatch_thread(char *path, int pid); + // for creating a process + BPatch_thread(char *path, char *argv[], char *envp[] = NULL, int stdin_fd = 0, + int stdout_fd = 1, int stderr_fd = 2); + // for attaching + BPatch_thread(char *path, int pid); + + // for forking + BPatch_thread(int childPid, process *proc); public: ~BPatch_thread(); -- 1.8.3.1