GDB (API)
/home/stan/gdb/src/gdb/dicos-tdep.c
Go to the documentation of this file.
00001 /* Target-dependent, architecture-independent code for DICOS, for GDB.
00002 
00003    Copyright (C) 2009-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 "osabi.h"
00022 #include "gdb_string.h"
00023 #include "solib.h"
00024 #include "solib-target.h"
00025 #include "inferior.h"
00026 #include "dicos-tdep.h"
00027 
00028 void
00029 dicos_init_abi (struct gdbarch *gdbarch)
00030 {
00031   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
00032 
00033   set_solib_ops (gdbarch, &solib_target_so_ops);
00034 
00035   /* Every process, although has its own address space, sees the same
00036      list of shared libraries.  There's no "main executable" in DICOS,
00037      so this accounts for all code.  */
00038   set_gdbarch_has_global_solist (gdbarch, 1);
00039 
00040   /* The DICOS breakpoint API takes care of magically making
00041      breakpoints visible to all inferiors.  */
00042   set_gdbarch_has_global_breakpoints (gdbarch, 1);
00043 
00044   /* There's no (standard definition of) entry point or a guaranteed
00045      text location with a symbol where to place the call dummy, so we
00046      need it on the stack.  Rely on i386_gdbarch_init used also for
00047      amd64 to set up ON_STACK inferior calls.  */
00048 
00049   /* DICOS rewinds the PC itself.  */
00050   set_gdbarch_decr_pc_after_break (gdbarch, 0);
00051 }
00052 
00053 /* Return true if ABFD is a dicos load module.  HEADER_SIZE is the
00054    expected size of the "header" section in bytes.  */
00055 
00056 int
00057 dicos_load_module_p (bfd *abfd, int header_size)
00058 {
00059   long storage_needed;
00060   int ret = 0;
00061   asymbol **symbol_table = NULL;
00062   const char *symname = "Dicos_loadModuleInfo";
00063   asection *section;
00064 
00065   /* DICOS files don't have a .note.ABI-tag marker or something
00066      similar.  We do know there's always a "header" section of
00067      HEADER_SIZE bytes (size depends on architecture), and there's
00068      always a "Dicos_loadModuleInfo" symbol defined.  Look for the
00069      section first, as that should be cheaper.  */
00070 
00071   section = bfd_get_section_by_name (abfd, "header");
00072   if (!section)
00073     return 0;
00074 
00075   if (bfd_section_size (abfd, section) != header_size)
00076     return 0;
00077 
00078   /* Dicos LMs always have a "Dicos_loadModuleInfo" symbol
00079      defined.  Look for it.  */
00080 
00081   storage_needed = bfd_get_symtab_upper_bound (abfd);
00082   if (storage_needed < 0)
00083     {
00084       warning (_("Can't read elf symbols from %s: %s"),
00085                bfd_get_filename (abfd),
00086                bfd_errmsg (bfd_get_error ()));
00087       return 0;
00088     }
00089 
00090   if (storage_needed > 0)
00091     {
00092       long i, symcount;
00093 
00094       symbol_table = xmalloc (storage_needed);
00095       symcount = bfd_canonicalize_symtab (abfd, symbol_table);
00096 
00097       if (symcount < 0)
00098         warning (_("Can't read elf symbols from %s: %s"),
00099                  bfd_get_filename (abfd),
00100                  bfd_errmsg (bfd_get_error ()));
00101       else
00102         {
00103           for (i = 0; i < symcount; i++)
00104             {
00105               asymbol *sym = symbol_table[i];
00106               if (sym->name != NULL
00107                   && symname[0] == sym->name[0]
00108                   && strcmp (symname + 1, sym->name + 1) == 0)
00109                 {
00110                   ret = 1;
00111                   break;
00112                 }
00113             }
00114         }
00115     }
00116 
00117   xfree (symbol_table);
00118   return ret;
00119 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines