Skip to content

Commit

Permalink
More improvements to debugger. Allow to pick running process to debug…
Browse files Browse the repository at this point in the history
…. Improve expressions inspection.
  • Loading branch information
SpartanJ committed Jan 20, 2025
1 parent 84f1740 commit 5533ab4
Show file tree
Hide file tree
Showing 15 changed files with 301 additions and 76 deletions.
4 changes: 2 additions & 2 deletions .ecode/project_build.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@
},
{
"args": "",
"command": "${project_root}/bin/eepp-unit-tests-debug",
"command": "${project_root}/bin/unit_tests/eepp-unit-tests-debug",
"name": "eepp-unit_tests-debug",
"run_in_terminal": true,
"working_dir": "${project_root}/bin/unit_tests/"
},
{
"args": "",
"command": "${project_root}/bin/eepp-unit_tests",
"command": "${project_root}/bin/unit_tests/eepp-unit_tests",
"name": "eepp-unit_tests",
"run_in_terminal": true,
"working_dir": "${project_root}/bin/unit_tests"
Expand Down
4 changes: 2 additions & 2 deletions bin/assets/plugins/debugger.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"request": "attach",
"arguments": {
"program": "${file}",
"pid": "${pid}"
"pid": "${command:PickProcess}"
}
}
]
Expand Down Expand Up @@ -114,7 +114,7 @@
"request": "attach",
"arguments": {
"program": "${file}",
"pid": "${pid}"
"pid": "${command:PickProcess}"
}
}
]
Expand Down
13 changes: 12 additions & 1 deletion include/eepp/ui/uiwindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,24 @@ class EE_API UIWindow : public UIWidget {
bool BorderAutoSize = true;
};

enum WindowBaseContainerType { SIMPLE_LAYOUT, LINEAR_LAYOUT, RELATIVE_LAYOUT };
enum WindowBaseContainerType {
SIMPLE_LAYOUT,
VERTICAL_LINEAR_LAYOUT,
HORIZONTAL_LINEAR_LAYOUT,
RELATIVE_LAYOUT
};

static UIWindow* NewOpt( WindowBaseContainerType type,
const StyleConfig& windowStyleConfig = StyleConfig() );

static UIWindow* New();

static UIWindow* NewVBox();

static UIWindow* NewHBox();

static UIWindow* NewRelLay();

explicit UIWindow( WindowBaseContainerType type, const StyleConfig& windowStyleConfig );

