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 | |
nethercote | bb1c991 | 2004-01-04 16:43:23 +0000 | [diff] [blame] | 11 | Copyright (C) 2000-2004 Julian Seward |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 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 | |
fitzhardinge | b727d04 | 2004-01-06 00:18:21 +0000 | [diff] [blame^] | 34 | #include <stdlib.h> |
| 35 | #include <sys/ptrace.h> |
| 36 | #include <sys/signal.h> |
| 37 | #include <sys/user.h> |
| 38 | #include <sys/wait.h> |
| 39 | #include <unistd.h> |
| 40 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 41 | /* --------------------------------------------------------------------- |
| 42 | Compute offsets into baseBlock. See comments in vg_include.h. |
| 43 | ------------------------------------------------------------------ */ |
| 44 | |
| 45 | /* The variables storing offsets. */ |
| 46 | |
| 47 | #define INVALID_OFFSET (-1) |
| 48 | |
| 49 | Int VGOFF_(m_eax) = INVALID_OFFSET; |
| 50 | Int VGOFF_(m_ecx) = INVALID_OFFSET; |
| 51 | Int VGOFF_(m_edx) = INVALID_OFFSET; |
| 52 | Int VGOFF_(m_ebx) = INVALID_OFFSET; |
| 53 | Int VGOFF_(m_esp) = INVALID_OFFSET; |
| 54 | Int VGOFF_(m_ebp) = INVALID_OFFSET; |
| 55 | Int VGOFF_(m_esi) = INVALID_OFFSET; |
| 56 | Int VGOFF_(m_edi) = INVALID_OFFSET; |
| 57 | Int VGOFF_(m_eflags) = INVALID_OFFSET; |
sewardj | fa492d4 | 2002-12-08 18:20:01 +0000 | [diff] [blame] | 58 | Int VGOFF_(m_dflag) = INVALID_OFFSET; |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 59 | Int VGOFF_(m_ssestate) = INVALID_OFFSET; |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 60 | Int VGOFF_(ldt) = INVALID_OFFSET; |
| 61 | Int VGOFF_(m_cs) = INVALID_OFFSET; |
| 62 | Int VGOFF_(m_ss) = INVALID_OFFSET; |
| 63 | Int VGOFF_(m_ds) = INVALID_OFFSET; |
| 64 | Int VGOFF_(m_es) = INVALID_OFFSET; |
| 65 | Int VGOFF_(m_fs) = INVALID_OFFSET; |
| 66 | Int VGOFF_(m_gs) = INVALID_OFFSET; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 67 | Int VGOFF_(m_eip) = INVALID_OFFSET; |
| 68 | Int VGOFF_(spillslots) = INVALID_OFFSET; |
| 69 | Int VGOFF_(sh_eax) = INVALID_OFFSET; |
| 70 | Int VGOFF_(sh_ecx) = INVALID_OFFSET; |
| 71 | Int VGOFF_(sh_edx) = INVALID_OFFSET; |
| 72 | Int VGOFF_(sh_ebx) = INVALID_OFFSET; |
| 73 | Int VGOFF_(sh_esp) = INVALID_OFFSET; |
| 74 | Int VGOFF_(sh_ebp) = INVALID_OFFSET; |
| 75 | Int VGOFF_(sh_esi) = INVALID_OFFSET; |
| 76 | Int VGOFF_(sh_edi) = INVALID_OFFSET; |
| 77 | Int VGOFF_(sh_eflags) = INVALID_OFFSET; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 78 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 79 | Int VGOFF_(helper_idiv_64_32) = INVALID_OFFSET; |
| 80 | Int VGOFF_(helper_div_64_32) = INVALID_OFFSET; |
| 81 | Int VGOFF_(helper_idiv_32_16) = INVALID_OFFSET; |
| 82 | Int VGOFF_(helper_div_32_16) = INVALID_OFFSET; |
| 83 | Int VGOFF_(helper_idiv_16_8) = INVALID_OFFSET; |
| 84 | Int VGOFF_(helper_div_16_8) = INVALID_OFFSET; |
| 85 | Int VGOFF_(helper_imul_32_64) = INVALID_OFFSET; |
| 86 | Int VGOFF_(helper_mul_32_64) = INVALID_OFFSET; |
| 87 | Int VGOFF_(helper_imul_16_32) = INVALID_OFFSET; |
| 88 | Int VGOFF_(helper_mul_16_32) = INVALID_OFFSET; |
| 89 | Int VGOFF_(helper_imul_8_16) = INVALID_OFFSET; |
| 90 | Int VGOFF_(helper_mul_8_16) = INVALID_OFFSET; |
| 91 | Int VGOFF_(helper_CLD) = INVALID_OFFSET; |
| 92 | Int VGOFF_(helper_STD) = INVALID_OFFSET; |
| 93 | Int VGOFF_(helper_get_dirflag) = INVALID_OFFSET; |
sewardj | 7d78e78 | 2002-06-02 00:04:00 +0000 | [diff] [blame] | 94 | Int VGOFF_(helper_CLC) = INVALID_OFFSET; |
| 95 | Int VGOFF_(helper_STC) = INVALID_OFFSET; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 96 | Int VGOFF_(helper_shldl) = INVALID_OFFSET; |
| 97 | Int VGOFF_(helper_shldw) = INVALID_OFFSET; |
| 98 | Int VGOFF_(helper_shrdl) = INVALID_OFFSET; |
| 99 | Int VGOFF_(helper_shrdw) = INVALID_OFFSET; |
daywalker | b18d253 | 2003-09-27 20:15:01 +0000 | [diff] [blame] | 100 | Int VGOFF_(helper_IN) = INVALID_OFFSET; |
| 101 | Int VGOFF_(helper_OUT) = INVALID_OFFSET; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 102 | Int VGOFF_(helper_RDTSC) = INVALID_OFFSET; |
| 103 | Int VGOFF_(helper_CPUID) = INVALID_OFFSET; |
| 104 | Int VGOFF_(helper_BSWAP) = INVALID_OFFSET; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 105 | Int VGOFF_(helper_bsf) = INVALID_OFFSET; |
| 106 | Int VGOFF_(helper_bsr) = INVALID_OFFSET; |
| 107 | Int VGOFF_(helper_fstsw_AX) = INVALID_OFFSET; |
| 108 | Int VGOFF_(helper_SAHF) = INVALID_OFFSET; |
njn | d6251f1 | 2003-06-03 13:38:51 +0000 | [diff] [blame] | 109 | Int VGOFF_(helper_LAHF) = INVALID_OFFSET; |
sewardj | 4d0ab1f | 2002-03-24 10:00:09 +0000 | [diff] [blame] | 110 | Int VGOFF_(helper_DAS) = INVALID_OFFSET; |
sewardj | fe8a166 | 2002-03-24 11:54:07 +0000 | [diff] [blame] | 111 | Int VGOFF_(helper_DAA) = INVALID_OFFSET; |
mueller | f217c73 | 2004-01-02 22:42:29 +0000 | [diff] [blame] | 112 | Int VGOFF_(helper_cmpxchg8b) = INVALID_OFFSET; |
sewardj | 5109643 | 2002-12-14 23:59:09 +0000 | [diff] [blame] | 113 | Int VGOFF_(helper_undefined_instruction) = INVALID_OFFSET; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 114 | |
| 115 | /* MAX_NONCOMPACT_HELPERS can be increased easily. If MAX_COMPACT_HELPERS is |
| 116 | * increased too much, they won't really be compact any more... */ |
| 117 | #define MAX_COMPACT_HELPERS 8 |
njn | fedb736 | 2003-02-24 10:21:45 +0000 | [diff] [blame] | 118 | #define MAX_NONCOMPACT_HELPERS 50 |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 119 | |
| 120 | UInt VG_(n_compact_helpers) = 0; |
| 121 | UInt VG_(n_noncompact_helpers) = 0; |
| 122 | |
| 123 | Addr VG_(compact_helper_addrs) [MAX_COMPACT_HELPERS]; |
| 124 | Int VG_(compact_helper_offsets)[MAX_COMPACT_HELPERS]; |
| 125 | Addr VG_(noncompact_helper_addrs) [MAX_NONCOMPACT_HELPERS]; |
| 126 | Int VG_(noncompact_helper_offsets)[MAX_NONCOMPACT_HELPERS]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 127 | |
| 128 | /* This is the actual defn of baseblock. */ |
| 129 | UInt VG_(baseBlock)[VG_BASEBLOCK_WORDS]; |
| 130 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 131 | /* Client address space */ |
| 132 | Addr VG_(client_base); /* client address space limits */ |
| 133 | Addr VG_(client_end); |
| 134 | Addr VG_(client_mapbase); |
fitzhardinge | 9236079 | 2003-12-24 10:11:11 +0000 | [diff] [blame] | 135 | Addr VG_(client_trampoline_code); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 136 | Addr VG_(clstk_base); |
| 137 | Addr VG_(clstk_end); |
| 138 | Addr VG_(brk_base); /* start of brk */ |
| 139 | Addr VG_(brk_limit); /* current brk */ |
| 140 | Addr VG_(shadow_base); /* skin's shadow memory */ |
| 141 | Addr VG_(shadow_end); |
| 142 | Addr VG_(valgrind_base); /* valgrind's address range */ |
| 143 | Addr VG_(valgrind_mmap_end); /* valgrind's mmaps are between valgrind_base and here */ |
| 144 | Addr VG_(valgrind_end); |
| 145 | |
| 146 | /* stage1 (main) executable */ |
fitzhardinge | a49f9b5 | 2003-12-16 22:26:45 +0000 | [diff] [blame] | 147 | Int VG_(vgexecfd) = -1; |
| 148 | |
| 149 | /* client executable */ |
| 150 | Int VG_(clexecfd) = -1; |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 151 | |
| 152 | /* Path to library directory */ |
| 153 | const Char *VG_(libdir) = VG_LIBDIR; |
| 154 | |
| 155 | /* our argc/argv */ |
| 156 | Int VG_(vg_argc); |
| 157 | Char **VG_(vg_argv); |
| 158 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 159 | /* PID of the main thread */ |
| 160 | Int VG_(main_pid); |
| 161 | |
| 162 | /* PGRP of process */ |
| 163 | Int VG_(main_pgrp); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 164 | |
fitzhardinge | f0046f2 | 2003-12-18 02:39:22 +0000 | [diff] [blame] | 165 | /* Maximum allowed application-visible file descriptor */ |
fitzhardinge | b791a19 | 2003-12-18 07:22:44 +0000 | [diff] [blame] | 166 | Int VG_(max_fd) = -1; |
fitzhardinge | f0046f2 | 2003-12-18 02:39:22 +0000 | [diff] [blame] | 167 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 168 | /* Words. */ |
| 169 | static Int baB_off = 0; |
| 170 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 171 | /* jmp_buf for fatal signals */ |
| 172 | Int VG_(fatal_sigNo) = -1; |
| 173 | Bool VG_(fatal_signal_set) = False; |
| 174 | jmp_buf VG_(fatal_signal_jmpbuf); |
| 175 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 176 | /* Returns the offset, in words. */ |
| 177 | static Int alloc_BaB ( Int words ) |
| 178 | { |
| 179 | Int off = baB_off; |
| 180 | baB_off += words; |
| 181 | if (baB_off >= VG_BASEBLOCK_WORDS) |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 182 | VG_(core_panic)( "alloc_BaB: baseBlock is too small"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 183 | |
| 184 | return off; |
| 185 | } |
| 186 | |
njn | 0c7a5b5 | 2003-04-30 09:00:33 +0000 | [diff] [blame] | 187 | /* Align offset, in *bytes* */ |
| 188 | static void align_BaB ( UInt align ) |
| 189 | { |
| 190 | vg_assert(2 == align || 4 == align || 8 == align || 16 == align); |
| 191 | baB_off += (align-1); |
| 192 | baB_off &= ~(align-1); |
| 193 | } |
| 194 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 195 | /* Allocate 1 word in baseBlock and set it to the given value. */ |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 196 | static Int alloc_BaB_1_set ( Addr a ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 197 | { |
| 198 | Int off = alloc_BaB(1); |
| 199 | VG_(baseBlock)[off] = (UInt)a; |
| 200 | return off; |
| 201 | } |
| 202 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 203 | /* Registers a function in compact_helper_addrs; compact_helper_offsets is |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 204 | filled in later. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 205 | void VG_(register_compact_helper)(Addr a) |
| 206 | { |
| 207 | if (MAX_COMPACT_HELPERS <= VG_(n_compact_helpers)) { |
| 208 | VG_(printf)("Can only register %d compact helpers\n", |
| 209 | MAX_COMPACT_HELPERS); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 210 | VG_(core_panic)("Too many compact helpers registered"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 211 | } |
| 212 | VG_(compact_helper_addrs)[VG_(n_compact_helpers)] = a; |
| 213 | VG_(n_compact_helpers)++; |
| 214 | } |
| 215 | |
| 216 | /* Registers a function in noncompact_helper_addrs; noncompact_helper_offsets |
| 217 | * is filled in later. |
| 218 | */ |
| 219 | void VG_(register_noncompact_helper)(Addr a) |
| 220 | { |
| 221 | if (MAX_NONCOMPACT_HELPERS <= VG_(n_noncompact_helpers)) { |
| 222 | VG_(printf)("Can only register %d non-compact helpers\n", |
| 223 | MAX_NONCOMPACT_HELPERS); |
| 224 | VG_(printf)("Try increasing MAX_NON_COMPACT_HELPERS\n"); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 225 | VG_(core_panic)("Too many non-compact helpers registered"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 226 | } |
| 227 | VG_(noncompact_helper_addrs)[VG_(n_noncompact_helpers)] = a; |
| 228 | VG_(n_noncompact_helpers)++; |
| 229 | } |
| 230 | |
| 231 | /* Allocate offsets in baseBlock for the skin helpers */ |
sewardj | 05bcdcb | 2003-05-18 10:05:38 +0000 | [diff] [blame] | 232 | static |
| 233 | void assign_helpers_in_baseBlock(UInt n, Int offsets[], Addr addrs[]) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 234 | { |
sewardj | 05bcdcb | 2003-05-18 10:05:38 +0000 | [diff] [blame] | 235 | UInt i; |
| 236 | for (i = 0; i < n; i++) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 237 | offsets[i] = alloc_BaB_1_set( addrs[i] ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 238 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 239 | |
njn | f4ce3d3 | 2003-02-10 10:17:26 +0000 | [diff] [blame] | 240 | Bool VG_(need_to_handle_esp_assignment)(void) |
| 241 | { |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 242 | return ( VG_(defined_new_mem_stack_4)() || |
| 243 | VG_(defined_die_mem_stack_4)() || |
| 244 | VG_(defined_new_mem_stack_8)() || |
| 245 | VG_(defined_die_mem_stack_8)() || |
| 246 | VG_(defined_new_mem_stack_12)() || |
| 247 | VG_(defined_die_mem_stack_12)() || |
| 248 | VG_(defined_new_mem_stack_16)() || |
| 249 | VG_(defined_die_mem_stack_16)() || |
| 250 | VG_(defined_new_mem_stack_32)() || |
| 251 | VG_(defined_die_mem_stack_32)() || |
| 252 | VG_(defined_new_mem_stack)() || |
| 253 | VG_(defined_die_mem_stack)() |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 254 | ); |
njn | f4ce3d3 | 2003-02-10 10:17:26 +0000 | [diff] [blame] | 255 | } |
| 256 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 257 | /* Here we assign actual offsets. It's important to get the most |
| 258 | popular referents within 128 bytes of the start, so we can take |
| 259 | advantage of short addressing modes relative to %ebp. Popularity |
| 260 | of offsets was measured on 22 Feb 02 running a KDE application, and |
| 261 | the slots rearranged accordingly, with a 1.5% reduction in total |
| 262 | size of translations. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 263 | static void vg_init_baseBlock ( void ) |
| 264 | { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 265 | /* Those with offsets under 128 are carefully chosen. */ |
| 266 | |
| 267 | /* WORD offsets in this column */ |
| 268 | /* 0 */ VGOFF_(m_eax) = alloc_BaB(1); |
| 269 | /* 1 */ VGOFF_(m_ecx) = alloc_BaB(1); |
| 270 | /* 2 */ VGOFF_(m_edx) = alloc_BaB(1); |
| 271 | /* 3 */ VGOFF_(m_ebx) = alloc_BaB(1); |
| 272 | /* 4 */ VGOFF_(m_esp) = alloc_BaB(1); |
| 273 | /* 5 */ VGOFF_(m_ebp) = alloc_BaB(1); |
| 274 | /* 6 */ VGOFF_(m_esi) = alloc_BaB(1); |
| 275 | /* 7 */ VGOFF_(m_edi) = alloc_BaB(1); |
| 276 | /* 8 */ VGOFF_(m_eflags) = alloc_BaB(1); |
| 277 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 278 | if (VG_(needs).shadow_regs) { |
| 279 | /* 9 */ VGOFF_(sh_eax) = alloc_BaB(1); |
| 280 | /* 10 */ VGOFF_(sh_ecx) = alloc_BaB(1); |
| 281 | /* 11 */ VGOFF_(sh_edx) = alloc_BaB(1); |
| 282 | /* 12 */ VGOFF_(sh_ebx) = alloc_BaB(1); |
| 283 | /* 13 */ VGOFF_(sh_esp) = alloc_BaB(1); |
| 284 | /* 14 */ VGOFF_(sh_ebp) = alloc_BaB(1); |
| 285 | /* 15 */ VGOFF_(sh_esi) = alloc_BaB(1); |
| 286 | /* 16 */ VGOFF_(sh_edi) = alloc_BaB(1); |
| 287 | /* 17 */ VGOFF_(sh_eflags) = alloc_BaB(1); |
| 288 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 289 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 290 | /* 9,10,11 or 18,19,20... depends on number whether shadow regs are used |
| 291 | * and on compact helpers registered */ |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 292 | |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 293 | /* Make these most-frequently-called specialised ones compact, if they |
| 294 | are used. */ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 295 | if (VG_(defined_new_mem_stack_4)()) |
| 296 | VG_(register_compact_helper)( (Addr) VG_(tool_interface).track_new_mem_stack_4); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 297 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 298 | if (VG_(defined_die_mem_stack_4)()) |
| 299 | VG_(register_compact_helper)( (Addr) VG_(tool_interface).track_die_mem_stack_4); |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 300 | |
| 301 | /* (9 or 18) + n_compact_helpers */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 302 | /* Allocate slots for compact helpers */ |
| 303 | assign_helpers_in_baseBlock(VG_(n_compact_helpers), |
| 304 | VG_(compact_helper_offsets), |
| 305 | VG_(compact_helper_addrs)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 306 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 307 | /* (9/10 or 18/19) + n_compact_helpers */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 308 | VGOFF_(m_eip) = alloc_BaB(1); |
| 309 | |
| 310 | /* There are currently 24 spill slots */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 311 | /* (11+/20+ .. 32+/43+) + n_compact_helpers. This can overlap the magic |
| 312 | * boundary at >= 32 words, but most spills are to low numbered spill |
| 313 | * slots, so the ones above the boundary don't see much action. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 314 | VGOFF_(spillslots) = alloc_BaB(VG_MAX_SPILLSLOTS); |
| 315 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 316 | /* I gave up counting at this point. Since they're above the |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 317 | short-amode-boundary, there's no point. */ |
| 318 | |
sewardj | fa492d4 | 2002-12-08 18:20:01 +0000 | [diff] [blame] | 319 | VGOFF_(m_dflag) = alloc_BaB(1); |
| 320 | |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 321 | /* The FPU/SSE state. This _must_ be 16-byte aligned. */ |
njn | 0c7a5b5 | 2003-04-30 09:00:33 +0000 | [diff] [blame] | 322 | align_BaB(16); |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 323 | VGOFF_(m_ssestate) = alloc_BaB(VG_SIZE_OF_SSESTATE_W); |
| 324 | vg_assert( |
| 325 | ( ((UInt)(& VG_(baseBlock)[VGOFF_(m_ssestate)])) |
| 326 | % 16 ) |
| 327 | == 0 |
| 328 | ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 329 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 330 | /* This thread's LDT pointer, and segment registers. */ |
| 331 | VGOFF_(ldt) = alloc_BaB(1); |
| 332 | VGOFF_(m_cs) = alloc_BaB(1); |
| 333 | VGOFF_(m_ss) = alloc_BaB(1); |
| 334 | VGOFF_(m_ds) = alloc_BaB(1); |
| 335 | VGOFF_(m_es) = alloc_BaB(1); |
| 336 | VGOFF_(m_fs) = alloc_BaB(1); |
| 337 | VGOFF_(m_gs) = alloc_BaB(1); |
| 338 | |
sewardj | e104247 | 2002-09-30 12:33:11 +0000 | [diff] [blame] | 339 | VG_(register_noncompact_helper)( (Addr) & VG_(do_useseg) ); |
| 340 | |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 341 | #define REG(kind, size) \ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 342 | if (VG_(defined_##kind##_mem_stack##size)()) \ |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 343 | VG_(register_noncompact_helper)( \ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 344 | (Addr) VG_(tool_interface).track_##kind##_mem_stack##size ); |
njn | 9b007f6 | 2003-04-07 14:40:25 +0000 | [diff] [blame] | 345 | |
| 346 | REG(new, _8); |
| 347 | REG(new, _12); |
| 348 | REG(new, _16); |
| 349 | REG(new, _32); |
| 350 | REG(new, ); |
| 351 | REG(die, _8); |
| 352 | REG(die, _12); |
| 353 | REG(die, _16); |
| 354 | REG(die, _32); |
| 355 | REG(die, ); |
| 356 | #undef REG |
| 357 | |
| 358 | if (VG_(need_to_handle_esp_assignment)()) |
| 359 | VG_(register_noncompact_helper)((Addr) VG_(unknown_esp_update)); |
| 360 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 361 | /* Helper functions. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 362 | VGOFF_(helper_idiv_64_32) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 363 | = alloc_BaB_1_set( (Addr) & VG_(helper_idiv_64_32)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 364 | VGOFF_(helper_div_64_32) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 365 | = alloc_BaB_1_set( (Addr) & VG_(helper_div_64_32)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 366 | VGOFF_(helper_idiv_32_16) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 367 | = alloc_BaB_1_set( (Addr) & VG_(helper_idiv_32_16)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 368 | VGOFF_(helper_div_32_16) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 369 | = alloc_BaB_1_set( (Addr) & VG_(helper_div_32_16)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 370 | VGOFF_(helper_idiv_16_8) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 371 | = alloc_BaB_1_set( (Addr) & VG_(helper_idiv_16_8)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 372 | VGOFF_(helper_div_16_8) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 373 | = alloc_BaB_1_set( (Addr) & VG_(helper_div_16_8)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 374 | |
| 375 | VGOFF_(helper_imul_32_64) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 376 | = alloc_BaB_1_set( (Addr) & VG_(helper_imul_32_64)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 377 | VGOFF_(helper_mul_32_64) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 378 | = alloc_BaB_1_set( (Addr) & VG_(helper_mul_32_64)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 379 | VGOFF_(helper_imul_16_32) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 380 | = alloc_BaB_1_set( (Addr) & VG_(helper_imul_16_32)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 381 | VGOFF_(helper_mul_16_32) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 382 | = alloc_BaB_1_set( (Addr) & VG_(helper_mul_16_32)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 383 | VGOFF_(helper_imul_8_16) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 384 | = alloc_BaB_1_set( (Addr) & VG_(helper_imul_8_16)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 385 | VGOFF_(helper_mul_8_16) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 386 | = alloc_BaB_1_set( (Addr) & VG_(helper_mul_8_16)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 387 | |
| 388 | VGOFF_(helper_CLD) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 389 | = alloc_BaB_1_set( (Addr) & VG_(helper_CLD)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 390 | VGOFF_(helper_STD) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 391 | = alloc_BaB_1_set( (Addr) & VG_(helper_STD)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 392 | VGOFF_(helper_get_dirflag) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 393 | = alloc_BaB_1_set( (Addr) & VG_(helper_get_dirflag)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 394 | |
sewardj | 7d78e78 | 2002-06-02 00:04:00 +0000 | [diff] [blame] | 395 | VGOFF_(helper_CLC) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 396 | = alloc_BaB_1_set( (Addr) & VG_(helper_CLC)); |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 397 | VGOFF_(helper_STC) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 398 | = alloc_BaB_1_set( (Addr) & VG_(helper_STC)); |
sewardj | 7d78e78 | 2002-06-02 00:04:00 +0000 | [diff] [blame] | 399 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 400 | VGOFF_(helper_shldl) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 401 | = alloc_BaB_1_set( (Addr) & VG_(helper_shldl)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 402 | VGOFF_(helper_shldw) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 403 | = alloc_BaB_1_set( (Addr) & VG_(helper_shldw)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 404 | VGOFF_(helper_shrdl) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 405 | = alloc_BaB_1_set( (Addr) & VG_(helper_shrdl)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 406 | VGOFF_(helper_shrdw) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 407 | = alloc_BaB_1_set( (Addr) & VG_(helper_shrdw)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 408 | |
| 409 | VGOFF_(helper_RDTSC) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 410 | = alloc_BaB_1_set( (Addr) & VG_(helper_RDTSC)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 411 | VGOFF_(helper_CPUID) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 412 | = alloc_BaB_1_set( (Addr) & VG_(helper_CPUID)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 413 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 414 | VGOFF_(helper_bsf) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 415 | = alloc_BaB_1_set( (Addr) & VG_(helper_bsf)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 416 | VGOFF_(helper_bsr) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 417 | = alloc_BaB_1_set( (Addr) & VG_(helper_bsr)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 418 | |
| 419 | VGOFF_(helper_fstsw_AX) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 420 | = alloc_BaB_1_set( (Addr) & VG_(helper_fstsw_AX)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 421 | VGOFF_(helper_SAHF) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 422 | = alloc_BaB_1_set( (Addr) & VG_(helper_SAHF)); |
njn | d6251f1 | 2003-06-03 13:38:51 +0000 | [diff] [blame] | 423 | VGOFF_(helper_LAHF) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 424 | = alloc_BaB_1_set( (Addr) & VG_(helper_LAHF)); |
sewardj | 4d0ab1f | 2002-03-24 10:00:09 +0000 | [diff] [blame] | 425 | VGOFF_(helper_DAS) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 426 | = alloc_BaB_1_set( (Addr) & VG_(helper_DAS)); |
sewardj | fe8a166 | 2002-03-24 11:54:07 +0000 | [diff] [blame] | 427 | VGOFF_(helper_DAA) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 428 | = alloc_BaB_1_set( (Addr) & VG_(helper_DAA)); |
daywalker | b18d253 | 2003-09-27 20:15:01 +0000 | [diff] [blame] | 429 | VGOFF_(helper_IN) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 430 | = alloc_BaB_1_set( (Addr) & VG_(helper_IN)); |
daywalker | b18d253 | 2003-09-27 20:15:01 +0000 | [diff] [blame] | 431 | VGOFF_(helper_OUT) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 432 | = alloc_BaB_1_set( (Addr) & VG_(helper_OUT)); |
mueller | f217c73 | 2004-01-02 22:42:29 +0000 | [diff] [blame] | 433 | VGOFF_(helper_cmpxchg8b) |
| 434 | = alloc_BaB_1_set( (Addr) & VG_(helper_cmpxchg8b)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 435 | |
sewardj | 5109643 | 2002-12-14 23:59:09 +0000 | [diff] [blame] | 436 | VGOFF_(helper_undefined_instruction) |
daywalker | b106c42 | 2003-09-29 10:56:24 +0000 | [diff] [blame] | 437 | = alloc_BaB_1_set( (Addr) & VG_(helper_undefined_instruction)); |
sewardj | 5109643 | 2002-12-14 23:59:09 +0000 | [diff] [blame] | 438 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 439 | /* Allocate slots for noncompact helpers */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 440 | assign_helpers_in_baseBlock(VG_(n_noncompact_helpers), |
| 441 | VG_(noncompact_helper_offsets), |
| 442 | VG_(noncompact_helper_addrs)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 443 | |
njn | cc7bb47 | 2002-10-14 09:25:19 +0000 | [diff] [blame] | 444 | |
| 445 | /* Initialise slots that require it */ |
| 446 | VG_(copy_m_state_static_to_baseBlock)(); |
| 447 | |
| 448 | /* Pretend the root thread has a completely empty LDT to start with. */ |
| 449 | VG_(baseBlock)[VGOFF_(ldt)] = (UInt)NULL; |
| 450 | |
| 451 | /* Initialise shadow regs */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 452 | if (VG_(needs).shadow_regs) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 453 | VG_(baseBlock)[VGOFF_(sh_esp)] = |
| 454 | VG_(baseBlock)[VGOFF_(sh_ebp)] = |
| 455 | VG_(baseBlock)[VGOFF_(sh_eax)] = |
| 456 | VG_(baseBlock)[VGOFF_(sh_ecx)] = |
| 457 | VG_(baseBlock)[VGOFF_(sh_edx)] = |
| 458 | VG_(baseBlock)[VGOFF_(sh_ebx)] = |
| 459 | VG_(baseBlock)[VGOFF_(sh_esi)] = |
njn | d304045 | 2003-05-19 15:04:06 +0000 | [diff] [blame] | 460 | VG_(baseBlock)[VGOFF_(sh_edi)] = 0; |
| 461 | VG_(baseBlock)[VGOFF_(sh_eflags)] = 0; |
| 462 | VG_TRACK( post_regs_write_init ); |
njn | cc7bb47 | 2002-10-14 09:25:19 +0000 | [diff] [blame] | 463 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | |
| 467 | /* --------------------------------------------------------------------- |
| 468 | Global entities which are not referenced from generated code. |
| 469 | ------------------------------------------------------------------ */ |
| 470 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 471 | /* Ditto our signal delivery stack. */ |
njn | 6eba4ef | 2003-05-01 08:06:41 +0000 | [diff] [blame] | 472 | UInt VG_(sigstack)[VG_SIGSTACK_SIZE_W]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 473 | |
| 474 | /* Saving stuff across system calls. */ |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 475 | __attribute__ ((aligned (16))) |
| 476 | UInt VG_(real_sse_state_saved_over_syscall)[VG_SIZE_OF_SSESTATE_W]; |
sewardj | 43c356f | 2002-06-02 00:21:08 +0000 | [diff] [blame] | 477 | Addr VG_(esp_saved_over_syscall); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 478 | |
| 479 | /* Counts downwards in vg_run_innerloop. */ |
| 480 | UInt VG_(dispatch_ctr); |
| 481 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 482 | |
| 483 | /* 64-bit counter for the number of basic blocks done. */ |
| 484 | ULong VG_(bbs_done); |
| 485 | /* 64-bit counter for the number of bbs to go before a debug exit. */ |
| 486 | ULong VG_(bbs_to_go); |
| 487 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 488 | /* This is the ThreadId of the last thread the scheduler ran. */ |
| 489 | ThreadId VG_(last_run_tid) = 0; |
| 490 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 491 | /* This is the argument to __NR_exit() supplied by the first thread to |
| 492 | call that syscall. We eventually pass that to __NR_exit() for |
| 493 | real. */ |
njn | 633de32 | 2003-05-12 20:40:13 +0000 | [diff] [blame] | 494 | Int VG_(exitcode) = 0; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 495 | |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 496 | /* Tell the logging mechanism whether we are logging to a file |
| 497 | descriptor or a socket descriptor. */ |
| 498 | Bool VG_(logging_to_filedes) = True; |
| 499 | |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 500 | /* Is this a SSE/SSE2-capable CPU? If so, we had better save/restore |
| 501 | the SSE state all over the place. This is set up very early, in |
| 502 | vg_startup.S. We have to determine it early since we can't even |
| 503 | correctly snapshot the startup machine state without it. */ |
| 504 | /* Initially True. Safer to err on the side of SSEness and get SIGILL |
daywalker | 7e73e5f | 2003-07-04 16:18:15 +0000 | [diff] [blame] | 505 | than to not notice for some reason that we have SSE and get weird |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 506 | errors later on. */ |
| 507 | Bool VG_(have_ssestate) = True; |
| 508 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 509 | |
| 510 | /* --------------------------------------------------------------------- |
| 511 | Counters, for informational purposes only. |
| 512 | ------------------------------------------------------------------ */ |
| 513 | |
| 514 | /* Number of lookups which miss the fast tt helper. */ |
| 515 | UInt VG_(tt_fast_misses) = 0; |
| 516 | |
| 517 | |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 518 | /* Counts for TT/TC informational messages. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 519 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 520 | /* Number and total o/t size of translations overall. */ |
| 521 | UInt VG_(overall_in_count) = 0; |
| 522 | UInt VG_(overall_in_osize) = 0; |
| 523 | UInt VG_(overall_in_tsize) = 0; |
| 524 | /* Number and total o/t size of discards overall. */ |
| 525 | UInt VG_(overall_out_count) = 0; |
| 526 | UInt VG_(overall_out_osize) = 0; |
| 527 | UInt VG_(overall_out_tsize) = 0; |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 528 | /* The number of discards of TT/TC. */ |
| 529 | UInt VG_(number_of_tc_discards) = 0; |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 530 | /* Counts of chain and unchain operations done. */ |
| 531 | UInt VG_(bb_enchain_count) = 0; |
| 532 | UInt VG_(bb_dechain_count) = 0; |
| 533 | /* Number of unchained jumps performed. */ |
| 534 | UInt VG_(unchained_jumps_done) = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 535 | |
| 536 | |
| 537 | /* Counts pertaining to the register allocator. */ |
| 538 | |
| 539 | /* total number of uinstrs input to reg-alloc */ |
| 540 | UInt VG_(uinstrs_prealloc) = 0; |
| 541 | |
| 542 | /* total number of uinstrs added due to spill code */ |
| 543 | UInt VG_(uinstrs_spill) = 0; |
| 544 | |
| 545 | /* number of bbs requiring spill code */ |
| 546 | UInt VG_(translations_needing_spill) = 0; |
| 547 | |
| 548 | /* total of register ranks over all translations */ |
| 549 | UInt VG_(total_reg_rank) = 0; |
| 550 | |
| 551 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 552 | /* Counts pertaining to internal sanity checking. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 553 | UInt VG_(sanity_fast_count) = 0; |
| 554 | UInt VG_(sanity_slow_count) = 0; |
| 555 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 556 | /* Counts pertaining to the scheduler. */ |
| 557 | UInt VG_(num_scheduling_events_MINOR) = 0; |
| 558 | UInt VG_(num_scheduling_events_MAJOR) = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 559 | |
| 560 | |
| 561 | /* --------------------------------------------------------------------- |
| 562 | Values derived from command-line options. |
| 563 | ------------------------------------------------------------------ */ |
| 564 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 565 | /* Define, and set defaults. */ |
| 566 | Bool VG_(clo_error_limit) = True; |
| 567 | Bool VG_(clo_GDB_attach) = False; |
sewardj | 6024b21 | 2003-07-13 10:54:33 +0000 | [diff] [blame] | 568 | Char* VG_(clo_GDB_path) = GDB_PATH; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 569 | Bool VG_(clo_gen_suppressions) = False; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 570 | Int VG_(sanity_level) = 1; |
| 571 | Int VG_(clo_verbosity) = 1; |
| 572 | Bool VG_(clo_demangle) = True; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 573 | Bool VG_(clo_trace_children) = False; |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 574 | |
nethercote | e173069 | 2003-11-20 10:38:07 +0000 | [diff] [blame] | 575 | /* See big comment in vg_include.h for meaning of these three. |
| 576 | fd is initially stdout, for --help, but gets moved to stderr by default |
| 577 | immediately afterwards. */ |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 578 | VgLogTo VG_(clo_log_to) = VgLogTo_Fd; |
nethercote | e173069 | 2003-11-20 10:38:07 +0000 | [diff] [blame] | 579 | Int VG_(clo_logfile_fd) = 1; |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 580 | Char* VG_(clo_logfile_name) = NULL; |
| 581 | |
sewardj | 6024b21 | 2003-07-13 10:54:33 +0000 | [diff] [blame] | 582 | Int VG_(clo_input_fd) = 0; /* stdin */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 583 | Int VG_(clo_n_suppressions) = 0; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 584 | Char* VG_(clo_suppressions)[VG_CLO_MAX_SFILES]; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 585 | Bool VG_(clo_profile) = False; |
| 586 | Bool VG_(clo_single_step) = False; |
| 587 | Bool VG_(clo_optimise) = True; |
| 588 | UChar VG_(clo_trace_codegen) = 0; // 00000000b |
| 589 | Bool VG_(clo_trace_syscalls) = False; |
| 590 | Bool VG_(clo_trace_signals) = False; |
| 591 | Bool VG_(clo_trace_symtab) = False; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 592 | Bool VG_(clo_trace_sched) = False; |
| 593 | Int VG_(clo_trace_pthread_level) = 0; |
sewardj | 59438c0 | 2003-01-05 12:16:30 +0000 | [diff] [blame] | 594 | ULong VG_(clo_stop_after) = 1000000000000000LL; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 595 | Int VG_(clo_dump_error) = 0; |
| 596 | Int VG_(clo_backtrace_size) = 4; |
| 597 | Char* VG_(clo_weird_hacks) = NULL; |
sewardj | 858964b | 2002-10-05 14:15:43 +0000 | [diff] [blame] | 598 | Bool VG_(clo_run_libc_freeres) = True; |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 599 | Bool VG_(clo_track_fds) = False; |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 600 | Bool VG_(clo_chain_bb) = True; |
nethercote | 77eba60 | 2003-11-13 17:35:04 +0000 | [diff] [blame] | 601 | Bool VG_(clo_show_below_main) = False; |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 602 | Bool VG_(clo_pointercheck) = True; |
fitzhardinge | 462f4f9 | 2003-12-18 02:10:54 +0000 | [diff] [blame] | 603 | Bool VG_(clo_branchpred) = False; |
sewardj | 2370f3b | 2002-11-30 15:01:01 +0000 | [diff] [blame] | 604 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 605 | static Bool VG_(clo_wait_for_gdb) = False; |
| 606 | |
| 607 | /* If we're doing signal routing, poll for signals every 50mS by |
| 608 | default. */ |
| 609 | Int VG_(clo_signal_polltime) = 50; |
| 610 | |
| 611 | /* These flags reduce thread wakeup latency on syscall completion and |
| 612 | signal delivery, respectively. The downside is possible unfairness. */ |
| 613 | Bool VG_(clo_lowlat_syscalls) = False; /* low-latency syscalls */ |
| 614 | Bool VG_(clo_lowlat_signals) = False; /* low-latency signals */ |
| 615 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 616 | /* This Bool is needed by wrappers in vg_clientmalloc.c to decide how |
| 617 | to behave. Initially we say False. */ |
| 618 | Bool VG_(running_on_simd_CPU) = False; |
| 619 | |
| 620 | /* Holds client's %esp at the point we gained control. */ |
| 621 | Addr VG_(esp_at_startup); |
| 622 | |
sewardj | d5815ec | 2003-04-06 12:23:27 +0000 | [diff] [blame] | 623 | /* Indicates presence, and holds address of client's sysinfo page, a |
| 624 | feature of some modern kernels used to provide vsyscalls, etc. */ |
| 625 | Bool VG_(sysinfo_page_exists) = False; |
| 626 | Addr VG_(sysinfo_page_addr) = 0; |
| 627 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 628 | /* As deduced from VG_(esp_at_startup), the client's argc, argv[] and |
| 629 | envp[] as extracted from the client's stack at startup-time. */ |
| 630 | Int VG_(client_argc); |
| 631 | Char** VG_(client_argv); |
| 632 | Char** VG_(client_envp); |
| 633 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 634 | /* --------------------------------------------------------------------- |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 635 | Processing of command-line options. |
| 636 | ------------------------------------------------------------------ */ |
| 637 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 638 | void VG_(bad_option) ( Char* opt ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 639 | { |
| 640 | VG_(shutdown_logging)(); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 641 | VG_(clo_log_to) = VgLogTo_Fd; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 642 | VG_(clo_logfile_fd) = 2; /* stderr */ |
| 643 | VG_(printf)("valgrind.so: Bad option `%s'; aborting.\n", opt); |
| 644 | VG_(exit)(1); |
| 645 | } |
| 646 | |
| 647 | static void config_error ( Char* msg ) |
| 648 | { |
| 649 | VG_(shutdown_logging)(); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 650 | VG_(clo_log_to) = VgLogTo_Fd; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 651 | VG_(clo_logfile_fd) = 2; /* stderr */ |
sewardj | 19d8141 | 2002-06-03 01:10:40 +0000 | [diff] [blame] | 652 | VG_(printf)( |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 653 | "valgrind: Startup or configuration error:\n %s\n", msg); |
sewardj | 19d8141 | 2002-06-03 01:10:40 +0000 | [diff] [blame] | 654 | VG_(printf)( |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 655 | "valgrind: Unable to start up properly. Giving up.\n"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 656 | VG_(exit)(1); |
| 657 | } |
| 658 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 659 | void VG_(usage) ( void ) |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 660 | { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 661 | Char* usage1 = |
| 662 | "usage: valgrind [options] prog-and-args\n" |
| 663 | "\n" |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 664 | " common user options for all Valgrind tools, with defaults in [ ]:\n" |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 665 | " --tool=<name> Use the Valgrind tool named <name> [memcheck]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 666 | " --help show this message\n" |
| 667 | " --version show version\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 668 | " -q --quiet run silently; only print error msgs\n" |
| 669 | " -v --verbose be more verbose, incl counts of errors\n" |
nethercote | 77eba60 | 2003-11-13 17:35:04 +0000 | [diff] [blame] | 670 | " --trace-children=no|yes Valgrind-ise child processes? [no]\n" |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 671 | " --track-fds=no|yes Track open file descriptors? [no]\n" |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 672 | "\n" |
| 673 | " uncommon user options for all Valgrind tools:\n" |
nethercote | 77eba60 | 2003-11-13 17:35:04 +0000 | [diff] [blame] | 674 | " --run-libc-freeres=no|yes Free up glibc memory at exit? [yes]\n" |
| 675 | " --weird-hacks=hack1,hack2,... [none]\n" |
sewardj | 3d652a3 | 2002-10-20 18:11:49 +0000 | [diff] [blame] | 676 | " recognised hacks are: ioctl-VTIME truncate-writes lax-ioctls\n" |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 677 | " --signal-polltime=<time> time, in mS, we should poll for signals.\n" |
| 678 | " Only applies for older kernels which need\n" |
| 679 | " signal routing [50]\n" |
| 680 | " --lowlat-signals=no|yes improve wake-up latency when a thread receives\n" |
| 681 | " a signal [no]\n" |
| 682 | " --lowlat-syscalls=no|yes improve wake-up latency when a thread's\n" |
| 683 | " syscall completes [no]\n" |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 684 | " --pointercheck=no|yes enforce client address space limits [yes]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 685 | "\n" |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 686 | " user options for Valgrind tools that report errors:\n" |
| 687 | " --logfile-fd=<number> file descriptor for messages [2=stderr]\n" |
| 688 | " --logfile=<file> log messages to <file>.pid<pid>\n" |
| 689 | " --logsocket=ipaddr:port log messages to socket ipaddr:port\n" |
| 690 | " --demangle=no|yes automatically demangle C++ names? [yes]\n" |
| 691 | " --num-callers=<number> show <num> callers in stack traces [4]\n" |
| 692 | " --error-limit=no|yes stop showing new errors if too many? [yes]\n" |
| 693 | " --show-below-main=no|yes continue stack traces below main() [no]\n" |
| 694 | " --suppressions=<filename> suppress errors described in <filename>\n" |
| 695 | " --gen-suppressions=no|yes print suppressions for errors detected [no]\n" |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 696 | |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 697 | " --gdb-attach=no|yes start GDB when errors detected? [no]\n" |
| 698 | " --gdb-path=/path/to/gdb path to the GDB to use [/usr/bin/gdb]\n" |
| 699 | " --input-fd=<number> file descriptor for (gdb) input [0=stdin]\n" |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 700 | "\n"; |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 701 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 702 | Char* usage2 = |
| 703 | "\n" |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 704 | " debugging options for all Valgrind tools:\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 705 | " --sanity-level=<number> level of sanity checking to do [1]\n" |
| 706 | " --single-step=no|yes translate each instr separately? [no]\n" |
| 707 | " --optimise=no|yes improve intermediate code? [yes]\n" |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 708 | " --profile=no|yes profile? (tool must be built for it) [no]\n" |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 709 | " --chain-bb=no|yes do basic-block chaining? [yes]\n" |
fitzhardinge | 462f4f9 | 2003-12-18 02:10:54 +0000 | [diff] [blame] | 710 | " --branchpred=yes|no generate branch prediction hints [no]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 711 | " --trace-codegen=<XXXXX> show generated code? (X = 0|1) [00000]\n" |
| 712 | " --trace-syscalls=no|yes show all system calls? [no]\n" |
| 713 | " --trace-signals=no|yes show signal handling details? [no]\n" |
| 714 | " --trace-symtab=no|yes show symbol table details? [no]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 715 | " --trace-sched=no|yes show thread scheduler details? [no]\n" |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 716 | " --trace-pthread=none|some|all show pthread event details? [none]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 717 | " --stop-after=<number> switch to real CPU after executing\n" |
| 718 | " <number> basic blocks [infinity]\n" |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 719 | " --wait-for-gdb=yes|no pause on startup to wait for gdb attach\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 720 | "\n" |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 721 | " debugging options for Valgrind tools that report errors\n" |
| 722 | " --dump-error=<number> show translation for basic block associated\n" |
| 723 | " with <number>'th error context [0=show none]\n" |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 724 | "\n"; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 725 | |
| 726 | Char* usage3 = |
| 727 | "\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 728 | " Extra options are read from env variable $VALGRIND_OPTS\n" |
| 729 | "\n" |
nethercote | bb1c991 | 2004-01-04 16:43:23 +0000 | [diff] [blame] | 730 | " Valgrind is Copyright (C) 2000-2004 Julian Seward\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 731 | " and licensed under the GNU General Public License, version 2.\n" |
| 732 | " Bug reports, feedback, admiration, abuse, etc, to: %s.\n" |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 733 | "\n" |
nethercote | 137bc55 | 2003-11-14 17:47:54 +0000 | [diff] [blame] | 734 | " Tools are copyright and licensed by their authors. See each\n" |
| 735 | " tool's start-up message for more information.\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 736 | "\n"; |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 737 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 738 | VG_(printf)(usage1); |
| 739 | if (VG_(details).name) { |
| 740 | VG_(printf)(" user options for %s:\n", VG_(details).name); |
| 741 | /* Don't print skin string directly for security, ha! */ |
| 742 | if (VG_(needs).command_line_options) |
| 743 | SK_(print_usage)(); |
| 744 | else |
| 745 | VG_(printf)(" (none)\n"); |
| 746 | } |
| 747 | VG_(printf)(usage2); |
| 748 | |
| 749 | if (VG_(details).name) { |
| 750 | VG_(printf)(" debugging options for %s:\n", VG_(details).name); |
| 751 | |
| 752 | if (VG_(needs).command_line_options) |
| 753 | SK_(print_debug_usage)(); |
| 754 | else |
| 755 | VG_(printf)(" (none)\n"); |
| 756 | } |
nethercote | 421281e | 2003-11-20 16:20:55 +0000 | [diff] [blame] | 757 | VG_(printf)(usage3, VG_BUGS_TO); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 758 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 759 | VG_(shutdown_logging)(); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 760 | VG_(clo_log_to) = VgLogTo_Fd; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 761 | VG_(clo_logfile_fd) = 2; /* stderr */ |
| 762 | VG_(exit)(1); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 763 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 764 | |
sewardj | 1c1b116 | 2003-02-23 01:25:51 +0000 | [diff] [blame] | 765 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 766 | static void process_cmd_line_options ( const KickstartParams *kp ) |
sewardj | 1c1b116 | 2003-02-23 01:25:51 +0000 | [diff] [blame] | 767 | { |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 768 | Int argc; |
| 769 | Char **argv; |
| 770 | Int i, eventually_logfile_fd; |
| 771 | Int *auxp; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 772 | |
| 773 | # define ISSPACE(cc) ((cc) == ' ' || (cc) == '\t' || (cc) == '\n') |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 774 | |
nethercote | e173069 | 2003-11-20 10:38:07 +0000 | [diff] [blame] | 775 | /* log to stderr by default, but usage message goes to stdout */ |
| 776 | eventually_logfile_fd = 2; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 777 | |
| 778 | /* Once logging is started, we can safely send messages pertaining |
| 779 | to failures in initialisation. */ |
| 780 | VG_(startup_logging)(); |
| 781 | |
sewardj | 19d8141 | 2002-06-03 01:10:40 +0000 | [diff] [blame] | 782 | /* Check for sane path in ./configure --prefix=... */ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 783 | if (VG_LIBDIR[0] != '/') |
sewardj | 19d8141 | 2002-06-03 01:10:40 +0000 | [diff] [blame] | 784 | config_error("Please use absolute paths in " |
| 785 | "./configure --prefix=... or --libdir=..."); |
sewardj | 3817091 | 2002-05-10 21:07:22 +0000 | [diff] [blame] | 786 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 787 | for(auxp = kp->client_auxv; auxp[0] != VKI_AT_NULL; auxp += 2) { |
| 788 | switch(auxp[0]) { |
| 789 | case VKI_AT_SYSINFO: |
| 790 | VG_(sysinfo_page_exists) = True; |
fitzhardinge | 9236079 | 2003-12-24 10:11:11 +0000 | [diff] [blame] | 791 | auxp[1] = (Int)(VG_(client_trampoline_code) + VG_(tramp_syscall_offset)); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 792 | VG_(sysinfo_page_addr) = auxp[1]; |
| 793 | break; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 794 | } |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 795 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 796 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 797 | VG_(client_envp) = kp->client_envp; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 798 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 799 | argc = kp->argc; |
| 800 | argv = kp->argv; |
| 801 | |
| 802 | VG_(vg_argc) = argc; |
| 803 | VG_(vg_argv) = argv; |
| 804 | |
| 805 | /* We know the initial ESP is pointing at argc/argv */ |
| 806 | VG_(client_argc) = *(Int *)kp->client_esp; |
| 807 | VG_(client_argv) = (Char **)(kp->client_esp + sizeof(Int)); |
| 808 | |
| 809 | for (i = 1; i < argc; i++) { |
| 810 | /* Ignore these options - they've already been handled */ |
| 811 | if (VG_CLO_STREQN(7, argv[i], "--tool=") || |
| 812 | VG_CLO_STREQN(7, argv[i], "--skin=")) |
| 813 | continue; |
| 814 | if (VG_CLO_STREQN(7, argv[i], "--exec=")) |
| 815 | continue; |
| 816 | |
| 817 | if ( VG_CLO_STREQ(argv[i], "--")) |
| 818 | continue; |
| 819 | else if (VG_CLO_STREQ(argv[i], "-v") || |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 820 | VG_CLO_STREQ(argv[i], "--verbose")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 821 | VG_(clo_verbosity)++; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 822 | else if (VG_CLO_STREQ(argv[i], "-q") || |
| 823 | VG_CLO_STREQ(argv[i], "--quiet")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 824 | VG_(clo_verbosity)--; |
| 825 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 826 | else if (VG_CLO_STREQ(argv[i], "--error-limit=yes")) |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 827 | VG_(clo_error_limit) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 828 | else if (VG_CLO_STREQ(argv[i], "--error-limit=no")) |
sewardj | 2e43290 | 2002-06-13 20:44:00 +0000 | [diff] [blame] | 829 | VG_(clo_error_limit) = False; |
sewardj | 72f98ff | 2002-06-13 17:23:38 +0000 | [diff] [blame] | 830 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 831 | else if (VG_CLO_STREQ(argv[i], "--gdb-attach=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 832 | VG_(clo_GDB_attach) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 833 | else if (VG_CLO_STREQ(argv[i], "--gdb-attach=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 834 | VG_(clo_GDB_attach) = False; |
| 835 | |
sewardj | 6024b21 | 2003-07-13 10:54:33 +0000 | [diff] [blame] | 836 | else if (VG_CLO_STREQN(11,argv[i], "--gdb-path=")) |
| 837 | VG_(clo_GDB_path) = &argv[i][11]; |
| 838 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 839 | else if (VG_CLO_STREQ(argv[i], "--gen-suppressions=yes")) |
| 840 | VG_(clo_gen_suppressions) = True; |
| 841 | else if (VG_CLO_STREQ(argv[i], "--gen-suppressions=no")) |
| 842 | VG_(clo_gen_suppressions) = False; |
| 843 | |
nethercote | 77eba60 | 2003-11-13 17:35:04 +0000 | [diff] [blame] | 844 | else if (VG_CLO_STREQ(argv[i], "--show-below-main=yes")) |
| 845 | VG_(clo_show_below_main) = True; |
| 846 | else if (VG_CLO_STREQ(argv[i], "--show-below-main=no")) |
| 847 | VG_(clo_show_below_main) = False; |
| 848 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 849 | else if (VG_CLO_STREQ(argv[i], "--pointercheck=yes")) |
| 850 | VG_(clo_pointercheck) = True; |
| 851 | else if (VG_CLO_STREQ(argv[i], "--pointercheck=no")) |
| 852 | VG_(clo_pointercheck) = False; |
| 853 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 854 | else if (VG_CLO_STREQ(argv[i], "--demangle=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 855 | VG_(clo_demangle) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 856 | else if (VG_CLO_STREQ(argv[i], "--demangle=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 857 | VG_(clo_demangle) = False; |
| 858 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 859 | else if (VG_CLO_STREQ(argv[i], "--trace-children=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 860 | VG_(clo_trace_children) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 861 | else if (VG_CLO_STREQ(argv[i], "--trace-children=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 862 | VG_(clo_trace_children) = False; |
| 863 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 864 | else if (VG_CLO_STREQ(argv[i], "--run-libc-freeres=yes")) |
sewardj | 858964b | 2002-10-05 14:15:43 +0000 | [diff] [blame] | 865 | VG_(clo_run_libc_freeres) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 866 | else if (VG_CLO_STREQ(argv[i], "--run-libc-freeres=no")) |
sewardj | 858964b | 2002-10-05 14:15:43 +0000 | [diff] [blame] | 867 | VG_(clo_run_libc_freeres) = False; |
| 868 | |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 869 | else if (VG_CLO_STREQ(argv[i], "--track-fds=yes")) |
| 870 | VG_(clo_track_fds) = True; |
| 871 | else if (VG_CLO_STREQ(argv[i], "--track-fds=no")) |
| 872 | VG_(clo_track_fds) = False; |
| 873 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 874 | else if (VG_CLO_STREQN(15, argv[i], "--sanity-level=")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 875 | VG_(sanity_level) = (Int)VG_(atoll)(&argv[i][15]); |
| 876 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 877 | else if (VG_CLO_STREQN(13, argv[i], "--logfile-fd=")) { |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 878 | VG_(clo_log_to) = VgLogTo_Fd; |
| 879 | VG_(clo_logfile_name) = NULL; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 880 | eventually_logfile_fd = (Int)VG_(atoll)(&argv[i][13]); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 881 | } |
| 882 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 883 | else if (VG_CLO_STREQN(10, argv[i], "--logfile=")) { |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 884 | VG_(clo_log_to) = VgLogTo_File; |
| 885 | VG_(clo_logfile_name) = &argv[i][10]; |
| 886 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 887 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 888 | else if (VG_CLO_STREQN(12, argv[i], "--logsocket=")) { |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 889 | VG_(clo_log_to) = VgLogTo_Socket; |
| 890 | VG_(clo_logfile_name) = &argv[i][12]; |
| 891 | } |
| 892 | |
sewardj | 6024b21 | 2003-07-13 10:54:33 +0000 | [diff] [blame] | 893 | else if (VG_CLO_STREQN(11, argv[i], "--input-fd=")) |
| 894 | VG_(clo_input_fd) = (Int)VG_(atoll)(&argv[i][11]); |
| 895 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 896 | else if (VG_CLO_STREQN(15, argv[i], "--suppressions=")) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 897 | if (VG_(clo_n_suppressions) >= VG_CLO_MAX_SFILES) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 898 | VG_(message)(Vg_UserMsg, "Too many suppression files specified."); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 899 | VG_(message)(Vg_UserMsg, |
| 900 | "Increase VG_CLO_MAX_SFILES and recompile."); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 901 | VG_(bad_option)(argv[i]); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 902 | } |
| 903 | VG_(clo_suppressions)[VG_(clo_n_suppressions)] = &argv[i][15]; |
| 904 | VG_(clo_n_suppressions)++; |
| 905 | } |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 906 | else if (VG_CLO_STREQ(argv[i], "--profile=yes")) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 907 | VG_(clo_profile) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 908 | else if (VG_CLO_STREQ(argv[i], "--profile=no")) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 909 | VG_(clo_profile) = False; |
| 910 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 911 | else if (VG_CLO_STREQ(argv[i], "--chain-bb=yes")) |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 912 | VG_(clo_chain_bb) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 913 | else if (VG_CLO_STREQ(argv[i], "--chain-bb=no")) |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 914 | VG_(clo_chain_bb) = False; |
| 915 | |
fitzhardinge | 462f4f9 | 2003-12-18 02:10:54 +0000 | [diff] [blame] | 916 | else if (VG_CLO_STREQ(argv[i], "--branchpred=yes")) |
| 917 | VG_(clo_branchpred) = True; |
| 918 | else if (VG_CLO_STREQ(argv[i], "--branchpred=no")) |
| 919 | VG_(clo_branchpred) = False; |
| 920 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 921 | else if (VG_CLO_STREQ(argv[i], "--single-step=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 922 | VG_(clo_single_step) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 923 | else if (VG_CLO_STREQ(argv[i], "--single-step=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 924 | VG_(clo_single_step) = False; |
| 925 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 926 | else if (VG_CLO_STREQ(argv[i], "--optimise=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 927 | VG_(clo_optimise) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 928 | else if (VG_CLO_STREQ(argv[i], "--optimise=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 929 | VG_(clo_optimise) = False; |
| 930 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 931 | /* "vwxyz" --> 000zyxwv (binary) */ |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 932 | else if (VG_CLO_STREQN(16, argv[i], "--trace-codegen=")) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 933 | Int j; |
| 934 | char* opt = & argv[i][16]; |
| 935 | |
| 936 | if (5 != VG_(strlen)(opt)) { |
| 937 | VG_(message)(Vg_UserMsg, |
| 938 | "--trace-codegen argument must have 5 digits"); |
| 939 | VG_(bad_option)(argv[i]); |
| 940 | } |
| 941 | for (j = 0; j < 5; j++) { |
| 942 | if ('0' == opt[j]) { /* do nothing */ } |
| 943 | else if ('1' == opt[j]) VG_(clo_trace_codegen) |= (1 << j); |
| 944 | else { |
| 945 | VG_(message)(Vg_UserMsg, "--trace-codegen argument can only " |
| 946 | "contain 0s and 1s"); |
| 947 | VG_(bad_option)(argv[i]); |
| 948 | } |
| 949 | } |
| 950 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 951 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 952 | else if (VG_CLO_STREQ(argv[i], "--trace-syscalls=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 953 | VG_(clo_trace_syscalls) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 954 | else if (VG_CLO_STREQ(argv[i], "--trace-syscalls=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 955 | VG_(clo_trace_syscalls) = False; |
| 956 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 957 | else if (VG_CLO_STREQ(argv[i], "--trace-signals=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 958 | VG_(clo_trace_signals) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 959 | else if (VG_CLO_STREQ(argv[i], "--trace-signals=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 960 | VG_(clo_trace_signals) = False; |
| 961 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 962 | else if (VG_CLO_STREQ(argv[i], "--trace-symtab=yes")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 963 | VG_(clo_trace_symtab) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 964 | else if (VG_CLO_STREQ(argv[i], "--trace-symtab=no")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 965 | VG_(clo_trace_symtab) = False; |
| 966 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 967 | else if (VG_CLO_STREQ(argv[i], "--trace-sched=yes")) |
sewardj | 8937c81 | 2002-04-12 20:12:20 +0000 | [diff] [blame] | 968 | VG_(clo_trace_sched) = True; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 969 | else if (VG_CLO_STREQ(argv[i], "--trace-sched=no")) |
sewardj | 8937c81 | 2002-04-12 20:12:20 +0000 | [diff] [blame] | 970 | VG_(clo_trace_sched) = False; |
| 971 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 972 | else if (VG_CLO_STREQ(argv[i], "--trace-pthread=none")) |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 973 | VG_(clo_trace_pthread_level) = 0; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 974 | else if (VG_CLO_STREQ(argv[i], "--trace-pthread=some")) |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 975 | VG_(clo_trace_pthread_level) = 1; |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 976 | else if (VG_CLO_STREQ(argv[i], "--trace-pthread=all")) |
sewardj | 45b4b37 | 2002-04-16 22:50:32 +0000 | [diff] [blame] | 977 | VG_(clo_trace_pthread_level) = 2; |
sewardj | 8937c81 | 2002-04-12 20:12:20 +0000 | [diff] [blame] | 978 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 979 | else if (VG_CLO_STREQN(14, argv[i], "--weird-hacks=")) |
sewardj | 8d365b5 | 2002-05-12 10:52:16 +0000 | [diff] [blame] | 980 | VG_(clo_weird_hacks) = &argv[i][14]; |
sewardj | 3984b85 | 2002-05-12 03:00:17 +0000 | [diff] [blame] | 981 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 982 | else if (VG_CLO_STREQN(17, argv[i], "--signal-polltime=")) |
| 983 | VG_(clo_signal_polltime) = VG_(atoll)(&argv[i][17]); |
| 984 | |
| 985 | else if (VG_CLO_STREQ(argv[i], "--lowlat-signals=yes")) |
| 986 | VG_(clo_lowlat_signals) = True; |
| 987 | else if (VG_CLO_STREQ(argv[i], "--lowlat-signals=no")) |
| 988 | VG_(clo_lowlat_signals) = False; |
| 989 | |
| 990 | else if (VG_CLO_STREQ(argv[i], "--lowlat-syscalls=yes")) |
| 991 | VG_(clo_lowlat_syscalls) = True; |
| 992 | else if (VG_CLO_STREQ(argv[i], "--lowlat-syscalls=no")) |
| 993 | VG_(clo_lowlat_syscalls) = False; |
| 994 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 995 | else if (VG_CLO_STREQN(13, argv[i], "--stop-after=")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 996 | VG_(clo_stop_after) = VG_(atoll)(&argv[i][13]); |
| 997 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 998 | else if (VG_CLO_STREQN(13, argv[i], "--dump-error=")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 999 | VG_(clo_dump_error) = (Int)VG_(atoll)(&argv[i][13]); |
| 1000 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1001 | else if (VG_CLO_STREQ(argv[i], "--wait-for-gdb=yes")) |
| 1002 | VG_(clo_wait_for_gdb) = True; |
| 1003 | else if (VG_CLO_STREQ(argv[i], "--wait-for-gdb=no")) |
| 1004 | VG_(clo_wait_for_gdb) = False; |
| 1005 | |
njn | 43c799e | 2003-04-08 00:08:52 +0000 | [diff] [blame] | 1006 | else if (VG_CLO_STREQN(14, argv[i], "--num-callers=")) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1007 | /* Make sure it's sane. */ |
| 1008 | VG_(clo_backtrace_size) = (Int)VG_(atoll)(&argv[i][14]); |
njn | 6c84655 | 2003-09-16 07:41:43 +0000 | [diff] [blame] | 1009 | if (VG_(clo_backtrace_size) < 1) |
| 1010 | VG_(clo_backtrace_size) = 1; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1011 | if (VG_(clo_backtrace_size) >= VG_DEEPEST_BACKTRACE) |
| 1012 | VG_(clo_backtrace_size) = VG_DEEPEST_BACKTRACE; |
| 1013 | } |
| 1014 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1015 | else if (VG_(needs).command_line_options) { |
| 1016 | Bool ok = SK_(process_cmd_line_option)(argv[i]); |
| 1017 | if (!ok) |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1018 | VG_(usage)(); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1019 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1020 | else |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1021 | VG_(usage)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | # undef ISSPACE |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1025 | |
njn | f9ebf67 | 2003-05-12 21:41:30 +0000 | [diff] [blame] | 1026 | if (VG_(clo_verbosity) < 0) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1027 | VG_(clo_verbosity) = 0; |
| 1028 | |
| 1029 | if (VG_(clo_GDB_attach) && VG_(clo_trace_children)) { |
| 1030 | VG_(message)(Vg_UserMsg, ""); |
| 1031 | VG_(message)(Vg_UserMsg, |
| 1032 | "--gdb-attach=yes conflicts with --trace-children=yes"); |
| 1033 | VG_(message)(Vg_UserMsg, |
| 1034 | "Please choose one or the other, but not both."); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1035 | VG_(bad_option)("--gdb-attach=yes and --trace-children=yes"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1038 | /* Set up logging now. After this is done, VG_(clo_logfile_fd) |
| 1039 | should be connected to whatever sink has been selected, and we |
| 1040 | indiscriminately chuck stuff into it without worrying what the |
| 1041 | nature of it is. Oh the wonder of Unix streams. */ |
| 1042 | |
nethercote | e173069 | 2003-11-20 10:38:07 +0000 | [diff] [blame] | 1043 | /* So far we should be still attached to stdout, so we can show on |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1044 | the terminal any problems to do with processing command line |
| 1045 | opts. */ |
nethercote | e173069 | 2003-11-20 10:38:07 +0000 | [diff] [blame] | 1046 | vg_assert(VG_(clo_logfile_fd) == 1 /* stdout */); |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1047 | vg_assert(VG_(logging_to_filedes) == True); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1048 | |
| 1049 | switch (VG_(clo_log_to)) { |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1050 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1051 | case VgLogTo_Fd: |
| 1052 | vg_assert(VG_(clo_logfile_name) == NULL); |
| 1053 | VG_(clo_logfile_fd) = eventually_logfile_fd; |
| 1054 | break; |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1055 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1056 | case VgLogTo_File: { |
| 1057 | Char logfilename[1000]; |
jsgf | f3c3f1a | 2003-10-14 22:13:28 +0000 | [diff] [blame] | 1058 | Int seq = 0; |
| 1059 | Int pid = VG_(getpid)(); |
| 1060 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1061 | vg_assert(VG_(clo_logfile_name) != NULL); |
| 1062 | vg_assert(VG_(strlen)(VG_(clo_logfile_name)) <= 900); /* paranoia */ |
jsgf | f3c3f1a | 2003-10-14 22:13:28 +0000 | [diff] [blame] | 1063 | |
| 1064 | for(;;) { |
| 1065 | if (seq == 0) |
| 1066 | VG_(sprintf)(logfilename, "%s.pid%d", |
| 1067 | VG_(clo_logfile_name), pid ); |
| 1068 | else |
| 1069 | VG_(sprintf)(logfilename, "%s.pid%d.%d", |
| 1070 | VG_(clo_logfile_name), pid, seq ); |
| 1071 | seq++; |
| 1072 | |
| 1073 | eventually_logfile_fd |
| 1074 | = VG_(open)(logfilename, |
| 1075 | VKI_O_CREAT|VKI_O_WRONLY|VKI_O_EXCL|VKI_O_TRUNC, |
| 1076 | VKI_S_IRUSR|VKI_S_IWUSR); |
| 1077 | if (eventually_logfile_fd >= 0) { |
fitzhardinge | 9b8c2f3 | 2004-01-06 00:15:26 +0000 | [diff] [blame] | 1078 | VG_(clo_logfile_fd) = VG_(safe_fd)(eventually_logfile_fd); |
jsgf | f3c3f1a | 2003-10-14 22:13:28 +0000 | [diff] [blame] | 1079 | break; |
| 1080 | } else { |
| 1081 | if (eventually_logfile_fd != -VKI_EEXIST) { |
| 1082 | VG_(message)(Vg_UserMsg, |
| 1083 | "Can't create/open log file `%s.pid%d'; giving up!", |
| 1084 | VG_(clo_logfile_name), pid); |
| 1085 | VG_(bad_option)( |
| 1086 | "--logfile=<file> didn't work out for some reason."); |
| 1087 | break; |
| 1088 | } |
| 1089 | } |
| 1090 | } |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1091 | break; |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | case VgLogTo_Socket: { |
| 1095 | vg_assert(VG_(clo_logfile_name) != NULL); |
| 1096 | vg_assert(VG_(strlen)(VG_(clo_logfile_name)) <= 900); /* paranoia */ |
| 1097 | eventually_logfile_fd |
| 1098 | = VG_(connect_via_socket)( VG_(clo_logfile_name) ); |
| 1099 | if (eventually_logfile_fd == -1) { |
| 1100 | VG_(message)(Vg_UserMsg, |
| 1101 | "Invalid --logsocket=ipaddr or --logsocket=ipaddr:port spec"); |
| 1102 | VG_(message)(Vg_UserMsg, |
| 1103 | "of `%s'; giving up!", VG_(clo_logfile_name) ); |
| 1104 | VG_(bad_option)( |
| 1105 | "--logsocket="); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1106 | } |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1107 | if (eventually_logfile_fd == -2) { |
| 1108 | VG_(message)(Vg_UserMsg, |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 1109 | "valgrind: failed to connect to logging server `%s'.", |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1110 | VG_(clo_logfile_name) ); |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 1111 | VG_(message)(Vg_UserMsg, |
| 1112 | "Log messages will sent to stderr instead." ); |
| 1113 | VG_(message)(Vg_UserMsg, |
| 1114 | "" ); |
| 1115 | /* We don't change anything here. */ |
| 1116 | } else { |
| 1117 | vg_assert(eventually_logfile_fd > 0); |
| 1118 | VG_(clo_logfile_fd) = eventually_logfile_fd; |
| 1119 | VG_(logging_to_filedes) = False; |
| 1120 | } |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 1121 | break; |
| 1122 | } |
| 1123 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1126 | /* Move logfile_fd into the safe range, so it doesn't conflict with any app fds */ |
fitzhardinge | f0046f2 | 2003-12-18 02:39:22 +0000 | [diff] [blame] | 1127 | eventually_logfile_fd = VG_(fcntl)(VG_(clo_logfile_fd), VKI_F_DUPFD, VG_(max_fd)+1); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1128 | if (eventually_logfile_fd < 0) |
| 1129 | VG_(message)(Vg_UserMsg, "valgrind: failed to move logfile fd into safe range"); |
| 1130 | else { |
| 1131 | VG_(clo_logfile_fd) = eventually_logfile_fd; |
| 1132 | VG_(fcntl)(VG_(clo_logfile_fd), VKI_F_SETFD, VKI_FD_CLOEXEC); |
| 1133 | } |
| 1134 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1135 | /* Ok, the logging sink is running now. Print a suitable preamble. |
| 1136 | If logging to file or a socket, write details of parent PID and |
| 1137 | command line args, to help people trying to interpret the |
| 1138 | results of a run which encompasses multiple processes. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1139 | |
sewardj | 83adf41 | 2002-05-01 01:25:45 +0000 | [diff] [blame] | 1140 | if (VG_(clo_verbosity > 0)) { |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 1141 | /* Skin details */ |
| 1142 | VG_(message)(Vg_UserMsg, "%s%s%s, %s for x86-linux.", |
| 1143 | VG_(details).name, |
| 1144 | NULL == VG_(details).version ? "" : "-", |
| 1145 | NULL == VG_(details).version |
| 1146 | ? (Char*)"" : VG_(details).version, |
| 1147 | VG_(details).description); |
| 1148 | VG_(message)(Vg_UserMsg, "%s", VG_(details).copyright_author); |
sewardj | 3b2736a | 2002-03-24 12:18:35 +0000 | [diff] [blame] | 1149 | |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 1150 | /* Core details */ |
| 1151 | VG_(message)(Vg_UserMsg, |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1152 | "Using valgrind-%s, a program supervision framework for x86-linux.", |
sewardj | 4aa62ba | 2002-10-05 15:49:27 +0000 | [diff] [blame] | 1153 | VERSION); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1154 | VG_(message)(Vg_UserMsg, |
nethercote | bb1c991 | 2004-01-04 16:43:23 +0000 | [diff] [blame] | 1155 | "Copyright (C) 2000-2004, and GNU GPL'd, by Julian Seward."); |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
nethercote | c1e395d | 2003-11-10 13:26:49 +0000 | [diff] [blame] | 1158 | if (VG_(clo_verbosity) > 0 && VG_(clo_log_to) != VgLogTo_Fd) { |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1159 | VG_(message)(Vg_UserMsg, ""); |
| 1160 | VG_(message)(Vg_UserMsg, |
| 1161 | "My PID = %d, parent PID = %d. Prog and args are:", |
| 1162 | VG_(getpid)(), VG_(getppid)() ); |
| 1163 | for (i = 0; i < VG_(client_argc); i++) |
| 1164 | VG_(message)(Vg_UserMsg, " %s", VG_(client_argv)[i]); |
| 1165 | } |
| 1166 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1167 | if (VG_(clo_verbosity) > 1) { |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1168 | if (VG_(clo_log_to) != VgLogTo_Fd) |
| 1169 | VG_(message)(Vg_UserMsg, ""); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1170 | VG_(message)(Vg_UserMsg, "Valgrind library directory: %s", VG_(libdir)); |
njn | 86dc2bc | 2003-09-09 07:26:21 +0000 | [diff] [blame] | 1171 | VG_(message)(Vg_UserMsg, "Command line"); |
| 1172 | for (i = 0; i < VG_(client_argc); i++) |
| 1173 | VG_(message)(Vg_UserMsg, " %s", VG_(client_argv)[i]); |
| 1174 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1175 | VG_(message)(Vg_UserMsg, "Startup, with flags:"); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1176 | for (i = 1; i < argc; i++) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1177 | VG_(message)(Vg_UserMsg, " %s", argv[i]); |
| 1178 | } |
| 1179 | } |
| 1180 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1181 | if (VG_(clo_n_suppressions) < VG_CLO_MAX_SFILES-1 && |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1182 | (VG_(needs).core_errors || VG_(needs).skin_errors)) { |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1183 | /* If there are no suppression files specified and the skin |
| 1184 | needs one, load the default */ |
| 1185 | static const Char default_supp[] = "default.supp"; |
| 1186 | Int len = VG_(strlen)(VG_(libdir)) + 1 + sizeof(default_supp); |
| 1187 | Char *buf = VG_(arena_malloc)(VG_AR_CORE, len); |
| 1188 | VG_(sprintf)(buf, "%s/%s", VG_(libdir), default_supp); |
| 1189 | VG_(clo_suppressions)[VG_(clo_n_suppressions)] = buf; |
| 1190 | VG_(clo_n_suppressions)++; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1191 | } |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1192 | |
njn | 6a23053 | 2003-07-21 10:38:23 +0000 | [diff] [blame] | 1193 | if (VG_(clo_gen_suppressions) && |
| 1194 | !VG_(needs).core_errors && !VG_(needs).skin_errors) { |
| 1195 | config_error("Can't use --gen-suppressions=yes with this skin,\n" |
| 1196 | " as it doesn't generate errors."); |
| 1197 | } |
| 1198 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1201 | /* --------------------------------------------------------------------- |
| 1202 | Copying to/from m_state_static. |
| 1203 | ------------------------------------------------------------------ */ |
| 1204 | |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1205 | /* See comment about this in vg_include.h. Change only with |
| 1206 | great care. |
| 1207 | */ |
| 1208 | __attribute__ ((aligned (16))) |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1209 | UInt VG_(m_state_static) [6 /* segment regs, Intel order */ |
| 1210 | + 8 /* int regs, in Intel order */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1211 | + 1 /* %eflags */ |
| 1212 | + 1 /* %eip */ |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1213 | + VG_SIZE_OF_SSESTATE_W /* FPU state */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1214 | ]; |
| 1215 | |
sewardj | fa492d4 | 2002-12-08 18:20:01 +0000 | [diff] [blame] | 1216 | UInt VG_(insertDflag)(UInt eflags, Int d) |
| 1217 | { |
| 1218 | vg_assert(d == 1 || d == -1); |
| 1219 | eflags &= ~EFlagD; |
| 1220 | |
| 1221 | if (d < 0) |
| 1222 | eflags |= EFlagD; |
| 1223 | |
| 1224 | return eflags; |
| 1225 | } |
| 1226 | |
| 1227 | Int VG_(extractDflag)(UInt eflags) |
| 1228 | { |
| 1229 | Int ret; |
| 1230 | |
| 1231 | if (eflags & EFlagD) |
| 1232 | ret = -1; |
| 1233 | else |
| 1234 | ret = 1; |
| 1235 | |
| 1236 | return ret; |
| 1237 | } |
| 1238 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1239 | void VG_(copy_baseBlock_to_m_state_static) ( void ) |
| 1240 | { |
| 1241 | Int i; |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1242 | VG_(m_state_static)[ 0/4] = VG_(baseBlock)[VGOFF_(m_cs)]; |
| 1243 | VG_(m_state_static)[ 4/4] = VG_(baseBlock)[VGOFF_(m_ss)]; |
| 1244 | VG_(m_state_static)[ 8/4] = VG_(baseBlock)[VGOFF_(m_ds)]; |
| 1245 | VG_(m_state_static)[12/4] = VG_(baseBlock)[VGOFF_(m_es)]; |
| 1246 | VG_(m_state_static)[16/4] = VG_(baseBlock)[VGOFF_(m_fs)]; |
| 1247 | VG_(m_state_static)[20/4] = VG_(baseBlock)[VGOFF_(m_gs)]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1248 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1249 | VG_(m_state_static)[24/4] = VG_(baseBlock)[VGOFF_(m_eax)]; |
| 1250 | VG_(m_state_static)[28/4] = VG_(baseBlock)[VGOFF_(m_ecx)]; |
| 1251 | VG_(m_state_static)[32/4] = VG_(baseBlock)[VGOFF_(m_edx)]; |
| 1252 | VG_(m_state_static)[36/4] = VG_(baseBlock)[VGOFF_(m_ebx)]; |
| 1253 | VG_(m_state_static)[40/4] = VG_(baseBlock)[VGOFF_(m_esp)]; |
| 1254 | VG_(m_state_static)[44/4] = VG_(baseBlock)[VGOFF_(m_ebp)]; |
| 1255 | VG_(m_state_static)[48/4] = VG_(baseBlock)[VGOFF_(m_esi)]; |
| 1256 | VG_(m_state_static)[52/4] = VG_(baseBlock)[VGOFF_(m_edi)]; |
| 1257 | |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1258 | VG_(m_state_static)[56/4] |
| 1259 | = VG_(insertDflag)(VG_(baseBlock)[VGOFF_(m_eflags)], |
| 1260 | VG_(baseBlock)[VGOFF_(m_dflag)]); |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1261 | VG_(m_state_static)[60/4] = VG_(baseBlock)[VGOFF_(m_eip)]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1262 | |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1263 | for (i = 0; i < VG_SIZE_OF_SSESTATE_W; i++) |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1264 | VG_(m_state_static)[64/4 + i] |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1265 | = VG_(baseBlock)[VGOFF_(m_ssestate) + i]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | |
| 1269 | void VG_(copy_m_state_static_to_baseBlock) ( void ) |
| 1270 | { |
| 1271 | Int i; |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1272 | VG_(baseBlock)[VGOFF_(m_cs)] = VG_(m_state_static)[ 0/4]; |
| 1273 | VG_(baseBlock)[VGOFF_(m_ss)] = VG_(m_state_static)[ 4/4]; |
| 1274 | VG_(baseBlock)[VGOFF_(m_ds)] = VG_(m_state_static)[ 8/4]; |
| 1275 | VG_(baseBlock)[VGOFF_(m_es)] = VG_(m_state_static)[12/4]; |
| 1276 | VG_(baseBlock)[VGOFF_(m_fs)] = VG_(m_state_static)[16/4]; |
| 1277 | VG_(baseBlock)[VGOFF_(m_gs)] = VG_(m_state_static)[20/4]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1278 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1279 | VG_(baseBlock)[VGOFF_(m_eax)] = VG_(m_state_static)[24/4]; |
| 1280 | VG_(baseBlock)[VGOFF_(m_ecx)] = VG_(m_state_static)[28/4]; |
| 1281 | VG_(baseBlock)[VGOFF_(m_edx)] = VG_(m_state_static)[32/4]; |
| 1282 | VG_(baseBlock)[VGOFF_(m_ebx)] = VG_(m_state_static)[36/4]; |
| 1283 | VG_(baseBlock)[VGOFF_(m_esp)] = VG_(m_state_static)[40/4]; |
| 1284 | VG_(baseBlock)[VGOFF_(m_ebp)] = VG_(m_state_static)[44/4]; |
| 1285 | VG_(baseBlock)[VGOFF_(m_esi)] = VG_(m_state_static)[48/4]; |
| 1286 | VG_(baseBlock)[VGOFF_(m_edi)] = VG_(m_state_static)[52/4]; |
| 1287 | |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1288 | VG_(baseBlock)[VGOFF_(m_eflags)] |
| 1289 | = VG_(m_state_static)[56/4] & ~EFlagD; |
| 1290 | VG_(baseBlock)[VGOFF_(m_dflag)] |
| 1291 | = VG_(extractDflag)(VG_(m_state_static)[56/4]); |
sewardj | fa492d4 | 2002-12-08 18:20:01 +0000 | [diff] [blame] | 1292 | |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1293 | VG_(baseBlock)[VGOFF_(m_eip)] = VG_(m_state_static)[60/4]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1294 | |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1295 | for (i = 0; i < VG_SIZE_OF_SSESTATE_W; i++) |
| 1296 | VG_(baseBlock)[VGOFF_(m_ssestate) + i] |
sewardj | 92a5956 | 2002-09-30 00:53:10 +0000 | [diff] [blame] | 1297 | = VG_(m_state_static)[64/4 + i]; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1300 | Addr VG_(get_stack_pointer) ( void ) |
| 1301 | { |
| 1302 | return VG_(baseBlock)[VGOFF_(m_esp)]; |
| 1303 | } |
| 1304 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1305 | /* --------------------------------------------------------------------- |
| 1306 | Show accumulated counts. |
| 1307 | ------------------------------------------------------------------ */ |
| 1308 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1309 | static __inline__ Int safe_idiv(Int a, Int b) |
| 1310 | { |
| 1311 | return (b == 0 ? 0 : a / b); |
| 1312 | } |
| 1313 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1314 | static void vg_show_counts ( void ) |
| 1315 | { |
| 1316 | VG_(message)(Vg_DebugMsg, |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 1317 | " TT/TC: %d tc sectors discarded.", |
| 1318 | VG_(number_of_tc_discards) ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1319 | VG_(message)(Vg_DebugMsg, |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 1320 | " %d chainings, %d unchainings.", |
| 1321 | VG_(bb_enchain_count), VG_(bb_dechain_count) ); |
| 1322 | VG_(message)(Vg_DebugMsg, |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1323 | "translate: new %d (%d -> %d; ratio %d:10)", |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1324 | VG_(overall_in_count), |
| 1325 | VG_(overall_in_osize), |
| 1326 | VG_(overall_in_tsize), |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1327 | safe_idiv(10*VG_(overall_in_tsize), VG_(overall_in_osize))); |
| 1328 | VG_(message)(Vg_DebugMsg, |
| 1329 | " discard %d (%d -> %d; ratio %d:10).", |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1330 | VG_(overall_out_count), |
| 1331 | VG_(overall_out_osize), |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1332 | VG_(overall_out_tsize), |
| 1333 | safe_idiv(10*VG_(overall_out_tsize), VG_(overall_out_osize))); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1334 | VG_(message)(Vg_DebugMsg, |
njn | e0205ff | 2003-04-08 00:56:14 +0000 | [diff] [blame] | 1335 | " dispatch: %llu jumps (bb entries), of which %u (%lu%%) were unchained.", |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 1336 | VG_(bbs_done), |
| 1337 | VG_(unchained_jumps_done), |
| 1338 | ((ULong)(100) * (ULong)(VG_(unchained_jumps_done))) |
| 1339 | / ( VG_(bbs_done)==0 ? 1 : VG_(bbs_done) ) |
| 1340 | ); |
| 1341 | |
| 1342 | VG_(message)(Vg_DebugMsg, |
| 1343 | " %d/%d major/minor sched events. %d tt_fast misses.", |
| 1344 | VG_(num_scheduling_events_MAJOR), |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1345 | VG_(num_scheduling_events_MINOR), |
| 1346 | VG_(tt_fast_misses)); |
sewardj | 22854b9 | 2002-11-30 14:00:47 +0000 | [diff] [blame] | 1347 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1348 | VG_(message)(Vg_DebugMsg, |
| 1349 | "reg-alloc: %d t-req-spill, " |
| 1350 | "%d+%d orig+spill uis, %d total-reg-r.", |
| 1351 | VG_(translations_needing_spill), |
| 1352 | VG_(uinstrs_prealloc), |
| 1353 | VG_(uinstrs_spill), |
| 1354 | VG_(total_reg_rank) ); |
| 1355 | VG_(message)(Vg_DebugMsg, |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1356 | " sanity: %d cheap, %d expensive checks.", |
| 1357 | VG_(sanity_fast_count), |
| 1358 | VG_(sanity_slow_count) ); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1359 | VG_(print_ccall_stats)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | |
| 1363 | /* --------------------------------------------------------------------- |
| 1364 | Main! |
| 1365 | ------------------------------------------------------------------ */ |
| 1366 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1367 | /* Initialize the PID and PGRP of scheduler LWP; this is also called |
| 1368 | in any new children after fork. */ |
| 1369 | static void newpid(ThreadId unused) |
| 1370 | { |
| 1371 | /* PID of scheduler LWP */ |
| 1372 | VG_(main_pid) = VG_(getpid)(); |
| 1373 | VG_(main_pgrp) = VG_(getpgrp)(); |
| 1374 | } |
| 1375 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1376 | /* Where we jump to once Valgrind has got control, and the real |
| 1377 | machine's state has been copied to the m_state_static. */ |
| 1378 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1379 | void VG_(main) ( const KickstartParams *kp, void (*tool_init)(void), void *tool_dlhandle ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1380 | { |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1381 | VgSchedReturnCode src; |
fitzhardinge | f0046f2 | 2003-12-18 02:39:22 +0000 | [diff] [blame] | 1382 | struct vki_rlimit rl; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1383 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1384 | /* initial state */ |
| 1385 | if (0) |
| 1386 | VG_(printf)("starting esp=%p eip=%p, esp=%p\n", kp->client_esp, kp->client_eip, &src); |
| 1387 | VG_(esp_at_startup) = kp->client_esp; |
| 1388 | VG_(memset)(&VG_(m_state_static), 0, sizeof(VG_(m_state_static))); |
| 1389 | VG_(m_state_static)[40/4] = kp->client_esp; |
| 1390 | VG_(m_state_static)[60/4] = kp->client_eip; |
| 1391 | |
| 1392 | /* set up an initial FPU state (doesn't really matter what it is, |
| 1393 | so long as it's somewhat valid) */ |
| 1394 | if (!VG_(have_ssestate)) |
| 1395 | asm volatile("fwait; fnsave %0; fwait; frstor %0; fwait" |
| 1396 | : : "m" (VG_(m_state_static)[64/4]) : "cc", "memory"); |
| 1397 | else |
| 1398 | asm volatile("fwait; fxsave %0; fwait; andl $0xffbf, %1; fxrstor %0; fwait" |
| 1399 | : : "m" (VG_(m_state_static)[64/4]), "m" (VG_(m_state_static)[(64+24)/4]) : "cc", "memory"); |
| 1400 | |
| 1401 | VG_(brk_base) = VG_(brk_limit) = kp->client_brkbase; |
| 1402 | VG_(client_base) = kp->client_base; |
| 1403 | VG_(client_end) = kp->client_end; |
| 1404 | VG_(client_mapbase) = kp->client_mapbase; |
| 1405 | VG_(clstk_base) = kp->clstk_base; |
| 1406 | VG_(clstk_end) = kp->clstk_end; |
fitzhardinge | 9236079 | 2003-12-24 10:11:11 +0000 | [diff] [blame] | 1407 | vg_assert(VG_(clstk_end) == VG_(client_end)); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1408 | |
| 1409 | VG_(shadow_base) = kp->shadow_base; |
| 1410 | VG_(shadow_end) = kp->shadow_end; |
| 1411 | VG_(valgrind_base) = kp->vg_base; |
| 1412 | VG_(valgrind_mmap_end) = kp->vg_mmap_end; |
| 1413 | VG_(valgrind_end) = kp->vg_end; |
| 1414 | |
| 1415 | VG_(libdir) = kp->libdir; |
| 1416 | |
fitzhardinge | 9236079 | 2003-12-24 10:11:11 +0000 | [diff] [blame] | 1417 | VG_(client_trampoline_code) = kp->cl_tramp_code; |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1418 | |
njn | 0c7a5b5 | 2003-04-30 09:00:33 +0000 | [diff] [blame] | 1419 | if (0) { |
| 1420 | if (VG_(have_ssestate)) |
| 1421 | VG_(printf)("Looks like a SSE-capable CPU\n"); |
| 1422 | else |
| 1423 | VG_(printf)("Looks like a MMX-only CPU\n"); |
| 1424 | } |
sewardj | b91ae7f | 2003-04-29 23:50:00 +0000 | [diff] [blame] | 1425 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1426 | VG_(atfork)(NULL, NULL, newpid); |
| 1427 | newpid(VG_INVALID_THREADID); |
| 1428 | |
fitzhardinge | f0046f2 | 2003-12-18 02:39:22 +0000 | [diff] [blame] | 1429 | /* Get the current file descriptor limits. */ |
| 1430 | if (VG_(getrlimit)(VKI_RLIMIT_NOFILE, &rl) < 0) { |
| 1431 | rl.rlim_cur = 1024; |
| 1432 | rl.rlim_max = 1024; |
| 1433 | } |
| 1434 | |
| 1435 | /* Work out where to move the soft limit to. */ |
| 1436 | if (rl.rlim_cur + VG_N_RESERVED_FDS <= rl.rlim_max) { |
| 1437 | rl.rlim_cur = rl.rlim_cur + VG_N_RESERVED_FDS; |
| 1438 | } else { |
| 1439 | rl.rlim_cur = rl.rlim_max; |
| 1440 | } |
| 1441 | |
| 1442 | /* Reserve some file descriptors for our use. */ |
| 1443 | VG_(max_fd) = rl.rlim_cur - VG_N_RESERVED_FDS; |
| 1444 | |
| 1445 | /* Update the soft limit. */ |
| 1446 | VG_(setrlimit)(VKI_RLIMIT_NOFILE, &rl); |
| 1447 | |
fitzhardinge | b791a19 | 2003-12-18 07:22:44 +0000 | [diff] [blame] | 1448 | if (kp->vgexecfd != -1) |
| 1449 | VG_(vgexecfd) = VG_(safe_fd)(kp->vgexecfd); |
| 1450 | if (kp->clexecfd != -1) |
| 1451 | VG_(clexecfd) = VG_(safe_fd)(kp->clexecfd); |
| 1452 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1453 | /* Read /proc/self/maps into a buffer. Must be before: |
| 1454 | - SK_(pre_clo_init)(): so that if it calls VG_(malloc)(), any mmap'd |
| 1455 | superblocks are not erroneously identified as being owned by the |
| 1456 | client, which would be bad. |
| 1457 | - init_memory(): that's where the buffer is parsed |
| 1458 | - init_tt_tc(): so the anonymous mmaps for the translation table and |
| 1459 | translation cache aren't identified as part of the client, which would |
| 1460 | waste > 20M of virtual address space, and be bad. |
| 1461 | */ |
njn | fa1016e | 2003-09-25 17:54:11 +0000 | [diff] [blame] | 1462 | VG_(read_procselfmaps)(); |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1463 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1464 | /* Setup stuff that depends on the skin. Must be before: |
| 1465 | - vg_init_baseBlock(): to register helpers |
| 1466 | - process_cmd_line_options(): to register skin name and description, |
| 1467 | and turn on/off 'command_line_options' need |
| 1468 | - init_memory() (to setup memory event trackers). |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1469 | */ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1470 | (*tool_init)(); |
| 1471 | VG_(tool_init_dlsym)(tool_dlhandle); |
| 1472 | |
njn | 810086f | 2002-11-14 12:42:47 +0000 | [diff] [blame] | 1473 | VG_(sanity_check_needs)(); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1474 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1475 | /* Process Valgrind's command-line opts */ |
| 1476 | process_cmd_line_options(kp); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1477 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1478 | /* Hook to delay things long enough so we can get the pid and |
| 1479 | attach GDB in another shell. */ |
| 1480 | if (VG_(clo_wait_for_gdb)) { |
| 1481 | VG_(printf)("pid=%d\n", VG_(getpid)()); |
| 1482 | /* do "jump *$eip" to skip this in gdb */ |
| 1483 | VG_(do_syscall)(__NR_pause); |
| 1484 | } |
| 1485 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1486 | /* Do post command-line processing initialisation. Must be before: |
| 1487 | - vg_init_baseBlock(): to register any more helpers |
| 1488 | */ |
njn | cc7bb47 | 2002-10-14 09:25:19 +0000 | [diff] [blame] | 1489 | SK_(post_clo_init)(); |
| 1490 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1491 | /* Set up baseBlock offsets and copy the saved machine's state into it. */ |
njn | cc7bb47 | 2002-10-14 09:25:19 +0000 | [diff] [blame] | 1492 | vg_init_baseBlock(); |
| 1493 | |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 1494 | /* Search for file descriptors that are inherited from our parent. */ |
| 1495 | if (VG_(clo_track_fds)) |
| 1496 | VG_(init_preopened_fds)(); |
| 1497 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1498 | /* Initialise the scheduler, and copy the client's state from |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1499 | baseBlock into VG_(threads)[1]. Must be before: |
| 1500 | - VG_(sigstartup_actions)() |
| 1501 | */ |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1502 | VG_(scheduler_init)(); |
| 1503 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1504 | /* Set up the ProxyLWP machinery */ |
| 1505 | VG_(proxy_init)(); |
| 1506 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1507 | /* Initialise the signal handling subsystem, temporarily parking |
| 1508 | the saved blocking-mask in saved_sigmask. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1509 | VG_(sigstartup_actions)(); |
| 1510 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1511 | /* Perhaps we're profiling Valgrind? */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1512 | if (VG_(clo_profile)) |
| 1513 | VGP_(init_profiling)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1514 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1515 | /* Start calibration of our RDTSC-based clock. */ |
| 1516 | VG_(start_rdtsc_calibration)(); |
| 1517 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1518 | /* Parse /proc/self/maps to learn about startup segments. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1519 | VGP_PUSHCC(VgpInitMem); |
| 1520 | VG_(init_memory)(); |
| 1521 | VGP_POPCC(VgpInitMem); |
| 1522 | |
| 1523 | /* Read the list of errors to suppress. This should be found in |
| 1524 | the file specified by vg_clo_suppressions. */ |
| 1525 | if (VG_(needs).core_errors || VG_(needs).skin_errors) |
| 1526 | VG_(load_suppressions)(); |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1527 | |
sewardj | 5f07b66 | 2002-04-23 16:52:51 +0000 | [diff] [blame] | 1528 | /* End calibration of our RDTSC-based clock, leaving it as long as |
| 1529 | we can. */ |
| 1530 | VG_(end_rdtsc_calibration)(); |
| 1531 | |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 1532 | /* Initialise translation table and translation cache. */ |
sewardj | 18d7513 | 2002-05-16 11:06:21 +0000 | [diff] [blame] | 1533 | VG_(init_tt_tc)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1534 | |
| 1535 | if (VG_(clo_verbosity) == 1) { |
| 1536 | VG_(message)(Vg_UserMsg, |
| 1537 | "For more details, rerun with: -v"); |
| 1538 | } |
| 1539 | |
sewardj | 25c7c3a | 2003-07-10 00:17:58 +0000 | [diff] [blame] | 1540 | /* Force a read of the debug info so that we can look for |
| 1541 | glibc entry points to intercept. */ |
sewardj | 25c7c3a | 2003-07-10 00:17:58 +0000 | [diff] [blame] | 1542 | VG_(setup_code_redirect_table)(); |
| 1543 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1544 | /* Now it is safe for malloc et al in vg_clientmalloc.c to act |
| 1545 | instrumented-ly. */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1546 | if (VG_(clo_verbosity) > 0) |
| 1547 | VG_(message)(Vg_UserMsg, ""); |
| 1548 | |
| 1549 | VG_(bbs_to_go) = VG_(clo_stop_after); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1550 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1551 | if (VG_(clo_pointercheck)) { |
| 1552 | vki_modify_ldt_t ldt = { VG_POINTERCHECK_SEGIDX, |
| 1553 | VG_(client_base), |
| 1554 | (VG_(client_end)-VG_(client_base)) / VKI_BYTES_PER_PAGE, |
| 1555 | 1, /* 32 bit */ |
| 1556 | 0, /* contents: data, RW, non-expanding */ |
| 1557 | 0, /* not read-exec only */ |
| 1558 | 1, /* limit in pages */ |
| 1559 | 0, /* !seg not present */ |
| 1560 | 1, /* usable */ |
| 1561 | }; |
| 1562 | Int ret = VG_(do_syscall)(__NR_modify_ldt, 1, &ldt, sizeof(ldt)); |
| 1563 | |
| 1564 | if (ret < 0) { |
| 1565 | VG_(message)(Vg_UserMsg, |
| 1566 | "Warning: ignoring --pointercheck=yes, " |
| 1567 | "because modify_ldt failed (errno=%d)", -ret); |
| 1568 | VG_(clo_pointercheck) = False; |
| 1569 | } |
| 1570 | } |
| 1571 | |
sewardj | 018f762 | 2002-05-15 21:13:39 +0000 | [diff] [blame] | 1572 | /* Run! */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1573 | VG_(running_on_simd_CPU) = True; |
sewardj | 671ff54 | 2002-05-07 09:25:30 +0000 | [diff] [blame] | 1574 | VGP_PUSHCC(VgpSched); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1575 | |
| 1576 | if (__builtin_setjmp(&VG_(fatal_signal_jmpbuf)) == 0) { |
| 1577 | VG_(fatal_signal_set) = True; |
| 1578 | src = VG_(scheduler)(); |
| 1579 | } else |
| 1580 | src = VgSrc_FatalSig; |
| 1581 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1582 | VGP_POPCC(VgpSched); |
| 1583 | VG_(running_on_simd_CPU) = False; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1584 | |
| 1585 | if (VG_(clo_verbosity) > 0) |
| 1586 | VG_(message)(Vg_UserMsg, ""); |
| 1587 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1588 | if (src == VgSrc_Deadlock) { |
| 1589 | VG_(message)(Vg_UserMsg, |
| 1590 | "Warning: pthread scheduler exited due to deadlock"); |
| 1591 | } |
| 1592 | |
rjwalsh | f5f536f | 2003-11-17 17:45:00 +0000 | [diff] [blame] | 1593 | /* Print out file descriptor summary and stats. */ |
| 1594 | if(VG_(clo_track_fds)) |
| 1595 | VG_(fd_stats)(); |
| 1596 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1597 | if (VG_(needs).core_errors || VG_(needs).skin_errors) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1598 | VG_(show_all_errors)(); |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 1599 | |
njn | 7d9f94d | 2003-04-22 21:41:40 +0000 | [diff] [blame] | 1600 | SK_(fini)( VG_(exitcode) ); |
njn | 4f9c934 | 2002-04-29 16:03:24 +0000 | [diff] [blame] | 1601 | |
sewardj | 0c3b53f | 2002-05-01 01:58:35 +0000 | [diff] [blame] | 1602 | VG_(do_sanity_checks)( True /*include expensive checks*/ ); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1603 | |
| 1604 | if (VG_(clo_verbosity) > 1) |
| 1605 | vg_show_counts(); |
| 1606 | |
sewardj | c0d8f68 | 2002-11-30 00:49:43 +0000 | [diff] [blame] | 1607 | if (VG_(clo_verbosity) > 3) |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1608 | VG_(print_UInstr_histogram)(); |
| 1609 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1610 | if (0) { |
| 1611 | VG_(message)(Vg_DebugMsg, ""); |
| 1612 | VG_(message)(Vg_DebugMsg, |
| 1613 | "------ Valgrind's internal memory use stats follow ------" ); |
| 1614 | VG_(mallocSanityCheckAll)(); |
| 1615 | VG_(show_all_arena_stats)(); |
| 1616 | VG_(message)(Vg_DebugMsg, |
| 1617 | "------ Valgrind's ExeContext management stats follow ------" ); |
| 1618 | VG_(show_ExeContext_stats)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1621 | if (VG_(clo_profile)) |
| 1622 | VGP_(done_profiling)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1623 | |
| 1624 | VG_(shutdown_logging)(); |
| 1625 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1626 | /* We're exiting, so nuke all the threads and clean up the proxy LWPs */ |
| 1627 | vg_assert(src == VgSrc_FatalSig || |
| 1628 | VG_(threads)[VG_(last_run_tid)].status == VgTs_Runnable || |
| 1629 | VG_(threads)[VG_(last_run_tid)].status == VgTs_WaitJoiner); |
| 1630 | VG_(nuke_all_threads_except)(VG_INVALID_THREADID); |
| 1631 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1632 | /* Decide how to exit. This depends on what the scheduler |
| 1633 | returned. */ |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1634 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1635 | switch (src) { |
| 1636 | case VgSrc_ExitSyscall: /* the normal way out */ |
| 1637 | vg_assert(VG_(last_run_tid) > 0 |
| 1638 | && VG_(last_run_tid) < VG_N_THREADS); |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1639 | VG_(proxy_shutdown)(); |
| 1640 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1641 | /* The thread's %EBX at the time it did __NR_exit() will hold |
| 1642 | the arg to __NR_exit(), so we just do __NR_exit() with |
| 1643 | that arg. */ |
| 1644 | VG_(exit)( VG_(exitcode) ); |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1645 | /* NOT ALIVE HERE! */ |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 1646 | VG_(core_panic)("entered the afterlife in vg_main() -- ExitSyscall"); |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1647 | break; /* what the hell :) */ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1648 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1649 | case VgSrc_Deadlock: |
| 1650 | /* Just exit now. No point in continuing. */ |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1651 | VG_(proxy_shutdown)(); |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1652 | VG_(exit)(0); |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 1653 | VG_(core_panic)("entered the afterlife in vg_main() -- Deadlock"); |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1654 | break; |
| 1655 | |
| 1656 | case VgSrc_BbsDone: |
| 1657 | /* Tricky; we have to try and switch back to the real CPU. |
| 1658 | This is all very dodgy and won't work at all in the |
| 1659 | presence of threads, or if the client happened to be |
| 1660 | running a signal handler. */ |
| 1661 | /* Prepare to restore state to the real CPU. */ |
sewardj | 839299f | 2003-06-14 11:57:59 +0000 | [diff] [blame] | 1662 | VG_(sigshutdown_actions)(); |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1663 | VG_(load_thread_state)(1 /* root thread */ ); |
| 1664 | VG_(copy_baseBlock_to_m_state_static)(); |
| 1665 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1666 | VG_(proxy_shutdown)(); |
| 1667 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1668 | /* This pushes a return address on the simulator's stack, |
| 1669 | which is abandoned. We call vg_sigshutdown_actions() at |
| 1670 | the end of vg_switch_to_real_CPU(), so as to ensure that |
| 1671 | the original stack and machine state is restored before |
| 1672 | the real signal mechanism is restored. */ |
| 1673 | VG_(switch_to_real_CPU)(); |
| 1674 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1675 | case VgSrc_FatalSig: |
| 1676 | /* We were killed by a fatal signal, so replicate the effect */ |
| 1677 | vg_assert(VG_(fatal_sigNo) != -1); |
| 1678 | VG_(kill_self)(VG_(fatal_sigNo)); |
| 1679 | VG_(core_panic)("vg_main(): signal was supposed to be fatal"); |
| 1680 | break; |
| 1681 | |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1682 | default: |
njn | e427a66 | 2002-10-02 11:08:25 +0000 | [diff] [blame] | 1683 | VG_(core_panic)("vg_main(): unexpected scheduler return code"); |
sewardj | 7e87e38 | 2002-05-03 19:09:05 +0000 | [diff] [blame] | 1684 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | |
| 1688 | /* Debugging thing .. can be called from assembly with OYNK macro. */ |
| 1689 | void VG_(oynk) ( Int n ) |
| 1690 | { |
| 1691 | OINK(n); |
| 1692 | } |
| 1693 | |
| 1694 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1695 | /* Walk through a colon-separated environment variable, and remove the |
| 1696 | entries which matches file_pattern. It slides everything down over |
| 1697 | the removed entries, and pads the remaining space with '\0'. It |
| 1698 | modifies the entries in place (in the client address space), but it |
| 1699 | shouldn't matter too much, since we only do this just before an |
| 1700 | execve(). |
sewardj | 78e25c9 | 2002-05-20 23:38:33 +0000 | [diff] [blame] | 1701 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1702 | This is also careful to mop up any excess ':'s, since empty strings |
| 1703 | delimited by ':' are considered to be '.' in a path. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1704 | */ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1705 | void VG_(mash_colon_env)(Char *varp, const Char *remove_pattern) |
sewardj | 45b672d | 2003-07-25 19:58:11 +0000 | [diff] [blame] | 1706 | { |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1707 | Char *const start = varp; |
| 1708 | Char *entry_start = varp; |
| 1709 | Char *output = varp; |
sewardj | 45b672d | 2003-07-25 19:58:11 +0000 | [diff] [blame] | 1710 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1711 | if (varp == NULL) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1712 | return; |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1713 | |
| 1714 | while(*varp) { |
| 1715 | if (*varp == ':') { |
| 1716 | Char prev; |
| 1717 | Bool match; |
| 1718 | |
| 1719 | /* This is a bit subtle: we want to match against the entry |
| 1720 | we just copied, because it may have overlapped with |
| 1721 | itself, junking the original. */ |
| 1722 | |
| 1723 | prev = *output; |
| 1724 | *output = '\0'; |
| 1725 | |
| 1726 | match = VG_(string_match)(remove_pattern, entry_start); |
| 1727 | |
| 1728 | *output = prev; |
| 1729 | |
| 1730 | if (match) { |
| 1731 | output = entry_start; |
| 1732 | varp++; /* skip ':' after removed entry */ |
| 1733 | } else |
| 1734 | entry_start = output+1; /* entry starts after ':' */ |
| 1735 | } |
| 1736 | |
| 1737 | *output++ = *varp++; |
sewardj | 3e1eb1f | 2002-05-18 13:14:17 +0000 | [diff] [blame] | 1738 | } |
| 1739 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1740 | /* match against the last entry */ |
| 1741 | if (VG_(string_match)(remove_pattern, entry_start)) { |
| 1742 | output = entry_start; |
| 1743 | if (output > start) { |
| 1744 | /* remove trailing ':' */ |
| 1745 | output--; |
| 1746 | vg_assert(*output == ':'); |
| 1747 | } |
| 1748 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1749 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 1750 | /* pad out the left-overs with '\0' */ |
| 1751 | while(output < varp) |
| 1752 | *output++ = '\0'; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1753 | } |
| 1754 | |
fitzhardinge | b727d04 | 2004-01-06 00:18:21 +0000 | [diff] [blame^] | 1755 | /* Start GDB and get it to attach to this process. Called if the user |
| 1756 | requests this service after an error has been shown, so she can |
| 1757 | poke around and look at parameters, memory, etc. You can't |
| 1758 | meaningfully get GDB to continue the program, though; to continue, |
| 1759 | quit GDB. */ |
| 1760 | void VG_(start_GDB) ( Int tid ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1761 | { |
fitzhardinge | b727d04 | 2004-01-06 00:18:21 +0000 | [diff] [blame^] | 1762 | Int pid; |
njn | 9315df3 | 2003-04-16 20:50:50 +0000 | [diff] [blame] | 1763 | |
fitzhardinge | b727d04 | 2004-01-06 00:18:21 +0000 | [diff] [blame^] | 1764 | if ((pid = fork()) == 0) |
| 1765 | { |
| 1766 | ptrace(PTRACE_TRACEME, 0, NULL, NULL); |
| 1767 | VG_(kkill)(VG_(getpid)(), VKI_SIGSTOP); |
| 1768 | } |
| 1769 | else if (pid > 0) |
| 1770 | { |
| 1771 | struct user_regs_struct regs; |
| 1772 | Int status; |
| 1773 | Int res; |
| 1774 | |
| 1775 | if (VG_(is_running_thread)( tid )) { |
| 1776 | regs.xcs = VG_(baseBlock)[VGOFF_(m_cs)]; |
| 1777 | regs.xss = VG_(baseBlock)[VGOFF_(m_ss)]; |
| 1778 | regs.xds = VG_(baseBlock)[VGOFF_(m_ds)]; |
| 1779 | regs.xes = VG_(baseBlock)[VGOFF_(m_es)]; |
| 1780 | regs.xfs = VG_(baseBlock)[VGOFF_(m_fs)]; |
| 1781 | regs.xgs = VG_(baseBlock)[VGOFF_(m_gs)]; |
| 1782 | regs.eax = VG_(baseBlock)[VGOFF_(m_eax)]; |
| 1783 | regs.ebx = VG_(baseBlock)[VGOFF_(m_ebx)]; |
| 1784 | regs.ecx = VG_(baseBlock)[VGOFF_(m_ecx)]; |
| 1785 | regs.edx = VG_(baseBlock)[VGOFF_(m_edx)]; |
| 1786 | regs.esi = VG_(baseBlock)[VGOFF_(m_esi)]; |
| 1787 | regs.edi = VG_(baseBlock)[VGOFF_(m_edi)]; |
| 1788 | regs.ebp = VG_(baseBlock)[VGOFF_(m_ebp)]; |
| 1789 | regs.esp = VG_(baseBlock)[VGOFF_(m_esp)]; |
| 1790 | regs.eflags = VG_(baseBlock)[VGOFF_(m_eflags)]; |
| 1791 | regs.eip = VG_(baseBlock)[VGOFF_(m_eip)]; |
| 1792 | } else { |
| 1793 | ThreadState* tst = & VG_(threads)[ tid ]; |
| 1794 | |
| 1795 | regs.xcs = tst->m_cs; |
| 1796 | regs.xss = tst->m_ss; |
| 1797 | regs.xds = tst->m_ds; |
| 1798 | regs.xes = tst->m_es; |
| 1799 | regs.xfs = tst->m_fs; |
| 1800 | regs.xgs = tst->m_gs; |
| 1801 | regs.eax = tst->m_eax; |
| 1802 | regs.ebx = tst->m_ebx; |
| 1803 | regs.ecx = tst->m_ecx; |
| 1804 | regs.edx = tst->m_edx; |
| 1805 | regs.esi = tst->m_esi; |
| 1806 | regs.edi = tst->m_edi; |
| 1807 | regs.ebp = tst->m_ebp; |
| 1808 | regs.esp = tst->m_esp; |
| 1809 | regs.eflags = tst->m_eflags; |
| 1810 | regs.eip = tst->m_eip; |
| 1811 | } |
| 1812 | |
| 1813 | if ((res = VG_(waitpid)(pid, &status, 0)) == pid && |
| 1814 | WIFSTOPPED(status) && WSTOPSIG(status) == SIGSTOP && |
| 1815 | ptrace(PTRACE_SETREGS, pid, NULL, ®s) == 0 && |
| 1816 | ptrace(PTRACE_DETACH, pid, NULL, SIGSTOP) == 0) { |
| 1817 | UChar buf[VG_(strlen)(VG_(clo_GDB_path)) + 100]; |
| 1818 | |
| 1819 | VG_(sprintf)(buf, "%s -nw /proc/%d/fd/%d %d", |
| 1820 | VG_(clo_GDB_path), VG_(main_pid), VG_(clexecfd), pid); |
| 1821 | VG_(message)(Vg_UserMsg, "starting GDB with cmd: %s", buf); |
| 1822 | res = VG_(system)(buf); |
| 1823 | if (res == 0) { |
| 1824 | VG_(message)(Vg_UserMsg, ""); |
| 1825 | VG_(message)(Vg_UserMsg, |
| 1826 | "GDB has detached. Valgrind regains control. We continue."); |
| 1827 | } else { |
| 1828 | VG_(message)(Vg_UserMsg, "Apparently failed!"); |
| 1829 | VG_(message)(Vg_UserMsg, ""); |
| 1830 | } |
| 1831 | } |
| 1832 | |
| 1833 | VG_(kkill)(pid, VKI_SIGKILL); |
| 1834 | VG_(waitpid)(pid, &status, 0); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1835 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | |
| 1839 | /* Print some helpful-ish text about unimplemented things, and give |
| 1840 | up. */ |
sewardj | cfc39b2 | 2002-05-08 01:58:18 +0000 | [diff] [blame] | 1841 | void VG_(unimplemented) ( Char* msg ) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1842 | { |
| 1843 | VG_(message)(Vg_UserMsg, ""); |
| 1844 | VG_(message)(Vg_UserMsg, |
| 1845 | "Valgrind detected that your program requires"); |
| 1846 | VG_(message)(Vg_UserMsg, |
| 1847 | "the following unimplemented functionality:"); |
| 1848 | VG_(message)(Vg_UserMsg, " %s", msg); |
| 1849 | VG_(message)(Vg_UserMsg, |
| 1850 | "This may be because the functionality is hard to implement,"); |
| 1851 | VG_(message)(Vg_UserMsg, |
| 1852 | "or because no reasonable program would behave this way,"); |
| 1853 | VG_(message)(Vg_UserMsg, |
nethercote | 421281e | 2003-11-20 16:20:55 +0000 | [diff] [blame] | 1854 | "or because nobody has yet needed it. In any case, let us know at"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1855 | VG_(message)(Vg_UserMsg, |
nethercote | 421281e | 2003-11-20 16:20:55 +0000 | [diff] [blame] | 1856 | "%s and/or try to work around the problem, if you can.", VG_BUGS_TO); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1857 | VG_(message)(Vg_UserMsg, |
| 1858 | ""); |
| 1859 | VG_(message)(Vg_UserMsg, |
| 1860 | "Valgrind has to exit now. Sorry. Bye!"); |
| 1861 | VG_(message)(Vg_UserMsg, |
| 1862 | ""); |
sewardj | 15a43e1 | 2002-04-17 19:35:12 +0000 | [diff] [blame] | 1863 | VG_(pp_sched_status)(); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1864 | VG_(exit)(1); |
| 1865 | } |
| 1866 | |
| 1867 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1868 | /* --------------------------------------------------------------------- |
| 1869 | Sanity check machinery (permanently engaged). |
| 1870 | ------------------------------------------------------------------ */ |
| 1871 | |
| 1872 | /* A fast sanity check -- suitable for calling circa once per |
| 1873 | millisecond. */ |
| 1874 | |
| 1875 | void VG_(do_sanity_checks) ( Bool force_expensive ) |
| 1876 | { |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1877 | VGP_PUSHCC(VgpCoreCheapSanity); |
| 1878 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1879 | if (VG_(sanity_level) < 1) return; |
| 1880 | |
| 1881 | /* --- First do all the tests that we can do quickly. ---*/ |
| 1882 | |
| 1883 | VG_(sanity_fast_count)++; |
| 1884 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1885 | /* Check stuff pertaining to the memory check system. */ |
| 1886 | |
| 1887 | /* Check that nobody has spuriously claimed that the first or |
| 1888 | last 16 pages of memory have become accessible [...] */ |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1889 | if (VG_(needs).sanity_checks) { |
| 1890 | VGP_PUSHCC(VgpSkinCheapSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1891 | vg_assert(SK_(cheap_sanity_check)()); |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1892 | VGP_POPCC(VgpSkinCheapSanity); |
| 1893 | } |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1894 | |
| 1895 | /* --- Now some more expensive checks. ---*/ |
| 1896 | |
| 1897 | /* Once every 25 times, check some more expensive stuff. */ |
| 1898 | if ( force_expensive |
| 1899 | || VG_(sanity_level) > 1 |
| 1900 | || (VG_(sanity_level) == 1 && (VG_(sanity_fast_count) % 25) == 0)) { |
| 1901 | |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1902 | VGP_PUSHCC(VgpCoreExpensiveSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1903 | VG_(sanity_slow_count)++; |
| 1904 | |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 1905 | VG_(proxy_sanity)(); |
| 1906 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1907 | # if 0 |
| 1908 | { void zzzmemscan(void); zzzmemscan(); } |
| 1909 | # endif |
| 1910 | |
| 1911 | if ((VG_(sanity_fast_count) % 250) == 0) |
| 1912 | VG_(sanity_check_tc_tt)(); |
| 1913 | |
| 1914 | if (VG_(needs).sanity_checks) { |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1915 | VGP_PUSHCC(VgpSkinExpensiveSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1916 | vg_assert(SK_(expensive_sanity_check)()); |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1917 | VGP_POPCC(VgpSkinExpensiveSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1918 | } |
| 1919 | /* |
| 1920 | if ((VG_(sanity_fast_count) % 500) == 0) VG_(mallocSanityCheckAll)(); |
| 1921 | */ |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1922 | VGP_POPCC(VgpCoreExpensiveSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | if (VG_(sanity_level) > 1) { |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1926 | VGP_PUSHCC(VgpCoreExpensiveSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1927 | /* Check sanity of the low-level memory manager. Note that bugs |
| 1928 | in the client's code can cause this to fail, so we don't do |
| 1929 | this check unless specially asked for. And because it's |
| 1930 | potentially very expensive. */ |
| 1931 | VG_(mallocSanityCheckAll)(); |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1932 | VGP_POPCC(VgpCoreExpensiveSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1933 | } |
njn | 37cea30 | 2002-09-30 11:24:00 +0000 | [diff] [blame] | 1934 | VGP_POPCC(VgpCoreCheapSanity); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 1935 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1936 | /*--------------------------------------------------------------------*/ |
| 1937 | /*--- end vg_main.c ---*/ |
| 1938 | /*--------------------------------------------------------------------*/ |