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]);
361 // RHEL4 Module.symvers file only has 3 tokens. No
362 // 'EXPORT_SYMBOL' token at the end of the line.
363 else if (tokens
.size() == 3 && tokens
[2] == "vmlinux")
364 s
.kernel_exports
.insert (tokens
[1]);
367 clog
<< _F(ngettext("Parsed kernel %s, which contained one vmlinux export",
368 "Parsed kernel %s, which contained %zu vmlinux exports",
369 s
.kernel_exports
.size()), kernel_exports_file
.c_str(),
370 s
.kernel_exports
.size()) << endl
;
378 create_temp_dir (systemtap_session
&s
)
380 if (!s
.tmpdir
.empty())
383 // Create a temporary directory to build within.
384 // Be careful with this, as "tmpdir" is "rm -rf"'d at the end.
385 const char * tmpdir_env
= getenv("TMPDIR");
389 string stapdir
= "/stapXXXXXX";
390 string tmpdirt
= tmpdir_env
+ stapdir
;
391 const char *tmpdir_name
= mkdtemp((char *)tmpdirt
.c_str());
394 const char* e
= strerror(errno
);
395 //TRANSLATORS: we can't make the directory due to the error
396 cerr
<< _F("ERROR: cannot create temporary directory (\" %s \"): %s", tmpdirt
.c_str(), e
) << endl
;
400 s
.tmpdir
= tmpdir_name
;
403 clog
<< _F("Created temporary directory \"%s\"", s
.tmpdir
.c_str()) << endl
;
408 remove_temp_dir(systemtap_session
&s
)
410 if (!s
.tmpdir
.empty())
412 if (s
.keep_tmpdir
&& !s
.tmpdir_opt_set
)
413 clog
<< _F("Keeping temporary directory \"%s\"", s
.tmpdir
.c_str()) << endl
;
414 else if (!s
.tmpdir_opt_set
)
416 // Mask signals while we're deleting the temporary directory.
417 stap_sigmasker masked
;
419 // Remove the temporary directory.
420 vector
<string
> cleanupcmd
;
421 cleanupcmd
.push_back("rm");
422 cleanupcmd
.push_back("-rf");
423 cleanupcmd
.push_back(s
.tmpdir
);
425 (void) stap_system(s
.verbose
, cleanupcmd
);
431 // Compilation passes 0 through 4
433 passes_0_4 (systemtap_session
&s
)
437 // If we don't know the release, there's no hope either locally or on a server.
438 if (s
.kernel_release
.empty())
440 if (s
.kernel_build_tree
.empty())
441 cerr
<< _("ERROR: kernel release isn't specified") << endl
;
443 cerr
<< _F("ERROR: kernel release isn't found in \"%s\"",
444 s
.kernel_build_tree
.c_str()) << endl
;
448 // Create a temporary directory to build within.
449 // Be careful with this, as "s.tmpdir" is "rm -rf"'d at the end.
450 rc
= create_temp_dir (s
);
454 // Perform passes 0 through 4 using a compile server?
455 if (! s
.specified_servers
.empty ())
458 compile_server_client
client (s
);
459 int rc
= client
.passes_0_4 ();
460 // Need to give a user a better diagnostic, if she didn't
461 // even ask for a server
462 if (rc
&& s
.automatic_server_mode
) {
463 cerr
<< _("Note: --use-server --unprivileged was selected because of stapusr membership.") << endl
;
467 cerr
<< _("WARNING: Without NSS, using a compile-server is not supported by this version of systemtap") << endl
;
468 // This cannot be an attempt to use a server after a local compile failed
469 // since --use-server-on-error is locked to 'no' if we don't have
471 assert (! s
.try_server ());
475 // PASS 0: setting up
476 s
.verbose
= s
.perpass_verbose
[0];
477 PROBE1(stap
, pass0__start
, &s
);
479 // For PR1477, we used to override $PATH and $LC_ALL and other stuff
480 // here. We seem to use complete pathnames in
481 // buildrun.cxx/tapsets.cxx now, so this is not necessary. Further,
482 // it interferes with util.cxx:find_executable(), used for $PATH
485 s
.kernel_base_release
.assign(s
.kernel_release
, 0, s
.kernel_release
.find('-'));
487 // Now that no further changes to s.kernel_build_tree can occur, let's use it.
488 if ((rc
= parse_kernel_config (s
)) != 0)
490 // Try again with a server
495 if ((rc
= parse_kernel_exports (s
)) != 0)
497 // Try again with a server
502 // Create the name of the C source file within the temporary
504 s
.translated_source
= string(s
.tmpdir
) + "/" + s
.module_name
+ ".c";
506 PROBE1(stap
, pass0__end
, &s
);
508 struct tms tms_before
;
509 times (& tms_before
);
510 struct timeval tv_before
;
511 gettimeofday (&tv_before
, NULL
);
513 // PASS 1a: PARSING USER SCRIPT
514 PROBE1(stap
, pass1a__start
, &s
);
516 struct stat user_file_stat
;
517 int user_file_stat_rc
= -1;
519 if (s
.script_file
== "-")
521 s
.user_file
= parse (s
, cin
, s
.guru_mode
);
522 user_file_stat_rc
= fstat (STDIN_FILENO
, & user_file_stat
);
524 else if (s
.script_file
!= "")
526 s
.user_file
= parse (s
, s
.script_file
, s
.guru_mode
);
527 user_file_stat_rc
= stat (s
.script_file
.c_str(), & user_file_stat
);
531 istringstream
ii (s
.cmdline_script
);
532 s
.user_file
= parse (s
, ii
, s
.guru_mode
);
534 if (s
.user_file
== 0)
536 // Syntax errors already printed.
540 // Construct arch / kernel-versioning search path
541 vector
<string
> version_suffixes
;
542 string kvr
= s
.kernel_release
;
543 const string
& arch
= s
.architecture
;
544 // add full kernel-version-release (2.6.NN-FOOBAR) + arch
545 version_suffixes
.push_back ("/" + kvr
+ "/" + arch
);
546 version_suffixes
.push_back ("/" + kvr
);
547 // add kernel version (2.6.NN) + arch
548 if (kvr
!= s
.kernel_base_release
) {
549 kvr
= s
.kernel_base_release
;
550 version_suffixes
.push_back ("/" + kvr
+ "/" + arch
);
551 version_suffixes
.push_back ("/" + kvr
);
553 // add kernel family (2.6) + arch
554 string::size_type dot1_index
= kvr
.find ('.');
555 string::size_type dot2_index
= kvr
.rfind ('.');
556 while (dot2_index
> dot1_index
&& dot2_index
!= string::npos
) {
557 kvr
.erase(dot2_index
);
558 version_suffixes
.push_back ("/" + kvr
+ "/" + arch
);
559 version_suffixes
.push_back ("/" + kvr
);
560 dot2_index
= kvr
.rfind ('.');
562 // add architecture search path
563 version_suffixes
.push_back("/" + arch
);
564 // add empty string as last element
565 version_suffixes
.push_back ("");
567 // PASS 1b: PARSING LIBRARY SCRIPTS
568 PROBE1(stap
, pass1b__start
, &s
);
570 set
<pair
<dev_t
, ino_t
> > seen_library_files
;
572 for (unsigned i
=0; i
<s
.include_path
.size(); i
++)
574 // now iterate upon it
575 for (unsigned k
=0; k
<version_suffixes
.size(); k
++)
578 string dir
= s
.include_path
[i
] + version_suffixes
[k
] + "/*.stp";
579 int r
= glob(dir
.c_str (), 0, NULL
, & globbuf
);
580 if (r
== GLOB_NOSPACE
|| r
== GLOB_ABORTED
)
582 // GLOB_NOMATCH is acceptable
584 unsigned prev_s_library_files
= s
.library_files
.size();
586 for (unsigned j
=0; j
<globbuf
.gl_pathc
; j
++)
588 if (pending_interrupts
)
591 struct stat tapset_file_stat
;
592 int stat_rc
= stat (globbuf
.gl_pathv
[j
], & tapset_file_stat
);
593 if (stat_rc
== 0 && user_file_stat_rc
== 0 &&
594 user_file_stat
.st_dev
== tapset_file_stat
.st_dev
&&
595 user_file_stat
.st_ino
== tapset_file_stat
.st_ino
)
598 << _F("usage error: tapset file '%s' cannot be run directly as a session script.",
599 globbuf
.gl_pathv
[j
]) << endl
;
603 // PR11949: duplicate-eliminate tapset files
606 pair
<dev_t
,ino_t
> here
= make_pair(tapset_file_stat
.st_dev
,
607 tapset_file_stat
.st_ino
);
608 if (seen_library_files
.find(here
) != seen_library_files
.end())
610 seen_library_files
.insert (here
);
613 // XXX: privilege only for /usr/share/systemtap?
614 stapfile
* f
= parse (s
, globbuf
.gl_pathv
[j
], true);
615 if (f
== 0 && !s
.suppress_warnings
)
616 s
.print_warning("tapset '" + string(globbuf
.gl_pathv
[j
])
617 + "' has errors, and will be skipped.");
619 s
.library_files
.push_back (f
);
622 unsigned next_s_library_files
= s
.library_files
.size();
623 if (s
.verbose
>1 && globbuf
.gl_pathc
> 0)
624 //TRANSLATORS: Searching through directories, 'processed' means 'examined so far'
625 clog
<< _F("Searched: \" %s \", found: %zu, processed: %u",
626 dir
.c_str(), globbuf
.gl_pathc
,
627 (next_s_library_files
-prev_s_library_files
)) << endl
;
629 globfree (& globbuf
);
635 if (rc
== 0 && s
.last_pass
== 1)
637 cout
<< _("# parse tree dump") << endl
;
638 s
.user_file
->print (cout
);
641 for (unsigned i
=0; i
<s
.library_files
.size(); i
++)
643 s
.library_files
[i
]->print (cout
);
648 struct tms tms_after
;
650 unsigned _sc_clk_tck
= sysconf (_SC_CLK_TCK
);
651 struct timeval tv_after
;
652 gettimeofday (&tv_after
, NULL
);
654 #define TIMESPRINT "in " << \
655 (tms_after.tms_cutime + tms_after.tms_utime \
656 - tms_before.tms_cutime - tms_before.tms_utime) * 1000 / (_sc_clk_tck) << "usr/" \
657 << (tms_after.tms_cstime + tms_after.tms_stime \
658 - tms_before.tms_cstime - tms_before.tms_stime) * 1000 / (_sc_clk_tck) << "sys/" \
659 << ((tv_after.tv_sec - tv_before.tv_sec) * 1000 + \
660 ((long)tv_after.tv_usec - (long)tv_before.tv_usec) / 1000) << "real ms."
662 // syntax errors, if any, are already printed
665 clog
<< "Pass 1: parsed user script and "
666 << s
.library_files
.size()
667 << " library script(s) "
673 if (rc
&& !s
.listing_mode
)
674 cerr
<< _("Pass 1: parse failed. Try again with another '--vp 1' option.") << endl
;
675 //cerr << "Pass 1: parse failed. "
676 // << "Try again with another '--vp 1' option."
679 PROBE1(stap
, pass1__end
, &s
);
681 if (rc
|| s
.last_pass
== 1 || pending_interrupts
) return rc
;
683 times (& tms_before
);
684 gettimeofday (&tv_before
, NULL
);
686 // PASS 2: ELABORATION
687 s
.verbose
= s
.perpass_verbose
[1];
688 PROBE1(stap
, pass2__start
, &s
);
689 rc
= semantic_pass (s
);
691 if (s
.listing_mode
|| (rc
== 0 && s
.last_pass
== 2))
692 printscript(s
, cout
);
695 gettimeofday (&tv_after
, NULL
);
697 if (s
.verbose
) clog
<< "Pass 2: analyzed script: "
698 << s
.probes
.size() << " probe(s), "
699 << s
.functions
.size() << " function(s), "
700 << s
.embeds
.size() << " embed(s), "
701 << s
.globals
.size() << " global(s) "
706 if (rc
&& !s
.listing_mode
&& !s
.try_server ())
707 cerr
<< _("Pass 2: analysis failed. Try again with another '--vp 01' option.") << endl
;
708 //cerr << "Pass 2: analysis failed. "
709 // << "Try again with another '--vp 01' option."
712 /* Print out list of missing files. XXX should be "if (rc)" ? */
713 missing_rpm_list_print(s
,"-debuginfo");
715 PROBE1(stap
, pass2__end
, &s
);
717 if (rc
|| s
.listing_mode
|| s
.last_pass
== 2 || pending_interrupts
) return rc
;
719 rc
= prepare_translate_pass (s
);
720 if (rc
|| pending_interrupts
) return rc
;
722 // Generate hash. There isn't any point in generating the hash
723 // if last_pass is 2, since we'll quit before using it.
724 if (s
.use_script_cache
)
727 unsigned saved_verbose
;
730 // Make sure we're in verbose mode, so that printscript()
731 // will output function/probe bodies.
732 saved_verbose
= s
.verbose
;
734 printscript(s
, o
); // Print script to 'o'
735 s
.verbose
= saved_verbose
;
739 find_script_hash (s
, o
.str());
741 // See if we can use cached source/module.
742 if (get_script_from_cache(s
))
744 // We may still need to build uprobes, if it's not also cached.
746 rc
= uprobes_pass(s
);
748 // If our last pass isn't 5, we're done (since passes 3 and
749 // 4 just generate what we just pulled out of the cache).
750 if (rc
|| s
.last_pass
< 5 || pending_interrupts
)
753 // Short-circuit to pass 5.
758 // PASS 3: TRANSLATION
759 s
.verbose
= s
.perpass_verbose
[2];
760 times (& tms_before
);
761 gettimeofday (&tv_before
, NULL
);
762 PROBE1(stap
, pass3__start
, &s
);
764 rc
= translate_pass (s
);
765 if (! rc
&& s
.last_pass
== 3)
767 ifstream
i (s
.translated_source
.c_str());
772 gettimeofday (&tv_after
, NULL
);
775 clog
<< "Pass 3: translated to C into \""
776 << s
.translated_source
782 if (rc
&& ! s
.try_server ())
783 cerr
<< _("Pass 3: translation failed. Try again with another '--vp 001' option.") << endl
;
784 //cerr << "Pass 3: translation failed. "
785 // << "Try again with another '--vp 001' option."
788 PROBE1(stap
, pass3__end
, &s
);
790 if (rc
|| s
.last_pass
== 3 || pending_interrupts
) return rc
;
792 // PASS 4: COMPILATION
793 s
.verbose
= s
.perpass_verbose
[3];
794 times (& tms_before
);
795 gettimeofday (&tv_before
, NULL
);
796 PROBE1(stap
, pass4__start
, &s
);
800 find_stapconf_hash(s
);
801 get_stapconf_from_cache(s
);
803 rc
= compile_pass (s
);
804 if (! rc
&& s
.last_pass
== 4)
806 cout
<< ((s
.hash_path
== "") ? (s
.module_name
+ string(".ko")) : s
.hash_path
);
811 gettimeofday (&tv_after
, NULL
);
813 if (s
.verbose
) clog
<< "Pass 4: compiled C into \""
814 << s
.module_name
<< ".ko"
819 if (rc
&& ! s
.try_server ())
820 cerr
<< _("Pass 4: compilation failed. Try again with another '--vp 0001' option.") << endl
;
821 //cerr << "Pass 4: compilation failed. "
822 // << "Try again with another '--vp 0001' option."
826 // Update cache. Cache cleaning is kicked off at the beginning of this function.
827 if (s
.use_script_cache
)
828 add_script_to_cache(s
);
830 add_stapconf_to_cache(s
);
832 // We may need to save the module in $CWD if the cache was
833 // inaccessible for some reason.
834 if (! s
.use_script_cache
&& s
.last_pass
== 4)
835 s
.save_module
= true;
837 // Copy module to the current directory.
838 if (s
.save_module
&& !pending_interrupts
)
840 string module_src_path
= s
.tmpdir
+ "/" + s
.module_name
+ ".ko";
841 string module_dest_path
= s
.module_name
+ ".ko";
842 copy_file(module_src_path
, module_dest_path
, s
.verbose
> 1);
846 PROBE1(stap
, pass4__end
, &s
);
852 pass_5 (systemtap_session
&s
, vector
<remote
*> targets
)
855 s
.verbose
= s
.perpass_verbose
[4];
856 struct tms tms_before
;
857 times (& tms_before
);
858 struct timeval tv_before
;
859 gettimeofday (&tv_before
, NULL
);
860 // NB: this message is a judgement call. The other passes don't emit
861 // a "hello, I'm starting" message, but then the others aren't interactive
862 // and don't take an indefinite amount of time.
863 PROBE1(stap
, pass5__start
, &s
);
864 if (s
.verbose
) clog
<< _("Pass 5: starting run.") << endl
;
865 int rc
= remote::run(targets
);
866 struct tms tms_after
;
868 unsigned _sc_clk_tck
= sysconf (_SC_CLK_TCK
);
869 struct timeval tv_after
;
870 gettimeofday (&tv_after
, NULL
);
871 if (s
.verbose
) clog
<< "Pass 5: run completed "
876 cerr
<< _("Pass 5: run failed. Try again with another '--vp 00001' option.") << endl
;
877 //cerr << "Pass 5: run failed. "
878 // << "Try again with another '--vp 00001' option."
881 // Interrupting pass-5 to quit is normal, so we want an EXIT_SUCCESS below.
882 pending_interrupts
= 0;
884 PROBE1(stap
, pass5__end
, &s
);
890 cleanup (systemtap_session
&s
, int rc
)
892 // PASS 6: cleaning up
893 PROBE1(stap
, pass6__start
, &s
);
895 for (systemtap_session::session_map_t::iterator it
= s
.subsessions
.begin();
896 it
!= s
.subsessions
.end(); ++it
)
897 cleanup (*it
->second
, rc
);
899 // update the database information
900 if (!rc
&& s
.tapset_compile_coverage
&& !pending_interrupts
) {
901 #ifdef HAVE_LIBSQLITE3
902 update_coverage_db(s
);
904 cerr
<< _("Coverage database not available without libsqlite3") << endl
;
908 // Clean up temporary directory. Obviously, be careful with this.
911 PROBE1(stap
, pass6__end
, &s
);
915 passes_0_4_again_with_server (systemtap_session
&s
)
917 // Not a server and not already using a server.
918 assert (! s
.client_options
);
919 assert (s
.specified_servers
.empty ());
921 // Specify default server(s).
922 s
.specified_servers
.push_back ("");
924 // Remove the previous temporary directory and start fresh.
927 // Try to compile again, using the server
928 clog
<< _("Attempting compilation using a compile server")
930 int rc
= passes_0_4 (s
);
935 main (int argc
, char * const argv
[])
937 // Initialize defaults.
940 setlocale (LC_ALL
, "");
941 bindtextdomain (PACKAGE
, LOCALEDIR
);
942 textdomain (PACKAGE
);
944 // Set up our handler to catch routine signals, to allow clean
945 // and reasonably timely exit.
946 setup_signals(&handle_interrupt
);
948 // Process the command line.
949 int rc
= s
.parse_cmdline (argc
, argv
);
953 // Check for options conflicts. Exits if errors are detected.
954 s
.check_options (argc
, argv
);
956 // arguments parsed; get down to business
960 // Some of the remote methods need to write temporary data, so go ahead
961 // and create the main tempdir now.
962 rc
= create_temp_dir (s
);
964 // Prepare connections for each specified remote target.
965 vector
<remote
*> targets
;
966 if (s
.remote_uris
.empty())
967 s
.remote_uris
.push_back("direct:");
968 for (unsigned i
= 0; rc
== 0 && i
< s
.remote_uris
.size(); ++i
)
970 remote
*target
= remote::create(s
, s
.remote_uris
[i
]);
972 targets
.push_back(target
);
977 // Discover and loop over each unique session created by the remote targets.
978 set
<systemtap_session
*> sessions
;
979 for (unsigned i
= 0; i
< targets
.size(); ++i
)
980 sessions
.insert(targets
[i
]->get_session());
981 for (set
<systemtap_session
*>::iterator it
= sessions
.begin();
982 rc
== 0 && !pending_interrupts
&& it
!= sessions
.end(); ++it
)
984 systemtap_session
& ss
= **it
;
986 clog
<< _F("Session arch: %s release: %s",
987 ss
.architecture
.c_str(), ss
.kernel_release
.c_str()) << endl
;
989 // If requested, query server status. This is independent of other tasks.
990 query_server_status (ss
);
992 // If requested, manage trust of servers. This is independent of other tasks.
993 manage_server_trust (ss
);
995 // Run the passes only if a script has been specified. The requirement for
996 // a script has already been checked in systemtap_session::check_options.
999 // Run passes 0-4 for each unique session,
1000 // either locally or using a compile-server.
1001 ss
.init_try_server ();
1002 if ((rc
= passes_0_4 (ss
)))
1004 // Compilation failed.
1005 // Try again using a server if appropriate.
1006 if (ss
.try_server ())
1007 rc
= passes_0_4_again_with_server (ss
);
1012 // Run pass 5, if requested
1013 if (rc
== 0 && s
.have_script
&& s
.last_pass
>= 5 && ! pending_interrupts
)
1014 rc
= pass_5 (s
, targets
);
1017 for (unsigned i
= 0; i
< targets
.size(); ++i
)
1021 return (rc
||pending_interrupts
) ? EXIT_FAILURE
: EXIT_SUCCESS
;
1024 /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */