Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to set custom source paths #497

Merged
merged 2 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ Options:
libraries.
--appPath <path> Path to folder containing the application executable
and libraries.
--sourcePaths <paths> Colon separated list of extra paths to the source
code.
--arch <path> Architecture to use for unwinding.
--exportTo <path> Path to .perfparser output file to which the input
data should be exported. A single input file has to
Expand Down Expand Up @@ -326,6 +328,9 @@ For easier navigation, you can simply click on a line and the other view will ju
You can follow function calls with a double click.
In the sourcecode view you can press ctrl+f or press the search icon to open a search window.

If you have the sources in different directory, you can use `--sourcePaths` or the settings to
select tell the disassembler to search there for the source code.

## Known Issues

If anything breaks in the above and the output is less usable than `perf report`, please
Expand Down
7 changes: 7 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ int main(int argc, char** argv)
QStringLiteral("path"));
parser.addOption(appPath);

QCommandLineOption sourcePath(
QStringLiteral("sourcePaths"),
QCoreApplication::translate("main", "Colon separated list of extra paths to the source code."),
QStringLiteral("paths"));
parser.addOption(sourcePath);

QCommandLineOption arch(QStringLiteral("arch"),
QCoreApplication::translate("main", "Architecture to use for unwinding."),
QStringLiteral("path"));
Expand Down Expand Up @@ -176,6 +182,7 @@ int main(int argc, char** argv)
applyArg(extraLibPaths, &Settings::setExtraLibPaths);
applyArg(appPath, &Settings::setAppPath);
applyArg(arch, &Settings::setArch);
applyArg(sourcePath, &Settings::setSourceCodePaths);
};

const auto settings = Settings::instance();
Expand Down
3 changes: 2 additions & 1 deletion src/models/disassemblyoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ DisassemblyOutput DisassemblyOutput::disassemble(const QString& objdump, const Q

const auto objdumpOutput = objdumpParse(output);
disassemblyOutput.disassemblyLines = objdumpOutput.disassemblyLines;
disassemblyOutput.mainSourceFileName =
disassemblyOutput.mainSourceFileName = objdumpOutput.mainSourceFileName;
disassemblyOutput.realSourceFileName =
findSourceCodeFile(objdumpOutput.mainSourceFileName, sourceCodePaths, sysroot);
return disassemblyOutput;
}
3 changes: 3 additions & 0 deletions src/models/disassemblyoutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ struct DisassemblyOutput

quint64 baseAddress = 0;
// due to inlining there can be multiple source files encountered in the disassembly lines above
// this is the file referenced in the debug infos
QString mainSourceFileName;
// if the source file is moved this contains the path the the existing file
QString realSourceFileName;

Data::Symbol symbol;
QString errorMessage;
Expand Down
15 changes: 13 additions & 2 deletions src/models/sourcecodemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@

#include <QDir>
#include <QFile>
#include <QLoggingCategory>
#include <QScopeGuard>
#include <QTextBlock>
#include <QTextDocument>

#include <algorithm>
#include <limits>

#include "highlighter.hpp"
#include "search.h"

Q_LOGGING_CATEGORY(sourcecodemodel, "hotspot.sourcecodemodel", QtWarningMsg)

