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
, "ppc"))
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)
107 arch
= TARGET_ARCHITECTURE
->arch_name
;
108 endian
= TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
? "be" : "le";
111 sprintf (arch_path
, "%s/%s%s", nto_root
, arch
, endian
);
113 buf
= alloca (strlen (path_fmt
) + strlen (arch_path
) * 5 + 1);
114 sprintf (buf
, path_fmt
, arch_path
, arch_path
, arch_path
, arch_path
,
117 return openp (buf
, 1, solib
, o_flags
, 0, temp_pathname
);
121 nto_init_solib_absolute_prefix (void)
123 char buf
[PATH_MAX
* 2], arch_path
[PATH_MAX
];
124 char *nto_root
, *endian
;
127 nto_root
= nto_target ();
128 if (strcmp (TARGET_ARCHITECTURE
->arch_name
, "i386") == 0)
133 else if (strcmp (TARGET_ARCHITECTURE
->arch_name
, "rs6000") == 0)
140 arch
= TARGET_ARCHITECTURE
->arch_name
;
141 endian
= TARGET_BYTE_ORDER
== BFD_ENDIAN_BIG
? "be" : "le";
144 sprintf (arch_path
, "%s/%s%s", nto_root
, arch
, endian
);
146 sprintf (buf
, "set solib-absolute-prefix %s", arch_path
);
147 execute_command (buf
, 0);
151 nto_parse_redirection (char *pargv
[], char **pin
, char **pout
, char **perr
)
154 char *in
, *out
, *err
, *p
;
157 for (n
= 0; pargv
[n
]; n
++);
164 argv
= xcalloc (n
+ 1, sizeof argv
[0]);
166 for (i
= 0, n
= 0; n
< argc
; n
++)
185 else if (*p
++ == '2' && *p
++ == '>')
187 if (*p
== '&' && *(p
+ 1) == '1')
195 argv
[i
++] = pargv
[n
];
203 /* The struct lm_info, LM_ADDR, and nto_truncate_ptr are copied from
204 solib-svr4.c to support nto_relocate_section_addresses
205 which is different from the svr4 version. */
209 /* Pointer to copy of link map from inferior. The type is char *
210 rather than void *, so that we may use byte offsets to find the
211 various fields without the need for a cast. */
216 LM_ADDR (struct so_list
*so
)
218 struct link_map_offsets
*lmo
= nto_fetch_link_map_offsets ();
220 return (CORE_ADDR
) extract_signed_integer (so
->lm_info
->lm
+
226 nto_truncate_ptr (CORE_ADDR addr
)
228 if (TARGET_PTR_BIT
== sizeof (CORE_ADDR
) * 8)
229 /* We don't need to truncate anything, and the bit twiddling below
230 will fail due to overflow problems. */
233 return addr
& (((CORE_ADDR
) 1 << TARGET_PTR_BIT
) - 1);
237 find_load_phdr (bfd
*abfd
)
239 Elf_Internal_Phdr
*phdr
;
242 if (!elf_tdata (abfd
))
245 phdr
= elf_tdata (abfd
)->phdr
;
246 for (i
= 0; i
< elf_elfheader (abfd
)->e_phnum
; i
++, phdr
++)
248 if (phdr
->p_type
== PT_LOAD
&& (phdr
->p_flags
& PF_X
))
255 nto_relocate_section_addresses (struct so_list
*so
, struct section_table
*sec
)
257 /* Neutrino treats the l_addr base address field in link.h as different than
258 the base address in the System V ABI and so the offset needs to be
259 calculated and applied to relocations. */
260 Elf_Internal_Phdr
*phdr
= find_load_phdr (sec
->bfd
);
261 unsigned vaddr
= phdr
? phdr
->p_vaddr
: 0;
263 sec
->addr
= nto_truncate_ptr (sec
->addr
+ LM_ADDR (so
) - vaddr
);
264 sec
->endaddr
= nto_truncate_ptr (sec
->endaddr
+ LM_ADDR (so
) - vaddr
);
268 fetch_core_registers (char *core_reg_sect
, unsigned core_reg_size
,
269 int which
, CORE_ADDR reg_addr
)
273 /* See corelow.c:get_core_registers for values of WHICH. */
276 memcpy ((char *) ®set
, core_reg_sect
,
277 min (core_reg_size
, sizeof (regset
)));
278 nto_supply_gregset ((char *) ®set
);
282 memcpy ((char *) ®set
, core_reg_sect
,
283 min (core_reg_size
, sizeof (regset
)));
284 nto_supply_fpregset ((char *) ®set
);
289 nto_dummy_supply_regset (char *regs
)
294 /* Register that we are able to handle ELF file formats using standard
295 procfs "regset" structures. */
296 static struct core_fns regset_core_fns
= {
297 bfd_target_elf_flavour
, /* core_flavour */
298 default_check_format
, /* check_format */
299 default_core_sniffer
, /* core_sniffer */
300 fetch_core_registers
, /* core_read_registers */
305 _initialize_nto_tdep (void)
307 add_setshow_cmd ("nto-debug", class_maintenance
, var_zinteger
,
308 &nto_internal_debugging
, "Set QNX NTO internal debugging.\n\
309 When non-zero, nto specific debug info is\n\
310 displayed. Different information is displayed\n\
311 for different positive values.", "Show QNX NTO internal debugging.\n",
312 NULL
, NULL
, &setdebuglist
, &showdebuglist
);
314 /* We use SIG45 for pulses, or something, so nostop, noprint
316 signal_stop_update (target_signal_from_name ("SIG45"), 0);
317 signal_print_update (target_signal_from_name ("SIG45"), 0);
318 signal_pass_update (target_signal_from_name ("SIG45"), 1);
320 /* By default we don't want to stop on these two, but we do want to pass. */
321 #if defined(SIGSELECT)
322 signal_stop_update (SIGSELECT
, 0);
323 signal_print_update (SIGSELECT
, 0);
324 signal_pass_update (SIGSELECT
, 1);
327 #if defined(SIGPHOTON)
328 signal_stop_update (SIGPHOTON
, 0);
329 signal_print_update (SIGPHOTON
, 0);
330 signal_pass_update (SIGPHOTON
, 1);
333 /* Register core file support. */
334 add_core_fns (®set_core_fns
);