"InitGoogle"-style argv stashing.
This lets us give the command line in crash dumps when dex2oat dies in the
continuous build on the Mac. I've also taken the opportunity to use the
basename of argv[0] as the default log tag, so dex2oat will now show up in
logcat as "dex2oat" instead of "art" (and we can probably stop manually
prefixing dex2oat log output).
Also stash pthread_self() so we can _correctly_ report "handle=" in the
SIGQUIT output.
Change-Id: Ia8249cd19bab5b816cb94a531a65becdfacaa98b
diff --git a/src/logging.cc b/src/logging.cc
index 7d176a2..86c8bdf 100644
--- a/src/logging.cc
+++ b/src/logging.cc
@@ -24,14 +24,28 @@
LogVerbosity gLogVerbosity;
-static bool gInitLoggingCalled = false;
static LogSeverity gMinimumLogSeverity = INFO;
+static std::string* gCmdLine;
+static std::string* gProgramInvocationName;
+static std::string* gProgramInvocationShortName;
static Mutex& GetLoggingLock() {
static Mutex logging_lock("LogMessage lock");
return logging_lock;
}
+const char* GetCmdLine() {
+ return (gCmdLine != NULL) ? gCmdLine->c_str() : NULL;
+}
+
+const char* ProgramInvocationName() {
+ return (gProgramInvocationName != NULL) ? gProgramInvocationName->c_str() : "art";
+}
+
+const char* ProgramInvocationShortName() {
+ return (gProgramInvocationShortName != NULL) ? gProgramInvocationShortName->c_str() : "art";
+}
+
// Configure logging based on ANDROID_LOG_TAGS environment variable.
// We need to parse a string that looks like
//
@@ -40,8 +54,19 @@
// The tag (or '*' for the global level) comes first, followed by a colon
// and a letter indicating the minimum priority level we're expected to log.
// This can be used to reveal or conceal logs with specific tags.
-void InitLogging() {
- gInitLoggingCalled = true;
+void InitLogging(char* argv[]) {
+ // Stash the command line for later use. We can use /proc/self/cmdline on Linux to recover this,
+ // but we don't have that luxury on the Mac, and there are a couple of argv[0] variants that are
+ // commonly used.
+ gCmdLine = new std::string(argv[0]);
+ for (size_t i = 1; argv[i] != NULL; ++i) {
+ gCmdLine->append(" ");
+ gCmdLine->append(argv[i]);
+ }
+ gProgramInvocationName = new std::string(argv[0]);
+ const char* last_slash = strrchr(argv[0], '/');
+ gProgramInvocationShortName = new std::string((last_slash != NULL) ? last_slash + 1 : argv[0]);
+
const char* tags = getenv("ANDROID_LOG_TAGS");
if (tags == NULL) {
return;