KDAB / GammaRay

GammaRay is a tool to poke around in a Qt-application and also to manipulate the application to some extent.
https://www.kdab.com/gammaray
Other
1.63k stars 283 forks source link

GammaRay 3.0.95 won't attach to minimalwidgetapplication (or any other Qt app) #952

Closed frnkwtzl closed 8 months ago

frnkwtzl commented 9 months ago

I followed the instructions in GammaRay Tutorials (Part 2), i.e. built GammaRay from Git Clone with Compiler Kit Qt 6.5.4 for macOS, build configuration release, using Qt Creator 12.0.2 on a Mac Mini with Apple M2 Pro Chip running macOS Sonoma (14.2.1). This resulted in GammaRay 3.0.95 (revision: 1dbceb189). At some point of this process I selected the first entry of this list: projfile I launched /testbin/minimalwidgetapplication minimal Then I ran GammaRay – gammaray-launcher from within Qt Creator. selftest attach After clicking Attach GammaRay terminated immediately, with Qt Creator's Application Output printing

22:16:11: Starting /Users/fw/Desktop/build-GammaRay-Qt_6_5_4_for_macOS-Release/GammaRay.app/Contents/MacOS/gammaray-launcher...
Startup: gammaray-launcher
Detaching: /Users/fw/Desktop/build-GammaRay-Qt_6_5_4_for_macOS-Release/GammaRay.app/Contents/MacOS/gammaray --inprocess --probe qt6_5-arm64 --no-listen --pid 2482
Working Directory: /Users/fw/Desktop/build-GammaRay-Qt_6_5_4_for_macOS-Release/GammaRay.app/Contents/MacOS
22:16:19: /Users/fw/Desktop/build-GammaRay-Qt_6_5_4_for_macOS-Release/GammaRay.app/Contents/MacOS/gammaray-launcher exited with code 0

This happens with any access mode option selected, and also when attempting to launch (rather than attach to) minimalwidgetapplication. I didn't manage to attach to or launch any other Qt application either.

I am new to all this, so please be gentle with my verboseness as well as omissions. I'll be happy to run more tests or provide additional information as needed.

ferdnyc commented 9 months ago

IIRC, recent macOS has process space protection that prevents normal processes from attaching to other normal processes in different process spaces, even if run by the same user. This also affects tools like gdb, for example.

AIUI there are ways to override this protection, but the simplest solution is often to simply launch the process-to-be-inspected as a child of the debugging tool. That keeps it in the same process space, and should make it inspectable.

If you run GammaRay itself first, and then use its "Launch" tab to start /testbin/minimalwidgetapplication as a child of the GammaRay process, does that work?

ferdnyc commented 9 months ago

Shoot, sorry, I missed that you'd already covered that:

This happens with any access mode option selected, and also when attempting to launch (rather than attach to) minimalwidgetapplication. I didn't manage to attach to or launch any Qt application either.

ferdnyc commented 9 months ago

I tracked down a discussion I recalled having a while back regarding how this has to be handled for gdb:

https://gist.github.com/mike-myers-tob/9a6013124bad7ff074d3297db2c98247

Basically, the binary has to be codesigned (a local certificate is fine), and it has to be configured with a set of entitlements that permit debugging of other processes, for it to be usable in macOS 11+. I would not be at all surprised if the same is true of GammaRay.

frnkwtzl commented 9 months ago

After codesigning <build directory>/GammaRay.app/Contents/MacOS/gammaray and <build directory>/GammaRay.app/Contents/MacOS/gammaray-launcher, and running <build directory>/GammaRay.app (from Finder, not from Qt Creator), I was able to launch and attach to <build directory>//testbin/minimalwidgetapplication as well as launch <build directory>//testbin/minimalcoreapplication. Bildschirmfoto 2024-02-29 um 21 07 03

The latter didn't display a GUI of its own, though. Not sure if this is to be expected, but at least I'm beginning to get somewhere. Will proceed to introspecting custom projects (once I figured out how to build an executable from a Qt for Python Qt Quick Project).