njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Command line options. pub_tool_options.h ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
njn | 9f20746 | 2009-03-10 22:02:09 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2009 Julian Seward |
njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 11 | jseward@acm.org |
| 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 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __PUB_TOOL_OPTIONS_H |
| 32 | #define __PUB_TOOL_OPTIONS_H |
| 33 | |
sewardj | f9b5b7d | 2005-07-26 23:47:00 +0000 | [diff] [blame] | 34 | #include "libvex.h" // for VexControl |
| 35 | |
| 36 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 37 | // Higher-level command-line option recognisers; use in if/else chains. |
| 38 | // Note that they assign a value to the 'qq_var' argument. So often they |
| 39 | // can be used like this: |
| 40 | // |
| 41 | // if VG_STR_CLO(arg, "--foo", clo_foo) { } |
| 42 | // |
| 43 | // But if you want to do further checking or processing, you can do this: |
| 44 | // |
| 45 | // if VG_STR_CLO(arg, "--foo", clo_foo) { <further checking or processing> } |
| 46 | // |
| 47 | // They use GNU statement expressions to do the qq_var assignment within a |
| 48 | // conditional expression. |
njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 49 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 50 | // String argument, eg. --foo=yes or --foo=no |
njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 51 | #define VG_BOOL_CLO(qq_arg, qq_option, qq_var) \ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 52 | (VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=") && \ |
| 53 | ({ \ |
| 54 | Char* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ]; \ |
| 55 | if VG_STREQ(val, "yes") (qq_var) = True; \ |
| 56 | else if VG_STREQ(val, "no") (qq_var) = False; \ |
| 57 | True; \ |
| 58 | }) \ |
| 59 | ) |
njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 60 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 61 | // String argument, eg. --foo=bar |
njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 62 | #define VG_STR_CLO(qq_arg, qq_option, qq_var) \ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 63 | (VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=") && \ |
| 64 | ({ \ |
| 65 | Char* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ]; \ |
| 66 | (qq_var) = val; \ |
| 67 | True; \ |
| 68 | }) \ |
| 69 | ) |
njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 70 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 71 | // Unbounded integer arg, eg. --foo=10 |
| 72 | #define VG_INT_CLO(qq_arg, qq_option, qq_var) \ |
| 73 | (VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=") && \ |
| 74 | ({ \ |
| 75 | Char* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ]; \ |
njn | ea5d235 | 2007-11-11 21:58:21 +0000 | [diff] [blame] | 76 | Char* s; \ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 77 | Long n = VG_(strtoll10)( val, &s ); \ |
njn | ea5d235 | 2007-11-11 21:58:21 +0000 | [diff] [blame] | 78 | (qq_var) = n; \ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 79 | /* Check for non-numeralness, or overflow. */ \ |
njn | e4faf5d | 2007-11-26 02:55:12 +0000 | [diff] [blame] | 80 | if ('\0' != s[0] || (qq_var) != n) VG_(err_bad_option)(qq_arg); \ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 81 | True; \ |
| 82 | }) \ |
| 83 | ) |
njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 84 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 85 | // Bounded integer arg, eg. --foo=10 ; if the value exceeds the bounds it |
| 86 | // causes an abort. 'qq_base' can be 10 or 16. |
| 87 | #define VG_BINTN_CLO(qq_base, qq_arg, qq_option, qq_var, qq_lo, qq_hi) \ |
| 88 | (VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=") && \ |
| 89 | ({ \ |
| 90 | Char* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ]; \ |
njn | 62721e9 | 2007-11-11 22:15:58 +0000 | [diff] [blame] | 91 | Char* s; \ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 92 | Long n = VG_(strtoll##qq_base)( val, &s ); \ |
njn | 62721e9 | 2007-11-11 22:15:58 +0000 | [diff] [blame] | 93 | (qq_var) = n; \ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 94 | /* Check for non-numeralness, or overflow. */ \ |
| 95 | /* Nb: it will overflow if qq_var is unsigned and qq_val is negative! */ \ |
njn | e4faf5d | 2007-11-26 02:55:12 +0000 | [diff] [blame] | 96 | if ('\0' != s[0] || (qq_var) != n) VG_(err_bad_option)(qq_arg); \ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 97 | /* Check bounds. */ \ |
| 98 | if ((qq_var) < (qq_lo) || (qq_var) > (qq_hi)) { \ |
| 99 | VG_(message)(Vg_UserMsg, \ |
sewardj | 5d9dc75 | 2009-07-15 14:52:18 +0000 | [diff] [blame] | 100 | "'%s' argument must be between %lld and %lld\n", \ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 101 | (qq_option), (Long)(qq_lo), (Long)(qq_hi)); \ |
| 102 | VG_(err_bad_option)(qq_arg); \ |
| 103 | } \ |
| 104 | True; \ |
| 105 | }) \ |
| 106 | ) |
njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 107 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 108 | // Bounded decimal integer arg, eg. --foo=100 |
| 109 | #define VG_BINT_CLO(qq_arg, qq_option, qq_var, qq_lo, qq_hi) \ |
| 110 | VG_BINTN_CLO(10, (qq_arg), qq_option, (qq_var), (qq_lo), (qq_hi)) |
| 111 | |
| 112 | // Bounded hexadecimal integer arg, eg. --foo=0x1fa8 |
sewardj | eb0fa93 | 2007-11-30 21:41:40 +0000 | [diff] [blame] | 113 | #define VG_BHEX_CLO(qq_arg, qq_option, qq_var, qq_lo, qq_hi) \ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 114 | VG_BINTN_CLO(16, (qq_arg), qq_option, (qq_var), (qq_lo), (qq_hi)) |
sewardj | eb0fa93 | 2007-11-30 21:41:40 +0000 | [diff] [blame] | 115 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 116 | // Double (decimal) arg, eg. --foo=4.6 |
| 117 | // XXX: there's not VG_BDBL_CLO because we don't have a good way of printing |
| 118 | // floats at the moment! |
njn | 62721e9 | 2007-11-11 22:15:58 +0000 | [diff] [blame] | 119 | #define VG_DBL_CLO(qq_arg, qq_option, qq_var) \ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 120 | (VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=") && \ |
| 121 | ({ \ |
| 122 | Char* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ]; \ |
njn | 62721e9 | 2007-11-11 22:15:58 +0000 | [diff] [blame] | 123 | Char* s; \ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 124 | double n = VG_(strtod)( val, &s ); \ |
njn | 62721e9 | 2007-11-11 22:15:58 +0000 | [diff] [blame] | 125 | (qq_var) = n; \ |
| 126 | /* Check for non-numeralness */ \ |
njn | e4faf5d | 2007-11-26 02:55:12 +0000 | [diff] [blame] | 127 | if ('\0' != s[0]) VG_(err_bad_option)(qq_arg); \ |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 128 | True; \ |
| 129 | }) \ |
| 130 | ) |
njn | 62721e9 | 2007-11-11 22:15:58 +0000 | [diff] [blame] | 131 | |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 132 | // Arg whose value is denoted by the exact presence of the given string; |
| 133 | // if it matches, qq_var is assigned the value in qq_val. |
| 134 | #define VG_XACT_CLO(qq_arg, qq_option, qq_var, qq_val) \ |
| 135 | (VG_STREQ((qq_arg), (qq_option)) && \ |
| 136 | ({ \ |
| 137 | (qq_var) = (qq_val); \ |
| 138 | True; \ |
| 139 | }) \ |
| 140 | ) |
sewardj | f767d96 | 2007-02-12 17:47:14 +0000 | [diff] [blame] | 141 | |
njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 142 | /* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */ |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 143 | extern Int VG_(clo_verbosity); |
njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 144 | |
sewardj | 2d9e874 | 2009-08-07 15:46:56 +0000 | [diff] [blame] | 145 | /* Show tool and core statistics */ |
| 146 | extern Bool VG_(clo_stats); |
| 147 | |
sewardj | 71bc3cb | 2005-05-19 00:25:45 +0000 | [diff] [blame] | 148 | /* Emit all messages as XML? default: NO */ |
| 149 | /* If clo_xml is set, various other options are set in a non-default |
| 150 | way. See vg_main.c and mc_main.c. */ |
| 151 | extern Bool VG_(clo_xml); |
njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 152 | |
sewardj | 768db0e | 2005-07-19 14:18:56 +0000 | [diff] [blame] | 153 | /* An arbitrary user-supplied string which is copied into the |
| 154 | XML output, in between <usercomment> tags. */ |
| 155 | extern HChar* VG_(clo_xml_user_comment); |
| 156 | |
sewardj | f9b5b7d | 2005-07-26 23:47:00 +0000 | [diff] [blame] | 157 | /* Vex iropt control. Tool-visible so tools can make Vex optimise |
| 158 | less aggressively if that is needed (callgrind needs this). */ |
| 159 | extern VexControl VG_(clo_vex_control); |
| 160 | |
sewardj | da09859 | 2008-01-09 18:37:41 +0000 | [diff] [blame] | 161 | /* Number of parents of a backtrace. Default: 8. */ |
| 162 | extern Int VG_(clo_backtrace_size); |
| 163 | |
njn | 6882443 | 2009-02-10 06:48:00 +0000 | [diff] [blame] | 164 | /* Continue stack traces below main()? Default: NO */ |
| 165 | extern Bool VG_(clo_show_below_main); |
| 166 | |
| 167 | |
sewardj | 6893d65 | 2006-10-15 01:25:13 +0000 | [diff] [blame] | 168 | /* Call this if a recognised option was bad for some reason. Note: |
| 169 | don't use it just because an option was unrecognised -- return |
njn | 83df0b6 | 2009-02-25 01:01:05 +0000 | [diff] [blame] | 170 | 'False' from VG_(tdict).tool_process_cmd_line_option) to indicate that -- |
| 171 | use it if eg. an option was given an inappropriate argument. |
| 172 | This function prints an error message, then shuts down the entire system. |
| 173 | It returns a Bool so it can be used in the _CLO_ macros. */ |
njn | 3ed1971 | 2007-11-22 23:01:59 +0000 | [diff] [blame] | 174 | __attribute__((noreturn)) |
sewardj | 6893d65 | 2006-10-15 01:25:13 +0000 | [diff] [blame] | 175 | extern void VG_(err_bad_option) ( Char* opt ); |
| 176 | |
sewardj | 5eed741 | 2008-11-17 12:45:01 +0000 | [diff] [blame] | 177 | /* Used to expand file names. "option_name" is the option name, eg. |
njn | 374a36d | 2007-11-23 01:41:32 +0000 | [diff] [blame] | 178 | "--log-file". 'format' is what follows, eg. "cachegrind.out.%p". In |
| 179 | 'format': |
| 180 | - "%p" is replaced with PID. |
| 181 | - "%q{QUAL}" is replaced with the environment variable $QUAL. If $QUAL |
| 182 | isn't set, we abort. If the "{QUAL}" part is malformed, we abort. |
| 183 | - "%%" is replaced with "%". |
| 184 | Anything else after '%' causes an abort. |
njn | 2dd08f5 | 2007-11-23 22:37:35 +0000 | [diff] [blame] | 185 | If the format specifies a relative file name, it's put in the program's |
| 186 | initial working directory. If it specifies an absolute file name (ie. |
| 187 | starts with '/') then it is put there. |
sewardj | 5eed741 | 2008-11-17 12:45:01 +0000 | [diff] [blame] | 188 | |
| 189 | Note that "option_name" has no effect on the returned string: the |
| 190 | returned string depends only on "format" and the PIDs and |
| 191 | environment variables that it references (if any). "option_name" is |
| 192 | merely used in printing error messages, if an error message needs |
| 193 | to be printed due to malformedness of the "format" argument. |
njn | 374a36d | 2007-11-23 01:41:32 +0000 | [diff] [blame] | 194 | */ |
| 195 | extern Char* VG_(expand_file_name)(Char* option_name, Char* format); |
sewardj | 6893d65 | 2006-10-15 01:25:13 +0000 | [diff] [blame] | 196 | |
njn | 2024234 | 2005-05-16 23:31:24 +0000 | [diff] [blame] | 197 | #endif // __PUB_TOOL_OPTIONS_H |
| 198 | |
| 199 | /*--------------------------------------------------------------------*/ |
| 200 | /*--- end ---*/ |
| 201 | /*--------------------------------------------------------------------*/ |