diff --git a/debuggers/common/CMakeLists.txt b/debuggers/common/CMakeLists.txt index e12353a18d..984d5c2b91 100644 --- a/debuggers/common/CMakeLists.txt +++ b/debuggers/common/CMakeLists.txt @@ -1,27 +1,27 @@ set(debuggercommon_SRCS mi/mi.cpp mi/milexer.cpp mi/miparser.cpp mi/micommand.cpp mi/micommandqueue.cpp debuglog.cpp midebugger.cpp midebugsession.cpp breakpointcontrollerbase.cpp miframestackmodel.cpp - variablecontrollerbase.cpp + mivariablecontroller.cpp mivariable.cpp stringhelpers.cpp stty.cpp ) #ki18n_wrap_ui(debuggercommon_SRCS something.ui) add_library(kdevdebuggercommon STATIC ${debuggercommon_SRCS}) target_link_libraries(kdevdebuggercommon PUBLIC KDev::Debugger PRIVATE Qt5::Core ) kde_target_enable_exceptions(kdevdebuggercommon PUBLIC) diff --git a/debuggers/common/variablecontrollerbase.cpp b/debuggers/common/mivariablecontroller.cpp similarity index 84% rename from debuggers/common/variablecontrollerbase.cpp rename to debuggers/common/mivariablecontroller.cpp index 8f496e190e..b397f10ea5 100644 --- a/debuggers/common/variablecontrollerbase.cpp +++ b/debuggers/common/mivariablecontroller.cpp @@ -1,260 +1,260 @@ /* * GDB Debugger Support * * Copyright 2007 Hamish Rodda * Copyright 2008 Vladimir Prus * Copyright 2009 Niko Sams * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "variablecontrollerbase.h" +#include "mivariablecontroller.h" #include "debuglog.h" #include "midebugsession.h" #include "mivariable.h" #include "mi/mi.h" #include "mi/micommand.h" #include "stringhelpers.h" #include #include #include #include #include #include using namespace KDevelop; using namespace KDevDebugger; using namespace KDevDebugger::MI; using KTextEditor::Cursor; using KTextEditor::Document; using KTextEditor::Range; -VariableControllerBase::VariableControllerBase(MIDebugSession *parent) +MIVariableController::MIVariableController(MIDebugSession *parent) : IVariableController(parent) { Q_ASSERT(parent); connect(parent, &MIDebugSession::inferiorStopped, - this, &VariableControllerBase::programStopped); + this, &MIVariableController::programStopped); connect(parent, &MIDebugSession::stateChanged, - this, &VariableControllerBase::stateChanged); + this, &MIVariableController::stateChanged); } -MIDebugSession *VariableControllerBase::debugSession() const +MIDebugSession *MIVariableController::debugSession() const { return static_cast(const_cast(QObject::parent())); } -void VariableControllerBase::programStopped(const AsyncRecord& r) +void MIVariableController::programStopped(const AsyncRecord& r) { if (debugSession()->debuggerStateIsOn(s_shuttingDown)) return; if (r.hasField("reason") && r["reason"].literal() == "function-finished" && r.hasField("gdb-result-var")) { variableCollection()->watches()->addFinishResult(r["gdb-result-var"].literal()); } else { variableCollection()->watches()->removeFinishResult(); } } -void VariableControllerBase::update() +void MIVariableController::update() { qCDebug(DEBUGGERGDB) << autoUpdate(); if (autoUpdate() & UpdateWatches) { variableCollection()->watches()->reinstall(); } if (autoUpdate() & UpdateLocals) { updateLocals(); } if ((autoUpdate() & UpdateLocals) || ((autoUpdate() & UpdateWatches) && variableCollection()->watches()->childCount() > 0)) { debugSession()->addCommand( new MICommand(VarUpdate, "--all-values *", this, - &VariableControllerBase::handleVarUpdate)); + &MIVariableController::handleVarUpdate)); } } -void VariableControllerBase::handleVarUpdate(const ResultRecord& r) +void MIVariableController::handleVarUpdate(const ResultRecord& r) { const Value& changed = r["changelist"]; for (int i = 0; i < changed.size(); ++i) { const Value& var = changed[i]; MIVariable* v = MIVariable::findByVarobjName(var["name"].literal()); // v can be NULL here if we've already removed locals after step, // but the corresponding -var-delete command is still in the queue. if (v) { v->handleUpdate(var); } } } class StackListArgumentsHandler : public MICommandHandler { public: StackListArgumentsHandler(QStringList localsName) : m_localsName(localsName) {} void handle(const ResultRecord &r) override { if (!KDevelop::ICore::self()->debugController()) return; //happens on shutdown // FIXME: handle error. const Value& locals = r["stack-args"][0]["args"]; for (int i = 0; i < locals.size(); i++) { m_localsName << locals[i].literal(); } QList variables = KDevelop::ICore::self()->debugController()->variableCollection() ->locals()->updateLocals(m_localsName); foreach (Variable *v, variables) { v->attachMaybe(); } } private: QStringList m_localsName; }; class StackListLocalsHandler : public MICommandHandler { public: StackListLocalsHandler(MIDebugSession *session) : m_session(session) {} void handle(const ResultRecord &r) override { // FIXME: handle error. const Value& locals = r["locals"]; QStringList localsName; for (int i = 0; i < locals.size(); i++) { const Value& var = locals[i]; localsName << var["name"].literal(); } int frame = m_session->frameStackModel()->currentFrame(); m_session->addCommand( //dont'show value, low-frame, high-frame new MICommand(StackListArguments, QString("0 %1 %2").arg(frame).arg(frame), new StackListArgumentsHandler(localsName))); } private: MIDebugSession *m_session; }; -void VariableControllerBase::updateLocals() +void MIVariableController::updateLocals() { debugSession()->addCommand( new MICommand(StackListLocals, "--simple-values", new StackListLocalsHandler(debugSession()))); } -Range VariableControllerBase::expressionRangeUnderCursor(Document* doc, const Cursor& cursor) +Range MIVariableController::expressionRangeUnderCursor(Document* doc, const Cursor& cursor) { QString line = doc->line(cursor.line()); int index = cursor.column(); QChar c = line[index]; if (!c.isLetterOrNumber() && c != '_') return {}; int start = Utils::expressionAt(line, index+1); int end = index; for (; end < line.size(); ++end) { QChar c = line[end]; if (!(c.isLetterOrNumber() || c == '_')) break; } if (!(start < end)) return {}; return { Cursor{cursor.line(), start}, Cursor{cursor.line(), end} }; } -void VariableControllerBase::addWatch(KDevelop::Variable* variable) +void MIVariableController::addWatch(KDevelop::Variable* variable) { // FIXME: should add async 'get full expression' method // to MIVariable, not poke at varobj. In that case, // we will be able to make addWatch a generic method, not // gdb-specific one. if (MIVariable *gv = dynamic_cast(variable)) { debugSession()->addCommand( new MICommand(VarInfoPathExpression, gv->varobj(), this, - &VariableControllerBase::addWatch)); + &MIVariableController::addWatch)); } } -void VariableControllerBase::addWatchpoint(KDevelop::Variable* variable) +void MIVariableController::addWatchpoint(KDevelop::Variable* variable) { // FIXME: should add async 'get full expression' method // to MIVariable, not poke at varobj. In that case, // we will be able to make addWatchpoint a generic method, not // gdb-specific one. if (MIVariable *gv = dynamic_cast(variable)) { debugSession()->addCommand( new MICommand(VarInfoPathExpression, gv->varobj(), this, - &VariableControllerBase::addWatchpoint)); + &MIVariableController::addWatchpoint)); } } -void VariableControllerBase::addWatch(const ResultRecord& r) +void MIVariableController::addWatch(const ResultRecord& r) { // FIXME: handle error. if (r.reason == "done" && !r["path_expr"].literal().isEmpty()) { variableCollection()->watches()->add(r["path_expr"].literal()); } } -void VariableControllerBase::addWatchpoint(const ResultRecord& r) +void MIVariableController::addWatchpoint(const ResultRecord& r) { if (r.reason == "done" && !r["path_expr"].literal().isEmpty()) { KDevelop::ICore::self()->debugController()->breakpointModel()->addWatchpoint(r["path_expr"].literal()); } } -Variable* VariableControllerBase::createVariable(TreeModel* model, TreeItem* parent, +Variable* MIVariableController::createVariable(TreeModel* model, TreeItem* parent, const QString& expression, const QString& display) { return new MIVariable(model, parent, expression, display); } -void VariableControllerBase::handleEvent(IDebugSession::event_t event) +void MIVariableController::handleEvent(IDebugSession::event_t event) { IVariableController::handleEvent(event); } -void VariableControllerBase::stateChanged(IDebugSession::DebuggerState state) +void MIVariableController::stateChanged(IDebugSession::DebuggerState state) { if (state == IDebugSession::EndedState) { MIVariable::markAllDead(); } } diff --git a/debuggers/common/variablecontrollerbase.h b/debuggers/common/mivariablecontroller.h similarity index 90% rename from debuggers/common/variablecontrollerbase.h rename to debuggers/common/mivariablecontroller.h index 9de649177d..b4ce97ea21 100644 --- a/debuggers/common/variablecontrollerbase.h +++ b/debuggers/common/mivariablecontroller.h @@ -1,76 +1,76 @@ /* * Variable controller implementation common to MI based debugger * * Copyright 2007 Hamish Rodda * Copyright 2008 Vladimir Prus * Copyright 2009 Niko Sams * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifndef VARIABLECONTROLLERBASE_H -#define VARIABLECONTROLLERBASE_H +#ifndef MIVARIABLECONTROLLER_H +#define MIVARIABLECONTROLLER_H #include "dbgglobal.h" #include namespace KDevDebugger { namespace MI { struct AsyncRecord; struct ResultRecord; struct Value; } class MIDebugSession; -class VariableControllerBase : public KDevelop::IVariableController +class MIVariableController : public KDevelop::IVariableController { Q_OBJECT public: - VariableControllerBase( MIDebugSession* parent); + MIVariableController( MIDebugSession* parent); KDevelop::Variable* createVariable(KDevelop::TreeModel* model, KDevelop::TreeItem* parent, const QString& expression, const QString& display = "") override; KTextEditor::Range expressionRangeUnderCursor(KTextEditor::Document* doc, const KTextEditor::Cursor& cursor) override; void addWatch(KDevelop::Variable* variable) override; void addWatchpoint(KDevelop::Variable* variable) override; void update() override; private slots: void programStopped(const MI::AsyncRecord &r); void stateChanged(KDevelop::IDebugSession::DebuggerState); private: MIDebugSession* debugSession() const; void updateLocals(); void handleVarUpdate(const MI::ResultRecord& r); void addWatch(const MI::ResultRecord& r); void addWatchpoint(const MI::ResultRecord& r); void handleEvent(KDevelop::IDebugSession::event_t event) override; }; } // end of namespace KDevDebugger -#endif // VARIABLECONTROLLERBASE_H +#endif // MIVARIABLECONTROLLER_H diff --git a/debuggers/gdb/variablecontroller.cpp b/debuggers/gdb/variablecontroller.cpp index fd21879bdd..ee7eb74b92 100644 --- a/debuggers/gdb/variablecontroller.cpp +++ b/debuggers/gdb/variablecontroller.cpp @@ -1,37 +1,37 @@ /* * GDB-specific variable controller implementation * Copyright 2016 Aetf * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #include "variablecontroller.h" #include "debugsession.h" using namespace KDevDebugger::GDB; VariableController::VariableController(DebugSession *parent) - : VariableControllerBase(parent) + : MIVariableController(parent) { } DebugSession *VariableController::debugSession() const { return static_cast(const_cast(QObject::parent())); } diff --git a/debuggers/gdb/variablecontroller.h b/debuggers/gdb/variablecontroller.h index b05393a81b..88531e5ce4 100644 --- a/debuggers/gdb/variablecontroller.h +++ b/debuggers/gdb/variablecontroller.h @@ -1,45 +1,45 @@ /* * GDB-specific variable controller implementation * Copyright 2016 Aetf * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ #ifndef VARIABLECONTROLLER_H #define VARIABLECONTROLLER_H -#include "variablecontrollerbase.h" +#include "mivariablecontroller.h" namespace KDevDebugger { namespace GDB { class DebugSession; -class VariableController : public VariableControllerBase +class VariableController : public MIVariableController { Q_OBJECT public: VariableController(DebugSession* parent); private: DebugSession* debugSession() const; }; } // end of namespace GDB } // end of namespace KDevDebugger #endif // VARIABLECONTROLLER_H