blob: 50493d772dd3ea539c7c8d226d689ddce97c6d22 [file] [log] [blame]
njn20242342005-05-16 23:31:24 +00001
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
sewardj9eecbbb2010-05-03 21:37:12 +000010 Copyright (C) 2000-2010 Julian Seward
njn20242342005-05-16 23:31:24 +000011 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
sewardjf9b5b7d2005-07-26 23:47:00 +000034#include "libvex.h" // for VexControl
35
36
njn83df0b62009-02-25 01:01:05 +000037// 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.
njn20242342005-05-16 23:31:24 +000049
njn83df0b62009-02-25 01:01:05 +000050// String argument, eg. --foo=yes or --foo=no
njn20242342005-05-16 23:31:24 +000051#define VG_BOOL_CLO(qq_arg, qq_option, qq_var) \
njn83df0b62009-02-25 01:01:05 +000052 (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; \
sewardj36f3c792011-05-17 16:29:29 +000057 else VG_(fmsg_bad_option)(qq_arg, "Invalid boolean value '%s'" \
58 " (should be 'yes' or 'no')\n", val); \
njn83df0b62009-02-25 01:01:05 +000059 True; \
60 }) \
61 )
njn20242342005-05-16 23:31:24 +000062
njn83df0b62009-02-25 01:01:05 +000063// String argument, eg. --foo=bar
njn20242342005-05-16 23:31:24 +000064#define VG_STR_CLO(qq_arg, qq_option, qq_var) \
njn83df0b62009-02-25 01:01:05 +000065 (VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=") && \
66 ({ \
67 Char* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ]; \
68 (qq_var) = val; \
69 True; \
70 }) \
71 )
njn20242342005-05-16 23:31:24 +000072
njn83df0b62009-02-25 01:01:05 +000073// Unbounded integer arg, eg. --foo=10
74#define VG_INT_CLO(qq_arg, qq_option, qq_var) \
75 (VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=") && \
76 ({ \
77 Char* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ]; \
njnea5d2352007-11-11 21:58:21 +000078 Char* s; \
njn83df0b62009-02-25 01:01:05 +000079 Long n = VG_(strtoll10)( val, &s ); \
njnea5d2352007-11-11 21:58:21 +000080 (qq_var) = n; \
njn83df0b62009-02-25 01:01:05 +000081 /* Check for non-numeralness, or overflow. */ \
njnb1cc5d62010-07-06 04:05:23 +000082 if ('\0' != s[0] || (qq_var) != n) VG_(fmsg_bad_option)(qq_arg, ""); \
njn83df0b62009-02-25 01:01:05 +000083 True; \
84 }) \
85 )
njn20242342005-05-16 23:31:24 +000086
njn83df0b62009-02-25 01:01:05 +000087// Bounded integer arg, eg. --foo=10 ; if the value exceeds the bounds it
88// causes an abort. 'qq_base' can be 10 or 16.
89#define VG_BINTN_CLO(qq_base, qq_arg, qq_option, qq_var, qq_lo, qq_hi) \
90 (VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=") && \
91 ({ \
92 Char* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ]; \
njn62721e92007-11-11 22:15:58 +000093 Char* s; \
njn83df0b62009-02-25 01:01:05 +000094 Long n = VG_(strtoll##qq_base)( val, &s ); \
njn62721e92007-11-11 22:15:58 +000095 (qq_var) = n; \
njnb1cc5d62010-07-06 04:05:23 +000096 /* MMM: separate the two cases, and explain the problem; likewise */ \
97 /* for all the other macros in this file. */ \
njn83df0b62009-02-25 01:01:05 +000098 /* Check for non-numeralness, or overflow. */ \
99 /* Nb: it will overflow if qq_var is unsigned and qq_val is negative! */ \
njnb1cc5d62010-07-06 04:05:23 +0000100 if ('\0' != s[0] || (qq_var) != n) VG_(fmsg_bad_option)(qq_arg, ""); \
njn83df0b62009-02-25 01:01:05 +0000101 /* Check bounds. */ \
102 if ((qq_var) < (qq_lo) || (qq_var) > (qq_hi)) { \
njnb1cc5d62010-07-06 04:05:23 +0000103 VG_(fmsg_bad_option)(qq_arg, \
104 "'%s' argument must be between %lld and %lld\n", \
105 (qq_option), (Long)(qq_lo), (Long)(qq_hi)); \
njn83df0b62009-02-25 01:01:05 +0000106 } \
107 True; \
108 }) \
109 )
njn20242342005-05-16 23:31:24 +0000110
njn83df0b62009-02-25 01:01:05 +0000111// Bounded decimal integer arg, eg. --foo=100
112#define VG_BINT_CLO(qq_arg, qq_option, qq_var, qq_lo, qq_hi) \
113 VG_BINTN_CLO(10, (qq_arg), qq_option, (qq_var), (qq_lo), (qq_hi))
114
115// Bounded hexadecimal integer arg, eg. --foo=0x1fa8
sewardjeb0fa932007-11-30 21:41:40 +0000116#define VG_BHEX_CLO(qq_arg, qq_option, qq_var, qq_lo, qq_hi) \
njn83df0b62009-02-25 01:01:05 +0000117 VG_BINTN_CLO(16, (qq_arg), qq_option, (qq_var), (qq_lo), (qq_hi))
sewardjeb0fa932007-11-30 21:41:40 +0000118
njn83df0b62009-02-25 01:01:05 +0000119// Double (decimal) arg, eg. --foo=4.6
120// XXX: there's not VG_BDBL_CLO because we don't have a good way of printing
121// floats at the moment!
njn62721e92007-11-11 22:15:58 +0000122#define VG_DBL_CLO(qq_arg, qq_option, qq_var) \
njn83df0b62009-02-25 01:01:05 +0000123 (VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=") && \
124 ({ \
125 Char* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ]; \
njn62721e92007-11-11 22:15:58 +0000126 Char* s; \
njn83df0b62009-02-25 01:01:05 +0000127 double n = VG_(strtod)( val, &s ); \
njn62721e92007-11-11 22:15:58 +0000128 (qq_var) = n; \
129 /* Check for non-numeralness */ \
njnb1cc5d62010-07-06 04:05:23 +0000130 if ('\0' != s[0]) VG_(fmsg_bad_option)(qq_arg, ""); \
njn83df0b62009-02-25 01:01:05 +0000131 True; \
132 }) \
133 )
njn62721e92007-11-11 22:15:58 +0000134
njn83df0b62009-02-25 01:01:05 +0000135// Arg whose value is denoted by the exact presence of the given string;
136// if it matches, qq_var is assigned the value in qq_val.
137#define VG_XACT_CLO(qq_arg, qq_option, qq_var, qq_val) \
138 (VG_STREQ((qq_arg), (qq_option)) && \
139 ({ \
140 (qq_var) = (qq_val); \
141 True; \
142 }) \
143 )
sewardjf767d962007-02-12 17:47:14 +0000144
njn20242342005-05-16 23:31:24 +0000145/* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */
sewardj71bc3cb2005-05-19 00:25:45 +0000146extern Int VG_(clo_verbosity);
njn20242342005-05-16 23:31:24 +0000147
sewardj2d9e8742009-08-07 15:46:56 +0000148/* Show tool and core statistics */
149extern Bool VG_(clo_stats);
150
sewardj3b290482011-05-06 21:02:55 +0000151/* wait for vgdb/gdb after reporting that amount of error.
152 Note that this is the initial value provided from the command line.
153 The real value is maintained in VG_(dyn_vgdb_error) and
154 can be changed dynamically.*/
155extern Int VG_(clo_vgdb_error);
156
sewardj71bc3cb2005-05-19 00:25:45 +0000157/* Emit all messages as XML? default: NO */
158/* If clo_xml is set, various other options are set in a non-default
159 way. See vg_main.c and mc_main.c. */
160extern Bool VG_(clo_xml);
njn20242342005-05-16 23:31:24 +0000161
sewardj768db0e2005-07-19 14:18:56 +0000162/* An arbitrary user-supplied string which is copied into the
163 XML output, in between <usercomment> tags. */
164extern HChar* VG_(clo_xml_user_comment);
165
sewardjf9b5b7d2005-07-26 23:47:00 +0000166/* Vex iropt control. Tool-visible so tools can make Vex optimise
167 less aggressively if that is needed (callgrind needs this). */
168extern VexControl VG_(clo_vex_control);
169
sewardjda098592008-01-09 18:37:41 +0000170/* Number of parents of a backtrace. Default: 8. */
171extern Int VG_(clo_backtrace_size);
172
njn68824432009-02-10 06:48:00 +0000173/* Continue stack traces below main()? Default: NO */
174extern Bool VG_(clo_show_below_main);
175
176
sewardj5eed7412008-11-17 12:45:01 +0000177/* Used to expand file names. "option_name" is the option name, eg.
njn374a36d2007-11-23 01:41:32 +0000178 "--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.
njn2dd08f52007-11-23 22:37:35 +0000185 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.
sewardj5eed7412008-11-17 12:45:01 +0000188
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.
njn374a36d2007-11-23 01:41:32 +0000194*/
195extern Char* VG_(expand_file_name)(Char* option_name, Char* format);
sewardj6893d652006-10-15 01:25:13 +0000196
njn20242342005-05-16 23:31:24 +0000197#endif // __PUB_TOOL_OPTIONS_H
198
199/*--------------------------------------------------------------------*/
200/*--- end ---*/
201/*--------------------------------------------------------------------*/