Skip to content

Commit

Permalink
Separate gdb output
Browse files Browse the repository at this point in the history
  • Loading branch information
mls-m5 committed Nov 2, 2023
1 parent 814f82c commit 6673217
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
38 changes: 35 additions & 3 deletions src/plugin/gdbdebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ void GdbDebugger::applicationOutputCallback(
_applicationOutputCallback = f;
}

void GdbDebugger::debuggerOutputCallback(
std::function<void(std::string_view)> f) {
_debuggerOutputCallback = f;
}

void GdbDebugger::gdbStatusCallback(std::function<void(std::string_view)> f) {
_gdbStatusCallback = f;
}
Expand Down Expand Up @@ -228,12 +233,39 @@ void GdbDebugger::inputThread(std::istream &in) {
changeState({});
}

// std::cout << line << std::endl;

if (_applicationOutputCallback) {
// TODO: Separate applcation output from gdb output with gdb tty
// command and special pipes
_applicationOutputCallback(line);

bool isGdbOutput = false;

if (!line.empty()) {
auto first = line.front();
switch (first) {
case '^':
case '*':
case '+':
case '=':
case '~':
case '@':
case '&':
isGdbOutput = true;
break;
default:
break;
}
}

if (line.starts_with("(gdb)")) {
isGdbOutput = true;
}

if (isGdbOutput) {
_debuggerOutputCallback(line);
}
else {
_applicationOutputCallback(line);
}
}

// Implement the regex logic here:
Expand Down
3 changes: 3 additions & 0 deletions src/plugin/gdbdebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class GdbDebugger : public IDebugger {
/// Application output
void applicationOutputCallback(
std::function<void(std::string_view)>) override;
/// Only messages from the debugger
void debuggerOutputCallback(std::function<void(std::string_view)>) override;

void gdbStatusCallback(std::function<void(std::string_view)>) override;
void stateCallback(std::function<void(DebuggerState)>) override;
Expand Down Expand Up @@ -59,6 +61,7 @@ class GdbDebugger : public IDebugger {

std::function<void(DebuggerState state)> _callback;
std::function<void(std::string_view)> _applicationOutputCallback;
std::function<void(std::string_view)> _debuggerOutputCallback;
std::function<void(std::string_view)> _gdbStatusCallback;

void inputThread(std::istream &in);
Expand Down
2 changes: 2 additions & 0 deletions src/plugin/idebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class IDebugger {

virtual void applicationOutputCallback(
std::function<void(std::string_view)>) = 0;
virtual void debuggerOutputCallback(
std::function<void(std::string_view)>) = 0;
virtual void stateCallback(std::function<void(DebuggerState)>) = 0;
virtual void gdbStatusCallback(std::function<void(std::string_view)>) = 0;

Expand Down
11 changes: 11 additions & 0 deletions src/plugin/rundebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "core/ijobqueue.h"
#include "plugin/idebugger.h"
#include "script/ienvironment.h"
#include "syntax/palette.h"
#include "text/fstring.h"
#include "views/editor.h"
#include "views/mainwindow.h"
Expand All @@ -22,6 +23,15 @@ void debug(std::shared_ptr<IEnvironment> env) {
env->console().cursor(cursor);
});
};
auto printDebug = [wenv = env->weak_from_this()](std::string_view str) {
auto env = wenv.lock();
env->context().guiQueue().addTask([env, str = std::string{str}] {
env->console().buffer().pushBack(FString{str, Palette::comment});
auto cursor = env->console().buffer().end();
// cursor.x(0);
// env->console().cursor(cursor);
});
};

auto statusMessage = [wenv = env->weak_from_this()](std::string_view str) {
auto env = wenv.lock();
Expand Down Expand Up @@ -53,6 +63,7 @@ void debug(std::shared_ptr<IEnvironment> env) {
debugger->command(env->project().settings().debug.command);
debugger->workingDirectory(env->project().settings().debug.workingDir);
debugger->applicationOutputCallback(print);
debugger->debuggerOutputCallback(printDebug);
debugger->gdbStatusCallback(statusMessage);
debugger->stateCallback(stateCallback);

Expand Down

0 comments on commit 6673217

Please sign in to comment.