<div dir="ltr">Thanks for the info Jim. That answers my questions. I will file a bug for lldb error message.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 9, 2016 at 5:57 PM, Jim Ingham <span dir="ltr"><<a href="mailto:jingham@apple.com" target="_blank">jingham@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Mar 9, 2016, at 3:04 PM, Jeffrey Tan via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a>> wrote:<br>
><br>
</span><span class="">> Hi,<br>
><br>
> My colleague is trying to use our lldb IDE attaching to app run/build from Xcode which failed. I can reproduce this with lldb console:<br>
><br>
> jeffreytan-mbp:$ ps aux | grep iOSApp<br>
> jeffreytan 61816 0.0 0.0 2432772 676 s002 S+ 3:00PM 0:00.00 grep iOSApp<br>
> jeffreytan 61806 0.0 0.2 2721120 38600 ?? SXs 3:00PM 0:00.24 /Users/jeffreytan/Library/Developer/CoreSimulator/Devices/EF17E202-3981-4DB0-87C9-2A9345C1E713/data/Containers/Bundle/Application/CAEBA7D7-D284-4489-8A53-A88E56F9BB04/iOSAppTest.app/iOSAppTest<br>
> jeffreytan-mbp:$ lldb -p 61806<br>
> (lldb) process attach --pid 61806<br>
> error: attach failed: attach failed: unable to attach<br>
><br>
> My theory is:<br>
> 1. Xcode does not have the concept of run without debugger and run under debugger, so it always run app with debugger enabled.(Is this true?)<br>
<br>
</span>That is not true. In the Run Scheme, uncheck the "Debug Executable" checkbox. But running with the debugger is the default.<br>
<br>
Note, an X in the status field for ps means the app is being debugged. So in this case, the app you were trying to attach to WAS already being debugged.<br>
<span class=""><br>
> 2. And you can't have two native debuggers debugging the same process on Mac(this is true on Windows, is it true for Mac or Linux?)<br>
<br>
</span>That is true for Mac, and in general for ptrace based debugging. I don't know much about procfs.<br>
<span class=""><br>
><br>
> If both are true, can we report meaningful message like "inferior is already being debugged" or something similar instead of the generic error message like "attach failed: unable to attach"?<br>
<br>
</span>That should be possible, there's code to eliminate already debugged processes in the "Attach to process by name" functionality. So if you specify a PID and the attach fails, we could check after the fact and see if it is already being traced. Please file a bug for this, and/or take a whack at fixing it if you feel like it.<br>
<span class=""><br>
><br>
> Btw: I found I can still use gdb to attach to the process(with a permission elevation dialog pop-up) and see the callstack. How does gdb do that?<br>
<br>
</span>I haven't looked at the FSF gdb OS X support for years, so I can't really comment on it. But it is not possible to ptrace something that is already ptraced, so if gdb is still doing it this way, then it should also fail. Maybe it is only getting the mach task and exception ports and debugging just with them? You can have multiple readers for the task port, and you can steal the exception port from someone else. But if it did that, the other debugger should stop working.<br>
<span class="HOEnZb"><font color="#888888"><br>
Jim<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
><br>
> Jeffrey<br>
> _______________________________________________<br>
> lldb-dev mailing list<br>
> <a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a><br>
<br>
</div></div></blockquote></div><br></div>