I need to run another process that needs to ptrace() its inferior. But also gdb needs to ptrace() the same inferior as well, so this will lead to chaos.
The first and obvious solution that came to my mind was to detach the gdb whenever the other process needs to access the inferior and then attach again. However, this is also problematic when the inferior is stopped for debugging.
Then I tried to launch the other process from gdb using gdb's shell
command thinking maybe it can work if gdb executes the other process as its child. But even when gdb executes it as a child, they'll have different PIDs, so the problem still continues.
Is it possible to make gdb and the other process look like they share the same PID so they can attach to the same inferior?
No, there's no way to do this.
Your best bet is to add new code to gdb to do what you want.