[Lldb-commits] [lldb] r366847 - Revert "Revert "Implement xfer:libraries-svr4:read packet""
Antonio Afonso via lldb-commits
lldb-commits at lists.llvm.org
Tue Jul 23 13:40:31 PDT 2019
Author: aadsm
Date: Tue Jul 23 13:40:30 2019
New Revision: 366847
URL: http://llvm.org/viewvc/llvm-project?rev=366847&view=rev
Log:
Revert "Revert "Implement xfer:libraries-svr4:read packet""
This reverts commit 08c38f77c5fb4d3735ec215032fed8ee6730b3db.
Added:
lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/
lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/Makefile
lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/TestGdbRemoteLibrariesSvr4Support.py
lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/main.cpp
lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_a.cpp
lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_a.mk
lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_b_quote.cpp
lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_b_quote.mk
Modified:
lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h
lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
lldb/trunk/source/Plugins/Process/POSIX/NativeProcessELF.cpp
lldb/trunk/source/Plugins/Process/POSIX/NativeProcessELF.h
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
Modified: lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h?rev=366847&r1=366846&r2=366847&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h (original)
+++ lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h Tue Jul 23 13:40:30 2019
@@ -32,6 +32,14 @@ namespace lldb_private {
class MemoryRegionInfo;
class ResumeActionList;
+struct SVR4LibraryInfo {
+ std::string name;
+ lldb::addr_t link_map;
+ lldb::addr_t base_addr;
+ lldb::addr_t ld_addr;
+ lldb::addr_t next;
+};
+
// NativeProcessProtocol
class NativeProcessProtocol {
public:
@@ -86,6 +94,12 @@ public:
virtual lldb::addr_t GetSharedLibraryInfoAddress() = 0;
+ virtual llvm::Expected<std::vector<SVR4LibraryInfo>>
+ GetLoadedSVR4Libraries() {
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Not implemented");
+ }
+
virtual bool IsAlive() const;
virtual size_t UpdateThreads() = 0;
Modified: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py?rev=366847&r1=366846&r2=366847&view=diff
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py (original)
+++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py Tue Jul 23 13:40:30 2019
@@ -513,7 +513,8 @@ class GdbRemoteTestCaseBase(TestBase):
self,
inferior_args=None,
inferior_sleep_seconds=3,
- inferior_exe_path=None):
+ inferior_exe_path=None,
+ inferior_env=None):
"""Prep the debug monitor, the inferior, and the expected packet stream.
Handle the separate cases of using the debug monitor in attach-to-inferior mode
@@ -576,6 +577,9 @@ class GdbRemoteTestCaseBase(TestBase):
# Build the expected protocol stream
self.add_no_ack_remote_stream()
+ if inferior_env:
+ for name, value in inferior_env.items():
+ self.add_set_environment_packets(name, value)
if self._inferior_startup == self._STARTUP_LAUNCH:
self.add_verified_launch_packets(launch_args)
@@ -656,6 +660,12 @@ class GdbRemoteTestCaseBase(TestBase):
{"direction": "send", "regex": r"^\$(.+)#[0-9a-fA-F]{2}$", "capture": {1: "process_info_raw"}}],
True)
+ def add_set_environment_packets(self, name, value):
+ self.test_sequence.add_log_lines(
+ ["read packet: $QEnvironment:" + name + "=" + value + "#00",
+ "send packet: $OK#00",
+ ], True)
+
_KNOWN_PROCESS_INFO_KEYS = [
"pid",
"parent-pid",
@@ -816,6 +826,7 @@ class GdbRemoteTestCaseBase(TestBase):
"error"])
self.assertIsNotNone(val)
+ mem_region_dict["name"] = seven.unhexlify(mem_region_dict.get("name", ""))
# Return the dictionary of key-value pairs for the memory region.
return mem_region_dict
@@ -1000,6 +1011,22 @@ class GdbRemoteTestCaseBase(TestBase):
return context
+ def continue_process_and_wait_for_stop(self):
+ self.test_sequence.add_log_lines(
+ [
+ "read packet: $vCont;c#a8",
+ {
+ "direction": "send",
+ "regex": r"^\$T([0-9a-fA-F]{2})(.*)#[0-9a-fA-F]{2}$",
+ "capture": {1: "stop_signo", 2: "stop_key_val_text"},
+ },
+ ],
+ True,
+ )
+ context = self.expect_gdbremote_sequence()
+ self.assertIsNotNone(context)
+ return self.parse_interrupt_packets(context)
+
def select_modifiable_register(self, reg_infos):
"""Find a register that can be read/written freely."""
PREFERRED_REGISTER_NAMES = set(["rax", ])
Added: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/Makefile?rev=366847&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/Makefile (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/Makefile Tue Jul 23 13:40:30 2019
@@ -0,0 +1,17 @@
+LEVEL = ../../../make
+
+LIB_PREFIX := svr4lib
+LD_EXTRAS := -L. -l$(LIB_PREFIX)_a -l$(LIB_PREFIX)_b\"
+CXX_SOURCES := main.cpp
+USE_LIBDL := 1
+MAKE_DSYM := NO
+
+include $(LEVEL)/Makefile.rules
+
+a.out: $(LIB_PREFIX)_a $(LIB_PREFIX)_b_quote
+
+svr4lib_%:
+ $(MAKE) VPATH=$(SRCDIR) -I $(SRCDIR) -f "$(SRCDIR)/$(LIB_PREFIX)_$*.mk"
+
+clean::
+ $(MAKE) -f $(SRCDIR)/$(LIB_PREFIX)_a.mk clean
Added: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/TestGdbRemoteLibrariesSvr4Support.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/TestGdbRemoteLibrariesSvr4Support.py?rev=366847&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/TestGdbRemoteLibrariesSvr4Support.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/TestGdbRemoteLibrariesSvr4Support.py Tue Jul 23 13:40:30 2019
@@ -0,0 +1,130 @@
+import xml.etree.ElementTree as ET
+
+import gdbremote_testcase
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+
+
+class TestGdbRemoteLibrariesSvr4Support(gdbremote_testcase.GdbRemoteTestCaseBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ FEATURE_NAME = "qXfer:libraries-svr4:read"
+
+ def setup_test(self):
+ self.init_llgs_test()
+ self.build()
+ self.set_inferior_startup_launch()
+ env = {}
+ env[self.dylibPath] = self.getBuildDir()
+ self.prep_debug_monitor_and_inferior(inferior_env=env)
+ self.continue_process_and_wait_for_stop()
+
+ def get_expected_libs(self):
+ return ["libsvr4lib_a.so", 'libsvr4lib_b".so']
+
+ def has_libraries_svr4_support(self):
+ self.add_qSupported_packets()
+ context = self.expect_gdbremote_sequence()
+ self.assertIsNotNone(context)
+ features = self.parse_qSupported_response(context)
+ return self.FEATURE_NAME in features and features[self.FEATURE_NAME] == "+"
+
+ def get_libraries_svr4_data(self):
+ # Start up llgs and inferior, and check for libraries-svr4 support.
+ if not self.has_libraries_svr4_support():
+ self.skipTest("libraries-svr4 not supported")
+
+ # Grab the libraries-svr4 data.
+ self.reset_test_sequence()
+ self.test_sequence.add_log_lines(
+ [
+ "read packet: $qXfer:libraries-svr4:read::0,ffff:#00",
+ {
+ "direction": "send",
+ "regex": re.compile(
+ r"^\$([^E])(.*)#[0-9a-fA-F]{2}$", re.MULTILINE | re.DOTALL
+ ),
+ "capture": {1: "response_type", 2: "content_raw"},
+ },
+ ],
+ True,
+ )
+
+ context = self.expect_gdbremote_sequence()
+ self.assertIsNotNone(context)
+
+ # Ensure we end up with all libraries-svr4 data in one packet.
+ self.assertEqual(context.get("response_type"), "l")
+
+ # Decode binary data.
+ content_raw = context.get("content_raw")
+ self.assertIsNotNone(content_raw)
+ return content_raw
+
+ def get_libraries_svr4_xml(self):
+ libraries_svr4 = self.get_libraries_svr4_data()
+ xml_root = None
+ try:
+ xml_root = ET.fromstring(libraries_svr4)
+ except xml.etree.ElementTree.ParseError:
+ pass
+ self.assertIsNotNone(xml_root, "Malformed libraries-svr4 XML")
+ return xml_root
+
+ def libraries_svr4_well_formed(self):
+ xml_root = self.get_libraries_svr4_xml()
+ self.assertEqual(xml_root.tag, "library-list-svr4")
+ for child in xml_root:
+ self.assertEqual(child.tag, "library")
+ self.assertItemsEqual(child.attrib.keys(), ["name", "lm", "l_addr", "l_ld"])
+
+ def libraries_svr4_has_correct_load_addr(self):
+ xml_root = self.get_libraries_svr4_xml()
+ for child in xml_root:
+ name = child.attrib.get("name")
+ base_name = os.path.basename(name)
+ if os.path.basename(name) not in self.get_expected_libs():
+ continue
+ load_addr = int(child.attrib.get("l_addr"), 16)
+ self.reset_test_sequence()
+ self.add_query_memory_region_packets(load_addr)
+ context = self.expect_gdbremote_sequence()
+ mem_region = self.parse_memory_region_packet(context)
+ self.assertEqual(load_addr, int(mem_region.get("start", 0), 16))
+ self.assertEqual(
+ os.path.realpath(name), os.path.realpath(mem_region.get("name", ""))
+ )
+
+ def libraries_svr4_libs_present(self):
+ xml_root = self.get_libraries_svr4_xml()
+ libraries_svr4_names = []
+ for child in xml_root:
+ name = child.attrib.get("name")
+ libraries_svr4_names.append(os.path.realpath(name))
+ for lib in self.get_expected_libs():
+ self.assertIn(self.getBuildDir() + "/" + lib, libraries_svr4_names)
+
+ @llgs_test
+ @skipUnlessPlatform(["linux", "android", "netbsd"])
+ def test_supports_libraries_svr4(self):
+ self.setup_test()
+ self.assertTrue(self.has_libraries_svr4_support())
+
+ @llgs_test
+ @skipUnlessPlatform(["linux", "android", "netbsd"])
+ def test_libraries_svr4_well_formed(self):
+ self.setup_test()
+ self.libraries_svr4_well_formed()
+
+ @llgs_test
+ @skipUnlessPlatform(["linux", "android", "netbsd"])
+ def test_libraries_svr4_load_addr(self):
+ self.setup_test()
+ self.libraries_svr4_has_correct_load_addr()
+
+ @llgs_test
+ @skipUnlessPlatform(["linux", "android", "netbsd"])
+ def test_libraries_svr4_libs_present(self):
+ self.setup_test()
+ self.libraries_svr4_libs_present()
Added: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/main.cpp?rev=366847&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/main.cpp (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/main.cpp Tue Jul 23 13:40:30 2019
@@ -0,0 +1,15 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+int main(int argc, char **argv) {
+ // Perform a null pointer access.
+ int *const null_int_ptr = nullptr;
+ *null_int_ptr = 0xDEAD;
+
+ return 0;
+}
Added: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_a.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_a.cpp?rev=366847&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_a.cpp (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_a.cpp Tue Jul 23 13:40:30 2019
@@ -0,0 +1,9 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+int svr4lib_a() { return 42; }
Added: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_a.mk
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_a.mk?rev=366847&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_a.mk (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_a.mk Tue Jul 23 13:40:30 2019
@@ -0,0 +1,9 @@
+LEVEL = ../../../make
+
+LIB_PREFIX := svr4lib
+
+DYLIB_NAME := $(LIB_PREFIX)_a
+DYLIB_CXX_SOURCES := $(LIB_PREFIX)_a.cpp
+DYLIB_ONLY := YES
+
+include $(LEVEL)/Makefile.rules
Added: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_b_quote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_b_quote.cpp?rev=366847&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_b_quote.cpp (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_b_quote.cpp Tue Jul 23 13:40:30 2019
@@ -0,0 +1,9 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+int svr4lib_b_quote() { return 42; }
Added: lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_b_quote.mk
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_b_quote.mk?rev=366847&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_b_quote.mk (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/tools/lldb-server/libraries-svr4/svr4lib_b_quote.mk Tue Jul 23 13:40:30 2019
@@ -0,0 +1,9 @@
+LEVEL = ../../../make
+
+LIB_PREFIX := svr4lib
+
+DYLIB_NAME := $(LIB_PREFIX)_b\"
+DYLIB_CXX_SOURCES := $(LIB_PREFIX)_b_quote.cpp
+DYLIB_ONLY := YES
+
+include $(LEVEL)/Makefile.rules
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=366847&r1=366846&r2=366847&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Tue Jul 23 13:40:30 2019
@@ -2076,4 +2076,4 @@ Status NativeProcessLinux::StopProcessor
m_processor_trace_monitor.erase(iter);
return error;
-}
+}
\ No newline at end of file
Modified: lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h?rev=366847&r1=366846&r2=366847&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h (original)
+++ lldb/trunk/source/Plugins/Process/NetBSD/NativeProcessNetBSD.h Tue Jul 23 13:40:30 2019
@@ -9,12 +9,12 @@
#ifndef liblldb_NativeProcessNetBSD_H_
#define liblldb_NativeProcessNetBSD_H_
+#include "Plugins/Process/POSIX/NativeProcessELF.h"
#include "lldb/Target/MemoryRegionInfo.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/FileSpec.h"
#include "NativeThreadNetBSD.h"
-#include "lldb/Host/common/NativeProcessProtocol.h"
namespace lldb_private {
namespace process_netbsd {
@@ -25,7 +25,7 @@ namespace process_netbsd {
/// for debugging.
///
/// Changes in the inferior process state are broadcasted.
-class NativeProcessNetBSD : public NativeProcessProtocol {
+class NativeProcessNetBSD : public NativeProcessELF {
public:
class Factory : public NativeProcessProtocol::Factory {
public:
Modified: lldb/trunk/source/Plugins/Process/POSIX/NativeProcessELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/POSIX/NativeProcessELF.cpp?rev=366847&r1=366846&r2=366847&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/POSIX/NativeProcessELF.cpp (original)
+++ lldb/trunk/source/Plugins/Process/POSIX/NativeProcessELF.cpp Tue Jul 23 13:40:30 2019
@@ -107,4 +107,73 @@ lldb::addr_t NativeProcessELF::GetELFIma
return LLDB_INVALID_ADDRESS;
}
-} // namespace lldb_private
\ No newline at end of file
+template <typename T>
+llvm::Expected<SVR4LibraryInfo>
+NativeProcessELF::ReadSVR4LibraryInfo(lldb::addr_t link_map_addr) {
+ ELFLinkMap<T> link_map;
+ size_t bytes_read;
+ auto error =
+ ReadMemory(link_map_addr, &link_map, sizeof(link_map), bytes_read);
+ if (!error.Success())
+ return error.ToError();
+
+ char name_buffer[PATH_MAX];
+ error = ReadMemory(link_map.l_name, &name_buffer, sizeof(name_buffer),
+ bytes_read);
+ if (bytes_read == 0)
+ return error.ToError();
+ name_buffer[PATH_MAX - 1] = '\0';
+
+ SVR4LibraryInfo info;
+ info.name = std::string(name_buffer);
+ info.link_map = link_map_addr;
+ info.base_addr = link_map.l_addr;
+ info.ld_addr = link_map.l_ld;
+ info.next = link_map.l_next;
+
+ return info;
+}
+
+llvm::Expected<std::vector<SVR4LibraryInfo>>
+NativeProcessELF::GetLoadedSVR4Libraries() {
+ // Address of DT_DEBUG.d_ptr which points to r_debug
+ lldb::addr_t info_address = GetSharedLibraryInfoAddress();
+ if (info_address == LLDB_INVALID_ADDRESS)
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Invalid shared library info address");
+ // Address of r_debug
+ lldb::addr_t address = 0;
+ size_t bytes_read;
+ auto status =
+ ReadMemory(info_address, &address, GetAddressByteSize(), bytes_read);
+ if (!status.Success())
+ return status.ToError();
+ if (address == 0)
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Invalid r_debug address");
+ // Read r_debug.r_map
+ lldb::addr_t link_map = 0;
+ status = ReadMemory(address + GetAddressByteSize(), &link_map,
+ GetAddressByteSize(), bytes_read);
+ if (!status.Success())
+ return status.ToError();
+ if (address == 0)
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "Invalid link_map address");
+
+ std::vector<SVR4LibraryInfo> library_list;
+ while (link_map) {
+ llvm::Expected<SVR4LibraryInfo> info =
+ GetAddressByteSize() == 8 ? ReadSVR4LibraryInfo<uint64_t>(link_map)
+ : ReadSVR4LibraryInfo<uint32_t>(link_map);
+ if (!info)
+ return info.takeError();
+ if (!info->name.empty() && info->base_addr != 0)
+ library_list.push_back(*info);
+ link_map = info->next;
+ }
+
+ return library_list;
+}
+
+} // namespace lldb_private
Modified: lldb/trunk/source/Plugins/Process/POSIX/NativeProcessELF.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/POSIX/NativeProcessELF.h?rev=366847&r1=366846&r2=366847&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/POSIX/NativeProcessELF.h (original)
+++ lldb/trunk/source/Plugins/Process/POSIX/NativeProcessELF.h Tue Jul 23 13:40:30 2019
@@ -37,6 +37,13 @@ protected:
template <typename ELF_EHDR, typename ELF_PHDR, typename ELF_DYN>
lldb::addr_t GetELFImageInfoAddress();
+ llvm::Expected<std::vector<SVR4LibraryInfo>>
+ GetLoadedSVR4Libraries() override;
+
+ template <typename T>
+ llvm::Expected<SVR4LibraryInfo>
+ ReadSVR4LibraryInfo(lldb::addr_t link_map_addr);
+
std::unique_ptr<AuxVector> m_aux_vector;
llvm::Optional<lldb::addr_t> m_shared_library_info_addr;
};
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp?rev=366847&r1=366846&r2=366847&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp Tue Jul 23 13:40:30 2019
@@ -825,6 +825,7 @@ GDBRemoteCommunicationServerCommon::Hand
#if defined(__linux__) || defined(__NetBSD__)
response.PutCString(";QPassSignals+");
response.PutCString(";qXfer:auxv:read+");
+ response.PutCString(";qXfer:libraries-svr4:read+");
#endif
return SendPacketNoLock(response.GetString());
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp?rev=366847&r1=366846&r2=366847&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.cpp Tue Jul 23 13:40:30 2019
@@ -2765,6 +2765,24 @@ GDBRemoteCommunicationServerLLGS::ReadXf
return std::move(*buffer_or_error);
}
+ if (object == "libraries-svr4") {
+ auto library_list = m_debugged_process_up->GetLoadedSVR4Libraries();
+ if (!library_list)
+ return library_list.takeError();
+
+ StreamString response;
+ response.Printf("<library-list-svr4 version=\"1.0\">");
+ for (auto const &library : *library_list) {
+ response.Printf("<library name=\"%s\" ",
+ XMLEncodeAttributeValue(library.name.c_str()).c_str());
+ response.Printf("lm=\"0x%" PRIx64 "\" ", library.link_map);
+ response.Printf("l_addr=\"0x%" PRIx64 "\" ", library.base_addr);
+ response.Printf("l_ld=\"0x%" PRIx64 "\" />", library.ld_addr);
+ }
+ response.Printf("</library-list-svr4>");
+ return MemoryBuffer::getMemBufferCopy(response.GetString(), __FUNCTION__);
+ }
+
return llvm::make_error<PacketUnimplementedError>(
"Xfer object not supported");
}
@@ -3283,3 +3301,28 @@ GDBRemoteCommunicationServerLLGS::FindMo
return GDBRemoteCommunicationServerCommon::FindModuleFile(module_path, arch);
}
+
+std::string GDBRemoteCommunicationServerLLGS::XMLEncodeAttributeValue(
+ llvm::StringRef value) {
+ std::string result;
+ for (const char &c : value) {
+ switch (c) {
+ case '\'':
+ result += "'";
+ break;
+ case '"':
+ result += """;
+ break;
+ case '<':
+ result += "<";
+ break;
+ case '>':
+ result += ">";
+ break;
+ default:
+ result += c;
+ break;
+ }
+ }
+ return result;
+}
\ No newline at end of file
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h?rev=366847&r1=366846&r2=366847&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerLLGS.h Tue Jul 23 13:40:30 2019
@@ -196,6 +196,8 @@ protected:
llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
ReadXferObject(llvm::StringRef object, llvm::StringRef annex);
+ static std::string XMLEncodeAttributeValue(llvm::StringRef value);
+
private:
void HandleInferiorState_Exited(NativeProcessProtocol *process);
More information about the lldb-commits
mailing list