[patch] general updates and improvements to QNX NTO support

Kris Warkentin
2004-11-19T20:47:48Z

[-- Attachment #1: Type: text/plain, Size: 2212 bytes --]

Sorry about the vagueness of the patch description. I've been working
on this off and on for a while but I've been lazy about submitting. By
and large, most of this is just about being able to switch targets to
future-proof against a multi-arch gdb.

Also I've created hooks for recognizing when we're dealing with a
Neutrino target. Unfortunately there is no nice way to recognize our
binaries so I have to fall back on cheating.

A few other things are there as well such as an 'in_dynsym_resolve_code'
for better solib support, a core sniffer and some assorted
re-arrangement of things.

I had started getting rid of some of the deprecated things (core_fns)
but was having trouble so I ripped that part of the patch out to work on
and submit later. Looks like I'm also going to have to get rid of
to_xfer_memory.

cheers,

Kris

ChangeLog entry:
2004-11-19 Kris Warkentin <kewarken@qnx.com>

* nto-tdep.h: Include osabi.h. Prototypes for generic Neutrino
osabi sniffer, signal handling initializer and
'in_dynsym_resolve_code' function.
(struct nto_target_ops): Put comments inline with struct. Add osabi
sniffer hook. Redefine macros to permit testing/assignment.
* nto-tdep.c (nto_find_and_open_solib): Allocate all buffers
dynamically to support arbitrary root paths. Check for basename of
lib in search path and then check for absolute.
(nto_in_dynsym_resolve_code): New function.
(nto_core_sniffer): New function.
(regset_core_fns): Register core sniffer.
(nto_initialize_signals): New function.
(_initialize_nto_tdep): Move signal initialization code to above to
avoid initialization race conditions.
* nto-procfs.c: Minor formatting/indenting changes.
(procfs_is_nto_target): New function.
(procfs_open): Set nto_is_nto_target.
(_initialize_procfs): Ditto. Remove notice_signals() call to avoid
initialization race conditions.
(procfs_create_inferior): Resume inferior after creation.
* i386-nto-tdep.c (init_i386nto_ops): Use new macros for assignment.
(i386nto_init_abi): Initialize signals. Set
TARGET_SO_IN_DYNSYM_RESOLVE_CODE.
(_initialize_i386nto_tdep): Register osabi sniffer.

[-- Attachment #2: new.diff --]
[-- Type: text/x-patch, Size: 17760 bytes --]

Index: i386-nto-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-nto-tdep.c,v
retrieving revision 1.15
diff -u -r1.15 i386-nto-tdep.c
--- i386-nto-tdep.c 31 Oct 2004 19:52:46 -0000 1.15
+++ i386-nto-tdep.c 19 Nov 2004 20:07:18 -0000
@@ -258,15 +258,14 @@
static void
init_i386nto_ops (void)
{
- current_nto_target.nto_regset_id = i386nto_regset_id;
- current_nto_target.nto_supply_gregset = i386nto_supply_gregset;
- current_nto_target.nto_supply_fpregset = i386nto_supply_fpregset;
- current_nto_target.nto_supply_altregset = nto_dummy_supply_regset;
- current_nto_target.nto_supply_regset = i386nto_supply_regset;
- current_nto_target.nto_register_area = i386nto_register_area;
- current_nto_target.nto_regset_fill = i386nto_regset_fill;
- current_nto_target.nto_fetch_link_map_offsets =
- i386nto_svr4_fetch_link_map_offsets;
+ nto_regset_id = i386nto_regset_id;
+ nto_supply_gregset = i386nto_supply_gregset;
+ nto_supply_fpregset = i386nto_supply_fpregset;
+ nto_supply_altregset = nto_dummy_supply_regset;
+ nto_supply_regset = i386nto_supply_regset;
+ nto_register_area = i386nto_register_area;
+ nto_regset_fill = i386nto_regset_fill;
+ nto_fetch_link_map_offsets = i386nto_svr4_fetch_link_map_offsets;
}

static void
@@ -274,6 +273,9 @@
{
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);

+ /* Deal with our strange signals. */
+ nto_initialize_signals ();
+
/* NTO uses ELF. */
i386_elf_init_abi (info, gdbarch);

@@ -301,6 +303,9 @@
/* Supply a nice function to find our solibs. */
TARGET_SO_FIND_AND_OPEN_SOLIB = nto_find_and_open_solib;

+ /* Our linker code is in libc. */
+ TARGET_SO_IN_DYNSYM_RESOLVE_CODE = nto_in_dynsym_resolve_code;
+
init_i386nto_ops ();
}

@@ -309,4 +314,6 @@
{
gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_QNXNTO,
i386nto_init_abi);
+ gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_elf_flavour,
+ nto_elf_osabi_sniffer);
}
Index: nto-procfs.c
===================================================================
RCS file: /cvs/src/src/gdb/nto-procfs.c,v
retrieving revision 1.6
diff -u -r1.6 nto-procfs.c
--- nto-procfs.c 8 Oct 2004 20:29:47 -0000 1.6
+++ nto-procfs.c 19 Nov 2004 20:07:18 -0000
@@ -97,20 +97,26 @@
is required is because QNX node descriptors are transient so
we have to re-acquire them every time. */
static unsigned
-nto_node(void)
+nto_node (void)
{
unsigned node;

- if (ND_NODE_CMP(nto_procfs_node, ND_LOCAL_NODE) == 0)
+ if (ND_NODE_CMP (nto_procfs_node, ND_LOCAL_NODE) == 0)
return ND_LOCAL_NODE;

- node = netmgr_strtond(nto_procfs_path,0);
+ node = netmgr_strtond (nto_procfs_path, 0);
if (node == -1)
- error ("Lost the QNX node. Debug session probably over.");
+ error ("Lost the QNX node. Debug session probably over.");

return (node);
}

+static enum gdb_osabi
+procfs_is_nto_target (bfd *abfd)
+{
+ return GDB_OSABI_QNXNTO;
+}
+
/* This is called when we call 'target procfs <arg>' from the (gdb) prompt.
For QNX6 (nto), the only valid arg will be a QNX node string,
eg: "/net/some_node". If arg is not a valid QNX node, we will
@@ -124,6 +130,8 @@
int fd, total_size;
procfs_sysinfo *sysinfo;

+ nto_is_nto_target = procfs_is_nto_target;
+
/* Set the default node used for spawning to this one,
and only override it if there is a valid arg. */

@@ -153,7 +161,8 @@
*endstr = 0;
}
}
- snprintf (nto_procfs_path, PATH_MAX - 1, "%s%s", nodestr ? nodestr : "", "/proc");
+ snprintf (nto_procfs_path, PATH_MAX - 1, "%s%s", nodestr ? nodestr : "",
+ "/proc");
if (nodestr)
xfree (nodestr);

@@ -271,7 +280,7 @@
if (dp == NULL)
{
fprintf_unfiltered (gdb_stderr, "failed to opendir \"%s\" - %d (%s)",
- nto_procfs_path, errno, safe_strerror (errno));
+ nto_procfs_path, errno, safe_strerror (errno));
return;
}

@@ -299,7 +308,7 @@
if (fd == -1)
{
fprintf_unfiltered (gdb_stderr, "failed to open %s - %d (%s)\n",
- buf, errno, safe_strerror (errno));
+ buf, errno, safe_strerror (errno));
closedir (dp);
return;
}
@@ -308,8 +317,8 @@
if (devctl (fd, DCMD_PROC_INFO, pidinfo, sizeof (buf), 0) != EOK)
{
fprintf_unfiltered (gdb_stderr,
- "devctl DCMD_PROC_INFO failed - %d (%s)\n", errno,
- safe_strerror (errno));
+ "devctl DCMD_PROC_INFO failed - %d (%s)\n",
+ errno, safe_strerror (errno));
break;
}
num_threads = pidinfo->num_threads;
@@ -375,7 +384,8 @@
err = devctl (ctl_fd, DCMD_PROC_MAPINFO, NULL, 0, &num);
if (err != EOK)
{
- printf ("failed devctl num mapinfos - %d (%s)\n", err, safe_strerror (err));
+ printf ("failed devctl num mapinfos - %d (%s)\n", err,
+ safe_strerror (err));
return;
}