explicit UIWindow( WindowBaseContainerType type = SIMPLE_LAYOUT );
Expand Down
3 changes: 3 additions & 0 deletions src/eepp/ui/uiwidgetcreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ void UIWidgetCreator::createBaseWidgetList() {
registeredWidget["loader"] = UILoader::New;
registeredWidget["selectbutton"] = UISelectButton::New;
registeredWidget["window"] = UIWindow::New;
registeredWidget["windowvbox"] = UIWindow::NewVBox;
registeredWidget["windowhbox"] = UIWindow::NewHBox;
registeredWidget["windowrellay"] = UIWindow::NewRelLay;
registeredWidget["scrollview"] = UIScrollView::New;
registeredWidget["textureregion"] = UITextureRegion::New;
registeredWidget["touchdraggable"] = UITouchDraggableWidget::New;
Expand Down
18 changes: 17 additions & 1 deletion src/eepp/ui/uiwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ UIWindow* UIWindow::New() {
return eeNew( UIWindow, ( SIMPLE_LAYOUT ) );
}

UIWindow* UIWindow::NewVBox() {
return eeNew( UIWindow, ( VERTICAL_LINEAR_LAYOUT ) );
}

UIWindow* UIWindow::NewHBox() {
return eeNew( UIWindow, ( HORIZONTAL_LINEAR_LAYOUT ) );
}

UIWindow* UIWindow::NewRelLay() {
return eeNew( UIWindow, ( RELATIVE_LAYOUT ) );
}

UIWindow::UIWindow( UIWindow::WindowBaseContainerType type ) : UIWindow( type, StyleConfig() ) {}

UIWindow::UIWindow( UIWindow::WindowBaseContainerType type, const StyleConfig& windowStyleConfig ) :
Expand Down Expand Up @@ -65,9 +77,13 @@ UIWindow::UIWindow( UIWindow::WindowBaseContainerType type, const StyleConfig& w
getUISceneNode()->windowAdd( this );

switch ( type ) {
case LINEAR_LAYOUT:
case VERTICAL_LINEAR_LAYOUT:
mContainer = UILinearLayout::NewWithTag( "window::container", UIOrientation::Vertical );
break;
case HORIZONTAL_LINEAR_LAYOUT:
mContainer =
UILinearLayout::NewWithTag( "window::container", UIOrientation::Horizontal );
break;
case RELATIVE_LAYOUT:
mContainer = UIRelativeLayout::NewWithTag( "window::container" );
break;
Expand Down
1 change: 1 addition & 0 deletions src/tools/ecode/plugins/debugger/dap/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ static const auto DAP_OUTPUT = "output"sv;

// fields
static const auto DAP_NAME = "name"sv;
static const auto DAP_VALUE = "value"sv;
static const auto DAP_SYSTEM_PROCESS_ID = "systemProcessId"sv;
static const auto DAP_IS_LOCAL_PROCESS = "isLocalProcess"sv;
static const auto DAP_POINTER_SIZE = "pointerSize"sv;
Expand Down
59 changes: 28 additions & 31 deletions src/tools/ecode/plugins/debugger/dap/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ template <typename T> json toJsonArray( const std::vector<T>& items ) {
namespace ecode::dap {

Message::Message( const json& body ) :
id( body[DAP_ID].get<int>() ),
format( body["format"].get<std::string>() ),
id( body.value( DAP_ID, 0 ) ),
format( body.value( "format", "" ) ),
variables( parseOptionalStringMap( body, "variables" ) ),
sendTelemetry( parseOptionalBool( body, "sendTelemetry" ) ),
showUser( parseOptionalBool( body, "showUser" ) ),
Expand Down Expand Up @@ -123,7 +123,7 @@ Output::Output( const json& body ) :
column( parseOptionalInt( body, DAP_COLUMN ) ),
data( body.contains( DAP_DATA ) ? body[DAP_DATA] : nlohmann::json{} ) {
if ( body.contains( DAP_GROUP ) ) {
const auto value = body[DAP_GROUP].get<std::string>();
const auto value = body.value( DAP_GROUP, "" );
if ( DAP_START == value ) {
group = Group::Start;
} else if ( "startCollapsed" == value ) {
Expand All @@ -133,7 +133,7 @@ Output::Output( const json& body ) :
}
}
if ( body.contains( DAP_CATEGORY ) ) {
const auto value = body[DAP_CATEGORY].get<std::string>();
const auto value = body.value( DAP_CATEGORY, "" );
if ( "console" == value ) {
category = Category::Console;
} else if ( "important" == value ) {
Expand Down Expand Up @@ -222,8 +222,7 @@ json Source::toJson() const {
}

Checksum::Checksum( const json& body ) :
checksum( body[DAP_CHECKSUM].get<std::string>() ),
algorithm( body[DAP_ALGORITHM].get<std::string>() ) {}
checksum( body.value( DAP_CHECKSUM, "" ) ), algorithm( body.value( DAP_ALGORITHM, "" ) ) {}

json Checksum::toJson() const {
json out;
Expand All @@ -244,10 +243,10 @@ Capabilities::Capabilities( const json& body ) :
supportsGotoTargetsRequest( body.value( "supportsGotoTargetsRequest", false ) ) {}

ThreadEvent::ThreadEvent( const json& body ) :
reason( body[DAP_REASON].get<std::string>() ), threadId( body[DAP_THREAD_ID].get<int>() ) {}
reason( body.value( DAP_REASON, "" ) ), threadId( body.value( DAP_THREAD_ID, 0 ) ) {}

StoppedEvent::StoppedEvent( const json& body ) :
reason( body[DAP_REASON].get<std::string>() ),
reason( body.value( DAP_REASON, "" ) ),
description( parseOptionalString( body, "description" ) ),
threadId( body.value( DAP_THREAD_ID, 1 ) ),
preserveFocusHint( parseOptionalBool( body, "preserveFocusHint" ) ),
Expand All @@ -256,7 +255,7 @@ StoppedEvent::StoppedEvent( const json& body ) :
hitBreakpointsIds( parseOptionalIntList( body, "hitBreakpointsIds" ) ) {}

DapThread::DapThread( const json& body ) :
id( body[DAP_ID].get<int>() ), name( body[DAP_NAME].get<std::string>() ) {}
id( body.value( DAP_ID, 1 ) ), name( body.value( DAP_NAME, "" ) ) {}

DapThread::DapThread( const int id ) : id( id ), name( std::string() ) {}

Expand All @@ -265,11 +264,11 @@ std::vector<DapThread> DapThread::parseList( const json& threads ) {
}

StackFrame::StackFrame( const json& body ) :
id( body[DAP_ID].get<int>() ),
name( body[DAP_NAME].get<std::string>() ),
id( body.value( DAP_ID, 0 ) ),
name( body.value( DAP_NAME, "" ) ),
source( parseOptionalObject<Source>( body, DAP_SOURCE ) ),
line( body[DAP_LINE].get<int>() ),
column( body[DAP_COLUMN].get<int>() ),
line( body.value( DAP_LINE, 0 ) ),
column( body.value( DAP_COLUMN, 0 ) ),
endLine( parseOptionalInt( body, "endLine" ) ),
canRestart( parseOptionalBool( body, "canRestart" ) ),
instructionPointerReference( parseOptionalString( body, "instructionPointerReference" ) ),
Expand All @@ -284,7 +283,7 @@ StackTraceInfo::StackTraceInfo( const json& body ) :
Module::Module( const json& body ) :
id_int( parseOptionalInt( body, DAP_ID ) ),
id_str( parseOptionalString( body, DAP_ID ) ),
name( body[DAP_NAME].get<std::string>() ),
name( body.value( DAP_NAME, "" ) ),
path( parseOptionalString( body, DAP_PATH ) ),
isOptimized( parseOptionalBool( body, "isOptimized" ) ),
isUserCode( parseOptionalBool( body, "isUserCode" ) ),
Expand All @@ -295,12 +294,12 @@ Module::Module( const json& body ) :
addressRange( parseOptionalString( body, "addressRange" ) ) {}

ModuleEvent::ModuleEvent( const json& body ) :
reason( body[DAP_REASON].get<std::string>() ), module( Module( body["module"] ) ) {}
reason( body.value( DAP_REASON, "" ) ), module( Module( body["module"] ) ) {}

Scope::Scope( const json& body ) :
name( body[DAP_NAME].get<std::string>() ),
name( body.value( DAP_NAME, "" ) ),
presentationHint( parseOptionalString( body, DAP_PRESENTATION_HINT ) ),
variablesReference( body[DAP_VARIABLES_REFERENCE].get<int>() ),
variablesReference( body.value( DAP_VARIABLES_REFERENCE, 0 ) ),
namedVariables( parseOptionalInt( body, "namedVariables" ) ),
indexedVariables( parseOptionalInt( body, "indexedVariables" ) ),
expensive( parseOptionalBool( body, "expensive" ) ),
Expand All @@ -318,11 +317,11 @@ std::vector<Scope> Scope::parseList( const json& scopes ) {
}

Variable::Variable( const json& body ) :
name( body[DAP_NAME].get<std::string>() ),
value( body["value"].get<std::string>() ),
name( body.value( DAP_NAME, "" ) ),
value( body.value( DAP_VALUE, "" ) ),
type( parseOptionalString( body, DAP_TYPE ) ),
evaluateName( parseOptionalString( body, "evaluateName" ) ),
variablesReference( body[DAP_VARIABLES_REFERENCE].get<int>() ),
variablesReference( body.value( DAP_VARIABLES_REFERENCE, 0 ) ),
namedVariables( parseOptionalInt( body, "namedVariables" ) ),
indexedVariables( parseOptionalInt( body, "indexedVariables" ) ),
memoryReference( parseOptionalString( body, "memoryReference" ) ) {}
Expand All @@ -339,15 +338,14 @@ ModulesInfo::ModulesInfo( const json& body ) :
totalModules( parseOptionalInt( body, "totalModules" ) ) {}

ContinuedEvent::ContinuedEvent( const json& body ) :
threadId( body[DAP_THREAD_ID].get<int>() ),
threadId( body.value( DAP_THREAD_ID, 1 ) ),
allThreadsContinued( parseOptionalBool( body, DAP_ALL_THREADS_CONTINUED ) ) {}

ContinuedEvent::ContinuedEvent( int threadId, bool allThreadsContinued ) :
threadId( threadId ), allThreadsContinued( allThreadsContinued ) {}

SourceContent::SourceContent( const json& body ) :
content( body["content"].get<std::string>() ),
mimeType( parseOptionalString( body, "mimeType" ) ) {}
content( body.value( "content", "" ) ), mimeType( parseOptionalString( body, "mimeType" ) ) {}

SourceContent::SourceContent( const std::string& path ) {
const FileInfo file( path );
Expand All @@ -358,7 +356,7 @@ SourceContent::SourceContent( const std::string& path ) {
}

SourceBreakpoint::SourceBreakpoint( const json& body ) :
line( body[DAP_LINE].get<int>() ),
line( body.value( DAP_LINE, 0 ) ),
column( parseOptionalInt( body, DAP_COLUMN ) ),
condition( parseOptionalString( body, DAP_CONDITION ) ),
hitCondition( parseOptionalString( body, DAP_HIT_CONDITION ) ),
Expand Down Expand Up @@ -399,21 +397,20 @@ Breakpoint::Breakpoint( const json& body ) :
Breakpoint::Breakpoint( const int line ) : line( line ) {}

BreakpointEvent::BreakpointEvent( const json& body ) :
reason( body[DAP_REASON].get<std::string>() ),
breakpoint( Breakpoint( body[DAP_BREAKPOINT] ) ) {}
reason( body.value( DAP_REASON, "" ) ), breakpoint( Breakpoint( body[DAP_BREAKPOINT] ) ) {}

EvaluateInfo::EvaluateInfo( const json& body ) :
result( body[DAP_RESULT].get<std::string>() ),
result( body.value( DAP_RESULT, "" ) ),
type( parseOptionalString( body, DAP_TYPE ) ),
variablesReference( body[DAP_VARIABLES_REFERENCE].get<int>() ),
variablesReference( body.value( DAP_VARIABLES_REFERENCE, 0 ) ),
namedVariables( parseOptionalInt( body, "namedVariables" ) ),
indexedVariables( parseOptionalInt( body, "indexedVariables" ) ),
memoryReference( parseOptionalString( body, "memoryReference" ) ) {}

GotoTarget::GotoTarget( const json& body ) :
id( body[DAP_ID].get<int>() ),
label( body["label"].get<std::string>() ),
line( body[DAP_LINE].get<int>() ),
id( body.value( DAP_ID, 0 ) ),
label( body.value( "label", "" ) ),
line( body.value( DAP_LINE, 0 ) ),
column( parseOptionalInt( body, DAP_COLUMN ) ),
endLine( parseOptionalInt( body, DAP_END_LINE ) ),
endColumn( parseOptionalInt( body, DAP_END_COLUMN ) ),
Expand Down
25 changes: 18 additions & 7 deletions src/tools/ecode/plugins/debugger/debuggerclientlistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ void DebuggerClientListener::initUI() {
static_cast<ModelVariableNode*>( modelEvent->getModelIndex().internalData() );
mClient->variables( node->var.variablesReference );
mVariablesHolder->saveExpandedState( modelEvent->getModelIndex() );
} else if ( modelEvent->getModelEventType() == Abstract::ModelEventType::CloseTree ) {
mVariablesHolder->removeExpandedState( modelEvent->getModelIndex() );
}
} );

Expand Down Expand Up @@ -157,6 +159,11 @@ void DebuggerClientListener::debuggeeExited( int /*exitCode*/ ) {
void DebuggerClientListener::debuggeeStopped( const StoppedEvent& event ) {
Log::debug( "DebuggerClientListener::debuggeeStopped: reason %s", event.reason );

if ( "exception" == event.reason ) {
mPlugin->getPluginContext()->getNotificationCenter()->addNotification(
mPlugin->i18n( "debuggee_exception_triggered", "Debuggee triggered an exception" ) );
}

mCurrentThreadId = mStoppedData->threadId ? *mStoppedData->threadId : 1;
mStoppedData = event;

Expand Down Expand Up @@ -215,14 +222,14 @@ void DebuggerClientListener::debuggingProcess( const ProcessInfo& ) {}

void DebuggerClientListener::errorResponse( const std::string& command, const std::string& summary,
const std::optional<Message>& /*message*/ ) {
if ( command != "evaluate" ) {
if ( command == "launch" ) {
failed();
}
if ( command == "evaluate" )
return;

mPlugin->getPluginContext()->getNotificationCenter()->addNotification( summary,
Seconds( 5 ) );
}
if ( command == "launch" )
failed();

mPlugin->getPluginContext()->getNotificationCenter()->addNotification( summary, Seconds( 5 ),
true );
}

void DebuggerClientListener::threadChanged( const ThreadEvent& ) {}
Expand Down Expand Up @@ -298,6 +305,10 @@ void DebuggerClientListener::stackTrace( const int threadId, StackTraceInfo&& st
var.memoryReference = info->memoryReference;
}
mPlugin->mExpressionsHolder->upsertRootChild( std::move( var ) );
ExpandedState::Location location{ mCurrentScopePos->first, mCurrentScopePos->second,
mCurrentFrameId };
mPlugin->mExpressionsHolder->restoreExpandedState(
location, mClient, getStatusDebuggerController()->getUIExpressions(), true );
} );
}
}
Expand Down
Loading

0 comments on commit 5533ab4

Please sign in to comment.