Skip to content

Commit bf72ca3

Browse files
author
Kevin Frei
committed
Working on API test migration
1 parent 1cde47b commit bf72ca3

File tree

5 files changed

+192
-12
lines changed

5 files changed

+192
-12
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ LLDB_BASE_DIR := $(THIS_FILE_DIR)/../../../../../
5151
#
5252
# GNUWin32 uname gives "windows32" or "server version windows32" while
5353
# some versions of MSYS uname return "MSYS_NT*", but most environments
54-
# standardize on "Windows_NT", so we'll make it consistent here.
54+
# standardize on "Windows_NT", so we'll make it consistent here.
5555
# When running tests from Visual Studio, the environment variable isn't
5656
# inherited all the way down to the process spawned for make.
5757
#----------------------------------------------------------------------
@@ -210,6 +210,12 @@ else
210210
ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
211211
DSYM = $(EXE).debug
212212
endif
213+
214+
ifeq "$(MERGE_DWOS)" "YES"
215+
MAKE_DWO := YES
216+
DWP_NAME = $(EXE).dwp
217+
DYLIB_DWP_NAME = $(DYLIB_NAME).dwp
218+
endif
213219
endif
214220

215221
LIMIT_DEBUG_INFO_FLAGS =
@@ -357,6 +363,7 @@ ifneq "$(OS)" "Darwin"
357363

358364
OBJCOPY ?= $(call replace_cc_with,objcopy)
359365
ARCHIVER ?= $(call replace_cc_with,ar)
366+
DWP ?= $(call reaplce_cc_with,dwp)
360367
override AR = $(ARCHIVER)
361368
endif
362369

@@ -565,9 +572,16 @@ else
565572
endif
566573
else
567574
ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
575+
ifneq "$(KEEP_FULL_DEBUG_BINARY)" "YES"
568576
$(OBJCOPY) --only-keep-debug "$(EXE)" "$(DSYM)"
577+
else
578+
cp "$(EXE)" "$(DSYM)"
579+
endif
569580
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DSYM)" "$(EXE)" "$(EXE)"
570581
endif
582+
ifeq "$(MERGE_DWOS)" "YES"
583+
$(DWP) -o "$(DWP_FILE)" $(DWOS)
584+
endif
571585
endif
572586

573587
#----------------------------------------------------------------------
@@ -610,9 +624,16 @@ endif
610624
else
611625
$(LD) $(DYLIB_OBJECTS) $(LDFLAGS) -shared -o "$(DYLIB_FILENAME)"
612626
ifeq "$(SPLIT_DEBUG_SYMBOLS)" "YES"
627+
ifneq "$(KEEP_FULL_DEBUG_BINARY)" "YES"
628+
cp "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug"
629+
else
613630
$(OBJCOPY) --only-keep-debug "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME).debug"
631+
endif
614632
$(OBJCOPY) --strip-debug --add-gnu-debuglink="$(DYLIB_FILENAME).debug" "$(DYLIB_FILENAME)" "$(DYLIB_FILENAME)"
615633
endif
634+
ifeq "$(MERGE_DWOS)" "YES"
635+
$(DWP) -o $(DYLIB_DWP_FILE) $(DYLIB_DWOS)
636+
endif
616637
endif
617638

618639
#----------------------------------------------------------------------

