This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA 2/5] Darwin: Handle unrelocated dyld.


On 2018-08-22 06:11, Xavier Roirand wrote:
@@ -558,6 +600,56 @@ darwin_solib_create_inferior_hook (int from_tty)
       if (vmaddr != load_addr)
 	objfile_rebase (symfile_objfile, load_addr - vmaddr);
     }
+
+  /* Set solib notifier (to reload list of shared libraries).  */
+  notifier = info->all_image.notifier;
+  info->notifier_set = 1;
+
+  if (info->all_image.count == 0)
+    {
+      CORE_ADDR start;
+
+ /* Dyld hasn't yet relocated itself, so the notifier address may be
+        incorrect (as it has to be relocated).
+ (Apparently dyld doesn't need to relocate itself on x86-64 darwin,
+        but don't assume that).
+        Set an event breakpoint at the entry point.  */
+      start = bfd_get_start_address (exec_bfd);
+      if (start == 0)
+       notifier = 0;
+      else
+        {
+          gdb_bfd_ref_ptr dyld_bfd (darwin_get_dyld_bfd ());
+          if (dyld_bfd != NULL)
+            {
+              CORE_ADDR dyld_bfd_start_address;
+              CORE_ADDR dyld_relocated_base_address;
+              CORE_ADDR pc;
+
+ dyld_bfd_start_address = bfd_get_start_address (dyld_bfd.get());
+
+ /* We find the dynamic linker's base address by examining
+                 the current pc (which should point at the entry point
+                 for the dynamic linker) and subtracting the offset of
+                 the entry point.  */
+
+              pc = regcache_read_pc (get_current_regcache ());
+ dyld_relocated_base_address = pc - dyld_bfd_start_address;
+
+              /* We get the proper notifier relocated address by
+                 adding the dyld relocated base address to the current
+                 notifier offset value.  */
+
+              notifier += dyld_relocated_base_address;
+              info->notifier_set = 0;
+            }
+        }
+    }
+
+  /* Add the breakpoint which is hit by dyld when the list of solib is
+     modified.  */
+  if (notifier != 0)
+    create_solib_event_breakpoint (target_gdbarch (), notifier);
 }

Also, if the process of finding the notifier address fails at any point, could we display a warning?

Simon


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]