SourceCodeModel::SourceCodeModel(KSyntaxHighlighting::Repository* repository, QObject* parent)
: QAbstractTableModel(parent)
, m_document(new QTextDocument(this))
Expand Down Expand Up @@ -49,7 +53,7 @@ void SourceCodeModel::setDisassembly(const DisassemblyOutput& disassemblyOutput,
if (disassemblyOutput.mainSourceFileName.isEmpty())
return;

QFile file(m_sysroot + QDir::separator() + disassemblyOutput.mainSourceFileName);
QFile file(m_sysroot + QDir::separator() + disassemblyOutput.realSourceFileName);

if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
Expand All @@ -63,7 +67,7 @@ void SourceCodeModel::setDisassembly(const DisassemblyOutput& disassemblyOutput,
m_document->setTextWidth(m_document->idealWidth());

int maxLineNumber = 0;
int minLineNumber = INT_MAX;
int minLineNumber = std::numeric_limits<int>::max();

m_validLineNumbers.clear();

Expand Down Expand Up @@ -102,6 +106,13 @@ void SourceCodeModel::setDisassembly(const DisassemblyOutput& disassemblyOutput,
m_validLineNumbers.insert(line.fileLine.line);
}

if (maxLineNumber == 0) {
qCWarning(sourcecodemodel) << "failed to parse line numbers from disassembly output";
return;
}

qCDebug(sourcecodemodel) << disassemblyOutput.mainSourceFileName << minLineNumber << maxLineNumber;

Q_ASSERT(minLineNumber > 0);
Q_ASSERT(minLineNumber < maxLineNumber);

Expand Down
3 changes: 2 additions & 1 deletion src/resultscallercalleepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,9 @@ void ResultsCallerCalleePage::openEditor(const Data::Symbol& symbol)
const auto location = toSourceMapLocation(fileLine, symbol);
if (location) {
auto settings = Settings::instance();
const auto colon = QLatin1Char(':');
auto remappedSourceFile =
findSourceCodeFile(location.path, settings->sourceCodePaths(), settings->sysroot());
findSourceCodeFile(location.path, settings->sourceCodePaths().split(colon), settings->sysroot());
emit navigateToCode(remappedSourceFile, location.lineNumber, 0);
return true;
}
Expand Down
8 changes: 5 additions & 3 deletions src/resultsdisassemblypage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ ResultsDisassemblyPage::ResultsDisassemblyPage(CostContextMenu* costContextMenu,
m_sourceCodeModel->updateHighlighting(fileLine.line);
};

connect(settings, &Settings::sourceCodePathsChanged, this, [this](const QString&) { showDisassembly(); });

connect(ui->assemblyView, &QTreeView::entered, this, updateFromDisassembly);

connect(ui->sourceCodeView, &QTreeView::entered, this, updateFromSource);
Expand Down Expand Up @@ -353,9 +355,9 @@ void ResultsDisassemblyPage::showDisassembly()
auto settings = Settings::instance();
const auto colon = QLatin1Char(':');

showDisassembly(DisassemblyOutput::disassemble(objdump(), m_arch, settings->debugPaths().split(colon),
settings->extraLibPaths().split(colon), settings->sourceCodePaths(),
settings->sysroot(), curSymbol));
showDisassembly(DisassemblyOutput::disassemble(
objdump(), m_arch, settings->debugPaths().split(colon), settings->extraLibPaths().split(colon),
settings->sourceCodePaths().split(colon), settings->sysroot(), curSymbol));
}

void ResultsDisassemblyPage::showDisassembly(const DisassemblyOutput& disassemblyOutput)
Expand Down
6 changes: 3 additions & 3 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ void Settings::loadFromFile()
sharedConfig->group("PathSettings").writeEntry("userPaths", this->userPaths());
sharedConfig->group("PathSettings").writeEntry("systemPaths", this->systemPaths());
});
m_sourceCodePaths = sharedConfig->group("PathSettings").readEntry("sourceCodePaths", QStringList());
connect(this, &Settings::sourceCodePathsChanged, this, [sharedConfig](const QStringList& paths) {
m_sourceCodePaths = sharedConfig->group("PathSettings").readEntry("sourceCodePaths", QString());
connect(this, &Settings::sourceCodePathsChanged, this, [sharedConfig](const QString& paths) {
sharedConfig->group("PathSettings").writeEntry("sourceCodePaths", paths);
});

Expand Down Expand Up @@ -227,7 +227,7 @@ void Settings::loadFromFile()
});
}

void Settings::setSourceCodePaths(const QStringList& paths)
void Settings::setSourceCodePaths(const QString& paths)
{
if (m_sourceCodePaths != paths) {
m_sourceCodePaths = paths;
Expand Down
8 changes: 4 additions & 4 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class Settings : public QObject
return m_lastUsedEnvironment;
}

QStringList sourceCodePaths() const
QString sourceCodePaths() const
{
return m_sourceCodePaths;
}
Expand All @@ -163,7 +163,7 @@ class Settings : public QObject
void objdumpChanged(const QString& objdump);
void callgraphChanged();
void lastUsedEnvironmentChanged(const QString& envName);
void sourceCodePathsChanged(const QStringList& paths);
void sourceCodePathsChanged(const QString& paths);

public slots:
void setPrettifySymbols(bool prettifySymbols);
Expand All @@ -184,7 +184,7 @@ public slots:
void setCallgraphColors(const QColor& active, const QColor& inactive);
void setCostAggregation(Settings::CostAggregation costAggregation);
void setLastUsedEnvironment(const QString& envName);
void setSourceCodePaths(const QStringList& paths);
void setSourceCodePaths(const QString& paths);

private:
Settings() = default;
Expand All @@ -198,7 +198,6 @@ public slots:
QStringList m_userPaths;
QStringList m_systemPaths;
QStringList m_debuginfodUrls;
QStringList m_sourceCodePaths;

QString m_sysroot;
QString m_kallsyms;
Expand All @@ -207,6 +206,7 @@ public slots:
QString m_appPath;
QString m_arch;
QString m_objdump;
QString m_sourceCodePaths;

QString m_lastUsedEnvironment;

Expand Down
8 changes: 5 additions & 3 deletions src/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,13 @@ void SettingsDialog::addSourcePathPage()

sourcePathPage->setupUi(page);

const auto colon = QLatin1Char(':');
connect(Settings::instance(), &Settings::sourceCodePathsChanged, this,
[this](const QStringList& paths) { sourcePathPage->sourcePaths->setItems(paths); });
[this, colon](const QString& paths) { sourcePathPage->sourcePaths->setItems(paths.split(colon)); });

setupMultiPath(sourcePathPage->sourcePaths, sourcePathPage->label, buttonBox()->button(QDialogButtonBox::Ok));

connect(buttonBox(), &QDialogButtonBox::accepted, this,
[this] { Settings::instance()->setSourceCodePaths(sourcePathPage->sourcePaths->items()); });
connect(buttonBox(), &QDialogButtonBox::accepted, this, [this, colon] {
Settings::instance()->setSourceCodePaths(sourcePathPage->sourcePaths->items().join(colon));
});
}