- 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: show error message when user set a shortcut that's already being used.
- 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
- change: use Shift+Enter to break line

View File

@ -217,6 +217,14 @@ bool CompilerInfoManager::supportCovertingCharset(const QString &compilerType)
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::getInstance()
@ -241,6 +249,11 @@ bool ClangCompilerInfo::supportConvertingCharset()
return false;
}
bool ClangCompilerInfo::forceUTF8InDebugger()
{
return true;
}
GCCCompilerInfo::GCCCompilerInfo():CompilerInfo(COMPILER_GCC)
{
}
@ -249,3 +262,8 @@ bool GCCCompilerInfo::supportConvertingCharset()
{
return true;
}
bool GCCCompilerInfo::forceUTF8InDebugger()
{
return false;
}

View File

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

View File

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

View File

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

View File

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

View File

@ -78,6 +78,7 @@ public:
int hexValue(int defaultValue=-1) const;
QString pathValue() const;
QString utf8PathValue() const;
ParseValueType type() const;
bool isValid() const;
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);
if (!mDebugger->start(filePath))
if (!mDebugger->start(mProject->options().compilerSet, filePath))
return;
filePath.replace('\\','/');
mDebugger->sendCommand("-file-exec-and-symbols", '"' + filePath + '"');
@ -1799,7 +1799,7 @@ void MainWindow::debug()
prepareDebugger();
QString filePath = debugFile.filePath().replace('\\','/');
if (!mDebugger->start(filePath))
if (!mDebugger->start(pSettings->compilerSets().defaultIndex(),filePath))
return;
mDebugger->sendCommand("-file-exec-and-symbols", QString("\"%1\"").arg(filePath));
}