1 /* nto-tdep.c - general QNX Neutrino target functionality.
3 Copyright 2003 Free Software Foundation, Inc.
5 Contributed by QNX Software Systems Ltd.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
25 #include "gdb_string.h"
28 #include "cli/cli-decode.h"
29 #include "cli/cli-cmds.h"
34 #include "solib-svr4.h"
38 #include <sys/cygwin.h>
42 static char default_nto_target[] = "C:\\QNXsdk\\target\\qnx6";
43 #elif defined(__sun__) || defined(linux)
44 static char default_nto_target[] = "/opt/QNXsdk/target/qnx6";
46 static char default_nto_target[] = "";
49 struct nto_target_ops current_nto_target;
54 char *p = getenv ("QNX_TARGET");
57 static char buf[PATH_MAX];
59 cygwin_conv_to_posix_path (p, buf);
61 cygwin_conv_to_posix_path (default_nto_target, buf);
64 return p ? p : default_nto_target;
68 /* Take a string such as i386, rs6000, etc. and map it onto CPUTYPE_X86,
69 CPUTYPE_PPC, etc. as defined in nto-share/dsmsgs.h. */
71 nto_map_arch_to_cputype (const char *arch)
73 if (!strcmp (arch, "i386") || !strcmp (arch, "x86"))
75 if (!strcmp (arch, "rs6000") || !strcmp (arch, "powerpc"))
77 if (!strcmp (arch, "mips"))
79 if (!strcmp (arch, "arm"))
81 if (!strcmp (arch, "sh"))
83 return CPUTYPE_UNKNOWN;
87 nto_find_and_open_solib (char *solib, unsigned o_flags, char **temp_pathname)
89 char *buf, arch_path[PATH_MAX], *nto_root, *endian;
91 char *path_fmt = "%s/lib:%s/usr/lib:%s/usr/photon/lib\
92 :%s/usr/photon/dll:%s/lib/dll";
94 nto_root = nto_target ();
95 if (strcmp (TARGET_ARCHITECTURE->arch_name, "i386") == 0)
100 else if (strcmp (TARGET_ARCHITECTURE->arch_name, "rs6000") == 0
101 || strcmp (TARGET_ARCHITECTURE->arch_name, "powerpc") == 0)
108 arch = TARGET_ARCHITECTURE->arch_name;
109 endian = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? "be" : "le";
112 sprintf (arch_path, "%s/%s%s", nto_root, arch, endian);
114 buf = alloca (strlen (path_fmt) + strlen (arch_path) * 5 + 1);
115 sprintf (buf, path_fmt, arch_path, arch_path, arch_path, arch_path,
118 return openp (buf, 1, solib, o_flags, 0, temp_pathname);
122 nto_init_solib_absolute_prefix (void)
124 char buf[PATH_MAX * 2], arch_path[PATH_MAX];
125 char *nto_root, *endian;
128 nto_root = nto_target ();
129 if (strcmp (TARGET_ARCHITECTURE->arch_name, "i386") == 0)
134 else if (strcmp (TARGET_ARCHITECTURE->arch_name, "rs6000") == 0
135 || strcmp (TARGET_ARCHITECTURE->arch_name, "powerpc") == 0)
142 arch = TARGET_ARCHITECTURE->arch_name;
143 endian = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? "be" : "le";
146 sprintf (arch_path, "%s/%s%s", nto_root, arch, endian);
148 sprintf (buf, "set solib-absolute-prefix %s", arch_path);
149 execute_command (buf, 0);
153 nto_parse_redirection (char *pargv[], char **pin, char **pout, char **perr)
156 char *in, *out, *err, *p;
159 for (n = 0; pargv[n]; n++);
166 argv = xcalloc (n + 1, sizeof argv[0]);
168 for (i = 0, n = 0; n < argc; n++)
187 else if (*p++ == '2' && *p++ == '>')
189 if (*p == '&' && *(p + 1) == '1')
197 argv[i++] = pargv[n];
205 /* The struct lm_info, LM_ADDR, and nto_truncate_ptr are copied from
206 solib-svr4.c to support nto_relocate_section_addresses
207 which is different from the svr4 version. */
211 /* Pointer to copy of link map from inferior. The type is char *
212 rather than void *, so that we may use byte offsets to find the
213 various fields without the need for a cast. */
218 LM_ADDR (struct so_list *so)
220 struct link_map_offsets *lmo = nto_fetch_link_map_offsets ();
222 return (CORE_ADDR) extract_signed_integer (so->lm_info->lm +
228 nto_truncate_ptr (CORE_ADDR addr)
230 if (TARGET_PTR_BIT == sizeof (CORE_ADDR) * 8)
231 /* We don't need to truncate anything, and the bit twiddling below
232 will fail due to overflow problems. */
235 return addr & (((CORE_ADDR) 1 << TARGET_PTR_BIT) - 1);
239 find_load_phdr (bfd *abfd)
241 Elf_Internal_Phdr *phdr;
244 if (!elf_tdata (abfd))
247 phdr = elf_tdata (abfd)->phdr;
248 for (i = 0; i < elf_elfheader (abfd)->e_phnum; i++, phdr++)
250 if (phdr->p_type == PT_LOAD && (phdr->p_flags & PF_X))
257 nto_relocate_section_addresses (struct so_list *so, struct section_table *sec)
259 /* Neutrino treats the l_addr base address field in link.h as different than
260 the base address in the System V ABI and so the offset needs to be
261 calculated and applied to relocations. */
262 Elf_Internal_Phdr *phdr = find_load_phdr (sec->bfd);
263 unsigned vaddr = phdr ? phdr->p_vaddr : 0;
265 sec->addr = nto_truncate_ptr (sec->addr + LM_ADDR (so) - vaddr);
266 sec->endaddr = nto_truncate_ptr (sec->endaddr + LM_ADDR (so) - vaddr);
270 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
271 int which, CORE_ADDR reg_addr)
275 /* See corelow.c:get_core_registers for values of WHICH. */
278 memcpy ((char *) ®set, core_reg_sect,
279 min (core_reg_size, sizeof (regset)));
280 nto_supply_gregset ((char *) ®set);
284 memcpy ((char *) ®set, core_reg_sect,
285 min (core_reg_size, sizeof (regset)));
286 nto_supply_fpregset ((char *) ®set);
291 nto_dummy_supply_regset (char *regs)
296 /* Register that we are able to handle ELF file formats using standard
297 procfs "regset" structures. */
298 static struct core_fns regset_core_fns = {
299 bfd_target_elf_flavour, /* core_flavour */
300 default_check_format, /* check_format */
301 default_core_sniffer, /* core_sniffer */
302 fetch_core_registers, /* core_read_registers */
307 _initialize_nto_tdep (void)
309 add_setshow_cmd ("nto-debug", class_maintenance, var_zinteger,
310 &nto_internal_debugging, "Set QNX NTO internal debugging.\n\
311 When non-zero, nto specific debug info is\n\
312 displayed. Different information is displayed\n\
313 for different positive values.", "Show QNX NTO internal debugging.\n",
314 NULL, NULL, &setdebuglist, &showdebuglist);
316 /* We use SIG45 for pulses, or something, so nostop, noprint
318 signal_stop_update (target_signal_from_name ("SIG45"), 0);
319 signal_print_update (target_signal_from_name ("SIG45"), 0);
320 signal_pass_update (target_signal_from_name ("SIG45"), 1);
322 /* By default we don't want to stop on these two, but we do want to pass. */
323 #if defined(SIGSELECT)
324 signal_stop_update (SIGSELECT, 0);
325 signal_print_update (SIGSELECT, 0);
326 signal_pass_update (SIGSELECT, 1);
329 #if defined(SIGPHOTON)
330 signal_stop_update (SIGPHOTON, 0);
331 signal_print_update (SIGPHOTON, 0);
332 signal_pass_update (SIGPHOTON, 1);
335 /* Register core file support. */
336 add_core_fns (®set_core_fns);