Fixes compile error and Merge branch 'Defensive' of ssh://coriander.cs.wisc.edu/u...
[dyninst.git] / dyninstAPI / h / BPatch_snippet.h
1 /*
2  * Copyright (c) 1996-2011 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  * By your use of Paradyn, you understand and agree that we (or any
12  * other person or entity with proprietary rights in Paradyn) are
13  * under no obligation to provide either maintenance services,
14  * update services, notices of latent defects, or correction of
15  * defects for Paradyn.
16  * 
17  * This library is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU Lesser General Public
19  * License as published by the Free Software Foundation; either
20  * version 2.1 of the License, or (at your option) any later version.
21  * 
22  * This library is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25  * Lesser General Public License for more details.
26  * 
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30  */
31
32 #ifndef _BPatch_snippet_h_
33 #define _BPatch_snippet_h_
34
35 #include "BPatch_dll.h"
36 #include "BPatch_Vector.h"
37 #include "BPatch_sourceObj.h"
38 #include "BPatch_type.h"
39 #include "BPatch_module.h"
40 //#include "BPatch_addressSpace.h"
41 //#include "BPatch_function.h"
42 #include "BPatch_eventLock.h"
43 #include "BPatch_callbacks.h"
44 #include "BPatch_instruction.h" // for register type
45 #include "BPatch_enums.h"
46 #include "dyn_detail/boost/shared_ptr.hpp"
47
48 class AstNode;
49 // Don't include the boost shared_ptr library
50 class BPatch_snippet;
51
52 namespace dyn_detail 
53 {
54    namespace boost {
55       template< typename T > class shared_ptr;
56       template<> class shared_ptr<AstNode *>;
57    }
58 }
59
60 namespace Dyninst {
61    namespace PatchAPI {
62       class DynASTSnippet;
63       DynASTSnippet *convert(const BPatch_snippet *);
64    }
65 }
66
67 typedef dyn_detail::boost::shared_ptr<AstNode> AstNodePtr;
68
69 class AstNode;
70 class process;
71 class BPatch_process;
72 class BPatch_function;
73 class BPatch_point;
74 class BPatch_addressSpace;
75 class int_variable;
76 class mapped_object;
77
78
79 typedef enum {
80     BPatch_lt,
81     BPatch_eq,
82     BPatch_gt,
83     BPatch_le,
84     BPatch_ne,
85     BPatch_ge,
86     BPatch_and,
87     BPatch_or
88 } BPatch_relOp;
89
90 typedef enum {
91     BPatch_assign,
92     BPatch_plus,
93     BPatch_minus,
94     BPatch_divide,
95     BPatch_times,
96     BPatch_mod,
97     BPatch_ref,
98     BPatch_fieldref,
99     BPatch_seq,
100     BPatch_bit_and,             // not supported yet
101     BPatch_bit_or,              // not supported yet
102     BPatch_bit_xor,             // not supported yet
103     BPatch_left_shift,          // not supported yet
104     BPatch_right_shift          // not supported yet
105 } BPatch_binOp;
106
107 // for backwards compatability
108 #define BPatch_addr BPatch_address
109
110 typedef enum {
111     BPatch_negate,
112     BPatch_address,
113 #ifdef IBM_BPATCH_COMPAT
114     BPatch_deref,
115     BPatch_bit_compl            // not supported yet
116 #else
117     BPatch_deref
118 #endif
119 } BPatch_unOp;
120
121 #ifdef DYNINST_CLASS_NAME
122 #undef DYNINST_CLASS_NAME
123 #endif
124 #define DYNINST_CLASS_NAME BPatch_snippet
125
126 class BPATCH_DLL_EXPORT BPatch_snippet : public BPatch_eventLock {
127
128     friend class BPatch_process;
129     friend class BPatch_binaryEdit;
130     friend class BPatch_addressSpace;
131     friend class BPatch_thread;
132     friend class BPatch_arithExpr;
133     friend class BPatch_boolExpr;
134     friend class BPatch_funcCallExpr;
135     friend class BPatch_variableExpr;
136     friend class BPatch_ifExpr;
137     friend class BPatch_ifMachineConditionExpr;
138     friend class BPatch_sequence;
139     friend class BPatch_insnExpr;
140     friend class BPatch_stopThreadExpr;
141     friend class BPatch_shadowExpr;
142     friend class BPatch_utilExpr;
143     friend AstNodePtr generateArrayRef(const BPatch_snippet &lOperand, 
144                                        const BPatch_snippet &rOperand);
145     friend AstNodePtr generateFieldRef(const BPatch_snippet &lOperand, 
146                                        const BPatch_snippet &rOperand);
147     friend AstNodePtr generateVariableBase(const BPatch_snippet &lOperand);
148     
149
150     public:
151
152     int PDSEP_astMinCost(); // This will go away too
153
154
155     //  BPatch_snippet::BPatch_snippet
156     //  Default constructor
157
158     BPatch_snippet();
159     BPatch_snippet(AstNodePtr ast) {BPatch_snippet(); ast_wrapper = ast;}
160
161     //  BPatch_snippet::BPatch_snippet
162     //  Copy constructor
163
164     public:  BPatch_snippet(const BPatch_snippet &src) : BPatch_eventLock(src)
165              { LOCK_FUNCTION_V(BPatch_snippetInt,(src)); }
166
167
168   public:
169     //DynC internal use only
170     //  BPatch_snippet::getType
171     //  Returns the type of the underlying AST
172     API_EXPORT(Int, (),
173     BPatch_type *,getType,());
174
175     operator Dyninst::PatchAPI::DynASTSnippet *() const;
176
177   private: 
178
179     void BPatch_snippetInt(const BPatch_snippet &src);
180     void BPatch_snippetInt(const AstNodePtr &node);
181     //  BPatch_snippet:operator=
182     //  Assign one BPatch_snippet to another
183     API_EXPORT_OPER(_equals, (src),
184
185     BPatch_snippet &,operator=,(const BPatch_snippet &src));
186
187     //  BPatch_snippet::~BPatch_snippet
188     //  Destructor, decrements reference count to snippet, deleting when none are left
189     API_EXPORT_DTOR(_dtor, (),
190     
191     ~,BPatch_snippet,());
192
193     //  BPatch_snippet::getCost
194     //  Returns an estimated cost of executing the snippet, in seconds.
195     API_EXPORT(Int, (),
196
197     float,getCost,());
198
199     //  BPatch_snippet::getCostAtPoint
200     //  Returns an estimated cost of executing the snippet at a specified point, in seconds.
201     API_EXPORT(Int, (pt),
202
203     float,getCostAtPoint,(BPatch_point *pt));
204
205     //  BPatch_snippet::is_trivial
206     //  allows users to check to see if
207     //  a snippet operation failed (leaving ast NULL)
208     API_EXPORT(Int, (),
209
210     bool,is_trivial,());
211
212     //    protected:
213     //AstNodePtr *ast_wrapper; 
214
215     AstNodePtr ast_wrapper;
216
217 };
218
219 #ifdef DYNINST_CLASS_NAME
220 #undef DYNINST_CLASS_NAME
221 #endif
222 #define DYNINST_CLASS_NAME BPatch_arithExpr
223
224 class BPATCH_DLL_EXPORT BPatch_arithExpr: public BPatch_snippet {
225
226     //  BPatch_arithExpr::BPatch_arithExpr (Binary Arithmetic Operation)
227     //  
228     API_EXPORT_CTOR(Bin, (op, lOperand, rOperand),
229     BPatch_arithExpr,(BPatch_binOp op,
230                       const BPatch_snippet &lOperand,
231                       const BPatch_snippet &rOperand));
232
233     //  BPatch_arithExpr::BPatch_arithExpr (Unary Arithmetic Operation)
234     //  
235     API_EXPORT_CTOR(Un, (op, lOperand),
236     BPatch_arithExpr,(BPatch_unOp op, const BPatch_snippet &lOperand));
237 };
238
239 #ifdef DYNINST_CLASS_NAME
240 #undef DYNINST_CLASS_NAME
241 #endif
242 #define DYNINST_CLASS_NAME BPatch_boolExpr
243
244 class BPATCH_DLL_EXPORT BPatch_boolExpr : public BPatch_snippet {
245
246     //  BPatch_boolExpr::BPatch_boolExpr
247     //  Creates a representation of boolean operation
248     API_EXPORT_CTOR(Int, (op, lOperand, rOperand),
249     BPatch_boolExpr,(BPatch_relOp op, const BPatch_snippet &lOperand,
250                      const BPatch_snippet &rOperand));
251 };
252
253 #ifdef DYNINST_CLASS_NAME
254 #undef DYNINST_CLASS_NAME
255 #endif
256 #define DYNINST_CLASS_NAME BPatch_constExpr
257
258 class BPATCH_DLL_EXPORT BPatch_constExpr : public BPatch_snippet {
259
260     //  BPatch_constExpr::BPatch_constExpr
261     //  Creates a representation of a (signed int) value
262     API_EXPORT_CTOR(SignedInt, (value),
263     BPatch_constExpr,(signed int value));
264
265     //  Creates a representation of an (unsigned int) value
266     API_EXPORT_CTOR(UnsignedInt, (value),
267     BPatch_constExpr,(unsigned int value));
268     
269     //  Creates a representation of a (signed long) value
270     API_EXPORT_CTOR(SignedLong, (value),
271     BPatch_constExpr,(signed long value));
272     
273     //  Creates a representation of an (unsigned long) value
274     API_EXPORT_CTOR(UnsignedLong, (value),
275     BPatch_constExpr,(unsigned long value));
276
277     //  BPatch_constExpr::BPatch_constExpr
278     //  Creates a representation of a (char *) value
279     API_EXPORT_CTOR(CharStar, (value),
280     BPatch_constExpr,(const char *value));
281
282     //  BPatch_constExpr::BPatch_constExpr
283     //  Creates a representation of a (void *) value
284     API_EXPORT_CTOR(VoidStar, (value),
285     BPatch_constExpr,(const void *value));
286
287     //  BPatch_constExpr::BPatch_constExpr
288     //  Creates a representation of a (long long) value
289     API_EXPORT_CTOR(LongLong, (value),
290     BPatch_constExpr,(long long value));
291
292 #ifdef IBM_BPATCH_COMPAT
293     //  BPatch_constExpr::BPatch_constExpr
294     //  Creates a representation of a (float) value
295     API_EXPORT_CTOR(Float, (value),
296     BPatch_constExpr,(float value));
297 #endif
298
299     // Should _always_ have a default constructor. This
300     // one produces a 0
301     BPatch_constExpr() : BPatch_snippet() {};
302
303 };
304
305 #ifdef DYNINST_CLASS_NAME
306 #undef DYNINST_CLASS_NAME
307 #endif
308 #define DYNINST_CLASS_NAME BPatch_regExpr
309
310 class BPATCH_DLL_EXPORT BPatch_regExpr : public BPatch_snippet {
311
312     // DEPRECATED!!!
313
314     //  BPatch_regExpr::BPatch_regExpr
315     //  Creates a representation of the contents of a particular register
316     //  specified by <value>
317     API_EXPORT_CTOR(Int, (value),
318     BPatch_regExpr,(unsigned int value));
319 };
320
321 #ifdef DYNINST_CLASS_NAME
322 #undef DYNINST_CLASS_NAME
323 #endif
324 #define DYNINST_CLASS_NAME BPatch_funcCallExpr
325
326 class BPATCH_DLL_EXPORT BPatch_funcCallExpr : public BPatch_snippet {
327
328     //  BPatch_funcCallExpr::BPatch_funcCallExpr
329     //  Creates a representation of a function call
330     API_EXPORT_CTOR(Int, (func, args),
331     BPatch_funcCallExpr,(const BPatch_function& func,
332                          const BPatch_Vector<BPatch_snippet *> &args));
333 };
334
335 #ifdef DYNINST_CLASS_NAME
336 #undef DYNINST_CLASS_NAME
337 #endif
338 #define DYNINST_CLASS_NAME BPatch_ifExpr
339
340 class BPATCH_DLL_EXPORT BPatch_ifExpr : public BPatch_snippet {
341
342     //  BPatch_ifExpr::BPatch_ifExpr
343     //  Creates a conditional expression "if <conditional> tClause;"
344     API_EXPORT_CTOR(Int, (conditional, tClause),
345     BPatch_ifExpr,(const BPatch_boolExpr &conditional,
346                    const BPatch_snippet &tClause));
347
348     //  BPatch_ifExpr::BPatch_ifExpr
349     //  Creates a conditional expression 
350     //  "if <conditional> tClause; else fClause;"
351     API_EXPORT_CTOR(WithElse, (conditional, tClause, fClause),
352     BPatch_ifExpr,(const BPatch_boolExpr &conditional,
353                    const BPatch_snippet &tClause,
354                    const BPatch_snippet &fClause));
355 };
356
357 #ifdef DYNINST_CLASS_NAME
358 #undef DYNINST_CLASS_NAME
359 #endif
360 #define DYNINST_CLASS_NAME BPatch_nullExpr
361
362 class BPATCH_DLL_EXPORT BPatch_nullExpr : public BPatch_snippet {
363
364     //  BPatch_nullExpr::BPatch_nullExpr
365     //  Creates a null snippet that can be used as a placeholder.
366     API_EXPORT_CTOR(Int, (),
367     BPatch_nullExpr,());
368
369 };
370
371 #ifdef DYNINST_CLASS_NAME
372 #undef DYNINST_CLASS_NAME
373 #endif
374 #define DYNINST_CLASS_NAME BPatch_paramExpr
375
376 class BPATCH_DLL_EXPORT BPatch_paramExpr : public BPatch_snippet {
377     //  BPatch_paramExpr::BPatch_paramExpr
378     //  Represents a parameter of a function (used in creating funcCallExpr)
379     //  n    is the index of the parameter that should be retrieved
380     //  loc  indicates whether the parameter lookup will be added at the call,
381     //       at the function's entry point, or whether Dyninst should guess
382     //       based on the instPoint type, which is error-prone and deprecated
383     API_EXPORT_CTOR(Int, (n,loc),
384     BPatch_paramExpr,(int n, BPatch_ploc loc=BPatch_ploc_guess));
385 };
386
387 #ifdef DYNINST_CLASS_NAME
388 #undef DYNINST_CLASS_NAME
389 #endif
390 #define DYNINST_CLASS_NAME BPatch_retExpr
391
392 class BPATCH_DLL_EXPORT BPatch_retExpr : public BPatch_snippet {
393
394     //  BPatch_retExpr::BPatch_retExpr
395     //  Represents the return value from the function in which the 
396     //  snippet is inserted
397     API_EXPORT_CTOR(Int, (),
398     BPatch_retExpr,());
399 };
400
401 #ifdef DYNINST_CLASS_NAME
402 #undef DYNINST_CLASS_NAME
403 #endif
404 #define DYNINST_CLASS_NAME BPatch_retAddrExpr
405
406 class BPATCH_DLL_EXPORT BPatch_retAddrExpr : public BPatch_snippet {
407
408     //  BPatch_retAddrExpr::BPatch_retAddrExpr
409     //  Represents the return address from the function in which the
410     //  snippet is inserted
411     API_EXPORT_CTOR(Int, (),
412     BPatch_retAddrExpr,());
413 };
414
415 #ifdef DYNINST_CLASS_NAME
416 #undef DYNINST_CLASS_NAME
417 #endif
418 #define DYNINST_CLASS_NAME BPatch_registerExpr
419
420 class BPATCH_DLL_EXPORT BPatch_registerExpr : public BPatch_snippet {
421     friend class BPatch_addressSpace;
422     //  BPatch_registerExpr::BPatch_registerExpr
423     //  Represents the return value from the function in which the 
424     //  snippet is inserted
425
426     API_EXPORT_CTOR(Int, (reg),
427                     BPatch_registerExpr, (BPatch_register reg));
428     API_EXPORT_CTOR(Int, (reg),
429                     BPatch_registerExpr, (Dyninst::MachRegister reg));
430 };
431
432 #ifdef DYNINST_CLASS_NAME
433 #undef DYNINST_CLASS_NAME
434 #endif
435 #define DYNINST_CLASS_NAME BPatch_sequence
436
437 class BPATCH_DLL_EXPORT BPatch_sequence : public BPatch_snippet {
438
439     //  BPatch_sequence::BPatch_sequence
440     //  Represents a sequence of statements
441     API_EXPORT_CTOR(Int, (items),
442     BPatch_sequence,(const BPatch_Vector<BPatch_snippet *> &items));
443 };
444
445 #ifdef DYNINST_CLASS_NAME
446 #undef DYNINST_CLASS_NAME
447 #endif
448 #define DYNINST_CLASS_NAME BPatch_variableExpr
449
450 class BPATCH_DLL_EXPORT BPatch_variableExpr : public BPatch_snippet 
451 {
452     friend class BPatch_process;
453     friend class BPatch_addressSpace;
454     friend class BPatch_binaryEdit;
455     friend class BPatch_image;
456     friend class BPatch_function;
457
458     const char          *name;
459     BPatch_addressSpace     *appAddSpace;
460     AddressSpace *lladdrSpace;
461     void                *address;
462     int                 size;
463     BPatch_point        *scope;
464     bool                isLocal;
465     BPatch_type *type;
466     int_variable *intvar;
467     
468
469     AddressSpace *getAS();
470  private:
471     // Used to get expressions for the components of a structure
472     // Used to get function pointers
473     BPatch_variableExpr(char *in_name, 
474                         BPatch_addressSpace *in_addSpace,
475                         AddressSpace *as,
476                         AstNodePtr ast_wrapper_,
477                         BPatch_type *type, void* in_address);
478     // Used to get forked copies of variable expressions
479     // Used by malloc & malloc_by_type
480     BPatch_variableExpr(BPatch_addressSpace *in_addSpace, 
481                         AddressSpace *as,
482                         void *in_address, 
483                         int in_register, BPatch_type *type, 
484                         BPatch_storageClass storage = BPatch_storageAddr,
485                         BPatch_point *scp = NULL);
486     // Used for locals (naturally)
487     BPatch_variableExpr(BPatch_addressSpace *in_addSpace,
488                         AddressSpace *as,
489                         BPatch_localVar *lv, BPatch_type *type,
490                         BPatch_point *scp);
491     
492     //    BPatch_variableExpr(const char *name, BPatch_addressSpace *in_addSpace,
493     //                    AddressSpace *ll_addSpace, void *in_address, 
494     //                    BPatch_type *type);
495     // Used by findOrCreateVariable
496     BPatch_variableExpr(BPatch_addressSpace *in_addSpace,
497                         AddressSpace *ll_addSpace, int_variable *iv,
498                         BPatch_type *type);
499
500     static BPatch_variableExpr* makeVariableExpr(BPatch_addressSpace* in_addSpace,
501                                                  int_variable* v,
502                                                  BPatch_type* type);
503     static BPatch_variableExpr* makeVariableExpr(BPatch_addressSpace* in_addSpace,
504                                                  AddressSpace* in_llAddSpace,
505                                                  std::string name,
506                                                  void* offset,
507                                                  BPatch_type* type);
508     
509     
510
511   public:
512
513     // Public functions for use by users of the library:
514
515     //  BPatch_variableExpr::getSize
516     //  Returns the size (in bytes) of this variable
517     API_EXPORT(Int, (),
518     unsigned int,getSize,() CONST_EXPORT);
519
520     //  BPatch_variableExpr::getType
521     //  Returns the type of this variable
522     API_EXPORT(Int, (),
523     const BPatch_type *,getType,());
524
525     //  BPatch_variableExpr::setType
526     //  Sets the type of this variable
527     //  XXX -- should this really be public?
528     API_EXPORT(Int, (t),
529     bool,setType,(BPatch_type *t));
530
531     //  BPatch_variableExpr::setSize
532     //  Sets the size of this variable
533     //  XXX -- should this really be public?
534     API_EXPORT(Int, (sz),
535     bool,setSize,(int sz));
536
537     //  BPatch_variableExpr::readValue
538     //  Read the value of a variable in a thread's address space.
539     //  <dst> is assumed to be the same size as the variable.
540     API_EXPORT(Int, (dst),
541     bool,readValue,(void *dst));
542
543     //  BPatch_variableExpr::readValue
544     //  Read the value of a variable in a thread's address space.
545     //  Will read <len> bytes into <dst>
546     API_EXPORT(WithLength, (dst, len),
547     bool,readValue,(void *dst, int len));
548
549     //  BPatch_variableExpr::writeValue
550     //  Write a value into a variable in a thread's address space.
551     //  variable is assumed to be the same size as the <dst>.
552     //  returns false if the type info isn't available (i.e. we don't know the size)
553     API_EXPORT(Int, (src, saveWorld),
554     bool,writeValue,(const void *src, bool saveWorld=false));
555
556     //  BPatch_variableExpr::writeValue
557     //  Write a value into a variable in a thread's address space.
558     //  Will write <len> bytes from <src> into variable
559     API_EXPORT(WithLength, (src, len, saveWorld),
560     bool,writeValue,(const void *src, int len,bool saveWorld=false));
561
562     //  BPatch_variableExpr::getName
563     //  Returns the symbol table name for this variable
564     API_EXPORT(Int, (),
565     const char *,getName,());
566
567     //  BPatch_variableExpr::getBaseAddr
568     //  Returns base address of this variable in the target's address space
569     API_EXPORT(Int, (),
570     void *,getBaseAddr,());
571
572     //  BPatch_variableExpr::getComponents
573     //  return variable expressions for all of the fields in a struct/union
574     API_EXPORT(Int, (),
575     BPatch_Vector<BPatch_variableExpr *> *,getComponents,());
576
577 #ifdef IBM_BPATCH_COMPAT
578     API_EXPORT(WithLength, (buffer, max),
579     char *,getName,(char *buffer, int max));
580
581     API_EXPORT(Int, (),
582     void *,getAddress,());
583
584 #endif
585
586 };
587
588 #ifdef DYNINST_CLASS_NAME
589 #undef DYNINST_CLASS_NAME
590 #endif
591 #define DYNINST_CLASS_NAME BPatch_breakPointExpr
592
593 class BPATCH_DLL_EXPORT BPatch_breakPointExpr : public BPatch_snippet {
594
595     //  BPatch_breakPointExpr::BPatch_breakPointExpr
596     //  Creates a representation of a break point in the target process
597
598     API_EXPORT_CTOR(Int, (),
599     BPatch_breakPointExpr,());
600 };
601
602 // VG(11/05/01): This nullary snippet will return the effective
603 // address of a memory access when inserted at an instrumentation
604 // point that is a memory access.  In other words, the instruction at
605 // the point where it is inserted is the one to get effective address
606 // for.  Furthermore, there must be memory access information about
607 // the inst. point; this basically means that the point must have been
608 // created using a method that attaches that info to the point -
609 // e.g. using findPoint(const BPatch_Set<BPatch_opCode>& ops) from
610 // BPatch_function.
611
612 // VG(7/31/02): Since x86 can have 2 addresses per instruction, there is
613 // now parameter for the constructor indicating which of these you want.
614 // It defaults to the 1st access (#0).
615
616 // VG(8/14/02): added conditional parameter
617
618 #ifdef DYNINST_CLASS_NAME
619 #undef DYNINST_CLASS_NAME
620 #endif
621 #define DYNINST_CLASS_NAME BPatch_effectiveAddressExpr
622
623 class BPATCH_DLL_EXPORT BPatch_effectiveAddressExpr : public BPatch_snippet
624 {
625
626   //  BPatch_effectiveAddressExpr:: BPatch_effectiveAddressExpr
627   //  Construct a snippet representing an effective address.
628
629   API_EXPORT_CTOR(Int, (_which),
630   BPatch_effectiveAddressExpr,(int _which = 0));
631 };
632
633 #ifdef DYNINST_CLASS_NAME
634 #undef DYNINST_CLASS_NAME
635 #endif
636 #define DYNINST_CLASS_NAME BPatch_bytesAccessedExpr
637
638 // Number of bytes moved
639 class BPATCH_DLL_EXPORT BPatch_bytesAccessedExpr : public BPatch_snippet
640 {
641
642   //  BPatch_bytesAccessedExpr::BPatch_bytesAccessedExpr
643   //  Construct a snippet representing the number of bytes accessed.
644
645   API_EXPORT_CTOR(Int, (_which),
646   BPatch_bytesAccessedExpr,(int _which = 0));
647 };
648
649 // VG(8/11/2): It is possible to have a more general expression, say 
650 // machineConditionExpr, then have this reimplemented as ifExpr(machineConditionExpr, ...),
651 // and have an optimization (fast path) for that case using the specialized
652 // AST that supports this class. Memory instrumentation has no need for a standalone
653 // machineConditionExpr, so that remains TBD...
654
655 #ifdef DYNINST_CLASS_NAME
656 #undef DYNINST_CLASS_NAME
657 #endif
658 #define DYNINST_CLASS_NAME BPatch_ifMachineConditionExpr
659
660 class BPATCH_DLL_EXPORT BPatch_ifMachineConditionExpr : public BPatch_snippet {
661
662   //  BPatch_ifMachineConditionExpr::BPatch_ifMachineConditionExpr
663   //  
664
665   API_EXPORT_CTOR(Int, (tClause),
666   BPatch_ifMachineConditionExpr,(const BPatch_snippet &tClause));
667 };
668
669 #ifdef DYNINST_CLASS_NAME
670 #undef DYNINST_CLASS_NAME
671 #endif
672 #define DYNINST_CLASS_NAME BPatch_threadIndexExpr
673
674 class BPATCH_DLL_EXPORT BPatch_threadIndexExpr : public BPatch_snippet {
675   //
676   // BPatch_threadIndexExpr::BPatch_threadIndexExpr
677   API_EXPORT_CTOR(Int, (),
678   BPatch_threadIndexExpr,());
679 };
680
681 #ifdef DYNINST_CLASS_NAME
682 #undef DYNINST_CLASS_NAME
683 #endif
684 #define DYNINST_CLASS_NAME BPatch_tidExpr
685
686 class BPATCH_DLL_EXPORT BPatch_tidExpr : public BPatch_snippet {
687   //
688   // BPatch_tidExpr::BPatch_tidExpr
689   API_EXPORT_CTOR(Int, (proc),
690   BPatch_tidExpr,(BPatch_process *proc));
691 };
692
693 class BPatch_instruction;
694
695 #ifdef DYNINST_CLASS_NAME
696 #undef DYNINST_CLASS_NAME
697 #endif
698 #define DYNINST_CLASS_NAME BPatch_insnExpr
699
700 class BPATCH_DLL_EXPORT BPatch_insnExpr : public BPatch_snippet {
701     //
702     // BPatch_insnExpr::BPatch_insnExpr
703     API_EXPORT_CTOR(Int, (insn),
704                     BPatch_insnExpr,(BPatch_instruction *insn));
705     
706     // Replace the effective address of a load with the provided snippet
707     API_EXPORT(Int, (l), 
708     bool, overrideLoadAddress, (BPatch_snippet &l));
709
710     // Replace the effective address of a store with the provided snippet
711     API_EXPORT(Int, (s), 
712     bool, overrideStoreAddress, (BPatch_snippet &s));
713
714 };
715
716 typedef enum {
717     BPatch_noInterp,
718     BPatch_interpAsTarget,
719     BPatch_interpAsReturnAddr,
720 } BPatch_stInterpret;
721
722 #ifdef DYNINST_CLASS_NAME
723 #undef DYNINST_CLASS_NAME
724 #endif
725 #define DYNINST_CLASS_NAME BPatch_shadowExpr
726
727 class BPATCH_DLL_EXPORT BPatch_shadowExpr : public BPatch_snippet {
728
729   // BPatch_stopThreadExpr 
730   //  This snippet type stops the thread that executes it.  It
731   //  evaluates a calculation snippet and triggers a callback to the
732   //  user program with the result of the calculation and a pointer to
733   //  the BPatch_point at which the snippet was inserted
734   API_EXPORT_CTOR(Int, (entry, cb, calculation, useCache, interp),
735   BPatch_shadowExpr, 
736   (bool entry, 
737   const BPatchStopThreadCallback &cb,
738    const BPatch_snippet &calculation,
739    bool useCache = false,
740    BPatch_stInterpret interp = BPatch_noInterp));
741 };
742
743 #ifdef DYNINST_CLASS_NAME
744 #undef DYNINST_CLASS_NAME
745 #endif
746 #define DYNINST_CLASS_NAME BPatch_stopThreadExpr
747
748 class BPATCH_DLL_EXPORT BPatch_stopThreadExpr : public BPatch_snippet {
749
750   // BPatch_stopThreadExpr 
751   //  This snippet type stops the thread that executes it.  It
752   //  evaluates a calculation snippet and triggers a callback to the
753   //  user program with the result of the calculation and a pointer to
754   //  the BPatch_point at which the snippet was inserted
755   API_EXPORT_CTOR(Int, (cb, calculation, useCache, interp),
756   BPatch_stopThreadExpr, 
757   (const BPatchStopThreadCallback &cb,
758    const BPatch_snippet &calculation,
759    bool useCache = false,
760    BPatch_stInterpret interp = BPatch_noInterp));
761
762   // for internal use in conjunction with memory emulation and defensive 
763   // mode analysis
764   BPatch_stopThreadExpr(
765    const BPatchStopThreadCallback &cb,
766    const BPatch_snippet &calculation,
767    const mapped_object &obj,
768    bool useCache = false,
769    BPatch_stInterpret interp = BPatch_noInterp);
770 };
771
772 #ifdef DYNINST_CLASS_NAME
773 #undef DYNINST_CLASS_NAME
774 #endif
775 #define DYNINST_CLASS_NAME BPatch_originalAddressExpr
776
777 class BPATCH_DLL_EXPORT BPatch_originalAddressExpr : public BPatch_snippet
778 {
779
780   //  BPatch_originalAddressExpr
781   //  Construct a snippet representing the original address of an 
782   //  instruction
783
784   API_EXPORT_CTOR(Int, (),
785   BPatch_originalAddressExpr, ());
786 };
787
788 #ifdef DYNINST_CLASS_NAME
789 #undef DYNINST_CLASS_NAME
790 #endif
791 #define DYNINST_CLASS_NAME BPatch_actualAddressExpr
792
793 class BPATCH_DLL_EXPORT BPatch_actualAddressExpr : public BPatch_snippet
794 {
795
796   //  BPatch_actualAddressExpr
797   //  Construct a snippet representing the actual (relocated) address
798   //  where the snippet was executed.
799
800   API_EXPORT_CTOR(Int, (),
801   BPatch_actualAddressExpr, ());
802 };
803
804 #ifdef DYNINST_CLASS_NAME
805 #undef DYNINST_CLASS_NAME
806 #endif
807 #define DYNINST_CLASS_NAME BPatch_dynamicTargetExpr
808
809 class BPATCH_DLL_EXPORT BPatch_dynamicTargetExpr : public BPatch_snippet
810 {
811
812   //  BPatch_dynamicTargetExpr
813   //  Construct a snippet to calculate the target of a 
814   //  dynamic control transfer instruction
815
816   API_EXPORT_CTOR(Int, (),
817   BPatch_dynamicTargetExpr, ());
818 };
819
820 #endif /* _BPatch_snippet_h_ */
821
822