Skip to contentSkip to conversation

Fix breakpoint support in Nios II user-mode emulation.

PATCH Applied Sandra Loosemore 3 participants 5 messages Feb 13, 2019 – Feb 25, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix breakpoint support in Nios II user-mode emulation.

Nios II user-mode emulation was missing handling for EXCP_DEBUG, making the gdb stub essentially useless. This patch adds the missing piece. The new code was copied from the existing EXCP_TRAP handling and is also similar to what other targets (e.g., arm) do with EXCP_DEBUG.

---
 linux-user/nios2/cpu_loop.c | 6 ++++++
 1 file changed, 6 insertions(+)
linux-user/nios2/cpu_loop.c +6 -0
index b96b1aa..5aa1eca 100644
@@ -73,6 +73,12 @@ void cpu_loop(CPUNios2State *env)
                 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
                 break;
             }
+        case EXCP_DEBUG:
+            info.si_signo = TARGET_SIGTRAP;
+            info.si_errno = 0;
+            info.si_code = TARGET_TRAP_BRKPT;
+            queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
+            break;
         case 0xaa:
             switch (env->regs[R_PC]) {
             /*case 0x1000:*/  /* TODO:__kuser_helper_version */
Signature · 1 line
2.8.1
#1 lore raw

CC'ing NiosII Maintainers

Quoted 28 lines · Sandra Loosemore

Nios II user-mode emulation was missing handling for EXCP_DEBUG, making the gdb stub essentially useless. This patch adds the missing piece. The new code was copied from the existing EXCP_TRAP handling and is also similar to what other targets (e.g., arm) do with EXCP_DEBUG.

---
 linux-user/nios2/cpu_loop.c | 6 ++++++
 1 file changed, 6 insertions(+)
linux-user/nios2/cpu_loop.c +6 -0
index b96b1aa..5aa1eca 100644
@@ -73,6 +73,12 @@ void cpu_loop(CPUNios2State *env)
                 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
                 break;
             }
+        case EXCP_DEBUG:
+            info.si_signo = TARGET_SIGTRAP;
+            info.si_errno = 0;
+            info.si_code = TARGET_TRAP_BRKPT;
+            queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
+            break;
         case 0xaa:
             switch (env->regs[R_PC]) {
             /*case 0x1000:*/  /* TODO:__kuser_helper_version */
Reviewed-by on v1 1/1
#3 lore raw
In reply to Sandra Loosemore
Quoted 18 lines · Sandra Loosemore

Nios II user-mode emulation was missing handling for EXCP_DEBUG, making the gdb stub essentially useless. This patch adds the missing piece. The new code was copied from the existing EXCP_TRAP handling and is also similar to what other targets (e.g., arm) do with EXCP_DEBUG.

---
 linux-user/nios2/cpu_loop.c | 6 ++++++
 1 file changed, 6 insertions(+)
linux-user/nios2/cpu_loop.c +0 -0
index b96b1aa..5aa1eca 100644
@@ -73,6 +73,12 @@ void cpu_loop(CPUNios2State *env)
                 queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
                 break;

linux-user/nios2/cpu_loop.c void cpu_loop(CPUNios2State *env) · line 84

Quoted 10 lines
linux-user/nios2/cpu_loop.c +6 -0
             }
+        case EXCP_DEBUG:
+            info.si_signo = TARGET_SIGTRAP;
+            info.si_errno = 0;
+            info.si_code = TARGET_TRAP_BRKPT;
+            queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
+            break;
         case 0xaa:
             switch (env->regs[R_PC]) {
             /*case 0x1000:*/  /* TODO:__kuser_helper_version */

I don't know NiosII at all, but a quick check of the kernel sources suggests this is correct, so

thanks
-- PMM

#4 lore raw
In reply to Sandra Loosemore
Quoted 18 lines · Sandra Loosemore

Nios II user-mode emulation was missing handling for EXCP_DEBUG, making the gdb stub essentially useless. This patch adds the missing piece. The new code was copied from the existing EXCP_TRAP handling and is also similar to what other targets (e.g., arm) do with EXCP_DEBUG.

---
  linux-user/nios2/cpu_loop.c | 6 ++++++
  1 file changed, 6 insertions(+)
linux-user/nios2/cpu_loop.c +0 -0
index b96b1aa..5aa1eca 100644
@@ -73,6 +73,12 @@ void cpu_loop(CPUNios2State *env)
                  queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
                  break;

linux-user/nios2/cpu_loop.c void cpu_loop(CPUNios2State *env) · line 84

Quoted 10 lines
linux-user/nios2/cpu_loop.c +6 -0
              }
+        case EXCP_DEBUG:
+            info.si_signo = TARGET_SIGTRAP;
+            info.si_errno = 0;
+            info.si_code = TARGET_TRAP_BRKPT;
+            queue_signal(env, info.si_signo, QEMU_SI_FAULT, &info);
+            break;
          case 0xaa:
              switch (env->regs[R_PC]) {
              /*case 0x1000:*/  /* TODO:__kuser_helper_version */

Applied to my linux-user branch.

Thanks,
Laurent