work save
This commit is contained in:
parent
bab5ad37f0
commit
2339f66d4a
|
@ -54,7 +54,53 @@ void Debugger::start()
|
|||
|
||||
//MainForm.UpdateAppTitle;
|
||||
|
||||
//Application.HintHidePause := 5000;
|
||||
//Application.HintHidePause := 5000;
|
||||
}
|
||||
|
||||
void Debugger::stop()
|
||||
{
|
||||
if (mExecuting) {
|
||||
mExecuting = false;
|
||||
if WatchVarList.Count = 0 then // nothing worth showing, restore view
|
||||
MainForm.LeftPageControl.ActivePageIndex := LeftPageIndexBackup;
|
||||
|
||||
// Close CPU window
|
||||
if Assigned(CPUForm) then
|
||||
CPUForm.Close;
|
||||
|
||||
// stop gdb
|
||||
TerminateProcess(fProcessID, 0);
|
||||
|
||||
Reader.Terminate;
|
||||
Reader := nil;
|
||||
|
||||
// Free resources
|
||||
CloseHandle(fProcessID);
|
||||
CloseHandle(fOutputRead);
|
||||
CloseHandle(fInputWrite);
|
||||
|
||||
MainForm.RemoveActiveBreakpoints;
|
||||
|
||||
MainForm.UpdateAppTitle;
|
||||
|
||||
MainForm.OnBacktraceReady;
|
||||
|
||||
Application.HintHidePause := 2500;
|
||||
|
||||
WatchView.Items.BeginUpdate;
|
||||
try
|
||||
//Clear all watch values
|
||||
for I := 0 to WatchVarList.Count - 1 do begin
|
||||
WatchVar := PWatchVar(WatchVarList.Items[I]);
|
||||
WatchVar^.Node.Text := WatchVar^.Name + ' = '+Lang[ID_MSG_EXECUTE_TO_EVALUATE];
|
||||
|
||||
// Delete now invalid children
|
||||
WatchVar^.Node.DeleteChildren;
|
||||
end;
|
||||
finally
|
||||
WatchView.Items.EndUpdate;
|
||||
end;
|
||||
}
|
||||
}
|
||||
|
||||
void Debugger::sendCommand(const QString &command, const QString ¶ms, bool updateWatch, bool showInConsole, DebugCommandSource source)
|
||||
|
@ -76,6 +122,9 @@ void Debugger::addBreakpoint(int line, const QString &filename)
|
|||
bp->filename = filename;
|
||||
bp->condition = "";
|
||||
mBreakpointModel->addBreakpoint(bp);
|
||||
if (mExecuting) {
|
||||
sendBreakpointCommand(bp);
|
||||
}
|
||||
}
|
||||
|
||||
void Debugger::deleteBreakpoints(const QString &filename)
|
||||
|
@ -126,6 +175,13 @@ void Debugger::setBreakPointCondition(int index, const QString &condition)
|
|||
}
|
||||
}
|
||||
|
||||
void Debugger::sendAllBreakpointsToDebugger()
|
||||
{
|
||||
for (PBreakpoint breakpoint:mBreakpointModel->breakpoints()) {
|
||||
sendBreakpointCommand(breakpoint);
|
||||
}
|
||||
}
|
||||
|
||||
bool Debugger::useUTF8() const
|
||||
{
|
||||
return mUseUTF8;
|
||||
|
@ -148,30 +204,40 @@ BreakpointModel *Debugger::breakpointModel()
|
|||
|
||||
void Debugger::sendBreakpointCommand(int index)
|
||||
{
|
||||
// break "filename":linenum
|
||||
PBreakpoint breakpoint = mBreakpointModel->breakpoints()[index];
|
||||
QString condition;
|
||||
if (!breakpoint->condition.isEmpty()) {
|
||||
condition = " if " + breakpoint->condition;
|
||||
sendBreakpointCommand(mBreakpointModel->breakpoints()[index]);
|
||||
}
|
||||
|
||||
void Debugger::sendBreakpointCommand(PBreakpoint breakpoint)
|
||||
{
|
||||
if (breakpoint && mExecuting) {
|
||||
// break "filename":linenum
|
||||
QString condition;
|
||||
if (!breakpoint->condition.isEmpty()) {
|
||||
condition = " if " + breakpoint->condition;
|
||||
}
|
||||
QString filename = breakpoint->filename;
|
||||
filename.replace('\\','/');
|
||||
sendCommand("break",
|
||||
QString("\"%1\":%2").arg(filename)
|
||||
.arg(breakpoint->line)+condition);
|
||||
}
|
||||
QString filename = breakpoint->filename;
|
||||
filename.replace('\\','/');
|
||||
sendCommand("break",
|
||||
QString("\"%1\":%2").arg(filename)
|
||||
.arg(breakpoint->line)+condition);
|
||||
}
|
||||
|
||||
void Debugger::sendClearBreakpointCommand(int index)
|
||||
{
|
||||
sendClearBreakpointCommand(mBreakpointModel->breakpoints()[breakpoint]);
|
||||
}
|
||||
|
||||
void Debugger::sendClearBreakpointCommand(PBreakpoint breakpoint)
|
||||
{
|
||||
// Debugger already running? Remove it from GDB
|
||||
if (mExecuting) {
|
||||
if (breakpoint && mExecuting) {
|
||||
//clear "filename":linenum
|
||||
PBreakpoint breakpoint = mBreakpointModel->breakpoints()[index];
|
||||
QString filename = breakpoint->filename;
|
||||
filename.replace('\\','/');
|
||||
sendCommand("clear",
|
||||
QString("\"%1\":%2").arg(filename)
|
||||
.arg(breakpoint->line));
|
||||
QString("\"%1\":%2").arg(filename)
|
||||
.arg(breakpoint->line));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -140,6 +140,7 @@ public:
|
|||
void removeBreakpoint(int line, const QString& filename);
|
||||
void removeBreakpoint(int index);
|
||||
void setBreakPointCondition(int index, const QString& condition);
|
||||
void sendAllBreakpointsToDebugger();
|
||||
|
||||
bool useUTF8() const;
|
||||
void setUseUTF8(bool useUTF8);
|
||||
|
@ -151,7 +152,9 @@ signals:
|
|||
|
||||
private:
|
||||
void sendBreakpointCommand(int index);
|
||||
void sendBreakpointCommand(PBreakpoint breakpoint);
|
||||
void sendClearBreakpointCommand(int index);
|
||||
void sendClearBreakpointCommand(PBreakpoint breakpoint);
|
||||
|
||||
private:
|
||||
bool mExecuting;
|
||||
|
|
|
@ -425,6 +425,8 @@ void MainWindow::debug()
|
|||
return;
|
||||
bool debugEnabled;
|
||||
bool stripEnabled;
|
||||
QString filePath;
|
||||
QFileInfo debugFile;
|
||||
switch(getCompileTarget()) {
|
||||
case CompileTarget::Project:
|
||||
break;
|
||||
|
@ -534,8 +536,9 @@ void MainWindow::debug()
|
|||
|
||||
|
||||
// Did we compiled?
|
||||
QFile exeFile(getCompiledExecutableName(e->filename()));
|
||||
if (!exeFile.exists()) {
|
||||
filePath = getCompiledExecutableName(e->filename());
|
||||
debugFile.setFile(filePath);
|
||||
if (!debugFile.exists()) {
|
||||
if (QMessageBox::question(this,tr("Compile"),
|
||||
tr("Source file is not compiled.")+"<BR /><BR />" + tr("Compile now?"),
|
||||
QMessageBox::Yes|QMessageBox::No,
|
||||
|
@ -546,7 +549,7 @@ void MainWindow::debug()
|
|||
return;
|
||||
}
|
||||
} else {
|
||||
if (compareFileModifiedTime(e->filename(),exeFile.fileName())>=0) {
|
||||
if (compareFileModifiedTime(e->filename(),filePath)>=0) {
|
||||
if (QMessageBox::question(this,tr("Compile"),
|
||||
tr("Source file is more recent than executable.")+"<BR /><BR />" + tr("Recompile?"),
|
||||
QMessageBox::Yes|QMessageBox::No,
|
||||
|
@ -562,10 +565,9 @@ void MainWindow::debug()
|
|||
|
||||
prepareDebugger();
|
||||
|
||||
mDebugger->UseUTF8 = (e->fileEncoding() == ENCODING_UTF8 || e->fileEncoding() == ENCODING_UTF8_BOM);
|
||||
|
||||
mDebugger->setUseUTF8(e->fileEncoding() == ENCODING_UTF8 || e->fileEncoding() == ENCODING_UTF8_BOM);
|
||||
mDebugger->start();
|
||||
mDebugger->sendCommand("file", QString("\"%1\"").arg(exeFile.fileName().replace('\\','/')));
|
||||
mDebugger->sendCommand("file", QString("\"%1\"").arg(debugFile.filePath().replace('\\','/')));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -576,79 +578,76 @@ void MainWindow::debug()
|
|||
mDebugger->sendCommand("dir",
|
||||
QString("\"%1\"").arg(dir.replace('\\','/')));
|
||||
}
|
||||
|
||||
// Add include folders
|
||||
for I := 0 to CDir.Count - 1 do
|
||||
fDebugger.SendCommand('dir', '"' + StringReplace(CDir[i], '\', '/', [rfReplaceAll]) + '"');
|
||||
|
||||
// Add more include folders, duplicates will be added/moved to front of list
|
||||
for I := 0 to CppDir.Count - 1 do
|
||||
fDebugger.SendCommand('dir', '"' + StringReplace(CppDir[i], '\', '/', [rfReplaceAll]) + '"');
|
||||
end;
|
||||
// Add include folders
|
||||
for (QString dir:compilerSet->CIncludeDirs()) {
|
||||
mDebugger->sendCommand("dir",
|
||||
QString("\"%1\"").arg(dir.replace('\\','/')));
|
||||
}
|
||||
for (QString dir:compilerSet->CppIncludeDirs()) {
|
||||
mDebugger->sendCommand("dir",
|
||||
QString("\"%1\"").arg(dir.replace('\\','/')));
|
||||
}
|
||||
|
||||
// Add breakpoints and watch vars
|
||||
for i := 0 to fDebugger.WatchVarList.Count - 1 do
|
||||
fDebugger.AddWatchVar(i);
|
||||
|
||||
mDebugger->sendAllBreakpointsToDebugger();
|
||||
for i := 0 to fDebugger.BreakPointList.Count - 1 do
|
||||
fDebugger.AddBreakpoint(i);
|
||||
|
||||
// Run the debugger
|
||||
fDebugger.SendCommand('set', 'width 0'); // don't wrap output, very annoying
|
||||
fDebugger.SendCommand('set', 'new-console on');
|
||||
fDebugger.SendCommand('set', 'confirm off');
|
||||
fDebugger.SendCommand('cd', ExcludeTrailingPathDelimiter(ExtractFileDir(filepath))); // restore working directory
|
||||
if not hasBreakPoint then begin
|
||||
case GetCompileTarget of
|
||||
cttNone:
|
||||
Exit;
|
||||
cttFile:
|
||||
begin
|
||||
params := '';
|
||||
if fCompiler.UseRunParams then
|
||||
params := params + ' ' + fCompiler.RunParams;
|
||||
if fCompiler.UseInputFile then
|
||||
params := params + ' < "' + fCompiler.InputFile + '"';
|
||||
fDebugger.SendCommand('start', params);
|
||||
UpdateDebugInfo;
|
||||
end;
|
||||
cttProject: begin
|
||||
params := '';
|
||||
if fCompiler.UseRunParams then
|
||||
params := params + ' ' + fProject.Options.CmdLineArgs;
|
||||
if fCompiler.UseInputFile then
|
||||
params := params + ' < "' + fCompiler.InputFile + '"';
|
||||
mDebugger->sendCommand("set", "width 0"); // don't wrap output, very annoying
|
||||
mDebugger->sendCommand("set", "new-console on");
|
||||
mDebugger->sendCommand("set", "confirm off");
|
||||
mDebugger->sendCommand("cd", excludeTrailingPathDelimiter(debugFile.path())); // restore working directory
|
||||
if (!debugInferiorhasBreakpoint()) {
|
||||
QString params;
|
||||
switch(getCompileTarget()) {
|
||||
case CompileTarget::None:
|
||||
return;
|
||||
case CompileTarget::File:
|
||||
// if (mCompiler->useRunParams) {
|
||||
|
||||
fDebugger.SendCommand('start', params);
|
||||
UpdateDebugInfo;
|
||||
end;
|
||||
end;
|
||||
end else begin
|
||||
case GetCompileTarget of
|
||||
cttNone:
|
||||
Exit;
|
||||
cttFile: begin
|
||||
params := '';
|
||||
if fCompiler.UseRunParams then
|
||||
params := params + ' ' + fCompiler.RunParams;
|
||||
if fCompiler.UseInputFile then
|
||||
params := params + ' < "' + fCompiler.InputFile + '"';
|
||||
fDebugger.SendCommand('run', params);
|
||||
UpdateDebugInfo;
|
||||
end;
|
||||
cttProject: begin
|
||||
params := '';
|
||||
if fCompiler.UseRunParams then
|
||||
params := params + ' ' + fProject.Options.CmdLineArgs;
|
||||
if fCompiler.UseInputFile then
|
||||
params := params + ' < "' + fCompiler.InputFile + '"';
|
||||
// }
|
||||
mDebugger->sendCommand("start",params);
|
||||
updateDebugInfo();
|
||||
break;
|
||||
case CompileTarget::Project:
|
||||
//params := '';
|
||||
//if fCompiler.UseRunParams then
|
||||
// params := params + ' ' + fProject.Options.CmdLineArgs;
|
||||
//if fCompiler.UseInputFile then
|
||||
// params := params + ' < "' + fCompiler.InputFile + '"';
|
||||
|
||||
fDebugger.SendCommand('run', params);
|
||||
UpdateDebugInfo;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
//fDebugger.SendCommand('start', params);
|
||||
//UpdateDebugInfo;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
QString params;
|
||||
switch(getCompileTarget()) {
|
||||
case CompileTarget::None:
|
||||
return;
|
||||
case CompileTarget::File:
|
||||
// if (mCompiler->useRunParams) {
|
||||
|
||||
// }
|
||||
mDebugger->sendCommand("run",params);
|
||||
updateDebugInfo();
|
||||
break;
|
||||
case CompileTarget::Project:
|
||||
//params := '';
|
||||
//if fCompiler.UseRunParams then
|
||||
// params := params + ' ' + fProject.Options.CmdLineArgs;
|
||||
//if fCompiler.UseInputFile then
|
||||
// params := params + ' < "' + fCompiler.InputFile + '"';
|
||||
|
||||
//fDebugger.SendCommand('run', params);
|
||||
//UpdateDebugInfo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::openCloseMessageSheet(bool open)
|
||||
|
@ -1170,3 +1169,25 @@ CompileTarget MainWindow::getCompileTarget()
|
|||
// end;
|
||||
return target;
|
||||
}
|
||||
|
||||
bool MainWindow::debugInferiorhasBreakpoint()
|
||||
{
|
||||
Editor * e = mEditorList->getEditor();
|
||||
if (e==nullptr)
|
||||
return false;
|
||||
if (!e->inProject()) {
|
||||
for (PBreakpoint breakpoint:mDebugger->breakpointModel()->breakpoints()) {
|
||||
if (e->filename() == breakpoint->filename) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (PBreakpoint breakpoint:mDebugger->breakpointModel()->breakpoints()) {
|
||||
Editor* e1 = mEditorList->getOpenedEditorByFilename(breakpoint->filename);
|
||||
if (e1->inProject()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -130,6 +130,7 @@ private slots:
|
|||
void on_actionDebug_triggered();
|
||||
|
||||
CompileTarget getCompileTarget();
|
||||
bool debugInferiorhasBreakpoint();
|
||||
|
||||
public slots:
|
||||
void onCompileLog(const QString& msg);
|
||||
|
|
Loading…
Reference in New Issue