• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

GNU Binutils with patches for OS216


Commit MetaInfo

Révisionf37bc8b13c898fa39731c20d8565b24e006c13a8 (tree)
l'heure2018-09-29 06:15:54
AuteurJohn Baldwin <jhb@Free...>
CommiterJohn Baldwin

Message de Log

Use the existing instruction to determine the RISC-V breakpoint kind.

RISC-V supports instructions of varying lengths. Standard existing
instructions in the base ISA are 4 bytes in length, but the 'C'
extension adds support for compressed, 2 byte instructions. RISC-V
supports two different breakpoint instructions: EBREAK is a 4 byte
instruction in the base ISA, and C.EBREAK is a 2 byte instruction only
available on processors implementing the 'C' extension. Using EBREAK
to set breakpoints on compressed instructions causes problems as the
second half of EBREAK will overwrite the first 2 bytes of the
following instruction breaking other threads in the process if their
PC is the following instruction. Thus, breakpoints on compressed
instructions need to use C.EBREAK instead of EBREAK.

Previously, the riscv architecture checked the MISA register to
determine if the 'C' extension was available. If so, it used C.EBREAK
for all breakpoints. However, the MISA register is not necessarily
available to supervisor mode operating systems. While native targets
could provide a fake MISA register value, this patch instead examines
the existing instruction at a breakpoint target to determine which
breakpoint instruction to use. If the existing instruction is a
compressed instruction, C.EBREAK is used, otherwise EBREAK is used.

gdb/ChangeLog:

* disasm-selftests.c (print_one_insn_test): Add bfd_arch_riscv to
case with explicit breakpoint kind.
* riscv-tdep.c (show_use_compressed_breakpoints): Remove
'additional_info' and related logic.
(riscv_debug_breakpoints): New variable.
(riscv_breakpoint_kind_from_pc): Use the length of the existing
instruction to determine the breakpoint kind.
(_initialize_riscv_tdep): Add 'set/show debug riscv breakpoints'
flag. Update description of 'set/show riscv
use-compressed-breakpoints' flag.

Change Summary

Modification

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,16 @@
1+2018-09-28 John Baldwin <jhb@FreeBSD.org>
2+
3+ * disasm-selftests.c (print_one_insn_test): Add bfd_arch_riscv to
4+ case with explicit breakpoint kind.
5+ * riscv-tdep.c (show_use_compressed_breakpoints): Remove
6+ 'additional_info' and related logic.
7+ (riscv_debug_breakpoints): New variable.
8+ (riscv_breakpoint_kind_from_pc): Use the length of the existing
9+ instruction to determine the breakpoint kind.
10+ (_initialize_riscv_tdep): Add 'set/show debug riscv breakpoints'
11+ flag. Update description of 'set/show riscv
12+ use-compressed-breakpoints' flag.
13+
114 2018-09-28 Andrew Burgess <andrew.burgess@embecosm.com>
215
316 (NEWS): Mention changes to frame related commands.
--- a/gdb/disasm-selftests.c
+++ b/gdb/disasm-selftests.c
@@ -77,9 +77,10 @@ print_one_insn_test (struct gdbarch *gdbarch)
7777 /* fall through */
7878 case bfd_arch_nios2:
7979 case bfd_arch_score:
80- /* nios2 and score need to know the current instruction to select
81- breakpoint instruction. Give the breakpoint instruction kind
82- explicitly. */
80+ case bfd_arch_riscv:
81+ /* nios2, riscv, and score need to know the current instruction
82+ to select breakpoint instruction. Give the breakpoint
83+ instruction kind explicitly. */
8384 int bplen;
8485 insn = gdbarch_sw_breakpoint_from_kind (gdbarch, 4, &bplen);
8586 len = bplen;
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -210,20 +210,9 @@ show_use_compressed_breakpoints (struct ui_file *file, int from_tty,
210210 struct cmd_list_element *c,
211211 const char *value)
212212 {
213- const char *additional_info;
214- struct gdbarch *gdbarch = target_gdbarch ();
215-
216- if (use_compressed_breakpoints == AUTO_BOOLEAN_AUTO)
217- if (riscv_has_feature (gdbarch, 'C'))
218- additional_info = _(" (currently on)");
219- else
220- additional_info = _(" (currently off)");
221- else
222- additional_info = "";
223-
224213 fprintf_filtered (file,
225214 _("Debugger's use of compressed breakpoints is set "
226- "to %s%s.\n"), value, additional_info);
215+ "to %s.\n"), value);
227216 }
228217
229218 /* The set and show lists for 'set riscv' and 'show riscv' prefixes. */
@@ -284,6 +273,11 @@ show_riscv_debug_variable (struct ui_file *file, int from_tty,
284273 c->name, value);
285274 }
286275
276+/* When this is set to non-zero debugging information about breakpoint
277+ kinds will be printed. */
278+
279+static unsigned int riscv_debug_breakpoints = 0;
280+
287281 /* When this is set to non-zero debugging information about inferior calls
288282 will be printed. */
289283
@@ -417,7 +411,18 @@ riscv_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
417411 {
418412 if (use_compressed_breakpoints == AUTO_BOOLEAN_AUTO)
419413 {
420- if (riscv_has_feature (gdbarch, 'C'))
414+ gdb_byte buf[1];
415+
416+ /* Read the opcode byte to determine the instruction length. */
417+ read_code (*pcptr, buf, 1);
418+
419+ if (riscv_debug_breakpoints)
420+ fprintf_unfiltered
421+ (gdb_stdlog,
422+ "Using %s for breakpoint at %s (instruction length %d)\n",
423+ riscv_insn_length (buf[0]) == 2 ? "C.EBREAK" : "EBREAK",
424+ paddress (gdbarch, *pcptr), riscv_insn_length (buf[0]));
425+ if (riscv_insn_length (buf[0]) == 2)
421426 return 2;
422427 else
423428 return 4;
@@ -2953,6 +2958,16 @@ _initialize_riscv_tdep (void)
29532958 &showdebugriscvcmdlist, "show debug riscv ", 0,
29542959 &showdebuglist);
29552960
2961+ add_setshow_zuinteger_cmd ("breakpoints", class_maintenance,
2962+ &riscv_debug_breakpoints, _("\
2963+Set riscv breakpoint debugging."), _("\
2964+Show riscv breakpoint debugging."), _("\
2965+When non-zero, print debugging information for the riscv specific parts\n\
2966+of the breakpoint mechanism."),
2967+ NULL,
2968+ show_riscv_debug_variable,
2969+ &setdebugriscvcmdlist, &showdebugriscvcmdlist);
2970+
29562971 add_setshow_zuinteger_cmd ("infcall", class_maintenance,
29572972 &riscv_debug_infcall, _("\
29582973 Set riscv inferior call debugging."), _("\
@@ -2989,10 +3004,10 @@ of the stack unwinding mechanism."),
29893004 _("\
29903005 Set debugger's use of compressed breakpoints."), _(" \
29913006 Show debugger's use of compressed breakpoints."), _("\
2992-Debugging compressed code requires compressed breakpoints to be used. If\n \
2993-left to 'auto' then gdb will use them if $misa indicates the C extension\n \
2994-is supported. If that doesn't give the correct behavior, then this option\n\
2995-can be used."),
3007+Debugging compressed code requires compressed breakpoints to be used. If\n\
3008+left to 'auto' then gdb will use them if the existing instruction is a\n\
3009+compressed instruction. If that doesn't give the correct behavior, then\n\
3010+this option can be used."),
29963011 NULL,
29973012 show_use_compressed_breakpoints,
29983013 &setriscvcmdlist,