Skip to content

[lldb][test] Fix TestMultipleDebuggers test on non-x86, other small issues #101169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lldb/packages/Python/lldbsuite/test/lldbtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1514,45 +1514,51 @@ def getstdFlag(self):
stdflag = "-std=c++11"
return stdflag

def buildDriver(self, sources, exe_name):
def buildDriver(self, sources, exe_name, defines=None):
"""Platform-specific way to build a program that links with LLDB (via the liblldb.so
or LLDB.framework).
"""
if defines is None:
defines = []

stdflag = self.getstdFlag()
stdlibflag = self.getstdlibFlag()
defines = " ".join(["-D{}={}".format(name, value) for name, value in defines])

lib_dir = configuration.lldb_libs_dir
if self.hasDarwinFramework():
d = {
"CXX_SOURCES": sources,
"EXE": exe_name,
"CFLAGS_EXTRAS": "%s %s" % (stdflag, stdlibflag),
"CFLAGS_EXTRAS": "%s %s %s" % (stdflag, stdlibflag, defines),
"FRAMEWORK_INCLUDES": "-F%s" % self.framework_dir,
"LD_EXTRAS": "%s -Wl,-rpath,%s" % (self.lib_lldb, self.framework_dir),
}
elif sys.platform.startswith("win"):
d = {
"CXX_SOURCES": sources,
"EXE": exe_name,
"CFLAGS_EXTRAS": "%s %s -I%s -I%s"
"CFLAGS_EXTRAS": "%s %s -I%s -I%s %s"
% (
stdflag,
stdlibflag,
os.path.join(os.environ["LLDB_SRC"], "include"),
os.path.join(configuration.lldb_obj_root, "include"),
defines,
),
"LD_EXTRAS": "-L%s -lliblldb" % lib_dir,
}
else:
d = {
"CXX_SOURCES": sources,
"EXE": exe_name,
"CFLAGS_EXTRAS": "%s %s -I%s -I%s"
"CFLAGS_EXTRAS": "%s %s -I%s -I%s %s"
% (
stdflag,
stdlibflag,
os.path.join(os.environ["LLDB_SRC"], "include"),
os.path.join(configuration.lldb_obj_root, "include"),
defines,
),
"LD_EXTRAS": "-L%s -llldb -Wl,-rpath,%s" % (lib_dir, lib_dir),
}
Expand Down
10 changes: 6 additions & 4 deletions lldb/test/API/api/multiple-debuggers/TestMultipleDebuggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
class TestMultipleSimultaneousDebuggers(TestBase):
NO_DEBUG_INFO_TESTCASE = True

# This test has been flaky lately on Linux buildbots and Github/Buildkite CI
# runs.
@skipIfLinux
# Sometimes times out on Linux, see https://github.com/llvm/llvm-project/issues/101162.
@skipIfNoSBHeaders
@skipIfWindows
@skipIfHostIncompatibleWithTarget
def test_multiple_debuggers(self):
self.driver_exe = self.getBuildArtifact("multi-process-driver")
self.buildDriver("multi-process-driver.cpp", self.driver_exe)
self.buildDriver(
"multi-process-driver.cpp",
self.driver_exe,
defines=[("LLDB_HOST_ARCH", lldbplatformutil.getArchitecture())],
)
self.addTearDownHook(lambda: os.remove(self.driver_exe))

self.inferior_exe = self.getBuildArtifact("testprog")
Expand Down
36 changes: 22 additions & 14 deletions lldb/test/API/api/multiple-debuggers/multi-process-driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>

#include "lldb/API/LLDB.h"
#include "lldb/API/SBCommandInterpreter.h"
Expand All @@ -30,6 +31,9 @@

#define DEBUG 0

#define STR1(x) #x
#define STR(x) STR1(x)

using namespace lldb;

bool *completed_threads_array = 0;
Expand Down Expand Up @@ -102,20 +106,21 @@ void *do_one_debugger (void *in)
if (debugger.IsValid ())
{
debugger.SetAsync (true);
SBTarget target = debugger.CreateTargetWithFileAndArch(inferior_process_name, "x86_64");
SBTarget target = debugger.CreateTargetWithFileAndArch(inferior_process_name,
STR(LLDB_HOST_ARCH));
SBCommandInterpreter command_interp = debugger.GetCommandInterpreter();
if (target.IsValid())
{
SBBreakpoint bar_br = target.BreakpointCreateByName ("bar", "testprog");
if (!bar_br.IsValid())
{
printf ("#%lld: failed to set breakpoint on bar, exiting.\n", threadnum);
printf ("#%" PRIu64 ": failed to set breakpoint on bar, exiting.\n", threadnum);
exit (1);
}
SBBreakpoint foo_br = target.BreakpointCreateByName ("foo", "testprog");
if (!foo_br.IsValid())
{
printf ("#%lld: Failed to set breakpoint on foo()\n", threadnum);
printf ("#%" PRIu64 ": Failed to set breakpoint on foo()\n", threadnum);
}

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

if (!walk_stack_to_main (process.GetThreadAtIndex(0)))
{
printf ("#%lld: backtrace while @ foo() failed\n", threadnum);
printf ("#%" PRIu64 ": backtrace while @ foo() failed\n", threadnum);
completed_threads_array[threadnum] = true;
return (void *) 1;
}

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

if (process.GetState() == StateType::eStateExited)
{
printf ("#%lld: Process exited\n", threadnum);
printf ("#%" PRIu64 ": Process exited\n", threadnum);
completed_threads_array[threadnum] = true;
return (void *) 1;
}


if (!walk_stack_to_main (process.GetThreadAtIndex(0)))
{
printf ("#%lld: backtrace while @ bar() failed\n", threadnum);
printf ("#%" PRIu64 ": backtrace while @ bar() failed\n", threadnum);
completed_threads_array[threadnum] = true;
return (void *) 1;
}

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

#if DEBUG == 1
printf ("#%lld: All good!\n", threadnum);
printf ("#%" PRIu64 ": All good!\n", threadnum);
#endif
successful_threads_array[threadnum] = true;
completed_threads_array[threadnum] = true;
return (void*) 0;
}
else
{
printf("#%lld: process failed to launch\n", threadnum);
printf("#%" PRIu64 ": process failed to launch\n", threadnum);
successful_threads_array[threadnum] = false;
completed_threads_array[threadnum] = true;
return (void*) 0;
}
}
else
{
printf ("#%lld: did not get valid target\n", threadnum);
printf ("#%" PRIu64 ": did not get valid target\n", threadnum);
successful_threads_array[threadnum] = false;
completed_threads_array[threadnum] = true;
return (void*) 0;
}
}
else
{
printf ("#%lld: did not get debugger\n", threadnum);
printf ("#%" PRIu64 ": did not get debugger\n", threadnum);
successful_threads_array[threadnum] = false;
completed_threads_array[threadnum] = true;
return (void*) 0;
Expand Down
Loading