Skip to content

Commit 6702310

Browse files
dcpleungstephanosio
authored andcommitted
gdb: arch to tell whether it supports 'g' packets
This adds a callback to gdbarch so indicate whether the architecture supports 'g' packets to remote target. For example, on Xtensa, xt-ocd does not support 'g' packet. However, the register fetching code keeps on trying 'g' packet which results in infinite loop. So this provides a mechanism for architecture to indicate whether 'g' packet is supported. Signed-off-by: Daniel Leung <daniel.leung@intel.com> Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
1 parent 0523aed commit 6702310

File tree

6 files changed

+53
-1
lines changed

6 files changed

+53
-1
lines changed

gdb/arch-utils.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,13 @@ default_update_call_site_pc (struct gdbarch *gdbarch, CORE_ADDR pc)
11301130
return pc;
11311131
}
11321132

1133+
/* See arch-utils.h */
1134+
int
1135+
default_remote_supports_g_packet (struct gdbarch *gdbarch)
1136+
{
1137+
return 1;
1138+
}
1139+
11331140
/* Non-zero if we want to trace architecture code. */
11341141

11351142
#ifndef GDBARCH_DEBUG

gdb/arch-utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,4 +414,7 @@ extern enum return_value_convention default_gdbarch_return_value
414414
struct regcache *regcache, struct value **read_value,
415415
const gdb_byte *writebuf);
416416

417+
/* Default implementation of gdbarch remote_supports_g_packet method. */
418+
extern int default_remote_supports_g_packet (struct gdbarch *gdbarch);
419+
417420
#endif /* GDB_ARCH_UTILS_H */

gdb/gdbarch-gen.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ struct gdbarch
261261
gdbarch_read_core_file_mappings_ftype *read_core_file_mappings = default_read_core_file_mappings;
262262
gdbarch_use_target_description_from_corefile_notes_ftype *use_target_description_from_corefile_notes = default_use_target_description_from_corefile_notes;
263263
gdbarch_core_parse_exec_context_ftype *core_parse_exec_context = default_core_parse_exec_context;
264+
gdbarch_remote_supports_g_packet_ftype *remote_supports_g_packet = default_remote_supports_g_packet;
264265
};
265266

266267
/* Create a new ``struct gdbarch'' based on information provided by
@@ -533,6 +534,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
533534
/* Skip verify of read_core_file_mappings, invalid_p == 0. */
534535
/* Skip verify of use_target_description_from_corefile_notes, invalid_p == 0. */
535536
/* Skip verify of core_parse_exec_context, invalid_p == 0. */
537+
/* Skip verify of remote_supports_g_packet, invalid_p == 0. */
536538
if (!log.empty ())
537539
internal_error (_("verify_gdbarch: the following are invalid ...%s"),
538540
log.c_str ());
@@ -1401,6 +1403,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
14011403
gdb_printf (file,
14021404
"gdbarch_dump: core_parse_exec_context = <%s>\n",
14031405
host_address_to_string (gdbarch->core_parse_exec_context));
1406+
gdb_printf (file,
1407+
"gdbarch_dump: remote_supports_g_packet = <%s>\n",
1408+
host_address_to_string (gdbarch->remote_supports_g_packet));
14041409
if (gdbarch->dump_tdep != NULL)
14051410
gdbarch->dump_tdep (gdbarch, file);
14061411
}
@@ -5529,3 +5534,20 @@ set_gdbarch_core_parse_exec_context (struct gdbarch *gdbarch,
55295534
{
55305535
gdbarch->core_parse_exec_context = core_parse_exec_context;
55315536
}
5537+
5538+
int
5539+
gdbarch_remote_supports_g_packet (struct gdbarch *gdbarch)
5540+
{
5541+
gdb_assert (gdbarch != NULL);
5542+
gdb_assert (gdbarch->remote_supports_g_packet != NULL);
5543+
if (gdbarch_debug >= 2)
5544+
gdb_printf (gdb_stdlog, "gdbarch_remote_supports_g_packet called\n");
5545+
return gdbarch->remote_supports_g_packet (gdbarch);
5546+
}
5547+
5548+
void
5549+
set_gdbarch_remote_supports_g_packet (struct gdbarch *gdbarch,
5550+
gdbarch_remote_supports_g_packet_ftype remote_supports_g_packet)
5551+
{
5552+
gdbarch->remote_supports_g_packet = remote_supports_g_packet;
5553+
}

gdb/gdbarch-gen.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,3 +1793,9 @@ extern void set_gdbarch_use_target_description_from_corefile_notes (struct gdbar
17931793
typedef core_file_exec_context (gdbarch_core_parse_exec_context_ftype) (struct gdbarch *gdbarch, bfd *cbfd);
17941794
extern core_file_exec_context gdbarch_core_parse_exec_context (struct gdbarch *gdbarch, bfd *cbfd);
17951795
extern void set_gdbarch_core_parse_exec_context (struct gdbarch *gdbarch, gdbarch_core_parse_exec_context_ftype *core_parse_exec_context);
1796+
1797+
/* No comment */
1798+
1799+
typedef int (gdbarch_remote_supports_g_packet_ftype) (struct gdbarch *gdbarch);
1800+
extern int gdbarch_remote_supports_g_packet (struct gdbarch *gdbarch);
1801+
extern void set_gdbarch_remote_supports_g_packet (struct gdbarch *gdbarch, gdbarch_remote_supports_g_packet_ftype *remote_supports_g_packet);

gdb/gdbarch_components.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,3 +2835,14 @@
28352835
predefault="default_core_parse_exec_context",
28362836
invalid=False,
28372837
)
2838+
2839+
Method(
2840+
comment="""
2841+
Return 1 if arch supports 'g' packets
2842+
""",
2843+
type="int",
2844+
name="remote_supports_g_packet",
2845+
params=[],
2846+
predefault="default_remote_supports_g_packet",
2847+
invalid=False,
2848+
)

gdb/remote.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,7 @@ map_regcache_remote_table (struct gdbarch *gdbarch, struct packet_reg *regs)
18931893
{
18941894
int regnum, num_remote_regs, offset;
18951895
struct packet_reg **remote_regs;
1896+
int remote_supports_g_packet;
18961897

18971898
for (regnum = 0; regnum < gdbarch_num_regs (gdbarch); regnum++)
18981899
{
@@ -1922,9 +1923,11 @@ map_regcache_remote_table (struct gdbarch *gdbarch, struct packet_reg *regs)
19221923
[] (const packet_reg *a, const packet_reg *b)
19231924
{ return a->pnum < b->pnum; });
19241925

1926+
remote_supports_g_packet = gdbarch_remote_supports_g_packet(gdbarch);
1927+
19251928
for (regnum = 0, offset = 0; regnum < num_remote_regs; regnum++)
19261929
{
1927-
remote_regs[regnum]->in_g_packet = 1;
1930+
remote_regs[regnum]->in_g_packet = remote_supports_g_packet;
19281931
remote_regs[regnum]->offset = offset;
19291932
offset += register_size (gdbarch, remote_regs[regnum]->regnum);
19301933
}

0 commit comments

Comments
 (0)