~ubuntu-branches/debian/sid/valgrind/sid

« back to all changes in this revision

Viewing changes to coregrind/m_options.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrés Roldán
  • Date: 2008-06-13 02:31:40 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080613023140-rezbg9gtvybimy2q
Tags: 1:3.3.1-2
* debian/rules:
  - Forgot to copy debian-libc6-dbg.supp to /usr/lib/valgrind. 
    (Closes: #486021)

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
   This file is part of Valgrind, a dynamic binary instrumentation
9
9
   framework.
10
10
 
11
 
   Copyright (C) 2000-2006 Nicholas Nethercote
 
11
   Copyright (C) 2000-2007 Nicholas Nethercote
12
12
      njn@valgrind.org
13
13
 
14
14
   This program is free software; you can redistribute it and/or
30
30
*/
31
31
 
32
32
#include "pub_core_basics.h"
 
33
#include "pub_core_vki.h"
33
34
#include "pub_core_options.h"
 
35
#include "pub_core_libcassert.h"
 
36
#include "pub_core_libcbase.h"
 
37
#include "pub_core_libcfile.h"
 
38
#include "pub_core_libcprint.h"
 
39
#include "pub_core_libcproc.h"
 
40
#include "pub_core_mallocfree.h"
34
41
 
35
42
// See pub_{core,tool}_options.h for explanations of all these.
36
43
 
48
55
HChar* VG_(clo_xml_user_comment) = NULL;
49
56
Bool   VG_(clo_demangle)       = True;
50
57
Bool   VG_(clo_trace_children) = False;
51
 
Int    VG_(clo_log_fd)         = 2;
 
58
Bool   VG_(clo_child_silent_after_fork) = False;
 
59
Int    VG_(clo_log_fd)         = 2; /* must be signed, as -1 is possible. */
52
60
Char*  VG_(clo_log_name)       = NULL;
53
 
Char*  VG_(clo_log_file_qualifier) = NULL;
54
61
Bool   VG_(clo_time_stamp)     = False;
55
62
Int    VG_(clo_input_fd)       = 0; /* stdin */
56
63
Int    VG_(clo_n_suppressions) = 0;
61
68
Bool   VG_(clo_trace_syscalls) = False;
62
69
Bool   VG_(clo_trace_signals)  = False;
63
70
Bool   VG_(clo_trace_symtab)   = False;
 
71
HChar* VG_(clo_trace_symtab_patt) = "*";
64
72
Bool   VG_(clo_trace_cfi)      = False;
 
73
Bool   VG_(clo_debug_dump_syms) = False;
 
74
Bool   VG_(clo_debug_dump_line) = False;
 
75
Bool   VG_(clo_debug_dump_frames) = False;
65
76
Bool   VG_(clo_trace_redir)    = False;
66
77
Bool   VG_(clo_trace_sched)    = False;
67
78
Bool   VG_(clo_trace_pthreads) = False;
68
79
Int    VG_(clo_dump_error)     = 0;
69
80
Int    VG_(clo_backtrace_size) = 12;
70
81
Char*  VG_(clo_sim_hints)      = NULL;
 
82
Bool   VG_(clo_sym_offsets)    = False;
71
83
Bool   VG_(clo_run_libc_freeres) = True;
72
84
Bool   VG_(clo_track_fds)      = False;
73
85
Bool   VG_(clo_show_below_main)= False;
74
 
Bool   VG_(clo_model_pthreads) = False;
75
86
Bool   VG_(clo_show_emwarns)   = False;
76
 
Int    VG_(clo_max_stackframe) = 2000000;
 
87
Word   VG_(clo_max_stackframe) = 2000000;
77
88
Bool   VG_(clo_wait_for_gdb)   = False;
78
89
VgSmc  VG_(clo_smc_check)      = Vg_SmcStack;
79
90
HChar* VG_(clo_kernel_variant) = NULL;
80
91
 
81
92
 
 
93
/*====================================================================*/
 
94
/*=== Command line errors                                          ===*/
 
95
/*====================================================================*/
 
96
 
 
97
static void revert_to_stderr ( void )
 
98
{
 
99
   vg_assert( !VG_(logging_to_socket) );
 
100
   VG_(clo_log_fd) = 2; /* stderr */
 
101
}
 
102
 
 
103
__attribute__((noreturn))
 
104
void VG_(err_bad_option) ( Char* opt )
 
105
{
 
106
   revert_to_stderr();
 
107
   VG_(printf)("valgrind: Bad option '%s'; aborting.\n", opt);
 
108
   VG_(printf)("valgrind: Use --help for more information.\n");
 
109
   VG_(exit)(1);
 
110
}
 
111
 
 
112
__attribute__((noreturn))
 
113
void VG_(err_missing_prog) ( void  )
 
114
{
 
115
   revert_to_stderr();
 
116
   VG_(printf)("valgrind: no program specified\n");
 
117
   VG_(printf)("valgrind: Use --help for more information.\n");
 
118
   VG_(exit)(1);
 
119
}
 
120
 
 
121
__attribute__((noreturn))
 
122
void VG_(err_config_error) ( Char* msg )
 
123
{
 
124
   revert_to_stderr();
 
125
   VG_(printf)("valgrind: Startup or configuration error:\n   %s\n", msg);
 
126
   VG_(printf)("valgrind: Unable to start up properly.  Giving up.\n");
 
127
   VG_(exit)(1);
 
128
}
 
129
 
 
130
// Copies the string, prepending it with the startup working directory, and
 
131
// expanding %p and %q entries.  Returns a new, malloc'd string.
 
132
Char* VG_(expand_file_name)(Char* option_name, Char* format)
 
133
{
 
134
   static Char base_dir[VKI_PATH_MAX];
 
135
   Int len, i = 0, j = 0;
 
136
   Char* out;
 
137
 
 
138
   Bool ok = VG_(get_startup_wd)(base_dir, VKI_PATH_MAX);
 
139
   tl_assert(ok);
 
140
 
 
141
   if (VG_STREQ(format, "")) {
 
142
      // Empty name, bad.
 
143
      VG_(message)(Vg_UserMsg, "%s: filename is empty", option_name);
 
144
      goto bad;
 
145
   }
 
146
 
 
147
   // If 'format' starts with a '/', do not prefix with startup dir.
 
148
   if (format[0] != '/') {
 
149
      j += VG_(strlen)(base_dir);
 
150
   }
 
151
 
 
152
   // The 10 is slop, it should be enough in most cases.
 
153
   len = j + VG_(strlen)(format) + 10;
 
154
   out = VG_(malloc)( len );
 
155
   if (format[0] != '/') {
 
156
      VG_(strcpy)(out, base_dir);
 
157
      out[j++] = '/';
 
158
   }
 
159
 
 
160
#define ENSURE_THIS_MUCH_SPACE(x) \
 
161
   if (j + x >= len) { \
 
162
      len += (10 + x); \
 
163
      out = VG_(realloc)(out, len); \
 
164
   }
 
165
 
 
166
   while (format[i]) {
 
167
      if (format[i] != '%') {
 
168
         ENSURE_THIS_MUCH_SPACE(1);
 
169
         out[j++] = format[i++];
 
170
         
 
171
      } else {
 
172
         // We saw a '%'.  What's next...
 
173
         i++;
 
174
         if      ('%' == format[i]) {
 
175
            // Replace '%%' with '%'.
 
176
            ENSURE_THIS_MUCH_SPACE(1);
 
177
            out[j++] = format[i++];
 
178
         }
 
179
         else if ('p' == format[i]) {
 
180
            // Print the PID.  Assume that it's not longer than 10 chars --
 
181
            // reasonable since 'pid' is an Int (ie. 32 bits).
 
182
            Int pid = VG_(getpid)();
 
183
            ENSURE_THIS_MUCH_SPACE(10);
 
184
            j += VG_(sprintf)(&out[j], "%d", pid);
 
185
            i++;
 
186
         } 
 
187
         else if ('q' == format[i]) {
 
188
            i++;
 
189
            if ('{' == format[i]) {
 
190
               // Get the env var name, print its contents.
 
191
               Char* qualname;
 
192
               Char* qual;
 
193
               i++;
 
194
               qualname = &format[i];
 
195
               while (True) {
 
196
                  if (0 == format[i]) {
 
197
                     VG_(message)(Vg_UserMsg, "%s: malformed %%q specifier",
 
198
                        option_name);
 
199
                     goto bad;
 
200
                  } else if ('}' == format[i]) {
 
201
                     // Temporarily replace the '}' with NUL to extract var
 
202
                     // name.
 
203
                     format[i] = 0;
 
204
                     qual = VG_(getenv)(qualname);
 
205
                     if (NULL == qual) {
 
206
                        VG_(message)(Vg_UserMsg,
 
207
                           "%s: environment variable %s is not set",
 
208
                           option_name, qualname);
 
209
                        format[i] = '}';  // Put the '}' back.
 
210
                        goto bad;
 
211
                     }
 
212
                     format[i] = '}';     // Put the '}' back.
 
213
                     i++;
 
214
                     break;
 
215
                  }
 
216
                  i++;
 
217
               }
 
218
               ENSURE_THIS_MUCH_SPACE(VG_(strlen)(qual));
 
219
               j += VG_(sprintf)(&out[j], "%s", qual);
 
220
            } else {
 
221
               VG_(message)(Vg_UserMsg,
 
222
                  "%s: expected '{' after '%%q'", option_name);
 
223
               goto bad;
 
224
            }
 
225
         } 
 
226
         else {
 
227
            // Something else, abort.
 
228
            VG_(message)(Vg_UserMsg,
 
229
               "%s: expected 'p' or 'q' or '%%' after '%%'", option_name);
 
230
            goto bad;
 
231
         }
 
232
      }
 
233
   }
 
234
   ENSURE_THIS_MUCH_SPACE(1);
 
235
   out[j++] = 0;
 
236
 
 
237
   return out;
 
238
 
 
239
  bad: {
 
240
   Char* opt =    // 2:  1 for the '=', 1 for the NUL.
 
241
      VG_(malloc)( VG_(strlen)(option_name) + VG_(strlen)(format) + 2 );
 
242
   VG_(strcpy)(opt, option_name);
 
243
   VG_(strcat)(opt, "=");
 
244
   VG_(strcat)(opt, format);
 
245
   VG_(err_bad_option)(opt);
 
246
  }
 
247
}
 
248
 
 
249
 
 
250
 
82
251
/*--------------------------------------------------------------------*/
83
252
/*--- end                                              m_options.c ---*/
84
253
/*--------------------------------------------------------------------*/