Malloc replacements: add some C++14/17 comments
[valgrind.git] / callgrind / global.h
blob4a988a4811e9738d2ab5c312039c15f6d47cf837
1 /*--------------------------------------------------------------------*/
2 /*--- Callgrind data structures, functions. global.h ---*/
3 /*--------------------------------------------------------------------*/
5 /*
6 This file is part of Valgrind, a dynamic binary instrumentation
7 framework.
9 Copyright (C) 2004-2017 Josef Weidendorfer
10 josef.weidendorfer@gmx.de
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
17 This program is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, see <http://www.gnu.org/licenses/>.
25 The GNU General Public License is contained in the file COPYING.
28 #ifndef CLG_GLOBAL
29 #define CLG_GLOBAL
31 #include "pub_tool_basics.h"
32 #include "pub_tool_vki.h"
33 #include "pub_tool_debuginfo.h"
34 #include "pub_tool_libcbase.h"
35 #include "pub_tool_libcassert.h"
36 #include "pub_tool_libcfile.h"
37 #include "pub_tool_libcprint.h"
38 #include "pub_tool_libcproc.h"
39 #include "pub_tool_machine.h"
40 #include "pub_tool_mallocfree.h"
41 #include "pub_tool_options.h"
42 #include "pub_tool_tooliface.h"
43 #include "pub_tool_xarray.h"
44 #include "pub_tool_clientstate.h"
45 #include "pub_tool_machine.h" // VG_(fnptr_to_fnentry)
47 #include "events.h" // defines CLG_ macro
48 #include "costs.h"
51 /*------------------------------------------------------------*/
52 /*--- Callgrind compile options --- */
53 /*------------------------------------------------------------*/
55 /* Enable debug output */
56 #define CLG_ENABLE_DEBUG 1
58 /* Enable experimental features? */
59 #define CLG_EXPERIMENTAL 0
62 /*------------------------------------------------------------*/
63 /*--- Command line options ---*/
64 /*------------------------------------------------------------*/
66 #define DEFAULT_OUTFORMAT "callgrind.out.%p"
68 /* If and how to collect syscall time.
69 systime_no : do not collect systime
70 systime_msec : collect syscount, systime elapsed, milli second precision.
71 systime_usec : collect syscount, systime elapsed, micro second precision.
72 systime_nsec : collect syscount, systime elapsed, systime cpu, nano second
73 precision. */
74 typedef enum {
75 systime_no,
76 systime_msec,
77 systime_usec,
78 systime_nsec
79 } Collect_Systime;
81 typedef struct _CommandLineOptions CommandLineOptions;
82 struct _CommandLineOptions {
84 /* Dump format options */
85 const HChar* out_format; /* Format string for callgrind output file name */
86 Bool combine_dumps; /* Dump trace parts into same file? */
87 Bool compress_strings;
88 Bool compress_events;
89 Bool compress_pos;
90 Bool mangle_names;
91 Bool compress_mangled;
92 Bool dump_line;
93 Bool dump_instr;
94 Bool dump_bb;
95 Bool dump_bbs; /* Dump basic block information? */
97 /* Dump generation options */
98 ULong dump_every_bb; /* Dump every xxx BBs. */
100 /* Collection options */
101 Bool separate_threads; /* Separate threads in dump? */
102 Int separate_callers; /* Separate dependent on how many callers? */
103 Int separate_recursions; /* Max level of recursions to separate */
104 Bool skip_plt; /* Skip functions in PLT section? */
105 Bool skip_direct_recursion; /* Increment direct recursions the level? */
107 Bool collect_atstart; /* Start in collecting state ? */
108 Bool collect_jumps; /* Collect (cond.) jumps in functions ? */
110 Bool collect_alloc; /* Collect size of allocated memory */
111 Collect_Systime collect_systime; /* Collect time for system calls */
113 Bool collect_bus; /* Collect global bus events */
115 /* Instrument options */
116 Bool instrument_atstart; /* Instrument at start? */
117 Bool simulate_cache; /* Call into cache simulator ? */
118 Bool simulate_branch; /* Call into branch prediction simulator ? */
120 /* Call graph generation */
121 Bool pop_on_jump; /* Handle a jump between functions as ret+call */
123 #if CLG_ENABLE_DEBUG
124 Int verbose;
125 ULong verbose_start;
126 #endif
129 /*------------------------------------------------------------*/
130 /*--- Constants ---*/
131 /*------------------------------------------------------------*/
133 /* Minimum cache line size allowed */
134 #define MIN_LINE_SIZE 16
137 /*------------------------------------------------------------*/
138 /*--- Statistics ---*/
139 /*------------------------------------------------------------*/
141 typedef struct _Statistics Statistics;
142 struct _Statistics {
143 ULong call_counter;
144 ULong jcnd_counter;
145 ULong jump_counter;
146 ULong rec_call_counter;
147 ULong ret_counter;
148 ULong bb_executions;
150 Int context_counter;
151 Int bb_retranslations;
153 Int distinct_objs;
154 Int distinct_files;
155 Int distinct_fns;
156 Int distinct_contexts;
157 Int distinct_bbs;
158 Int distinct_jccs;
159 Int distinct_bbccs;
160 Int distinct_instrs;
161 Int distinct_skips;
163 Int bb_hash_resizes;
164 Int bbcc_hash_resizes;
165 Int jcc_hash_resizes;
166 Int cxt_hash_resizes;
167 Int fn_array_resizes;
168 Int call_stack_resizes;
169 Int fn_stack_resizes;
171 Int full_debug_BBs;
172 Int file_line_debug_BBs;
173 Int fn_name_debug_BBs;
174 Int no_debug_BBs;
175 Int bbcc_lru_misses;
176 Int jcc_lru_misses;
177 Int cxt_lru_misses;
178 Int bbcc_clones;
182 /*------------------------------------------------------------*/
183 /*--- Structure declarations ---*/
184 /*------------------------------------------------------------*/
186 typedef struct _Context Context;
187 typedef struct _CC CC;
188 typedef struct _BB BB;
189 typedef struct _BBCC BBCC;
190 typedef struct _jCC jCC;
191 typedef struct _fCC fCC;
192 typedef struct _fn_node fn_node;
193 typedef struct _file_node file_node;
194 typedef struct _obj_node obj_node;
195 typedef struct _fn_config fn_config;
196 typedef struct _call_entry call_entry;
197 typedef struct _thread_info thread_info;
199 /* Costs of event sets. Aliases to arrays of 64-bit values */
200 typedef ULong* SimCost; /* All events the simulator can produce */
201 typedef ULong* UserCost;
202 typedef ULong* FullCost; /* Simulator + User */
205 /* The types of control flow changes that can happen between
206 * execution of two BBs in a thread.
208 typedef enum {
209 jk_None = 0, /* no explicit change by a guest instruction */
210 jk_Jump, /* regular jump */
211 jk_Call,
212 jk_Return,
213 jk_CondJump /* conditional jump taken (only used as jCC type) */
214 } ClgJumpKind;
217 /* JmpCall cost center
218 * for subroutine call (from->bb->jmp_addr => to->bb->addr)
220 * Each BB has at most one CALL instruction. The list of JCC from
221 * this call is a pointer to the list head (stored in BBCC), and
222 * <next_from> in the JCC struct.
224 * For fast lookup, JCCs are reachable with a hash table, keyed by
225 * the (from_bbcc,to) pair. <next_hash> is used for the JCC chain
226 * of one hash table entry.
228 * Cost <sum> holds event counts for already returned executions.
229 * <last> are the event counters at last enter of the subroutine.
230 * <sum> is updated on returning from the subroutine by
231 * adding the diff of <last> and current event counters to <sum>.
233 * After updating, <last> is set to current event counters. Thus,
234 * events are not counted twice for recursive calls (TODO: True?)
237 struct _jCC {
238 ClgJumpKind jmpkind; /* jk_Call, jk_Jump, jk_CondJump */
239 jCC* next_hash; /* for hash entry chain */
240 jCC* next_from; /* next JCC from a BBCC */
241 BBCC *from, *to; /* call arc from/to this BBCC */
242 UInt jmp; /* jump no. in source */
244 ULong call_counter; /* no wraparound with 64 bit */
246 FullCost cost; /* simulator + user counters */
251 * Info for one instruction of a basic block.
253 typedef struct _InstrInfo InstrInfo;
254 struct _InstrInfo {
255 UInt instr_offset;
256 UInt instr_size;
257 UInt cost_offset;
258 EventSet* eventset;
264 * Info for a side exit in a BB
266 typedef struct _CJmpInfo CJmpInfo;
267 struct _CJmpInfo {
268 UInt instr; /* instruction index for BB.instr array */
269 ClgJumpKind jmpkind; /* jump kind when leaving BB at this side exit */
274 * An instrumented basic block (BB).
276 * BBs are put into a resizable hash to allow for fast detection if a
277 * BB is to be retranslated but cost info is already available.
278 * The key for a BB is a (object, offset) tupel making it independent
279 * from possibly multiple mappings of the same ELF object.
281 * At the beginning of each instrumented BB,
282 * a call to setup_bbcc(), specifying a pointer to the
283 * according BB structure, is added.
285 * As cost of a BB has to be distinguished depending on the context,
286 * multiple cost centers for one BB (struct BBCC) exist and the according
287 * BBCC is set by setup_bbcc.
289 struct _BB {
290 obj_node* obj; /* ELF object of BB */
291 PtrdiffT offset; /* offset of BB in ELF object file */
292 BB* next; /* chaining for a hash entry */
294 VgSectKind sect_kind; /* section of this BB, e.g. PLT */
295 UInt instr_count;
297 /* filled by CLG_(get_fn_node) if debug info is available */
298 fn_node* fn; /* debug info for this BB */
299 UInt line;
300 Bool is_entry; /* True if this BB is a function entry */
302 BBCC* bbcc_list; /* BBCCs for same BB (see next_bbcc in BBCC) */
303 BBCC* last_bbcc; /* Temporary: Cached for faster access (LRU) */
305 /* filled by CLG_(instrument) if not seen before */
306 UInt cjmp_count; /* number of side exits */
307 CJmpInfo* jmp; /* array of info for condition jumps,
308 * allocated directly after this struct */
309 Bool cjmp_inverted; /* is last side exit actually fall through? */
311 UInt instr_len;
312 UInt cost_count;
313 InstrInfo instr[0]; /* info on instruction sizes and costs */
319 * Function context
321 * Basic blocks are always executed in the scope of a context.
322 * A function context is a list of function nodes representing
323 * the call chain to the current context: I.e. fn[0] is the
324 * function we are currently in, fn[1] has called fn[0], and so on.
325 * Recursion levels are used for fn[0].
327 * To get a unique number for a full execution context, use
328 * rec_index = min(<fn->rec_separation>,<active>) - 1;
329 * unique_no = <number> + rec_index
331 * For each Context, recursion index and BB, there can be a BBCC.
333 struct _Context {
334 UInt size; // number of function dependencies
335 UInt base_number; // for context compression & dump array
336 Context* next; // entry chaining for hash
337 UWord hash; // for faster lookup...
338 fn_node* fn[0];
343 * Cost info for a side exits from a BB
345 typedef struct _JmpData JmpData;
346 struct _JmpData {
347 ULong ecounter; /* number of times the BB was left at this exit */
348 jCC* jcc_list; /* JCCs used for this exit */
353 * Basic Block Cost Center
355 * On demand, multiple BBCCs will be created for the same BB
356 * dependent on command line options and:
357 * - current function (it's possible that a BB is executed in the
358 * context of different functions, e.g. in manual assembler/PLT)
359 * - current thread ID
360 * - position where current function is called from
361 * - recursion level of current function
363 * The cost centres for the instructions of a basic block are
364 * stored in a contiguous array.
365 * They are distinguishable by their tag field.
367 struct _BBCC {
368 BB* bb; /* BB for this cost center */
370 Context* cxt; /* execution context of this BBCC */
371 ThreadId tid; /* only for assertion check purpose */
372 UInt rec_index; /* Recursion index in rec->bbcc for this bbcc */
373 BBCC** rec_array; /* Variable sized array of pointers to
374 * recursion BBCCs. Shared. */
375 ULong ret_counter; /* how often returned from jccs of this bbcc;
376 * used to check if a dump for this BBCC is needed */
378 BBCC* next_bbcc; /* Chain of BBCCs for same BB */
379 BBCC* lru_next_bbcc; /* BBCC executed next the last time */
381 jCC* lru_from_jcc; /* Temporary: Cached for faster access (LRU) */
382 jCC* lru_to_jcc; /* Temporary: Cached for faster access (LRU) */
383 FullCost skipped; /* cost for skipped functions called from
384 * jmp_addr. Allocated lazy */
386 BBCC* next; /* entry chain in hash */
387 ULong* cost; /* start of 64bit costs for this BBCC */
388 ULong ecounter_sum; /* execution counter for first instruction of BB */
389 JmpData jmp[0];
393 /* the <number> of fn_node, file_node and obj_node are for compressed dumping
394 * and a index into the dump boolean table and fn_info_table
397 struct _fn_node {
398 HChar* name;
399 UInt number;
400 Context* last_cxt; /* LRU info */
401 Context* pure_cxt; /* the context with only the function itself */
402 file_node* file; /* reverse mapping for 2nd hash */
403 fn_node* next;
405 Bool dump_before :1;
406 Bool dump_after :1;
407 Bool zero_before :1;
408 Bool toggle_collect :1;
409 Bool skip :1;
410 Bool pop_on_jump : 1;
412 Bool is_malloc :1;
413 Bool is_realloc :1;
414 Bool is_free :1;
416 Int group;
417 Int separate_callers;
418 Int separate_recursions;
419 #if CLG_ENABLE_DEBUG
420 Int verbosity; /* Stores old verbosity level while in function */
421 #endif
424 /* Quite arbitrary fixed hash sizes */
426 #define N_OBJ_ENTRIES 47
427 #define N_FILE_ENTRIES 53
428 #define N_FN_ENTRIES 87
430 struct _file_node {
431 HChar* name;
432 fn_node* fns[N_FN_ENTRIES];
433 UInt number;
434 obj_node* obj;
435 file_node* next;
438 /* If an object is dlopened multiple times, we hope that <name> is unique;
439 * <start> and <offset> can change with each dlopen, and <start> is
440 * zero when object is unmapped (possible at dump time).
442 struct _obj_node {
443 const HChar* name;
444 UInt last_slash_pos;
446 Addr start; /* Start address of text segment mapping */
447 SizeT size; /* Length of mapping */
448 PtrdiffT offset; /* Offset between symbol address and file offset */
450 file_node* files[N_FILE_ENTRIES];
451 UInt number;
452 obj_node* next;
455 /* an entry in the callstack
457 * <nonskipped> is 0 if the function called is not skipped (usual case).
458 * Otherwise, it is the last non-skipped BBCC. This one gets all
459 * the calls to non-skipped functions and all costs in skipped
460 * instructions.
462 struct _call_entry {
463 jCC* jcc; /* jCC for this call */
464 FullCost enter_cost; /* cost event counters at entering frame */
465 Addr sp; /* stack pointer directly after call */
466 Addr ret_addr; /* address to which to return to
467 * is 0 on a simulated call */
468 BBCC* nonskipped; /* see above */
469 Context* cxt; /* context before call */
470 Int fn_sp; /* function stack index before call */
475 * Execution state of main thread or a running signal handler in
476 * a thread while interrupted by another signal handler.
477 * As there's no scheduling among running signal handlers of one thread,
478 * we only need a subset of a full thread state:
479 * - event counter
480 * - collect state
481 * - last BB, last jump kind, last nonskipped BB
482 * - callstack pointer for sanity checking and correct unwinding
483 * after exit
485 typedef struct _exec_state exec_state;
486 struct _exec_state {
488 /* the signum of the handler, 0 for main thread context
490 Int sig;
492 /* the old call stack pointer at entering the signal handler */
493 Int orig_sp;
495 FullCost cost;
496 Bool collect;
497 Context* cxt;
499 /* number of conditional jumps passed in last BB */
500 Int jmps_passed;
501 BBCC* bbcc; /* last BB executed */
502 BBCC* nonskipped;
504 Int call_stack_bottom; /* Index into fn_stack */
507 /* Global state structures */
508 typedef struct _bb_hash bb_hash;
509 struct _bb_hash {
510 UInt size, entries;
511 BB** table;
514 typedef struct _cxt_hash cxt_hash;
515 struct _cxt_hash {
516 UInt size, entries;
517 Context** table;
520 /* Thread specific state structures, i.e. parts of a thread state.
521 * There are variables for the current state of each part,
522 * on which a thread state is copied at thread switch.
524 typedef struct _bbcc_hash bbcc_hash;
525 struct _bbcc_hash {
526 UInt size, entries;
527 BBCC** table;
530 typedef struct _jcc_hash jcc_hash;
531 struct _jcc_hash {
532 UInt size, entries;
533 jCC** table;
534 jCC* spontaneous;
537 typedef struct _fn_array fn_array;
538 struct _fn_array {
539 UInt size;
540 UInt* array;
543 typedef struct _call_stack call_stack;
544 struct _call_stack {
545 UInt size;
546 Int sp;
547 call_entry* entry;
550 typedef struct _fn_stack fn_stack;
551 struct _fn_stack {
552 UInt size;
553 fn_node **bottom, **top;
556 /* The maximum number of simultaneous running signal handlers per thread.
557 * This is the number of execution states storable in a thread.
559 #define MAX_SIGHANDLERS 10
561 typedef struct _exec_stack exec_stack;
562 struct _exec_stack {
563 Int sp; /* > 0 if a handler is running */
564 exec_state* entry[MAX_SIGHANDLERS];
567 /* Thread State
569 * This structure stores thread specific info while a thread is *not*
570 * running. See function switch_thread() for save/restore on thread switch.
572 * If --separate-threads=no, BBCCs and JCCs can be shared by all threads, i.e.
573 * only structures of thread 1 are used.
574 * This involves variables fn_info_table, bbcc_table and jcc_table.
576 struct _thread_info {
578 /* state */
579 fn_stack fns; /* function stack */
580 call_stack calls; /* context call arc stack */
581 exec_stack states; /* execution states interrupted by signals */
583 /* dump statistics */
584 FullCost lastdump_cost; /* Cost at last dump */
585 FullCost sighandler_cost;
587 /* thread specific data structure containers */
588 fn_array fn_active;
589 jcc_hash jccs;
590 bbcc_hash bbccs;
593 /* Structs used for dumping */
595 /* Address position inside of a BBCC:
596 * This includes
597 * - the address offset from the BB start address
598 * - file/line from debug info for that address (can change inside a BB)
600 typedef struct _AddrPos AddrPos;
601 struct _AddrPos {
602 Addr addr;
603 Addr bb_addr;
604 file_node* file;
605 UInt line;
608 /* a simulator cost entity that can be written out in one line */
609 typedef struct _AddrCost AddrCost;
610 struct _AddrCost {
611 AddrPos p;
612 SimCost cost;
615 /* A function in an execution context */
616 typedef struct _FnPos FnPos;
617 struct _FnPos {
618 file_node* file;
619 fn_node* fn;
620 obj_node* obj;
621 Context* cxt;
622 int rec_index;
623 UInt line;
626 /*------------------------------------------------------------*/
627 /*--- Cache simulator interface ---*/
628 /*------------------------------------------------------------*/
630 struct cachesim_if
632 void (*print_opts)(void);
633 Bool (*parse_opt)(const HChar* arg);
634 void (*post_clo_init)(void);
635 void (*clear)(void);
636 void (*dump_desc)(VgFile *fp);
637 void (*printstat)(Int,Int,Int);
638 void (*add_icost)(SimCost, BBCC*, InstrInfo*, ULong);
639 void (*finish)(void);
641 void (*log_1I0D)(InstrInfo*) VG_REGPARM(1);
642 void (*log_2I0D)(InstrInfo*, InstrInfo*) VG_REGPARM(2);
643 void (*log_3I0D)(InstrInfo*, InstrInfo*, InstrInfo*) VG_REGPARM(3);
645 void (*log_1I1Dr)(InstrInfo*, Addr, Word) VG_REGPARM(3);
646 void (*log_1I1Dw)(InstrInfo*, Addr, Word) VG_REGPARM(3);
648 void (*log_0I1Dr)(InstrInfo*, Addr, Word) VG_REGPARM(3);
649 void (*log_0I1Dw)(InstrInfo*, Addr, Word) VG_REGPARM(3);
651 // function names of helpers (for debugging generated code)
652 const HChar *log_1I0D_name, *log_2I0D_name, *log_3I0D_name;
653 const HChar *log_1I1Dr_name, *log_1I1Dw_name;
654 const HChar *log_0I1Dr_name, *log_0I1Dw_name;
657 // Event groups
658 #define EG_USE 0
659 #define EG_IR 1
660 #define EG_DR 2
661 #define EG_DW 3
662 #define EG_BC 4
663 #define EG_BI 5
664 #define EG_BUS 6
665 #define EG_ALLOC 7
666 #define EG_SYS 8
668 struct event_sets {
669 EventSet *base, *full;
672 #define fullOffset(group) (CLG_(sets).full->offset[group])
675 /*------------------------------------------------------------*/
676 /*--- Functions ---*/
677 /*------------------------------------------------------------*/
679 /* from clo.c */
681 void CLG_(set_clo_defaults)(void);
682 void CLG_(update_fn_config)(fn_node*);
683 Bool CLG_(process_cmd_line_option)(const HChar*);
684 void CLG_(print_usage)(void);
685 void CLG_(print_debug_usage)(void);
687 /* from sim.c */
688 void CLG_(init_eventsets)(void);
690 /* from main.c */
691 Bool CLG_(get_debug_info)(Addr, const HChar **dirname,
692 const HChar **filename,
693 const HChar **fn_name, UInt*, DebugInfo**);
694 void CLG_(collectBlockInfo)(IRSB* bbIn, UInt*, UInt*, Bool*);
695 void CLG_(set_instrument_state)(const HChar*,Bool);
696 void CLG_(dump_profile)(const HChar* trigger,Bool only_current_thread);
697 void CLG_(zero_all_cost)(Bool only_current_thread);
698 Int CLG_(get_dump_counter)(void);
699 void CLG_(fini)(Int exitcode);
701 /* from bb.c */
702 void CLG_(init_bb_hash)(void);
703 bb_hash* CLG_(get_bb_hash)(void);
704 BB* CLG_(get_bb)(Addr addr, IRSB* bb_in, Bool *seen_before);
705 void CLG_(delete_bb)(Addr addr);
707 static __inline__ Addr bb_addr(BB* bb)
708 { return bb->offset + bb->obj->offset; }
709 static __inline__ Addr bb_jmpaddr(BB* bb)
710 { UInt off = (bb->instr_count > 0) ? bb->instr[bb->instr_count-1].instr_offset : 0;
711 return off + bb->offset + bb->obj->offset; }
713 /* from fn.c */
714 void CLG_(init_fn_array)(fn_array*);
715 void CLG_(copy_current_fn_array)(fn_array* dst);
716 fn_array* CLG_(get_current_fn_array)(void);
717 void CLG_(set_current_fn_array)(fn_array*);
718 UInt* CLG_(get_fn_entry)(Int n);
720 void CLG_(init_obj_table)(void);
721 obj_node* CLG_(get_obj_node)(DebugInfo* si);
722 file_node* CLG_(get_file_node)(obj_node*, const HChar *dirname,
723 const HChar* filename);
724 fn_node* CLG_(get_fn_node)(BB* bb);
726 /* from bbcc.c */
727 void CLG_(init_bbcc_hash)(bbcc_hash* bbccs);
728 void CLG_(copy_current_bbcc_hash)(bbcc_hash* dst);
729 bbcc_hash* CLG_(get_current_bbcc_hash)(void);
730 void CLG_(set_current_bbcc_hash)(bbcc_hash*);
731 void CLG_(forall_bbccs)(void (*func)(BBCC*));
732 void CLG_(zero_bbcc)(BBCC* bbcc);
733 BBCC* CLG_(get_bbcc)(BB* bb);
734 BBCC* CLG_(clone_bbcc)(BBCC* orig, Context* cxt, Int rec_index);
735 void CLG_(setup_bbcc)(BB* bb) VG_REGPARM(1);
738 /* from jumps.c */
739 void CLG_(init_jcc_hash)(jcc_hash*);
740 void CLG_(copy_current_jcc_hash)(jcc_hash* dst);
741 void CLG_(set_current_jcc_hash)(jcc_hash*);
742 jCC* CLG_(get_jcc)(BBCC* from, UInt, BBCC* to);
744 /* from callstack.c */
745 void CLG_(init_call_stack)(call_stack*);
746 void CLG_(copy_current_call_stack)(call_stack* dst);
747 void CLG_(set_current_call_stack)(call_stack*);
748 call_entry* CLG_(get_call_entry)(Int n);
750 void CLG_(push_call_stack)(BBCC* from, UInt jmp, BBCC* to, Addr sp, Bool skip);
751 void CLG_(pop_call_stack)(void);
752 Int CLG_(unwind_call_stack)(Addr sp, Int);
754 /* from context.c */
755 void CLG_(init_fn_stack)(fn_stack*);
756 void CLG_(copy_current_fn_stack)(fn_stack*);
757 void CLG_(set_current_fn_stack)(fn_stack*);
759 void CLG_(init_cxt_table)(void);
760 Context* CLG_(get_cxt)(fn_node** fn);
761 void CLG_(push_cxt)(fn_node* fn);
763 /* from threads.c */
764 void CLG_(init_threads)(void);
765 thread_info** CLG_(get_threads)(void);
766 thread_info* CLG_(get_current_thread)(void);
767 void CLG_(switch_thread)(ThreadId tid);
768 void CLG_(forall_threads)(void (*func)(thread_info*));
769 void CLG_(run_thread)(ThreadId tid);
771 void CLG_(init_exec_state)(exec_state* es);
772 void CLG_(init_exec_stack)(exec_stack*);
773 void CLG_(copy_current_exec_stack)(exec_stack*);
774 void CLG_(set_current_exec_stack)(exec_stack*);
775 void CLG_(pre_signal)(ThreadId tid, Int sigNum, Bool alt_stack);
776 void CLG_(post_signal)(ThreadId tid, Int sigNum);
777 void CLG_(run_post_signal_on_call_stack_bottom)(void);
779 /* from dump.c */
780 void CLG_(init_dumps)(void);
782 /*------------------------------------------------------------*/
783 /*--- Exported global variables ---*/
784 /*------------------------------------------------------------*/
786 extern CommandLineOptions CLG_(clo);
787 extern Statistics CLG_(stat);
788 extern EventMapping* CLG_(dumpmap);
790 /* Function active counter array, indexed by function number */
791 extern UInt* CLG_(fn_active_array);
792 extern Bool CLG_(instrument_state);
793 /* min of L1 and LL cache line sizes */
794 extern Int CLG_(min_line_size);
795 extern call_stack CLG_(current_call_stack);
796 extern fn_stack CLG_(current_fn_stack);
797 extern exec_state CLG_(current_state);
798 extern ThreadId CLG_(current_tid);
799 extern FullCost CLG_(total_cost);
800 extern struct cachesim_if CLG_(cachesim);
801 extern struct event_sets CLG_(sets);
803 // set by setup_bbcc at start of every BB, and needed by log_* helpers
804 extern Addr CLG_(bb_base);
805 extern ULong* CLG_(cost_base);
808 /*------------------------------------------------------------*/
809 /*--- Debug output ---*/
810 /*------------------------------------------------------------*/
812 #if CLG_ENABLE_DEBUG
814 #define CLG_DEBUGIF(x) \
815 if (UNLIKELY( (CLG_(clo).verbose >x) && \
816 (CLG_(stat).bb_executions >= CLG_(clo).verbose_start)))
818 #define CLG_DEBUG(x,format,args...) \
819 CLG_DEBUGIF(x) { \
820 CLG_(print_bbno)(); \
821 VG_(printf)(format,##args); \
824 #define CLG_ASSERT(cond) \
825 if (UNLIKELY(!(cond))) { \
826 CLG_(print_context)(); \
827 CLG_(print_bbno)(); \
828 tl_assert(cond); \
831 #else
832 #define CLG_DEBUGIF(x) if (0)
833 #define CLG_DEBUG(x...) {}
834 #define CLG_ASSERT(cond) tl_assert(cond);
835 #endif
837 /* from debug.c */
838 void CLG_(print_bbno)(void);
839 void CLG_(print_context)(void);
840 void CLG_(print_jcc)(int s, jCC* jcc);
841 void CLG_(print_bbcc)(int s, BBCC* bbcc);
842 void CLG_(print_bbcc_fn)(BBCC* bbcc);
843 void CLG_(print_execstate)(int s, exec_state* es);
844 void CLG_(print_eventset)(int s, EventSet* es);
845 void CLG_(print_cost)(int s, EventSet*, ULong* cost);
846 void CLG_(print_bb)(int s, BB* bb);
847 void CLG_(print_bbcc_cost)(int s, BBCC*);
848 void CLG_(print_cxt)(int s, Context* cxt, int rec_index);
849 void CLG_(print_short_jcc)(jCC* jcc);
850 void CLG_(print_stackentry)(int s, int sp);
851 void CLG_(print_addr)(Addr addr);
852 void CLG_(print_addr_ln)(Addr addr);
854 void* CLG_(malloc)(const HChar* cc, UWord s, const HChar* f);
855 void* CLG_(free)(void* p, const HChar* f);
856 #if 0
857 #define CLG_MALLOC(_cc,x) CLG_(malloc)((_cc),x,__FUNCTION__)
858 #define CLG_FREE(p) CLG_(free)(p,__FUNCTION__)
859 #else
860 #define CLG_MALLOC(_cc,x) VG_(malloc)((_cc),x)
861 #define CLG_FREE(p) VG_(free)(p)
862 #endif
864 #endif /* CLG_GLOBAL */