blob: c03920b40825773602c11d0043f358100bb2b937 [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
sewardj9ebd6e02007-01-08 06:01:59 +000010 Copyright (C) 2000-2007 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
53#define VG_NUM_CLO(qq_arg, qq_option, qq_var) \
54 if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \
njnea5d2352007-11-11 21:58:21 +000055 Char* s; \
56 Long n = VG_(strtoll10)( &qq_arg[ VG_(strlen)(qq_option)+1 ], &s );\
57 (qq_var) = n; \
58 /* Check for non-numeralness, or overflow */ \
59 if ('\0' != s[0] || (qq_var) != n) VG_(err_bad_option)(qq_arg); \
njn20242342005-05-16 23:31:24 +000060 }
61
sewardj91b470c2007-08-28 17:03:01 +000062/* Same as VG_NUM_CLO but does not coerce the result value to 32 bits
63 on 64-bit platforms. */
64#define VG_NUMW_CLO(qq_arg, qq_option, qq_var) \
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 */ \
70 if ('\0' != s[0]) VG_(err_bad_option)(qq_arg); \
sewardj91b470c2007-08-28 17:03:01 +000071 }
72
njn20242342005-05-16 23:31:24 +000073/* Bounded integer arg */
74#define VG_BNUM_CLO(qq_arg, qq_option, qq_var, qq_lo, qq_hi) \
75 if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \
njn62721e92007-11-11 22:15:58 +000076 Char* s; \
77 Long n = VG_(strtoll10)( &qq_arg[ VG_(strlen)(qq_option)+1 ], &s );\
78 (qq_var) = n; \
79 /* Check for non-numeralness, or overflow */ \
80 if ('\0' != s[0] || (qq_var) != n) VG_(err_bad_option)(qq_arg); \
njn20242342005-05-16 23:31:24 +000081 if ((qq_var) < (qq_lo)) (qq_var) = (qq_lo); \
82 if ((qq_var) > (qq_hi)) (qq_var) = (qq_hi); \
83 }
84
njn62721e92007-11-11 22:15:58 +000085/* Double arg */
86#define VG_DBL_CLO(qq_arg, qq_option, qq_var) \
87 if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \
88 Char* s; \
89 double n = VG_(strtod)( &qq_arg[ VG_(strlen)(qq_option)+1 ], &s );\
90 (qq_var) = n; \
91 /* Check for non-numeralness */ \
92 if ('\0' != s[0]) VG_(err_bad_option)(qq_arg); \
93 }
94
sewardjf767d962007-02-12 17:47:14 +000095/* Bool arg whose value is denoted by the exact presence of the given string. */
96#define VG_XACT_CLO(qq_arg, qq_option, qq_var) \
97 if (VG_CLO_STREQ(qq_arg, qq_option)) { \
98 (qq_var) = True; \
99 } /* else leave it alone */
100
njn20242342005-05-16 23:31:24 +0000101/* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */
sewardj71bc3cb2005-05-19 00:25:45 +0000102extern Int VG_(clo_verbosity);
njn20242342005-05-16 23:31:24 +0000103
sewardj71bc3cb2005-05-19 00:25:45 +0000104/* Emit all messages as XML? default: NO */
105/* If clo_xml is set, various other options are set in a non-default
106 way. See vg_main.c and mc_main.c. */
107extern Bool VG_(clo_xml);
njn20242342005-05-16 23:31:24 +0000108
sewardj768db0e2005-07-19 14:18:56 +0000109/* An arbitrary user-supplied string which is copied into the
110 XML output, in between <usercomment> tags. */
111extern HChar* VG_(clo_xml_user_comment);
112
sewardjf9b5b7d2005-07-26 23:47:00 +0000113/* Vex iropt control. Tool-visible so tools can make Vex optimise
114 less aggressively if that is needed (callgrind needs this). */
115extern VexControl VG_(clo_vex_control);
116
sewardj6893d652006-10-15 01:25:13 +0000117/* Call this if a recognised option was bad for some reason. Note:
118 don't use it just because an option was unrecognised -- return
119 'False' from VG_(tdict).tool_process_cmd_line_option) to indicate
120 that. This function prints an error message, then shuts down the
121 entire system. */
njn3ed19712007-11-22 23:01:59 +0000122__attribute__((noreturn))
sewardj6893d652006-10-15 01:25:13 +0000123extern void VG_(err_bad_option) ( Char* opt );
124
njn374a36d2007-11-23 01:41:32 +0000125/* Used to expand file names. 'option_name" is the option name, eg.
126 "--log-file". 'format' is what follows, eg. "cachegrind.out.%p". In
127 'format':
128 - "%p" is replaced with PID.
129 - "%q{QUAL}" is replaced with the environment variable $QUAL. If $QUAL
130 isn't set, we abort. If the "{QUAL}" part is malformed, we abort.
131 - "%%" is replaced with "%".
132 Anything else after '%' causes an abort.
133*/
134extern Char* VG_(expand_file_name)(Char* option_name, Char* format);
sewardj6893d652006-10-15 01:25:13 +0000135
njn20242342005-05-16 23:31:24 +0000136#endif // __PUB_TOOL_OPTIONS_H
137
138/*--------------------------------------------------------------------*/
139/*--- end ---*/
140/*--------------------------------------------------------------------*/