[Lldb-commits] [lldb] r304795 - replace uses of strerror with llvm::sys::StrError
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Tue Jun 6 07:06:17 PDT 2017
Author: labath
Date: Tue Jun 6 09:06:17 2017
New Revision: 304795
URL: http://llvm.org/viewvc/llvm-project?rev=304795&view=rev
Log:
replace uses of strerror with llvm::sys::StrError
strerror is not thread-safe. llvm's StrError tries hard to retrieve the
string in a thread-safe way and falls back to strerror only if it does
not have another way.
Modified:
lldb/trunk/source/Commands/CommandObjectRegister.cpp
lldb/trunk/source/Host/common/Host.cpp
lldb/trunk/source/Host/posix/ConnectionFileDescriptorPosix.cpp
lldb/trunk/source/Host/posix/ProcessLauncherPosixFork.cpp
lldb/trunk/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp
lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
lldb/trunk/source/Utility/Status.cpp
lldb/trunk/tools/lldb-server/lldb-gdbserver.cpp
Modified: lldb/trunk/source/Commands/CommandObjectRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectRegister.cpp?rev=304795&r1=304794&r2=304795&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectRegister.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectRegister.cpp Tue Jun 6 09:06:17 2017
@@ -7,12 +7,6 @@
//
//===----------------------------------------------------------------------===//
-// C Includes
-// C++ Includes
-// Other libraries and framework includes
-#include "llvm/ADT/STLExtras.h"
-
-// Project includes
#include "CommandObjectRegister.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/RegisterValue.h"
@@ -32,6 +26,7 @@
#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Thread.h"
#include "lldb/Utility/DataExtractor.h"
+#include "llvm/Support/Errno.h"
using namespace lldb;
using namespace lldb_private;
@@ -178,8 +173,8 @@ protected:
if (set_idx < reg_ctx->GetRegisterSetCount()) {
if (!DumpRegisterSet(m_exe_ctx, strm, reg_ctx, set_idx)) {
if (errno)
- result.AppendErrorWithFormat("register read failed: %s\n",
- strerror(errno));
+ result.AppendErrorWithFormatv("register read failed: {0}\n",
+ llvm::sys::StrError());
else
result.AppendError("unknown error while reading registers.\n");
result.SetStatus(eReturnStatusFailed);
Modified: lldb/trunk/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=304795&r1=304794&r2=304795&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Host.cpp (original)
+++ lldb/trunk/source/Host/common/Host.cpp Tue Jun 6 09:06:17 2017
@@ -68,6 +68,7 @@
#include "lldb/Utility/Status.h"
#include "lldb/lldb-private-forward.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/Errno.h"
#include "llvm/Support/FileSystem.h"
#if defined(_WIN32)
@@ -217,10 +218,9 @@ static thread_result_t MonitorChildProce
if (errno == EINTR)
continue;
else {
- if (log)
- log->Printf(
- "%s (arg = %p) thread exiting because waitpid failed (%s)...",
- __FUNCTION__, arg, strerror(errno));
+ LLDB_LOG(log,
+ "arg = {0}, thread exiting because waitpid failed ({1})...",
+ arg, llvm::sys::StrError());
break;
}
} else if (wait_pid > 0) {
Modified: lldb/trunk/source/Host/posix/ConnectionFileDescriptorPosix.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/ConnectionFileDescriptorPosix.cpp?rev=304795&r1=304794&r2=304795&view=diff
==============================================================================
--- lldb/trunk/source/Host/posix/ConnectionFileDescriptorPosix.cpp (original)
+++ lldb/trunk/source/Host/posix/ConnectionFileDescriptorPosix.cpp Tue Jun 6 09:06:17 2017
@@ -36,6 +36,7 @@
#include <sstream>
// Other libraries and framework includes
+#include "llvm/Support/Errno.h"
#include "llvm/Support/ErrorHandling.h"
#if defined(__APPLE__)
#include "llvm/ADT/SmallVector.h"
@@ -461,10 +462,8 @@ size_t ConnectionFileDescriptor::Read(vo
return 0;
default:
- if (log)
- log->Printf(
- "%p ConnectionFileDescriptor::Read (), unexpected error: %s",
- static_cast<void *>(this), strerror(error_value));
+ LLDB_LOG(log, "this = {0}, unexpected error: {1}", this,
+ llvm::sys::StrError(error_value));
status = eConnectionStatusError;
break; // Break to close....
}
Modified: lldb/trunk/source/Host/posix/ProcessLauncherPosixFork.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/posix/ProcessLauncherPosixFork.cpp?rev=304795&r1=304794&r2=304795&view=diff
==============================================================================
--- lldb/trunk/source/Host/posix/ProcessLauncherPosixFork.cpp (original)
+++ lldb/trunk/source/Host/posix/ProcessLauncherPosixFork.cpp Tue Jun 6 09:06:17 2017
@@ -14,6 +14,7 @@
#include "lldb/Target/ProcessLaunchInfo.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Log.h"
+#include "llvm/Support/Errno.h"
#include <limits.h>
#include <sys/ptrace.h>
@@ -204,8 +205,8 @@ ProcessLauncherPosixFork::LaunchProcess(
::pid_t pid = ::fork();
if (pid == -1) {
// Fork failed
- error.SetErrorStringWithFormat("Fork failed with error message: %s",
- strerror(errno));
+ error.SetErrorStringWithFormatv("Fork failed with error message: {0}",
+ llvm::sys::StrError());
return HostProcess(LLDB_INVALID_PROCESS_ID);
}
if (pid == 0) {
Modified: lldb/trunk/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp?rev=304795&r1=304794&r2=304795&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Darwin/DarwinProcessLauncher.cpp Tue Jun 6 09:06:17 2017
@@ -35,6 +35,7 @@
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StreamString.h"
+#include "llvm/Support/Errno.h"
#include "CFBundle.h"
#include "CFString.h"
@@ -319,13 +320,12 @@ static Status PosixSpawnChildForPTraceDe
::posix_spawnattr_setsigdefault(&attr, &all_signals);
if ((error_code = ::posix_spawnattr_setflags(&attr, flags)) != 0) {
- if (log)
- log->Printf("::posix_spawnattr_setflags(&attr, "
- "POSIX_SPAWN_START_SUSPENDED%s) failed: %s",
- flags & _POSIX_SPAWN_DISABLE_ASLR
- ? " | _POSIX_SPAWN_DISABLE_ASLR"
- : "",
- strerror(error_code));
+ LLDB_LOG(log,
+ "::posix_spawnattr_setflags(&attr, "
+ "POSIX_SPAWN_START_SUSPENDED{0}) failed: {1}",
+ flags & _POSIX_SPAWN_DISABLE_ASLR ? " | _POSIX_SPAWN_DISABLE_ASLR"
+ : "",
+ llvm::sys::StrError(error_code));
error.SetError(error_code, eErrorTypePOSIX);
return error;
}
@@ -341,10 +341,10 @@ static Status PosixSpawnChildForPTraceDe
error_code =
::posix_spawnattr_setbinpref_np(&attr, 1, &desired_cpu_type, &ocount);
if (error_code != 0) {
- if (log)
- log->Printf("::posix_spawnattr_setbinpref_np(&attr, 1, "
- "cpu_type = 0x%8.8x, count => %llu): %s",
- desired_cpu_type, (uint64_t)ocount, strerror(error_code));
+ LLDB_LOG(log,
+ "::posix_spawnattr_setbinpref_np(&attr, 1, "
+ "cpu_type = {0:x8}, count => {1}): {2}",
+ desired_cpu_type, ocount, llvm::sys::StrError(error_code));
error.SetError(error_code, eErrorTypePOSIX);
return error;
}
@@ -361,10 +361,8 @@ static Status PosixSpawnChildForPTraceDe
posix_spawn_file_actions_t file_actions;
if ((error_code = ::posix_spawn_file_actions_init(&file_actions)) != 0) {
- if (log)
- log->Printf("::posix_spawn_file_actions_init(&file_actions) "
- "failed: %s",
- strerror(error_code));
+ LLDB_LOG(log, "::posix_spawn_file_actions_init(&file_actions) failed: {0}",
+ llvm::sys::StrError(error_code));
error.SetError(error_code, eErrorTypePOSIX);
return error;
}
@@ -409,11 +407,11 @@ static Status PosixSpawnChildForPTraceDe
error_code = ::posix_spawnp(pid, path, &file_actions, &attr,
(char *const *)argv, (char *const *)envp);
if (error_code != 0) {
- if (log)
- log->Printf("::posix_spawnp(pid => %p, path = '%s', file_actions "
- "= %p, attr = %p, argv = %p, envp = %p) failed: %s",
- pid, path, &file_actions, &attr, argv, envp,
- strerror(error_code));
+ LLDB_LOG(log,
+ "::posix_spawnp(pid => {0}, path = '{1}', file_actions "
+ "= {2}, attr = {3}, argv = {4}, envp = {5}) failed: {6}",
+ pid, path, &file_actions, &attr, argv, envp,
+ llvm::sys::StrError(error_code));
error.SetError(error_code, eErrorTypePOSIX);
return error;
}
Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp?rev=304795&r1=304794&r2=304795&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessMonitor.cpp Tue Jun 6 09:06:17 2017
@@ -30,6 +30,7 @@
#include "lldb/Target/Thread.h"
#include "lldb/Target/UnixSignals.h"
#include "lldb/Utility/Status.h"
+#include "llvm/Support/Errno.h"
#include "FreeBSDThread.h"
#include "Plugins/Process/POSIX/CrashReason.h"
@@ -529,10 +530,8 @@ void ResumeOperation::Execute(ProcessMon
if (PTRACE(PT_CONTINUE, pid, (caddr_t)1, data)) {
Log *log(ProcessPOSIXLog::GetLogIfAllCategoriesSet(POSIX_LOG_PROCESS));
-
- if (log)
- log->Printf("ResumeOperation (%" PRIu64 ") failed: %s", pid,
- strerror(errno));
+ LLDB_LOG(log, "ResumeOperation ({0}) failed: {1}", pid,
+ llvm::sys::StrError(errno));
m_result = false;
} else
m_result = true;
Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp?rev=304795&r1=304794&r2=304795&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Tue Jun 6 09:06:17 2017
@@ -43,14 +43,14 @@
#include "lldb/Utility/LLDBAssert.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StringExtractor.h"
+#include "llvm/Support/Errno.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Threading.h"
#include "NativeThreadLinux.h"
#include "Plugins/Process/POSIX/ProcessPOSIXLog.h"
#include "Procfs.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/Threading.h"
-
#include <linux/unistd.h>
#include <sys/socket.h>
#include <sys/syscall.h>
@@ -97,7 +97,7 @@ static bool ProcessVmReadvSupported() {
LLDB_LOG(log,
"syscall process_vm_readv failed (error: {0}). Fast memory "
"reads disabled.",
- strerror(errno));
+ llvm::sys::StrError());
});
return is_supported;
@@ -1988,7 +1988,7 @@ Status NativeProcessLinux::ReadMemory(ll
LLDB_LOG(log,
"using process_vm_readv to read {0} bytes from inferior "
"address {1:x}: {2}",
- size, addr, success ? "Success" : strerror(errno));
+ size, addr, success ? "Success" : llvm::sys::StrError(errno));
if (success)
return Status();
Modified: lldb/trunk/source/Utility/Status.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/Status.cpp?rev=304795&r1=304794&r2=304795&view=diff
==============================================================================
--- lldb/trunk/source/Utility/Status.cpp (original)
+++ lldb/trunk/source/Utility/Status.cpp Tue Jun 6 09:06:17 2017
@@ -11,10 +11,11 @@
#include "lldb/Utility/Status.h"
#include "lldb/Utility/VASPrintf.h"
-#include "lldb/lldb-defines.h" // for LLDB_GENERIC_ERROR
-#include "lldb/lldb-enumerations.h" // for ErrorType, ErrorType::eErr...
-#include "llvm/ADT/SmallString.h" // for SmallString
-#include "llvm/ADT/StringRef.h" // for StringRef
+#include "lldb/lldb-defines.h" // for LLDB_GENERIC_ERROR
+#include "lldb/lldb-enumerations.h" // for ErrorType, ErrorType::eErr...
+#include "llvm/ADT/SmallString.h" // for SmallString
+#include "llvm/ADT/StringRef.h" // for StringRef
+#include "llvm/Support/Errno.h"
#include "llvm/Support/FormatProviders.h" // for format_provider
#include <cerrno>
@@ -27,7 +28,6 @@
#endif
#include <stdint.h> // for uint32_t
-#include <string.h> // for strerror
namespace llvm {
class raw_ostream;
@@ -121,23 +121,21 @@ const char *Status::AsCString(const char
return nullptr;
if (m_string.empty()) {
- const char *s = nullptr;
switch (m_type) {
case eErrorTypeMachKernel:
#if defined(__APPLE__)
- s = ::mach_error_string(m_code);
+ if (const char *s = ::mach_error_string(m_code))
+ m_string.assign(s);
#endif
break;
case eErrorTypePOSIX:
- s = ::strerror(m_code);
+ m_string = llvm::sys::StrError(m_code);
break;
default:
break;
}
- if (s != nullptr)
- m_string.assign(s);
}
if (m_string.empty()) {
if (default_error_str)
Modified: lldb/trunk/tools/lldb-server/lldb-gdbserver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-server/lldb-gdbserver.cpp?rev=304795&r1=304794&r2=304795&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-server/lldb-gdbserver.cpp (original)
+++ lldb/trunk/tools/lldb-server/lldb-gdbserver.cpp Tue Jun 6 09:06:17 2017
@@ -21,8 +21,6 @@
// C++ Includes
-// Other libraries and framework includes
-#include "llvm/ADT/StringRef.h"
#include "Acceptor.h"
#include "LLDBServerUtilities.h"
@@ -36,6 +34,8 @@
#include "lldb/Host/Socket.h"
#include "lldb/Host/StringConvert.h"
#include "lldb/Utility/Status.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Errno.h"
#ifndef LLGS_PROGRAM_NAME
#define LLGS_PROGRAM_NAME "lldb-server"
@@ -398,10 +398,9 @@ int main_gdbserver(int argc, char *argv[
{
const ::pid_t new_sid = setsid();
if (new_sid == -1) {
- const char *errno_str = strerror(errno);
- fprintf(stderr, "failed to set new session id for %s (%s)\n",
- LLGS_PROGRAM_NAME,
- errno_str ? errno_str : "<no error string>");
+ llvm::errs() << llvm::formatv(
+ "failed to set new session id for {0} ({1})\n", LLGS_PROGRAM_NAME,
+ llvm::sys::StrError());
}
}
break;
More information about the lldb-commits
mailing list