Highlight current debugged line.

Hid debugger panel if other panel is opened.
Silence the debugger by default.
This commit is contained in:
Martín Lucas Golini
2025-02-05 01:02:46 -03:00
parent 52fb2a311c
commit eae433796e
15 changed files with 84 additions and 21 deletions

View File

@@ -38,9 +38,10 @@ void DebuggerClientDap::makeRequest( const std::string_view& command,
std::string cmd = jsonCmd.dump();
std::string msg( String::format( "Content-Length: %zu\r\n\r\n%s", cmd.size(), cmd ) );
Log::instance()->writel( mDebug ? LogLevel::Info : LogLevel::Debug,
"DebuggerClientDap::makeRequest:" );
Log::instance()->writel( mDebug ? LogLevel::Info : LogLevel::Debug, msg );
if ( mDebug ) {
Log::debug( "DebuggerClientDap::makeRequest:" );
Log::debug( msg );
}
mBus->write( msg.data(), msg.size() );
@@ -59,9 +60,10 @@ void DebuggerClientDap::makeResponse( int reqSeq, bool success, const std::strin
std::string cmd = jsonCmd.dump();
std::string msg( String::format( "Content-Length: %zu\r\n\r\n%s", cmd.size(), cmd ) );
Log::instance()->writel( mDebug ? LogLevel::Info : LogLevel::Debug,
"DebuggerClientDap::makeResponse:" );
Log::instance()->writel( mDebug ? LogLevel::Info : LogLevel::Debug, msg );
if ( mDebug ) {
Log::debug( "DebuggerClientDap::makeResponse:" );
Log::debug( msg );
}
mBus->write( msg.data(), msg.size() );
}
@@ -71,10 +73,14 @@ bool DebuggerClientDap::isServerConnected() const {
( mBus->state() == Bus::State::Running );
}
bool DebuggerClientDap::supportsTerminate() const {
bool DebuggerClientDap::supportsTerminateRequest() const {
return mAdapterCapabilities.supportsTerminateRequest;
}
bool DebuggerClientDap::supportsTerminateDebuggee() const {
return mAdapterCapabilities.supportTerminateDebuggee;
}
bool DebuggerClientDap::start() {
bool started = mBus->start();
if ( started )
@@ -528,8 +534,11 @@ bool DebuggerClientDap::terminate( bool restart ) {
return true;
}
bool DebuggerClientDap::disconnect( bool restart ) {
bool DebuggerClientDap::disconnect( bool terminateDebuggee, bool restart ) {
nlohmann::json arguments;
if ( mAdapterCapabilities.supportTerminateDebuggee && terminateDebuggee )
arguments["terminateDebuggee"] = true;
if ( restart )
arguments["restart"] = true;

View File

@@ -42,7 +42,7 @@ class DebuggerClientDap : public DebuggerClient {
bool terminate( bool restart ) override;
bool disconnect( bool restart = false ) override;
bool disconnect( bool terminateDebuggee, bool restart = false ) override;
bool threads() override;
@@ -63,7 +63,9 @@ class DebuggerClientDap : public DebuggerClient {
bool isServerConnected() const override;
bool supportsTerminate() const override;
bool supportsTerminateRequest() const override;
bool supportsTerminateDebuggee() const override;
bool setBreakpoints( const std::string& path,
const std::vector<dap::SourceBreakpoint>& breakpoints,
@@ -85,6 +87,8 @@ class DebuggerClientDap : public DebuggerClient {
bool started() const override;
void setSilent( bool silent ) override { mDebug = !silent; }
protected:
std::unique_ptr<Bus> mBus;
UnorderedMap<std::string, UnorderedSet<int>> mBreakpoints;

View File

@@ -71,7 +71,7 @@ class DebuggerClient {
virtual bool terminate( bool restart ) = 0;
virtual bool disconnect( bool restart = false ) = 0;
virtual bool disconnect( bool terminateDebuggee, bool restart = false ) = 0;
virtual bool threads() = 0;
@@ -93,7 +93,9 @@ class DebuggerClient {
virtual bool isServerConnected() const = 0;
virtual bool supportsTerminate() const = 0;
virtual bool supportsTerminateRequest() const = 0;
virtual bool supportsTerminateDebuggee() const = 0;
virtual bool setBreakpoints( const std::string& path,
const std::vector<dap::SourceBreakpoint>& breakpoints,
@@ -113,6 +115,8 @@ class DebuggerClient {
virtual bool configurationDone() = 0;
virtual void setSilent( bool silent ) = 0;
void addListener( Listener* listener );
void removeListener( Listener* listener );

View File

@@ -310,7 +310,9 @@ void DebuggerClientListener::outputProduced( const Output& output ) {
}
}
void DebuggerClientListener::debuggingProcess( const ProcessInfo& ) {}
void DebuggerClientListener::debuggingProcess( const ProcessInfo& info ) {
mProcessInfo = info;
}
void DebuggerClientListener::errorResponse( const std::string& command, const std::string& summary,
const std::optional<Message>& /*message*/ ) {

View File

@@ -71,6 +71,8 @@ class DebuggerClientListener : public DebuggerClient::Listener {
void sendBreakpoints();
const ProcessInfo& getProcessInfo() const { return mProcessInfo; }
protected:
DebuggerClient* mClient{ nullptr };
DebuggerPlugin* mPlugin{ nullptr };
@@ -84,6 +86,7 @@ class DebuggerClientListener : public DebuggerClient::Listener {
std::shared_ptr<StackModel> mStackModel;
std::shared_ptr<VariablesHolder> mVariablesHolder;
std::unordered_map<int, Scope> mScopeRef;
ProcessInfo mProcessInfo;
StatusDebuggerController* getStatusDebuggerController() const;

View File

@@ -374,6 +374,11 @@ void DebuggerPlugin::loadDAPConfig( const std::string& path, bool updateConfigFi
mFetchGlobals = config.value( "fetch_globals", false );
else if ( updateConfigFile )
config["fetch_globals"] = mFetchGlobals;
if ( config.contains( "silent" ) )
mSilence = config.value( "silent", true );
else if ( updateConfigFile )
config["silent"] = mSilence;
}
if ( j.contains( "dap" ) ) {
@@ -1446,6 +1451,23 @@ void DebuggerPlugin::drawLineNumbersBefore( UICodeEditor* editor,
}
}
void DebuggerPlugin::drawBeforeLineText( UICodeEditor* editor, const Int64& index,
Vector2f position, const Float& /*fontSize*/,
const Float& lineHeight ) {
if ( !mDebugger || !mListener || !mListener->isStopped() || !mListener->getCurrentScopePos() ||
editor->getDocument().getFilePath() != mListener->getCurrentScopePos()->first ||
mListener->getCurrentScopePos()->second - 1 != index ||
!editor->getDocumentView().isLineVisible( index ) )
return;
Primitives p;
Color color( editor->getColorScheme().getEditorSyntaxStyle( "warning"_sst ).color );
Color blendedColor( Color( color, 20 ).blendAlpha( editor->getAlpha() ) );
p.setColor( blendedColor );
p.drawRectangle(
Rectf( position, Sizef( editor->getViewportWidth( false, true ), lineHeight ) ) );
}
bool DebuggerPlugin::setBreakpoint( const std::string& doc, Uint32 lineNumber ) {
Lock l( mBreakpointsMutex );
@@ -1978,6 +2000,7 @@ void DebuggerPlugin::run( const std::string& debugger, ProtocolSettings&& protoc
mListener = std::make_unique<DebuggerClientListener>( mDebugger.get(), this );
mListener->setIsRemote( isRemote );
mDebugger->addListener( mListener.get() );
mDebugger->setSilent( mSilence );
DebuggerClientDap* dap = static_cast<DebuggerClientDap*>( mDebugger.get() );
dap->runInTerminalCb = [this]( bool isIntegrated, std::string cmd,
@@ -2012,7 +2035,7 @@ void DebuggerPlugin::exitDebugger( bool requestDisconnect ) {
mDebugger->removeListener( mListener.get() );
if ( requestDisconnect && mDebugger )
mDebugger->disconnect( false );
mDebugger->disconnect( true, false );
if ( mDebugger || mListener ) {
mThreadPool->run( [this] {
@@ -2170,7 +2193,6 @@ void DebuggerPlugin::displayTooltip( UICodeEditor* editor, const std::string& ex
}
bool DebuggerPlugin::onMouseMove( UICodeEditor* editor, const Vector2i& position, const Uint32& ) {
if ( !mDebugger || !mListener || !mDebugger->isServerConnected() ||
mDebuggingState != StatusDebuggerController::State::Paused ) {
return false;
@@ -2227,7 +2249,7 @@ bool DebuggerPlugin::onMouseMove( UICodeEditor* editor, const Vector2i& position
},
mHoverDelay, getMouseMoveHash( editor ) );
editor->updateMouseCursor( position.asFloat() );
return true;
return false;
}
void DebuggerPlugin::onDocumentLineMove( TextDocument* doc, const Int64& fromLine,

View File

@@ -77,6 +77,8 @@ class DebuggerPlugin : public PluginBase {
void initStatusDebuggerController();
bool isSilent() const { return mSilence; }
protected:
friend class DebuggerClientListener;
@@ -84,6 +86,7 @@ class DebuggerPlugin : public PluginBase {
bool mFetchRegisters{ false };
bool mFetchGlobals{ false };
bool mChangingBreakpoint{ false };
bool mSilence{ true };
std::string mProjectPath;
std::vector<DapTool> mDaps;
@@ -207,6 +210,9 @@ class DebuggerPlugin : public PluginBase {
const Float& lineHeight, const Float& lineNumberWidth,
const int& lineNumberDigits, const Float& fontSize ) override;
void drawBeforeLineText( UICodeEditor* editor, const Int64& index, Vector2f position,
const Float& /*fontSize*/, const Float& lineHeight ) override;
bool setBreakpoint( UICodeEditor* editor, Uint32 lineNumber );
bool setBreakpoint( TextDocument* doc, Uint32 lineNumber );