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);
if (condition.isEmpty()) {
sendCommand("cond",
sendCommand("-break-condition",
QString("%1").arg(breakpoint->line));
} else {
sendCommand("cond",
sendCommand("-break-condition",
QString("%1 %2").arg(breakpoint->line).arg(condition));
}
}
@ -362,9 +362,8 @@ void Debugger::notifyAfterProcessWatchVar()
void Debugger::updateDebugInfo()
{
sendCommand("backtrace", "");
sendCommand("info locals", "");
sendCommand("info args", "");
sendCommand("-stack-list-frames", "");
sendCommand("-stack-list-variables", "--skip-unavailable --allvalues");
}
bool Debugger::useUTF8() const
@ -403,13 +402,14 @@ void Debugger::sendBreakpointCommand(PBreakpoint breakpoint)
// break "filename":linenum
QString condition;
if (!breakpoint->condition.isEmpty()) {
condition = " if " + breakpoint->condition;
condition = " -c " + breakpoint->condition;
}
QString filename = breakpoint->filename;
filename.replace('\\','/');
sendCommand("break",
QString("\"%1\":%2").arg(filename)
.arg(breakpoint->line)+condition);
sendCommand("-break-insert",
QString("%1 --source \"%2\" --line %3")
.arg(condition,filename)
.arg(breakpoint->line));
}
}
@ -772,6 +772,16 @@ AnnotationType DebugReader::getNextAnnotation()
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()
{
// Walk up to an enter sequence
@ -1176,6 +1186,29 @@ void DebugReader::processDebugOutput()
doupdatecpuwindow = 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
if (mOutput.indexOf("warning: Source file is more recent than executable.") >= 0)
doreceivedsfwarning = true;
@ -1630,7 +1663,7 @@ void DebugReader::run()
bool errorOccurred = false;
QString cmd = mDebuggerPath;
// QString arguments = "--annotate=2";
QString arguments = "--annotate=2 --silent";
QString arguments = "--interpret=mi --silent";
QString workingDir = QFileInfo(mDebuggerPath).path();
mProcess = new QProcess();
@ -1680,7 +1713,8 @@ void DebugReader::run()
break;
readed = mProcess->readAll();
buffer += readed;
if (getLastAnnotation(buffer) == AnnotationType::TPrompt) {
if ( readed.endsWith("\r\n")&& outputTerminated(buffer)) {
mOutput = QString::fromUtf8(buffer);
processDebugOutput();
buffer.clear();

View File

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

View File

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