@@ -565,7 +575,7 @@

if (devctl (ctl_fd, DCMD_PROC_STATUS, &status, sizeof (status), 0) == EOK
&& status.flags & _DEBUG_FLAG_STOPPED)
- SignalKill (nto_node(), PIDGET (ptid), 0, SIGCONT, 0, 0);
+ SignalKill (nto_node (), PIDGET (ptid), 0, SIGCONT, 0, 0);
attach_flag = 1;
nto_init_solib_absolute_prefix ();
return ptid;
@@ -778,7 +788,7 @@
siggnal = atoi (args);

if (siggnal)
- SignalKill (nto_node(), PIDGET (inferior_ptid), 0, siggnal, 0, 0);
+ SignalKill (nto_node (), PIDGET (inferior_ptid), 0, siggnal, 0, 0);

close (ctl_fd);
ctl_fd = -1;
@@ -868,8 +878,8 @@
{
if (signal_to_pass != status.info.si_signo)
{
- SignalKill (nto_node(), PIDGET (inferior_ptid), 0, signal_to_pass,
- 0, 0);
+ SignalKill (nto_node (), PIDGET (inferior_ptid), 0,
+ signal_to_pass, 0, 0);
run.flags |= _DEBUG_RUN_CLRFLT | _DEBUG_RUN_CLRSIG;
}
else /* Let it kill the program without telling us. */
@@ -892,7 +902,7 @@
{
if (!ptid_equal (inferior_ptid, null_ptid))
{
- SignalKill (nto_node(), PIDGET (inferior_ptid), 0, SIGKILL, 0, 0);
+ SignalKill (nto_node (), PIDGET (inferior_ptid), 0, SIGKILL, 0, 0);
close (ctl_fd);
}
inferior_ptid = null_ptid;
@@ -1042,7 +1052,7 @@

if (ND_NODE_CMP (nto_procfs_node, ND_LOCAL_NODE) != 0)
{
- inherit.nd = nto_node();
+ inherit.nd = nto_node ();
inherit.flags |= SPAWN_SETND;
inherit.flags &= ~SPAWN_EXEC;
}
@@ -1055,7 +1065,8 @@
sigprocmask (SIG_BLOCK, &set, NULL);

if (pid == -1)
- error ("Error spawning %s: %d (%s)", argv[0], errno, safe_strerror (errno));
+ error ("Error spawning %s: %d (%s)", argv[0], errno,
+ safe_strerror (errno));

if (fds[0] != STDIN_FILENO)
close (fds[0]);
@@ -1083,6 +1094,8 @@
|| (symfile_objfile != NULL && symfile_objfile->obfd != NULL))
SOLIB_CREATE_INFERIOR_HOOK (pid);
#endif
+ stop_soon = 0;
+ proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
}

static void
@@ -1324,7 +1337,6 @@

/* Set up trace and fault sets, as gdb expects them. */
sigemptyset (&run.trace);
- notice_signals ();

/* Stuff some information. */
nto_cpuinfo_flags = SYSPAGE_ENTRY (cpuinfo)->flags;
@@ -1332,6 +1344,8 @@

add_info ("pidlist", procfs_pidlist, "pidlist");
add_info ("meminfo", procfs_meminfo, "memory information");
+
+ nto_is_nto_target = procfs_is_nto_target;
}

