From a47464b2738c5180061f4cfe6b3f72238b3cfa7d Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Fri, 18 Nov 2016 20:44:46 +0000 Subject: [PATCH] Change CreateTarget and dependents to accept StringRef. llvm-svn: 287376 --- .../lldb/Interpreter/OptionGroupArchitecture.h | 5 +-- lldb/include/lldb/Target/TargetList.h | 16 +++++---- lldb/source/API/SBDebugger.cpp | 3 +- lldb/source/Commands/CommandObjectProcess.cpp | 2 +- lldb/source/Commands/CommandObjectTarget.cpp | 2 +- .../Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp | 6 ++-- .../Plugins/Platform/Linux/PlatformLinux.cpp | 4 +-- .../Plugins/Platform/NetBSD/PlatformNetBSD.cpp | 6 ++-- .../Plugins/Platform/POSIX/PlatformPOSIX.cpp | 2 +- .../Plugins/Platform/Windows/PlatformWindows.cpp | 4 +-- .../gdb-server/PlatformRemoteGDBServer.cpp | 8 ++--- lldb/source/Target/Platform.cpp | 4 +-- lldb/source/Target/TargetList.cpp | 40 ++++++++++++---------- 13 files changed, 51 insertions(+), 51 deletions(-) diff --git a/lldb/include/lldb/Interpreter/OptionGroupArchitecture.h b/lldb/include/lldb/Interpreter/OptionGroupArchitecture.h index 1354324..742cd6d 100644 --- a/lldb/include/lldb/Interpreter/OptionGroupArchitecture.h +++ b/lldb/include/lldb/Interpreter/OptionGroupArchitecture.h @@ -33,7 +33,6 @@ public: Error SetOptionValue(uint32_t option_idx, llvm::StringRef option_value, ExecutionContext *execution_context) override; - Error SetOptionValue(uint32_t, const char *, ExecutionContext *) = delete; void OptionParsingStarting(ExecutionContext *execution_context) override; @@ -41,9 +40,7 @@ public: bool ArchitectureWasSpecified() const { return !m_arch_str.empty(); } - const char *GetArchitectureName() { - return (m_arch_str.empty() ? nullptr : m_arch_str.c_str()); - } + llvm::StringRef GetArchitectureName() const { return m_arch_str; } protected: std::string m_arch_str; // Save the arch triple in case a platform is diff --git a/lldb/include/lldb/Target/TargetList.h b/lldb/include/lldb/Target/TargetList.h index d231d0c..81b81db 100644 --- a/lldb/include/lldb/Target/TargetList.h +++ b/lldb/include/lldb/Target/TargetList.h @@ -91,8 +91,8 @@ public: /// @return /// An error object that indicates success or failure //------------------------------------------------------------------ - Error CreateTarget(Debugger &debugger, const char *user_exe_path, - const char *triple_cstr, bool get_dependent_modules, + Error CreateTarget(Debugger &debugger, llvm::StringRef user_exe_path, + llvm::StringRef triple_str, bool get_dependent_modules, const OptionGroupPlatform *platform_options, lldb::TargetSP &target_sp); @@ -102,7 +102,7 @@ public: /// Same as the function above, but used when you already know the /// platform you will be using //------------------------------------------------------------------ - Error CreateTarget(Debugger &debugger, const char *user_exe_path, + Error CreateTarget(Debugger &debugger, llvm::StringRef user_exe_path, const ArchSpec &arch, bool get_dependent_modules, lldb::PlatformSP &platform_sp, lldb::TargetSP &target_sp); @@ -211,15 +211,17 @@ protected: private: lldb::TargetSP GetDummyTarget(lldb_private::Debugger &debugger); - Error CreateDummyTarget(Debugger &debugger, const char *specified_arch_name, + Error CreateDummyTarget(Debugger &debugger, + llvm::StringRef specified_arch_name, lldb::TargetSP &target_sp); - Error CreateTargetInternal(Debugger &debugger, const char *user_exe_path, - const char *triple_cstr, bool get_dependent_files, + Error CreateTargetInternal(Debugger &debugger, llvm::StringRef user_exe_path, + llvm::StringRef triple_str, + bool get_dependent_files, const OptionGroupPlatform *platform_options, lldb::TargetSP &target_sp, bool is_dummy_target); - Error CreateTargetInternal(Debugger &debugger, const char *user_exe_path, + Error CreateTargetInternal(Debugger &debugger, llvm::StringRef user_exe_path, const ArchSpec &arch, bool get_dependent_modules, lldb::PlatformSP &platform_sp, lldb::TargetSP &target_sp, bool is_dummy_target); diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp index e8f5542..c74bc75 100644 --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -603,8 +603,7 @@ SBTarget SBDebugger::CreateTarget(const char *filename) { Error error; const bool add_dependent_modules = true; error = m_opaque_sp->GetTargetList().CreateTarget( - *m_opaque_sp, filename, nullptr, add_dependent_modules, nullptr, - target_sp); + *m_opaque_sp, filename, "", add_dependent_modules, nullptr, target_sp); if (error.Success()) { m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp.get()); diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp index 144ba3f..fd3795e 100644 --- a/lldb/source/Commands/CommandObjectProcess.cpp +++ b/lldb/source/Commands/CommandObjectProcess.cpp @@ -472,7 +472,7 @@ protected: Error error; error = m_interpreter.GetDebugger().GetTargetList().CreateTarget( - m_interpreter.GetDebugger(), nullptr, nullptr, false, + m_interpreter.GetDebugger(), "", "", false, nullptr, // No platform options new_target_sp); target = new_target_sp.get(); diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp index d36adb4..d2e53aa 100644 --- a/lldb/source/Commands/CommandObjectTarget.cpp +++ b/lldb/source/Commands/CommandObjectTarget.cpp @@ -278,7 +278,7 @@ protected: Debugger &debugger = m_interpreter.GetDebugger(); TargetSP target_sp; - const char *arch_cstr = m_arch_option.GetArchitectureName(); + llvm::StringRef arch_cstr = m_arch_option.GetArchitectureName(); const bool get_dependent_files = m_add_dependents.GetOptionValue().GetCurrentValue(); Error error(debugger.GetTargetList().CreateTarget( diff --git a/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp b/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp index 9a6a375..9ea97a5 100644 --- a/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp +++ b/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp @@ -582,9 +582,9 @@ lldb::ProcessSP PlatformFreeBSD::Attach(ProcessAttachInfo &attach_info, TargetSP new_target_sp; ArchSpec emptyArchSpec; - error = debugger.GetTargetList().CreateTarget( - debugger, NULL, emptyArchSpec, false, m_remote_platform_sp, - new_target_sp); + error = debugger.GetTargetList().CreateTarget(debugger, "", emptyArchSpec, + false, m_remote_platform_sp, + new_target_sp); target = new_target_sp.get(); } else error.Clear(); diff --git a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp index 8c2b370..270fe53 100644 --- a/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp +++ b/lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp @@ -565,8 +565,8 @@ PlatformLinux::DebugProcess(ProcessLaunchInfo &launch_info, Debugger &debugger, log->Printf("PlatformLinux::%s creating new target", __FUNCTION__); TargetSP new_target_sp; - error = debugger.GetTargetList().CreateTarget( - debugger, nullptr, nullptr, false, nullptr, new_target_sp); + error = debugger.GetTargetList().CreateTarget(debugger, "", "", false, + nullptr, new_target_sp); if (error.Fail()) { if (log) log->Printf("PlatformLinux::%s failed to create new target: %s", diff --git a/lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp b/lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp index 6ae6252..bc4bfd3 100644 --- a/lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp +++ b/lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp @@ -520,9 +520,9 @@ lldb::ProcessSP PlatformNetBSD::Attach(ProcessAttachInfo &attach_info, TargetSP new_target_sp; ArchSpec emptyArchSpec; - error = debugger.GetTargetList().CreateTarget( - debugger, NULL, emptyArchSpec, false, m_remote_platform_sp, - new_target_sp); + error = debugger.GetTargetList().CreateTarget(debugger, "", emptyArchSpec, + false, m_remote_platform_sp, + new_target_sp); target = new_target_sp.get(); } else error.Clear(); diff --git a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp index 569a862..676e330 100644 --- a/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp +++ b/lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp @@ -629,7 +629,7 @@ lldb::ProcessSP PlatformPOSIX::Attach(ProcessAttachInfo &attach_info, if (target == NULL) { TargetSP new_target_sp; - error = debugger.GetTargetList().CreateTarget(debugger, NULL, NULL, false, + error = debugger.GetTargetList().CreateTarget(debugger, "", "", false, NULL, new_target_sp); target = new_target_sp.get(); if (log) diff --git a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp index f16ebc4..290d8ea 100644 --- a/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp +++ b/lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp @@ -474,8 +474,8 @@ lldb::ProcessSP PlatformWindows::Attach(ProcessAttachInfo &attach_info, FileSpec emptyFileSpec; ArchSpec emptyArchSpec; - error = debugger.GetTargetList().CreateTarget( - debugger, nullptr, nullptr, false, nullptr, new_target_sp); + error = debugger.GetTargetList().CreateTarget(debugger, "", "", false, + nullptr, new_target_sp); target = new_target_sp.get(); } diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp index 7962ca8..43f7a53 100644 --- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp +++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp @@ -505,8 +505,8 @@ lldb::ProcessSP PlatformRemoteGDBServer::DebugProcess( if (target == NULL) { TargetSP new_target_sp; - error = debugger.GetTargetList().CreateTarget( - debugger, NULL, NULL, false, NULL, new_target_sp); + error = debugger.GetTargetList().CreateTarget(debugger, "", "", false, + NULL, new_target_sp); target = new_target_sp.get(); } else error.Clear(); @@ -592,8 +592,8 @@ lldb::ProcessSP PlatformRemoteGDBServer::Attach( if (target == NULL) { TargetSP new_target_sp; - error = debugger.GetTargetList().CreateTarget( - debugger, NULL, NULL, false, NULL, new_target_sp); + error = debugger.GetTargetList().CreateTarget(debugger, "", "", false, + NULL, new_target_sp); target = new_target_sp.get(); } else error.Clear(); diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp index d25c3b2..43371ec 100644 --- a/lldb/source/Target/Platform.cpp +++ b/lldb/source/Target/Platform.cpp @@ -1767,8 +1767,8 @@ lldb::ProcessSP Platform::ConnectProcess(llvm::StringRef connect_url, if (!target) { TargetSP new_target_sp; - error = debugger.GetTargetList().CreateTarget( - debugger, nullptr, nullptr, false, nullptr, new_target_sp); + error = debugger.GetTargetList().CreateTarget(debugger, "", "", false, + nullptr, new_target_sp); target = new_target_sp.get(); } diff --git a/lldb/source/Target/TargetList.cpp b/lldb/source/Target/TargetList.cpp index 97910ce..8d4d238 100644 --- a/lldb/source/Target/TargetList.cpp +++ b/lldb/source/Target/TargetList.cpp @@ -55,17 +55,19 @@ TargetList::~TargetList() { m_target_list.clear(); } -Error TargetList::CreateTarget(Debugger &debugger, const char *user_exe_path, - const char *triple_cstr, +Error TargetList::CreateTarget(Debugger &debugger, + llvm::StringRef user_exe_path, + llvm::StringRef triple_str, bool get_dependent_files, const OptionGroupPlatform *platform_options, TargetSP &target_sp) { - return CreateTargetInternal(debugger, user_exe_path, triple_cstr, + return CreateTargetInternal(debugger, user_exe_path, triple_str, get_dependent_files, platform_options, target_sp, false); } -Error TargetList::CreateTarget(Debugger &debugger, const char *user_exe_path, +Error TargetList::CreateTarget(Debugger &debugger, + llvm::StringRef user_exe_path, const ArchSpec &specified_arch, bool get_dependent_files, PlatformSP &platform_sp, TargetSP &target_sp) { @@ -75,19 +77,21 @@ Error TargetList::CreateTarget(Debugger &debugger, const char *user_exe_path, } Error TargetList::CreateTargetInternal( - Debugger &debugger, const char *user_exe_path, const char *triple_cstr, - bool get_dependent_files, const OptionGroupPlatform *platform_options, - TargetSP &target_sp, bool is_dummy_target) { + Debugger &debugger, llvm::StringRef user_exe_path, + llvm::StringRef triple_str, bool get_dependent_files, + const OptionGroupPlatform *platform_options, TargetSP &target_sp, + bool is_dummy_target) { Error error; PlatformSP platform_sp; // This is purposely left empty unless it is specified by triple_cstr. // If not initialized via triple_cstr, then the currently selected platform // will set the architecture correctly. - const ArchSpec arch(triple_cstr); - if (triple_cstr && triple_cstr[0]) { + const ArchSpec arch(triple_str); + if (!triple_str.empty()) { if (!arch.IsValid()) { - error.SetErrorStringWithFormat("invalid triple '%s'", triple_cstr); + error.SetErrorStringWithFormat("invalid triple '%s'", + triple_str.str().c_str()); return error; } } @@ -113,7 +117,7 @@ Error TargetList::CreateTargetInternal( } } - if (user_exe_path && user_exe_path[0]) { + if (!user_exe_path.empty()) { ModuleSpecList module_specs; ModuleSpec module_spec; module_spec.GetFileSpec().SetFile(user_exe_path, true); @@ -306,7 +310,7 @@ lldb::TargetSP TargetList::GetDummyTarget(lldb_private::Debugger &debugger) { } Error TargetList::CreateDummyTarget(Debugger &debugger, - const char *specified_arch_name, + llvm::StringRef specified_arch_name, lldb::TargetSP &target_sp) { PlatformSP host_platform_sp(Platform::GetHostPlatform()); return CreateTargetInternal( @@ -315,7 +319,7 @@ Error TargetList::CreateDummyTarget(Debugger &debugger, } Error TargetList::CreateTargetInternal(Debugger &debugger, - const char *user_exe_path, + llvm::StringRef user_exe_path, const ArchSpec &specified_arch, bool get_dependent_files, lldb::PlatformSP &platform_sp, @@ -341,7 +345,7 @@ Error TargetList::CreateTargetInternal(Debugger &debugger, arch = specified_arch; FileSpec file(user_exe_path, false); - if (!file.Exists() && user_exe_path && user_exe_path[0] == '~') { + if (!file.Exists() && user_exe_path.startswith("~")) { // we want to expand the tilde but we don't want to resolve any symbolic // links // so we can't use the FileSpec constructor's resolve flag @@ -361,11 +365,9 @@ Error TargetList::CreateTargetInternal(Debugger &debugger, if (file.GetFileType() == FileSpec::eFileTypeDirectory) user_exe_path_is_bundle = true; - if (file.IsRelative() && user_exe_path) { + if (file.IsRelative() && !user_exe_path.empty()) { // Ignore paths that start with "./" and "../" - if (!((user_exe_path[0] == '.' && user_exe_path[1] == '/') || - (user_exe_path[0] == '.' && user_exe_path[1] == '.' && - user_exe_path[2] == '/'))) { + if (!user_exe_path.startswith("./") && !user_exe_path.startswith("../")) { char cwd[PATH_MAX]; if (getcwd(cwd, sizeof(cwd))) { std::string cwd_user_exe_path(cwd); @@ -417,7 +419,7 @@ Error TargetList::CreateTargetInternal(Debugger &debugger, // Set argv0 with what the user typed, unless the user specified a // directory. If the user specified a directory, then it is probably a // bundle that was resolved and we need to use the resolved bundle path - if (user_exe_path) { + if (!user_exe_path.empty()) { // Use exactly what the user typed as the first argument when we exec or // posix_spawn if (user_exe_path_is_bundle && resolved_bundle_exe_path[0]) { -- 2.7.4