Skip to contentSkip to conversation

Fix breakpoints in nios2 user-mode emulation.

PATCH In review Sandra Loosemore 3 participants 5 messages Sep 11, 2018 – Sep 12, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix breakpoints in nios2 user-mode emulation.

Without this patch, QEMU exits immediately when it execution stops at a breakpoint, instead of reporting it to GDB.

---
 linux-user/nios2/cpu_loop.c | 3 +++
 1 file changed, 3 insertions(+)
linux-user/nios2/cpu_loop.c +3 -0
index dac7a06..a5ae37f 100644
@@ -71,6 +71,9 @@ void cpu_loop(CPUNios2State *env)
                 gdbsig = TARGET_SIGTRAP;
                 break;
             }
+        case EXCP_DEBUG:
+            gdbsig = TARGET_SIGTRAP;
+            break;
         case 0xaa:
             switch (env->regs[R_PC]) {
             /*case 0x1000:*/  /* TODO:__kuser_helper_version */
Signature · 1 line
2.8.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Sandra Loosemore

Without this patch, QEMU exits immediately when it execution stops at a breakpoint, instead of reporting it to GDB.

---
 linux-user/nios2/cpu_loop.c | 3 +++
 1 file changed, 3 insertions(+)
linux-user/nios2/cpu_loop.c +0 -0
index dac7a06..a5ae37f 100644

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

Quoted 6 lines
linux-user/nios2/cpu_loop.c +3 -0
@@ -71,6 +71,9 @@ void cpu_loop(CPUNios2State *env)
                 gdbsig = TARGET_SIGTRAP;
                 break;
             }
+        case EXCP_DEBUG:
+            gdbsig = TARGET_SIGTRAP;
+            break;

This really isn't complete. You set gdbsig from odd places instead of using queue_signal; you fail to honor the return value from gdb_handlesig.

But I suppose those should be separate patches, so

r~

#2 lore raw
Quoted 24 lines · Richard Henderson
Quoted 13 lines · Sandra Loosemore

Without this patch, QEMU exits immediately when it execution stops at a breakpoint, instead of reporting it to GDB.

---
  linux-user/nios2/cpu_loop.c | 3 +++
  1 file changed, 3 insertions(+)
linux-user/nios2/cpu_loop.c +0 -0
index dac7a06..a5ae37f 100644

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

Quoted 6 lines
linux-user/nios2/cpu_loop.c +3 -0
@@ -71,6 +71,9 @@ void cpu_loop(CPUNios2State *env)
                  gdbsig = TARGET_SIGTRAP;
                  break;
              }
+        case EXCP_DEBUG:
+            gdbsig = TARGET_SIGTRAP;
+            break;

This really isn't complete. You set gdbsig from odd places instead of using queue_signal; you fail to honor the return value from gdb_handlesig.

Quoted 2 lines

But I suppose those should be separate patches, so

Yes, I thought this code was rather ugly. But I thought a minimal patch to un-break GDB use would be easier to get in than any kind of rewrite, particularly given that I'm not terribly familiar with current best practices in the QEMU development community, etc.

-Sandra

#3 lore raw
In reply to Richard Henderson
Quoted 24 lines · Richard Henderson
Quoted 13 lines · Sandra Loosemore

Without this patch, QEMU exits immediately when it execution stops at a breakpoint, instead of reporting it to GDB.

---
 linux-user/nios2/cpu_loop.c | 3 +++
 1 file changed, 3 insertions(+)
linux-user/nios2/cpu_loop.c +0 -0
index dac7a06..a5ae37f 100644

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

Quoted 6 lines
linux-user/nios2/cpu_loop.c +3 -0
@@ -71,6 +71,9 @@ void cpu_loop(CPUNios2State *env)
                 gdbsig = TARGET_SIGTRAP;
                 break;
             }
+        case EXCP_DEBUG:
+            gdbsig = TARGET_SIGTRAP;
+            break;

This really isn't complete. You set gdbsig from odd places instead of using queue_signal; you fail to honor the return value from gdb_handlesig.

Quoted 2 lines

But I suppose those should be separate patches, so

At least the cpu_loops have been separated now.. I guess the next step is to audit each one for common features? There do seem to be some magic numbers in the nios loop which I find concerning.

Quoted 3 lines

r~

--
Alex Bennée

#4 lore raw
Quoted 27 lines · Alex Bennée
Quoted 24 lines · Richard Henderson
Quoted 13 lines · Sandra Loosemore

Without this patch, QEMU exits immediately when it execution stops at a breakpoint, instead of reporting it to GDB.

---
  linux-user/nios2/cpu_loop.c | 3 +++
  1 file changed, 3 insertions(+)
linux-user/nios2/cpu_loop.c +0 -0
index dac7a06..a5ae37f 100644

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

Quoted 6 lines
linux-user/nios2/cpu_loop.c +3 -0
@@ -71,6 +71,9 @@ void cpu_loop(CPUNios2State *env)
                  gdbsig = TARGET_SIGTRAP;
                  break;
              }
+        case EXCP_DEBUG:
+            gdbsig = TARGET_SIGTRAP;
+            break;

This really isn't complete. You set gdbsig from odd places instead of using queue_signal; you fail to honor the return value from gdb_handlesig.

Quoted 6 lines
Quoted 2 lines

But I suppose those should be separate patches, so

At least the cpu_loops have been separated now.. I guess the next step is to audit each one for common features? There do seem to be some magic numbers in the nios loop which I find concerning.

I'm not sure where the 0xaa value came from, but it is used to indicate syscalls through the kuser page mapped at address 0x1000 in user space. The addresses are a fixed ABI although not terribly well-documented AFAICT. There's code in target/nios2 that catches attempts to execute code on that page, and in the Linux kernel the code that goes on the kuser page is at the end of arch/nios2/kernel/entry.S. This all could certainly be better documented in the QEMU cpu_loop code too.

-Sandra