work save

This commit is contained in:
royqh1979@gmail.com 2021-11-10 12:29:02 +08:00
parent 4e7269cbf0
commit 77e2a32940
3 changed files with 77 additions and 40 deletions

View File

@ -224,10 +224,10 @@ void Debugger::setBreakPointCondition(int index, const QString &condition)
{ {
PBreakpoint breakpoint=mBreakpointModel->setBreakPointCondition(index,condition); PBreakpoint breakpoint=mBreakpointModel->setBreakPointCondition(index,condition);
if (condition.isEmpty()) { if (condition.isEmpty()) {
sendCommand("cond", sendCommand("-break-condition",
QString("%1").arg(breakpoint->line)); QString("%1").arg(breakpoint->line));
} else { } else {
sendCommand("cond", sendCommand("-break-condition",
QString("%1 %2").arg(breakpoint->line).arg(condition)); QString("%1 %2").arg(breakpoint->line).arg(condition));
} }
} }
@ -362,9 +362,8 @@ void Debugger::notifyAfterProcessWatchVar()
void Debugger::updateDebugInfo() void Debugger::updateDebugInfo()
{ {
sendCommand("backtrace", ""); sendCommand("-stack-list-frames", "");
sendCommand("info locals", ""); sendCommand("-stack-list-variables", "--skip-unavailable --allvalues");
sendCommand("info args", "");
} }
bool Debugger::useUTF8() const bool Debugger::useUTF8() const
@ -403,13 +402,14 @@ void Debugger::sendBreakpointCommand(PBreakpoint breakpoint)
// break "filename":linenum // break "filename":linenum
QString condition; QString condition;
if (!breakpoint->condition.isEmpty()) { if (!breakpoint->condition.isEmpty()) {
condition = " if " + breakpoint->condition; condition = " -c " + breakpoint->condition;
} }
QString filename = breakpoint->filename; QString filename = breakpoint->filename;
filename.replace('\\','/'); filename.replace('\\','/');
sendCommand("break", sendCommand("-break-insert",
QString("\"%1\":%2").arg(filename) QString("%1 --source \"%2\" --line %3")
.arg(breakpoint->line)+condition); .arg(condition,filename)
.arg(breakpoint->line));
} }
} }
@ -772,6 +772,16 @@ AnnotationType DebugReader::getNextAnnotation()
return getAnnotation(getNextWord()); return getAnnotation(getNextWord());
} }
bool DebugReader::outputTerminated(QByteArray &text)
{
QStringList lines = TextToLines(QString::fromUtf8(text));
foreach (const QString& line,lines) {
if (line == "(gdb)")
return true;
}
return false;
}
QString DebugReader::getNextFilledLine() QString DebugReader::getNextFilledLine()
{ {
// Walk up to an enter sequence // Walk up to an enter sequence
@ -1176,6 +1186,29 @@ void DebugReader::processDebugOutput()
doupdatecpuwindow = false; doupdatecpuwindow = false;
doreceivedsfwarning = false; doreceivedsfwarning = false;
QStringList lines = TextToLines(mOutput);
mOutputLine = 0;
while (mOutputLine<lines.length()) {
QString line = lines[mOutputLine];
line = removeToken(line);
mOutputLine++;
if (line.isEmpty()) {
continue;
}
switch (line[0].unicode()) {
case '~': // console stream output
case '@': // target stream output
case '&': // log stream output
//todo: process console stream output
break;
case '^': // result record
case '
}
}
// Global checks // Global checks
if (mOutput.indexOf("warning: Source file is more recent than executable.") >= 0) if (mOutput.indexOf("warning: Source file is more recent than executable.") >= 0)
doreceivedsfwarning = true; doreceivedsfwarning = true;
@ -1630,7 +1663,7 @@ void DebugReader::run()
bool errorOccurred = false; bool errorOccurred = false;
QString cmd = mDebuggerPath; QString cmd = mDebuggerPath;
// QString arguments = "--annotate=2"; // QString arguments = "--annotate=2";
QString arguments = "--annotate=2 --silent"; QString arguments = "--interpret=mi --silent";
QString workingDir = QFileInfo(mDebuggerPath).path(); QString workingDir = QFileInfo(mDebuggerPath).path();
mProcess = new QProcess(); mProcess = new QProcess();
@ -1680,7 +1713,8 @@ void DebugReader::run()
break; break;
readed = mProcess->readAll(); readed = mProcess->readAll();
buffer += readed; buffer += readed;
if (getLastAnnotation(buffer) == AnnotationType::TPrompt) {
if ( readed.endsWith("\r\n")&& outputTerminated(buffer)) {
mOutput = QString::fromUtf8(buffer); mOutput = QString::fromUtf8(buffer);
processDebugOutput(); processDebugOutput();
buffer.clear(); buffer.clear();

View File

@ -305,6 +305,7 @@ private:
AnnotationType getAnnotation(const QString& s); AnnotationType getAnnotation(const QString& s);
AnnotationType getLastAnnotation(const QByteArray& text); AnnotationType getLastAnnotation(const QByteArray& text);
AnnotationType getNextAnnotation(); AnnotationType getNextAnnotation();
bool outputTerminated(QByteArray& text);
QString getNextFilledLine(); QString getNextFilledLine();
QString getNextLine(); QString getNextLine();
QString getNextWord(); QString getNextWord();
@ -372,6 +373,8 @@ private:
bool doupdatelocal; bool doupdatelocal;
bool mStop; bool mStop;
int mOutputLine;
friend class Debugger; friend class Debugger;
// QThread interface // QThread interface
protected: protected:

View File

@ -1296,13 +1296,14 @@ void MainWindow::debug()
if (!mDebugger->start()) if (!mDebugger->start())
return; return;
filePath.replace('\\','/'); filePath.replace('\\','/');
mDebugger->sendCommand("set","host charset UTF-8"); mDebugger->sendCommand("-gdb-set","mi-async on");
mDebugger->sendCommand("file", '"' + filePath + '"'); mDebugger->sendCommand("-gdb-set","host-charset UTF-8");
mDebugger->sendCommand("-file-exec-and-symbols", '"' + filePath + '"');
if (mProject->options().type == ProjectType::DynamicLib) { if (mProject->options().type == ProjectType::DynamicLib) {
QString host =mProject->options().hostApplication; QString host =mProject->options().hostApplication;
host.replace('\\','/'); host.replace('\\','/');
mDebugger->sendCommand("exec-file", '"' + host + '"'); mDebugger->sendCommand("-file-exec-file", '"' + host + '"');
} }
includeOrSkipDirs(mProject->options().includes, includeOrSkipDirs(mProject->options().includes,
@ -1375,7 +1376,9 @@ void MainWindow::debug()
mDebugger->setUseUTF8(e->fileEncoding() == ENCODING_UTF8 || e->fileEncoding() == ENCODING_UTF8_BOM); mDebugger->setUseUTF8(e->fileEncoding() == ENCODING_UTF8 || e->fileEncoding() == ENCODING_UTF8_BOM);
if (!mDebugger->start()) if (!mDebugger->start())
return; return;
mDebugger->sendCommand("file", QString("\"%1\"").arg(debugFile.filePath().replace('\\','/'))); mDebugger->sendCommand("-gdb-set","mi-async on");
mDebugger->sendCommand("-gdb-set","host-charset UTF-8");
mDebugger->sendCommand("-file-exec-and-symbols", QString("\"%1\"").arg(debugFile.filePath().replace('\\','/')));
} }
} }
break; break;
@ -1406,40 +1409,37 @@ void MainWindow::debug()
mDebugger->sendAllBreakpointsToDebugger(); mDebugger->sendAllBreakpointsToDebugger();
// Run the debugger // Run the debugger
mDebugger->sendCommand("set", "width 0"); // don't wrap output, very annoying mDebugger->sendCommand("-gdb-set", "width 0"); // don't wrap output, very annoying
mDebugger->sendCommand("set", "new-console on"); mDebugger->sendCommand("-gdb-set", "new-console on");
mDebugger->sendCommand("set", "confirm off"); mDebugger->sendCommand("-gdb-set", "confirm off");
mDebugger->sendCommand("set", "print repeats 0"); // don't repeat elements mDebugger->sendCommand("-gdb-set", "print repeats 0"); // don't repeat elements
mDebugger->sendCommand("set", "print elements 0"); // don't limit elements mDebugger->sendCommand("-gdb-set", "print elements 0"); // don't limit elements
mDebugger->sendCommand("cd", excludeTrailingPathDelimiter(debugFile.path())); // restore working directory mDebugger->sendCommand("-environment-cd", excludeTrailingPathDelimiter(debugFile.path())); // restore working directory
if (!debugInferiorhasBreakpoint()) { if (!debugInferiorhasBreakpoint()) {
QString params;
switch(getCompileTarget()) { switch(getCompileTarget()) {
case CompileTarget::None: case CompileTarget::None:
return; return;
case CompileTarget::File: case CompileTarget::File:
mDebugger->sendCommand("start",params); mDebugger->sendCommand("-exec-run", "--start");
mDebugger->updateDebugInfo(); mDebugger->updateDebugInfo();
break; break;
case CompileTarget::Project: case CompileTarget::Project:
params = ""; mDebugger->sendCommand("-exec-run", "--start");
mDebugger->sendCommand("start",params);
mDebugger->updateDebugInfo(); mDebugger->updateDebugInfo();
break; break;
default: default:
break; break;
} }
} else { } else {
QString params;
switch(getCompileTarget()) { switch(getCompileTarget()) {
case CompileTarget::None: case CompileTarget::None:
return; return;
case CompileTarget::File: case CompileTarget::File:
mDebugger->sendCommand("run",params); mDebugger->sendCommand("-exec-run","");
mDebugger->updateDebugInfo(); mDebugger->updateDebugInfo();
break; break;
case CompileTarget::Project: case CompileTarget::Project:
mDebugger->sendCommand("run",params); mDebugger->sendCommand("-exec-run","");
mDebugger->updateDebugInfo(); mDebugger->updateDebugInfo();
break; break;
default: default:
@ -1617,13 +1617,13 @@ void MainWindow::includeOrSkipDirs(const QStringList &dirs, bool skip)
foreach (QString dir,dirs) { foreach (QString dir,dirs) {
QString dirName = dir.replace('\\','/'); QString dirName = dir.replace('\\','/');
if (skip) { if (skip) {
mDebugger->sendCommand( // mDebugger->sendCommand(
"skip", // "skip",
QString("-gfi \"%1/%2\"") // QString("-gfi \"%1/%2\"")
.arg(dirName,"*.*")); // .arg(dirName,"*.*"));
} else { } else {
mDebugger->sendCommand( mDebugger->sendCommand(
"dir", "-environment-directory",
QString("\"%1\"").arg(dirName)); QString("\"%1\"").arg(dirName));
} }
} }
@ -3932,7 +3932,7 @@ void MainWindow::on_actionStep_Over_triggered()
if (mDebugger->executing()) { if (mDebugger->executing()) {
//WatchView.Items.BeginUpdate(); //WatchView.Items.BeginUpdate();
mDebugger->invalidateAllVars(); mDebugger->invalidateAllVars();
mDebugger->sendCommand("next", ""); mDebugger->sendCommand("-exec-next", "");
mDebugger->updateDebugInfo(); mDebugger->updateDebugInfo();
mDebugger->refreshWatchVars(); mDebugger->refreshWatchVars();
} }
@ -3943,7 +3943,7 @@ void MainWindow::on_actionStep_Into_triggered()
if (mDebugger->executing()) { if (mDebugger->executing()) {
//WatchView.Items.BeginUpdate(); //WatchView.Items.BeginUpdate();
mDebugger->invalidateAllVars(); mDebugger->invalidateAllVars();
mDebugger->sendCommand("step", ""); mDebugger->sendCommand("-exec-step", "");
mDebugger->updateDebugInfo(); mDebugger->updateDebugInfo();
mDebugger->refreshWatchVars(); mDebugger->refreshWatchVars();
} }
@ -3955,7 +3955,7 @@ void MainWindow::on_actionStep_Out_triggered()
if (mDebugger->executing()) { if (mDebugger->executing()) {
//WatchView.Items.BeginUpdate(); //WatchView.Items.BeginUpdate();
mDebugger->invalidateAllVars(); mDebugger->invalidateAllVars();
mDebugger->sendCommand("finish", ""); mDebugger->sendCommand("-exec-finish", "");
mDebugger->updateDebugInfo(); mDebugger->updateDebugInfo();
mDebugger->refreshWatchVars(); mDebugger->refreshWatchVars();
} }
@ -3969,8 +3969,8 @@ void MainWindow::on_actionRun_To_Cursor_triggered()
if (e!=nullptr) { if (e!=nullptr) {
//WatchView.Items.BeginUpdate(); //WatchView.Items.BeginUpdate();
mDebugger->invalidateAllVars(); mDebugger->invalidateAllVars();
mDebugger->sendCommand("tbreak", QString(" %1").arg(e->caretY())); mDebugger->sendCommand("-break-insert", QString("-t --line %1").arg(e->caretY()));
mDebugger->sendCommand("continue", ""); mDebugger->sendCommand("-exec-continue", "");
mDebugger->updateDebugInfo(); mDebugger->updateDebugInfo();
mDebugger->refreshWatchVars(); mDebugger->refreshWatchVars();
} }
@ -3983,7 +3983,7 @@ void MainWindow::on_actionContinue_triggered()
if (mDebugger->executing()) { if (mDebugger->executing()) {
//WatchView.Items.BeginUpdate(); //WatchView.Items.BeginUpdate();
mDebugger->invalidateAllVars(); mDebugger->invalidateAllVars();
mDebugger->sendCommand("continue", ""); mDebugger->sendCommand("-exec-continue", "");
mDebugger->updateDebugInfo(); mDebugger->updateDebugInfo();
mDebugger->refreshWatchVars(); mDebugger->refreshWatchVars();
} }
@ -4044,7 +4044,7 @@ void MainWindow::onDebugMemoryAddressInput()
if (!s.isEmpty()) { if (!s.isEmpty()) {
connect(mDebugger, &Debugger::memoryExamineReady, connect(mDebugger, &Debugger::memoryExamineReady,
this, &MainWindow::onMemoryExamineReady); this, &MainWindow::onMemoryExamineReady);
mDebugger->sendCommand("x/64bx",s,false); mDebugger->sendCommand("-data-read-memory/64bx",s,false);
} }
} }