blob: 7d8e60f6a06a9b0e2ec81d4c8057a203a7c297d9 [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
sewardj4d474d02008-02-11 11:34:59 +000010 Copyright (C) 2000-2008 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
njn20242342005-05-16 23:31:24 +000037/* Use these for recognising tool command line options -- stops comparing
38 once whitespace is reached. */
39#define VG_CLO_STREQ(s1,s2) (0==VG_(strcmp_ws)((s1),(s2)))
40#define VG_CLO_STREQN(nn,s1,s2) (0==VG_(strncmp_ws)((s1),(s2),(nn)))
41
42/* Higher-level command-line option recognisers; use in if/else chains */
43
44#define VG_BOOL_CLO(qq_arg, qq_option, qq_var) \
45 if (VG_CLO_STREQ(qq_arg, qq_option"=yes")) { (qq_var) = True; } \
46 else if (VG_CLO_STREQ(qq_arg, qq_option"=no")) { (qq_var) = False; }
47
48#define VG_STR_CLO(qq_arg, qq_option, qq_var) \
49 if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \
50 (qq_var) = &qq_arg[ VG_(strlen)(qq_option)+1 ]; \
51 }
52
sewardj5abcc0b2007-11-30 17:50:44 +000053/* Unbounded integer arg */
njn20242342005-05-16 23:31:24 +000054#define VG_NUM_CLO(qq_arg, qq_option, qq_var) \
55 if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \
njnea5d2352007-11-11 21:58:21 +000056 Char* s; \
57 Long n = VG_(strtoll10)( &qq_arg[ VG_(strlen)(qq_option)+1 ], &s );\
58 (qq_var) = n; \
59 /* Check for non-numeralness, or overflow */ \
njne4faf5d2007-11-26 02:55:12 +000060 if ('\0' != s[0] || (qq_var) != n) VG_(err_bad_option)(qq_arg); \
njn20242342005-05-16 23:31:24 +000061 }
62
63/* Bounded integer arg */
64#define VG_BNUM_CLO(qq_arg, qq_option, qq_var, qq_lo, qq_hi) \
65 if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \
njn62721e92007-11-11 22:15:58 +000066 Char* s; \
67 Long n = VG_(strtoll10)( &qq_arg[ VG_(strlen)(qq_option)+1 ], &s );\
68 (qq_var) = n; \
69 /* Check for non-numeralness, or overflow */ \
njne4faf5d2007-11-26 02:55:12 +000070 if ('\0' != s[0] || (qq_var) != n) VG_(err_bad_option)(qq_arg); \
njn20242342005-05-16 23:31:24 +000071 if ((qq_var) < (qq_lo)) (qq_var) = (qq_lo); \
72 if ((qq_var) > (qq_hi)) (qq_var) = (qq_hi); \
73 }
74
sewardjeb0fa932007-11-30 21:41:40 +000075/* Bounded hexadecimal arg */
76#define VG_BHEX_CLO(qq_arg, qq_option, qq_var, qq_lo, qq_hi) \
77 if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \
78 Char* s; \
79 Long n = VG_(strtoll16)( &qq_arg[ VG_(strlen)(qq_option)+1 ], &s );\
80 (qq_var) = n; \
81 /* Check for non-numeralness, or overflow */ \
82 if ('\0' != s[0] || (qq_var) != n) VG_(err_bad_option)(qq_arg); \
83 if ((qq_var) < (qq_lo)) (qq_var) = (qq_lo); \
84 if ((qq_var) > (qq_hi)) (qq_var) = (qq_hi); \
85 }
86
njn62721e92007-11-11 22:15:58 +000087/* Double arg */
88#define VG_DBL_CLO(qq_arg, qq_option, qq_var) \
89 if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \
90 Char* s; \
91 double n = VG_(strtod)( &qq_arg[ VG_(strlen)(qq_option)+1 ], &s );\
92 (qq_var) = n; \
93 /* Check for non-numeralness */ \
njne4faf5d2007-11-26 02:55:12 +000094 if ('\0' != s[0]) VG_(err_bad_option)(qq_arg); \
njn62721e92007-11-11 22:15:58 +000095 }
96
sewardjf767d962007-02-12 17:47:14 +000097/* Bool arg whose value is denoted by the exact presence of the given string. */
98#define VG_XACT_CLO(qq_arg, qq_option, qq_var) \
99 if (VG_CLO_STREQ(qq_arg, qq_option)) { \
100 (qq_var) = True; \
101 } /* else leave it alone */
102
njn20242342005-05-16 23:31:24 +0000103/* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */
sewardj71bc3cb2005-05-19 00:25:45 +0000104extern Int VG_(clo_verbosity);
njn20242342005-05-16 23:31:24 +0000105
sewardj71bc3cb2005-05-19 00:25:45 +0000106/* Emit all messages as XML? default: NO */
107/* If clo_xml is set, various other options are set in a non-default
108 way. See vg_main.c and mc_main.c. */
109extern Bool VG_(clo_xml);
njn20242342005-05-16 23:31:24 +0000110
sewardj768db0e2005-07-19 14:18:56 +0000111/* An arbitrary user-supplied string which is copied into the
112 XML output, in between <usercomment> tags. */
113extern HChar* VG_(clo_xml_user_comment);
114
sewardjf9b5b7d2005-07-26 23:47:00 +0000115/* Vex iropt control. Tool-visible so tools can make Vex optimise
116 less aggressively if that is needed (callgrind needs this). */
117extern VexControl VG_(clo_vex_control);
118
sewardjda098592008-01-09 18:37:41 +0000119/* Number of parents of a backtrace. Default: 8. */
120extern Int VG_(clo_backtrace_size);
121
sewardj6893d652006-10-15 01:25:13 +0000122/* Call this if a recognised option was bad for some reason. Note:
123 don't use it just because an option was unrecognised -- return
124 'False' from VG_(tdict).tool_process_cmd_line_option) to indicate
125 that. This function prints an error message, then shuts down the
126 entire system. */
njn3ed19712007-11-22 23:01:59 +0000127__attribute__((noreturn))
sewardj6893d652006-10-15 01:25:13 +0000128extern void VG_(err_bad_option) ( Char* opt );
129
sewardj5eed7412008-11-17 12:45:01 +0000130/* Used to expand file names. "option_name" is the option name, eg.
njn374a36d2007-11-23 01:41:32 +0000131 "--log-file". 'format' is what follows, eg. "cachegrind.out.%p". In
132 'format':
133 - "%p" is replaced with PID.
134 - "%q{QUAL}" is replaced with the environment variable $QUAL. If $QUAL
135 isn't set, we abort. If the "{QUAL}" part is malformed, we abort.
136 - "%%" is replaced with "%".
137 Anything else after '%' causes an abort.
njn2dd08f52007-11-23 22:37:35 +0000138 If the format specifies a relative file name, it's put in the program's
139 initial working directory. If it specifies an absolute file name (ie.
140 starts with '/') then it is put there.
sewardj5eed7412008-11-17 12:45:01 +0000141
142 Note that "option_name" has no effect on the returned string: the
143 returned string depends only on "format" and the PIDs and
144 environment variables that it references (if any). "option_name" is
145 merely used in printing error messages, if an error message needs
146 to be printed due to malformedness of the "format" argument.
njn374a36d2007-11-23 01:41:32 +0000147*/
148extern Char* VG_(expand_file_name)(Char* option_name, Char* format);
sewardj6893d652006-10-15 01:25:13 +0000149
njn20242342005-05-16 23:31:24 +0000150#endif // __PUB_TOOL_OPTIONS_H
151
152/*--------------------------------------------------------------------*/
153/*--- end ---*/
154/*--------------------------------------------------------------------*/