From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JxRcA-0003BZ-Ag for qemu-devel@nongnu.org; Sat, 17 May 2008 14:58:42 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JxRc8-00039B-Rz for qemu-devel@nongnu.org; Sat, 17 May 2008 14:58:42 -0400 Received: from [199.232.76.173] (port=46268 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JxRc8-00038y-LL for qemu-devel@nongnu.org; Sat, 17 May 2008 14:58:40 -0400 Received: from savannah.gnu.org ([199.232.41.3]:41516 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JxRc8-00043Z-9a for qemu-devel@nongnu.org; Sat, 17 May 2008 14:58:40 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1JxRc3-0008HR-Lo for qemu-devel@nongnu.org; Sat, 17 May 2008 18:58:36 +0000 Received: from edgar_igl by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1JxRc2-0008H8-4P for qemu-devel@nongnu.org; Sat, 17 May 2008 18:58:34 +0000 MIME-Version: 1.0 Errors-To: edgar_igl Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: "Edgar E. Iglesias" Message-Id: Date: Sat, 17 May 2008 18:58:34 +0000 Subject: [Qemu-devel] [4478] Add support for the 'k' (kill) and 'D' (detach) packets ( Jason Wessel). Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 4478 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4478 Author: edgar_igl Date: 2008-05-17 18:58:29 +0000 (Sat, 17 May 2008) Log Message: ----------- Add support for the 'k' (kill) and 'D' (detach) packets (Jason Wessel). Implement the 'k' gdbserial packet which kills the qemu instance via the debugger stub. Implement the 'D' detach packet for the gdb stub such that you can disconnect gdb with the "detach" command. This required implementing a cpu_breakpoint_remove_all() and a cpu_watchpoint_remove_all() function to cleanup all the breakpoints and watchpoints prior to leaving the gdb stub else simulation can stop with no debugger attached. On a '?' packet remove all the breakpoints and watchpoints. This is considered more of a safety net in case you force killed gdb or it crashed and you are reconnecting. The identical behavior exists for kgdb in the linux kernel. Modified Paths: -------------- trunk/cpu-all.h trunk/exec.c trunk/gdbstub.c Modified: trunk/cpu-all.h =================================================================== --- trunk/cpu-all.h 2008-05-17 18:44:58 UTC (rev 4477) +++ trunk/cpu-all.h 2008-05-17 18:58:29 UTC (rev 4478) @@ -760,8 +760,10 @@ int cpu_watchpoint_insert(CPUState *env, target_ulong addr); int cpu_watchpoint_remove(CPUState *env, target_ulong addr); +void cpu_watchpoint_remove_all(CPUState *env); int cpu_breakpoint_insert(CPUState *env, target_ulong pc); int cpu_breakpoint_remove(CPUState *env, target_ulong pc); +void cpu_breakpoint_remove_all(CPUState *env); #define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */ #define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */ Modified: trunk/exec.c =================================================================== --- trunk/exec.c 2008-05-17 18:44:58 UTC (rev 4477) +++ trunk/exec.c 2008-05-17 18:58:29 UTC (rev 4478) @@ -1139,6 +1139,16 @@ return -1; } +/* Remove all watchpoints. */ +void cpu_watchpoint_remove_all(CPUState *env) { + int i; + + for (i = 0; i < env->nb_watchpoints; i++) { + tlb_flush_page(env, env->watchpoint[i].vaddr); + } + env->nb_watchpoints = 0; +} + /* add a breakpoint. EXCP_DEBUG is returned by the CPU loop if a breakpoint is reached */ int cpu_breakpoint_insert(CPUState *env, target_ulong pc) @@ -1162,6 +1172,17 @@ #endif } +/* remove all breakpoints */ +void cpu_breakpoint_remove_all(CPUState *env) { +#if defined(TARGET_HAS_ICE) + int i; + for(i = 0; i < env->nb_breakpoints; i++) { + breakpoint_invalidate(env, env->breakpoints[i]); + } + env->nb_breakpoints = 0; +#endif +} + /* remove a breakpoint */ int cpu_breakpoint_remove(CPUState *env, target_ulong pc) { Modified: trunk/gdbstub.c =================================================================== --- trunk/gdbstub.c 2008-05-17 18:44:58 UTC (rev 4477) +++ trunk/gdbstub.c 2008-05-17 18:58:29 UTC (rev 4478) @@ -962,6 +962,12 @@ /* TODO: Make this return the correct value for user-mode. */ snprintf(buf, sizeof(buf), "S%02x", SIGTRAP); put_packet(s, buf); + /* Remove all the breakpoints when this query is issued, + * because gdb is doing and initial connect and the state + * should be cleaned up. + */ + cpu_breakpoint_remove_all(env); + cpu_watchpoint_remove_all(env); break; case 'c': if (*p != '\0') { @@ -985,6 +991,17 @@ } gdb_continue(s); return RS_IDLE; + case 'k': + /* Kill the target */ + fprintf(stderr, "\nQEMU: Terminated via GDBstub\n"); + exit(0); + case 'D': + /* Detach packet */ + cpu_breakpoint_remove_all(env); + cpu_watchpoint_remove_all(env); + gdb_continue(s); + put_packet(s, "OK"); + break; case 's': if (*p != '\0') { addr = strtoull(p, (char **)&p, 16);