nisargjhaveri / vscode-ios-debug

iOS debugging in Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=nisargjhaveri.ios-debug
92 stars 11 forks source link

Log doesn't work well #3

Closed aelam closed 2 years ago

aelam commented 2 years ago

Just tested it, everything works well, expect the log, I tried to print something from the code, but nothing is printed out and I've checked every tab

https://github.com/nisargjhaveri/vscode-ios-debug/blob/cdd2b51d14b78ba34f2506a9f6bf8d5218ca677e/lldb/logs.py#L1 I doubt it may be the new mac doesn't have python(2) any more

Do you have any idea about it? Thank you!

bzarco commented 2 years ago

I noticed the same issue. When digging into the extension code I noticed that cdd2b51d14b78ba34f2506a9f6bf8d5218ca677e is not in the published version. @nisargjhaveri Is there any way it could be published (if ready)? Thanks for such a great extension!

aelam commented 2 years ago

@bzarco I've found the master version doesn't work well either. Does it work for you?

nisargjhaveri commented 2 years ago

@aelam. Thanks for raising this. It used to work for me, but seems like something has changed. I tried and looks like it is not redirecting the log output to the specified file when debugger is attached. Looking into what changed and what would be the workaround. Let me know if you have any ideas.

The #!/usr/bin/env python is not really used since we directly import this script in lldb, AFAIK, so that shouldn't be the issue.

@bzarco I has some more changes planned, but it has been long. I'll publish as soon as we figure out the recent change. Glad the extension was useful. :)

aelam commented 2 years ago

unfortunately, I've tried to search the location of the log everywhere but no clue, it only print in the console.app don't know how appcode does it

bzarco commented 2 years ago

@nisargjhaveri I played around with it and have a workaround in #4, feel free to close if you have a better solution.

nisargjhaveri commented 2 years ago

Did some more experiments, my current suspicion is that NSLog is behaving differently and is no longer printing to stderr when debugger is attached.

Tried fprintf(stderr, "something") and it shows up correctly in the logs, but not the ones using NSLog.

bzarco commented 2 years ago

Interesting, I didn't think of trying different types of logging. I was testing with a simple print("test") in Swift, and that started working with #4. In your testing, did the fprintf output show with the --stdout arg? or did it need #4? I can repro NSLog not showing up, I also tried Logger and os_log, which don't show up either.

Note that I tried in the device as well, and only the print output shows up, so it is consistent with the simulator.

aelam commented 2 years ago

When you forward the log location can you still the log in.console.app

bzarco commented 2 years ago

simctl launch behavior on my setup, fyi:

--stdout/stderr: Nothing is written with or without debugger. --console: print doesn't show with or without debugger, NSLog shows without debugger only. --console-pty: print shows with or without debugger, NSLog shows without debugger only.

bzarco commented 2 years ago

Found the real solution, need to set OS_ACTIVITY_DT_MODE env variable to YES (prefixed with SIMCTL_CHILD_ for simulator, using --env "OS_ACTIVITY_DT_MODE=YES" with ios-deploy for device). This works without #4 (so with the original --stdout/stderr args). I believe this is what Xcode does (looks like based on the value of OS_ACTIVITY_MODE from what I read, but didn't dig deeper).

bzarco commented 2 years ago

Looks like this is how ios-deploy handles it... that is not run in this case because of --nolldb. Seems like it could be solved for both simulator/devide with an lldb command?

nisargjhaveri commented 2 years ago

Right. Thanks a lot for the investigations!

OS_ACTIVITY_DT_MODE seems like the correct thing to use.

We can set OS_ACTIVITY_DT_MODE for device by passing env to lldb via launch config and by setting SIMCTL_CHILD_ OS_ACTIVITY_DT_MODE in case of Simulator. I don't think we can set env via lldb in case of Simulator as the process would have already been launched. I can make these changes.

Though, using print in Swift still doesn't work for me without --console-tty. Could you please verify that it works with the original --stdout/stderr without your changes for you?

Also, sorry for the confusion, seems like the method I used for testing logging internally directly printed to stderr. This was probably never working for NSLog or print. :/

nisargjhaveri commented 2 years ago

With af7abc5e0b, NSLog should start working for both Simulator and Device launch configs.

bzarco commented 2 years ago

Thanks for the quick fix! You are right, I must have missed that print wasn't working without --console-pty (device does print everything now!). I rebased #4 and verified simulator debug now works with all kinds of logging.

nisargjhaveri commented 2 years ago

This should now be fixed with af7abc5e0b and c2d50370d42. Thanks!