sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
njn | 04e1698 | 2005-05-31 00:23:43 +0000 | [diff] [blame] | 3 | /*--- Startup: the real stuff m_main.c ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
njn | b9c427c | 2004-12-01 14:14:42 +0000 | [diff] [blame] | 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 9 | |
sewardj | 9eecbbb | 2010-05-03 21:37:12 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2010 Julian Seward |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 11 | jseward@acm.org |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 12 | |
| 13 | This program is free software; you can redistribute it and/or |
| 14 | modify it under the terms of the GNU General Public License as |
| 15 | published by the Free Software Foundation; either version 2 of the |
| 16 | License, or (at your option) any later version. |
| 17 | |
| 18 | This program is distributed in the hope that it will be useful, but |
| 19 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | General Public License for more details. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 28 | The GNU General Public License is contained in the file COPYING. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 29 | */ |
| 30 | |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 31 | #include "pub_core_basics.h" |
sewardj | 4cfea4f | 2006-10-14 19:26:10 +0000 | [diff] [blame] | 32 | #include "pub_core_vki.h" |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 33 | #include "pub_core_vkiscnums.h" |
sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame] | 34 | #include "pub_core_libcsetjmp.h" // to keep _threadstate.h happy |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 35 | #include "pub_core_threadstate.h" |
sewardj | 14c7cc5 | 2007-02-25 15:08:24 +0000 | [diff] [blame] | 36 | #include "pub_core_xarray.h" |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 37 | #include "pub_core_clientstate.h" |
sewardj | 55f9d1a | 2005-04-25 11:11:44 +0000 | [diff] [blame] | 38 | #include "pub_core_aspacemgr.h" |
njn | ac1e033 | 2009-05-08 00:39:31 +0000 | [diff] [blame] | 39 | #include "pub_core_aspacehl.h" |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 40 | #include "pub_core_commandline.h" |
njn | 2521d32 | 2005-05-08 14:45:13 +0000 | [diff] [blame] | 41 | #include "pub_core_debuglog.h" |
| 42 | #include "pub_core_errormgr.h" |
| 43 | #include "pub_core_execontext.h" |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 44 | #include "pub_core_gdbserver.h" |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 45 | #include "pub_core_initimg.h" |
njn | 97405b2 | 2005-06-02 03:39:33 +0000 | [diff] [blame] | 46 | #include "pub_core_libcbase.h" |
njn | 132bfcc | 2005-06-04 19:16:06 +0000 | [diff] [blame] | 47 | #include "pub_core_libcassert.h" |
njn | eb8896b | 2005-06-04 20:03:55 +0000 | [diff] [blame] | 48 | #include "pub_core_libcfile.h" |
njn | 36a20fa | 2005-06-03 03:08:39 +0000 | [diff] [blame] | 49 | #include "pub_core_libcprint.h" |
njn | f39e9a3 | 2005-06-12 02:43:17 +0000 | [diff] [blame] | 50 | #include "pub_core_libcproc.h" |
njn | de62cbf | 2005-06-10 22:08:14 +0000 | [diff] [blame] | 51 | #include "pub_core_libcsignal.h" |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 52 | #include "pub_core_syscall.h" // VG_(strerror) |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 53 | #include "pub_core_mach.h" |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 54 | #include "pub_core_machine.h" |
njn | af1d7df | 2005-06-11 01:31:52 +0000 | [diff] [blame] | 55 | #include "pub_core_mallocfree.h" |
njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 56 | #include "pub_core_options.h" |
sewardj | fdf91b4 | 2005-09-28 00:53:09 +0000 | [diff] [blame] | 57 | #include "pub_core_debuginfo.h" |
njn | d1af003 | 2005-05-29 17:01:48 +0000 | [diff] [blame] | 58 | #include "pub_core_redir.h" |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 59 | #include "pub_core_scheduler.h" |
sewardj | f9ebc39 | 2010-05-09 22:30:43 +0000 | [diff] [blame] | 60 | #include "pub_core_seqmatch.h" // For VG_(string_match) |
njn | 0c24647 | 2005-05-31 01:00:08 +0000 | [diff] [blame] | 61 | #include "pub_core_signals.h" |
njn | 2025cf9 | 2005-06-26 20:44:48 +0000 | [diff] [blame] | 62 | #include "pub_core_stacks.h" // For VG_(register_stack) |
njn | c1b0181 | 2005-06-17 22:19:06 +0000 | [diff] [blame] | 63 | #include "pub_core_syswrap.h" |
njn | 43b9a8a | 2005-05-10 04:37:01 +0000 | [diff] [blame] | 64 | #include "pub_core_tooliface.h" |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 65 | #include "pub_core_translate.h" // For VG_(translate) |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 66 | #include "pub_core_trampoline.h" |
njn | 8bddf58 | 2005-05-13 23:40:55 +0000 | [diff] [blame] | 67 | #include "pub_core_transtab.h" |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 68 | |
| 69 | /* Stuff for reading AIX5 /proc/<pid>/sysent files */ |
| 70 | #if defined(VGO_aix5) |
| 71 | /* --- !!! --- EXTERNAL HEADERS start --- !!! --- */ |
| 72 | # include <sys/procfs.h> /* prsysent_t */ |
| 73 | /* --- !!! --- EXTERNAL HEADERS end --- !!! --- */ |
| 74 | # define VG_AIX5_SYSENT_SIZE 100000 |
| 75 | static UChar aix5_sysent_buf[VG_AIX5_SYSENT_SIZE]; |
| 76 | #endif |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 77 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 78 | |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 79 | /*====================================================================*/ |
| 80 | /*=== Counters, for profiling purposes only ===*/ |
| 81 | /*====================================================================*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 82 | |
nethercote | 3a42fb8 | 2004-08-03 18:08:50 +0000 | [diff] [blame] | 83 | static void print_all_stats ( void ) |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 84 | { |
njn | 42c8355 | 2005-12-05 20:45:59 +0000 | [diff] [blame] | 85 | VG_(print_translation_stats)(); |
nethercote | 92e7b7f | 2004-08-07 17:52:25 +0000 | [diff] [blame] | 86 | VG_(print_tt_tc_stats)(); |
nethercote | 844e712 | 2004-08-02 15:27:22 +0000 | [diff] [blame] | 87 | VG_(print_scheduler_stats)(); |
njn | 9271cbc | 2005-03-13 05:38:25 +0000 | [diff] [blame] | 88 | VG_(print_ExeContext_stats)(); |
sewardj | 12ab765 | 2006-10-17 02:10:42 +0000 | [diff] [blame] | 89 | VG_(print_errormgr_stats)(); |
njn | 9271cbc | 2005-03-13 05:38:25 +0000 | [diff] [blame] | 90 | |
nethercote | 3a42fb8 | 2004-08-03 18:08:50 +0000 | [diff] [blame] | 91 | // Memory stats |
nethercote | 885dd91 | 2004-08-03 23:14:00 +0000 | [diff] [blame] | 92 | if (VG_(clo_verbosity) > 2) { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 93 | VG_(message)(Vg_DebugMsg, "\n"); |
nethercote | 3a42fb8 | 2004-08-03 18:08:50 +0000 | [diff] [blame] | 94 | VG_(message)(Vg_DebugMsg, |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 95 | "------ Valgrind's internal memory use stats follow ------\n" ); |
nethercote | 885dd91 | 2004-08-03 23:14:00 +0000 | [diff] [blame] | 96 | VG_(sanity_check_malloc_all)(); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 97 | VG_(message)(Vg_DebugMsg, "------\n" ); |
nethercote | 3a42fb8 | 2004-08-03 18:08:50 +0000 | [diff] [blame] | 98 | VG_(print_all_arena_stats)(); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 99 | VG_(message)(Vg_DebugMsg, "\n"); |
nethercote | 3a42fb8 | 2004-08-03 18:08:50 +0000 | [diff] [blame] | 100 | } |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | |
| 104 | /*====================================================================*/ |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 105 | /*=== Command-line: variables, processing, etc ===*/ |
| 106 | /*====================================================================*/ |
| 107 | |
| 108 | // See pub_{core,tool}_options.h for explanations of all these. |
| 109 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 110 | static void usage_NORETURN ( Bool debug_help ) |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 111 | { |
sewardj | 7839d11 | 2007-11-20 19:45:03 +0000 | [diff] [blame] | 112 | /* 'usage1' contains a %s for the name of the GDB executable, which |
| 113 | must be supplied when it is VG_(printf)'d. */ |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 114 | Char* usage1 = |
njn | 00cfcfc | 2005-11-12 18:53:50 +0000 | [diff] [blame] | 115 | "usage: valgrind [options] prog-and-args\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 116 | "\n" |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 117 | " tool-selection option, with default in [ ]:\n" |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 118 | " --tool=<name> use the Valgrind tool named <name> [memcheck]\n" |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 119 | "\n" |
| 120 | " basic user options for all Valgrind tools, with defaults in [ ]:\n" |
nethercote | a76368b | 2004-06-16 11:56:29 +0000 | [diff] [blame] | 121 | " -h --help show this message\n" |
nethercote | 6c999f2 | 2004-01-31 22:55:15 +0000 | [diff] [blame] | 122 | " --help-debug show this message, plus debugging options\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 123 | " --version show version\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 124 | " -q --quiet run silently; only print error msgs\n" |
sewardj | 2d9e874 | 2009-08-07 15:46:56 +0000 | [diff] [blame] | 125 | " -v --verbose be more verbose -- show misc extra info\n" |
sewardj | 6e31f80 | 2007-11-17 22:29:25 +0000 | [diff] [blame] | 126 | " --trace-children=no|yes Valgrind-ise child processes (follow execve)? [no]\n" |
sewardj | 0642127 | 2009-11-05 08:55:13 +0000 | [diff] [blame] | 127 | " --trace-children-skip=patt1,patt2,... specifies a list of executables\n" |
| 128 | " that --trace-children=yes should not trace into\n" |
sewardj | 9ab64a4 | 2010-12-06 11:40:04 +0000 | [diff] [blame] | 129 | " --trace-children-skip-by-arg=patt1,patt2,... same as --trace-children-skip=\n" |
| 130 | " but check the argv[] entries for children, rather\n" |
| 131 | " than the exe name, to make a follow/no-follow decision\n" |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 132 | " --child-silent-after-fork=no|yes omit child output between fork & exec? [no]\n" |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 133 | " --vgdb=no|yes|full activate gdbserver? [yes]\n" |
| 134 | " full is slower but provides precise watchpoint/step\n" |
sewardj | 1568e17 | 2011-06-18 08:28:04 +0000 | [diff] [blame] | 135 | " --vgdb-error=<number> invoke gdbserver after <number> errors [%d]\n" |
| 136 | " to get started quickly, use --vgdb-error=0\n" |
| 137 | " and follow the on-screen directions\n" |
nethercote | 0d58850 | 2004-06-21 13:27:11 +0000 | [diff] [blame] | 138 | " --track-fds=no|yes track open file descriptors? [no]\n" |
thughes | 6233a38 | 2004-08-21 11:10:44 +0000 | [diff] [blame] | 139 | " --time-stamp=no|yes add timestamps to log messages? [no]\n" |
njn | ce54555 | 2005-07-25 22:36:52 +0000 | [diff] [blame] | 140 | " --log-fd=<number> log messages to file descriptor [2=stderr]\n" |
njn | 374a36d | 2007-11-23 01:41:32 +0000 | [diff] [blame] | 141 | " --log-file=<file> log messages to <file>\n" |
njn | ce54555 | 2005-07-25 22:36:52 +0000 | [diff] [blame] | 142 | " --log-socket=ipaddr:port log messages to socket ipaddr:port\n" |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 143 | "\n" |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 144 | " user options for Valgrind tools that report errors:\n" |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 145 | " --xml=yes emit error output in XML (some tools only)\n" |
| 146 | " --xml-fd=<number> XML output to file descriptor\n" |
| 147 | " --xml-file=<file> XML output to <file>\n" |
| 148 | " --xml-socket=ipaddr:port XML output to socket ipaddr:port\n" |
| 149 | " --xml-user-comment=STR copy STR verbatim into XML output\n" |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 150 | " --demangle=no|yes automatically demangle C++ names? [yes]\n" |
njn | 20b4a15 | 2005-10-19 22:39:40 +0000 | [diff] [blame] | 151 | " --num-callers=<number> show <number> callers in stack traces [12]\n" |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 152 | " --error-limit=no|yes stop showing new errors if too many? [yes]\n" |
sewardj | b977908 | 2006-05-12 23:50:15 +0000 | [diff] [blame] | 153 | " --error-exitcode=<number> exit code to return if errors found [0=disable]\n" |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 154 | " --show-below-main=no|yes continue stack traces below main() [no]\n" |
| 155 | " --suppressions=<filename> suppress errors described in <filename>\n" |
sewardj | d153fae | 2005-01-10 17:24:47 +0000 | [diff] [blame] | 156 | " --gen-suppressions=no|yes|all print suppressions for errors? [no]\n" |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 157 | " --db-attach=no|yes start debugger when errors detected? [no]\n" |
sewardj | 7839d11 | 2007-11-20 19:45:03 +0000 | [diff] [blame] | 158 | " --db-command=<command> command to start debugger [%s -nw %%f %%p]\n" |
nethercote | 04d0fbc | 2004-01-26 16:48:06 +0000 | [diff] [blame] | 159 | " --input-fd=<number> file descriptor for input [0=stdin]\n" |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 160 | " --dsymutil=no|yes run dsymutil on Mac OS X when helpful? [no]\n" |
sewardj | 97724e5 | 2005-04-02 23:40:59 +0000 | [diff] [blame] | 161 | " --max-stackframe=<number> assume stack switch for SP changes larger\n" |
| 162 | " than <number> bytes [2000000]\n" |
sewardj | 95d86c0 | 2007-12-18 01:49:23 +0000 | [diff] [blame] | 163 | " --main-stacksize=<number> set size of main thread's stack (in bytes)\n" |
| 164 | " [use current 'ulimit' value]\n" |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 165 | "\n" |
| 166 | " user options for Valgrind tools that replace malloc:\n" |
| 167 | " --alignment=<number> set minimum alignment of heap allocations [%ld]\n" |
| 168 | "\n" |
| 169 | " uncommon user options for all Valgrind tools:\n" |
sewardj | 14cdbf8 | 2010-10-12 00:44:05 +0000 | [diff] [blame] | 170 | " --fullpath-after= (with nothing after the '=')\n" |
| 171 | " show full source paths in call stacks\n" |
| 172 | " --fullpath-after=string like --fullpath-after=, but only show the\n" |
| 173 | " part of the path after 'string'. Allows removal\n" |
| 174 | " of path prefixes. Use this flag multiple times\n" |
| 175 | " to specify a set of prefixes to remove.\n" |
sewardj | 6dbcc63 | 2011-06-07 21:39:28 +0000 | [diff] [blame] | 176 | " --smc-check=none|stack|all|all-non-file [stack]\n" |
| 177 | " checks for self-modifying code: none, only for\n" |
| 178 | " code found in stacks, for all code, or for all\n" |
| 179 | " code except that from file-backed mappings\n" |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 180 | " --read-var-info=yes|no read debug info on stack and global variables\n" |
| 181 | " and use it to print better error messages in\n" |
| 182 | " tools that make use of it (Memcheck, Helgrind,\n" |
bart | f6122a0 | 2010-03-27 07:38:39 +0000 | [diff] [blame] | 183 | " DRD) [no]\n" |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 184 | " --vgdb-poll=<number> gdbserver poll max every <number> basic blocks [%d] \n" |
| 185 | " --vgdb-shadow-registers=no|yes let gdb see the shadow registers [no]\n" |
| 186 | " --vgdb-prefix=<prefix> prefix for vgdb FIFOs [%s]\n" |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 187 | " --run-libc-freeres=no|yes free up glibc memory at exit on Linux? [yes]\n" |
| 188 | " --sim-hints=hint1,hint2,... known hints:\n" |
| 189 | " lax-ioctls, enable-outer [none]\n" |
| 190 | " --kernel-variant=variant1,variant2,... known variants: bproc [none]\n" |
| 191 | " handle non-standard kernel variants\n" |
| 192 | " --show-emwarns=no|yes show warnings about emulation limits? [no]\n" |
sewardj | f9ebc39 | 2010-05-09 22:30:43 +0000 | [diff] [blame] | 193 | " --require-text-symbol=:sonamepattern:symbolpattern abort run if the\n" |
| 194 | " stated shared object doesn't have the stated\n" |
| 195 | " text symbol. Patterns can contain ? and *.\n" |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 196 | "\n"; |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 197 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 198 | Char* usage2 = |
| 199 | "\n" |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 200 | " debugging options for all Valgrind tools:\n" |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 201 | " -d show verbose debugging output\n" |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 202 | " --stats=no|yes show tool and core statistics [no]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 203 | " --sanity-level=<number> level of sanity checking to do [1]\n" |
sewardj | fa8ec11 | 2005-01-19 11:55:34 +0000 | [diff] [blame] | 204 | " --trace-flags=<XXXXXXXX> show generated code? (X = 0|1) [00000000]\n" |
| 205 | " --profile-flags=<XXXXXXXX> ditto, but for profiling (X = 0|1) [00000000]\n" |
sewardj | 33afdb5 | 2006-01-17 02:36:40 +0000 | [diff] [blame] | 206 | " --trace-notbelow=<number> only show BBs above <number> [999999999]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 207 | " --trace-syscalls=no|yes show all system calls? [no]\n" |
| 208 | " --trace-signals=no|yes show signal handling details? [no]\n" |
| 209 | " --trace-symtab=no|yes show symbol table details? [no]\n" |
sewardj | f767d96 | 2007-02-12 17:47:14 +0000 | [diff] [blame] | 210 | " --trace-symtab-patt=<patt> limit debuginfo tracing to obj name <patt>\n" |
sewardj | ce058b0 | 2005-05-01 08:55:38 +0000 | [diff] [blame] | 211 | " --trace-cfi=no|yes show call-frame-info details? [no]\n" |
sewardj | f767d96 | 2007-02-12 17:47:14 +0000 | [diff] [blame] | 212 | " --debug-dump=syms mimic /usr/bin/readelf --syms\n" |
| 213 | " --debug-dump=line mimic /usr/bin/readelf --debug-dump=line\n" |
| 214 | " --debug-dump=frames mimic /usr/bin/readelf --debug-dump=frames\n" |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 215 | " --trace-redir=no|yes show redirection details? [no]\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 216 | " --trace-sched=no|yes show thread scheduler details? [no]\n" |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 217 | " --profile-heap=no|yes profile Valgrind's own space use\n" |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 218 | " --wait-for-gdb=yes|no pause on startup to wait for gdb attach\n" |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 219 | " --sym-offsets=yes|no show syms in form 'name+offset' ? [no]\n" |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 220 | " --command-line-only=no|yes only use command line options [no]\n" |
njn | 613812e | 2005-03-11 04:57:30 +0000 | [diff] [blame] | 221 | "\n" |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 222 | " Vex options for all Valgrind tools:\n" |
| 223 | " --vex-iropt-verbosity=<0..9> [0]\n" |
| 224 | " --vex-iropt-level=<0..2> [2]\n" |
| 225 | " --vex-iropt-precise-memory-exns=no|yes [no]\n" |
| 226 | " --vex-iropt-unroll-thresh=<0..400> [120]\n" |
| 227 | " --vex-guest-max-insns=<1..100> [50]\n" |
| 228 | " --vex-guest-chase-thresh=<0..99> [10]\n" |
sewardj | 540cc4a | 2010-01-15 10:57:57 +0000 | [diff] [blame] | 229 | " --vex-guest-chase-cond=no|yes [no]\n" |
sewardj | fa8ec11 | 2005-01-19 11:55:34 +0000 | [diff] [blame] | 230 | " --trace-flags and --profile-flags values (omit the middle space):\n" |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 231 | " 1000 0000 show conversion into IR\n" |
| 232 | " 0100 0000 show after initial opt\n" |
| 233 | " 0010 0000 show after instrumentation\n" |
| 234 | " 0001 0000 show after second opt\n" |
| 235 | " 0000 1000 show after tree building\n" |
| 236 | " 0000 0100 show selecting insns\n" |
| 237 | " 0000 0010 show after reg-alloc\n" |
| 238 | " 0000 0001 show final assembly\n" |
njn | 33dbfce | 2006-06-02 22:58:34 +0000 | [diff] [blame] | 239 | " (Nb: you need --trace-notbelow with --trace-flags for full details)\n" |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 240 | "\n" |
nethercote | 2b0793f | 2003-12-02 10:41:18 +0000 | [diff] [blame] | 241 | " debugging options for Valgrind tools that report errors\n" |
| 242 | " --dump-error=<number> show translation for basic block associated\n" |
| 243 | " with <number>'th error context [0=show none]\n" |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 244 | "\n" |
| 245 | " debugging options for Valgrind tools that replace malloc:\n" |
| 246 | " --trace-malloc=no|yes show client malloc details? [no]\n" |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 247 | "\n"; |
njn | 3e88418 | 2003-04-15 13:03:23 +0000 | [diff] [blame] | 248 | |
| 249 | Char* usage3 = |
| 250 | "\n" |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 251 | " Extra options read from ~/.valgrindrc, $VALGRIND_OPTS, ./.valgrindrc\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 252 | "\n" |
njn | 10b9aea | 2009-07-14 06:55:05 +0000 | [diff] [blame] | 253 | " %s is %s\n" |
sewardj | 9eecbbb | 2010-05-03 21:37:12 +0000 | [diff] [blame] | 254 | " Valgrind is Copyright (C) 2000-2010, and GNU GPL'd, by Julian Seward et al.\n" |
sewardj | e089f01 | 2010-10-13 21:47:29 +0000 | [diff] [blame] | 255 | " LibVEX is Copyright (C) 2004-2010, and GNU GPL'd, by OpenWorks LLP et al.\n" |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 256 | "\n" |
njn | 10b9aea | 2009-07-14 06:55:05 +0000 | [diff] [blame] | 257 | " Bug reports, feedback, admiration, abuse, etc, to: %s.\n" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 258 | "\n"; |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 259 | |
sewardj | 12373b1 | 2007-11-20 21:38:14 +0000 | [diff] [blame] | 260 | Char* gdb_path = GDB_PATH; |
sewardj | 12373b1 | 2007-11-20 21:38:14 +0000 | [diff] [blame] | 261 | |
njn | be9b47b | 2005-05-15 16:22:58 +0000 | [diff] [blame] | 262 | // Ensure the message goes to stdout |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 263 | VG_(log_output_sink).fd = 1; |
| 264 | VG_(log_output_sink).is_socket = False; |
njn | be9b47b | 2005-05-15 16:22:58 +0000 | [diff] [blame] | 265 | |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 266 | /* 'usage1' expects two int, two char* argument, and one SizeT argument. */ |
| 267 | VG_(printf)(usage1, |
| 268 | VG_(clo_vgdb_error), gdb_path, VG_MIN_MALLOC_SZB, |
| 269 | VG_(clo_vgdb_poll), VG_(clo_vgdb_prefix)); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 270 | if (VG_(details).name) { |
| 271 | VG_(printf)(" user options for %s:\n", VG_(details).name); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 272 | if (VG_(needs).command_line_options) |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 273 | VG_TDICT_CALL(tool_print_usage); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 274 | else |
| 275 | VG_(printf)(" (none)\n"); |
| 276 | } |
nethercote | 6c999f2 | 2004-01-31 22:55:15 +0000 | [diff] [blame] | 277 | if (debug_help) { |
sewardj | bbaef87 | 2008-11-01 23:55:32 +0000 | [diff] [blame] | 278 | VG_(printf)("%s", usage2); |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 279 | |
nethercote | 6c999f2 | 2004-01-31 22:55:15 +0000 | [diff] [blame] | 280 | if (VG_(details).name) { |
| 281 | VG_(printf)(" debugging options for %s:\n", VG_(details).name); |
| 282 | |
| 283 | if (VG_(needs).command_line_options) |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 284 | VG_TDICT_CALL(tool_print_debug_usage); |
nethercote | 6c999f2 | 2004-01-31 22:55:15 +0000 | [diff] [blame] | 285 | else |
| 286 | VG_(printf)(" (none)\n"); |
| 287 | } |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 288 | } |
njn | 10b9aea | 2009-07-14 06:55:05 +0000 | [diff] [blame] | 289 | VG_(printf)(usage3, VG_(details).name, VG_(details).copyright_author, |
| 290 | VG_BUGS_TO); |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 291 | VG_(exit)(0); |
njn | 7cf0bd3 | 2002-06-08 13:36:03 +0000 | [diff] [blame] | 292 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 293 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 294 | |
sewardj | 95d86c0 | 2007-12-18 01:49:23 +0000 | [diff] [blame] | 295 | /* Peer at previously set up VG_(args_for_valgrind) and do some |
| 296 | minimal command line processing that must happen early on: |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 297 | |
sewardj | 95d86c0 | 2007-12-18 01:49:23 +0000 | [diff] [blame] | 298 | - show the version string, if requested (-v) |
| 299 | - extract any request for help (--help, -h, --help-debug) |
| 300 | - get the toolname (--tool=) |
| 301 | - set VG_(clo_max_stackframe) (--max-stackframe=) |
| 302 | - set VG_(clo_main_stacksize) (--main-stacksize=) |
| 303 | |
| 304 | That's all it does. The main command line processing is done below |
| 305 | by main_process_cmd_line_options. Note that |
| 306 | main_process_cmd_line_options has to handle but ignore the ones we |
| 307 | have handled here. |
| 308 | */ |
| 309 | static void early_process_cmd_line_options ( /*OUT*/Int* need_help, |
| 310 | /*OUT*/HChar** tool ) |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 311 | { |
| 312 | UInt i; |
| 313 | HChar* str; |
sewardj | 8b635a4 | 2004-11-22 19:01:47 +0000 | [diff] [blame] | 314 | |
sewardj | 14c7cc5 | 2007-02-25 15:08:24 +0000 | [diff] [blame] | 315 | vg_assert( VG_(args_for_valgrind) ); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 316 | |
sewardj | 14c7cc5 | 2007-02-25 15:08:24 +0000 | [diff] [blame] | 317 | /* parse the options we have (only the options we care about now) */ |
| 318 | for (i = 0; i < VG_(sizeXA)( VG_(args_for_valgrind) ); i++) { |
| 319 | |
| 320 | str = * (HChar**) VG_(indexXA)( VG_(args_for_valgrind), i ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 321 | vg_assert(str); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 322 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 323 | // Nb: the version string goes to stdout. |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 324 | if VG_XACT_CLO(str, "--version", VG_(log_output_sink).fd, 1) { |
| 325 | VG_(log_output_sink).is_socket = False; |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 326 | VG_(printf)("valgrind-" VERSION "\n"); |
| 327 | VG_(exit)(0); |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 328 | } |
njn | cce38e6 | 2010-07-06 04:25:12 +0000 | [diff] [blame] | 329 | else if VG_XACT_CLO(str, "--help", *need_help, *need_help+1) {} |
| 330 | else if VG_XACT_CLO(str, "-h", *need_help, *need_help+1) {} |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 331 | |
njn | cce38e6 | 2010-07-06 04:25:12 +0000 | [diff] [blame] | 332 | else if VG_XACT_CLO(str, "--help-debug", *need_help, *need_help+2) {} |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 333 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 334 | // The tool has already been determined, but we need to know the name |
| 335 | // here. |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 336 | else if VG_STR_CLO(str, "--tool", *tool) {} |
sewardj | 5bdfbd2 | 2007-12-15 22:13:05 +0000 | [diff] [blame] | 337 | |
sewardj | 95d86c0 | 2007-12-18 01:49:23 +0000 | [diff] [blame] | 338 | // Set up VG_(clo_max_stackframe) and VG_(clo_main_stacksize). |
| 339 | // These are needed by VG_(ii_create_image), which happens |
| 340 | // before main_process_cmd_line_options(). |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 341 | else if VG_INT_CLO(str, "--max-stackframe", VG_(clo_max_stackframe)) {} |
| 342 | else if VG_INT_CLO(str, "--main-stacksize", VG_(clo_main_stacksize)) {} |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 343 | } |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 344 | } |
| 345 | |
sewardj | 95d86c0 | 2007-12-18 01:49:23 +0000 | [diff] [blame] | 346 | /* The main processing for command line options. See comments above |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 347 | on early_process_cmd_line_options. |
| 348 | |
| 349 | Comments on how the logging options are handled: |
| 350 | |
| 351 | User can specify: |
| 352 | --log-fd= for a fd to write to (default setting, fd = 2) |
| 353 | --log-file= for a file name to write to |
| 354 | --log-socket= for a socket to write to |
| 355 | |
| 356 | As a result of examining these and doing relevant socket/file |
| 357 | opening, a final fd is established. This is stored in |
| 358 | VG_(log_output_sink) in m_libcprint. Also, if --log-file=STR was |
| 359 | specified, then STR, after expansion of %p and %q templates within |
| 360 | it, is stored in VG_(clo_log_fname_expanded), in m_options, just in |
| 361 | case anybody wants to know what it is. |
| 362 | |
| 363 | When printing, VG_(log_output_sink) is consulted to find the |
| 364 | fd to send output to. |
| 365 | |
| 366 | Exactly analogous actions are undertaken for the XML output |
| 367 | channel, with the one difference that the default fd is -1, meaning |
| 368 | the channel is disabled by default. |
sewardj | 95d86c0 | 2007-12-18 01:49:23 +0000 | [diff] [blame] | 369 | */ |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 370 | static |
| 371 | void main_process_cmd_line_options ( /*OUT*/Bool* logging_to_fd, |
| 372 | /*OUT*/Char** xml_fname_unexpanded, |
| 373 | const HChar* toolname ) |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 374 | { |
njn | da033f5 | 2005-12-19 21:27:58 +0000 | [diff] [blame] | 375 | // VG_(clo_log_fd) is used by all the messaging. It starts as 2 (stderr) |
| 376 | // and we cannot change it until we know what we are changing it to is |
| 377 | // ok. So we have tmp_log_fd to hold the tmp fd prior to that point. |
sewardj | 9264559 | 2005-07-23 09:18:34 +0000 | [diff] [blame] | 378 | SysRes sres; |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 379 | Int i, tmp_log_fd, tmp_xml_fd; |
sewardj | 9264559 | 2005-07-23 09:18:34 +0000 | [diff] [blame] | 380 | Int toolname_len = VG_(strlen)(toolname); |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 381 | Char* tmp_str; // Used in a couple of places. |
njn | be9b47b | 2005-05-15 16:22:58 +0000 | [diff] [blame] | 382 | enum { |
| 383 | VgLogTo_Fd, |
| 384 | VgLogTo_File, |
njn | be9b47b | 2005-05-15 16:22:58 +0000 | [diff] [blame] | 385 | VgLogTo_Socket |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 386 | } log_to = VgLogTo_Fd, // Where is logging output to be sent? |
| 387 | xml_to = VgLogTo_Fd; // Where is XML output to be sent? |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 388 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 389 | /* Temporarily holds the string STR specified with |
| 390 | --{log,xml}-{name,socket}=STR. 'fs' stands for |
| 391 | file-or-socket. */ |
| 392 | Char* log_fsname_unexpanded = NULL; |
| 393 | Char* xml_fsname_unexpanded = NULL; |
| 394 | |
| 395 | /* Log to stderr by default, but usage message goes to stdout. XML |
| 396 | output is initially disabled. */ |
njn | da033f5 | 2005-12-19 21:27:58 +0000 | [diff] [blame] | 397 | tmp_log_fd = 2; |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 398 | tmp_xml_fd = -1; |
| 399 | |
sewardj | 19d8141 | 2002-06-03 01:10:40 +0000 | [diff] [blame] | 400 | /* Check for sane path in ./configure --prefix=... */ |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 401 | if (VG_LIBDIR[0] != '/') |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 402 | VG_(err_config_error)("Please use absolute paths in " |
| 403 | "./configure --prefix=... or --libdir=..."); |
sewardj | 3817091 | 2002-05-10 21:07:22 +0000 | [diff] [blame] | 404 | |
sewardj | 14c7cc5 | 2007-02-25 15:08:24 +0000 | [diff] [blame] | 405 | vg_assert( VG_(args_for_valgrind) ); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 406 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 407 | /* BEGIN command-line processing loop */ |
| 408 | |
sewardj | 14c7cc5 | 2007-02-25 15:08:24 +0000 | [diff] [blame] | 409 | for (i = 0; i < VG_(sizeXA)( VG_(args_for_valgrind) ); i++) { |
| 410 | |
| 411 | HChar* arg = * (HChar**) VG_(indexXA)( VG_(args_for_valgrind), i ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 412 | HChar* colon = arg; |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 413 | |
njn | 1274d24 | 2007-03-26 23:38:42 +0000 | [diff] [blame] | 414 | // Look for a colon in the option name. |
thughes | 3bfd5a0 | 2004-07-18 08:05:44 +0000 | [diff] [blame] | 415 | while (*colon && *colon != ':' && *colon != '=') |
| 416 | colon++; |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 417 | |
njn | 1274d24 | 2007-03-26 23:38:42 +0000 | [diff] [blame] | 418 | // Does it have the form "--toolname:foo"? We have to do it at the start |
| 419 | // in case someone has combined a prefix with a core-specific option, |
| 420 | // eg. "--memcheck:verbose". |
thughes | 3bfd5a0 | 2004-07-18 08:05:44 +0000 | [diff] [blame] | 421 | if (*colon == ':') { |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 422 | if (VG_STREQN(2, arg, "--") && |
| 423 | VG_STREQN(toolname_len, arg+2, toolname) && |
| 424 | VG_STREQN(1, arg+2+toolname_len, ":")) |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 425 | { |
njn | 1274d24 | 2007-03-26 23:38:42 +0000 | [diff] [blame] | 426 | // Prefix matches, convert "--toolname:foo" to "--foo". |
| 427 | // Two things to note: |
| 428 | // - We cannot modify the option in-place. If we did, and then |
| 429 | // a child was spawned with --trace-children=yes, the |
| 430 | // now-non-prefixed option would be passed and could screw up |
| 431 | // the child. |
| 432 | // - We create copies, and never free them. Why? Non-prefixed |
| 433 | // options hang around forever, so tools need not make copies |
| 434 | // of strings within them. We need to have the same behaviour |
| 435 | // for prefixed options. The pointer to the copy will be lost |
| 436 | // once we leave this function (although a tool may keep a |
| 437 | // pointer into it), but the space wasted is insignificant. |
| 438 | // (In bug #142197, the copies were being freed, which caused |
| 439 | // problems for tools that reasonably assumed that arguments |
| 440 | // wouldn't disappear on them.) |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 441 | if (0) |
| 442 | VG_(printf)("tool-specific arg: %s\n", arg); |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 443 | arg = VG_(strdup)("main.mpclo.1", arg + toolname_len + 1); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 444 | arg[0] = '-'; |
| 445 | arg[1] = '-'; |
| 446 | |
| 447 | } else { |
| 448 | // prefix doesn't match, skip to next arg |
| 449 | continue; |
| 450 | } |
| 451 | } |
| 452 | |
fitzhardinge | 98abfc7 | 2003-12-16 02:05:15 +0000 | [diff] [blame] | 453 | /* Ignore these options - they've already been handled */ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 454 | if VG_STREQN( 7, arg, "--tool=") {} |
| 455 | else if VG_STREQN(20, arg, "--command-line-only=") {} |
| 456 | else if VG_STREQ( arg, "--") {} |
| 457 | else if VG_STREQ( arg, "-d") {} |
| 458 | else if VG_STREQN(16, arg, "--max-stackframe") {} |
| 459 | else if VG_STREQN(16, arg, "--main-stacksize") {} |
| 460 | else if VG_STREQN(14, arg, "--profile-heap") {} |
nethercote | 27fec90 | 2004-06-16 21:26:32 +0000 | [diff] [blame] | 461 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 462 | // These options are new. |
| 463 | else if (VG_STREQ(arg, "-v") || |
| 464 | VG_STREQ(arg, "--verbose")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 465 | VG_(clo_verbosity)++; |
nethercote | 27fec90 | 2004-06-16 21:26:32 +0000 | [diff] [blame] | 466 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 467 | else if (VG_STREQ(arg, "-q") || |
| 468 | VG_STREQ(arg, "--quiet")) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 469 | VG_(clo_verbosity)--; |
| 470 | |
sewardj | 2d9e874 | 2009-08-07 15:46:56 +0000 | [diff] [blame] | 471 | else if VG_BOOL_CLO(arg, "--stats", VG_(clo_stats)) {} |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 472 | else if VG_BOOL_CLO(arg, "--xml", VG_(clo_xml)) {} |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 473 | else if VG_XACT_CLO(arg, "--vgdb=no", VG_(clo_vgdb), Vg_VgdbNo) {} |
| 474 | else if VG_XACT_CLO(arg, "--vgdb=yes", VG_(clo_vgdb), Vg_VgdbYes) {} |
| 475 | else if VG_XACT_CLO(arg, "--vgdb=full", VG_(clo_vgdb), Vg_VgdbFull) {} |
| 476 | else if VG_INT_CLO (arg, "--vgdb-poll", VG_(clo_vgdb_poll)) {} |
| 477 | else if VG_INT_CLO (arg, "--vgdb-error", VG_(clo_vgdb_error)) {} |
| 478 | else if VG_STR_CLO (arg, "--vgdb-prefix", VG_(clo_vgdb_prefix)) {} |
| 479 | else if VG_BOOL_CLO(arg, "--vgdb-shadow-registers", |
| 480 | VG_(clo_vgdb_shadow_registers)) {} |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 481 | else if VG_BOOL_CLO(arg, "--db-attach", VG_(clo_db_attach)) {} |
| 482 | else if VG_BOOL_CLO(arg, "--demangle", VG_(clo_demangle)) {} |
| 483 | else if VG_BOOL_CLO(arg, "--error-limit", VG_(clo_error_limit)) {} |
| 484 | else if VG_INT_CLO (arg, "--error-exitcode", VG_(clo_error_exitcode)) {} |
| 485 | else if VG_BOOL_CLO(arg, "--show-emwarns", VG_(clo_show_emwarns)) {} |
sewardj | 95d86c0 | 2007-12-18 01:49:23 +0000 | [diff] [blame] | 486 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 487 | else if VG_BOOL_CLO(arg, "--run-libc-freeres", VG_(clo_run_libc_freeres)) {} |
| 488 | else if VG_BOOL_CLO(arg, "--show-below-main", VG_(clo_show_below_main)) {} |
| 489 | else if VG_BOOL_CLO(arg, "--time-stamp", VG_(clo_time_stamp)) {} |
| 490 | else if VG_BOOL_CLO(arg, "--track-fds", VG_(clo_track_fds)) {} |
| 491 | else if VG_BOOL_CLO(arg, "--trace-children", VG_(clo_trace_children)) {} |
| 492 | else if VG_BOOL_CLO(arg, "--child-silent-after-fork", |
| 493 | VG_(clo_child_silent_after_fork)) {} |
| 494 | else if VG_BOOL_CLO(arg, "--trace-sched", VG_(clo_trace_sched)) {} |
| 495 | else if VG_BOOL_CLO(arg, "--trace-signals", VG_(clo_trace_signals)) {} |
| 496 | else if VG_BOOL_CLO(arg, "--trace-symtab", VG_(clo_trace_symtab)) {} |
| 497 | else if VG_STR_CLO (arg, "--trace-symtab-patt", VG_(clo_trace_symtab_patt)) {} |
| 498 | else if VG_BOOL_CLO(arg, "--trace-cfi", VG_(clo_trace_cfi)) {} |
| 499 | else if VG_XACT_CLO(arg, "--debug-dump=syms", VG_(clo_debug_dump_syms), |
| 500 | True) {} |
| 501 | else if VG_XACT_CLO(arg, "--debug-dump=line", VG_(clo_debug_dump_line), |
| 502 | True) {} |
| 503 | else if VG_XACT_CLO(arg, "--debug-dump=frames", |
| 504 | VG_(clo_debug_dump_frames), True) {} |
| 505 | else if VG_BOOL_CLO(arg, "--trace-redir", VG_(clo_trace_redir)) {} |
sewardj | 95d86c0 | 2007-12-18 01:49:23 +0000 | [diff] [blame] | 506 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 507 | else if VG_BOOL_CLO(arg, "--trace-syscalls", VG_(clo_trace_syscalls)) {} |
| 508 | else if VG_BOOL_CLO(arg, "--wait-for-gdb", VG_(clo_wait_for_gdb)) {} |
| 509 | else if VG_STR_CLO (arg, "--db-command", VG_(clo_db_command)) {} |
| 510 | else if VG_STR_CLO (arg, "--sim-hints", VG_(clo_sim_hints)) {} |
| 511 | else if VG_BOOL_CLO(arg, "--sym-offsets", VG_(clo_sym_offsets)) {} |
| 512 | else if VG_BOOL_CLO(arg, "--read-var-info", VG_(clo_read_var_info)) {} |
sewardj | f767d96 | 2007-02-12 17:47:14 +0000 | [diff] [blame] | 513 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 514 | else if VG_INT_CLO (arg, "--dump-error", VG_(clo_dump_error)) {} |
| 515 | else if VG_INT_CLO (arg, "--input-fd", VG_(clo_input_fd)) {} |
| 516 | else if VG_INT_CLO (arg, "--sanity-level", VG_(clo_sanity_level)) {} |
| 517 | else if VG_BINT_CLO(arg, "--num-callers", VG_(clo_backtrace_size), 1, |
| 518 | VG_DEEPEST_BACKTRACE) {} |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 519 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 520 | else if VG_XACT_CLO(arg, "--smc-check=none", VG_(clo_smc_check), |
| 521 | Vg_SmcNone); |
| 522 | else if VG_XACT_CLO(arg, "--smc-check=stack", VG_(clo_smc_check), |
| 523 | Vg_SmcStack); |
| 524 | else if VG_XACT_CLO(arg, "--smc-check=all", VG_(clo_smc_check), |
| 525 | Vg_SmcAll); |
sewardj | 6dbcc63 | 2011-06-07 21:39:28 +0000 | [diff] [blame] | 526 | else if VG_XACT_CLO(arg, "--smc-check=all-non-file", |
| 527 | VG_(clo_smc_check), |
| 528 | Vg_SmcAllNonFile); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 529 | |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 530 | else if VG_STR_CLO (arg, "--kernel-variant", VG_(clo_kernel_variant)) {} |
sewardj | 26412bd | 2005-07-07 10:05:05 +0000 | [diff] [blame] | 531 | |
njn | 97db761 | 2009-08-04 02:32:55 +0000 | [diff] [blame] | 532 | else if VG_BOOL_CLO(arg, "--dsymutil", VG_(clo_dsymutil)) {} |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 533 | |
sewardj | 9ab64a4 | 2010-12-06 11:40:04 +0000 | [diff] [blame] | 534 | else if VG_STR_CLO (arg, "--trace-children-skip", |
| 535 | VG_(clo_trace_children_skip)) {} |
| 536 | else if VG_STR_CLO (arg, "--trace-children-skip-by-arg", |
| 537 | VG_(clo_trace_children_skip_by_arg)) {} |
sewardj | 0642127 | 2009-11-05 08:55:13 +0000 | [diff] [blame] | 538 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 539 | else if VG_BINT_CLO(arg, "--vex-iropt-verbosity", |
| 540 | VG_(clo_vex_control).iropt_verbosity, 0, 10) {} |
| 541 | else if VG_BINT_CLO(arg, "--vex-iropt-level", |
| 542 | VG_(clo_vex_control).iropt_level, 0, 2) {} |
| 543 | else if VG_BOOL_CLO(arg, "--vex-iropt-precise-memory-exns", |
| 544 | VG_(clo_vex_control).iropt_precise_memory_exns) {} |
| 545 | else if VG_BINT_CLO(arg, "--vex-iropt-unroll-thresh", |
| 546 | VG_(clo_vex_control).iropt_unroll_thresh, 0, 400) {} |
| 547 | else if VG_BINT_CLO(arg, "--vex-guest-max-insns", |
| 548 | VG_(clo_vex_control).guest_max_insns, 1, 100) {} |
| 549 | else if VG_BINT_CLO(arg, "--vex-guest-chase-thresh", |
| 550 | VG_(clo_vex_control).guest_chase_thresh, 0, 99) {} |
sewardj | 540cc4a | 2010-01-15 10:57:57 +0000 | [diff] [blame] | 551 | else if VG_BOOL_CLO(arg, "--vex-guest-chase-cond", |
| 552 | VG_(clo_vex_control).guest_chase_cond) {} |
sewardj | 94c8eb4 | 2008-09-19 20:13:39 +0000 | [diff] [blame] | 553 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 554 | else if VG_INT_CLO(arg, "--log-fd", tmp_log_fd) { |
| 555 | log_to = VgLogTo_Fd; |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 556 | log_fsname_unexpanded = NULL; |
| 557 | } |
| 558 | else if VG_INT_CLO(arg, "--xml-fd", tmp_xml_fd) { |
| 559 | xml_to = VgLogTo_Fd; |
| 560 | xml_fsname_unexpanded = NULL; |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 561 | } |
| 562 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 563 | else if VG_STR_CLO(arg, "--log-file", log_fsname_unexpanded) { |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 564 | log_to = VgLogTo_File; |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 565 | } |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 566 | else if VG_STR_CLO(arg, "--xml-file", xml_fsname_unexpanded) { |
| 567 | xml_to = VgLogTo_File; |
| 568 | } |
| 569 | |
| 570 | else if VG_STR_CLO(arg, "--log-socket", log_fsname_unexpanded) { |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 571 | log_to = VgLogTo_Socket; |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 572 | } |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 573 | else if VG_STR_CLO(arg, "--xml-socket", xml_fsname_unexpanded) { |
| 574 | xml_to = VgLogTo_Socket; |
| 575 | } |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 576 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 577 | else if VG_STR_CLO(arg, "--xml-user-comment", |
| 578 | VG_(clo_xml_user_comment)) {} |
sewardj | 768db0e | 2005-07-19 14:18:56 +0000 | [diff] [blame] | 579 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 580 | else if VG_STR_CLO(arg, "--suppressions", tmp_str) { |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 581 | if (VG_(clo_n_suppressions) >= VG_CLO_MAX_SFILES) { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 582 | VG_(fmsg_bad_option)(arg, |
| 583 | "Too many suppression files specified.\n" |
| 584 | "Increase VG_CLO_MAX_SFILES and recompile.\n"); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 585 | } |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 586 | VG_(clo_suppressions)[VG_(clo_n_suppressions)] = tmp_str; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 587 | VG_(clo_n_suppressions)++; |
| 588 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 589 | |
sewardj | 14cdbf8 | 2010-10-12 00:44:05 +0000 | [diff] [blame] | 590 | else if VG_STR_CLO (arg, "--fullpath-after", tmp_str) { |
| 591 | if (VG_(clo_n_fullpath_after) >= VG_CLO_MAX_FULLPATH_AFTER) { |
| 592 | VG_(fmsg_bad_option)(arg, |
| 593 | "Too many --fullpath-after= specifications.\n" |
| 594 | "Increase VG_CLO_MAX_FULLPATH_AFTER and recompile.\n"); |
| 595 | } |
| 596 | VG_(clo_fullpath_after)[VG_(clo_n_fullpath_after)] = tmp_str; |
| 597 | VG_(clo_n_fullpath_after)++; |
| 598 | } |
| 599 | |
sewardj | f9ebc39 | 2010-05-09 22:30:43 +0000 | [diff] [blame] | 600 | else if VG_STR_CLO(arg, "--require-text-symbol", tmp_str) { |
| 601 | if (VG_(clo_n_req_tsyms) >= VG_CLO_MAX_REQ_TSYMS) { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 602 | VG_(fmsg_bad_option)(arg, |
| 603 | "Too many --require-text-symbol= specifications.\n" |
| 604 | "Increase VG_CLO_MAX_REQ_TSYMS and recompile.\n"); |
sewardj | f9ebc39 | 2010-05-09 22:30:43 +0000 | [diff] [blame] | 605 | } |
| 606 | /* String needs to be of the form C?*C?*, where C is any |
| 607 | character, but is the same both times. Having it in this |
| 608 | form facilitates finding the boundary between the sopatt |
| 609 | and the fnpatt just by looking for the second occurrence |
| 610 | of C, without hardwiring any assumption about what C |
| 611 | is. */ |
| 612 | Char patt[7]; |
| 613 | Bool ok = True; |
| 614 | ok = tmp_str && VG_(strlen)(tmp_str) > 0; |
| 615 | if (ok) { |
| 616 | patt[0] = patt[3] = tmp_str[0]; |
| 617 | patt[1] = patt[4] = '?'; |
| 618 | patt[2] = patt[5] = '*'; |
| 619 | patt[6] = 0; |
| 620 | ok = VG_(string_match)(patt, tmp_str); |
| 621 | } |
| 622 | if (!ok) { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 623 | VG_(fmsg_bad_option)(arg, |
| 624 | "Invalid --require-text-symbol= specification.\n"); |
sewardj | f9ebc39 | 2010-05-09 22:30:43 +0000 | [diff] [blame] | 625 | } |
| 626 | VG_(clo_req_tsyms)[VG_(clo_n_req_tsyms)] = tmp_str; |
| 627 | VG_(clo_n_req_tsyms)++; |
| 628 | } |
| 629 | |
sewardj | fa8ec11 | 2005-01-19 11:55:34 +0000 | [diff] [blame] | 630 | /* "stuvwxyz" --> stuvwxyz (binary) */ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 631 | else if VG_STR_CLO(arg, "--trace-flags", tmp_str) { |
sewardj | fa8ec11 | 2005-01-19 11:55:34 +0000 | [diff] [blame] | 632 | Int j; |
sewardj | fa8ec11 | 2005-01-19 11:55:34 +0000 | [diff] [blame] | 633 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 634 | if (8 != VG_(strlen)(tmp_str)) { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 635 | VG_(fmsg_bad_option)(arg, |
| 636 | "--trace-flags argument must have 8 digits\n"); |
sewardj | fa8ec11 | 2005-01-19 11:55:34 +0000 | [diff] [blame] | 637 | } |
| 638 | for (j = 0; j < 8; j++) { |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 639 | if ('0' == tmp_str[j]) { /* do nothing */ } |
| 640 | else if ('1' == tmp_str[j]) VG_(clo_trace_flags) |= (1 << (7-j)); |
sewardj | fa8ec11 | 2005-01-19 11:55:34 +0000 | [diff] [blame] | 641 | else { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 642 | VG_(fmsg_bad_option)(arg, |
| 643 | "--trace-flags argument can only contain 0s and 1s\n"); |
sewardj | fa8ec11 | 2005-01-19 11:55:34 +0000 | [diff] [blame] | 644 | } |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | /* "stuvwxyz" --> stuvwxyz (binary) */ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 649 | else if VG_STR_CLO(arg, "--profile-flags", tmp_str) { |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 650 | Int j; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 651 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 652 | if (8 != VG_(strlen)(tmp_str)) { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 653 | VG_(fmsg_bad_option)(arg, |
| 654 | "--profile-flags argument must have 8 digits\n"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 655 | } |
sewardj | 8b635a4 | 2004-11-22 19:01:47 +0000 | [diff] [blame] | 656 | for (j = 0; j < 8; j++) { |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 657 | if ('0' == tmp_str[j]) { /* do nothing */ } |
| 658 | else if ('1' == tmp_str[j]) VG_(clo_profile_flags) |= (1 << (7-j)); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 659 | else { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 660 | VG_(fmsg_bad_option)(arg, |
| 661 | "--profile-flags argument can only contain 0s and 1s\n"); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 665 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 666 | else if VG_INT_CLO (arg, "--trace-notbelow", VG_(clo_trace_notbelow)) {} |
sewardj | c771b29 | 2004-11-30 18:55:21 +0000 | [diff] [blame] | 667 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 668 | else if VG_XACT_CLO(arg, "--gen-suppressions=no", |
| 669 | VG_(clo_gen_suppressions), 0) {} |
| 670 | else if VG_XACT_CLO(arg, "--gen-suppressions=yes", |
| 671 | VG_(clo_gen_suppressions), 1) {} |
| 672 | else if VG_XACT_CLO(arg, "--gen-suppressions=all", |
| 673 | VG_(clo_gen_suppressions), 2) {} |
sewardj | d153fae | 2005-01-10 17:24:47 +0000 | [diff] [blame] | 674 | |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 675 | else if ( ! VG_(needs).command_line_options |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 676 | || ! VG_TDICT_CALL(tool_process_cmd_line_option, arg) ) { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 677 | VG_(fmsg_bad_option)(arg, ""); |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 678 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 679 | } |
| 680 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 681 | /* END command-line processing loop */ |
| 682 | |
sewardj | 998d40d | 2004-12-06 14:24:52 +0000 | [diff] [blame] | 683 | /* Make VEX control parameters sane */ |
| 684 | |
| 685 | if (VG_(clo_vex_control).guest_chase_thresh |
| 686 | >= VG_(clo_vex_control).guest_max_insns) |
| 687 | VG_(clo_vex_control).guest_chase_thresh |
| 688 | = VG_(clo_vex_control).guest_max_insns - 1; |
| 689 | |
| 690 | if (VG_(clo_vex_control).guest_chase_thresh < 0) |
| 691 | VG_(clo_vex_control).guest_chase_thresh = 0; |
| 692 | |
| 693 | /* Check various option values */ |
nethercote | 27fec90 | 2004-06-16 21:26:32 +0000 | [diff] [blame] | 694 | |
njn | f9ebf67 | 2003-05-12 21:41:30 +0000 | [diff] [blame] | 695 | if (VG_(clo_verbosity) < 0) |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 696 | VG_(clo_verbosity) = 0; |
| 697 | |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 698 | VG_(dyn_vgdb_error) = VG_(clo_vgdb_error); |
| 699 | |
njn | be9b47b | 2005-05-15 16:22:58 +0000 | [diff] [blame] | 700 | if (VG_(clo_gen_suppressions) > 0 && |
| 701 | !VG_(needs).core_errors && !VG_(needs).tool_errors) { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 702 | VG_(fmsg_bad_option)("--gen-suppressions=yes", |
| 703 | "Can't use --gen-suppressions= with %s\n" |
| 704 | "because it doesn't generate errors.\n", VG_(details).name); |
njn | be9b47b | 2005-05-15 16:22:58 +0000 | [diff] [blame] | 705 | } |
| 706 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 707 | /* If XML output is requested, check that the tool actually |
| 708 | supports it. */ |
| 709 | if (VG_(clo_xml) && !VG_(needs).xml_output) { |
| 710 | VG_(clo_xml) = False; |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 711 | VG_(fmsg_bad_option)("--xml=yes", |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 712 | "%s does not support XML output.\n", VG_(details).name); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 713 | /*NOTREACHED*/ |
| 714 | } |
| 715 | |
| 716 | vg_assert( VG_(clo_gen_suppressions) >= 0 ); |
| 717 | vg_assert( VG_(clo_gen_suppressions) <= 2 ); |
| 718 | |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 719 | /* If we've been asked to emit XML, mash around various other |
| 720 | options so as to constrain the output somewhat, and to remove |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 721 | any need for user input during the run. |
| 722 | */ |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 723 | if (VG_(clo_xml)) { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 724 | |
| 725 | /* We can't allow --gen-suppressions=yes, since that requires us |
| 726 | to print the error and then ask the user if she wants a |
| 727 | suppression for it, but in XML mode we won't print it until |
| 728 | we know whether we also need to print a suppression. Hence a |
| 729 | circular dependency. So disallow this. |
| 730 | (--gen-suppressions=all is still OK since we don't need any |
| 731 | user interaction in this case.) */ |
| 732 | if (VG_(clo_gen_suppressions) == 1) { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 733 | VG_(fmsg_bad_option)( |
| 734 | "--xml=yes together with --gen-suppressions=yes", |
| 735 | "When --xml=yes is specified, --gen-suppressions=no\n" |
| 736 | "or --gen-suppressions=all is allowed, but not " |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 737 | "--gen-suppressions=yes.\n"); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | /* We can't allow DB attaching (or we maybe could, but results |
| 741 | could be chaotic ..) since it requires user input. Hence |
| 742 | disallow. */ |
| 743 | if (VG_(clo_db_attach)) { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 744 | VG_(fmsg_bad_option)( |
| 745 | "--xml=yes together with --db-attach=yes", |
| 746 | "--db-attach=yes is not allowed with --xml=yes\n" |
| 747 | "because it would require user input.\n"); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | /* Disallow dump_error in XML mode; sounds like a recipe for |
| 751 | chaos. No big deal; dump_error is a flag for debugging V |
| 752 | itself. */ |
| 753 | if (VG_(clo_dump_error) > 0) { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 754 | VG_(fmsg_bad_option)("--xml=yes together with --dump-error", ""); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 755 | } |
| 756 | |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 757 | /* Disable error limits (this might be a bad idea!) */ |
| 758 | VG_(clo_error_limit) = False; |
| 759 | /* Disable emulation warnings */ |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 760 | |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 761 | /* Also, we want to set options for the leak checker, but that |
| 762 | will have to be done in Memcheck's flag-handling code, not |
| 763 | here. */ |
| 764 | } |
| 765 | |
njn | be9b47b | 2005-05-15 16:22:58 +0000 | [diff] [blame] | 766 | /* All non-logging-related options have been checked. If the logging |
| 767 | option specified is ok, we can switch to it, as we know we won't |
| 768 | have to generate any other command-line-related error messages. |
| 769 | (So far we should be still attached to stderr, so we can show on |
| 770 | the terminal any problems to do with processing command line |
| 771 | opts.) |
| 772 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 773 | So set up logging now. After this is done, VG_(log_output_sink) |
| 774 | and (if relevant) VG_(xml_output_sink) should be connected to |
| 775 | whatever sink has been selected, and we indiscriminately chuck |
| 776 | stuff into it without worrying what the nature of it is. Oh the |
| 777 | wonder of Unix streams. */ |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 778 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 779 | vg_assert(VG_(log_output_sink).fd == 2 /* stderr */); |
| 780 | vg_assert(VG_(log_output_sink).is_socket == False); |
| 781 | vg_assert(VG_(clo_log_fname_expanded) == NULL); |
| 782 | |
| 783 | vg_assert(VG_(xml_output_sink).fd == -1 /* disabled */); |
| 784 | vg_assert(VG_(xml_output_sink).is_socket == False); |
| 785 | vg_assert(VG_(clo_xml_fname_expanded) == NULL); |
| 786 | |
| 787 | /* --- set up the normal text output channel --- */ |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 788 | |
njn | be9b47b | 2005-05-15 16:22:58 +0000 | [diff] [blame] | 789 | switch (log_to) { |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 790 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 791 | case VgLogTo_Fd: |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 792 | vg_assert(log_fsname_unexpanded == NULL); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 793 | break; |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 794 | |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 795 | case VgLogTo_File: { |
njn | 374a36d | 2007-11-23 01:41:32 +0000 | [diff] [blame] | 796 | Char* logfilename; |
jsgf | f3c3f1a | 2003-10-14 22:13:28 +0000 | [diff] [blame] | 797 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 798 | vg_assert(log_fsname_unexpanded != NULL); |
| 799 | vg_assert(VG_(strlen)(log_fsname_unexpanded) <= 900); /* paranoia */ |
jsgf | f3c3f1a | 2003-10-14 22:13:28 +0000 | [diff] [blame] | 800 | |
njn | 374a36d | 2007-11-23 01:41:32 +0000 | [diff] [blame] | 801 | // Nb: we overwrite an existing file of this name without asking |
| 802 | // any questions. |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 803 | logfilename = VG_(expand_file_name)("--log-file", |
| 804 | log_fsname_unexpanded); |
njn | 374a36d | 2007-11-23 01:41:32 +0000 | [diff] [blame] | 805 | sres = VG_(open)(logfilename, |
njn | da033f5 | 2005-12-19 21:27:58 +0000 | [diff] [blame] | 806 | VKI_O_CREAT|VKI_O_WRONLY|VKI_O_TRUNC, |
| 807 | VKI_S_IRUSR|VKI_S_IWUSR); |
njn | cda2f0f | 2009-05-18 02:12:08 +0000 | [diff] [blame] | 808 | if (!sr_isError(sres)) { |
| 809 | tmp_log_fd = sr_Res(sres); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 810 | VG_(clo_log_fname_expanded) = logfilename; |
njn | be9b47b | 2005-05-15 16:22:58 +0000 | [diff] [blame] | 811 | } else { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 812 | VG_(fmsg)("can't create log file '%s': %s\n", |
| 813 | logfilename, VG_(strerror)(sr_Err(sres))); |
| 814 | VG_(exit)(1); |
sewardj | 603d410 | 2005-01-11 14:01:02 +0000 | [diff] [blame] | 815 | /*NOTREACHED*/ |
njn | 374a36d | 2007-11-23 01:41:32 +0000 | [diff] [blame] | 816 | } |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 817 | break; |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | case VgLogTo_Socket: { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 821 | vg_assert(log_fsname_unexpanded != NULL); |
| 822 | vg_assert(VG_(strlen)(log_fsname_unexpanded) <= 900); /* paranoia */ |
| 823 | tmp_log_fd = VG_(connect_via_socket)( log_fsname_unexpanded ); |
njn | da033f5 | 2005-12-19 21:27:58 +0000 | [diff] [blame] | 824 | if (tmp_log_fd == -1) { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 825 | VG_(fmsg)("Invalid --log-socket spec of '%s'\n", |
| 826 | log_fsname_unexpanded); |
| 827 | VG_(exit)(1); |
njn | be9b47b | 2005-05-15 16:22:58 +0000 | [diff] [blame] | 828 | /*NOTREACHED*/ |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 829 | } |
njn | da033f5 | 2005-12-19 21:27:58 +0000 | [diff] [blame] | 830 | if (tmp_log_fd == -2) { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 831 | VG_(umsg)("failed to connect to logging server '%s'.\n" |
| 832 | "Log messages will sent to stderr instead.\n", |
| 833 | log_fsname_unexpanded ); |
| 834 | |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 835 | /* We don't change anything here. */ |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 836 | vg_assert(VG_(log_output_sink).fd == 2); |
njn | da033f5 | 2005-12-19 21:27:58 +0000 | [diff] [blame] | 837 | tmp_log_fd = 2; |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 838 | } else { |
njn | da033f5 | 2005-12-19 21:27:58 +0000 | [diff] [blame] | 839 | vg_assert(tmp_log_fd > 0); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 840 | VG_(log_output_sink).is_socket = True; |
sewardj | 570f890 | 2002-11-03 11:44:36 +0000 | [diff] [blame] | 841 | } |
sewardj | 73cf3bc | 2002-11-03 03:20:15 +0000 | [diff] [blame] | 842 | break; |
| 843 | } |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 844 | } |
| 845 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 846 | /* --- set up the XML output channel --- */ |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 847 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 848 | switch (xml_to) { |
| 849 | |
| 850 | case VgLogTo_Fd: |
| 851 | vg_assert(xml_fsname_unexpanded == NULL); |
| 852 | break; |
| 853 | |
| 854 | case VgLogTo_File: { |
| 855 | Char* xmlfilename; |
| 856 | |
| 857 | vg_assert(xml_fsname_unexpanded != NULL); |
| 858 | vg_assert(VG_(strlen)(xml_fsname_unexpanded) <= 900); /* paranoia */ |
| 859 | |
| 860 | // Nb: we overwrite an existing file of this name without asking |
| 861 | // any questions. |
| 862 | xmlfilename = VG_(expand_file_name)("--xml-file", |
| 863 | xml_fsname_unexpanded); |
| 864 | sres = VG_(open)(xmlfilename, |
| 865 | VKI_O_CREAT|VKI_O_WRONLY|VKI_O_TRUNC, |
| 866 | VKI_S_IRUSR|VKI_S_IWUSR); |
| 867 | if (!sr_isError(sres)) { |
| 868 | tmp_xml_fd = sr_Res(sres); |
| 869 | VG_(clo_xml_fname_expanded) = xmlfilename; |
| 870 | /* strdup here is probably paranoid overkill, but ... */ |
| 871 | *xml_fname_unexpanded = VG_(strdup)( "main.mpclo.2", |
| 872 | xml_fsname_unexpanded ); |
| 873 | } else { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 874 | VG_(fmsg)("can't create XML file '%s': %s\n", |
| 875 | xmlfilename, VG_(strerror)(sr_Err(sres))); |
| 876 | VG_(exit)(1); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 877 | /*NOTREACHED*/ |
| 878 | } |
| 879 | break; |
| 880 | } |
| 881 | |
| 882 | case VgLogTo_Socket: { |
| 883 | vg_assert(xml_fsname_unexpanded != NULL); |
| 884 | vg_assert(VG_(strlen)(xml_fsname_unexpanded) <= 900); /* paranoia */ |
| 885 | tmp_xml_fd = VG_(connect_via_socket)( xml_fsname_unexpanded ); |
| 886 | if (tmp_xml_fd == -1) { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 887 | VG_(fmsg)("Invalid --xml-socket spec of '%s'\n", |
| 888 | xml_fsname_unexpanded ); |
| 889 | VG_(exit)(1); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 890 | /*NOTREACHED*/ |
| 891 | } |
| 892 | if (tmp_xml_fd == -2) { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 893 | VG_(umsg)("failed to connect to XML logging server '%s'.\n" |
| 894 | "XML output will sent to stderr instead.\n", |
| 895 | xml_fsname_unexpanded); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 896 | /* We don't change anything here. */ |
| 897 | vg_assert(VG_(xml_output_sink).fd == 2); |
| 898 | tmp_xml_fd = 2; |
| 899 | } else { |
| 900 | vg_assert(tmp_xml_fd > 0); |
| 901 | VG_(xml_output_sink).is_socket = True; |
| 902 | } |
| 903 | break; |
| 904 | } |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 905 | } |
| 906 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 907 | /* If we've got this far, and XML mode was requested, but no XML |
| 908 | output channel appears to have been specified, just stop. We |
| 909 | could continue, and XML output will simply vanish into nowhere, |
| 910 | but that is likely to confuse the hell out of users, which is |
| 911 | distinctly Ungood. */ |
| 912 | if (VG_(clo_xml) && tmp_xml_fd == -1) { |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 913 | VG_(fmsg_bad_option)( |
| 914 | "--xml=yes, but no XML destination specified", |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 915 | "--xml=yes has been specified, but there is no XML output\n" |
| 916 | "destination. You must specify an XML output destination\n" |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 917 | "using --xml-fd, --xml-file or --xml-socket.\n" |
| 918 | ); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | // Finalise the output fds: the log fd .. |
| 922 | |
njn | da033f5 | 2005-12-19 21:27:58 +0000 | [diff] [blame] | 923 | if (tmp_log_fd >= 0) { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 924 | // Move log_fd into the safe range, so it doesn't conflict with |
| 925 | // any app fds. |
njn | da033f5 | 2005-12-19 21:27:58 +0000 | [diff] [blame] | 926 | tmp_log_fd = VG_(fcntl)(tmp_log_fd, VKI_F_DUPFD, VG_(fd_hard_limit)); |
| 927 | if (tmp_log_fd < 0) { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 928 | VG_(message)(Vg_UserMsg, "valgrind: failed to move logfile fd " |
| 929 | "into safe range, using stderr\n"); |
| 930 | VG_(log_output_sink).fd = 2; // stderr |
| 931 | VG_(log_output_sink).is_socket = False; |
njn | da033f5 | 2005-12-19 21:27:58 +0000 | [diff] [blame] | 932 | } else { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 933 | VG_(log_output_sink).fd = tmp_log_fd; |
| 934 | VG_(fcntl)(VG_(log_output_sink).fd, VKI_F_SETFD, VKI_FD_CLOEXEC); |
njn | da033f5 | 2005-12-19 21:27:58 +0000 | [diff] [blame] | 935 | } |
| 936 | } else { |
| 937 | // If they said --log-fd=-1, don't print anything. Plausible for use in |
| 938 | // regression testing suites that use client requests to count errors. |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 939 | VG_(log_output_sink).fd = -1; |
| 940 | VG_(log_output_sink).is_socket = False; |
jsgf | 855d93d | 2003-10-13 22:26:55 +0000 | [diff] [blame] | 941 | } |
| 942 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 943 | // Finalise the output fds: and the XML fd .. |
| 944 | |
| 945 | if (tmp_xml_fd >= 0) { |
| 946 | // Move xml_fd into the safe range, so it doesn't conflict with |
| 947 | // any app fds. |
| 948 | tmp_xml_fd = VG_(fcntl)(tmp_xml_fd, VKI_F_DUPFD, VG_(fd_hard_limit)); |
| 949 | if (tmp_xml_fd < 0) { |
| 950 | VG_(message)(Vg_UserMsg, "valgrind: failed to move XML file fd " |
| 951 | "into safe range, using stderr\n"); |
| 952 | VG_(xml_output_sink).fd = 2; // stderr |
| 953 | VG_(xml_output_sink).is_socket = False; |
| 954 | } else { |
| 955 | VG_(xml_output_sink).fd = tmp_xml_fd; |
| 956 | VG_(fcntl)(VG_(xml_output_sink).fd, VKI_F_SETFD, VKI_FD_CLOEXEC); |
| 957 | } |
| 958 | } else { |
| 959 | // If they said --xml-fd=-1, don't print anything. Plausible for use in |
| 960 | // regression testing suites that use client requests to count errors. |
| 961 | VG_(xml_output_sink).fd = -1; |
| 962 | VG_(xml_output_sink).is_socket = False; |
| 963 | } |
| 964 | |
| 965 | // Suppressions related stuff |
| 966 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 967 | if (VG_(clo_n_suppressions) < VG_CLO_MAX_SFILES-1 && |
| 968 | (VG_(needs).core_errors || VG_(needs).tool_errors)) { |
| 969 | /* If we haven't reached the max number of suppressions, load |
| 970 | the default one. */ |
| 971 | static const Char default_supp[] = "default.supp"; |
| 972 | Int len = VG_(strlen)(VG_(libdir)) + 1 + sizeof(default_supp); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 973 | Char *buf = VG_(arena_malloc)(VG_AR_CORE, "main.mpclo.3", len); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 974 | VG_(sprintf)(buf, "%s/%s", VG_(libdir), default_supp); |
| 975 | VG_(clo_suppressions)[VG_(clo_n_suppressions)] = buf; |
| 976 | VG_(clo_n_suppressions)++; |
| 977 | } |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 978 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 979 | *logging_to_fd = log_to == VgLogTo_Fd || log_to == VgLogTo_Socket; |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 980 | } |
| 981 | |
sewardj | 4efbaa7 | 2008-06-04 06:51:58 +0000 | [diff] [blame] | 982 | // Write the name and value of log file qualifiers to the xml file. |
| 983 | static void print_file_vars(Char* format) |
| 984 | { |
| 985 | Int i = 0; |
| 986 | |
| 987 | while (format[i]) { |
| 988 | if (format[i] == '%') { |
| 989 | // We saw a '%'. What's next... |
| 990 | i++; |
| 991 | if ('q' == format[i]) { |
| 992 | i++; |
| 993 | if ('{' == format[i]) { |
| 994 | // Get the env var name, print its contents. |
| 995 | Char* qualname; |
| 996 | Char* qual; |
| 997 | i++; |
| 998 | qualname = &format[i]; |
| 999 | while (True) { |
| 1000 | if ('}' == format[i]) { |
| 1001 | // Temporarily replace the '}' with NUL to extract var |
| 1002 | // name. |
| 1003 | format[i] = 0; |
| 1004 | qual = VG_(getenv)(qualname); |
| 1005 | break; |
| 1006 | } |
| 1007 | i++; |
| 1008 | } |
| 1009 | |
sewardj | 7ca100d | 2009-08-15 23:05:34 +0000 | [diff] [blame] | 1010 | VG_(printf_xml_no_f_c)( |
| 1011 | "<logfilequalifier> <var>%t</var> " |
| 1012 | "<value>%t</value> </logfilequalifier>\n", |
| 1013 | qualname,qual |
| 1014 | ); |
sewardj | 4efbaa7 | 2008-06-04 06:51:58 +0000 | [diff] [blame] | 1015 | format[i] = '}'; |
| 1016 | i++; |
| 1017 | } |
| 1018 | } |
| 1019 | } else { |
| 1020 | i++; |
| 1021 | } |
| 1022 | } |
| 1023 | } |
| 1024 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1025 | |
| 1026 | /*====================================================================*/ |
| 1027 | /*=== Printing the preamble ===*/ |
| 1028 | /*====================================================================*/ |
| 1029 | |
njn | f8a11cf | 2009-08-02 23:03:06 +0000 | [diff] [blame] | 1030 | // Print the command, escaping any chars that require it. |
bart | a3054f5 | 2010-06-14 18:12:56 +0000 | [diff] [blame] | 1031 | static void umsg_or_xml_arg(const Char* arg, |
njn | f8a11cf | 2009-08-02 23:03:06 +0000 | [diff] [blame] | 1032 | UInt (*umsg_or_xml)( const HChar*, ... ) ) |
| 1033 | { |
| 1034 | SizeT len = VG_(strlen)(arg); |
| 1035 | Char* special = " \\<>"; |
| 1036 | Int i; |
| 1037 | for (i = 0; i < len; i++) { |
| 1038 | if (VG_(strchr)(special, arg[i])) { |
| 1039 | umsg_or_xml("\\"); // escape with a backslash if necessary |
| 1040 | } |
| 1041 | umsg_or_xml("%c", arg[i]); |
| 1042 | } |
| 1043 | } |
| 1044 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1045 | /* Ok, the logging sink is running now. Print a suitable preamble. |
| 1046 | If logging to file or a socket, write details of parent PID and |
| 1047 | command line args, to help people trying to interpret the |
| 1048 | results of a run which encompasses multiple processes. */ |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1049 | static void print_preamble ( Bool logging_to_fd, |
| 1050 | Char* xml_fname_unexpanded, |
| 1051 | const HChar* toolname ) |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1052 | { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1053 | Int i; |
tom | 60a4b0b | 2005-10-12 10:45:27 +0000 | [diff] [blame] | 1054 | HChar* xpre = VG_(clo_xml) ? " <line>" : ""; |
| 1055 | HChar* xpost = VG_(clo_xml) ? "</line>" : ""; |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1056 | UInt (*umsg_or_xml)( const HChar*, ... ) |
| 1057 | = VG_(clo_xml) ? VG_(printf_xml) : VG_(umsg); |
tom | 60a4b0b | 2005-10-12 10:45:27 +0000 | [diff] [blame] | 1058 | |
sewardj | 14c7cc5 | 2007-02-25 15:08:24 +0000 | [diff] [blame] | 1059 | vg_assert( VG_(args_for_client) ); |
| 1060 | vg_assert( VG_(args_for_valgrind) ); |
sewardj | 99a2ceb | 2007-11-09 12:30:36 +0000 | [diff] [blame] | 1061 | vg_assert( toolname ); |
sewardj | 14c7cc5 | 2007-02-25 15:08:24 +0000 | [diff] [blame] | 1062 | |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 1063 | if (VG_(clo_xml)) { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1064 | VG_(printf_xml)("<?xml version=\"1.0\"?>\n"); |
| 1065 | VG_(printf_xml)("\n"); |
| 1066 | VG_(printf_xml)("<valgrindoutput>\n"); |
| 1067 | VG_(printf_xml)("\n"); |
| 1068 | VG_(printf_xml)("<protocolversion>4</protocolversion>\n"); |
| 1069 | VG_(printf_xml)("<protocoltool>%s</protocoltool>\n", toolname); |
| 1070 | VG_(printf_xml)("\n"); |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 1071 | } |
| 1072 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1073 | if (VG_(clo_xml) || VG_(clo_verbosity > 0)) { |
sewardj | d7bddad | 2005-06-13 16:48:32 +0000 | [diff] [blame] | 1074 | |
| 1075 | if (VG_(clo_xml)) |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1076 | VG_(printf_xml)("<preamble>\n"); |
sewardj | d7bddad | 2005-06-13 16:48:32 +0000 | [diff] [blame] | 1077 | |
nethercote | 996901a | 2004-08-03 13:29:09 +0000 | [diff] [blame] | 1078 | /* Tool details */ |
sewardj | 743a208 | 2010-07-23 17:03:22 +0000 | [diff] [blame] | 1079 | umsg_or_xml( VG_(clo_xml) ? "%s%t%t%t, %t%s\n" : "%s%s%s%s, %s%s\n", |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 1080 | xpre, |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 1081 | VG_(details).name, |
njn | b9c427c | 2004-12-01 14:14:42 +0000 | [diff] [blame] | 1082 | NULL == VG_(details).version ? "" : "-", |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 1083 | NULL == VG_(details).version |
| 1084 | ? (Char*)"" : VG_(details).version, |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 1085 | VG_(details).description, |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1086 | xpost ); |
sewardj | 99a2ceb | 2007-11-09 12:30:36 +0000 | [diff] [blame] | 1087 | |
njn | 10b9aea | 2009-07-14 06:55:05 +0000 | [diff] [blame] | 1088 | if (VG_(strlen)(toolname) >= 4 && VG_STREQN(4, toolname, "exp-")) { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1089 | umsg_or_xml( |
njn | b6267bd | 2009-08-12 00:14:16 +0000 | [diff] [blame] | 1090 | "%sNOTE: This is an Experimental-Class Valgrind Tool%s\n", |
sewardj | 99a2ceb | 2007-11-09 12:30:36 +0000 | [diff] [blame] | 1091 | xpre, xpost |
| 1092 | ); |
| 1093 | } |
| 1094 | |
sewardj | 743a208 | 2010-07-23 17:03:22 +0000 | [diff] [blame] | 1095 | umsg_or_xml( VG_(clo_xml) ? "%s%t%s\n" : "%s%s%s\n", |
| 1096 | xpre, VG_(details).copyright_author, xpost ); |
sewardj | 3b2736a | 2002-03-24 12:18:35 +0000 | [diff] [blame] | 1097 | |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 1098 | /* Core details */ |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1099 | umsg_or_xml( |
njn | f73d87f | 2009-07-24 04:47:04 +0000 | [diff] [blame] | 1100 | "%sUsing Valgrind-%s and LibVEX; rerun with -h for copyright info%s\n", |
| 1101 | xpre, VERSION, xpost |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1102 | ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1103 | |
njn | f3977a3 | 2009-08-04 00:27:56 +0000 | [diff] [blame] | 1104 | // Print the command line. At one point we wrapped at 80 chars and |
| 1105 | // printed a '\' as a line joiner, but that makes it hard to cut and |
| 1106 | // paste the command line (because of the "==pid==" prefixes), so we now |
| 1107 | // favour utility and simplicity over aesthetics. |
| 1108 | umsg_or_xml("%sCommand: ", xpre); |
njn | 53162bf | 2009-07-29 23:34:49 +0000 | [diff] [blame] | 1109 | if (VG_(args_the_exename)) |
njn | f8a11cf | 2009-08-02 23:03:06 +0000 | [diff] [blame] | 1110 | umsg_or_xml_arg(VG_(args_the_exename), umsg_or_xml); |
njn | 53162bf | 2009-07-29 23:34:49 +0000 | [diff] [blame] | 1111 | for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) { |
| 1112 | HChar* s = *(HChar**)VG_(indexXA)( VG_(args_for_client), i ); |
njn | f8a11cf | 2009-08-02 23:03:06 +0000 | [diff] [blame] | 1113 | umsg_or_xml(" "); |
| 1114 | umsg_or_xml_arg(s, umsg_or_xml); |
njn | 53162bf | 2009-07-29 23:34:49 +0000 | [diff] [blame] | 1115 | } |
njn | f3977a3 | 2009-08-04 00:27:56 +0000 | [diff] [blame] | 1116 | umsg_or_xml("%s\n", xpost); |
njn | 53162bf | 2009-07-29 23:34:49 +0000 | [diff] [blame] | 1117 | |
sewardj | d7bddad | 2005-06-13 16:48:32 +0000 | [diff] [blame] | 1118 | if (VG_(clo_xml)) |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1119 | VG_(printf_xml)("</preamble>\n"); |
njn | d04b7c6 | 2002-10-03 14:05:52 +0000 | [diff] [blame] | 1120 | } |
| 1121 | |
njn | b6267bd | 2009-08-12 00:14:16 +0000 | [diff] [blame] | 1122 | // Print the parent PID, and other stuff, if necessary. |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1123 | if (!VG_(clo_xml) && VG_(clo_verbosity) > 0 && !logging_to_fd) { |
njn | 305dc00 | 2009-07-30 23:36:43 +0000 | [diff] [blame] | 1124 | VG_(umsg)("Parent PID: %d\n", VG_(getppid)()); |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1125 | } |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 1126 | else |
| 1127 | if (VG_(clo_xml)) { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1128 | VG_(printf_xml)("\n"); |
| 1129 | VG_(printf_xml)("<pid>%d</pid>\n", VG_(getpid)()); |
| 1130 | VG_(printf_xml)("<ppid>%d</ppid>\n", VG_(getppid)()); |
| 1131 | VG_(printf_xml_no_f_c)("<tool>%t</tool>\n", toolname); |
| 1132 | if (xml_fname_unexpanded) |
| 1133 | print_file_vars(xml_fname_unexpanded); |
sewardj | 768db0e | 2005-07-19 14:18:56 +0000 | [diff] [blame] | 1134 | if (VG_(clo_xml_user_comment)) { |
| 1135 | /* Note: the user comment itself is XML and is therefore to |
| 1136 | be passed through verbatim (%s) rather than escaped |
| 1137 | (%t). */ |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1138 | VG_(printf_xml)("<usercomment>%s</usercomment>\n", |
| 1139 | VG_(clo_xml_user_comment)); |
sewardj | 768db0e | 2005-07-19 14:18:56 +0000 | [diff] [blame] | 1140 | } |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1141 | VG_(printf_xml)("\n"); |
| 1142 | VG_(printf_xml)("<args>\n"); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1143 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1144 | VG_(printf_xml)(" <vargv>\n"); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1145 | if (VG_(name_of_launcher)) |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1146 | VG_(printf_xml_no_f_c)(" <exe>%t</exe>\n", |
| 1147 | VG_(name_of_launcher)); |
sewardj | 125fd4f | 2007-03-08 19:56:14 +0000 | [diff] [blame] | 1148 | else |
njn | b1cc5d6 | 2010-07-06 04:05:23 +0000 | [diff] [blame] | 1149 | VG_(printf_xml_no_f_c)(" <exe>%t</exe>\n", |
| 1150 | "(launcher name unknown)"); |
sewardj | 14c7cc5 | 2007-02-25 15:08:24 +0000 | [diff] [blame] | 1151 | for (i = 0; i < VG_(sizeXA)( VG_(args_for_valgrind) ); i++) { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1152 | VG_(printf_xml_no_f_c)( |
| 1153 | " <arg>%t</arg>\n", |
| 1154 | * (HChar**) VG_(indexXA)( VG_(args_for_valgrind), i ) |
| 1155 | ); |
sewardj | b8a3dac | 2005-07-19 12:39:11 +0000 | [diff] [blame] | 1156 | } |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1157 | VG_(printf_xml)(" </vargv>\n"); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1158 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1159 | VG_(printf_xml)(" <argv>\n"); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1160 | if (VG_(args_the_exename)) |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1161 | VG_(printf_xml_no_f_c)(" <exe>%t</exe>\n", |
| 1162 | VG_(args_the_exename)); |
sewardj | 14c7cc5 | 2007-02-25 15:08:24 +0000 | [diff] [blame] | 1163 | for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1164 | VG_(printf_xml_no_f_c)( |
| 1165 | " <arg>%t</arg>\n", |
| 1166 | * (HChar**) VG_(indexXA)( VG_(args_for_client), i ) |
| 1167 | ); |
sewardj | 8665d8e | 2005-06-01 17:35:23 +0000 | [diff] [blame] | 1168 | } |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1169 | VG_(printf_xml)(" </argv>\n"); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1170 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1171 | VG_(printf_xml)("</args>\n"); |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 1172 | } |
sewardj | 4cf0569 | 2002-10-27 20:28:29 +0000 | [diff] [blame] | 1173 | |
njn | b6267bd | 2009-08-12 00:14:16 +0000 | [diff] [blame] | 1174 | // Last thing in the preamble is a blank line. |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1175 | if (VG_(clo_xml)) |
| 1176 | VG_(printf_xml)("\n"); |
njn | b6267bd | 2009-08-12 00:14:16 +0000 | [diff] [blame] | 1177 | else if (VG_(clo_verbosity) > 0) |
| 1178 | VG_(umsg)("\n"); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1179 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1180 | if (VG_(clo_verbosity) > 1) { |
sewardj | 9264559 | 2005-07-23 09:18:34 +0000 | [diff] [blame] | 1181 | SysRes fd; |
sewardj | 1f0bbc7 | 2005-11-16 03:51:02 +0000 | [diff] [blame] | 1182 | VexArch vex_arch; |
| 1183 | VexArchInfo vex_archinfo; |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1184 | if (!logging_to_fd) |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1185 | VG_(message)(Vg_DebugMsg, "\n"); |
njn | a331164 | 2009-08-10 01:29:14 +0000 | [diff] [blame] | 1186 | VG_(message)(Vg_DebugMsg, "Valgrind options:\n"); |
sewardj | 14c7cc5 | 2007-02-25 15:08:24 +0000 | [diff] [blame] | 1187 | for (i = 0; i < VG_(sizeXA)( VG_(args_for_valgrind) ); i++) { |
| 1188 | VG_(message)(Vg_DebugMsg, |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1189 | " %s\n", |
sewardj | 14c7cc5 | 2007-02-25 15:08:24 +0000 | [diff] [blame] | 1190 | * (HChar**) VG_(indexXA)( VG_(args_for_valgrind), i )); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1191 | } |
nethercote | a70f735 | 2004-04-18 12:08:46 +0000 | [diff] [blame] | 1192 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1193 | VG_(message)(Vg_DebugMsg, "Contents of /proc/version:\n"); |
nethercote | a70f735 | 2004-04-18 12:08:46 +0000 | [diff] [blame] | 1194 | fd = VG_(open) ( "/proc/version", VKI_O_RDONLY, 0 ); |
njn | cda2f0f | 2009-05-18 02:12:08 +0000 | [diff] [blame] | 1195 | if (sr_isError(fd)) { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1196 | VG_(message)(Vg_DebugMsg, " can't open /proc/version\n"); |
nethercote | a70f735 | 2004-04-18 12:08:46 +0000 | [diff] [blame] | 1197 | } else { |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 1198 | # define BUF_LEN 256 |
nethercote | a70f735 | 2004-04-18 12:08:46 +0000 | [diff] [blame] | 1199 | Char version_buf[BUF_LEN]; |
njn | f3977a3 | 2009-08-04 00:27:56 +0000 | [diff] [blame] | 1200 | Int n = VG_(read) ( sr_Res(fd), version_buf, BUF_LEN ); |
| 1201 | vg_assert(n <= BUF_LEN); |
| 1202 | if (n > 0) { |
| 1203 | version_buf[n-1] = '\0'; |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1204 | VG_(message)(Vg_DebugMsg, " %s\n", version_buf); |
nethercote | a70f735 | 2004-04-18 12:08:46 +0000 | [diff] [blame] | 1205 | } else { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1206 | VG_(message)(Vg_DebugMsg, " (empty?)\n"); |
nethercote | a70f735 | 2004-04-18 12:08:46 +0000 | [diff] [blame] | 1207 | } |
njn | cda2f0f | 2009-05-18 02:12:08 +0000 | [diff] [blame] | 1208 | VG_(close)(sr_Res(fd)); |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 1209 | # undef BUF_LEN |
nethercote | a70f735 | 2004-04-18 12:08:46 +0000 | [diff] [blame] | 1210 | } |
sewardj | 1f0bbc7 | 2005-11-16 03:51:02 +0000 | [diff] [blame] | 1211 | |
| 1212 | VG_(machine_get_VexArchInfo)( &vex_arch, &vex_archinfo ); |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 1213 | VG_(message)( |
| 1214 | Vg_DebugMsg, |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1215 | "Arch and hwcaps: %s, %s\n", |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 1216 | LibVEX_ppVexArch ( vex_arch ), |
| 1217 | LibVEX_ppVexHwCaps ( vex_arch, vex_archinfo.hwcaps ) |
| 1218 | ); |
sewardj | e66f2e0 | 2006-12-30 17:45:08 +0000 | [diff] [blame] | 1219 | VG_(message)( |
| 1220 | Vg_DebugMsg, |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1221 | "Page sizes: currently %d, max supported %d\n", |
sewardj | e66f2e0 | 2006-12-30 17:45:08 +0000 | [diff] [blame] | 1222 | (Int)VKI_PAGE_SIZE, (Int)VKI_MAX_PAGE_SIZE |
| 1223 | ); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1224 | VG_(message)(Vg_DebugMsg, |
| 1225 | "Valgrind library directory: %s\n", VG_(libdir)); |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1226 | } |
nethercote | f6a1d50 | 2004-08-09 12:21:57 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1229 | |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1230 | /*====================================================================*/ |
| 1231 | /*=== File descriptor setup ===*/ |
| 1232 | /*====================================================================*/ |
| 1233 | |
sewardj | 5f229e2 | 2005-09-28 01:36:01 +0000 | [diff] [blame] | 1234 | /* Number of file descriptors that Valgrind tries to reserve for |
| 1235 | it's own use - just a small constant. */ |
| 1236 | #define N_RESERVED_FDS (10) |
| 1237 | |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1238 | static void setup_file_descriptors(void) |
| 1239 | { |
| 1240 | struct vki_rlimit rl; |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 1241 | Bool show = False; |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1242 | |
| 1243 | /* Get the current file descriptor limits. */ |
| 1244 | if (VG_(getrlimit)(VKI_RLIMIT_NOFILE, &rl) < 0) { |
| 1245 | rl.rlim_cur = 1024; |
| 1246 | rl.rlim_max = 1024; |
| 1247 | } |
| 1248 | |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 1249 | # if defined(VGO_darwin) |
| 1250 | /* Darwin lies. It reports file max as RLIM_INFINITY but |
| 1251 | silently disallows anything bigger than 10240. */ |
| 1252 | if (rl.rlim_cur >= 10240 && rl.rlim_max == 0x7fffffffffffffffULL) { |
| 1253 | rl.rlim_max = 10240; |
| 1254 | } |
| 1255 | # endif |
| 1256 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 1257 | if (show) |
njn | 8a7b41b | 2007-09-23 00:51:24 +0000 | [diff] [blame] | 1258 | VG_(printf)("fd limits: host, before: cur %lu max %lu\n", |
sewardj | a8ffda6 | 2008-07-18 18:23:24 +0000 | [diff] [blame] | 1259 | (UWord)rl.rlim_cur, (UWord)rl.rlim_max); |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 1260 | |
| 1261 | # if defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5) |
| 1262 | /* I don't know why this kludge is needed; however if rl.rlim_cur |
| 1263 | is RLIM_INFINITY, then VG_(safe_fd)'s attempts using VG_(fcntl) |
| 1264 | to lift V's file descriptors above the threshold RLIM_INFINITY - |
| 1265 | N_RESERVED_FDS fail. So just use a relatively conservative |
| 1266 | value in this case. */ |
| 1267 | if (rl.rlim_cur > 1024) |
| 1268 | rl.rlim_cur = 1024; |
| 1269 | # endif |
| 1270 | |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1271 | /* Work out where to move the soft limit to. */ |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 1272 | if (rl.rlim_cur + N_RESERVED_FDS <= rl.rlim_max) { |
| 1273 | rl.rlim_cur = rl.rlim_cur + N_RESERVED_FDS; |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1274 | } else { |
| 1275 | rl.rlim_cur = rl.rlim_max; |
| 1276 | } |
| 1277 | |
| 1278 | /* Reserve some file descriptors for our use. */ |
njn | 14319cc | 2005-03-13 06:26:22 +0000 | [diff] [blame] | 1279 | VG_(fd_soft_limit) = rl.rlim_cur - N_RESERVED_FDS; |
| 1280 | VG_(fd_hard_limit) = rl.rlim_cur - N_RESERVED_FDS; |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1281 | |
| 1282 | /* Update the soft limit. */ |
| 1283 | VG_(setrlimit)(VKI_RLIMIT_NOFILE, &rl); |
| 1284 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 1285 | if (show) { |
njn | 8a7b41b | 2007-09-23 00:51:24 +0000 | [diff] [blame] | 1286 | VG_(printf)("fd limits: host, after: cur %lu max %lu\n", |
sewardj | a8ffda6 | 2008-07-18 18:23:24 +0000 | [diff] [blame] | 1287 | (UWord)rl.rlim_cur, (UWord)rl.rlim_max); |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 1288 | VG_(printf)("fd limits: guest : cur %u max %u\n", |
| 1289 | VG_(fd_soft_limit), VG_(fd_hard_limit)); |
| 1290 | } |
| 1291 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1292 | if (VG_(cl_exec_fd) != -1) |
| 1293 | VG_(cl_exec_fd) = VG_(safe_fd)( VG_(cl_exec_fd) ); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1294 | } |
| 1295 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1296 | |
njn | 2da7335 | 2005-06-18 01:35:16 +0000 | [diff] [blame] | 1297 | /*====================================================================*/ |
njn | 2025cf9 | 2005-06-26 20:44:48 +0000 | [diff] [blame] | 1298 | /*=== BB profiling ===*/ |
| 1299 | /*====================================================================*/ |
| 1300 | |
| 1301 | static |
| 1302 | void show_BB_profile ( BBProfEntry tops[], UInt n_tops, ULong score_total ) |
| 1303 | { |
| 1304 | ULong score_cumul, score_here; |
| 1305 | Char buf_cumul[10], buf_here[10]; |
| 1306 | Char name[64]; |
| 1307 | Int r; |
| 1308 | |
| 1309 | VG_(printf)("\n"); |
| 1310 | VG_(printf)("-----------------------------------------------------------\n"); |
| 1311 | VG_(printf)("--- BEGIN BB Profile (summary of scores) ---\n"); |
| 1312 | VG_(printf)("-----------------------------------------------------------\n"); |
| 1313 | VG_(printf)("\n"); |
| 1314 | |
| 1315 | VG_(printf)("Total score = %lld\n\n", score_total); |
| 1316 | |
| 1317 | score_cumul = 0; |
| 1318 | for (r = 0; r < n_tops; r++) { |
| 1319 | if (tops[r].addr == 0) |
| 1320 | continue; |
| 1321 | name[0] = 0; |
| 1322 | VG_(get_fnname_w_offset)(tops[r].addr, name, 64); |
| 1323 | name[63] = 0; |
| 1324 | score_here = tops[r].score; |
| 1325 | score_cumul += score_here; |
| 1326 | VG_(percentify)(score_cumul, score_total, 2, 6, buf_cumul); |
| 1327 | VG_(percentify)(score_here, score_total, 2, 6, buf_here); |
| 1328 | VG_(printf)("%3d: (%9lld %s) %9lld %s 0x%llx %s\n", |
| 1329 | r, |
| 1330 | score_cumul, buf_cumul, |
| 1331 | score_here, buf_here, tops[r].addr, name ); |
| 1332 | } |
| 1333 | |
| 1334 | VG_(printf)("\n"); |
| 1335 | VG_(printf)("-----------------------------------------------------------\n"); |
| 1336 | VG_(printf)("--- BB Profile (BB details) ---\n"); |
| 1337 | VG_(printf)("-----------------------------------------------------------\n"); |
| 1338 | VG_(printf)("\n"); |
| 1339 | |
| 1340 | score_cumul = 0; |
| 1341 | for (r = 0; r < n_tops; r++) { |
| 1342 | if (tops[r].addr == 0) |
| 1343 | continue; |
| 1344 | name[0] = 0; |
| 1345 | VG_(get_fnname_w_offset)(tops[r].addr, name, 64); |
| 1346 | name[63] = 0; |
| 1347 | score_here = tops[r].score; |
| 1348 | score_cumul += score_here; |
| 1349 | VG_(percentify)(score_cumul, score_total, 2, 6, buf_cumul); |
| 1350 | VG_(percentify)(score_here, score_total, 2, 6, buf_here); |
| 1351 | VG_(printf)("\n"); |
| 1352 | VG_(printf)("=-=-=-=-=-=-=-=-=-=-=-=-=-= begin BB rank %d " |
| 1353 | "=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n", r); |
| 1354 | VG_(printf)("%3d: (%9lld %s) %9lld %s 0x%llx %s\n", |
| 1355 | r, |
| 1356 | score_cumul, buf_cumul, |
| 1357 | score_here, buf_here, tops[r].addr, name ); |
| 1358 | VG_(printf)("\n"); |
sewardj | bcccbc0 | 2007-04-09 22:24:57 +0000 | [diff] [blame] | 1359 | VG_(discard_translations)(tops[r].addr, 1, "bb profile"); |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1360 | VG_(translate)(0, tops[r].addr, True, VG_(clo_profile_flags), 0, True); |
njn | 2025cf9 | 2005-06-26 20:44:48 +0000 | [diff] [blame] | 1361 | VG_(printf)("=-=-=-=-=-=-=-=-=-=-=-=-=-= end BB rank %d " |
| 1362 | "=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n", r); |
| 1363 | } |
| 1364 | |
| 1365 | VG_(printf)("\n"); |
| 1366 | VG_(printf)("-----------------------------------------------------------\n"); |
| 1367 | VG_(printf)("--- END BB Profile ---\n"); |
| 1368 | VG_(printf)("-----------------------------------------------------------\n"); |
| 1369 | VG_(printf)("\n"); |
| 1370 | } |
| 1371 | |
| 1372 | |
| 1373 | /*====================================================================*/ |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1374 | /*=== main() ===*/ |
| 1375 | /*====================================================================*/ |
| 1376 | |
sewardj | fdf91b4 | 2005-09-28 00:53:09 +0000 | [diff] [blame] | 1377 | /* When main() is entered, we should be on the following stack, not |
| 1378 | the one the kernel gave us. We will run on this stack until |
| 1379 | simulation of the root thread is started, at which point a transfer |
| 1380 | is made to a dynamically allocated stack. This is for the sake of |
| 1381 | uniform overflow detection for all Valgrind threads. This is |
| 1382 | marked global even though it isn't, because assembly code below |
| 1383 | needs to reference the name. */ |
| 1384 | |
| 1385 | /*static*/ VgStack VG_(interim_stack); |
| 1386 | |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 1387 | /* These are the structures used to hold info for creating the initial |
| 1388 | client image. |
| 1389 | |
| 1390 | 'iicii' mostly holds important register state present at system |
| 1391 | startup (_start_valgrind). valgrind_main() then fills in the rest |
| 1392 | of it and passes it to VG_(ii_create_image)(). That produces |
| 1393 | 'iifii', which is later handed to VG_(ii_finalise_image). */ |
| 1394 | |
| 1395 | /* In all OS-instantiations, the_iicii has a field .sp_at_startup. |
| 1396 | This should get some address inside the stack on which we gained |
sewardj | fdf91b4 | 2005-09-28 00:53:09 +0000 | [diff] [blame] | 1397 | control (eg, it could be the SP at startup). It doesn't matter |
| 1398 | exactly where in the stack it is. This value is passed to the |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 1399 | address space manager at startup. On Linux, aspacem then uses it |
| 1400 | to identify the initial stack segment and hence the upper end of |
| 1401 | the usable address space. */ |
sewardj | fdf91b4 | 2005-09-28 00:53:09 +0000 | [diff] [blame] | 1402 | |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 1403 | static IICreateImageInfo the_iicii; |
| 1404 | static IIFinaliseImageInfo the_iifii; |
| 1405 | |
sewardj | fdf91b4 | 2005-09-28 00:53:09 +0000 | [diff] [blame] | 1406 | |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 1407 | /* A simple pair structure, used for conveying debuginfo handles to |
| 1408 | calls to VG_TRACK(new_mem_startup, ...). */ |
| 1409 | typedef struct { Addr a; ULong ull; } Addr_n_ULong; |
| 1410 | |
| 1411 | |
sewardj | 1ae3f3a | 2005-09-28 10:47:38 +0000 | [diff] [blame] | 1412 | /* --- Forwards decls to do with shutdown --- */ |
| 1413 | |
| 1414 | static void final_tidyup(ThreadId tid); |
| 1415 | |
| 1416 | /* Do everything which needs doing when the last thread exits */ |
| 1417 | static |
| 1418 | void shutdown_actions_NORETURN( ThreadId tid, |
| 1419 | VgSchedReturnCode tids_schedretcode ); |
| 1420 | |
| 1421 | /* --- end of Forwards decls to do with shutdown --- */ |
sewardj | fdf91b4 | 2005-09-28 00:53:09 +0000 | [diff] [blame] | 1422 | |
| 1423 | |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 1424 | /* By the time we get to valgrind_main, the_iicii should already have |
| 1425 | been filled in with any important details as required by whatever |
| 1426 | OS we have been built for. |
| 1427 | */ |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 1428 | static |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 1429 | Int valgrind_main ( Int argc, HChar **argv, HChar **envp ) |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1430 | { |
sewardj | 13247ca | 2005-12-30 22:52:20 +0000 | [diff] [blame] | 1431 | HChar* toolname = "memcheck"; // default to Memcheck |
sewardj | 13247ca | 2005-12-30 22:52:20 +0000 | [diff] [blame] | 1432 | Int need_help = 0; // 0 = no, 1 = --help, 2 = --help-debug |
sewardj | de764e8 | 2007-11-09 23:13:22 +0000 | [diff] [blame] | 1433 | ThreadId tid_main = VG_INVALID_THREADID; |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1434 | Bool logging_to_fd = False; |
| 1435 | Char* xml_fname_unexpanded = NULL; |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1436 | Int loglevel, i; |
nethercote | 73b526f | 2004-10-31 18:48:21 +0000 | [diff] [blame] | 1437 | struct vki_rlimit zero = { 0, 0 }; |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 1438 | XArray* addr2dihandle = NULL; |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 1439 | |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1440 | //============================================================ |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1441 | // |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1442 | // Nb: startup is complex. Prerequisites are shown at every step. |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1443 | // *** Be very careful when messing with the order *** |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1444 | // |
| 1445 | // The first order of business is to get debug logging, the address |
| 1446 | // space manager and the dynamic memory manager up and running. |
| 1447 | // Once that's done, we can relax a bit. |
| 1448 | // |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1449 | //============================================================ |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1450 | |
| 1451 | /* This is needed to make VG_(getenv) usable early. */ |
| 1452 | VG_(client_envp) = (Char**)envp; |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1453 | |
sewardj | 1cf558c | 2005-04-25 01:36:56 +0000 | [diff] [blame] | 1454 | //-------------------------------------------------------------- |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 1455 | // Start up Mach kernel interface, if any |
| 1456 | // p: none |
| 1457 | //-------------------------------------------------------------- |
| 1458 | # if defined(VGO_darwin) |
| 1459 | VG_(mach_init)(); |
| 1460 | # endif |
| 1461 | |
| 1462 | //-------------------------------------------------------------- |
sewardj | 1cf558c | 2005-04-25 01:36:56 +0000 | [diff] [blame] | 1463 | // Start up the logging mechanism |
| 1464 | // p: none |
| 1465 | //-------------------------------------------------------------- |
| 1466 | /* Start the debugging-log system ASAP. First find out how many |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 1467 | "-d"s were specified. This is a pre-scan of the command line. Also |
| 1468 | get --profile-heap=yes which is needed by the time we start up dynamic |
| 1469 | memory management. */ |
sewardj | 1cf558c | 2005-04-25 01:36:56 +0000 | [diff] [blame] | 1470 | loglevel = 0; |
| 1471 | for (i = 1; i < argc; i++) { |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 1472 | if (argv[i][0] != '-') break; |
| 1473 | if VG_STREQ(argv[i], "--") break; |
| 1474 | if VG_STREQ(argv[i], "-d") loglevel++; |
| 1475 | if VG_BOOL_CLO(argv[i], "--profile-heap", VG_(clo_profile_heap)) {} |
sewardj | 1cf558c | 2005-04-25 01:36:56 +0000 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | /* ... and start the debug logger. Now we can safely emit logging |
| 1479 | messages all through startup. */ |
sewardj | 1075931 | 2005-05-30 23:52:47 +0000 | [diff] [blame] | 1480 | VG_(debugLog_startup)(loglevel, "Stage 2 (main)"); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1481 | VG_(debugLog)(1, "main", "Welcome to Valgrind version " |
| 1482 | VERSION " debug logging\n"); |
| 1483 | |
| 1484 | //-------------------------------------------------------------- |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 1485 | // AIX5 only: register the system call numbers |
| 1486 | // p: logging |
| 1487 | // p: that the initial few syscall numbers stated in the |
| 1488 | // bootblock have been installed (else we can't |
| 1489 | // open/read/close). |
| 1490 | //-------------------------------------------------------------- |
| 1491 | # if defined(VGO_aix5) |
| 1492 | VG_(debugLog)(1, "main", "aix5: registering syscalls ..\n"); |
| 1493 | { UChar sysent_name[50]; |
| 1494 | SysRes fd; |
| 1495 | Bool ok; |
| 1496 | Int n_unregd, sysent_used = 0; |
| 1497 | prsysent_t* sysent_hdr; |
| 1498 | |
| 1499 | VG_(sprintf)(sysent_name, "/proc/%d/sysent", VG_(getpid)()); |
| 1500 | fd = VG_(open)(sysent_name, VKI_O_RDONLY, 0); |
| 1501 | if (fd.isError) |
| 1502 | VG_(err_config_error)("aix5: can't open /proc/<pid>/sysent"); |
| 1503 | |
| 1504 | sysent_used = VG_(read)(fd.res, aix5_sysent_buf, VG_AIX5_SYSENT_SIZE); |
| 1505 | if (sysent_used < 0) |
| 1506 | VG_(err_config_error)("aix5: error reading /proc/<pid>/sysent"); |
| 1507 | if (sysent_used >= VG_AIX5_SYSENT_SIZE) |
| 1508 | VG_(err_config_error)("aix5: VG_AIX5_SYSENT_SIZE is too low; " |
| 1509 | "increase and recompile"); |
| 1510 | VG_(close)(fd.res); |
| 1511 | |
| 1512 | vg_assert(sysent_used > 0 && sysent_used < VG_AIX5_SYSENT_SIZE); |
| 1513 | |
| 1514 | sysent_hdr = (prsysent_t*)&aix5_sysent_buf[0]; |
| 1515 | |
| 1516 | n_unregd = 0; |
| 1517 | for (i = 0; i < sysent_hdr->pr_nsyscalls; i++) { |
| 1518 | UChar* name = &aix5_sysent_buf[ sysent_hdr |
| 1519 | ->pr_syscall[i].pr_nameoff ]; |
| 1520 | UInt nmbr = sysent_hdr->pr_syscall[i].pr_number; |
| 1521 | VG_(debugLog)(3, "main", "aix5: bind syscall %d to \"%s\"\n", |
| 1522 | nmbr, name); |
| 1523 | ok = VG_(aix5_register_syscall)(nmbr, name); |
| 1524 | if (!ok) |
| 1525 | n_unregd++; |
| 1526 | if (!ok) |
| 1527 | VG_(debugLog)(3, "main", |
| 1528 | "aix5: bind FAILED: %d to \"%s\"\n", |
| 1529 | nmbr, name); |
| 1530 | } |
| 1531 | VG_(debugLog)(1, "main", "aix5: .. %d syscalls known, %d unknown\n", |
| 1532 | sysent_hdr->pr_nsyscalls - n_unregd, n_unregd ); |
| 1533 | VG_(debugLog)(1, "main", "aix5: __NR_AIX5_FAKE_SIGRETURN = %d\n", |
| 1534 | __NR_AIX5_FAKE_SIGRETURN ); |
| 1535 | } |
| 1536 | # endif |
| 1537 | |
| 1538 | //-------------------------------------------------------------- |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1539 | // Ensure we're on a plausible stack. |
| 1540 | // p: logging |
| 1541 | //-------------------------------------------------------------- |
| 1542 | VG_(debugLog)(1, "main", "Checking current stack is plausible\n"); |
sewardj | fdf91b4 | 2005-09-28 00:53:09 +0000 | [diff] [blame] | 1543 | { HChar* limLo = (HChar*)(&VG_(interim_stack).bytes[0]); |
| 1544 | HChar* limHi = limLo + sizeof(VG_(interim_stack)); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1545 | HChar* aLocal = (HChar*)&zero; /* any auto local will do */ |
| 1546 | if (aLocal < limLo || aLocal >= limHi) { |
| 1547 | /* something's wrong. Stop. */ |
| 1548 | VG_(debugLog)(0, "main", "Root stack %p to %p, a local %p\n", |
| 1549 | limLo, limHi, aLocal ); |
| 1550 | VG_(debugLog)(0, "main", "Valgrind: FATAL: " |
| 1551 | "Initial stack switched failed.\n"); |
| 1552 | VG_(debugLog)(0, "main", " Cannot continue. Sorry.\n"); |
| 1553 | VG_(exit)(1); |
| 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | //-------------------------------------------------------------- |
| 1558 | // Ensure we have a plausible pointer to the stack on which |
| 1559 | // we gained control (not the current stack!) |
| 1560 | // p: logging |
| 1561 | //-------------------------------------------------------------- |
| 1562 | VG_(debugLog)(1, "main", "Checking initial stack was noted\n"); |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 1563 | if (the_iicii.sp_at_startup == 0) { |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1564 | VG_(debugLog)(0, "main", "Valgrind: FATAL: " |
| 1565 | "Initial stack was not noted.\n"); |
| 1566 | VG_(debugLog)(0, "main", " Cannot continue. Sorry.\n"); |
| 1567 | VG_(exit)(1); |
| 1568 | } |
| 1569 | |
| 1570 | //-------------------------------------------------------------- |
| 1571 | // Start up the address space manager, and determine the |
| 1572 | // approximate location of the client's stack |
njn | ea2d6fd | 2010-07-01 00:20:20 +0000 | [diff] [blame] | 1573 | // p: logging, plausible-stack |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1574 | //-------------------------------------------------------------- |
| 1575 | VG_(debugLog)(1, "main", "Starting the address space manager\n"); |
sewardj | e66f2e0 | 2006-12-30 17:45:08 +0000 | [diff] [blame] | 1576 | vg_assert(VKI_PAGE_SIZE == 4096 || VKI_PAGE_SIZE == 65536); |
| 1577 | vg_assert(VKI_MAX_PAGE_SIZE == 4096 || VKI_MAX_PAGE_SIZE == 65536); |
| 1578 | vg_assert(VKI_PAGE_SIZE <= VKI_MAX_PAGE_SIZE); |
| 1579 | vg_assert(VKI_PAGE_SIZE == (1 << VKI_PAGE_SHIFT)); |
| 1580 | vg_assert(VKI_MAX_PAGE_SIZE == (1 << VKI_MAX_PAGE_SHIFT)); |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 1581 | the_iicii.clstack_top = VG_(am_startup)( the_iicii.sp_at_startup ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1582 | VG_(debugLog)(1, "main", "Address space manager is running\n"); |
| 1583 | |
| 1584 | //-------------------------------------------------------------- |
| 1585 | // Start up the dynamic memory manager |
| 1586 | // p: address space management |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 1587 | // p: getting --profile-heap |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1588 | // In fact m_mallocfree is self-initialising, so there's no |
| 1589 | // initialisation call to do. Instead, try a simple malloc/ |
| 1590 | // free pair right now to check that nothing is broken. |
| 1591 | //-------------------------------------------------------------- |
| 1592 | VG_(debugLog)(1, "main", "Starting the dynamic memory manager\n"); |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 1593 | { void* p = VG_(malloc)( "main.vm.1", 12345 ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1594 | if (p) VG_(free)( p ); |
| 1595 | } |
| 1596 | VG_(debugLog)(1, "main", "Dynamic memory manager is running\n"); |
sewardj | 1cf558c | 2005-04-25 01:36:56 +0000 | [diff] [blame] | 1597 | |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 1598 | //============================================================ |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1599 | // |
| 1600 | // Dynamic memory management is now available. |
| 1601 | // |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 1602 | //============================================================ |
| 1603 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1604 | //-------------------------------------------------------------- |
sewardj | f98e1c0 | 2008-10-25 16:22:41 +0000 | [diff] [blame] | 1605 | // Initialise m_debuginfo |
| 1606 | // p: dynamic memory allocation |
| 1607 | VG_(debugLog)(1, "main", "Initialise m_debuginfo\n"); |
| 1608 | VG_(di_initialise)(); |
| 1609 | |
| 1610 | //-------------------------------------------------------------- |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1611 | // Look for alternative libdir |
| 1612 | { HChar *cp = VG_(getenv)(VALGRIND_LIB); |
| 1613 | if (cp != NULL) |
| 1614 | VG_(libdir) = cp; |
njn | cde90d3 | 2009-07-22 22:41:38 +0000 | [diff] [blame] | 1615 | VG_(debugLog)(1, "main", "VG_(libdir) = %s\n", VG_(libdir)); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | //-------------------------------------------------------------- |
| 1619 | // Extract the launcher name from the environment. |
njn | a842d79 | 2009-05-21 01:15:18 +0000 | [diff] [blame] | 1620 | VG_(debugLog)(1, "main", "Getting launcher's name ...\n"); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1621 | VG_(name_of_launcher) = VG_(getenv)(VALGRIND_LAUNCHER); |
| 1622 | if (VG_(name_of_launcher) == NULL) { |
| 1623 | VG_(printf)("valgrind: You cannot run '%s' directly.\n", argv[0]); |
| 1624 | VG_(printf)("valgrind: You should use $prefix/bin/valgrind.\n"); |
| 1625 | VG_(exit)(1); |
| 1626 | } |
njn | a842d79 | 2009-05-21 01:15:18 +0000 | [diff] [blame] | 1627 | VG_(debugLog)(1, "main", "... %s\n", VG_(name_of_launcher)); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1628 | |
| 1629 | //-------------------------------------------------------------- |
fitzhardinge | b50068f | 2004-02-24 23:42:55 +0000 | [diff] [blame] | 1630 | // Get the current process datasize rlimit, and set it to zero. |
| 1631 | // This prevents any internal uses of brk() from having any effect. |
| 1632 | // We remember the old value so we can restore it on exec, so that |
| 1633 | // child processes will have a reasonable brk value. |
| 1634 | VG_(getrlimit)(VKI_RLIMIT_DATA, &VG_(client_rlimit_data)); |
| 1635 | zero.rlim_max = VG_(client_rlimit_data).rlim_max; |
| 1636 | VG_(setrlimit)(VKI_RLIMIT_DATA, &zero); |
thughes | c37184f | 2004-09-11 14:16:57 +0000 | [diff] [blame] | 1637 | |
| 1638 | // Get the current process stack rlimit. |
| 1639 | VG_(getrlimit)(VKI_RLIMIT_STACK, &VG_(client_rlimit_stack)); |
| 1640 | |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 1641 | //-------------------------------------------------------------- |
| 1642 | // Figure out what sort of CPU we're on, and whether it is |
| 1643 | // able to run V. |
| 1644 | VG_(debugLog)(1, "main", "Get hardware capabilities ...\n"); |
| 1645 | { VexArch vex_arch; |
| 1646 | VexArchInfo vex_archinfo; |
| 1647 | Bool ok = VG_(machine_get_hwcaps)(); |
| 1648 | if (!ok) { |
| 1649 | VG_(printf)("\n"); |
| 1650 | VG_(printf)("valgrind: fatal error: unsupported CPU.\n"); |
| 1651 | VG_(printf)(" Supported CPUs are:\n"); |
| 1652 | VG_(printf)(" * x86 (practically any; Pentium-I or above), " |
| 1653 | "AMD Athlon or above)\n"); |
| 1654 | VG_(printf)(" * AMD Athlon64/Opteron\n"); |
| 1655 | VG_(printf)(" * PowerPC (most; ppc405 and above)\n"); |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1656 | VG_(printf)(" * System z (64bit only - s390x; z900 and above)\n"); |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 1657 | VG_(printf)("\n"); |
| 1658 | VG_(exit)(1); |
| 1659 | } |
| 1660 | VG_(machine_get_VexArchInfo)( &vex_arch, &vex_archinfo ); |
sewardj | e3121f3 | 2006-01-27 21:23:23 +0000 | [diff] [blame] | 1661 | VG_(debugLog)( |
| 1662 | 1, "main", "... arch = %s, hwcaps = %s\n", |
| 1663 | LibVEX_ppVexArch ( vex_arch ), |
| 1664 | LibVEX_ppVexHwCaps ( vex_arch, vex_archinfo.hwcaps ) |
| 1665 | ); |
sewardj | e2d1e67 | 2005-11-12 23:10:48 +0000 | [diff] [blame] | 1666 | } |
| 1667 | |
sewardj | 198f34f | 2007-07-09 23:13:07 +0000 | [diff] [blame] | 1668 | //-------------------------------------------------------------- |
| 1669 | // Record the working directory at startup |
| 1670 | // p: none (Linux), getenv and sys_getpid work (AIX) |
| 1671 | VG_(debugLog)(1, "main", "Getting the working directory at startup\n"); |
| 1672 | { Bool ok = VG_(record_startup_wd)(); |
| 1673 | if (!ok) |
| 1674 | VG_(err_config_error)( "Can't establish current working " |
| 1675 | "directory at startup"); |
| 1676 | } |
| 1677 | { Char buf[VKI_PATH_MAX+1]; |
| 1678 | Bool ok = VG_(get_startup_wd)( buf, sizeof(buf) ); |
| 1679 | vg_assert(ok); |
| 1680 | buf[VKI_PATH_MAX] = 0; |
| 1681 | VG_(debugLog)(1, "main", "... %s\n", buf ); |
| 1682 | } |
| 1683 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1684 | //============================================================ |
| 1685 | // Command line argument handling order: |
| 1686 | // * If --help/--help-debug are present, show usage message |
| 1687 | // (including the tool-specific usage) |
| 1688 | // * (If no --tool option given, default to Memcheck) |
| 1689 | // * Then, if client is missing, abort with error msg |
| 1690 | // * Then, if any cmdline args are bad, abort with error msg |
| 1691 | //============================================================ |
| 1692 | |
| 1693 | //-------------------------------------------------------------- |
| 1694 | // Split up argv into: C args, V args, V extra args, and exename. |
| 1695 | // p: dynamic memory allocation |
| 1696 | //-------------------------------------------------------------- |
| 1697 | VG_(debugLog)(1, "main", "Split up command line\n"); |
| 1698 | VG_(split_up_argv)( argc, argv ); |
sewardj | 14c7cc5 | 2007-02-25 15:08:24 +0000 | [diff] [blame] | 1699 | vg_assert( VG_(args_for_valgrind) ); |
| 1700 | vg_assert( VG_(args_for_client) ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1701 | if (0) { |
sewardj | 14c7cc5 | 2007-02-25 15:08:24 +0000 | [diff] [blame] | 1702 | for (i = 0; i < VG_(sizeXA)( VG_(args_for_valgrind) ); i++) |
| 1703 | VG_(printf)( |
| 1704 | "varg %s\n", |
| 1705 | * (HChar**) VG_(indexXA)( VG_(args_for_valgrind), i ) |
| 1706 | ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1707 | VG_(printf)(" exe %s\n", VG_(args_the_exename)); |
sewardj | 14c7cc5 | 2007-02-25 15:08:24 +0000 | [diff] [blame] | 1708 | for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) |
| 1709 | VG_(printf)( |
| 1710 | "carg %s\n", |
| 1711 | * (HChar**) VG_(indexXA)( VG_(args_for_client), i ) |
| 1712 | ); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
sewardj | 948a6fc | 2007-03-19 18:38:55 +0000 | [diff] [blame] | 1715 | # if defined(VGO_aix5) |
| 1716 | /* Tolerate ptraced-based launchers. They can't run 'no program' |
| 1717 | if the user types "valgrind --help", so they run a do-nothing |
| 1718 | program $prefix/bin/no_op_client_for_valgrind, and we catch that |
| 1719 | here and turn it the exe name back into NULL. Then --help, |
| 1720 | --version etc work as they should. */ |
| 1721 | if (VG_(args_the_exename) |
| 1722 | && VG_(strstr)( VG_(args_the_exename), "/no_op_client_for_valgrind" )) { |
| 1723 | VG_(args_the_exename) = NULL; |
| 1724 | } |
| 1725 | # endif |
| 1726 | |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1727 | //-------------------------------------------------------------- |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1728 | // Extract tool name and whether help has been requested. |
| 1729 | // Note we can't print the help message yet, even if requested, |
| 1730 | // because the tool has not been initialised. |
| 1731 | // p: split_up_argv [for VG_(args_for_valgrind)] |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1732 | //-------------------------------------------------------------- |
sewardj | 95d86c0 | 2007-12-18 01:49:23 +0000 | [diff] [blame] | 1733 | VG_(debugLog)(1, "main", |
| 1734 | "(early_) Process Valgrind's command line options\n"); |
| 1735 | early_process_cmd_line_options(&need_help, &toolname); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1736 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1737 | // Set default vex control params |
| 1738 | LibVEX_default_VexControl(& VG_(clo_vex_control)); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1739 | |
| 1740 | //-------------------------------------------------------------- |
| 1741 | // Load client executable, finding in $PATH if necessary |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 1742 | // p: early_process_cmd_line_options() [for 'exec', 'need_help', |
| 1743 | // clo_max_stackframe, |
| 1744 | // clo_main_stacksize] |
sewardj | 95d86c0 | 2007-12-18 01:49:23 +0000 | [diff] [blame] | 1745 | // p: layout_remaining_space [so there's space] |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 1746 | // |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1747 | // Set up client's environment |
sewardj | 95d86c0 | 2007-12-18 01:49:23 +0000 | [diff] [blame] | 1748 | // p: set-libdir [for VG_(libdir)] |
| 1749 | // p: early_process_cmd_line_options [for toolname] |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 1750 | // |
nethercote | 5ee67ca | 2004-06-22 14:00:09 +0000 | [diff] [blame] | 1751 | // Setup client stack, eip, and VG_(client_arg[cv]) |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1752 | // p: load_client() [for 'info'] |
| 1753 | // p: fix_environment() [for 'env'] |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 1754 | // |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1755 | // Setup client data (brk) segment. Initially a 1-page segment |
| 1756 | // which abuts a shrinkable reservation. |
| 1757 | // p: load_client() [for 'info' and hence VG_(brk_base)] |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 1758 | // |
| 1759 | // p: _start_in_C (for zeroing out the_iicii and putting some |
| 1760 | // initial values into it) |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1761 | //-------------------------------------------------------------- |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 1762 | if (!need_help) { |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 1763 | VG_(debugLog)(1, "main", "Create initial image\n"); |
| 1764 | |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 1765 | # if defined(VGO_linux) || defined(VGO_darwin) |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 1766 | the_iicii.argv = argv; |
| 1767 | the_iicii.envp = envp; |
| 1768 | the_iicii.toolname = toolname; |
| 1769 | # elif defined(VGO_aix5) |
| 1770 | /* the_iicii.intregs37 already set up */ |
| 1771 | /* the_iicii.bootblock already set up */ |
| 1772 | /* the_iicii.adler32_exp already set up */ |
| 1773 | /* the_iicii.sp_at_startup is irrelevant */ |
| 1774 | /* the_iicii.clstack_top is irrelevant */ |
| 1775 | the_iicii.toolname = toolname; |
| 1776 | # else |
njn | a842d79 | 2009-05-21 01:15:18 +0000 | [diff] [blame] | 1777 | # error "Unknown platform" |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 1778 | # endif |
| 1779 | |
sewardj | dc2f79e | 2007-12-22 14:14:04 +0000 | [diff] [blame] | 1780 | /* NOTE: this call reads VG_(clo_main_stacksize). */ |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 1781 | the_iifii = VG_(ii_create_image)( the_iicii ); |
| 1782 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 1783 | # if defined(VGO_aix5) |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 1784 | /* Tell aspacem where the initial client stack is, so that it |
| 1785 | can later produce a faked-up NSegment in response to |
| 1786 | VG_(am_find_nsegment) for that address range, if asked. */ |
sewardj | dc2f79e | 2007-12-22 14:14:04 +0000 | [diff] [blame] | 1787 | /* NOTE: this call reads VG_(clo_main_stacksize). */ |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 1788 | VG_(am_aix5_set_initial_client_sp)( the_iifii.initial_client_SP ); |
| 1789 | /* Now have a look at said fake segment, so we can find out |
| 1790 | the size of it. */ |
| 1791 | { SizeT sz; |
| 1792 | NSegment const* seg |
| 1793 | = VG_(am_find_nsegment)( the_iifii.initial_client_SP ); |
| 1794 | vg_assert(seg); |
| 1795 | sz = seg->end - seg->start + 1; |
sewardj | c9d3383 | 2007-12-22 14:12:42 +0000 | [diff] [blame] | 1796 | vg_assert(sz >= 0 && sz <= (256+1)*1024*1024); /* stay sane */ |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 1797 | the_iifii.clstack_max_size = sz; |
| 1798 | } |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 1799 | # endif |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1800 | } |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1801 | |
| 1802 | //============================================================== |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1803 | // |
| 1804 | // Finished loading/setting up the client address space. |
| 1805 | // |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1806 | //============================================================== |
| 1807 | |
| 1808 | //-------------------------------------------------------------- |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1809 | // setup file descriptors |
| 1810 | // p: n/a |
| 1811 | //-------------------------------------------------------------- |
sewardj | 1fbc1a5 | 2005-04-25 02:05:54 +0000 | [diff] [blame] | 1812 | VG_(debugLog)(1, "main", "Setup file descriptors\n"); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1813 | setup_file_descriptors(); |
| 1814 | |
| 1815 | //-------------------------------------------------------------- |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1816 | // create the fake /proc/<pid>/cmdline file and then unlink it, |
| 1817 | // but hold onto the fd, so we can hand it out to the client |
| 1818 | // when it tries to open /proc/<pid>/cmdline for itself. |
| 1819 | // p: setup file descriptors |
nethercote | c314eba | 2004-07-15 12:59:41 +0000 | [diff] [blame] | 1820 | //-------------------------------------------------------------- |
bart | 9b533f8 | 2009-08-25 20:15:41 +0000 | [diff] [blame] | 1821 | #if !defined(VGO_linux) |
| 1822 | // client shouldn't be using /proc! |
| 1823 | VG_(cl_cmdline_fd) = -1; |
| 1824 | #else |
| 1825 | if (!need_help) { |
| 1826 | HChar buf[50], buf2[50+64]; |
| 1827 | HChar nul[1]; |
| 1828 | Int fd, r; |
bart | a3054f5 | 2010-06-14 18:12:56 +0000 | [diff] [blame] | 1829 | const HChar* exename; |
nethercote | c314eba | 2004-07-15 12:59:41 +0000 | [diff] [blame] | 1830 | |
bart | 9b533f8 | 2009-08-25 20:15:41 +0000 | [diff] [blame] | 1831 | VG_(debugLog)(1, "main", "Create fake /proc/<pid>/cmdline\n"); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1832 | |
bart | 9b533f8 | 2009-08-25 20:15:41 +0000 | [diff] [blame] | 1833 | VG_(sprintf)(buf, "proc_%d_cmdline", VG_(getpid)()); |
| 1834 | fd = VG_(mkstemp)( buf, buf2 ); |
| 1835 | if (fd == -1) |
| 1836 | VG_(err_config_error)("Can't create client cmdline file in /tmp."); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1837 | |
bart | 9b533f8 | 2009-08-25 20:15:41 +0000 | [diff] [blame] | 1838 | nul[0] = 0; |
| 1839 | exename = VG_(args_the_exename) ? VG_(args_the_exename) |
| 1840 | : "unknown_exename"; |
sewardj | c7ffc94 | 2011-03-28 16:26:42 +0000 | [diff] [blame] | 1841 | VG_(write)(fd, exename, VG_(strlen)( exename )); |
bart | 9b533f8 | 2009-08-25 20:15:41 +0000 | [diff] [blame] | 1842 | VG_(write)(fd, nul, 1); |
| 1843 | |
| 1844 | for (i = 0; i < VG_(sizeXA)( VG_(args_for_client) ); i++) { |
| 1845 | HChar* arg = * (HChar**) VG_(indexXA)( VG_(args_for_client), i ); |
| 1846 | VG_(write)(fd, arg, VG_(strlen)( arg )); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1847 | VG_(write)(fd, nul, 1); |
| 1848 | } |
bart | 9b533f8 | 2009-08-25 20:15:41 +0000 | [diff] [blame] | 1849 | |
| 1850 | /* Don't bother to seek the file back to the start; instead do |
| 1851 | it every time a copy of it is given out (by PRE(sys_open)). |
| 1852 | That is probably more robust across fork() etc. */ |
| 1853 | |
| 1854 | /* Now delete it, but hang on to the fd. */ |
| 1855 | r = VG_(unlink)( buf2 ); |
| 1856 | if (r) |
| 1857 | VG_(err_config_error)("Can't delete client cmdline file in /tmp."); |
| 1858 | |
| 1859 | VG_(cl_cmdline_fd) = fd; |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1860 | } |
bart | 9b533f8 | 2009-08-25 20:15:41 +0000 | [diff] [blame] | 1861 | #endif |
nethercote | c314eba | 2004-07-15 12:59:41 +0000 | [diff] [blame] | 1862 | |
| 1863 | //-------------------------------------------------------------- |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1864 | // Init tool part 1: pre_clo_init |
nethercote | c314eba | 2004-07-15 12:59:41 +0000 | [diff] [blame] | 1865 | // p: setup_client_stack() [for 'VG_(client_arg[cv]'] |
nethercote | c314eba | 2004-07-15 12:59:41 +0000 | [diff] [blame] | 1866 | // p: setup_file_descriptors() [for 'VG_(fd_xxx_limit)'] |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1867 | //-------------------------------------------------------------- |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1868 | VG_(debugLog)(1, "main", "Initialise the tool part 1 (pre_clo_init)\n"); |
njn | 08ce7b3 | 2009-02-27 03:38:28 +0000 | [diff] [blame] | 1869 | VG_(tl_pre_clo_init)(); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1870 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1871 | //-------------------------------------------------------------- |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 1872 | // If --tool and --help/--help-debug was given, now give the core+tool |
| 1873 | // help message |
sewardj | 95d86c0 | 2007-12-18 01:49:23 +0000 | [diff] [blame] | 1874 | // p: early_process_cmd_line_options() [for 'need_help'] |
| 1875 | // p: tl_pre_clo_init [for 'VG_(tdict).usage'] |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1876 | //-------------------------------------------------------------- |
| 1877 | VG_(debugLog)(1, "main", "Print help and quit, if requested\n"); |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 1878 | if (need_help) { |
njn | cce38e6 | 2010-07-06 04:25:12 +0000 | [diff] [blame] | 1879 | usage_NORETURN(/*--help-debug?*/need_help >= 2); |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 1880 | } |
nethercote | c314eba | 2004-07-15 12:59:41 +0000 | [diff] [blame] | 1881 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1882 | //-------------------------------------------------------------- |
| 1883 | // Process command line options to Valgrind + tool |
| 1884 | // p: setup_client_stack() [for 'VG_(client_arg[cv]'] |
| 1885 | // p: setup_file_descriptors() [for 'VG_(fd_xxx_limit)'] |
| 1886 | //-------------------------------------------------------------- |
sewardj | 95d86c0 | 2007-12-18 01:49:23 +0000 | [diff] [blame] | 1887 | VG_(debugLog)(1, "main", |
| 1888 | "(main_) Process Valgrind's command line options, " |
| 1889 | "setup logging\n"); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1890 | main_process_cmd_line_options ( &logging_to_fd, &xml_fname_unexpanded, |
| 1891 | toolname ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1892 | |
| 1893 | //-------------------------------------------------------------- |
sewardj | 592ae09 | 2005-11-08 19:01:44 +0000 | [diff] [blame] | 1894 | // Zeroise the millisecond counter by doing a first read of it. |
| 1895 | // p: none |
| 1896 | //-------------------------------------------------------------- |
| 1897 | (void) VG_(read_millisecond_timer)(); |
| 1898 | |
| 1899 | //-------------------------------------------------------------- |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1900 | // Print the preamble |
| 1901 | // p: tl_pre_clo_init [for 'VG_(details).name' and friends] |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1902 | // p: main_process_cmd_line_options() |
| 1903 | // [for VG_(clo_verbosity), VG_(clo_xml), |
| 1904 | // logging_to_fd, xml_fname_unexpanded] |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1905 | //-------------------------------------------------------------- |
| 1906 | VG_(debugLog)(1, "main", "Print the preamble...\n"); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 1907 | print_preamble(logging_to_fd, xml_fname_unexpanded, toolname); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1908 | VG_(debugLog)(1, "main", "...finished the preamble\n"); |
| 1909 | |
| 1910 | //-------------------------------------------------------------- |
| 1911 | // Init tool part 2: post_clo_init |
| 1912 | // p: setup_client_stack() [for 'VG_(client_arg[cv]'] |
| 1913 | // p: setup_file_descriptors() [for 'VG_(fd_xxx_limit)'] |
| 1914 | // p: print_preamble() [so any warnings printed in post_clo_init |
| 1915 | // are shown after the preamble] |
| 1916 | //-------------------------------------------------------------- |
| 1917 | VG_(debugLog)(1, "main", "Initialise the tool part 2 (post_clo_init)\n"); |
njn | 51d827b | 2005-05-09 01:02:08 +0000 | [diff] [blame] | 1918 | VG_TDICT_CALL(tool_post_clo_init); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 1919 | { |
| 1920 | /* The tool's "needs" will by now be finalised, since it has no |
| 1921 | further opportunity to specify them. So now sanity check |
| 1922 | them. */ |
| 1923 | Char* s; |
| 1924 | Bool ok; |
| 1925 | ok = VG_(sanity_check_needs)( &s ); |
| 1926 | if (!ok) { |
| 1927 | VG_(tool_panic)(s); |
| 1928 | } |
| 1929 | } |
nethercote | f4928da | 2004-06-15 10:54:40 +0000 | [diff] [blame] | 1930 | |
| 1931 | //-------------------------------------------------------------- |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1932 | // Initialise translation table and translation cache |
| 1933 | // p: aspacem [??] |
| 1934 | // p: tl_pre_clo_init [for 'VG_(details).avg_translation_sizeB'] |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1935 | //-------------------------------------------------------------- |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1936 | VG_(debugLog)(1, "main", "Initialise TT/TC\n"); |
| 1937 | VG_(init_tt_tc)(); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 1938 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1939 | //-------------------------------------------------------------- |
| 1940 | // Initialise the redirect table. |
| 1941 | // p: init_tt_tc [so it can call VG_(search_transtab) safely] |
| 1942 | // p: aspacem [so can change ownership of sysinfo pages] |
| 1943 | //-------------------------------------------------------------- |
| 1944 | VG_(debugLog)(1, "main", "Initialise redirects\n"); |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 1945 | VG_(redir_initialise)(); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1946 | |
| 1947 | //-------------------------------------------------------------- |
| 1948 | // Allow GDB attach |
sewardj | 95d86c0 | 2007-12-18 01:49:23 +0000 | [diff] [blame] | 1949 | // p: main_process_cmd_line_options() [for VG_(clo_wait_for_gdb)] |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1950 | //-------------------------------------------------------------- |
| 1951 | /* Hook to delay things long enough so we can get the pid and |
| 1952 | attach GDB in another shell. */ |
| 1953 | if (VG_(clo_wait_for_gdb)) { |
sewardj | 95611ff | 2007-02-16 13:57:07 +0000 | [diff] [blame] | 1954 | Long iters; |
| 1955 | volatile Long q; |
sewardj | 1fbc1a5 | 2005-04-25 02:05:54 +0000 | [diff] [blame] | 1956 | VG_(debugLog)(1, "main", "Wait for GDB\n"); |
sewardj | 93ab857 | 2005-02-06 14:10:40 +0000 | [diff] [blame] | 1957 | VG_(printf)("pid=%d, entering delay loop\n", VG_(getpid)()); |
sewardj | 8211a57 | 2005-06-23 21:37:47 +0000 | [diff] [blame] | 1958 | |
| 1959 | # if defined(VGP_x86_linux) |
| 1960 | iters = 5; |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 1961 | # elif defined(VGP_amd64_linux) || defined(VGP_ppc64_linux) |
sewardj | 8211a57 | 2005-06-23 21:37:47 +0000 | [diff] [blame] | 1962 | iters = 10; |
| 1963 | # elif defined(VGP_ppc32_linux) |
sewardj | d714d2e | 2005-07-08 18:24:04 +0000 | [diff] [blame] | 1964 | iters = 5; |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 1965 | # elif defined(VGP_arm_linux) |
| 1966 | iters = 1; |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 1967 | # elif defined(VGP_s390x_linux) |
| 1968 | iters = 10; |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 1969 | # elif defined(VGP_ppc32_aix5) || defined(VGP_ppc64_aix5) |
| 1970 | iters = 4; |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 1971 | # elif defined(VGO_darwin) |
| 1972 | iters = 3; |
sewardj | 8211a57 | 2005-06-23 21:37:47 +0000 | [diff] [blame] | 1973 | # else |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 1974 | # error "Unknown plat" |
sewardj | 8211a57 | 2005-06-23 21:37:47 +0000 | [diff] [blame] | 1975 | # endif |
| 1976 | |
| 1977 | iters *= 1000*1000*1000; |
| 1978 | for (q = 0; q < iters; q++) |
| 1979 | ; |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1980 | } |
| 1981 | |
sewardj | b5d320c | 2005-03-13 18:57:15 +0000 | [diff] [blame] | 1982 | //-------------------------------------------------------------- |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1983 | // Search for file descriptors that are inherited from our parent |
sewardj | 95d86c0 | 2007-12-18 01:49:23 +0000 | [diff] [blame] | 1984 | // p: main_process_cmd_line_options [for VG_(clo_track_fds)] |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1985 | //-------------------------------------------------------------- |
sewardj | 1fbc1a5 | 2005-04-25 02:05:54 +0000 | [diff] [blame] | 1986 | if (VG_(clo_track_fds)) { |
| 1987 | VG_(debugLog)(1, "main", "Init preopened fds\n"); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1988 | VG_(init_preopened_fds)(); |
sewardj | 1fbc1a5 | 2005-04-25 02:05:54 +0000 | [diff] [blame] | 1989 | } |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 1990 | |
| 1991 | //-------------------------------------------------------------- |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 1992 | // Load debug info for the existing segments. |
| 1993 | // p: setup_code_redirect_table [so that redirs can be recorded] |
| 1994 | // p: mallocfree |
| 1995 | // p: probably: setup fds and process CLOs, so that logging works |
sewardj | f98e1c0 | 2008-10-25 16:22:41 +0000 | [diff] [blame] | 1996 | // p: initialise m_debuginfo |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 1997 | // |
| 1998 | // While doing this, make a note of the debuginfo-handles that |
| 1999 | // come back from VG_(di_notify_mmap)/VG_(di_aix5_notify_segchange). |
| 2000 | // Later, in "Tell the tool about the initial client memory permissions" |
| 2001 | // (just below) we can then hand these handles off to the tool in |
| 2002 | // calls to VG_TRACK(new_mem_startup, ...). This gives the tool the |
| 2003 | // opportunity to make further queries to m_debuginfo before the |
| 2004 | // client is started, if it wants. We put this information into an |
| 2005 | // XArray, each handle along with the associated segment start address, |
| 2006 | // and search the XArray for the handles later, when calling |
| 2007 | // VG_TRACK(new_mem_startup, ...). |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2008 | //-------------------------------------------------------------- |
| 2009 | VG_(debugLog)(1, "main", "Load initial debug info\n"); |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 2010 | |
| 2011 | tl_assert(!addr2dihandle); |
| 2012 | addr2dihandle = VG_(newXA)( VG_(malloc), "main.vm.2", |
| 2013 | VG_(free), sizeof(Addr_n_ULong) ); |
| 2014 | tl_assert(addr2dihandle); |
| 2015 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2016 | # if defined(VGO_linux) |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2017 | { Addr* seg_starts; |
| 2018 | Int n_seg_starts; |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 2019 | Addr_n_ULong anu; |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2020 | |
njn | ac1e033 | 2009-05-08 00:39:31 +0000 | [diff] [blame] | 2021 | seg_starts = VG_(get_segment_starts)( &n_seg_starts ); |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2022 | vg_assert(seg_starts && n_seg_starts >= 0); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2023 | |
sewardj | f72cced | 2005-11-08 00:45:47 +0000 | [diff] [blame] | 2024 | /* show them all to the debug info reader. allow_SkFileV has to |
| 2025 | be True here so that we read info from the valgrind executable |
| 2026 | itself. */ |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 2027 | for (i = 0; i < n_seg_starts; i++) { |
| 2028 | anu.ull = VG_(di_notify_mmap)( seg_starts[i], True/*allow_SkFileV*/ ); |
| 2029 | /* anu.ull holds the debuginfo handle returned by di_notify_mmap, |
| 2030 | if any. */ |
| 2031 | if (anu.ull > 0) { |
| 2032 | anu.a = seg_starts[i]; |
| 2033 | VG_(addToXA)( addr2dihandle, &anu ); |
| 2034 | } |
| 2035 | } |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2036 | |
| 2037 | VG_(free)( seg_starts ); |
| 2038 | } |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2039 | # elif defined(VGO_aix5) |
| 2040 | { AixCodeSegChange* changes; |
| 2041 | Int changes_size, changes_used; |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 2042 | Addr_n_ULong anu; |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2043 | |
| 2044 | /* Find out how many AixCodeSegChange records we will need, |
| 2045 | and acquire them. */ |
| 2046 | changes_size = VG_(am_aix5_reread_procmap_howmany_directives)(); |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 2047 | changes = VG_(malloc)("main.vm.3", changes_size * sizeof(AixCodeSegChange)); |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2048 | vg_assert(changes); |
| 2049 | |
| 2050 | /* Now re-read /proc/<pid>/map and acquire a change set */ |
| 2051 | VG_(am_aix5_reread_procmap)( changes, &changes_used ); |
| 2052 | vg_assert(changes_used >= 0 && changes_used <= changes_size); |
| 2053 | |
| 2054 | /* And notify m_debuginfo of the changes. */ |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 2055 | for (i = 0; i < changes_used; i++) { |
| 2056 | anu.ull = VG_(di_aix5_notify_segchange)( |
| 2057 | changes[i].code_start, |
| 2058 | changes[i].code_len, |
| 2059 | changes[i].data_start, |
| 2060 | changes[i].data_len, |
| 2061 | changes[i].file_name, |
| 2062 | changes[i].mem_name, |
| 2063 | changes[i].is_mainexe, |
| 2064 | changes[i].acquire |
| 2065 | ); |
| 2066 | if (anu.ull > 0) { |
| 2067 | tl_assert(changes[i].acquire); |
| 2068 | anu.a = changes[i].code_start; /* is this correct? */ |
| 2069 | VG_(addToXA)( addr2dihandle, &anu ); |
| 2070 | } |
| 2071 | } |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2072 | |
| 2073 | VG_(free)(changes); |
| 2074 | } |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 2075 | # elif defined(VGO_darwin) |
| 2076 | { Addr* seg_starts; |
| 2077 | Int n_seg_starts; |
| 2078 | seg_starts = VG_(get_segment_starts)( &n_seg_starts ); |
| 2079 | vg_assert(seg_starts && n_seg_starts >= 0); |
| 2080 | |
| 2081 | /* show them all to the debug info reader. |
| 2082 | Don't read from V segments (unlike Linux) */ |
| 2083 | // GrP fixme really? |
| 2084 | for (i = 0; i < n_seg_starts; i++) |
| 2085 | VG_(di_notify_mmap)( seg_starts[i], False/*don't allow_SkFileV*/ ); |
| 2086 | |
| 2087 | VG_(free)( seg_starts ); |
| 2088 | } |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2089 | # else |
| 2090 | # error Unknown OS |
| 2091 | # endif |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2092 | |
| 2093 | //-------------------------------------------------------------- |
| 2094 | // Tell aspacem of ownership change of the asm helpers, so that |
| 2095 | // m_translate allows them to be translated. However, only do this |
| 2096 | // after the initial debug info read, since making a hole in the |
| 2097 | // address range for the stage2 binary confuses the debug info reader. |
| 2098 | // p: aspacem |
| 2099 | //-------------------------------------------------------------- |
| 2100 | { Bool change_ownership_v_c_OK; |
sewardj | 1a85f4f | 2006-01-12 21:15:35 +0000 | [diff] [blame] | 2101 | Addr co_start = VG_PGROUNDDN( (Addr)&VG_(trampoline_stuff_start) ); |
| 2102 | Addr co_endPlus = VG_PGROUNDUP( (Addr)&VG_(trampoline_stuff_end) ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2103 | VG_(debugLog)(1,"redir", |
| 2104 | "transfer ownership V -> C of 0x%llx .. 0x%llx\n", |
| 2105 | (ULong)co_start, (ULong)co_endPlus-1 ); |
| 2106 | |
| 2107 | change_ownership_v_c_OK |
| 2108 | = VG_(am_change_ownership_v_to_c)( co_start, co_endPlus - co_start ); |
| 2109 | vg_assert(change_ownership_v_c_OK); |
| 2110 | } |
| 2111 | |
| 2112 | //-------------------------------------------------------------- |
sewardj | de764e8 | 2007-11-09 23:13:22 +0000 | [diff] [blame] | 2113 | // Initialise the scheduler (phase 1) [generates tid_main] |
| 2114 | // p: none, afaics |
| 2115 | //-------------------------------------------------------------- |
| 2116 | VG_(debugLog)(1, "main", "Initialise scheduler (phase 1)\n"); |
| 2117 | tid_main = VG_(scheduler_init_phase1)(); |
| 2118 | vg_assert(tid_main >= 0 && tid_main < VG_N_THREADS |
| 2119 | && tid_main != VG_INVALID_THREADID); |
| 2120 | /* Tell the tool about tid_main */ |
| 2121 | VG_TRACK( pre_thread_ll_create, VG_INVALID_THREADID, tid_main ); |
| 2122 | |
| 2123 | //-------------------------------------------------------------- |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2124 | // Tell the tool about the initial client memory permissions |
| 2125 | // p: aspacem |
| 2126 | // p: mallocfree |
| 2127 | // p: setup_client_stack |
| 2128 | // p: setup_client_dataseg |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 2129 | // |
| 2130 | // For each segment we tell the client about, look up in |
| 2131 | // addr2dihandle as created above, to see if there's a debuginfo |
| 2132 | // handle associated with the segment, that we can hand along |
| 2133 | // to the tool, to be helpful. |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2134 | //-------------------------------------------------------------- |
| 2135 | VG_(debugLog)(1, "main", "Tell tool about initial permissions\n"); |
| 2136 | { Addr* seg_starts; |
| 2137 | Int n_seg_starts; |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2138 | |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 2139 | tl_assert(addr2dihandle); |
| 2140 | |
tom | 7c1a19a | 2008-01-02 10:13:04 +0000 | [diff] [blame] | 2141 | /* Mark the main thread as running while we tell the tool about |
| 2142 | the client memory so that the tool can associate that memory |
| 2143 | with the main thread. */ |
| 2144 | tl_assert(VG_(running_tid) == VG_INVALID_THREADID); |
| 2145 | VG_(running_tid) = tid_main; |
| 2146 | |
njn | ac1e033 | 2009-05-08 00:39:31 +0000 | [diff] [blame] | 2147 | seg_starts = VG_(get_segment_starts)( &n_seg_starts ); |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2148 | vg_assert(seg_starts && n_seg_starts >= 0); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2149 | |
| 2150 | /* show interesting ones to the tool */ |
| 2151 | for (i = 0; i < n_seg_starts; i++) { |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 2152 | Word j, n; |
sewardj | 12ab765 | 2006-10-17 02:10:42 +0000 | [diff] [blame] | 2153 | NSegment const* seg |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2154 | = VG_(am_find_nsegment)( seg_starts[i] ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2155 | vg_assert(seg); |
| 2156 | if (seg->kind == SkFileC || seg->kind == SkAnonC) { |
sewardj | c6d86a3 | 2009-01-31 15:08:08 +0000 | [diff] [blame] | 2157 | /* This next assertion is tricky. If it is placed |
| 2158 | immediately before this 'if', it very occasionally fails. |
| 2159 | Why? Because previous iterations of the loop may have |
| 2160 | caused tools (via the new_mem_startup calls) to do |
| 2161 | dynamic memory allocation, and that may affect the mapped |
| 2162 | segments; in particular it may cause segment merging to |
| 2163 | happen. Hence we cannot assume that seg_starts[i], which |
| 2164 | reflects the state of the world before we started this |
| 2165 | loop, is the same as seg->start, as the latter reflects |
| 2166 | the state of the world (viz, mappings) at this particular |
| 2167 | iteration of the loop. |
| 2168 | |
| 2169 | Why does moving it inside the 'if' make it safe? Because |
| 2170 | any dynamic memory allocation done by the tools will |
| 2171 | affect only the state of Valgrind-owned segments, not of |
| 2172 | Client-owned segments. And the 'if' guards against that |
| 2173 | -- we only get in here for Client-owned segments. |
| 2174 | |
| 2175 | In other words: the loop may change the state of |
| 2176 | Valgrind-owned segments as it proceeds. But it should |
| 2177 | not cause the Client-owned segments to change. */ |
| 2178 | vg_assert(seg->start == seg_starts[i]); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2179 | VG_(debugLog)(2, "main", |
| 2180 | "tell tool about %010lx-%010lx %c%c%c\n", |
| 2181 | seg->start, seg->end, |
| 2182 | seg->hasR ? 'r' : '-', |
| 2183 | seg->hasW ? 'w' : '-', |
| 2184 | seg->hasX ? 'x' : '-' ); |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 2185 | /* search addr2dihandle to see if we have an entry |
| 2186 | matching seg->start. */ |
| 2187 | n = VG_(sizeXA)( addr2dihandle ); |
| 2188 | for (j = 0; j < n; j++) { |
| 2189 | Addr_n_ULong* anl = VG_(indexXA)( addr2dihandle, j ); |
| 2190 | if (anl->a == seg->start) { |
| 2191 | tl_assert(anl->ull > 0); /* check it's a valid handle */ |
| 2192 | break; |
| 2193 | } |
| 2194 | } |
| 2195 | vg_assert(j >= 0 && j <= n); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2196 | VG_TRACK( new_mem_startup, seg->start, seg->end+1-seg->start, |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 2197 | seg->hasR, seg->hasW, seg->hasX, |
| 2198 | /* and the retrieved debuginfo handle, if any */ |
| 2199 | j < n |
| 2200 | ? ((Addr_n_ULong*)VG_(indexXA)( addr2dihandle, j ))->ull |
| 2201 | : 0 ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2202 | } |
| 2203 | } |
| 2204 | |
| 2205 | VG_(free)( seg_starts ); |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 2206 | VG_(deleteXA)( addr2dihandle ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2207 | |
| 2208 | /* Also do the initial stack permissions. */ |
bart | e05b3a4 | 2010-09-07 16:32:53 +0000 | [diff] [blame] | 2209 | { |
| 2210 | SSizeT inaccessible_len; |
| 2211 | NSegment const* seg |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 2212 | = VG_(am_find_nsegment)( the_iifii.initial_client_SP ); |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2213 | vg_assert(seg); |
| 2214 | vg_assert(seg->kind == SkAnonC); |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 2215 | vg_assert(the_iifii.initial_client_SP >= seg->start); |
| 2216 | vg_assert(the_iifii.initial_client_SP <= seg->end); |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2217 | # if defined(VGO_aix5) |
| 2218 | VG_(clstk_base) = seg->start; |
| 2219 | VG_(clstk_end) = seg->end; |
| 2220 | # endif |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2221 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2222 | /* Stuff below the initial SP is unaddressable. Take into |
| 2223 | account any ABI-mandated space below the stack pointer that |
| 2224 | is required (VG_STACK_REDZONE_SZB). setup_client_stack() |
| 2225 | will have allocated an extra page if a red zone is required, |
| 2226 | to be on the safe side. */ |
bart | e05b3a4 | 2010-09-07 16:32:53 +0000 | [diff] [blame] | 2227 | inaccessible_len = the_iifii.initial_client_SP - VG_STACK_REDZONE_SZB |
| 2228 | - seg->start; |
| 2229 | vg_assert(inaccessible_len >= 0); |
| 2230 | if (inaccessible_len > 0) |
| 2231 | VG_TRACK( die_mem_stack, |
| 2232 | seg->start, |
| 2233 | inaccessible_len ); |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2234 | VG_(debugLog)(2, "main", "mark stack inaccessible %010lx-%010lx\n", |
| 2235 | seg->start, |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 2236 | the_iifii.initial_client_SP-1 - VG_STACK_REDZONE_SZB); |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2237 | } |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2238 | |
| 2239 | /* Also the assembly helpers. */ |
| 2240 | VG_TRACK( new_mem_startup, |
| 2241 | (Addr)&VG_(trampoline_stuff_start), |
sewardj | c6527d6 | 2006-02-13 17:54:31 +0000 | [diff] [blame] | 2242 | (Addr)&VG_(trampoline_stuff_end) |
| 2243 | - (Addr)&VG_(trampoline_stuff_start), |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2244 | False, /* readable? */ |
| 2245 | False, /* writable? */ |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 2246 | True /* executable? */, |
| 2247 | 0 /* di_handle: no associated debug info */ ); |
tom | 7c1a19a | 2008-01-02 10:13:04 +0000 | [diff] [blame] | 2248 | |
| 2249 | /* Clear the running thread indicator */ |
| 2250 | VG_(running_tid) = VG_INVALID_THREADID; |
| 2251 | tl_assert(VG_(running_tid) == VG_INVALID_THREADID); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2252 | } |
| 2253 | |
| 2254 | //-------------------------------------------------------------- |
sewardj | de764e8 | 2007-11-09 23:13:22 +0000 | [diff] [blame] | 2255 | // Initialise the scheduler (phase 2) |
| 2256 | // p: Initialise the scheduler (phase 1) [for tid_main] |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2257 | // p: setup_file_descriptors() [else VG_(safe_fd)() breaks] |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2258 | // p: setup_client_stack |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2259 | //-------------------------------------------------------------- |
sewardj | de764e8 | 2007-11-09 23:13:22 +0000 | [diff] [blame] | 2260 | VG_(debugLog)(1, "main", "Initialise scheduler (phase 2)\n"); |
sewardj | 12ab765 | 2006-10-17 02:10:42 +0000 | [diff] [blame] | 2261 | { NSegment const* seg |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 2262 | = VG_(am_find_nsegment)( the_iifii.initial_client_SP ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2263 | vg_assert(seg); |
| 2264 | vg_assert(seg->kind == SkAnonC); |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 2265 | vg_assert(the_iifii.initial_client_SP >= seg->start); |
| 2266 | vg_assert(the_iifii.initial_client_SP <= seg->end); |
sewardj | de764e8 | 2007-11-09 23:13:22 +0000 | [diff] [blame] | 2267 | VG_(scheduler_init_phase2)( tid_main, |
| 2268 | seg->end, the_iifii.clstack_max_size ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2269 | } |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2270 | |
| 2271 | //-------------------------------------------------------------- |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2272 | // Set up state for the root thread |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2273 | // p: ? |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2274 | // setup_scheduler() [for sched-specific thread 1 stuff] |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 2275 | // VG_(ii_create_image) [for 'the_iicii' initial info] |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 2276 | //-------------------------------------------------------------- |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 2277 | VG_(debugLog)(1, "main", "Finalise initial image\n"); |
| 2278 | VG_(ii_finalise_image)( the_iifii ); |
njn | ea4b28c | 2004-11-30 16:04:58 +0000 | [diff] [blame] | 2279 | |
sewardj | 2a99cf6 | 2004-11-24 10:44:19 +0000 | [diff] [blame] | 2280 | //-------------------------------------------------------------- |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2281 | // Initialise the signal handling subsystem |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2282 | // p: n/a |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2283 | //-------------------------------------------------------------- |
| 2284 | // Nb: temporarily parks the saved blocking-mask in saved_sigmask. |
sewardj | 1fbc1a5 | 2005-04-25 02:05:54 +0000 | [diff] [blame] | 2285 | VG_(debugLog)(1, "main", "Initialise signal management\n"); |
njn | cda2f0f | 2009-05-18 02:12:08 +0000 | [diff] [blame] | 2286 | /* Check that the kernel-interface signal definitions look sane */ |
| 2287 | VG_(vki_do_initial_consistency_checks)(); |
| 2288 | /* .. and go on to use them. */ |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2289 | VG_(sigstartup_actions)(); |
| 2290 | |
| 2291 | //-------------------------------------------------------------- |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2292 | // Read suppression file |
sewardj | 95d86c0 | 2007-12-18 01:49:23 +0000 | [diff] [blame] | 2293 | // p: main_process_cmd_line_options() [for VG_(clo_suppressions)] |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2294 | //-------------------------------------------------------------- |
sewardj | 1fbc1a5 | 2005-04-25 02:05:54 +0000 | [diff] [blame] | 2295 | if (VG_(needs).core_errors || VG_(needs).tool_errors) { |
| 2296 | VG_(debugLog)(1, "main", "Load suppressions\n"); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2297 | VG_(load_suppressions)(); |
sewardj | 1fbc1a5 | 2005-04-25 02:05:54 +0000 | [diff] [blame] | 2298 | } |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2299 | |
| 2300 | //-------------------------------------------------------------- |
rjwalsh | 0140af5 | 2005-06-04 20:42:33 +0000 | [diff] [blame] | 2301 | // register client stack |
| 2302 | //-------------------------------------------------------------- |
njn | 945ed2e | 2005-06-24 03:28:30 +0000 | [diff] [blame] | 2303 | VG_(clstk_id) = VG_(register_stack)(VG_(clstk_base), VG_(clstk_end)); |
rjwalsh | 0140af5 | 2005-06-04 20:42:33 +0000 | [diff] [blame] | 2304 | |
| 2305 | //-------------------------------------------------------------- |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2306 | // Show the address space state so far |
| 2307 | //-------------------------------------------------------------- |
| 2308 | VG_(debugLog)(1, "main", "\n"); |
| 2309 | VG_(debugLog)(1, "main", "\n"); |
| 2310 | VG_(am_show_nsegments)(1,"Memory layout at client startup"); |
| 2311 | VG_(debugLog)(1, "main", "\n"); |
| 2312 | VG_(debugLog)(1, "main", "\n"); |
| 2313 | |
| 2314 | //-------------------------------------------------------------- |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2315 | // Run! |
| 2316 | //-------------------------------------------------------------- |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 2317 | if (VG_(clo_xml)) { |
sewardj | 68cde6f | 2005-07-19 12:17:51 +0000 | [diff] [blame] | 2318 | HChar buf[50]; |
sewardj | 592ae09 | 2005-11-08 19:01:44 +0000 | [diff] [blame] | 2319 | VG_(elapsed_wallclock_time)(buf); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 2320 | VG_(printf_xml_no_f_c)( "<status>\n" |
| 2321 | " <state>RUNNING</state>\n" |
| 2322 | " <time>%t</time>\n" |
| 2323 | "</status>\n", |
| 2324 | buf ); |
| 2325 | VG_(printf_xml_no_f_c)( "\n" ); |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 2326 | } |
| 2327 | |
sewardj | 1fbc1a5 | 2005-04-25 02:05:54 +0000 | [diff] [blame] | 2328 | VG_(debugLog)(1, "main", "Running thread 1\n"); |
sewardj | 1ae3f3a | 2005-09-28 10:47:38 +0000 | [diff] [blame] | 2329 | |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 2330 | /* As a result of the following call, the last thread standing |
sewardj | 1ae3f3a | 2005-09-28 10:47:38 +0000 | [diff] [blame] | 2331 | eventually winds up running shutdown_actions_NORETURN |
| 2332 | just below. Unfortunately, simply exporting said function |
| 2333 | causes m_main to be part of a module cycle, which is pretty |
| 2334 | nonsensical. So instead of doing that, the address of said |
| 2335 | function is stored in a global variable 'owned' by m_syswrap, |
| 2336 | and it uses that function pointer to get back here when it needs |
| 2337 | to. */ |
| 2338 | |
| 2339 | /* Set continuation address. */ |
| 2340 | VG_(address_of_m_main_shutdown_actions_NORETURN) |
| 2341 | = & shutdown_actions_NORETURN; |
| 2342 | |
| 2343 | /* Run the first thread, eventually ending up at the continuation |
| 2344 | address. */ |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 2345 | VG_(main_thread_wrapper_NORETURN)(1); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2346 | |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 2347 | /*NOTREACHED*/ |
| 2348 | vg_assert(0); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2349 | } |
| 2350 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2351 | /* Do everything which needs doing when the last thread exits or when |
| 2352 | a thread exits requesting a complete process exit (exit on AIX). |
| 2353 | |
| 2354 | We enter here holding The Lock. For the case VgSrc_ExitProcess we |
| 2355 | must never release it, because to do so would allow other threads |
| 2356 | to continue after the system is ostensibly shut down. So we must |
| 2357 | go to our grave, so to speak, holding the lock. |
| 2358 | |
| 2359 | In fact, there is never any point in releasing the lock at this |
| 2360 | point - we have it, we're shutting down the entire system, and |
| 2361 | for the case VgSrc_ExitProcess doing so positively causes trouble. |
| 2362 | So don't. |
| 2363 | |
| 2364 | The final_tidyup call makes a bit of a nonsense of the ExitProcess |
| 2365 | case, since it will run the libc_freeres function, thus allowing |
| 2366 | other lurking threads to run again. Hmm. */ |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2367 | |
sewardj | 1ae3f3a | 2005-09-28 10:47:38 +0000 | [diff] [blame] | 2368 | static |
| 2369 | void shutdown_actions_NORETURN( ThreadId tid, |
| 2370 | VgSchedReturnCode tids_schedretcode ) |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2371 | { |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 2372 | VG_(debugLog)(1, "main", "entering VG_(shutdown_actions_NORETURN)\n"); |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2373 | VG_(am_show_nsegments)(1,"Memory layout at client shutdown"); |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 2374 | |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2375 | vg_assert(VG_(is_running_thread)(tid)); |
| 2376 | |
sewardj | 12ab765 | 2006-10-17 02:10:42 +0000 | [diff] [blame] | 2377 | vg_assert(tids_schedretcode == VgSrc_ExitThread |
| 2378 | || tids_schedretcode == VgSrc_ExitProcess |
| 2379 | || tids_schedretcode == VgSrc_FatalSig ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2380 | |
sewardj | 12ab765 | 2006-10-17 02:10:42 +0000 | [diff] [blame] | 2381 | if (tids_schedretcode == VgSrc_ExitThread) { |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2382 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2383 | // We are the last surviving thread. Right? |
| 2384 | vg_assert( VG_(count_living_threads)() == 1 ); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2385 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2386 | // Wait for all other threads to exit. |
| 2387 | // jrs: Huh? but they surely are already gone |
| 2388 | VG_(reap_threads)(tid); |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2389 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2390 | // Clean the client up before the final report |
| 2391 | // this causes the libc_freeres function to run |
| 2392 | final_tidyup(tid); |
| 2393 | |
| 2394 | /* be paranoid */ |
| 2395 | vg_assert(VG_(is_running_thread)(tid)); |
| 2396 | vg_assert(VG_(count_living_threads)() == 1); |
| 2397 | |
| 2398 | } else { |
| 2399 | |
| 2400 | // We may not be the last surviving thread. However, we |
| 2401 | // want to shut down the entire process. We hold the lock |
| 2402 | // and we need to keep hold of it all the way out, in order |
| 2403 | // that none of the other threads ever run again. |
| 2404 | vg_assert( VG_(count_living_threads)() >= 1 ); |
| 2405 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2406 | // Clean the client up before the final report |
| 2407 | // this causes the libc_freeres function to run |
| 2408 | // perhaps this is unsafe, as per comment above |
| 2409 | final_tidyup(tid); |
| 2410 | |
| 2411 | /* be paranoid */ |
| 2412 | vg_assert(VG_(is_running_thread)(tid)); |
| 2413 | vg_assert(VG_(count_living_threads)() >= 1); |
| 2414 | } |
sewardj | b5f6f51 | 2005-03-10 23:59:00 +0000 | [diff] [blame] | 2415 | |
| 2416 | VG_(threads)[tid].status = VgTs_Empty; |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2417 | //-------------------------------------------------------------- |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 2418 | // Finalisation: cleanup, messages, etc. Order not so important, only |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2419 | // affects what order the messages come. |
| 2420 | //-------------------------------------------------------------- |
njn | b6267bd | 2009-08-12 00:14:16 +0000 | [diff] [blame] | 2421 | // First thing in the post-amble is a blank line. |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 2422 | if (VG_(clo_xml)) |
| 2423 | VG_(printf_xml)("\n"); |
njn | b6267bd | 2009-08-12 00:14:16 +0000 | [diff] [blame] | 2424 | else if (VG_(clo_verbosity) > 0) |
| 2425 | VG_(message)(Vg_UserMsg, "\n"); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2426 | |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 2427 | if (VG_(clo_xml)) { |
sewardj | 68cde6f | 2005-07-19 12:17:51 +0000 | [diff] [blame] | 2428 | HChar buf[50]; |
sewardj | 592ae09 | 2005-11-08 19:01:44 +0000 | [diff] [blame] | 2429 | VG_(elapsed_wallclock_time)(buf); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 2430 | VG_(printf_xml_no_f_c)( "<status>\n" |
| 2431 | " <state>FINISHED</state>\n" |
| 2432 | " <time>%t</time>\n" |
njn | b6267bd | 2009-08-12 00:14:16 +0000 | [diff] [blame] | 2433 | "</status>\n" |
| 2434 | "\n", |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 2435 | buf); |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 2436 | } |
| 2437 | |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2438 | /* Print out file descriptor summary and stats. */ |
| 2439 | if (VG_(clo_track_fds)) |
nethercote | 3a42fb8 | 2004-08-03 18:08:50 +0000 | [diff] [blame] | 2440 | VG_(show_open_fds)(); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2441 | |
sewardj | 2d9e874 | 2009-08-07 15:46:56 +0000 | [diff] [blame] | 2442 | /* Call the tool's finalisation function. This makes Memcheck's |
| 2443 | leak checker run, and possibly chuck a bunch of leak errors into |
| 2444 | the error management machinery. */ |
| 2445 | VG_TDICT_CALL(tool_fini, 0/*exitcode*/); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2446 | |
sewardj | 2d9e874 | 2009-08-07 15:46:56 +0000 | [diff] [blame] | 2447 | /* Show the error counts. */ |
sewardj | 7ca100d | 2009-08-15 23:05:34 +0000 | [diff] [blame] | 2448 | if (VG_(clo_xml) |
| 2449 | && (VG_(needs).core_errors || VG_(needs).tool_errors)) { |
sewardj | 2d9e874 | 2009-08-07 15:46:56 +0000 | [diff] [blame] | 2450 | VG_(show_error_counts_as_XML)(); |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 2451 | } |
sewardj | 2d9e874 | 2009-08-07 15:46:56 +0000 | [diff] [blame] | 2452 | |
| 2453 | /* In XML mode, this merely prints the used suppressions. */ |
| 2454 | if (VG_(needs).core_errors || VG_(needs).tool_errors) |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 2455 | VG_(show_all_errors)(VG_(clo_verbosity), VG_(clo_xml)); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2456 | |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 2457 | if (VG_(clo_xml)) { |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 2458 | VG_(printf_xml)("\n"); |
| 2459 | VG_(printf_xml)("</valgrindoutput>\n"); |
| 2460 | VG_(printf_xml)("\n"); |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 2461 | } |
| 2462 | |
nethercote | 885dd91 | 2004-08-03 23:14:00 +0000 | [diff] [blame] | 2463 | VG_(sanity_check_general)( True /*include expensive checks*/ ); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2464 | |
sewardj | 2d9e874 | 2009-08-07 15:46:56 +0000 | [diff] [blame] | 2465 | if (VG_(clo_stats)) |
nethercote | 3a42fb8 | 2004-08-03 18:08:50 +0000 | [diff] [blame] | 2466 | print_all_stats(); |
nethercote | 71980f0 | 2004-01-24 18:18:54 +0000 | [diff] [blame] | 2467 | |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 2468 | /* Show a profile of the heap(s) at shutdown. Optionally, first |
| 2469 | throw away all the debug info, as that makes it easy to spot |
| 2470 | leaks in the debuginfo reader. */ |
| 2471 | if (VG_(clo_profile_heap)) { |
| 2472 | if (0) VG_(di_discard_ALL_debuginfo)(); |
| 2473 | VG_(print_arena_cc_analysis)(); |
| 2474 | } |
| 2475 | |
njn | 2025cf9 | 2005-06-26 20:44:48 +0000 | [diff] [blame] | 2476 | if (VG_(clo_profile_flags) > 0) { |
sewardj | 5471ec6 | 2006-10-17 13:58:17 +0000 | [diff] [blame] | 2477 | #define N_MAX 200 |
njn | 2025cf9 | 2005-06-26 20:44:48 +0000 | [diff] [blame] | 2478 | BBProfEntry tops[N_MAX]; |
| 2479 | ULong score_total = VG_(get_BB_profile) (tops, N_MAX); |
| 2480 | show_BB_profile(tops, N_MAX, score_total); |
| 2481 | } |
sewardj | fa8ec11 | 2005-01-19 11:55:34 +0000 | [diff] [blame] | 2482 | |
sewardj | 8b635a4 | 2004-11-22 19:01:47 +0000 | [diff] [blame] | 2483 | /* Print Vex storage stats */ |
sewardj | bf42651 | 2005-01-17 18:35:30 +0000 | [diff] [blame] | 2484 | if (0) |
| 2485 | LibVEX_ShowAllocStats(); |
sewardj | 1d88711 | 2005-05-30 21:44:08 +0000 | [diff] [blame] | 2486 | |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 2487 | /* Flush any output cached by previous calls to VG_(message). */ |
| 2488 | VG_(message_flush)(); |
| 2489 | |
sewardj | 3b29048 | 2011-05-06 21:02:55 +0000 | [diff] [blame] | 2490 | /* terminate gdbserver if ever it was started. We terminate it here so that it get |
| 2491 | the output above if output was redirected to gdb */ |
| 2492 | VG_(gdbserver) (0); |
| 2493 | |
njn | 8aa3585 | 2005-06-10 22:59:56 +0000 | [diff] [blame] | 2494 | /* Ok, finally exit in the os-specific way, according to the scheduler's |
| 2495 | return code. In short, if the (last) thread exited by calling |
| 2496 | sys_exit, do likewise; if the (last) thread stopped due to a fatal |
| 2497 | signal, terminate the entire system with that same fatal signal. */ |
| 2498 | VG_(debugLog)(1, "core_os", |
njn | 7b85dd5 | 2005-06-12 17:26:29 +0000 | [diff] [blame] | 2499 | "VG_(terminate_NORETURN)(tid=%lld)\n", (ULong)tid); |
njn | 8aa3585 | 2005-06-10 22:59:56 +0000 | [diff] [blame] | 2500 | |
njn | 8aa3585 | 2005-06-10 22:59:56 +0000 | [diff] [blame] | 2501 | switch (tids_schedretcode) { |
sewardj | 12ab765 | 2006-10-17 02:10:42 +0000 | [diff] [blame] | 2502 | case VgSrc_ExitThread: /* the normal way out (Linux) */ |
| 2503 | case VgSrc_ExitProcess: /* the normal way out (AIX) */ |
sewardj | b977908 | 2006-05-12 23:50:15 +0000 | [diff] [blame] | 2504 | /* Change the application return code to user's return code, |
| 2505 | if an error was found */ |
| 2506 | if (VG_(clo_error_exitcode) > 0 |
| 2507 | && VG_(get_n_errs_found)() > 0) { |
| 2508 | VG_(exit)( VG_(clo_error_exitcode) ); |
| 2509 | } else { |
| 2510 | /* otherwise, return the client's exit code, in the normal |
| 2511 | way. */ |
| 2512 | VG_(exit)( VG_(threads)[tid].os_state.exitcode ); |
| 2513 | } |
njn | 8aa3585 | 2005-06-10 22:59:56 +0000 | [diff] [blame] | 2514 | /* NOT ALIVE HERE! */ |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2515 | VG_(core_panic)("entered the afterlife in main() -- ExitT/P"); |
njn | 8aa3585 | 2005-06-10 22:59:56 +0000 | [diff] [blame] | 2516 | break; /* what the hell :) */ |
| 2517 | |
| 2518 | case VgSrc_FatalSig: |
| 2519 | /* We were killed by a fatal signal, so replicate the effect */ |
| 2520 | vg_assert(VG_(threads)[tid].os_state.fatalsig != 0); |
| 2521 | VG_(kill_self)(VG_(threads)[tid].os_state.fatalsig); |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 2522 | /* we shouldn't be alive at this point. But VG_(kill_self) |
| 2523 | sometimes fails with EPERM on Darwin, for unclear reasons. */ |
| 2524 | # if defined(VGO_darwin) |
| 2525 | VG_(debugLog)(0, "main", "VG_(kill_self) failed. Exiting normally.\n"); |
| 2526 | VG_(exit)(0); /* bogus, but we really need to exit now */ |
| 2527 | /* fall through .. */ |
| 2528 | # endif |
njn | 8aa3585 | 2005-06-10 22:59:56 +0000 | [diff] [blame] | 2529 | VG_(core_panic)("main(): signal was supposed to be fatal"); |
| 2530 | break; |
| 2531 | |
| 2532 | default: |
| 2533 | VG_(core_panic)("main(): unexpected scheduler return code"); |
| 2534 | } |
njn | e96be67 | 2005-05-08 19:08:54 +0000 | [diff] [blame] | 2535 | } |
sewardj | 8b635a4 | 2004-11-22 19:01:47 +0000 | [diff] [blame] | 2536 | |
sewardj | 1ae3f3a | 2005-09-28 10:47:38 +0000 | [diff] [blame] | 2537 | /* -------------------- */ |
| 2538 | |
| 2539 | /* Final clean-up before terminating the process. |
| 2540 | Clean up the client by calling __libc_freeres() (if requested) |
| 2541 | This is Linux-specific? |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 2542 | GrP fixme glibc-specific, anyway |
sewardj | 1ae3f3a | 2005-09-28 10:47:38 +0000 | [diff] [blame] | 2543 | */ |
| 2544 | static void final_tidyup(ThreadId tid) |
| 2545 | { |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 2546 | #if !defined(VGO_darwin) |
sewardj | cf95181 | 2006-01-17 02:22:21 +0000 | [diff] [blame] | 2547 | # if defined(VGP_ppc64_linux) |
| 2548 | Addr r2; |
| 2549 | # endif |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 2550 | Addr __libc_freeres_wrapper = VG_(client___libc_freeres_wrapper); |
sewardj | 1ae3f3a | 2005-09-28 10:47:38 +0000 | [diff] [blame] | 2551 | |
| 2552 | vg_assert(VG_(is_running_thread)(tid)); |
| 2553 | |
| 2554 | if ( !VG_(needs).libc_freeres || |
| 2555 | !VG_(clo_run_libc_freeres) || |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 2556 | 0 == __libc_freeres_wrapper ) |
sewardj | 1ae3f3a | 2005-09-28 10:47:38 +0000 | [diff] [blame] | 2557 | return; /* can't/won't do it */ |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2558 | # if defined(VGO_aix5) |
| 2559 | return; /* inapplicable on non-Linux platforms */ |
| 2560 | # endif |
sewardj | 1ae3f3a | 2005-09-28 10:47:38 +0000 | [diff] [blame] | 2561 | |
sewardj | cf95181 | 2006-01-17 02:22:21 +0000 | [diff] [blame] | 2562 | # if defined(VGP_ppc64_linux) |
| 2563 | r2 = VG_(get_tocptr)( __libc_freeres_wrapper ); |
| 2564 | if (r2 == 0) { |
| 2565 | VG_(message)(Vg_UserMsg, |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 2566 | "Caught __NR_exit, but can't run __libc_freeres()\n"); |
sewardj | cf95181 | 2006-01-17 02:22:21 +0000 | [diff] [blame] | 2567 | VG_(message)(Vg_UserMsg, |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 2568 | " since cannot establish TOC pointer for it.\n"); |
sewardj | cf95181 | 2006-01-17 02:22:21 +0000 | [diff] [blame] | 2569 | return; |
| 2570 | } |
| 2571 | # endif |
| 2572 | |
sewardj | 1ae3f3a | 2005-09-28 10:47:38 +0000 | [diff] [blame] | 2573 | if (VG_(clo_verbosity) > 2 || |
| 2574 | VG_(clo_trace_syscalls) || |
| 2575 | VG_(clo_trace_sched)) |
| 2576 | VG_(message)(Vg_DebugMsg, |
sewardj | 738856f | 2009-07-15 14:48:32 +0000 | [diff] [blame] | 2577 | "Caught __NR_exit; running __libc_freeres()\n"); |
sewardj | 1ae3f3a | 2005-09-28 10:47:38 +0000 | [diff] [blame] | 2578 | |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 2579 | /* set thread context to point to libc_freeres_wrapper */ |
sewardj | 1a85f4f | 2006-01-12 21:15:35 +0000 | [diff] [blame] | 2580 | /* ppc64-linux note: __libc_freeres_wrapper gives us the real |
| 2581 | function entry point, not a fn descriptor, so can use it |
| 2582 | directly. However, we need to set R2 (the toc pointer) |
| 2583 | appropriately. */ |
sewardj | 1ae3f3a | 2005-09-28 10:47:38 +0000 | [diff] [blame] | 2584 | VG_(set_IP)(tid, __libc_freeres_wrapper); |
sewardj | cf95181 | 2006-01-17 02:22:21 +0000 | [diff] [blame] | 2585 | # if defined(VGP_ppc64_linux) |
| 2586 | VG_(threads)[tid].arch.vex.guest_GPR2 = r2; |
| 2587 | # endif |
sewardj | 1ae3f3a | 2005-09-28 10:47:38 +0000 | [diff] [blame] | 2588 | |
| 2589 | /* Block all blockable signals by copying the real block state into |
| 2590 | the thread's block state*/ |
| 2591 | VG_(sigprocmask)(VKI_SIG_BLOCK, NULL, &VG_(threads)[tid].sig_mask); |
| 2592 | VG_(threads)[tid].tmp_sig_mask = VG_(threads)[tid].sig_mask; |
| 2593 | |
| 2594 | /* and restore handlers to default */ |
| 2595 | VG_(set_default_handler)(VKI_SIGSEGV); |
| 2596 | VG_(set_default_handler)(VKI_SIGBUS); |
| 2597 | VG_(set_default_handler)(VKI_SIGILL); |
| 2598 | VG_(set_default_handler)(VKI_SIGFPE); |
| 2599 | |
| 2600 | // We were exiting, so assert that... |
| 2601 | vg_assert(VG_(is_exiting)(tid)); |
| 2602 | // ...but now we're not again |
| 2603 | VG_(threads)[tid].exitreason = VgSrc_None; |
| 2604 | |
| 2605 | // run until client thread exits - ideally with LIBC_FREERES_DONE, |
| 2606 | // but exit/exitgroup/signal will do |
| 2607 | VG_(scheduler)(tid); |
| 2608 | |
| 2609 | vg_assert(VG_(is_exiting)(tid)); |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 2610 | #endif |
sewardj | 1ae3f3a | 2005-09-28 10:47:38 +0000 | [diff] [blame] | 2611 | } |
| 2612 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2613 | |
| 2614 | /*====================================================================*/ |
njn | 49f80e8 | 2009-05-21 01:25:43 +0000 | [diff] [blame] | 2615 | /*=== Getting to main() alive: LINUX ===*/ |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2616 | /*====================================================================*/ |
| 2617 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2618 | #if defined(VGO_linux) |
| 2619 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2620 | /* If linking of the final executables is done with glibc present, |
| 2621 | then Valgrind starts at main() above as usual, and all of the |
| 2622 | following code is irrelevant. |
| 2623 | |
| 2624 | However, this is not the intended mode of use. The plan is to |
| 2625 | avoid linking against glibc, by giving gcc the flags |
| 2626 | -nodefaultlibs -lgcc -nostartfiles at startup. |
| 2627 | |
| 2628 | From this derive two requirements: |
| 2629 | |
| 2630 | 1. gcc may emit calls to memcpy and memset to deal with structure |
| 2631 | assignments etc. Since we have chosen to ignore all the |
| 2632 | "normal" supporting libraries, we have to provide our own |
| 2633 | implementations of them. No problem. |
| 2634 | |
| 2635 | 2. We have to provide a symbol "_start", to which the kernel |
| 2636 | hands control at startup. Hence the code below. |
| 2637 | */ |
| 2638 | |
| 2639 | /* ---------------- Requirement 1 ---------------- */ |
| 2640 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2641 | void* memcpy(void *dest, const void *src, SizeT n); |
| 2642 | void* memcpy(void *dest, const void *src, SizeT n) { |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2643 | return VG_(memcpy)(dest,src,n); |
| 2644 | } |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2645 | void* memset(void *s, int c, SizeT n); |
| 2646 | void* memset(void *s, int c, SizeT n) { |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2647 | return VG_(memset)(s,c,n); |
| 2648 | } |
| 2649 | |
bart | 82616e1 | 2010-06-13 13:46:24 +0000 | [diff] [blame] | 2650 | /* BVA: abort() for those platforms that need it (PPC and ARM). */ |
| 2651 | void abort(void); |
| 2652 | void abort(void){ |
| 2653 | VG_(printf)("Something called raise().\n"); |
| 2654 | vg_assert(0); |
| 2655 | } |
| 2656 | |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 2657 | /* EAZG: ARM's EABI will call floating point exception handlers in |
| 2658 | libgcc which boil down to an abort or raise, that's usually defined |
| 2659 | in libc. Instead, define them here. */ |
| 2660 | #if defined(VGP_arm_linux) |
| 2661 | void raise(void); |
| 2662 | void raise(void){ |
| 2663 | VG_(printf)("Something called raise().\n"); |
| 2664 | vg_assert(0); |
| 2665 | } |
| 2666 | |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 2667 | void __aeabi_unwind_cpp_pr0(void); |
| 2668 | void __aeabi_unwind_cpp_pr0(void){ |
| 2669 | VG_(printf)("Something called __aeabi_unwind_cpp_pr0()\n"); |
| 2670 | vg_assert(0); |
| 2671 | } |
sewardj | 38efe4b | 2010-08-22 12:23:01 +0000 | [diff] [blame] | 2672 | |
| 2673 | void __aeabi_unwind_cpp_pr1(void); |
| 2674 | void __aeabi_unwind_cpp_pr1(void){ |
| 2675 | VG_(printf)("Something called __aeabi_unwind_cpp_pr1()\n"); |
| 2676 | vg_assert(0); |
| 2677 | } |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 2678 | #endif |
| 2679 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2680 | /* ---------------- Requirement 2 ---------------- */ |
| 2681 | |
| 2682 | /* Glibc's sysdeps/i386/elf/start.S has the following gem of a |
| 2683 | comment, which explains how the stack looks right at process start |
| 2684 | (when _start is jumped to). Hence _start passes %esp to |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2685 | _start_in_C_linux, which extracts argc/argv/envp and starts up |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2686 | correctly. */ |
| 2687 | |
| 2688 | /* This is the canonical entry point, usually the first thing in the text |
| 2689 | segment. The SVR4/i386 ABI (pages 3-31, 3-32) says that when the entry |
| 2690 | point runs, most registers' values are unspecified, except for: |
| 2691 | |
| 2692 | %edx Contains a function pointer to be registered with `atexit'. |
| 2693 | This is how the dynamic linker arranges to have DT_FINI |
| 2694 | functions called for shared libraries that have been loaded |
| 2695 | before this code runs. |
| 2696 | |
| 2697 | %esp The stack contains the arguments and environment: |
| 2698 | 0(%esp) argc |
| 2699 | 4(%esp) argv[0] |
| 2700 | ... |
| 2701 | (4*argc)(%esp) NULL |
| 2702 | (4*(argc+1))(%esp) envp[0] |
| 2703 | ... |
| 2704 | NULL |
| 2705 | */ |
| 2706 | |
| 2707 | /* The kernel hands control to _start, which extracts the initial |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2708 | stack pointer and calls onwards to _start_in_C_linux. This also switches |
sewardj | a48a493 | 2005-09-29 11:09:56 +0000 | [diff] [blame] | 2709 | the new stack. */ |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2710 | #if defined(VGP_x86_linux) |
| 2711 | asm("\n" |
sewardj | d9fc382 | 2005-11-18 23:50:43 +0000 | [diff] [blame] | 2712 | ".text\n" |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2713 | "\t.globl _start\n" |
| 2714 | "\t.type _start,@function\n" |
| 2715 | "_start:\n" |
| 2716 | /* set up the new stack in %eax */ |
sewardj | fdf91b4 | 2005-09-28 00:53:09 +0000 | [diff] [blame] | 2717 | "\tmovl $vgPlain_interim_stack, %eax\n" |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2718 | "\taddl $"VG_STRINGIFY(VG_STACK_GUARD_SZB)", %eax\n" |
| 2719 | "\taddl $"VG_STRINGIFY(VG_STACK_ACTIVE_SZB)", %eax\n" |
| 2720 | "\tsubl $16, %eax\n" |
| 2721 | "\tandl $~15, %eax\n" |
| 2722 | /* install it, and collect the original one */ |
| 2723 | "\txchgl %eax, %esp\n" |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2724 | /* call _start_in_C_linux, passing it the startup %esp */ |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2725 | "\tpushl %eax\n" |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2726 | "\tcall _start_in_C_linux\n" |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2727 | "\thlt\n" |
sewardj | 2fedc64 | 2005-11-19 02:02:57 +0000 | [diff] [blame] | 2728 | ".previous\n" |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2729 | ); |
| 2730 | #elif defined(VGP_amd64_linux) |
| 2731 | asm("\n" |
sewardj | d9fc382 | 2005-11-18 23:50:43 +0000 | [diff] [blame] | 2732 | ".text\n" |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2733 | "\t.globl _start\n" |
| 2734 | "\t.type _start,@function\n" |
| 2735 | "_start:\n" |
| 2736 | /* set up the new stack in %rdi */ |
sewardj | fdf91b4 | 2005-09-28 00:53:09 +0000 | [diff] [blame] | 2737 | "\tmovq $vgPlain_interim_stack, %rdi\n" |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2738 | "\taddq $"VG_STRINGIFY(VG_STACK_GUARD_SZB)", %rdi\n" |
| 2739 | "\taddq $"VG_STRINGIFY(VG_STACK_ACTIVE_SZB)", %rdi\n" |
| 2740 | "\tandq $~15, %rdi\n" |
| 2741 | /* install it, and collect the original one */ |
| 2742 | "\txchgq %rdi, %rsp\n" |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2743 | /* call _start_in_C_linux, passing it the startup %rsp */ |
| 2744 | "\tcall _start_in_C_linux\n" |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2745 | "\thlt\n" |
sewardj | 2fedc64 | 2005-11-19 02:02:57 +0000 | [diff] [blame] | 2746 | ".previous\n" |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2747 | ); |
sewardj | a48a493 | 2005-09-29 11:09:56 +0000 | [diff] [blame] | 2748 | #elif defined(VGP_ppc32_linux) |
| 2749 | asm("\n" |
sewardj | d9fc382 | 2005-11-18 23:50:43 +0000 | [diff] [blame] | 2750 | ".text\n" |
sewardj | a48a493 | 2005-09-29 11:09:56 +0000 | [diff] [blame] | 2751 | "\t.globl _start\n" |
| 2752 | "\t.type _start,@function\n" |
| 2753 | "_start:\n" |
| 2754 | /* set up the new stack in r16 */ |
| 2755 | "\tlis 16,vgPlain_interim_stack@ha\n" |
| 2756 | "\tla 16,vgPlain_interim_stack@l(16)\n" |
| 2757 | "\tlis 17,("VG_STRINGIFY(VG_STACK_GUARD_SZB)" >> 16)\n" |
| 2758 | "\tori 17,17,("VG_STRINGIFY(VG_STACK_GUARD_SZB)" & 0xFFFF)\n" |
| 2759 | "\tlis 18,("VG_STRINGIFY(VG_STACK_ACTIVE_SZB)" >> 16)\n" |
| 2760 | "\tori 18,18,("VG_STRINGIFY(VG_STACK_ACTIVE_SZB)" & 0xFFFF)\n" |
| 2761 | "\tadd 16,17,16\n" |
| 2762 | "\tadd 16,18,16\n" |
| 2763 | "\trlwinm 16,16,0,0,27\n" |
| 2764 | /* now r16 = &vgPlain_interim_stack + VG_STACK_GUARD_SZB + |
| 2765 | VG_STACK_ACTIVE_SZB rounded down to the nearest 16-byte |
| 2766 | boundary. And r1 is the original SP. Set the SP to r16 and |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2767 | call _start_in_C_linux, passing it the initial SP. */ |
sewardj | a48a493 | 2005-09-29 11:09:56 +0000 | [diff] [blame] | 2768 | "\tmr 3,1\n" |
| 2769 | "\tmr 1,16\n" |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2770 | "\tbl _start_in_C_linux\n" |
sewardj | a48a493 | 2005-09-29 11:09:56 +0000 | [diff] [blame] | 2771 | "\ttrap\n" |
sewardj | 2fedc64 | 2005-11-19 02:02:57 +0000 | [diff] [blame] | 2772 | ".previous\n" |
sewardj | a48a493 | 2005-09-29 11:09:56 +0000 | [diff] [blame] | 2773 | ); |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 2774 | #elif defined(VGP_ppc64_linux) |
| 2775 | asm("\n" |
cerion | 2108204 | 2005-12-06 19:07:08 +0000 | [diff] [blame] | 2776 | /* PPC64 ELF ABI says '_start' points to a function descriptor. |
| 2777 | So we must have one, and that is what goes into the .opd section. */ |
cerion | 297c88f | 2005-12-22 15:53:12 +0000 | [diff] [blame] | 2778 | "\t.align 2\n" |
cerion | 2108204 | 2005-12-06 19:07:08 +0000 | [diff] [blame] | 2779 | "\t.global _start\n" |
| 2780 | "\t.section \".opd\",\"aw\"\n" |
| 2781 | "\t.align 3\n" |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 2782 | "_start:\n" |
cerion | 2108204 | 2005-12-06 19:07:08 +0000 | [diff] [blame] | 2783 | "\t.quad ._start,.TOC.@tocbase,0\n" |
| 2784 | "\t.previous\n" |
| 2785 | "\t.type ._start,@function\n" |
| 2786 | "\t.global ._start\n" |
| 2787 | "._start:\n" |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 2788 | /* set up the new stack in r16 */ |
| 2789 | "\tlis 16, vgPlain_interim_stack@highest\n" |
| 2790 | "\tori 16,16,vgPlain_interim_stack@higher\n" |
| 2791 | "\tsldi 16,16,32\n" |
| 2792 | "\toris 16,16,vgPlain_interim_stack@h\n" |
| 2793 | "\tori 16,16,vgPlain_interim_stack@l\n" |
| 2794 | "\txor 17,17,17\n" |
| 2795 | "\tlis 17,("VG_STRINGIFY(VG_STACK_GUARD_SZB)" >> 16)\n" |
| 2796 | "\tori 17,17,("VG_STRINGIFY(VG_STACK_GUARD_SZB)" & 0xFFFF)\n" |
| 2797 | "\txor 18,18,18\n" |
| 2798 | "\tlis 18,("VG_STRINGIFY(VG_STACK_ACTIVE_SZB)" >> 16)\n" |
| 2799 | "\tori 18,18,("VG_STRINGIFY(VG_STACK_ACTIVE_SZB)" & 0xFFFF)\n" |
| 2800 | "\tadd 16,17,16\n" |
| 2801 | "\tadd 16,18,16\n" |
| 2802 | "\trldicr 16,16,0,59\n" |
| 2803 | /* now r16 = &vgPlain_interim_stack + VG_STACK_GUARD_SZB + |
| 2804 | VG_STACK_ACTIVE_SZB rounded down to the nearest 16-byte |
| 2805 | boundary. And r1 is the original SP. Set the SP to r16 and |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2806 | call _start_in_C_linux, passing it the initial SP. */ |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 2807 | "\tmr 3,1\n" |
| 2808 | "\tmr 1,16\n" |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2809 | "\tbl ._start_in_C_linux\n" |
cerion | 2108204 | 2005-12-06 19:07:08 +0000 | [diff] [blame] | 2810 | "\tnop\n" |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 2811 | "\ttrap\n" |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 2812 | ); |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 2813 | #elif defined(VGP_s390x_linux) |
| 2814 | /* |
| 2815 | This is the canonical entry point, usually the first thing in the text |
| 2816 | segment. Most registers' values are unspecified, except for: |
| 2817 | |
| 2818 | %r14 Contains a function pointer to be registered with `atexit'. |
| 2819 | This is how the dynamic linker arranges to have DT_FINI |
| 2820 | functions called for shared libraries that have been loaded |
| 2821 | before this code runs. |
| 2822 | |
| 2823 | %r15 The stack contains the arguments and environment: |
| 2824 | 0(%r15) argc |
| 2825 | 8(%r15) argv[0] |
| 2826 | ... |
| 2827 | (8*argc)(%r15) NULL |
| 2828 | (8*(argc+1))(%r15) envp[0] |
| 2829 | ... |
| 2830 | NULL |
| 2831 | */ |
| 2832 | asm("\n\t" |
| 2833 | ".text\n\t" |
| 2834 | ".globl _start\n\t" |
| 2835 | ".type _start,@function\n\t" |
| 2836 | "_start:\n\t" |
| 2837 | /* set up the new stack in %r1 */ |
| 2838 | "larl %r1, vgPlain_interim_stack\n\t" |
| 2839 | "larl %r5, 1f\n\t" |
| 2840 | "ag %r1, 0(%r5)\n\t" |
| 2841 | "ag %r1, 2f-1f(%r5)\n\t" |
| 2842 | "nill %r1, 0xFFF0\n\t" |
| 2843 | /* install it, and collect the original one */ |
| 2844 | "lgr %r2, %r15\n\t" |
| 2845 | "lgr %r15, %r1\n\t" |
| 2846 | /* call _start_in_C_linux, passing it the startup %r15 */ |
| 2847 | "brasl %r14, _start_in_C_linux\n\t" |
| 2848 | /* trigger execution of an invalid opcode -> halt machine */ |
| 2849 | "j .+2\n\t" |
| 2850 | "1: .quad "VG_STRINGIFY(VG_STACK_GUARD_SZB)"\n\t" |
| 2851 | "2: .quad "VG_STRINGIFY(VG_STACK_ACTIVE_SZB)"\n\t" |
| 2852 | ".previous\n" |
| 2853 | ); |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 2854 | #elif defined(VGP_arm_linux) |
| 2855 | asm("\n" |
sewardj | b51c926 | 2011-05-03 14:24:11 +0000 | [diff] [blame] | 2856 | "\t.text\n" |
| 2857 | "\t.align 4\n" |
| 2858 | "\t.type _start,#function\n" |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 2859 | "\t.global _start\n" |
| 2860 | "_start:\n" |
| 2861 | "\tldr r0, [pc, #36]\n" |
| 2862 | "\tldr r1, [pc, #36]\n" |
| 2863 | "\tadd r0, r1, r0\n" |
| 2864 | "\tldr r1, [pc, #32]\n" |
| 2865 | "\tadd r0, r1, r0\n" |
| 2866 | "\tmvn r1, #15\n" |
| 2867 | "\tand r0, r0, r1\n" |
| 2868 | "\tmov r1, sp\n" |
| 2869 | "\tmov sp, r0\n" |
| 2870 | "\tmov r0, r1\n" |
| 2871 | "\tb _start_in_C_linux\n" |
| 2872 | "\t.word vgPlain_interim_stack\n" |
| 2873 | "\t.word "VG_STRINGIFY(VG_STACK_GUARD_SZB)"\n" |
| 2874 | "\t.word "VG_STRINGIFY(VG_STACK_ACTIVE_SZB)"\n" |
| 2875 | ); |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2876 | #else |
njn | 49f80e8 | 2009-05-21 01:25:43 +0000 | [diff] [blame] | 2877 | # error "Unknown linux platform" |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2878 | #endif |
| 2879 | |
sewardj | e66f2e0 | 2006-12-30 17:45:08 +0000 | [diff] [blame] | 2880 | /* --- !!! --- EXTERNAL HEADERS start --- !!! --- */ |
| 2881 | #define _GNU_SOURCE |
| 2882 | #define _FILE_OFFSET_BITS 64 |
| 2883 | /* This is in order to get AT_NULL and AT_PAGESIZE. */ |
| 2884 | #include <elf.h> |
| 2885 | /* --- !!! --- EXTERNAL HEADERS end --- !!! --- */ |
| 2886 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2887 | /* Avoid compiler warnings: this fn _is_ used, but labelling it |
| 2888 | 'static' causes gcc to complain it isn't. */ |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2889 | void _start_in_C_linux ( UWord* pArgc ); |
| 2890 | void _start_in_C_linux ( UWord* pArgc ) |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2891 | { |
| 2892 | Int r; |
| 2893 | Word argc = pArgc[0]; |
| 2894 | HChar** argv = (HChar**)&pArgc[1]; |
| 2895 | HChar** envp = (HChar**)&pArgc[1+argc+1]; |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 2896 | |
| 2897 | VG_(memset)( &the_iicii, 0, sizeof(the_iicii) ); |
| 2898 | VG_(memset)( &the_iifii, 0, sizeof(the_iifii) ); |
| 2899 | |
| 2900 | the_iicii.sp_at_startup = (Addr)pArgc; |
| 2901 | |
sewardj | e66f2e0 | 2006-12-30 17:45:08 +0000 | [diff] [blame] | 2902 | # if defined(VGP_ppc32_linux) || defined(VGP_ppc64_linux) |
| 2903 | { |
| 2904 | /* ppc/ppc64 can be configured with different page sizes. |
| 2905 | Determine this early. This is an ugly hack and really should |
| 2906 | be moved into valgrind_main. */ |
| 2907 | UWord *sp = &pArgc[1+argc+1]; |
| 2908 | while (*sp++ != 0) |
| 2909 | ; |
| 2910 | for (; *sp != AT_NULL && *sp != AT_PAGESZ; sp += 2); |
| 2911 | if (*sp == AT_PAGESZ) { |
| 2912 | VKI_PAGE_SIZE = sp[1]; |
| 2913 | for (VKI_PAGE_SHIFT = 12; |
| 2914 | VKI_PAGE_SHIFT <= VKI_MAX_PAGE_SHIFT; VKI_PAGE_SHIFT++) |
| 2915 | if (VKI_PAGE_SIZE == (1UL << VKI_PAGE_SHIFT)) |
| 2916 | break; |
| 2917 | } |
| 2918 | } |
| 2919 | # endif |
| 2920 | |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 2921 | r = valgrind_main( (Int)argc, argv, envp ); |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2922 | /* NOTREACHED */ |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 2923 | VG_(exit)(r); |
| 2924 | } |
| 2925 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2926 | |
| 2927 | /*====================================================================*/ |
| 2928 | /*=== Getting to main() alive: AIX5 ===*/ |
| 2929 | /*====================================================================*/ |
| 2930 | |
njn | 49f80e8 | 2009-05-21 01:25:43 +0000 | [diff] [blame] | 2931 | #elif defined(VGO_aix5) |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2932 | |
| 2933 | /* This is somewhat simpler than the Linux case. _start_valgrind |
| 2934 | receives control from the magic piece of code created in this |
| 2935 | process' address space by the launcher, via use of ptrace(). At |
| 2936 | the point of entry: |
| 2937 | |
| 2938 | - the initial client process image is in memory and ready to roll, |
| 2939 | except that we've partially trashed its integer register state |
| 2940 | in order to get this far. So .. |
| 2941 | |
| 2942 | - intregs37 holds the client's initial integer register state, so |
| 2943 | we can restore it before starting the client on the VCPU. |
| 2944 | |
| 2945 | - we're on the client's stack. This is not good; therefore the |
| 2946 | first order of business is to switch to our temporary stack. |
| 2947 | |
| 2948 | - the client's initial argc/v/envp is in r3/r4/r5 (32 bit mode) or |
| 2949 | r14/r15/r16 (64 bit mode). They are pulled out of the stashed |
| 2950 | integer register state and passed to our main(). |
| 2951 | |
| 2952 | The launcher will have played some games with argv. If the launcher |
| 2953 | ($prefix/bin/valgrind) was started like this |
| 2954 | |
| 2955 | valgrind [args-for-V] app [args-for-app] |
| 2956 | |
| 2957 | then the launcher will have started the client as |
| 2958 | |
| 2959 | app [args-for-V] app [args-for-app] |
| 2960 | |
| 2961 | m_initimg will have to mess with the client's initial r4/r5 |
| 2962 | (32-bit) or r15/r16 (64-bit) so that it believes it was execd as |
| 2963 | "app [args-for-app]". Well, that's no big deal. |
| 2964 | */ |
| 2965 | |
| 2966 | #include "launcher-aix5-bootblock.h" |
| 2967 | |
| 2968 | void _start_in_C_aix5 ( AIX5Bootblock* bootblock ); |
| 2969 | void _start_in_C_aix5 ( AIX5Bootblock* bootblock ) |
| 2970 | { |
| 2971 | Int r; |
| 2972 | ULong* intregs37; |
| 2973 | UWord argc, argv, envp; |
| 2974 | __NR_getpid = bootblock->__NR_getpid; |
| 2975 | __NR_write = bootblock->__NR_write; |
| 2976 | __NR_exit = bootblock->__NR_exit; |
| 2977 | __NR_open = bootblock->__NR_open; |
| 2978 | __NR_read = bootblock->__NR_read; |
| 2979 | __NR_close = bootblock->__NR_close; |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 2980 | |
| 2981 | VG_(memset)( &the_iicii, 0, sizeof(the_iicii) ); |
| 2982 | VG_(memset)( &the_iifii, 0, sizeof(the_iifii) ); |
| 2983 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2984 | intregs37 = &bootblock->iregs_pc_cr_lr_ctr_xer[0]; |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 2985 | the_iicii.intregs37 = intregs37; |
| 2986 | the_iicii.bootblock = (void*)bootblock; |
| 2987 | the_iicii.adler32_exp = bootblock->adler32; |
| 2988 | |
| 2989 | /* Not important on AIX. */ |
| 2990 | the_iicii.sp_at_startup = (Addr)0x31415927ULL; |
| 2991 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 2992 | # if defined(VGP_ppc32_aix5) |
| 2993 | argc = (UWord)intregs37[3]; /* client's r3 == argc */ |
| 2994 | argv = (UWord)intregs37[4]; |
| 2995 | envp = (UWord)intregs37[5]; |
| 2996 | # else /* defined(VGP_ppc64_aix5) */ |
| 2997 | argc = (UWord)intregs37[14]; /* client's r14 == argc */ |
| 2998 | argv = (UWord)intregs37[15]; |
| 2999 | envp = (UWord)intregs37[16]; |
| 3000 | # endif |
sewardj | f9d2f9b | 2006-11-17 20:00:57 +0000 | [diff] [blame] | 3001 | |
| 3002 | r = valgrind_main( (Int)argc, (HChar**)argv, (HChar**)envp ); |
| 3003 | |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 3004 | /* NOTREACHED */ |
| 3005 | VG_(exit)(r); |
| 3006 | } |
| 3007 | |
| 3008 | /* THE ENTRY POINT */ |
| 3009 | void _start_valgrind ( AIX5Bootblock* bootblock ); |
| 3010 | void _start_valgrind ( AIX5Bootblock* bootblock ) |
| 3011 | { |
| 3012 | /* Switch immediately to our temporary stack, and continue. This |
| 3013 | is pretty dodgy in that it assumes that gcc does not place on |
| 3014 | the stack, anything needed to form the _start_in_C_aix5 call, |
| 3015 | since it will be on the old stack. */ |
| 3016 | register UWord new_r1; |
| 3017 | new_r1 = (UWord)&VG_(interim_stack); |
| 3018 | new_r1 += VG_STACK_GUARD_SZB; /* step over lower guard page */ |
| 3019 | new_r1 += VG_STACK_ACTIVE_SZB; /* step to top of active area */ |
| 3020 | new_r1 -= 512; /* paranoia */ |
| 3021 | __asm__ __volatile__("mr 1,%0" :/*wr*/ |
| 3022 | :/*rd*/ "b"(new_r1) |
| 3023 | :/*trash*/"r1","memory"); |
| 3024 | _start_in_C_aix5(bootblock); |
| 3025 | /*NOTREACHED*/ |
| 3026 | VG_(exit)(0); |
| 3027 | } |
| 3028 | |
sewardj | 61a1b05 | 2008-10-22 00:56:53 +0000 | [diff] [blame] | 3029 | /* At some point in Oct 2008, static linking appeared to stop working |
| 3030 | on AIX 5.3. This breaks the build since we link statically. The |
| 3031 | linking fails citing absence of the following five symbols as the |
| 3032 | reason. In the absence of a better solution, here are stand-ins |
| 3033 | for them. Kludge appears to work; presumably said functions, |
| 3034 | assuming they are indeed functions, are never called. */ |
| 3035 | void encrypted_pw_passlen ( void ) { vg_assert(0); } |
| 3036 | void crypt_r ( void ) { vg_assert(0); } |
| 3037 | void max_history_size ( void ) { vg_assert(0); } |
| 3038 | void getpass_auto ( void ) { vg_assert(0); } |
| 3039 | void max_pw_passlen ( void ) { vg_assert(0); } |
| 3040 | |
njn | 49f80e8 | 2009-05-21 01:25:43 +0000 | [diff] [blame] | 3041 | |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 3042 | /*====================================================================*/ |
| 3043 | /*=== Getting to main() alive: darwin ===*/ |
| 3044 | /*====================================================================*/ |
| 3045 | |
| 3046 | #elif defined(VGO_darwin) |
| 3047 | |
njn | ea2d6fd | 2010-07-01 00:20:20 +0000 | [diff] [blame] | 3048 | /* |
| 3049 | Memory layout established by kernel: |
| 3050 | |
| 3051 | 0(%esp) argc |
| 3052 | 4(%esp) argv[0] |
| 3053 | ... |
| 3054 | argv[argc-1] |
| 3055 | NULL |
| 3056 | envp[0] |
| 3057 | ... |
| 3058 | envp[n] |
| 3059 | NULL |
| 3060 | executable name (presumably, a pointer to it) |
| 3061 | NULL |
| 3062 | |
| 3063 | Ditto in the 64-bit case, except all offsets from SP are obviously |
| 3064 | twice as large. |
| 3065 | */ |
| 3066 | |
| 3067 | /* The kernel hands control to _start, which extracts the initial |
| 3068 | stack pointer and calls onwards to _start_in_C_darwin. This also |
| 3069 | switches to the new stack. */ |
| 3070 | #if defined(VGP_x86_darwin) |
| 3071 | asm("\n" |
| 3072 | ".text\n" |
| 3073 | ".align 2,0x90\n" |
| 3074 | "\t.globl __start\n" |
| 3075 | "__start:\n" |
| 3076 | /* set up the new stack in %eax */ |
| 3077 | "\tmovl $_vgPlain_interim_stack, %eax\n" |
| 3078 | "\taddl $"VG_STRINGIFY(VG_STACK_GUARD_SZB)", %eax\n" |
| 3079 | "\taddl $"VG_STRINGIFY(VG_STACK_ACTIVE_SZB)", %eax\n" |
| 3080 | "\tsubl $16, %eax\n" |
| 3081 | "\tandl $~15, %eax\n" |
| 3082 | /* install it, and collect the original one */ |
| 3083 | "\txchgl %eax, %esp\n" |
| 3084 | /* call _start_in_C_darwin, passing it the startup %esp */ |
| 3085 | "\tpushl %eax\n" |
| 3086 | "\tcall __start_in_C_darwin\n" |
| 3087 | "\tint $3\n" |
| 3088 | "\tint $3\n" |
| 3089 | ); |
| 3090 | #elif defined(VGP_amd64_darwin) |
| 3091 | asm("\n" |
| 3092 | ".text\n" |
| 3093 | "\t.globl __start\n" |
| 3094 | ".align 3,0x90\n" |
| 3095 | "__start:\n" |
| 3096 | /* set up the new stack in %rdi */ |
| 3097 | "\tmovabsq $_vgPlain_interim_stack, %rdi\n" |
| 3098 | "\taddq $"VG_STRINGIFY(VG_STACK_GUARD_SZB)", %rdi\n" |
| 3099 | "\taddq $"VG_STRINGIFY(VG_STACK_ACTIVE_SZB)", %rdi\n" |
| 3100 | "\tandq $~15, %rdi\n" |
| 3101 | /* install it, and collect the original one */ |
| 3102 | "\txchgq %rdi, %rsp\n" |
| 3103 | /* call _start_in_C_darwin, passing it the startup %rsp */ |
| 3104 | "\tcall __start_in_C_darwin\n" |
| 3105 | "\tint $3\n" |
| 3106 | "\tint $3\n" |
| 3107 | ); |
| 3108 | #endif |
| 3109 | |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 3110 | void* __memcpy_chk(void *dest, const void *src, SizeT n, SizeT n2); |
| 3111 | void* __memcpy_chk(void *dest, const void *src, SizeT n, SizeT n2) { |
| 3112 | // skip check |
| 3113 | return VG_(memcpy)(dest,src,n); |
| 3114 | } |
| 3115 | void* __memset_chk(void *s, int c, SizeT n, SizeT n2); |
| 3116 | void* __memset_chk(void *s, int c, SizeT n, SizeT n2) { |
| 3117 | // skip check |
| 3118 | return VG_(memset)(s,c,n); |
| 3119 | } |
| 3120 | void bzero(void *s, SizeT n); |
| 3121 | void bzero(void *s, SizeT n) { |
| 3122 | VG_(memset)(s,0,n); |
| 3123 | } |
| 3124 | |
| 3125 | void* memcpy(void *dest, const void *src, SizeT n); |
| 3126 | void* memcpy(void *dest, const void *src, SizeT n) { |
| 3127 | return VG_(memcpy)(dest,src,n); |
| 3128 | } |
| 3129 | void* memset(void *s, int c, SizeT n); |
| 3130 | void* memset(void *s, int c, SizeT n) { |
| 3131 | return VG_(memset)(s,c,n); |
| 3132 | } |
| 3133 | |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 3134 | /* Avoid compiler warnings: this fn _is_ used, but labelling it |
| 3135 | 'static' causes gcc to complain it isn't. */ |
| 3136 | void _start_in_C_darwin ( UWord* pArgc ); |
| 3137 | void _start_in_C_darwin ( UWord* pArgc ) |
| 3138 | { |
| 3139 | Int r; |
njn | ea2d6fd | 2010-07-01 00:20:20 +0000 | [diff] [blame] | 3140 | Int argc = *(Int *)pArgc; // not pArgc[0] on LP64 |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 3141 | HChar** argv = (HChar**)&pArgc[1]; |
| 3142 | HChar** envp = (HChar**)&pArgc[1+argc+1]; |
| 3143 | |
| 3144 | VG_(memset)( &the_iicii, 0, sizeof(the_iicii) ); |
| 3145 | VG_(memset)( &the_iifii, 0, sizeof(the_iifii) ); |
| 3146 | |
| 3147 | the_iicii.sp_at_startup = (Addr)pArgc; |
| 3148 | |
| 3149 | r = valgrind_main( (Int)argc, argv, envp ); |
| 3150 | /* NOTREACHED */ |
| 3151 | VG_(exit)(r); |
| 3152 | } |
| 3153 | |
| 3154 | |
njn | 49f80e8 | 2009-05-21 01:25:43 +0000 | [diff] [blame] | 3155 | #else |
| 3156 | |
| 3157 | # error "Unknown OS" |
| 3158 | #endif |
sewardj | 17c1104 | 2006-10-15 01:26:40 +0000 | [diff] [blame] | 3159 | |
| 3160 | |
sewardj | 0af71bb | 2010-07-01 14:50:30 +0000 | [diff] [blame] | 3161 | /*====================================================================*/ |
| 3162 | /*=== {u,}{div,mod}di3 replacements ===*/ |
| 3163 | /*====================================================================*/ |
njn | ea2d6fd | 2010-07-01 00:20:20 +0000 | [diff] [blame] | 3164 | |
| 3165 | /* For static linking on x86-darwin, we need to supply our own 64-bit |
| 3166 | integer division code, else the link dies thusly: |
| 3167 | |
| 3168 | ld_classic: Undefined symbols: |
| 3169 | ___udivdi3 |
| 3170 | ___umoddi3 |
| 3171 | */ |
| 3172 | #if defined(VGP_x86_darwin) |
| 3173 | |
| 3174 | /* Routines for doing signed/unsigned 64 x 64 ==> 64 div and mod |
| 3175 | (udivdi3, umoddi3, divdi3, moddi3) using only 32 x 32 ==> 32 |
| 3176 | division. Cobbled together from |
| 3177 | |
| 3178 | http://www.hackersdelight.org/HDcode/divlu.c |
| 3179 | http://www.hackersdelight.org/HDcode/divls.c |
| 3180 | http://www.hackersdelight.org/HDcode/newCode/divDouble.c |
| 3181 | |
| 3182 | The code from those three files is covered by the following license, |
| 3183 | as it appears at: |
| 3184 | |
| 3185 | http://www.hackersdelight.org/permissions.htm |
| 3186 | |
| 3187 | You are free to use, copy, and distribute any of the code on |
| 3188 | this web site, whether modified by you or not. You need not give |
| 3189 | attribution. This includes the algorithms (some of which appear |
| 3190 | in Hacker's Delight), the Hacker's Assistant, and any code |
| 3191 | submitted by readers. Submitters implicitly agree to this. |
| 3192 | */ |
| 3193 | |
| 3194 | /* Long division, unsigned (64/32 ==> 32). |
| 3195 | This procedure performs unsigned "long division" i.e., division of a |
| 3196 | 64-bit unsigned dividend by a 32-bit unsigned divisor, producing a |
| 3197 | 32-bit quotient. In the overflow cases (divide by 0, or quotient |
| 3198 | exceeds 32 bits), it returns a remainder of 0xFFFFFFFF (an impossible |
| 3199 | value). |
| 3200 | The dividend is u1 and u0, with u1 being the most significant word. |
| 3201 | The divisor is parameter v. The value returned is the quotient. |
| 3202 | Max line length is 57, to fit in hacker.book. */ |
| 3203 | |
| 3204 | static Int nlz32(UInt x) |
| 3205 | { |
| 3206 | Int n; |
| 3207 | if (x == 0) return(32); |
| 3208 | n = 0; |
| 3209 | if (x <= 0x0000FFFF) {n = n +16; x = x <<16;} |
| 3210 | if (x <= 0x00FFFFFF) {n = n + 8; x = x << 8;} |
| 3211 | if (x <= 0x0FFFFFFF) {n = n + 4; x = x << 4;} |
| 3212 | if (x <= 0x3FFFFFFF) {n = n + 2; x = x << 2;} |
| 3213 | if (x <= 0x7FFFFFFF) {n = n + 1;} |
| 3214 | return n; |
| 3215 | } |
| 3216 | |
| 3217 | /* 64 x 32 ==> 32 unsigned division, using only 32 x 32 ==> 32 |
| 3218 | division as a primitive. */ |
| 3219 | static UInt divlu2(UInt u1, UInt u0, UInt v, UInt *r) |
| 3220 | { |
| 3221 | const UInt b = 65536; // Number base (16 bits). |
| 3222 | UInt un1, un0, // Norm. dividend LSD's. |
| 3223 | vn1, vn0, // Norm. divisor digits. |
| 3224 | q1, q0, // Quotient digits. |
| 3225 | un32, un21, un10, // Dividend digit pairs. |
| 3226 | rhat; // A remainder. |
| 3227 | Int s; // Shift amount for norm. |
| 3228 | |
| 3229 | if (u1 >= v) { // If overflow, set rem. |
| 3230 | if (r != NULL) // to an impossible value, |
| 3231 | *r = 0xFFFFFFFF; // and return the largest |
| 3232 | return 0xFFFFFFFF;} // possible quotient. |
| 3233 | |
| 3234 | s = nlz32(v); // 0 <= s <= 31. |
| 3235 | v = v << s; // Normalize divisor. |
| 3236 | vn1 = v >> 16; // Break divisor up into |
| 3237 | vn0 = v & 0xFFFF; // two 16-bit digits. |
| 3238 | |
| 3239 | un32 = (u1 << s) | ((u0 >> (32 - s)) & (-s >> 31)); |
| 3240 | un10 = u0 << s; // Shift dividend left. |
| 3241 | |
| 3242 | un1 = un10 >> 16; // Break right half of |
| 3243 | un0 = un10 & 0xFFFF; // dividend into two digits. |
| 3244 | |
| 3245 | q1 = un32/vn1; // Compute the first |
| 3246 | rhat = un32 - q1*vn1; // quotient digit, q1. |
| 3247 | again1: |
| 3248 | if (q1 >= b || q1*vn0 > b*rhat + un1) { |
| 3249 | q1 = q1 - 1; |
| 3250 | rhat = rhat + vn1; |
| 3251 | if (rhat < b) goto again1;} |
| 3252 | |
| 3253 | un21 = un32*b + un1 - q1*v; // Multiply and subtract. |
| 3254 | |
| 3255 | q0 = un21/vn1; // Compute the second |
| 3256 | rhat = un21 - q0*vn1; // quotient digit, q0. |
| 3257 | again2: |
| 3258 | if (q0 >= b || q0*vn0 > b*rhat + un0) { |
| 3259 | q0 = q0 - 1; |
| 3260 | rhat = rhat + vn1; |
| 3261 | if (rhat < b) goto again2;} |
| 3262 | |
| 3263 | if (r != NULL) // If remainder is wanted, |
| 3264 | *r = (un21*b + un0 - q0*v) >> s; // return it. |
| 3265 | return q1*b + q0; |
| 3266 | } |
| 3267 | |
| 3268 | |
| 3269 | /* 64 x 32 ==> 32 signed division, using only 32 x 32 ==> 32 division |
| 3270 | as a primitive. */ |
| 3271 | static Int divls(Int u1, UInt u0, Int v, Int *r) |
| 3272 | { |
| 3273 | Int q, uneg, vneg, diff, borrow; |
| 3274 | |
| 3275 | uneg = u1 >> 31; // -1 if u < 0. |
| 3276 | if (uneg) { // Compute the absolute |
| 3277 | u0 = -u0; // value of the dividend u. |
| 3278 | borrow = (u0 != 0); |
| 3279 | u1 = -u1 - borrow;} |
| 3280 | |
| 3281 | vneg = v >> 31; // -1 if v < 0. |
| 3282 | v = (v ^ vneg) - vneg; // Absolute value of v. |
| 3283 | |
| 3284 | if ((UInt)u1 >= (UInt)v) goto overflow; |
| 3285 | |
| 3286 | q = divlu2(u1, u0, v, (UInt *)r); |
| 3287 | |
| 3288 | diff = uneg ^ vneg; // Negate q if signs of |
| 3289 | q = (q ^ diff) - diff; // u and v differed. |
| 3290 | if (uneg && r != NULL) |
| 3291 | *r = -*r; |
| 3292 | |
| 3293 | if ((diff ^ q) < 0 && q != 0) { // If overflow, |
| 3294 | overflow: // set remainder |
| 3295 | if (r != NULL) // to an impossible value, |
| 3296 | *r = 0x80000000; // and return the largest |
| 3297 | q = 0x80000000;} // possible neg. quotient. |
| 3298 | return q; |
| 3299 | } |
| 3300 | |
| 3301 | |
| 3302 | |
| 3303 | /* This file contains a program for doing 64/64 ==> 64 division, on a |
| 3304 | machine that does not have that instruction but that does have |
| 3305 | instructions for "long division" (64/32 ==> 32). Code for unsigned |
| 3306 | division is given first, followed by a simple program for doing the |
| 3307 | signed version by using the unsigned version. |
| 3308 | These programs are useful in implementing "long long" (64-bit) |
| 3309 | arithmetic on a machine that has the long division instruction. It will |
| 3310 | work on 64- and 32-bit machines, provided the compiler implements long |
| 3311 | long's (64-bit integers). It is desirable that the machine have the |
| 3312 | Count Leading Zeros instruction. |
| 3313 | In the GNU world, these programs are known as __divdi3 and __udivdi3, |
| 3314 | and similar names are used here. |
| 3315 | This material is not in HD, but may be in a future edition. |
| 3316 | Max line length is 57, to fit in hacker.book. */ |
| 3317 | |
| 3318 | |
| 3319 | static Int nlz64(ULong x) |
| 3320 | { |
| 3321 | Int n; |
| 3322 | if (x == 0) return(64); |
| 3323 | n = 0; |
| 3324 | if (x <= 0x00000000FFFFFFFFULL) {n = n + 32; x = x << 32;} |
| 3325 | if (x <= 0x0000FFFFFFFFFFFFULL) {n = n + 16; x = x << 16;} |
| 3326 | if (x <= 0x00FFFFFFFFFFFFFFULL) {n = n + 8; x = x << 8;} |
| 3327 | if (x <= 0x0FFFFFFFFFFFFFFFULL) {n = n + 4; x = x << 4;} |
| 3328 | if (x <= 0x3FFFFFFFFFFFFFFFULL) {n = n + 2; x = x << 2;} |
| 3329 | if (x <= 0x7FFFFFFFFFFFFFFFULL) {n = n + 1;} |
| 3330 | return n; |
| 3331 | } |
| 3332 | |
| 3333 | // ---------------------------- udivdi3 -------------------------------- |
| 3334 | |
| 3335 | /* The variables u0, u1, etc. take on only 32-bit values, but they |
| 3336 | are declared long long to avoid some compiler warning messages and to |
| 3337 | avoid some unnecessary EXTRs that the compiler would put in, to |
| 3338 | convert long longs to ints. |
| 3339 | |
| 3340 | First the procedure takes care of the case in which the divisor is a |
| 3341 | 32-bit quantity. There are two subcases: (1) If the left half of the |
| 3342 | dividend is less than the divisor, one execution of DIVU is all that |
| 3343 | is required (overflow is not possible). (2) Otherwise it does two |
| 3344 | divisions, using the grade school method, with variables used as |
| 3345 | suggested below. |
| 3346 | |
| 3347 | q1 q0 |
| 3348 | ________ |
| 3349 | v) u1 u0 |
| 3350 | q1*v |
| 3351 | ____ |
| 3352 | k u0 */ |
| 3353 | |
| 3354 | /* These macros must be used with arguments of the appropriate type |
| 3355 | (unsigned long long for DIVU and long long for DIVS. They are |
| 3356 | simulations of the presumed machines ops. I.e., they look at only the |
| 3357 | low-order 32 bits of the divisor, they return garbage if the division |
| 3358 | overflows, and they return garbage in the high-order half of the |
| 3359 | quotient doubleword. |
| 3360 | In practice, these would be replaced with uses of the machine's DIVU |
| 3361 | and DIVS instructions (e.g., by using the GNU "asm" facility). */ |
| 3362 | |
| 3363 | static UInt DIVU ( ULong u, UInt v ) |
| 3364 | { |
| 3365 | UInt uHi = (UInt)(u >> 32); |
| 3366 | UInt uLo = (UInt)u; |
| 3367 | return divlu2(uHi, uLo, v, NULL); |
| 3368 | } |
| 3369 | |
| 3370 | static Int DIVS ( Long u, Int v ) |
| 3371 | { |
| 3372 | Int uHi = (Int)(u >> 32); |
| 3373 | UInt uLo = (UInt)u; |
| 3374 | return divls(uHi, uLo, v, NULL); |
| 3375 | } |
| 3376 | |
| 3377 | /* 64 x 64 ==> 64 unsigned division, using only 32 x 32 ==> 32 |
| 3378 | division as a primitive. */ |
| 3379 | static ULong udivdi3(ULong u, ULong v) |
| 3380 | { |
| 3381 | ULong u0, u1, v1, q0, q1, k, n; |
| 3382 | |
| 3383 | if (v >> 32 == 0) { // If v < 2**32: |
| 3384 | if (u >> 32 < v) // If u/v cannot overflow, |
| 3385 | return DIVU(u, v) // just do one division. |
| 3386 | & 0xFFFFFFFF; |
| 3387 | else { // If u/v would overflow: |
| 3388 | u1 = u >> 32; // Break u up into two |
| 3389 | u0 = u & 0xFFFFFFFF; // halves. |
| 3390 | q1 = DIVU(u1, v) // First quotient digit. |
| 3391 | & 0xFFFFFFFF; |
| 3392 | k = u1 - q1*v; // First remainder, < v. |
| 3393 | q0 = DIVU((k << 32) + u0, v) // 2nd quot. digit. |
| 3394 | & 0xFFFFFFFF; |
| 3395 | return (q1 << 32) + q0; |
| 3396 | } |
| 3397 | } |
| 3398 | // Here v >= 2**32. |
| 3399 | n = nlz64(v); // 0 <= n <= 31. |
| 3400 | v1 = (v << n) >> 32; // Normalize the divisor |
| 3401 | // so its MSB is 1. |
| 3402 | u1 = u >> 1; // To ensure no overflow. |
| 3403 | q1 = DIVU(u1, v1) // Get quotient from |
| 3404 | & 0xFFFFFFFF; // divide unsigned insn. |
| 3405 | q0 = (q1 << n) >> 31; // Undo normalization and |
| 3406 | // division of u by 2. |
| 3407 | if (q0 != 0) // Make q0 correct or |
| 3408 | q0 = q0 - 1; // too small by 1. |
| 3409 | if ((u - q0*v) >= v) |
| 3410 | q0 = q0 + 1; // Now q0 is correct. |
| 3411 | return q0; |
| 3412 | } |
| 3413 | |
| 3414 | |
| 3415 | // ----------------------------- divdi3 -------------------------------- |
| 3416 | |
| 3417 | /* This routine presumes that smallish cases (those which can be done in |
| 3418 | one execution of DIVS) are common. If this is not the case, the test for |
| 3419 | this case should be deleted. |
| 3420 | Note that the test for when DIVS can be used is not entirely |
| 3421 | accurate. For example, DIVS is not used if v = 0xFFFFFFFF8000000, |
| 3422 | whereas if could be (if u is sufficiently small in magnitude). */ |
| 3423 | |
| 3424 | // ------------------------------ cut ---------------------------------- |
| 3425 | |
| 3426 | static ULong my_llabs ( Long x ) |
| 3427 | { |
| 3428 | ULong t = x >> 63; |
| 3429 | return (x ^ t) - t; |
| 3430 | } |
| 3431 | |
| 3432 | /* 64 x 64 ==> 64 signed division, using only 32 x 32 ==> 32 division |
| 3433 | as a primitive. */ |
| 3434 | static Long divdi3(Long u, Long v) |
| 3435 | { |
| 3436 | ULong au, av; |
| 3437 | Long q, t; |
| 3438 | au = my_llabs(u); |
| 3439 | av = my_llabs(v); |
| 3440 | if (av >> 31 == 0) { // If |v| < 2**31 and |
| 3441 | // if (v << 32 >> 32 == v) { // If v is in range and |
| 3442 | if (au < av << 31) { // |u|/|v| cannot |
| 3443 | q = DIVS(u, v); // overflow, use DIVS. |
| 3444 | return (q << 32) >> 32; |
| 3445 | } |
| 3446 | } |
| 3447 | q = udivdi3(au,av); // Invoke udivdi3. |
| 3448 | t = (u ^ v) >> 63; // If u, v have different |
| 3449 | return (q ^ t) - t; // signs, negate q. |
| 3450 | } |
| 3451 | |
| 3452 | // ---------------------------- end cut -------------------------------- |
| 3453 | |
sewardj | 0af71bb | 2010-07-01 14:50:30 +0000 | [diff] [blame] | 3454 | ULong __udivdi3 (ULong u, ULong v); |
njn | ea2d6fd | 2010-07-01 00:20:20 +0000 | [diff] [blame] | 3455 | ULong __udivdi3 (ULong u, ULong v) |
| 3456 | { |
| 3457 | return udivdi3(u,v); |
| 3458 | } |
| 3459 | |
sewardj | 0af71bb | 2010-07-01 14:50:30 +0000 | [diff] [blame] | 3460 | Long __divdi3 (Long u, Long v); |
njn | ea2d6fd | 2010-07-01 00:20:20 +0000 | [diff] [blame] | 3461 | Long __divdi3 (Long u, Long v) |
| 3462 | { |
| 3463 | return divdi3(u,v); |
| 3464 | } |
| 3465 | |
sewardj | 0af71bb | 2010-07-01 14:50:30 +0000 | [diff] [blame] | 3466 | ULong __umoddi3 (ULong u, ULong v); |
njn | ea2d6fd | 2010-07-01 00:20:20 +0000 | [diff] [blame] | 3467 | ULong __umoddi3 (ULong u, ULong v) |
| 3468 | { |
| 3469 | ULong q = __udivdi3(u, v); |
| 3470 | ULong r = u - q * v; |
| 3471 | return r; |
| 3472 | } |
| 3473 | |
sewardj | 0af71bb | 2010-07-01 14:50:30 +0000 | [diff] [blame] | 3474 | Long __moddi3 (Long u, Long v); |
njn | ea2d6fd | 2010-07-01 00:20:20 +0000 | [diff] [blame] | 3475 | Long __moddi3 (Long u, Long v) |
| 3476 | { |
| 3477 | Long q = __divdi3(u, v); |
| 3478 | Long r = u - q * v; |
| 3479 | return r; |
| 3480 | } |
| 3481 | |
| 3482 | #endif |
| 3483 | |
| 3484 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 3485 | /*--------------------------------------------------------------------*/ |
njn | 04e1698 | 2005-05-31 00:23:43 +0000 | [diff] [blame] | 3486 | /*--- end ---*/ |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 3487 | /*--------------------------------------------------------------------*/ |