-
Notifications
You must be signed in to change notification settings - Fork 3
/
session.cxx
2421 lines (2189 loc) · 84.1 KB
/
session.cxx
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
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// session functions
// Copyright (C) 2010-2013 Red Hat Inc.
//
// This file is part of systemtap, and is free software. You can
// redistribute it and/or modify it under the terms of the GNU General
// Public License (GPL); either version 2, or (at your option) any
// later version.
#include "config.h"
#include "session.h"
#include "cache.h"
#include "stapregex.h"
#include "elaborate.h"
#include "translate.h"
#include "buildrun.h"
#include "coveragedb.h"
#include "hash.h"
#include "task_finder.h"
#include "csclient.h"
#include "rpm_finder.h"
#include "util.h"
#include "cmdline.h"
#include "git_version.h"
#include "version.h"
#include <cerrno>
#include <cstdlib>
extern "C" {
#include <getopt.h>
#include <limits.h>
#include <grp.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <sys/resource.h>
#include <elfutils/libdwfl.h>
#include <unistd.h>
#include <sys/wait.h>
}
#if HAVE_NSS
extern "C" {
#include <nspr.h>
}
#endif
#include <string>
using namespace std;
/* getopt variables */
extern int optind;
#define PATH_TBD string("__TBD__")
#if HAVE_NSS
bool systemtap_session::NSPR_Initialized = false;
#endif
systemtap_session::systemtap_session ():
// NB: pointer members must be manually initialized!
// NB: don't forget the copy constructor too!
runtime_mode(kernel_runtime),
base_hash(0),
pattern_root(new match_node),
user_file (0),
dfa_counter (0),
dfa_maxstate (0),
dfa_maxtag (0),
need_tagged_dfa (false),
be_derived_probes(0),
dwarf_derived_probes(0),
kprobe_derived_probes(0),
hwbkpt_derived_probes(0),
perf_derived_probes(0),
uprobe_derived_probes(0),
utrace_derived_probes(0),
itrace_derived_probes(0),
task_finder_derived_probes(0),
timer_derived_probes(0),
netfilter_derived_probes(0),
profile_derived_probes(0),
mark_derived_probes(0),
tracepoint_derived_probes(0),
hrtimer_derived_probes(0),
procfs_derived_probes(0),
dynprobe_derived_probes(0),
java_derived_probes(0),
op (0), up (0),
sym_kprobes_text_start (0),
sym_kprobes_text_end (0),
sym_stext (0),
module_cache (0),
benchmark_sdt_loops(0),
benchmark_sdt_threads(0),
suppressed_warnings(0),
suppressed_errors(0),
warningerr_count(0),
last_token (0)
{
struct utsname buf;
(void) uname (& buf);
kernel_release = string (buf.release);
release = kernel_release;
kernel_build_tree = "/lib/modules/" + kernel_release + "/build";
architecture = machine = normalize_machine(buf.machine);
for (unsigned i=0; i<5; i++) perpass_verbose[i]=0;
verbose = 0;
have_script = false;
runtime_specified = false;
include_arg_start = -1;
timing = false;
guru_mode = false;
bulk_mode = false;
unoptimized = false;
suppress_warnings = false;
panic_warnings = false;
listing_mode = false;
listing_mode_vars = false;
dump_probe_types = false;
#ifdef ENABLE_PROLOGUES
prologue_searching = true;
#else
prologue_searching = false;
#endif
buffer_size = 0;
last_pass = 5;
module_name = "stap_" + lex_cast(getpid());
stapconf_name = "stapconf_" + lex_cast(getpid()) + ".h";
output_file = ""; // -o FILE
tmpdir_opt_set = false;
save_module = false;
modname_given = false;
keep_tmpdir = false;
cmd = "";
target_pid = 0;
use_cache = true;
use_script_cache = true;
poison_cache = false;
tapset_compile_coverage = false;
need_uprobes = false;
need_unwind = false;
need_symbols = false;
uprobes_path = "";
load_only = false;
skip_badvars = false;
privilege = pr_stapdev;
privilege_set = false;
omit_werror = false;
compatible = VERSION; // XXX: perhaps also process GIT_SHAID if available?
unwindsym_ldd = false;
client_options = false;
server_cache = NULL;
automatic_server_mode = false;
use_server_on_error = false;
try_server_status = try_server_unset;
use_remote_prefix = false;
systemtap_v_check = false;
download_dbinfo = 0;
suppress_handler_errors = false;
native_build = true; // presumed
sysroot = "";
update_release_sysroot = false;
suppress_time_limits = false;
color_mode = color_auto;
color_errors = isatty(STDERR_FILENO) // conditions for coloring when
&& strcmp(getenv("TERM") ?: "notdumb", "dumb"); // on auto
// PR12443: put compiled-in / -I paths in front, to be preferred during
// tapset duplicate-file elimination
const char* s_p = getenv ("SYSTEMTAP_TAPSET");
if (s_p != NULL)
{
include_path.push_back (s_p);
}
else
{
include_path.push_back (string(PKGDATADIR) + "/tapset");
}
/* adding in the XDG_DATA_DIRS variable path,
* this searches in conjunction with SYSTEMTAP_TAPSET
* to locate stap scripts, either can be disabled if
* needed using env $PATH=/dev/null where $PATH is the
* path you want disabled
*/
const char* s_p1 = getenv ("XDG_DATA_DIRS");
if ( s_p1 != NULL )
{
vector<string> dirs;
tokenize(s_p1, dirs, ":");
for(vector<string>::iterator i = dirs.begin(); i != dirs.end(); ++i)
{
include_path.push_back(*i + "/systemtap/tapset");
}
}
const char* s_r = getenv ("SYSTEMTAP_RUNTIME");
if (s_r != NULL)
runtime_path = s_r;
else
runtime_path = string(PKGDATADIR) + "/runtime";
const char* s_d = getenv ("SYSTEMTAP_DIR");
if (s_d != NULL)
data_path = s_d;
else
data_path = get_home_directory() + string("/.systemtap");
if (create_dir(data_path.c_str()) == 1)
{
const char* e = strerror (errno);
print_warning("failed to create systemtap data directory \"" + data_path + "\" " + e + ", disabling cache support.");
use_cache = use_script_cache = false;
}
if (use_cache)
{
cache_path = data_path + "/cache";
if (create_dir(cache_path.c_str()) == 1)
{
const char* e = strerror (errno);
print_warning("failed to create cache directory (\" " + cache_path + " \") " + e + ", disabling cache support.");
use_cache = use_script_cache = false;
}
}
const char* s_tc = getenv ("SYSTEMTAP_COVERAGE");
if (s_tc != NULL)
tapset_compile_coverage = true;
const char* s_kr = getenv ("SYSTEMTAP_RELEASE");
if (s_kr != NULL) {
setup_kernel_release(s_kr);
}
create_tmp_dir();
}
systemtap_session::systemtap_session (const systemtap_session& other,
const string& arch,
const string& kern):
// NB: pointer members must be manually initialized!
// NB: this needs to consider everything that the base ctor does,
// plus copying any wanted implicit fields (strings, vectors, etc.)
runtime_mode(other.runtime_mode),
base_hash(0),
pattern_root(new match_node),
user_file (other.user_file),
dfa_counter(0),
need_tagged_dfa(other.need_tagged_dfa),
be_derived_probes(0),
dwarf_derived_probes(0),
kprobe_derived_probes(0),
hwbkpt_derived_probes(0),
perf_derived_probes(0),
uprobe_derived_probes(0),
utrace_derived_probes(0),
itrace_derived_probes(0),
task_finder_derived_probes(0),
timer_derived_probes(0),
netfilter_derived_probes(0),
profile_derived_probes(0),
mark_derived_probes(0),
tracepoint_derived_probes(0),
hrtimer_derived_probes(0),
procfs_derived_probes(0),
dynprobe_derived_probes(0),
java_derived_probes(0),
op (0), up (0),
sym_kprobes_text_start (0),
sym_kprobes_text_end (0),
sym_stext (0),
module_cache (0),
benchmark_sdt_loops(other.benchmark_sdt_loops),
benchmark_sdt_threads(other.benchmark_sdt_threads),
suppressed_warnings(0),
suppressed_errors(0),
warningerr_count(0),
last_token (0)
{
release = kernel_release = kern;
kernel_build_tree = "/lib/modules/" + kernel_release + "/build";
architecture = machine = normalize_machine(arch);
setup_kernel_release(kern.c_str());
native_build = false; // assumed; XXX: could be computed as in check_options()
// These are all copied in the same order as the default ctor did above.
copy(other.perpass_verbose, other.perpass_verbose + 5, perpass_verbose);
verbose = other.verbose;
have_script = other.have_script;
runtime_specified = other.runtime_specified;
include_arg_start = other.include_arg_start;
timing = other.timing;
guru_mode = other.guru_mode;
bulk_mode = other.bulk_mode;
unoptimized = other.unoptimized;
suppress_warnings = other.suppress_warnings;
panic_warnings = other.panic_warnings;
listing_mode = other.listing_mode;
listing_mode_vars = other.listing_mode_vars;
dump_probe_types = other.dump_probe_types;
prologue_searching = other.prologue_searching;
buffer_size = other.buffer_size;
last_pass = other.last_pass;
module_name = other.module_name;
stapconf_name = other.stapconf_name;
output_file = other.output_file; // XXX how should multiple remotes work?
tmpdir_opt_set = false;
save_module = other.save_module;
modname_given = other.modname_given;
keep_tmpdir = other.keep_tmpdir;
cmd = other.cmd;
target_pid = other.target_pid; // XXX almost surely nonsense for multiremote
use_cache = other.use_cache;
use_script_cache = other.use_script_cache;
poison_cache = other.poison_cache;
tapset_compile_coverage = other.tapset_compile_coverage;
need_uprobes = false;
need_unwind = false;
need_symbols = false;
uprobes_path = "";
load_only = other.load_only;
skip_badvars = other.skip_badvars;
privilege = other.privilege;
privilege_set = other.privilege_set;
omit_werror = other.omit_werror;
compatible = other.compatible;
unwindsym_ldd = other.unwindsym_ldd;
client_options = other.client_options;
server_cache = NULL;
use_server_on_error = other.use_server_on_error;
try_server_status = other.try_server_status;
use_remote_prefix = other.use_remote_prefix;
systemtap_v_check = other.systemtap_v_check;
download_dbinfo = other.download_dbinfo;
suppress_handler_errors = other.suppress_handler_errors;
sysroot = other.sysroot;
update_release_sysroot = other.update_release_sysroot;
sysenv = other.sysenv;
suppress_time_limits = other.suppress_time_limits;
color_errors = other.color_errors;
color_mode = other.color_mode;
include_path = other.include_path;
runtime_path = other.runtime_path;
// NB: assuming that "other" created these already
data_path = other.data_path;
cache_path = other.cache_path;
tapset_compile_coverage = other.tapset_compile_coverage;
// These are fields that were left to their default ctor, but now we want to
// copy them from "other". In the same order as declared...
script_file = other.script_file;
cmdline_script = other.cmdline_script;
c_macros = other.c_macros;
args = other.args;
kbuildflags = other.kbuildflags;
globalopts = other.globalopts;
modinfos = other.modinfos;
client_options_disallowed_for_unprivileged = other.client_options_disallowed_for_unprivileged;
server_status_strings = other.server_status_strings;
specified_servers = other.specified_servers;
server_trust_spec = other.server_trust_spec;
server_args = other.server_args;
unwindsym_modules = other.unwindsym_modules;
automatic_server_mode = other.automatic_server_mode;
create_tmp_dir();
}
systemtap_session::~systemtap_session ()
{
remove_tmp_dir();
delete_map(subsessions);
delete pattern_root;
}
const string
systemtap_session::module_filename() const
{
if (runtime_usermode_p())
return module_name + ".so";
return module_name + ".ko";
}
#if HAVE_NSS
void
systemtap_session::NSPR_init ()
{
if (! NSPR_Initialized)
{
PR_Init (PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 1);
NSPR_Initialized = true;
}
}
#endif // HAVE_NSS
systemtap_session*
systemtap_session::clone(const string& arch, const string& release)
{
const string norm_arch = normalize_machine(arch);
if (this->architecture == norm_arch && this->kernel_release == release)
return this;
systemtap_session*& s = subsessions[make_pair(norm_arch, release)];
if (!s)
s = new systemtap_session(*this, norm_arch, release);
return s;
}
void
systemtap_session::version ()
{
clog << _F("Systemtap translator/driver (version %s/%s, %s)\n"
"Copyright (C) 2005-2013 Red Hat, Inc. and others\n"
"This is free software; see the source for copying conditions.",
VERSION, dwfl_version(NULL), STAP_EXTENDED_VERSION) << endl;
clog << _("enabled features:")
#ifdef HAVE_AVAHI
<< " AVAHI"
#endif
#ifdef HAVE_LIBRPM
<< " LIBRPM"
#endif
#ifdef HAVE_LIBSQLITE3
<< " LIBSQLITE3"
#endif
#ifdef HAVE_NSS
<< " NSS"
#endif
#ifdef HAVE_BOOST_SHARED_PTR_HPP
<< " BOOST_SHARED_PTR"
#endif
#ifdef HAVE_TR1_UNORDERED_MAP
<< " TR1_UNORDERED_MAP"
#endif
#ifdef ENABLE_PROLOGUES
<< " PROLOGUES"
#endif
#ifdef ENABLE_NLS
<< " NLS"
#endif
#ifdef HAVE_DYNINST
<< " DYNINST"
#endif
#ifdef HAVE_JAVA
<< " JAVA"
#endif
#ifdef HAVE_LIBVIRT
<< " LIBVIRT"
#endif
#ifdef HAVE_LIBXML2
<< " LIBXML2"
#endif
<< endl;
}
void
systemtap_session::usage (int exitcode)
{
// For error cases, just suggest --help, so we don't obscure
// the actual error message with all the help text.
if (exitcode != EXIT_SUCCESS)
{
clog << _("Try '--help' for more information.") << endl;
throw exit_exception(exitcode);
}
version ();
clog
<< endl
<< _F("Usage: stap [options] FILE Run script in file.\n"
" or: stap [options] - Run script on stdin.\n"
" or: stap [options] -e SCRIPT Run given script.\n"
" or: stap [options] -l PROBE List matching probes.\n"
" or: stap [options] -L PROBE List matching probes and local variables.\n\n"
"Options (in %s/rc and on command line):\n"
" -- end of translator options, script options follow\n"
" -h --help show help\n"
" -V --version show version\n"
" -p NUM stop after pass NUM 1-5, instead of %d\n"
" (parse, elaborate, translate, compile, run)\n"
" -v add verbosity to all passes\n"
" --vp {N}+ add per-pass verbosity [", data_path.c_str(), last_pass);
for (unsigned i=0; i<5; i++)
clog << (perpass_verbose[i] <= 9 ? perpass_verbose[i] : 9);
clog
<< "]" << endl;
clog << _F(" -k keep temporary directory\n"
" -u unoptimized translation %s\n"
" -w suppress warnings %s\n"
" -W turn warnings into errors %s\n"
" -g guru mode %s\n"
" -P prologue-searching for function probes %s\n"
" -b bulk (percpu file) mode %s\n"
" -s NUM buffer size in megabytes, instead of %d\n"
" -I DIR look in DIR for additional .stp script files", (unoptimized ? _(" [set]") : ""),
(suppress_warnings ? _(" [set]") : ""), (panic_warnings ? _(" [set]") : ""),
(guru_mode ? _(" [set]") : ""), (prologue_searching ? _(" [set]") : ""),
(bulk_mode ? _(" [set]") : ""), buffer_size);
if (include_path.size() == 0)
clog << endl;
else
clog << _(", in addition to") << endl;
for (unsigned i=0; i<include_path.size(); i++)
clog << " " << include_path[i].c_str() << endl;
clog
<< _F(" -D NM=VAL emit macro definition into generated C code\n"
" -B NM=VAL pass option to kbuild make\n"
" --modinfo NM=VAL\n"
" include a MODULE_INFO(NM,VAL) in the generated C code\n"
" -G VAR=VAL set global variable to value\n"
//TRANSLATORS: translating 'runtime' is not advised
" -R DIR look in DIR for runtime, instead of\n"
" %s\n"
" -r DIR cross-compile to kernel with given build tree; or else\n"
" -r RELEASE cross-compile to kernel /lib/modules/RELEASE/build, instead of\n"
" %s\n"
" -a ARCH cross-compile to given architecture, instead of %s\n"
" -m MODULE set probe module name, instead of \n"
" %s\n"
" -o FILE send script output to file, instead of stdout. This supports\n"
" strftime(3) formats for FILE\n"
" -c CMD start the probes, run CMD, and exit when it finishes\n"
" -x PID sets target() to PID\n"
" -F run as on-file flight recorder with -o.\n"
" run as on-memory flight recorder without -o.\n"
" -S size[,n] set maximum of the size and the number of files.\n"
" -d OBJECT add unwind/symbol data for OBJECT file", runtime_path.c_str(), kernel_build_tree.c_str(), architecture.c_str(), module_name.c_str());
if (unwindsym_modules.size() == 0)
clog << endl;
else
clog << _(", in addition to") << endl;
{
vector<string> syms (unwindsym_modules.begin(), unwindsym_modules.end());
for (unsigned i=0; i<syms.size(); i++)
clog << " " << syms[i].c_str() << endl;
}
clog
<< _F(" --ldd add unwind/symbol data for all referenced object files.\n"
" --all-modules\n"
" add unwind/symbol data for all loaded kernel objects.\n"
" -t collect probe timing information\n"
#ifdef HAVE_LIBSQLITE3
" -q generate information on tapset coverage\n"
#endif /* HAVE_LIBSQLITE3 */
" --runtime=MODE\n"
" set the pass-5 runtime mode, instead of kernel\n"
#ifdef HAVE_DYNINST
" --dyninst\n"
" shorthand for --runtime=dyninst\n"
#endif /* HAVE_DYNINST */
" --privilege=PRIVILEGE_LEVEL\n"
" check the script for constructs not allowed at the given privilege level\n"
" --unprivileged\n"
" equivalent to --privilege=stapusr\n"
" --compatible=VERSION\n"
" suppress incompatible language/tapset changes beyond VERSION,\n"
" instead of %s\n"
" --check-version\n"
" displays warnings where a syntax element may be \n"
" version dependent\n"
" --skip-badvars\n"
" substitute zero for bad context $variables\n"
" --suppress-handler-errors\n"
" catch all runtime errors, quietly skip probe handlers\n"
" --use-server[=SERVER-SPEC]\n"
" specify systemtap compile-servers\n"
" --list-servers[=PROPERTIES]\n"
" report on the status of the specified compile-servers:\n"
" all,specified,online,trusted,signer,compatible\n"
#if HAVE_NSS
" --trust-servers[=TRUST-SPEC]\n"
" add/revoke trust of specified compile-servers:\n"
" ssl,signer,all-users,revoke,no-prompt\n"
" --use-server-on-error[=yes/no]\n"
" retry compilation using a compile server upon compilation error\n"
#endif
" --remote=HOSTNAME\n"
" run pass 5 on the specified ssh host.\n"
" may be repeated for targeting multiple hosts.\n"
" --remote-prefix\n"
" prefix each line of remote output with a host index.\n"
" --tmpdir=NAME\n"
" specify name of temporary directory to be used.\n"
" --download-debuginfo[=OPTION]\n"
" automatically download debuginfo using ABRT.\n"
" yes,no,ask,<timeout value>\n"
" --dump-probe-types\n"
" show a list of available probe types.\n"
" --sysroot=DIR\n"
" specify sysroot directory where target files (executables,\n" " libraries, etc.) are located.\n"
" --sysenv=VAR=VALUE\n"
" provide an alternate value for an environment variable\n"
" where the value on a remote system differs. Path\n"
" variables (e.g. PATH, LD_LIBRARY_PATH) are assumed to be\n"
" relative to the sysroot.\n"
" --suppress-time-limits\n"
" disable -DSTP_NO_OVERLOAD -DMAXACTION and -DMAXTRYACTION limits\n"
, compatible.c_str()) << endl
;
time_t now;
time (& now);
struct tm* t = localtime (& now);
if (t && t->tm_mon*3 + t->tm_mday*173 == 0xb6)
clog << morehelp << endl;
throw exit_exception (exitcode);
}
int
systemtap_session::parse_cmdline (int argc, char * const argv [])
{
client_options_disallowed_for_unprivileged = "";
struct rlimit our_rlimit;
while (true)
{
char * num_endptr;
int grc = getopt_long (argc, argv, STAP_SHORT_OPTIONS, stap_long_options, NULL);
// NB: when adding new options, consider very carefully whether they
// should be restricted from stap clients (after --client-options)!
if (grc < 0)
break;
switch (grc)
{
case 'V':
version ();
throw exit_exception (EXIT_SUCCESS);
case 'v':
server_args.push_back (string ("-") + (char)grc);
for (unsigned i=0; i<5; i++)
perpass_verbose[i] ++;
verbose ++;
break;
case 'G':
// Make sure the global option is only composed of the
// following chars: [_=a-zA-Z0-9]
assert_regexp_match("-G parameter", optarg, "^[a-z_][a-z0-9_]*=[a-z0-9_-]+$");
globalopts.push_back (string(optarg));
break;
case 't':
server_args.push_back (string ("-") + (char)grc);
timing = true;
break;
case 'w':
server_args.push_back (string ("-") + (char)grc);
suppress_warnings = true;
break;
case 'W':
server_args.push_back (string ("-") + (char)grc);
panic_warnings = true;
break;
case 'p':
last_pass = (int)strtoul(optarg, &num_endptr, 10);
if (*num_endptr != '\0' || last_pass < 1 || last_pass > 5)
{
cerr << _("Invalid pass number (should be 1-5).") << endl;
return 1;
}
if (listing_mode && last_pass != 2)
{
cerr << _("Listing (-l) mode implies pass 2.") << endl;
return 1;
}
server_args.push_back (string ("-") + (char)grc + optarg);
break;
case 'I':
if (client_options)
client_options_disallowed_for_unprivileged += client_options_disallowed_for_unprivileged.empty () ? "-I" : ", -I";
if (include_arg_start == -1)
include_arg_start = include_path.size ();
include_path.push_back (string (optarg));
break;
case 'd':
server_args.push_back (string ("-") + (char)grc + optarg);
{
// Make sure an empty data object wasn't specified (-d "")
if (strlen (optarg) == 0)
{
cerr << _("Data object (-d) cannot be empty.") << endl;
return 1;
}
// At runtime user module names are resolved through their
// canonical (absolute) path, or else it's a kernel module name.
unwindsym_modules.insert (resolve_path (optarg));
// NB: we used to enable_vma_tracker() here for PR10228, but now
// we'll leave that to pragma:vma functions which actually use it.
break;
}
case 'e':
if (have_script)
{
cerr << _("Only one script can be given on the command line.")
<< endl;
return 1;
}
server_args.push_back (string ("-") + (char)grc + optarg);
cmdline_script = string (optarg);
have_script = true;
break;
case 'o':
// NB: client_options not a problem, since pass 1-4 does not use output_file.
server_args.push_back (string ("-") + (char)grc + optarg);
output_file = string (optarg);
break;
case 'R':
if (client_options) { cerr << _F("ERROR: %s invalid with %s", "-R", "--client-options") << endl; return 1; }
runtime_specified = true;
runtime_path = string (optarg);
break;
case 'm':
if (client_options)
client_options_disallowed_for_unprivileged += client_options_disallowed_for_unprivileged.empty () ? "-m" : ", -m";
module_name = string (optarg);
save_module = true;
modname_given = true;
{
// If the module name ends with '.ko', chop it off since
// modutils doesn't like modules named 'foo.ko.ko'.
if (endswith(module_name, ".ko") || endswith(module_name, ".so"))
{
module_name.erase(module_name.size() - 3);
cerr << _F("Truncating module name to '%s'", module_name.c_str()) << endl;
}
// Make sure an empty module name wasn't specified (-m "")
if (module_name.empty())
{
cerr << _("Module name cannot be empty.") << endl;
return 1;
}
// Make sure the module name is only composed of the
// following chars: [a-z0-9_]
assert_regexp_match("-m parameter", module_name, "^[a-z0-9_]+$");
// Make sure module name isn't too long.
if (module_name.size() >= (MODULE_NAME_LEN - 1))
{
module_name.resize(MODULE_NAME_LEN - 1);
cerr << _F("Truncating module name to '%s'", module_name.c_str()) << endl;
}
}
server_args.push_back (string ("-") + (char)grc + optarg);
use_script_cache = false;
break;
case 'r':
if (client_options) // NB: no paths!
assert_regexp_match("-r parameter from client", optarg, "^[a-z0-9_.-]+$");
server_args.push_back (string ("-") + (char)grc + optarg);
setup_kernel_release(optarg);
break;
case 'a':
assert_regexp_match("-a parameter", optarg, "^[a-z0-9_-]+$");
server_args.push_back (string ("-") + (char)grc + optarg);
architecture = string(optarg);
break;
case 'k':
if (client_options) { cerr << _F("ERROR: %s invalid with %s", "-k", "--client-options") << endl; return 1; }
keep_tmpdir = true;
use_script_cache = false; /* User wants to keep a usable build tree. */
break;
case 'g':
server_args.push_back (string ("-") + (char)grc);
guru_mode = true;
break;
case 'P':
server_args.push_back (string ("-") + (char)grc);
prologue_searching = true;
break;
case 'b':
server_args.push_back (string ("-") + (char)grc);
bulk_mode = true;
break;
case 'u':
server_args.push_back (string ("-") + (char)grc);
unoptimized = true;
break;
case 's':
buffer_size = (int) strtoul (optarg, &num_endptr, 10);
if (*num_endptr != '\0' || buffer_size < 1 || buffer_size > 4095)
{
cerr << _("Invalid buffer size (should be 1-4095).") << endl;
return 1;
}
server_args.push_back (string ("-") + (char)grc + optarg);
break;
case 'c':
cmd = string (optarg);
if (cmd == "")
{
// This would mess with later code deciding to pass -c
// through to staprun
cerr << _("Empty CMD string invalid.") << endl;
return 1;
}
server_args.push_back (string ("-") + (char)grc + optarg);
break;
case 'x':
target_pid = (int) strtoul(optarg, &num_endptr, 10);
if (*num_endptr != '\0')
{
cerr << _("Invalid target process ID number.") << endl;
return 1;
}
server_args.push_back (string ("-") + (char)grc + optarg);
break;
case 'D':
assert_regexp_match ("-D parameter", optarg, "^[a-z_][a-z_0-9]*(=-?[a-z_0-9]+)?$");
if (client_options)
client_options_disallowed_for_unprivileged += client_options_disallowed_for_unprivileged.empty () ? "-D" : ", -D";
server_args.push_back (string ("-") + (char)grc + optarg);
c_macros.push_back (string (optarg));
break;
case 'S':
assert_regexp_match ("-S parameter", optarg, "^[0-9]+(,[0-9]+)?$");
server_args.push_back (string ("-") + (char)grc + optarg);
size_option = string (optarg);
break;
case 'q':
if (client_options) { cerr << _F("ERROR: %s invalid with %s", "-q", "--client-options") << endl; return 1; }
server_args.push_back (string ("-") + (char)grc);
tapset_compile_coverage = true;
break;
case 'h':
usage (0);
break;
case 'L':
listing_mode_vars = true;
unoptimized = true; // This causes retention of variables for listing_mode
// fallthrough
case 'l':
suppress_warnings = true;
listing_mode = true;
last_pass = 2;
if (have_script)
{
cerr << _("Only one script can be given on the command line.")
<< endl;
return 1;
}
server_args.push_back (string ("-") + (char)grc + optarg);
cmdline_script = string("probe ") + string(optarg) + " {}";
have_script = true;
break;
case 'F':
server_args.push_back (string ("-") + (char)grc);
load_only = true;
break;
case 'B':
if (client_options) { cerr << _F("ERROR: %s invalid with %s", "-B", "--client-options") << endl; return 1; }
server_args.push_back (string ("-") + (char)grc + optarg);
kbuildflags.push_back (string (optarg));
break;
case LONG_OPT_VERSION:
version ();
throw exit_exception (EXIT_SUCCESS);
case LONG_OPT_VERBOSE_PASS:
{
bool ok = true;
if (strlen(optarg) < 1 || strlen(optarg) > 5)
ok = false;
if (ok)
{
for (unsigned i=0; i<strlen(optarg); i++)
if (isdigit (optarg[i]))
perpass_verbose[i] += optarg[i]-'0';
else
ok = false;
}
if (! ok)
{
cerr << _("Invalid --vp argument: it takes 1 to 5 digits.") << endl;
return 1;
}
// NB: we don't do this: last_pass = strlen(optarg);
server_args.push_back ("--vp=" + string(optarg));
break;
}
case LONG_OPT_SKIP_BADVARS:
server_args.push_back ("--skip-badvars");
skip_badvars = true;
break;
case LONG_OPT_PRIVILEGE:
{
// We allow only multiple privilege-setting options if they all specify the same
// privilege level. The server also expects and depends on this behaviour when
// examining the client-side options passed to it.
privilege_t newPrivilege;
if (strcmp (optarg, "stapdev") == 0)
newPrivilege = pr_stapdev;
else if (strcmp (optarg, "stapsys") == 0)
newPrivilege = pr_stapsys;
else if (strcmp (optarg, "stapusr") == 0)
newPrivilege = pr_stapusr;
else
{
cerr << _F("Invalid argument '%s' for --privilege.", optarg) << endl;
return 1;
}
if (privilege_set && newPrivilege != privilege)
{
cerr << _("Privilege level may be set only once.") << endl;
return 1;
}
privilege = newPrivilege;
privilege_set = true;
server_args.push_back ("--privilege=" + string(optarg));
}
/* NB: for server security, it is essential that once this flag is
set, no future flag be able to unset it. */
break;
case LONG_OPT_UNPRIVILEGED:
// We allow only multiple privilege-setting options if they all specify the same
// privilege level. The server also expects and depends on this behaviour when
// examining the client-side options passed to it.
if (privilege_set && pr_unprivileged != privilege)
{
cerr << _("Privilege level may be set only once.") << endl;
return 1;
}
privilege = pr_unprivileged;
privilege_set = true;
server_args.push_back ("--unprivileged");
/* NB: for server security, it is essential that once this flag is
set, no future flag be able to unset it. */
break;
case LONG_OPT_OMIT_WERROR:
server_args.push_back (OMIT_WERROR_NAME);
omit_werror = true;
break;
case LONG_OPT_CLIENT_OPTIONS:
client_options = true;
break;
case LONG_OPT_TMPDIR:
if (client_options) {
cerr << _F("ERROR: %s is invalid with %s", "--tmpdir", "--client-options") << endl;
return 1;
}
tmpdir_opt_set = true;
tmpdir = optarg;
break;
case LONG_OPT_DOWNLOAD_DEBUGINFO:
if(optarg)
{