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 Bool collect_bus; /* Collect global bus events */
92 /* Instrument options */
93 Bool instrument_atstart; /* Instrument at start? */
94 Bool simulate_cache; /* Call into cache simulator ? */
95 Bool simulate_branch; /* Call into branch prediction simulator ? */
97 /* Call graph generation */
98 Bool pop_on_jump; /* Handle a jump between functions as ret+call */
106 /*------------------------------------------------------------*/
107 /*--- Constants ---*/
108 /*------------------------------------------------------------*/
111 /* According to IA-32 Intel Architecture Software Developer's Manual: Vol 2 */
112 #define MAX_x86_INSTR_SIZE 16
114 /* Minimum cache line size allowed */
115 #define MIN_LINE_SIZE 16
117 /* Size of various buffers used for storing strings */
118 #define FILENAME_LEN VKI_PATH_MAX
119 #define FN_NAME_LEN 4096 /* for C++ code :-) */
120 #define OBJ_NAME_LEN 256
121 #define COSTS_LEN 512 /* at least 17x 64bit values */
123 #define COMMIFY_BUF_LEN 128
124 #define RESULTS_BUF_LEN 256
125 #define LINE_BUF_LEN 64
128 /* Convenience macros */
130 /* Use this only when size of sprintf args are known to fit into
131 * given buffer; for strings of unknown length, use WRITE_STR below
133 #define WRITE_SPRINTF(fd, zz_buf, fmt, args...) \
134 do { Int len = VG_(sprintf)(zz_buf, fmt, ## args); \
135 VG_(write)(fd, (void*)zz_buf, len); \
138 #define WRITE_STR(fd, str) \
139 do { if (str) { Int len = VG_(strlen)(str); \
140 VG_(write)(fd, (void*)str, len); } \
141 else VG_(write)(fd, "(null)", 6); \
144 #define WRITE_STR2(fd, str1, str2) \
145 do { if (str1) { Int len = VG_(strlen)(str1); \
146 VG_(write)(fd, (void*)str1, len); } \
147 else VG_(write)(fd, "(null)", 6); \
148 if (str2) { Int len = VG_(strlen)(str2); \
149 VG_(write)(fd, (void*)str2, len); } \
150 else VG_(write)(fd, "(null)", 6); \
153 #define WRITE_STR3(fd, str1, str2, str3) \
154 do { if (str1) { Int len = VG_(strlen)(str1); \
155 VG_(write)(fd, (void*)str1, len); } \
156 else VG_(write)(fd, "(null)", 6); \
157 if (str2) { Int len = VG_(strlen)(str2); \
158 VG_(write)(fd, (void*)str2, len); } \
159 else VG_(write)(fd, "(null)", 6); \
160 if (str3) { Int len = VG_(strlen)(str3); \
161 VG_(write)(fd, (void*)str3, len); } \
162 else VG_(write)(fd, "(null)", 6); \
166 /*------------------------------------------------------------*/
167 /*--- Statistics ---*/
168 /*------------------------------------------------------------*/
170 typedef struct _Statistics Statistics;
175 ULong rec_call_counter;
180 Int bb_retranslations;
185 Int distinct_contexts;
193 Int bbcc_hash_resizes;
194 Int jcc_hash_resizes;
195 Int cxt_hash_resizes;
196 Int fn_array_resizes;
197 Int call_stack_resizes;
198 Int fn_stack_resizes;
201 Int file_line_debug_BBs;
202 Int fn_name_debug_BBs;
211 /*------------------------------------------------------------*/
212 /*--- Structure declarations ---*/
213 /*------------------------------------------------------------*/
215 typedef struct _Context Context;
216 typedef struct _CC CC;
217 typedef struct _BB BB;
218 typedef struct _Skipped Skipped;
219 typedef struct _BBCC BBCC;
220 typedef struct _jCC jCC;
221 typedef struct _fCC fCC;
222 typedef struct _fn_node fn_node;
223 typedef struct _file_node file_node;
224 typedef struct _obj_node obj_node;
225 typedef struct _fn_config fn_config;
226 typedef struct _call_entry call_entry;
227 typedef struct _thread_info thread_info;
229 /* Costs of event sets. Aliases to arrays of 64-bit values */
230 typedef ULong* SimCost; /* All events the simulator can produce */
231 typedef ULong* UserCost;
232 typedef ULong* FullCost; /* Simulator + User */
235 /* JmpCall cost center
236 * for subroutine call (from->bb->jmp_addr => to->bb->addr)
238 * Each BB has at most one CALL instruction. The list of JCC from
239 * this call is a pointer to the list head (stored in BBCC), and
240 * <next_from> in the JCC struct.
242 * For fast lookup, JCCs are reachable with a hash table, keyed by
243 * the (from_bbcc,to) pair. <next_hash> is used for the JCC chain
244 * of one hash table entry.
246 * Cost <sum> holds event counts for already returned executions.
247 * <last> are the event counters at last enter of the subroutine.
248 * <sum> is updated on returning from the subroutine by
249 * adding the diff of <last> and current event counters to <sum>.
251 * After updating, <last> is set to current event counters. Thus,
252 * events are not counted twice for recursive calls (TODO: True?)
254 #define JmpNone (Ijk_Boring+30)
255 #define JmpCond (Ijk_Boring+31)
258 Int jmpkind; /* JmpCall, JmpBoring, JmpCond */
259 jCC* next_hash; /* for hash entry chain */
260 jCC* next_from; /* next JCC from a BBCC */
261 BBCC *from, *to; /* call arc from/to this BBCC */
262 UInt jmp; /* jump no. in source */
264 ULong call_counter; /* no wraparound with 64 bit */
266 FullCost cost; /* simulator + user counters */
271 * Info for one instruction of a basic block.
273 typedef struct _InstrInfo InstrInfo;
283 * Info for a conditional jump in a basic block
285 typedef struct _CJmpInfo CJmpInfo;
287 UInt instr; /* instruction index in this basic block */
288 Bool skip; /* Cond.Jumps to next instruction should be ignored */
293 * An instrumented basic block (BB).
295 * BBs are put into a resizable hash to allow for fast detection if a
296 * BB is to be retranslated but cost info is already available.
297 * The key for a BB is a (object, offset) tupel making it independent
298 * from possibly multiple mappings of the same ELF object.
300 * At the beginning of each instrumented BB,
301 * a call to setup_bbcc(), specifying a pointer to the
302 * according BB structure, is added.
304 * As cost of a BB has to be distinguished depending on the context,
305 * multiple cost centers for one BB (struct BBCC) exist and the according
306 * BBCC is set by setup_bbcc.
309 obj_node* obj; /* ELF object of BB */
310 PtrdiffT offset; /* offset of BB in ELF object file */
311 BB* next; /* chaining for a hash entry */
313 VgSectKind sect_kind; /* section of this BB, e.g. PLT */
316 /* filled by CLG_(get_fn_node) if debug info is available */
317 fn_node* fn; /* debug info for this BB */
319 Bool is_entry; /* True if this BB is a function entry */
321 BBCC* bbcc_list; /* BBCCs for same BB (see next_bbcc in BBCC) */
322 BBCC* last_bbcc; /* Temporary: Cached for faster access (LRU) */
324 /* filled by CLG_(instrument) if not seen before */
325 UInt cjmp_count; /* number of conditional exits */
326 CJmpInfo* jmp; /* array of info for condition jumps,
327 * allocated directly after this struct */
328 Int jmpkind; /* remember jump kind of final exit */
329 Bool cjmp_inverted; /* condition of last cond.jump can be inverted by VEX */
333 InstrInfo instr[0]; /* info on instruction sizes and costs */
341 * Basic blocks are always executed in the scope of a context.
342 * A function context is a list of function nodes representing
343 * the call chain to the current context: I.e. fn[0] is the
344 * function we are currently in, fn[1] has called fn[0], and so on.
345 * Recursion levels are used for fn[0].
347 * To get a unique number for a full execution context, use
348 * rec_index = min(<fn->rec_separation>,<active>) - 1;
349 * unique_no = <number> + rec_index
351 * For each Context, recursion index and BB, there can be a BBCC.
354 UInt size; // number of function dependencies
355 UInt base_number; // for context compression & dump array
356 Context* next; // entry chaining for hash
357 UWord hash; // for faster lookup...
363 * Info for a conditional jump in a basic block
365 typedef struct _JmpData JmpData;
367 ULong ecounter; /* number of times the BB was left at this exit */
368 jCC* jcc_list; /* JCCs for Cond.Jumps from this exit */
373 * Basic Block Cost Center
375 * On demand, multiple BBCCs will be created for the same BB
376 * dependend on command line options and:
377 * - current function (it's possible that a BB is executed in the
378 * context of different functions, e.g. in manual assembler/PLT)
379 * - current thread ID
380 * - position where current function is called from
381 * - recursion level of current function
383 * The cost centres for the instructions of a basic block are
384 * stored in a contiguous array.
385 * They are distinguishable by their tag field.
388 BB* bb; /* BB for this cost center */
390 Context* cxt; /* execution context of this BBCC */
391 ThreadId tid; /* only for assertion check purpose */
392 UInt rec_index; /* Recursion index in rec->bbcc for this bbcc */
393 BBCC** rec_array; /* Variable sized array of pointers to
394 * recursion BBCCs. Shared. */
395 ULong ret_counter; /* how often returned from jccs of this bbcc;
396 * used to check if a dump for this BBCC is needed */
398 BBCC* next_bbcc; /* Chain of BBCCs for same BB */
399 BBCC* lru_next_bbcc; /* BBCC executed next the last time */
401 jCC* lru_from_jcc; /* Temporary: Cached for faster access (LRU) */
402 jCC* lru_to_jcc; /* Temporary: Cached for faster access (LRU) */
403 FullCost skipped; /* cost for skipped functions called from
404 * jmp_addr. Allocated lazy */
406 BBCC* next; /* entry chain in hash */
407 ULong* cost; /* start of 64bit costs for this BBCC */
408 ULong ecounter_sum; /* execution counter for first instruction of BB */
413 /* the <number> of fn_node, file_node and obj_node are for compressed dumping
414 * and a index into the dump boolean table and fn_info_table
420 Context* last_cxt; /* LRU info */
421 Context* pure_cxt; /* the context with only the function itself */
422 file_node* file; /* reverse mapping for 2nd hash */
428 Bool toggle_collect :1;
430 Bool pop_on_jump : 1;
437 Int separate_callers;
438 Int separate_recursions;
440 Int verbosity; /* Stores old verbosity level while in function */
444 /* Quite arbitrary fixed hash sizes */
446 #define N_OBJ_ENTRIES 47
447 #define N_FILE_ENTRIES 53
448 #define N_FN_ENTRIES 87
449 #define N_BBCC2_ENTRIES 37
453 fn_node* fns[N_FN_ENTRIES];
459 /* If an object is dlopened multiple times, we hope that <name> is unique;
460 * <start> and <offset> can change with each dlopen, and <start> is
461 * zero when object is unmapped (possible at dump time).
467 Addr start; /* Start address of text segment mapping */
468 SizeT size; /* Length of mapping */
469 PtrdiffT offset; /* Offset between symbol address and file offset */
471 file_node* files[N_FILE_ENTRIES];
476 /* an entry in the callstack
478 * <nonskipped> is 0 if the function called is not skipped (usual case).
479 * Otherwise, it is the last non-skipped BBCC. This one gets all
480 * the calls to non-skipped functions and all costs in skipped
484 jCC* jcc; /* jCC for this call */
485 FullCost enter_cost; /* cost event counters at entering frame */
486 Addr sp; /* stack pointer directly after call */
487 Addr ret_addr; /* address to which to return to
488 * is 0 on a simulated call */
489 BBCC* nonskipped; /* see above */
490 Context* cxt; /* context before call */
491 Int fn_sp; /* function stack index before call */
496 * Execution state of main thread or a running signal handler in
497 * a thread while interrupted by another signal handler.
498 * As there's no scheduling among running signal handlers of one thread,
499 * we only need a subset of a full thread state:
502 * - last BB, last jump kind, last nonskipped BB
503 * - callstack pointer for sanity checking and correct unwinding
506 typedef struct _exec_state exec_state;
509 /* the signum of the handler, 0 for main thread context
513 /* the old call stack pointer at entering the signal handler */
520 Int jmps_passed; /* number of conditional jumps passed in last BB */
521 BBCC* bbcc; /* last BB executed */
524 Int call_stack_bottom; /* Index into fn_stack */
527 /* Global state structures */
528 typedef struct _bb_hash bb_hash;
534 typedef struct _cxt_hash cxt_hash;
540 /* Thread specific state structures, i.e. parts of a thread state.
541 * There are variables for the current state of each part,
542 * on which a thread state is copied at thread switch.
544 typedef struct _bbcc_hash bbcc_hash;
550 typedef struct _jcc_hash jcc_hash;
557 typedef struct _fn_array fn_array;
563 typedef struct _call_stack call_stack;
570 typedef struct _fn_stack fn_stack;
573 fn_node **bottom, **top;
576 /* The maximum number of simultaneous running signal handlers per thread.
577 * This is the number of execution states storable in a thread.
579 #define MAX_SIGHANDLERS 10
581 typedef struct _exec_stack exec_stack;
583 Int sp; /* > 0 if a handler is running */
584 exec_state* entry[MAX_SIGHANDLERS];
589 * This structure stores thread specific info while a thread is *not*
590 * running. See function switch_thread() for save/restore on thread switch.
592 * If --separate-threads=no, BBCCs and JCCs can be shared by all threads, i.e.
593 * only structures of thread 1 are used.
594 * This involves variables fn_info_table, bbcc_table and jcc_table.
596 struct _thread_info {
599 fn_stack fns; /* function stack */
600 call_stack calls; /* context call arc stack */
601 exec_stack states; /* execution states interrupted by signals */
603 /* dump statistics */
604 FullCost lastdump_cost; /* Cost at last dump */
605 FullCost sighandler_cost;
607 /* thread specific data structure containers */
613 /* Structs used for dumping */
615 /* Address position inside of a BBCC:
617 * - the address offset from the BB start address
618 * - file/line from debug info for that address (can change inside a BB)
620 typedef struct _AddrPos AddrPos;
628 /* a simulator cost entity that can be written out in one line */
629 typedef struct _AddrCost AddrCost;
635 /* A function in an execution context */
636 typedef struct _FnPos FnPos;
646 /*------------------------------------------------------------*/
647 /*--- Cache simulator interface ---*/
648 /*------------------------------------------------------------*/
652 void (*print_opts)(void);
653 Bool (*parse_opt)(Char* arg);
654 void (*post_clo_init)(void);
656 void (*getdesc)(Char* buf);
657 void (*printstat)(Int,Int,Int);
658 void (*add_icost)(SimCost, BBCC*, InstrInfo*, ULong);
659 void (*finish)(void);
661 void (*log_1I0D)(InstrInfo*) VG_REGPARM(1);
662 void (*log_2I0D)(InstrInfo*, InstrInfo*) VG_REGPARM(2);
663 void (*log_3I0D)(InstrInfo*, InstrInfo*, InstrInfo*) VG_REGPARM(3);
665 void (*log_1I1Dr)(InstrInfo*, Addr, Word) VG_REGPARM(3);
666 void (*log_1I1Dw)(InstrInfo*, Addr, Word) VG_REGPARM(3);
668 void (*log_0I1Dr)(InstrInfo*, Addr, Word) VG_REGPARM(3);
669 void (*log_0I1Dw)(InstrInfo*, Addr, Word) VG_REGPARM(3);
671 // function names of helpers (for debugging generated code)
672 Char *log_1I0D_name, *log_2I0D_name, *log_3I0D_name;
673 Char *log_1I1Dr_name, *log_1I1Dw_name;
674 Char *log_0I1Dr_name, *log_0I1Dw_name;
677 // set by setup_bbcc at start of every BB, and needed by log_* helpers
678 extern Addr CLG_(bb_base);
679 extern ULong* CLG_(cost_base);
693 EventSet *base, *full;
695 extern struct event_sets CLG_(sets);
697 #define fullOffset(group) (CLG_(sets).full->offset[group])
700 /*------------------------------------------------------------*/
701 /*--- Functions ---*/
702 /*------------------------------------------------------------*/
706 void CLG_(set_clo_defaults)(void);
707 void CLG_(update_fn_config)(fn_node*);
708 Bool CLG_(process_cmd_line_option)(Char*);
709 void CLG_(print_usage)(void);
710 void CLG_(print_debug_usage)(void);
713 extern struct cachesim_if CLG_(cachesim);
714 void CLG_(init_eventsets)(void);
717 Bool CLG_(get_debug_info)(Addr, Char filename[FILENAME_LEN],
718 Char fn_name[FN_NAME_LEN], UInt*, DebugInfo**);
719 void CLG_(collectBlockInfo)(IRSB* bbIn, UInt*, UInt*, Bool*);
720 void CLG_(set_instrument_state)(Char*,Bool);
721 void CLG_(dump_profile)(Char* trigger,Bool only_current_thread);
722 void CLG_(zero_all_cost)(Bool only_current_thread);
723 Int CLG_(get_dump_counter)(void);
724 void CLG_(fini)(Int exitcode);
727 void CLG_(init_command)(void);
728 void CLG_(check_command)(void);
729 void CLG_(finish_command)(void);
732 void CLG_(init_bb_hash)(void);
733 bb_hash* CLG_(get_bb_hash)(void);
734 BB* CLG_(get_bb)(Addr addr, IRSB* bb_in, Bool *seen_before);
735 void CLG_(delete_bb)(Addr addr);
737 static __inline__ Addr bb_addr(BB* bb)
738 { return bb->offset + bb->obj->offset; }
739 static __inline__ Addr bb_jmpaddr(BB* bb)
740 { UInt off = (bb->instr_count > 0) ? bb->instr[bb->instr_count-1].instr_offset : 0;
741 return off + bb->offset + bb->obj->offset; }
744 void CLG_(init_fn_array)(fn_array*);
745 void CLG_(copy_current_fn_array)(fn_array* dst);
746 fn_array* CLG_(get_current_fn_array)(void);
747 void CLG_(set_current_fn_array)(fn_array*);
748 UInt* CLG_(get_fn_entry)(Int n);
750 void CLG_(init_obj_table)(void);
751 obj_node* CLG_(get_obj_node)(DebugInfo* si);
752 file_node* CLG_(get_file_node)(obj_node*, Char* filename);
753 fn_node* CLG_(get_fn_node)(BB* bb);
756 void CLG_(init_bbcc_hash)(bbcc_hash* bbccs);
757 void CLG_(copy_current_bbcc_hash)(bbcc_hash* dst);
758 bbcc_hash* CLG_(get_current_bbcc_hash)(void);
759 void CLG_(set_current_bbcc_hash)(bbcc_hash*);
760 void CLG_(forall_bbccs)(void (*func)(BBCC*));
761 void CLG_(zero_bbcc)(BBCC* bbcc);
762 BBCC* CLG_(get_bbcc)(BB* bb);
763 BBCC* CLG_(clone_bbcc)(BBCC* orig, Context* cxt, Int rec_index);
764 void CLG_(setup_bbcc)(BB* bb) VG_REGPARM(1);
768 void CLG_(init_jcc_hash)(jcc_hash*);
769 void CLG_(copy_current_jcc_hash)(jcc_hash* dst);
770 jcc_hash* CLG_(get_current_jcc_hash)(void);
771 void CLG_(set_current_jcc_hash)(jcc_hash*);
772 jCC* CLG_(get_jcc)(BBCC* from, UInt, BBCC* to);
774 /* from callstack.c */
775 void CLG_(init_call_stack)(call_stack*);
776 void CLG_(copy_current_call_stack)(call_stack* dst);
777 void CLG_(set_current_call_stack)(call_stack*);
778 call_entry* CLG_(get_call_entry)(Int n);
780 void CLG_(push_call_stack)(BBCC* from, UInt jmp, BBCC* to, Addr sp, Bool skip);
781 void CLG_(pop_call_stack)(void);
782 Int CLG_(unwind_call_stack)(Addr sp, Int);
785 void CLG_(init_fn_stack)(fn_stack*);
786 void CLG_(copy_current_fn_stack)(fn_stack*);
787 fn_stack* CLG_(get_current_fn_stack)(void);
788 void CLG_(set_current_fn_stack)(fn_stack*);
790 void CLG_(init_cxt_table)(void);
791 cxt_hash* CLG_(get_cxt_hash)(void);
792 Context* CLG_(get_cxt)(fn_node** fn);
793 void CLG_(push_cxt)(fn_node* fn);
796 void CLG_(init_threads)(void);
797 thread_info** CLG_(get_threads)(void);
798 thread_info* CLG_(get_current_thread)(void);
799 void CLG_(switch_thread)(ThreadId tid);
800 void CLG_(forall_threads)(void (*func)(thread_info*));
801 void CLG_(run_thread)(ThreadId tid);
803 void CLG_(init_exec_state)(exec_state* es);
804 void CLG_(init_exec_stack)(exec_stack*);
805 void CLG_(copy_current_exec_stack)(exec_stack*);
806 void CLG_(set_current_exec_stack)(exec_stack*);
807 void CLG_(pre_signal)(ThreadId tid, Int sigNum, Bool alt_stack);
808 void CLG_(post_signal)(ThreadId tid, Int sigNum);
809 void CLG_(run_post_signal_on_call_stack_bottom)(void);
812 extern FullCost CLG_(total_cost);
813 void CLG_(init_dumps)(void);
814 Char* CLG_(get_out_file)(void);
815 Char* CLG_(get_out_directory)(void);
817 /*------------------------------------------------------------*/
818 /*--- Exported global variables ---*/
819 /*------------------------------------------------------------*/
821 extern CommandLineOptions CLG_(clo);
822 extern Statistics CLG_(stat);
823 extern EventMapping* CLG_(dumpmap);
825 /* Function active counter array, indexed by function number */
826 extern UInt* CLG_(fn_active_array);
827 extern Bool CLG_(instrument_state);
829 extern call_stack CLG_(current_call_stack);
830 extern fn_stack CLG_(current_fn_stack);
831 extern exec_state CLG_(current_state);
832 extern ThreadId CLG_(current_tid);
835 /*------------------------------------------------------------*/
836 /*--- Debug output ---*/
837 /*------------------------------------------------------------*/
841 #define CLG_DEBUGIF(x) \
842 if ( (CLG_(clo).verbose >x) && \
843 (CLG_(stat).bb_executions >= CLG_(clo).verbose_start))
845 #define CLG_DEBUG(x,format,args...) \
847 CLG_(print_bbno)(); \
848 VG_(printf)(format,##args); \
851 #define CLG_ASSERT(cond) \
853 CLG_(print_context)(); \
854 CLG_(print_bbno)(); \
859 #define CLG_DEBUGIF(x) if (0)
860 #define CLG_DEBUG(x...) {}
861 #define CLG_ASSERT(cond) tl_assert(cond);
865 void CLG_(print_bbno)(void);
866 void CLG_(print_context)(void);
867 void CLG_(print_jcc)(int s, jCC* jcc);
868 void CLG_(print_bbcc)(int s, BBCC* bbcc);
869 void CLG_(print_bbcc_fn)(BBCC* bbcc);
870 void CLG_(print_execstate)(int s, exec_state* es);
871 void CLG_(print_eventset)(int s, EventSet* es);
872 void CLG_(print_cost)(int s, EventSet*, ULong* cost);
873 void CLG_(print_bb)(int s, BB* bb);
874 void CLG_(print_bbcc_cost)(int s, BBCC*);
875 void CLG_(print_cxt)(int s, Context* cxt, int rec_index);
876 void CLG_(print_short_jcc)(jCC* jcc);
877 void CLG_(print_stackentry)(int s, int sp);
878 void CLG_(print_addr)(Addr addr);
879 void CLG_(print_addr_ln)(Addr addr);
881 void* CLG_(malloc)(HChar* cc, UWord s, char* f);
882 void* CLG_(free)(void* p, char* f);
884 #define CLG_MALLOC(_cc,x) CLG_(malloc)((_cc),x,__FUNCTION__)
885 #define CLG_FREE(p) CLG_(free)(p,__FUNCTION__)
887 #define CLG_MALLOC(_cc,x) VG_(malloc)((_cc),x)
888 #define CLG_FREE(p) VG_(free)(p)
891 #endif /* CLG_GLOBAL */