gdb/frame-base.c - gdb

Global variables defined

Data types defined

Functions defined

Source code

  1. /* Definitions for frame address handler, for GDB, the GNU debugger.

  2.    Copyright (C) 2003-2015 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 "gdb_obstack.h"

  18. /* A default frame base implementations.  If it wasn't for the old
  19.    DEPRECATED_FRAME_LOCALS_ADDRESS and DEPRECATED_FRAME_ARGS_ADDRESS,
  20.    these could be combined into a single function.  All architectures
  21.    really need to override this.  */

  22. static CORE_ADDR
  23. default_frame_base_address (struct frame_info *this_frame, void **this_cache)
  24. {
  25.   return get_frame_base (this_frame); /* sigh! */
  26. }

  27. static CORE_ADDR
  28. default_frame_locals_address (struct frame_info *this_frame, void **this_cache)
  29. {
  30.   return default_frame_base_address (this_frame, this_cache);
  31. }

  32. static CORE_ADDR
  33. default_frame_args_address (struct frame_info *this_frame, void **this_cache)
  34. {
  35.   return default_frame_base_address (this_frame, this_cache);
  36. }

  37. const struct frame_base default_frame_base = {
  38.   NULL, /* No parent.  */
  39.   default_frame_base_address,
  40.   default_frame_locals_address,
  41.   default_frame_args_address
  42. };

  43. static struct gdbarch_data *frame_base_data;

  44. struct frame_base_table_entry
  45. {
  46.   frame_base_sniffer_ftype *sniffer;
  47.   struct frame_base_table_entry *next;
  48. };

  49. struct frame_base_table
  50. {
  51.   struct frame_base_table_entry *head;
  52.   struct frame_base_table_entry **tail;
  53.   const struct frame_base *default_base;
  54. };

  55. static void *
  56. frame_base_init (struct obstack *obstack)
  57. {
  58.   struct frame_base_table *table
  59.     = OBSTACK_ZALLOC (obstack, struct frame_base_table);

  60.   table->tail = &table->head;
  61.   table->default_base = &default_frame_base;
  62.   return table;
  63. }

  64. void
  65. frame_base_append_sniffer (struct gdbarch *gdbarch,
  66.                            frame_base_sniffer_ftype *sniffer)
  67. {
  68.   struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data);

  69.   (*table->tail)
  70.     = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_base_table_entry);
  71.   (*table->tail)->sniffer = sniffer;
  72.   table->tail = &(*table->tail)->next;
  73. }

  74. void
  75. frame_base_set_default (struct gdbarch *gdbarch,
  76.                         const struct frame_base *default_base)
  77. {
  78.   struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data);

  79.   table->default_base = default_base;
  80. }

  81. const struct frame_base *
  82. frame_base_find_by_frame (struct frame_info *this_frame)
  83. {
  84.   struct gdbarch *gdbarch = get_frame_arch (this_frame);
  85.   struct frame_base_table *table = gdbarch_data (gdbarch, frame_base_data);
  86.   struct frame_base_table_entry *entry;

  87.   for (entry = table->head; entry != NULL; entry = entry->next)
  88.     {
  89.       const struct frame_base *desc = NULL;

  90.       desc = entry->sniffer (this_frame);
  91.       if (desc != NULL)
  92.         return desc;
  93.     }
  94.   return table->default_base;
  95. }

  96. extern initialize_file_ftype _initialize_frame_base; /* -Wmissing-prototypes */

  97. void
  98. _initialize_frame_base (void)
  99. {
  100.   frame_base_data = gdbarch_data_register_pre_init (frame_base_init);
  101. }