From 570db83ef4b9d5f0aa1594764be06c681d0ca81e Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Fri, 21 Feb 2020 11:20:21 +0100 Subject: [PATCH] Don't print a dash if thread name is not known Normally `ThreadName()` should return `programname-PID/threadname-TID`, but if the thread name is not known it would return `programname-PID/-TID`. Change it to return `programname-PID/TID` instead. --- src/mp/util.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mp/util.cpp b/src/mp/util.cpp index b6ee50c3..363f09cc 100644 --- a/src/mp/util.cpp +++ b/src/mp/util.cpp @@ -51,7 +51,11 @@ std::string ThreadName(const char* exe_name) #endif // HAVE_PTHREAD_GETNAME_NP std::ostringstream buffer; - buffer << (exe_name ? exe_name : "") << "-" << getpid() << "/" << thread_name << "-"; + buffer << (exe_name ? exe_name : "") << "-" << getpid() << "/"; + + if (thread_name[0] != '\0') { + buffer << thread_name << "-"; + } // Prefer platform specific thread ids over the standard C++11 ones because // the former are shorter and are the same as what gdb prints "LWP ...".