From f7ab65cd6744bc3f6d014f756b065a5e4d4783bb Mon Sep 17 00:00:00 2001 From: cxl Date: Tue, 26 Jun 2018 07:50:29 +0000 Subject: [PATCH] ide: GDB now supports breaking the process in Win32 git-svn-id: svn://ultimatepp.org/upp/trunk@12017 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/ide/Debuggers/Debuggers.h | 6 ++++++ uppsrc/ide/Debuggers/Gdb.cpp | 33 +++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/uppsrc/ide/Debuggers/Debuggers.h b/uppsrc/ide/Debuggers/Debuggers.h index c36fabb1a..0a9cb3f53 100644 --- a/uppsrc/ide/Debuggers/Debuggers.h +++ b/uppsrc/ide/Debuggers/Debuggers.h @@ -152,6 +152,10 @@ public: String autoline; bool firstrun; + int pid = 0; // debugee pid + + String DoRun(); + bool Result(String& result, const String& s); void AddReg(const char *reg, Label *lbl) { regname.Add(reg); reglbl.Add(lbl); } @@ -205,6 +209,8 @@ public: void CopyStack(); void CopyStackAll(); void CopyDisas(); + + void BreakRunning(); bool Create(One&& host, const String& exefile, const String& cmdline, bool console); diff --git a/uppsrc/ide/Debuggers/Gdb.cpp b/uppsrc/ide/Debuggers/Gdb.cpp index 094518c75..c7b5ad97d 100644 --- a/uppsrc/ide/Debuggers/Gdb.cpp +++ b/uppsrc/ide/Debuggers/Gdb.cpp @@ -16,7 +16,7 @@ void Gdb::DebugBar(Bar& bar) bar.Add(b, AK_RUNTO, DbgImg::RunTo(), THISBACK(DoRunTo)); bar.Add(b, AK_RUN, DbgImg::Run(), THISBACK(Run)); // bar.Add(b, AK_SETIP, DbgImg::SetIp(), THISBACK(SetIp)); -// bar.Add(!b, AK_STOP, DbgImg::Stop(), THISBACK(BreakRunning)); + bar.Add(!b && pid, AK_BREAK, DbgImg::Stop(), THISBACK(BreakRunning)); bar.MenuSeparator(); bar.Add(b, AK_AUTOS, THISBACK1(SetTab, 0)); bar.Add(b, AK_LOCALS, THISBACK1(SetTab, 1)); @@ -276,6 +276,19 @@ String Gdb::Cmdp(const char *cmdline, bool fr) return s; } +String Gdb::DoRun() +{ + if(firstrun) { + firstrun = false; + Cmd("start"); + String s = Cmd("info inferior"); + int q = s.FindAfter("process"); + pid = atoi(~s + q); + IdeSetBar(); + } + return Cmdp("continue"); +} + bool Gdb::RunTo() { if(IdeIsDebugLock()) @@ -293,8 +306,7 @@ bool Gdb::RunTo() Exclamation("No code at chosen location !"); return false; } - String e = Cmdp(firstrun ? "run" : "continue"); - firstrun = false; + String e = DoRun(); FastCmd("clear " + bi); if(df) disas.SetFocus(); @@ -303,12 +315,23 @@ bool Gdb::RunTo() return true; } +void Gdb::BreakRunning() +{ +#ifdef PLATFORM_WIN32 + HANDLE h = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid); + if(h) { + DebugBreakProcess(h); + CloseHandle(h); + } +#endif +} + void Gdb::Run() { if(IdeIsDebugLock()) return; - CheckEnd(Cmdp(firstrun ? "run" : "continue")); - firstrun = false; + String s = DoRun(); + CheckEnd(s); IdeActivateBottom(); }