File: pub_tool_options.h

package info (click to toggle)
valgrind 1%3A3.25.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 180,392 kB
  • sloc: ansic: 827,945; exp: 26,134; xml: 23,776; asm: 14,769; cpp: 9,431; makefile: 7,680; sh: 6,687; perl: 5,451; python: 1,498; javascript: 981; awk: 166; csh: 1
file content (450 lines) | stat: -rw-r--r-- 21,607 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450

/*--------------------------------------------------------------------*/
/*--- Command line options.                     pub_tool_options.h ---*/
/*--------------------------------------------------------------------*/

/*
   This file is part of Valgrind, a dynamic binary instrumentation
   framework.

   Copyright (C) 2000-2017 Julian Seward
      jseward@acm.org

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, see <http://www.gnu.org/licenses/>.

   The GNU General Public License is contained in the file COPYING.
*/

#ifndef __PUB_TOOL_OPTIONS_H
#define __PUB_TOOL_OPTIONS_H

#include "pub_tool_basics.h"     // for VG_ macro
#include "pub_tool_libcbase.h"   // for VG__ str functions
#include "pub_tool_libcprint.h"  // for VG_(fmsg_bad_option)
#include "libvex.h"              // for VexControl

// Command line option parsing happens in the following modes:
//   cloE : Early processing, used by coregrind m_main.c to parse the
//      command line  options that must be handled early on.
//   cloP : Processing,  used by coregrind and tools during startup, when
//      doing command line options Processing.
//   clodD : Dynamic, used to dynamically change options after startup.
//      A subset of the command line options can be changed dynamically
//      after startup.
//   cloH : Help, special mode to produce the list of dynamically changeable
//      options for --help-dyn-options.
typedef
   enum {
      cloE = 1,
      cloP = 2,
      cloD = 4,
      cloH = 8
   } Clo_Mode;

// Defines often used mode sets, e.g. for options used in several modes.
#define cloEP (cloE | cloP)
#define cloED (cloE | cloD)
#define cloPD (cloP | cloD)

// Sets and gets the current option parsing mode.
// VG_(set_Clo_Mode) also resets the value of VG_(Clo_Recognised) to False.
void VG_(set_Clo_Mode) (Clo_Mode mode);

Clo_Mode VG_(Clo_Mode) (void);

// This is called by the various macros below to indicate that
// the currently parsed option has been recognised.
void VG_(set_Clo_Recognised) (void);
Bool VG_(Clo_Recognised) (void);


/* Once the system is started up, the dynamic options can be changed
   (mode CloD) or listed (mode cloH) using the below.  */
void VG_(process_dynamic_option) (Clo_Mode mode, HChar *value);

// Macros below are calling VG_(check_clom) to handle an option according
// to the current Clo_Mode.
// If recognised, it marks the option as recognised, and then returns True
// if the current mode matches the modes allowed for this option,
// False if option should not be processed according to current mode
// and qq_mode.
// It produces a warning if mode is cloD and cloD is not allowed by
// modes.  If current mode is cloH, CHECK_CLOM calls VG_(list_clo) if cloD
// is allowed by modes.
Bool VG_(check_clom) (Clo_Mode modes, const HChar* arg, const HChar* option,
                      Bool recognised);

// Higher-level command-line option recognisers;  use in if/else chains. 
// Note that they assign a value to the 'qq_var' argument.  So often they
// can be used like this:
//
//   if VG_STR_CLO(arg, "--foo", clo_foo) { }
//
// But if you want to do further checking or processing, you can do this:
//
//   if VG_STR_CLO(arg, "--foo", clo_foo) { <checking or processing> }
//
// The recognisers above are only modifying their argument in the relevant
// parsing mode (by default, only during cloP mode).
// If an option is handled during other modes than cloP, use the *M
// variants of the recognisers to specify the mode.
//
// They use GNU statement expressions to do the qq_var assignment within a
// conditional expression.

// Used to produce the list of dynamically changeable options.
extern void VG_(list_clo)(const HChar *qq_option);

