diff --git a/debuggers/common/miframestackmodel.cpp b/debuggers/common/miframestackmodel.cpp --- a/debuggers/common/miframestackmodel.cpp +++ b/debuggers/common/miframestackmodel.cpp @@ -26,6 +26,8 @@ #include +#include + using namespace KDevelop; using namespace KDevMI; using namespace KDevMI::MI; @@ -74,25 +76,26 @@ { const Value& threads = r["threads"]; - // Traverse GDB threads in backward order -- since GDB - // reports them in backward order. We want UI to - // show thread IDs in the natural order. - // FIXME: at least GDB 7.11 is reporting in the right order, - // consider sort the list afterwards. - - QList threadsList; - int gidx = threads.size()-1; - for (; gidx >= 0; --gidx) { - KDevelop::FrameStackModel::ThreadItem i; - const Value & threadMI = threads[gidx]; - i.nr = threadMI["id"].toInt(); + QList threadsList; + for (int i = 0; i!= threads.size(); ++i) { + const auto &threadMI = threads[i]; + FrameStackModel::ThreadItem threadItem; + threadItem.nr = threadMI["id"].toInt(); if (threadMI["state"].literal() == "stopped") { - i.name = getFunctionOrAddress(threads[gidx]["frame"]); + threadItem.name = getFunctionOrAddress(threadMI["frame"]); } else { - i.name = i18n("(running)"); + i18n("(running)"); } - threadsList << i; + threadsList << threadItem; } + // Sort the list by id, some old version of GDB + // reports them in backward order. We want UI to + // show thread IDs in the natural order. + std::sort(threadsList.begin(), threadsList.end(), + [](const FrameStackModel::ThreadItem &a, const FrameStackModel::ThreadItem &b){ + return a.nr < b.nr; + }); + setThreads(threadsList); if (r.hasField("current-thread-id")) { int currentThreadId = r["current-thread-id"].toInt(); diff --git a/debuggers/gdb/debugsession.h b/debuggers/gdb/debugsession.h --- a/debuggers/gdb/debugsession.h +++ b/debuggers/gdb/debugsession.h @@ -72,6 +72,11 @@ VariableController * variableController() const override; GdbFrameStackModel * frameStackModel() const override; + // FIXME: only used in unit test currently, + // potentially could be made a user configurable option + // Whether turn off auto-disable ASLR when starting inferiors + void setAutoDisableASLR(bool enable); + protected: GdbDebugger *createDebugger() const override; void initializeDebugger() override; @@ -89,6 +94,8 @@ BreakpointController *m_breakpointController; VariableController *m_variableController; GdbFrameStackModel *m_frameStackModel; + + bool m_autoDisableASLR; }; } // end of namespace GDB diff --git a/debuggers/gdb/debugsession.cpp b/debuggers/gdb/debugsession.cpp --- a/debuggers/gdb/debugsession.cpp +++ b/debuggers/gdb/debugsession.cpp @@ -58,6 +58,7 @@ , m_breakpointController(nullptr) , m_variableController(nullptr) , m_frameStackModel(nullptr) + , m_autoDisableASLR(false) { m_breakpointController = new BreakpointController(this); m_variableController = new VariableController(this); @@ -68,6 +69,11 @@ { } +void DebugSession::setAutoDisableASLR(bool enable) +{ + m_autoDisableASLR = enable; +} + BreakpointController *DebugSession::breakpointController() const { return m_breakpointController; @@ -120,6 +126,10 @@ addCommand(MI::NonMI, "source " + fileName); } + // GDB can't disable ASLR on CI server. + addCommand(MI::GdbSet, + QStringLiteral("disable-randomization %1").arg(m_autoDisableASLR ? "on" : "off")); + qCDebug(DEBUGGERGDB) << "Initialized GDB"; } diff --git a/debuggers/gdb/gdb.h b/debuggers/gdb/gdb.h --- a/debuggers/gdb/gdb.h +++ b/debuggers/gdb/gdb.h @@ -35,11 +35,6 @@ ~GdbDebugger() override; bool start(KConfigGroup& config, const QStringList& extraArguments = {}) override; - - /** Reports debugger interal output, including stderr output from debugger - and the 'log' MI channel */ - void debuggerInternalOutput(const QString& s); - }; } // end of namespace GDB diff --git a/debuggers/gdb/gdbframestackmodel.cpp b/debuggers/gdb/gdbframestackmodel.cpp --- a/debuggers/gdb/gdbframestackmodel.cpp +++ b/debuggers/gdb/gdbframestackmodel.cpp @@ -21,8 +21,6 @@ */ #include "gdbframestackmodel.h" -#include - #include "debugsession.h" diff --git a/debuggers/gdb/unittests/test_gdb.cpp b/debuggers/gdb/unittests/test_gdb.cpp --- a/debuggers/gdb/unittests/test_gdb.cpp +++ b/debuggers/gdb/unittests/test_gdb.cpp @@ -57,7 +57,6 @@ namespace KDevMI { namespace GDB { QUrl findExecutable(const QString& name) - { QFileInfo info(qApp->applicationDirPath() + "/unittests/" + name); Q_ASSERT(info.exists()); @@ -182,6 +181,7 @@ TestDebugSession() : DebugSession() { setSourceInitFile(false); + setAutoDisableASLR(false); m_frameStackModel = new TestFrameStackModel(this); KDevelop::ICore::self()->debugController()->addSession(this); }