summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2012-10-25 06:39:23 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-31 09:34:17 (GMT)
commita9dfa72fd199dd62f91764b4321df89ad02794bf (patch)
treebec033fb60c7040db46dcdb0f5fd6473ff8940d2 /src
parent524394e37c594807ed874f4926bf13af990358d1 (diff)
downloadQt-a9dfa72fd199dd62f91764b4321df89ad02794bf.zip
Qt-a9dfa72fd199dd62f91764b4321df89ad02794bf.tar.gz
Qt-a9dfa72fd199dd62f91764b4321df89ad02794bf.tar.bz2
Fix debugger detection when running on Linux.
Newer Linuxes have a symlink named 'exe' to the executable and 'cmdline' is empty. Task-number: QTBUG-27632 Change-Id: I45eb2186e2608e9600c4b6b27a033d8b1350deee Reviewed-by: Tobias Hunger <tobias.hunger@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/gui/kernel/qapplication_x11.cpp48
1 files changed, 28 insertions, 20 deletions
diff --git a/src/gui/kernel/qapplication_x11.cpp b/src/gui/kernel/qapplication_x11.cpp
index 47b2236..9582abf 100644
--- a/src/gui/kernel/qapplication_x11.cpp
+++ b/src/gui/kernel/qapplication_x11.cpp
@@ -1630,6 +1630,30 @@ static void getXDefault(const char *group, const char *key, bool *val)
}
#endif
+#if defined(QT_DEBUG) && defined(Q_OS_LINUX)
+// Find out if our parent process is gdb by looking at the 'exe' symlink under /proc,.
+// or, for older Linuxes, read out 'cmdline'.
+bool runningUnderDebugger()
+{
+ const QString parentProc = QLatin1String("/proc/") + QString::number(getppid());
+ const QFileInfo parentProcExe(parentProc + QLatin1String("/exe"));
+ if (parentProcExe.isSymLink())
+ return parentProcExe.symLinkTarget().endsWith(QLatin1String("/gdb"));
+ QFile f(parentProc + QLatin1String("/cmdline"));
+ if (!f.open(QIODevice::ReadOnly))
+ return false;
+ QByteArray s;
+ char c;
+ while (f.getChar(&c) && c) {
+ if (c == '/')
+ s.clear();
+ else
+ s += c;
+ }
+ return s == "gdb";
+}
+#endif
+
// ### This should be static but it isn't because of the friend declaration
// ### in qpaintdevice.h which then should have a static too but can't have
// ### it because "storage class specifiers invalid in friend function
@@ -1854,26 +1878,10 @@ void qt_init(QApplicationPrivate *priv, int,
priv->argc = j;
#if defined(QT_DEBUG) && defined(Q_OS_LINUX)
- if (!appNoGrab && !appDoGrab) {
- QString s;
- s.sprintf("/proc/%d/cmdline", getppid());
- QFile f(s);
- if (f.open(QIODevice::ReadOnly)) {
- s.clear();
- char c;
- while (f.getChar(&c) && c) {
- if (c == '/')
- s.clear();
- else
- s += QLatin1Char(c);
- }
- if (s == QLatin1String("gdb")) {
- appNoGrab = true;
- qDebug("Qt: gdb: -nograb added to command-line options.\n"
- "\t Use the -dograb option to enforce grabbing.");
- }
- f.close();
- }
+ if (!appNoGrab && !appDoGrab && runningUnderDebugger()) {
+ appNoGrab = true;
+ qDebug("Qt: gdb: -nograb added to command-line options.\n"
+ "\t Use the -dograb option to enforce grabbing.");
}
#endif