From 8a769224fec77bae1a2ffff779a16a03398c4dda Mon Sep 17 00:00:00 2001 From: cxl Date: Sun, 1 Jul 2018 20:54:57 +0000 Subject: [PATCH] ide: GDB improvements git-svn-id: svn://ultimatepp.org/upp/trunk@12037 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/Core/Other.h | 8 +- uppsrc/ide/Builders/Build.cpp | 2 +- uppsrc/ide/Core/Core.h | 1 - uppsrc/ide/Core/Core.upp | 2 - uppsrc/ide/Core/Host.cpp | 11 ++- uppsrc/ide/Core/Host.h | 7 +- uppsrc/ide/Core/HostTools.cpp | 6 -- uppsrc/ide/Core/HostTools.h | 12 --- uppsrc/ide/Debuggers/Debuggers.h | 20 ++--- uppsrc/ide/Debuggers/Gdb.cpp | 129 +++++++++++-------------------- uppsrc/ide/idefile.cpp | 2 +- 11 files changed, 64 insertions(+), 136 deletions(-) delete mode 100644 uppsrc/ide/Core/HostTools.cpp delete mode 100644 uppsrc/ide/Core/HostTools.h diff --git a/uppsrc/Core/Other.h b/uppsrc/Core/Other.h index 86b7b4bb5..9ee5e158a 100644 --- a/uppsrc/Core/Other.h +++ b/uppsrc/Core/Other.h @@ -69,7 +69,8 @@ public: One(T *newt) { ptr = newt; } template One(One&& p) { Pick(pick(p)); } - One(MakeOne&&); + template + One(MakeOne&&); One(const One& p, int) { ptr = p.IsEmpty() ? NULL : DeepCopyNew(*p); } One(const One& p) = delete; ~One() { Free(); } @@ -83,9 +84,10 @@ struct MakeOne : One { }; template -One::One(MakeOne&& p) +template +One::One(MakeOne&& p) { - Pick(pick(p)); + Attach(p.Detach()); } class Any : Moveable { diff --git a/uppsrc/ide/Builders/Build.cpp b/uppsrc/ide/Builders/Build.cpp index 360f46df7..943ba7e41 100644 --- a/uppsrc/ide/Builders/Build.cpp +++ b/uppsrc/ide/Builders/Build.cpp @@ -249,6 +249,7 @@ struct OneFileHost : Host { virtual String GetHostPath(const String& path) { return host->GetHostPath(path); } virtual String GetLocalPath(const String& path) { return host->GetLocalPath(path); } virtual String NormalizePath(const String& path) { return host->NormalizePath(path); } + virtual String NormalizeExecutablePath(const String& path) { return host->NormalizeExecutablePath(path); } virtual void DeleteFile(const Vector& path) { host->DeleteFile(path); } virtual void DeleteFolderDeep(const String& folder) { host->DeleteFolderDeep(folder); } virtual void ChDir(const String& path) { host->ChDir(path); } @@ -268,7 +269,6 @@ struct OneFileHost : Host { virtual void Launch(const char *cmdline, bool) { host->Launch(cmdline); } virtual void AddFlags(Index& cfg) { host->AddFlags(cfg); } virtual const Vector& GetExecutablesDirs() const { return host->GetExecutablesDirs(); } - virtual const HostTools& GetTools() const { return host->GetTools(); } virtual Vector GetFileInfo(const Vector& path) { Vector fi = host->GetFileInfo(path); diff --git a/uppsrc/ide/Core/Core.h b/uppsrc/ide/Core/Core.h index 8c74deb45..d471dbb8e 100644 --- a/uppsrc/ide/Core/Core.h +++ b/uppsrc/ide/Core/Core.h @@ -148,7 +148,6 @@ void IdeSetBar(); void IdeGotoFileAndId(const String& path, const String& id); -#include "HostTools.h" #include "Host.h" struct IdeMacro { diff --git a/uppsrc/ide/Core/Core.upp b/uppsrc/ide/Core/Core.upp index 5bd84b4fd..448dc9da7 100644 --- a/uppsrc/ide/Core/Core.upp +++ b/uppsrc/ide/Core/Core.upp @@ -19,8 +19,6 @@ file Host readonly separator, Host.h, Host.cpp, - HostTools.h, - HostTools.cpp, Logger readonly separator, Logger.cpp, Logger.h, diff --git a/uppsrc/ide/Core/Host.cpp b/uppsrc/ide/Core/Host.cpp index d2704b88b..216642ade 100644 --- a/uppsrc/ide/Core/Host.cpp +++ b/uppsrc/ide/Core/Host.cpp @@ -5,7 +5,6 @@ #include LocalHost::LocalHost() - : tools(MakeOne()) { } @@ -29,6 +28,11 @@ String LocalHost::NormalizePath(const String& path) return ::NormalizePath(path); } +String LocalHost::NormalizeExecutablePath(const String& path) +{ + return NormalizeExePath(path); +} + Vector LocalHost::GetFileInfo(const Vector& path) { Vector fi; @@ -364,11 +368,6 @@ const Vector& LocalHost::GetExecutablesDirs() const return exedirs; } -const HostTools& LocalHost::GetTools() const -{ - return *tools.Get(); -} - bool LocalHost::HasPlatformFlag(const Index& cfg) { static const Index platformFlags = { diff --git a/uppsrc/ide/Core/Host.h b/uppsrc/ide/Core/Host.h index b38ab3341..aed8bcb68 100644 --- a/uppsrc/ide/Core/Host.h +++ b/uppsrc/ide/Core/Host.h @@ -14,6 +14,7 @@ public: virtual String GetHostPath(const String& path) = 0; virtual String GetLocalPath(const String& path) = 0; virtual String NormalizePath(const String& path) = 0; + virtual String NormalizeExecutablePath(const String& path) = 0; virtual Vector GetFileInfo(const Vector& path) = 0; virtual void DeleteFile(const Vector& path) = 0; virtual void DeleteFolderDeep(const String& dir) = 0; @@ -35,7 +36,6 @@ public: virtual void AddFlags(Index& cfg) = 0; virtual const Vector& GetExecutablesDirs() const = 0; - virtual const HostTools& GetTools() const = 0; }; class LocalHost : public Host { @@ -53,6 +53,7 @@ public: /* Host */ String GetHostPath(const String& path) override; String GetLocalPath(const String& path) override; String NormalizePath(const String& path) override; + String NormalizeExecutablePath(const String& path) override; Vector GetFileInfo(const Vector& path) override; void DeleteFile(const Vector& path) override; void DeleteFolderDeep(const String& dir) override; @@ -74,13 +75,9 @@ public: /* Host */ void AddFlags(Index& cfg) override; const Vector& GetExecutablesDirs() const override; - const HostTools& GetTools() const override; private: bool HasPlatformFlag(const Index& cfg); - -private: - One tools; }; /* diff --git a/uppsrc/ide/Core/HostTools.cpp b/uppsrc/ide/Core/HostTools.cpp deleted file mode 100644 index 0f3830e5e..000000000 --- a/uppsrc/ide/Core/HostTools.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "Core.h" - -String LocalHostTools::NormalizeExecutablePath(const String& path) const -{ - return ::NormalizeExePath(path); -} diff --git a/uppsrc/ide/Core/HostTools.h b/uppsrc/ide/Core/HostTools.h deleted file mode 100644 index 4d63382d4..000000000 --- a/uppsrc/ide/Core/HostTools.h +++ /dev/null @@ -1,12 +0,0 @@ -class HostTools { -public: - virtual ~HostTools() {} - - virtual String NormalizeExecutablePath(const String& path) const = 0; -}; - -class LocalHostTools final : public HostTools { -public: - String NormalizeExecutablePath(const String& path) const override; -}; - diff --git a/uppsrc/ide/Debuggers/Debuggers.h b/uppsrc/ide/Debuggers/Debuggers.h index 6ff6ad7e9..3f27dbeb3 100644 --- a/uppsrc/ide/Debuggers/Debuggers.h +++ b/uppsrc/ide/Debuggers/Debuggers.h @@ -152,8 +152,6 @@ public: String autoline; bool firstrun; - int frame_idx; - int pid = 0; // debugee pid String DoRun(); @@ -176,7 +174,7 @@ public: void Step(const char *cmd); - String Cmdp(const char *cmdline, bool fr = false); + String Cmdp(const char *cmdline, bool fr = false, bool setframe = true); void DoRunTo() { RunTo(); } @@ -186,8 +184,7 @@ public: void DisasCursor(); void DisasFocus(); void DropFrames(); - - String ObtainFrame(int frame_idx); + void LoadFrames(); void SwitchFrame(); void SwitchThread(); @@ -217,9 +214,8 @@ public: void BreakRunning(); bool Create(One&& host, const String& exefile, const String& cmdline, bool console); - - // Period check for killed console - TimeCallback periodic; + + TimeCallback periodic; // Period check for killed console void Periodic(); typedef Gdb CLASSNAME; @@ -227,13 +223,7 @@ public: virtual ~Gdb(); Gdb(); -private: - void RestoreFramePos(); - - bool CreateDbg(One& host, const String& exeFile, bool console); - -private: - const int max_stack_trace_size; + const int max_stack_trace_size = 400; }; #include "Gdb_MI2.h" diff --git a/uppsrc/ide/Debuggers/Gdb.cpp b/uppsrc/ide/Debuggers/Gdb.cpp index 71a9c0b0a..399f81707 100644 --- a/uppsrc/ide/Debuggers/Gdb.cpp +++ b/uppsrc/ide/Debuggers/Gdb.cpp @@ -83,7 +83,6 @@ void Gdb::CopyStackAll() String s = ss.GetLine(); CParser p(s); try { - bool active = p.Char('*'); if(p.IsNumber()) { int id = p.ReadInt(); r << "----------------------------------\r\n" @@ -92,7 +91,6 @@ void Gdb::CopyStackAll() FastCmd(Sprintf("thread %d", id)); int i = 0; - int q = ~frame; frame.Clear(); for(;;) { String s = FormatFrame(FastCmd("frame " + AsString(i++))); @@ -223,7 +221,7 @@ void Gdb::CheckEnd(const char *s) } } -String Gdb::Cmdp(const char *cmdline, bool fr) +String Gdb::Cmdp(const char *cmdline, bool fr, bool setframe) { expression_cache.Clear(); IdeHidePtr(); @@ -250,9 +248,11 @@ String Gdb::Cmdp(const char *cmdline, bool fr) catch(CParser::Error) {} SyncDisas(fr); } - frame.Clear(); - frame.Add(0, FormatFrame(FastCmd("frame"))); - frame <<= 0; + if(setframe) { + frame.Clear(); + frame.Add(0, FormatFrame(FastCmd("frame"))); + frame <<= 0; + } threads.Clear(); s = FastCmd("info threads"); StringStream ss(s); @@ -326,28 +326,19 @@ void Gdb::BreakRunning() { #ifdef PLATFORM_WIN32 HANDLE h = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid); - if(!h) { - auto error = t_("Failed to open debugge process."); - - Loge() << METHOD_NAME << error; - ErrorOK(error); - + if(h) { + DebugBreakProcess(h); + CloseHandle(h); return; } - - DebugBreakProcess(h); - CloseHandle(h); #endif #ifdef PLATFORM_POSIX - if (kill(pid, SIGINT) == -1) { - auto error = t_("Failed to send SIGINT signal to debugge process."); - - Loge() << METHOD_NAME << error; - ErrorOK(error); - + if(kill(pid, SIGINT) != -1) return; - } #endif + const char *error = t_("Failed to interrupt debugee process."); + Loge() << METHOD_NAME << error; + ErrorOK(error); } void Gdb::Run() @@ -390,57 +381,43 @@ void Gdb::DisasFocus() void Gdb::DropFrames() { - int i = 0; - - frame.Clear(); - while(i <= max_stack_trace_size) { - auto s = ObtainFrame(i); - if(IsNull(s)) { - break; - } - - if (i == max_stack_trace_size) { - auto msg = Sprintf( - "More entries.. (Only first %d elements had been printed)", max_stack_trace_size); - - frame.Add(i, msg); - break; - } - - frame.Add(i++, s); - } - - if (frame_idx == -1 && frame.GetCount() >= 0) { - frame_idx = 0; - } - - RestoreFramePos(); + if(frame.GetCount() < 2) + LoadFrames(); } -String Gdb::ObtainFrame(int frame_idx) +void Gdb::LoadFrames() { - return FormatFrame(FastCmd(Sprintf("frame %d", frame_idx))); + if(frame.GetCount()) + frame.Trim(frame.GetCount() - 1); + int i = frame.GetCount(); + int n = 0; + for(;;) { + String s = FormatFrame(FastCmd(Sprintf("frame %d", i))); + if(IsNull(s)) + break; + if(n++ >= max_stack_trace_size) { + frame.Add(Null, Sprintf(" (%d loaded)", frame.GetCount())); + break; + } + frame.Add(i++, s); + } } void Gdb::SwitchFrame() { - auto i = static_cast(~frame); - if (i == max_stack_trace_size) { - RestoreFramePos(); - return; + int i = ~frame; + if(IsNull(i)) { + i = frame.GetCount() - 1; + LoadFrames(); + frame <<= i; } - - frame_idx = i; - - Cmdp(Sprintf("frame %d", i), i); + Cmdp("frame " + AsString(i), i, false); } void Gdb::SwitchThread() { - frame_idx = -1; - - int i = static_cast(~threads); - Cmdp(Sprintf("thread %d", i), i); + int i = ~threads; + Cmdp("thread " + AsString(i)); } bool Gdb::Key(dword key, int count) @@ -455,18 +432,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); - - if (!CreateDbg(host, exefile, console)) { + + dbg = host->StartProcess(GdbCommand(console) + host->NormalizeExecutablePath(exefile)); + + if (!dbg) { ErrorOK("Error while invoking gdb!"); return false; } @@ -509,14 +481,6 @@ bool Gdb::Create(One&& _host, const String& exefile, const String& cmdline return true; } -bool Gdb::CreateDbg(One& host, const String& exeFile, bool console) -{ - const auto& hostTools = host->GetTools(); - dbg = host->StartProcess(GdbCommand(console) + hostTools.NormalizeExecutablePath(exeFile)); - - return static_cast(dbg); -} - Gdb::~Gdb() { IdeRemoveBottom(*this); @@ -531,8 +495,6 @@ void Gdb::Periodic() } Gdb::Gdb() - : frame_idx(-1) - , max_stack_trace_size(200) { locals.NoHeader(); locals.AddColumn("", 1); @@ -593,9 +555,8 @@ Gdb::Gdb() One GdbCreate(One&& host, const String& exefile, const String& cmdline, bool console) { - One dbg = MakeOne(); - if(!dbg->Create(pick(host), exefile, cmdline, console)) { + auto dbg = MakeOne(); + if(!dbg->Create(pick(host), exefile, cmdline, console)) return nullptr; - } - return dbg; + return pick(dbg); } diff --git a/uppsrc/ide/idefile.cpp b/uppsrc/ide/idefile.cpp index e7387b66e..eb8ebcf47 100644 --- a/uppsrc/ide/idefile.cpp +++ b/uppsrc/ide/idefile.cpp @@ -565,7 +565,7 @@ void Ide::EditFile0(const String& path, byte charset, int spellcheck_comments, c const int64 max_size = 768*1024*1024; #endif const int view_limit = 256*1024*1024; - if(view_file.GetSize() < 256*1024*1024 || editastext.Find(editfile) >= 0 && view_file.GetSize() < max_size) { + if(view_file.GetSize() < view_limit || editastext.Find(editfile) >= 0 && view_file.GetSize() < max_size) { le = editor.Load(view_file, charset); view_file.Close(); }