|
| 1 | +From 733f5079219b6a6edbc63ba5ce7d98a17236656a Mon Sep 17 00:00:00 2001 |
| 2 | +From: Daniel Leung < [email protected]> |
| 3 | +Date: Mon, 14 Sep 2020 13:04:31 -0700 |
| 4 | +Subject: [PATCH 5/6] gdb: arch to tell whether it supports 'g' packets |
| 5 | + |
| 6 | +This adds a callback to gdbarch so indicate whether |
| 7 | +the architecture supports 'g' packets to remote target. |
| 8 | +For example, on Xtensa, xt-ocd does not support 'g' |
| 9 | +packet. However, the register fetching code keeps on |
| 10 | +trying 'g' packet which results in infinite loop. So |
| 11 | +this provides a mechanism for architecture to indicate |
| 12 | +whether 'g' packet is supported. |
| 13 | + |
| 14 | +Signed-off-by: Daniel Leung < [email protected]> |
| 15 | +--- |
| 16 | + gdb/arch-utils.c | 6 ++++++ |
| 17 | + gdb/arch-utils.h | 2 ++ |
| 18 | + gdb/gdbarch.c | 21 +++++++++++++++++++++ |
| 19 | + gdb/gdbarch.h | 5 +++++ |
| 20 | + gdb/remote.c | 5 ++++- |
| 21 | + 5 files changed, 38 insertions(+), 1 deletion(-) |
| 22 | + |
| 23 | +diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c |
| 24 | +index 8d484c78e3..cb4e89dfff 100644 |
| 25 | +--- a/gdb/arch-utils.c |
| 26 | ++++ b/gdb/arch-utils.c |
| 27 | +@@ -1004,6 +1004,12 @@ default_get_pc_address_flags (frame_info *frame, CORE_ADDR pc) |
| 28 | + return ""; |
| 29 | + } |
| 30 | + |
| 31 | ++int |
| 32 | ++default_remote_supports_g_packet (struct gdbarch *gdbarch) |
| 33 | ++{ |
| 34 | ++ return 1; |
| 35 | ++} |
| 36 | ++ |
| 37 | + void |
| 38 | + _initialize_gdbarch_utils (void) |
| 39 | + { |
| 40 | +diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h |
| 41 | +index 3fb9ad317a..1a0df4a86b 100644 |
| 42 | +--- a/gdb/arch-utils.h |
| 43 | ++++ b/gdb/arch-utils.h |
| 44 | +@@ -276,4 +276,6 @@ extern ULONGEST default_type_align (struct gdbarch *gdbarch, |
| 45 | + extern std::string default_get_pc_address_flags (frame_info *frame, |
| 46 | + CORE_ADDR pc); |
| 47 | + |
| 48 | ++int default_remote_supports_g_packet (struct gdbarch *gdbarch); |
| 49 | ++ |
| 50 | + #endif /* ARCH_UTILS_H */ |
| 51 | +diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c |
| 52 | +index ab9bf1f5f4..636c51fc82 100644 |
| 53 | +--- a/gdb/gdbarch.c |
| 54 | ++++ b/gdb/gdbarch.c |
| 55 | +@@ -358,6 +358,7 @@ struct gdbarch |
| 56 | + const disasm_options_and_args_t * valid_disassembler_options; |
| 57 | + gdbarch_type_align_ftype *type_align; |
| 58 | + gdbarch_get_pc_address_flags_ftype *get_pc_address_flags; |
| 59 | ++ gdbarch_remote_supports_g_packet_ftype *remote_supports_g_packet; |
| 60 | + }; |
| 61 | + |
| 62 | + /* Create a new ``struct gdbarch'' based on information provided by |
| 63 | +@@ -473,6 +474,7 @@ gdbarch_alloc (const struct gdbarch_info *info, |
| 64 | + gdbarch->addressable_memory_unit_size = default_addressable_memory_unit_size; |
| 65 | + gdbarch->type_align = default_type_align; |
| 66 | + gdbarch->get_pc_address_flags = default_get_pc_address_flags; |
| 67 | ++ gdbarch->remote_supports_g_packet = default_remote_supports_g_packet; |
| 68 | + /* gdbarch_alloc() */ |
| 69 | + |
| 70 | + return gdbarch; |
| 71 | +@@ -1500,6 +1502,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) |
| 72 | + fprintf_unfiltered (file, |
| 73 | + "gdbarch_dump: xml_syscall_file = %s\n", |
| 74 | + pstring (gdbarch->xml_syscall_file)); |
| 75 | ++ fprintf_unfiltered (file, |
| 76 | ++ "gdbarch_dump: remote_supports_g_packet = <%s>\n", |
| 77 | ++ host_address_to_string (gdbarch->remote_supports_g_packet)); |
| 78 | + if (gdbarch->dump_tdep != NULL) |
| 79 | + gdbarch->dump_tdep (gdbarch, file); |
| 80 | + } |
| 81 | +@@ -5156,6 +5161,22 @@ set_gdbarch_get_pc_address_flags (struct gdbarch *gdbarch, |
| 82 | + gdbarch->get_pc_address_flags = get_pc_address_flags; |
| 83 | + } |
| 84 | + |
| 85 | ++int |
| 86 | ++gdbarch_remote_supports_g_packet (struct gdbarch *gdbarch) |
| 87 | ++{ |
| 88 | ++ gdb_assert (gdbarch != NULL); |
| 89 | ++ gdb_assert (gdbarch->remote_supports_g_packet != NULL); |
| 90 | ++ if (gdbarch_debug >= 2) |
| 91 | ++ fprintf_unfiltered (gdb_stdlog, "gdbarch_remote_supports_g_packet called\n"); |
| 92 | ++ return gdbarch->remote_supports_g_packet (gdbarch); |
| 93 | ++} |
| 94 | ++ |
| 95 | ++void |
| 96 | ++set_gdbarch_remote_supports_g_packet (struct gdbarch *gdbarch, |
| 97 | ++ gdbarch_remote_supports_g_packet_ftype *remote_supports_g_packet) |
| 98 | ++{ |
| 99 | ++ gdbarch->remote_supports_g_packet = remote_supports_g_packet; |
| 100 | ++} |
| 101 | + |
| 102 | + /* Keep a registry of per-architecture data-pointers required by GDB |
| 103 | + modules. */ |
| 104 | +diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h |
| 105 | +index 9f32ac23ab..67612bb93e 100644 |
| 106 | +--- a/gdb/gdbarch.h |
| 107 | ++++ b/gdb/gdbarch.h |
| 108 | +@@ -1642,6 +1642,11 @@ extern void set_gdbarch_get_pc_address_flags (struct gdbarch *gdbarch, gdbarch_g |
| 109 | + |
| 110 | + extern struct gdbarch_tdep *gdbarch_tdep (struct gdbarch *gdbarch); |
| 111 | + |
| 112 | ++/* If arch supports 'g' packets */ |
| 113 | ++ |
| 114 | ++typedef int (gdbarch_remote_supports_g_packet_ftype) (struct gdbarch *gdbarch); |
| 115 | ++extern int gdbarch_remote_supports_g_packet (struct gdbarch *gdbarch); |
| 116 | ++extern void set_gdbarch_remote_supports_g_packet (struct gdbarch *gdbarch, gdbarch_remote_supports_g_packet_ftype *remote_supports_g_packet); |
| 117 | + |
| 118 | + /* Mechanism for co-ordinating the selection of a specific |
| 119 | + architecture. |
| 120 | +diff --git a/gdb/remote.c b/gdb/remote.c |
| 121 | +index 9222be6b9f..a090228b1c 100644 |
| 122 | +--- a/gdb/remote.c |
| 123 | ++++ b/gdb/remote.c |
| 124 | +@@ -1276,6 +1276,7 @@ map_regcache_remote_table (struct gdbarch *gdbarch, struct packet_reg *regs) |
| 125 | + { |
| 126 | + int regnum, num_remote_regs, offset; |
| 127 | + struct packet_reg **remote_regs; |
| 128 | ++ int remote_supports_g_packet; |
| 129 | + |
| 130 | + for (regnum = 0; regnum < gdbarch_num_regs (gdbarch); regnum++) |
| 131 | + { |
| 132 | +@@ -1305,9 +1306,11 @@ map_regcache_remote_table (struct gdbarch *gdbarch, struct packet_reg *regs) |
| 133 | + [] (const packet_reg *a, const packet_reg *b) |
| 134 | + { return a->pnum < b->pnum; }); |
| 135 | + |
| 136 | ++ remote_supports_g_packet = gdbarch_remote_supports_g_packet(gdbarch); |
| 137 | ++ |
| 138 | + for (regnum = 0, offset = 0; regnum < num_remote_regs; regnum++) |
| 139 | + { |
| 140 | +- remote_regs[regnum]->in_g_packet = 1; |
| 141 | ++ remote_regs[regnum]->in_g_packet = remote_supports_g_packet; |
| 142 | + remote_regs[regnum]->offset = offset; |
| 143 | + offset += register_size (gdbarch, remote_regs[regnum]->regnum); |
| 144 | + } |
| 145 | +-- |
| 146 | +2.28.0 |
| 147 | + |
0 commit comments