// True if current option parsing mode matches qq_mode
// and the first qq_len characters of qq_arg match qq_option.
#define VG_STREQN_CLOM(qq_mode, qq_len, qq_arg, qq_option) \
   (VG_(check_clom)                                        \
    (qq_mode, qq_arg, qq_option,                           \
     VG_STREQN(qq_len, qq_arg, qq_option)))

// True if current option parsing mode matches qq_mode
// and qq_arg match qq_option.
#define VG_STREQ_CLOM(qq_mode, qq_arg, qq_option)       \
   (VG_(check_clom)                                     \
    (qq_mode, qq_arg, qq_option,                        \
     VG_STREQ(qq_arg, qq_option)))

static inline
Bool VG_(bool_clom)(Clo_Mode qq_mode, const HChar* qq_arg, const HChar* qq_option, Bool* qq_var, Bool qq_vareq_arg)
{
   Bool res = False;
   if (VG_(check_clom)(qq_mode, qq_arg, qq_option, qq_vareq_arg))
   {
      const HChar* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ];
      if (VG_(strcmp)(val, "yes") == 0)
      {
         *qq_var = True;
         res = True;
      }
      else if (VG_(strcmp)(val, "no") == 0)
      {
         *qq_var = False;
         res = True;
      }
      else
      {
         VG_(fmsg_bad_option)(qq_arg, "Invalid boolean value '%s'"
                                      " (should be 'yes' or 'no')\n",
          /* gcc 10 (20200119) complains that |val| could be null here. */
          /* I think it is wrong, but anyway, to placate it .. */
                                              (val ? val : "(null)"));
      }
   } else if (VG_STREQN(VG_(strlen)(qq_option), qq_arg, qq_option) &&
              VG_(strlen)(qq_option) == VG_(strlen)(qq_arg))
   {
      VG_(fmsg_bad_option)(qq_arg,
                           "Missing boolean value, did you mean '%s=yes'?\n",
                           qq_arg);
   }

   return res;
}

// String argument, eg. --foo=yes or --foo=no
#define VG_BOOL_CLOM(qq_mode, qq_arg, qq_option, qq_var)        \
   (VG_(bool_clom)((qq_mode), (qq_arg), (qq_option), &(qq_var), \
   VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"="))   \
   )

#define VG_BOOL_CLO(qq_arg, qq_option, qq_var) \
   VG_BOOL_CLOM(cloP, qq_arg, qq_option, qq_var)

// String argument, eg. --foo=bar
#define VG_STR_CLOM(qq_mode, qq_arg, qq_option, qq_var)                 \
   (VG_(check_clom)                                                     \
    (qq_mode, qq_arg, qq_option,                                        \
     VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) &&      \
    ({const HChar* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ];         \
      (qq_var) = val;                                                   \
      True; }))

#define VG_STR_CLO(qq_arg, qq_option, qq_var) \
   VG_STR_CLOM(cloP, qq_arg, qq_option, qq_var)

// UInt enum set arg, eg. --foo=fubar,bar,baz or --foo=none
// or --foo=all  (if qq_all is True)
#define VG_USETGEN_CLOM(qq_mode, qq_arg, qq_option, qq_vals, qq_var, qq_all) \
   (VG_(check_clom)                                                     \
    (qq_mode, qq_arg, qq_option,                                        \
     VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) &&      \
    ({Bool res = True;                                                  \
       const HChar* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ];        \
      if (!VG_(parse_enum_set)(qq_vals,                                 \
                               qq_all,/*allow_all*/                     \
                               val,                                     \
                               &(qq_var))) {                            \
         VG_(fmsg_bad_option)(qq_arg, "%s is an invalid %s set\n",      \
                              val, &qq_option[2]);                        \
         res = False; }                                                 \
      res; }))

// UInt enum set arg, eg. --foo=fubar,bar,baz or --foo=none or --foo=all
#define VG_USET_CLO(qq_arg, qq_option, qq_vals, qq_var) \
   VG_USETGEN_CLOM(cloP, (qq_arg), qq_option, (qq_vals), (qq_var), True)
#define VG_USET_CLOM(qq_mode, qq_arg, qq_option, qq_vals, qq_var) \
   VG_USETGEN_CLOM(qq_mode, (qq_arg), qq_option, (qq_vals), (qq_var), True)

