[llvm] r358455 - Only use argv[0] as the main executable name if it exists.

Sean Silva via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 15 15:07:56 PDT 2019


Author: silvas
Date: Mon Apr 15 15:07:56 2019
New Revision: 358455

URL: http://llvm.org/viewvc/llvm-project?rev=358455&view=rev
Log:
Only use argv[0] as the main executable name if it exists.

Under some environments, argv[0] doesn't hold a valid file name, but
sys::fs::getMainExecutable will find the main executable properly.

This patch tweaks the logic to fall back to sys::fs::getMainExecutable
in more situations.

Differential Revision: https://reviews.llvm.org/D60730

Modified:
    llvm/trunk/lib/Support/Signals.cpp

Modified: llvm/trunk/lib/Support/Signals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Signals.cpp?rev=358455&r1=358454&r2=358455&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Signals.cpp (original)
+++ llvm/trunk/lib/Support/Signals.cpp Mon Apr 15 15:07:56 2019
@@ -131,8 +131,8 @@ static bool printSymbolizedStackTrace(St
   // If we don't know argv0 or the address of main() at this point, try
   // to guess it anyway (it's possible on some platforms).
   std::string MainExecutableName =
-      Argv0.empty() ? sys::fs::getMainExecutable(nullptr, nullptr)
-                    : (std::string)Argv0;
+      sys::fs::exists(Argv0) ? (std::string)Argv0
+                             : sys::fs::getMainExecutable(nullptr, nullptr);
   BumpPtrAllocator Allocator;
   StringSaver StrPool(Allocator);
   std::vector<const char *> Modules(Depth, nullptr);




More information about the llvm-commits mailing list