Index: nto-tdep.c
===================================================================
RCS file: /cvs/src/src/gdb/nto-tdep.c,v
retrieving revision 1.9
diff -u -r1.9 nto-tdep.c
--- nto-tdep.c 30 Jul 2004 19:17:19 -0000 1.9
+++ nto-tdep.c 19 Nov 2004 20:07:18 -0000
@@ -86,10 +86,10 @@
int
nto_find_and_open_solib (char *solib, unsigned o_flags, char **temp_pathname)
{
- char *buf, arch_path[PATH_MAX], *nto_root, *endian;
+ char *buf, *arch_path, *nto_root, *endian, *base;
const char *arch;
- char *path_fmt = "%s/lib:%s/usr/lib:%s/usr/photon/lib\
-:%s/usr/photon/dll:%s/lib/dll";
+ int ret;
+#define PATH_FMT "%s/lib:%s/usr/lib:%s/usr/photon/lib:%s/usr/photon/dll:%s/lib/dll"

nto_root = nto_target ();
if (strcmp (TARGET_ARCHITECTURE->arch_name, "i386") == 0)
@@ -109,13 +109,38 @@
endian = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? "be" : "le";
}

+ /* In case nto_root is short, add strlen(solib)
+ so we can reuse arch_path below. */
+ arch_path =
+ alloca (strlen (nto_root) + strlen (arch) + strlen (endian) + 2 +
+ strlen (solib));
sprintf (arch_path, "%s/%s%s", nto_root, arch, endian);

- buf = alloca (strlen (path_fmt) + strlen (arch_path) * 5 + 1);
- sprintf (buf, path_fmt, arch_path, arch_path, arch_path, arch_path,
+ buf = alloca (strlen (PATH_FMT) + strlen (arch_path) * 5 + 1);
+ sprintf (buf, PATH_FMT, arch_path, arch_path, arch_path, arch_path,
arch_path);

- return openp (buf, OPF_TRY_CWD_FIRST, solib, o_flags, 0, temp_pathname);
+ /* Don't assume basename() isn't destructive. */
+ base = strrchr (solib, '/');
+ if (!base)
+ base = solib;
+ else
+ base++; /* Skip over '/'. */
+
+ ret = openp (buf, 1, base, o_flags, 0, temp_pathname);
+ if (ret < 0 && base != solib)
+ {
+ sprintf (arch_path, "/%s", solib);
+ ret = open (arch_path, o_flags, 0);
+ if (temp_pathname)
+ {
+ if (ret >= 0)
+ *temp_pathname = gdb_realpath (arch_path);
+ else
+ **temp_pathname = '\0';
+ }
+ }
+ return ret;
}

void
@@ -266,6 +291,53 @@
sec->endaddr = nto_truncate_ptr (sec->endaddr + LM_ADDR (so) - vaddr);
}

+/* This is cheating a bit because our linker code is in libc.so. If we
+ ever implement lazy linking, this may need to be re-examined. */
+int
+nto_in_dynsym_resolve_code (CORE_ADDR pc)
+{
+ if (in_plt_section (pc, NULL))
+ return 1;
+ return 0;
+}
+
+void
+nto_generic_supply_gpregset (const struct regset *regset,
+ struct regcache *regcache, int regnum,
+ const void *gregs, size_t len)
+{
+}
+
+void
+nto_generic_supply_fpregset (const struct regset *regset,
+ struct regcache *regcache, int regnum,
+ const void *fpregs, size_t len)
+{
+}
+
+void
+nto_generic_supply_altregset (const struct regset *regset,
+ struct regcache *regcache, int regnum,
+ const void *altregs, size_t len)
+{
+}
+
+void
+nto_dummy_supply_regset (char *regs)
+{
+ /* Do nothing. */
+}
+
+enum gdb_osabi
+nto_elf_osabi_sniffer (bfd *abfd)
+{
+ if (nto_is_nto_target)
+ {
+ return nto_is_nto_target (abfd);
+ }
+ return GDB_OSABI_UNKNOWN;
+}
+
static void
fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
int which, CORE_ADDR reg_addr)
@@ -287,12 +359,6 @@
}
}

-void
-nto_dummy_supply_regset (char *regs)
-{
- /* Do nothing. */
-}
-
/* Register that we are able to handle ELF file formats using standard
procfs "regset" structures. */
static struct core_fns regset_core_fns = {
@@ -304,18 +370,8 @@
};

