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"
31 #include "stap-probe.h"
39 #include <sys/utsname.h>
40 #include <sys/times.h>
50 uniq_list(list
<string
>& l
)
53 list
<string
>::iterator i
= l
.begin();
55 if (s
.insert(*i
).second
)
62 printscript(systemtap_session
& s
, ostream
& o
)
66 // We go through some heroic measures to produce clean output.
67 // Record the alias and probe pointer as <name, set<derived_probe *> >
68 map
<string
,set
<derived_probe
*> > probe_list
;
70 // Pre-process the probe alias
71 for (unsigned i
=0; i
<s
.probes
.size(); i
++)
73 if (pending_interrupts
) return;
75 derived_probe
* p
= s
.probes
[i
];
76 // NB: p->basest() is not so interesting;
77 // p->almost_basest() doesn't quite work, so ...
79 p
->collect_derivation_chain (chain
);
80 probe
* second
= (chain
.size()>1) ? chain
[chain
.size()-2] : chain
[0];
83 p
->printsig(cerr
); cerr
<< endl
;
84 cerr
<< "chain[" << chain
.size() << "]:" << endl
;
85 for (unsigned j
=0; j
<chain
.size(); j
++)
87 cerr
<< " [" << j
<< "]: " << endl
;
88 cerr
<< "\tlocations[" << chain
[j
]->locations
.size() << "]:" << endl
;
89 for (unsigned k
=0; k
<chain
[j
]->locations
.size(); k
++)
91 cerr
<< "\t [" << k
<< "]: ";
92 chain
[j
]->locations
[k
]->print(cerr
);
95 const probe_alias
*a
= chain
[j
]->get_alias();
98 cerr
<< "\taliases[" << a
->alias_names
.size() << "]:" << endl
;
99 for (unsigned k
=0; k
<a
->alias_names
.size(); k
++)
101 cerr
<< "\t [" << k
<< "]: ";
102 a
->alias_names
[k
]->print(cerr
);
110 const probe_alias
*a
= second
->get_alias();
113 assert (a
->alias_names
.size() >= 1);
114 a
->alias_names
[0]->print(tmps
); // XXX: [0] is arbitrary; perhaps print all
118 assert (second
->locations
.size() >= 1);
119 second
->locations
[0]->print(tmps
); // XXX: [0] is less arbitrary here, but still ...
121 string pp
= tmps
.str();
123 // Now duplicate-eliminate. An alias may have expanded to
124 // several actual derived probe points, but we only want to
125 // print the alias head name once.
126 probe_list
[pp
].insert(p
);
129 // print probe name and variables if there
130 for (map
<string
, set
<derived_probe
*> >::iterator it
=probe_list
.begin(); it
!=probe_list
.end(); ++it
)
132 o
<< it
->first
; // probe name or alias
134 // Print the locals and arguments for -L mode only
135 if (s
.listing_mode_vars
)
137 map
<string
,unsigned> var_count
; // format <"name:type",count>
138 map
<string
,unsigned> arg_count
;
139 list
<string
> var_list
;
140 list
<string
> arg_list
;
141 // traverse set<derived_probe *> to collect all locals and arguments
142 for (set
<derived_probe
*>::iterator ix
=it
->second
.begin(); ix
!=it
->second
.end(); ++ix
)
144 derived_probe
* p
= *ix
;
145 // collect available locals of the probe
146 for (unsigned j
=0; j
<p
->locals
.size(); j
++)
149 vardecl
* v
= p
->locals
[j
];
151 var_count
[tmps
.str()]++;
152 var_list
.push_back(tmps
.str());
154 // collect arguments of the probe if there
155 list
<string
> arg_set
;
157 for (list
<string
>::iterator ia
=arg_set
.begin(); ia
!=arg_set
.end(); ++ia
) {
159 arg_list
.push_back(*ia
);
166 // print the set-intersection only
167 for (list
<string
>::iterator ir
=var_list
.begin(); ir
!=var_list
.end(); ++ir
)
168 if (var_count
.find(*ir
)->second
== it
->second
.size()) // print locals
170 for (list
<string
>::iterator ir
=arg_list
.begin(); ir
!=arg_list
.end(); ++ir
)
171 if (arg_count
.find(*ir
)->second
== it
->second
.size()) // print arguments
179 if (s
.embeds
.size() > 0)
180 o
<< _("# global embedded code") << endl
;
181 for (unsigned i
=0; i
<s
.embeds
.size(); i
++)
183 if (pending_interrupts
) return;
184 embeddedcode
* ec
= s
.embeds
[i
];
189 if (s
.globals
.size() > 0)
190 o
<< _("# globals") << endl
;
191 for (unsigned i
=0; i
<s
.globals
.size(); i
++)
193 if (pending_interrupts
) return;
194 vardecl
* v
= s
.globals
[i
];
196 if (s
.verbose
&& v
->init
)
204 if (s
.functions
.size() > 0)
205 o
<< _("# functions") << endl
;
206 for (map
<string
,functiondecl
*>::iterator it
= s
.functions
.begin(); it
!= s
.functions
.end(); it
++)
208 if (pending_interrupts
) return;
209 functiondecl
* f
= it
->second
;
212 if (f
->locals
.size() > 0)
213 o
<< _(" # locals") << endl
;
214 for (unsigned j
=0; j
<f
->locals
.size(); j
++)
216 vardecl
* v
= f
->locals
[j
];
228 if (s
.probes
.size() > 0)
229 o
<< _("# probes") << endl
;
230 for (unsigned i
=0; i
<s
.probes
.size(); i
++)
232 if (pending_interrupts
) return;
233 derived_probe
* p
= s
.probes
[i
];
236 if (p
->locals
.size() > 0)
237 o
<< _(" # locals") << endl
;
238 for (unsigned j
=0; j
<p
->locals
.size(); j
++)
240 vardecl
* v
= p
->locals
[j
];
255 int pending_interrupts
;
258 void handle_interrupt (int sig
)
260 // This might be nice, but we don't know our current verbosity...
261 // clog << _F("Received signal %d", sig) << endl << flush;
262 kill_stap_spawn(sig
);
263 pending_interrupts
++;
264 // Absorb the first two signals. This used to be one, but when
265 // stap is run under sudo, and then interrupted, sudo relays a
266 // redundant copy of the signal to stap, leading to an unclean shutdown.
267 if (pending_interrupts
> 2) // XXX: should be configurable? time-based?
269 char msg
[] = "Too many interrupts received, exiting.\n";
270 int rc
= write (2, msg
, sizeof(msg
)-1);
271 if (rc
) {/* Do nothing; we don't care if our last gasp went out. */ ;}
278 setup_signals (sighandler_t handler
)
282 memset(&sa
, 0, sizeof(sa
));
283 sa
.sa_handler
= handler
;
284 sigemptyset (&sa
.sa_mask
);
285 if (handler
!= SIG_IGN
)
287 sigaddset (&sa
.sa_mask
, SIGHUP
);
288 sigaddset (&sa
.sa_mask
, SIGPIPE
);
289 sigaddset (&sa
.sa_mask
, SIGINT
);
290 sigaddset (&sa
.sa_mask
, SIGTERM
);
291 sigaddset (&sa
.sa_mask
, SIGXFSZ
);
292 sigaddset (&sa
.sa_mask
, SIGXCPU
);
294 sa
.sa_flags
= SA_RESTART
;
296 sigaction (SIGHUP
, &sa
, NULL
);
297 sigaction (SIGPIPE
, &sa
, NULL
);
298 sigaction (SIGINT
, &sa
, NULL
);
299 sigaction (SIGTERM
, &sa
, NULL
);
300 sigaction (SIGXFSZ
, &sa
, NULL
);
301 sigaction (SIGXCPU
, &sa
, NULL
);
304 int parse_kernel_config (systemtap_session
&s
)
306 // PR10702: pull config options
307 string kernel_config_file
= s
.kernel_build_tree
+ "/.config";
309 int rc
= stat(kernel_config_file
.c_str(), &st
);
312 clog
<< _F("Checking \"%s\" failed with error: %s",
313 kernel_config_file
.c_str(), strerror(errno
)) << endl
;
314 find_devel_rpms(s
, s
.kernel_build_tree
.c_str());
315 missing_rpm_list_print(s
,"-devel");
319 ifstream
kcf (kernel_config_file
.c_str());
321 while (getline (kcf
, line
))
323 if (!startswith(line
, "CONFIG_")) continue;
324 size_t off
= line
.find('=');
325 if (off
== string::npos
) continue;
326 string key
= line
.substr(0, off
);
327 string value
= line
.substr(off
+1, string::npos
);
328 s
.kernel_config
[key
] = value
;
331 clog
<< _F("Parsed kernel \"%s\", ", kernel_config_file
.c_str())
332 << _F(ngettext("containing %zu tuple", "containing %zu tuples",
333 s
.kernel_config
.size()), s
.kernel_config
.size()) << endl
;
340 int parse_kernel_exports (systemtap_session
&s
)
342 string kernel_exports_file
= s
.kernel_build_tree
+ "/Module.symvers";
344 int rc
= stat(kernel_exports_file
.c_str(), &st
);
347 clog
<< _F("Checking \"%s\" failed with error: %s\nEnsure kernel development headers & makefiles are installed",
348 kernel_exports_file
.c_str(), strerror(errno
)) << endl
;
352 ifstream
kef (kernel_exports_file
.c_str());
354 while (getline (kef
, line
))
356 vector
<string
> tokens
;
357 tokenize (line
, tokens
, "\t");
358 if (tokens
.size() == 4 &&
359 tokens
[2] == "vmlinux" &&
360 tokens
[3].substr(0,13) == string("EXPORT_SYMBOL"))
361 s
.kernel_exports
.insert (tokens
[1]);
362 // RHEL4 Module.symvers file only has 3 tokens. No
363 // 'EXPORT_SYMBOL' token at the end of the line.
364 else if (tokens
.size() == 3 && tokens
[2] == "vmlinux")
365 s
.kernel_exports
.insert (tokens
[1]);
368 clog
<< _F(ngettext("Parsed kernel %s, which contained one vmlinux export",
369 "Parsed kernel %s, which contained %zu vmlinux exports",
370 s
.kernel_exports
.size()), kernel_exports_file
.c_str(),
371 s
.kernel_exports
.size()) << endl
;
379 create_temp_dir (systemtap_session
&s
)
381 if (!s
.tmpdir
.empty())
384 // Create a temporary directory to build within.
385 // Be careful with this, as "tmpdir" is "rm -rf"'d at the end.
386 const char * tmpdir_env
= getenv("TMPDIR");
390 string stapdir
= "/stapXXXXXX";
391 string tmpdirt
= tmpdir_env
+ stapdir
;
392 const char *tmpdir_name
= mkdtemp((char *)tmpdirt
.c_str());
395 const char* e
= strerror(errno
);
396 //TRANSLATORS: we can't make the directory due to the error
397 cerr
<< _F("ERROR: cannot create temporary directory (\" %s \"): %s", tmpdirt
.c_str(), e
) << endl
;
401 s
.tmpdir
= tmpdir_name
;
404 clog
<< _F("Created temporary directory \"%s\"", s
.tmpdir
.c_str()) << endl
;
409 remove_temp_dir(systemtap_session
&s
)
411 if (!s
.tmpdir
.empty())
413 if (s
.keep_tmpdir
&& !s
.tmpdir_opt_set
)
414 clog
<< _F("Keeping temporary directory \"%s\"", s
.tmpdir
.c_str()) << endl
;
415 else if (!s
.tmpdir_opt_set
)
417 // Mask signals while we're deleting the temporary directory.
418 stap_sigmasker masked
;
420 // Remove the temporary directory.
421 vector
<string
> cleanupcmd
;
422 cleanupcmd
.push_back("rm");
423 cleanupcmd
.push_back("-rf");
424 cleanupcmd
.push_back(s
.tmpdir
);
426 (void) stap_system(s
.verbose
, cleanupcmd
);
432 // Compilation passes 0 through 4
434 passes_0_4 (systemtap_session
&s
)
438 // If we don't know the release, there's no hope either locally or on a server.
439 if (s
.kernel_release
.empty())
441 if (s
.kernel_build_tree
.empty())
442 cerr
<< _("ERROR: kernel release isn't specified") << endl
;
444 cerr
<< _F("ERROR: kernel release isn't found in \"%s\"",
445 s
.kernel_build_tree
.c_str()) << endl
;
449 // Create a temporary directory to build within.
450 // Be careful with this, as "s.tmpdir" is "rm -rf"'d at the end.
451 rc
= create_temp_dir (s
);
455 // Perform passes 0 through 4 using a compile server?
456 if (! s
.specified_servers
.empty ())
459 compile_server_client
client (s
);
460 int rc
= client
.passes_0_4 ();
461 // Need to give a user a better diagnostic, if she didn't
462 // even ask for a server
463 if (rc
&& s
.automatic_server_mode
) {
464 cerr
<< _("Note: --use-server --unprivileged was selected because of stapusr membership.") << endl
;
468 cerr
<< _("WARNING: Without NSS, using a compile-server is not supported by this version of systemtap") << endl
;
469 // This cannot be an attempt to use a server after a local compile failed
470 // since --use-server-on-error is locked to 'no' if we don't have
472 assert (! s
.try_server ());
476 // PASS 0: setting up
477 s
.verbose
= s
.perpass_verbose
[0];
478 PROBE1(stap
, pass0__start
, &s
);
480 // For PR1477, we used to override $PATH and $LC_ALL and other stuff
481 // here. We seem to use complete pathnames in
482 // buildrun.cxx/tapsets.cxx now, so this is not necessary. Further,
483 // it interferes with util.cxx:find_executable(), used for $PATH
486 s
.kernel_base_release
.assign(s
.kernel_release
, 0, s
.kernel_release
.find('-'));
488 // Now that no further changes to s.kernel_build_tree can occur, let's use it.
489 if ((rc
= parse_kernel_config (s
)) != 0)
491 // Try again with a server
496 if ((rc
= parse_kernel_exports (s
)) != 0)
498 // Try again with a server
503 // Create the name of the C source file within the temporary
504 // directory. Note the _src prefix, explained in
505 // buildrun.cxx:compile_pass()
506 s
.translated_source
= string(s
.tmpdir
) + "/" + s
.module_name
+ "_src.c";
508 PROBE1(stap
, pass0__end
, &s
);
510 struct tms tms_before
;
511 times (& tms_before
);
512 struct timeval tv_before
;
513 gettimeofday (&tv_before
, NULL
);
515 // PASS 1a: PARSING USER SCRIPT
516 PROBE1(stap
, pass1a__start
, &s
);
518 struct stat user_file_stat
;
519 int user_file_stat_rc
= -1;
521 if (s
.script_file
== "-")
523 s
.user_file
= parse (s
, cin
, s
.guru_mode
);
524 user_file_stat_rc
= fstat (STDIN_FILENO
, & user_file_stat
);
526 else if (s
.script_file
!= "")
528 s
.user_file
= parse (s
, s
.script_file
, s
.guru_mode
);
529 user_file_stat_rc
= stat (s
.script_file
.c_str(), & user_file_stat
);
533 istringstream
ii (s
.cmdline_script
);
534 s
.user_file
= parse (s
, ii
, s
.guru_mode
);
536 if (s
.user_file
== 0)
538 // Syntax errors already printed.
542 // Construct arch / kernel-versioning search path
543 vector
<string
> version_suffixes
;
544 string kvr
= s
.kernel_release
;
545 const string
& arch
= s
.architecture
;
546 // add full kernel-version-release (2.6.NN-FOOBAR) + arch
547 version_suffixes
.push_back ("/" + kvr
+ "/" + arch
);
548 version_suffixes
.push_back ("/" + kvr
);
549 // add kernel version (2.6.NN) + arch
550 if (kvr
!= s
.kernel_base_release
) {
551 kvr
= s
.kernel_base_release
;
552 version_suffixes
.push_back ("/" + kvr
+ "/" + arch
);
553 version_suffixes
.push_back ("/" + kvr
);
555 // add kernel family (2.6) + arch
556 string::size_type dot1_index
= kvr
.find ('.');
557 string::size_type dot2_index
= kvr
.rfind ('.');
558 while (dot2_index
> dot1_index
&& dot2_index
!= string::npos
) {
559 kvr
.erase(dot2_index
);
560 version_suffixes
.push_back ("/" + kvr
+ "/" + arch
);
561 version_suffixes
.push_back ("/" + kvr
);
562 dot2_index
= kvr
.rfind ('.');
564 // add architecture search path
565 version_suffixes
.push_back("/" + arch
);
566 // add empty string as last element
567 version_suffixes
.push_back ("");
569 // PASS 1b: PARSING LIBRARY SCRIPTS
570 PROBE1(stap
, pass1b__start
, &s
);
572 set
<pair
<dev_t
, ino_t
> > seen_library_files
;
574 for (unsigned i
=0; i
<s
.include_path
.size(); i
++)
576 // now iterate upon it
577 for (unsigned k
=0; k
<version_suffixes
.size(); k
++)
580 string dir
= s
.include_path
[i
] + version_suffixes
[k
] + "/*.stp";
581 int r
= glob(dir
.c_str (), 0, NULL
, & globbuf
);
582 if (r
== GLOB_NOSPACE
|| r
== GLOB_ABORTED
)
584 // GLOB_NOMATCH is acceptable
586 unsigned prev_s_library_files
= s
.library_files
.size();
588 for (unsigned j
=0; j
<globbuf
.gl_pathc
; j
++)
590 if (pending_interrupts
)
593 struct stat tapset_file_stat
;
594 int stat_rc
= stat (globbuf
.gl_pathv
[j
], & tapset_file_stat
);
595 if (stat_rc
== 0 && user_file_stat_rc
== 0 &&
596 user_file_stat
.st_dev
== tapset_file_stat
.st_dev
&&
597 user_file_stat
.st_ino
== tapset_file_stat
.st_ino
)
600 << _F("usage error: tapset file '%s' cannot be run directly as a session script.",
601 globbuf
.gl_pathv
[j
]) << endl
;
605 // PR11949: duplicate-eliminate tapset files
608 pair
<dev_t
,ino_t
> here
= make_pair(tapset_file_stat
.st_dev
,
609 tapset_file_stat
.st_ino
);
610 if (seen_library_files
.find(here
) != seen_library_files
.end())
612 seen_library_files
.insert (here
);
615 // XXX: privilege only for /usr/share/systemtap?
616 stapfile
* f
= parse (s
, globbuf
.gl_pathv
[j
], true);
617 if (f
== 0 && !s
.suppress_warnings
)
618 s
.print_warning("tapset '" + string(globbuf
.gl_pathv
[j
])
619 + "' has errors, and will be skipped.");
621 s
.library_files
.push_back (f
);
624 unsigned next_s_library_files
= s
.library_files
.size();
625 if (s
.verbose
>1 && globbuf
.gl_pathc
> 0)
626 //TRANSLATORS: Searching through directories, 'processed' means 'examined so far'
627 clog
<< _F("Searched: \" %s \", found: %zu, processed: %u",
628 dir
.c_str(), globbuf
.gl_pathc
,
629 (next_s_library_files
-prev_s_library_files
)) << endl
;
631 globfree (& globbuf
);
637 if (rc
== 0 && s
.last_pass
== 1)
639 cout
<< _("# parse tree dump") << endl
;
640 s
.user_file
->print (cout
);
643 for (unsigned i
=0; i
<s
.library_files
.size(); i
++)
645 s
.library_files
[i
]->print (cout
);
650 struct tms tms_after
;
652 unsigned _sc_clk_tck
= sysconf (_SC_CLK_TCK
);
653 struct timeval tv_after
;
654 gettimeofday (&tv_after
, NULL
);
656 #define TIMESPRINT "in " << \
657 (tms_after.tms_cutime + tms_after.tms_utime \
658 - tms_before.tms_cutime - tms_before.tms_utime) * 1000 / (_sc_clk_tck) << "usr/" \
659 << (tms_after.tms_cstime + tms_after.tms_stime \
660 - tms_before.tms_cstime - tms_before.tms_stime) * 1000 / (_sc_clk_tck) << "sys/" \
661 << ((tv_after.tv_sec - tv_before.tv_sec) * 1000 + \
662 ((long)tv_after.tv_usec - (long)tv_before.tv_usec) / 1000) << "real ms."
664 // syntax errors, if any, are already printed
667 clog
<< "Pass 1: parsed user script and "
668 << s
.library_files
.size()
669 << " library script(s) "
675 if (rc
&& !s
.listing_mode
)
676 cerr
<< _("Pass 1: parse failed. Try again with another '--vp 1' option.") << endl
;
677 //cerr << "Pass 1: parse failed. "
678 // << "Try again with another '--vp 1' option."
681 PROBE1(stap
, pass1__end
, &s
);
683 if (rc
|| s
.last_pass
== 1 || pending_interrupts
) return rc
;
685 times (& tms_before
);
686 gettimeofday (&tv_before
, NULL
);
688 // PASS 2: ELABORATION
689 s
.verbose
= s
.perpass_verbose
[1];
690 PROBE1(stap
, pass2__start
, &s
);
691 rc
= semantic_pass (s
);
693 // Dump a list of known probe point types, if requested.
694 if (s
.dump_probe_types
)
695 s
.pattern_root
->dump (s
);
697 if (s
.listing_mode
|| (rc
== 0 && s
.last_pass
== 2))
698 printscript(s
, cout
);
701 gettimeofday (&tv_after
, NULL
);
703 if (s
.verbose
) clog
<< "Pass 2: analyzed script: "
704 << s
.probes
.size() << " probe(s), "
705 << s
.functions
.size() << " function(s), "
706 << s
.embeds
.size() << " embed(s), "
707 << s
.globals
.size() << " global(s) "
712 if (rc
&& !s
.listing_mode
&& !s
.try_server ())
713 cerr
<< _("Pass 2: analysis failed. Try again with another '--vp 01' option.") << endl
;
714 //cerr << "Pass 2: analysis failed. "
715 // << "Try again with another '--vp 01' option."
718 /* Print out list of missing files. XXX should be "if (rc)" ? */
719 missing_rpm_list_print(s
,"-debuginfo");
721 PROBE1(stap
, pass2__end
, &s
);
723 if (rc
|| s
.listing_mode
|| s
.last_pass
== 2 || pending_interrupts
) return rc
;
725 rc
= prepare_translate_pass (s
);
726 if (rc
|| pending_interrupts
) return rc
;
728 // Generate hash. There isn't any point in generating the hash
729 // if last_pass is 2, since we'll quit before using it.
730 if (s
.use_script_cache
)
733 unsigned saved_verbose
;
736 // Make sure we're in verbose mode, so that printscript()
737 // will output function/probe bodies.
738 saved_verbose
= s
.verbose
;
740 printscript(s
, o
); // Print script to 'o'
741 s
.verbose
= saved_verbose
;
745 find_script_hash (s
, o
.str());
747 // See if we can use cached source/module.
748 if (get_script_from_cache(s
))
750 // We may still need to build uprobes, if it's not also cached.
752 rc
= uprobes_pass(s
);
754 // If our last pass isn't 5, we're done (since passes 3 and
755 // 4 just generate what we just pulled out of the cache).
756 if (rc
|| s
.last_pass
< 5 || pending_interrupts
)
759 // Short-circuit to pass 5.
764 // PASS 3: TRANSLATION
765 s
.verbose
= s
.perpass_verbose
[2];
766 times (& tms_before
);
767 gettimeofday (&tv_before
, NULL
);
768 PROBE1(stap
, pass3__start
, &s
);
770 rc
= translate_pass (s
);
771 if (! rc
&& s
.last_pass
== 3)
773 ifstream
i (s
.translated_source
.c_str());
778 gettimeofday (&tv_after
, NULL
);
781 clog
<< "Pass 3: translated to C into \""
782 << s
.translated_source
788 if (rc
&& ! s
.try_server ())
789 cerr
<< _("Pass 3: translation failed. Try again with another '--vp 001' option.") << endl
;
790 //cerr << "Pass 3: translation failed. "
791 // << "Try again with another '--vp 001' option."
794 PROBE1(stap
, pass3__end
, &s
);
796 if (rc
|| s
.last_pass
== 3 || pending_interrupts
) return rc
;
798 // PASS 4: COMPILATION
799 s
.verbose
= s
.perpass_verbose
[3];
800 times (& tms_before
);
801 gettimeofday (&tv_before
, NULL
);
802 PROBE1(stap
, pass4__start
, &s
);
806 find_stapconf_hash(s
);
807 get_stapconf_from_cache(s
);
809 rc
= compile_pass (s
);
810 if (! rc
&& s
.last_pass
== 4)
812 cout
<< ((s
.hash_path
== "") ? (s
.module_name
+ string(".ko")) : s
.hash_path
);
817 gettimeofday (&tv_after
, NULL
);
819 if (s
.verbose
) clog
<< "Pass 4: compiled C into \""
820 << s
.module_name
<< ".ko"
825 if (rc
&& ! s
.try_server ())
826 cerr
<< _("Pass 4: compilation failed. Try again with another '--vp 0001' option.") << endl
;
827 //cerr << "Pass 4: compilation failed. "
828 // << "Try again with another '--vp 0001' option."
832 // Update cache. Cache cleaning is kicked off at the beginning of this function.
833 if (s
.use_script_cache
)
834 add_script_to_cache(s
);
836 add_stapconf_to_cache(s
);
838 // We may need to save the module in $CWD if the cache was
839 // inaccessible for some reason.
840 if (! s
.use_script_cache
&& s
.last_pass
== 4)
841 s
.save_module
= true;
843 // Copy module to the current directory.
844 if (s
.save_module
&& !pending_interrupts
)
846 string module_src_path
= s
.tmpdir
+ "/" + s
.module_name
+ ".ko";
847 string module_dest_path
= s
.module_name
+ ".ko";
848 copy_file(module_src_path
, module_dest_path
, s
.verbose
> 1);
852 PROBE1(stap
, pass4__end
, &s
);
858 pass_5 (systemtap_session
&s
, vector
<remote
*> targets
)
861 s
.verbose
= s
.perpass_verbose
[4];
862 struct tms tms_before
;
863 times (& tms_before
);
864 struct timeval tv_before
;
865 gettimeofday (&tv_before
, NULL
);
866 // NB: this message is a judgement call. The other passes don't emit
867 // a "hello, I'm starting" message, but then the others aren't interactive
868 // and don't take an indefinite amount of time.
869 PROBE1(stap
, pass5__start
, &s
);
870 if (s
.verbose
) clog
<< _("Pass 5: starting run.") << endl
;
871 int rc
= remote::run(targets
);
872 struct tms tms_after
;
874 unsigned _sc_clk_tck
= sysconf (_SC_CLK_TCK
);
875 struct timeval tv_after
;
876 gettimeofday (&tv_after
, NULL
);
877 if (s
.verbose
) clog
<< "Pass 5: run completed "
882 cerr
<< _("Pass 5: run failed. Try again with another '--vp 00001' option.") << endl
;
883 //cerr << "Pass 5: run failed. "
884 // << "Try again with another '--vp 00001' option."
887 // Interrupting pass-5 to quit is normal, so we want an EXIT_SUCCESS below.
888 pending_interrupts
= 0;
890 PROBE1(stap
, pass5__end
, &s
);
896 cleanup (systemtap_session
&s
, int rc
)
898 // PASS 6: cleaning up
899 PROBE1(stap
, pass6__start
, &s
);
901 for (systemtap_session::session_map_t::iterator it
= s
.subsessions
.begin();
902 it
!= s
.subsessions
.end(); ++it
)
903 cleanup (*it
->second
, rc
);
905 // update the database information
906 if (!rc
&& s
.tapset_compile_coverage
&& !pending_interrupts
) {
907 #ifdef HAVE_LIBSQLITE3
908 update_coverage_db(s
);
910 cerr
<< _("Coverage database not available without libsqlite3") << endl
;
914 // Clean up temporary directory. Obviously, be careful with this.
917 PROBE1(stap
, pass6__end
, &s
);
921 passes_0_4_again_with_server (systemtap_session
&s
)
923 // Not a server and not already using a server.
924 assert (! s
.client_options
);
925 assert (s
.specified_servers
.empty ());
927 // Specify default server(s).
928 s
.specified_servers
.push_back ("");
930 // Remove the previous temporary directory and start fresh.
933 // Try to compile again, using the server
934 clog
<< _("Attempting compilation using a compile server")
936 int rc
= passes_0_4 (s
);
941 main (int argc
, char * const argv
[])
943 // Initialize defaults.
946 setlocale (LC_ALL
, "");
947 bindtextdomain (PACKAGE
, LOCALEDIR
);
948 textdomain (PACKAGE
);
950 // Set up our handler to catch routine signals, to allow clean
951 // and reasonably timely exit.
952 setup_signals(&handle_interrupt
);
954 // Process the command line.
955 int rc
= s
.parse_cmdline (argc
, argv
);
959 // Check for options conflicts. Exits if errors are detected.
960 s
.check_options (argc
, argv
);
962 // arguments parsed; get down to business
966 // Some of the remote methods need to write temporary data, so go ahead
967 // and create the main tempdir now.
968 rc
= create_temp_dir (s
);
970 // Prepare connections for each specified remote target.
971 vector
<remote
*> targets
;
972 if (s
.remote_uris
.empty())
973 s
.remote_uris
.push_back("direct:");
974 for (unsigned i
= 0; rc
== 0 && i
< s
.remote_uris
.size(); ++i
)
976 remote
*target
= remote::create(s
, s
.remote_uris
[i
]);
978 targets
.push_back(target
);
983 // Discover and loop over each unique session created by the remote targets.
984 set
<systemtap_session
*> sessions
;
985 for (unsigned i
= 0; i
< targets
.size(); ++i
)
986 sessions
.insert(targets
[i
]->get_session());
987 for (set
<systemtap_session
*>::iterator it
= sessions
.begin();
988 rc
== 0 && !pending_interrupts
&& it
!= sessions
.end(); ++it
)
990 systemtap_session
& ss
= **it
;
992 clog
<< _F("Session arch: %s release: %s",
993 ss
.architecture
.c_str(), ss
.kernel_release
.c_str()) << endl
;
995 // If requested, query server status. This is independent of other tasks.
996 query_server_status (ss
);
998 // If requested, manage trust of servers. This is independent of other tasks.
999 manage_server_trust (ss
);
1001 // Run the passes only if a script has been specified. The requirement for
1002 // a script has already been checked in systemtap_session::check_options.
1003 // Run the passes also if a dump of supported probe types has been requested via a server.
1004 if (ss
.have_script
|| (ss
.dump_probe_types
&& ! s
.specified_servers
.empty ()))
1006 // Run passes 0-4 for each unique session,
1007 // either locally or using a compile-server.
1008 ss
.init_try_server ();
1009 if ((rc
= passes_0_4 (ss
)))
1011 // Compilation failed.
1012 // Try again using a server if appropriate.
1013 if (ss
.try_server ())
1014 rc
= passes_0_4_again_with_server (ss
);
1017 else if (ss
.dump_probe_types
)
1019 // Dump a list of known probe point types, if requested.
1020 register_standard_tapsets(ss
);
1021 ss
.pattern_root
->dump (ss
);
1025 // Run pass 5, if requested
1026 if (rc
== 0 && s
.have_script
&& s
.last_pass
>= 5 && ! pending_interrupts
)
1027 rc
= pass_5 (s
, targets
);
1030 for (unsigned i
= 0; i
< targets
.size(); ++i
)
1034 return (rc
||pending_interrupts
) ? EXIT_FAILURE
: EXIT_SUCCESS
;
1037 /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */