Skip to content

Commit 1535a16

Browse files
author
Kevin Frei
committed
I think I have the files I need finally generating properly
1 parent 4085409 commit 1535a16

File tree

8 files changed

+323
-157
lines changed

8 files changed

+323
-157
lines changed

lldb/test/API/debuginfod/Makefile

Lines changed: 0 additions & 105 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
C_SOURCES := main.c
2+
LD_EXTRAS := -Wl,--build-id
3+
4+
# For normal (non DWP) Debuginfod tests, we need:
5+
6+
# * The "full" binary: a.out.debug
7+
# Produced by Makefile.rules with KEEP_FULL_DEBUG_BINARY set to YES and
8+
# SPLIT_DEBUG_SYMBOLS set to YES
9+
10+
# * The stripped binary (a.out)
11+
# Produced by Makefile.rules with SPLIT_DEBUG_SYMBOLS set to YES
12+
13+
# * The 'only-keep-debug' binary (a.out.dbg)
14+
# Produced below
15+
16+
# * The .uuid file (for a little easier testing code)
17+
# Produced below
18+
19+
# Don't strip the debug info from a.out:
20+
SPLIT_DEBUG_SYMBOLS := YES
21+
KEEP_FULL_DEBUG_BINARY := YES
22+
23+
all: a.out a.out.uuid a.out.dbg a.out.debug
24+
25+
# Put the build-id into a file by itself for minimum effort in Python
26+
a.out.uuid: a.out
27+
$(OBJCOPY) --dump-section=.note.gnu.build-id=$@ $<
28+
29+
a.out.dbg: a.out.debug
30+
$(OBJCOPY) --only-keep-debug $< $@
31+
32+
include Makefile.rules
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
"""
2+
Test support for the DebugInfoD network symbol acquisition protocol.
3+
"""
4+
5+
import lldb
6+
import lldbsuite.test.lldbutil as lldbutil
7+
from lldbsuite.test.lldbtest import *
8+
9+
def getUUID(aoutuuid):
10+
"""
11+
Pull the 20 byte UUID out of the .note.gnu.build-id section that was dumped
12+
to a file already, as part of the build.
13+
"""
14+
import struct
15+
with open(aoutuuid, "rb") as f:
16+
data = f.read(36)
17+
if len(data) != 36:
18+
return None
19+
header = struct.unpack_from("<4I", data)
20+
if len(header) != 4:
21+
return None
22+
# 4 element 'prefix', 20 bytes of uuid, 3 byte long string, 'GNU':
23+
if header[0] != 4 or header[1] != 20 or header[2] != 3 or header[3] != 0x554e47:
24+
return None
25+
return data[16:].hex()
26+
27+
def config_test(local_files, uuid, debuginfo, executable):
28+
"""
29+
Set up a test with local_files[] copied to a particular location
30+
so that we control which files are, or are not, found in the file system.
31+
Also, create a stand-alone file-system 'hosted' debuginfod server for the
32+
given UUID.
33+
34+
Make the filesystem look like:
35+
36+
/tmp/<tmpdir>/test/[local_files]
37+
38+
/tmp/<tmpdir>/cache (for lldb to use as a temp cache)
39+
40+
/tmp/<tmpdir>/buildid/<uuid>/executable -> <executable>
41+
/tmp/<tmpdir>/buildid/<uuid>/debuginfo -> <debuginfo>
42+
Returns the /tmp/<tmpdir> path
43+
"""
44+
import os
45+
import shutil
46+
import tempfile
47+
48+
tmp_dir = tempfile.mkdtemp()
49+
test_dir = os.path.join(tmp_dir, "test")
50+
uuid_dir = os.path.join(tmp_dir, "buildid", uuid)
51+
52+
# Make the 3 directories
53+
os.makedirs(os.path.join(tmp_dir, "cache"))
54+
os.makedirs(uuid_dir)
55+
os.makedirs(test_dir)
56+
57+
# Copy the files used by the test:
58+
for f in local_files:
59+
shutil.copy(f, test_dir)
60+
61+
# Fill in the 'file://...' mocked Debuginfod server
62+
if debuginfo:
63+
shutil.move(debuginfo, os.path.join(uuiddir, "debuginfo"))
64+
if executable:
65+
shutil.move(executable, os.path.join(uuiddir, "executable"))
66+
67+
return tmp_dir
68+
69+
70+
# Need to test 5 different scenarios:
71+
# 1 - A stripped binary with it's corresponding unstripped binary:
72+
# 2 - A stripped binary with a corresponding --only-keep-debug symbols file
73+
# 3 - A split binary with it's corresponding DWP file
74+
# 4 - A stripped, split binary with an unstripped binary and a DWP file
75+
# 5 - A stripped, split binary with an --only-keep-debug symbols file and a DWP file
76+
77+
class DebugInfodTests(TestBase):
78+
# No need to try every flavor of debug inf.
79+
NO_DEBUG_INFO_TESTCASE = True
80+
81+
def test_stuff(self):
82+
"""This should test stuff."""
83+
self.build()
84+
# Pull the UUID out of the binary.
85+
uuid_file = self.getBuildArtifact("a.out.uuid")
86+
self.aout = self.getBuildArtifact("a.out")
87+
self.debugbin = self.getBuildArtifact("a.out.debug")
88+
self.dwp = self.getBuildArtifact("a.out.dwp")
89+
self.uuid = getUUID(uuid_file)
90+
# Setup the fake DebugInfoD server.
91+
server_root = config_fake_debuginfod_server(self.uuid, self.dwp, self.debugbin)
92+
93+
# Configure LLDB properly
94+
self.runCmd("settings set symbols.enable-external-lookup true")
95+
self.runCmd("settings set plugin.symbol-locator.debuginfod.cache-path %s/cache" % server_root)
96+
self.runCmd("settings clear plugin.symbol-locator.debuginfod.server-urls")
97+
cmd = "settings insert-before plugin.symbol-locator.debuginfod.server-urls 0 file://%s" % server_root
98+
self.runCmd(cmd)
99+
print(cmd)
100+
# Check to see if the symbol file is properly loaded
101+
self.main_source_file = lldb.SBFileSpec("main.c")
102+
self.sample_test()
103+
104+
def sample_test(self):
105+
"""You might use the test implementation in several ways, say so here."""
106+
# This function starts a process, "a.out" by default, sets a source
107+
# breakpoint, runs to it, and returns the thread, process & target.
108+
# It optionally takes an SBLaunchOption argument if you want to pass
109+
# arguments or environment variables.
110+
target = target = self.dbg.CreateTarget(self.aout)
111+
self.assertTrue(target and target.IsValid(), "Target is valid")
112+
bp = target.BreakpointCreateByName("func")
113+
self.assertTrue(bp and bp.IsValid(), "Breakpoint is valid")
114+
self.assertEqual(bp.GetNumLocations(), 1)
115+
print("Loc @ Index 0:")
116+
print(bp.GetLocationAtIndex(0))
117+
loc = bp.GetLocationAtIndex(0)
118+
self.assertTrue(loc and loc.IsValid(), "Location is valid")
119+
addr = loc.GetAddress()
120+
self.assertTrue(addr and addr.IsValid(), "Loc address is valid")
121+
line_entry = addr.GetLineEntry()
122+
self.assertTrue(line_entry and line_entry.IsValid(), "Loc line entry is valid")
123+
self.assertEqual(line_entry.GetLine(), 18)
124+
self.assertEqual(loc.GetLineEntry().GetFileSpec().GetFilename(), self.main_source_file.GetFilename())
125+
126+
def sample_test_no_launch(self):
127+
"""Same as above but doesn't launch a process."""
128+
129+
target = self.createTestTarget()
130+
self.expect_expr("global_test_var", result_value="10")
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
C_SOURCES := main.c
2+
LD_EXTRAS := -Wl,--build-id
3+
4+
# For split-dwarf Debuginfod tests, we need:
5+
6+
# * A .DWP file (a.out.dwp)
7+
# Produced by Makefile.rules with MAKE_DWO and MERGE_DWOS both set to YES
8+
9+
# * The "full" binary: it's missing things that live in .dwo's (a.out.debug)
10+
# Produced by Makefile.rules with KEEP_FULL_DEBUG_BINARY set to YES and
11+
# SPLIT_DEBUG_SYMBOLS set to YES
12+
13+
# * The stripped binary (a.out)
14+
# Produced by Makefile.rules
15+
16+
# * The 'only-keep-debug' binary (a.out.dbg)
17+
# Produced below
18+
19+
# * The .uuid file (for a little easier testing code)
20+
# Produced here in the rule below
21+
22+
MAKE_DWO := YES
23+
MERGE_DWOS := YES
24+
SPLIT_DEBUG_SYMBOLS := YES
25+
KEEP_FULL_DEBUG_BINARY := YES
26+
27+
all: a.out.uuid a.out a.out.debug a.out.dbg
28+
29+
a.out.dbg: a.out.debug
30+
$(OBJCOPY) --only-keep-debug $< $@
31+
32+
# Put the build-id into a file by itself for minimum effort in Python
33+
a.out.uuid: a.out
34+
$(OBJCOPY) --dump-section=.note.gnu.build-id=$@ $<
35+
36+
include Makefile.rules

0 commit comments

Comments
 (0)