2 /*--------------------------------------------------------------------*/
3 /*--- Command line options. pub_tool_options.h ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2000-2017 Julian Seward
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.
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.
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
28 The GNU General Public License is contained in the file COPYING.
31 #ifndef __PUB_TOOL_OPTIONS_H
32 #define __PUB_TOOL_OPTIONS_H
34 #include "pub_tool_basics.h" // for VG_ macro
35 #include "libvex.h" // for VexControl
38 // Higher-level command-line option recognisers; use in if/else chains.
39 // Note that they assign a value to the 'qq_var' argument. So often they
40 // can be used like this:
42 // if VG_STR_CLO(arg, "--foo", clo_foo) { }
44 // But if you want to do further checking or processing, you can do this:
46 // if VG_STR_CLO(arg, "--foo", clo_foo) { <further checking or processing> }
48 // They use GNU statement expressions to do the qq_var assignment within a
49 // conditional expression.
51 // String argument, eg. --foo=yes or --foo=no
52 #define VG_BOOL_CLO(qq_arg, qq_option, qq_var) \
53 (VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=") && \
55 const HChar* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ]; \
56 if VG_STREQ(val, "yes") (qq_var) = True; \
57 else if VG_STREQ(val, "no") (qq_var) = False; \
58 else VG_(fmsg_bad_option)(qq_arg, "Invalid boolean value '%s'" \
59 " (should be 'yes' or 'no')\n", val); \
64 // String argument, eg. --foo=bar
65 #define VG_STR_CLO(qq_arg, qq_option, qq_var) \
66 (VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=") && \
68 const HChar* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ]; \
74 // UInt enum set arg, eg. --foo=fubar,bar,baz or --foo=none
75 // or --foo=all (if qq_all is True)
76 #define VG_USETGEN_CLO(qq_arg, qq_option, qq_vals, qq_var, qq_all) \
77 (VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=") && \
79 const HChar* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ]; \
80 if (!VG_(parse_enum_set)(qq_vals, \
81 qq_all,/*allow_all*/ \
84 VG_(fmsg_bad_option)(qq_arg, "%s is an invalid %s set\n", \
90 // UInt enum set arg, eg. --foo=fubar,bar,baz or --foo=none or --foo=all
91 #define VG_USET_CLO(qq_arg, qq_option, qq_vals, qq_var) \
92 VG_USETGEN_CLO((qq_arg), qq_option, (qq_vals), (qq_var), True)
94 /* Same as VG_USET_CLO but not allowing --foo=all.
95 To be used when some or all of the enum set are mutually eXclusive. */
96 #define VG_USETX_CLO(qq_arg, qq_option, qq_vals, qq_var) \
97 VG_USETGEN_CLO((qq_arg), qq_option, (qq_vals), (qq_var), False)
99 // Unbounded integer arg, eg. --foo=10
100 #define VG_INT_CLO(qq_arg, qq_option, qq_var) \
101 (VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=") && \
103 const HChar* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ]; \
105 Long n = VG_(strtoll10)( val, &s ); \
107 /* Check for non-numeralness, or overflow. */ \
108 if ('\0' != s[0] || (qq_var) != n) VG_(fmsg_bad_option)(qq_arg, \
109 "Invalid integer value '%s'\n", val); \
114 // Bounded integer arg, eg. --foo=10 ; if the value exceeds the bounds it
115 // causes an abort. 'qq_base' can be 10 or 16.
116 #define VG_BINTN_CLO(qq_base, qq_arg, qq_option, qq_var, qq_lo, qq_hi) \
117 (VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=") && \
119 const HChar* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ]; \
121 Long n = VG_(strtoll##qq_base)( val, &s ); \
123 /* MMM: separate the two cases, and explain the problem; likewise */ \
124 /* for all the other macros in this file. */ \
125 /* Check for non-numeralness, or overflow. */ \
126 /* Nb: it will overflow if qq_var is unsigned and qq_val is negative! */ \
127 if ('\0' != s[0] || (qq_var) != n) VG_(fmsg_bad_option)(qq_arg, \
128 "Invalid integer value '%s'\n", val); \
129 /* Check bounds. */ \
130 if ((qq_var) < (qq_lo) || (qq_var) > (qq_hi)) { \
131 VG_(fmsg_bad_option)(qq_arg, \
132 "'%s' argument must be between %lld and %lld\n", \
133 (qq_option), (Long)(qq_lo), (Long)(qq_hi)); \
139 // Bounded decimal integer arg, eg. --foo=100
140 #define VG_BINT_CLO(qq_arg, qq_option, qq_var, qq_lo, qq_hi) \
141 VG_BINTN_CLO(10, (qq_arg), qq_option, (qq_var), (qq_lo), (qq_hi))
143 // Bounded hexadecimal integer arg, eg. --foo=0x1fa8
144 #define VG_BHEX_CLO(qq_arg, qq_option, qq_var, qq_lo, qq_hi) \
145 VG_BINTN_CLO(16, (qq_arg), qq_option, (qq_var), (qq_lo), (qq_hi))
147 // Double (decimal) arg, eg. --foo=4.6
148 // XXX: there's not VG_BDBL_CLO because we don't have a good way of printing
149 // floats at the moment!
150 #define VG_DBL_CLO(qq_arg, qq_option, qq_var) \
151 (VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=") && \
153 const HChar* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ]; \
155 double n = VG_(strtod)( val, &s ); \
157 /* Check for non-numeralness */ \
158 if ('\0' != s[0]) VG_(fmsg_bad_option)(qq_arg, \
159 "Invalid floating point value '%s'\n",val); \
164 // Arg whose value is denoted by the exact presence of the given string;
165 // if it matches, qq_var is assigned the value in qq_val.
166 #define VG_XACT_CLO(qq_arg, qq_option, qq_var, qq_val) \
167 (VG_STREQ((qq_arg), (qq_option)) && \
169 (qq_var) = (qq_val); \
174 // Arg that can be one of a set of strings, as specified in an NULL
175 // terminated array. Returns the index of the string in |qq_ix|, or
176 // aborts if not found.
177 #define VG_STRINDEX_CLO(qq_arg, qq_option, qq_strings, qq_ix) \
178 (VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=") && \
180 const HChar* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ]; \
181 for (qq_ix = 0; (qq_strings)[qq_ix]; qq_ix++) { \
182 if (VG_STREQ(val, (qq_strings)[qq_ix])) \
185 if ((qq_strings)[qq_ix] == NULL) \
186 VG_(fmsg_bad_option)(qq_arg, \
187 "Invalid string '%s' in '%s'\n", val, qq_arg); \
192 /* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */
193 extern Int
VG_(clo_verbosity
);
195 /* Show tool and core statistics */
196 extern Bool
VG_(clo_stats
);
198 /* wait for vgdb/gdb after reporting that amount of error.
199 Note that this is the initial value provided from the command line.
200 The real value is maintained in VG_(dyn_vgdb_error) and
201 can be changed dynamically.*/
202 extern Int
VG_(clo_vgdb_error
);
204 /* If user has provided the --vgdb-prefix command line option,
205 VG_(arg_vgdb_prefix) points at the provided argument (including the
206 '--vgdb-prefix=' string).
207 Otherwise, it is NULL.
208 Typically, this is used by tools to produce user message with the
209 expected vgdb prefix argument, if the user has changed the default. */
210 extern const HChar
*VG_(arg_vgdb_prefix
);
212 /* Emit all messages as XML? default: NO */
213 /* If clo_xml is set, various other options are set in a non-default
214 way. See vg_main.c and mc_main.c. */
215 extern Bool
VG_(clo_xml
);
217 /* An arbitrary user-supplied string which is copied into the
218 XML output, in between <usercomment> tags. */
219 extern const HChar
* VG_(clo_xml_user_comment
);
221 /* Vex iropt control. Tool-visible so tools can make Vex optimise
222 less aggressively if that is needed (callgrind needs this). */
223 extern VexControl
VG_(clo_vex_control
);
224 extern VexRegisterUpdates
VG_(clo_px_file_backed
);
226 extern Int
VG_(clo_redzone_size
);
230 Vg_XTMemory_None
, // Do not do any xtree memory profiling.
231 Vg_XTMemory_Allocs
, // Currently allocated size xtree memory profiling
232 Vg_XTMemory_Full
, // Full profiling : Current allocated size, total
233 // allocated size, nr of blocks, total freed size, ...
236 // Tools that replace malloc can optionally implement memory profiling
237 // following the value of VG_(clo_xtree_profile_memory) to produce a report
238 // at the end of execution.
239 extern VgXTMemory
VG_(clo_xtree_memory
);
240 /* Holds the filename to use for xtree memory profiling output, before expansion
241 of %p and %q templates. */
242 extern const HChar
* VG_(clo_xtree_memory_file
);
243 /* Compress strings in xtree dumps. */
244 extern Bool
VG_(clo_xtree_compress_strings
);
246 /* Number of parents of a backtrace. Default: 12 */
247 extern Int
VG_(clo_backtrace_size
);
249 /* Continue stack traces below main()? Default: NO */
250 extern Bool
VG_(clo_show_below_main
);
252 /* Keep symbols (and all other debuginfo) for code that is unloaded (dlclose
253 or similar) so that stack traces can still give line/file info for
254 previously captured stack traces. e.g. ... showing where a block was
255 allocated e.g. leaks of or accesses just outside a block. */
256 extern Bool
VG_(clo_keep_debuginfo
);
259 /* Used to expand file names. "option_name" is the option name, eg.
260 "--log-file". 'format' is what follows, eg. "cachegrind.out.%p". In
262 - "%p" is replaced with PID.
263 - "%q{QUAL}" is replaced with the environment variable $QUAL. If $QUAL
264 isn't set, we abort. If the "{QUAL}" part is malformed, we abort.
265 - "%%" is replaced with "%".
266 Anything else after '%' causes an abort.
267 If the format specifies a relative file name, it's put in the program's
268 initial working directory. If it specifies an absolute file name (ie.
269 starts with '/') then it is put there.
271 Note that "option_name" has no effect on the returned string: the
272 returned string depends only on "format" and the PIDs and
273 environment variables that it references (if any). "option_name" is
274 merely used in printing error messages, if an error message needs
275 to be printed due to malformedness of the "format" argument.
277 extern HChar
* VG_(expand_file_name
)(const HChar
* option_name
,
278 const HChar
* format
);
280 #endif // __PUB_TOOL_OPTIONS_H
282 /*--------------------------------------------------------------------*/
284 /*--------------------------------------------------------------------*/