Skip to content

Commit 491bf0e

Browse files
committed
[lldb][test] Fix TestMultipleDebuggers test on non-x86, other small issues
This test has been flaky lately (llvm#101162) and I disabled it everywhere initially. I found that it always uses "x86_64" for the program architecture so the test was "passing" elsewhere but I don't think it was meant to. So I have added a define to pass on the host's architecture when compiling. This makes it work on AArch64 as well. While I'm here I've fixed the uint64_t formatting warnings by using the defined formats that'll work everywhere. In addition, I found that the function names include "()" on Linux, so now we check for "foo" or "foo()". The test cpp file has never been formatted so I've not done that either, just kept to the local style. I've removed the Linux skip to see if any of this helps the timeouts, and to verify the build command changes. If the timeouts come back I'll disable it again.
1 parent 533a229 commit 491bf0e

File tree

3 files changed

+38
-22
lines changed

3 files changed

+38
-22
lines changed

lldb/packages/Python/lldbsuite/test/lldbtest.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,45 +1514,51 @@ def getstdFlag(self):
15141514
stdflag = "-std=c++11"
15151515
return stdflag
15161516

1517-
def buildDriver(self, sources, exe_name):
1517+
def buildDriver(self, sources, exe_name, defines=None):
15181518
"""Platform-specific way to build a program that links with LLDB (via the liblldb.so
15191519
or LLDB.framework).
15201520
"""
1521+
if defines is None:
1522+
defines = []
1523+
15211524
stdflag = self.getstdFlag()
15221525
stdlibflag = self.getstdlibFlag()
1526+
defines = " ".join(["-D{}={}".format(name, value) for name, value in defines])
15231527

15241528
lib_dir = configuration.lldb_libs_dir
15251529
if self.hasDarwinFramework():
15261530
d = {
15271531
"CXX_SOURCES": sources,
15281532
"EXE": exe_name,
1529-
"CFLAGS_EXTRAS": "%s %s" % (stdflag, stdlibflag),
1533+
"CFLAGS_EXTRAS": "%s %s %s" % (stdflag, stdlibflag, defines),
15301534
"FRAMEWORK_INCLUDES": "-F%s" % self.framework_dir,
15311535
"LD_EXTRAS": "%s -Wl,-rpath,%s" % (self.lib_lldb, self.framework_dir),
15321536
}
15331537
elif sys.platform.startswith("win"):
15341538
d = {
15351539
"CXX_SOURCES": sources,
15361540
"EXE": exe_name,
1537-
"CFLAGS_EXTRAS": "%s %s -I%s -I%s"
1541+
"CFLAGS_EXTRAS": "%s %s -I%s -I%s %s"
15381542
% (
15391543
stdflag,
15401544
stdlibflag,
15411545
os.path.join(os.environ["LLDB_SRC"], "include"),
15421546
os.path.join(configuration.lldb_obj_root, "include"),
1547+
defines,
15431548
),
15441549
"LD_EXTRAS": "-L%s -lliblldb" % lib_dir,
15451550
}
15461551
else:
15471552
d = {
15481553
"CXX_SOURCES": sources,
15491554
"EXE": exe_name,
1550-
"CFLAGS_EXTRAS": "%s %s -I%s -I%s"
1555+
"CFLAGS_EXTRAS": "%s %s -I%s -I%s %s"
15511556
% (
15521557
stdflag,
15531558
stdlibflag,
15541559
os.path.join(os.environ["LLDB_SRC"], "include"),
15551560
os.path.join(configuration.lldb_obj_root, "include"),
1561+
defines,
15561562
),
15571563
"LD_EXTRAS": "-L%s -llldb -Wl,-rpath,%s" % (lib_dir, lib_dir),
15581564
}

lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@
1212
class TestMultipleSimultaneousDebuggers(TestBase):
1313
NO_DEBUG_INFO_TESTCASE = True
1414

15-
# This test has been flaky lately on Linux buildbots and Github/Buildkite CI
16-
# runs.
17-
@skipIfLinux
15+
# Sometimes times out on Linux, see https://github.com/llvm/llvm-project/issues/101162.
1816
@skipIfNoSBHeaders
1917
@skipIfWindows
2018
@skipIfHostIncompatibleWithTarget
2119
def test_multiple_debuggers(self):
2220
self.driver_exe = self.getBuildArtifact("multi-process-driver")
23-
self.buildDriver("multi-process-driver.cpp", self.driver_exe)
21+
self.buildDriver(
22+
"multi-process-driver.cpp",
23+
self.driver_exe,
24+
defines=[("LLDB_HOST_ARCH", lldbplatformutil.getArchitecture())],
25+
)
2426
self.addTearDownHook(lambda: os.remove(self.driver_exe))
2527

2628
self.inferior_exe = self.getBuildArtifact("testprog")

lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <stdio.h>
1717
#include <stdlib.h>
1818
#include <string.h>
19+
#include <inttypes.h>
1920

2021
#include "lldb/API/LLDB.h"
2122
#include "lldb/API/SBCommandInterpreter.h"
@@ -30,6 +31,9 @@
3031

3132
#define DEBUG 0
3233

34+
#define STR1(x) #x
35+
#define STR(x) STR1(x)
36+
3337
using namespace lldb;
3438

3539
bool *completed_threads_array = 0;
@@ -102,20 +106,21 @@ void *do_one_debugger (void *in)
102106
if (debugger.IsValid ())
103107
{
104108
debugger.SetAsync (true);
105-
SBTarget target = debugger.CreateTargetWithFileAndArch(inferior_process_name, "x86_64");
109+
SBTarget target = debugger.CreateTargetWithFileAndArch(inferior_process_name,
110+
STR(LLDB_HOST_ARCH));
106111
SBCommandInterpreter command_interp = debugger.GetCommandInterpreter();
107112
if (target.IsValid())
108113
{
109114
SBBreakpoint bar_br = target.BreakpointCreateByName ("bar", "testprog");
110115
if (!bar_br.IsValid())
111116
{
112-
printf ("#%lld: failed to set breakpoint on bar, exiting.\n", threadnum);
117+
printf ("#%" PRIu64 ": failed to set breakpoint on bar, exiting.\n", threadnum);
113118
exit (1);
114119
}
115120
SBBreakpoint foo_br = target.BreakpointCreateByName ("foo", "testprog");
116121
if (!foo_br.IsValid())
117122
{
118-
printf ("#%lld: Failed to set breakpoint on foo()\n", threadnum);
123+
printf ("#%" PRIu64 ": Failed to set breakpoint on foo()\n", threadnum);
119124
}
120125

121126
SBLaunchInfo launch_info (NULL);
@@ -136,15 +141,17 @@ void *do_one_debugger (void *in)
136141

137142
if (!walk_stack_to_main (process.GetThreadAtIndex(0)))
138143
{
139-
printf ("#%lld: backtrace while @ foo() failed\n", threadnum);
144+
printf ("#%" PRIu64 ": backtrace while @ foo() failed\n", threadnum);
140145
completed_threads_array[threadnum] = true;
141146
return (void *) 1;
142147
}
143148

144-
if (strcmp (process.GetThreadAtIndex(0).GetFrameAtIndex(0).GetFunctionName(), "foo") != 0)
149+
// On Linux the () are included.
150+
const char* hit_fn = process.GetThreadAtIndex(0).GetFrameAtIndex(0).GetFunctionName();
151+
if (strcmp (hit_fn, "foo") != 0 && strcmp (hit_fn, "foo()") != 0)
145152
{
146153
#if DEBUG == 1
147-
printf ("#%lld: First breakpoint did not stop at foo(), instead stopped at '%s'\n", threadnum, process.GetThreadAtIndex(0).GetFrameAtIndex(0).GetFunctionName());
154+
printf ("#%" PRIu64 ": First breakpoint did not stop at foo(), instead stopped at '%s'\n", threadnum, process.GetThreadAtIndex(0).GetFrameAtIndex(0).GetFunctionName());
148155
#endif
149156
completed_threads_array[threadnum] = true;
150157
return (void*) 1;
@@ -156,22 +163,23 @@ void *do_one_debugger (void *in)
156163

157164
if (process.GetState() == StateType::eStateExited)
158165
{
159-
printf ("#%lld: Process exited\n", threadnum);
166+
printf ("#%" PRIu64 ": Process exited\n", threadnum);
160167
completed_threads_array[threadnum] = true;
161168
return (void *) 1;
162169
}
163170

164171

165172
if (!walk_stack_to_main (process.GetThreadAtIndex(0)))
166173
{
167-
printf ("#%lld: backtrace while @ bar() failed\n", threadnum);
174+
printf ("#%" PRIu64 ": backtrace while @ bar() failed\n", threadnum);
168175
completed_threads_array[threadnum] = true;
169176
return (void *) 1;
170177
}
171178

172-
if (strcmp (process.GetThreadAtIndex(0).GetFrameAtIndex(0).GetFunctionName(), "bar") != 0)
179+
hit_fn = process.GetThreadAtIndex(0).GetFrameAtIndex(0).GetFunctionName();
180+
if (strcmp (hit_fn, "bar") != 0 && strcmp (hit_fn, "bar()") != 0)
173181
{
174-
printf ("#%lld: First breakpoint did not stop at bar()\n", threadnum);
182+
printf ("#%" PRIu64 ": First breakpoint did not stop at bar()\n", threadnum);
175183
completed_threads_array[threadnum] = true;
176184
return (void*) 1;
177185
}
@@ -183,31 +191,31 @@ void *do_one_debugger (void *in)
183191
SBDebugger::Destroy(debugger);
184192

185193
#if DEBUG == 1
186-
printf ("#%lld: All good!\n", threadnum);
194+
printf ("#%" PRIu64 ": All good!\n", threadnum);
187195
#endif
188196
successful_threads_array[threadnum] = true;
189197
completed_threads_array[threadnum] = true;
190198
return (void*) 0;
191199
}
192200
else
193201
{
194-
printf("#%lld: process failed to launch\n", threadnum);
202+
printf("#%" PRIu64 ": process failed to launch\n", threadnum);
195203
successful_threads_array[threadnum] = false;
196204
completed_threads_array[threadnum] = true;
197205
return (void*) 0;
198206
}
199207
}
200208
else
201209
{
202-
printf ("#%lld: did not get valid target\n", threadnum);
210+
printf ("#%" PRIu64 ": did not get valid target\n", threadnum);
203211
successful_threads_array[threadnum] = false;
204212
completed_threads_array[threadnum] = true;
205213
return (void*) 0;
206214
}
207215
}
208216
else
209217
{
210-
printf ("#%lld: did not get debugger\n", threadnum);
218+
printf ("#%" PRIu64 ": did not get debugger\n", threadnum);
211219
successful_threads_array[threadnum] = false;
212220
completed_threads_array[threadnum] = true;
213221
return (void*) 0;

0 commit comments

Comments
 (0)