This commit enables arbitrary instrumentation points at the last instruction
[dyninst.git] / dyninstAPI / h / BPatch_point.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_point_h_
43 #define _BPatch_point_h_
44
45 #include "BPatch_dll.h"
46 #include "BPatch_Vector.h"
47
48 class process;
49 class instPoint;
50 class BPatch_thread;
51 class BPatch_image;
52 class BPatch_function;
53 class BPatch_memoryAccess;
54 class BPatchSnippetHandle;
55
56 /*
57  * Used to specify whether a snippet is to be called before the instructions
58  * at the point where it is inserted, or after.
59  */
60 typedef enum {
61     BPatch_callBefore,
62     BPatch_callAfter
63 } BPatch_callWhen;
64
65 /*
66  * Provide these definitions for backwards compatability.
67  *
68  */
69 #define BPatch_entry BPatch_locEntry
70 #define BPatch_exit BPatch_locExit
71 #define BPatch_subroutine BPatch_locSubroutine
72 #define BPatch_longJump BPatch_locLongJump
73 #define BPatch_allLocations BPatch_locAllLocations
74 #define BPatch_instruction BPatch_locInstruction
75
76 /*
77  * Used with BPatch_function::findPoint to specify which of the possible
78  * instrumentation points within a procedure should be returned.
79  */
80 typedef enum eBPatch_procedureLocation {
81     BPatch_locEntry,
82     BPatch_locExit,
83     BPatch_locSubroutine,
84     BPatch_locLongJump,
85     BPatch_locAllLocations,
86     BPatch_locInstruction,
87     BPatch_locSourceBlockEntry,         // not yet used
88     BPatch_locSourceBlockExit,          // not yet used
89     BPatch_locSourceLoopEntry,          // not yet used
90     BPatch_locSourceLoopExit,           // not yet used
91     BPatch_locBasicBlockEntry,          // not yet used
92     BPatch_locBasicBlockExit,           // not yet used
93     BPatch_locSourceLoop,               // not yet used
94     BPatch_locBasicBlockLoopEntry,      // not yet used
95     BPatch_locBasicBlockLoopExit,       // not yet used
96     BPatch_locVarInitStart,             // not yet used
97     BPatch_locVarInitEnd,               // not yet used
98     BPatch_locStatement         // not yet used
99 } BPatch_procedureLocation;
100
101
102 /* VG (09/07/01) Created */
103
104 typedef enum eBPatch_opCode {
105   BPatch_opLoad,
106   BPatch_opStore,
107   BPatch_opPrefetch
108 } BPatch_opCode;
109
110 /* VG(09/17/01) Added memory access pointer */
111
112 /* VG(11/06/01) Moved constructor to implementation file because it
113    needs to link instPoint back pointer (and we don't want to include
114    that here) */
115 class BPATCH_DLL_EXPORT BPatch_point {
116     friend class BPatch_thread;
117     friend class BPatch_image;
118     friend class BPatch_function;
119     friend class process;
120     friend BPatch_point* createInstructionInstPoint(process*proc,void*address,
121                                                     BPatch_point** alternative,
122                                                     BPatch_function* bpf = NULL);
123     friend BPatch_point* createInstPointForMemAccess(process *proc,
124                                                      void *addr,
125                                                      BPatch_memoryAccess* ma,
126                                                      BPatch_point** alternative);
127     process     *proc;
128     const BPatch_function       *func;
129     instPoint   *point;
130     BPatch_procedureLocation pointType;
131     BPatch_memoryAccess *memacc;
132
133     BPatch_point(process *_proc, BPatch_function *_func, instPoint *_point,
134                  BPatch_procedureLocation _pointType, BPatch_memoryAccess* _ma = NULL);
135 public:
136     //~BPatch_point() { delete memacc; };
137
138     const BPatch_procedureLocation getPointType() { return pointType; }
139     const BPatch_function *getFunction() { return func; }
140     BPatch_function *getCalledFunction();
141     void            *getAddress();
142     const BPatch_memoryAccess* getMemoryAccess() const { return memacc; }
143
144     // to get all current snippets at this point
145     const BPatch_Vector<BPatchSnippetHandle *> getCurrentSnippets();
146
147     // to get all current snippets as defined by when at this point
148     const BPatch_Vector<BPatchSnippetHandle *> 
149                getCurrentSnippets(BPatch_callWhen when);
150
151 #ifdef IBM_BPATCH_COMPAT
152     void *getPointAddress() { return getAddress(); }
153
154     int getPointLine() { return -1; }
155
156     BPatch_function     *getContainingFunction() { return const_cast<BPatch_function*>(getFunction()); };
157 #endif
158
159     int             getDisplacedInstructions(int maxSize, void *insns);
160
161     bool        usesTrap_NP();
162 };
163
164 #endif /* _BPatch_point_h_ */