[Lldb-commits] [lldb] r293045 - Replace chdir() usage with the llvm equivalent.
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Wed Jan 25 03:10:53 PST 2017
Author: labath
Date: Wed Jan 25 05:10:52 2017
New Revision: 293045
URL: http://llvm.org/viewvc/llvm-project?rev=293045&view=rev
Log:
Replace chdir() usage with the llvm equivalent.
This removes a hack in PosixApi.h, which tends to produce strange
compile errors when it's included in the wrong order.
Modified:
lldb/trunk/include/lldb/Host/windows/PosixApi.h
lldb/trunk/source/Host/windows/Windows.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
lldb/trunk/source/Target/Platform.cpp
Modified: lldb/trunk/include/lldb/Host/windows/PosixApi.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/windows/PosixApi.h?rev=293045&r1=293044&r2=293045&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/windows/PosixApi.h (original)
+++ lldb/trunk/include/lldb/Host/windows/PosixApi.h Wed Jan 25 05:10:52 2017
@@ -82,7 +82,6 @@ char *strcasestr(const char *s, const ch
char *realpath(const char *name, char *resolved);
int usleep(uint32_t useconds);
-int chdir(const char *path);
char *basename(char *path);
char *dirname(char *path);
Modified: lldb/trunk/source/Host/windows/Windows.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/Windows.cpp?rev=293045&r1=293044&r2=293045&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/Windows.cpp (original)
+++ lldb/trunk/source/Host/windows/Windows.cpp Wed Jan 25 05:10:52 2017
@@ -23,12 +23,6 @@
#include <stdlib.h>
#include <string.h>
-// These prototypes are defined in <direct.h>, but it also defines chdir(),
-// giving multiply defined errors
-extern "C" {
-int _chdir(const char *path);
-}
-
namespace {
bool utf8ToWide(const char *utf8, wchar_t *buf, size_t bufSize) {
const llvm::UTF8 *sourceStart = reinterpret_cast<const llvm::UTF8 *>(utf8);
@@ -189,9 +183,6 @@ char *basename(char *path) {
return &l1[1];
}
-// use _chdir() instead of SetCurrentDirectory() because it updates errno
-int chdir(const char *path) { return _chdir(path); }
-
char *dirname(char *path) {
char *l1 = strrchr(path, '\\');
char *l2 = strrchr(path, '/');
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp?rev=293045&r1=293044&r2=293045&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp Wed Jan 25 05:10:52 2017
@@ -353,8 +353,6 @@ GDBRemoteCommunicationServerPlatform::Ha
GDBRemoteCommunication::PacketResult
GDBRemoteCommunicationServerPlatform::Handle_qGetWorkingDir(
StringExtractorGDBRemote &packet) {
- // If this packet is sent to a platform, then change the current working
- // directory
llvm::SmallString<64> cwd;
if (std::error_code ec = llvm::sys::fs::current_path(cwd))
@@ -372,10 +370,8 @@ GDBRemoteCommunicationServerPlatform::Ha
std::string path;
packet.GetHexByteString(path);
- // If this packet is sent to a platform, then change the current working
- // directory
- if (::chdir(path.c_str()) != 0)
- return SendErrorResponse(errno);
+ if (std::error_code ec = llvm::sys::fs::set_current_path(path))
+ return SendErrorResponse(ec.value());
return SendOKResponse();
}
Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=293045&r1=293044&r2=293045&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Wed Jan 25 05:10:52 2017
@@ -748,14 +748,12 @@ Error Platform::Install(const FileSpec &
bool Platform::SetWorkingDirectory(const FileSpec &file_spec) {
if (IsHost()) {
Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_PLATFORM);
- if (log)
- log->Printf("Platform::SetWorkingDirectory('%s')",
- file_spec.GetCString());
- if (file_spec) {
- if (::chdir(file_spec.GetCString()) == 0)
- return true;
+ LLDB_LOG(log, "{0}", file_spec);
+ if (std::error_code ec = llvm::sys::fs::set_current_path(file_spec.GetPath())) {
+ LLDB_LOG(log, "error: {0}", ec.message());
+ return false;
}
- return false;
+ return true;
} else {
m_working_dir.Clear();
return SetRemoteWorkingDirectory(file_spec);
More information about the lldb-commits
mailing list