4

I'm still new to xcode. I have "show disassembly when debugging" UNCHECKED but I know that as I step through my own code that I will still regularly be thrown into assembly code when system methods are called.

My question is ...... Is there any way to quickly step over the assembly code to the NEXT line of my own custom code rather than endlessly hitting F6 or F8. I know that, in advance, I can set a new breakpoint at the next custom method to be called and press the run button, but when I quickly step through my code, I usually don't know in advance when the debugger will throw me into assembly code and when that happens it's then too late to be hitting the "run to next breakpoint" button. Any help appreciated.

EDIT - thx for the "continue to current line" suggestion but often when i try to do this i put cursor on a line of my own code and the "continue to current line" command under the debug menu is greyed out. also i usually dont know in advance where the code execution will reenter my own code so i could be putting the cursor in a spot which wont be called anyway. Basically im trying to learn the order of execution of my code by stepping thru line by line. Everytime i get "thrown" into dissassemby i dont know in advance where the order of execution will re-enter my own custom code (much of which might be other person's code) so pressing continue often takes me to the end of the build and im none the wiser to the path taken. The only option i see is to endlessly press Fn-F8 which is a right pain. Surely i must be missing something?

EDIT - thx @Jim for your suggestion. still no luck, ive tried your code (lldb) "break set -r .* -s MyBinary" substituting MyBinary with the name of the app im trying to set breakpoints on all methods in and all i get is "Breakpoint 2: no locations (pending). WARNING: Unable to resolve breakpoint to any actual locations. i did a google search on this to this page How to automatically set breakpoints on all methods in XCode? and that page indicates the words break set should be breakpoint set and there is no * after the . so i tried that and same error message appears and no breakpoints are set. any suggestions?

Community
  • 1
  • 1
lozflan
  • 835
  • 10
  • 23

2 Answers2

1

One trick for tracing execution through the functions in one binary is to use a regular expression breakpoint to stop on all the functions in that binary, e.g.:

(lldb) break set -r .* -s MyBinary

Then you can just use "continue" to go from call to call in your code. You can provide the -s option more than once to set the breakpoint in multiple shared libraries.

lldb's execution doesn't slow down much even with tens of thousands of breakpoints, though initially setting them might take a bit particularly if you are debugging an iOS app. So this is a viable technique for medium sized libraries.

If you are trying to trace execution on just one thread, then use the -t option to break set to limit the breakpoint to that thread.

Also, remember that you can disable individual locations within this breakpoint. So if you hit a breakpoint on some function you don't care about, look at the PC banner in the source window on the LHS it will say something like "Thread 1: breakpoint 1.1", so just do:

(lldb) break dis 1.1

That way you can focus in on the functions you actually care about as you go.

Jim Ingham
  • 25,260
  • 2
  • 55
  • 63
  • How do we find the name to sub in for MyBinary? Haven't been able to find any info on that. – Agent Friday Jan 30 '20 at 06:13
  • It should be the name of the binary. So the name of the executable, if your binary is an executable, if you have a standard Unix library like `libBinary.dylib`, then that will be the name. For .app's the name is the name of the actual binary (the one that's in `MyApp.app/Contents/MacOS`) and similarly for .frameworks it is the base name of the framework (the name in `Versions/Current` in the framework. You can use `image list` in lldb to see all the loaded images, then find the one you are interested in and the name will be the base name of whatever that loaded library is. – Jim Ingham Jan 30 '20 at 19:10
  • OK, got it working. It looks like on iOS, the executable will be the first line of the `image list` output, and if it happens to contain spaces, just wrap it in quotes. So if the path output is `/some-long-path/Debug-iphoneos/some app.app/some app`, then the last parameter would be just `'some app'` – Agent Friday Feb 01 '20 at 20:47
  • That's right. The executable will be the first entry on macOS as well. If you want to know more about the syntax of lldb commands (why you need the quotes...) there's a description here: https://lldb.llvm.org/use/tutorial.html. – Jim Ingham Feb 03 '20 at 18:47
0

When you hit the assembly code, change to your code in the editor window and position the cursor on the line you which to jump. Next, hit ^⌘C on your keyboard and the debugger will run through to the current line in the editor. Under the Debug menu, ^⌘C is Continue to Current Line.

neilco
  • 7,964
  • 2
  • 36
  • 41