aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbarch.c
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2018-09-07 20:04:44 +0100
committerAndrew Burgess <andrew.burgess@embecosm.com>2018-12-19 20:59:38 +0000
commit8bcb5208976448aab20df7dd50e9286ef1f7e22c (patch)
tree60b911587b7c7a0e77aed216bad3a5dcd81777dc /gdb/gdbarch.c
parentb9519cfe9828b9ee5a73e74b4be83d46f33e6886 (diff)
downloadfsf-binutils-gdb-8bcb5208976448aab20df7dd50e9286ef1f7e22c.zip
fsf-binutils-gdb-8bcb5208976448aab20df7dd50e9286ef1f7e22c.tar.gz
fsf-binutils-gdb-8bcb5208976448aab20df7dd50e9286ef1f7e22c.tar.bz2
gdb: Add default frame methods to gdbarch
Supply default gdbarch methods for gdbarch_dummy_id, gdbarch_unwind_pc, and gdbarch_unwind_sp. This patch doesn't actually convert any targets to use these methods, and so, there will be no user visible changes after this commit. The implementations for default_dummy_id and default_unwind_sp are fairly straight forward, these just take on the pattern used by most targets. Once these default methods are in place then most targets will be able to switch over. The implementation for default_unwind_pc is also fairly straight forward, but maybe needs some explanation. This patch has gone through a number of iterations: https://sourceware.org/ml/gdb-patches/2018-03/msg00165.html https://sourceware.org/ml/gdb-patches/2018-03/msg00306.html https://sourceware.org/ml/gdb-patches/2018-06/msg00090.html https://sourceware.org/ml/gdb-patches/2018-09/msg00127.html and the implementation of default_unwind_pc has changed over this time. Originally, I took an implementation like this: CORE_ADDR default_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) { int pc_regnum = gdbarch_pc_regnum (gdbarch); return frame_unwind_register_unsigned (next_frame, pc_regnum); } This is basically a clone of default_unwind_sp, but using $pc. It was pointed out that we could potentially do better, and in version 2 the implementation became: CORE_ADDR default_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) { struct type *type; int pc_regnum; CORE_ADDR addr; struct value *value; pc_regnum = gdbarch_pc_regnum (gdbarch); value = frame_unwind_register_value (next_frame, pc_regnum); type = builtin_type (gdbarch)->builtin_func_ptr; addr = extract_typed_address (value_contents_all (value), type); addr = gdbarch_addr_bits_remove (gdbarch, addr); release_value (value); value_free (value); return addr; } The idea was to try split out some of the steps of unwinding the $pc, steps that are on some (or many) targets no-ops, and so allow targets that do override these methods, to make use of default_unwind_pc. This implementation remained in place for version 2, 3, and 4. However, I realised that I'd made a mistake, most targets simply use frame_unwind_register_unsigned to unwind the $pc, and this throws an error if the register value is optimized out or unavailable. My new proposed implementation doesn't do this, I was going to end up breaking many targets. I considered duplicating the code from frame_unwind_register_unsigned that throws the errors into my new default_unwind_pc, however, this felt really overly complex. So, what I instead went with was to simply revert back to using frame_unwind_register_unsigned. Almost all existing targets already use this. Some of the ones that don't can be converted to, which means almost all targets could end up using the default. One addition I have made over the version 1 implementation is to add a call to gdbarch_addr_bits_remove. For most targets this is a no-op, but for a handful, having this call in place will mean that they can use the default method. After all this, the new default_unwind_pc now looks like this: CORE_ADDR default_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame) { int pc_regnum = gdbarch_pc_regnum (gdbarch); CORE_ADDR pc = frame_unwind_register_unsigned (next_frame, pc_regnum); pc = gdbarch_addr_bits_remove (gdbarch, pc); return pc; } gdb/ChangeLog: * gdb/dummy-frame.c (default_dummy_id): Defined new function. * gdb/dummy-frame.h (default_dummy_id): Declare new function. * gdb/frame-unwind.c (default_unwind_pc): Define new function. (default_unwind_sp): Define new function. * gdb/frame-unwind.h (default_unwind_pc): Declare new function. (default_unwind_sp): Declare new function. * gdb/frame.c (frame_unwind_pc): Assume gdbarch_unwind_pc is available. (get_frame_sp): Assume that gdbarch_unwind_sp is available. * gdb/gdbarch.c: Regenerate. * gdb/gdbarch.h: Regenerate. * gdb/gdbarch.sh: Update definition of dummy_id, unwind_pc, and unwind_sp. Add additional header files to be included in generated file.
Diffstat (limited to 'gdb/gdbarch.c')
-rw-r--r--gdb/gdbarch.c41
1 files changed, 8 insertions, 33 deletions
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index bc4f786..193142c 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -48,6 +48,8 @@
#include "regcache.h"
#include "objfiles.h"
#include "auxv.h"
+#include "frame-unwind.h"
+#include "dummy-frame.h"
/* Static function declarations */
@@ -408,6 +410,7 @@ gdbarch_alloc (const struct gdbarch_info *info,
gdbarch->ecoff_reg_to_regnum = no_op_reg_to_regnum;
gdbarch->sdb_reg_to_regnum = no_op_reg_to_regnum;
gdbarch->dwarf2_reg_to_regnum = no_op_reg_to_regnum;
+ gdbarch->dummy_id = default_dummy_id;
gdbarch->deprecated_fp_regnum = -1;
gdbarch->call_dummy_location = AT_ENTRY_POINT;
gdbarch->code_of_frame_writable = default_code_of_frame_writable;
@@ -427,6 +430,8 @@ gdbarch_alloc (const struct gdbarch_info *info,
gdbarch->memory_insert_breakpoint = default_memory_insert_breakpoint;
gdbarch->memory_remove_breakpoint = default_memory_remove_breakpoint;
gdbarch->remote_register_number = default_remote_register_number;
+ gdbarch->unwind_pc = default_unwind_pc;
+ gdbarch->unwind_sp = default_unwind_sp;
gdbarch->stabs_argument_has_addr = default_stabs_argument_has_addr;
gdbarch->convert_from_func_ptr_addr = convert_from_func_ptr_addr_identity;
gdbarch->addr_bits_remove = core_addr_identity;
@@ -570,7 +575,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
if (gdbarch->register_name == 0)
log.puts ("\n\tregister_name");
/* Skip verify of register_type, has predicate. */
- /* Skip verify of dummy_id, has predicate. */
+ /* Skip verify of dummy_id, invalid_p == 0 */
/* Skip verify of deprecated_fp_regnum, invalid_p == 0 */
/* Skip verify of push_dummy_call, has predicate. */
/* Skip verify of call_dummy_location, invalid_p == 0 */
@@ -609,8 +614,8 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of remote_register_number, invalid_p == 0 */
/* Skip verify of fetch_tls_load_module_address, has predicate. */
/* Skip verify of frame_args_skip, invalid_p == 0 */
- /* Skip verify of unwind_pc, has predicate. */
- /* Skip verify of unwind_sp, has predicate. */
+ /* Skip verify of unwind_pc, invalid_p == 0 */
+ /* Skip verify of unwind_sp, invalid_p == 0 */
/* Skip verify of frame_num_args, has predicate. */
/* Skip verify of frame_align, has predicate. */
/* Skip verify of stabs_argument_has_addr, invalid_p == 0 */
@@ -955,9 +960,6 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
"gdbarch_dump: dtrace_probe_is_enabled = <%s>\n",
host_address_to_string (gdbarch->dtrace_probe_is_enabled));
fprintf_unfiltered (file,
- "gdbarch_dump: gdbarch_dummy_id_p() = %d\n",
- gdbarch_dummy_id_p (gdbarch));
- fprintf_unfiltered (file,
"gdbarch_dump: dummy_id = <%s>\n",
host_address_to_string (gdbarch->dummy_id));
fprintf_unfiltered (file,
@@ -1441,15 +1443,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
"gdbarch_dump: type_align = <%s>\n",
host_address_to_string (gdbarch->type_align));
fprintf_unfiltered (file,
- "gdbarch_dump: gdbarch_unwind_pc_p() = %d\n",
- gdbarch_unwind_pc_p (gdbarch));
- fprintf_unfiltered (file,
"gdbarch_dump: unwind_pc = <%s>\n",
host_address_to_string (gdbarch->unwind_pc));
fprintf_unfiltered (file,
- "gdbarch_dump: gdbarch_unwind_sp_p() = %d\n",
- gdbarch_unwind_sp_p (gdbarch));
- fprintf_unfiltered (file,
"gdbarch_dump: unwind_sp = <%s>\n",
host_address_to_string (gdbarch->unwind_sp));
fprintf_unfiltered (file,
@@ -2307,13 +2303,6 @@ set_gdbarch_register_type (struct gdbarch *gdbarch,
gdbarch->register_type = register_type;
}
-int
-gdbarch_dummy_id_p (struct gdbarch *gdbarch)
-{
- gdb_assert (gdbarch != NULL);
- return gdbarch->dummy_id != NULL;
-}
-
struct frame_id
gdbarch_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
{
@@ -3046,13 +3035,6 @@ set_gdbarch_frame_args_skip (struct gdbarch *gdbarch,
gdbarch->frame_args_skip = frame_args_skip;
}
-int
-gdbarch_unwind_pc_p (struct gdbarch *gdbarch)
-{
- gdb_assert (gdbarch != NULL);
- return gdbarch->unwind_pc != NULL;
-}
-
CORE_ADDR
gdbarch_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
{
@@ -3070,13 +3052,6 @@ set_gdbarch_unwind_pc (struct gdbarch *gdbarch,
gdbarch->unwind_pc = unwind_pc;
}
-int
-gdbarch_unwind_sp_p (struct gdbarch *gdbarch)
-{
- gdb_assert (gdbarch != NULL);
- return gdbarch->unwind_sp != NULL;
-}
-
CORE_ADDR
gdbarch_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
{