Skip to content

Commit c148a05

Browse files
committed
Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20211016' into staging
Move gdb singlestep to generic code Fix cpu_common_props # gpg: Signature made Sat 16 Oct 2021 11:13:54 AM PDT # gpg: using RSA key 7A481E78868B4DB6A85A05C064DF38E8AF7E215F # gpg: issuer "[email protected]" # gpg: Good signature from "Richard Henderson <[email protected]>" [ultimate] * remotes/rth/tags/pull-tcg-20211016: (24 commits) Revert "cpu: Move cpu_common_props to hw/core/cpu.c" target/xtensa: Drop check for singlestep_enabled target/tricore: Drop check for singlestep_enabled target/sh4: Drop check for singlestep_enabled target/s390x: Drop check for singlestep_enabled target/rx: Drop checks for singlestep_enabled target/riscv: Remove exit_tb and lookup_and_goto_ptr target/riscv: Remove dead code after exception target/ppc: Drop exit checks for singlestep_enabled target/openrisc: Drop checks for singlestep_enabled target/mips: Drop exit checks for singlestep_enabled target/mips: Fix single stepping target/microblaze: Drop checks for singlestep_enabled target/microblaze: Check CF_NO_GOTO_TB for DISAS_JUMP target/m68k: Drop checks for singlestep_enabled target/i386: Drop check for singlestep_enabled target/i386: Check CF_NO_GOTO_TB for dc->jmp_opt target/hppa: Drop checks for singlestep_enabled target/arm: Drop checks for singlestep_enabled target/hexagon: Drop checks for singlestep_enabled ... Signed-off-by: Richard Henderson <[email protected]>
2 parents 6587b0c + 995b87d commit c148a05

34 files changed

+141
-386
lines changed

accel/tcg/cpu-exec.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,17 @@ cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit)
383383
cc->set_pc(cpu, last_tb->pc);
384384
}
385385
}
386+
387+
/*
388+
* If gdb single-step, and we haven't raised another exception,
389+
* raise a debug exception. Single-step with another exception
390+
* is handled in cpu_handle_exception.
391+
*/
392+
if (unlikely(cpu->singlestep_enabled) && cpu->exception_index == -1) {
393+
cpu->exception_index = EXCP_DEBUG;
394+
cpu_loop_exit(cpu);
395+
}
396+
386397
return last_tb;
387398
}
388399

cpu.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,27 @@ void cpu_exec_unrealizefn(CPUState *cpu)
179179
cpu_list_remove(cpu);
180180
}
181181

182+
static Property cpu_common_props[] = {
183+
#ifndef CONFIG_USER_ONLY
184+
/*
185+
* Create a memory property for softmmu CPU object,
186+
* so users can wire up its memory. (This can't go in hw/core/cpu.c
187+
* because that file is compiled only once for both user-mode
188+
* and system builds.) The default if no link is set up is to use
189+
* the system address space.
190+
*/
191+
DEFINE_PROP_LINK("memory", CPUState, memory, TYPE_MEMORY_REGION,
192+
MemoryRegion *),
193+
#endif
194+
DEFINE_PROP_BOOL("start-powered-off", CPUState, start_powered_off, false),
195+
DEFINE_PROP_END_OF_LIST(),
196+
};
197+
198+
void cpu_class_init_props(DeviceClass *dc)
199+
{
200+
device_class_set_props(dc, cpu_common_props);
201+
}
202+
182203
void cpu_exec_initfn(CPUState *cpu)
183204
{
184205
cpu->as = NULL;

hw/core/cpu-common.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -257,21 +257,6 @@ static int64_t cpu_common_get_arch_id(CPUState *cpu)
257257
return cpu->cpu_index;
258258
}
259259