void
-_initialize_nto_tdep (void)
+nto_initialize_signals (void)
{
- add_setshow_zinteger_cmd ("nto-debug", class_maintenance,
- &nto_internal_debugging, "\
-Set QNX NTO internal debugging.", "\
-Show QNX NTO internal debugging.", "\
-When non-zero, nto specific debug info is\n\
-displayed. Different information is displayed\n\
-for different positive values.", "\
-QNX NTO internal debugging is %s.",
- NULL, NULL, &setdebuglist, &showdebuglist);
-
/* We use SIG45 for pulses, or something, so nostop, noprint
and pass them. */
signal_stop_update (target_signal_from_name ("SIG45"), 0);
@@ -334,7 +390,19 @@
signal_print_update (SIGPHOTON, 0);
signal_pass_update (SIGPHOTON, 1);
#endif
+}

+void
+_initialize_nto_tdep (void)
+{
+ add_setshow_zinteger_cmd ("nto-debug", class_maintenance,
+ &nto_internal_debugging, "\
+Set QNX NTO internal debugging.", "\
+Show QNX NTO internal debugging.", "\
+When non-zero, nto specific debug info is\n\
+displayed. Different information is displayed\n\
+for different positive values.", "\
+QNX NTO internal debugging is %s.", NULL, NULL, &setdebuglist, &showdebuglist);
/* Register core file support. */
deprecated_add_core_fns (&regset_core_fns);
}
Index: nto-tdep.h
===================================================================
RCS file: /cvs/src/src/gdb/nto-tdep.h,v
retrieving revision 1.2
diff -u -r1.2 nto-tdep.h
--- nto-tdep.h 6 May 2003 16:47:47 -0000 1.2
+++ nto-tdep.h 19 Nov 2004 20:07:18 -0000
@@ -26,6 +26,8 @@

#include "defs.h"
#include "solist.h"
+#include "osabi.h"
+#include "regset.h"

/* Generic functions in nto-tdep.c. */

@@ -36,39 +38,38 @@

int proc_iterate_over_mappings (int (*func) (int, CORE_ADDR));

-void nto_relocate_section_addresses (struct so_list *, struct section_table *);
+void nto_relocate_section_addresses (struct so_list *,
+ struct section_table *);

int nto_map_arch_to_cputype (const char *);

int nto_find_and_open_solib (char *, unsigned, char **);

+enum gdb_osabi nto_elf_osabi_sniffer (bfd *abfd);
+
+void nto_initialize_signals (void);
+
+void nto_generic_supply_gpregset (const struct regset *, struct regcache *,
+ int, const void *, size_t);
+
+void nto_generic_supply_fpregset (const struct regset *, struct regcache *,
+ int, const void *, size_t);
+
+void nto_generic_supply_altregset (const struct regset *, struct regcache *,
+ int, const void *, size_t);
+
/* Dummy function for initializing nto_target_ops on targets which do
not define a particular regset. */
void nto_dummy_supply_regset (char *regs);

+int nto_in_dynsym_resolve_code (CORE_ADDR pc);
+
/* Target operations defined for Neutrino targets (<target>-nto-tdep.c). */

struct nto_target_ops
{
- int nto_internal_debugging;
- unsigned nto_cpuinfo_flags;
- int nto_cpuinfo_valid;
-
- int (*nto_regset_id) (int);
- void (*nto_supply_gregset) (char *);
- void (*nto_supply_fpregset) (char *);
- void (*nto_supply_altregset) (char *);
- void (*nto_supply_regset) (int, char *);
- int (*nto_register_area) (int, int, unsigned *);
- int (*nto_regset_fill) (int, char *);
- struct link_map_offsets *(*nto_fetch_link_map_offsets) (void);
-};
-
-extern struct nto_target_ops current_nto_target;
-
/* For 'maintenance debug nto-debug' command. */
-#define nto_internal_debugging \
- (current_nto_target.nto_internal_debugging)
+ int nto_internal_debugging;

