1/* Target-dependent, architecture-independent code for DICOS, for GDB. 2 3 Copyright (C) 2009-2020 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 "solib.h" 23#include "solib-target.h" 24#include "inferior.h" 25#include "dicos-tdep.h" 26#include "gdbarch.h" 27 28void 29dicos_init_abi (struct gdbarch *gdbarch) 30{ 31 set_solib_ops (gdbarch, &solib_target_so_ops); 32 33 /* Every process, although has its own address space, sees the same 34 list of shared libraries. There's no "main executable" in DICOS, 35 so this accounts for all code. */ 36 set_gdbarch_has_global_solist (gdbarch, 1); 37 38 /* The DICOS breakpoint API takes care of magically making 39 breakpoints visible to all inferiors. */ 40 set_gdbarch_has_global_breakpoints (gdbarch, 1); 41 42 /* There's no (standard definition of) entry point or a guaranteed 43 text location with a symbol where to place the call dummy, so we 44 need it on the stack. Rely on i386_gdbarch_init used also for 45 amd64 to set up ON_STACK inferior calls. */ 46 47 /* DICOS rewinds the PC itself. */ 48 set_gdbarch_decr_pc_after_break (gdbarch, 0); 49} 50 51/* Return true if ABFD is a dicos load module. HEADER_SIZE is the 52 expected size of the "header" section in bytes. */ 53 54int 55dicos_load_module_p (bfd *abfd, int header_size) 56{ 57 long storage_needed; 58 int ret = 0; 59 asymbol **symbol_table = NULL; 60 const char *symname = "Dicos_loadModuleInfo"; 61 asection *section; 62 63 /* DICOS files don't have a .note.ABI-tag marker or something 64 similar. We do know there's always a "header" section of 65 HEADER_SIZE bytes (size depends on architecture), and there's 66 always a "Dicos_loadModuleInfo" symbol defined. Look for the 67 section first, as that should be cheaper. */ 68 69 section = bfd_get_section_by_name (abfd, "header"); 70 if (!section) 71 return 0; 72 73 if (bfd_section_size (section) != header_size) 74 return 0; 75 76 /* Dicos LMs always have a "Dicos_loadModuleInfo" symbol 77 defined. Look for it. */ 78 79 storage_needed = bfd_get_symtab_upper_bound (abfd); 80 if (storage_needed < 0) 81 { 82 warning (_("Can't read elf symbols from %s: %s"), 83 bfd_get_filename (abfd), 84 bfd_errmsg (bfd_get_error ())); 85 return 0; 86 } 87 88 if (storage_needed > 0) 89 { 90 long i, symcount; 91 92 symbol_table = (asymbol **) xmalloc (storage_needed); 93 symcount = bfd_canonicalize_symtab (abfd, symbol_table); 94 95 if (symcount < 0) 96 warning (_("Can't read elf symbols from %s: %s"), 97 bfd_get_filename (abfd), 98 bfd_errmsg (bfd_get_error ())); 99 else 100 { 101 for (i = 0; i < symcount; i++) 102 { 103 asymbol *sym = symbol_table[i]; 104 if (sym->name != NULL 105 && symname[0] == sym->name[0] 106 && strcmp (symname + 1, sym->name + 1) == 0) 107 { 108 ret = 1; 109 break; 110 } 111 } 112 } 113 } 114 115 xfree (symbol_table); 116 return ret; 117} 118