- enhancement: can debug files that has non-ascii chars in its path and is compiled by clang

- fix: when debugging project, default compiler set is wrongly used
This commit is contained in:
Roy Qu 2022-05-15 17:14:22 +08:00
parent 394e500941
commit c56a020781
8 changed files with 74 additions and 9 deletions

View File

@ -7,6 +7,8 @@ Red Panda C++ Version 1.0.8
- enhancement: auto set output suffix to ".s" when compiler commandline argument for "-S" is turned on - enhancement: auto set output suffix to ".s" when compiler commandline argument for "-S" is turned on
- enhancement: show error message when user set a shortcut that's already being used. - enhancement: show error message when user set a shortcut that's already being used.
- enhancement: adjust scheme colors for "dark" and "high contrast" themes - enhancement: adjust scheme colors for "dark" and "high contrast" themes
- enhancement: can debug files that has non-ascii chars in its path and is compiled by clang
- fix: when debugging project, default compiler set is wrongly used
Red Panda C++ Version 1.0.7 Red Panda C++ Version 1.0.7
- change: use Shift+Enter to break line - change: use Shift+Enter to break line

View File

@ -217,6 +217,14 @@ bool CompilerInfoManager::supportCovertingCharset(const QString &compilerType)
return pInfo->supportConvertingCharset(); return pInfo->supportConvertingCharset();
} }
bool CompilerInfoManager::forceUTF8InDebugger(const QString &compilerType)
{
PCompilerInfo pInfo = getInfo(compilerType);
if (!pInfo)
return false;
return pInfo->forceUTF8InDebugger();
}
PCompilerInfoManager CompilerInfoManager::instance; PCompilerInfoManager CompilerInfoManager::instance;
PCompilerInfoManager CompilerInfoManager::getInstance() PCompilerInfoManager CompilerInfoManager::getInstance()
@ -241,6 +249,11 @@ bool ClangCompilerInfo::supportConvertingCharset()
return false; return false;
} }
bool ClangCompilerInfo::forceUTF8InDebugger()
{
return true;
}
GCCCompilerInfo::GCCCompilerInfo():CompilerInfo(COMPILER_GCC) GCCCompilerInfo::GCCCompilerInfo():CompilerInfo(COMPILER_GCC)
{ {
} }
@ -249,3 +262,8 @@ bool GCCCompilerInfo::supportConvertingCharset()
{ {
return true; return true;
} }
bool GCCCompilerInfo::forceUTF8InDebugger()
{
return false;
}

View File

@ -69,6 +69,7 @@ public:
bool hasCompilerOption(const QString& key) const; bool hasCompilerOption(const QString& key) const;
virtual bool supportConvertingCharset()=0; virtual bool supportConvertingCharset()=0;
virtual bool forceUTF8InDebugger()=0;
protected: protected:
void addOption(const QString& key, void addOption(const QString& key,
const QString& name, const QString& name,
@ -99,6 +100,7 @@ public:
static PCompilerOption getCompilerOption(const QString& compilerType, const QString& optKey); static PCompilerOption getCompilerOption(const QString& compilerType, const QString& optKey);
static QList<PCompilerOption> getCompilerOptions(const QString& compilerType); static QList<PCompilerOption> getCompilerOptions(const QString& compilerType);
static bool supportCovertingCharset(const QString& compilerType); static bool supportCovertingCharset(const QString& compilerType);
static bool forceUTF8InDebugger(const QString& compilerType);
static PCompilerInfoManager getInstance(); static PCompilerInfoManager getInstance();
static void addInfo(const QString& name, PCompilerInfo info); static void addInfo(const QString& name, PCompilerInfo info);
private: private:
@ -112,12 +114,14 @@ class ClangCompilerInfo: public CompilerInfo{
public: public:
ClangCompilerInfo(); ClangCompilerInfo();
bool supportConvertingCharset() override; bool supportConvertingCharset() override;
bool forceUTF8InDebugger() override;
}; };
class GCCCompilerInfo: public CompilerInfo{ class GCCCompilerInfo: public CompilerInfo{
public: public:
GCCCompilerInfo(); GCCCompilerInfo();
bool supportConvertingCharset() override; bool supportConvertingCharset() override;
bool forceUTF8InDebugger() override;
}; };

View File

@ -33,7 +33,8 @@
#include <QJsonObject> #include <QJsonObject>
#include "widgets/signalmessagedialog.h" #include "widgets/signalmessagedialog.h"
Debugger::Debugger(QObject *parent) : QObject(parent) Debugger::Debugger(QObject *parent) : QObject(parent),
mForceUTF8(false)
{ {
mBreakpointModel=new BreakpointModel(this); mBreakpointModel=new BreakpointModel(this);
mBacktraceModel=new BacktraceModel(this); mBacktraceModel=new BacktraceModel(this);
@ -54,15 +55,20 @@ Debugger::Debugger(QObject *parent) : QObject(parent)
this, &Debugger::fetchVarChildren); this, &Debugger::fetchVarChildren);
} }
bool Debugger::start(const QString& inferior) bool Debugger::start(int compilerSetIndex, const QString& inferior)
{ {
Settings::PCompilerSet compilerSet = pSettings->compilerSets().defaultSet();
Settings::PCompilerSet compilerSet = pSettings->compilerSets().getSet(compilerSetIndex);
if (!compilerSet) {
compilerSet = pSettings->compilerSets().defaultSet();
}
if (!compilerSet) { if (!compilerSet) {
QMessageBox::critical(pMainWindow, QMessageBox::critical(pMainWindow,
tr("No compiler set"), tr("No compiler set"),
tr("No compiler set is configured.")+tr("Can't start debugging.")); tr("No compiler set is configured.")+tr("Can't start debugging."));
return false; return false;
} }
setForceUTF8(CompilerInfoManager::forceUTF8InDebugger(compilerSet->compilerType()));
mExecuting = true; mExecuting = true;
QString debuggerPath = compilerSet->debugger(); QString debuggerPath = compilerSet->debugger();
//QFile debuggerProgram(debuggerPath); //QFile debuggerProgram(debuggerPath);
@ -425,6 +431,16 @@ void Debugger::fetchVarChildren(const QString &varName)
} }
} }
bool Debugger::forceUTF8() const
{
return mForceUTF8;
}
void Debugger::setForceUTF8(bool newForceUTF8)
{
mForceUTF8 = newForceUTF8;
}
MemoryModel *Debugger::memoryModel() const MemoryModel *Debugger::memoryModel() const
{ {
return mMemoryModel; return mMemoryModel;
@ -855,7 +871,10 @@ void DebugReader::processExecAsyncRecord(const QByteArray &line)
GDBMIResultParser::ParseObject frameObj = frame.object(); GDBMIResultParser::ParseObject frameObj = frame.object();
mCurrentAddress = frameObj["addr"].hexValue(); mCurrentAddress = frameObj["addr"].hexValue();
mCurrentLine = frameObj["line"].intValue(); mCurrentLine = frameObj["line"].intValue();
mCurrentFile = frameObj["fullname"].pathValue(); if (mDebugger->forceUTF8())
mCurrentFile = frameObj["fullname"].utf8PathValue();
else
mCurrentFile = frameObj["fullname"].pathValue();
mCurrentFunc = frameObj["func"].value(); mCurrentFunc = frameObj["func"].value();
} }
if (reason == "signal-received") { if (reason == "signal-received") {
@ -994,6 +1013,11 @@ void DebugReader::runNextCmd()
if (!pCmd->params.isEmpty()) { if (!pCmd->params.isEmpty()) {
params = pCmd->params.toLocal8Bit(); params = pCmd->params.toLocal8Bit();
} }
//clang compatibility
if (pCmd->command == "-break-insert" && mDebugger->forceUTF8()) {
params = pCmd->params.toUtf8();
}
if (pCmd->command == "-var-create") { if (pCmd->command == "-var-create") {
//hack for variable creation,to easy remember var expression //hack for variable creation,to easy remember var expression
params = " - @ "+params; params = " - @ "+params;
@ -1125,8 +1149,12 @@ bool DebugReader::outputTerminated(const QByteArray &text)
void DebugReader::handleBreakpoint(const GDBMIResultParser::ParseObject& breakpoint) void DebugReader::handleBreakpoint(const GDBMIResultParser::ParseObject& breakpoint)
{ {
QString filename;
// gdb use system encoding for file path // gdb use system encoding for file path
QString filename = breakpoint["fullname"].pathValue(); if (mDebugger->forceUTF8())
filename = breakpoint["fullname"].utf8PathValue();
else
filename = breakpoint["fullname"].pathValue();
int line = breakpoint["line"].intValue(); int line = breakpoint["line"].intValue();
int number = breakpoint["number"].intValue(); int number = breakpoint["number"].intValue();
emit breakpointInfoGetted(filename, line , number); emit breakpointInfoGetted(filename, line , number);
@ -1139,7 +1167,10 @@ void DebugReader::handleStack(const QList<GDBMIResultParser::ParseValue> & stack
GDBMIResultParser::ParseObject frameObject = frameValue.object(); GDBMIResultParser::ParseObject frameObject = frameValue.object();
PTrace trace = std::make_shared<Trace>(); PTrace trace = std::make_shared<Trace>();
trace->funcname = frameObject["func"].value(); trace->funcname = frameObject["func"].value();
trace->filename = frameObject["fullname"].pathValue(); if (mDebugger->forceUTF8())
trace->filename = frameObject["fullname"].utf8PathValue();
else
trace->filename = frameObject["fullname"].pathValue();
trace->line = frameObject["line"].intValue(); trace->line = frameObject["line"].intValue();
trace->level = frameObject["level"].intValue(0); trace->level = frameObject["level"].intValue(0);
trace->address = frameObject["addr"].value(); trace->address = frameObject["addr"].value();

View File

@ -259,7 +259,7 @@ class Debugger : public QObject
public: public:
explicit Debugger(QObject *parent = nullptr); explicit Debugger(QObject *parent = nullptr);
// Play/pause // Play/pause
bool start(const QString& inferior); bool start(int compilerSetIndex, const QString& inferior);
void sendCommand(const QString& command, const QString& params, void sendCommand(const QString& command, const QString& params,
DebugCommandSource source = DebugCommandSource::Other); DebugCommandSource source = DebugCommandSource::Other);
bool commandRunning(); bool commandRunning();
@ -303,6 +303,9 @@ public:
MemoryModel *memoryModel() const; MemoryModel *memoryModel() const;
bool forceUTF8() const;
void setForceUTF8(bool newForceUTF8);
signals: signals:
void evalValueReady(const QString& s); void evalValueReady(const QString& s);
void memoryExamineReady(const QStringList& s); void memoryExamineReady(const QStringList& s);
@ -341,6 +344,7 @@ private:
MemoryModel *mMemoryModel; MemoryModel *mMemoryModel;
DebugReader *mReader; DebugReader *mReader;
DebugTarget *mTarget; DebugTarget *mTarget;
bool mForceUTF8;
int mLeftPageIndexBackup; int mLeftPageIndexBackup;
}; };

View File

@ -377,6 +377,11 @@ QString GDBMIResultParser::ParseValue::pathValue() const
return QFileInfo(QString::fromLocal8Bit(mValue)).absoluteFilePath(); return QFileInfo(QString::fromLocal8Bit(mValue)).absoluteFilePath();
} }
QString GDBMIResultParser::ParseValue::utf8PathValue() const
{
return QFileInfo(QString::fromUtf8(mValue)).absoluteFilePath();
}
GDBMIResultParser::ParseValueType GDBMIResultParser::ParseValue::type() const GDBMIResultParser::ParseValueType GDBMIResultParser::ParseValue::type() const
{ {
return mType; return mType;

View File

@ -78,6 +78,7 @@ public:
int hexValue(int defaultValue=-1) const; int hexValue(int defaultValue=-1) const;
QString pathValue() const; QString pathValue() const;
QString utf8PathValue() const;
ParseValueType type() const; ParseValueType type() const;
bool isValid() const; bool isValid() const;
ParseValue& operator=(const QByteArray& value); ParseValue& operator=(const QByteArray& value);

View File

@ -1721,7 +1721,7 @@ 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(filePath)) if (!mDebugger->start(mProject->options().compilerSet, filePath))
return; return;
filePath.replace('\\','/'); filePath.replace('\\','/');
mDebugger->sendCommand("-file-exec-and-symbols", '"' + filePath + '"'); mDebugger->sendCommand("-file-exec-and-symbols", '"' + filePath + '"');
@ -1799,7 +1799,7 @@ void MainWindow::debug()
prepareDebugger(); prepareDebugger();
QString filePath = debugFile.filePath().replace('\\','/'); QString filePath = debugFile.filePath().replace('\\','/');
if (!mDebugger->start(filePath)) if (!mDebugger->start(pSettings->compilerSets().defaultIndex(),filePath))
return; return;
mDebugger->sendCommand("-file-exec-and-symbols", QString("\"%1\"").arg(filePath)); mDebugger->sendCommand("-file-exec-and-symbols", QString("\"%1\"").arg(filePath));
} }