gdb/trad-frame.c - gdb

Data types defined

Functions defined

Source code

  1. /* Traditional frame unwind support, 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.h"
  16. #include "trad-frame.h"
  17. #include "regcache.h"
  18. #include "frame-unwind.h"
  19. #include "value.h"

  20. struct trad_frame_cache
  21. {
  22.   struct frame_info *this_frame;
  23.   CORE_ADDR this_base;
  24.   struct trad_frame_saved_reg *prev_regs;
  25.   struct frame_id this_id;
  26. };

  27. struct trad_frame_cache *
  28. trad_frame_cache_zalloc (struct frame_info *this_frame)
  29. {
  30.   struct trad_frame_cache *this_trad_cache;

  31.   this_trad_cache = FRAME_OBSTACK_ZALLOC (struct trad_frame_cache);
  32.   this_trad_cache->prev_regs = trad_frame_alloc_saved_regs (this_frame);
  33.   this_trad_cache->this_frame = this_frame;
  34.   return this_trad_cache;
  35. }

  36. /* A traditional frame is unwound by analysing the function prologue
  37.    and using the information gathered to track registers.  For
  38.    non-optimized frames, the technique is reliable (just need to check
  39.    for all potential instruction sequences).  */

  40. struct trad_frame_saved_reg *
  41. trad_frame_alloc_saved_regs (struct frame_info *this_frame)
  42. {
  43.   int regnum;
  44.   struct gdbarch *gdbarch = get_frame_arch (this_frame);
  45.   int numregs = gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
  46.   struct trad_frame_saved_reg *this_saved_regs
  47.     = FRAME_OBSTACK_CALLOC (numregs, struct trad_frame_saved_reg);

  48.   for (regnum = 0; regnum < numregs; regnum++)
  49.     {
  50.       this_saved_regs[regnum].realreg = regnum;
  51.       this_saved_regs[regnum].addr = -1;
  52.     }
  53.   return this_saved_regs;
  54. }

  55. enum { TF_REG_VALUE = -1, TF_REG_UNKNOWN = -2 };

  56. int
  57. trad_frame_value_p (struct trad_frame_saved_reg this_saved_regs[], int regnum)
  58. {
  59.   return (this_saved_regs[regnum].realreg == TF_REG_VALUE);
  60. }

  61. int
  62. trad_frame_addr_p (struct trad_frame_saved_reg this_saved_regs[], int regnum)
  63. {
  64.   return (this_saved_regs[regnum].realreg >= 0
  65.           && this_saved_regs[regnum].addr != -1);
  66. }

  67. int
  68. trad_frame_realreg_p (struct trad_frame_saved_reg this_saved_regs[],
  69.                       int regnum)
  70. {
  71.   return (this_saved_regs[regnum].realreg >= 0
  72.           && this_saved_regs[regnum].addr == -1);
  73. }

  74. void
  75. trad_frame_set_value (struct trad_frame_saved_reg this_saved_regs[],
  76.                       int regnum, LONGEST val)
  77. {
  78.   /* Make the REALREG invalid, indicating that the ADDR contains the
  79.      register's value.  */
  80.   this_saved_regs[regnum].realreg = TF_REG_VALUE;
  81.   this_saved_regs[regnum].addr = val;
  82. }

  83. void
  84. trad_frame_set_reg_value (struct trad_frame_cache *this_trad_cache,
  85.                           int regnum, LONGEST val)
  86. {
  87.   /* External interface for users of trad_frame_cache
  88.      (who cannot access the prev_regs object directly).  */
  89.   trad_frame_set_value (this_trad_cache->prev_regs, regnum, val);
  90. }

  91. void
  92. trad_frame_set_reg_realreg (struct trad_frame_cache *this_trad_cache,
  93.                             int regnum, int realreg)
  94. {
  95.   this_trad_cache->prev_regs[regnum].realreg = realreg;
  96.   this_trad_cache->prev_regs[regnum].addr = -1;
  97. }

  98. void
  99. trad_frame_set_reg_addr (struct trad_frame_cache *this_trad_cache,
  100.                          int regnum, CORE_ADDR addr)
  101. {
  102.   this_trad_cache->prev_regs[regnum].addr = addr;
  103. }

  104. void
  105. trad_frame_set_unknown (struct trad_frame_saved_reg this_saved_regs[],
  106.                         int regnum)
  107. {
  108.   /* Make the REALREG invalid, indicating that the value is not known.  */
  109.   this_saved_regs[regnum].realreg = TF_REG_UNKNOWN;
  110.   this_saved_regs[regnum].addr = -1;
  111. }

  112. struct value *
  113. trad_frame_get_prev_register (struct frame_info *this_frame,
  114.                               struct trad_frame_saved_reg this_saved_regs[],
  115.                               int regnum)
  116. {
  117.   if (trad_frame_addr_p (this_saved_regs, regnum))
  118.     /* The register was saved in memory.  */
  119.     return frame_unwind_got_memory (this_frame, regnum,
  120.                                     this_saved_regs[regnum].addr);
  121.   else if (trad_frame_realreg_p (this_saved_regs, regnum))
  122.     return frame_unwind_got_register (this_frame, regnum,
  123.                                       this_saved_regs[regnum].realreg);
  124.   else if (trad_frame_value_p (this_saved_regs, regnum))
  125.     /* The register's value is available.  */
  126.     return frame_unwind_got_constant (this_frame, regnum,
  127.                                       this_saved_regs[regnum].addr);
  128.   else
  129.     return frame_unwind_got_optimized (this_frame, regnum);
  130. }

  131. struct value *
  132. trad_frame_get_register (struct trad_frame_cache *this_trad_cache,
  133.                          struct frame_info *this_frame,
  134.                          int regnum)
  135. {
  136.   return trad_frame_get_prev_register (this_frame, this_trad_cache->prev_regs,
  137.                                        regnum);
  138. }

  139. void
  140. trad_frame_set_id (struct trad_frame_cache *this_trad_cache,
  141.                    struct frame_id this_id)
  142. {
  143.   this_trad_cache->this_id = this_id;
  144. }

  145. void
  146. trad_frame_get_id (struct trad_frame_cache *this_trad_cache,
  147.                    struct frame_id *this_id)
  148. {
  149.   (*this_id) = this_trad_cache->this_id;
  150. }

  151. void
  152. trad_frame_set_this_base (struct trad_frame_cache *this_trad_cache,
  153.                           CORE_ADDR this_base)
  154. {
  155.   this_trad_cache->this_base = this_base;
  156. }

  157. CORE_ADDR
  158. trad_frame_get_this_base (struct trad_frame_cache *this_trad_cache)
  159. {
  160.   return this_trad_cache->this_base;
  161. }