pub_tool_options.h revision eb0fa9345010077e1e4852b238dde303b8f271b3
12024234c590f408994b373abfb00bc2cd2a90c48njn
22024234c590f408994b373abfb00bc2cd2a90c48njn/*--------------------------------------------------------------------*/
32024234c590f408994b373abfb00bc2cd2a90c48njn/*--- Command line options.                     pub_tool_options.h ---*/
42024234c590f408994b373abfb00bc2cd2a90c48njn/*--------------------------------------------------------------------*/
52024234c590f408994b373abfb00bc2cd2a90c48njn
62024234c590f408994b373abfb00bc2cd2a90c48njn/*
72024234c590f408994b373abfb00bc2cd2a90c48njn   This file is part of Valgrind, a dynamic binary instrumentation
82024234c590f408994b373abfb00bc2cd2a90c48njn   framework.
92024234c590f408994b373abfb00bc2cd2a90c48njn
109ebd6e0c607fa30301b1325874eb8de871c21cc5sewardj   Copyright (C) 2000-2007 Julian Seward
112024234c590f408994b373abfb00bc2cd2a90c48njn      jseward@acm.org
122024234c590f408994b373abfb00bc2cd2a90c48njn
132024234c590f408994b373abfb00bc2cd2a90c48njn   This program is free software; you can redistribute it and/or
142024234c590f408994b373abfb00bc2cd2a90c48njn   modify it under the terms of the GNU General Public License as
152024234c590f408994b373abfb00bc2cd2a90c48njn   published by the Free Software Foundation; either version 2 of the
162024234c590f408994b373abfb00bc2cd2a90c48njn   License, or (at your option) any later version.
172024234c590f408994b373abfb00bc2cd2a90c48njn
182024234c590f408994b373abfb00bc2cd2a90c48njn   This program is distributed in the hope that it will be useful, but
192024234c590f408994b373abfb00bc2cd2a90c48njn   WITHOUT ANY WARRANTY; without even the implied warranty of
202024234c590f408994b373abfb00bc2cd2a90c48njn   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
212024234c590f408994b373abfb00bc2cd2a90c48njn   General Public License for more details.
222024234c590f408994b373abfb00bc2cd2a90c48njn
232024234c590f408994b373abfb00bc2cd2a90c48njn   You should have received a copy of the GNU General Public License
242024234c590f408994b373abfb00bc2cd2a90c48njn   along with this program; if not, write to the Free Software
252024234c590f408994b373abfb00bc2cd2a90c48njn   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
262024234c590f408994b373abfb00bc2cd2a90c48njn   02111-1307, USA.
272024234c590f408994b373abfb00bc2cd2a90c48njn
282024234c590f408994b373abfb00bc2cd2a90c48njn   The GNU General Public License is contained in the file COPYING.
292024234c590f408994b373abfb00bc2cd2a90c48njn*/
302024234c590f408994b373abfb00bc2cd2a90c48njn
312024234c590f408994b373abfb00bc2cd2a90c48njn#ifndef __PUB_TOOL_OPTIONS_H
322024234c590f408994b373abfb00bc2cd2a90c48njn#define __PUB_TOOL_OPTIONS_H
332024234c590f408994b373abfb00bc2cd2a90c48njn
34f9b5b7de773bb764b239483c937b4ac2698b31d3sewardj#include "libvex.h"              // for VexControl
35f9b5b7de773bb764b239483c937b4ac2698b31d3sewardj
36f9b5b7de773bb764b239483c937b4ac2698b31d3sewardj
372024234c590f408994b373abfb00bc2cd2a90c48njn/* Use these for recognising tool command line options -- stops comparing
382024234c590f408994b373abfb00bc2cd2a90c48njn   once whitespace is reached. */
392024234c590f408994b373abfb00bc2cd2a90c48njn#define VG_CLO_STREQ(s1,s2)     (0==VG_(strcmp_ws)((s1),(s2)))
402024234c590f408994b373abfb00bc2cd2a90c48njn#define VG_CLO_STREQN(nn,s1,s2) (0==VG_(strncmp_ws)((s1),(s2),(nn)))
412024234c590f408994b373abfb00bc2cd2a90c48njn
422024234c590f408994b373abfb00bc2cd2a90c48njn/* Higher-level command-line option recognisers;  use in if/else chains */
432024234c590f408994b373abfb00bc2cd2a90c48njn
442024234c590f408994b373abfb00bc2cd2a90c48njn#define VG_BOOL_CLO(qq_arg, qq_option, qq_var) \
452024234c590f408994b373abfb00bc2cd2a90c48njn        if (VG_CLO_STREQ(qq_arg, qq_option"=yes")) { (qq_var) = True; } \
462024234c590f408994b373abfb00bc2cd2a90c48njn   else if (VG_CLO_STREQ(qq_arg, qq_option"=no"))  { (qq_var) = False; }
472024234c590f408994b373abfb00bc2cd2a90c48njn
482024234c590f408994b373abfb00bc2cd2a90c48njn#define VG_STR_CLO(qq_arg, qq_option, qq_var) \
492024234c590f408994b373abfb00bc2cd2a90c48njn   if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \
502024234c590f408994b373abfb00bc2cd2a90c48njn      (qq_var) = &qq_arg[ VG_(strlen)(qq_option)+1 ]; \
512024234c590f408994b373abfb00bc2cd2a90c48njn   }
522024234c590f408994b373abfb00bc2cd2a90c48njn
535abcc0bacf2575d475d53e9a21e98fd2445d0bc6sewardj/* Unbounded integer arg */
542024234c590f408994b373abfb00bc2cd2a90c48njn#define VG_NUM_CLO(qq_arg, qq_option, qq_var) \
552024234c590f408994b373abfb00bc2cd2a90c48njn   if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \
56ea5d2357bc8d93a8d796853e7f78db2927d47980njn      Char* s; \
57ea5d2357bc8d93a8d796853e7f78db2927d47980njn      Long n = VG_(strtoll10)( &qq_arg[ VG_(strlen)(qq_option)+1 ], &s );\
58ea5d2357bc8d93a8d796853e7f78db2927d47980njn      (qq_var) = n; \
59ea5d2357bc8d93a8d796853e7f78db2927d47980njn      /* Check for non-numeralness, or overflow */ \
60e4faf5d5b87f44f8cac41fa42122fc4202e9f799njn      if ('\0' != s[0] || (qq_var) != n) VG_(err_bad_option)(qq_arg); \
612024234c590f408994b373abfb00bc2cd2a90c48njn   }
622024234c590f408994b373abfb00bc2cd2a90c48njn
632024234c590f408994b373abfb00bc2cd2a90c48njn/* Bounded integer arg */
642024234c590f408994b373abfb00bc2cd2a90c48njn#define VG_BNUM_CLO(qq_arg, qq_option, qq_var, qq_lo, qq_hi) \
652024234c590f408994b373abfb00bc2cd2a90c48njn   if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \
6662721e90cec685b202424719f7237620e2c5780dnjn      Char* s; \
6762721e90cec685b202424719f7237620e2c5780dnjn      Long n = VG_(strtoll10)( &qq_arg[ VG_(strlen)(qq_option)+1 ], &s );\
6862721e90cec685b202424719f7237620e2c5780dnjn      (qq_var) = n; \
6962721e90cec685b202424719f7237620e2c5780dnjn      /* Check for non-numeralness, or overflow */ \
70e4faf5d5b87f44f8cac41fa42122fc4202e9f799njn      if ('\0' != s[0] || (qq_var) != n) VG_(err_bad_option)(qq_arg); \
712024234c590f408994b373abfb00bc2cd2a90c48njn      if ((qq_var) < (qq_lo)) (qq_var) = (qq_lo); \
722024234c590f408994b373abfb00bc2cd2a90c48njn      if ((qq_var) > (qq_hi)) (qq_var) = (qq_hi); \
732024234c590f408994b373abfb00bc2cd2a90c48njn   }
742024234c590f408994b373abfb00bc2cd2a90c48njn
75eb0fa9345010077e1e4852b238dde303b8f271b3sewardj/* Bounded hexadecimal arg */
76eb0fa9345010077e1e4852b238dde303b8f271b3sewardj#define VG_BHEX_CLO(qq_arg, qq_option, qq_var, qq_lo, qq_hi) \
77eb0fa9345010077e1e4852b238dde303b8f271b3sewardj   if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \
78eb0fa9345010077e1e4852b238dde303b8f271b3sewardj      Char* s; \
79eb0fa9345010077e1e4852b238dde303b8f271b3sewardj      Long n = VG_(strtoll16)( &qq_arg[ VG_(strlen)(qq_option)+1 ], &s );\
80eb0fa9345010077e1e4852b238dde303b8f271b3sewardj      (qq_var) = n; \
81eb0fa9345010077e1e4852b238dde303b8f271b3sewardj      /* Check for non-numeralness, or overflow */ \
82eb0fa9345010077e1e4852b238dde303b8f271b3sewardj      if ('\0' != s[0] || (qq_var) != n) VG_(err_bad_option)(qq_arg); \
83eb0fa9345010077e1e4852b238dde303b8f271b3sewardj      if ((qq_var) < (qq_lo)) (qq_var) = (qq_lo); \
84eb0fa9345010077e1e4852b238dde303b8f271b3sewardj      if ((qq_var) > (qq_hi)) (qq_var) = (qq_hi); \
85eb0fa9345010077e1e4852b238dde303b8f271b3sewardj   }
86eb0fa9345010077e1e4852b238dde303b8f271b3sewardj
8762721e90cec685b202424719f7237620e2c5780dnjn/* Double arg */
8862721e90cec685b202424719f7237620e2c5780dnjn#define VG_DBL_CLO(qq_arg, qq_option, qq_var) \
8962721e90cec685b202424719f7237620e2c5780dnjn   if (VG_CLO_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) { \
9062721e90cec685b202424719f7237620e2c5780dnjn      Char* s; \
9162721e90cec685b202424719f7237620e2c5780dnjn      double n = VG_(strtod)( &qq_arg[ VG_(strlen)(qq_option)+1 ], &s );\
9262721e90cec685b202424719f7237620e2c5780dnjn      (qq_var) = n; \
9362721e90cec685b202424719f7237620e2c5780dnjn      /* Check for non-numeralness */ \
94e4faf5d5b87f44f8cac41fa42122fc4202e9f799njn      if ('\0' != s[0]) VG_(err_bad_option)(qq_arg); \
9562721e90cec685b202424719f7237620e2c5780dnjn   }
9662721e90cec685b202424719f7237620e2c5780dnjn
97f767d967b9ef331dcd7d0cd4584f6570cd829333sewardj/* Bool arg whose value is denoted by the exact presence of the given string. */
98f767d967b9ef331dcd7d0cd4584f6570cd829333sewardj#define VG_XACT_CLO(qq_arg, qq_option, qq_var) \
99f767d967b9ef331dcd7d0cd4584f6570cd829333sewardj   if (VG_CLO_STREQ(qq_arg, qq_option)) { \
100f767d967b9ef331dcd7d0cd4584f6570cd829333sewardj      (qq_var) = True; \
101f767d967b9ef331dcd7d0cd4584f6570cd829333sewardj   } /* else leave it alone */
102f767d967b9ef331dcd7d0cd4584f6570cd829333sewardj
1032024234c590f408994b373abfb00bc2cd2a90c48njn/* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */
10471bc3cbb1b6da72fe1d3a9fea90e53847c5b0a6fsewardjextern Int  VG_(clo_verbosity);
1052024234c590f408994b373abfb00bc2cd2a90c48njn
10671bc3cbb1b6da72fe1d3a9fea90e53847c5b0a6fsewardj/* Emit all messages as XML? default: NO */
10771bc3cbb1b6da72fe1d3a9fea90e53847c5b0a6fsewardj/* If clo_xml is set, various other options are set in a non-default
10871bc3cbb1b6da72fe1d3a9fea90e53847c5b0a6fsewardj   way.  See vg_main.c and mc_main.c. */
10971bc3cbb1b6da72fe1d3a9fea90e53847c5b0a6fsewardjextern Bool VG_(clo_xml);
1102024234c590f408994b373abfb00bc2cd2a90c48njn
111768db0eac5cd57ab3245f49b0e54fa51b63bc09fsewardj/* An arbitrary user-supplied string which is copied into the
112768db0eac5cd57ab3245f49b0e54fa51b63bc09fsewardj   XML output, in between <usercomment> tags. */
113768db0eac5cd57ab3245f49b0e54fa51b63bc09fsewardjextern HChar* VG_(clo_xml_user_comment);
114768db0eac5cd57ab3245f49b0e54fa51b63bc09fsewardj
115f9b5b7de773bb764b239483c937b4ac2698b31d3sewardj/* Vex iropt control.  Tool-visible so tools can make Vex optimise
116f9b5b7de773bb764b239483c937b4ac2698b31d3sewardj   less aggressively if that is needed (callgrind needs this). */
117f9b5b7de773bb764b239483c937b4ac2698b31d3sewardjextern VexControl VG_(clo_vex_control);
118f9b5b7de773bb764b239483c937b4ac2698b31d3sewardj
1196893d65852940741dbebbc6ba1480e89cf34e30fsewardj/* Call this if a recognised option was bad for some reason.  Note:
1206893d65852940741dbebbc6ba1480e89cf34e30fsewardj   don't use it just because an option was unrecognised -- return
1216893d65852940741dbebbc6ba1480e89cf34e30fsewardj   'False' from VG_(tdict).tool_process_cmd_line_option) to indicate
1226893d65852940741dbebbc6ba1480e89cf34e30fsewardj   that.  This function prints an error message, then shuts down the
1236893d65852940741dbebbc6ba1480e89cf34e30fsewardj   entire system. */
1243ed1971497f0d58f894ed6a61c30ea3a79b69a25njn__attribute__((noreturn))
1256893d65852940741dbebbc6ba1480e89cf34e30fsewardjextern void VG_(err_bad_option) ( Char* opt );
1266893d65852940741dbebbc6ba1480e89cf34e30fsewardj
127374a36dbfb6d08ed8d77c31a88e198a861ffadf0njn/* Used to expand file names.  'option_name" is the option name, eg.
128374a36dbfb6d08ed8d77c31a88e198a861ffadf0njn   "--log-file".  'format' is what follows, eg. "cachegrind.out.%p".  In
129374a36dbfb6d08ed8d77c31a88e198a861ffadf0njn   'format':
130374a36dbfb6d08ed8d77c31a88e198a861ffadf0njn   - "%p" is replaced with PID.
131374a36dbfb6d08ed8d77c31a88e198a861ffadf0njn   - "%q{QUAL}" is replaced with the environment variable $QUAL.  If $QUAL
132374a36dbfb6d08ed8d77c31a88e198a861ffadf0njn     isn't set, we abort.  If the "{QUAL}" part is malformed, we abort.
133374a36dbfb6d08ed8d77c31a88e198a861ffadf0njn   - "%%" is replaced with "%".
134374a36dbfb6d08ed8d77c31a88e198a861ffadf0njn   Anything else after '%' causes an abort.
1352dd08f575042c604cebf32f2c2002a0fba0ed800njn   If the format specifies a relative file name, it's put in the program's
1362dd08f575042c604cebf32f2c2002a0fba0ed800njn   initial working directory.  If it specifies an absolute file name (ie.
1372dd08f575042c604cebf32f2c2002a0fba0ed800njn   starts with '/') then it is put there.
138374a36dbfb6d08ed8d77c31a88e198a861ffadf0njn*/
139374a36dbfb6d08ed8d77c31a88e198a861ffadf0njnextern Char* VG_(expand_file_name)(Char* option_name, Char* format);
1406893d65852940741dbebbc6ba1480e89cf34e30fsewardj
1412024234c590f408994b373abfb00bc2cd2a90c48njn#endif   // __PUB_TOOL_OPTIONS_H
1422024234c590f408994b373abfb00bc2cd2a90c48njn
1432024234c590f408994b373abfb00bc2cd2a90c48njn/*--------------------------------------------------------------------*/
1442024234c590f408994b373abfb00bc2cd2a90c48njn/*--- end                                                          ---*/
1452024234c590f408994b373abfb00bc2cd2a90c48njn/*--------------------------------------------------------------------*/
146