Skip to contentSkip to conversation

cpu-exec: make TBs generated codes unlinked when -singlestep

PATCH In review Jincheng Miao 4 participants 7 messages Jul 25, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpu-exec: make TBs generated codes unlinked when -singlestep

'-singlestep' option will make TB contains only one instruction, so that the qemu_log could output trace log when CPU_LOG_EXEC sets, and it could help developers to debug control flow.

But currently, in cpu_exec(), it doesn't check singlestep when tb_add_jump(), so the TB linked is executed siliently. Therefore, this patch adds singlestep check before tb_add_jump().

---
 cpu-exec.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
cpu-exec.c +2 -2
index 38e5f02..64b7289 100644
@@ -622,8 +622,8 @@ int cpu_exec(CPUArchState *env)
                 }
                 /* see if we can patch the calling TB. When the TB
                    spans two pages, we cannot safely do a direct
-                   jump. */
-                if (next_tb != 0 && tb->page_addr[1] == -1) {
+                   jump. So as when singlestep is enabled. */
+                if (next_tb != 0 && tb->page_addr[1] == -1 && !singlestep) {
                     tb_add_jump((TranslationBlock *)(next_tb & ~TB_EXIT_MASK),
                                 next_tb & TB_EXIT_MASK, tb);
                 }
Signature · 1 line
1.7.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Jincheng Miao

'-singlestep' option will make TB contains only one instruction, so that the qemu_log could output trace log when CPU_LOG_EXEC sets, and it could help developers to debug control flow.

But currently, in cpu_exec(), it doesn't check singlestep when tb_add_jump(), so the TB linked is executed siliently. Therefore, this patch adds singlestep check before tb_add_jump().

Reasonable. I've been thinking that we simply shoudn't emit goto_tb under single-step. That does require fixes to all but 2 or 3 of the backends though, and this patch attacks the problem all in one place.

r~

#2 lore raw
Quoted 9 lines · Richard Henderson
Quoted 8 lines · Jincheng Miao

'-singlestep' option will make TB contains only one instruction, so that the qemu_log could output trace log when CPU_LOG_EXEC sets, and it could help developers to debug control flow.

But currently, in cpu_exec(), it doesn't check singlestep when tb_add_jump(), so the TB linked is executed siliently. Therefore, this patch adds singlestep check before tb_add_jump().

Quoted 5 lines
Quoted 1 line

Reasonable. I've been thinking that we simply shoudn't emit goto_tb under single-step. That does require fixes to all but 2 or 3 of the backends though, and this patch attacks the problem all in one place.

Huh? We already don't emit goto_tb if single-stepping, surely? (Well, I guess some of the backends might well be broken, but in that case they probably don't get the other bits of singlestep support right either...)

-- PMM

#3 lore raw
Quoted 4 lines · Peter Maydell

Huh? We already don't emit goto_tb if single-stepping, surely? (Well, I guess some of the backends might well be broken, but in that case they probably don't get the other bits of singlestep support right either...)

Indeed. I noticed this a month or so ago.

Almost all backends check the gdb env->single_step to prevent goto_tb, but forget about the tcg debugging singlestep.

r~

#4 lore raw
Quoted 10 lines · Richard Henderson
Quoted 4 lines · Peter Maydell

Huh? We already don't emit goto_tb if single-stepping, surely? (Well, I guess some of the backends might well be broken, but in that case they probably don't get the other bits of singlestep support right either...)

Indeed. I noticed this a month or so ago.

Almost all backends check the gdb env->single_step to prevent goto_tb, but forget about the tcg debugging singlestep.

Oh, we have two flavours of singlestep? That's confusing... (I'm currently working on the ARMv8 architectural singlestep, which will make 3 for target-arm.)

thanks
-- PMM

#5 lore raw
Quoted 11 lines · Peter Maydell
Quoted 9 lines · Richard Henderson
Quoted 4 lines · Peter Maydell

Huh? We already don't emit goto_tb if single-stepping, surely? (Well, I guess some of the backends might well be broken, but in that case they probably don't get the other bits of singlestep support right either...)

Indeed. I noticed this a month or so ago.

Almost all backends check the gdb env->single_step to prevent goto_tb, but forget about the tcg debugging singlestep.

Oh, we have two flavours of singlestep? That's confusing...

IMHO, CPUState->singlestep_enabled is a cpu execute mode, for emulating it, an exception should be raised.

But '-singlestep' from command line rules qemu how to generate TBs and their generated codes. In this situation, a TB only contains one instruction, and should be unlinked.

Am I right?

Quoted 5 lines

(I'm currently working on the ARMv8 architectural singlestep, which will make 3 for target-arm.)

thanks
-- PMM

Tested-by on v1 1/1
#6 lore raw
In reply to Jincheng Miao

Hello,

Quoted 9 lines · Jincheng Miao

'-singlestep' option will make TB contains only one instruction, so that the qemu_log could output trace log when CPU_LOG_EXEC sets, and it could help developers to debug control flow.

But currently, in cpu_exec(), it doesn't check singlestep when tb_add_jump(), so the TB linked is executed siliently. Therefore, this patch adds singlestep check before tb_add_jump().

I tested your patch in an environment generating run time traces and it works fine.

Thanks,

Laurent

Quoted 23 lines
---
 cpu-exec.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
cpu-exec.c +2 -3
index 38e5f02..64b7289 100644
@@ -622,8 +622,8 @@ int cpu_exec(CPUArchState *env)
                 }
                 /* see if we can patch the calling TB. When the TB
                    spans two pages, we cannot safely do a direct
-                   jump. */
-                if (next_tb != 0 && tb->page_addr[1] == -1) {
+                   jump. So as when singlestep is enabled. */
+                if (next_tb != 0 && tb->page_addr[1] == -1 && !singlestep) {
                     tb_add_jump((TranslationBlock *)(next_tb & ~TB_EXIT_MASK),
                                 next_tb & TB_EXIT_MASK, tb);
                 }
--

1.7.1