From 33ba3dd2d425dc8c50d82089df06e0cdc7dbd9e2 Mon Sep 17 00:00:00 2001 From: klugier Date: Sat, 30 Jun 2018 14:37:37 +0000 Subject: [PATCH] Gdb: Debugger now remembers the last selected position in stack trace + minor GDB creation improvement. git-svn-id: svn://ultimatepp.org/upp/trunk@12031 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/ide/Debuggers/Debuggers.h | 4 ++++ uppsrc/ide/Debuggers/Gdb.cpp | 32 ++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/uppsrc/ide/Debuggers/Debuggers.h b/uppsrc/ide/Debuggers/Debuggers.h index 0dcf4e6d7..6ff6ad7e9 100644 --- a/uppsrc/ide/Debuggers/Debuggers.h +++ b/uppsrc/ide/Debuggers/Debuggers.h @@ -152,6 +152,8 @@ public: String autoline; bool firstrun; + int frame_idx; + int pid = 0; // debugee pid String DoRun(); @@ -226,6 +228,8 @@ public: Gdb(); private: + void RestoreFramePos(); + bool CreateDbg(One& host, const String& exeFile, bool console); private: diff --git a/uppsrc/ide/Debuggers/Gdb.cpp b/uppsrc/ide/Debuggers/Gdb.cpp index f8d00c6fe..00b8a0a1f 100644 --- a/uppsrc/ide/Debuggers/Gdb.cpp +++ b/uppsrc/ide/Debuggers/Gdb.cpp @@ -388,7 +388,7 @@ void Gdb::DisasFocus() void Gdb::DropFrames() { int i = 0; - int q = ~frame; + frame.Clear(); while(i <= max_stack_trace_size) { auto s = ObtainFrame(i); @@ -407,7 +407,11 @@ void Gdb::DropFrames() frame.Add(i++, s); } - frame <<= q; + if (frame_idx == -1 && frame.GetCount() >= 0) { + frame_idx = 0; + } + + RestoreFramePos(); } String Gdb::ObtainFrame(int frame_idx) @@ -419,15 +423,20 @@ void Gdb::SwitchFrame() { auto i = static_cast(~frame); if (i == max_stack_trace_size) { - i = 0; + RestoreFramePos(); + return; } + frame_idx = i; + Cmdp(Sprintf("frame %d", i), i); } void Gdb::SwitchThread() { - int i = (int)~threads; + frame_idx = -1; + + int i = static_cast(~threads); Cmdp(Sprintf("thread %d", i), i); } @@ -443,6 +452,13 @@ bool Gdb::Key(dword key, int count) return Ctrl::Key(key, count); } +void Gdb::RestoreFramePos() +{ + if (frame_idx >= 0 && frame_idx < frame.GetCount()) { + frame <<= frame_idx; + } +} + bool Gdb::Create(One&& _host, const String& exefile, const String& cmdline, bool console) { host = pick(_host); @@ -512,7 +528,8 @@ void Gdb::Periodic() } Gdb::Gdb() - : max_stack_trace_size(200) + : frame_idx(-1) + , max_stack_trace_size(200) { locals.NoHeader(); locals.AddColumn("", 1); @@ -573,10 +590,9 @@ Gdb::Gdb() One GdbCreate(One&& host, const String& exefile, const String& cmdline, bool console) { - Gdb *dbg = new Gdb; + One dbg = MakeOne(); if(!dbg->Create(pick(host), exefile, cmdline, console)) { - delete dbg; - return NULL; + return nullptr; } return dbg; }