Xcode: finding a variable value while setting a breakpoint - iphone

I am a seasoned Visual Studio programmer, and when I set a breakpoint, I can open an intermediate window and type ?variableName to view the current value of the variable.
In Xcode however, I can't seem to find an equivalent. I can hover over the variable name when stepping through the code, but long strings are truncated in the view.
Is there an Xcode equivalent to the intermediate window of Visual Studio? If not, how can I set a breakpoint and watch the value (the full value in the case of longer strings)?
Many thanks,
Brett

Use the console window (under the Run menu - choose "Show console") and then it's a gdb debugger. Then you can issue:
po variableName
Another way is to hover over the variable, right-click (or [Ctrl]+[left-click]) and choose "Print Description". The output will be sent to the gdb console.

There is a debugger GUI you can open by clicking the little spray bottle next to the step commands (or through Run > Debugger). It has a GUI window with pretty much all the objects in the frame you're looking at and the current call stack.

Related

Breakpoints grouping and naming in eclipse and Visual Studio

I work with large project having different modules, subprojects. When I am working with one module I need to create set of debugpoints/breakpoints to debug that module.
When I have to work with other one, to debug it, I have to create another set of breakpoints and disable the ones created to debug the earlier module.
When I want to debug (dont conclude that I write buggy code...its just that....it just happens :p) third module, I have to create thrid set of debug points, disable the earlier two sets corresponding to earlier two modules.
Same with debugging fourth module.
Same with debugging fifth module.
Now I want to come back to debugging first module. I have breakpoints related to all modules in my breakpoint window. Say 5 breakpoints corresponding to each module. Total 5*5 = 25. Now I have to go through reading each breakpoint checking which belongs to the first one, enabling them and disabling others.
Am I missing something. Is some simpler/standard way to ease this already there in eclipse.
I feel there should be say "Save set of breakpoints" option which note all the breakpoints currently in the breakpoint window as belonging to same set and will then ask us to give name to that set, say in my case "Module 1".
Then another option "Create new breakpoint set", which will clear up breakpoint window without deleting already created named breakpoint sets
Then, ofcourse the option to "Load breakpoint set" which will simply show up the set we saved as, say in dropdownlist. We select the named breakpoint set and it will end up loading those set of breakpoints.
Q. Am I overthinking? Is similar stuff already there? Also willing to know if similar stuff is there in Visual Studio too
Use 'Breakpoint Working Sets' for this.
In the Breakpoints view (in the Debug perspective) click the small triangle at the top right of the view and select the 'Working Sets...' menu item. This will let you manage the breakpoint working sets.
More details in the Eclipse help

Using breakpoints in Xcode

I'm using the debugger to pause execution of my program at any time and view the state of the running code, so I set breakpoints before running my executable so that I can stop at known points and view the values of variables in my source code.
After I viewed my code, it comes to one new screen. Here I press "step over" button means it come to view the next line, if I press "Continue program execution" button means then it skipped the step by step execution and comes to execution part. Image shown below.
My doubt is, why the compiler come here after viewed my code? How to analyse this assembly language coding and what is the purpose of this code?
If you pause execution or a breakpoint is triggered, the debug area opens, displaying the values of variables and registers plus the debug console. You can use the buttons at the right end of the debug area toolbar to display both the variables and console panes or to hide either one.
The variables pane displays variables and registers. You specify which items to display using the pop-up menu in the top-left corner of the variables pane:
Auto displays only the variables you’re most likely to be interested
in, given the current context.
Local displays local variables.
All displays all variables and registers.
Use the search field to filter the items displayed in the variables pane.
The console pane displays program output and lets you enter commands to the debugger tool. You specify the type of output the console displays with the pop-up menu in the top-left corner of the console pane:
All Output displays target and debugger output.
Debugger Output displays debugger output only.
Target Output displays target output only.
Use these to understand what is happening at break points.
Maybe your code casted exception and goes back to [UIViewController loadViewIfRequired] method . This method is in the compiled program and it is binary now so you won't see the source code and the assembly language is presented instead.
It is possible that [UIViewController loadViewIfRequired] has exception handling code.

Allegro question, how can I get rid of the cmd window?

