The break instruction in RISC-V does not have an immediate value field, so
the kernel cannot identify the purpose of each trap exception through the
opcode. This makes the existing identification schemes in other
architecture unsuitable for the RISC-V kernel. To solve this problem, this
patch adds kgdb_has_hit_break(), which can help RISC-V kernel identify
the KGDB trap exception.

Signed-off-by: Vincent Chen <vincent.c...@sifive.com>
Reviewed-by: Palmer Dabbelt <palmerdabb...@google.com>
Acked-by: Daniel Thompson <daniel.thomp...@linaro.org>
---
 include/linux/kgdb.h      |  1 +
 kernel/debug/debug_core.c | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
index b072aeb1fd78..03c64aa8ba36 100644
--- a/include/linux/kgdb.h
+++ b/include/linux/kgdb.h
@@ -311,6 +311,7 @@ extern int kgdb_hex2mem(char *buf, char *mem, int count);
 
 extern int kgdb_isremovedbreak(unsigned long addr);
 extern void kgdb_schedule_breakpoint(void);
+extern int kgdb_has_hit_break(unsigned long addr);
 
 extern int
 kgdb_handle_exception(int ex_vector, int signo, int err_code,
diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
index 2b7c9b67931d..01bc3eea3d4d 100644
--- a/kernel/debug/debug_core.c
+++ b/kernel/debug/debug_core.c
@@ -417,6 +417,18 @@ int kgdb_isremovedbreak(unsigned long addr)
        return 0;
 }
 
+int kgdb_has_hit_break(unsigned long addr)
+{
+       int i;
+
+       for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
+               if (kgdb_break[i].state == BP_ACTIVE &&
+                   kgdb_break[i].bpt_addr == addr)
+                       return 1;
+       }
+       return 0;
+}
+
 int dbg_remove_all_break(void)
 {
        int error;
-- 
2.7.4



_______________________________________________
Kgdb-bugreport mailing list
Kgdb-bugreport@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kgdb-bugreport

Reply via email to