From 8a71b339ee3000c5ba495e19048254e60b01decc Mon Sep 17 00:00:00 2001 From: Stanislav Shwartsman Date: Fri, 1 Aug 2008 08:36:04 +0000 Subject: [PATCH] Fixed breakpoint handling in SMP mode --- bochs/bx_debug/dbg_main.cc | 42 +++++++++++++++----------------------- bochs/bx_debug/debug.h | 4 ++-- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/bochs/bx_debug/dbg_main.cc b/bochs/bx_debug/dbg_main.cc index 48c9b6ba2..cae67184a 100644 --- a/bochs/bx_debug/dbg_main.cc +++ b/bochs/bx_debug/dbg_main.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: dbg_main.cc,v 1.154 2008-07-26 14:20:24 sshwarts Exp $ +// $Id: dbg_main.cc,v 1.155 2008-08-01 08:36:04 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -1567,6 +1567,8 @@ void bx_dbg_unwatch(int read, bx_phy_address address) void bx_dbg_continue_command(void) { + int cpu; + // continue executing, until a guard found one_more: @@ -1575,6 +1577,12 @@ one_more: // the others a chance. bx_guard.guard_for |= BX_DBG_GUARD_CTRL_C; // stop on Ctrl-C + for (cpu=0; cpu < BX_SMP_PROCESSORS; cpu++) { + BX_CPU(cpu)->guard_found.guard_found = 0; + BX_CPU(cpu)->guard_found.icount = 0; + BX_CPU(cpu)->guard_found.time_tick = bx_pc_system.time_ticks(); + } + // update gui (disable continue command, enable stop command, etc.) sim_running->set(1); SIM->refresh_ci(); @@ -1598,19 +1606,16 @@ one_more: #define BX_DBG_DEFAULT_ICOUNT_QUANTUM 5 Bit32u quantum = (BX_SMP_PROCESSORS>1) ? BX_DBG_DEFAULT_ICOUNT_QUANTUM : 0; - int cpu; + Bit32u max_executed = 0; for (cpu=0; cpu < BX_SMP_PROCESSORS; cpu++) { - BX_CPU(cpu)->guard_found.guard_found = 0; - BX_CPU(cpu)->guard_found.icount = 0; - BX_CPU(cpu)->guard_found.time_tick = bx_pc_system.time_ticks(); + Bit64u cpu_icount = BX_CPU(cpu)->guard_found.icount; BX_CPU(cpu)->cpu_loop(quantum); + Bit32u executed = BX_CPU(cpu)->guard_found.icount - cpu_icount; + if (executed > max_executed) max_executed = executed; // set stop flag if a guard found other than icount or halted unsigned long found = BX_CPU(cpu)->guard_found.guard_found; stop_reason_t reason = (stop_reason_t) BX_CPU(cpu)->stop_reason; - if (found) { - stop = 1; - which = cpu; - } else if (reason != STOP_NO_REASON && reason != STOP_CPU_HALTED) { + if (found || (reason != STOP_NO_REASON && reason != STOP_CPU_HALTED)) { stop = 1; which = cpu; } @@ -1621,20 +1626,7 @@ one_more: #if BX_SUPPORT_SMP // increment time tick only after all processors have had their chance. - if (BX_SMP_PROCESSORS == 1) { - // all ticks are handled inside the cpu loop - } - else { - // We must tick by the number of instructions that were - // ACTUALLY executed, not the number that we asked it to - // execute. Even this is tricky with SMP because one might - // have hit a breakpoint, while others executed the whole - // quantum. - Bit32u max_executed = 0; - for (cpu=0; cpuguard_found.icount > max_executed) - max_executed = BX_CPU(cpu)->guard_found.icount; - } + if (BX_SMP_PROCESSORS > 1) { // potential deadlock if all processors are halted. Then // max_executed will be 0, tick will be incremented by zero, and // there will never be a timed event to wake them up. To avoid this, @@ -1690,9 +1682,7 @@ void bx_dbg_stepN_command(Bit32u count) // set stop flag if a guard found other than icount or halted unsigned long found = BX_CPU(cpu)->guard_found.guard_found; stop_reason_t reason = (stop_reason_t) BX_CPU(cpu)->stop_reason; - if (found) - stop = 1; - else if (reason != STOP_NO_REASON && reason != STOP_CPU_HALTED) + if (found || (reason != STOP_NO_REASON && reason != STOP_CPU_HALTED)) stop = 1; } #if BX_SUPPORT_SMP == 0 diff --git a/bochs/bx_debug/debug.h b/bochs/bx_debug/debug.h index a16059a5f..6b36200e6 100644 --- a/bochs/bx_debug/debug.h +++ b/bochs/bx_debug/debug.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: debug.h,v 1.44 2008-05-31 21:07:30 sshwarts Exp $ +// $Id: debug.h,v 1.45 2008-08-01 08:36:04 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -453,7 +453,7 @@ typedef struct { typedef struct bx_guard_found_t { unsigned long guard_found; unsigned iaddr_index; - Bit32u icount; // number of completed instructions + Bit64u icount; // number of completed instructions from last breakpoint hit Bit32u cs; // cs:eip and linear addr of instruction at guard point bx_address eip; bx_address laddr;