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 23 Mar 2004 21:07:41 -0000 @@ -26,6 +26,7 @@ #include "defs.h" #include "solist.h" +#include "osabi.h" /* Generic functions in nto-tdep.c. */ @@ -36,39 +37,29 @@ 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); + /* 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 (-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 +67,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 Index: nto-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/nto-tdep.c,v retrieving revision 1.6 diff -u -r1.6 nto-tdep.c --- nto-tdep.c 17 Jun 2003 18:30:48 -0000 1.6 +++ nto-tdep.c 23 Mar 2004 21:07:41 -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, 1, 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 @@ -287,32 +312,51 @@ } } +/* 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) +{ + return 0; +} + void nto_dummy_supply_regset (char *regs) { /* Do nothing. */ } +static int +nto_core_sniffer (struct core_fns *our_fns, bfd *abfd) +{ + if (bfd_get_section_by_name (abfd, ".qnx_core_info")) + return 1; + return default_core_sniffer (our_fns, abfd); +} + +enum gdb_osabi +nto_elf_osabi_sniffer (bfd *abfd) +{ + if (nto_is_nto_target) + { + return nto_is_nto_target (abfd); + } + return GDB_OSABI_UNKNOWN; +} + /* Register that we are able to handle ELF file formats using standard procfs "regset" structures. */ static struct core_fns regset_core_fns = { bfd_target_elf_flavour, /* core_flavour */ default_check_format, /* check_format */ - default_core_sniffer, /* core_sniffer */ + nto_core_sniffer, /* core_sniffer */ fetch_core_registers, /* core_read_registers */ NULL /* next */ }; void -_initialize_nto_tdep (void) +nto_initialize_signals (void) { - add_setshow_cmd ("nto-debug", class_maintenance, var_zinteger, - &nto_internal_debugging, "Set QNX NTO internal debugging.\n\ -When non-zero, nto specific debug info is\n\ -displayed. Different information is displayed\n\ -for different positive values.", "Show QNX NTO internal debugging.\n", - 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); @@ -331,6 +375,17 @@ signal_print_update (SIGPHOTON, 0); signal_pass_update (SIGPHOTON, 1); #endif +} + +void +_initialize_nto_tdep (void) +{ + add_setshow_cmd ("nto-debug", class_maintenance, var_zinteger, + &nto_internal_debugging, "Set QNX NTO internal debugging.\n\ +When non-zero, nto specific debug info is\n\ +displayed. Different information is displayed\n\ +for different positive values.", "Show QNX NTO internal debugging.\n", + NULL, NULL, &setdebuglist, &showdebuglist); /* Register core file support. */ add_core_fns (®set_core_fns); Index: i386-nto-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/i386-nto-tdep.c,v retrieving revision 1.10 diff -u -r1.10 i386-nto-tdep.c --- i386-nto-tdep.c 23 Mar 2004 14:47:56 -0000 1.10 +++ i386-nto-tdep.c 23 Mar 2004 21:07:41 -0000 @@ -251,15 +251,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 @@ -267,6 +266,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); @@ -295,6 +297,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 (); } @@ -303,4 +308,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.3 diff -u -r1.3 nto-procfs.c --- nto-procfs.c 18 Jul 2003 17:15:33 -0000 1.3 +++ nto-procfs.c 23 Mar 2004 21:07:42 -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 ' 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; @@ -1041,7 +1051,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; } @@ -1054,7 +1064,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]); @@ -1082,6 +1093,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 @@ -1323,7 +1336,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; @@ -1331,6 +1343,8 @@ add_info ("pidlist", procfs_pidlist, "pidlist"); add_info ("meminfo", procfs_meminfo, "memory information"); + + nto_is_nto_target = procfs_is_nto_target; }