frame-base.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* Definitions for frame address handler, for GDB, the GNU debugger.
  2. Copyright (C) 2003-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 "frame-base.h"
  16. #include "frame.h"
  17. #include "gdbsupport/gdb_obstack.h"
  18. #include "gdbarch.h"
  19. /* A default frame base implementations. If it wasn't for the old
  20. DEPRECATED_FRAME_LOCALS_ADDRESS and DEPRECATED_FRAME_ARGS_ADDRESS,
  21. these could be combined into a single function. All architectures
  22. really need to override this. */
  23. static CORE_ADDR
  24. default_frame_base_address (struct frame_info *this_frame, void **this_cache)
  25. {
  26. return get_frame_base (this_frame); /* sigh! */
  27. }
  28. static CORE_ADDR
  29. default_frame_locals_address (struct frame_info *this_frame, void **this_cache)
  30. {
  31. return default_frame_base_address (this_frame, this_cache);
  32. }
  33. static CORE_ADDR
  34. default_frame_args_address (struct frame_info *this_frame, void **this_cache)
  35. {
  36. return default_frame_base_address (this_frame, this_cache);
  37. }
  38. const struct frame_base default_frame_base = {
  39. NULL, /* No parent. */
  40. default_frame_base_address,
  41. default_frame_locals_address,
  42. default_frame_args_address
  43. };
  44. static struct gdbarch_data *frame_base_data;
  45. struct frame_base_table_entry
  46. {
  47. frame_base_sniffer_ftype *sniffer;
  48. struct frame_base_table_entry *next;
  49. };
  50. struct frame_base_table
  51. {
  52. struct frame_base_table_entry *head;
  53. struct frame_base_table_entry **tail;
  54. const struct frame_base *default_base;
  55. };
  56. static void *
  57. frame_base_init (struct obstack *obstack)
  58. {
  59. struct frame_base_table *table
  60. = OBSTACK_ZALLOC (obstack, struct frame_base_table);
  61. table->tail = &table->head;
  62. table->default_base = &default_frame_base;
  63. return table;
  64. }
  65. void
  66. frame_base_append_sniffer (struct gdbarch *gdbarch,
  67. frame_base_sniffer_ftype *sniffer)
  68. {
  69. struct frame_base_table *table
  70. = (struct frame_base_table *) gdbarch_data (gdbarch, frame_base_data);
  71. (*table->tail)
  72. = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_base_table_entry);
  73. (*table->tail)->sniffer = sniffer;
  74. table->tail = &(*table->tail)->next;
  75. }
  76. void
  77. frame_base_set_default (struct gdbarch *gdbarch,
  78. const struct frame_base *default_base)
  79. {
  80. struct frame_base_table *table
  81. = (struct frame_base_table *) gdbarch_data (gdbarch, frame_base_data);
  82. table->default_base = default_base;
  83. }
  84. const struct frame_base *
  85. frame_base_find_by_frame (struct frame_info *this_frame)
  86. {
  87. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  88. struct frame_base_table *table
  89. = (struct frame_base_table *) gdbarch_data (gdbarch, frame_base_data);
  90. struct frame_base_table_entry *entry;
  91. for (entry = table->head; entry != NULL; entry = entry->next)
  92. {
  93. const struct frame_base *desc = NULL;
  94. desc = entry->sniffer (this_frame);
  95. if (desc != NULL)
  96. return desc;
  97. }
  98. return table->default_base;
  99. }
  100. void _initialize_frame_base ();
  101. void
  102. _initialize_frame_base ()
  103. {
  104. frame_base_data = gdbarch_data_register_pre_init (frame_base_init);
  105. }