blob: f6190a206c7785bd874221901d084078ab8ab6b3 [file] [log] [blame]
weidendoa17f2a32006-03-20 10:27:30 +00001/*--------------------------------------------------------------------*/
2/*--- Callgrind ---*/
3/*--- global.h ---*/
4/*--- (C) 2004, 2005 Josef Weidendorfer ---*/
5/*--------------------------------------------------------------------*/
6
7#ifndef CLG_GLOBAL
8#define CLG_GLOBAL
9
10#include "pub_tool_basics.h"
11#include "pub_tool_debuginfo.h"
12#include "pub_tool_libcbase.h"
13#include "pub_tool_libcassert.h"
14#include "pub_tool_libcfile.h"
15#include "pub_tool_libcprint.h"
16#include "pub_tool_libcproc.h"
17#include "pub_tool_machine.h"
18#include "pub_tool_mallocfree.h"
19#include "pub_tool_options.h"
20#include "pub_tool_tooliface.h"
21#include "pub_tool_clientstate.h"
22#include "pub_tool_machine.h" // VG_(fnptr_to_fnentry)
23
24#include "events.h" // defines CLG_ macro
25#include "costs.h"
26
27
28/*------------------------------------------------------------*/
29/*--- Calltree compile options --- */
30/*------------------------------------------------------------*/
31
32/* Enable debug output */
33#define CLG_ENABLE_DEBUG 1
34
35/* Enable experimental features? */
36#define CLG_EXPERIMENTAL 0
37
38/* Syscall Timing in microseconds?
39 * (define to 0 if you get compile errors) */
40#define CLG_MICROSYSTIME 0
41
42/* Set to 1 if you want full sanity checks for JCC */
43#define JCC_CHECK 0
44
45
46
47/*------------------------------------------------------------*/
48/*--- Command line options ---*/
49/*------------------------------------------------------------*/
50
51#define DEFAULT_DUMPNAME "callgrind.out"
52#define DEFAULT_COMMANDNAME "callgrind.cmd"
53#define DEFAULT_RESULTNAME "callgrind.res"
54#define DEFAULT_INFONAME "/tmp/callgrind.info"
55
56typedef struct _CommandLineOptions CommandLineOptions;
57struct _CommandLineOptions {
58
59 /* Dump format options */
60 Char* filename_base; /* Base name for dumps */
61 Bool combine_dumps; /* Dump trace parts into same file? */
62 Bool compress_strings;
63 Bool compress_events;
64 Bool compress_pos;
65 Bool mangle_names;
66 Bool compress_mangled;
67 Bool dump_line;
68 Bool dump_instr;
69 Bool dump_bb;
70 Bool dump_bbs; /* Dump basic block information? */
71
72 /* Dump generation options */
weidendo9e326b72006-03-31 13:16:15 +000073 ULong dump_every_bb; /* Dump every xxx BBs. */
weidendoa17f2a32006-03-20 10:27:30 +000074
75 /* Collection options */
76 Bool separate_threads; /* Separate threads in dump? */
77 Int separate_callers; /* Separate dependent on how many callers? */
78 Int separate_recursions; /* Max level of recursions to separate */
79 Bool skip_plt; /* Skip functions in PLT section? */
80 Bool skip_direct_recursion; /* Increment direct recursions the level? */
81
82 Bool collect_atstart; /* Start in collecting state ? */
83 Bool collect_jumps; /* Collect (cond.) jumps in functions ? */
84
85 Bool collect_alloc; /* Collect size of allocated memory */
86 Bool collect_systime; /* Collect time for system calls */
87
88 /* Instrument options */
89 Bool instrument_atstart; /* Instrument at start? */
90 Bool simulate_cache; /* Call into cache simulator ? */
91
weidendoa762b0f2006-05-01 00:55:54 +000092 /* Call graph generation */
93 Bool pop_on_jump; /* Handle a jump between functions as ret+call */
94
weidendoa17f2a32006-03-20 10:27:30 +000095#if CLG_ENABLE_DEBUG
96 Int verbose;
97 ULong verbose_start;
98#endif
99};
100
101/*------------------------------------------------------------*/
102/*--- Constants ---*/
103/*------------------------------------------------------------*/
104
105
106/* According to IA-32 Intel Architecture Software Developer's Manual: Vol 2 */
107#define MAX_x86_INSTR_SIZE 16
108
109/* Minimum cache line size allowed */
110#define MIN_LINE_SIZE 16
111
112/* Size of various buffers used for storing strings */
113#define FILENAME_LEN 256
114#define FN_NAME_LEN 4096 /* for C++ code :-) */
115#define OBJ_NAME_LEN 256
116#define BUF_LEN 512
117#define COMMIFY_BUF_LEN 128
118#define RESULTS_BUF_LEN 128
119#define LINE_BUF_LEN 64
120
121
122
123/*------------------------------------------------------------*/
124/*--- Statistics ---*/
125/*------------------------------------------------------------*/
126
127typedef struct _Statistics Statistics;
128struct _Statistics {
129 ULong call_counter;
130 ULong jcnd_counter;
131 ULong jump_counter;
132 ULong rec_call_counter;
133 ULong ret_counter;
134 ULong bb_executions;
135
136 Int context_counter;
137 Int bb_retranslations;
138
139 Int distinct_objs;
140 Int distinct_files;
141 Int distinct_fns;
142 Int distinct_contexts;
143 Int distinct_bbs;
144 Int distinct_jccs;
145 Int distinct_bbccs;
146 Int distinct_instrs;
147 Int distinct_skips;
148
149 Int bb_hash_resizes;
150 Int bbcc_hash_resizes;
151 Int jcc_hash_resizes;
152 Int cxt_hash_resizes;
153 Int fn_array_resizes;
154 Int call_stack_resizes;
155 Int fn_stack_resizes;
156
157 Int full_debug_BBs;
158 Int file_line_debug_BBs;
159 Int fn_name_debug_BBs;
160 Int no_debug_BBs;
161 Int bbcc_lru_misses;
162 Int jcc_lru_misses;
163 Int cxt_lru_misses;
164 Int bbcc_clones;
165};
166
167
168/*------------------------------------------------------------*/
169/*--- Structure declarations ---*/
170/*------------------------------------------------------------*/
171
172typedef struct _Context Context;
173typedef struct _CC CC;
174typedef struct _BB BB;
175typedef struct _Skipped Skipped;
176typedef struct _BBCC BBCC;
177typedef struct _jCC jCC;
178typedef struct _fCC fCC;
179typedef struct _fn_node fn_node;
180typedef struct _file_node file_node;
181typedef struct _obj_node obj_node;
182typedef struct _fn_config fn_config;
183typedef struct _call_entry call_entry;
184typedef struct _thread_info thread_info;
185
186/* Costs of event sets. Aliases to arrays of 64-bit values */
187typedef ULong* SimCost; /* All events the simulator can produce */
188typedef ULong* UserCost;
189typedef ULong* FullCost; /* Simulator + User */
190
191
192/* JmpCall cost center
193 * for subroutine call (from->bb->jmp_addr => to->bb->addr)
194 *
195 * Each BB has at most one CALL instruction. The list of JCC from
196 * this call is a pointer to the list head (stored in BBCC), and
197 * <next_from> in the JCC struct.
198 *
199 * For fast lookup, JCCs are reachable with a hash table, keyed by
200 * the (from_bbcc,to) pair. <next_hash> is used for the JCC chain
201 * of one hash table entry.
202 *
203 * Cost <sum> holds event counts for already returned executions.
204 * <last> are the event counters at last enter of the subroutine.
205 * <sum> is updated on returning from the subroutine by
206 * adding the diff of <last> and current event counters to <sum>.
207 *
208 * After updating, <last> is set to current event counters. Thus,
209 * events are not counted twice for recursive calls (TODO: True?)
210 */
211#define JmpNone (Ijk_Boring+30)
212#define JmpCond (Ijk_Boring+31)
213
214struct _jCC {
215 Int jmpkind; /* JmpCall, JmpBoring, JmpCond */
216 jCC* next_hash; /* for hash entry chain */
217 jCC* next_from; /* next JCC from a BBCC */
218 BBCC *from, *to; /* call arc from/to this BBCC */
219 UInt jmp; /* jump no. in source */
220
221 ULong call_counter; /* no wraparound with 64 bit */
222
223 FullCost cost; /* simulator + user counters */
224};
225
226
227/*
228 * Info for one instruction of a basic block.
229 */
230typedef struct _InstrInfo InstrInfo;
231struct _InstrInfo {
232 UInt instr_offset;
233 UInt instr_size;
234 UInt data_size;
235 UInt cost_offset;
236 EventSet* eventset;
237};
238
239
240/*
241 * Info for a conditional jump in a basic block
242 */
243typedef struct _CJmpInfo CJmpInfo;
244struct _CJmpInfo {
245 UInt instr; /* instruction index in this basic block */
246 Bool skip; /* Cond.Jumps to next instruction should be ignored */
247};
248
249
250/**
251 * An instrumented basic block (BB).
252 *
253 * BBs are put into a resizable hash to allow for fast detection if a
254 * BB is to be retranslated but cost info is already available.
255 * The key for a BB is a (object, offset) tupel making it independent
256 * from possibly multiple mappings of the same ELF object.
257 *
258 * At the beginning of each instrumented BB,
259 * a call to setup_bbcc(), specifying a pointer to the
260 * according BB structure, is added.
261 *
262 * As cost of a BB has to be distinguished depending on the context,
263 * multiple cost centers for one BB (struct BBCC) exist and the according
264 * BBCC is set by setup_bbcc.
265 */
266struct _BB {
267 obj_node* obj; /* ELF object of BB */
268 OffT offset; /* offset of BB in ELF object file */
269 BB* next; /* chaining for a hash entry */
270
271 VgSectKind sect_kind; /* section of this BB, e.g. PLT */
272 UInt instr_count;
273
274 /* filled by CLG_(get_fn_node) if debug info is available */
275 fn_node* fn; /* debug info for this BB */
276 UInt line;
277 Bool is_entry; /* True if this BB is a function entry */
278
279 BBCC* bbcc_list; /* BBCCs for same BB (see next_bbcc in BBCC) */
280 BBCC* last_bbcc; /* Temporary: Cached for faster access (LRU) */
281
282 /* filled by CLG_(instrument) if not seen before */
283 UInt cjmp_count; /* number of conditional exits */
284 CJmpInfo* jmp; /* array of info for condition jumps,
285 * allocated directly after this struct */
286 Int jmpkind; /* remember jump kind of final exit */
287 Bool cjmp_inverted; /* condition of last cond.jump can be inverted by VEX */
288
289 UInt instr_len;
290 UInt cost_count;
291 InstrInfo instr[0]; /* info on instruction sizes and costs */
292};
293
294
295
296/**
297 * Function context
298 *
299 * Basic blocks are always executed in the scope of a context.
300 * A function context is a list of function nodes representing
301 * the call chain to the current context: I.e. fn[0] is the
302 * function we are currently in, fn[1] has called fn[0], and so on.
303 * Recursion levels are used for fn[0].
304 *
305 * To get a unique number for a full execution context, use
306 * rec_index = min(<fn->rec_separation>,<active>) - 1;
307 * unique_no = <number> + rec_index
308 *
309 * For each Context, recursion index and BB, there can be a BBCC.
310 */
311struct _Context {
312 UInt size; // number of function dependencies
313 UInt base_number; // for context compression & dump array
314 Context* next; // entry chaining for hash
315 UWord hash; // for faster lookup...
316 fn_node* fn[0];
317};
318
319
320/*
321 * Info for a conditional jump in a basic block
322 */
323typedef struct _JmpData JmpData;
324struct _JmpData {
325 ULong ecounter; /* number of times the BB was left at this exit */
326 jCC* jcc_list; /* JCCs for Cond.Jumps from this exit */
327};
328
329
330/*
331 * Basic Block Cost Center
332 *
333 * On demand, multiple BBCCs will be created for the same BB
334 * dependend on command line options and:
335 * - current function (it's possible that a BB is executed in the
336 * context of different functions, e.g. in manual assembler/PLT)
337 * - current thread ID
338 * - position where current function is called from
339 * - recursion level of current function
340 *
341 * The cost centres for the instructions of a basic block are
342 * stored in a contiguous array.
343 * They are distinguishable by their tag field.
344 */
345struct _BBCC {
346 BB* bb; /* BB for this cost center */
347
348 Context* cxt; /* execution context of this BBCC */
349 ThreadId tid; /* only for assertion check purpose */
350 UInt rec_index; /* Recursion index in rec->bbcc for this bbcc */
351 BBCC** rec_array; /* Variable sized array of pointers to
352 * recursion BBCCs. Shared. */
353 ULong ret_counter; /* how often returned from jccs of this bbcc;
354 * used to check if a dump for this BBCC is needed */
355
356 BBCC* next_bbcc; /* Chain of BBCCs for same BB */
357 BBCC* lru_next_bbcc; /* BBCC executed next the last time */
358
359 jCC* lru_from_jcc; /* Temporary: Cached for faster access (LRU) */
360 jCC* lru_to_jcc; /* Temporary: Cached for faster access (LRU) */
361 FullCost skipped; /* cost for skipped functions called from
362 * jmp_addr. Allocated lazy */
363
364 BBCC* next; /* entry chain in hash */
365 ULong* cost; /* start of 64bit costs for this BBCC */
366 ULong ecounter_sum; /* execution counter for first instruction of BB */
367 JmpData jmp[0];
368};
369
370
371/* the <number> of fn_node, file_node and obj_node are for compressed dumping
372 * and a index into the dump boolean table and fn_info_table
373 */
374
375struct _fn_node {
376 Char* name;
377 UInt number;
378 Context* last_cxt; /* LRU info */
379 Context* pure_cxt; /* the context with only the function itself */
380 file_node* file; /* reverse mapping for 2nd hash */
381 fn_node* next;
382
383 Bool dump_before :1;
384 Bool dump_after :1;
385 Bool zero_before :1;
386 Bool toggle_collect :1;
387 Bool skip :1;
388 Bool pop_on_jump : 1;
389
390 Bool is_malloc :1;
391 Bool is_realloc :1;
392 Bool is_free :1;
393
394 Int group;
395 Int separate_callers;
396 Int separate_recursions;
397#if CLG_ENABLE_DEBUG
398 Int verbosity; /* Stores old verbosity level while in function */
399#endif
400};
401
402/* Quite arbitrary fixed hash sizes */
403
404#define N_OBJ_ENTRIES 47
405#define N_FILE_ENTRIES 53
406#define N_FN_ENTRIES 87
407#define N_BBCC2_ENTRIES 37
408
409struct _file_node {
410 Char* name;
411 fn_node* fns[N_FN_ENTRIES];
412 UInt number;
413 obj_node* obj;
414 file_node* next;
415};
416
417/* If an object is dlopened multiple times, we hope that <name> is unique;
418 * <start> and <offset> can change with each dlopen, and <start> is
419 * zero when object is unmapped (possible at dump time).
420 */
421struct _obj_node {
422 Char* name;
423 UInt last_slash_pos;
424
425 Addr start; /* Start address of text segment mapping */
426 SizeT size; /* Length of mapping */
427 OffT offset; /* Offset between symbol address and file offset */
428
429 file_node* files[N_FILE_ENTRIES];
430 UInt number;
431 obj_node* next;
432};
433
434/* an entry in the callstack
435 *
436 * <nonskipped> is 0 if the function called is not skipped (usual case).
437 * Otherwise, it is the last non-skipped BBCC. This one gets all
438 * the calls to non-skipped functions and all costs in skipped
439 * instructions.
440 */
441struct _call_entry {
442 jCC* jcc; /* jCC for this call */
443 FullCost enter_cost; /* cost event counters at entering frame */
444 Addr sp; /* stack pointer directly after call */
445 Addr ret_addr; /* address to which to return to
446 * is 0 on a simulated call */
447 BBCC* nonskipped; /* see above */
448 Context* cxt; /* context before call */
449 Int fn_sp; /* function stack index before call */
450};
451
452
453/*
454 * Execution state of main thread or a running signal handler in
455 * a thread while interrupted by another signal handler.
456 * As there's no scheduling among running signal handlers of one thread,
457 * we only need a subset of a full thread state:
458 * - event counter
459 * - collect state
460 * - last BB, last jump kind, last nonskipped BB
461 * - callstack pointer for sanity checking and correct unwinding
462 * after exit
463 */
464typedef struct _exec_state exec_state;
465struct _exec_state {
466
467 /* the signum of the handler, 0 for main thread context
468 */
469 Int sig;
470
471 /* the old call stack pointer at entering the signal handler */
472 Int orig_sp;
473
474 FullCost cost;
475 Bool collect;
476 Context* cxt;
477
478 Int jmps_passed; /* number of conditional jumps passed in last BB */
479 BBCC* bbcc; /* last BB executed */
480 BBCC* nonskipped;
481
482 Int call_stack_bottom; /* Index into fn_stack */
483};
484
485/* Global state structures */
486typedef struct _bb_hash bb_hash;
487struct _bb_hash {
488 UInt size, entries;
489 BB** table;
490};
491
492typedef struct _cxt_hash cxt_hash;
493struct _cxt_hash {
494 UInt size, entries;
495 Context** table;
496};
497
498/* Thread specific state structures, i.e. parts of a thread state.
499 * There are variables for the current state of each part,
500 * on which a thread state is copied at thread switch.
501 */
502typedef struct _bbcc_hash bbcc_hash;
503struct _bbcc_hash {
504 UInt size, entries;
505 BBCC** table;
506};
507
508typedef struct _jcc_hash jcc_hash;
509struct _jcc_hash {
510 UInt size, entries;
511 jCC** table;
512 jCC* spontaneous;
513};
514
515typedef struct _fn_array fn_array;
516struct _fn_array {
517 UInt size;
518 UInt* array;
519};
520
521typedef struct _call_stack call_stack;
522struct _call_stack {
523 UInt size;
524 Int sp;
525 call_entry* entry;
526};
527
528typedef struct _fn_stack fn_stack;
529struct _fn_stack {
530 UInt size;
531 fn_node **bottom, **top;
532};
533
534/* The maximum number of simultaneous running signal handlers per thread.
535 * This is the number of execution states storable in a thread.
536 */
537#define MAX_SIGHANDLERS 10
538
539typedef struct _exec_stack exec_stack;
540struct _exec_stack {
541 Int sp; /* > 0 if a handler is running */
542 exec_state* entry[MAX_SIGHANDLERS];
543};
544
545/* Thread State
546 *
547 * This structure stores thread specific info while a thread is *not*
548 * running. See function switch_thread() for save/restore on thread switch.
549 *
550 * If --separate-threads=no, BBCCs and JCCs can be shared by all threads, i.e.
551 * only structures of thread 1 are used.
552 * This involves variables fn_info_table, bbcc_table and jcc_table.
553 */
554struct _thread_info {
555
556 /* state */
557 fn_stack fns; /* function stack */
558 call_stack calls; /* context call arc stack */
559 exec_stack states; /* execution states interrupted by signals */
560
561 /* dump statistics */
562 FullCost lastdump_cost; /* Cost at last dump */
563 FullCost sighandler_cost;
564
565 /* thread specific data structure containers */
566 fn_array fn_active;
567 jcc_hash jccs;
568 bbcc_hash bbccs;
569};
570
571/* Structs used for dumping */
572
573/* Address position inside of a BBCC:
574 * This includes
575 * - the address offset from the BB start address
576 * - file/line from debug info for that address (can change inside a BB)
577 */
578typedef struct _AddrPos AddrPos;
579struct _AddrPos {
580 Addr addr;
581 Addr bb_addr;
582 file_node* file;
583 UInt line;
584};
585
586/* a simulator cost entity that can be written out in one line */
587typedef struct _AddrCost AddrCost;
588struct _AddrCost {
589 AddrPos p;
590 SimCost cost;
591};
592
593/* A function in an execution context */
594typedef struct _FnPos FnPos;
595struct _FnPos {
596 file_node* file;
597 fn_node* fn;
598 obj_node* obj;
599 Context* cxt;
600 int rec_index;
601 UInt line;
602};
603
604/*------------------------------------------------------------*/
605/*--- Cache simulator interface ---*/
606/*------------------------------------------------------------*/
607
608struct cachesim_if
609{
610 void (*print_opts)(void);
611 Bool (*parse_opt)(Char* arg);
612 void (*post_clo_init)(void);
613 void (*clear)(void);
614 void (*getdesc)(Char* buf);
615 void (*printstat)(void);
616 void (*add_icost)(SimCost, BBCC*, InstrInfo*, ULong);
617 void (*after_bbsetup)(void);
618 void (*finish)(void);
619
620 void (*log_1I0D)(InstrInfo*) VG_REGPARM(1);
621
622 void (*log_1I1Dr)(InstrInfo*, Addr) VG_REGPARM(2);
623 void (*log_1I1Dw)(InstrInfo*, Addr) VG_REGPARM(2);
624 void (*log_1I2D)(InstrInfo*, Addr, Addr) VG_REGPARM(3);
625
626 void (*log_0I1Dr)(InstrInfo*, Addr) VG_REGPARM(2);
627 void (*log_0I1Dw)(InstrInfo*, Addr) VG_REGPARM(2);
628 void (*log_0I2D)(InstrInfo*, Addr, Addr) VG_REGPARM(3);
629
630 // function names of helpers (for debugging generated code)
631 Char *log_1I0D_name;
632 Char *log_1I1Dr_name, *log_1I1Dw_name, *log_1I2D_name;
633 Char *log_0I1Dr_name, *log_0I1Dw_name, *log_0I2D_name;
634};
635
636
637/*------------------------------------------------------------*/
638/*--- Functions ---*/
639/*------------------------------------------------------------*/
640
641/* from clo.c */
642
643void CLG_(set_clo_defaults)(void);
644void CLG_(update_fn_config)(fn_node*);
645Bool CLG_(process_cmd_line_option)(Char*);
646void CLG_(print_usage)(void);
647void CLG_(print_debug_usage)(void);
648
649/* from sim.c */
650struct event_sets {
651 EventSet *use, *Ir, *Dr, *Dw;
652 EventSet *D0, *D1r, *D1w, *D2;
653 EventSet *sim;
654 EventSet *full; /* sim plus user events */
655
656 /* offsets into eventsets */
657 Int off_sim_Ir, off_sim_Dr, off_sim_Dw;
658 Int off_full_Ir, off_full_Dr, off_full_Dw;
659 Int off_full_user, off_full_alloc, off_full_systime;
660};
661
662extern struct event_sets CLG_(sets);
663extern struct cachesim_if CLG_(cachesim);
664
665void CLG_(init_eventsets)(Int user);
666
667/* from main.c */
668Bool CLG_(get_debug_info)(Addr, Char filename[FILENAME_LEN],
669 Char fn_name[FN_NAME_LEN], UInt*, SegInfo**);
670void CLG_(collectBlockInfo)(IRBB* bbIn, UInt*, UInt*, Bool*);
671void CLG_(set_instrument_state)(Char*,Bool);
672void CLG_(dump_profile)(Char* trigger,Bool only_current_thread);
673void CLG_(zero_all_cost)(Bool only_current_thread);
674Int CLG_(get_dump_counter)(void);
675void CLG_(fini)(Int exitcode);
676
677/* from command.c */
678void CLG_(init_command)(Char* dir, Char* dumps);
679void CLG_(check_command)(void);
680void CLG_(finish_command)(void);
681
682/* from bb.c */
683void CLG_(init_bb_hash)(void);
684bb_hash* CLG_(get_bb_hash)(void);
685BB* CLG_(get_bb)(Addr addr, IRBB* bb_in, Bool *seen_before);
686void CLG_(delete_bb)(Addr addr);
687
688static __inline__ Addr bb_addr(BB* bb)
689 { return bb->offset + bb->obj->offset; }
690static __inline__ Addr bb_jmpaddr(BB* bb)
691 { return bb->instr[bb->instr_count-1].instr_offset + bb->offset + bb->obj->offset; }
692
693/* from fn.c */
694void CLG_(init_fn_array)(fn_array*);
695void CLG_(copy_current_fn_array)(fn_array* dst);
696fn_array* CLG_(get_current_fn_array)(void);
697void CLG_(set_current_fn_array)(fn_array*);
698UInt* CLG_(get_fn_entry)(Int n);
699
700void CLG_(init_obj_table)(void);
701obj_node* CLG_(get_obj_node)(SegInfo* si);
702file_node* CLG_(get_file_node)(obj_node*, Char* filename);
703fn_node* CLG_(get_fn_node)(BB* bb);
704
705/* from bbcc.c */
706void CLG_(init_bbcc_hash)(bbcc_hash* bbccs);
707void CLG_(copy_current_bbcc_hash)(bbcc_hash* dst);
708bbcc_hash* CLG_(get_current_bbcc_hash)(void);
709void CLG_(set_current_bbcc_hash)(bbcc_hash*);
710void CLG_(forall_bbccs)(void (*func)(BBCC*));
711void CLG_(zero_bbcc)(BBCC* bbcc);
712BBCC* CLG_(get_bbcc)(BB* bb);
713BBCC* CLG_(clone_bbcc)(BBCC* orig, Context* cxt, Int rec_index);
714void CLG_(setup_bbcc)(BB* bb) VG_REGPARM(1);
715
716
717/* from jumps.c */
718void CLG_(init_jcc_hash)(jcc_hash*);
719void CLG_(copy_current_jcc_hash)(jcc_hash* dst);
720jcc_hash* CLG_(get_current_jcc_hash)(void);
721void CLG_(set_current_jcc_hash)(jcc_hash*);
722jCC* CLG_(get_jcc)(BBCC* from, UInt, BBCC* to);
723
724/* from callstack.c */
725void CLG_(init_call_stack)(call_stack*);
726void CLG_(copy_current_call_stack)(call_stack* dst);
727void CLG_(set_current_call_stack)(call_stack*);
728call_entry* CLG_(get_call_entry)(Int n);
729
730void CLG_(push_call_stack)(BBCC* from, UInt jmp, BBCC* to, Addr sp, Bool skip);
731void CLG_(pop_call_stack)(void);
732void CLG_(unwind_call_stack)(Addr sp, Int);
733
734/* from context.c */
735void CLG_(init_fn_stack)(fn_stack*);
736void CLG_(copy_current_fn_stack)(fn_stack*);
737fn_stack* CLG_(get_current_fn_stack)(void);
738void CLG_(set_current_fn_stack)(fn_stack*);
739
740void CLG_(init_cxt_table)(void);
741cxt_hash* CLG_(get_cxt_hash)(void);
742Context* CLG_(get_cxt)(fn_node** fn);
743void CLG_(push_cxt)(fn_node* fn);
744
745/* from threads.c */
746void CLG_(init_threads)(void);
747thread_info** CLG_(get_threads)(void);
748thread_info* CLG_(get_current_thread)(void);
749void CLG_(switch_thread)(ThreadId tid);
750void CLG_(forall_threads)(void (*func)(thread_info*));
751void CLG_(run_thread)(ThreadId tid);
752
753void CLG_(init_exec_state)(exec_state* es);
754void CLG_(init_exec_stack)(exec_stack*);
755void CLG_(copy_current_exec_stack)(exec_stack*);
756void CLG_(set_current_exec_stack)(exec_stack*);
757void CLG_(pre_signal)(ThreadId tid, Int sigNum, Bool alt_stack);
758void CLG_(post_signal)(ThreadId tid, Int sigNum);
759void CLG_(run_post_signal_on_call_stack_bottom)(void);
760
761/* from dump.c */
762extern FullCost CLG_(total_cost);
763void CLG_(init_files)(Char** dir, Char** file);
764Char* CLG_(get_dump_file_base)(void);
765
766
767/*------------------------------------------------------------*/
768/*--- Exported global variables ---*/
769/*------------------------------------------------------------*/
770
771extern CommandLineOptions CLG_(clo);
772extern Statistics CLG_(stat);
773extern EventMapping* CLG_(dumpmap);
774
775/* Function active counter array, indexed by function number */
776extern UInt* CLG_(fn_active_array);
777extern Bool CLG_(instrument_state);
778
779extern call_stack CLG_(current_call_stack);
780extern fn_stack CLG_(current_fn_stack);
781extern exec_state CLG_(current_state);
782extern ThreadId CLG_(current_tid);
783
784
785/*------------------------------------------------------------*/
786/*--- Debug output ---*/
787/*------------------------------------------------------------*/
788
789#if CLG_ENABLE_DEBUG
790
791#define CLG_DEBUGIF(x) \
792 if ( (CLG_(clo).verbose >x) && \
793 (CLG_(stat).bb_executions >= CLG_(clo).verbose_start))
794
795#define CLG_DEBUG(x,format,args...) \
796 CLG_DEBUGIF(x) { \
797 CLG_(print_bbno)(); \
798 VG_(printf)(format,##args); \
799 }
800
801#define CLG_ASSERT(cond) \
802 if (!(cond)) { \
803 CLG_(print_context)(); \
804 CLG_(print_bbno)(); \
805 tl_assert(cond); \
806 }
807
808#else
809#define CLG_DEBUGIF(x) if (0)
810#define CLG_DEBUG(x...) {}
811#define CLG_ASSERT(cond) tl_assert(cond);
812#endif
813
814/* from debug.c */
815void CLG_(print_bbno)(void);
816void CLG_(print_context)(void);
817void CLG_(print_jcc)(int s, jCC* jcc);
818void CLG_(print_bbcc)(int s, BBCC* bbcc, Bool);
819void CLG_(print_bbcc_fn)(BBCC* bbcc);
820void CLG_(print_execstate)(int s, exec_state* es);
821void CLG_(print_eventset)(int s, EventSet* es);
822void CLG_(print_cost)(int s, EventSet*, ULong* cost);
823void CLG_(print_bb)(int s, BB* bb);
824void CLG_(print_bbcc_cost)(int s, BBCC*);
825void CLG_(print_cxt)(int s, Context* cxt, int rec_index);
826void CLG_(print_short_jcc)(jCC* jcc);
827void CLG_(print_stackentry)(int s, int sp);
828void CLG_(print_addr)(Addr addr);
829void CLG_(print_addr_ln)(Addr addr);
830
831void* CLG_(malloc)(UWord s, char* f);
832void* CLG_(free)(void* p, char* f);
833#if 0
834#define CLG_MALLOC(x) CLG_(malloc)(x,__FUNCTION__)
835#define CLG_FREE(p) CLG_(free)(p,__FUNCTION__)
836#else
837#define CLG_MALLOC(x) VG_(malloc)(x)
838#define CLG_FREE(p) VG_(free)(p)
839#endif
840
841#endif /* CLG_GLOBAL */