1 /*--------------------------------------------------------------------*/
4 /*--- (C) 2004, 2005 Josef Weidendorfer ---*/
5 /*--------------------------------------------------------------------*/
10 #include "pub_tool_basics.h"
11 #include "pub_tool_vki.h"
12 #include "pub_tool_debuginfo.h"
13 #include "pub_tool_libcbase.h"
14 #include "pub_tool_libcassert.h"
15 #include "pub_tool_libcfile.h"
16 #include "pub_tool_libcprint.h"
17 #include "pub_tool_libcproc.h"
18 #include "pub_tool_machine.h"
19 #include "pub_tool_mallocfree.h"
20 #include "pub_tool_options.h"
21 #include "pub_tool_tooliface.h"
22 #include "pub_tool_xarray.h"
23 #include "pub_tool_clientstate.h"
24 #include "pub_tool_machine.h" // VG_(fnptr_to_fnentry)
26 #include "events.h" // defines CLG_ macro
30 /*------------------------------------------------------------*/
31 /*--- Calltree compile options --- */
32 /*------------------------------------------------------------*/
34 /* Enable debug output */
35 #define CLG_ENABLE_DEBUG 1
37 /* Enable experimental features? */
38 #define CLG_EXPERIMENTAL 0
40 /* Syscall Timing in microseconds?
41 * (define to 0 if you get compile errors) */
42 #define CLG_MICROSYSTIME 0
44 /* Set to 1 if you want full sanity checks for JCC */
49 /*------------------------------------------------------------*/
50 /*--- Command line options ---*/
51 /*------------------------------------------------------------*/
53 #define DEFAULT_OUTFORMAT "callgrind.out.%p"
54 #define DEFAULT_COMMANDNAME "callgrind.cmd"
55 #define DEFAULT_RESULTNAME "callgrind.res"
56 #define DEFAULT_INFONAME "/tmp/callgrind.info"
58 typedef struct _CommandLineOptions CommandLineOptions;
59 struct _CommandLineOptions {
61 /* Dump format options */
62 Char* out_format; /* Format string for callgrind output file name */
63 Bool combine_dumps; /* Dump trace parts into same file? */
64 Bool compress_strings;
68 Bool compress_mangled;
72 Bool dump_bbs; /* Dump basic block information? */
74 /* Dump generation options */
75 ULong dump_every_bb; /* Dump every xxx BBs. */
77 /* Collection options */
78 Bool separate_threads; /* Separate threads in dump? */
79 Int separate_callers; /* Separate dependent on how many callers? */
80 Int separate_recursions; /* Max level of recursions to separate */
81 Bool skip_plt; /* Skip functions in PLT section? */
82 Bool skip_direct_recursion; /* Increment direct recursions the level? */
84 Bool collect_atstart; /* Start in collecting state ? */
85 Bool collect_jumps; /* Collect (cond.) jumps in functions ? */
87 Bool collect_alloc; /* Collect size of allocated memory */
88 Bool collect_systime; /* Collect time for system calls */
90 /* Instrument options */
91 Bool instrument_atstart; /* Instrument at start? */
92 Bool simulate_cache; /* Call into cache simulator ? */
94 /* Call graph generation */
95 Bool pop_on_jump; /* Handle a jump between functions as ret+call */
103 /*------------------------------------------------------------*/
104 /*--- Constants ---*/
105 /*------------------------------------------------------------*/
108 /* According to IA-32 Intel Architecture Software Developer's Manual: Vol 2 */
109 #define MAX_x86_INSTR_SIZE 16
111 /* Minimum cache line size allowed */
112 #define MIN_LINE_SIZE 16
114 /* Size of various buffers used for storing strings */
115 #define FILENAME_LEN 256
116 #define FN_NAME_LEN 4096 /* for C++ code :-) */
117 #define OBJ_NAME_LEN 256
119 #define COMMIFY_BUF_LEN 128
120 #define RESULTS_BUF_LEN 128
121 #define LINE_BUF_LEN 64
124 /* Convenience macros */
126 /* Use this only when size of sprintf args are known to fit into
127 * given buffer; for strings of unknown length, use WRITE_STR below
129 #define WRITE_SPRINTF(fd, zz_buf, fmt, args...) \
130 do { Int len = VG_(sprintf)(zz_buf, fmt, ## args); \
131 VG_(write)(fd, (void*)zz_buf, len); \
134 #define WRITE_STR(fd, str) \
135 do { if (str) { Int len = VG_(strlen)(str); \
136 VG_(write)(fd, (void*)str, len); } \
137 else VG_(write)(fd, "(null)", 6); \
140 #define WRITE_STR2(fd, str1, str2) \
141 do { if (str1) { Int len = VG_(strlen)(str1); \
142 VG_(write)(fd, (void*)str1, len); } \
143 else VG_(write)(fd, "(null)", 6); \
144 if (str2) { Int len = VG_(strlen)(str2); \
145 VG_(write)(fd, (void*)str2, len); } \
146 else VG_(write)(fd, "(null)", 6); \
149 #define WRITE_STR3(fd, str1, str2, str3) \
150 do { if (str1) { Int len = VG_(strlen)(str1); \
151 VG_(write)(fd, (void*)str1, len); } \
152 else VG_(write)(fd, "(null)", 6); \
153 if (str2) { Int len = VG_(strlen)(str2); \
154 VG_(write)(fd, (void*)str2, len); } \
155 else VG_(write)(fd, "(null)", 6); \
156 if (str3) { Int len = VG_(strlen)(str3); \
157 VG_(write)(fd, (void*)str3, len); } \
158 else VG_(write)(fd, "(null)", 6); \
162 /*------------------------------------------------------------*/
163 /*--- Statistics ---*/
164 /*------------------------------------------------------------*/
166 typedef struct _Statistics Statistics;
171 ULong rec_call_counter;
176 Int bb_retranslations;
181 Int distinct_contexts;
189 Int bbcc_hash_resizes;
190 Int jcc_hash_resizes;
191 Int cxt_hash_resizes;
192 Int fn_array_resizes;
193 Int call_stack_resizes;
194 Int fn_stack_resizes;
197 Int file_line_debug_BBs;
198 Int fn_name_debug_BBs;
207 /*------------------------------------------------------------*/
208 /*--- Structure declarations ---*/
209 /*------------------------------------------------------------*/
211 typedef struct _Context Context;
212 typedef struct _CC CC;
213 typedef struct _BB BB;
214 typedef struct _Skipped Skipped;
215 typedef struct _BBCC BBCC;
216 typedef struct _jCC jCC;
217 typedef struct _fCC fCC;
218 typedef struct _fn_node fn_node;
219 typedef struct _file_node file_node;
220 typedef struct _obj_node obj_node;
221 typedef struct _fn_config fn_config;
222 typedef struct _call_entry call_entry;
223 typedef struct _thread_info thread_info;
225 /* Costs of event sets. Aliases to arrays of 64-bit values */
226 typedef ULong* SimCost; /* All events the simulator can produce */
227 typedef ULong* UserCost;
228 typedef ULong* FullCost; /* Simulator + User */
231 /* JmpCall cost center
232 * for subroutine call (from->bb->jmp_addr => to->bb->addr)
234 * Each BB has at most one CALL instruction. The list of JCC from
235 * this call is a pointer to the list head (stored in BBCC), and
236 * <next_from> in the JCC struct.
238 * For fast lookup, JCCs are reachable with a hash table, keyed by
239 * the (from_bbcc,to) pair. <next_hash> is used for the JCC chain
240 * of one hash table entry.
242 * Cost <sum> holds event counts for already returned executions.
243 * <last> are the event counters at last enter of the subroutine.
244 * <sum> is updated on returning from the subroutine by
245 * adding the diff of <last> and current event counters to <sum>.
247 * After updating, <last> is set to current event counters. Thus,
248 * events are not counted twice for recursive calls (TODO: True?)
250 #define JmpNone (Ijk_Boring+30)
251 #define JmpCond (Ijk_Boring+31)
254 Int jmpkind; /* JmpCall, JmpBoring, JmpCond */
255 jCC* next_hash; /* for hash entry chain */
256 jCC* next_from; /* next JCC from a BBCC */
257 BBCC *from, *to; /* call arc from/to this BBCC */
258 UInt jmp; /* jump no. in source */
260 ULong call_counter; /* no wraparound with 64 bit */
262 FullCost cost; /* simulator + user counters */
267 * Info for one instruction of a basic block.
269 typedef struct _InstrInfo InstrInfo;
279 * Info for a conditional jump in a basic block
281 typedef struct _CJmpInfo CJmpInfo;
283 UInt instr; /* instruction index in this basic block */
284 Bool skip; /* Cond.Jumps to next instruction should be ignored */
289 * An instrumented basic block (BB).
291 * BBs are put into a resizable hash to allow for fast detection if a
292 * BB is to be retranslated but cost info is already available.
293 * The key for a BB is a (object, offset) tupel making it independent
294 * from possibly multiple mappings of the same ELF object.
296 * At the beginning of each instrumented BB,
297 * a call to setup_bbcc(), specifying a pointer to the
298 * according BB structure, is added.
300 * As cost of a BB has to be distinguished depending on the context,
301 * multiple cost centers for one BB (struct BBCC) exist and the according
302 * BBCC is set by setup_bbcc.
305 obj_node* obj; /* ELF object of BB */
306 PtrdiffT offset; /* offset of BB in ELF object file */
307 BB* next; /* chaining for a hash entry */
309 VgSectKind sect_kind; /* section of this BB, e.g. PLT */
312 /* filled by CLG_(get_fn_node) if debug info is available */
313 fn_node* fn; /* debug info for this BB */
315 Bool is_entry; /* True if this BB is a function entry */
317 BBCC* bbcc_list; /* BBCCs for same BB (see next_bbcc in BBCC) */
318 BBCC* last_bbcc; /* Temporary: Cached for faster access (LRU) */
320 /* filled by CLG_(instrument) if not seen before */
321 UInt cjmp_count; /* number of conditional exits */
322 CJmpInfo* jmp; /* array of info for condition jumps,
323 * allocated directly after this struct */
324 Int jmpkind; /* remember jump kind of final exit */
325 Bool cjmp_inverted; /* condition of last cond.jump can be inverted by VEX */
329 InstrInfo instr[0]; /* info on instruction sizes and costs */
337 * Basic blocks are always executed in the scope of a context.
338 * A function context is a list of function nodes representing
339 * the call chain to the current context: I.e. fn[0] is the
340 * function we are currently in, fn[1] has called fn[0], and so on.
341 * Recursion levels are used for fn[0].
343 * To get a unique number for a full execution context, use
344 * rec_index = min(<fn->rec_separation>,<active>) - 1;
345 * unique_no = <number> + rec_index
347 * For each Context, recursion index and BB, there can be a BBCC.
350 UInt size; // number of function dependencies
351 UInt base_number; // for context compression & dump array
352 Context* next; // entry chaining for hash
353 UWord hash; // for faster lookup...
359 * Info for a conditional jump in a basic block
361 typedef struct _JmpData JmpData;
363 ULong ecounter; /* number of times the BB was left at this exit */
364 jCC* jcc_list; /* JCCs for Cond.Jumps from this exit */
369 * Basic Block Cost Center
371 * On demand, multiple BBCCs will be created for the same BB
372 * dependend on command line options and:
373 * - current function (it's possible that a BB is executed in the
374 * context of different functions, e.g. in manual assembler/PLT)
375 * - current thread ID
376 * - position where current function is called from
377 * - recursion level of current function
379 * The cost centres for the instructions of a basic block are
380 * stored in a contiguous array.
381 * They are distinguishable by their tag field.
384 BB* bb; /* BB for this cost center */
386 Context* cxt; /* execution context of this BBCC */
387 ThreadId tid; /* only for assertion check purpose */
388 UInt rec_index; /* Recursion index in rec->bbcc for this bbcc */
389 BBCC** rec_array; /* Variable sized array of pointers to
390 * recursion BBCCs. Shared. */
391 ULong ret_counter; /* how often returned from jccs of this bbcc;
392 * used to check if a dump for this BBCC is needed */
394 BBCC* next_bbcc; /* Chain of BBCCs for same BB */
395 BBCC* lru_next_bbcc; /* BBCC executed next the last time */
397 jCC* lru_from_jcc; /* Temporary: Cached for faster access (LRU) */
398 jCC* lru_to_jcc; /* Temporary: Cached for faster access (LRU) */
399 FullCost skipped; /* cost for skipped functions called from
400 * jmp_addr. Allocated lazy */
402 BBCC* next; /* entry chain in hash */
403 ULong* cost; /* start of 64bit costs for this BBCC */
404 ULong ecounter_sum; /* execution counter for first instruction of BB */
409 /* the <number> of fn_node, file_node and obj_node are for compressed dumping
410 * and a index into the dump boolean table and fn_info_table
416 Context* last_cxt; /* LRU info */
417 Context* pure_cxt; /* the context with only the function itself */
418 file_node* file; /* reverse mapping for 2nd hash */
424 Bool toggle_collect :1;
426 Bool pop_on_jump : 1;
433 Int separate_callers;
434 Int separate_recursions;
436 Int verbosity; /* Stores old verbosity level while in function */
440 /* Quite arbitrary fixed hash sizes */
442 #define N_OBJ_ENTRIES 47
443 #define N_FILE_ENTRIES 53
444 #define N_FN_ENTRIES 87
445 #define N_BBCC2_ENTRIES 37
449 fn_node* fns[N_FN_ENTRIES];
455 /* If an object is dlopened multiple times, we hope that <name> is unique;
456 * <start> and <offset> can change with each dlopen, and <start> is
457 * zero when object is unmapped (possible at dump time).
463 Addr start; /* Start address of text segment mapping */
464 SizeT size; /* Length of mapping */
465 PtrdiffT offset; /* Offset between symbol address and file offset */
467 file_node* files[N_FILE_ENTRIES];
472 /* an entry in the callstack
474 * <nonskipped> is 0 if the function called is not skipped (usual case).
475 * Otherwise, it is the last non-skipped BBCC. This one gets all
476 * the calls to non-skipped functions and all costs in skipped
480 jCC* jcc; /* jCC for this call */
481 FullCost enter_cost; /* cost event counters at entering frame */
482 Addr sp; /* stack pointer directly after call */
483 Addr ret_addr; /* address to which to return to
484 * is 0 on a simulated call */
485 BBCC* nonskipped; /* see above */
486 Context* cxt; /* context before call */
487 Int fn_sp; /* function stack index before call */
492 * Execution state of main thread or a running signal handler in
493 * a thread while interrupted by another signal handler.
494 * As there's no scheduling among running signal handlers of one thread,
495 * we only need a subset of a full thread state:
498 * - last BB, last jump kind, last nonskipped BB
499 * - callstack pointer for sanity checking and correct unwinding
502 typedef struct _exec_state exec_state;
505 /* the signum of the handler, 0 for main thread context
509 /* the old call stack pointer at entering the signal handler */
516 Int jmps_passed; /* number of conditional jumps passed in last BB */
517 BBCC* bbcc; /* last BB executed */
520 Int call_stack_bottom; /* Index into fn_stack */
523 /* Global state structures */
524 typedef struct _bb_hash bb_hash;
530 typedef struct _cxt_hash cxt_hash;
536 /* Thread specific state structures, i.e. parts of a thread state.
537 * There are variables for the current state of each part,
538 * on which a thread state is copied at thread switch.
540 typedef struct _bbcc_hash bbcc_hash;
546 typedef struct _jcc_hash jcc_hash;
553 typedef struct _fn_array fn_array;
559 typedef struct _call_stack call_stack;
566 typedef struct _fn_stack fn_stack;
569 fn_node **bottom, **top;
572 /* The maximum number of simultaneous running signal handlers per thread.
573 * This is the number of execution states storable in a thread.
575 #define MAX_SIGHANDLERS 10
577 typedef struct _exec_stack exec_stack;
579 Int sp; /* > 0 if a handler is running */
580 exec_state* entry[MAX_SIGHANDLERS];
585 * This structure stores thread specific info while a thread is *not*
586 * running. See function switch_thread() for save/restore on thread switch.
588 * If --separate-threads=no, BBCCs and JCCs can be shared by all threads, i.e.
589 * only structures of thread 1 are used.
590 * This involves variables fn_info_table, bbcc_table and jcc_table.
592 struct _thread_info {
595 fn_stack fns; /* function stack */
596 call_stack calls; /* context call arc stack */
597 exec_stack states; /* execution states interrupted by signals */
599 /* dump statistics */
600 FullCost lastdump_cost; /* Cost at last dump */
601 FullCost sighandler_cost;
603 /* thread specific data structure containers */
609 /* Structs used for dumping */
611 /* Address position inside of a BBCC:
613 * - the address offset from the BB start address
614 * - file/line from debug info for that address (can change inside a BB)
616 typedef struct _AddrPos AddrPos;
624 /* a simulator cost entity that can be written out in one line */
625 typedef struct _AddrCost AddrCost;
631 /* A function in an execution context */
632 typedef struct _FnPos FnPos;
642 /*------------------------------------------------------------*/
643 /*--- Cache simulator interface ---*/
644 /*------------------------------------------------------------*/
648 void (*print_opts)(void);
649 Bool (*parse_opt)(Char* arg);
650 void (*post_clo_init)(void);
652 void (*getdesc)(Char* buf);
653 void (*printstat)(void);
654 void (*add_icost)(SimCost, BBCC*, InstrInfo*, ULong);
655 void (*after_bbsetup)(void);
656 void (*finish)(void);
658 void (*log_1I0D)(InstrInfo*) VG_REGPARM(1);
659 void (*log_2I0D)(InstrInfo*, InstrInfo*) VG_REGPARM(2);
660 void (*log_3I0D)(InstrInfo*, InstrInfo*, InstrInfo*) VG_REGPARM(3);
662 void (*log_1I1Dr)(InstrInfo*, Addr, Word) VG_REGPARM(3);
663 void (*log_1I1Dw)(InstrInfo*, Addr, Word) VG_REGPARM(3);
665 void (*log_0I1Dr)(InstrInfo*, Addr, Word) VG_REGPARM(3);
666 void (*log_0I1Dw)(InstrInfo*, Addr, Word) VG_REGPARM(3);
668 // function names of helpers (for debugging generated code)
669 Char *log_1I0D_name, *log_2I0D_name, *log_3I0D_name;
670 Char *log_1I1Dr_name, *log_1I1Dw_name;
671 Char *log_0I1Dr_name, *log_0I1Dw_name;
675 /*------------------------------------------------------------*/
676 /*--- Functions ---*/
677 /*------------------------------------------------------------*/
681 void CLG_(set_clo_defaults)(void);
682 void CLG_(update_fn_config)(fn_node*);
683 Bool CLG_(process_cmd_line_option)(Char*);
684 void CLG_(print_usage)(void);
685 void CLG_(print_debug_usage)(void);
689 EventSet *Use, *Ir, *Dr, *Dw;
690 EventSet *UIr, *UIrDr, *UIrDrDw, *UIrDw, *UIrDwDr;
693 /* offsets into eventsets */
694 Int off_full_Ir, off_full_Dr, off_full_Dw;
695 Int off_full_alloc, off_full_systime;
698 extern struct event_sets CLG_(sets);
699 extern struct cachesim_if CLG_(cachesim);
701 void CLG_(init_eventsets)(Int user);
704 Bool CLG_(get_debug_info)(Addr, Char filename[FILENAME_LEN],
705 Char fn_name[FN_NAME_LEN], UInt*, DebugInfo**);
706 void CLG_(collectBlockInfo)(IRSB* bbIn, UInt*, UInt*, Bool*);
707 void CLG_(set_instrument_state)(Char*,Bool);
708 void CLG_(dump_profile)(Char* trigger,Bool only_current_thread);
709 void CLG_(zero_all_cost)(Bool only_current_thread);
710 Int CLG_(get_dump_counter)(void);
711 void CLG_(fini)(Int exitcode);
714 void CLG_(init_command)(void);
715 void CLG_(check_command)(void);
716 void CLG_(finish_command)(void);
719 void CLG_(init_bb_hash)(void);
720 bb_hash* CLG_(get_bb_hash)(void);
721 BB* CLG_(get_bb)(Addr addr, IRSB* bb_in, Bool *seen_before);
722 void CLG_(delete_bb)(Addr addr);
724 static __inline__ Addr bb_addr(BB* bb)
725 { return bb->offset + bb->obj->offset; }
726 static __inline__ Addr bb_jmpaddr(BB* bb)
727 { UInt off = (bb->instr_count > 0) ? bb->instr[bb->instr_count-1].instr_offset : 0;
728 return off + bb->offset + bb->obj->offset; }
731 void CLG_(init_fn_array)(fn_array*);
732 void CLG_(copy_current_fn_array)(fn_array* dst);
733 fn_array* CLG_(get_current_fn_array)(void);
734 void CLG_(set_current_fn_array)(fn_array*);
735 UInt* CLG_(get_fn_entry)(Int n);
737 void CLG_(init_obj_table)(void);
738 obj_node* CLG_(get_obj_node)(DebugInfo* si);
739 file_node* CLG_(get_file_node)(obj_node*, Char* filename);
740 fn_node* CLG_(get_fn_node)(BB* bb);
743 void CLG_(init_bbcc_hash)(bbcc_hash* bbccs);
744 void CLG_(copy_current_bbcc_hash)(bbcc_hash* dst);
745 bbcc_hash* CLG_(get_current_bbcc_hash)(void);
746 void CLG_(set_current_bbcc_hash)(bbcc_hash*);
747 void CLG_(forall_bbccs)(void (*func)(BBCC*));
748 void CLG_(zero_bbcc)(BBCC* bbcc);
749 BBCC* CLG_(get_bbcc)(BB* bb);
750 BBCC* CLG_(clone_bbcc)(BBCC* orig, Context* cxt, Int rec_index);
751 void CLG_(setup_bbcc)(BB* bb) VG_REGPARM(1);
755 void CLG_(init_jcc_hash)(jcc_hash*);
756 void CLG_(copy_current_jcc_hash)(jcc_hash* dst);
757 jcc_hash* CLG_(get_current_jcc_hash)(void);
758 void CLG_(set_current_jcc_hash)(jcc_hash*);
759 jCC* CLG_(get_jcc)(BBCC* from, UInt, BBCC* to);
761 /* from callstack.c */
762 void CLG_(init_call_stack)(call_stack*);
763 void CLG_(copy_current_call_stack)(call_stack* dst);
764 void CLG_(set_current_call_stack)(call_stack*);
765 call_entry* CLG_(get_call_entry)(Int n);
767 void CLG_(push_call_stack)(BBCC* from, UInt jmp, BBCC* to, Addr sp, Bool skip);
768 void CLG_(pop_call_stack)(void);
769 void CLG_(unwind_call_stack)(Addr sp, Int);
772 void CLG_(init_fn_stack)(fn_stack*);
773 void CLG_(copy_current_fn_stack)(fn_stack*);
774 fn_stack* CLG_(get_current_fn_stack)(void);
775 void CLG_(set_current_fn_stack)(fn_stack*);
777 void CLG_(init_cxt_table)(void);
778 cxt_hash* CLG_(get_cxt_hash)(void);
779 Context* CLG_(get_cxt)(fn_node** fn);
780 void CLG_(push_cxt)(fn_node* fn);
783 void CLG_(init_threads)(void);
784 thread_info** CLG_(get_threads)(void);
785 thread_info* CLG_(get_current_thread)(void);
786 void CLG_(switch_thread)(ThreadId tid);
787 void CLG_(forall_threads)(void (*func)(thread_info*));
788 void CLG_(run_thread)(ThreadId tid);
790 void CLG_(init_exec_state)(exec_state* es);
791 void CLG_(init_exec_stack)(exec_stack*);
792 void CLG_(copy_current_exec_stack)(exec_stack*);
793 void CLG_(set_current_exec_stack)(exec_stack*);
794 void CLG_(pre_signal)(ThreadId tid, Int sigNum, Bool alt_stack);
795 void CLG_(post_signal)(ThreadId tid, Int sigNum);
796 void CLG_(run_post_signal_on_call_stack_bottom)(void);
799 extern FullCost CLG_(total_cost);
800 void CLG_(init_dumps)(void);
801 Char* CLG_(get_out_file)(void);
802 Char* CLG_(get_out_directory)(void);
804 /*------------------------------------------------------------*/
805 /*--- Exported global variables ---*/
806 /*------------------------------------------------------------*/
808 extern CommandLineOptions CLG_(clo);
809 extern Statistics CLG_(stat);
810 extern EventMapping* CLG_(dumpmap);
812 /* Function active counter array, indexed by function number */
813 extern UInt* CLG_(fn_active_array);
814 extern Bool CLG_(instrument_state);
816 extern call_stack CLG_(current_call_stack);
817 extern fn_stack CLG_(current_fn_stack);
818 extern exec_state CLG_(current_state);
819 extern ThreadId CLG_(current_tid);
822 /*------------------------------------------------------------*/
823 /*--- Debug output ---*/
824 /*------------------------------------------------------------*/
828 #define CLG_DEBUGIF(x) \
829 if ( (CLG_(clo).verbose >x) && \
830 (CLG_(stat).bb_executions >= CLG_(clo).verbose_start))
832 #define CLG_DEBUG(x,format,args...) \
834 CLG_(print_bbno)(); \
835 VG_(printf)(format,##args); \
838 #define CLG_ASSERT(cond) \
840 CLG_(print_context)(); \
841 CLG_(print_bbno)(); \
846 #define CLG_DEBUGIF(x) if (0)
847 #define CLG_DEBUG(x...) {}
848 #define CLG_ASSERT(cond) tl_assert(cond);
852 void CLG_(print_bbno)(void);
853 void CLG_(print_context)(void);
854 void CLG_(print_jcc)(int s, jCC* jcc);
855 void CLG_(print_bbcc)(int s, BBCC* bbcc);
856 void CLG_(print_bbcc_fn)(BBCC* bbcc);
857 void CLG_(print_execstate)(int s, exec_state* es);
858 void CLG_(print_eventset)(int s, EventSet* es);
859 void CLG_(print_cost)(int s, EventSet*, ULong* cost);
860 void CLG_(print_bb)(int s, BB* bb);
861 void CLG_(print_bbcc_cost)(int s, BBCC*);
862 void CLG_(print_cxt)(int s, Context* cxt, int rec_index);
863 void CLG_(print_short_jcc)(jCC* jcc);
864 void CLG_(print_stackentry)(int s, int sp);
865 void CLG_(print_addr)(Addr addr);
866 void CLG_(print_addr_ln)(Addr addr);
868 void* CLG_(malloc)(HChar* cc, UWord s, char* f);
869 void* CLG_(free)(void* p, char* f);
871 #define CLG_MALLOC(_cc,x) CLG_(malloc)((_cc),x,__FUNCTION__)
872 #define CLG_FREE(p) CLG_(free)(p,__FUNCTION__)
874 #define CLG_MALLOC(_cc,x) VG_(malloc)((_cc),x)
875 #define CLG_FREE(p) VG_(free)(p)
878 #endif /* CLG_GLOBAL */