This is the mail archive of the gdb@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: GDB solib interface


Ok, I modified my gdbserver to conform to the interface and wrote a stub main executable and shared library. The share library symbol file is now loaded when gdb connects to the gdbserver, but my guess is that solib_target_relocate_section_addresses() needs to do more than just set so->textsection.

The reason is that gdb thinks that the test shared library function is somewhere around 0x6* hex. Specifically, gdb is reporting that the functions reside at the offsets I get when I do an objdump -xt of the library.

Does anyone have an idea of what variables I need to change to make the symbol file line up with the load on the remote target.

I've attached the diff. The previous one on this list does not compile cleanly. This one does, but has the above mentions problem.

=================== start of diff ==========================
diff -ruN insight-6.5/gdb/Makefile.in insight-6.5-with-patch/gdb/Makefile.in
--- insight-6.5/gdb/Makefile.in 2006-05-12 13:53:15.000000000 -0700
+++ insight-6.5-with-patch/gdb/Makefile.in 2006-12-15 16:30:06.546875000 -0700
@@ -2467,7 +2467,7 @@
$(gdb_stabs_h) $(gdbthread_h) $(remote_h) $(regcache_h) $(value_h) \
$(gdb_assert_h) $(event_loop_h) $(event_top_h) $(inf_loop_h) \
$(serial_h) $(gdbcore_h) $(remote_fileio_h) $(solib_h) $(observer_h) \
- $(cli_decode_h) $(cli_setshow_h)
+ $(cli_decode_h) $(cli_setshow_h) $(solist_h)
remote-e7000.o: remote-e7000.c $(defs_h) $(gdbcore_h) $(gdbarch_h) \
$(inferior_h) $(target_h) $(value_h) $(command_h) $(gdb_string_h) \
$(exceptions_h) $(gdbcmd_h) $(serial_h) $(remote_utils_h) \
@@ -2603,6 +2603,8 @@
$(gdbcore_h) $(target_h) $(inferior_h) $(gdb_assert_h) \
$(solist_h) $(solib_h) $(solib_svr4_h) $(bfd_target_h) $(elf_bfd_h) \
$(exec_h)
+solib-target.o: solib-target.c $(defs_h) $(solist_h) $(symtab_h) $(symfile_h) \
+ $(target_h) $(gdb_string_h)
sol-thread.o: sol-thread.c $(defs_h) $(gdbthread_h) $(target_h) \
$(inferior_h) $(gdb_stat_h) $(gdbcmd_h) $(gdbcore_h) $(regcache_h) \
$(solib_h) $(symfile_h) $(gdb_string_h) $(gregset_h)
diff -ruN insight-6.5/gdb/config/i386/#i386gnu.mt# insight-6.5-with-patch/gdb/config/i386/#i386gnu.mt#
--- insight-6.5/gdb/config/i386/#i386gnu.mt# 1969-12-31 17:00:00.000000000 -0700
+++ insight-6.5-with-patch/gdb/config/i386/#i386gnu.mt# 2006-12-15 16:45:03.593750000 -0700
@@ -0,0 +1,2 @@
+# Target: Intel 386 running the GNU Hurd
+TDEPFILES= i386-tdep.o i387-tdep.o i386gnu-tdep.o
diff -ruN insight-6.5/gdb/config/i386/linux.mt insight-6.5-with-patch/gdb/config/i386/linux.mt
--- insight-6.5/gdb/config/i386/linux.mt 2004-09-13 13:55:39.000000000 -0700
+++ insight-6.5-with-patch/gdb/config/i386/linux.mt 2006-12-15 16:44:16.812500000 -0700
@@ -1,4 +1,4 @@
# Target: Intel 386 running GNU/Linux
TDEPFILES= i386-tdep.o i386-linux-tdep.o glibc-tdep.o i387-tdep.o \
- solib.o solib-svr4.o symfile-mem.o
+ solib.o solib-svr4.o solib-target.o symfile-mem.o
DEPRECATED_TM_FILE= tm-linux.h
diff -ruN insight-6.5/gdb/config/powerpc/ppc-sim.mt insight-6.5-with-patch/gdb/config/powerpc/ppc-sim.mt
--- insight-6.5/gdb/config/powerpc/ppc-sim.mt 2004-11-13 18:11:07.000000000 -0700
+++ insight-6.5-with-patch/gdb/config/powerpc/ppc-sim.mt 2006-12-16 14:54:12.906250000 -0700
@@ -1,5 +1,5 @@
# Target: PowerPC running eabi and including the simulator
-TDEPFILES= rs6000-tdep.o monitor.o dsrec.o ppcbug-rom.o dink32-rom.o ocd.o ppc-sysv-tdep.o solib.o solib-svr4.o
+TDEPFILES= rs6000-tdep.o monitor.o dsrec.o ppcbug-rom.o dink32-rom.o ocd.o ppc-sysv-tdep.o solib.o solib-svr4.o solib-target.o
DEPRECATED_TM_FILE= tm-ppc-eabi.h


