1 // systemtap translator/driver
2 // Copyright (C) 2005-2011 Red Hat Inc.
3 // Copyright (C) 2005 IBM Corp.
4 // Copyright (C) 2006 Intel Corporation.
6 // This file is part of systemtap, and is free software. You can
7 // redistribute it and/or modify it under the terms of the GNU General
8 // Public License (GPL); either version 2, or (at your option) any
14 #include "elaborate.h"
15 #include "translate.h"
21 #include "coveragedb.h"
22 #include "rpm_finder.h"
23 #include "task_finder.h"
30 #include "stap-probe.h"
38 #include <sys/utsname.h>
39 #include <sys/times.h>
49 uniq_list(list
<string
>& l
)
52 list
<string
>::iterator i
= l
.begin();
54 if (s
.insert(*i
).second
)
61 printscript(systemtap_session
& s
, ostream
& o
)
65 // We go through some heroic measures to produce clean output.
66 // Record the alias and probe pointer as <name, set<derived_probe *> >
67 map
<string
,set
<derived_probe
*> > probe_list
;
69 // Pre-process the probe alias
70 for (unsigned i
=0; i
<s
.probes
.size(); i
++)
72 if (pending_interrupts
) return;
74 derived_probe
* p
= s
.probes
[i
];
75 // NB: p->basest() is not so interesting;
76 // p->almost_basest() doesn't quite work, so ...
78 p
->collect_derivation_chain (chain
);
79 probe
* second
= (chain
.size()>1) ? chain
[chain
.size()-2] : chain
[0];
82 p
->printsig(cerr
); cerr
<< endl
;
83 cerr
<< "chain[" << chain
.size() << "]:" << endl
;
84 for (unsigned j
=0; j
<chain
.size(); j
++)
86 cerr
<< " [" << j
<< "]: " << endl
;
87 cerr
<< "\tlocations[" << chain
[j
]->locations
.size() << "]:" << endl
;
88 for (unsigned k
=0; k
<chain
[j
]->locations
.size(); k
++)
90 cerr
<< "\t [" << k
<< "]: ";
91 chain
[j
]->locations
[k
]->print(cerr
);
94 const probe_alias
*a
= chain
[j
]->get_alias();
97 cerr
<< "\taliases[" << a
->alias_names
.size() << "]:" << endl
;
98 for (unsigned k
=0; k
<a
->alias_names
.size(); k
++)
100 cerr
<< "\t [" << k
<< "]: ";
101 a
->alias_names
[k
]->print(cerr
);
109 const probe_alias
*a
= second
->get_alias();
112 assert (a
->alias_names
.size() >= 1);
113 a
->alias_names
[0]->print(tmps
); // XXX: [0] is arbitrary; perhaps print all
117 assert (second
->locations
.size() >= 1);
118 second
->locations
[0]->print(tmps
); // XXX: [0] is less arbitrary here, but still ...
120 string pp
= tmps
.str();
122 // Now duplicate-eliminate. An alias may have expanded to
123 // several actual derived probe points, but we only want to
124 // print the alias head name once.
125 probe_list
[pp
].insert(p
);
128 // print probe name and variables if there
129 for (map
<string
, set
<derived_probe
*> >::iterator it
=probe_list
.begin(); it
!=probe_list
.end(); ++it
)
131 o
<< it
->first
; // probe name or alias
133 // Print the locals and arguments for -L mode only
134 if (s
.listing_mode_vars
)
136 map
<string
,unsigned> var_count
; // format <"name:type",count>
137 map
<string
,unsigned> arg_count
;
138 list
<string
> var_list
;
139 list
<string
> arg_list
;
140 // traverse set<derived_probe *> to collect all locals and arguments
141 for (set
<derived_probe
*>::iterator ix
=it
->second
.begin(); ix
!=it
->second
.end(); ++ix
)
143 derived_probe
* p
= *ix
;
144 // collect available locals of the probe
145 for (unsigned j
=0; j
<p
->locals
.size(); j
++)
148 vardecl
* v
= p
->locals
[j
];
150 var_count
[tmps
.str()]++;
151 var_list
.push_back(tmps
.str());
153 // collect arguments of the probe if there
154 list
<string
> arg_set
;
156 for (list
<string
>::iterator ia
=arg_set
.begin(); ia
!=arg_set
.end(); ++ia
) {
158 arg_list
.push_back(*ia
);
165 // print the set-intersection only
166 for (list
<string
>::iterator ir
=var_list
.begin(); ir
!=var_list
.end(); ++ir
)
167 if (var_count
.find(*ir
)->second
== it
->second
.size()) // print locals
169 for (list
<string
>::iterator ir
=arg_list
.begin(); ir
!=arg_list
.end(); ++ir
)
170 if (arg_count
.find(*ir
)->second
== it
->second
.size()) // print arguments
178 if (s
.embeds
.size() > 0)
179 o
<< _("# global embedded code") << endl
;
180 for (unsigned i
=0; i
<s
.embeds
.size(); i
++)
182 if (pending_interrupts
) return;
183 embeddedcode
* ec
= s
.embeds
[i
];
188 if (s
.globals
.size() > 0)
189 o
<< _("# globals") << endl
;
190 for (unsigned i
=0; i
<s
.globals
.size(); i
++)
192 if (pending_interrupts
) return;
193 vardecl
* v
= s
.globals
[i
];
195 if (s
.verbose
&& v
->init
)
203 if (s
.functions
.size() > 0)
204 o
<< _("# functions") << endl
;
205 for (map
<string
,functiondecl
*>::iterator it
= s
.functions
.begin(); it
!= s
.functions
.end(); it
++)
207 if (pending_interrupts
) return;
208 functiondecl
* f
= it
->second
;
211 if (f
->locals
.size() > 0)
212 o
<< _(" # locals") << endl
;
213 for (unsigned j
=0; j
<f
->locals
.size(); j
++)
215 vardecl
* v
= f
->locals
[j
];
227 if (s
.probes
.size() > 0)
228 o
<< _("# probes") << endl
;
229 for (unsigned i
=0; i
<s
.probes
.size(); i
++)
231 if (pending_interrupts
) return;
232 derived_probe
* p
= s
.probes
[i
];
235 if (p
->locals
.size() > 0)
236 o
<< _(" # locals") << endl
;
237 for (unsigned j
=0; j
<p
->locals
.size(); j
++)
239 vardecl
* v
= p
->locals
[j
];
254 int pending_interrupts
;
257 void handle_interrupt (int sig
)
259 // This might be nice, but we don't know our current verbosity...
260 // clog << _F("Received signal %d", sig) << endl << flush;
261 kill_stap_spawn(sig
);
262 pending_interrupts
++;
263 // Absorb the first two signals. This used to be one, but when
264 // stap is run under sudo, and then interrupted, sudo relays a
265 // redundant copy of the signal to stap, leading to an unclean shutdown.
266 if (pending_interrupts
> 2) // XXX: should be configurable? time-based?
268 char msg
[] = "Too many interrupts received, exiting.\n";
269 int rc
= write (2, msg
, sizeof(msg
)-1);
270 if (rc
) {/* Do nothing; we don't care if our last gasp went out. */ ;}
277 setup_signals (sighandler_t handler
)
281 memset(&sa
, 0, sizeof(sa
));
282 sa
.sa_handler
= handler
;
283 sigemptyset (&sa
.sa_mask
);
284 if (handler
!= SIG_IGN
)
286 sigaddset (&sa
.sa_mask
, SIGHUP
);
287 sigaddset (&sa
.sa_mask
, SIGPIPE
);
288 sigaddset (&sa
.sa_mask
, SIGINT
);
289 sigaddset (&sa
.sa_mask
, SIGTERM
);
290 sigaddset (&sa
.sa_mask
, SIGXFSZ
);
291 sigaddset (&sa
.sa_mask
, SIGXCPU
);
293 sa
.sa_flags
= SA_RESTART
;
295 sigaction (SIGHUP
, &sa
, NULL
);
296 sigaction (SIGPIPE
, &sa
, NULL
);
297 sigaction (SIGINT
, &sa
, NULL
);
298 sigaction (SIGTERM
, &sa
, NULL
);
299 sigaction (SIGXFSZ
, &sa
, NULL
);
300 sigaction (SIGXCPU
, &sa
, NULL
);
303 int parse_kernel_config (systemtap_session
&s
)
305 // PR10702: pull config options
306 string kernel_config_file
= s
.kernel_build_tree
+ "/.config";
308 int rc
= stat(kernel_config_file
.c_str(), &st
);
311 clog
<< _F("Checking \"%s\" failed with error: %s",
312 kernel_config_file
.c_str(), strerror(errno
)) << endl
;
313 find_devel_rpms(s
, s
.kernel_build_tree
.c_str());
314 missing_rpm_list_print(s
,"-devel");
318 ifstream
kcf (kernel_config_file
.c_str());
320 while (getline (kcf
, line
))
322 if (!startswith(line
, "CONFIG_")) continue;
323 size_t off
= line
.find('=');
324 if (off
== string::npos
) continue;
325 string key
= line
.substr(0, off
);
326 string value
= line
.substr(off
+1, string::npos
);
327 s
.kernel_config
[key
] = value
;
330 clog
<< _F("Parsed kernel \"%s\", ", kernel_config_file
.c_str())
331 << _F(ngettext("containing %zu tuple", "containing %zu tuples",
332 s
.kernel_config
.size()), s
.kernel_config
.size()) << endl
;
339 int parse_kernel_exports (systemtap_session
&s
)
341 string kernel_exports_file
= s
.kernel_build_tree
+ "/Module.symvers";
343 int rc
= stat(kernel_exports_file
.c_str(), &st
);
346 clog
<< _F("Checking \"%s\" failed with error: %s\nEnsure kernel development headers & makefiles are installed",
347 kernel_exports_file
.c_str(), strerror(errno
)) << endl
;
351 ifstream
kef (kernel_exports_file
.c_str());
353 while (getline (kef
, line
))
355 vector
<string
> tokens
;
356 tokenize (line
, tokens
, "\t");
357 if (tokens
.size() == 4 &&
358 tokens
[2] == "vmlinux" &&
359 tokens
[3].substr(0,13) == string("EXPORT_SYMBOL"))
360 s
.kernel_exports
.insert (tokens
[1]);
363 clog
<< _F(ngettext("Parsed kernel %s, which contained one vmlinux export",
364 "Parsed kernel %s, which contained %zu vmlinux exports",
365 s
.kernel_exports
.size()), kernel_exports_file
.c_str(),
366 s
.kernel_exports
.size()) << endl
;
374 create_temp_dir (systemtap_session
&s
)
376 if (!s
.tmpdir
.empty())
379 // Create a temporary directory to build within.
380 // Be careful with this, as "tmpdir" is "rm -rf"'d at the end.
381 const char * tmpdir_env
= getenv("TMPDIR");
385 string stapdir
= "/stapXXXXXX";
386 string tmpdirt
= tmpdir_env
+ stapdir
;
387 const char *tmpdir_name
= mkdtemp((char *)tmpdirt
.c_str());
390 const char* e
= strerror(errno
);
391 //TRANSLATORS: we can't make the directory due to the error
392 cerr
<< _F("ERROR: cannot create temporary directory (\" %s \"): %s", tmpdirt
.c_str(), e
) << endl
;
396 s
.tmpdir
= tmpdir_name
;
399 clog
<< _F("Created temporary directory \"%s\"", s
.tmpdir
.c_str()) << endl
;
404 remove_temp_dir(systemtap_session
&s
)
406 if (!s
.tmpdir
.empty())
408 if (s
.keep_tmpdir
&& !s
.tmpdir_opt_set
)
409 clog
<< _F("Keeping temporary directory \"%s\"", s
.tmpdir
.c_str()) << endl
;
410 else if (!s
.tmpdir_opt_set
)
412 // Mask signals while we're deleting the temporary directory.
413 stap_sigmasker masked
;
415 // Remove the temporary directory.
416 vector
<string
> cleanupcmd
;
417 cleanupcmd
.push_back("rm");
418 cleanupcmd
.push_back("-rf");
419 cleanupcmd
.push_back(s
.tmpdir
);
421 (void) stap_system(s
.verbose
, cleanupcmd
);
427 // Compilation passes 0 through 4
429 passes_0_4 (systemtap_session
&s
)
433 // If we don't know the release, there's no hope either locally or on a server.
434 if (s
.kernel_release
.empty())
436 if (s
.kernel_build_tree
.empty())
437 cerr
<< _("ERROR: kernel release isn't specified") << endl
;
439 cerr
<< _F("ERROR: kernel release isn't found in \"%s\"",
440 s
.kernel_build_tree
.c_str()) << endl
;
444 // Create a temporary directory to build within.
445 // Be careful with this, as "s.tmpdir" is "rm -rf"'d at the end.
446 rc
= create_temp_dir (s
);
450 // Perform passes 0 through 4 using a compile server?
451 if (! s
.specified_servers
.empty ())
454 compile_server_client
client (s
);
455 int rc
= client
.passes_0_4 ();
456 // Need to give a user a better diagnostic, if she didn't
457 // even ask for a server
458 if (rc
&& s
.automatic_server_mode
) {
459 cerr
<< _("Note: --use-server --unprivileged was selected because of stapusr membership.") << endl
;
463 cerr
<< _("WARNING: Without NSS, using a compile-server is not supported by this version of systemtap") << endl
;
464 // This cannot be an attempt to use a server after a local compile failed
465 // since --use-server-on-error is locked to 'no' if we don't have
467 assert (! s
.try_server ());
471 // PASS 0: setting up
472 s
.verbose
= s
.perpass_verbose
[0];
473 PROBE1(stap
, pass0__start
, &s
);
475 // For PR1477, we used to override $PATH and $LC_ALL and other stuff
476 // here. We seem to use complete pathnames in
477 // buildrun.cxx/tapsets.cxx now, so this is not necessary. Further,
478 // it interferes with util.cxx:find_executable(), used for $PATH
481 s
.kernel_base_release
.assign(s
.kernel_release
, 0, s
.kernel_release
.find('-'));
483 // Now that no further changes to s.kernel_build_tree can occur, let's use it.
484 if ((rc
= parse_kernel_config (s
)) != 0)
486 // Try again with a server
491 if ((rc
= parse_kernel_exports (s
)) != 0)
493 // Try again with a server
498 // Create the name of the C source file within the temporary
500 s
.translated_source
= string(s
.tmpdir
) + "/" + s
.module_name
+ ".c";
502 PROBE1(stap
, pass0__end
, &s
);
504 struct tms tms_before
;
505 times (& tms_before
);
506 struct timeval tv_before
;
507 gettimeofday (&tv_before
, NULL
);
509 // PASS 1a: PARSING USER SCRIPT
510 PROBE1(stap
, pass1a__start
, &s
);
512 struct stat user_file_stat
;
513 int user_file_stat_rc
= -1;
515 if (s
.script_file
== "-")
517 s
.user_file
= parse (s
, cin
, s
.guru_mode
);
518 user_file_stat_rc
= fstat (STDIN_FILENO
, & user_file_stat
);
520 else if (s
.script_file
!= "")
522 s
.user_file
= parse (s
, s
.script_file
, s
.guru_mode
);
523 user_file_stat_rc
= stat (s
.script_file
.c_str(), & user_file_stat
);
527 istringstream
ii (s
.cmdline_script
);
528 s
.user_file
= parse (s
, ii
, s
.guru_mode
);
530 if (s
.user_file
== 0)
532 // Syntax errors already printed.
536 // Construct arch / kernel-versioning search path
537 vector
<string
> version_suffixes
;
538 string kvr
= s
.kernel_release
;
539 const string
& arch
= s
.architecture
;
540 // add full kernel-version-release (2.6.NN-FOOBAR) + arch
541 version_suffixes
.push_back ("/" + kvr
+ "/" + arch
);
542 version_suffixes
.push_back ("/" + kvr
);
543 // add kernel version (2.6.NN) + arch
544 if (kvr
!= s
.kernel_base_release
) {
545 kvr
= s
.kernel_base_release
;
546 version_suffixes
.push_back ("/" + kvr
+ "/" + arch
);
547 version_suffixes
.push_back ("/" + kvr
);
549 // add kernel family (2.6) + arch
550 string::size_type dot1_index
= kvr
.find ('.');
551 string::size_type dot2_index
= kvr
.rfind ('.');
552 while (dot2_index
> dot1_index
&& dot2_index
!= string::npos
) {
553 kvr
.erase(dot2_index
);
554 version_suffixes
.push_back ("/" + kvr
+ "/" + arch
);
555 version_suffixes
.push_back ("/" + kvr
);
556 dot2_index
= kvr
.rfind ('.');
558 // add architecture search path
559 version_suffixes
.push_back("/" + arch
);
560 // add empty string as last element
561 version_suffixes
.push_back ("");
563 // PASS 1b: PARSING LIBRARY SCRIPTS
564 PROBE1(stap
, pass1b__start
, &s
);
566 set
<pair
<dev_t
, ino_t
> > seen_library_files
;
568 for (unsigned i
=0; i
<s
.include_path
.size(); i
++)
570 // now iterate upon it
571 for (unsigned k
=0; k
<version_suffixes
.size(); k
++)
574 string dir
= s
.include_path
[i
] + version_suffixes
[k
] + "/*.stp";
575 int r
= glob(dir
.c_str (), 0, NULL
, & globbuf
);
576 if (r
== GLOB_NOSPACE
|| r
== GLOB_ABORTED
)
578 // GLOB_NOMATCH is acceptable
580 unsigned prev_s_library_files
= s
.library_files
.size();
582 for (unsigned j
=0; j
<globbuf
.gl_pathc
; j
++)
584 if (pending_interrupts
)
587 struct stat tapset_file_stat
;
588 int stat_rc
= stat (globbuf
.gl_pathv
[j
], & tapset_file_stat
);
589 if (stat_rc
== 0 && user_file_stat_rc
== 0 &&
590 user_file_stat
.st_dev
== tapset_file_stat
.st_dev
&&
591 user_file_stat
.st_ino
== tapset_file_stat
.st_ino
)
594 << _F("usage error: tapset file '%s' cannot be run directly as a session script.",
595 globbuf
.gl_pathv
[j
]) << endl
;
599 // PR11949: duplicate-eliminate tapset files
602 pair
<dev_t
,ino_t
> here
= make_pair(tapset_file_stat
.st_dev
,
603 tapset_file_stat
.st_ino
);
604 if (seen_library_files
.find(here
) != seen_library_files
.end())
606 seen_library_files
.insert (here
);
609 // XXX: privilege only for /usr/share/systemtap?
610 stapfile
* f
= parse (s
, globbuf
.gl_pathv
[j
], true);
611 if (f
== 0 && !s
.suppress_warnings
)
612 s
.print_warning("tapset '" + string(globbuf
.gl_pathv
[j
])
613 + "' has errors, and will be skipped.");
615 s
.library_files
.push_back (f
);
618 unsigned next_s_library_files
= s
.library_files
.size();
619 if (s
.verbose
>1 && globbuf
.gl_pathc
> 0)
620 //TRANSLATORS: Searching through directories, 'processed' means 'examined so far'
621 clog
<< _F("Searched: \" %s \", found: %zu, processed: %u",
622 dir
.c_str(), globbuf
.gl_pathc
,
623 (next_s_library_files
-prev_s_library_files
)) << endl
;
625 globfree (& globbuf
);
631 if (rc
== 0 && s
.last_pass
== 1)
633 cout
<< _("# parse tree dump") << endl
;
634 s
.user_file
->print (cout
);
637 for (unsigned i
=0; i
<s
.library_files
.size(); i
++)
639 s
.library_files
[i
]->print (cout
);
644 struct tms tms_after
;
646 unsigned _sc_clk_tck
= sysconf (_SC_CLK_TCK
);
647 struct timeval tv_after
;
648 gettimeofday (&tv_after
, NULL
);
650 #define TIMESPRINT "in " << \
651 (tms_after.tms_cutime + tms_after.tms_utime \
652 - tms_before.tms_cutime - tms_before.tms_utime) * 1000 / (_sc_clk_tck) << "usr/" \
653 << (tms_after.tms_cstime + tms_after.tms_stime \
654 - tms_before.tms_cstime - tms_before.tms_stime) * 1000 / (_sc_clk_tck) << "sys/" \
655 << ((tv_after.tv_sec - tv_before.tv_sec) * 1000 + \
656 ((long)tv_after.tv_usec - (long)tv_before.tv_usec) / 1000) << "real ms."
658 // syntax errors, if any, are already printed
661 clog
<< "Pass 1: parsed user script and "
662 << s
.library_files
.size()
663 << " library script(s) "
669 if (rc
&& !s
.listing_mode
)
670 cerr
<< _("Pass 1: parse failed. Try again with another '--vp 1' option.") << endl
;
671 //cerr << "Pass 1: parse failed. "
672 // << "Try again with another '--vp 1' option."
675 PROBE1(stap
, pass1__end
, &s
);
677 if (rc
|| s
.last_pass
== 1 || pending_interrupts
) return rc
;
679 times (& tms_before
);
680 gettimeofday (&tv_before
, NULL
);
682 // PASS 2: ELABORATION
683 s
.verbose
= s
.perpass_verbose
[1];
684 PROBE1(stap
, pass2__start
, &s
);
685 rc
= semantic_pass (s
);
687 if (s
.listing_mode
|| (rc
== 0 && s
.last_pass
== 2))
688 printscript(s
, cout
);
691 gettimeofday (&tv_after
, NULL
);
693 if (s
.verbose
) clog
<< "Pass 2: analyzed script: "
694 << s
.probes
.size() << " probe(s), "
695 << s
.functions
.size() << " function(s), "
696 << s
.embeds
.size() << " embed(s), "
697 << s
.globals
.size() << " global(s) "
702 if (rc
&& !s
.listing_mode
&& !s
.try_server ())
703 cerr
<< _("Pass 2: analysis failed. Try again with another '--vp 01' option.") << endl
;
704 //cerr << "Pass 2: analysis failed. "
705 // << "Try again with another '--vp 01' option."
708 /* Print out list of missing files. XXX should be "if (rc)" ? */
709 missing_rpm_list_print(s
,"-debuginfo");
711 PROBE1(stap
, pass2__end
, &s
);
713 if (rc
|| s
.listing_mode
|| s
.last_pass
== 2 || pending_interrupts
) return rc
;
715 rc
= prepare_translate_pass (s
);
716 if (rc
|| pending_interrupts
) return rc
;
718 // Generate hash. There isn't any point in generating the hash
719 // if last_pass is 2, since we'll quit before using it.
720 if (s
.use_script_cache
)
723 unsigned saved_verbose
;
726 // Make sure we're in verbose mode, so that printscript()
727 // will output function/probe bodies.
728 saved_verbose
= s
.verbose
;
730 printscript(s
, o
); // Print script to 'o'
731 s
.verbose
= saved_verbose
;
735 find_script_hash (s
, o
.str());
737 // See if we can use cached source/module.
738 if (get_script_from_cache(s
))
740 // We may still need to build uprobes, if it's not also cached.
742 rc
= uprobes_pass(s
);
744 // If our last pass isn't 5, we're done (since passes 3 and
745 // 4 just generate what we just pulled out of the cache).
746 if (rc
|| s
.last_pass
< 5 || pending_interrupts
)
749 // Short-circuit to pass 5.
754 // PASS 3: TRANSLATION
755 s
.verbose
= s
.perpass_verbose
[2];
756 times (& tms_before
);
757 gettimeofday (&tv_before
, NULL
);
758 PROBE1(stap
, pass3__start
, &s
);
760 rc
= translate_pass (s
);
761 if (! rc
&& s
.last_pass
== 3)
763 ifstream
i (s
.translated_source
.c_str());
768 gettimeofday (&tv_after
, NULL
);
771 clog
<< "Pass 3: translated to C into \""
772 << s
.translated_source
778 if (rc
&& ! s
.try_server ())
779 cerr
<< _("Pass 3: translation failed. Try again with another '--vp 001' option.") << endl
;
780 //cerr << "Pass 3: translation failed. "
781 // << "Try again with another '--vp 001' option."
784 PROBE1(stap
, pass3__end
, &s
);
786 if (rc
|| s
.last_pass
== 3 || pending_interrupts
) return rc
;
788 // PASS 4: COMPILATION
789 s
.verbose
= s
.perpass_verbose
[3];
790 times (& tms_before
);
791 gettimeofday (&tv_before
, NULL
);
792 PROBE1(stap
, pass4__start
, &s
);
796 find_stapconf_hash(s
);
797 get_stapconf_from_cache(s
);
799 rc
= compile_pass (s
);
800 if (! rc
&& s
.last_pass
== 4)
802 cout
<< ((s
.hash_path
== "") ? (s
.module_name
+ string(".ko")) : s
.hash_path
);
807 gettimeofday (&tv_after
, NULL
);
809 if (s
.verbose
) clog
<< "Pass 4: compiled C into \""
810 << s
.module_name
<< ".ko"
815 if (rc
&& ! s
.try_server ())
816 cerr
<< _("Pass 4: compilation failed. Try again with another '--vp 0001' option.") << endl
;
817 //cerr << "Pass 4: compilation failed. "
818 // << "Try again with another '--vp 0001' option."
822 // Update cache. Cache cleaning is kicked off at the beginning of this function.
823 if (s
.use_script_cache
)
824 add_script_to_cache(s
);
826 add_stapconf_to_cache(s
);
828 // We may need to save the module in $CWD if the cache was
829 // inaccessible for some reason.
830 if (! s
.use_script_cache
&& s
.last_pass
== 4)
831 s
.save_module
= true;
833 // Copy module to the current directory.
834 if (s
.save_module
&& !pending_interrupts
)
836 string module_src_path
= s
.tmpdir
+ "/" + s
.module_name
+ ".ko";
837 string module_dest_path
= s
.module_name
+ ".ko";
838 copy_file(module_src_path
, module_dest_path
, s
.verbose
> 1);
842 PROBE1(stap
, pass4__end
, &s
);
848 pass_5 (systemtap_session
&s
, vector
<remote
*> targets
)
851 s
.verbose
= s
.perpass_verbose
[4];
852 struct tms tms_before
;
853 times (& tms_before
);
854 struct timeval tv_before
;
855 gettimeofday (&tv_before
, NULL
);
856 // NB: this message is a judgement call. The other passes don't emit
857 // a "hello, I'm starting" message, but then the others aren't interactive
858 // and don't take an indefinite amount of time.
859 PROBE1(stap
, pass5__start
, &s
);
860 if (s
.verbose
) clog
<< _("Pass 5: starting run.") << endl
;
861 int rc
= remote::run(targets
);
862 struct tms tms_after
;
864 unsigned _sc_clk_tck
= sysconf (_SC_CLK_TCK
);
865 struct timeval tv_after
;
866 gettimeofday (&tv_after
, NULL
);
867 if (s
.verbose
) clog
<< "Pass 5: run completed "
872 cerr
<< _("Pass 5: run failed. Try again with another '--vp 00001' option.") << endl
;
873 //cerr << "Pass 5: run failed. "
874 // << "Try again with another '--vp 00001' option."
877 // Interrupting pass-5 to quit is normal, so we want an EXIT_SUCCESS below.
878 pending_interrupts
= 0;
880 PROBE1(stap
, pass5__end
, &s
);
886 cleanup (systemtap_session
&s
, int rc
)
888 // PASS 6: cleaning up
889 PROBE1(stap
, pass6__start
, &s
);
891 for (systemtap_session::session_map_t::iterator it
= s
.subsessions
.begin();
892 it
!= s
.subsessions
.end(); ++it
)
893 cleanup (*it
->second
, rc
);
895 // update the database information
896 if (!rc
&& s
.tapset_compile_coverage
&& !pending_interrupts
) {
897 #ifdef HAVE_LIBSQLITE3
898 update_coverage_db(s
);
900 cerr
<< _("Coverage database not available without libsqlite3") << endl
;
904 // Clean up temporary directory. Obviously, be careful with this.
907 PROBE1(stap
, pass6__end
, &s
);
911 passes_0_4_again_with_server (systemtap_session
&s
)
913 // Not a server and not already using a server.
914 assert (! s
.client_options
);
915 assert (s
.specified_servers
.empty ());
917 // Specify default server(s).
918 s
.specified_servers
.push_back ("");
920 // Remove the previous temporary directory and start fresh.
923 // Try to compile again, using the server
924 clog
<< _("Attempting compilation using a compile server")
926 int rc
= passes_0_4 (s
);
931 main (int argc
, char * const argv
[])
933 // Initialize defaults.
936 setlocale (LC_ALL
, "");
937 bindtextdomain (PACKAGE
, LOCALEDIR
);
938 textdomain (PACKAGE
);
940 // Set up our handler to catch routine signals, to allow clean
941 // and reasonably timely exit.
942 setup_signals(&handle_interrupt
);
944 // Process the command line.
945 int rc
= s
.parse_cmdline (argc
, argv
);
949 // Check for options conflicts. Exits if errors are detected.
950 s
.check_options (argc
, argv
);
952 // arguments parsed; get down to business
956 // Some of the remote methods need to write temporary data, so go ahead
957 // and create the main tempdir now.
958 rc
= create_temp_dir (s
);
960 // Prepare connections for each specified remote target.
961 vector
<remote
*> targets
;
962 if (s
.remote_uris
.empty())
963 s
.remote_uris
.push_back("direct:");
964 for (unsigned i
= 0; rc
== 0 && i
< s
.remote_uris
.size(); ++i
)
966 remote
*target
= remote::create(s
, s
.remote_uris
[i
]);
968 targets
.push_back(target
);
973 // Discover and loop over each unique session created by the remote targets.
974 set
<systemtap_session
*> sessions
;
975 for (unsigned i
= 0; i
< targets
.size(); ++i
)
976 sessions
.insert(targets
[i
]->get_session());
977 for (set
<systemtap_session
*>::iterator it
= sessions
.begin();
978 rc
== 0 && !pending_interrupts
&& it
!= sessions
.end(); ++it
)
980 systemtap_session
& ss
= **it
;
982 clog
<< _F("Session arch: %s release: %s",
983 ss
.architecture
.c_str(), ss
.kernel_release
.c_str()) << endl
;
985 // If requested, query server status. This is independent of other tasks.
986 query_server_status (ss
);
988 // If requested, manage trust of servers. This is independent of other tasks.
989 manage_server_trust (ss
);
991 // Run the passes only if a script has been specified. The requirement for
992 // a script has already been checked in systemtap_session::check_options.
995 // Run passes 0-4 for each unique session,
996 // either locally or using a compile-server.
997 ss
.init_try_server ();
998 if ((rc
= passes_0_4 (ss
)))
1000 // Compilation failed.
1001 // Try again using a server if appropriate.
1002 if (ss
.try_server ())
1003 rc
= passes_0_4_again_with_server (ss
);
1008 // Run pass 5, if requested
1009 if (rc
== 0 && s
.have_script
&& s
.last_pass
>= 5 && ! pending_interrupts
)
1010 rc
= pass_5 (s
, targets
);
1013 for (unsigned i
= 0; i
< targets
.size(); ++i
)
1017 return (rc
||pending_interrupts
) ? EXIT_FAILURE
: EXIT_SUCCESS
;
1020 /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */