|
57 | 57 | #include "dwarf2-frame.h"
|
58 | 58 | #include "user-regs.h"
|
59 | 59 | #include "valprint.h"
|
| 60 | +#include "common-defs.h" |
60 | 61 | #include "opcode/riscv-opc.h"
|
61 | 62 | #include <algorithm>
|
62 | 63 |
|
@@ -158,26 +159,51 @@ static const struct register_alias riscv_register_aliases[] =
|
158 | 159 | #undef DECLARE_CSR
|
159 | 160 | };
|
160 | 161 |
|
| 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 | + |
161 | 181 | static int
|
162 | 182 | riscv_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
|
163 | 183 | {
|
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) |
165 | 186 | {
|
166 | 187 | /* TODO: Because we try to read misa, it is not possible to set a
|
167 | 188 | breakpoint before connecting to a live target. A suggested workaround is
|
168 | 189 | to look at the ELF file in this case. */
|
169 | 190 | struct frame_info *frame = get_current_frame ();
|
170 | 191 | uint32_t misa = get_frame_register_unsigned (frame, RISCV_CSR_MISA_REGNUM);
|
171 | 192 | if (misa & (1<<2))
|
172 |
| - gdbarch_tdep (gdbarch)->supports_compressed_isa = SUP_YES; |
| 193 | + gdbarch_tdep (gdbarch)->supports_compressed_isa = AUTO_BOOLEAN_TRUE; |
173 | 194 | else
|
174 |
| - gdbarch_tdep (gdbarch)->supports_compressed_isa = SUP_NO; |
| 195 | + gdbarch_tdep (gdbarch)->supports_compressed_isa = AUTO_BOOLEAN_FALSE; |
175 | 196 | }
|
176 | 197 |
|
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) { |
178 | 203 | return 2;
|
179 |
| - else |
| 204 | + } else { |
180 | 205 | return 4;
|
| 206 | + } |
181 | 207 | }
|
182 | 208 |
|
183 | 209 | static const gdb_byte *
|
@@ -1236,7 +1262,7 @@ riscv_gdbarch_init (struct gdbarch_info info,
|
1236 | 1262 | gdbarch = gdbarch_alloc (&info, tdep);
|
1237 | 1263 |
|
1238 | 1264 | tdep->riscv_abi = abi;
|
1239 |
| - tdep->supports_compressed_isa = SUP_UNKNOWN; |
| 1265 | + tdep->supports_compressed_isa = AUTO_BOOLEAN_AUTO; |
1240 | 1266 |
|
1241 | 1267 | /* Target data types. */
|
1242 | 1268 | set_gdbarch_short_bit (gdbarch, 16);
|
@@ -1336,4 +1362,28 @@ void
|
1336 | 1362 | _initialize_riscv_tdep (void)
|
1337 | 1363 | {
|
1338 | 1364 | 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); |
1339 | 1389 | }
|
0 commit comments