SIM_OBS = remote-sim.o
diff -ruN insight-6.5/gdb/infrun.c insight-6.5-with-patch/gdb/infrun.c
--- insight-6.5/gdb/infrun.c 2006-06-15 18:14:50.000000000 -0700
+++ insight-6.5-with-patch/gdb/infrun.c 2006-12-15 16:30:06.593750000 -0700
@@ -877,8 +877,10 @@
clear_proceed_status ();


  stepping_past_singlestep_breakpoint = 0;
+
+  target_last_wait_ptid = minus_one_ptid;
}
-
+
/* This enum encodes possible reasons for doing a target_wait, so that
   wfi can call target_wait in one place.  (Ultimately the call will be
   moved out of the infinite loop entirely.) */
@@ -1255,6 +1257,9 @@
  target_last_wait_ptid = ecs->ptid;
  target_last_waitstatus = *ecs->wp;

+ /* Always clear state belonging to the previous time we stopped. */ + stop_stack_dummy = 0;
+
adjust_pc_after_break (ecs);


  switch (ecs->infwait_state)
@@ -1315,13 +1320,16 @@
      /* Ignore gracefully during startup of the inferior, as it
         might be the shell which has just loaded some objects,
         otherwise add the symbols for the newly loaded objects.  */
-#ifdef SOLIB_ADD
      if (stop_soon == NO_STOP_QUIETLY)
-    {
+     {
+      int breakpoints_were_inserted;
+
      /* Remove breakpoints, SOLIB_ADD might adjust
         breakpoint addresses via breakpoint_re_set.  */
+      breakpoints_were_inserted = breakpoints_inserted;
      if (breakpoints_inserted)
        remove_breakpoints ();
+      breakpoints_inserted = 0;

      /* Check for any newly added shared libraries if we're
         supposed to be adding them automatically.  Switch
@@ -1343,17 +1351,52 @@
         exec/process stratum, instead relying on the target stack
         to propagate relevant changes (stop, section table
         changed, ...) up to other layers.  */
+#ifdef SOLIB_ADD
      SOLIB_ADD (NULL, 0, &current_target, auto_solib_add);
+#else
+      solib_add (NULL, 0, &current_target, auto_solib_add);
+#endif
      target_terminal_inferior ();

- /* Reinsert breakpoints and continue. */
- if (breakpoints_inserted)
- insert_breakpoints ();
+ /* Try to reenable shared library breakpoints, additional
+ code segments in shared libraries might be mapped in now. */
+ re_enable_breakpoints_in_shlibs ();
+
+ /* If requested, stop when the dynamic linker notifies
+ gdb of events. This allows the user to get control
+ and place breakpoints in initializer routines for
+ dynamically loaded objects (among other things). */
+ if (stop_on_solib_events)
+ {
+ stop_stepping (ecs);
+ return;
+ }
+
+ /* NOTE drow/2006-03-14: This might be a good place to check
+ for "catch load". */
+
+ /* Reinsert breakpoints and continue. */
+ if (breakpoints_were_inserted)
+ {
+ insert_breakpoints ();
+ breakpoints_inserted = 1;
+ }
}
-#endif
- resume (0, TARGET_SIGNAL_0);
- prepare_to_wait (ecs);
- return;
+
+ /* NOTE drow/2006-03-28: For the reason described before the
+ previous if statement, GDB used to automatically resume
+ here. But that's only true if a shell is running; if
+ we've just attached to a process, then that's a whole
+ different case - it might have been stopped at a load
+ event. */
+ if (inferior_ignoring_startup_exec_events || stop_soon == NO_STOP_QUIETLY)
+ {
+ resume (0, TARGET_SIGNAL_0);
+ prepare_to_wait (ecs);
+ return;
+ }
+ else
+ break;


case TARGET_WAITKIND_SPURIOUS:
if (debug_infrun)
@@ -1760,7 +1803,6 @@
ecs->another_trap = 0;
bpstat_clear (&stop_bpstat);
stop_step = 0;
- stop_stack_dummy = 0;
stop_print_frame = 1;
ecs->random_signal = 0;
stopped_by_random_signal = 0;
diff -ruN insight-6.5/gdb/remote.c insight-6.5-with-patch/gdb/remote.c
--- insight-6.5/gdb/remote.c 2006-05-05 13:08:45.000000000 -0700
+++ insight-6.5-with-patch/gdb/remote.c 2006-12-16 13:11:38.609375000 -0700
@@ -43,6 +43,7 @@
#include "gdb_assert.h"
#include "observer.h"
#include "solib.h"
+#include "solist.h"
#include "cli/cli-decode.h"
#include "cli/cli-setshow.h"


@@ -765,6 +766,7 @@
  PACKET_Z4,
  PACKET_qPart_auxv,
  PACKET_qGetTLSAddr,
+  PACKET_qfDllInfo,
  PACKET_MAX
};

