sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- C startup stuff, reached from vg_startup.S. ---*/ |
| 4 | /*--- vg_main.c ---*/ |
| 5 | /*--------------------------------------------------------------------*/ |
| 6 | |
| 7 | /* |
njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame] | 8 | This file is part of Valgrind, an extensible x86 protected-mode |
| 9 | emulator for monitoring program execution on x86-Unixes. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 10 | |
| 11 | Copyright (C) 2000-2002 Julian Seward |
| 12 | jseward@acm.org |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 13 | |
| 14 | This program is free software; you can redistribute it and/or |
| 15 | modify it under the terms of the GNU General Public License as |
| 16 | published by the Free Software Foundation; either version 2 of the |
| 17 | License, or (at your option) any later version. |
| 18 | |
| 19 | This program is distributed in the hope that it will be useful, but |
| 20 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 | General Public License for more details. |
| 23 | |
| 24 | You should have received a copy of the GNU General Public License |
| 25 | along with this program; if not, write to the Free Software |
| 26 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 27 | 02111-1307, USA. |
| 28 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 29 | The GNU General Public License is contained in the file COPYING. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 30 | */ |
| 31 | |
| 32 | #include "vg_include.h" |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 33 | |
| 34 | /* --------------------------------------------------------------------- |
| 35 | Compute offsets into baseBlock. See comments in vg_include.h. |
| 36 | ------------------------------------------------------------------ */ |
| 37 | |
| 38 | /* The variables storing offsets. */ |
| 39 | |
| 40 | #define INVALID_OFFSET (-1) |
| 41 | |
| 42 | Int VGOFF_(m_eax) = INVALID_OFFSET; |
| 43 | Int VGOFF_(m_ecx) = INVALID_OFFSET; |
| 44 | Int VGOFF_(m_edx) = INVALID_OFFSET; |
| 45 | Int VGOFF_(m_ebx) = INVALID_OFFSET; |
| 46 | Int VGOFF_(m_esp) = INVALID_OFFSET; |
| 47 | Int VGOFF_(m_ebp) = INVALID_OFFSET; |
| 48 | Int VGOFF_(m_esi) = INVALID_OFFSET; |
| 49 | Int VGOFF_(m_edi) = INVALID_OFFSET; |
| 50 | Int VGOFF_(m_eflags) = INVALID_OFFSET; |
sewardj | fa492d4 | 2002-12-08 18:20:01 +0000 | [diff] [blame] | 51 | Int VGOFF_(m_dflag) = INVALID_OFFSET; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 52 | Int VGOFF_(m_fpustate) = INVALID_OFFSET; |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 53 | Int VGOFF_(ldt) = INVALID_OFFSET; |
| 54 | Int VGOFF_(m_cs) = INVALID_OFFSET; |
| 55 | Int VGOFF_(m_ss) = INVALID_OFFSET; |
| 56 | Int VGOFF_(m_ds) = INVALID_OFFSET; |
| 57 | Int VGOFF_(m_es) = INVALID_OFFSET; |
| 58 | Int VGOFF_(m_fs) = INVALID_OFFSET; |
| 59 | Int VGOFF_(m_gs) = INVALID_OFFSET; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 60 | Int VGOFF_(m_eip) = INVALID_OFFSET; |
| 61 | Int VGOFF_(spillslots) = INVALID_OFFSET; |
| 62 | Int VGOFF_(sh_eax) = INVALID_OFFSET; |
| 63 | Int VGOFF_(sh_ecx) = INVALID_OFFSET; |
| 64 | Int VGOFF_(sh_edx) = INVALID_OFFSET; |
| 65 | Int VGOFF_(sh_ebx) = INVALID_OFFSET; |
| 66 | Int VGOFF_(sh_esp) = INVALID_OFFSET; |
| 67 | Int VGOFF_(sh_ebp) = INVALID_OFFSET; |
| 68 | Int VGOFF_(sh_esi) = INVALID_OFFSET; |
| 69 | Int VGOFF_(sh_edi) = INVALID_OFFSET; |
| 70 | Int VGOFF_(sh_eflags) = INVALID_OFFSET; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 71 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 72 | Int VGOFF_(helper_idiv_64_32) = INVALID_OFFSET; |
| 73 | Int VGOFF_(helper_div_64_32) = INVALID_OFFSET; |
| 74 | Int VGOFF_(helper_idiv_32_16) = INVALID_OFFSET; |
| 75 | Int VGOFF_(helper_div_32_16) = INVALID_OFFSET; |
| 76 | Int VGOFF_(helper_idiv_16_8) = INVALID_OFFSET; |
| 77 | Int VGOFF_(helper_div_16_8) = INVALID_OFFSET; |
| 78 | Int VGOFF_(helper_imul_32_64) = INVALID_OFFSET; |
| 79 | Int VGOFF_(helper_mul_32_64) = INVALID_OFFSET; |
| 80 | Int VGOFF_(helper_imul_16_32) = INVALID_OFFSET; |
| 81 | Int VGOFF_(helper_mul_16_32) = INVALID_OFFSET; |
| 82 | Int VGOFF_(helper_imul_8_16) = INVALID_OFFSET; |
| 83 | Int VGOFF_(helper_mul_8_16) = INVALID_OFFSET; |
| 84 | Int VGOFF_(helper_CLD) = INVALID_OFFSET; |
| 85 | Int VGOFF_(helper_STD) = INVALID_OFFSET; |
| 86 | Int VGOFF_(helper_get_dirflag) = INVALID_OFFSET; |
sewardj | 7d78e78 | 2002-06-02 00:04:00 +0000 | [diff] [blame] | 87 | Int VGOFF_(helper_CLC) = INVALID_OFFSET; |
| 88 | Int VGOFF_(helper_STC) = INVALID_OFFSET; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 89 | Int VGOFF_(helper_shldl) = INVALID_OFFSET; |
| 90 | Int VGOFF_(helper_shldw) = INVALID_OFFSET; |
| 91 | Int VGOFF_(helper_shrdl) = INVALID_OFFSET; |
| 92 | Int VGOFF_(helper_shrdw) = INVALID_OFFSET; |
| 93 | Int VGOFF_(helper_RDTSC) = INVALID_OFFSET; |
| 94 | Int VGOFF_(helper_CPUID) = INVALID_OFFSET; |
| 95 | Int VGOFF_(helper_BSWAP) = INVALID_OFFSET; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 96 | Int VGOFF_(helper_bsf) = INVALID_OFFSET; |
| 97 | Int VGOFF_(helper_bsr) = INVALID_OFFSET; |
| 98 | Int VGOFF_(helper_fstsw_AX) = INVALID_OFFSET; |
| 99 | Int VGOFF_(helper_SAHF) = INVALID_OFFSET; |
sewardj | 4d0ab1f | 2002-03-24 10:00:09 +0000 | [diff] [blame] | 100 | Int VGOFF_(helper_DAS) = INVALID_OFFSET; |
sewardj | fe8a166 | 2002-03-24 11:54:07 +0000 | [diff] [blame] | 101 | Int VGOFF_(helper_DAA) = INVALID_OFFSET; |
sewardj | 5109643 | 2002-12-14 23:59:09 +0000 | [diff] [blame] | 102 | Int VGOFF_(helper_undefined_instruction) = INVALID_OFFSET; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 103 | |
| 104 | /* MAX_NONCOMPACT_HELPERS can be increased easily. If MAX_COMPACT_HELPERS is |
| 105 | * increased too much, they won't really be compact any more... */ |
| 106 | #define MAX_COMPACT_HELPERS 8 |
njn | fedb736 | 2003-02-24 10:21:45 +0000 | [diff] [blame] | 107 | #define MAX_NONCOMPACT_HELPERS 50 |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 108 | |
| 109 | UInt VG_(n_compact_helpers) = 0; |
| 110 | UInt VG_(n_noncompact_helpers) = 0; |
| 111 | |
| 112 | Addr VG_(compact_helper_addrs) [MAX_COMPACT_HELPERS]; |
| 113 | Int VG_(compact_helper_offsets)[MAX_COMPACT_HELPERS]; |
| 114 | Addr VG_(noncompact_helper_addrs) [MAX_NONCOMPACT_HELPERS]; |
| 115 | Int VG_(noncompact_helper_offsets)[MAX_NONCOMPACT_HELPERS]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 116 | |
| 117 | /* This is the actual defn of baseblock. */ |
| 118 | UInt VG_(baseBlock)[VG_BASEBLOCK_WORDS]; |
| 119 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 120 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 121 | /* Words. */ |
| 122 | static Int baB_off = 0; |
| 123 | |
| 124 | /* Returns the offset, in words. */ |
| 125 | static Int alloc_BaB ( Int words ) |
| 126 | { |
| 127 | Int off = baB_off; |
| 128 | baB_off += words; |
| 129 | if (baB_off >= VG_BASEBLOCK_WORDS) |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 130 | VG_(core_panic)( "alloc_BaB: baseBlock is too small"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 131 | |
| 132 | return off; |
| 133 | } |
| 134 | |
| 135 | /* Allocate 1 word in baseBlock and set it to the given value. */ |
| 136 | static Int alloc_BaB_1_set ( Addr a ) |
| 137 | { |
| 138 | Int off = alloc_BaB(1); |
| 139 | VG_(baseBlock)[off] = (UInt)a; |
| 140 | return off; |
| 141 | } |
| 142 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 143 | /* Registers a function in compact_helper_addrs; compact_helper_offsets is |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 144 | filled in later. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 145 | void VG_(register_compact_helper)(Addr a) |
| 146 | { |
| 147 | if (MAX_COMPACT_HELPERS <= VG_(n_compact_helpers)) { |
| 148 | VG_(printf)("Can only register %d compact helpers\n", |
| 149 | MAX_COMPACT_HELPERS); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 150 | VG_(core_panic)("Too many compact helpers registered"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 151 | } |
| 152 | VG_(compact_helper_addrs)[VG_(n_compact_helpers)] = a; |
| 153 | VG_(n_compact_helpers)++; |
| 154 | } |
| 155 | |
| 156 | /* Registers a function in noncompact_helper_addrs; noncompact_helper_offsets |
| 157 | * is filled in later. |
| 158 | */ |
| 159 | void VG_(register_noncompact_helper)(Addr a) |
| 160 | { |
| 161 | if (MAX_NONCOMPACT_HELPERS <= VG_(n_noncompact_helpers)) { |
| 162 | VG_(printf)("Can only register %d non-compact helpers\n", |
| 163 | MAX_NONCOMPACT_HELPERS); |
| 164 | VG_(printf)("Try increasing MAX_NON_COMPACT_HELPERS\n"); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 165 | VG_(core_panic)("Too many non-compact helpers registered"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 166 | } |
| 167 | VG_(noncompact_helper_addrs)[VG_(n_noncompact_helpers)] = a; |
| 168 | VG_(n_noncompact_helpers)++; |
| 169 | } |
| 170 | |
| 171 | /* Allocate offsets in baseBlock for the skin helpers */ |
| 172 | static void assign_helpers_in_baseBlock(UInt n, Int offsets[], Addr addrs[]) |
| 173 | { |
| 174 | Int i; |
| 175 | for (i = 0; i < n; i++) offsets[i] = alloc_BaB_1_set( addrs[i] ); |
| 176 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 177 | |
njn | f4ce3d3 | 2003-02-10 10:17:26 +0000 | [diff] [blame] | 178 | Bool VG_(need_to_handle_esp_assignment)(void) |
| 179 | { |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 180 | return ( VG_(track_events).new_mem_stack_4 || |
| 181 | VG_(track_events).die_mem_stack_4 || |
| 182 | VG_(track_events).new_mem_stack_8 || |
| 183 | VG_(track_events).die_mem_stack_8 || |
| 184 | VG_(track_events).new_mem_stack_12 || |
| 185 | VG_(track_events).die_mem_stack_12 || |
| 186 | VG_(track_events).new_mem_stack_16 || |
| 187 | VG_(track_events).die_mem_stack_16 || |
| 188 | VG_(track_events).new_mem_stack_32 || |
| 189 | VG_(track_events).die_mem_stack_32 || |
| 190 | VG_(track_events).new_mem_stack || |
| 191 | VG_(track_events).die_mem_stack |
| 192 | ); |
njn | f4ce3d3 | 2003-02-10 10:17:26 +0000 | [diff] [blame] | 193 | } |
| 194 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 195 | /* Here we assign actual offsets. It's important to get the most |
| 196 | popular referents within 128 bytes of the start, so we can take |
| 197 | advantage of short addressing modes relative to %ebp. Popularity |
| 198 | of offsets was measured on 22 Feb 02 running a KDE application, and |
| 199 | the slots rearranged accordingly, with a 1.5% reduction in total |
| 200 | size of translations. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 201 | static void vg_init_baseBlock ( void ) |
| 202 | { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 203 | /* Those with offsets under 128 are carefully chosen. */ |
| 204 | |
| 205 | /* WORD offsets in this column */ |
| 206 | /* 0 */ VGOFF_(m_eax) = alloc_BaB(1); |
| 207 | /* 1 */ VGOFF_(m_ecx) = alloc_BaB(1); |
| 208 | /* 2 */ VGOFF_(m_edx) = alloc_BaB(1); |
| 209 | /* 3 */ VGOFF_(m_ebx) = alloc_BaB(1); |
| 210 | /* 4 */ VGOFF_(m_esp) = alloc_BaB(1); |
| 211 | /* 5 */ VGOFF_(m_ebp) = alloc_BaB(1); |
| 212 | /* 6 */ VGOFF_(m_esi) = alloc_BaB(1); |
| 213 | /* 7 */ VGOFF_(m_edi) = alloc_BaB(1); |
| 214 | /* 8 */ VGOFF_(m_eflags) = alloc_BaB(1); |
| 215 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 216 | if (VG_(needs).shadow_regs) { |
| 217 | /* 9 */ VGOFF_(sh_eax) = alloc_BaB(1); |
| 218 | /* 10 */ VGOFF_(sh_ecx) = alloc_BaB(1); |
| 219 | /* 11 */ VGOFF_(sh_edx) = alloc_BaB(1); |
| 220 | /* 12 */ VGOFF_(sh_ebx) = alloc_BaB(1); |
| 221 | /* 13 */ VGOFF_(sh_esp) = alloc_BaB(1); |
| 222 | /* 14 */ VGOFF_(sh_ebp) = alloc_BaB(1); |
| 223 | /* 15 */ VGOFF_(sh_esi) = alloc_BaB(1); |
| 224 | /* 16 */ VGOFF_(sh_edi) = alloc_BaB(1); |
| 225 | /* 17 */ VGOFF_(sh_eflags) = alloc_BaB(1); |
| 226 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 227 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 228 | /* 9,10,11 or 18,19,20... depends on number whether shadow regs are used |
| 229 | * and on compact helpers registered */ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 230 | |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 231 | /* Make these most-frequently-called specialised ones compact, if they |
| 232 | are used. */ |
| 233 | if (VG_(track_events).new_mem_stack_4) |
| 234 | VG_(register_compact_helper)( (Addr) VG_(track_events).new_mem_stack_4); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 235 | |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 236 | if (VG_(track_events).die_mem_stack_4) |
| 237 | VG_(register_compact_helper)( (Addr) VG_(track_events).die_mem_stack_4); |
| 238 | |
| 239 | /* (9 or 18) + n_compact_helpers */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 240 | /* Allocate slots for compact helpers */ |
| 241 | assign_helpers_in_baseBlock(VG_(n_compact_helpers), |
| 242 | VG_(compact_helper_offsets), |
| 243 | VG_(compact_helper_addrs)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 244 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 245 | /* (9/10 or 18/19) + n_compact_helpers */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 246 | VGOFF_(m_eip) = alloc_BaB(1); |
| 247 | |
| 248 | /* There are currently 24 spill slots */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 249 | /* (11+/20+ .. 32+/43+) + n_compact_helpers. This can overlap the magic |
| 250 | * boundary at >= 32 words, but most spills are to low numbered spill |
| 251 | * slots, so the ones above the boundary don't see much action. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 252 | VGOFF_(spillslots) = alloc_BaB(VG_MAX_SPILLSLOTS); |
| 253 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 254 | /* I gave up counting at this point. Since they're above the |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 255 | short-amode-boundary, there's no point. */ |
| 256 | |
sewardj | fa492d4 | 2002-12-08 18:20:01 +0000 | [diff] [blame] | 257 | VGOFF_(m_dflag) = alloc_BaB(1); |
| 258 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 259 | VGOFF_(m_fpustate) = alloc_BaB(VG_SIZE_OF_FPUSTATE_W); |
| 260 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 261 | /* This thread's LDT pointer, and segment registers. */ |
| 262 | VGOFF_(ldt) = alloc_BaB(1); |
| 263 | VGOFF_(m_cs) = alloc_BaB(1); |
| 264 | VGOFF_(m_ss) = alloc_BaB(1); |
| 265 | VGOFF_(m_ds) = alloc_BaB(1); |
| 266 | VGOFF_(m_es) = alloc_BaB(1); |
| 267 | VGOFF_(m_fs) = alloc_BaB(1); |
| 268 | VGOFF_(m_gs) = alloc_BaB(1); |
| 269 | |
sewardj | e104247 | 2002-09-30 12:33:11 +0000 | [diff] [blame] | 270 | VG_(register_noncompact_helper)( (Addr) & VG_(do_useseg) ); |
| 271 | |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 272 | #define REG(kind, size) \ |
| 273 | if (VG_(track_events).kind##_mem_stack##size) \ |
| 274 | VG_(register_noncompact_helper)( \ |
| 275 | (Addr) VG_(track_events).kind##_mem_stack##size ); |
| 276 | |
| 277 | REG(new, _8); |
| 278 | REG(new, _12); |
| 279 | REG(new, _16); |
| 280 | REG(new, _32); |
| 281 | REG(new, ); |
| 282 | REG(die, _8); |
| 283 | REG(die, _12); |
| 284 | REG(die, _16); |
| 285 | REG(die, _32); |
| 286 | REG(die, ); |
| 287 | #undef REG |
| 288 | |
| 289 | if (VG_(need_to_handle_esp_assignment)()) |
| 290 | VG_(register_noncompact_helper)((Addr) VG_(unknown_esp_update)); |
| 291 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 292 | /* Helper functions. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 293 | VGOFF_(helper_idiv_64_32) |
| 294 | = alloc_BaB_1_set( (Addr) & VG_(helper_idiv_64_32) ); |
| 295 | VGOFF_(helper_div_64_32) |
| 296 | = alloc_BaB_1_set( (Addr) & VG_(helper_div_64_32) ); |
| 297 | VGOFF_(helper_idiv_32_16) |
| 298 | = alloc_BaB_1_set( (Addr) & VG_(helper_idiv_32_16) ); |
| 299 | VGOFF_(helper_div_32_16) |
| 300 | = alloc_BaB_1_set( (Addr) & VG_(helper_div_32_16) ); |
| 301 | VGOFF_(helper_idiv_16_8) |
| 302 | = alloc_BaB_1_set( (Addr) & VG_(helper_idiv_16_8) ); |
| 303 | VGOFF_(helper_div_16_8) |
| 304 | = alloc_BaB_1_set( (Addr) & VG_(helper_div_16_8) ); |
| 305 | |
| 306 | VGOFF_(helper_imul_32_64) |
| 307 | = alloc_BaB_1_set( (Addr) & VG_(helper_imul_32_64) ); |
| 308 | VGOFF_(helper_mul_32_64) |
| 309 | = alloc_BaB_1_set( (Addr) & VG_(helper_mul_32_64) ); |
| 310 | VGOFF_(helper_imul_16_32) |
| 311 | = alloc_BaB_1_set( (Addr) & VG_(helper_imul_16_32) ); |
| 312 | VGOFF_(helper_mul_16_32) |
| 313 | = alloc_BaB_1_set( (Addr) & VG_(helper_mul_16_32) ); |
| 314 | VGOFF_(helper_imul_8_16) |
| 315 | = alloc_BaB_1_set( (Addr) & VG_(helper_imul_8_16) ); |
| 316 | VGOFF_(helper_mul_8_16) |
| 317 | = alloc_BaB_1_set( (Addr) & VG_(helper_mul_8_16) ); |
| 318 | |
| 319 | VGOFF_(helper_CLD) |
| 320 | = alloc_BaB_1_set( (Addr) & VG_(helper_CLD) ); |
| 321 | VGOFF_(helper_STD) |
| 322 | = alloc_BaB_1_set( (Addr) & VG_(helper_STD) ); |
| 323 | VGOFF_(helper_get_dirflag) |
| 324 | = alloc_BaB_1_set( (Addr) & VG_(helper_get_dirflag) ); |
| 325 | |
sewardj | 7d78e78 | 2002-06-02 00:04:00 +0000 | [diff] [blame] | 326 | VGOFF_(helper_CLC) |
| 327 | = alloc_BaB_1_set( (Addr) & VG_(helper_CLC) ); |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 328 | VGOFF_(helper_STC) |
sewardj | 7d78e78 | 2002-06-02 00:04:00 +0000 | [diff] [blame] | 329 | = alloc_BaB_1_set( (Addr) & VG_(helper_STC) ); |
| 330 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 331 | VGOFF_(helper_shldl) |
| 332 | = alloc_BaB_1_set( (Addr) & VG_(helper_shldl) ); |
| 333 | VGOFF_(helper_shldw) |
| 334 | = alloc_BaB_1_set( (Addr) & VG_(helper_shldw) ); |
| 335 | VGOFF_(helper_shrdl) |
| 336 | = alloc_BaB_1_set( (Addr) & VG_(helper_shrdl) ); |
| 337 | VGOFF_(helper_shrdw) |
| 338 | = alloc_BaB_1_set( (Addr) & VG_(helper_shrdw) ); |
| 339 | |
| 340 | VGOFF_(helper_RDTSC) |
| 341 | = alloc_BaB_1_set( (Addr) & VG_(helper_RDTSC) ); |
| 342 | VGOFF_(helper_CPUID) |
| 343 | = alloc_BaB_1_set( (Addr) & VG_(helper_CPUID) ); |
| 344 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 345 | VGOFF_(helper_bsf) |
| 346 | = alloc_BaB_1_set( (Addr) & VG_(helper_bsf) ); |
| 347 | VGOFF_(helper_bsr) |
| 348 | = alloc_BaB_1_set( (Addr) & VG_(helper_bsr) ); |
| 349 | |
| 350 | VGOFF_(helper_fstsw_AX) |
| 351 | = alloc_BaB_1_set( (Addr) & VG_(helper_fstsw_AX) ); |
| 352 | VGOFF_(helper_SAHF) |
| 353 | = alloc_BaB_1_set( (Addr) & VG_(helper_SAHF) ); |
sewardj | 4d0ab1f | 2002-03-24 10:00:09 +0000 | [diff] [blame] | 354 | VGOFF_(helper_DAS) |
| 355 | = alloc_BaB_1_set( (Addr) & VG_(helper_DAS) ); |
sewardj | fe8a166 | 2002-03-24 11:54:07 +0000 | [diff] [blame] | 356 | VGOFF_(helper_DAA) |
| 357 | = alloc_BaB_1_set( (Addr) & VG_(helper_DAA) ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 358 | |
sewardj | 5109643 | 2002-12-14 23:59:09 +0000 | [diff] [blame] | 359 | VGOFF_(helper_undefined_instruction) |
| 360 | = alloc_BaB_1_set( (Addr) & VG_(helper_undefined_instruction) ); |
| 361 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 362 | /* Allocate slots for noncompact helpers */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 363 | assign_helpers_in_baseBlock(VG_(n_noncompact_helpers), |
| 364 | VG_(noncompact_helper_offsets), |
| 365 | VG_(noncompact_helper_addrs)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 366 | |
njn | cc7bb47 | 2002-10-14 09:25:19 +0000 | [diff] [blame] | 367 | |
| 368 | /* Initialise slots that require it */ |
| 369 | VG_(copy_m_state_static_to_baseBlock)(); |
| 370 | |
| 371 | /* Pretend the root thread has a completely empty LDT to start with. */ |
| 372 | VG_(baseBlock)[VGOFF_(ldt)] = (UInt)NULL; |
| 373 | |
| 374 | /* Initialise shadow regs */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 375 | if (VG_(needs).shadow_regs) { |
| 376 | UInt eflags; |
| 377 | |
| 378 | SK_(written_shadow_regs_values) ( & VG_(written_shadow_reg), & eflags ); |
| 379 | VG_(baseBlock)[VGOFF_(sh_esp)] = |
| 380 | VG_(baseBlock)[VGOFF_(sh_ebp)] = |
| 381 | VG_(baseBlock)[VGOFF_(sh_eax)] = |
| 382 | VG_(baseBlock)[VGOFF_(sh_ecx)] = |
| 383 | VG_(baseBlock)[VGOFF_(sh_edx)] = |
| 384 | VG_(baseBlock)[VGOFF_(sh_ebx)] = |
| 385 | VG_(baseBlock)[VGOFF_(sh_esi)] = |
| 386 | VG_(baseBlock)[VGOFF_(sh_edi)] = VG_(written_shadow_reg); |
| 387 | VG_(baseBlock)[VGOFF_(sh_eflags)] = eflags; |
| 388 | |
njn | cc7bb47 | 2002-10-14 09:25:19 +0000 | [diff] [blame] | 389 | } else { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 390 | VG_(written_shadow_reg) = VG_UNUSED_SHADOW_REG_VALUE; |
njn | cc7bb47 | 2002-10-14 09:25:19 +0000 | [diff] [blame] | 391 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | |
| 395 | /* --------------------------------------------------------------------- |
| 396 | Global entities which are not referenced from generated code. |
| 397 | ------------------------------------------------------------------ */ |
| 398 | |
| 399 | /* The stack on which Valgrind runs. We can't use the same stack as |
| 400 | the simulatee -- that's an important design decision. */ |
| 401 | UInt VG_(stack)[10000]; |
| 402 | |
| 403 | /* Ditto our signal delivery stack. */ |
| 404 | UInt VG_(sigstack)[10000]; |
| 405 | |
| 406 | /* Saving stuff across system calls. */ |
sewardj | 43c356f | 2002-06-02 00:21:08 +0000 | [diff] [blame] | 407 | UInt VG_(real_fpu_state_saved_over_syscall)[VG_SIZE_OF_FPUSTATE_W]; |
| 408 | Addr VG_(esp_saved_over_syscall); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 409 | |
| 410 | /* Counts downwards in vg_run_innerloop. */ |
| 411 | UInt VG_(dispatch_ctr); |
| 412 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 413 | |
| 414 | /* 64-bit counter for the number of basic blocks done. */ |
| 415 | ULong VG_(bbs_done); |
| 416 | /* 64-bit counter for the number of bbs to go before a debug exit. */ |
| 417 | ULong VG_(bbs_to_go); |
| 418 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 419 | /* This is the ThreadId of the last thread the scheduler ran. */ |
| 420 | ThreadId VG_(last_run_tid) = 0; |
| 421 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 422 | /* This is the argument to __NR_exit() supplied by the first thread to |
| 423 | call that syscall. We eventually pass that to __NR_exit() for |
| 424 | real. */ |
| 425 | UInt VG_(exitcode) = 0; |
| 426 | |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 427 | /* Tell the logging mechanism whether we are logging to a file |
| 428 | descriptor or a socket descriptor. */ |
| 429 | Bool VG_(logging_to_filedes) = True; |
| 430 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 431 | |
| 432 | /* --------------------------------------------------------------------- |
| 433 | Counters, for informational purposes only. |
| 434 | ------------------------------------------------------------------ */ |
| 435 | |
| 436 | /* Number of lookups which miss the fast tt helper. */ |
| 437 | UInt VG_(tt_fast_misses) = 0; |
| 438 | |
| 439 | |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 440 | /* Counts for TT/TC informational messages. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 441 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 442 | /* Number and total o/t size of translations overall. */ |
| 443 | UInt VG_(overall_in_count) = 0; |
| 444 | UInt VG_(overall_in_osize) = 0; |
| 445 | UInt VG_(overall_in_tsize) = 0; |
| 446 | /* Number and total o/t size of discards overall. */ |
| 447 | UInt VG_(overall_out_count) = 0; |
| 448 | UInt VG_(overall_out_osize) = 0; |
| 449 | UInt VG_(overall_out_tsize) = 0; |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 450 | /* The number of discards of TT/TC. */ |
| 451 | UInt VG_(number_of_tc_discards) = 0; |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 452 | /* Counts of chain and unchain operations done. */ |
| 453 | UInt VG_(bb_enchain_count) = 0; |
| 454 | UInt VG_(bb_dechain_count) = 0; |
| 455 | /* Number of unchained jumps performed. */ |
| 456 | UInt VG_(unchained_jumps_done) = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 457 | |
| 458 | |
| 459 | /* Counts pertaining to the register allocator. */ |
| 460 | |
| 461 | /* total number of uinstrs input to reg-alloc */ |
| 462 | UInt VG_(uinstrs_prealloc) = 0; |
| 463 | |
| 464 | /* total number of uinstrs added due to spill code */ |
| 465 | UInt VG_(uinstrs_spill) = 0; |
| 466 | |
| 467 | /* number of bbs requiring spill code */ |
| 468 | UInt VG_(translations_needing_spill) = 0; |
| 469 | |
| 470 | /* total of register ranks over all translations */ |
| 471 | UInt VG_(total_reg_rank) = 0; |
| 472 | |
| 473 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 474 | /* Counts pertaining to internal sanity checking. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 475 | UInt VG_(sanity_fast_count) = 0; |
| 476 | UInt VG_(sanity_slow_count) = 0; |
| 477 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 478 | /* Counts pertaining to the scheduler. */ |
| 479 | UInt VG_(num_scheduling_events_MINOR) = 0; |
| 480 | UInt VG_(num_scheduling_events_MAJOR) = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 481 | |
| 482 | |
| 483 | /* --------------------------------------------------------------------- |
| 484 | Values derived from command-line options. |
| 485 | ------------------------------------------------------------------ */ |
| 486 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 487 | /* Define, and set defaults. */ |
| 488 | Bool VG_(clo_error_limit) = True; |
| 489 | Bool VG_(clo_GDB_attach) = False; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 490 | Bool VG_(clo_gen_suppressions) = False; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 491 | Int VG_(sanity_level) = 1; |
| 492 | Int VG_(clo_verbosity) = 1; |
| 493 | Bool VG_(clo_demangle) = True; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 494 | Bool VG_(clo_trace_children) = False; |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 495 | |
| 496 | /* See big comment in vg_include.h for meaning of these three. */ |
| 497 | VgLogTo VG_(clo_log_to) = VgLogTo_Fd; |
| 498 | Int VG_(clo_logfile_fd) = 2; |
| 499 | Char* VG_(clo_logfile_name) = NULL; |
| 500 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 501 | Int VG_(clo_n_suppressions) = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 502 | Char* VG_(clo_suppressions)[VG_CLO_MAX_SFILES]; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 503 | Bool VG_(clo_profile) = False; |
| 504 | Bool VG_(clo_single_step) = False; |
| 505 | Bool VG_(clo_optimise) = True; |
| 506 | UChar VG_(clo_trace_codegen) = 0; // 00000000b |
| 507 | Bool VG_(clo_trace_syscalls) = False; |
| 508 | Bool VG_(clo_trace_signals) = False; |
| 509 | Bool VG_(clo_trace_symtab) = False; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 510 | Bool VG_(clo_trace_sched) = False; |
| 511 | Int VG_(clo_trace_pthread_level) = 0; |
sewardj | 59438c0 | 2003-01-05 12:16:30 +0000 | [diff] [blame] | 512 | ULong VG_(clo_stop_after) = 1000000000000000LL; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 513 | Int VG_(clo_dump_error) = 0; |
| 514 | Int VG_(clo_backtrace_size) = 4; |
| 515 | Char* VG_(clo_weird_hacks) = NULL; |
sewardj | 858964b | 2002-10-05 14:15:43 +0000 | [diff] [blame] | 516 | Bool VG_(clo_run_libc_freeres) = True; |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 517 | Bool VG_(clo_chain_bb) = True; |
sewardj | 2370f3b | 2002-11-30 15:01:01 +0000 | [diff] [blame] | 518 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 519 | |
| 520 | /* This Bool is needed by wrappers in vg_clientmalloc.c to decide how |
| 521 | to behave. Initially we say False. */ |
| 522 | Bool VG_(running_on_simd_CPU) = False; |
| 523 | |
| 524 | /* Holds client's %esp at the point we gained control. */ |
| 525 | Addr VG_(esp_at_startup); |
| 526 | |
sewardj | d5815ec | 2003-04-06 12:23:27 +0000 | [diff] [blame] | 527 | /* Indicates presence, and holds address of client's sysinfo page, a |
| 528 | feature of some modern kernels used to provide vsyscalls, etc. */ |
| 529 | Bool VG_(sysinfo_page_exists) = False; |
| 530 | Addr VG_(sysinfo_page_addr) = 0; |
| 531 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 532 | /* As deduced from VG_(esp_at_startup), the client's argc, argv[] and |
| 533 | envp[] as extracted from the client's stack at startup-time. */ |
| 534 | Int VG_(client_argc); |
| 535 | Char** VG_(client_argv); |
| 536 | Char** VG_(client_envp); |
| 537 | |
| 538 | /* A place into which to copy the value of env var VG_ARGS, so we |
| 539 | don't have to modify the original. */ |
| 540 | static Char vg_cmdline_copy[M_VG_CMDLINE_STRLEN]; |
| 541 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 542 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 543 | Processing of command-line options. |
| 544 | ------------------------------------------------------------------ */ |
| 545 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 546 | void VG_(bad_option) ( Char* opt ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 547 | { |
| 548 | VG_(shutdown_logging)(); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 549 | VG_(clo_log_to) = VgLogTo_Fd; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 550 | VG_(clo_logfile_fd) = 2; /* stderr */ |
| 551 | VG_(printf)("valgrind.so: Bad option `%s'; aborting.\n", opt); |
| 552 | VG_(exit)(1); |
| 553 | } |
| 554 | |
| 555 | static void config_error ( Char* msg ) |
| 556 | { |
| 557 | VG_(shutdown_logging)(); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 558 | VG_(clo_log_to) = VgLogTo_Fd; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 559 | VG_(clo_logfile_fd) = 2; /* stderr */ |
sewardj | 19d8141 | 2002-06-03 01:10:40 +0000 | [diff] [blame] | 560 | VG_(printf)( |
| 561 | "valgrind.so: Startup or configuration error:\n %s\n", msg); |
| 562 | VG_(printf)( |
| 563 | "valgrind.so: Unable to start up properly. Giving up.\n"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 564 | VG_(exit)(1); |
| 565 | } |
| 566 | |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 567 | static void args_grok_error ( Char* msg ) |
| 568 | { |
| 569 | VG_(shutdown_logging)(); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 570 | VG_(clo_log_to) = VgLogTo_Fd; |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 571 | VG_(clo_logfile_fd) = 2; /* stderr */ |
| 572 | VG_(printf)("valgrind.so: When searching for " |
| 573 | "client's argc/argc/envp:\n\t%s\n", msg); |
| 574 | config_error("couldn't find client's argc/argc/envp"); |
| 575 | } |
| 576 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 577 | static void usage ( void ) |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 578 | { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 579 | Char* usage1 = |
| 580 | "usage: valgrind [options] prog-and-args\n" |
| 581 | "\n" |
| 582 | " core user options, with defaults in [ ], are:\n" |
| 583 | " --help show this message\n" |
| 584 | " --version show version\n" |
| 585 | " --skin=<name> main task (skin to use) [Valgrind]\n" |
| 586 | " -q --quiet run silently; only print error msgs\n" |
| 587 | " -v --verbose be more verbose, incl counts of errors\n" |
| 588 | " --gdb-attach=no|yes start GDB when errors detected? [no]\n" |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 589 | " --gen-suppressions=no|yes print suppressions for errors detected [no]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 590 | " --demangle=no|yes automatically demangle C++ names? [yes]\n" |
| 591 | " --num-callers=<number> show <num> callers in stack traces [4]\n" |
| 592 | " --error-limit=no|yes stop showing new errors if too many? [yes]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 593 | " --trace-children=no|yes Valgrind-ise child processes? [no]\n" |
sewardj | 858964b | 2002-10-05 14:15:43 +0000 | [diff] [blame] | 594 | " --run-libc-freeres=no|yes Free up glibc memory at exit? [yes]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 595 | " --logfile-fd=<number> file descriptor for messages [2=stderr]\n" |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 596 | " --logfile=<file> log messages to <file>.pid<pid>\n" |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 597 | " --logsocket=ipaddr:port log messages to socket ipaddr:port\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 598 | " --suppressions=<filename> suppress errors described in\n" |
| 599 | " suppressions file <filename>\n" |
| 600 | " --weird-hacks=hack1,hack2,... [no hacks selected]\n" |
sewardj | 3d652a3 | 2002-10-20 18:11:49 +0000 | [diff] [blame] | 601 | " recognised hacks are: ioctl-VTIME truncate-writes lax-ioctls\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 602 | "\n" |
| 603 | " %s skin user options:\n"; |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 604 | |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 605 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 606 | Char* usage2 = |
| 607 | "\n" |
| 608 | " core options for debugging Valgrind itself are:\n" |
| 609 | " --sanity-level=<number> level of sanity checking to do [1]\n" |
| 610 | " --single-step=no|yes translate each instr separately? [no]\n" |
| 611 | " --optimise=no|yes improve intermediate code? [yes]\n" |
| 612 | " --profile=no|yes profile? (skin must be built for it) [no]\n" |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 613 | " --chain-bb=no|yes do basic-block chaining? [yes]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 614 | " --trace-codegen=<XXXXX> show generated code? (X = 0|1) [00000]\n" |
| 615 | " --trace-syscalls=no|yes show all system calls? [no]\n" |
| 616 | " --trace-signals=no|yes show signal handling details? [no]\n" |
| 617 | " --trace-symtab=no|yes show symbol table details? [no]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 618 | " --trace-sched=no|yes show thread scheduler details? [no]\n" |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame^] | 619 | " --trace-pthread=none|some|all show pthread event details? [none]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 620 | " --stop-after=<number> switch to real CPU after executing\n" |
| 621 | " <number> basic blocks [infinity]\n" |
| 622 | " --dump-error=<number> show translation for basic block\n" |
| 623 | " associated with <number>'th\n" |
| 624 | " error context [0=don't show any]\n" |
| 625 | "\n" |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame^] | 626 | " %s skin debugging options:\n"; |
| 627 | |
| 628 | Char* usage3 = |
| 629 | "\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 630 | " Extra options are read from env variable $VALGRIND_OPTS\n" |
| 631 | "\n" |
| 632 | " Valgrind is Copyright (C) 2000-2002 Julian Seward\n" |
| 633 | " and licensed under the GNU General Public License, version 2.\n" |
| 634 | " Bug reports, feedback, admiration, abuse, etc, to: %s.\n" |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 635 | "\n" |
| 636 | " Skins are copyright and licensed by their authors. See each\n" |
| 637 | " skin's start-up message for more information.\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 638 | "\n"; |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 639 | |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 640 | VG_(printf)(usage1, VG_(details).name); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 641 | /* Don't print skin string directly for security, ha! */ |
| 642 | if (VG_(needs).command_line_options) |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame^] | 643 | SK_(print_usage)(); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 644 | else |
| 645 | VG_(printf)(" (none)\n"); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame^] | 646 | VG_(printf)(usage2, VG_(details).name); |
| 647 | if (VG_(needs).command_line_options) |
| 648 | SK_(print_debug_usage)(); |
| 649 | else |
| 650 | VG_(printf)(" (none)\n"); |
| 651 | VG_(printf)(usage3, VG_EMAIL_ADDR); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 652 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 653 | VG_(shutdown_logging)(); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 654 | VG_(clo_log_to) = VgLogTo_Fd; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 655 | VG_(clo_logfile_fd) = 2; /* stderr */ |
| 656 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 657 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 658 | |
sewardj | 1c1b116 | 2003-02-23 01:25:51 +0000 | [diff] [blame] | 659 | |
| 660 | /* Callback for lookiing for the stackl segment. */ |
| 661 | static Addr vg_foundstack_start = (Addr)NULL; |
| 662 | static UInt vg_foundstack_size = 0; |
| 663 | |
| 664 | static void vg_findstack_callback ( Addr start, UInt size, |
sewardj | 53fe458 | 2003-02-23 01:41:17 +0000 | [diff] [blame] | 665 | Char r, Char w, Char x, |
| 666 | UInt foffset, UChar* filename ) |
sewardj | 1c1b116 | 2003-02-23 01:25:51 +0000 | [diff] [blame] | 667 | { |
| 668 | Addr lastword; |
| 669 | if (size == 0) return; |
sewardj | 04421d0 | 2003-02-23 03:54:59 +0000 | [diff] [blame] | 670 | if (r != 'r' || w != 'w' |
| 671 | /* || x != 'x' --not necessarily so on x86-64*/ |
| 672 | ) return; |
sewardj | 1c1b116 | 2003-02-23 01:25:51 +0000 | [diff] [blame] | 673 | lastword = start + size - 4; |
sewardj | 53fe458 | 2003-02-23 01:41:17 +0000 | [diff] [blame] | 674 | if (start <= VG_(esp_at_startup) |
| 675 | && VG_(esp_at_startup) <= lastword) { |
| 676 | vg_foundstack_start = start; |
| 677 | vg_foundstack_size = size; |
| 678 | vg_assert(vg_foundstack_size > 0); |
sewardj | 1c1b116 | 2003-02-23 01:25:51 +0000 | [diff] [blame] | 679 | } |
| 680 | } |
| 681 | |
| 682 | |
| 683 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 684 | static void process_cmd_line_options ( void ) |
| 685 | { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 686 | Char* argv[M_VG_CMDLINE_OPTS]; |
| 687 | UInt argc; |
| 688 | Char* p; |
| 689 | Char* str; |
| 690 | Int i, eventually_logfile_fd, ctr; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 691 | |
| 692 | # define ISSPACE(cc) ((cc) == ' ' || (cc) == '\t' || (cc) == '\n') |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 693 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 694 | eventually_logfile_fd = VG_(clo_logfile_fd); |
| 695 | |
| 696 | /* Once logging is started, we can safely send messages pertaining |
| 697 | to failures in initialisation. */ |
| 698 | VG_(startup_logging)(); |
| 699 | |
sewardj | 19d8141 | 2002-06-03 01:10:40 +0000 | [diff] [blame] | 700 | /* Check for sane path in ./configure --prefix=... */ |
| 701 | if (VG_(strlen)(VG_LIBDIR) < 1 |
| 702 | || VG_LIBDIR[0] != '/') |
| 703 | config_error("Please use absolute paths in " |
| 704 | "./configure --prefix=... or --libdir=..."); |
sewardj | 3817091 | 2002-05-10 21:07:22 +0000 | [diff] [blame] | 705 | |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 706 | /* (Suggested by Fabrice Bellard ... ) |
| 707 | We look for the Linux ELF table and go down until we find the |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 708 | envc & envp. It is not fool-proof, but these structures should |
sewardj | 3817091 | 2002-05-10 21:07:22 +0000 | [diff] [blame] | 709 | change less often than the libc ones. */ |
| 710 | { |
sewardj | 53fe458 | 2003-02-23 01:41:17 +0000 | [diff] [blame] | 711 | UInt* sp; |
sewardj | 1c1b116 | 2003-02-23 01:25:51 +0000 | [diff] [blame] | 712 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame^] | 713 | /* Look for the stack segment by parsing /proc/self/maps and |
sewardj | 53fe458 | 2003-02-23 01:41:17 +0000 | [diff] [blame] | 714 | looking for a section bracketing VG_(esp_at_startup) which |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame^] | 715 | has rwx permissions and no associated file. Note that this uses |
| 716 | the /proc/self/maps contents read at the start of VG_(main)(), |
| 717 | and doesn't re-read /proc/self/maps. */ |
sewardj | 1c1b116 | 2003-02-23 01:25:51 +0000 | [diff] [blame] | 718 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame^] | 719 | VG_(read_procselfmaps)( vg_findstack_callback, /*read_from_file*/False ); |
sewardj | 53fe458 | 2003-02-23 01:41:17 +0000 | [diff] [blame] | 720 | |
| 721 | /* Now vg_foundstack_start and vg_foundstack_size |
| 722 | should delimit the stack. */ |
| 723 | if (vg_foundstack_size == 0) { |
| 724 | args_grok_error("Cannot determine stack segment " |
| 725 | "from /proc/self/maps"); |
| 726 | } |
sewardj | 1c1b116 | 2003-02-23 01:25:51 +0000 | [diff] [blame] | 727 | |
| 728 | if (0) |
sewardj | 53fe458 | 2003-02-23 01:41:17 +0000 | [diff] [blame] | 729 | VG_(printf)("stack segment is %p .. %p\n", |
| 730 | vg_foundstack_start, |
| 731 | vg_foundstack_start + vg_foundstack_size - 4 ); |
sewardj | 1c1b116 | 2003-02-23 01:25:51 +0000 | [diff] [blame] | 732 | |
sewardj | 53fe458 | 2003-02-23 01:41:17 +0000 | [diff] [blame] | 733 | sp = (UInt*)(vg_foundstack_start + vg_foundstack_size); |
| 734 | if ((((UInt)(sp)) % VKI_BYTES_PER_PAGE) != 0) { |
| 735 | args_grok_error("Stack segment is not page aligned?!"); |
| 736 | } |
sewardj | 1c1b116 | 2003-02-23 01:25:51 +0000 | [diff] [blame] | 737 | |
sewardj | 53fe458 | 2003-02-23 01:41:17 +0000 | [diff] [blame] | 738 | /* we locate: NEW_AUX_ENT(1, AT_PAGESZ, ELF_EXEC_PAGESIZE) in |
| 739 | the elf interpreter table */ |
sewardj | 1c1b116 | 2003-02-23 01:25:51 +0000 | [diff] [blame] | 740 | |
sewardj | 3817091 | 2002-05-10 21:07:22 +0000 | [diff] [blame] | 741 | sp -= 2; |
sewardj | 3817091 | 2002-05-10 21:07:22 +0000 | [diff] [blame] | 742 | while (sp[0] != VKI_AT_PAGESZ || sp[1] != 4096) { |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 743 | /* VG_(printf)("trying %p\n", sp); */ |
sewardj | 3817091 | 2002-05-10 21:07:22 +0000 | [diff] [blame] | 744 | sp--; |
| 745 | } |
sewardj | 3817091 | 2002-05-10 21:07:22 +0000 | [diff] [blame] | 746 | |
| 747 | if (sp[2] == VKI_AT_BASE |
| 748 | && sp[0] == VKI_AT_PAGESZ |
| 749 | && sp[-2] == VKI_AT_PHNUM |
| 750 | && sp[-4] == VKI_AT_PHENT |
sewardj | d9c2d6d | 2002-05-18 11:55:05 +0000 | [diff] [blame] | 751 | && sp[-6] == VKI_AT_PHDR |
| 752 | && sp[-6-1] == 0) { |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 753 | if (0) |
| 754 | VG_(printf)("Looks like you've got a 2.2.X kernel here.\n"); |
sewardj | 3817091 | 2002-05-10 21:07:22 +0000 | [diff] [blame] | 755 | sp -= 6; |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 756 | } else |
| 757 | if (sp[2] == VKI_AT_CLKTCK |
| 758 | && sp[0] == VKI_AT_PAGESZ |
sewardj | d9c2d6d | 2002-05-18 11:55:05 +0000 | [diff] [blame] | 759 | && sp[-2] == VKI_AT_HWCAP |
| 760 | && sp[-2-1] == 0) { |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 761 | if (0) |
| 762 | VG_(printf)("Looks like you've got a 2.4.X kernel here.\n"); |
| 763 | sp -= 2; |
| 764 | } else |
sewardj | d9c2d6d | 2002-05-18 11:55:05 +0000 | [diff] [blame] | 765 | if (sp[2] == VKI_AT_CLKTCK |
| 766 | && sp[0] == VKI_AT_PAGESZ |
| 767 | && sp[-2] == VKI_AT_HWCAP |
sewardj | d5815ec | 2003-04-06 12:23:27 +0000 | [diff] [blame] | 768 | && sp[-4] == VKI_AT_SYSINFO |
| 769 | && sp[-4-1] == 0) { |
| 770 | if (0) |
| 771 | VG_(printf)("Looks like you've got a 2.4.X kernel with " |
| 772 | "a sysinfo page at %x here.\n", sp[-3]); |
| 773 | VG_(sysinfo_page_exists) = True; |
| 774 | VG_(sysinfo_page_addr) = sp[-3]; |
| 775 | sp -= 4; |
| 776 | } else |
| 777 | if (sp[2] == VKI_AT_CLKTCK |
| 778 | && sp[0] == VKI_AT_PAGESZ |
| 779 | && sp[-2] == VKI_AT_HWCAP |
sewardj | ce61d05 | 2002-07-25 00:49:51 +0000 | [diff] [blame] | 780 | && sp[-4] == VKI_AT_USER_AUX_SEGMENT |
| 781 | && sp[-4-1] == 0) { |
| 782 | if (0) |
| 783 | VG_(printf)("Looks like you've got a R-H Limbo 2.4.X " |
| 784 | "kernel here.\n"); |
| 785 | sp -= 4; |
| 786 | } else |
| 787 | if (sp[2] == VKI_AT_CLKTCK |
| 788 | && sp[0] == VKI_AT_PAGESZ |
| 789 | && sp[-2] == VKI_AT_HWCAP |
sewardj | d9c2d6d | 2002-05-18 11:55:05 +0000 | [diff] [blame] | 790 | && sp[-2-20-1] == 0) { |
| 791 | if (0) |
| 792 | VG_(printf)("Looks like you've got a early 2.4.X kernel here.\n"); |
| 793 | sp -= 22; |
| 794 | } else |
sewardj | 8fdbeed | 2003-02-23 03:09:33 +0000 | [diff] [blame] | 795 | if (sp[2] == VKI_AT_CLKTCK |
| 796 | && sp[0] == VKI_AT_PAGESZ |
| 797 | && sp[-2] == VKI_AT_HWCAP |
| 798 | && sp[-4-1] == 0) { |
| 799 | if (0) |
| 800 | VG_(printf)("Looks like a >> 2.5.43 kernel here.\n"); |
| 801 | sp -= 4; |
| 802 | } else |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 803 | args_grok_error( |
| 804 | "ELF frame does not look like 2.2.X or 2.4.X.\n " |
| 805 | "See kernel sources linux/fs/binfmt_elf.c to make sense of this." |
| 806 | ); |
sewardj | 3817091 | 2002-05-10 21:07:22 +0000 | [diff] [blame] | 807 | |
| 808 | sp--; |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 809 | if (*sp != 0) |
| 810 | args_grok_error("can't find NULL at end of env[]"); |
| 811 | |
sewardj | 3817091 | 2002-05-10 21:07:22 +0000 | [diff] [blame] | 812 | /* sp now points to NULL at the end of env[] */ |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 813 | ctr = 0; |
sewardj | 3817091 | 2002-05-10 21:07:22 +0000 | [diff] [blame] | 814 | while (True) { |
| 815 | sp --; |
| 816 | if (*sp == 0) break; |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 817 | if (++ctr >= 1000) |
| 818 | args_grok_error( |
| 819 | "suspiciously many (1000) env[] entries; giving up"); |
| 820 | |
sewardj | 3817091 | 2002-05-10 21:07:22 +0000 | [diff] [blame] | 821 | } |
| 822 | /* sp now points to NULL at the end of argv[] */ |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 823 | VG_(client_envp) = (Char**)(sp+1); |
sewardj | 3817091 | 2002-05-10 21:07:22 +0000 | [diff] [blame] | 824 | |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 825 | ctr = 0; |
sewardj | 3817091 | 2002-05-10 21:07:22 +0000 | [diff] [blame] | 826 | VG_(client_argc) = 0; |
| 827 | while (True) { |
| 828 | sp--; |
| 829 | if (*sp == VG_(client_argc)) |
| 830 | break; |
| 831 | VG_(client_argc)++; |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 832 | if (++ctr >= 1000) |
| 833 | args_grok_error( |
| 834 | "suspiciously many (1000) argv[] entries; giving up"); |
sewardj | 3817091 | 2002-05-10 21:07:22 +0000 | [diff] [blame] | 835 | } |
| 836 | |
sewardj | a1679dd | 2002-05-10 22:31:40 +0000 | [diff] [blame] | 837 | VG_(client_argv) = (Char**)(sp+1); |
sewardj | 3817091 | 2002-05-10 21:07:22 +0000 | [diff] [blame] | 838 | } |
| 839 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 840 | /* Now that VG_(client_envp) has been set, we can extract the args |
| 841 | for Valgrind itself. Copy into global var so that we don't have to |
| 842 | write zeroes to the getenv'd value itself. */ |
| 843 | str = VG_(getenv)("VG_ARGS"); |
| 844 | argc = 0; |
| 845 | |
| 846 | if (!str) { |
| 847 | config_error("Can't read options from env var VG_ARGS."); |
| 848 | } |
| 849 | |
| 850 | if (VG_(strlen)(str) >= M_VG_CMDLINE_STRLEN-1) { |
| 851 | config_error("Command line length exceeds M_CMDLINE_STRLEN."); |
| 852 | } |
| 853 | VG_(strcpy)(vg_cmdline_copy, str); |
| 854 | str = NULL; |
| 855 | |
| 856 | p = &vg_cmdline_copy[0]; |
| 857 | while (True) { |
| 858 | while (ISSPACE(*p)) { *p = 0; p++; } |
| 859 | if (*p == 0) break; |
| 860 | if (argc < M_VG_CMDLINE_OPTS-1) { |
| 861 | argv[argc] = p; argc++; |
| 862 | } else { |
| 863 | config_error( |
| 864 | "Found more than M_CMDLINE_OPTS command-line opts."); |
| 865 | } |
| 866 | while (*p != 0 && !ISSPACE(*p)) p++; |
| 867 | } |
| 868 | |
| 869 | for (i = 0; i < argc; i++) { |
| 870 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 871 | if (VG_CLO_STREQ(argv[i], "-v") || |
| 872 | VG_CLO_STREQ(argv[i], "--verbose")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 873 | VG_(clo_verbosity)++; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 874 | else if (VG_CLO_STREQ(argv[i], "-q") || |
| 875 | VG_CLO_STREQ(argv[i], "--quiet")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 876 | VG_(clo_verbosity)--; |
| 877 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 878 | else if (VG_CLO_STREQ(argv[i], "--error-limit=yes")) |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 879 | VG_(clo_error_limit) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 880 | else if (VG_CLO_STREQ(argv[i], "--error-limit=no")) |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 881 | VG_(clo_error_limit) = False; |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 882 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 883 | else if (VG_CLO_STREQ(argv[i], "--gdb-attach=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 884 | VG_(clo_GDB_attach) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 885 | else if (VG_CLO_STREQ(argv[i], "--gdb-attach=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 886 | VG_(clo_GDB_attach) = False; |
| 887 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 888 | else if (VG_CLO_STREQ(argv[i], "--gen-suppressions=yes")) |
| 889 | VG_(clo_gen_suppressions) = True; |
| 890 | else if (VG_CLO_STREQ(argv[i], "--gen-suppressions=no")) |
| 891 | VG_(clo_gen_suppressions) = False; |
| 892 | |
| 893 | else if (VG_CLO_STREQ(argv[i], "--demangle=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 894 | VG_(clo_demangle) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 895 | else if (VG_CLO_STREQ(argv[i], "--demangle=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 896 | VG_(clo_demangle) = False; |
| 897 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 898 | else if (VG_CLO_STREQ(argv[i], "--trace-children=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 899 | VG_(clo_trace_children) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 900 | else if (VG_CLO_STREQ(argv[i], "--trace-children=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 901 | VG_(clo_trace_children) = False; |
| 902 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 903 | else if (VG_CLO_STREQ(argv[i], "--run-libc-freeres=yes")) |
sewardj | 858964b | 2002-10-05 14:15:43 +0000 | [diff] [blame] | 904 | VG_(clo_run_libc_freeres) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 905 | else if (VG_CLO_STREQ(argv[i], "--run-libc-freeres=no")) |
sewardj | 858964b | 2002-10-05 14:15:43 +0000 | [diff] [blame] | 906 | VG_(clo_run_libc_freeres) = False; |
| 907 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 908 | else if (VG_CLO_STREQN(15, argv[i], "--sanity-level=")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 909 | VG_(sanity_level) = (Int)VG_(atoll)(&argv[i][15]); |
| 910 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 911 | else if (VG_CLO_STREQN(13, argv[i], "--logfile-fd=")) { |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 912 | VG_(clo_log_to) = VgLogTo_Fd; |
| 913 | VG_(clo_logfile_name) = NULL; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 914 | eventually_logfile_fd = (Int)VG_(atoll)(&argv[i][13]); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 915 | } |
| 916 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 917 | else if (VG_CLO_STREQN(10, argv[i], "--logfile=")) { |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 918 | VG_(clo_log_to) = VgLogTo_File; |
| 919 | VG_(clo_logfile_name) = &argv[i][10]; |
| 920 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 921 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 922 | else if (VG_CLO_STREQN(12, argv[i], "--logsocket=")) { |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 923 | VG_(clo_log_to) = VgLogTo_Socket; |
| 924 | VG_(clo_logfile_name) = &argv[i][12]; |
| 925 | } |
| 926 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 927 | else if (VG_CLO_STREQN(15, argv[i], "--suppressions=")) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 928 | if (VG_(clo_n_suppressions) >= VG_CLO_MAX_SFILES) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 929 | VG_(message)(Vg_UserMsg, "Too many suppression files specified."); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 930 | VG_(message)(Vg_UserMsg, |
| 931 | "Increase VG_CLO_MAX_SFILES and recompile."); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 932 | VG_(bad_option)(argv[i]); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 933 | } |
| 934 | VG_(clo_suppressions)[VG_(clo_n_suppressions)] = &argv[i][15]; |
| 935 | VG_(clo_n_suppressions)++; |
| 936 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 937 | else if (VG_CLO_STREQ(argv[i], "--profile=yes")) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 938 | VG_(clo_profile) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 939 | else if (VG_CLO_STREQ(argv[i], "--profile=no")) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 940 | VG_(clo_profile) = False; |
| 941 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 942 | else if (VG_CLO_STREQ(argv[i], "--chain-bb=yes")) |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 943 | VG_(clo_chain_bb) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 944 | else if (VG_CLO_STREQ(argv[i], "--chain-bb=no")) |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 945 | VG_(clo_chain_bb) = False; |
| 946 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 947 | else if (VG_CLO_STREQ(argv[i], "--single-step=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 948 | VG_(clo_single_step) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 949 | else if (VG_CLO_STREQ(argv[i], "--single-step=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 950 | VG_(clo_single_step) = False; |
| 951 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 952 | else if (VG_CLO_STREQ(argv[i], "--optimise=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 953 | VG_(clo_optimise) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 954 | else if (VG_CLO_STREQ(argv[i], "--optimise=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 955 | VG_(clo_optimise) = False; |
| 956 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 957 | /* "vwxyz" --> 000zyxwv (binary) */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 958 | else if (VG_CLO_STREQN(16, argv[i], "--trace-codegen=")) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 959 | Int j; |
| 960 | char* opt = & argv[i][16]; |
| 961 | |
| 962 | if (5 != VG_(strlen)(opt)) { |
| 963 | VG_(message)(Vg_UserMsg, |
| 964 | "--trace-codegen argument must have 5 digits"); |
| 965 | VG_(bad_option)(argv[i]); |
| 966 | } |
| 967 | for (j = 0; j < 5; j++) { |
| 968 | if ('0' == opt[j]) { /* do nothing */ } |
| 969 | else if ('1' == opt[j]) VG_(clo_trace_codegen) |= (1 << j); |
| 970 | else { |
| 971 | VG_(message)(Vg_UserMsg, "--trace-codegen argument can only " |
| 972 | "contain 0s and 1s"); |
| 973 | VG_(bad_option)(argv[i]); |
| 974 | } |
| 975 | } |
| 976 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 977 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 978 | else if (VG_CLO_STREQ(argv[i], "--trace-syscalls=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 979 | VG_(clo_trace_syscalls) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 980 | else if (VG_CLO_STREQ(argv[i], "--trace-syscalls=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 981 | VG_(clo_trace_syscalls) = False; |
| 982 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 983 | else if (VG_CLO_STREQ(argv[i], "--trace-signals=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 984 | VG_(clo_trace_signals) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 985 | else if (VG_CLO_STREQ(argv[i], "--trace-signals=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 986 | VG_(clo_trace_signals) = False; |
| 987 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 988 | else if (VG_CLO_STREQ(argv[i], "--trace-symtab=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 989 | VG_(clo_trace_symtab) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 990 | else if (VG_CLO_STREQ(argv[i], "--trace-symtab=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 991 | VG_(clo_trace_symtab) = False; |
| 992 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 993 | else if (VG_CLO_STREQ(argv[i], "--trace-sched=yes")) |
sewardj | 8937c81 | 2002-04-12 20:12:20 +0000 | [diff] [blame] | 994 | VG_(clo_trace_sched) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 995 | else if (VG_CLO_STREQ(argv[i], "--trace-sched=no")) |
sewardj | 8937c81 | 2002-04-12 20:12:20 +0000 | [diff] [blame] | 996 | VG_(clo_trace_sched) = False; |
| 997 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 998 | else if (VG_CLO_STREQ(argv[i], "--trace-pthread=none")) |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 999 | VG_(clo_trace_pthread_level) = 0; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 1000 | else if (VG_CLO_STREQ(argv[i], "--trace-pthread=some")) |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1001 | VG_(clo_trace_pthread_level) = 1; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 1002 | else if (VG_CLO_STREQ(argv[i], "--trace-pthread=all")) |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 1003 | VG_(clo_trace_pthread_level) = 2; |
sewardj | 8937c81 | 2002-04-12 20:12:20 +0000 | [diff] [blame] | 1004 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 1005 | else if (VG_CLO_STREQN(14, argv[i], "--weird-hacks=")) |
sewardj | 8d365b5 | 2002-05-12 10:52:16 +0000 | [diff] [blame] | 1006 | VG_(clo_weird_hacks) = &argv[i][14]; |
sewardj | 3984b85 | 2002-05-12 03:00:17 +0000 | [diff] [blame] | 1007 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 1008 | else if (VG_CLO_STREQN(13, argv[i], "--stop-after=")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1009 | VG_(clo_stop_after) = VG_(atoll)(&argv[i][13]); |
| 1010 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 1011 | else if (VG_CLO_STREQN(13, argv[i], "--dump-error=")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1012 | VG_(clo_dump_error) = (Int)VG_(atoll)(&argv[i][13]); |
| 1013 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 1014 | else if (VG_CLO_STREQN(14, argv[i], "--num-callers=")) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1015 | /* Make sure it's sane. */ |
| 1016 | VG_(clo_backtrace_size) = (Int)VG_(atoll)(&argv[i][14]); |
| 1017 | if (VG_(clo_backtrace_size) < 2) |
| 1018 | VG_(clo_backtrace_size) = 2; |
| 1019 | if (VG_(clo_backtrace_size) >= VG_DEEPEST_BACKTRACE) |
| 1020 | VG_(clo_backtrace_size) = VG_DEEPEST_BACKTRACE; |
| 1021 | } |
| 1022 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1023 | else if (VG_(needs).command_line_options) { |
| 1024 | Bool ok = SK_(process_cmd_line_option)(argv[i]); |
| 1025 | if (!ok) |
| 1026 | usage(); |
| 1027 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1028 | else |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1029 | usage(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | # undef ISSPACE |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1033 | |
| 1034 | if (VG_(clo_verbosity < 0)) |
| 1035 | VG_(clo_verbosity) = 0; |
| 1036 | |
| 1037 | if (VG_(clo_GDB_attach) && VG_(clo_trace_children)) { |
| 1038 | VG_(message)(Vg_UserMsg, ""); |
| 1039 | VG_(message)(Vg_UserMsg, |
| 1040 | "--gdb-attach=yes conflicts with --trace-children=yes"); |
| 1041 | VG_(message)(Vg_UserMsg, |
| 1042 | "Please choose one or the other, but not both."); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1043 | VG_(bad_option)("--gdb-attach=yes and --trace-children=yes"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1044 | } |
| 1045 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1046 | /* Set up logging now. After this is done, VG_(clo_logfile_fd) |
| 1047 | should be connected to whatever sink has been selected, and we |
| 1048 | indiscriminately chuck stuff into it without worrying what the |
| 1049 | nature of it is. Oh the wonder of Unix streams. */ |
| 1050 | |
| 1051 | /* So far we should be still attached to stderr, so we can show on |
| 1052 | the terminal any problems to do with processing command line |
| 1053 | opts. */ |
| 1054 | vg_assert(VG_(clo_logfile_fd) == 2 /* stderr */); |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1055 | vg_assert(VG_(logging_to_filedes) == True); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1056 | |
| 1057 | switch (VG_(clo_log_to)) { |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1058 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1059 | case VgLogTo_Fd: |
| 1060 | vg_assert(VG_(clo_logfile_name) == NULL); |
| 1061 | VG_(clo_logfile_fd) = eventually_logfile_fd; |
| 1062 | break; |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1063 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1064 | case VgLogTo_File: { |
| 1065 | Char logfilename[1000]; |
| 1066 | vg_assert(VG_(clo_logfile_name) != NULL); |
| 1067 | vg_assert(VG_(strlen)(VG_(clo_logfile_name)) <= 900); /* paranoia */ |
| 1068 | VG_(sprintf)(logfilename, "%s.pid%d", |
| 1069 | VG_(clo_logfile_name), VG_(getpid)() ); |
| 1070 | eventually_logfile_fd |
| 1071 | = VG_(open)(logfilename, VKI_O_CREAT|VKI_O_WRONLY, |
| 1072 | VKI_S_IRUSR|VKI_S_IWUSR); |
| 1073 | if (eventually_logfile_fd != -1) { |
| 1074 | VG_(clo_logfile_fd) = eventually_logfile_fd; |
| 1075 | } else { |
| 1076 | VG_(message)(Vg_UserMsg, |
| 1077 | "Can't create/open log file `%s.pid%d'; giving up!", |
| 1078 | VG_(clo_logfile_name), VG_(getpid)()); |
| 1079 | VG_(bad_option)( |
| 1080 | "--logfile=<file> didn't work out for some reason."); |
| 1081 | } |
| 1082 | break; |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | case VgLogTo_Socket: { |
| 1086 | vg_assert(VG_(clo_logfile_name) != NULL); |
| 1087 | vg_assert(VG_(strlen)(VG_(clo_logfile_name)) <= 900); /* paranoia */ |
| 1088 | eventually_logfile_fd |
| 1089 | = VG_(connect_via_socket)( VG_(clo_logfile_name) ); |
| 1090 | if (eventually_logfile_fd == -1) { |
| 1091 | VG_(message)(Vg_UserMsg, |
| 1092 | "Invalid --logsocket=ipaddr or --logsocket=ipaddr:port spec"); |
| 1093 | VG_(message)(Vg_UserMsg, |
| 1094 | "of `%s'; giving up!", VG_(clo_logfile_name) ); |
| 1095 | VG_(bad_option)( |
| 1096 | "--logsocket="); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1097 | } |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1098 | if (eventually_logfile_fd == -2) { |
| 1099 | VG_(message)(Vg_UserMsg, |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 1100 | "valgrind: failed to connect to logging server `%s'.", |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1101 | VG_(clo_logfile_name) ); |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 1102 | VG_(message)(Vg_UserMsg, |
| 1103 | "Log messages will sent to stderr instead." ); |
| 1104 | VG_(message)(Vg_UserMsg, |
| 1105 | "" ); |
| 1106 | /* We don't change anything here. */ |
| 1107 | } else { |
| 1108 | vg_assert(eventually_logfile_fd > 0); |
| 1109 | VG_(clo_logfile_fd) = eventually_logfile_fd; |
| 1110 | VG_(logging_to_filedes) = False; |
| 1111 | } |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1112 | break; |
| 1113 | } |
| 1114 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | /* Ok, the logging sink is running now. Print a suitable preamble. |
| 1118 | If logging to file or a socket, write details of parent PID and |
| 1119 | command line args, to help people trying to interpret the |
| 1120 | results of a run which encompasses multiple processes. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1121 | |
sewardj | 83adf41 | 2002-05-01 01:25:45 +0000 | [diff] [blame] | 1122 | if (VG_(clo_verbosity > 0)) { |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 1123 | /* Skin details */ |
| 1124 | VG_(message)(Vg_UserMsg, "%s%s%s, %s for x86-linux.", |
| 1125 | VG_(details).name, |
| 1126 | NULL == VG_(details).version ? "" : "-", |
| 1127 | NULL == VG_(details).version |
| 1128 | ? (Char*)"" : VG_(details).version, |
| 1129 | VG_(details).description); |
| 1130 | VG_(message)(Vg_UserMsg, "%s", VG_(details).copyright_author); |
sewardj | 3b2736a | 2002-03-24 12:18:35 +0000 | [diff] [blame] | 1131 | |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 1132 | /* Core details */ |
| 1133 | VG_(message)(Vg_UserMsg, |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame^] | 1134 | "Using valgrind-%s, a program supervision framework for x86-linux.", |
sewardj | 4aa62ba | 2002-10-05 15:49:27 +0000 | [diff] [blame] | 1135 | VERSION); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1136 | VG_(message)(Vg_UserMsg, |
sewardj | 4aa62ba | 2002-10-05 15:49:27 +0000 | [diff] [blame] | 1137 | "Copyright (C) 2000-2002, and GNU GPL'd, by Julian Seward."); |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1140 | if (VG_(clo_log_to) != VgLogTo_Fd) { |
| 1141 | VG_(message)(Vg_UserMsg, ""); |
| 1142 | VG_(message)(Vg_UserMsg, |
| 1143 | "My PID = %d, parent PID = %d. Prog and args are:", |
| 1144 | VG_(getpid)(), VG_(getppid)() ); |
| 1145 | for (i = 0; i < VG_(client_argc); i++) |
| 1146 | VG_(message)(Vg_UserMsg, " %s", VG_(client_argv)[i]); |
| 1147 | } |
| 1148 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1149 | if (VG_(clo_verbosity) > 1) { |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1150 | if (VG_(clo_log_to) != VgLogTo_Fd) |
| 1151 | VG_(message)(Vg_UserMsg, ""); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1152 | VG_(message)(Vg_UserMsg, "Startup, with flags:"); |
| 1153 | for (i = 0; i < argc; i++) { |
| 1154 | VG_(message)(Vg_UserMsg, " %s", argv[i]); |
| 1155 | } |
| 1156 | } |
| 1157 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1158 | if (VG_(clo_n_suppressions) == 0 && |
| 1159 | (VG_(needs).core_errors || VG_(needs).skin_errors)) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1160 | config_error("No error-suppression files were specified."); |
| 1161 | } |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1162 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1165 | /* --------------------------------------------------------------------- |
| 1166 | Copying to/from m_state_static. |
| 1167 | ------------------------------------------------------------------ */ |
| 1168 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1169 | UInt VG_(m_state_static) [6 /* segment regs, Intel order */ |
| 1170 | + 8 /* int regs, in Intel order */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1171 | + 1 /* %eflags */ |
| 1172 | + 1 /* %eip */ |
| 1173 | + VG_SIZE_OF_FPUSTATE_W /* FPU state */ |
| 1174 | ]; |
| 1175 | |
sewardj | fa492d4 | 2002-12-08 18:20:01 +0000 | [diff] [blame] | 1176 | UInt VG_(insertDflag)(UInt eflags, Int d) |
| 1177 | { |
| 1178 | vg_assert(d == 1 || d == -1); |
| 1179 | eflags &= ~EFlagD; |
| 1180 | |
| 1181 | if (d < 0) |
| 1182 | eflags |= EFlagD; |
| 1183 | |
| 1184 | return eflags; |
| 1185 | } |
| 1186 | |
| 1187 | Int VG_(extractDflag)(UInt eflags) |
| 1188 | { |
| 1189 | Int ret; |
| 1190 | |
| 1191 | if (eflags & EFlagD) |
| 1192 | ret = -1; |
| 1193 | else |
| 1194 | ret = 1; |
| 1195 | |
| 1196 | return ret; |
| 1197 | } |
| 1198 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1199 | void VG_(copy_baseBlock_to_m_state_static) ( void ) |
| 1200 | { |
| 1201 | Int i; |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1202 | VG_(m_state_static)[ 0/4] = VG_(baseBlock)[VGOFF_(m_cs)]; |
| 1203 | VG_(m_state_static)[ 4/4] = VG_(baseBlock)[VGOFF_(m_ss)]; |
| 1204 | VG_(m_state_static)[ 8/4] = VG_(baseBlock)[VGOFF_(m_ds)]; |
| 1205 | VG_(m_state_static)[12/4] = VG_(baseBlock)[VGOFF_(m_es)]; |
| 1206 | VG_(m_state_static)[16/4] = VG_(baseBlock)[VGOFF_(m_fs)]; |
| 1207 | VG_(m_state_static)[20/4] = VG_(baseBlock)[VGOFF_(m_gs)]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1208 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1209 | VG_(m_state_static)[24/4] = VG_(baseBlock)[VGOFF_(m_eax)]; |
| 1210 | VG_(m_state_static)[28/4] = VG_(baseBlock)[VGOFF_(m_ecx)]; |
| 1211 | VG_(m_state_static)[32/4] = VG_(baseBlock)[VGOFF_(m_edx)]; |
| 1212 | VG_(m_state_static)[36/4] = VG_(baseBlock)[VGOFF_(m_ebx)]; |
| 1213 | VG_(m_state_static)[40/4] = VG_(baseBlock)[VGOFF_(m_esp)]; |
| 1214 | VG_(m_state_static)[44/4] = VG_(baseBlock)[VGOFF_(m_ebp)]; |
| 1215 | VG_(m_state_static)[48/4] = VG_(baseBlock)[VGOFF_(m_esi)]; |
| 1216 | VG_(m_state_static)[52/4] = VG_(baseBlock)[VGOFF_(m_edi)]; |
| 1217 | |
sewardj | fa492d4 | 2002-12-08 18:20:01 +0000 | [diff] [blame] | 1218 | VG_(m_state_static)[56/4] = VG_(insertDflag)(VG_(baseBlock)[VGOFF_(m_eflags)], |
| 1219 | VG_(baseBlock)[VGOFF_(m_dflag)]); |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1220 | VG_(m_state_static)[60/4] = VG_(baseBlock)[VGOFF_(m_eip)]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1221 | |
| 1222 | for (i = 0; i < VG_SIZE_OF_FPUSTATE_W; i++) |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1223 | VG_(m_state_static)[64/4 + i] |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1224 | = VG_(baseBlock)[VGOFF_(m_fpustate) + i]; |
| 1225 | } |
| 1226 | |
| 1227 | |
| 1228 | void VG_(copy_m_state_static_to_baseBlock) ( void ) |
| 1229 | { |
| 1230 | Int i; |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1231 | VG_(baseBlock)[VGOFF_(m_cs)] = VG_(m_state_static)[ 0/4]; |
| 1232 | VG_(baseBlock)[VGOFF_(m_ss)] = VG_(m_state_static)[ 4/4]; |
| 1233 | VG_(baseBlock)[VGOFF_(m_ds)] = VG_(m_state_static)[ 8/4]; |
| 1234 | VG_(baseBlock)[VGOFF_(m_es)] = VG_(m_state_static)[12/4]; |
| 1235 | VG_(baseBlock)[VGOFF_(m_fs)] = VG_(m_state_static)[16/4]; |
| 1236 | VG_(baseBlock)[VGOFF_(m_gs)] = VG_(m_state_static)[20/4]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1237 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1238 | VG_(baseBlock)[VGOFF_(m_eax)] = VG_(m_state_static)[24/4]; |
| 1239 | VG_(baseBlock)[VGOFF_(m_ecx)] = VG_(m_state_static)[28/4]; |
| 1240 | VG_(baseBlock)[VGOFF_(m_edx)] = VG_(m_state_static)[32/4]; |
| 1241 | VG_(baseBlock)[VGOFF_(m_ebx)] = VG_(m_state_static)[36/4]; |
| 1242 | VG_(baseBlock)[VGOFF_(m_esp)] = VG_(m_state_static)[40/4]; |
| 1243 | VG_(baseBlock)[VGOFF_(m_ebp)] = VG_(m_state_static)[44/4]; |
| 1244 | VG_(baseBlock)[VGOFF_(m_esi)] = VG_(m_state_static)[48/4]; |
| 1245 | VG_(baseBlock)[VGOFF_(m_edi)] = VG_(m_state_static)[52/4]; |
| 1246 | |
sewardj | fa492d4 | 2002-12-08 18:20:01 +0000 | [diff] [blame] | 1247 | VG_(baseBlock)[VGOFF_(m_eflags)] = VG_(m_state_static)[56/4] & ~EFlagD; |
| 1248 | VG_(baseBlock)[VGOFF_(m_dflag)] = VG_(extractDflag)(VG_(m_state_static)[56/4]); |
| 1249 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1250 | VG_(baseBlock)[VGOFF_(m_eip)] = VG_(m_state_static)[60/4]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1251 | |
| 1252 | for (i = 0; i < VG_SIZE_OF_FPUSTATE_W; i++) |
| 1253 | VG_(baseBlock)[VGOFF_(m_fpustate) + i] |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1254 | = VG_(m_state_static)[64/4 + i]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1257 | Addr VG_(get_stack_pointer) ( void ) |
| 1258 | { |
| 1259 | return VG_(baseBlock)[VGOFF_(m_esp)]; |
| 1260 | } |
| 1261 | |
| 1262 | /* Some random tests needed for leak checking */ |
| 1263 | |
| 1264 | Bool VG_(within_stack)(Addr a) |
| 1265 | { |
| 1266 | if (a >= ((Addr)(&VG_(stack))) |
| 1267 | && a <= ((Addr)(&VG_(stack))) + sizeof(VG_(stack))) |
| 1268 | return True; |
| 1269 | else |
| 1270 | return False; |
| 1271 | } |
| 1272 | |
| 1273 | Bool VG_(within_m_state_static)(Addr a) |
| 1274 | { |
| 1275 | if (a >= ((Addr)(&VG_(m_state_static))) |
| 1276 | && a <= ((Addr)(&VG_(m_state_static))) + sizeof(VG_(m_state_static))) |
| 1277 | return True; |
| 1278 | else |
| 1279 | return False; |
| 1280 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1281 | |
| 1282 | /* --------------------------------------------------------------------- |
| 1283 | Show accumulated counts. |
| 1284 | ------------------------------------------------------------------ */ |
| 1285 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1286 | static __inline__ Int safe_idiv(Int a, Int b) |
| 1287 | { |
| 1288 | return (b == 0 ? 0 : a / b); |
| 1289 | } |
| 1290 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1291 | static void vg_show_counts ( void ) |
| 1292 | { |
| 1293 | VG_(message)(Vg_DebugMsg, |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 1294 | " TT/TC: %d tc sectors discarded.", |
| 1295 | VG_(number_of_tc_discards) ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1296 | VG_(message)(Vg_DebugMsg, |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 1297 | " %d chainings, %d unchainings.", |
| 1298 | VG_(bb_enchain_count), VG_(bb_dechain_count) ); |
| 1299 | VG_(message)(Vg_DebugMsg, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1300 | "translate: new %d (%d -> %d; ratio %d:10)", |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1301 | VG_(overall_in_count), |
| 1302 | VG_(overall_in_osize), |
| 1303 | VG_(overall_in_tsize), |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1304 | safe_idiv(10*VG_(overall_in_tsize), VG_(overall_in_osize))); |
| 1305 | VG_(message)(Vg_DebugMsg, |
| 1306 | " discard %d (%d -> %d; ratio %d:10).", |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1307 | VG_(overall_out_count), |
| 1308 | VG_(overall_out_osize), |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1309 | VG_(overall_out_tsize), |
| 1310 | safe_idiv(10*VG_(overall_out_tsize), VG_(overall_out_osize))); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1311 | VG_(message)(Vg_DebugMsg, |
njn | e0205ff | 2003-04-08 00:56:14 +0000 | [diff] [blame] | 1312 | " dispatch: %llu jumps (bb entries), of which %u (%lu%%) were unchained.", |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 1313 | VG_(bbs_done), |
| 1314 | VG_(unchained_jumps_done), |
| 1315 | ((ULong)(100) * (ULong)(VG_(unchained_jumps_done))) |
| 1316 | / ( VG_(bbs_done)==0 ? 1 : VG_(bbs_done) ) |
| 1317 | ); |
| 1318 | |
| 1319 | VG_(message)(Vg_DebugMsg, |
| 1320 | " %d/%d major/minor sched events. %d tt_fast misses.", |
| 1321 | VG_(num_scheduling_events_MAJOR), |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1322 | VG_(num_scheduling_events_MINOR), |
| 1323 | VG_(tt_fast_misses)); |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 1324 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1325 | VG_(message)(Vg_DebugMsg, |
| 1326 | "reg-alloc: %d t-req-spill, " |
| 1327 | "%d+%d orig+spill uis, %d total-reg-r.", |
| 1328 | VG_(translations_needing_spill), |
| 1329 | VG_(uinstrs_prealloc), |
| 1330 | VG_(uinstrs_spill), |
| 1331 | VG_(total_reg_rank) ); |
| 1332 | VG_(message)(Vg_DebugMsg, |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1333 | " sanity: %d cheap, %d expensive checks.", |
| 1334 | VG_(sanity_fast_count), |
| 1335 | VG_(sanity_slow_count) ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1336 | VG_(print_ccall_stats)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | |
| 1340 | /* --------------------------------------------------------------------- |
| 1341 | Main! |
| 1342 | ------------------------------------------------------------------ */ |
| 1343 | |
| 1344 | /* Where we jump to once Valgrind has got control, and the real |
| 1345 | machine's state has been copied to the m_state_static. */ |
| 1346 | |
| 1347 | void VG_(main) ( void ) |
| 1348 | { |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1349 | Int i; |
| 1350 | VgSchedReturnCode src; |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1351 | ThreadState* tst; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1352 | |
njn | 27f1a38 | 2002-11-08 15:48:16 +0000 | [diff] [blame] | 1353 | /* Check skin and core versions are compatible */ |
| 1354 | if (VG_CORE_INTERFACE_MAJOR_VERSION != VG_(skin_interface_major_version)) { |
| 1355 | VG_(printf)("Error:\n" |
| 1356 | " Skin and core interface versions do not match.\n" |
| 1357 | " Interface version used by core is: %d.%d\n" |
| 1358 | " Interface version used by skin is: %d.%d\n" |
| 1359 | " The major version numbers must match.\n", |
| 1360 | VG_CORE_INTERFACE_MAJOR_VERSION, |
| 1361 | VG_CORE_INTERFACE_MINOR_VERSION, |
| 1362 | VG_(skin_interface_major_version), |
| 1363 | VG_(skin_interface_minor_version)); |
| 1364 | VG_(printf)(" You need to at least recompile, and possibly update,\n"); |
| 1365 | if (VG_CORE_INTERFACE_MAJOR_VERSION > VG_(skin_interface_major_version)) |
| 1366 | VG_(printf)(" your skin to work with this version of Valgrind.\n"); |
| 1367 | else |
| 1368 | VG_(printf)(" your version of Valgrind to work with this skin.\n"); |
| 1369 | VG_(printf)(" Aborting, sorry.\n"); |
| 1370 | VG_(exit)(1); |
| 1371 | } |
| 1372 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1373 | /* Set up our stack sanity-check words. */ |
| 1374 | for (i = 0; i < 10; i++) { |
| 1375 | VG_(stack)[i] = (UInt)(&VG_(stack)[i]) ^ 0xA4B3C2D1; |
| 1376 | VG_(stack)[10000-1-i] = (UInt)(&VG_(stack)[10000-i-1]) ^ 0xABCD4321; |
| 1377 | } |
| 1378 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame^] | 1379 | /* Read /proc/self/maps into a buffer. Must be before: |
| 1380 | - SK_(pre_clo_init)(): so that if it calls VG_(malloc)(), any mmap'd |
| 1381 | superblocks are not erroneously identified as being owned by the |
| 1382 | client, which would be bad. |
| 1383 | - init_memory(): that's where the buffer is parsed |
| 1384 | - init_tt_tc(): so the anonymous mmaps for the translation table and |
| 1385 | translation cache aren't identified as part of the client, which would |
| 1386 | waste > 20M of virtual address space, and be bad. |
| 1387 | */ |
| 1388 | VG_(read_procselfmaps_contents)(); |
| 1389 | |
sewardj | 1c1b116 | 2003-02-23 01:25:51 +0000 | [diff] [blame] | 1390 | /* Hook to delay things long enough so we can get the pid and |
| 1391 | attach GDB in another shell. */ |
| 1392 | if (0) { |
| 1393 | Int p, q; |
| 1394 | VG_(printf)("pid=%d\n", VG_(getpid)()); |
| 1395 | for (p = 0; p < 50000; p++) |
| 1396 | for (q = 0; q < 50000; q++) ; |
| 1397 | } |
| 1398 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1399 | /* Setup stuff that depends on the skin. Must be before: |
| 1400 | - vg_init_baseBlock(): to register helpers |
| 1401 | - process_cmd_line_options(): to register skin name and description, |
| 1402 | and turn on/off 'command_line_options' need |
| 1403 | - init_memory() (to setup memory event trackers). |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame^] | 1404 | */ |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1405 | SK_(pre_clo_init)(); |
| 1406 | VG_(sanity_check_needs)(); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1407 | |
njn | cc7bb47 | 2002-10-14 09:25:19 +0000 | [diff] [blame] | 1408 | /* Process Valgrind's command-line opts (from env var VG_ARGS). */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1409 | process_cmd_line_options(); |
| 1410 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame^] | 1411 | /* Do post command-line processing initialisation. Must be before: |
| 1412 | - vg_init_baseBlock(): to register any more helpers |
| 1413 | */ |
njn | cc7bb47 | 2002-10-14 09:25:19 +0000 | [diff] [blame] | 1414 | SK_(post_clo_init)(); |
| 1415 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame^] | 1416 | /* Set up baseBlock offsets and copy the saved machine's state into it. */ |
njn | cc7bb47 | 2002-10-14 09:25:19 +0000 | [diff] [blame] | 1417 | vg_init_baseBlock(); |
| 1418 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1419 | /* Initialise the scheduler, and copy the client's state from |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame^] | 1420 | baseBlock into VG_(threads)[1]. Must be before: |
| 1421 | - VG_(sigstartup_actions)() |
| 1422 | */ |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1423 | VG_(scheduler_init)(); |
| 1424 | |
| 1425 | /* Initialise the signal handling subsystem, temporarily parking |
| 1426 | the saved blocking-mask in saved_sigmask. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1427 | VG_(sigstartup_actions)(); |
| 1428 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1429 | /* Perhaps we're profiling Valgrind? */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1430 | if (VG_(clo_profile)) |
| 1431 | VGP_(init_profiling)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1432 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1433 | /* Start calibration of our RDTSC-based clock. */ |
| 1434 | VG_(start_rdtsc_calibration)(); |
| 1435 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame^] | 1436 | /* Parse /proc/self/maps to learn about startup segments. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1437 | VGP_PUSHCC(VgpInitMem); |
| 1438 | VG_(init_memory)(); |
| 1439 | VGP_POPCC(VgpInitMem); |
| 1440 | |
| 1441 | /* Read the list of errors to suppress. This should be found in |
| 1442 | the file specified by vg_clo_suppressions. */ |
| 1443 | if (VG_(needs).core_errors || VG_(needs).skin_errors) |
| 1444 | VG_(load_suppressions)(); |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1445 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1446 | /* End calibration of our RDTSC-based clock, leaving it as long as |
| 1447 | we can. */ |
| 1448 | VG_(end_rdtsc_calibration)(); |
| 1449 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame^] | 1450 | /* Initialise translation table and translation cache. */ |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1451 | VG_(init_tt_tc)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1452 | |
| 1453 | if (VG_(clo_verbosity) == 1) { |
| 1454 | VG_(message)(Vg_UserMsg, |
| 1455 | "For more details, rerun with: -v"); |
| 1456 | } |
| 1457 | |
| 1458 | /* Now it is safe for malloc et al in vg_clientmalloc.c to act |
| 1459 | instrumented-ly. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1460 | if (VG_(clo_verbosity) > 0) |
| 1461 | VG_(message)(Vg_UserMsg, ""); |
| 1462 | |
| 1463 | VG_(bbs_to_go) = VG_(clo_stop_after); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1464 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1465 | /* Run! */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1466 | VG_(running_on_simd_CPU) = True; |
sewardj | 671ff54 | 2002-05-07 09:25:30 +0000 | [diff] [blame] | 1467 | VGP_PUSHCC(VgpSched); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1468 | src = VG_(scheduler)(); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1469 | VGP_POPCC(VgpSched); |
| 1470 | VG_(running_on_simd_CPU) = False; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1471 | |
| 1472 | if (VG_(clo_verbosity) > 0) |
| 1473 | VG_(message)(Vg_UserMsg, ""); |
| 1474 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1475 | if (src == VgSrc_Deadlock) { |
| 1476 | VG_(message)(Vg_UserMsg, |
| 1477 | "Warning: pthread scheduler exited due to deadlock"); |
| 1478 | } |
| 1479 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1480 | if (VG_(needs).core_errors || VG_(needs).skin_errors) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1481 | VG_(show_all_errors)(); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1482 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1483 | SK_(fini)(); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1484 | |
sewardj | 0c3b53f | 2002-05-01 01:58:35 +0000 | [diff] [blame] | 1485 | VG_(do_sanity_checks)( True /*include expensive checks*/ ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1486 | |
| 1487 | if (VG_(clo_verbosity) > 1) |
| 1488 | vg_show_counts(); |
| 1489 | |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 1490 | if (VG_(clo_verbosity) > 3) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1491 | VG_(print_UInstr_histogram)(); |
| 1492 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1493 | if (0) { |
| 1494 | VG_(message)(Vg_DebugMsg, ""); |
| 1495 | VG_(message)(Vg_DebugMsg, |
| 1496 | "------ Valgrind's internal memory use stats follow ------" ); |
| 1497 | VG_(mallocSanityCheckAll)(); |
| 1498 | VG_(show_all_arena_stats)(); |
| 1499 | VG_(message)(Vg_DebugMsg, |
| 1500 | "------ Valgrind's ExeContext management stats follow ------" ); |
| 1501 | VG_(show_ExeContext_stats)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1502 | } |
| 1503 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1504 | if (VG_(clo_profile)) |
| 1505 | VGP_(done_profiling)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1506 | |
| 1507 | VG_(shutdown_logging)(); |
| 1508 | |
sewardj | 3e1eb1f | 2002-05-18 13:14:17 +0000 | [diff] [blame] | 1509 | /* Remove valgrind.so from a LD_PRELOAD=... string so child |
| 1510 | processes don't get traced into. Also mess up $libdir/valgrind |
| 1511 | so that our libpthread.so disappears from view. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1512 | if (!VG_(clo_trace_children)) { |
sewardj | 3e1eb1f | 2002-05-18 13:14:17 +0000 | [diff] [blame] | 1513 | VG_(mash_LD_PRELOAD_and_LD_LIBRARY_PATH)( |
| 1514 | VG_(getenv)("LD_PRELOAD"), |
| 1515 | VG_(getenv)("LD_LIBRARY_PATH") |
| 1516 | ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1519 | /* Decide how to exit. This depends on what the scheduler |
| 1520 | returned. */ |
| 1521 | switch (src) { |
| 1522 | case VgSrc_ExitSyscall: /* the normal way out */ |
| 1523 | vg_assert(VG_(last_run_tid) > 0 |
| 1524 | && VG_(last_run_tid) < VG_N_THREADS); |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1525 | tst = & VG_(threads)[VG_(last_run_tid)]; |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1526 | vg_assert(tst->status == VgTs_Runnable); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1527 | /* The thread's %EBX at the time it did __NR_exit() will hold |
| 1528 | the arg to __NR_exit(), so we just do __NR_exit() with |
| 1529 | that arg. */ |
| 1530 | VG_(exit)( VG_(exitcode) ); |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1531 | /* NOT ALIVE HERE! */ |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 1532 | VG_(core_panic)("entered the afterlife in vg_main() -- ExitSyscall"); |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1533 | break; /* what the hell :) */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1534 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1535 | case VgSrc_Deadlock: |
| 1536 | /* Just exit now. No point in continuing. */ |
| 1537 | VG_(exit)(0); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 1538 | VG_(core_panic)("entered the afterlife in vg_main() -- Deadlock"); |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1539 | break; |
| 1540 | |
| 1541 | case VgSrc_BbsDone: |
| 1542 | /* Tricky; we have to try and switch back to the real CPU. |
| 1543 | This is all very dodgy and won't work at all in the |
| 1544 | presence of threads, or if the client happened to be |
| 1545 | running a signal handler. */ |
| 1546 | /* Prepare to restore state to the real CPU. */ |
| 1547 | VG_(load_thread_state)(1 /* root thread */ ); |
| 1548 | VG_(copy_baseBlock_to_m_state_static)(); |
| 1549 | |
| 1550 | /* This pushes a return address on the simulator's stack, |
| 1551 | which is abandoned. We call vg_sigshutdown_actions() at |
| 1552 | the end of vg_switch_to_real_CPU(), so as to ensure that |
| 1553 | the original stack and machine state is restored before |
| 1554 | the real signal mechanism is restored. */ |
| 1555 | VG_(switch_to_real_CPU)(); |
| 1556 | |
| 1557 | default: |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 1558 | VG_(core_panic)("vg_main(): unexpected scheduler return code"); |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1559 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | |
| 1563 | /* Debugging thing .. can be called from assembly with OYNK macro. */ |
| 1564 | void VG_(oynk) ( Int n ) |
| 1565 | { |
| 1566 | OINK(n); |
| 1567 | } |
| 1568 | |
| 1569 | |
| 1570 | /* Find "valgrind.so" in a LD_PRELOAD=... string, and convert it to |
| 1571 | "valgrinq.so", which doesn't do anything. This is used to avoid |
| 1572 | tracing into child processes. To make this work the build system |
| 1573 | also supplies a dummy file, "valgrinq.so". |
sewardj | 78e25c9 | 2002-05-20 23:38:33 +0000 | [diff] [blame] | 1574 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1575 | Also replace "vgskin_<foo>.so" with whitespace, for the same reason; |
| 1576 | without it, child processes try to find valgrind.so symbols in the |
| 1577 | skin .so. |
| 1578 | |
sewardj | 78e25c9 | 2002-05-20 23:38:33 +0000 | [diff] [blame] | 1579 | Also look for $(libdir)/lib/valgrind in LD_LIBRARY_PATH and change |
| 1580 | it to $(libdir)/lib/valgrinq, so as to make our libpthread.so |
| 1581 | disappear. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1582 | */ |
sewardj | 3e1eb1f | 2002-05-18 13:14:17 +0000 | [diff] [blame] | 1583 | void VG_(mash_LD_PRELOAD_and_LD_LIBRARY_PATH) ( Char* ld_preload_str, |
| 1584 | Char* ld_library_path_str ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1585 | { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1586 | Char* p_prel = NULL; |
| 1587 | Char* sk_prel = NULL; |
| 1588 | Char* p_path = NULL; |
| 1589 | Int what = 0; |
sewardj | 78e25c9 | 2002-05-20 23:38:33 +0000 | [diff] [blame] | 1590 | if (ld_preload_str == NULL || ld_library_path_str == NULL) |
| 1591 | goto mutancy; |
sewardj | 3e1eb1f | 2002-05-18 13:14:17 +0000 | [diff] [blame] | 1592 | |
sewardj | 78e25c9 | 2002-05-20 23:38:33 +0000 | [diff] [blame] | 1593 | /* VG_(printf)("%s %s\n", ld_preload_str, ld_library_path_str); */ |
| 1594 | |
| 1595 | p_prel = VG_(strstr)(ld_preload_str, "valgrind.so"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1596 | sk_prel = VG_(strstr)(ld_preload_str, "vgskin_"); |
sewardj | 78e25c9 | 2002-05-20 23:38:33 +0000 | [diff] [blame] | 1597 | p_path = VG_(strstr)(ld_library_path_str, VG_LIBDIR); |
| 1598 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1599 | what = 1; |
sewardj | 78e25c9 | 2002-05-20 23:38:33 +0000 | [diff] [blame] | 1600 | if (p_prel == NULL) { |
sewardj | 3e1eb1f | 2002-05-18 13:14:17 +0000 | [diff] [blame] | 1601 | /* perhaps already happened? */ |
sewardj | 78e25c9 | 2002-05-20 23:38:33 +0000 | [diff] [blame] | 1602 | if (VG_(strstr)(ld_preload_str, "valgrinq.so") == NULL) |
| 1603 | goto mutancy; |
| 1604 | if (VG_(strstr)(ld_library_path_str, "lib/valgrinq") == NULL) |
| 1605 | goto mutancy; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1606 | return; |
sewardj | 3e1eb1f | 2002-05-18 13:14:17 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
sewardj | 78e25c9 | 2002-05-20 23:38:33 +0000 | [diff] [blame] | 1609 | what = 2; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1610 | if (sk_prel == NULL) goto mutancy; |
| 1611 | |
| 1612 | what = 3; |
sewardj | 78e25c9 | 2002-05-20 23:38:33 +0000 | [diff] [blame] | 1613 | if (p_path == NULL) goto mutancy; |
| 1614 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1615 | what = 4; |
| 1616 | { |
| 1617 | /* Blank from "vgskin_" back to prev. LD_PRELOAD entry, or start */ |
| 1618 | Char* p = sk_prel; |
| 1619 | while (*p != ':' && p > ld_preload_str) { |
| 1620 | *p = ' '; |
| 1621 | p--; |
| 1622 | } |
| 1623 | /* Blank from "vgskin_" to next LD_PRELOAD entry */ |
| 1624 | while (*p != ':' && *p != '\0') { |
| 1625 | *p = ' '; |
| 1626 | p++; |
| 1627 | } |
| 1628 | if (*p == '\0') goto mutancy; /* valgrind.so has disappeared?! */ |
| 1629 | *p = ' '; /* blank ending ':' */ |
| 1630 | } |
| 1631 | |
sewardj | 78e25c9 | 2002-05-20 23:38:33 +0000 | [diff] [blame] | 1632 | /* in LD_PRELOAD, turn valgrind.so into valgrinq.so. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1633 | what = 5; |
sewardj | 78e25c9 | 2002-05-20 23:38:33 +0000 | [diff] [blame] | 1634 | if (p_prel[7] != 'd') goto mutancy; |
| 1635 | p_prel[7] = 'q'; |
sewardj | 3e1eb1f | 2002-05-18 13:14:17 +0000 | [diff] [blame] | 1636 | |
| 1637 | /* in LD_LIBRARY_PATH, turn $libdir/valgrind (as configure'd) from |
| 1638 | .../lib/valgrind .../lib/valgrinq, which doesn't exist, |
| 1639 | so that our own libpthread.so goes out of scope. */ |
sewardj | 78e25c9 | 2002-05-20 23:38:33 +0000 | [diff] [blame] | 1640 | p_path += VG_(strlen)(VG_LIBDIR); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1641 | what = 6; |
sewardj | 78e25c9 | 2002-05-20 23:38:33 +0000 | [diff] [blame] | 1642 | if (p_path[0] != '/') goto mutancy; |
| 1643 | p_path++; /* step over / */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1644 | what = 7; |
sewardj | 78e25c9 | 2002-05-20 23:38:33 +0000 | [diff] [blame] | 1645 | if (p_path[7] != 'd') goto mutancy; |
| 1646 | p_path[7] = 'q'; |
| 1647 | return; |
| 1648 | |
| 1649 | mutancy: |
| 1650 | VG_(printf)( |
| 1651 | "\nVG_(mash_LD_PRELOAD_and_LD_LIBRARY_PATH): internal error:\n" |
| 1652 | " what = %d\n" |
| 1653 | " ld_preload_str = `%s'\n" |
| 1654 | " ld_library_path_str = `%s'\n" |
| 1655 | " p_prel = `%s'\n" |
| 1656 | " p_path = `%s'\n" |
| 1657 | " VG_LIBDIR = `%s'\n", |
sewardj | 19d8141 | 2002-06-03 01:10:40 +0000 | [diff] [blame] | 1658 | what, ld_preload_str, ld_library_path_str, |
| 1659 | p_prel, p_path, VG_LIBDIR |
| 1660 | ); |
sewardj | c26b448 | 2002-07-13 12:20:35 +0000 | [diff] [blame] | 1661 | VG_(printf)( |
| 1662 | "\n" |
| 1663 | "Note that this is often caused by mis-installation of valgrind.\n" |
| 1664 | "Correct installation procedure is:\n" |
| 1665 | " ./configure --prefix=/install/dir\n" |
| 1666 | " make install\n" |
| 1667 | "And then use /install/dir/bin/valgrind\n" |
| 1668 | "Moving the installation directory elsewhere after 'make install'\n" |
| 1669 | "will cause the above error. Hand-editing the paths in the shell\n" |
| 1670 | "scripts is also likely to cause problems.\n" |
| 1671 | "\n" |
| 1672 | ); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 1673 | VG_(core_panic)("VG_(mash_LD_PRELOAD_and_LD_LIBRARY_PATH) failed\n"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1674 | } |
| 1675 | |
sewardj | 3e1eb1f | 2002-05-18 13:14:17 +0000 | [diff] [blame] | 1676 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1677 | /* RUNS ON THE CLIENT'S STACK, but on the real CPU. Start GDB and get |
| 1678 | it to attach to this process. Called if the user requests this |
| 1679 | service after an error has been shown, so she can poke around and |
| 1680 | look at parameters, memory, etc. You can't meaningfully get GDB to |
| 1681 | continue the program, though; to continue, quit GDB. */ |
| 1682 | extern void VG_(start_GDB_whilst_on_client_stack) ( void ) |
| 1683 | { |
sewardj | e6a2524 | 2002-04-21 22:03:07 +0000 | [diff] [blame] | 1684 | Int res; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1685 | UChar buf[100]; |
| 1686 | VG_(sprintf)(buf, |
| 1687 | "/usr/bin/gdb -nw /proc/%d/exe %d", |
| 1688 | VG_(getpid)(), VG_(getpid)()); |
sewardj | e6a2524 | 2002-04-21 22:03:07 +0000 | [diff] [blame] | 1689 | VG_(message)(Vg_UserMsg, "starting GDB with cmd: %s", buf); |
| 1690 | res = VG_(system)(buf); |
| 1691 | if (res == 0) { |
| 1692 | VG_(message)(Vg_UserMsg, ""); |
| 1693 | VG_(message)(Vg_UserMsg, |
| 1694 | "GDB has detached. Valgrind regains control. We continue."); |
| 1695 | } else { |
| 1696 | VG_(message)(Vg_UserMsg, "Apparently failed!"); |
| 1697 | VG_(message)(Vg_UserMsg, ""); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1698 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | |
| 1702 | /* Print some helpful-ish text about unimplemented things, and give |
| 1703 | up. */ |
sewardj | cfc39b2 | 2002-05-08 01:58:18 +0000 | [diff] [blame] | 1704 | void VG_(unimplemented) ( Char* msg ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1705 | { |
| 1706 | VG_(message)(Vg_UserMsg, ""); |
| 1707 | VG_(message)(Vg_UserMsg, |
| 1708 | "Valgrind detected that your program requires"); |
| 1709 | VG_(message)(Vg_UserMsg, |
| 1710 | "the following unimplemented functionality:"); |
| 1711 | VG_(message)(Vg_UserMsg, " %s", msg); |
| 1712 | VG_(message)(Vg_UserMsg, |
| 1713 | "This may be because the functionality is hard to implement,"); |
| 1714 | VG_(message)(Vg_UserMsg, |
| 1715 | "or because no reasonable program would behave this way,"); |
| 1716 | VG_(message)(Vg_UserMsg, |
| 1717 | "or because nobody has yet needed it. In any case, let me know"); |
| 1718 | VG_(message)(Vg_UserMsg, |
| 1719 | "(jseward@acm.org) and/or try to work around the problem, if you can."); |
| 1720 | VG_(message)(Vg_UserMsg, |
| 1721 | ""); |
| 1722 | VG_(message)(Vg_UserMsg, |
| 1723 | "Valgrind has to exit now. Sorry. Bye!"); |
| 1724 | VG_(message)(Vg_UserMsg, |
| 1725 | ""); |
sewardj | 15a43e1 | 2002-04-17 19:35:12 +0000 | [diff] [blame] | 1726 | VG_(pp_sched_status)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1727 | VG_(exit)(1); |
| 1728 | } |
| 1729 | |
| 1730 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1731 | /* --------------------------------------------------------------------- |
| 1732 | Sanity check machinery (permanently engaged). |
| 1733 | ------------------------------------------------------------------ */ |
| 1734 | |
| 1735 | /* A fast sanity check -- suitable for calling circa once per |
| 1736 | millisecond. */ |
| 1737 | |
| 1738 | void VG_(do_sanity_checks) ( Bool force_expensive ) |
| 1739 | { |
| 1740 | Int i; |
| 1741 | |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1742 | VGP_PUSHCC(VgpCoreCheapSanity); |
| 1743 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1744 | if (VG_(sanity_level) < 1) return; |
| 1745 | |
| 1746 | /* --- First do all the tests that we can do quickly. ---*/ |
| 1747 | |
| 1748 | VG_(sanity_fast_count)++; |
| 1749 | |
| 1750 | /* Check that we haven't overrun our private stack. */ |
| 1751 | for (i = 0; i < 10; i++) { |
| 1752 | vg_assert(VG_(stack)[i] |
| 1753 | == ((UInt)(&VG_(stack)[i]) ^ 0xA4B3C2D1)); |
| 1754 | vg_assert(VG_(stack)[10000-1-i] |
| 1755 | == ((UInt)(&VG_(stack)[10000-i-1]) ^ 0xABCD4321)); |
| 1756 | } |
| 1757 | |
| 1758 | /* Check stuff pertaining to the memory check system. */ |
| 1759 | |
| 1760 | /* Check that nobody has spuriously claimed that the first or |
| 1761 | last 16 pages of memory have become accessible [...] */ |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1762 | if (VG_(needs).sanity_checks) { |
| 1763 | VGP_PUSHCC(VgpSkinCheapSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1764 | vg_assert(SK_(cheap_sanity_check)()); |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1765 | VGP_POPCC(VgpSkinCheapSanity); |
| 1766 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1767 | |
| 1768 | /* --- Now some more expensive checks. ---*/ |
| 1769 | |
| 1770 | /* Once every 25 times, check some more expensive stuff. */ |
| 1771 | if ( force_expensive |
| 1772 | || VG_(sanity_level) > 1 |
| 1773 | || (VG_(sanity_level) == 1 && (VG_(sanity_fast_count) % 25) == 0)) { |
| 1774 | |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1775 | VGP_PUSHCC(VgpCoreExpensiveSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1776 | VG_(sanity_slow_count)++; |
| 1777 | |
| 1778 | # if 0 |
| 1779 | { void zzzmemscan(void); zzzmemscan(); } |
| 1780 | # endif |
| 1781 | |
| 1782 | if ((VG_(sanity_fast_count) % 250) == 0) |
| 1783 | VG_(sanity_check_tc_tt)(); |
| 1784 | |
| 1785 | if (VG_(needs).sanity_checks) { |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1786 | VGP_PUSHCC(VgpSkinExpensiveSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1787 | vg_assert(SK_(expensive_sanity_check)()); |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1788 | VGP_POPCC(VgpSkinExpensiveSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1789 | } |
| 1790 | /* |
| 1791 | if ((VG_(sanity_fast_count) % 500) == 0) VG_(mallocSanityCheckAll)(); |
| 1792 | */ |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1793 | VGP_POPCC(VgpCoreExpensiveSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | if (VG_(sanity_level) > 1) { |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1797 | VGP_PUSHCC(VgpCoreExpensiveSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1798 | /* Check sanity of the low-level memory manager. Note that bugs |
| 1799 | in the client's code can cause this to fail, so we don't do |
| 1800 | this check unless specially asked for. And because it's |
| 1801 | potentially very expensive. */ |
| 1802 | VG_(mallocSanityCheckAll)(); |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1803 | VGP_POPCC(VgpCoreExpensiveSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1804 | } |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1805 | VGP_POPCC(VgpCoreCheapSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1806 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1807 | /*--------------------------------------------------------------------*/ |
| 1808 | /*--- end vg_main.c ---*/ |
| 1809 | /*--------------------------------------------------------------------*/ |