Debugging some wrapped Fortran code

I’ve created a Julia package that provides a wrapper around a Fortran subroutine. I’d like to build my Fortran shared library with debug information and use gdb to set a break point in the Fortran code. Is that possible to do, while still calling the Fortran code from Julia? I tried attaching gdb to Julia before I call my wrapper function, but it failed to attach.

Thanks!
Daniel

Here’s some more detail on what’s going on. When I try to attach gdb to the julia process, I get the following:

(gdb) attach 86616
Attaching to process 86616
Unable to find Mach task port for process-id 86616: (os/kern) failure (0x5).
 (please check gdb is codesigned - see taskgated(8))

I’m on a Mac. I did some searching and found that some steps to configure a certificate for gdb: https://sourceware.org/gdb/wiki/PermissionsDarwin. However, even after following those steps, my issue persisted. At the bottom of the same page, they have a command to filter the logs pertaining to the taskgated process. When I do that and try again, I get the following message:

   0    kernel: (AppleMobileFileIntegrity) macOSTaskPolicy: (org.gnu.gdb) may not get the taskport of (julia) (pid: 86616): (julia) is hardened, (julia) doesn't have get-task-allow, (org.gnu.gdb) is a declared debugger

This is pretty far over my head already. Does anyone have any ideas?

Just in case there was a step missing: make sure and follow everything in sections 1.3 and 1.4 of the linked GDB document (probably including the reboot, unfortunately). Then be sure to check the gdb entitlements. These must include get-task-allow as listed by with codesign -d --entitlements - $(which gdb) (from the final paragraph of section 1.3. See also this thread which might be helpful.

That said, I would generally suggest using LLDB on macOS. It is the platform-native debugger, supported by the OS publisher etc. There is still a lot of (arguably) missing functionality relative to GDB, and some major performance issues. But it generally works as expected on macOS, whereas (in my experience) GDB is very hit-or-miss.

Thanks for the suggestions!

I did do the reboot and I confirmed that get-task-allow is included in the entitlements.

I also tried lldb. I’ve always used gdb, so perhaps I just don’t know what I’m doing, but I tried the following:

(lldb) attach 95197
error: attach failed: Error 1
(lldb) process attach --pid 95197
error: attach failed: Error 1

I guess I need to go through a similar process to make sure lldb has the get-task-allow entitlement…

Looking at the thread you linked to… Is it the case that julia needs to also have the get-task-allow entitlement? Mine doesn’t:

$ codesign -d --entitlements - $(which julia)
Executable=/Applications/Julia-1.5.app/Contents/Resources/julia/bin/julia
��qq�<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>com.apple.security.automation.apple-events</key>
	<true/>
	<key>com.apple.security.cs.allow-dyld-environment-variables</key>
	<true/>
	<key>com.apple.security.cs.allow-jit</key>
	<true/>
	<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
	<true/>
	<key>com.apple.security.cs.debugger</key>
	<true/>
	<key>com.apple.security.cs.disable-library-validation</key>
	<true/>
	<key>com.apple.security.device.audio-input</key>
	<true/>
	<key>com.apple.security.device.camera</key>
	<true/>
</dict>
</plist>

Should be in 1.5.1.

1 Like

Thanks! I just downloaded it and get-task-allow is indeed now listed:

$ codesign -d --entitlements :- $(which julia)
Executable=/Applications/Julia-1.5.app/Contents/Resources/julia/bin/julia
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>com.apple.security.automation.apple-events</key>
	<true/>
	<key>com.apple.security.cs.get-task-allow</key>
	<true/>
	<key>com.apple.security.cs.allow-dyld-environment-variables</key>
	<true/>
	<key>com.apple.security.cs.allow-jit</key>
	<true/>
	<key>com.apple.security.cs.allow-unsigned-executable-memory</key>
	<true/>
	<key>com.apple.security.cs.debugger</key>
	<true/>
	<key>com.apple.security.cs.disable-library-validation</key>
	<true/>
	<key>com.apple.security.device.audio-input</key>
	<true/>
	<key>com.apple.security.device.camera</key>
	<true/>
</dict>
</plist>

But, unfortunately, I still can’t attach lldb to a julia process. When I try to attach it, I get this taskgated log entry:

   0    kernel: (AppleMobileFileIntegrity) macOSTaskPolicy: (com.apple.debugserver) may not get the taskport of (julia) (pid: 1523): (julia) is hardened, (julia) doesn't have get-task-allow, (com.apple.debugserver) is a declared debugger

I’m not sure why it says julia doesn’t have get-task-allow, when I can see that it clearly does.