@@ -1888,6 +1890,150 @@
  objfile_relocate (symfile_objfile, offs);
}

+/* Parse a load or unload message for a DLL. Loads are required to
+ have all fields, unloads must have at least one. P is not
+ necessarily NUL terminated, but it is always either NUL or semicolon
+ terminated (i.e. *P_END is either NUL or a semicolon) and the containing
+ string is NUL terminated. */
+
+int
+parse_load_response (const char *p, const char *p_end, int is_load) {
+ const char *name_start;
+ char *name;
+ CORE_ADDR text_addr, data_addr;
+ int i;
+
+ name = NULL;
+ text_addr = ~(CORE_ADDR) 0;
+ data_addr = ~(CORE_ADDR) 0;
+
+ if (p < p_end && strncmp (p, "Name=", 5) == 0)
+ {
+ p += 5;
+
+ name_start = p;
+ while (p < p_end && *p != ',')
+ p++;
+
+ if ((p - name_start) % 2 != 0)
+ return -1;
+
+ name = alloca ((p - name_start) / 2 + 1);
+ i = hex2bin (name_start, name, (p - name_start) / 2);
+ name[i] = '\0';
+
+ if (p < p_end)
+ p++;
+ }
+ else if (is_load)
+ return -1;
+
+ if (p < p_end && strncmp (p, "TextSeg=", 8) == 0)
+ {
+ p += 8;
+
+ text_addr = 0;
+ while (p < p_end && *p != ',')
+ text_addr = (text_addr << 4) + fromhex (*p++);
+
+ if (p < p_end)
+ p++;
+ }
+ else if (is_load)
+ return -1;
+
+ if (p < p_end && strncmp (p, "DataSeg=", 8) == 0)
+ {
+ p += 8;
+
+ data_addr = 0;
+ while (p < p_end && *p != ',')
+ data_addr = (data_addr << 4) + fromhex (*p++);
+
+ if (p < p_end)
+ p++;
+ }
+ else if (is_load)
+ return -1;
+
+ if (is_load)
+ current_target_so_ops->add_one_solib (name, text_addr, data_addr);
+ else
+ {
+ if (text_addr == ~(CORE_ADDR) 0
+ && data_addr == ~(CORE_ADDR) 0
+ && name == NULL)
+ return -1;
+
+ current_target_so_ops->remove_one_solib (name, text_addr, data_addr);
+ }
+
+ return 0;
+}
+
+/* Query the remote side for loaded solibs. */
+
+static void
+remote_get_shared_libraries (struct target_ops *ops) {
+ struct remote_state *rs = get_remote_state ();
+
+ /* If this target doesn't support remote DLLs, nothing to do. */ if
+ (current_target_so_ops->add_one_solib == NULL)
+ return;
+
+ /* If qfDllInfo is not available, nothing to do. */ if
+ (remote_protocol_packets[PACKET_qfDllInfo].support == PACKET_DISABLE)
+ return;
+
+ putpkt ("qfDllInfo");
+ getpkt (&rs->buf, &rs->buf_size, 0);
+
+ if (packet_ok (rs->buf, &remote_protocol_packets[PACKET_qfDllInfo]) == PACKET_ERROR)
+ {
+ warning (_("Remote failure reply: %s"), rs->buf);
+ return;
+ }
+ else if (remote_protocol_packets[PACKET_qfDllInfo].support == PACKET_DISABLE)
+ /* It wasn't disabled before, but it is now. */
+ return;
+
+ while (rs->buf[0] == 'm')
+ {
+ char *p = rs->buf + 1;
+
+ while (1)
+ {
+ char *p_end = p;
+
+ while (*p_end && *p_end != ';')
+ p_end++;
+
+ if (parse_load_response (p, p_end, 1) != 0)
+ {
+ warning (_("Malformed response to DLL query, %s"), rs->buf);
+ return;
+ }
+
+ if (*p_end == ';')
+ p = p_end + 1;
+ else
+ break;
+ }
+
+ putpkt ("qsDllInfo");
+ getpkt (&rs->buf, &rs->buf_size, 0);
+ }
+
+ if (strcmp (rs->buf, "l") != 0)
+ {
+ warning (_("Malformed response to DLL query, %s"), rs->buf);
+ return;
+ }
+
+ /* We don't need to call solib_add here, because we're being called from
+ ->current_sos (). */
+}
+
/* Stub for catch_errors. */


