std-regs.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Builtin frame register, for GDB, the GNU debugger.
  2. Copyright (C) 2002-2022 Free Software Foundation, Inc.
  3. Contributed by Red Hat.
  4. This file is part of GDB.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #include "defs.h"
  16. #include "user-regs.h"
  17. #include "frame.h"
  18. #include "gdbtypes.h"
  19. #include "value.h"
  20. #include "gdbarch.h"
  21. static struct value *
  22. value_of_builtin_frame_fp_reg (struct frame_info *frame, const void *baton)
  23. {
  24. struct gdbarch *gdbarch = get_frame_arch (frame);
  25. if (gdbarch_deprecated_fp_regnum (gdbarch) >= 0)
  26. /* NOTE: cagney/2003-04-24: Since the mere presence of "fp" in the
  27. register name table overrides this built-in $fp register, there
  28. is no real reason for this gdbarch_deprecated_fp_regnum trickery here.
  29. An architecture wanting to implement "$fp" as alias for a raw
  30. register can do so by adding "fp" to register name table (mind
  31. you, doing this is probably a dangerous thing). */
  32. return value_of_register (gdbarch_deprecated_fp_regnum (gdbarch),
  33. frame);
  34. else
  35. {
  36. struct type *data_ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
  37. struct value *val = allocate_value (data_ptr_type);
  38. gdb_byte *buf = value_contents_raw (val).data ();
  39. gdbarch_address_to_pointer (gdbarch, data_ptr_type,
  40. buf, get_frame_base_address (frame));
  41. return val;
  42. }
  43. }
  44. static struct value *
  45. value_of_builtin_frame_pc_reg (struct frame_info *frame, const void *baton)
  46. {
  47. struct gdbarch *gdbarch = get_frame_arch (frame);
  48. if (gdbarch_pc_regnum (gdbarch) >= 0)
  49. return value_of_register (gdbarch_pc_regnum (gdbarch), frame);
  50. else
  51. {
  52. struct type *func_ptr_type = builtin_type (gdbarch)->builtin_func_ptr;
  53. struct value *val = allocate_value (func_ptr_type);
  54. gdb_byte *buf = value_contents_raw (val).data ();
  55. gdbarch_address_to_pointer (gdbarch, func_ptr_type,
  56. buf, get_frame_pc (frame));
  57. return val;
  58. }
  59. }
  60. static struct value *
  61. value_of_builtin_frame_sp_reg (struct frame_info *frame, const void *baton)
  62. {
  63. struct gdbarch *gdbarch = get_frame_arch (frame);
  64. if (gdbarch_sp_regnum (gdbarch) >= 0)
  65. return value_of_register (gdbarch_sp_regnum (gdbarch), frame);
  66. error (_("Standard register ``$sp'' is not available for this target"));
  67. }
  68. static struct value *
  69. value_of_builtin_frame_ps_reg (struct frame_info *frame, const void *baton)
  70. {
  71. struct gdbarch *gdbarch = get_frame_arch (frame);
  72. if (gdbarch_ps_regnum (gdbarch) >= 0)
  73. return value_of_register (gdbarch_ps_regnum (gdbarch), frame);
  74. error (_("Standard register ``$ps'' is not available for this target"));
  75. }
  76. void _initialize_frame_reg ();
  77. void
  78. _initialize_frame_reg ()
  79. {
  80. /* Frame based $fp, $pc, $sp and $ps. These only come into play
  81. when the target does not define its own version of these
  82. registers. */
  83. user_reg_add_builtin ("fp", value_of_builtin_frame_fp_reg, NULL);
  84. user_reg_add_builtin ("pc", value_of_builtin_frame_pc_reg, NULL);
  85. user_reg_add_builtin ("sp", value_of_builtin_frame_sp_reg, NULL);
  86. user_reg_add_builtin ("ps", value_of_builtin_frame_ps_reg, NULL);
  87. }