Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Commit 6c1dab7

Browse files
Merge pull request #57 from timsifive/compressed_breakpoint_option
Compressed breakpoint option
2 parents 152e3e9 + 46dbc1b commit 6c1dab7

File tree

2 files changed

+57
-9
lines changed

2 files changed

+57
-9
lines changed

gdb/riscv-tdep.c

+56-6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "dwarf2-frame.h"
5858
#include "user-regs.h"
5959
#include "valprint.h"
60+
#include "common-defs.h"
6061
#include "opcode/riscv-opc.h"
6162
#include <algorithm>
6263

@@ -158,26 +159,51 @@ static const struct register_alias riscv_register_aliases[] =
158159
#undef DECLARE_CSR
159160
};
160161

162+
static enum auto_boolean use_compressed_breakpoints;
163+
164+
static struct cmd_list_element *setriscvcmdlist = NULL;
165+
static struct cmd_list_element *showriscvcmdlist = NULL;
166+
167+
static void
168+
show_riscv_command (char *args, int from_tty)
169+
{
170+
help_list (showriscvcmdlist, "show riscv ", all_commands, gdb_stdout);
171+
}
172+
173+
static void
174+
set_riscv_command (char *args, int from_tty)
175+
{
176+
printf_unfiltered
177+
("\"set riscv\" must be followed by an appropriate subcommand.\n");
178+
help_list (setriscvcmdlist, "set riscv ", all_commands, gdb_stdout);
179+
}
180+
161181
static int
162182
riscv_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
163183
{
164-
if (gdbarch_tdep (gdbarch)->supports_compressed_isa == SUP_UNKNOWN)
184+
if (use_compressed_breakpoints == AUTO_BOOLEAN_AUTO) {
185+
if (gdbarch_tdep (gdbarch)->supports_compressed_isa == AUTO_BOOLEAN_AUTO)
165186
{
166187
/* TODO: Because we try to read misa, it is not possible to set a
167188
breakpoint before connecting to a live target. A suggested workaround is
168189
to look at the ELF file in this case. */
169190
struct frame_info *frame = get_current_frame ();
170191
uint32_t misa = get_frame_register_unsigned (frame, RISCV_CSR_MISA_REGNUM);
171192
if (misa & (1<<2))
172-
gdbarch_tdep (gdbarch)->supports_compressed_isa = SUP_YES;
193+
gdbarch_tdep (gdbarch)->supports_compressed_isa = AUTO_BOOLEAN_TRUE;
173194
else
174-
gdbarch_tdep (gdbarch)->supports_compressed_isa = SUP_NO;
195+
gdbarch_tdep (gdbarch)->supports_compressed_isa = AUTO_BOOLEAN_FALSE;
175196
}
176197

177-
if (gdbarch_tdep (gdbarch)->supports_compressed_isa == SUP_YES)
198+
if (gdbarch_tdep (gdbarch)->supports_compressed_isa == AUTO_BOOLEAN_TRUE)
199+
return 2;
200+
else
201+
return 4;
202+
} else if (use_compressed_breakpoints == AUTO_BOOLEAN_TRUE) {
178203
return 2;
179-
else
204+
} else {
180205
return 4;
206+
}
181207
}
182208

183209
static const gdb_byte *
@@ -1236,7 +1262,7 @@ riscv_gdbarch_init (struct gdbarch_info info,
12361262
gdbarch = gdbarch_alloc (&info, tdep);
12371263

12381264
tdep->riscv_abi = abi;
1239-
tdep->supports_compressed_isa = SUP_UNKNOWN;
1265+
tdep->supports_compressed_isa = AUTO_BOOLEAN_AUTO;
12401266

12411267
/* Target data types. */
12421268
set_gdbarch_short_bit (gdbarch, 16);
@@ -1336,4 +1362,28 @@ void
13361362
_initialize_riscv_tdep (void)
13371363
{
13381364
gdbarch_register (bfd_arch_riscv, riscv_gdbarch_init, NULL);
1365+
1366+
/* Add root prefix command for all "set riscv"/"show riscv" commands. */
1367+
add_prefix_cmd ("riscv", no_class, set_riscv_command,
1368+
_("RISC-V specific commands."),
1369+
&setriscvcmdlist, "set riscv ", 0, &setlist);
1370+
1371+
add_prefix_cmd ("riscv", no_class, show_riscv_command,
1372+
_("RISC-V specific commands."),
1373+
&showriscvcmdlist, "show riscv ", 0, &showlist);
1374+
1375+
use_compressed_breakpoints = AUTO_BOOLEAN_AUTO;
1376+
add_setshow_auto_boolean_cmd ("use_compressed_breakpoints", no_class,
1377+
&use_compressed_breakpoints,
1378+
_("Configure whether to use compressed breakpoints."),
1379+
_("Show whether to use compressed breakpoints."),
1380+
_("\
1381+
Debugging compressed code requires compressed breakpoints to be used. If left\n\
1382+
to 'auto' then gdb will use them if $misa indicates the C extension is\n\
1383+
supported. If that doesn't give the correct behavior, then this option can be\n\
1384+
used."),
1385+
NULL,
1386+
NULL,
1387+
&setriscvcmdlist,
1388+
&showriscvcmdlist);
13391389
}

gdb/riscv-tdep.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,11 @@ enum {
6969

7070
#define RISCV_LAST_REGNUM (RISCV_NUM_REGS - 1)
7171

72-
typedef enum { SUP_UNKNOWN, SUP_YES, SUP_NO } supported_t;
73-
7472
/* RISC-V specific per-architecture information. */
7573
struct gdbarch_tdep
7674
{
7775
int riscv_abi;
78-
supported_t supports_compressed_isa;
76+
enum auto_boolean supports_compressed_isa;
7977
};
8078

8179
static inline int

0 commit comments

Comments
 (0)