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

Chgans/allow preload injector override #543

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions docs/manual/gammaray-advanced-usage.qdoc
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,15 @@

For more details on how to integrate the GammaRay client with and IDE, please see the
\l{https://docs.kdab.com/gammaray/latest/}{API documentation}.

\section1 Working around \c{ld.so} secure-execution mode (Linux only)

If your environment triggers the dynamic linker's secure-execution
mode, then the default \c{preload} injector will fail. In that
case, you can copy or link \c{gammaray_probe.so} into a standard
search directory (eg. \c{/usr/lib}), enable the set-user-ID mode
bit (eg. \c{chmod u+s /usr/lib/gammaray_probe.so}), and finally
use the \c{--injector-override gammaray_probe.so}

For more information about \c{ld.so}'s secure mode, see the \l{http://man7.org/linux/man-pages/man8/ld.so.8.html#ENVIRONMENT}{man page}
*/
3 changes: 3 additions & 0 deletions docs/manual/gammaray-command-line.qdoc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
\row
\li \c -i, \c --injector \c <injector>
\li Specify injector type to use (see below).
\row
\li \c -o, \c --injector-override \c <executable>
\li Override the injector executable if handled (requires \c{-i/--injector})
\row
\li \c --inprocess
\li Use the Gammaray 1.x in-process UI. This is not necessary in most cases,
Expand Down
2 changes: 1 addition & 1 deletion launcher/core/injector/injectorfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ AbstractInjector::Ptr createInjector(const QString &name, const QString &executa

#ifndef Q_OS_WIN
if (name == QLatin1String("preload")) {
return AbstractInjector::Ptr(new PreloadInjector);
return AbstractInjector::Ptr(new PreloadInjector(executableOverride));
}
#else
if (name == QLatin1String("windll")) {
Expand Down
16 changes: 11 additions & 5 deletions launcher/core/injector/preloadinjector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@

using namespace GammaRay;

PreloadInjector::PreloadInjector() = default;
PreloadInjector::PreloadInjector(const QString &probeDllOverride)
: ProcessInjector()
, m_probeDllOverride(probeDllOverride)
{
}

QString PreloadInjector::name() const
{
Expand All @@ -51,13 +55,15 @@ bool PreloadInjector::launch(const QStringList &programAndArgs, const QString &p
{
Q_UNUSED(probeFunc);

const QString actualProbeDll = m_probeDllOverride.isEmpty() ? probeDll : m_probeDllOverride;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better preserved at the caller side of this function, i.e. in Launcher::start. That requires the use of a separated commandline option though.


QProcessEnvironment env(_env);
#ifdef Q_OS_MAC
env.insert(QStringLiteral("DYLD_INSERT_LIBRARIES"), probeDll);
env.insert(QStringLiteral("DYLD_INSERT_LIBRARIES"), actualProbeDll);
env.insert(QStringLiteral("GAMMARAY_UNSET_DYLD"), QStringLiteral("1"));

// Make sure Qt do load it's correct libs/plugins.
if (probeDll.contains(QStringLiteral("_debug"), Qt::CaseInsensitive))
if (actualProbeDll.contains(QStringLiteral("_debug"), Qt::CaseInsensitive))
env.insert(QStringLiteral("DYLD_IMAGE_SUFFIX"), QStringLiteral("_debug"));

#else
Expand All @@ -68,13 +74,13 @@ bool PreloadInjector::launch(const QStringList &programAndArgs, const QString &p
// ASAN requires to be loaded first, so check if the target uses that
// and if so inject it before GammaRay
QStringList ldPreload;
foreach (const auto &lib, LibraryUtil::dependencies(exePath)) {
for (const auto &lib: LibraryUtil::dependencies(exePath)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do

const QVector<QByteArray> libraryDependencies = LibraryUtil::dependencies(exePath);
for (const auto &lib: libraryDependencies) {

else using range-for will detach the vector.

if (lib.contains("libasan.so") || lib.contains("libclang_rt.asan")) {
ldPreload.push_back(QString::fromLocal8Bit(lib));
break;
}
}
ldPreload.push_back(probeDll);
ldPreload.push_back(actualProbeDll);
env.insert(QStringLiteral("LD_PRELOAD"), ldPreload.join(QLatin1String(":")));
env.insert(QStringLiteral("GAMMARAY_UNSET_PRELOAD"), QStringLiteral("1"));

Expand Down
5 changes: 4 additions & 1 deletion launcher/core/injector/preloadinjector.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ class PreloadInjector : public ProcessInjector
{
Q_OBJECT
public:
PreloadInjector();
PreloadInjector(const QString &probeDllOverride = QString());
QString name() const override;
bool launch(const QStringList &programAndArgs, const QString &probeDll,
const QString &probeFunc, const QProcessEnvironment &_env) override;

private:
const QString m_probeDllOverride;
};
}

Expand Down