Changes to work towards compatability with IBM's version of dyninst.
[dyninst.git] / dyninstAPI / h / BPatch.h
1 /*
2  * Copyright (c) 1996 Barton P. Miller
3  * 
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.
10  * 
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.
17  * 
18  * (for other uses, please contact us at paradyn@cs.wisc.edu)
19  * 
20  * All warranties, including without limitation, any warranty of
21  * merchantability or fitness for a particular purpose, are hereby
22  * excluded.
23  * 
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.
29  * 
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.
40  */
41
42 #ifndef _BPatch_h_
43 #define _BPatch_h_
44
45 #include <stdio.h>
46 #include "BPatch_dll.h"
47 #include "BPatch_Vector.h"
48 #include "BPatch_thread.h"
49 #include "BPatch_type.h"
50
51 #ifdef mips_unknown_ce2_11 //ccw 28 july 2000
52 #include "remoteDevice.h"
53 #endif
54
55 class BPatch_typeCollection;
56 class BPatch_libInfo;
57 class BPatch_module;
58
59 typedef enum {
60     BPatchFatal, BPatchSerious, BPatchWarning, BPatchInfo
61 } BPatchErrorLevel;
62
63 typedef void (*BPatchErrorCallback)(BPatchErrorLevel severity,
64                                     int number,
65                                     const char **params);
66
67 typedef void (*BPatchDynLibraryCallback)(BPatch_thread *thr,
68                                          BPatch_module *mod,
69                                          bool load);
70
71 typedef void (*BPatchForkCallback)(BPatch_thread *parent, BPatch_thread *child);
72
73 typedef void (*BPatchExecCallback)(BPatch_thread *proc);
74
75 typedef void (*BPatchExitCallback)(BPatch_thread *proc, int code);
76
77 typedef void (*BPatchSignalCallback)(BPatch_thread *proc, int sigNum);
78
79
80 #ifdef IBM_BPATCH_COMPAT
81 typedef void *BPatch_Address;
82 typedef void (*BPatchLoggingCallback)(char *msg, int);
83 extern void setLogging_NP(BPatchLoggingCallback func, int);
84
85 typedef void (*BPatchThreadEventCallback)(BPatch_thread *thr, void *arg1, void *arg2);
86
87 #define BP_OK                   0
88 #define BP_Pending              1
89 #define BP_Delayed              2
90 #define BP_child                3
91 #define BP_state                4
92 #define BP_pthdbBadContext      5
93 #define BP_lastCode             6
94
95 extern int eCodes[BP_lastCode];
96
97 #endif
98
99 class BPATCH_DLL_EXPORT BPatch {
100     friend class BPatch_thread;
101     friend class process;
102
103     BPatch_libInfo      *info;
104
105     BPatchErrorCallback         errorHandler;
106     BPatchDynLibraryCallback    dynLibraryCallback;
107     BPatchForkCallback          postForkCallback;
108     BPatchForkCallback          preForkCallback;
109     BPatchExecCallback          execCallback;
110     BPatchExitCallback          exitCallback;
111     bool        typeCheckOn;
112     int         lastError;
113     bool        debugParseOn;
114
115     bool        getThreadEvent(bool block);
116     bool        havePendingEvent();
117
118     /* If true, trampolines can recurse to their heart's content.
119        Defaults to false */
120     bool        trampRecursiveOn;
121     bool        forceRelocation_NP;
122
123 public:
124     static BPatch                *bpatch;
125
126     BPatch_builtInTypeCollection *builtInTypes;
127     BPatch_typeCollection        *stdTypes;
128     BPatch_typeCollection        *APITypes; //API/User defined types
129     BPatch_type                  *type_Error;
130     BPatch_type                  *type_Untyped;
131 #ifdef mips_unknown_ce2_11 //ccw 28 july 2000
132         remoteDevice *rDevice;  //the ctor sets up the connection here and
133                                 //gets the tramptemplate from the CE device.
134 #endif
135
136  
137     bool isTypeChecked() { return typeCheckOn; }
138     bool parseDebugInfo() { return debugParseOn; }
139     bool isTrampRecursive() { return trampRecursiveOn; }
140     bool hasForcedRelocation_NP() { return forceRelocation_NP; }
141
142     // The following are only to be called by the library:
143     void registerProvisionalThread(int pid);
144     void registerForkedThread(int parentPid, int childPid, process *proc);
145     void registerExec(BPatch_thread *thread);
146     void registerExit(BPatch_thread *thread, int code);
147     void registerThread(BPatch_thread *thread);
148     void unRegisterThread(int pid);
149
150     BPatch_thread *getThreadByPid(int pid, bool *exists = NULL);
151
152     static void reportError(BPatchErrorLevel severity, int number, const char *str);
153
154     void clearError() { lastError = 0; }
155     int getLastError() { return lastError; }
156     // End of functions that are for internal use only
157
158 #ifdef IBM_BPATCH_COMPAT
159     int getLastErrorCode() { return lastError; }
160
161     BPatchThreadEventCallback registerDetachDoneCallback(BPatchThreadEventCallback) { return NULL; }
162     BPatchThreadEventCallback registerSnippetRemovedCallback(BPatchThreadEventCallback) { return NULL; }
163     BPatchSignalCallback registerSignalCallback(BPatchSignalCallback func, int sigNum) { return NULL; }
164
165     BPatchThreadEventCallback registerRPCTerminationCallback(BPatchThreadEventCallback);
166     BPatchThreadEventCallback           RPCdoneCallback;
167 #endif
168
169     BPatch();
170     ~BPatch();
171
172     static const char *getEnglishErrorString(int number);
173     static void formatErrorString(char *dst, int size,
174                                   const char *fmt, const char **params);
175     BPatchErrorCallback registerErrorCallback(BPatchErrorCallback function);
176     BPatchDynLibraryCallback registerDynLibraryCallback(BPatchDynLibraryCallback function);
177     BPatchForkCallback registerPostForkCallback(BPatchForkCallback func);
178     BPatchForkCallback registerPreForkCallback(BPatchForkCallback func);
179     BPatchExecCallback registerExecCallback(BPatchExecCallback func);
180     BPatchExitCallback registerExitCallback(BPatchExitCallback func);
181
182     BPatch_Vector<BPatch_thread*> *getThreads();
183
184     void setDebugParsing(bool x) { debugParseOn = x; }
185     void setTypeChecking(bool x) { typeCheckOn = x; }
186     void setTrampRecursive(bool x) { trampRecursiveOn = x; }
187     void setForcedRelocation_NP(bool x) { forceRelocation_NP = x; }
188
189     BPatch_thread *createProcess(char *path, char *argv[], 
190         char *envp[] = NULL, int stdin_fd=0, int stdout_fd=1, int stderr_fd=2);
191     BPatch_thread *attachProcess(char *path, int pid);
192
193     // Create Enum types. 
194     BPatch_type * createEnum(const char * name, 
195         BPatch_Vector<char *> elementNames,
196         BPatch_Vector<int> elementIds);
197     
198     // API selects elemetIds
199     BPatch_type * createEnum(const char * name, 
200         BPatch_Vector<char *> elementNames);
201
202     // Create Struct types. 
203     BPatch_type * createStruct( const char * name,
204                                 BPatch_Vector<char *> fieldNames,
205                                 BPatch_Vector<BPatch_type *> fieldTypes);
206
207     // Create Union types. 
208     BPatch_type * createUnion( const char * name, 
209                                 BPatch_Vector<char *> fieldNames,
210                                 BPatch_Vector<BPatch_type *> fieldTypes);
211  
212     // Creates BPatch_array type or symtyperanges ( scalars with upper and
213    //lower bound).
214     BPatch_type * createArray( const char * name, BPatch_type * ptr,
215                                unsigned int low, unsigned int hi );
216
217     // Creates BPatch_pointer types      
218     BPatch_type * createPointer( const char * name, BPatch_type * ptr,
219                                  int size = sizeof(void *));
220
221     // Creates BPatch_scalar types
222     BPatch_type * createScalar( const char * name, int size );
223     
224     // Creates typedefs.
225     BPatch_type * createTypedef( const char * name, BPatch_type * ptr );
226          
227     bool        pollForStatusChange();
228     bool        waitForStatusChange();
229 };
230
231 #endif /* _BPatch_h_ */