-
-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ptrace
support
#56
Comments
Doing this might be problematic on macOS because of entitlements needed to make the required mach system calls. I actually tried to implement it on Noah on macOS Catalina. Noah had every process running its own virtual processor with its own virtual address space, using similar page translation methods as blink. So basically each process manages its own Linux process on a micro VM. The Linux syscall interrupts are captured and routed to macOS. The VM state is also copied when a process is forked. My best approach was to manage every process's debugging state using a central debugging helper. Mach's vm_read/vm_write and mig would be used to tell the tracee to go into an infinite loop, to wait for messages and continue. MIG would be used to read the process's virtual memory. That's just the Mac side of things. I imagine a cross platform solution would be extremely complicated. |
All the operations in the documentation attached in my original post involves only sending a runtime signal, so the only call required is The debuggee then sends the required information to the debugger through some kind of connection. |
I think DarlingHQ uses a kernel module to achieve some of its ptrace functionality. IIRC, Darling also emulates Darwin's bsd threads in the lkm. I don't know if @jart plans to touch any kernel APIs. |
Wrong, at least since early 2022.
Half-true, DarlingHQ emulates BSD threads in its
Their |
Well that's pretty impressive stuff, I never knew they moved threads to userspace. I understand that many
According to DarlingHQ docs:
Firstly an RT signal is a realtime signal if I'm not wrong. You can't really send IPC/mach messages to a halted process. Regardless, Blink could use |
According to DarlingHQ docs:
(Emphasis mine)
The process is not actually halted (from the host machine's perspective), but the emulated code (in DarlingHQ's case, macOS code, in Blink's case, the Linux binary) should stop executing. Therefore, while the emulated binary seems to have stopped, background emulator tasks should still continue working.
Like I said, we're not actually invoking |
Let me rephrase. On macOS you can halt a process without Secondly:
Wine and DarlingHQ (probably blink too) are not emulators, they're compatibility layers. I like to refer to them as userspace hypervisors, even though that's probably wrong. They're like execution coordinators, kinda like Listen dude, I'm not here to argue. I'm here to list the points and possibilities in this issue (help solve the issue) and learn new things. This back and forth is counterproductive. |
I am aware of WINE's name as well as the fact that DarlingHQ loads a macOS binary directly on a Linux process's address space and executes instructions directly on the host's CPU. However, to simplify things I (and the DarlingHQ project itself) use the word "emulation" and its other forms. The term is commonly understood as "instruction set emulation" but depending on the context it can also mean "system call emulation" or "<insert something that needs compatibility> emulation".
FYI,
Again, quoting the documentation:
So, imagining a scenario when
Therefore, the hypothetical future This "cooperative debugging" carries one limitation that I mentioned before:
I'm not here to spark a debate either. I'm just clarifying my points for you, jart, other people who might help implement this in the future, and anyone who visits this discussion. |
I understand how cooperative debugging works. I understand what could be done to emulate the syscall ptrace. Like I said I've tried it before; more specifically tried and failed. What I don't understand is how we ended up here. I mentioned a possibility of something and you strike it down as impossible. I state the reason why I say that, and you maintain your stance. And you bring in examples from Look, none of us knows everything here. However, I find your responses (or rebuttals) rather arrogant. I have a hard time believing you don't intend to spark a debate. Regardless I'll maintain that there MAY BE A POSSIBLITY that entitlements will be needed. What if @jart decides to just halt the process and read it's memory, because that'd be easier? We wouldn't know would we? It's all conjecture what is required because we don't know what's going to be done. |
There might have been a misunderstanding in this conversation. Sure, I do acknowledge that if you directly use macOS APIs like your attempt described in the first comment, there may be a possibility that entitlements are needed. I also acknowledge that the approach I mentioned in the original post is just a suggestion. jart may use it, use your approach on macOS, or use a totally different one. The misunderstanding here might have been that I was suggesting a POSIX-only approach for Apart from some off-topic comments about Again, I do acknowledge that translating |
I'm still catching up on this thread. Wow a lot of lively discussion here. I'm so happy to see how passionate folks are about their visions for Blink's future. Please remember that we're all friends here, and that nothing is impossible. Please keep that in mind when writing your communications. Blink is very POSIX focused, but I don't want to be limited to POSIX. I'd be happy to see integration with Mach APIs happen if that makes Blink better. ptrace() is a powerful and cool Linux specific API that'd be great to have available on MacOS. The one Linux API that I think is even cooler is SECCOMP BPF, since I have real need of that, since it's what redbean uses to provide sandboxing on Linux. Debugging processes external to Blink has been less of a focus until now, since the motivation has been more geared towards improving the debuggability of things that run inside Blink. |
@trungnt2910 I never saw your reply. I also apologize for the misunderstanding on my part. Stooping low (argumentatively) to prove a point was and will always be counterproductive. |
One thing we discussed recently on Discord is that having ptrace could potentially pave the way for running GDB inside Blink. Obviously Blinkenlights is the native debugger experience that fully works inside and outside of Blink. But having GDB would be nice too. The canonical way to do GDB though would be to implement the GDB server protocol into Blink, so that GDB can connect via a TCP socket similar to what Qemu does. |
This is a very ad-hoc approach to provide debugging support for Blink. First, we have 1000 lines of code to bring If someone wants to use, for example, LLDB instead, or use some framework-specific debuggers like the .NET Core Debugger ( |
This syscall is crucial for debugging support on blink, which may aid development in many scenarios.
While Linux
ptrace
is quite a unique call, it can be emulated using a technique called "cooperative debugging", used by the Darling project to emulate macOSptrace
without having to actually rely on the host'sptrace
.The approach uses an internal signal, which I believe blink already does.
The text was updated successfully, but these errors were encountered: