2 * Copyright (c) 1996 Barton P. Miller
4 * We provide the Paradyn Parallel Performance Tools (below
5 * described as Paradyn") on an AS IS basis, and do not warrant its
6 * validity or performance. We reserve the right to update, modify,
7 * or discontinue this software at any time. We shall have no
8 * obligation to supply such updates or modifications or any other
9 * form of support to you.
11 * This license is for research uses. For such uses, there is no
12 * charge. We define "research use" to mean you may freely use it
13 * inside your organization for whatever purposes you see fit. But you
14 * may not re-distribute Paradyn or parts of Paradyn, in any form
15 * source or binary (including derivatives), electronic or otherwise,
16 * to any other organization or entity without our permission.
18 * (for other uses, please contact us at paradyn@cs.wisc.edu)
20 * All warranties, including without limitation, any warranty of
21 * merchantability or fitness for a particular purpose, are hereby
24 * By your use of Paradyn, you understand and agree that we (or any
25 * other person or entity with proprietary rights in Paradyn) are
26 * under no obligation to provide either maintenance services,
27 * update services, notices of latent defects, or correction of
28 * defects for Paradyn.
30 * Even if advised of the possibility of such damages, under no
31 * circumstances shall we (or any other person or entity with
32 * proprietary rights in the software licensed hereunder) be liable
33 * to you or any third party for direct, indirect, or consequential
34 * damages of any character regardless of type of action, including,
35 * without limitation, loss of profits, loss of use, loss of good
36 * will, or computer failure or malfunction. You agree to indemnify
37 * us (and any other person or entity with proprietary rights in the
38 * software licensed hereunder) for any and all liability it may
39 * incur to third parties resulting from your use of Paradyn.
42 #ifndef _BPatch_thread_h_
43 #define _BPatch_thread_h_
48 * The following is a kludge so that the functions that refer to signals (such
49 * as BPatch_thread::stopSignal) can emulate the Unix behavior on Windows NT.
56 #include "BPatch_dll.h"
57 #include "BPatch_Vector.h"
58 #include "BPatch_image.h"
59 #include "BPatch_snippet.h"
62 class miniTrampHandle;
66 // BPatch_callWhen is defined in BPatch_point.h
69 * Used to specify whether a snippet should be installed before other snippets
70 * that have previously been inserted at the same point, or after.
75 } BPatch_snippetOrder;
79 * Contains information about the code that was inserted by an earlier call to
80 * Bpatch_thread::insertSnippet.
82 class BPATCH_DLL_EXPORT BPatchSnippetHandle {
83 friend class BPatch_thread;
85 BPatch_Vector<miniTrampHandle *> mtHandles;
90 BPatchSnippetHandle(process *_proc) : proc(_proc) {};
91 ~BPatchSnippetHandle();
93 void add(miniTrampHandle *pointInstance);
94 void getMiniTrampHandles(BPatch_Vector<miniTrampHandle *> *save_mtHandles) {
95 for(unsigned i=0; i<mtHandles.size(); i++)
96 (*save_mtHandles).push_back(mtHandles[i]);
101 * The following types are used by BPatch_thread::getCallStack()
108 BPatch_frameTrampoline
111 // Contains information about a stack frame (used by
112 class BPATCH_DLL_EXPORT BPatch_frame {
113 BPatch_thread *thread;
118 BPatch_frame() : thread(NULL), pc(NULL), fp(NULL) {};
119 BPatch_frame(BPatch_thread *_thread, void *_pc, void *_fp) :
120 thread(_thread), pc(_pc), fp(_fp) {};
122 BPatch_frameType getFrameType();
124 void *getPC() { return pc; };
125 void *getFP() { return fp; };
127 BPatch_function *findFunction();
129 // The following are planned but no yet implemented:
130 // int getSignalNumber();
131 // BPatch_point *findPoint();
135 * Represents a thread of execution.
137 class BPATCH_DLL_EXPORT BPatch_thread {
139 friend class BPatch_image;
140 friend class BPatch_function;
141 friend class BPatch_frame;
142 friend class process;
143 friend bool pollForStatusChange();
149 bool mutationsActive;
150 bool createdViaAttach;
154 bool unreportedTermination;
156 void setUnreportedStop(bool new_value)
157 { unreportedStop = new_value; }
158 void setUnreportedTermination(bool new_value)
159 { unreportedTermination = new_value; }
161 bool pendingUnreportedStop()
162 { return unreportedStop; }
163 bool pendingUnreportedTermination()
164 { return unreportedTermination; }
166 bool statusIsStopped();
167 bool statusIsTerminated();
169 static void oneTimeCodeCallbackDispatch(process *theProc,
173 void *oneTimeCodeInternal(const BPatch_snippet &expr,
178 // for creating a process
179 BPatch_thread(const char *path, char *argv[], char *envp[] = NULL,
180 int stdin_fd = 0, int stdout_fd = 1, int stderr_fd = 2);
182 BPatch_thread(const char *path, int pid);
185 BPatch_thread(int childPid, process *proc);
190 BPatch_image *getImage() { return image; }
194 bool stopExecution();
195 bool continueExecution();
196 bool terminateExecution();
201 int terminationStatus();
203 void detach(bool cont);
205 bool dumpCore(const char *file, bool terminate);
206 bool dumpImage(const char *file);
207 char* dumpPatchedImage(const char* file);//ccw 28 oct 2001
209 BPatch_variableExpr *malloc(int n);
210 BPatch_variableExpr *malloc(const BPatch_type &type);
211 void free(const BPatch_variableExpr &ptr);
212 BPatch_variableExpr *getInheritedVariable(const BPatch_variableExpr &pVar);
213 BPatchSnippetHandle *getInheritedSnippet(
214 BPatchSnippetHandle &parentSnippet);
217 // to provide backward compatiblity
218 BPatchSnippetHandle *insertSnippet(
219 const BPatch_snippet &expr,
221 BPatch_snippetOrder order = BPatch_firstSnippet);
223 BPatchSnippetHandle *insertSnippet(
224 const BPatch_snippet &expr,
226 BPatch_callWhen when,
227 BPatch_snippetOrder order = BPatch_firstSnippet);
229 BPatchSnippetHandle *insertSnippet(
230 const BPatch_snippet &expr,
231 const BPatch_Vector<BPatch_point *> &points,
232 BPatch_snippetOrder order = BPatch_firstSnippet);
234 BPatchSnippetHandle *insertSnippet(
235 const BPatch_snippet &expr,
236 const BPatch_Vector<BPatch_point *> &points,
237 BPatch_callWhen when,
238 BPatch_snippetOrder order = BPatch_firstSnippet);
240 bool deleteSnippet(BPatchSnippetHandle *handle);
242 void setMutationsActive(bool activate);
244 bool replaceFunctionCall(BPatch_point &point,
245 BPatch_function &newFunc);
246 bool removeFunctionCall(BPatch_point &point);
247 bool replaceFunction(BPatch_function &oldFunc,
248 BPatch_function &newFunc);
250 void oneTimeCode(const BPatch_snippet &expr) {
251 oneTimeCodeInternal(expr, NULL, true);
254 void oneTimeCodeAsync(const BPatch_snippet &expr, void *userData = NULL) {
255 oneTimeCodeInternal(expr, userData, false);
258 //the reload argument is used by save the world to determine
259 //if this library should be reloaded by the mutated binary
260 //when it starts up. this is up to the user because loading
261 //an extra shared library could hide access to the 'correct'
262 //function by redefining a function
263 bool loadLibrary(const char *libname, bool reload = false);
265 //method that retrieves the line number and file name corresponding
267 bool getLineAndFile(unsigned long addr,unsigned short& lineNo,
268 char* fileName,int length);
269 //returns the function containing an address
270 BPatch_function *findFunctionByAddr(void *addr);
272 void getCallStack(BPatch_Vector<BPatch_frame>& stack);
274 void startSaveWorld();//ccw 23 jan 2002
275 #ifdef IBM_BPATCH_COMPAT
276 bool isThreaded() { return false; }
277 bool addSharedObject(const char *name, const unsigned long loadaddr);
282 #endif /* BPatch_thread_h_ */