Files
seer/src/GdbMonitor.cpp
T

181 lines
4.6 KiB
C++
Raw Normal View History

2025-08-26 17:26:05 -05:00
// SPDX-FileCopyrightText: 2021 Ernie Pasveer <epasveer@att.net>
//
// SPDX-License-Identifier: GPL-3.0-or-later
2021-09-01 13:58:59 -05:00
#include "GdbMonitor.h"
#include <QtCore/QtCore>
#include <QtCore/QProcess>
2022-03-26 08:33:45 -05:00
#include <QtCore/QLoggingCategory>
#include <QtCore/QDebug>
2021-09-01 13:58:59 -05:00
#include <iostream>
2022-03-26 08:33:45 -05:00
static QLoggingCategory LC("seer.gdbmonitor");
2021-09-01 13:58:59 -05:00
GdbMonitor::GdbMonitor (QObject* parent) : QObject(parent) {
_process = 0;
}
GdbMonitor::~GdbMonitor () {
}
void GdbMonitor::handleErrorOccurred (QProcess::ProcessError error) {
Q_UNUSED(error);
2022-10-17 17:43:09 -05:00
qCDebug(LC) << error;
2021-09-01 13:58:59 -05:00
qApp->exit();
}
void GdbMonitor::handleFinished (int exitCode, QProcess::ExitStatus exitStatus) {
Q_UNUSED(exitCode);
Q_UNUSED(exitStatus);
2022-10-17 17:43:09 -05:00
qCDebug(LC) << exitCode << exitStatus;
2021-09-01 13:58:59 -05:00
qApp->exit();
}
void GdbMonitor::handleReadyReadStandardError () {
2022-10-17 17:43:09 -05:00
qCDebug(LC) << "Ready to read stderr";
2021-09-01 13:58:59 -05:00
QProcess* p = (QProcess*)sender();
// Read a line at a time.
while (p->canReadLine()) {
QByteArray buf = p->readLine();
// Chop off trailing RETURN character.
if (buf[buf.size()-1] == '\n') {
buf.chop(1);
}
// Convert to a string.
QString text(buf);
2022-03-26 08:33:45 -05:00
qCDebug(LC) << text;
2021-09-01 13:58:59 -05:00
// Start broadcasting it around.
emit allTextOutput(text);
}
}
void GdbMonitor::handleReadyReadStandardOutput () {
2022-10-17 17:43:09 -05:00
qCDebug(LC) << "Ready to read stdout";
2021-09-01 13:58:59 -05:00
QProcess* p = (QProcess*)sender();
// Read a line at a time.
while (p->canReadLine()) {
QByteArray buf = p->readLine();
// Chop off trailing RETURN character.
if (buf[buf.size()-1] == '\n') {
buf.chop(1);
}
if (buf.size() == 0) { // Ignore empty lines.
continue;
}
2021-09-01 13:58:59 -05:00
// Convert to a string.
QString text(buf);
//qDebug() << "Read buffer" << buf.size() << (int)buf[buf.size()-1] << text;
2022-03-26 08:33:45 -05:00
qCDebug(LC) << text;
2021-11-03 13:50:38 -05:00
#if SEER_GDB_LOGOUT == 1
2025-11-07 11:34:00 +07:00
// Start broadcasting it around. For debugging
emit allTextOutput("From GdbMonitor: " + text + "\n");
#endif
2021-09-01 13:58:59 -05:00
if (text[0] == '~') {
emit tildeTextOutput(text);
}else if (text[0] == '=') {
emit equalTextOutput(text);
}else if (text[0] == '*') {
emit astrixTextOutput(text);
}else if (text[0] == '^') {
emit caretTextOutput(text);
}else if (text[0] == '&') {
emit ampersandTextOutput(text);
2022-10-17 17:43:09 -05:00
}else if (text[0] == '@') {
emit atsignTextOutput(text);
}else if (text.contains(QRegularExpression("^([0-9]+)\\~"))) {
2021-09-01 13:58:59 -05:00
emit tildeTextOutput(text);
}else if (text.contains(QRegularExpression("^([0-9]+)\\="))) {
2021-09-01 13:58:59 -05:00
emit equalTextOutput(text);
}else if (text.contains(QRegularExpression("^([0-9]+)\\*"))) {
2021-09-01 13:58:59 -05:00
emit astrixTextOutput(text);
}else if (text.contains(QRegularExpression("^([0-9]+)\\^"))) {
2021-09-01 13:58:59 -05:00
emit caretTextOutput(text);
}else if (text.contains(QRegularExpression("^([0-9]+)\\&"))) {
2021-09-01 13:58:59 -05:00
emit ampersandTextOutput(text);
}else{
emit textOutput(text);
}
}
2022-10-17 17:43:09 -05:00
qCDebug(LC) << "Finished reading stdout";
2021-09-01 13:58:59 -05:00
}
void GdbMonitor::handleTextOutput (QString text) {
2022-10-17 17:43:09 -05:00
qCDebug(LC) << "Ready to handle text output";
2022-03-26 08:33:45 -05:00
qCDebug(LC) << text;
2021-11-03 13:50:38 -05:00
2021-09-01 13:58:59 -05:00
emit allTextOutput(text);
if (text[0] == '~') {
emit tildeTextOutput(text);
}else if (text[0] == '=') {
emit equalTextOutput(text);
}else if (text[0] == '*') {
emit astrixTextOutput(text);
}else if (text[0] == '^') {
emit caretTextOutput(text);
}else if (text[0] == '&') {
emit ampersandTextOutput(text);
}else if (text.contains(QRegularExpression("^([0-9]+)\\~"))) {
2021-09-01 13:58:59 -05:00
emit tildeTextOutput(text);
}else if (text.contains(QRegularExpression("^([0-9]+)\\="))) {
2021-09-01 13:58:59 -05:00
emit equalTextOutput(text);
}else if (text.contains(QRegularExpression("^([0-9]+)\\*"))) {
2021-09-01 13:58:59 -05:00
emit astrixTextOutput(text);
}else if (text.contains(QRegularExpression("^([0-9]+)\\^"))) {
2021-09-01 13:58:59 -05:00
emit caretTextOutput(text);
}else if (text.contains(QRegularExpression("^([0-9]+)\\&"))) {
2021-09-01 13:58:59 -05:00
emit ampersandTextOutput(text);
}else{
emit textOutput(text);
}
2021-11-03 13:50:38 -05:00
2022-10-17 17:43:09 -05:00
qCDebug(LC) << "Finished handling text output";
2021-09-01 13:58:59 -05:00
}
void GdbMonitor::handleStarted() {
2022-10-17 17:43:09 -05:00
qCDebug(LC);
2021-09-01 13:58:59 -05:00
}
void GdbMonitor::handleStateChanged(QProcess::ProcessState newState) {
Q_UNUSED(newState);
2022-10-17 17:43:09 -05:00
qCDebug(LC) << newState;
2021-09-01 13:58:59 -05:00
}
void GdbMonitor::setProcess (QProcess* process) {
_process = process;
}
QProcess* GdbMonitor::process () {
return _process;
}