-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathmain.cpp
92 lines (76 loc) · 1.96 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "ExternalWidgetPicker.h"
#include "GdbLibraryInjector.h"
#include "PreloadInjector.h"
#include "TargetApplicationProxy.h"
#include "WidgetInspector.h"
#include "lib/InspectorServer.h"
#include "lib/ObjectProxy.h"
#include "lib/PlatformUtils.h"
#include <QApplication>
#include <QtCore/QLibrary>
#include <QtCore/QProcess>
#include <QtDebug>
QString injectorLibPath()
{
#if defined(Q_OS_LINUX) || defined(Q_OS_MAC)
// get path of shared library containing the qtInspectorInit entry
// point. See notes about this in CMakeLists.txt
return PlatformUtils::binaryPath(reinterpret_cast<void*>(&qtInspectorInit));
#else
return "lib/QtInspector.dll";
#endif
}
int main(int argc, char** argv)
{
QApplication app(argc,argv);
QStringList args = app.arguments();
if (args.count() < 2)
{
qWarning() << "Usage: qtinspector <pid>|<program> (<args>...)";
return -1;
}
QProcess process;
int targetPid = args.at(1).toInt();
// inject the helper library
QScopedPointer<Injector> injector;
if (targetPid != 0)
{
#ifdef Q_OS_UNIX
injector.reset(new GdbLibraryInjector);
#endif
if (!injector->inject(targetPid, injectorLibPath(), "qtInspectorInit"))
{
return false;
}
}
else
{
#ifdef Q_OS_UNIX
injector.reset(new PreloadInjector);
#endif
QStringList programArgs;
for (int i=2; i < args.count(); i++)
{
programArgs << args.at(i);
}
if (!injector->startAndInject(args.at(1),programArgs,injectorLibPath(),"qtInspectorInit",&targetPid))
{
return false;
}
}
TargetApplicationProxy proxy;
if (!proxy.connectToTarget(targetPid))
{
qWarning() << "Failed to inject helper library into process <pid>";
}
WidgetPicker* picker = new ExternalWidgetPicker(&proxy,0);
WidgetInspector inspector(&proxy);
inspector.setWidgetPicker(picker);
inspector.show();
int result = app.exec();
if (process.state() == QProcess::Running && !process.waitForFinished())
{
qWarning() << "Failed to wait for process" << process.pid() << "to exit";
}
return result;
}