From 0e3441e604da8e37685396e1f3f83ba447a20f90 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sun, 12 Feb 2023 12:53:14 +0800 Subject: [PATCH] - fix: Crash when debug project that has nasm files. - enhancement: Generate debug info for nasm files in Linux/MacOS. - enhancement: Compile/Run/Debug GAS source files. - enhancement: Compile/Debug GAS source files in project. --- NEWS.md | 5 +++ RedPandaIDE/compiler/filecompiler.cpp | 7 ++++ RedPandaIDE/compiler/projectcompiler.cpp | 38 +++++++++++++------- RedPandaIDE/editor.cpp | 2 ++ RedPandaIDE/mainwindow.cpp | 3 ++ RedPandaIDE/project.cpp | 6 ++++ RedPandaIDE/systemconsts.h | 1 + RedPandaIDE/utils.cpp | 3 ++ RedPandaIDE/utils.h | 1 + libs/qsynedit/qsynedit/qsynedit.cpp | 6 ---- libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp | 2 +- 11 files changed, 54 insertions(+), 20 deletions(-) diff --git a/NEWS.md b/NEWS.md index c997ca1c..6ea92e6f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,11 @@ Red Panda C++ Version 2.12 - enhancement: Code folding for #if/#endif - enhancement: When folding "if", don't fold "else"; - fix: Confirm if recompile, when start to debug and project files has modifications. + - fix: Crash when debug project that has nasm files. + - enhancement: Generate debug info for nasm files in Linux/MacOS. + - enhancement: Compile/Run/Debug GAS source files. + - enhancement: Compile/Debug GAS source files in project. + Red Panda C++ Version 2.11 diff --git a/RedPandaIDE/compiler/filecompiler.cpp b/RedPandaIDE/compiler/filecompiler.cpp index f4a3b49c..5c3a9618 100644 --- a/RedPandaIDE/compiler/filecompiler.cpp +++ b/RedPandaIDE/compiler/filecompiler.cpp @@ -98,6 +98,13 @@ bool FileCompiler::prepareForCompile() mArguments += getCharsetArgument(mEncoding, fileType, mOnlyCheckSyntax); QString strFileType; switch(fileType) { + case FileType::GAS: + mArguments += getCCompileArguments(mOnlyCheckSyntax); + mArguments += getCIncludeArguments(); + mArguments += getProjectIncludeArguments(); + strFileType = "GNU Assembler"; + mCompiler = compilerSet()->CCompiler(); + break; case FileType::CSource: mArguments += getCCompileArguments(mOnlyCheckSyntax); mArguments += getCIncludeArguments(); diff --git a/RedPandaIDE/compiler/projectcompiler.cpp b/RedPandaIDE/compiler/projectcompiler.cpp index 6b06bf90..9142d32c 100644 --- a/RedPandaIDE/compiler/projectcompiler.cpp +++ b/RedPandaIDE/compiler/projectcompiler.cpp @@ -160,7 +160,7 @@ void ProjectCompiler::writeMakeDefines(QFile &file) continue; if (fileType == FileType::CSource || fileType == FileType::CppSource - || fileType == FileType::ASM) { + || fileType == FileType::ASM || fileType==FileType::GAS) { if (!mProject->options().objectOutput.isEmpty()) { // ofile = C:\MyProgram\obj\main.o QString fullObjFile = includeTrailingPathDelimiter(mProject->options().objectOutput) @@ -285,21 +285,28 @@ void ProjectCompiler::writeMakeDefines(QFile &file) #ifdef Q_OS_WIN writeln(file,"WINDRESFLAGS = " + mProject->options().resourceCmd); #endif + if (compilerSet()->canAssemble()) { + QString asmFlags; #ifdef Q_OS_WIN - if (compilerSet()->canAssemble() && - Settings::CompilerSets::isTarget64Bit(compilerSet()->target())) { - if (mProject->getCompileOption(CC_CMD_OPT_POINTER_SIZE)=="32") - writeln(file,"ASMFLAGS = -f win32 " + mProject->options().assemblerArgs); - else - writeln(file,"ASMFLAGS = -f win64 " + mProject->options().assemblerArgs); - } else { - writeln(file,"ASMFLAGS = -f win32 " + mProject->options().assemblerArgs); - } + if (Settings::CompilerSets::isTarget64Bit(compilerSet()->target())) { + if (mProject->getCompileOption(CC_CMD_OPT_POINTER_SIZE)=="32") + asmFlags = "-f win32 " + mProject->options().assemblerArgs; + else + asmFlags = "-f win64 " + mProject->options().assemblerArgs; + } else { + asmFlags = "-f win32 " + mProject->options().assemblerArgs; + } #elif defined(Q_OS_LINUX) - writeln(file,"ASMFLAGS = -f elf64"); + asmFlags = "-f elf64"; + if (mProject->getCompileOption(CC_CMD_OPT_DEBUG_INFO) == COMPILER_OPTION_ON) + asmFlags += " -g "; #elif defined(Q_OS_MACOS) - writeln(file,"ASMFLAGS = -f macho64"); + asmFlags = "-f macho64"; + if (mProject->getCompileOption(CC_CMD_OPT_DEBUG_INFO) == COMPILER_OPTION_ON) + asmFlags += " -g "; #endif + writeln(file,"ASMFLAGS = " + asmFlags); + } // This needs to be put in before the clean command. if (mProject->options().type == ProjectType::DynamicLib) { @@ -379,7 +386,8 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file) FileType fileType = getFileType(unit->fileName()); // Only process source files if (fileType!=FileType::CSource && fileType!=FileType::CppSource - && fileType!=FileType::ASM) + && fileType!=FileType::ASM + && fileType!=FileType::GAS) continue; QString shortFileName = extractRelativePath(mProject->makeFileName(),unit->fileName()); @@ -494,6 +502,10 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file) else writeln(file, "\t$(CC) -c " + genMakePath1(shortFileName) + " -o " + objFileName2 + " $(CFLAGS) " + encodingStr); } + } else if (fileType==FileType::GAS) { + if (!mOnlyCheckSyntax) { + writeln(file, "\t$(CC) -c " + genMakePath1(shortFileName) + " -o " + objFileName2 + " $(CFLAGS) " + encodingStr); + } } else if (fileType==FileType::ASM) { if (!mOnlyCheckSyntax) { writeln(file, "\t$(ASM) " + genMakePath1(shortFileName) + " -o " + objFileName2 + " $(ASMFLAGS) "); diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 2f9d4b08..4044e333 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -3859,6 +3859,8 @@ QString Editor::getParserHint(const QStringList& expression,const QString &/*s*/ void Editor::showDebugHint(const QString &s, int line) { + if (!mParser) + return; PStatement statement = mParser->findStatementOf(mFilename,s,line); if (statement) { if (statement->kind != StatementKind::skVariable diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 39cd6411..d2298bd4 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -696,6 +696,9 @@ void MainWindow::updateCompileActions(const Editor *e) canGenerateAssembly = true; canCompile = true; canRun = true; + } else if (fileType == FileType::GAS) { + canCompile = true; + canRun = true; } } else { forProject = (mProject!=nullptr); diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 5b367801..7ae3e3d2 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -951,6 +951,7 @@ bool Project::assignTemplate(const std::shared_ptr aTemplate, b FileType fileType=getFileType(unit->fileName()); if (fileType==FileType::ASM + || fileType==FileType::GAS || isCFile(unit->fileName()) || isHFile(unit->fileName())) { Editor * editor = mEditorList->newEditor( unit->fileName(), @@ -1277,6 +1278,11 @@ PProjectUnit Project::internalAddUnit(const QString &inFileName, PProjectModelNo // Determine compilation flags switch(getFileType(inFileName)) { + case FileType::GAS: + newUnit->setCompile(true); + newUnit->setCompileCpp(false); + newUnit->setLink(true); + break; case FileType::ASM: newUnit->setCompile(true); newUnit->setCompileCpp(false); diff --git a/RedPandaIDE/systemconsts.h b/RedPandaIDE/systemconsts.h index b8f1a53f..c133a7da 100644 --- a/RedPandaIDE/systemconsts.h +++ b/RedPandaIDE/systemconsts.h @@ -84,6 +84,7 @@ #define RES_EXT "res" #define H_EXT "h" #define OBJ_EXT "o" +#define LST_EXT "lst" #define DEF_EXT "def" #define LIB_EXT "a" #define GCH_EXT "gch" diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index 7790a7fa..bd41ee74 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -86,6 +86,9 @@ FileType getFileType(const QString &filename) if (filename.endsWith(".asm",PATH_SENSITIVITY)) { return FileType::ASM; } + if (filename.endsWith(".s",PATH_SENSITIVITY)) { + return FileType::GAS; + } if (filename.endsWith(".dev",PATH_SENSITIVITY)) { return FileType::Project; } diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h index 0b4042b4..bb5e1f60 100644 --- a/RedPandaIDE/utils.h +++ b/RedPandaIDE/utils.h @@ -33,6 +33,7 @@ using PSimpleIni = std::shared_ptr; enum class FileType{ ASM, // asm source file (.asm) + GAS, // GNU assembler source file (.s) CSource, // c source file (.c) CppSource, // c++ source file (.cpp) CHeader, // c header (.h) diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index aef07287..60e240cc 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -1611,12 +1611,6 @@ int QSynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent QString trimmedLineText = lineText.trimmed(); mSyntaxer->setState(rangePreceeding); mSyntaxer->setLine(trimmedLineText,line-1); - int statePrePre; - if (startLine>1) { - statePrePre = mDocument->getSyntaxState(startLine-2).state; - } else { - statePrePre = 0; - } SyntaxState rangeAfterFirstToken = mSyntaxer->getState(); QString firstToken = mSyntaxer->getToken(); PTokenAttribute attr = mSyntaxer->getTokenAttribute(); diff --git a/libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp b/libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp index 5610fcc3..414f492d 100644 --- a/libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp @@ -98,7 +98,7 @@ QSet Syntaxer::keywords() const return QSet(); } -QString Syntaxer::foldString(QString startLine) +QString Syntaxer::foldString(QString /*startLine*/) { return " ... }"; }