diff --git a/lldb/include/lldb/Host/XML.h b/lldb/include/lldb/Host/XML.h --- a/lldb/include/lldb/Host/XML.h +++ b/lldb/include/lldb/Host/XML.h @@ -76,8 +76,8 @@ XMLNode GetChild() const; - llvm::StringRef GetAttributeValue(const char *name, - const char *fail_value = nullptr) const; + std::string GetAttributeValue(const char *name, + const char *fail_value = nullptr) const; bool GetAttributeValueAsUnsigned(const char *name, uint64_t &value, uint64_t fail_value = 0, int base = 0) const; diff --git a/lldb/source/Host/common/XML.cpp b/lldb/source/Host/common/XML.cpp --- a/lldb/source/Host/common/XML.cpp +++ b/lldb/source/Host/common/XML.cpp @@ -130,22 +130,25 @@ #endif } -llvm::StringRef XMLNode::GetAttributeValue(const char *name, - const char *fail_value) const { - const char *attr_value = nullptr; +std::string XMLNode::GetAttributeValue(const char *name, + const char *fail_value) const { + std::string attr_value; #if LLDB_ENABLE_LIBXML2 - - if (IsValid()) - attr_value = (const char *)xmlGetProp(m_node, (const xmlChar *)name); - else - attr_value = fail_value; + if (IsValid()) { + xmlChar *value = xmlGetProp(m_node, (const xmlChar *)name); + if (value) { + attr_value = (const char *)value; + xmlFree(value); + } + } else { + if (fail_value) + attr_value = fail_value; + } #else - attr_value = fail_value; + if (fail_value) + attr_value = fail_value; #endif - if (attr_value) - return llvm::StringRef(attr_value); - else - return llvm::StringRef(); + return attr_value; } bool XMLNode::GetAttributeValueAsUnsigned(const char *name, uint64_t &value, diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -4351,9 +4351,9 @@ } else if (name == "osabi") { node.GetElementText(target_info.osabi); } else if (name == "xi:include" || name == "include") { - llvm::StringRef href = node.GetAttributeValue("href"); + std::string href = node.GetAttributeValue("href"); if (!href.empty()) - target_info.includes.push_back(href.str()); + target_info.includes.push_back(href); } else if (name == "feature") { feature_nodes.push_back(node); } else if (name == "groups") { @@ -4392,9 +4392,9 @@ const XMLNode &node) -> bool { llvm::StringRef name = node.GetName(); if (name == "xi:include" || name == "include") { - llvm::StringRef href = node.GetAttributeValue("href"); + std::string href = node.GetAttributeValue("href"); if (!href.empty()) - target_info.includes.push_back(href.str()); + target_info.includes.push_back(href); } return true; }); @@ -4530,7 +4530,7 @@ "Error finding library-list-svr4 xml element"); // main link map structure - llvm::StringRef main_lm = root_element.GetAttributeValue("main-lm"); + std::string main_lm = root_element.GetAttributeValue("main-lm"); // FIXME: we're silently ignoring invalid data here if (!main_lm.empty()) llvm::to_integer(main_lm, list.m_link_map); @@ -4618,15 +4618,15 @@ "library", [log, &list](const XMLNode &library) -> bool { LoadedModuleInfoList::LoadedModuleInfo module; - llvm::StringRef name = library.GetAttributeValue("name"); - module.set_name(name.str()); + std::string name = library.GetAttributeValue("name"); + module.set_name(name); // The base address of a given library will be the address of its // first section. Most remotes send only one section for Windows // targets for example. const XMLNode §ion = library.FindFirstChildElementWithName("section"); - llvm::StringRef address = section.GetAttributeValue("address"); + std::string address = section.GetAttributeValue("address"); uint64_t address_value = LLDB_INVALID_ADDRESS; llvm::to_integer(address, address_value); module.set_base(address_value);