Skip to content

Commit 0a79b9a

Browse files
Kevin Freikevinfrei
Kevin Frei
authored andcommitted
Switched to using LLDB to get UUID at @clayborg's suggestion
1 parent cead28f commit 0a79b9a

File tree

5 files changed

+32
-68
lines changed

5 files changed

+32
-68
lines changed

lldb/packages/Python/lldbsuite/test/make/Makefile.rules

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ endif
577577
else
578578
ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
579579
ifeq "$(SAVE_FULL_DEBUG_BINARY)" "YES"
580-
cp "$(EXE)" "$(EXE).unstriped""
580+
cp "$(EXE)" "$(EXE).unstripped"
581581
endif
582582
$(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
583583
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
@@ -588,13 +588,6 @@ endif
588588
endif
589589

590590

591-
#----------------------------------------------------------------------
592-
# Support emitting the content of the GNU build-id into a file
593-
# This needs to be used in conjunction with GEN_GNU_BUILD_ID := YES
594-
#----------------------------------------------------------------------
595-
$(EXE).uuid : $(EXE)
596-
$(OBJCOPY) --dump-section=.note.gnu.build-id=$@ $<
597-
598591
#----------------------------------------------------------------------
599592
# Make the dylib
600593
#----------------------------------------------------------------------

lldb/test/API/debuginfod/Normal/Makefile

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,18 @@ C_SOURCES := main.c
22

33
# For normal (non DWP) Debuginfod tests, we need:
44

5-
# * The "full" binary: a.out.debug
6-
# Produced by Makefile.rules with KEEP_FULL_DEBUG_BINARY set to YES and
5+
# * The full binary: a.out.unstripped
6+
# Produced by Makefile.rules with SAVE_FULL_DEBUG_BINARY set to YES and
77
# SPLIT_DEBUG_SYMBOLS set to YES
88

99
# * The stripped binary (a.out)
1010
# Produced by Makefile.rules with SPLIT_DEBUG_SYMBOLS set to YES
1111

12-
# * The 'only-keep-debug' binary (a.out.dbg)
12+
# * The 'only-keep-debug' binary (a.out.debug)
1313
# Produced below
1414

15-
# * The .uuid file (for a little easier testing code)
16-
# Produced below
17-
18-
# Don't strip the debug info from a.out:
1915
SPLIT_DEBUG_SYMBOLS := YES
2016
SAVE_FULL_DEBUG_BINARY := YES
2117
GEN_GNU_BUILD_ID := YES
2218

23-
all: a.out.uuid a.out
24-
2519
include Makefile.rules

lldb/test/API/debuginfod/Normal/TestDebuginfod.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,13 @@
11
import os
22
import shutil
33
import tempfile
4-
import struct
54

65
import lldb
76
from lldbsuite.test.decorators import *
87
import lldbsuite.test.lldbutil as lldbutil
98
from lldbsuite.test.lldbtest import *
109

1110

12-
def getUUID(aoutuuid):
13-
"""
14-
Pull the 20 byte UUID out of the .note.gnu.build-id section that was dumped
15-
to a file already, as part of the build.
16-
"""
17-
with open(aoutuuid, "rb") as f:
18-
data = f.read(36)
19-
if len(data) != 36:
20-
return None
21-
header = struct.unpack_from("<4I", data)
22-
if len(header) != 4:
23-
return None
24-
# 4 element 'prefix', 20 bytes of uuid, 3 byte long string: 'GNU':
25-
if header[0] != 4 or header[1] != 20 or header[2] != 3 or header[3] != 0x554E47:
26-
return None
27-
return data[16:].hex()
28-
29-
3011
"""
3112
Test support for the DebugInfoD network symbol acquisition protocol.
3213
This one is for simple / no split-dwarf scenarios.
@@ -135,8 +116,8 @@ def config_test(self, local_files, debuginfo=None, executable=None):
135116

136117
self.build()
137118

138-
uuid = getUUID(self.getBuildArtifact("a.out.uuid"))
139-
if !uuid:
119+
uuid = self.getUUID("a.out")
120+
if not uuid:
140121
self.fail("Could not get UUID for a.out")
141122
return
142123
self.main_source_file = lldb.SBFileSpec("main.c")
@@ -185,3 +166,13 @@ def config_test(self, local_files, debuginfo=None, executable=None):
185166
"settings insert-before plugin.symbol-locator.debuginfod.server-urls 0 file://%s"
186167
% self.tmp_dir
187168
)
169+
170+
def getUUID(self, filename):
171+
try:
172+
target = self.dbg.CreateTarget(self.getBuildArtifact(filename))
173+
module = target.GetModuleAtIndex(0)
174+
uuid = module.GetUUIDString().replace("-", "").lower()
175+
self.dbg.DeleteTarget(target)
176+
return uuid if len(uuid) == 40 else None
177+
except:
178+
return None

lldb/test/API/debuginfod/SplitDWARF/Makefile

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,21 @@ C_SOURCES := main.c
33
# For split-dwarf Debuginfod tests, we need:
44

55
# * A .DWP file (a.out.dwp)
6-
# Produced by Makefile.rules with MAKE_DWO and MERGE_DWOS both set to YES
6+
# Produced by Makefile.rules with MAKE_DWP set to YES
77

8-
# * The "full" binary: it's missing things that live in .dwo's (a.out.debug)
9-
# Produced by Makefile.rules with KEEP_FULL_DEBUG_BINARY set to YES and
8+
# * The "full" binary (missing things that live in .dwo's) (a.out.unstripped)
9+
# Produced by Makefile.rules with SAVE_FULL_DEBUG_BINARY set to YES and
1010
# SPLIT_DEBUG_SYMBOLS set to YES
1111

1212
# * The stripped binary (a.out)
1313
# Produced by Makefile.rules
1414

15-
# * The 'only-keep-debug' binary (a.out.dbg)
15+
# * The 'only-keep-debug' binary (a.out.debug)
1616
# Produced below
1717

18-
# * The .uuid file (for a little easier testing code)
19-
# Produced here in the rule below
20-
2118
MAKE_DWP := YES
2219
SPLIT_DEBUG_SYMBOLS := YES
2320
SAVE_FULL_DEBUG_BINARY := YES
2421
GEN_GNU_BUILD_ID := YES
2522

26-
all: a.out.uuid a.out
27-
2823
include Makefile.rules

lldb/test/API/debuginfod/SplitDWARF/TestDebuginfodDWP.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,13 @@
44
import os
55
import shutil
66
import tempfile
7-
import struct
87

98
import lldb
109
from lldbsuite.test.decorators import *
1110
import lldbsuite.test.lldbutil as lldbutil
1211
from lldbsuite.test.lldbtest import *
1312

1413

15-
def getUUID(aoutuuid):
16-
"""
17-
Pull the 20 byte UUID out of the .note.gnu.build-id section that was dumped
18-
to a file already, as part of the build.
19-
"""
20-
with open(aoutuuid, "rb") as f:
21-
data = f.read(36)
22-
if len(data) != 36:
23-
return None
24-
header = struct.unpack_from("<4I", data)
25-
if len(header) != 4:
26-
return None
27-
# 4 element 'prefix', 20 bytes of uuid, 3 byte long string: 'GNU':
28-
if header[0] != 4 or header[1] != 20 or header[2] != 3 or header[3] != 0x554E47:
29-
return None
30-
return data[16:].hex()
31-
32-
3314
"""
3415
Test support for the DebugInfoD network symbol acquisition protocol.
3516
This file is for split-dwarf (dwp) scenarios.
@@ -145,8 +126,8 @@ def config_test(self, local_files, debuginfo=None, executable=None):
145126

146127
self.build()
147128

148-
uuid = getUUID(self.getBuildArtifact("a.out.uuid"))
149-
if !uuid:
129+
uuid = self.getUUID("a.out")
130+
if not uuid:
150131
self.fail("Could not get UUID for a.out")
151132
return
152133
self.main_source_file = lldb.SBFileSpec("main.c")
@@ -194,3 +175,13 @@ def config_test(self, local_files, debuginfo=None, executable=None):
194175
"settings insert-before plugin.symbol-locator.debuginfod.server-urls 0 file://%s"
195176
% self.tmp_dir
196177
)
178+
179+
def getUUID(self, filename):
180+
try:
181+
target = self.dbg.CreateTarget(self.getBuildArtifact(filename))
182+
module = target.GetModuleAtIndex(0)
183+
uuid = module.GetUUIDString().replace("-", "").lower()
184+
self.dbg.DeleteTarget(target)
185+
return uuid if len(uuid) == 40 else None
186+
except:
187+
return None

0 commit comments

Comments
 (0)