static int
@@ -2671,6 +2817,7 @@
  char *buf = rs->buf;
  ULONGEST thread_num = -1;
  ULONGEST addr;
+  int solibs_changed = 0;

status->kind = TARGET_WAITKIND_EXITED;
status->value.integer = 0;
@@ -2754,6 +2901,60 @@
p = unpack_varlen_hex (++p1, &addr);
remote_watch_data_address = (CORE_ADDR)addr;
}
+ else if (strncmp (p, "load", p1 - p) == 0)
+ {
+ p1++;
+ p_temp = p1;
+ while (*p_temp && *p_temp != ';')
+ p_temp++;
+
+ if (p_temp - p1 > 4
+ && strncmp (p_temp - 4, ",nop", 4) == 0)
+ {
+ /* For now, ignore no-op unload events. Later,
+ maybe report them? */
+ }
+ else
+ {
+ parse_load_response (p1, p_temp, 1);
+
+ solibs_changed = 1;
+ }
+
+ p = p_temp;
+ }
+ else if (strncmp (p, "unload", p1 - p) == 0)
+ {
+ p1++;
+ p_temp = p1;
+ while (*p_temp && *p_temp != ';')
+ p_temp++;
+
+ if (p_temp - p1 > 4
+ && strncmp (p_temp - 4, ",nop", 4) == 0)
+ {
+ /* For now, ignore no-op unload events. Later,
+ maybe report them? */
+ }
+ else
+ {
+ parse_load_response (p1, p_temp, 0);
+
+ solibs_changed = 1;
+ }
+
+ p = p_temp;
+ }
+ else if (strncmp (p, "dll", p1 - p) == 0)
+ {
+ p1++;
+ p_temp = p1;
+ while (*p_temp && *p_temp != ';')
+ p_temp++;
+
+ solibs_changed = -1;
+ p = p_temp;
+ }
else
{
/* Silently skip unknown optional info. */
@@ -2845,6 +3046,12 @@
}
}
got_status:
+ if (solibs_changed == -1)
+ remote_get_shared_libraries (NULL);
+ + if (solibs_changed != 0)
+ status->kind = TARGET_WAITKIND_LOADED;
+
if (thread_num != -1)
{
return pid_to_ptid (thread_num);
@@ -5229,6 +5436,7 @@
(e.g. /dev/ttyS0, /dev/ttya, COM1, etc.).";
remote_ops.to_open = remote_open;
remote_ops.to_close = remote_close;
+ remote_ops.to_get_shared_libraries = remote_get_shared_libraries;
remote_ops.to_detach = remote_detach;
remote_ops.to_disconnect = remote_disconnect;
remote_ops.to_resume = remote_resume;
@@ -5354,6 +5562,7 @@
remote_async_ops.to_open = remote_async_open;
remote_async_ops.to_close = remote_close;
remote_async_ops.to_detach = remote_detach;
+ remote_async_ops.to_get_shared_libraries = remote_get_shared_libraries;
remote_async_ops.to_disconnect = remote_disconnect;
remote_async_ops.to_resume = remote_async_resume;
remote_async_ops.to_wait = remote_async_wait;
@@ -5616,6 +5825,13 @@
&remote_set_cmdlist, &remote_show_cmdlist,
0);


