diff options
author | Zachary Turner <zturner@google.com> | 2017-05-12 05:49:54 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-05-12 05:49:54 +0000 |
commit | f76d93a92f091421f1359636575d61bab7266065 (patch) | |
tree | 6b64abbe4f97f9ef0c59bd84463da322b76cc238 /source/Plugins | |
parent | 02931751c1b0aab6c404b58513b0f6388343254d (diff) | |
download | lldb-f76d93a92f091421f1359636575d61bab7266065.tar.gz |
Update StructuredData::String to return StringRefs.
It was returning const std::string& which was leading to
unnecessary copies all over the place, and preventing people
from doing things like Dict->GetValueForKeyAsString("foo", ref);
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@302875 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'source/Plugins')
12 files changed, 48 insertions, 54 deletions
diff --git a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp index aaab97609..703b461f6 100644 --- a/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp +++ b/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderDarwin.cpp @@ -440,8 +440,8 @@ bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo( Segment segment; StructuredData::Dictionary *seg = segments->GetItemAtIndex(j)->GetAsDictionary(); - segment.name = ConstString( - seg->GetValueForKey("name")->GetAsString()->GetValue().c_str()); + segment.name = + ConstString(seg->GetValueForKey("name")->GetAsString()->GetValue()); segment.vmaddr = seg->GetValueForKey("vmaddr")->GetAsInteger()->GetValue(); segment.vmsize = @@ -478,8 +478,8 @@ bool DynamicLoaderDarwin::JSONImageInformationIntoImageInfo( image_infos[i].segments.push_back(segment); } - image_infos[i].uuid.SetFromCString( - image->GetValueForKey("uuid")->GetAsString()->GetValue().c_str()); + image_infos[i].uuid.SetFromStringRef( + image->GetValueForKey("uuid")->GetAsString()->GetValue()); // All sections listed in the dyld image info structure will all // either be fixed up already, or they will all be off by a single diff --git a/source/Plugins/OperatingSystem/Go/OperatingSystemGo.cpp b/source/Plugins/OperatingSystem/Go/OperatingSystemGo.cpp index 709466cb1..75bc518f7 100644 --- a/source/Plugins/OperatingSystem/Go/OperatingSystemGo.cpp +++ b/source/Plugins/OperatingSystem/Go/OperatingSystemGo.cpp @@ -340,8 +340,8 @@ bool OperatingSystemGo::UpdateThreadList(ThreadList &old_thread_list, memory_thread->IsValid()) { memory_thread->ClearBackingThread(); } else { - memory_thread.reset(new ThreadMemory( - *m_process, goroutine.m_goid, nullptr, nullptr, goroutine.m_gobuf)); + memory_thread.reset(new ThreadMemory(*m_process, goroutine.m_goid, "", "", + goroutine.m_gobuf)); } // Search for the backing thread if the goroutine is running. if (2 == (goroutine.m_status & 0xfff)) { diff --git a/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp b/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp index 0556318cc..14bf0784d 100644 --- a/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp +++ b/source/Plugins/OperatingSystem/Python/OperatingSystemPython.cpp @@ -240,8 +240,8 @@ ThreadSP OperatingSystemPython::CreateThreadFromThreadInfo( uint32_t core_number; addr_t reg_data_addr; - std::string name; - std::string queue; + llvm::StringRef name; + llvm::StringRef queue; thread_dict.GetValueForKeyAsInteger("core", core_number, UINT32_MAX); thread_dict.GetValueForKeyAsInteger("register_data_addr", reg_data_addr, @@ -266,8 +266,8 @@ ThreadSP OperatingSystemPython::CreateThreadFromThreadInfo( if (!thread_sp) { if (did_create_ptr) *did_create_ptr = true; - thread_sp.reset(new ThreadMemory(*m_process, tid, name.c_str(), - queue.c_str(), reg_data_addr)); + thread_sp.reset( + new ThreadMemory(*m_process, tid, name, queue, reg_data_addr)); } if (core_number < core_thread_list.GetSize(false)) { diff --git a/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp index 82c4efd80..645bfdfa7 100644 --- a/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp +++ b/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp @@ -784,7 +784,7 @@ const UnixSignalsSP &PlatformRemoteGDBServer::GetRemoteUnixSignals() { if (!dict->GetValueForKeyAsInteger("signo", signo)) return false; - std::string name; + llvm::StringRef name; if (!dict->GetValueForKeyAsString("name", name)) return false; @@ -809,7 +809,7 @@ const UnixSignalsSP &PlatformRemoteGDBServer::GetRemoteUnixSignals() { if (object_sp && object_sp->IsValid()) description = object_sp->GetStringValue(); - remote_signals_sp->AddSignal(signo, name.c_str(), suppress, stop, + remote_signals_sp->AddSignal(signo, name.str().c_str(), suppress, stop, notify, description.c_str()); return true; }); diff --git a/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp b/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp index 5e933d3b3..0bd90dbf7 100644 --- a/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp +++ b/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp @@ -48,10 +48,10 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict, if (dict.GetValueForKeyAsArray("sets", sets)) { const uint32_t num_sets = sets->GetSize(); for (uint32_t i = 0; i < num_sets; ++i) { - std::string set_name_str; + llvm::StringRef set_name_str; ConstString set_name; if (sets->GetItemAtIndexAsString(i, set_name_str)) - set_name.SetCString(set_name_str.c_str()); + set_name.SetString(set_name_str); if (set_name) { RegisterSet new_set = {set_name.AsCString(), NULL, 0, NULL}; m_sets.push_back(new_set); @@ -115,7 +115,7 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict, // expression // we can calculate the offset bool success = false; - std::string slice_str; + llvm::StringRef slice_str; if (reg_info_dict->GetValueForKeyAsString("slice", slice_str, nullptr)) { // Slices use the following format: // REGNAME[MSBIT:LSBIT] @@ -131,9 +131,9 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict, llvm::StringRef reg_name_str; std::string msbit_str; std::string lsbit_str; - if (regex_match.GetMatchAtIndex(slice_str.c_str(), 1, reg_name_str) && - regex_match.GetMatchAtIndex(slice_str.c_str(), 2, msbit_str) && - regex_match.GetMatchAtIndex(slice_str.c_str(), 3, lsbit_str)) { + if (regex_match.GetMatchAtIndex(slice_str, 1, reg_name_str) && + regex_match.GetMatchAtIndex(slice_str, 2, msbit_str) && + regex_match.GetMatchAtIndex(slice_str, 3, lsbit_str)) { const uint32_t msbit = StringConvert::ToUInt32(msbit_str.c_str(), UINT32_MAX); const uint32_t lsbit = @@ -269,17 +269,15 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict, reg_info.byte_size = bitsize / 8; - std::string dwarf_opcode_string; + llvm::StringRef dwarf_opcode_string; if (reg_info_dict->GetValueForKeyAsString("dynamic_size_dwarf_expr_bytes", dwarf_opcode_string)) { - reg_info.dynamic_size_dwarf_len = dwarf_opcode_string.length() / 2; + reg_info.dynamic_size_dwarf_len = dwarf_opcode_string.size() / 2; assert(reg_info.dynamic_size_dwarf_len > 0); std::vector<uint8_t> dwarf_opcode_bytes(reg_info.dynamic_size_dwarf_len); uint32_t j; - StringExtractor opcode_extractor; - // Swap "dwarf_opcode_string" over into "opcode_extractor" - opcode_extractor.GetStringRef().swap(dwarf_opcode_string); + StringExtractor opcode_extractor(dwarf_opcode_string); uint32_t ret_val = opcode_extractor.GetHexBytesAvail(dwarf_opcode_bytes); UNUSED_IF_ASSERT_DISABLED(ret_val); assert(ret_val == reg_info.dynamic_size_dwarf_len); @@ -290,9 +288,9 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict, reg_info.dynamic_size_dwarf_expr_bytes = m_dynamic_reg_size_map[i].data(); } - std::string format_str; + llvm::StringRef format_str; if (reg_info_dict->GetValueForKeyAsString("format", format_str, nullptr)) { - if (Args::StringToFormat(format_str.c_str(), reg_info.format, NULL) + if (Args::StringToFormat(format_str.str().c_str(), reg_info.format, NULL) .Fail()) { Clear(); printf("error: invalid 'format' value in register dictionary\n"); @@ -304,7 +302,7 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict, eFormatHex); } - std::string encoding_str; + llvm::StringRef encoding_str; if (reg_info_dict->GetValueForKeyAsString("encoding", encoding_str)) reg_info.encoding = Args::StringToEncoding(encoding_str, eEncodingUint); else @@ -334,7 +332,7 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict, reg_info.kinds[lldb::eRegisterKindEHFrame] = eh_frame_regno; reg_info_dict->GetValueForKeyAsInteger( "dwarf", reg_info.kinds[lldb::eRegisterKindDWARF], LLDB_INVALID_REGNUM); - std::string generic_str; + llvm::StringRef generic_str; if (reg_info_dict->GetValueForKeyAsString("generic", generic_str)) reg_info.kinds[lldb::eRegisterKindGeneric] = Args::StringToGenericRegister(generic_str); diff --git a/source/Plugins/Process/Utility/ThreadMemory.cpp b/source/Plugins/Process/Utility/ThreadMemory.cpp index b3cac1c85..5ff928c69 100644 --- a/source/Plugins/Process/Utility/ThreadMemory.cpp +++ b/source/Plugins/Process/Utility/ThreadMemory.cpp @@ -24,15 +24,11 @@ ThreadMemory::ThreadMemory(Process &process, tid_t tid, : Thread(process, tid), m_backing_thread_sp(), m_thread_info_valobj_sp(thread_info_valobj_sp), m_name(), m_queue() {} -ThreadMemory::ThreadMemory(Process &process, lldb::tid_t tid, const char *name, - const char *queue, lldb::addr_t register_data_addr) +ThreadMemory::ThreadMemory(Process &process, lldb::tid_t tid, + llvm::StringRef name, llvm::StringRef queue, + lldb::addr_t register_data_addr) : Thread(process, tid), m_backing_thread_sp(), m_thread_info_valobj_sp(), - m_name(), m_queue(), m_register_data_addr(register_data_addr) { - if (name) - m_name = name; - if (queue) - m_queue = queue; -} + m_name(name), m_queue(queue), m_register_data_addr(register_data_addr) {} ThreadMemory::~ThreadMemory() { DestroyThread(); } diff --git a/source/Plugins/Process/Utility/ThreadMemory.h b/source/Plugins/Process/Utility/ThreadMemory.h index 095544d24..89229710d 100644 --- a/source/Plugins/Process/Utility/ThreadMemory.h +++ b/source/Plugins/Process/Utility/ThreadMemory.h @@ -24,7 +24,7 @@ public: const lldb::ValueObjectSP &thread_info_valobj_sp); ThreadMemory(lldb_private::Process &process, lldb::tid_t tid, - const char *name, const char *queue, + llvm::StringRef name, llvm::StringRef queue, lldb::addr_t register_data_addr); ~ThreadMemory() override; diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 8d91db87b..550ec0ea4 100644 --- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -3224,12 +3224,12 @@ ParseModuleSpec(StructuredData::Dictionary *dict) { if (!dict) return llvm::None; - std::string string; + llvm::StringRef string; uint64_t integer; if (!dict->GetValueForKeyAsString("uuid", string)) return llvm::None; - result.GetUUID().SetFromCString(string.c_str(), string.size()); + result.GetUUID().SetFromStringRef(string, string.size()); if (!dict->GetValueForKeyAsInteger("file_offset", integer)) return llvm::None; @@ -3241,7 +3241,7 @@ ParseModuleSpec(StructuredData::Dictionary *dict) { if (!dict->GetValueForKeyAsString("triple", string)) return llvm::None; - result.GetArchitecture().SetTriple(string.c_str()); + result.GetArchitecture().SetTriple(string); if (!dict->GetValueForKeyAsString("file_path", string)) return llvm::None; diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp index d0000a001..de2400c51 100644 --- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -1140,7 +1140,7 @@ GDBRemoteCommunicationServerCommon::Handle_jModulesInfo( packet_array->GetItemAtIndex(i)->GetAsDictionary(); if (!query) continue; - std::string file, triple; + llvm::StringRef file, triple; if (!query->GetValueForKeyAsString("file", file) || !query->GetValueForKeyAsString("triple", triple)) continue; @@ -1278,9 +1278,10 @@ FileSpec GDBRemoteCommunicationServerCommon::FindModuleFile( #endif } -ModuleSpec GDBRemoteCommunicationServerCommon::GetModuleInfo( - const std::string &module_path, const std::string &triple) { - ArchSpec arch(triple.c_str()); +ModuleSpec +GDBRemoteCommunicationServerCommon::GetModuleInfo(llvm::StringRef module_path, + llvm::StringRef triple) { + ArchSpec arch(triple); const FileSpec req_module_path_spec(module_path, true); const FileSpec module_path_spec = diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h index 14d5612af..e9ab8f1a1 100644 --- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h +++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.h @@ -153,8 +153,7 @@ protected: const ArchSpec &arch); private: - ModuleSpec GetModuleInfo(const std::string &module_path, - const std::string &triple); + ModuleSpec GetModuleInfo(llvm::StringRef module_path, llvm::StringRef triple); }; } // namespace process_gdb_remote diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 37a415371..64684c596 100644 --- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -2113,9 +2113,9 @@ ProcessGDBRemote::SetThreadStopInfo(StructuredData::Dictionary *thread_dict) { if (mem_cache_dict->GetValueForKeyAsInteger<lldb::addr_t>( "address", mem_cache_addr)) { if (mem_cache_addr != LLDB_INVALID_ADDRESS) { - StringExtractor bytes; - if (mem_cache_dict->GetValueForKeyAsString( - "bytes", bytes.GetStringRef())) { + llvm::StringRef str; + if (mem_cache_dict->GetValueForKeyAsString("bytes", str)) { + StringExtractor bytes(str); bytes.SetFilePos(0); const size_t byte_size = bytes.GetStringRef().size() / 2; diff --git a/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp b/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp index 82ecdc5a0..f1450c31b 100644 --- a/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp +++ b/source/Plugins/StructuredData/DarwinLog/StructuredDataDarwinLog.cpp @@ -1817,7 +1817,7 @@ StructuredDataDarwinLog::DumpHeader(Stream &output_stream, } if (options_sp->GetDisplayActivityChain()) { - std::string activity_chain; + llvm::StringRef activity_chain; if (event.GetValueForKeyAsString("activity-chain", activity_chain) && !activity_chain.empty()) { if (header_count > 0) @@ -1856,7 +1856,7 @@ StructuredDataDarwinLog::DumpHeader(Stream &output_stream, } if (options_sp->GetDisplaySubsystem()) { - std::string subsystem; + llvm::StringRef subsystem; if (event.GetValueForKeyAsString("subsystem", subsystem) && !subsystem.empty()) { if (header_count > 0) @@ -1868,7 +1868,7 @@ StructuredDataDarwinLog::DumpHeader(Stream &output_stream, } if (options_sp->GetDisplayCategory()) { - std::string category; + llvm::StringRef category; if (event.GetValueForKeyAsString("category", category) && !category.empty()) { if (header_count > 0) @@ -1901,16 +1901,16 @@ size_t StructuredDataDarwinLog::HandleDisplayOfEvent( size_t total_bytes = 0; // Grab the message content. - std::string message; + llvm::StringRef message; if (!event.GetValueForKeyAsString("message", message)) return true; // Display the log entry. - const auto len = message.length(); + const auto len = message.size(); total_bytes += DumpHeader(stream, event); - stream.Write(message.c_str(), len); + stream.Write(message.data(), len); total_bytes += len; // Add an end of line. |