I'm trying to figure out how to determine what the next method call will be in Xcode if I have a breakpoint set at a particular line of code. Is there a way you can tell what method is executed next? The problem with using "Step Over" is that sometimes it switches into that screen (I don't know what it's called) that shows you the hexadecimal values. I'm guessing it's some sort of screen showing you the byte code? I'm not sure how to get around that and go to the next method in the chain.
Simply look at the stack trace on the left side of the screen. The topmost line (line 0) is the function that you are currently in. The next line below that (line 1) is the function that called the current function and it's the one you will return to when the current function is done.
Look at that stack trace. Notice how some lines are bold and some are not. The lines in bold are functions that you have the source code for. Either code you wrote or code you have from any 3rd party libraries you are using.
If you are stepping through some of your own code and you get to the last line of the function, look at the stack trace. Look at line 1. Is it bold or not? If not, then there is no source code and if you enter that function you will see the assembly code (all that hexadecimal stuff).
Let's say line 0 (your current function) is your own code. Then you see that line 1 and maybe 2 is not in bold, but line 3 is and you want to get to your code in line 3. Click on the "step out" up arrow ( ↥ ) to finish the current function. That will take you to the line 1 (now it becomes line 0). Now you are in the assembly code. Just tap the "step out" button again. Tap it again until you get back to your own code again.
Just look at the stack trace to see where each click of "step out" will take you next.
The picture below is an example. Look at the stack trace. Line 0 is the function I'm currently in. It's named effective in my ViewController class. Note it is bold. Line 1 is the function that called line 0. Line 1 is my cellForRowAt method. It is also in bold. The debugger is currently on the last line of the effective method. If I do either "step over" or "step out" at this point, I will be leave the effective method and return to the point where it was called. Line 1 shows where that is. Since line 1 is in bold I know I have the code for it.
Once you leave the current function and return to the previous function, all of the lines in the debugger shift up. Line 1 becomes line 0. Now I know that when I leave my cellForRowAt method, I would be taken into code I don't have the code for (since that line in the stack trace isn't bold). In fact, as you can in the stack trace, there are no more bold lines until the stack trace returns all of the way back to main. So unless you want to see lots of assembly code, once you finish debugging in cellForRowAt, you may as well click the "continue program execution" button.
Related
I want to have a single line of code with an if and the result on the same line. Example
if(_count > 0) return;
If I add a breakpoint on the line, it is set on the if(_count > 0):
but what I want is to have the breakpoint on the return; like so:
Is this doable?
NOTE: The closest question I could find on SO was this (which is not the same thing).
Just click on a part of the line and press F9. This will set breakpoint in the middle of the line.
EDIT
mareko posted a 3rd option that seems to work just fine and is much easier than messing around with all this line-and-character stuff. I'm going to leave this answer for completeness, but mareko's is much more practical in general.
Yes, but unfortunately, there is no drag-and-drop or anything like that. You have 2 options:
OPTION 1
Move your return to a new line:
obviously, you can leave it like that, but if you want to keep the return on the same line as the if, you can simply delete the new line and the whitespace between the if and the return -- the breakpoint should "stick" to the return as you move it around.
This is probably the easier way to do it unless you are currently debugging code that does not have edit-and-continue for whatever reason. In that case, you'll need option 2...
OPTION 2
Alternately, you can place the cursor just before the r in 'return' and then look in your status bar to see which character ("Ch") you are on. In my case, I'm on 20
now right click on the breakpoint and choose "Location..."
In the dialog box that pops up, set Character: to whatever the status bar was (20 in our example).
I am debugging a piece of code on visual studio and I forgot to note down the values I have kept a watch on. Can I go to previous line without rerunning the entire code?
There are similar questions asked on SO but in my case i haven't run through any error or exception. The code is running normally.
After pausing on a break point, right click on the line you want to "go back" to. From the menu that pops up, select "set next statement".
This will adjust the instruction pointer to continue from the specified line of code, but it will not roll back any variables or memory addresses to the values they were at before that line of code was originally executed.
It sounds like what you want to do is rewind / replay your code rather than just move to a specific line. You can move to a specific line, you can just right click and choose set next statement. Unfortunately, this won't rewind the state of the program to some past point (beyond setting the stack and doing a bit of unwinding).
To rewind/replay you need to be a bit trickier. Some options are: -
VMWare replay which will allow you to record and then go back to a certain point in time.
Intellitrace. I haven't tried it, but it allows you to replay to a point.
Which is a bit heavyweight and wont help you right now.
You can use the mouse to drag the yellow arrow pointing to the "next statement to be executed." This actually changes which statement will be executed next. It's not guaranteed to work, but as long as the code is not too complex, it could.
This is my first time on this amazing forum. I am also very new to vba (3 weeks).
I have 2 macros: CallerMac, WorkerMac. These are in separate modules within the "Modules" node of my VBAProject.
In its code, CallerMac imports a .bas file (which has the WorkerMac code) and executes it through a " Application.Run"
When the user is handed this code, they will run "CallerMac" (whose code wont change much) while the code imports the "WorkerMac" (likely to change often)
How can I, for debugging purposes, "F8"/Step into the copied code (WorkerMac) during execution?
Please let me know how I can rephrase my question if it doesn't say much to you or if I should have searched for it differently (I did a lot of searching before posting this code)
Many thanks.
You can place a breakpoint at the beginning of "WorkerMac" as you step through "CallerMac", and then use F8 to continue running "WorkerMac" in step mode.
You can add breakpoints by right clicking on a line that is an executable statement and going to Toggle->Breakpoint, or by clicking on the bar on the left next to the code. It should show a red circle in the bar and highlight the line in red.
The debugger lets me drag the little green line pointer, but it seems it has no effect at all and when I step it behaves as though I never dragged it.
Just wondering if the bug is:
That it's not correctly changing the current execution pointer, or
That it's allowing me to drag the thing at all.
Xcode changed from being able to drag the instruction pointer from the left, to a completely new visual item and moved it to the far right.
The hamburger icon (shown in the image below) is actually the drag handle for the current instruction pointer.
Can you change the current line of execution while debugging in Xcode?
YES, it can be changed.
It works, after you step over, but from next click.
See this example:
Assume the Green arrow is in "a"
>> NSLog(#"a");
NSLog(#"b");
NSLog(#"c");
NSLog(#"d");
NSLog(#"e");
NSLog(#"f");
It goes to some stack that will be printed when you "Step Over". Then it moves to "b".
as:
NSLog(#"a");
>> NSLog(#"b");
NSLog(#"c");
NSLog(#"d");
NSLog(#"e");
NSLog(#"f");
Then "b" goes into stack, and it will get printed. Now you change the >> to "e" by dragging, as:
NSLog(#"a");
NSLog(#"b");
NSLog(#"c");
NSLog(#"d");
>> NSLog(#"e");
NSLog(#"f");
Now "b" will get printed and the pointer will move to next statement i.e. "e".
If you again move it back or forward it will change its place but "e" will be printed, as it is already saved in some stack that is ready to print.
I am doing my first steps with GDB in TUI mode.
During the debug session I see that each line outputted to console occurs in a single line (in the picture you see 222222 highlighted in red). It is like having an output pane of one single line.
On top of that, each \n doesn't cleanup that line so all the strings do overwrite each other making my output very confusing.
Can you help me a bit with this issue or point me to some key command to look for in order to have a clean output?
I also highlighted another area (in the picture 1111111) because the first string is outputted there and then all other on the frame of the source code window.
You can always refresh tui screeen every time your program outputs something with Ctrl+L key binding. Or you can temporarily swith to normal mode, step and watch program output and switch back to tui mode (Ctrl+X A). See all key bindings here.