+ add_packet_config_cmd (&remote_protocol_packets[PACKET_qfDllInfo],
+ "qfDllInfo", "dll-info",
+ set_remote_protocol_packet_cmd,
+ show_remote_protocol_packet_cmd,
+ &remote_set_cmdlist, &remote_show_cmdlist,
+ 0);
+
add_packet_config_cmd (&remote_protocol_packets[PACKET_P],
"P", "set-register",
set_remote_protocol_packet_cmd,
diff -ruN insight-6.5/gdb/solib-target.c insight-6.5-with-patch/gdb/solib-target.c
--- insight-6.5/gdb/solib-target.c 1969-12-31 17:00:00.000000000 -0700
+++ insight-6.5-with-patch/gdb/solib-target.c 2006-12-29 12:35:17.453125000 -0700
@@ -0,0 +1,238 @@
+/* Definitions for targets which report shared library events.
+
+ Copyright (C) 2006
+ Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
+
+#include "defs.h"
+#include "solist.h"
+#include "symtab.h"
+#include "symfile.h"
+#include "target.h"
+
+#include "gdb_string.h"
+
+struct lm_info
+{
+ CORE_ADDR textSeg, dataSeg;
+};
+
+static struct so_list *solib_start;
+static int solibs_fetched;
+
+static struct so_list *
+solib_target_current_sos (void)
+{
+ struct so_list *sop;
+ struct so_list *start = NULL;
+ struct so_list *last = NULL;
+
+ /* If we have not asked the target for the list of shared libraries
+ yet, do it now. */
+ if (!solibs_fetched)
+ {
+ solibs_fetched = 1;
+ target_get_shared_libraries ();
+ }
+
+ for (sop = solib_start; sop; sop = sop->next)
+ {
+ struct so_list *new;
+
+ /* Duplicate the recorded solib. */
+ new = XZALLOC (struct so_list);
+ strcpy (new->so_name, sop->so_name);
+ strcpy (new->so_original_name, sop->so_original_name);
+ new->lm_info = XMALLOC (struct lm_info);
+ *new->lm_info = *sop->lm_info;
+
+ /* Add it to the list. */
+ if (!start)
+ last = start = new;
+ else
+ {
+ last->next = new;
+ last = new;
+ }
+ }
+
+ return start;
+}
+
+static void
+solib_target_special_symbol_handling (void) {
+ /* Nothing needed. */
+}
+
+static void
+solib_target_solib_create_inferior_hook (void) {
+ /* Nothing needed. */
+}
+
+static void
+solib_target_clear_solib (void)
+{
+ struct so_list *sop, *next;
+
+ for (sop = solib_start; sop; sop = next)
+ {
+ next = sop->next;
+
+ free_so (sop);
+ }
+
+ solib_start = NULL;
+ solibs_fetched = 0;
+}
+
+static void
+solib_target_free_so (struct so_list *so) {
+ xfree (so->lm_info);
+}
+
+static void
+solib_target_relocate_section_addresses (struct so_list *so,
+ struct section_table *sec)
+{
+ so->textsection = (void *)so->lm_info->textSeg;
+}
+
+static int
+solib_target_open_symbol_file_object (void *from_ttyp) {
+ /* We can't locate the main symbol file based on the target's
+ knowledge; the user has to specify it. */
+ return 0;
+}
+
+static int
+solib_target_in_dynsym_resolve_code (CORE_ADDR pc) {
+ /* Assume there isn't target dynsym resolution code. DLL targets
+ generally have only import stubs (which GDB treats as "PLT entries"),
+ and no runtime binding code. */
+ return 0;
+}
+
+static void
+solib_target_add_one_solib (char *soname, CORE_ADDR textSeg,
+ CORE_ADDR dataSeg)
+{
+ struct so_list *new_solib, *so;
+
+ /* We should already have queried the target for shared libraries
+ before this point. If we haven't, we may have just connected;
+ we'll be querying shortly. */
+ if (!solibs_fetched)
+ return;
+
+ /* Check for duplicates already on the list. This can happen, for
+ instance, if we are stopped at a DLL load event when we first
+ connect to a remote target: the DLL will already be in the
+ queried list, but also be reported by the initial wait. */
+ for (so = solib_start; so; so = so->next)
+ if (strcmp (so->so_name, soname) == 0
+ && so->lm_info->textSeg == textSeg
+ && so->lm_info->dataSeg == dataSeg)
+ return;
+
+ new_solib = XZALLOC (struct so_list); strncpy (new_solib->so_name,
+ soname, SO_NAME_MAX_PATH_SIZE - 1); + new_solib->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0'; strncpy
+ (new_solib->so_original_name, soname, SO_NAME_MAX_PATH_SIZE - 1); + new_solib->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
+
+ new_solib->lm_info = XZALLOC (struct lm_info); + new_solib->lm_info->textSeg = textSeg; new_solib->lm_info->dataSeg =
+ dataSeg;
+
+ if (solib_start == NULL)
+ solib_start = new_solib;
+ else
+ {
+ so = solib_start;
+ while (so->next)
+ so = so->next;
+ so->next = new_solib;
+ }
+
+ /* We do not trigger symbol reading here; the target will do it,
+ after all load events have been processed. */
+}
+
+static void
+solib_target_remove_one_solib (char *soname, CORE_ADDR textSeg,
+ CORE_ADDR dataSeg)
+{
+ struct so_list **slot, *removed;
+
+ /* We should already have queried the target for shared libraries
+ before this point. If we haven't, we may have just connected;
+ we'll be querying shortly. */
+ if (!solibs_fetched)
+ return;
+
+ for (slot = &solib_start; *slot != NULL; slot = &(*slot)->next)
+ {
+ if (textSeg != ~(CORE_ADDR) 0 && textSeg != (*slot)->lm_info->textSeg)
+ continue;
+ if (dataSeg != ~(CORE_ADDR) 0 && dataSeg != (*slot)->lm_info->dataSeg)
+ continue;
+ if (soname != NULL && strcmp (soname, (*slot)->so_name) != 0)
+ continue;
+ break;
+ }
+
+ if (*slot == NULL)
+ return;
+
+ removed = *slot;
+ *slot = removed->next;
+
+ free_so (removed);
+
+ /* We do not trigger symbol unloading here; the target will do it,
+ after all unload events have been processed. */
+}
+
+static struct target_so_ops solib_target_so_ops;
+
+extern initialize_file_ftype _initialize_solib_target; /*
+-Wmissing-prototypes */
+
+void
+_initialize_solib_target (void)
+{
+ solib_target_so_ops.relocate_section_addresses
+ = solib_target_relocate_section_addresses;
+ solib_target_so_ops.free_so = solib_target_free_so;
+ solib_target_so_ops.clear_solib = solib_target_clear_solib;
+ solib_target_so_ops.solib_create_inferior_hook
+ = solib_target_solib_create_inferior_hook;
+ solib_target_so_ops.special_symbol_handling
+ = solib_target_special_symbol_handling;
+ solib_target_so_ops.current_sos = solib_target_current_sos;
+ solib_target_so_ops.open_symbol_file_object
+ = solib_target_open_symbol_file_object;
+ solib_target_so_ops.in_dynsym_resolve_code
+ = solib_target_in_dynsym_resolve_code;
+ solib_target_so_ops.add_one_solib = solib_target_add_one_solib;
+ solib_target_so_ops.remove_one_solib = solib_target_remove_one_solib;
+
+ current_target_so_ops = &solib_target_so_ops;
+}
+
diff -ruN insight-6.5/gdb/solib-target.c~ insight-6.5-with-patch/gdb/solib-target.c~
--- insight-6.5/gdb/solib-target.c~ 1969-12-31 17:00:00.000000000 -0700
+++ insight-6.5-with-patch/gdb/solib-target.c~ 2006-12-19 09:04:15.109375000 -0700
@@ -0,0 +1,236 @@
+/* Definitions for targets which report shared library events.
+
+ Copyright (C) 2006
+ Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
+
+#include "defs.h"
+#include "solist.h"
+#include "symtab.h"
+#include "symfile.h"
+#include "target.h"
+
+#include "gdb_string.h"
+
+struct lm_info
+{
+ CORE_ADDR textSeg, dataSeg;
+};
+
+static struct so_list *solib_start;
+static int solibs_fetched;
+
+static struct so_list *
+solib_target_current_sos (void)
+{
+ struct so_list *sop;
+ struct so_list *start = NULL;
+ struct so_list *last = NULL;
+
+ /* If we have not asked the target for the list of shared libraries
+ yet, do it now. */
+ if (!solibs_fetched)
+ {
+ solibs_fetched = 1;
+ target_get_shared_libraries ();
+ }
+
+ for (sop = solib_start; sop; sop = sop->next)
+ {
+ struct so_list *new;
+
+ /* Duplicate the recorded solib. */
+ new = XZALLOC (struct so_list);
+ strcpy (new->so_name, sop->so_name);
+ strcpy (new->so_original_name, sop->so_original_name);
+ new->lm_info = XMALLOC (struct lm_info);
+ *new->lm_info = *sop->lm_info;
+
+ /* Add it to the list. */
+ if (!start)
+ last = start = new;
+ else
+ {
+ last->next = new;
+ last = new;
+ }
+ }
+
+ return start;
+}
+
+static void
+solib_target_special_symbol_handling (void) {
+ /* Nothing needed. */
+}
+
+static void
+solib_target_solib_create_inferior_hook (void) {
+ /* Nothing needed. */
+}
+
+static void
+solib_target_clear_solib (void)
+{
+ struct so_list *sop, *next;
+
+ for (sop = solib_start; sop; sop = next)
+ {
+ next = sop->next;
+
+ free_so (sop);
+ }
+
+ solib_start = NULL;
+ solibs_fetched = 0;
+}
+
+static void
+solib_target_free_so (struct so_list *so) {
+ xfree (so->lm_info);
+}
+
+static void
+solib_target_relocate_section_addresses (struct so_list *so,
+ struct section_table *sec)
+{
+ so->textsection = (void *)so->lm_info->textSeg;
+}
+
+static int
+solib_target_open_symbol_file_object (void *from_ttyp) {
+ /* We can't locate the main symbol file based on the target's
+ knowledge; the user has to specify it. */
+ return 0;
+}
+
+static int
+solib_target_in_dynsym_resolve_code (CORE_ADDR pc) {
+ /* Assume there isn't target dynsym resolution code. DLL targets
+ generally have only import stubs (which GDB treats as "PLT entries"),
+ and no runtime binding code. */
+ return 0;
+}
+
+static void
+solib_target_add_one_solib (char *soname, CORE_ADDR textSeg,
+ CORE_ADDR dataSeg)
+{
+ struct so_list *new_solib, *so;
+
+ /* We should already have queried the target for shared libraries
+ before this point. If we haven't, we may have just connected;
+ we'll be querying shortly. */
+ if (!solibs_fetched)
+ return;
+
+ /* Check for duplicates already on the list. This can happen, for
+ instance, if we are stopped at a DLL load event when we first
+ connect to a remote target: the DLL will already be in the
+ queried list, but also be reported by the initial wait. */
+ for (so = solib_start; so; so = so->next)
+ if (strcmp (so->so_name, soname) == 0
+ && so->lm_info->textSeg == textSeg
+ && so->lm_info->dataSeg == dataSeg)
+ return;
+
+ new_solib = XZALLOC (struct so_list); strncpy (new_solib->so_name,
+ soname, SO_NAME_MAX_PATH_SIZE - 1); + new_solib->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0'; strncpy
+ (new_solib->so_original_name, soname, SO_NAME_MAX_PATH_SIZE - 1); + new_solib->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
+
+ new_solib->lm_info = XZALLOC (struct lm_info); + new_solib->lm_info->textSeg = textSeg; new_solib->lm_info->dataSeg =
+ dataSeg;
+
+ if (solib_start == NULL)
+ solib_start = new_solib;
+ else
+ {
+ so = solib_start;
+ while (so->next)
+ so = so->next;
+ so->next = new_solib;
+ }
+
+ /* We do not trigger symbol reading here; the target will do it,
+ after all load events have been processed. */ }
+
+static void
+solib_target_remove_one_solib (char *soname, CORE_ADDR textSeg,
+ CORE_ADDR dataSeg)
+{
+ struct so_list **slot, *removed;
+
+ /* We should already have queried the target for shared libraries
+ before this point. If we haven't, we may have just connected;
+ we'll be querying shortly. */
+ if (!solibs_fetched)
+ return;
+
+ for (slot = &solib_start; *slot != NULL; slot = &(*slot)->next)
+ {
+ if (textSeg != ~(CORE_ADDR) 0 && textSeg != (*slot)->lm_info->textSeg)
+ continue;
+ if (dataSeg != ~(CORE_ADDR) 0 && dataSeg != (*slot)->lm_info->dataSeg)
+ continue;
+ if (soname != NULL && strcmp (soname, (*slot)->so_name) != 0)
+ continue;
+ break;
+ }
+
+ if (*slot == NULL)
+ return;
+
+ removed = *slot;
+ *slot = removed->next;
+
+ free_so (removed);
+
+ /* We do not trigger symbol unloading here; the target will do it,
+ after all unload events have been processed. */ }
+
+static struct target_so_ops solib_target_so_ops;
+
+extern initialize_file_ftype _initialize_solib_target; /*
+-Wmissing-prototypes */
+
+void
+_initialize_solib_target (void)
+{
+ solib_target_so_ops.relocate_section_addresses
+ = solib_target_relocate_section_addresses;
+ solib_target_so_ops.free_so = solib_target_free_so;
+ solib_target_so_ops.clear_solib = solib_target_clear_solib;
+ solib_target_so_ops.solib_create_inferior_hook
+ = solib_target_solib_create_inferior_hook;
+ solib_target_so_ops.special_symbol_handling
+ = solib_target_special_symbol_handling;
+ solib_target_so_ops.current_sos = solib_target_current_sos;
+ solib_target_so_ops.open_symbol_file_object
+ = solib_target_open_symbol_file_object;
+ solib_target_so_ops.in_dynsym_resolve_code
+ = solib_target_in_dynsym_resolve_code;
+ solib_target_so_ops.add_one_solib = solib_target_add_one_solib;
+ solib_target_so_ops.remove_one_solib = solib_target_remove_one_solib;
+
+ current_target_so_ops = &solib_target_so_ops;
+}
+
diff -ruN insight-6.5/gdb/solist.h insight-6.5-with-patch/gdb/solist.h
--- insight-6.5/gdb/solist.h 2005-12-17 15:34:02.000000000 -0700
+++ insight-6.5-with-patch/gdb/solist.h 2006-12-15 16:30:06.671875000 -0700
@@ -105,6 +105,10 @@
int (*find_and_open_solib) (char *soname,
unsigned o_flags, char **temp_pathname);
+ void (*add_one_solib) (char *soname, CORE_ADDR textSeg,
+ CORE_ADDR dataSeg);
+ void (*remove_one_solib) (char *soname, CORE_ADDR textSeg,
+ CORE_ADDR dataSeg);
};


