-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[lldb][MachO] Fix inspection of global variables that start with 'O' #161521
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
[lldb][MachO] Fix inspection of global variables that start with 'O' #161521
Conversation
@llvm/pr-subscribers-lldb Author: Michael Buch (Michael137) ChangesOn Darwin C-symbols are prefixed with a '_'. The LLDB Macho-O parses handles Objective-C metadata symbols starting with '_OBJC' specially. Previously global symbols starting with a '_O' prefix were lost because of incorrectly scoped if-guards. This patch removes those checks. There is more cleanup that can be done in this file because there's a bunch of duplicated checks for these ObjC symbols. I decided to leave that for an NFC follow-up. Depends on #161520 rdar://158159242 Full diff: https://github.com/llvm/llvm-project/pull/161521.diff 3 Files Affected:
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index fada1fda2b4bc..91c93be1b8cfd 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -2805,32 +2805,29 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
is_gsym = true;
sym[sym_idx].SetExternal(true);
- if (symbol_name && symbol_name[0] == '_' &&
- symbol_name[1] == 'O') {
- llvm::StringRef symbol_name_ref(symbol_name);
- if (symbol_name_ref.starts_with(
- g_objc_v2_prefix_class)) {
- symbol_name_non_abi_mangled = symbol_name + 1;
- symbol_name =
- symbol_name + g_objc_v2_prefix_class.size();
- type = eSymbolTypeObjCClass;
- demangled_is_synthesized = true;
-
- } else if (symbol_name_ref.starts_with(
- g_objc_v2_prefix_metaclass)) {
- symbol_name_non_abi_mangled = symbol_name + 1;
- symbol_name =
- symbol_name + g_objc_v2_prefix_metaclass.size();
- type = eSymbolTypeObjCMetaClass;
- demangled_is_synthesized = true;
- } else if (symbol_name_ref.starts_with(
- g_objc_v2_prefix_ivar)) {
- symbol_name_non_abi_mangled = symbol_name + 1;
- symbol_name =
- symbol_name + g_objc_v2_prefix_ivar.size();
- type = eSymbolTypeObjCIVar;
- demangled_is_synthesized = true;
- }
+ llvm::StringRef symbol_name_ref(symbol_name);
+ if (symbol_name_ref.starts_with(
+ g_objc_v2_prefix_class)) {
+ symbol_name_non_abi_mangled = symbol_name + 1;
+ symbol_name =
+ symbol_name + g_objc_v2_prefix_class.size();
+ type = eSymbolTypeObjCClass;
+ demangled_is_synthesized = true;
+
+ } else if (symbol_name_ref.starts_with(
+ g_objc_v2_prefix_metaclass)) {
+ symbol_name_non_abi_mangled = symbol_name + 1;
+ symbol_name =
+ symbol_name + g_objc_v2_prefix_metaclass.size();
+ type = eSymbolTypeObjCMetaClass;
+ demangled_is_synthesized = true;
+ } else if (symbol_name_ref.starts_with(
+ g_objc_v2_prefix_ivar)) {
+ symbol_name_non_abi_mangled = symbol_name + 1;
+ symbol_name =
+ symbol_name + g_objc_v2_prefix_ivar.size();
+ type = eSymbolTypeObjCIVar;
+ demangled_is_synthesized = true;
} else {
if (nlist.n_value != 0)
symbol_section = section_info.GetSection(
@@ -3652,7 +3649,7 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
if (is_debug) {
switch (nlist.n_type) {
- case N_GSYM:
+ case N_GSYM: {
// global symbol: name,,NO_SECT,type,0
// Sometimes the N_GSYM value contains the address.
@@ -3668,33 +3665,30 @@ void ObjectFileMachO::ParseSymtab(Symtab &symtab) {
is_gsym = true;
sym[sym_idx].SetExternal(true);
- if (symbol_name && symbol_name[0] == '_' && symbol_name[1] == 'O') {
- llvm::StringRef symbol_name_ref(symbol_name);
- if (symbol_name_ref.starts_with(g_objc_v2_prefix_class)) {
- symbol_name_non_abi_mangled = symbol_name + 1;
- symbol_name = symbol_name + g_objc_v2_prefix_class.size();
- type = eSymbolTypeObjCClass;
- demangled_is_synthesized = true;
-
- } else if (symbol_name_ref.starts_with(
- g_objc_v2_prefix_metaclass)) {
- symbol_name_non_abi_mangled = symbol_name + 1;
- symbol_name = symbol_name + g_objc_v2_prefix_metaclass.size();
- type = eSymbolTypeObjCMetaClass;
- demangled_is_synthesized = true;
- } else if (symbol_name_ref.starts_with(g_objc_v2_prefix_ivar)) {
- symbol_name_non_abi_mangled = symbol_name + 1;
- symbol_name = symbol_name + g_objc_v2_prefix_ivar.size();
- type = eSymbolTypeObjCIVar;
- demangled_is_synthesized = true;
- }
+ llvm::StringRef symbol_name_ref(symbol_name);
+ if (symbol_name_ref.starts_with(g_objc_v2_prefix_class)) {
+ symbol_name_non_abi_mangled = symbol_name + 1;
+ symbol_name = symbol_name + g_objc_v2_prefix_class.size();
+ type = eSymbolTypeObjCClass;
+ demangled_is_synthesized = true;
+
+ } else if (symbol_name_ref.starts_with(g_objc_v2_prefix_metaclass)) {
+ symbol_name_non_abi_mangled = symbol_name + 1;
+ symbol_name = symbol_name + g_objc_v2_prefix_metaclass.size();
+ type = eSymbolTypeObjCMetaClass;
+ demangled_is_synthesized = true;
+ } else if (symbol_name_ref.starts_with(g_objc_v2_prefix_ivar)) {
+ symbol_name_non_abi_mangled = symbol_name + 1;
+ symbol_name = symbol_name + g_objc_v2_prefix_ivar.size();
+ type = eSymbolTypeObjCIVar;
+ demangled_is_synthesized = true;
} else {
if (nlist.n_value != 0)
symbol_section =
section_info.GetSection(nlist.n_sect, nlist.n_value);
type = eSymbolTypeData;
}
- break;
+ } break;
case N_FNAME:
// procedure name (f77 kludge): name,,NO_SECT,0,0
diff --git a/lldb/test/Shell/Expr/TestGlobalSymbolObjCConflict.c b/lldb/test/Shell/Expr/TestGlobalSymbolObjCConflict.c
new file mode 100644
index 0000000000000..da7263648776f
--- /dev/null
+++ b/lldb/test/Shell/Expr/TestGlobalSymbolObjCConflict.c
@@ -0,0 +1,33 @@
+// Tests that LLDB correctly parses global symbols
+// starting with 'O'. On some platforms (e.g., Darwin)
+// C-symbols are prefixed with a '_'. The LLDB Macho-O
+// parses handles Objective-C metadata symbols starting
+// with '_OBJC' specially. This test ensures that we don't
+// lose track of regular global symbols with a '_O' prefix
+// in this.
+
+// RUN: %clang_host -c -g -fno-common %s -o %t.o
+// RUN: %clang_host %t.o -o %t.out
+// RUN: %lldb -b -x %t.out \
+// RUN: -o "b 17" \
+// RUN: -o "run" \
+// RUN: -o "p OglobalVar" \
+// RUN: -o "p Oabc" | FileCheck %s
+
+typedef struct {
+ int a;
+} Oabc_t;
+
+Oabc_t Oabc;
+int OglobalVar;
+
+int main(int argc, const char *argv[]) {
+ Oabc.a = 15;
+ OglobalVar = 10;
+ return OglobalVar + Oabc.a;
+}
+
+// CHECK: (lldb) p OglobalVar
+// CHECK: (int) 10
+// CHECK: (lldb) p Oabc
+// CHECK: (Oabc_t) (a = 15)
diff --git a/lldb/test/Shell/lit.cfg.py b/lldb/test/Shell/lit.cfg.py
index 505847fb763e0..cdc0cfe51f7c6 100644
--- a/lldb/test/Shell/lit.cfg.py
+++ b/lldb/test/Shell/lit.cfg.py
@@ -33,7 +33,7 @@
# suffixes: A list of file extensions to treat as test files. This is overriden
# by individual lit.local.cfg files in the test subdirectories.
-config.suffixes = [".test", ".cpp", ".s", ".m", ".ll"]
+config.suffixes = [".test", ".cpp", ".s", ".m", ".ll", ".c"]
# excludes: A list of directories to exclude from the testsuite. The 'Inputs'
# subdirectories contain auxiliary inputs for various tests in their parent
|
…unction Just a simple de-duplication of the same code. We saw a bug here recently (llvm#161521). Might as well isolate this all in one place. rdar://158159242
7e281d7
to
980ca0b
Compare
Required for llvm#161521 (cherry picked from commit 7ae3eca)
…lvm#161521) On Darwin C-symbols are prefixed with a '_'. The LLDB Macho-O parses handles Objective-C metadata symbols starting with '_OBJC' specially. Previously global symbols starting with a '_O' prefix were lost because of incorrectly scoped if-guards. This patch removes those checks. There is more cleanup that can be done in this file because there's a bunch of duplicated checks for these ObjC symbols. I decided to leave that for an NFC follow-up. Depends on llvm#161520 rdar://158159242 (cherry picked from commit 9f7e7f7)
…unction (llvm#161536) Just a simple de-duplication of the same code. We saw a bug here recently (llvm#161521). Might as well isolate this all in one place. rdar://158159242 (cherry picked from commit 23e0815)
…to helper function (#161536) Just a simple de-duplication of the same code. We saw a bug here recently (llvm/llvm-project#161521). Might as well isolate this all in one place. rdar://158159242
…ith 'O' (llvm#161521)" This reverts commit 1aefbce.
…lvm#161521) On Darwin C-symbols are prefixed with a '_'. The LLDB Macho-O parses handles Objective-C metadata symbols starting with '_OBJC' specially. Previously global symbols starting with a '_O' prefix were lost because of incorrectly scoped if-guards. This patch removes those checks. There is more cleanup that can be done in this file because there's a bunch of duplicated checks for these ObjC symbols. I decided to leave that for an NFC follow-up. Depends on llvm#161520 rdar://158159242
…unction (llvm#161536) Just a simple de-duplication of the same code. We saw a bug here recently (llvm#161521). Might as well isolate this all in one place. rdar://158159242
… start with 'O' (llvm#161521)"" This reverts commit e0677ad.
Required for llvm#161521 (cherry picked from commit 7ae3eca)
…lvm#161521) On Darwin C-symbols are prefixed with a '_'. The LLDB Macho-O parses handles Objective-C metadata symbols starting with '_OBJC' specially. Previously global symbols starting with a '_O' prefix were lost because of incorrectly scoped if-guards. This patch removes those checks. There is more cleanup that can be done in this file because there's a bunch of duplicated checks for these ObjC symbols. I decided to leave that for an NFC follow-up. Depends on llvm#161520 rdar://158159242 (cherry picked from commit 9f7e7f7)
On Darwin C-symbols are prefixed with a '_'. The LLDB Macho-O parses handles Objective-C metadata symbols starting with '_OBJC' specially. Previously global symbols starting with a '_O' prefix were lost because of incorrectly scoped if-guards. This patch removes those checks.
There is more cleanup that can be done in this file because there's a bunch of duplicated checks for these ObjC symbols. I decided to leave that for an NFC follow-up.
Depends on #161520
rdar://158159242