1 import xml.etree.ElementTree as ET
3 import gdbremote_testcase
4 from lldbsuite.test.decorators import *
5 from lldbsuite.test.lldbtest import *
8 class TestGdbRemoteLibrariesSvr4Support(gdbremote_testcase.GdbRemoteTestCaseBase):
10 mydir = TestBase.compute_mydir(__file__)
12 FEATURE_NAME = "qXfer:libraries-svr4:read"
17 self.set_inferior_startup_launch()
19 env[self.dylibPath] = self.getBuildDir()
20 self.prep_debug_monitor_and_inferior(inferior_env=env)
21 self.continue_process_and_wait_for_stop()
23 def get_expected_libs(self):
24 return ["libsvr4lib_a.so", 'libsvr4lib_b".so']
26 def has_libraries_svr4_support(self):
27 self.add_qSupported_packets()
28 context = self.expect_gdbremote_sequence()
29 self.assertIsNotNone(context)
30 features = self.parse_qSupported_response(context)
31 return self.FEATURE_NAME in features and features[self.FEATURE_NAME] == "+"
33 def get_libraries_svr4_data(self):
34 # Start up llgs and inferior, and check for libraries-svr4 support.
35 if not self.has_libraries_svr4_support():
36 self.skipTest("libraries-svr4 not supported")
38 # Grab the libraries-svr4 data.
39 self.reset_test_sequence()
40 self.test_sequence.add_log_lines(
42 "read packet: $qXfer:libraries-svr4:read::0,ffff:#00",
46 r"^\$([^E])(.*)#[0-9a-fA-F]{2}$", re.MULTILINE | re.DOTALL
48 "capture": {1: "response_type", 2: "content_raw"},
54 context = self.expect_gdbremote_sequence()
55 self.assertIsNotNone(context)
57 # Ensure we end up with all libraries-svr4 data in one packet.
58 self.assertEqual(context.get("response_type"), "l")
61 content_raw = context.get("content_raw")
62 self.assertIsNotNone(content_raw)
65 def get_libraries_svr4_xml(self):
66 libraries_svr4 = self.get_libraries_svr4_data()
69 xml_root = ET.fromstring(libraries_svr4)
70 except xml.etree.ElementTree.ParseError:
72 self.assertIsNotNone(xml_root, "Malformed libraries-svr4 XML")
75 def libraries_svr4_well_formed(self):
76 xml_root = self.get_libraries_svr4_xml()
77 self.assertEqual(xml_root.tag, "library-list-svr4")
78 for child in xml_root:
79 self.assertEqual(child.tag, "library")
80 self.assertItemsEqual(child.attrib.keys(), ["name", "lm", "l_addr", "l_ld"])
82 def libraries_svr4_has_correct_load_addr(self):
83 xml_root = self.get_libraries_svr4_xml()
84 for child in xml_root:
85 name = child.attrib.get("name")
86 base_name = os.path.basename(name)
87 if os.path.basename(name) not in self.get_expected_libs():
89 load_addr = int(child.attrib.get("l_addr"), 16)
90 self.reset_test_sequence()
91 self.add_query_memory_region_packets(load_addr)
92 context = self.expect_gdbremote_sequence()
93 mem_region = self.parse_memory_region_packet(context)
94 self.assertEqual(load_addr, int(mem_region.get("start", 0), 16))
96 os.path.realpath(name), os.path.realpath(mem_region.get("name", ""))
99 def libraries_svr4_libs_present(self):
100 xml_root = self.get_libraries_svr4_xml()
101 libraries_svr4_names = []
102 for child in xml_root:
103 name = child.attrib.get("name")
104 libraries_svr4_names.append(os.path.realpath(name))
105 for lib in self.get_expected_libs():
106 self.assertIn(self.getBuildDir() + "/" + lib, libraries_svr4_names)
109 @skipUnlessPlatform(["linux", "android", "netbsd"])
110 def test_supports_libraries_svr4(self):
112 self.assertTrue(self.has_libraries_svr4_support())
115 @skipUnlessPlatform(["linux", "android", "netbsd"])
116 @expectedFailureNetBSD
117 def test_libraries_svr4_well_formed(self):
119 self.libraries_svr4_well_formed()
122 @skipUnlessPlatform(["linux", "android", "netbsd"])
123 @expectedFailureNetBSD
124 def test_libraries_svr4_load_addr(self):
126 self.libraries_svr4_has_correct_load_addr()
129 @skipUnlessPlatform(["linux", "android", "netbsd"])
130 @expectedFailureNetBSD
131 def test_libraries_svr4_libs_present(self):
133 self.libraries_svr4_libs_present()