GDB (API)
/home/stan/gdb/src/gdb/i386bsd-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent code for i386 BSD's.
00002 
00003    Copyright (C) 2001-2013 Free Software Foundation, Inc.
00004 
00005    This file is part of GDB.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 3 of the License, or
00010    (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00019 
00020 #include "defs.h"
00021 #include "arch-utils.h"
00022 #include "frame.h"
00023 #include "gdbcore.h"
00024 #include "regcache.h"
00025 #include "osabi.h"
00026 
00027 #include "gdb_string.h"
00028 
00029 #include "i386-tdep.h"
00030 
00031 /* Support for signal handlers.  */
00032 
00033 /* Assuming THIS_FRAME is for a BSD sigtramp routine, return the
00034    address of the associated sigcontext structure.  */
00035 
00036 static CORE_ADDR
00037 i386bsd_sigcontext_addr (struct frame_info *this_frame)
00038 {
00039   struct gdbarch *gdbarch = get_frame_arch (this_frame);
00040   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
00041   gdb_byte buf[4];
00042   CORE_ADDR sp;
00043 
00044   get_frame_register (this_frame, I386_ESP_REGNUM, buf);
00045   sp = extract_unsigned_integer (buf, 4, byte_order);
00046 
00047   return read_memory_unsigned_integer (sp + 8, 4, byte_order);
00048 }
00049 
00050 
00051 /* Support for shared libraries.  */
00052 
00053 /* Traditional BSD (4.3 BSD, still used for BSDI and 386BSD).  */
00054 
00055 /* From <machine/signal.h>.  */
00056 int i386bsd_sc_reg_offset[] =
00057 {
00058   -1,                           /* %eax */
00059   -1,                           /* %ecx */
00060   -1,                           /* %edx */
00061   -1,                           /* %ebx */
00062   8 + 0 * 4,                    /* %esp */
00063   8 + 1 * 4,                    /* %ebp */
00064   -1,                           /* %esi */
00065   -1,                           /* %edi */
00066   8 + 3 * 4,                    /* %eip */
00067   8 + 4 * 4,                    /* %eflags */
00068   -1,                           /* %cs */
00069   -1,                           /* %ss */
00070   -1,                           /* %ds */
00071   -1,                           /* %es */
00072   -1,                           /* %fs */
00073   -1                            /* %gs */
00074 };
00075 
00076 void
00077 i386bsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
00078 {
00079   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00080 
00081   tdep->jb_pc_offset = 0;
00082 
00083   tdep->sigtramp_start = 0xfdbfdfc0;
00084   tdep->sigtramp_end = 0xfdbfe000;
00085   tdep->sigcontext_addr = i386bsd_sigcontext_addr;
00086   tdep->sc_reg_offset = i386bsd_sc_reg_offset;
00087   tdep->sc_num_regs = ARRAY_SIZE (i386bsd_sc_reg_offset);
00088 }
00089 
00090 
00091 static enum gdb_osabi
00092 i386bsd_aout_osabi_sniffer (bfd *abfd)
00093 {
00094   if (strcmp (bfd_get_target (abfd), "a.out-i386-netbsd") == 0)
00095     return GDB_OSABI_NETBSD_AOUT;
00096 
00097   if (strcmp (bfd_get_target (abfd), "a.out-i386-freebsd") == 0)
00098     return GDB_OSABI_FREEBSD_AOUT;
00099 
00100   return GDB_OSABI_UNKNOWN;
00101 }
00102 
00103 static enum gdb_osabi
00104 i386bsd_core_osabi_sniffer (bfd *abfd)
00105 {
00106   if (strcmp (bfd_get_target (abfd), "netbsd-core") == 0)
00107     return GDB_OSABI_NETBSD_AOUT;
00108 
00109   return GDB_OSABI_UNKNOWN;
00110 }
00111 
00112 
00113 /* Provide a prototype to silence -Wmissing-prototypes.  */
00114 void _initialize_i386bsd_tdep (void);
00115 
00116 void
00117 _initialize_i386bsd_tdep (void)
00118 {
00119   gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_aout_flavour,
00120                                   i386bsd_aout_osabi_sniffer);
00121 
00122   /* BFD doesn't set a flavour for NetBSD style a.out core files.  */
00123   gdbarch_register_osabi_sniffer (bfd_arch_i386, bfd_target_unknown_flavour,
00124                                   i386bsd_core_osabi_sniffer);
00125 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines