2

The Xcode console has a 'Debugger output' filter. I understand this is for use with lldb, and that you can get messages to print to this output by using breakpoints. My question is not how to do that.

My question is: what is the underlying mechanism Xcode itself uses to write lldb messages to Debugger Output (not Target Output)? Is there a variable similar to stdout or stderr that writes here? Is it possible, from Xcode target code (Swift/Obj-C/C), to write to this output?

2
  • NSLog (Obj-C) & print (Swift). There's a button in the bottom/left corner where you can switch between All Output, Debugger Output and Target Output. Is this what you want? Commented Jul 2, 2020 at 17:54
  • No, by default those go to "Target Output" (and by extension, "All Output") - I'm asking how to direct output to "Debugger Output" Commented Jul 2, 2020 at 19:07

1 Answer 1

7

Looks like Xcode uses a tty to communicate with lldb, and you can interface with the Debugger Output using that:

echo "Wheeeeeeee" > $(lsof -p $(ps -A | grep -m1 MacOS/Xcode | awk '{print $1}') | grep -m2 dev/ttys | tail -1 | awk '{print $9}')

Breaking the above down:

$ ps -A | grep -m1 MacOS/Xcode | awk '{print $1}' 
21280

This gives the process ID of Xcode (21280). Using this, we can find the files it has open:

$ lsof -p 21280 | grep /dev/ttys
Xcode   21280 tres   47u      CHR               16,3       0t0                3569 /dev/ttys003
Xcode   21280 tres   58u      CHR               16,5       0t0                3575 /dev/ttys005

The one with the highest number (/dev/ttys005 in this case) is the one we want, so let's extract it. tail -1 will give us the last line of output, and awk '{print $9}' will give us the 9th item on the line, which is what we want!

$ lsof -p 21280 | grep /dev/ttys | tail -1 | awk '{print $9}'
/dev/ttys005

Now we can use this to write whatever we want:

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

Impressive 👏 Is the other tty interface the Target Output?
Thanks and yep it is. Now to figure out how to write to it from the Simulator...
Any way to read from it as well? echo "Wheeeeeeee" > /dev/ttys004 prints to Target Output in xcode so I though maybe tail -f /dev/ttys004 would work... but it does not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.