[Lldb-commits] [lldb] [lldb] Fix AppleObjCDeclVendor for classes which have no methods (PR #145452)
Dave Lee via lldb-commits
lldb-commits at lists.llvm.org
Tue Jun 24 09:50:01 PDT 2025
https://github.com/kastiglione updated https://github.com/llvm/llvm-project/pull/145452
>From 57857bf2749a2801e9c4fb840a984a483ced6a44 Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Mon, 23 Jun 2025 20:36:38 -0700
Subject: [PATCH 1/3] [lldb] Fix AppleObjCDeclVendor for classes which have no
methods
Fix the rare case where an ObjC class has ivars but no methods. The fix is to not early
return when a class has no method list.
---
.../AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp | 7 +++----
.../test/API/lang/objc/class-without-methods/Makefile | 5 +++++
lldb/test/API/lang/objc/class-without-methods/Point.h | 8 ++++++++
lldb/test/API/lang/objc/class-without-methods/Point.m | 4 ++++
.../TestObjCClassWithoutMethods.py | 11 +++++++++++
lldb/test/API/lang/objc/class-without-methods/main.m | 9 +++++++++
6 files changed, 40 insertions(+), 4 deletions(-)
create mode 100644 lldb/test/API/lang/objc/class-without-methods/Makefile
create mode 100644 lldb/test/API/lang/objc/class-without-methods/Point.h
create mode 100644 lldb/test/API/lang/objc/class-without-methods/Point.m
create mode 100644 lldb/test/API/lang/objc/class-without-methods/TestObjCClassWithoutMethods.py
create mode 100644 lldb/test/API/lang/objc/class-without-methods/main.m
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp
index dac93931bab1b..1c120fcf2c356 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp
@@ -552,10 +552,9 @@ bool ClassDescriptorV2::Describe(
} else {
std::optional<method_list_t> base_method_list =
GetMethodList(process, class_ro->m_baseMethods_ptr);
- if (!base_method_list)
- return false;
- if (!ProcessMethodList(instance_method_func, *base_method_list))
- return false;
+ if (base_method_list)
+ if (!ProcessMethodList(instance_method_func, *base_method_list))
+ return false;
}
}
diff --git a/lldb/test/API/lang/objc/class-without-methods/Makefile b/lldb/test/API/lang/objc/class-without-methods/Makefile
new file mode 100644
index 0000000000000..f6f336c01bbc5
--- /dev/null
+++ b/lldb/test/API/lang/objc/class-without-methods/Makefile
@@ -0,0 +1,5 @@
+OBJC_SOURCES := Point.m main.m
+include Makefile.rules
+
+# Only objc metadata, no debug info, for Point.m
+Point.o: CFLAGS_EXTRAS += -g0
diff --git a/lldb/test/API/lang/objc/class-without-methods/Point.h b/lldb/test/API/lang/objc/class-without-methods/Point.h
new file mode 100644
index 0000000000000..85c0cd6c895b3
--- /dev/null
+++ b/lldb/test/API/lang/objc/class-without-methods/Point.h
@@ -0,0 +1,8 @@
+#import <objc/NSObject.h>
+
+ at interface Point : NSObject {
+ at public
+ float _x;
+ float _y;
+}
+ at end
diff --git a/lldb/test/API/lang/objc/class-without-methods/Point.m b/lldb/test/API/lang/objc/class-without-methods/Point.m
new file mode 100644
index 0000000000000..eb5888e5b599f
--- /dev/null
+++ b/lldb/test/API/lang/objc/class-without-methods/Point.m
@@ -0,0 +1,4 @@
+#import "Point.h"
+
+ at implementation Point
+ at end
diff --git a/lldb/test/API/lang/objc/class-without-methods/TestObjCClassWithoutMethods.py b/lldb/test/API/lang/objc/class-without-methods/TestObjCClassWithoutMethods.py
new file mode 100644
index 0000000000000..587f22dedadf7
--- /dev/null
+++ b/lldb/test/API/lang/objc/class-without-methods/TestObjCClassWithoutMethods.py
@@ -0,0 +1,11 @@
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class TestCase(TestBase):
+ def test(self):
+ self.build()
+ lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.m"))
+ self.expect("frame var -P1 p", substrs=["_x = 11", "_y = 22"])
diff --git a/lldb/test/API/lang/objc/class-without-methods/main.m b/lldb/test/API/lang/objc/class-without-methods/main.m
new file mode 100644
index 0000000000000..f3241f46bbe5f
--- /dev/null
+++ b/lldb/test/API/lang/objc/class-without-methods/main.m
@@ -0,0 +1,9 @@
+#import "Point.h"
+
+int main() {
+ Point *p = [Point new];
+ p->_x = 11;
+ p->_y = 22;
+ // break here
+ return 0;
+}
>From 039749958a76c2ab687863eee07468ca858c6f74 Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Tue, 24 Jun 2025 08:46:33 -0700
Subject: [PATCH 2/3] Flatten nested if
---
.../ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp
index 1c120fcf2c356..cc0c9e728964e 100644
--- a/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp
+++ b/lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCClassDescriptorV2.cpp
@@ -552,9 +552,9 @@ bool ClassDescriptorV2::Describe(
} else {
std::optional<method_list_t> base_method_list =
GetMethodList(process, class_ro->m_baseMethods_ptr);
- if (base_method_list)
- if (!ProcessMethodList(instance_method_func, *base_method_list))
- return false;
+ if (base_method_list &&
+ !ProcessMethodList(instance_method_func, *base_method_list))
+ return false;
}
}
>From 77eb488e14cae14cd2ac58e26f7e2d12bbe8c5f4 Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Tue, 24 Jun 2025 09:49:04 -0700
Subject: [PATCH 3/3] Move ivar declaration out of header
This ensures the debug info in main.o does not contain the ivars for Point.
---
lldb/test/API/lang/objc/class-without-methods/Point.h | 6 +-----
lldb/test/API/lang/objc/class-without-methods/Point.m | 5 ++++-
.../class-without-methods/TestObjCClassWithoutMethods.py | 2 +-
lldb/test/API/lang/objc/class-without-methods/main.m | 2 --
4 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/lldb/test/API/lang/objc/class-without-methods/Point.h b/lldb/test/API/lang/objc/class-without-methods/Point.h
index 85c0cd6c895b3..a352259954eff 100644
--- a/lldb/test/API/lang/objc/class-without-methods/Point.h
+++ b/lldb/test/API/lang/objc/class-without-methods/Point.h
@@ -1,8 +1,4 @@
#import <objc/NSObject.h>
- at interface Point : NSObject {
- at public
- float _x;
- float _y;
-}
+ at interface Point : NSObject
@end
diff --git a/lldb/test/API/lang/objc/class-without-methods/Point.m b/lldb/test/API/lang/objc/class-without-methods/Point.m
index eb5888e5b599f..770a857c80dc7 100644
--- a/lldb/test/API/lang/objc/class-without-methods/Point.m
+++ b/lldb/test/API/lang/objc/class-without-methods/Point.m
@@ -1,4 +1,7 @@
#import "Point.h"
- at implementation Point
+ at implementation Point {
+ float _x;
+ float _y;
+}
@end
diff --git a/lldb/test/API/lang/objc/class-without-methods/TestObjCClassWithoutMethods.py b/lldb/test/API/lang/objc/class-without-methods/TestObjCClassWithoutMethods.py
index 587f22dedadf7..f83b0352bf1a9 100644
--- a/lldb/test/API/lang/objc/class-without-methods/TestObjCClassWithoutMethods.py
+++ b/lldb/test/API/lang/objc/class-without-methods/TestObjCClassWithoutMethods.py
@@ -8,4 +8,4 @@ class TestCase(TestBase):
def test(self):
self.build()
lldbutil.run_to_source_breakpoint(self, "break here", lldb.SBFileSpec("main.m"))
- self.expect("frame var -P1 p", substrs=["_x = 11", "_y = 22"])
+ self.expect("frame var -P1 p", substrs=["_x = 0", "_y = 0"])
diff --git a/lldb/test/API/lang/objc/class-without-methods/main.m b/lldb/test/API/lang/objc/class-without-methods/main.m
index f3241f46bbe5f..0b6e14371bc59 100644
--- a/lldb/test/API/lang/objc/class-without-methods/main.m
+++ b/lldb/test/API/lang/objc/class-without-methods/main.m
@@ -2,8 +2,6 @@
int main() {
Point *p = [Point new];
- p->_x = 11;
- p->_y = 22;
// break here
return 0;
}
More information about the lldb-commits
mailing list