Skip to content

Commit 60671ec

Browse files
committed
Added own so modules.
1 parent 0518bff commit 60671ec

File tree

7 files changed

+102
-17
lines changed

7 files changed

+102
-17
lines changed
Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1-
CXX_SOURCES := main.cpp
2-
3-
include Makefile.rules
1+
CXX_SOURCES := main.cpp
2+
LD_EXTRAS := -L. -lloadunload_d -lloadunload_c -lloadunload_a -lloadunload_b
3+
4+
a.out: lib_b lib_a lib_c lib_d
5+
6+
include Makefile.rules
7+
8+
lib_a: lib_b
9+
$(MAKE) -f $(MAKEFILE_RULES) \
10+
DYLIB_ONLY=YES DYLIB_CXX_SOURCES=a.cpp DYLIB_NAME=loadunload_a \
11+
LD_EXTRAS="-L. -lloadunload_b"
12+
13+
lib_b:
14+
$(MAKE) -f $(MAKEFILE_RULES) \
15+
DYLIB_ONLY=YES DYLIB_CXX_SOURCES=b.cpp DYLIB_NAME=loadunload_b
16+
17+
lib_c:
18+
$(MAKE) -f $(MAKEFILE_RULES) \
19+
DYLIB_ONLY=YES DYLIB_CXX_SOURCES=c.cpp DYLIB_NAME=loadunload_c
20+
21+
lib_d:
22+
$(MAKE) -f $(MAKEFILE_RULES) \
23+
DYLIB_ONLY=YES DYLIB_CXX_SOURCES=d.cpp DYLIB_NAME=loadunload_d

lldb/test/API/functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,51 @@
99
from lldbsuite.test import lldbutil
1010

1111

12+
@skipUnlessPlatform(["linux"] + lldbplatformutil.getDarwinOSTriples())
1213
class ModuleLoadedNotifysTestCase(TestBase):
1314
NO_DEBUG_INFO_TESTCASE = True
1415

1516
# At least DynamicLoaderDarwin and DynamicLoaderPOSIXDYLD should batch up
1617
# notifications about newly added/removed libraries. Other DynamicLoaders may
1718
# not be written this way.
18-
@skipUnlessPlatform(["linux"] + lldbplatformutil.getDarwinOSTriples())
1919
def setUp(self):
2020
# Call super's setUp().
2121
TestBase.setUp(self)
2222
# Find the line number to break inside main().
2323
self.line = line_number("main.cpp", "// breakpoint")
2424

25+
def setup_test(self, solibs):
26+
if lldb.remote_platform:
27+
path = lldb.remote_platform.GetWorkingDirectory()
28+
for f in solibs:
29+
lldbutil.install_to_target(self, self.getBuildArtifact(f))
30+
else:
31+
path = self.getBuildDir()
32+
if self.dylibPath in os.environ:
33+
sep = self.platformContext.shlib_path_separator
34+
path = os.environ[self.dylibPath] + sep + path
35+
self.runCmd(
36+
"settings append target.env-vars '{}={}'".format(self.dylibPath, path)
37+
)
38+
self.default_path = path
39+
2540
def test_launch_notifications(self):
2641
"""Test that lldb broadcasts newly loaded libraries in batches."""
42+
43+
ext = "so"
44+
if self.platformIsDarwin():
45+
ext = "dylib"
46+
47+
expected_solibs = [
48+
"libloadunload_a." + ext,
49+
"libloadunload_b." + ext,
50+
"libloadunload_c." + ext,
51+
"libloadunload_d." + ext,
52+
]
53+
2754
self.build()
55+
self.setup_test(expected_solibs)
56+
2857
exe = self.getBuildArtifact("a.out")
2958
self.dbg.SetAsync(False)
3059

@@ -70,6 +99,8 @@ def test_launch_notifications(self):
7099
total_modules_added_events = 0
71100
total_modules_removed_events = 0
72101
already_loaded_modules = []
102+
max_solibs_per_event = 0
103+
max_solib_chunk_per_event = []
73104
while listener.GetNextEvent(event):
74105
if lldb.SBTarget.EventIsTargetEvent(event):
75106
if event.GetType() == lldb.SBTarget.eBroadcastBitModulesLoaded:
@@ -91,12 +122,17 @@ def test_launch_notifications(self):
91122
"{} is already loaded".format(module),
92123
)
93124
already_loaded_modules.append(module)
94-
if self.TraceOn():
95-
added_files.append(module.GetFileSpec().GetFilename())
125+
added_files.append(module.GetFileSpec().GetFilename())
96126
if self.TraceOn():
97127
# print all of the binaries that have been added
98128
print("Loaded files: %s" % (", ".join(added_files)))
99129

130+
# We will check the latest biggest chunk of loaded solibs.
131+
# We expect all of our solibs in the last chunk of loaded modules.
132+
if solib_count >= max_solibs_per_event:
133+
max_solib_chunk_per_event = added_files.copy()
134+
max_solibs_per_event = solib_count
135+
100136
if event.GetType() == lldb.SBTarget.eBroadcastBitModulesUnloaded:
101137
solib_count = lldb.SBTarget.GetNumModulesFromEvent(event)
102138
total_modules_removed_events += 1
@@ -115,9 +151,10 @@ def test_launch_notifications(self):
115151
# binaries in batches. Check that we got back more than 1 solib per event.
116152
# In practice on Darwin today, we get back two events for a do-nothing c
117153
# program: a.out and dyld, and then all the rest of the system libraries.
118-
# On Linux we get events for ld.so, [vdso], the binary and then all libraries.
119-
120-
avg_solibs_added_per_event = float(total_solibs_added) / float(
121-
total_modules_added_events
154+
# On Linux we get events for ld.so, [vdso], the binary and then all libraries,
155+
# but the different configurations could load a different number of .so modules
156+
# per event.
157+
self.assertGreaterEqual(
158+
len(set(max_solib_chunk_per_event).intersection(expected_solibs)),
159+
len(expected_solibs),
122160
)
123-
self.assertGreater(round(10.0 * avg_solibs_added_per_event), 10)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extern "C" int b_function();
2+
3+
int a_init() { return 234; }
4+
5+
int a_global = a_init();
6+
7+
extern "C" int a_function() { return b_function(); }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
int b_init() { return 345; }
2+
3+
int b_global = b_init();
4+
5+
extern "C" int b_function() { return 500; }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extern "C" int c_function() { return 600; }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
int d_init() { return 123; }
2+
3+
int d_global = d_init();
4+
5+
extern "C" int d_function() { return 700; }
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
#include <stdio.h>
2-
int main ()
3-
{
4-
puts("running"); // breakpoint here
5-
return 0;
6-
}
1+
#include <stdio.h>
2+
3+
extern "C" int a_function();
4+
extern "C" int c_function();
5+
extern "C" int b_function();
6+
extern "C" int d_function();
7+
8+
int main() {
9+
a_function();
10+
b_function();
11+
c_function();
12+
d_function();
13+
14+
puts("running"); // breakpoint here
15+
return 0;
16+
}

0 commit comments

Comments
 (0)