260-
static Property cpu_common_props[] = {
261-
#ifndef CONFIG_USER_ONLY
262-
/* Create a memory property for softmmu CPU object,
263-
* so users can wire up its memory. (This can't go in hw/core/cpu.c
264-
* because that file is compiled only once for both user-mode
265-
* and system builds.) The default if no link is set up is to use
266-
* the system address space.
267-
*/
268-
DEFINE_PROP_LINK("memory", CPUState, memory, TYPE_MEMORY_REGION,
269-
MemoryRegion *),
270-
#endif
271-
DEFINE_PROP_BOOL("start-powered-off", CPUState, start_powered_off, false),
272-
DEFINE_PROP_END_OF_LIST(),
273-
};
274-
275260
static void cpu_class_init(ObjectClass *klass, void *data)
276261
{
277262
DeviceClass *dc = DEVICE_CLASS(klass);
@@ -286,7 +271,7 @@ static void cpu_class_init(ObjectClass *klass, void *data)
286271
dc->realize = cpu_common_realizefn;
287272
dc->unrealize = cpu_common_unrealizefn;
288273
dc->reset = cpu_common_reset;
289-
device_class_set_props(dc, cpu_common_props);
274+
cpu_class_init_props(dc);
290275
/*
291276
* Reason: CPUs still need special care by board code: wiring up
292277
* IRQs, adding reset handlers, halting non-first CPUs, ...

include/hw/core/cpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,7 @@ void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
10081008
GCC_FMT_ATTR(2, 3);
10091009

10101010
/* $(top_srcdir)/cpu.c */
1011+
void cpu_class_init_props(DeviceClass *dc);
10111012
void cpu_exec_initfn(CPUState *cpu);
10121013
void cpu_exec_realizefn(CPUState *cpu, Error **errp);
10131014
void cpu_exec_unrealizefn(CPUState *cpu);

target/alpha/translate.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,17 +3005,10 @@ static void alpha_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
30053005
tcg_gen_movi_i64(cpu_pc, ctx->base.pc_next);
30063006
/* FALLTHRU */
30073007
case DISAS_PC_UPDATED:
3008-
if (!ctx->base.singlestep_enabled) {
3009-
tcg_gen_lookup_and_goto_ptr();
3010-
break;
3011-
}
3012-
/* FALLTHRU */
3008+
tcg_gen_lookup_and_goto_ptr();
3009+
break;
30133010
case DISAS_PC_UPDATED_NOCHAIN:
3014-
if (ctx->base.singlestep_enabled) {
3015-
gen_excp_1(EXCP_DEBUG, 0);
3016-
} else {
3017-
tcg_gen_exit_tb(NULL, 0);
3018-
}
3011+
tcg_gen_exit_tb(NULL, 0);
30193012
break;
30203013
default:
30213014
g_assert_not_reached();

target/arm/translate-a64.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,6 @@ static inline void gen_goto_tb(DisasContext *s, int n, uint64_t dest)
404404
gen_a64_set_pc_im(dest);
405405
if (s->ss_active) {
406406
gen_step_complete_exception(s);
407-
} else if (s->base.singlestep_enabled) {
408-
gen_exception_internal(EXCP_DEBUG);
409407
} else {
410408
tcg_gen_lookup_and_goto_ptr();
411409
s->base.is_jmp = DISAS_NORETURN;
@@ -14879,7 +14877,7 @@ static void aarch64_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
1487914877
{
1488014878
DisasContext *dc = container_of(dcbase, DisasContext, base);
1488114879

14882-
if (unlikely(dc->base.singlestep_enabled || dc->ss_active)) {
14880+
if (unlikely(dc->ss_active)) {
1488314881
/* Note that this means single stepping WFI doesn't halt the CPU.
1488414882
* For conditional branch insns this is harmless unreachable code as
1488514883
* gen_goto_tb() has already handled emitting the debug exception
@@ -14891,11 +14889,7 @@ static void aarch64_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
1489114889
/* fall through */
1489214890
case DISAS_EXIT:
1489314891
case DISAS_JUMP:
14894-
if (dc->base.singlestep_enabled) {
14895-
gen_exception_internal(EXCP_DEBUG);
14896-
} else {
14897-
gen_step_complete_exception(dc);
14898-
}
14892+
gen_step_complete_exception(dc);
1489914893
break;
1490014894
case DISAS_NORETURN:
1490114895
break;

target/arm/translate.c

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ static void gen_exception_internal(int excp)
341341
tcg_temp_free_i32(tcg_excp);
342342
}
343343

344-
static void gen_step_complete_exception(DisasContext *s)
344+
static void gen_singlestep_exception(DisasContext *s)
345345
{
346346
/* We just completed step of an insn. Move from Active-not-pending
347347
* to Active-pending, and then also take the swstep exception.
@@ -357,30 +357,6 @@ static void gen_step_complete_exception(DisasContext *s)
357357
s->base.is_jmp = DISAS_NORETURN;
358358
}
359359

360-
static void gen_singlestep_exception(DisasContext *s)
361-
{
362-
/* Generate the right kind of exception for singlestep, which is
363-
* either the architectural singlestep or EXCP_DEBUG for QEMU's
364-
* gdb singlestepping.
365-
*/
366-
if (s->ss_active) {
367-
gen_step_complete_exception(s);
368-
} else {
369-
gen_exception_internal(EXCP_DEBUG);
370-
}
371-
}
372-
373-
static inline bool is_singlestepping(DisasContext *s)
374-
{
375-
/* Return true if we are singlestepping either because of
376-
* architectural singlestep or QEMU gdbstub singlestep. This does
377-
* not include the command line '-singlestep' mode which is rather
378-
* misnamed as it only means "one instruction per TB" and doesn't
379-
* affect the code we generate.
380-
*/
381-
return s->base.singlestep_enabled || s->ss_active;
382-
}
383-
384360
void clear_eci_state(DisasContext *s)
385361
{
386362
/*
@@ -837,7 +813,7 @@ static inline void gen_bx_excret_final_code(DisasContext *s)
837813
/* Is the new PC value in the magic range indicating exception return? */
838814
tcg_gen_brcondi_i32(TCG_COND_GEU, cpu_R[15], min_magic, excret_label);
839815
/* No: end the TB as we would for a DISAS_JMP */
840-
if (is_singlestepping(s)) {
816+
if (s->ss_active) {
841817
gen_singlestep_exception(s);
842818
} else {
843819
tcg_gen_exit_tb(NULL, 0);
@@ -2606,7 +2582,7 @@ static void gen_goto_tb(DisasContext *s, int n, target_ulong dest)
26062582
/* Jump, specifying which TB number to use if we gen_goto_tb() */
26072583
static inline void gen_jmp_tb(DisasContext *s, uint32_t dest, int tbno)
26082584
{
2609-
if (unlikely(is_singlestepping(s))) {
2585+
if (unlikely(s->ss_active)) {
26102586
/* An indirect jump so that we still trigger the debug exception. */
26112587
gen_set_pc_im(s, dest);
26122588
s->base.is_jmp = DISAS_JUMP;
@@ -9459,7 +9435,7 @@ static void arm_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
94599435
dc->page_start = dc->base.pc_first & TARGET_PAGE_MASK;
94609436

94619437
/* If architectural single step active, limit to 1. */
9462-
if (is_singlestepping(dc)) {
9438+
if (dc->ss_active) {
94639439
dc->base.max_insns = 1;
94649440
}
94659441

@@ -9794,7 +9770,7 @@ static void arm_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
97949770
* insn codepath itself.
97959771
*/
97969772
gen_bx_excret_final_code(dc);
9797-
} else if (unlikely(is_singlestepping(dc))) {
9773+
} else if (unlikely(dc->ss_active)) {
97989774
/* Unconditional and "condition passed" instruction codepath. */
97999775
switch (dc->base.is_jmp) {
98009776
case DISAS_SWI:
@@ -9889,7 +9865,7 @@ static void arm_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
98899865
/* "Condition failed" instruction codepath for the branch/trap insn */
98909866
gen_set_label(dc->condlabel);
98919867
gen_set_condexec(dc);
9892-
if (unlikely(is_singlestepping(dc))) {
9868+
if (unlikely(dc->ss_active)) {
98939869
gen_set_pc_im(dc, dc->base.pc_next);
98949870
gen_singlestep_exception(dc);
98959871
} else {

target/avr/translate.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,11 +1087,7 @@ static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
10871087
tcg_gen_exit_tb(tb, n);
10881088
} else {
10891089
tcg_gen_movi_i32(cpu_pc, dest);
1090-
if (ctx->base.singlestep_enabled) {
1091-
gen_helper_debug(cpu_env);
1092-
} else {
1093-
tcg_gen_lookup_and_goto_ptr();
1094-
}
1090+
tcg_gen_lookup_and_goto_ptr();
10951091
}
10961092
ctx->base.is_jmp = DISAS_NORETURN;
10971093
}
@@ -3009,17 +3005,10 @@ static void avr_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
30093005
tcg_gen_movi_tl(cpu_pc, ctx->npc);
30103006
/* fall through */
30113007
case DISAS_LOOKUP:
3012-
if (!ctx->base.singlestep_enabled) {
3013-
tcg_gen_lookup_and_goto_ptr();
3014-
break;
3015-
}
3016-
/* fall through */
3008+
tcg_gen_lookup_and_goto_ptr();
3009+
break;
30173010
case DISAS_EXIT:
3018-
if (ctx->base.singlestep_enabled) {
3019-
gen_helper_debug(cpu_env);
3020-
} else {
3021-
tcg_gen_exit_tb(NULL, 0);
3022-
}
3011+
tcg_gen_exit_tb(NULL, 0);
30233012
break;
30243013
default:
30253014
g_assert_not_reached();

target/cris/translate.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3249,22 +3249,6 @@ static void cris_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
32493249
}
32503250
}
32513251

3252-
if (unlikely(dc->base.singlestep_enabled)) {
3253-
switch (is_jmp) {
3254-
case DISAS_TOO_MANY:
3255-
case DISAS_UPDATE_NEXT:
3256-
tcg_gen_movi_tl(env_pc, npc);
3257-
/* fall through */
3258-
case DISAS_JUMP:
3259-
case DISAS_UPDATE:
3260-
t_gen_raise_exception(EXCP_DEBUG);
3261-
return;
3262-
default:
3263-
break;
3264-
}
3265-
g_assert_not_reached();
3266-
}
3267-
32683252
switch (is_jmp) {
32693253
case DISAS_TOO_MANY:
32703254
gen_goto_tb(dc, 0, npc);

target/hexagon/translate.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ static void gen_end_tb(DisasContext *ctx)
6969
{
7070
gen_exec_counters(ctx);
7171
tcg_gen_mov_tl(hex_gpr[HEX_REG_PC], hex_next_PC);
72-
if (ctx->base.singlestep_enabled) {
73-
gen_exception_raw(EXCP_DEBUG);
74-
} else {
75-
tcg_gen_exit_tb(NULL, 0);
76-
}
72+
tcg_gen_exit_tb(NULL, 0);
7773
ctx->base.is_jmp = DISAS_NORETURN;
7874
}
7975

@@ -614,11 +610,7 @@ static void hexagon_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
614610
case DISAS_TOO_MANY:
615611
gen_exec_counters(ctx);
616612
tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], ctx->base.pc_next);
617-
if (ctx->base.singlestep_enabled) {
618-
gen_exception_raw(EXCP_DEBUG);
619-
} else {
620-
tcg_gen_exit_tb(NULL, 0);
621-
}
613+
tcg_gen_exit_tb(NULL, 0);
622614
break;
623615
case DISAS_NORETURN:
624616
break;

0 commit comments

Comments
 (0)