dicos-tdep.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* Target-dependent, architecture-independent code for DICOS, for GDB.
  2. Copyright (C) 2009-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include "defs.h"
  15. #include "osabi.h"
  16. #include "solib.h"
  17. #include "solib-target.h"
  18. #include "inferior.h"
  19. #include "dicos-tdep.h"
  20. #include "gdbarch.h"
  21. void
  22. dicos_init_abi (struct gdbarch *gdbarch)
  23. {
  24. set_solib_ops (gdbarch, &solib_target_so_ops);
  25. /* Every process, although has its own address space, sees the same
  26. list of shared libraries. There's no "main executable" in DICOS,
  27. so this accounts for all code. */
  28. set_gdbarch_has_global_solist (gdbarch, 1);
  29. /* The DICOS breakpoint API takes care of magically making
  30. breakpoints visible to all inferiors. */
  31. set_gdbarch_has_global_breakpoints (gdbarch, 1);
  32. /* There's no (standard definition of) entry point or a guaranteed
  33. text location with a symbol where to place the call dummy, so we
  34. need it on the stack. Rely on i386_gdbarch_init used also for
  35. amd64 to set up ON_STACK inferior calls. */
  36. /* DICOS rewinds the PC itself. */
  37. set_gdbarch_decr_pc_after_break (gdbarch, 0);
  38. }
  39. /* Return true if ABFD is a dicos load module. HEADER_SIZE is the
  40. expected size of the "header" section in bytes. */
  41. int
  42. dicos_load_module_p (bfd *abfd, int header_size)
  43. {
  44. long storage_needed;
  45. int ret = 0;
  46. asymbol **symbol_table = NULL;
  47. const char *symname = "Dicos_loadModuleInfo";
  48. asection *section;
  49. /* DICOS files don't have a .note.ABI-tag marker or something
  50. similar. We do know there's always a "header" section of
  51. HEADER_SIZE bytes (size depends on architecture), and there's
  52. always a "Dicos_loadModuleInfo" symbol defined. Look for the
  53. section first, as that should be cheaper. */
  54. section = bfd_get_section_by_name (abfd, "header");
  55. if (!section)
  56. return 0;
  57. if (bfd_section_size (section) != header_size)
  58. return 0;
  59. /* Dicos LMs always have a "Dicos_loadModuleInfo" symbol
  60. defined. Look for it. */
  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"),
  65. bfd_get_filename (abfd),
  66. bfd_errmsg (bfd_get_error ()));
  67. return 0;
  68. }
  69. if (storage_needed > 0)
  70. {
  71. long i, symcount;
  72. symbol_table = (asymbol **) xmalloc (storage_needed);
  73. symcount = bfd_canonicalize_symtab (abfd, symbol_table);
  74. if (symcount < 0)
  75. warning (_("Can't read elf symbols from %s: %s"),
  76. bfd_get_filename (abfd),
  77. bfd_errmsg (bfd_get_error ()));
  78. else
  79. {
  80. for (i = 0; i < symcount; i++)
  81. {
  82. asymbol *sym = symbol_table[i];
  83. if (sym->name != NULL
  84. && symname[0] == sym->name[0]
  85. && strcmp (symname + 1, sym->name + 1) == 0)
  86. {
  87. ret = 1;
  88. break;
  89. }
  90. }
  91. }
  92. }
  93. xfree (symbol_table);
  94. return ret;
  95. }