From 45f652c44e9d64d2c76227e1b333de1da4943052 Mon Sep 17 00:00:00 2001 From: micio Date: Sat, 28 Apr 2012 20:00:32 +0000 Subject: [PATCH] Ide/Debuggers /Gdb_MI2 : added asynchronous break command git-svn-id: svn://ultimatepp.org/upp/trunk@4872 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/ide/Debuggers/Gdb_MI2.cpp | 38 +++++++++++++++++++++++++++++--- uppsrc/ide/Debuggers/Gdb_MI2.h | 1 + 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/uppsrc/ide/Debuggers/Gdb_MI2.cpp b/uppsrc/ide/Debuggers/Gdb_MI2.cpp index 242158712..f0ee55a4d 100644 --- a/uppsrc/ide/Debuggers/Gdb_MI2.cpp +++ b/uppsrc/ide/Debuggers/Gdb_MI2.cpp @@ -10,6 +10,7 @@ void Gdb_MI2::DebugBar(Bar& bar) { bar.Add("Stop debugging", THISBACK(Stop)).Key(K_SHIFT_F5); bar.Separator(); + bar.Add("Asynchronous break", THISBACK(AsyncBrk)); bool b = !IdeIsDebugLock(); bar.Add(b, "Step into", DbgImg::StepInto(), THISBACK1(Step, disas.HasFocus() ? "exec-step-instruction" : "exec-step")).Key(K_F11); bar.Add(b, "Step over", DbgImg::StepOver(), THISBACK1(Step, disas.HasFocus() ? "exec-next-instruction" : "exec-next")).Key(K_F10); @@ -115,6 +116,24 @@ void Gdb_MI2::Run() IdeActivateBottom(); } +void Gdb_MI2::AsyncBrk() +{ + // send an interrupt command to all running threads + MICmd("exec-interrupt --all"); + + // gdb usually returns to command prompt instantly, BEFORE + // giving out stop reason, which we need. So, we wait some + // milliseconds and re-read (non blocking) GDB output to get it + for(int i = 0; i < 20 && !stopped; i++) + { + Sleep(100); + ReadGdb(false); + } + + // if target is correctly stopped, 'stopped' flag should be already set + // so we don't care here. If not set, target can't be stopped. +} + void Gdb_MI2::Stop() { stopped = true; @@ -489,7 +508,7 @@ MIValue Gdb_MI2::MICmd(const char *cmdLine) // sends command to debugger and get result data // should handle dbg unexpected termination ? - if(!dbg || !dbg->IsRunning() || IdeIsDebugLock()) + if(!dbg || !dbg->IsRunning() /* || IdeIsDebugLock() */) return MIValue(); // consume previous output from gdb... don't know why sometimes @@ -684,8 +703,11 @@ void Gdb_MI2::LogFrame(String const &msg, MIValue &frame) // check for stop reason void Gdb_MI2::CheckStopReason(void) { - ASSERT(!stopReason.IsEmpty()); - String reason = stopReason["reason"]; + String reason; + if(stopReason.IsEmpty()) + reason = "unknown reason"; + else + reason = stopReason["reason"]; if(reason == "exited-normally") { Stop(); @@ -701,6 +723,10 @@ void Gdb_MI2::CheckStopReason(void) LogFrame("Hit breakpoint", stopReason["frame"]); SyncIde(); } + else if(reason == "unknown reason") + { + PutConsole("Stopped by unknown reason"); + } else { LogFrame(Format("Stopped, reason '%s'", reason), stopReason["frame"]); @@ -1473,6 +1499,12 @@ bool Gdb_MI2::Create(One _host, const String& exefile, const String& cmdli watches.WhenAcceptEdit = THISBACK(SyncData); tab <<= THISBACK(SyncData); + // this one will allow asynchronous break of running app + MICmd("gdb-set target-async 1"); + MICmd("gdb-set pagination off"); + MICmd("gdb-set non-stop on"); +// MICmd("gdb-set interactive-mode off"); + MICmd("gdb-set disassembly-flavor intel"); MICmd("gdb-set exec-done-display off"); MICmd("gdb-set annotate 1"); diff --git a/uppsrc/ide/Debuggers/Gdb_MI2.h b/uppsrc/ide/Debuggers/Gdb_MI2.h index 5feec9938..ec39eff32 100644 --- a/uppsrc/ide/Debuggers/Gdb_MI2.h +++ b/uppsrc/ide/Debuggers/Gdb_MI2.h @@ -216,6 +216,7 @@ class Gdb_MI2 : public Debugger, public ParentCtrl // debugger IDE inteface virtual void DebugBar(Bar& bar); virtual bool SetBreakpoint(const String& filename, int line, const String& bp); + virtual void AsyncBrk(); virtual bool RunTo(); virtual void Run(); virtual void Stop();