[Lldb-commits] [lldb] [lldb][test] Add test-coverage for DW_AT_APPLE_objc_complete_type parsing (PR #120279)
Michael Buch via lldb-commits
lldb-commits at lists.llvm.org
Tue Dec 17 10:12:24 PST 2024
https://github.com/Michael137 created https://github.com/llvm/llvm-project/pull/120279
When given a DIE for an Objective-C interface (which doesn't have a `DW_AT_APPLE_objc_complete_type`), the `DWARFASTParserClang` will try to find the DIE which corresponds to the implementation to complete the interface DIE. The code is here:
https://github.com/llvm/llvm-project/blob/d2e7ee77d33e8b3be3b1d4e9bc5bc4c60b62b554/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp#L1718-L1738
However, this was currently not exercised in our test-suite (removing the code above didn't fail any LLDB test).
This patch adds a test which exercises this codepath (it will fail if we don't fetch the implementation DIE in the `DWARFASTParserClang`).
Something that's not currently clear to me is why `frame var *f` succeeds even without the `DW_AT_APPLE_objc_complete_type` infrastructure. If it's using the ObjC runtime, which should make `expr` do the same, in which case we can remove this code from `DWARFASTParserClang`.
>From 91c07eee2956e56880d5e565658cf2800af6f1b2 Mon Sep 17 00:00:00 2001
From: Michael Buch <michaelbuch12 at gmail.com>
Date: Tue, 17 Dec 2024 18:04:11 +0000
Subject: [PATCH] [lldb][test] Add test-coverage for
DW_AT_APPLE_objc_complete_type parsing
When given a DIE for an Objective-C interface (which doesn't have
a `DW_AT_APPLE_objc_complete_type`), the `DWARFASTParserClang` will
try to find the DIE which corresponds to the implementation to complete
the interface DIE. The code is here:
https://github.com/llvm/llvm-project/blob/d2e7ee77d33e8b3be3b1d4e9bc5bc4c60b62b554/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp#L1718-L1738
However, this was currently not exercised in our test-suite (removing
the code above didn't fail any LLDB test).
This patch adds a test which exercises this codepath (it will fail
if we don't fetch the implementation DIE in the `DWARFASTParserClang`).
Something that's not currently clear to me is why `frame var *f`
succeeds even without the `DW_AT_APPLE_objc_complete_type`
infrastructure. If it's using the ObjC runtime, which should make
`expr` do the same, in which case we can remove this code from
`DWARFASTParserClang`.
---
lldb/test/Shell/Expr/TestObjCHiddenIvars.test | 63 +++++++++++++++++++
1 file changed, 63 insertions(+)
create mode 100644 lldb/test/Shell/Expr/TestObjCHiddenIvars.test
diff --git a/lldb/test/Shell/Expr/TestObjCHiddenIvars.test b/lldb/test/Shell/Expr/TestObjCHiddenIvars.test
new file mode 100644
index 00000000000000..724a17fb7e2b8c
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestObjCHiddenIvars.test
@@ -0,0 +1,63 @@
+# Tests that LLDB correctly finds the implementation
+# DIE (with a `DW_AT_APPLE_objc_complete_type`)
+# given an interface DIE (without said attribute).
+#
+# RUN: split-file %s %t
+# RUN: %clangxx_host %t/lib.m -c -g -o %t/lib.o
+# RUN: %clangxx_host %t/main.m -c -g -o %t/main.o
+# RUN: %clangxx_host %t/main.o %t/lib.o -o %t/a.out -framework Foundation
+#
+# RUN: %lldb %t/a.out \
+# RUN: -o "breakpoint set -p 'return' -X main" \
+# RUN: -o run \
+# RUN: -o "expression *f" \
+# RUN: -o exit | FileCheck %s
+
+# CHECK: (lldb) expression *f
+# CHECK: (Foo) ${{[0-9]+}} = {
+# CHECK: y = 2
+# CHECK-NEXT: i = 1
+
+#--- main.m
+#import <Foundation/Foundation.h>
+#import "lib.h"
+
+extern Foo * func();
+
+int main() {
+ Foo * f = func();
+ return 0;
+}
+
+#--- lib.m
+#import <Foundation/Foundation.h>
+#import "lib.h"
+
+ at implementation Foo {
+int i;
+}
+
+- (id)init {
+ self->i = 1;
+ self->y = 2;
+
+ return self;
+}
+ at end
+
+Foo * func() {
+ return [[Foo alloc] init];
+}
+
+#--- lib.h
+#ifndef LIB_H_IN
+#define LIB_H_IN
+
+#import <Foundation/Foundation.h>
+
+ at interface Foo : NSObject {
+int y;
+}
+ at end
+
+#endif // _H_IN
More information about the lldb-commits
mailing list