[Lldb-commits] [lldb] [lldb] Fixing the python_api/block tests. (PR #184647)
John Harrison via lldb-commits
lldb-commits at lists.llvm.org
Wed Mar 4 13:56:41 PST 2026
https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/184647
>From 7620acc49f61ecdeb8248315e2469a5a57474182 Mon Sep 17 00:00:00 2001
From: John Harrison <harjohn at google.com>
Date: Wed, 4 Mar 2026 09:19:03 -0800
Subject: [PATCH 1/3] [lldb] Fixing the python_api/block tests.
Renaming the file to be unique and updating the symbols for Windows.
---
.../block/{TestBlocks.py => TestFrameBlocks.py} | 2 +-
lldb/test/API/python_api/block/fn.c | 8 +++++++-
lldb/test/API/python_api/block/main.c | 4 ++++
3 files changed, 12 insertions(+), 2 deletions(-)
rename lldb/test/API/python_api/block/{TestBlocks.py => TestFrameBlocks.py} (98%)
diff --git a/lldb/test/API/python_api/block/TestBlocks.py b/lldb/test/API/python_api/block/TestFrameBlocks.py
similarity index 98%
rename from lldb/test/API/python_api/block/TestBlocks.py
rename to lldb/test/API/python_api/block/TestFrameBlocks.py
index d5e7a5eeef49e..923cc4a79462a 100644
--- a/lldb/test/API/python_api/block/TestBlocks.py
+++ b/lldb/test/API/python_api/block/TestFrameBlocks.py
@@ -8,7 +8,7 @@
from lldbsuite.test import lldbutil
-class BlockAPITestCase(TestBase):
+class FrameBlocksTestCase(TestBase):
def test_block_equality(self):
"""Exercise SBBlock equality checks across frames and functions in different dylibs."""
self.build()
diff --git a/lldb/test/API/python_api/block/fn.c b/lldb/test/API/python_api/block/fn.c
index 80ea7e5baa11e..84716517bea29 100644
--- a/lldb/test/API/python_api/block/fn.c
+++ b/lldb/test/API/python_api/block/fn.c
@@ -1,4 +1,10 @@
-extern int fn(int a, int b) {
+#ifdef _WIN32
+#define EXPORT __declspec(dllexport)
+#else
+#define EXPORT extern
+#endif
+
+EXPORT int fn(int a, int b) {
if (a < b) {
int sum = a + b;
return sum; // breakpoint 2
diff --git a/lldb/test/API/python_api/block/main.c b/lldb/test/API/python_api/block/main.c
index 8200ecf5bdf4f..7e862f0e1a3c1 100644
--- a/lldb/test/API/python_api/block/main.c
+++ b/lldb/test/API/python_api/block/main.c
@@ -1,6 +1,10 @@
#include <stdio.h>
+#ifdef _WIN32
+__declspec(dllimport) int fn(int a, int b);
+#else
extern int fn(int a, int b);
+#endif
int main(int argc, char const *argv[]) {
int a = 3;
>From d6d438d4b7c8d905ddaae909d99cbc5dec8df14c Mon Sep 17 00:00:00 2001
From: John Harrison <harjohn at google.com>
Date: Wed, 4 Mar 2026 10:06:52 -0800
Subject: [PATCH 2/3] [lldb] Consolidating platform support checks in tests.
Moving the platform support check into `lldb/unittests/TestingSupport/TestUtilities.h` so it can be reused across tests.
Also skipping 'VariablesTest' cases that load a core dump if the platform is not supported.
---
lldb/unittests/DAP/Handler/DisconnectTest.cpp | 4 ----
lldb/unittests/DAP/TestBase.cpp | 17 +----------------
lldb/unittests/DAP/TestBase.h | 1 -
lldb/unittests/DAP/VariablesTest.cpp | 5 ++++-
.../TestingSupport/TestUtilities.cpp | 19 ++++++++++++++++++-
lldb/unittests/TestingSupport/TestUtilities.h | 12 ++++++++++++
6 files changed, 35 insertions(+), 23 deletions(-)
diff --git a/lldb/unittests/DAP/Handler/DisconnectTest.cpp b/lldb/unittests/DAP/Handler/DisconnectTest.cpp
index 212c5698feea8..1c19d35bd746d 100644
--- a/lldb/unittests/DAP/Handler/DisconnectTest.cpp
+++ b/lldb/unittests/DAP/Handler/DisconnectTest.cpp
@@ -38,10 +38,6 @@ TEST_F(DisconnectRequestHandlerTest, DisconnectTriggersTerminated) {
#ifndef __linux__
TEST_F(DisconnectRequestHandlerTest, DisconnectTriggersTerminateCommands) {
CreateDebugger();
-
- if (!GetDebuggerSupportsTarget("X86"))
- GTEST_SKIP() << "Unsupported platform";
-
LoadCore();
DisconnectRequestHandler handler(*dap);
diff --git a/lldb/unittests/DAP/TestBase.cpp b/lldb/unittests/DAP/TestBase.cpp
index 6073aa82a8eb7..cee90caf9ff7b 100644
--- a/lldb/unittests/DAP/TestBase.cpp
+++ b/lldb/unittests/DAP/TestBase.cpp
@@ -72,25 +72,10 @@ void DAPTestBase::SetUpTestSuite() {
}
void DAPTestBase::TearDownTestSuite() { SBDebugger::Terminate(); }
-bool DAPTestBase::GetDebuggerSupportsTarget(StringRef platform) {
- EXPECT_TRUE(dap->debugger);
-
- lldb::SBStructuredData data = dap->debugger.GetBuildConfiguration()
- .GetValueForKey("targets")
- .GetValueForKey("value");
- for (size_t i = 0; i < data.GetSize(); i++) {
- char buf[100] = {0};
- size_t size = data.GetItemAtIndex(i).GetStringValue(buf, sizeof(buf));
- if (StringRef(buf, size) == platform)
- return true;
- }
-
- return false;
-}
-
void DAPTestBase::CreateDebugger() {
dap->debugger = lldb::SBDebugger::Create();
ASSERT_TRUE(dap->debugger);
+ SKIP_UNLESS_PLATFORM_SUPPORTED(dap->debugger, "X86");
dap->target = dap->debugger.GetDummyTarget();
Expected<lldb::FileUP> dev_null = FileSystem::Instance().Open(
diff --git a/lldb/unittests/DAP/TestBase.h b/lldb/unittests/DAP/TestBase.h
index 7953e0fabfbe5..2a0febf298d63 100644
--- a/lldb/unittests/DAP/TestBase.h
+++ b/lldb/unittests/DAP/TestBase.h
@@ -112,7 +112,6 @@ class DAPTestBase : public TransportBase {
void SetUp() override;
void TearDown() override;
- bool GetDebuggerSupportsTarget(llvm::StringRef platform);
void CreateDebugger();
void LoadCore();
};
diff --git a/lldb/unittests/DAP/VariablesTest.cpp b/lldb/unittests/DAP/VariablesTest.cpp
index fe85e92a7fee2..8f590253f3b7c 100644
--- a/lldb/unittests/DAP/VariablesTest.cpp
+++ b/lldb/unittests/DAP/VariablesTest.cpp
@@ -59,7 +59,10 @@ class VariablesTest : public ::testing::Test {
std::optional<llvm::sys::fs::TempFile> core;
std::optional<llvm::sys::fs::TempFile> binary;
- void CreateDebugger() { debugger = lldb::SBDebugger::Create(); }
+ void CreateDebugger() {
+ debugger = lldb::SBDebugger::Create();
+ SKIP_UNLESS_PLATFORM_SUPPORTED(debugger, "X86");
+ }
void LoadCore() {
ASSERT_TRUE(debugger);
diff --git a/lldb/unittests/TestingSupport/TestUtilities.cpp b/lldb/unittests/TestingSupport/TestUtilities.cpp
index d164c227afb9e..8b65087065992 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.cpp
+++ b/lldb/unittests/TestingSupport/TestUtilities.cpp
@@ -7,11 +7,11 @@
//===----------------------------------------------------------------------===//
#include "TestUtilities.h"
+#include "lldb/API/SBStructuredData.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ObjectYAML/yaml2obj.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
-#include "llvm/Support/Program.h"
#include "llvm/Support/YAMLTraits.h"
#include "gtest/gtest.h"
@@ -61,3 +61,20 @@ llvm::Expected<llvm::sys::fs::TempFile> TestFile::writeToTemporaryFile() {
llvm::raw_fd_ostream(Temp->FD, /*shouldClose=*/false) << Buffer;
return std::move(*Temp);
}
+
+bool lldb_private::DebuggerSupportsPlatform(lldb::SBDebugger &debugger,
+ llvm::StringRef platform) {
+ EXPECT_TRUE(debugger);
+
+ lldb::SBStructuredData data =
+ debugger.GetBuildConfiguration().GetValueForKey("targets").GetValueForKey(
+ "value");
+ for (size_t i = 0; i < data.GetSize(); i++) {
+ char buf[100] = {0};
+ size_t size = data.GetItemAtIndex(i).GetStringValue(buf, sizeof(buf));
+ if (llvm::StringRef(buf, size) == platform)
+ return true;
+ }
+
+ return false;
+}
diff --git a/lldb/unittests/TestingSupport/TestUtilities.h b/lldb/unittests/TestingSupport/TestUtilities.h
index 68b4dbc127a7d..e27577472f5b6 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.h
+++ b/lldb/unittests/TestingSupport/TestUtilities.h
@@ -9,6 +9,7 @@
#ifndef LLDB_UNITTESTS_TESTINGSUPPORT_TESTUTILITIES_H
#define LLDB_UNITTESTS_TESTINGSUPPORT_TESTUTILITIES_H
+#include "lldb/API/SBDebugger.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Utility/DataBuffer.h"
#include "llvm/ADT/Twine.h"
@@ -16,6 +17,7 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/JSON.h"
#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
#include <string>
#define ASSERT_NO_ERROR(x) \
@@ -65,12 +67,22 @@ class TestFile {
std::string Buffer;
};
+/// Check if the debugger supports the given platform.
+bool DebuggerSupportsPlatform(lldb::SBDebugger &debugger,
+ llvm::StringRef platform);
+
+#define SKIP_UNLESS_PLATFORM_SUPPORTED(debugger, platform) \
+ if (!::lldb_private::DebuggerSupportsPlatform(debugger, platform)) { \
+ GTEST_SKIP() << "Unsupported platform"; \
+ }
+
template <typename T> static llvm::Expected<T> roundtripJSON(const T &input) {
std::string encoded;
llvm::raw_string_ostream OS(encoded);
OS << toJSON(input);
return llvm::json::parse<T>(encoded);
}
+
} // namespace lldb_private
#endif
>From 0e6b71d1100f91040b1e00c9f09728b832b6881b Mon Sep 17 00:00:00 2001
From: John Harrison <harjohn at google.com>
Date: Wed, 4 Mar 2026 13:56:22 -0800
Subject: [PATCH 3/3] Using `LLDB_DYLIB_EXPORT` and `LLDB_DYLIB_IMPORT` instead
of a custom define.
---
lldb/test/API/python_api/block/fn.c | 8 +-------
lldb/test/API/python_api/block/main.c | 6 +-----
2 files changed, 2 insertions(+), 12 deletions(-)
diff --git a/lldb/test/API/python_api/block/fn.c b/lldb/test/API/python_api/block/fn.c
index 84716517bea29..9534f8c2083ff 100644
--- a/lldb/test/API/python_api/block/fn.c
+++ b/lldb/test/API/python_api/block/fn.c
@@ -1,10 +1,4 @@
-#ifdef _WIN32
-#define EXPORT __declspec(dllexport)
-#else
-#define EXPORT extern
-#endif
-
-EXPORT int fn(int a, int b) {
+extern int LLDB_DYLIB_EXPORT fn(int a, int b) {
if (a < b) {
int sum = a + b;
return sum; // breakpoint 2
diff --git a/lldb/test/API/python_api/block/main.c b/lldb/test/API/python_api/block/main.c
index 7e862f0e1a3c1..7ce04f0b1ebe4 100644
--- a/lldb/test/API/python_api/block/main.c
+++ b/lldb/test/API/python_api/block/main.c
@@ -1,10 +1,6 @@
#include <stdio.h>
-#ifdef _WIN32
-__declspec(dllimport) int fn(int a, int b);
-#else
-extern int fn(int a, int b);
-#endif
+extern LLDB_DYLIB_IMPORT int fn(int a, int b);
int main(int argc, char const *argv[]) {
int a = 3;
More information about the lldb-commits
mailing list