Fix docker setup to unbreak "gdb" not stopping at breakpoints
Open, Needs TriagePublic

Description

Hi,

some KDevelop autotests run "gdb" in a childprocess for testing remote-controlling gdb from KDevelop. Which seems to work fine at least in the usual developer setup environments.

On KDE CI though, some random misbehaviour can be observed, at least when it comes to setting breakpoints:
in some CI build runs, but not all, the test fail as gdb does not stop at the breakpoints, other than expected. The behaviour seems not correlated to any changes in related KDevelop sources.

Some search hits on the internet suggest this might be related to the docker host setup WRT some syscalls (ptrace-something). Which might explain the randomness as the different hosts might have different setups?

Could this please be explored and solved, so help decreasing the amount of failing autotests with KDevelop?
Myself I lack docker knowledge, so only can point to the problem.

Following some details which hopefully help to understand and explore the problem:

A test where this misbehaviour currently can be seen is "qtprinters", from KDevelop. See the first of its test methods:

void QtPrintersTest::testQString()
{
    GdbProcess gdb("qstring");
    gdb.execute("break qstring.cpp:5");
    gdb.execute("run");
    QVERIFY(gdb.execute("print s").contains("\"test string\""));
    gdb.execute("next");
    QVERIFY(gdb.execute("print s").contains("\"test stringx\""));
}

Source: https://cgit.kde.org/kdevelop.git/tree/debuggers/gdb/printers/tests/qtprinters.cpp

"qstring" is a binary program built next to the "qtprinters" test from this sources:

#include <QString>
int main()
{
    QString s("test string");
    s.append("x");
    return 0;
}

https://cgit.kde.org/kdevelop.git/tree/debuggers/gdb/printers/tests/qstring.cpp

Well behaving CI run:
on "run" the target program is started, but execution stopped at the first breakpoint, as expected. The checks and the further execution all work as they should.

QDEBUG : QtPrintersTest::testQString() "break qstring.cpp:5"  =  "Breakpoint 1 at 0x401a82: file /home/jenkins/sources/kdevelop/kf5-qt5/debuggers/gdb/printers/tests/qstring.cpp, line 5."
QDEBUG : QtPrintersTest::testQString() "run"  =  "Starting program: /home/jenkins/sources/kdevelop/kf5-qt5/build/debuggers/gdb/printers/tests/qstring \n[Thread debugging using libthread_db enabled]\nUsing host libthread_db library \"/lib/x86_64-linux-gnu/libthread_db.so.1\".\n\nBreakpoint 1, main ()\n    at /home/jenkins/sources/kdevelop/kf5-qt5/debuggers/gdb/printers/tests/qstring.cpp:5\n5\t    s.append(\"...

E.g. https://build.kde.org/view/Kdevelop/job/kdevelop%20master%20kf5-qt5/PLATFORM=Linux,compiler=gcc/277/testReport/(root)/TestSuite/qtprinters/

Bad behaving CI run:
on "run" the target program is started, but does not stop at the breakpoint, instead completes execution, as can be seen by gdb message: "During startup program exited normally.". As consequence all following checks fail.

QDEBUG : QtPrintersTest::testQString() "break qstring.cpp:5"  =  "Breakpoint 1 at 0x401a82: file /home/jenkins/sources/kdevelop/kf5-qt5/debuggers/gdb/printers/tests/qstring.cpp, line 5."
QDEBUG : QtPrintersTest::testQString() "run"  =  "Starting program: /home/jenkins/sources/kdevelop/kf5-qt5/build/debuggers/gdb/printers/tests/qstring \nDuring startup program exited normally."
QDEBUG : QtPrintersTest::testQString() "print s"  =  "No symbol \"s\" in current context."
FAIL!  : QtPrintersTest::testQString() 'gdb.execute("print s").contains("\"test string\"")' returned FALSE. ()
   Loc: [/home/jenkins/sources/kdevelop/kf5-qt5/debuggers/gdb/printers/tests/qtprinters.cpp(104)]

E.g. https://build.kde.org/view/Kdevelop/job/kdevelop%20master%20kf5-qt5/PLATFORM=Linux,compiler=gcc/278/testReport/(root)/TestSuite/qtprinters/
(so run after the one before, triggered by scripty having committed only 2 lines in a desktop file)

Some links I found which might contain helpful info:
http://stackoverflow.com/questions/34856092/gdb-does-not-hit-any-breakpoints-when-run-it-from-inside-docker-container/35583411
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=729018

kossebau created this task.Feb 24 2017, 4:52 PM
Restricted Application added a subscriber: sysadmin. · View Herald TranscriptApr 12 2017, 11:26 AM

Fixing this would probably require granting the containers the CAP_SYS_PTRACE which the Jenkins plugin doesn't support currently.
I've filed https://github.com/KostyaSha/yet-another-docker-plugin/issues/148

bcooksley moved this task from Feature Requests to In Progress on the build.kde.org board.
bcooksley renamed this task from Fix docker host setups (?) to unbreak "gdb" not stopping at breakpoints (e.g. in KDevelop unit tests) to Fix docker setup to unbreak "gdb" not stopping at breakpoints.Aug 12 2017, 9:09 AM

We're changing to use the build.kde.org board exclusively for CI work, so removing Sysadmin from this (Sysadmin will still be informed of any CI task which gets opened)