* configure.tgt: Add i[34567]86-*-dicos* and x86_64-*-dicos*.
[deliverable/binutils-gdb.git] / gdb / i386-dicos-tdep.c
1 /* Target-dependent code for DICOS running on i386's, for GDB.
2
3 Copyright (C) 2008 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "osabi.h"
22 #include "gdb_string.h"
23 #include "solib.h"
24 #include "solib-target.h"
25
26 static void
27 i386_dicos_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
28 {
29 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
30
31 set_solib_ops (gdbarch, &solib_target_so_ops);
32 }
33
34 /* Look in the elf symbol table of ABFD for a symbol named WANTED.
35 Return true if found. */
36 static int
37 i386_dicos_bfd_has_symbol_p (bfd *abfd, const char *wanted)
38 {
39 long storage_needed;
40 int ret = 0;
41 asymbol **symbol_table = NULL;
42
43 storage_needed = bfd_get_symtab_upper_bound (abfd);
44 if (storage_needed < 0)
45 {
46 warning (_("Can't read elf symbols from %s: %s"), bfd_get_filename (abfd),
47 bfd_errmsg (bfd_get_error ()));
48 return 0;
49 }
50
51 if (storage_needed > 0)
52 {
53 long i, symcount;
54
55 symbol_table = xmalloc (storage_needed);
56 symcount = bfd_canonicalize_symtab (abfd, symbol_table);
57
58 if (symcount < 0)
59 warning (_("Can't read elf symbols from %s: %s"),
60 bfd_get_filename (abfd),
61 bfd_errmsg (bfd_get_error ()));
62 else
63 {
64 for (i = 0; i < symcount; i++)
65 {
66 asymbol *sym = symbol_table[i];
67 if (sym->name != NULL
68 && wanted[0] == sym->name[0]
69 && strcmp (wanted + 1, sym->name + 1) == 0)
70 {
71 ret = 1;
72 break;
73 }
74 }
75 }
76 }
77
78 xfree (symbol_table);
79 return ret;
80 }
81
82 static enum gdb_osabi
83 i386_dicos_osabi_sniffer (bfd *abfd)
84 {
85 char *target_name = bfd_get_target (abfd);
86
87 /* DICOS debug info files don't have a .note.ABI-tag marker or
88 something similar. We do know there's always a "header" section
89 of 36 bytes, and there's always a "Dicos_loadModuleInfo" symbol
90 defined. Look for the section first, as that should be
91 cheaper. */
92 if (strcmp (target_name, "elf32-i386") == 0)
93 {
94 asection *section = bfd_get_section_by_name (abfd, "header");
95 if (section
96 && bfd_section_size (abfd, section) == 36
97 && i386_dicos_bfd_has_symbol_p (abfd, "Dicos_loadModuleInfo"))
98 return GDB_OSABI_DICOS;
99 }
100
101 return GDB_OSABI_UNKNOWN;
102 }
103
104 /* Provide a prototype to silence -Wmissing-prototypes. */
105 void _initialize_i386_dicos_tdep (void);
106
107 void
108 _initialize_i386_dicos_tdep (void)
109 {
110 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_elf_flavour,
111 i386_dicos_osabi_sniffer);
112
113 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_DICOS,
114 i386_dicos_init_abi);
115 }
This page took 0.055154 seconds and 5 git commands to generate.