/* The CPUINFO flags from the remote. Currently used by
i386 for fxsave but future proofing other hosts.
@@ -76,47 +77,69 @@
depending on our host/target. It would only be invalid
if we were talking to an older pdebug which didn't support
the cpuinfo message. */
-#define nto_cpuinfo_flags \
- (current_nto_target.nto_cpuinfo_flags)
+ unsigned nto_cpuinfo_flags;

/* True if successfully retrieved cpuinfo from remote. */
-#define nto_cpuinfo_valid \
- (current_nto_target.nto_cpuinfo_valid)
+ int nto_cpuinfo_valid;

/* Given a register, return an id that represents the Neutrino
regset it came from. If reg == -1 update all regsets. */
-#define nto_regset_id(reg) \
- (*current_nto_target.nto_regset_id) (reg)
+ int (*nto_regset_id) (int);

-#define nto_supply_gregset(regs) \
- (*current_nto_target.nto_supply_gregset) (regs)
+ void (*nto_supply_gregset) (char *);

-#define nto_supply_fpregset(regs) \
- (*current_nto_target.nto_supply_fpregset) (regs)
+ void (*nto_supply_fpregset) (char *);

-#define nto_supply_altregset(regs) \
- (*current_nto_target.nto_supply_altregset) (regs)
+ void (*nto_supply_altregset) (char *);

/* Given a regset, tell gdb about registers stored in data. */
-#define nto_supply_regset(regset, data) \
- (*current_nto_target.nto_supply_regset) (regset, data)
+ void (*nto_supply_regset) (int, char *);

/* Given a register and regset, calculate the offset into the regset
and stuff it into the last argument. If regno is -1, calculate the
size of the entire regset. Returns length of data, -1 if unknown
regset, 0 if unknown register. */
-#define nto_register_area(reg, regset, off) \
- (*current_nto_target.nto_register_area) (reg, regset, off)
+ int (*nto_register_area) (int, int, unsigned *);

/* Build the Neutrino register set info into the data buffer.
Return -1 if unknown regset, 0 otherwise. */
-#define nto_regset_fill(regset, data) \
- (*current_nto_target.nto_regset_fill) (regset, data)
+ int (*nto_regset_fill) (int, char *);

/* Gives the fetch_link_map_offsets function exposure outside of
solib-svr4.c so that we can override relocate_section_addresses(). */
-#define nto_fetch_link_map_offsets() \
- (*current_nto_target.nto_fetch_link_map_offsets) ()
+ struct link_map_offsets *(*nto_fetch_link_map_offsets) (void);
+
+/* Used by nto_elf_osabi_sniffer to determine if we're connected to an
+ Neutrino target. */
+ enum gdb_osabi (*nto_is_nto_target) (bfd *abfd);
+};
+
+extern struct nto_target_ops current_nto_target;
+
+#define nto_internal_debugging (current_nto_target.nto_internal_debugging)
+
+#define nto_cpuinfo_flags (current_nto_target.nto_cpuinfo_flags)
+
+#define nto_cpuinfo_valid (current_nto_target.nto_cpuinfo_valid)
+
+#define nto_regset_id (current_nto_target.nto_regset_id)
+
+#define nto_supply_gregset (current_nto_target.nto_supply_gregset)
+
+#define nto_supply_fpregset (current_nto_target.nto_supply_fpregset)
+
+#define nto_supply_altregset (current_nto_target.nto_supply_altregset)
+
+#define nto_supply_regset (current_nto_target.nto_supply_regset)
+
+#define nto_register_area (current_nto_target.nto_register_area)
+
+#define nto_regset_fill (current_nto_target.nto_regset_fill)
+
+#define nto_fetch_link_map_offsets \
+(current_nto_target.nto_fetch_link_map_offsets)
+
+#define nto_is_nto_target (current_nto_target.nto_is_nto_target)

/* Keep this consistant with neutrino syspage.h. */
enum