lldb/test/API/debuginfod/Makefile

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
C_SOURCES := main.c
2+
CFLAGS_EXTRAS := -std=c99
3+
4+
MAKE_DWO := YES
5+
SPLIT_DEBUG_SYMBOLS := YES
6+
KEEP_FULL_DEBUG_BINARY := YES
7+
MERGE_DWOS := YES
8+
9+
# From shell, I can do this stuff pretty easily:
10+
# OBJCOPY --dump-section .note.gnu.build-id=<output.36.bytes.bin> <input.bin>
11+
# hexdump -s 16 -e '"%02x"' output.bin
12+
# Or this in a single command:
13+
# objcopy --dump-section=.note.gnu.build-id=/dev/stdout adfinder.stripped | xxd -s 16 -g 0 -p
14+
# I think I need to add capabilities in the Makefile.rules to strip the binary (not an -OKD binary)
15+
# and to create a DWP file
16+
17+
include Makefile.rules
18+
19+
20+
#!/bin/sh
21+
22+
# Testing 5 different scenarios:
23+
# 1 - A stripped binary with it's corresponding unstripped binary:
24+
# 2 - A stripped binary with a corresponding --only-keep-debug symbols file
25+
# 3 - A split binary with it's corresponding DWP file
26+
# 4 - A stripped, split binary with an unstripped binary and a DWP file
27+
# 5 - A stripped, split binary with an --only-keep-debug symbols file and a DWP file
28+
29+
##mkdir -p gen
30+
##mkdir -p run
31+
32+
# First, compile & link the binaries (normal and split)
33+
34+
##${builddir}/bin/clang -g -o gen/bin-normal.o -O0 -c main.c
35+
##ld -nostdlib gen/bin-normal.o --build-id=sha1 -o gen/bin-normal
36+
##${builddir}/bin/clang -g -gsplit-dwarf -o gen/bin-split.o -O0 -c main.c
37+
##ld -nostdlib gen/bin-split.o --build-id=sha1 -o gen/bin-split
38+
39+
# Next, create the file variations we need
40+
41+
# Variation 1: -g, stripped
42+
##${builddir}/bin/llvm-objcopy --strip-debug gen/bin-normal gen/bin-stripped
43+
# Variation 2: -g, stripped, --only-keep-debug symbols
44+
##${builddir}/bin/llvm-objcopy --only-keep-debug gen/bin-normal gen/sym-stripped
45+
# Variation 3: -gsplit-dwarf: .dwp
46+
##${builddir}/bin/llvm-dwp -e gen/bin-split -o gen/bin-split.dwp
47+
# Variation 4: -gsplit-dwarf: stripped, .dwp
48+
##${builddir}/bin/llvm-objcopy --strip-debug gen/bin-split gen/bin-split-stripped
49+
# Variation 5: -gsplit-dwarf: stripped, --only-keep-debug + .dwp
50+
##${builddir}/bin/llvm-objcopy --only-keep-debug gen/bin-split gen/sym-split
51+
52+
# Finally, produce the .yaml files for testing
53+
54+
# Scenario 1:
55+
# target: bin-stripped
56+
# Scenario 1a:
57+
# symbols: bin-normal (hosted as debuginfo)
58+
# Scenario 1b:
59+
# symbols: bin-normal (hosted as executable)
60+
##${builddir}/bin/obj2yaml gen/bin-stripped -o bin-stripped.yaml
61+
##${builddir}/bin/obj2yaml gen/bin-normal -o bin-normal.yaml
62+
# @ testing time: yaml2obj bin-stripped.yaml -o ${out}/bin-stripped
63+
# @ testing time: yaml2obj bin-normal.yaml -o ${out}/bin-normal
64+
65+
66+
# Scenario 2:
67+
# target: bin-stripped-okd
68+
# Scenario 2a:
69+
# symbols: sym-stripped (hosted as debuginfo)
70+
# Scenario 2b:
71+
# symbols: sym-stripped (hosted as executable)
72+
##${builddir}/bin/obj2yaml gen/sym-stripped -o sym-stripped.yaml
73+
# To produce a correct .gnu.debuglink, you have to do it at test generation time.
74+
# The section includes a CRC that yaml2obj doesn't properly produce.
75+
# @ testing time: yaml2obj sym-stripped.yaml -o ${out}/sym-stripped
76+
# @ testing time: llvm-objcopy bin-stripped --add-gnu-debuglink=${out}/sym-stripped ${out}/bin-stripped-okd
77+
78+
# Scenario 3:
79+
# target: bin-split
80+
# DWP: bin-split.dwp (hosted as debuginfo)
81+
##${builddir}/bin/obj2yaml gen/bin-split -o bin-split.yaml
82+
##${builddir}/bin/obj2yaml gen/bin-split.dwp -o bin-split-dwp.yaml
83+
# @ testing time: yaml2obj bin-split.yaml -o ${out}/bin-split
84+
# @ testing time: yaml2obj bin-split-dwp.yaml -o ${out}/bin-split.dwp
85+
86+
# Scenario 4:
87+
# target: bin-split-stripped
88+
# symbols: bin-split (hosted as executable)
89+
# DWP bin-split.dwp (hosted as debuginfo)
90+
# This doesn't work from a file system "as is".
91+
# I believe you can set the symbol file manually to the bin-split file.
92+
# TODO: Need to check for the -no-locator test to see what the name of
93+
# the .dwp is expected to be.
94+
##${builddir}/bin/obj2yaml gen/bin-split-stripped -o bin-split-stripped.yaml
95+
# bin-split and bin-split.dwp already generated in Scenario 3
96+
# @ testing time: yaml2obj bin-split-stripped.yaml -o ${out}/bin-split-stripped
97+
98+
# Scenario 5:
99+
# target: bin-split-stripped-okd
100+
# symbols: sym-split (hosted as executable)
101+
# DWP: bin-split.dwp (hosted as debuginfo)
102+
##${builddir}/bin/obj2yaml gen/sym-split -o sym-split.yaml
103+
# @ testing time: yaml2obj main-split-nodbg.yaml -o gen/main-split-nodbg.tmp
104+
# @ testing time: yaml2obj main-split-dbg.yaml -o run/main-split-dbg
105+
# @ testing time: llvm-objcopy gen/main-split-nodbg.tmp --add-gnu-debuglink=run/main-split-dbg run/main-split-nodbg
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Describe the purpose of the test class here.
3+
"""
4+
5+
6+
import lldb
7+
import lldbsuite.test.lldbutil as lldbutil
8+
from lldbsuite.test.lldbtest import *
9+
10+
11+
class RenameThisSampleTestTestCase(TestBase):
12+
# If your test case doesn't stress debug info, then
13+
# set this to true. That way it won't be run once for
14+
# each debug info format.
15+
NO_DEBUG_INFO_TESTCASE = True
16+
17+
def test_sample_rename_this(self):
18+
"""There can be many tests in a test case - describe this test here."""
19+
self.build()
20+
self.main_source_file = lldb.SBFileSpec("main.c")
21+
self.sample_test()
22+
23+
def setUp(self):
24+
# Call super's setUp().
25+
TestBase.setUp(self)
26+
# Set up your test case here. If your test doesn't need any set up then
27+
# remove this method from your TestCase class.
28+
# I need to setup the file-system-hosted Debuginfod server
29+
30+
def sample_test(self):
31+
"""You might use the test implementation in several ways, say so here."""
32+
33+
# This function starts a process, "a.out" by default, sets a source
34+
# breakpoint, runs to it, and returns the thread, process & target.
35+
# It optionally takes an SBLaunchOption argument if you want to pass
36+
# arguments or environment variables.
37+
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
38+
self, "Set a breakpoint here", self.main_source_file
39+
)
40+
41+
frame = thread.GetFrameAtIndex(0)
42+
test_var = frame.FindVariable("test_var")
43+
self.assertSuccess(test_var.GetError(), "Failed to fetch test_var")
44+
test_value = test_var.GetValueAsUnsigned()
45+
self.assertEqual(test_value, 10, "Got the right value for test_var")
46+
47+
def sample_test_no_launch(self):
48+
"""Same as above but doesn't launch a process."""
49+
50+
target = self.createTestTarget()
51+
self.expect_expr("global_test_var", result_value="10")

lldb/test/API/debuginfod/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This is a dump little pair of test files
2+
3+
int func(int argc, const char *argv[]) {
4+
return (argc + 1) * (argv[argc][0] + 2);
5+
}
6+
7+
int main(int argc, const char *argv[]) {
8+
return func(0, argv);
9+
}
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
// A script to (re)create the .yaml files is in 'make-inputs'. If you make changes
22
// you'll need to update the .note.gnu.buildid values in the tests, as the cache names
33

4-
int func(int argc, const char **argv) { return (argc + 1) * (argv[argc][0] + 2); }
5-
6-
__attribute__((force_align_arg_pointer)) void _start(void) {
7-
8-
/* main body of program: call main(), etc */
9-
10-
const char *argv[] = {""};
11-
func(0, argv);
4+
int func(int argc, const char **argv) {
5+
return (argc + 1) * (argv[argc][0] + 2);
6+
}
127

13-
/* exit system call */
14-
asm("mov $60,%rax; mov $0,%rdi; syscall");
15-
__builtin_unreachable(); // tell the compiler to make sure side effects are done before the asm statement
8+
int main(int argc, const char *argv[]) {
9+
return func(0, argv);
1610
}

0 commit comments

Comments
 (0)