[lldb] Try harder to find the __NSCFBoolean addresses
authorFred Riss <friss@apple.com>
Fri, 22 May 2020 02:21:51 +0000 (19:21 -0700)
committerJonas Devlieghere <jonas@devlieghere.com>
Fri, 6 Aug 2021 20:04:29 +0000 (13:04 -0700)
It looks like recent CoreFoundation builds strip the non-public symbol
that we were looking for to find the 2 boolean "classes". The public
symbol is of course there, and it contains the address of the private
one. If we don't find the private symbol directly, go through a memory
read at the public symbol's location instead.

lldb/source/Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.cpp

index 10512a9..b4b6c8b 100644 (file)
@@ -2967,11 +2967,13 @@ bool AppleObjCRuntimeV2::GetCFBooleanValuesIfNeeded() {
   if (m_CFBoolean_values)
     return true;
 
-  static ConstString g_kCFBooleanFalse("__kCFBooleanFalse");
-  static ConstString g_kCFBooleanTrue("__kCFBooleanTrue");
+  static ConstString g___kCFBooleanFalse("__kCFBooleanFalse");
+  static ConstString g___kCFBooleanTrue("__kCFBooleanTrue");
+  static ConstString g_kCFBooleanFalse("kCFBooleanFalse");
+  static ConstString g_kCFBooleanTrue("kCFBooleanTrue");
 
-  std::function<lldb::addr_t(ConstString)> get_symbol =
-      [this](ConstString sym) -> lldb::addr_t {
+  std::function<lldb::addr_t(ConstString, ConstString)> get_symbol =
+      [this](ConstString sym, ConstString real_sym) -> lldb::addr_t {
     SymbolContextList sc_list;
     GetProcess()->GetTarget().GetImages().FindSymbolsWithNameAndType(
         sym, lldb::eSymbolTypeData, sc_list);
@@ -2981,12 +2983,26 @@ bool AppleObjCRuntimeV2::GetCFBooleanValuesIfNeeded() {
       if (sc.symbol)
         return sc.symbol->GetLoadAddress(&GetProcess()->GetTarget());
     }
+    GetProcess()->GetTarget().GetImages().FindSymbolsWithNameAndType(
+        real_sym, lldb::eSymbolTypeData, sc_list);
+    if (sc_list.GetSize() != 1)
+      return LLDB_INVALID_ADDRESS;
 
-    return LLDB_INVALID_ADDRESS;
+    SymbolContext sc;
+    sc_list.GetContextAtIndex(0, sc);
+    if (!sc.symbol)
+      return LLDB_INVALID_ADDRESS;
+
+    lldb::addr_t addr = sc.symbol->GetLoadAddress(&GetProcess()->GetTarget());
+    Status error;
+    addr = GetProcess()->ReadPointerFromMemory(addr, error);
+    if (error.Fail())
+      return LLDB_INVALID_ADDRESS;
+    return addr;
   };
 
-  lldb::addr_t false_addr = get_symbol(g_kCFBooleanFalse);
-  lldb::addr_t true_addr = get_symbol(g_kCFBooleanTrue);
+  lldb::addr_t false_addr = get_symbol(g___kCFBooleanFalse, g_kCFBooleanFalse);
+  lldb::addr_t true_addr = get_symbol(g___kCFBooleanTrue, g_kCFBooleanTrue);
 
   return (m_CFBoolean_values = {false_addr, true_addr}).operator bool();
 }