/* Same as VG_USET_CLO but not allowing --foo=all.
   To be used when some or all of the enum set are mutually eXclusive. */
#define VG_USETX_CLO(qq_arg, qq_option, qq_vals, qq_var) \
   VG_USETGEN_CLOM(cloP, (qq_arg), qq_option, (qq_vals), (qq_var), False)
#define VG_USETX_CLOM(qq_mode, qq_arg, qq_option, qq_vals, qq_var) \
   VG_USETGEN_CLOM(qq_mode, (qq_arg), qq_option, (qq_vals), (qq_var), False)

// Unbounded integer arg, eg. --foo=10
#define VG_INT_CLOM(qq_mode, qq_arg, qq_option, qq_var)                 \
   (VG_(check_clom)                                                     \
    (qq_mode, qq_arg, qq_option,                                        \
     VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) &&      \
    ({Bool res = True;                                                  \
      const HChar* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ];         \
      HChar* s;                                                         \
      Long n = VG_(strtoll10)( val, &s );                               \
      (qq_var) = n;                                                     \
      /* Check for non-numeralness, or overflow. */                     \
      if ('\0' != s[0] || (qq_var) != n) {                              \
         VG_(fmsg_bad_option)(qq_arg,                                   \
                              "Invalid integer value '%s'\n", val);     \
         res = False; }                                                 \
      res; }))

#define VG_INT_CLO(qq_arg, qq_option, qq_var) \
   VG_INT_CLOM(cloP, qq_arg, qq_option, qq_var)

// Bounded integer arg, eg. --foo=10 ;  if the value exceeds the bounds it
// causes an abort.  'qq_base' can be 10 or 16.
#define VG_BINTN_CLOM(qq_mode, qq_base, qq_arg, qq_option, qq_var, qq_lo, qq_hi) \
   (VG_(check_clom)                                                     \
    (qq_mode, qq_arg, qq_option,                                        \
     VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) &&      \
    ({Bool res = True;                                                  \
      const HChar* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ];         \
      HChar* s;                                                         \
      Long n = VG_(strtoll##qq_base)( val, &s );                        \
      (qq_var) = n;                                                     \
      /* MMM: separate the two cases, and explain the problem;  likewise */ \
      /* for all the other macros in this file. */                      \
      /* Check for non-numeralness, or overflow. */                     \
      /* Nb: it will overflow if qq_var is unsigned and qq_val is negative! */ \
      if ('\0' != s[0] || (qq_var) != n) {                              \
         VG_(fmsg_bad_option)(qq_arg,                                   \
                              "Invalid integer value '%s'\n", val);     \
         res = False; }                                                 \
      /* Check bounds. */                                               \
      if ((qq_var) < (qq_lo) || (qq_var) > (qq_hi)) {                   \
         VG_(fmsg_bad_option)(qq_arg,                                   \
            "'%s' argument must be between %lld and %lld\n",            \
                              (qq_option), (Long)(qq_lo), (Long)(qq_hi)); \
         res = False;                                                  \
      }                                                                \
      res;}))

// As above, but for unsigned int arguments with a lower bound of 0
#define VG_BUINTN_CLOM(qq_mode, qq_base, qq_arg, qq_option, qq_var, qq_hi) \
(VG_(check_clom)                                                     \
 (qq_mode, qq_arg, qq_option,                                        \
  VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) &&      \
 ({Bool res = True;                                                  \
      const HChar* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ];         \
      HChar* s;                                                         \
      Long n = VG_(strtoll##qq_base)( val, &s );                        \
      (qq_var) = n;                                                     \
      if ('\0' != s[0] || (qq_var) != n) {                              \
         VG_(fmsg_bad_option)(qq_arg,                                   \
                              "Invalid integer value '%s'\n", val);     \
         res = False; }                                                 \
      /* Check bounds. */                                               \
      if ((qq_var) > (qq_hi)) {                                         \
         VG_(fmsg_bad_option)(qq_arg,                                   \
            "'%s' argument must be <= %lld\n",            \
                              (qq_option), (Long)(qq_hi));              \
         res = False;                                                  \
      }                                                                \
      res;}))