I've made a small game in Allegro, but every time I run the .exe file it opens both the allegro window for the graphics but also a command line window even though I don't have anything that prints to it.
It's kind ugly to have the cmd window next to the game window, so I wonder is there any way to not show it?
This really isn't specific to Allegro. The behavior is dependent on your compiler's linker settings.
Under gcc it is:
-Wl,--subsystem,windows
For MSVC:
/SUBSYSTEM:WINDOWS
If you use an IDE, look somewhere under the linker settings. It may also be referred to as something like "console" vs "windows (or GUI) application." You'll want the latter.
Here is a specific solution for C++ in Visual Studio Community 2022.
Right click on the project with you entry point and select "Properties". Under "Linker" and "System", change the row named "SubSystem" into "Windows (/SUBSYSTEM:WINDOWS)"
Source: https://www.allegro.cc/forums/thread/607888

XCode/GDB stops on my auto-continue breakpoints when debugging on Device

I just discovered (thanks to another very helpful post) that I can use GDB commands to create breakpoints that log information to the GDB console, whether debugging on the device or simulator. This is like NSLog, but much nicer in that you don't have to wait for the console to catch up, you don't have annoying timestamps, and you can turn them on/off at run time via the XCode breakpoint view).
Very nice, and I invested time figuring out how best to log messages and variables together. (Use the GDB command po [NSString stringWithFormat: #"Your message: %d %#",variable,[[object expression] description]]) for maximum versatility.
Everything worked wonderfully in the simulator. When I finally got around to device debugging, I was getting the messages just fine, but GDB was STOPPING on every breakpoint despite the fact that I configured them to auto-continue by checking the box in the breakpoint view.
I tried adding a "continue" commmand to each breakpoint, and it worked but GDB also started spewing information about every breakpoint hit and telling me "Continuing" after every line.
My questions:
Does this happen for you?
Can I change something so that auto-continue also works on the device
Can I tell GDB to be less verbose and only give me the output I print?
Please help!!
David
I've run into the same behavior. It turned out that XCode had duplicated the breakpoint at the intended line. Perhaps there's a bug where a left click occasionally adds a hidden breakpoint rather than disabling?
The solution was this:
Select the "Breakpoint Navigator" tab of the Navigator frame on the left
Look for duplicate breakpoints either manually or by entering the class name in the search box at the bottom of the Navigator. (remember that multiple project sections of the list may both contain a breakpoint for the same class)
Right-click on one and select Edit to figure out if it's the continue or not.
Right-click on the unwanted breakpoint and delete
David,
There are some useful console commands that you might want to familiarize yourself with.
info b (lists all breakpoints)
ena (enables all breakpoints)
dis (disables all breakpoints)
ena X (enable breakpoint number X)
dis X (disable breakpoint number X)
GDB also supports conditional breakpoints:
cond X [condition]
And, commands to execute automatically when a breakpoint is hit:
command X
Aaron
Another very useful option is a watchpoint - break only when given expression changes.

Tracking variable or memory change in Xcode?

Is there any way to track variable changes or memory changes in Xcode? I'm looking for functionality like Visual Studio's data breakpoint.
I want to know where my object's view frame is being changed. I want to set a breakpoint at a member variable and run it. Then I could determine where it's changed.
Xcode uses gdb (or lldb, but that's another story) to implement its debugging functionality. gdb has the ability to set hardware watchpoints and hence so does Xcode.
This is a useful page for generic debugging of memory errors. Xcode's debugging console window is really just a gdb shell, you can type in commands as you please. The ever-helpful Quinn Taylor explains how to do so in this related post.
If you'd rather avoid interacting with gdb directly, you can right-click a variable in Xcode's debugging window and select "Watch Variable". Xcode will then alert you whenever your variable's value has been changed.
You can use hardware watchpoints.
You have to get the address of the variable you want to track (type p &my_var in gdb prompt).
It will print somehting like 0x12345678.
With gdb: type watch *(int *)0x12345678.
With lldb: watch set expression (int *)0x12345678 (or w s e (int *)0x12345678)
This assumes your variable is an int. It will create an hardware watchpoint on this address.
Hope this helps.
Yes.
Under the Run menu there is "Debugger" which provides a visual frontend to gdb.
Also, there is a breakpoint button next to the Build and Run button. You can click that and manage your breakpoints under Run > Manage Breakpoints.
I know this post is old but in case you are still wondering I posted a detailed answer here: In XCode 6 how can you set a watchpoint without stopping execution?