* i386-dicos-tdep.c: Include "inferior.h".
[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 #include "inferior.h"
26
27 static CORE_ADDR
28 i386_dicos_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
29 {
30 /* Having a call dummy on the stack requires a gdbarch_frame_align
31 method to align the breakpoint instruction in the stack.
32 Strictly speaking, we could just return SP pristine on x86. But,
33 as long as we're providing a frame align method, might as well
34 align for efficiency. */
35 return sp & -(CORE_ADDR)16;
36 }
37
38 static void
39 i386_dicos_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
40 {
41 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
42
43 set_solib_ops (gdbarch, &solib_target_so_ops);
44
45 /* There's no (standard definition of) entry point or a guaranteed
46 text location we could find with a symbol where to place the call
47 dummy, so we put it on the stack. */
48 set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
49 set_gdbarch_frame_align (gdbarch, i386_dicos_frame_align);
50 }
51
52 /* Look in the elf symbol table of ABFD for a symbol named WANTED.
53 Return true if found. */
54 static int
55 i386_dicos_bfd_has_symbol_p (bfd *abfd, const char *wanted)
56 {
57 long storage_needed;
58 int ret = 0;
59 asymbol **symbol_table = NULL;
60
61 storage_needed = bfd_get_symtab_upper_bound (abfd);
62 if (storage_needed < 0)
63 {
64 warning (_("Can't read elf symbols from %s: %s"), bfd_get_filename (abfd),
65 bfd_errmsg (bfd_get_error ()));
66 return 0;
67 }
68
69 if (storage_needed > 0)
70 {
71 long i, symcount;
72
73 symbol_table = xmalloc (storage_needed);
74 symcount = bfd_canonicalize_symtab (abfd, symbol_table);
75
76 if (symcount < 0)
77 warning (_("Can't read elf symbols from %s: %s"),
78 bfd_get_filename (abfd),
79 bfd_errmsg (bfd_get_error ()));
80 else
81 {
82 for (i = 0; i < symcount; i++)
83 {
84 asymbol *sym = symbol_table[i];
85 if (sym->name != NULL
86 && wanted[0] == sym->name[0]
87 && strcmp (wanted + 1, sym->name + 1) == 0)
88 {
89 ret = 1;
90 break;
91 }
92 }
93 }
94 }
95
96 xfree (symbol_table);
97 return ret;
98 }
99
100 static enum gdb_osabi
101 i386_dicos_osabi_sniffer (bfd *abfd)
102 {
103 char *target_name = bfd_get_target (abfd);
104
105 /* DICOS debug info files don't have a .note.ABI-tag marker or
106 something similar. We do know there's always a "header" section
107 of 36 bytes, and there's always a "Dicos_loadModuleInfo" symbol
108 defined. Look for the section first, as that should be
109 cheaper. */
110 if (strcmp (target_name, "elf32-i386") == 0)
111 {
112 asection *section = bfd_get_section_by_name (abfd, "header");
113 if (section
114 && bfd_section_size (abfd, section) == 36
115 && i386_dicos_bfd_has_symbol_p (abfd, "Dicos_loadModuleInfo"))
116 return GDB_OSABI_DICOS;
117 }
118
119 return GDB_OSABI_UNKNOWN;
120 }
121
122 /* Provide a prototype to silence -Wmissing-prototypes. */
123 void _initialize_i386_dicos_tdep (void);
124
125 void
126 _initialize_i386_dicos_tdep (void)
127 {
128 gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_elf_flavour,
129 i386_dicos_osabi_sniffer);
130
131 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_DICOS,
132 i386_dicos_init_abi);
133 }
This page took 0.035247 seconds and 5 git commands to generate.