// Bounded decimal integer arg, eg. --foo=100
#define VG_BINT_CLO(qq_arg, qq_option, qq_var, qq_lo, qq_hi) \
   VG_BINTN_CLOM(cloP, 10, (qq_arg), qq_option, (qq_var), (qq_lo), (qq_hi))
#define VG_BINT_CLOM(qq_mode, qq_arg, qq_option, qq_var, qq_lo, qq_hi) \
   VG_BINTN_CLOM(qq_mode, 10, (qq_arg), qq_option, (qq_var), (qq_lo), (qq_hi))
#define VG_BUINT_CLOM(qq_mode, qq_arg, qq_option, qq_var, qq_hi) \
   VG_BUINTN_CLOM(qq_mode, 10, (qq_arg), qq_option, (qq_var), (qq_hi))

// Bounded hexadecimal integer arg, eg. --foo=0x1fa8
#define VG_BHEX_CLO(qq_arg, qq_option, qq_var, qq_lo, qq_hi) \
   VG_BINTN_CLOM(cloP, 16, (qq_arg), qq_option, (qq_var), (qq_lo), (qq_hi))

// Double (decimal) arg, eg. --foo=4.6
// XXX: there's not VG_BDBL_CLO because we don't have a good way of printing
// floats at the moment!
#define VG_DBL_CLOM(qq_mode, qq_arg, qq_option, qq_var) \
   (VG_(check_clom)                                                     \
    (qq_mode, qq_arg, qq_option,                                        \
     VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) &&      \
    ({Bool res = True;                                                  \
      const HChar* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ];         \
      HChar* s;                                                         \
      double n = VG_(strtod)( val, &s );                                \
      (qq_var) = n;                                                     \
      /* Check for non-numeralness */                                   \
      if ('\0' != s[0]) {                                               \
         VG_(fmsg_bad_option)(qq_arg,                                   \
                              "Invalid floating point value '%s'\n",val); \
         res = False; }                                                 \
      res;}))

#define VG_DBL_CLO( qq_arg, qq_option, qq_var) \
   VG_DBL_CLOM(cloP, qq_arg, qq_option, qq_var)

// Arg whose value is denoted by the exact presence of the given string;
// if it matches, qq_var is assigned the value in qq_val.
#define VG_XACT_CLOM(qq_mode, qq_arg, qq_option, qq_var, qq_val) \
   (VG_(check_clom) \
    (qq_mode, qq_arg, qq_option,                                \
     VG_STREQ((qq_arg), (qq_option))) &&                        \
    ({(qq_var) = (qq_val);                                      \
       True; }))

#define VG_XACT_CLO(qq_arg, qq_option, qq_var, qq_val) \
   VG_XACT_CLOM(cloP, qq_arg, qq_option, qq_var, qq_val)

// Arg that can be one of a set of strings, as specified in an NULL
// terminated array.  Returns the index of the string in |qq_ix|, or
// aborts if not found.
#define VG_STRINDEX_CLOM(qq_mode, qq_arg, qq_option, qq_strings, qq_ix) \
   (VG_(check_clom)                                                     \
    (qq_mode, qq_arg, qq_option,                                        \
     VG_STREQN(VG_(strlen)(qq_option)+1, qq_arg, qq_option"=")) &&      \
    ({Bool res = True;                                                  \
      const HChar* val = &(qq_arg)[ VG_(strlen)(qq_option)+1 ];         \
      for (qq_ix = 0; (qq_strings)[qq_ix]; qq_ix++) {                   \
         if (VG_STREQ(val, (qq_strings)[qq_ix]))                        \
            break;                                                      \
      }                                                                 \
      if ((qq_strings)[qq_ix] == NULL) {                                \
         VG_(fmsg_bad_option)(qq_arg,                                   \
                              "Invalid string '%s' in '%s'\n", val, qq_arg); \
         res = False;                                                   \
      } \
      res; }))

#define VG_STRINDEX_CLO(qq_arg, qq_option, qq_strings, qq_ix) \
   VG_STRINDEX_CLOM(cloP, qq_arg, qq_option, qq_strings, qq_ix)

/* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */
extern Int  VG_(clo_verbosity);

/* Show tool and core statistics */
extern Bool VG_(clo_stats);

/* wait for vgdb/gdb after reporting that amount of error.
   Note that this value can be changed dynamically. */
extern Int VG_(clo_vgdb_error);

/* Set by vgdb in --multi mode when launching valgrind. This suppresses
   the "TO DEBUG" banner because vgdb will take care of attaching in that
   case.  */
extern Bool VG_(clo_launched_with_multi);

/* If user has provided the --vgdb-prefix command line option,
   VG_(arg_vgdb_prefix) points at the provided argument (including the
   '--vgdb-prefix=' string).
   Otherwise, it is NULL.
   Typically, this is used by tools to produce user message with the
   expected vgdb prefix argument, if the user has changed the default. */
extern const HChar *VG_(arg_vgdb_prefix);

/* Emit all messages as XML? default: NO */
/* If clo_xml is set, various other options are set in a non-default
   way.  See vg_main.c and mc_main.c. */
extern Bool VG_(clo_xml);

/* An arbitrary user-supplied string which is copied into the
   XML output, in between <usercomment> tags. */
extern const HChar* VG_(clo_xml_user_comment);

/* Vex iropt control.  Tool-visible so tools can make Vex optimise
   less aggressively if that is needed (callgrind needs this). */
extern VexControl VG_(clo_vex_control);
extern VexRegisterUpdates VG_(clo_px_file_backed);

extern Int VG_(clo_redzone_size);

typedef
   enum {
      Vg_XTMemory_None,   // Do not do any xtree memory profiling.
      Vg_XTMemory_Allocs, // Currently allocated size xtree memory profiling
      Vg_XTMemory_Full,   // Full profiling : Current allocated size, total
      // allocated size, nr of blocks, total freed size, ...
   }
   VgXTMemory;
// Tools that replace malloc can optionally implement memory profiling
// following the value of VG_(clo_xtree_profile_memory) to produce a report
// at the end of execution.
extern VgXTMemory VG_(clo_xtree_memory);
/* Holds the filename to use for xtree memory profiling output, before expansion
   of %p and %q templates. */
extern const HChar* VG_(clo_xtree_memory_file);
/* Compress strings in xtree dumps. */
extern Bool VG_(clo_xtree_compress_strings);

/* Number of parents of a backtrace.  Default: 12  */
extern Int   VG_(clo_backtrace_size);

/* Continue stack traces below main()?  Default: NO */
extern Bool VG_(clo_show_below_main);

/* Keep symbols (and all other debuginfo) for code that is unloaded (dlclose
   or similar) so that stack traces can still give line/file info for
   previously captured stack traces.  e.g. ... showing where a block was
   allocated e.g. leaks of or accesses just outside a block. */
extern Bool VG_(clo_keep_debuginfo);

/* Track open file descriptors? 0 = No, 1 = Yes, 2 = All (including std)  */
extern UInt  VG_(clo_track_fds);

extern UInt  VG_(clo_modify_fds);


/* Used to expand file names.  "option_name" is the option name, eg.
   "--log-file".  'format' is what follows, eg. "cachegrind.out.%p".  In
   'format':
   - "%p" is replaced with PID.
   - "%q{QUAL}" is replaced with the environment variable $QUAL.  If $QUAL
     isn't set, we abort.  If the "{QUAL}" part is malformed, we abort.
   - "%%" is replaced with "%".
   Anything else after '%' causes an abort.
   If the format specifies a relative file name, it's put in the program's
   initial working directory.  If it specifies an absolute file name (ie.
   starts with '/') then it is put there.

   Note that "option_name" has no effect on the returned string: the
   returned string depends only on "format" and the PIDs and
   environment variables that it references (if any). "option_name" is
   merely used in printing error messages, if an error message needs
   to be printed due to malformedness of the "format" argument.
*/
extern HChar* VG_(expand_file_name)(const HChar* option_name,
                                    const HChar* format);

#endif   // __PUB_TOOL_OPTIONS_H

/*--------------------------------------------------------------------*/
/*--- end                                                          ---*/
/*--------------------------------------------------------------------*/