Reputation: 1012
I'm trying to debug an executable, that I manually built with clang
, with lldb
on MacOS host (ssh'd into) machine, through ssh
. However, when I run
it I get:
(lldb) error: process exited with status -1 (no such process.)
If I try the same with system executable like /bin/ls
it works, perhaps because they are signed by Apple. My executable isn't signed so I tried self-signing it but no luck.
Experimenting more, I copied /bin/ls
and resigned it with my own self-sign certificate which led to the same problem again! So, I believe this might be something to do with signing.
Other things that I have tried:
lldb
with sudo
.sudo DevToolsSecurity --enable
spctl developer-mode enable-terminal
Why do the system executables work but not mine?
System details:
Darwin 23.4.0 Darwin Kernel Version 23.4.0: arm64 macOS 14: Sonoma
NOTE: I have checked other answers. This one lldb gives error "error: process exited with status -1 (Error 1)" comes close but is unresolved as seen in the follow up comments on the top answer.
EDIT 1:
Dug more and generated logs. For the executable copied from /bin/ls
the debugger is successful in attaching to it
[LaunchAttach] (93085) about to task_for_pid(93084)
108 +0.029169 sec [16b9d/0103]: ::task_for_pid ( target_tport = 0x0203, pid = 93084, &task ) => err = 0x00000000 (success) err = 0x00000000
[LaunchAttach] (93085) successfully task_for_pid(93084)'ed
but for my own executable it fails
[LaunchAttach] (93825) about to task_for_pid(93824)
error: [LaunchAttach] MachTask::TaskPortForProcessID task_for_pid(93824) failed: ::task_for_pid ( target_tport = 0x0203, pid = 93824, &task ) => err = 0x00000005 ((os/kern) failure)
109 +0.027093 sec [16e81/0103]: error: ::task_for_pid ( target_tport = 0x0203, pid = 93824, &task ) => err = 0x00000005 ((os/kern) failure) err = ::task_for_pid ( target_tport = 0x0203, pid = 93824, &task ) => err = 0x00000005 ((os/kern) failure) (0x00000005)
Both executables are in the same directory.
EDIT 2: More info.
I compiled a simple example (default console app examples) with Xcode and here's what I found experimenting with it.
ssh
+ lldb
fails to get the task only when all of the following is true:
x86_64
build. ARM
build doesn't show the weird behavior.(nfs, nodev, nosuid, automounted, nobrowse)
. If it's on a "normal" filesystem (apfs, NFS exported, local, journaled, nobrowse, protect, root data)
somehow it works.NOTE: If either is not true, the debugging works. For e.g. I can debug the same code on the NFS filesystem mount when compiled for ARM
architecture.
#include <iostream>
int main() {
std::cout << "Hello, World!\n";
return 0;
}
The exe build by Xcode is signed and has the following entitlements.
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>com.apple.application-identifier</key><string></string><key>com.apple.security.get-task-allow</key><true/></dict></plist>
Upvotes: 2
Views: 164
Reputation: 31
You should try to enable developer mode.
Check status
DevToolsSecurity -status
Enable it
sudo DevToolsSecurity -enable
Check it again
DevToolsSecurity -status
Reference from this answer
Upvotes: 0