/* Free the memory associated with a (so_list *). */
diff -ruN insight-6.5/gdb/target.c insight-6.5-with-patch/gdb/target.c
--- insight-6.5/gdb/target.c 2006-05-05 13:08:45.000000000 -0700
+++ insight-6.5-with-patch/gdb/target.c 2006-12-16 13:13:21.765625000 -0700
@@ -456,6 +456,7 @@
INHERIT (to_make_corefile_notes, t);
INHERIT (to_get_thread_local_address, t);
INHERIT (to_magic, t);
+ /* Do not inherit to_get_shared_libraries. */
}
#undef INHERIT


@@ -1534,6 +1535,27 @@
}

/* Look through the list of possible targets for a target that can
+   fetch shared libraries.  */
+
+void
+target_get_shared_libraries (void)
+{
+  struct target_ops *t;
+
+  for (t = current_target.beneath; t != NULL; t = t->beneath)
+    {
+      if (t->to_get_shared_libraries != NULL)
+    {
+      t->to_get_shared_libraries (t);
+      break;
+    }
+    }
+
+  if (targetdebug)
+    fprintf_unfiltered (gdb_stdlog, "target_get_shared_libraries()\n");
+}
+
+/* Look through the list of possible targets for a target that can
   execute a run or attach command without any other data.  This is
   used to locate the default process stratum.

diff -ruN insight-6.5/gdb/target.h insight-6.5-with-patch/gdb/target.h
--- insight-6.5/gdb/target.h 2006-05-05 13:08:45.000000000 -0700
+++ insight-6.5-with-patch/gdb/target.h 2006-12-15 16:30:06.703125000 -0700
@@ -424,6 +424,9 @@
gdb_byte *readbuf, const gdb_byte *writebuf,
ULONGEST offset, LONGEST len);


+ /* Refresh the list of shared libraries. */
+ void (*to_get_shared_libraries) (struct target_ops *ops);
+
int to_magic;
/* Need sub-structure for target machine related rather than comm related?
*/
@@ -1092,6 +1095,10 @@
#define RESUME_EXECD_VFORKING_CHILD_TO_GET_PARENT_VFORK() (0)
#endif


+/* Refresh the list of shared libraries from the target.  */
+
+extern void target_get_shared_libraries (void);
+
/* Routines for maintenance of the target structures...

   add_target:   Add a target to the list of all possible targets.
============================== end of diff ==============================


Daniel Jacobowitz wrote:
On Sat, Dec 16, 2006 at 05:42:39PM -0700, Smith, Stephen (SWCOE) wrote:
The function solib_target_relocate_section_addresses() refers to
functions and datamembers that no longer exist.  I believe that
borrowing code from the svr4 code is the correct thing to do.

Can anyone confirm that that is the right thing?

Sorry, it's actually the other way round. It's not that the things it refers to no longer exist - they've never existed in the FSF source, they were part of another patch from the tree I took this from.

I think the equivalent would be initializing so->textsection.



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