llvm.org GIT mirror llvm / 0eeb3d4
Search for llvm-symbolizer binary in the same directory as argv[0], before looking for it along $PATH. This allows installs of LLVM tools outside of $PATH to find the symbolizer and produce pretty backtraces if they crash. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272232 91177308-0d34-0410-b5e6-96231b3b80d8 Richard Smith 3 years ago
41 changed file(s) with 87 addition(s) and 73 deletion(s). Raw diff Collapse all Expand all
3737
3838 /// When an error signal (such as SIBABRT or SIGSEGV) is delivered to the
3939 /// process, print a stack trace and then exit.
40 /// @brief Print a stack trace if a fatal signal occurs.
41 void PrintStackTraceOnErrorSignal(bool DisableCrashReporting = false);
40 /// \brief Print a stack trace if a fatal signal occurs.
41 /// \param Argv0 the current binary name, used to find the symbolizer
42 /// relative to the current binary before searching $PATH; can be
43 /// StringRef(), in which case we will only search $PATH.
44 /// \param DisableCrashReporting if \c true, disable the normal crash
45 /// reporting mechanisms on the underlying operating system.
46 void PrintStackTraceOnErrorSignal(StringRef Argv0,
47 bool DisableCrashReporting = false);
4248
4349 /// Disable all system dialog boxes that appear when the process crashes.
4450 void DisableSystemDialogsOnCrash();
6161 return format_hex((uint64_t)PC, PtrWidth);
6262 }
6363
64 static bool printSymbolizedStackTrace(void **StackTrace, int Depth,
64 static bool printSymbolizedStackTrace(StringRef Argv0,
65 void **StackTrace, int Depth,
6566 llvm::raw_ostream &OS)
6667 LLVM_ATTRIBUTE_USED;
6768
6869 /// Helper that launches llvm-symbolizer and symbolizes a backtrace.
69 static bool printSymbolizedStackTrace(void **StackTrace, int Depth,
70 static bool printSymbolizedStackTrace(StringRef Argv0,
71 void **StackTrace, int Depth,
7072 llvm::raw_ostream &OS) {
73 // Don't recursively invoke the llvm-symbolizer binary.
74 if (Argv0.find("llvm-symbolizer") != std::string::npos)
75 return false;
76
7177 // FIXME: Subtract necessary number from StackTrace entries to turn return addresses
7278 // into actual instruction addresses.
73 // Use llvm-symbolizer tool to symbolize the stack traces.
74 ErrorOr LLVMSymbolizerPathOrErr =
75 sys::findProgramByName("llvm-symbolizer");
79 // Use llvm-symbolizer tool to symbolize the stack traces. First look for it
80 // alongside our binary, then in $PATH.
81 ErrorOr LLVMSymbolizerPathOrErr = std::error_code();
82 if (!Argv0.empty()) {
83 StringRef Parent = llvm::sys::path::parent_path(Argv0);
84 if (!Parent.empty())
85 LLVMSymbolizerPathOrErr = sys::findProgramByName("llvm-symbolizer", Parent);
86 }
87 if (!LLVMSymbolizerPathOrErr)
88 LLVMSymbolizerPathOrErr = sys::findProgramByName("llvm-symbolizer");
7689 if (!LLVMSymbolizerPathOrErr)
7790 return false;
7891 const std::string &LLVMSymbolizerPath = *LLVMSymbolizerPathOrErr;
79 // We don't know argv0 or the address of main() at this point, but try
92
93 // If we don't know argv0 or the address of main() at this point, try
8094 // to guess it anyway (it's possible on some platforms).
81 std::string MainExecutableName = sys::fs::getMainExecutable(nullptr, nullptr);
82 if (MainExecutableName.empty() ||
83 MainExecutableName.find("llvm-symbolizer") != std::string::npos)
84 return false;
85
95 std::string MainExecutableName =
96 Argv0.empty() ? sys::fs::getMainExecutable(nullptr, nullptr)
97 : (std::string)Argv0;
8698 BumpPtrAllocator Allocator;
8799 StringSaver StrPool(Allocator);
88100 std::vector Modules(Depth, nullptr);
6666 static void (*InterruptFunction)() = nullptr;
6767
6868 static ManagedStatic> FilesToRemove;
69
70 static StringRef Argv0;
6971
7072 // IntSigs - Signals that represent requested termination. There's no bug
7173 // or failure, or if there is, it's not our direct responsibility. For whatever
407409 if (!depth)
408410 return;
409411
410 if (printSymbolizedStackTrace(StackTrace, depth, OS))
412 if (printSymbolizedStackTrace(Argv0, StackTrace, depth, OS))
411413 return;
412414 #if HAVE_DLFCN_H && __GNUG__
413415 int width = 0;
470472
471473 /// PrintStackTraceOnErrorSignal - When an error signal (such as SIGABRT or
472474 /// SIGSEGV) is delivered to the process, print a stack trace and then exit.
473 void llvm::sys::PrintStackTraceOnErrorSignal(bool DisableCrashReporting) {
475 void llvm::sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
476 bool DisableCrashReporting) {
477 ::Argv0 = Argv0;
478
474479 AddSignalHandler(PrintStackTraceSignalHandler, nullptr);
475480
476481 #if defined(__APPLE__) && defined(ENABLE_CRASH_OVERRIDES)
205205 static CRITICAL_SECTION CriticalSection;
206206 static bool CriticalSectionInitialized = false;
207207
208 static StringRef Argv0;
209
208210 enum {
209211 #if defined(_M_X64)
210212 NativeMachineType = IMAGE_FILE_MACHINE_AMD64
239241 break;
240242 }
241243
242 return printSymbolizedStackTrace(&StackTrace[0], Depth, OS);
244 return printSymbolizedStackTrace(Argv0, &StackTrace[0], Depth, OS);
243245 }
244246
245247 namespace {
495497
496498 /// PrintStackTraceOnErrorSignal - When an error signal (such as SIBABRT or
497499 /// SIGSEGV) is delivered to the process, print a stack trace and then exit.
498 void sys::PrintStackTraceOnErrorSignal(bool DisableCrashReporting) {
500 void sys::PrintStackTraceOnErrorSignal(StringRef Argv0,
501 bool DisableCrashReporting) {
502 ::Argv0 = Argv0;
503
499504 if (DisableCrashReporting || getenv("LLVM_DISABLE_CRASH_REPORT"))
500505 Process::PreventCoreFiles();
501506
112112
113113 int main(int argc, char **argv) {
114114 #ifndef DEBUG_BUGPOINT
115 llvm::sys::PrintStackTraceOnErrorSignal();
115 llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
116116 llvm::PrettyStackTraceProgram X(argc, argv);
117117 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
118118 #endif
236236 }
237237
238238 int main(int argc, char **argv) {
239 llvm::sys::PrintStackTraceOnErrorSignal();
239 llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
240240 llvm::PrettyStackTraceProgram StackPrinter(argc, argv);
241241 llvm::llvm_shutdown_obj Shutdown;
242242 LinkOptions Options;
201201 // main - Entry point for the llc compiler.
202202 //
203203 int main(int argc, char **argv) {
204 sys::PrintStackTraceOnErrorSignal();
204 sys::PrintStackTraceOnErrorSignal(argv[0]);
205205 PrettyStackTraceProgram X(argc, argv);
206206
207207 // Enable debug stream buffering.
364364 // main Driver function
365365 //
366366 int main(int argc, char **argv, char * const *envp) {
367 sys::PrintStackTraceOnErrorSignal();
367 sys::PrintStackTraceOnErrorSignal(argv[0]);
368368 PrettyStackTraceProgram X(argc, argv);
369369
370370 atexit(llvm_shutdown); // Call llvm_shutdown() on exit.
772772 int main(int argc, char **argv) {
773773 ToolName = argv[0];
774774 // Print a stack trace if we signal out.
775 sys::PrintStackTraceOnErrorSignal();
775 sys::PrintStackTraceOnErrorSignal(argv[0]);
776776 PrettyStackTraceProgram X(argc, argv);
777777 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
778778
8888
8989 int main(int argc, char **argv) {
9090 // Print a stack trace if we signal out.
91 sys::PrintStackTraceOnErrorSignal();
91 sys::PrintStackTraceOnErrorSignal(argv[0]);
9292 PrettyStackTraceProgram X(argc, argv);
9393 LLVMContext Context;
9494 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
914914
915915 int main(int argc, char **argv) {
916916 // Print a stack trace if we signal out.
917 sys::PrintStackTraceOnErrorSignal();
917 sys::PrintStackTraceOnErrorSignal(argv[0]);
918918 PrettyStackTraceProgram X(argc, argv);
919919 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
920920 cl::ParseCommandLineOptions(argc, argv, "llvm-bcanalyzer file analyzer\n");
2525 #include "llvm/Support/CommandLine.h"
2626 #include "llvm/Support/FileSystem.h"
2727 #include "llvm/Support/Format.h"
28 #include "llvm/Support/ManagedStatic.h"
2928 #include "llvm/Support/Path.h"
30 #include "llvm/Support/PrettyStackTrace.h"
3129 #include "llvm/Support/Process.h"
32 #include "llvm/Support/Signals.h"
3330 #include
3431 #include
3532
239236 }
240237
241238 int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
242 // Print a stack trace if we signal out.
243 sys::PrintStackTraceOnErrorSignal();
244 PrettyStackTraceProgram X(argc, argv);
245 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
246
247239 cl::opt ObjectFilename(
248240 cl::Positional, cl::Required, cl::location(this->ObjectFilename),
249241 cl::desc("Covered executable or object file."));
1010 #include "llvm/ProfileData/InstrProf.h"
1111 #include "llvm/Support/CommandLine.h"
1212 #include "llvm/Support/LEB128.h"
13 #include "llvm/Support/ManagedStatic.h"
14 #include "llvm/Support/PrettyStackTrace.h"
15 #include "llvm/Support/Signals.h"
1613 #include "llvm/Support/raw_ostream.h"
1714 #include
1815 #include
2118 using namespace object;
2219
2320 int convertForTestingMain(int argc, const char *argv[]) {
24 sys::PrintStackTraceOnErrorSignal();
25 PrettyStackTraceProgram X(argc, argv);
26 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
27
2821 cl::opt InputSourceFile(cl::Positional, cl::Required,
2922 cl::desc(""));
3023
1515 #include "llvm/Support/Errc.h"
1616 #include "llvm/Support/FileSystem.h"
1717 #include "llvm/Support/GCOV.h"
18 #include "llvm/Support/ManagedStatic.h"
1918 #include "llvm/Support/Path.h"
20 #include "llvm/Support/PrettyStackTrace.h"
21 #include "llvm/Support/Signals.h"
2219 #include
2320 using namespace llvm;
2421
8481 }
8582
8683 int gcovMain(int argc, const char *argv[]) {
87 // Print a stack trace if we signal out.
88 sys::PrintStackTraceOnErrorSignal();
89 PrettyStackTraceProgram X(argc, argv);
90 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
91
9284 cl::list SourceFiles(cl::Positional, cl::OneOrMore,
9385 cl::desc("SOURCEFILE"));
9486
1313 #include "llvm/ADT/StringRef.h"
1414 #include "llvm/ADT/StringSwitch.h"
1515 #include "llvm/Support/CommandLine.h"
16 #include "llvm/Support/ManagedStatic.h"
1617 #include "llvm/Support/Path.h"
18 #include "llvm/Support/PrettyStackTrace.h"
1719 #include "llvm/Support/Process.h"
20 #include "llvm/Support/Signals.h"
1821 #include "llvm/Support/raw_ostream.h"
1922 #include
2023
5053 }
5154
5255 int main(int argc, const char **argv) {
56 // Print a stack trace if we signal out.
57 sys::PrintStackTraceOnErrorSignal(argv[0]);
58 PrettyStackTraceProgram X(argc, argv);
59 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
60
5361 // If argv[0] is or ends with 'gcov', always be gcov compatible
5462 if (sys::path::stem(argv[0]).endswith_lower("gcov"))
5563 return gcovMain(argc, argv);
524524 }
525525
526526 int main(int argc, const char *argv[]) {
527 sys::PrintStackTraceOnErrorSignal();
527 sys::PrintStackTraceOnErrorSignal(argv[0]);
528528 PrettyStackTraceProgram X(argc, argv);
529529 llvm_shutdown_obj Y;
530530
133133
134134 int main(int argc, char **argv) {
135135 // Print a stack trace if we signal out.
136 sys::PrintStackTraceOnErrorSignal();
136 sys::PrintStackTraceOnErrorSignal(argv[0]);
137137 PrettyStackTraceProgram X(argc, argv);
138138
139139 LLVMContext Context;
145145
146146 int main(int argc, char **argv) {
147147 // Print a stack trace if we signal out.
148 sys::PrintStackTraceOnErrorSignal();
148 sys::PrintStackTraceOnErrorSignal(argv[0]);
149149 PrettyStackTraceProgram X(argc, argv);
150150 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
151151
101101
102102 int main(int argc, char **argv) {
103103 // Print a stack trace if we signal out.
104 sys::PrintStackTraceOnErrorSignal();
104 sys::PrintStackTraceOnErrorSignal(argv[0]);
105105 PrettyStackTraceProgram X(argc, argv);
106106
107107 LLVMContext Context;
178178
179179 int main(int argc, char **argv) {
180180 // Print a stack trace if we signal out.
181 sys::PrintStackTraceOnErrorSignal();
181 sys::PrintStackTraceOnErrorSignal(argv[0]);
182182 PrettyStackTraceProgram X(argc, argv);
183183 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
184184
334334
335335 int main(int argc, char **argv) {
336336 // Print a stack trace if we signal out.
337 sys::PrintStackTraceOnErrorSignal();
337 sys::PrintStackTraceOnErrorSignal(argv[0]);
338338 PrettyStackTraceProgram X(argc, argv);
339339
340340 LLVMContext Context;
690690
691691 int main(int argc, char **argv) {
692692 // Print a stack trace if we signal out.
693 sys::PrintStackTraceOnErrorSignal();
693 sys::PrintStackTraceOnErrorSignal(argv[0]);
694694 PrettyStackTraceProgram X(argc, argv);
695695
696696 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
368368
369369 int main(int argc, char **argv) {
370370 // Print a stack trace if we signal out.
371 sys::PrintStackTraceOnErrorSignal();
371 sys::PrintStackTraceOnErrorSignal(argv[0]);
372372 PrettyStackTraceProgram X(argc, argv);
373373 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
374374
207207
208208 int main(int argc, char **argv) {
209209 // Print a stack trace if we signal out.
210 sys::PrintStackTraceOnErrorSignal();
210 sys::PrintStackTraceOnErrorSignal(argv[0]);
211211 PrettyStackTraceProgram X(argc, argv);
212212
213213 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
13461346
13471347 int main(int argc, char **argv) {
13481348 // Print a stack trace if we signal out.
1349 sys::PrintStackTraceOnErrorSignal();
1349 sys::PrintStackTraceOnErrorSignal(argv[0]);
13501350 PrettyStackTraceProgram X(argc, argv);
13511351
13521352 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
17351735
17361736 int main(int argc, char **argv) {
17371737 // Print a stack trace if we signal out.
1738 sys::PrintStackTraceOnErrorSignal();
1738 sys::PrintStackTraceOnErrorSignal(argv[0]);
17391739 PrettyStackTraceProgram X(argc, argv);
17401740 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
17411741
432432
433433 int main(int argc_, const char *argv_[]) {
434434 // Print a stack trace if we signal out.
435 sys::PrintStackTraceOnErrorSignal();
435 sys::PrintStackTraceOnErrorSignal(argv_[0]);
436436 PrettyStackTraceProgram X(argc_, argv_);
437437
438438 ExitOnErr.setBanner("llvm-pdbdump: ");
517517
518518 int main(int argc, const char *argv[]) {
519519 // Print a stack trace if we signal out.
520 sys::PrintStackTraceOnErrorSignal();
520 sys::PrintStackTraceOnErrorSignal(argv[0]);
521521 PrettyStackTraceProgram X(argc, argv);
522522 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
523523
486486 }
487487
488488 int main(int argc, const char *argv[]) {
489 sys::PrintStackTraceOnErrorSignal();
489 sys::PrintStackTraceOnErrorSignal(argv[0]);
490490 PrettyStackTraceProgram X(argc, argv);
491491 llvm_shutdown_obj Y;
492492
725725 }
726726
727727 int main(int argc, char **argv) {
728 sys::PrintStackTraceOnErrorSignal();
728 sys::PrintStackTraceOnErrorSignal(argv[0]);
729729 PrettyStackTraceProgram X(argc, argv);
730730
731731 ProgramName = argv[0];
805805
806806 int main(int argc, char **argv) {
807807 // Print a stack trace if we signal out.
808 sys::PrintStackTraceOnErrorSignal();
808 sys::PrintStackTraceOnErrorSignal(argv[0]);
809809 PrettyStackTraceProgram X(argc, argv);
810810
811811 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
139139
140140 int main(int argc, char **argv) {
141141 // Print stack trace if we signal out.
142 sys::PrintStackTraceOnErrorSignal();
142 sys::PrintStackTraceOnErrorSignal(argv[0]);
143143 PrettyStackTraceProgram X(argc, argv);
144144 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
145145
4747
4848 int main(int argc, char *argv[]) {
4949 cl::ParseCommandLineOptions(argc, argv);
50 sys::PrintStackTraceOnErrorSignal();
50 sys::PrintStackTraceOnErrorSignal(argv[0]);
5151 PrettyStackTraceProgram X(argc, argv);
5252 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
5353
326326 // main for opt
327327 //
328328 int main(int argc, char **argv) {
329 sys::PrintStackTraceOnErrorSignal();
329 sys::PrintStackTraceOnErrorSignal(argv[0]);
330330 llvm::PrettyStackTraceProgram X(argc, argv);
331331
332332 // Enable debug stream buffering.
11961196
11971197 int main(int argc, char **argv) {
11981198 // Print stack trace if we signal out.
1199 sys::PrintStackTraceOnErrorSignal();
1199 sys::PrintStackTraceOnErrorSignal(argv[0]);
12001200 PrettyStackTraceProgram X(argc, argv);
12011201 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
12021202
525525 }
526526
527527 int main(int argc, char **argv) {
528 sys::PrintStackTraceOnErrorSignal();
528 sys::PrintStackTraceOnErrorSignal(argv[0]);
529529 llvm::PrettyStackTraceProgram X(argc, argv);
530530
531531 // Enable debug stream buffering.
7878
7979 int main(int argc, char **argv) {
8080 cl::ParseCommandLineOptions(argc, argv);
81 sys::PrintStackTraceOnErrorSignal();
81 sys::PrintStackTraceOnErrorSignal(argv[0]);
8282 PrettyStackTraceProgram X(argc, argv);
8383 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
8484
13051305 }
13061306
13071307 int main(int argc, char **argv) {
1308 sys::PrintStackTraceOnErrorSignal();
1308 sys::PrintStackTraceOnErrorSignal(argv[0]);
13091309 PrettyStackTraceProgram X(argc, argv);
13101310 cl::ParseCommandLineOptions(argc, argv);
13111311
295295
296296 int main(int argc, char **argv) {
297297 // Print a stack trace if we signal out.
298 sys::PrintStackTraceOnErrorSignal();
298 sys::PrintStackTraceOnErrorSignal(argv[0]);
299299 PrettyStackTraceProgram X(argc, argv);
300300 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
301301
178178 }
179179
180180 int main(int argc, char **argv) {
181 sys::PrintStackTraceOnErrorSignal();
181 sys::PrintStackTraceOnErrorSignal(argv[0]);
182182 PrettyStackTraceProgram X(argc, argv);
183183 cl::ParseCommandLineOptions(argc, argv);
184184
2121 const char *TestMainArgv0;
2222
2323 int main(int argc, char **argv) {
24 llvm::sys::PrintStackTraceOnErrorSignal(true /* Disable crash reporting */);
24 llvm::sys::PrintStackTraceOnErrorSignal(argv[0],
25 true /* Disable crash reporting */);
2526 testing::InitGoogleTest(&argc, argv);
2627 llvm::cl::ParseCommandLineOptions(argc, argv);
2728