From 08feb0168181fbbbbd8f7597c5f455db05b2e26a Mon Sep 17 00:00:00 2001 From: klugier Date: Fri, 29 Jun 2018 20:09:25 +0000 Subject: [PATCH] Gdb: #1 Added additional logs when kill close handle operation failed while breaking execution. #2 Gdb now supports displays up 200 entries of the stack to avoid ide not response when recursion is infinit. #3 Gdb now reports failure when breakpoint is not setted to TheIDE. #4 Remove infinit recursion in Ide::OnBreakpoint method. git-svn-id: svn://ultimatepp.org/upp/trunk@12028 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/ide/Core/Logger.h | 2 ++ uppsrc/ide/Debug.cpp | 12 ++++++++-- uppsrc/ide/Debuggers/Gdb.cpp | 46 ++++++++++++++++++++++++++---------- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/uppsrc/ide/Core/Logger.h b/uppsrc/ide/Core/Logger.h index 39f8b8726..9314710f1 100644 --- a/uppsrc/ide/Core/Logger.h +++ b/uppsrc/ide/Core/Logger.h @@ -4,6 +4,8 @@ #include #define UPP_FUNCTION_NAME String(__func__) +#define UPP_METHOD_NAME(ClassName) \ + String(ClassName) << "::" << UPP_FUNCTION_NAME << "(this = " << this << "): " namespace Upp { diff --git a/uppsrc/ide/Debug.cpp b/uppsrc/ide/Debug.cpp index 8b7cf6acd..d0879555d 100644 --- a/uppsrc/ide/Debug.cpp +++ b/uppsrc/ide/Debug.cpp @@ -367,9 +367,17 @@ void Ide::OnBreakpoint(int i) { if(!editfile.IsEmpty() && !designer && debugger) { String q = editor.GetBreakpoint(i); - if(q[0] != 0xe && !debugger->SetBreakpoint(editfile, i, q)) + if(q[0] != 0xe && !debugger->SetBreakpoint(editfile, i, q)) { + auto event = editor.WhenBreakpoint; + editor.WhenBreakpoint = {}; + if(!q.IsEmpty()) - editor.SetBreakpoint(i, q); + editor.SetBreakpoint(i, Null); + else + editor.SetBreakpoint(i, "1"); + + editor.WhenBreakpoint = event; + } } } diff --git a/uppsrc/ide/Debuggers/Gdb.cpp b/uppsrc/ide/Debuggers/Gdb.cpp index 9feebb337..0094b902f 100644 --- a/uppsrc/ide/Debuggers/Gdb.cpp +++ b/uppsrc/ide/Debuggers/Gdb.cpp @@ -1,5 +1,7 @@ #include "Debuggers.h" +#define METHOD_NAME UPP_METHOD_NAME("Gdb") + void Gdb::DebugBar(Bar& bar) { using namespace PdbKeys; @@ -15,7 +17,6 @@ void Gdb::DebugBar(Bar& bar) bar.Add(b, AK_STEPOUT, DbgImg::StepOut(), THISBACK1(Step, "finish")); 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 && pid, AK_BREAK, DbgImg::Stop(), THISBACK(BreakRunning)); bar.MenuSeparator(); bar.Add(b, AK_AUTOS, THISBACK1(SetTab, 0)); @@ -132,13 +133,16 @@ bool Gdb::TryBreak(const char *text) bool Gdb::SetBreakpoint(const String& filename, int line, const String& bp) { String bi = Bpoint(*host, filename, line); + + String command; if(bp.IsEmpty()) - FastCmd("clear " + bi); + command = "clear " + bi; else if(bp[0]==0xe || bp == "1") - FastCmd("b " + bi); + command = "b " + bi; else - FastCmd("b " + bi + " if " + bp); - return true; + command = "b " + bi + " if " + bp; + + return !FastCmd(command).IsEmpty(); } void Gdb::SetDisas(const String& text) @@ -303,7 +307,7 @@ bool Gdb::RunTo() else bi = Bpoint(*host, IdeGetFileName(), IdeGetFileLine()); if(!TryBreak("b " + bi)) { - Exclamation("No code at chosen location !"); + Exclamation("No code at chosen location!"); return false; } String e = DoRun(); @@ -319,13 +323,27 @@ void Gdb::BreakRunning() { #ifdef PLATFORM_WIN32 HANDLE h = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid); - if(h) { - DebugBreakProcess(h); - CloseHandle(h); + if(!h) { + auto error = t_("Failed to open debugge process."); + + Loge() << METHOD_NAME << error; + ErrorOK(error); + + return; } + + DebugBreakProcess(h); + CloseHandle(h); #endif #ifdef PLATFORM_POSIX - kill(pid, SIGINT); + if (kill(pid, SIGINT) == -1) { + auto error = t_("Failed to send SIGINT signal to debugge process."); + + Loge() << METHOD_NAME << error; + ErrorOK(error); + + return; + } #endif } @@ -369,12 +387,16 @@ void Gdb::DisasFocus() void Gdb::DropFrames() { + const int max_stack_trace_size = 200; + int i = 0; int q = ~frame; frame.Clear(); - for(;;) { + while(i < max_stack_trace_size) { String s = FormatFrame(FastCmd(Sprintf("frame %d", i))); - if(IsNull(s)) break; + if(IsNull(s)) { + break; + } frame.Add(i++, s); } frame <<= q;