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