Commit Graph

13 Commits

Author SHA1 Message Date
Marcus Tillmanns
373886bc21 ProcessStub: Fix start sequencing
An application that is using ptrace will send SIGTRAP as soon as it
reaches its execve call.

The process stub previously expected the only signal sent from the
inferior to be SIGSTOP due to the PTRACE_DETACH call with the
SIGSTOP argument.

This meant that a race could occur where the SIGTRAP was received
instead of the SIGSTOP and so the PTRACE_DETACH did not actually
detach correctly.

This patch fixes it so that it first waits for the SIGTRAP and then calls
detach and waits for the expected SIGSTOP.

Should this fail, more debug output is added to ease debugging failures.

Fixes: QTCREATORBUG-29463
Change-Id: Ibac8b75de0c5604aeb20faba8aff58633329341e
Reviewed-by: Artem Sokolovskii <artem.sokolovskii@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2023-08-29 13:25:08 +00:00
Marcus Tillmanns
d2acb8049b Terminal: Support yama/ptrace_scope=1
We set "PR_SET_PTRACER" to "PR_SET_PTRACER_ANY"
which will allow the debugger to attach to the inferior in both
mode 0 and mode 1 of yama/ptrace_scope. Mode 2 and 3 are still not
supported.

Fixes: QTCREATORBUG-29554
Change-Id: I61d9ef3d9128f03769436010c6f250ccdada52bc
Reviewed-by: hjk <hjk@qt.io>
2023-08-29 04:45:06 +00:00
Marcus Tillmanns
02e2a642dc ProcessStub: Add missing if
When not starting in debug mode, the inferior is not waiting
for ptrace(DETACH), so the code that calls DETACH waits for
something that does not happen.

Fixes: QTCREATORBUG-29503
Change-Id: Ic00a52b9e4f3a797d1be337a2ce53afc6ee63927
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2023-08-15 13:32:45 +00:00
Marcus Tillmanns
f13d9cc736 ProcessStub: Wait for detach to finish
Without calling waitpid() after detaching from the inferior
a race condition could occur where the ptrace(...) call would
finish before it was actually detached, leading to the following
gdb to fail attaching as the stub was still attached to it.

Calling waitpid here solves the race condition.

Fixes: QTCREATORBUG-29463
Change-Id: Ia1d79a18a96078bbf72589bebbc7d7ac027dea0d
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2023-08-10 08:14:29 +00:00
Marcus Tillmanns
6b8473a2e8 Terminal: Fix exit reporting in error cases
Previously the finished signal was sent not sent soon enough
for the Process to recognizes it correctly.

Also, the process stub would exit prematurely in cases of crashes.

The process stub should only return an error exit code if it did not
show the "waiting for keypress" message.

Fixes: QTCREATORBUG-29350
Change-Id: I86f7d75bacbdb5ee2b0009669926d94b6a75346a
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2023-06-30 11:14:49 +00:00
Christian Kandeler
5203704e24 qbs build: Mark some more tools as non-Qt
Plus small clean-ups.

Change-Id: I3601543b04bfc7b016769a63091a91f62607f2dc
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2023-06-19 11:26:56 +00:00
Marcus Tillmanns
d491faf94a Utils: Send ack from Process stub
Allow the server to listen for command results.
Fixes Qt Creator hanging when stopping application
being debugged.

Change-Id: Ia175b1bb1836b5593bc073394fa152923e1dda28
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2023-06-12 12:13:02 +00:00
Marcus Tillmanns
2039880e75 ProcessStub: Don't block main thread while waiting for keypress
Otherwise the request to exit from Qt Creator would be missed,
making QtC hang on exit while waiting for the stub to exit.

Fixes: QTCREATORBUG-15749
Change-Id: I26dfa2c8aa358c8d7ad662ef806f459d1bbb6ec2
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2023-06-08 12:37:42 +00:00
Marcus Tillmanns
c158921af3 ProjectExplorer: Don't allow remote run in terminal
Currently the process stub does not support starting / debugging
processes on remote devices. To reflect this the "Run In Terminal"
aspect is disabled for remote targets.

Fixes: QTCREATORBUG-29058
Change-Id: I9b3bcd65d4db468c683f2743a49227bfbecaf3d3
Reviewed-by: hjk <hjk@qt.io>
2023-05-15 10:05:54 +00:00
Marcus Tillmanns
ee52d204e6 ProcessStub: Read correct channel
Change-Id: Ib26c75f069c90290f7930becdec42bf6ff5aa3d9
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
2023-04-04 10:52:39 +00:00
Marcus Tillmanns
f1f5a7412a Utils: Send __qtc marker from stub
Docker and ssh devices need the real process id on the
remote device. The process stub now send this if it receives
it as the first line of output.

Change-Id: I5d3af39651958fc88d21c3854a0fa1d7f51547a6
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
2023-04-04 05:59:25 +00:00
Marcus Tillmanns
80fa3339e0 Utils: Re-add "press enter to continue" to stub
To keep the terminal from closing immediately, ask the user
to press enter after the inferior exited.

Make it configurable as the terminal plugin does not need
this.

Change-Id: I1949895f022a54539a6139be9f92fdc698f6534e
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2023-03-21 13:50:18 +00:00
Marcus Tillmanns
0870f2583b Terminal: Enable TerminalProcessInterface
Adds a new helper app "process_stub" that replaces the previous.
"process_stub_unix/win". The purpose was and is to allow processes
to be "injected" into other hosts apps like terminals while still
being able to control and debug them.

A new base class called "TerminalInterface" is used for both the new
Terminal plugin and the legacy TerminalProcess implementation.

Fixes: QTCREATORBUG-16364
Change-Id: If21273fe53ad545d1a768c17c83db4bf2fd85395
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2023-03-20 10:03:23 +00:00