View variable data while debugging in Objective-C - objective-c

I come from a .Net world so I'm used to just hovering over a variable while debugging and seeing what its value is.
In Objective-C I am incredibly confused on how to do that.
If I hover over it, I get a small popup with lots of information...that doesn't help me at all.
For example, I have an object called "myServer" and it is an instance of a "Server" that I have created through CoreData. One of its properties is "root" which is a simple NSString.
I cannot for the LIFE of me figure out how to view what the value of [myServer root] is.
Can some please give me some advice on this?

In the gdb console, type
po [myServer root]

I like to use GDB from the command line. Open a terminal and type
gdb
attach <your process name>
(be sure your program was built with debugging symbols). Then, when your variable name is in scope (e.g. when you break somewhere relevant) type
po variableName
to view its contents.

Another nice way to deal with this is to log directly from a breakpoint.
To do this, create a breakpoint after the value you want to see has been set, then edit it. Add a breakpoint action of 'log', and put the expression you want logged within a pair of # symbols. Check the box to the right, ensuring that the breakpoint doesn't actually cause a stop. The value will be output to the debugger console on doing a run & debug.
Doing it this way you (a) don't clutter your source, (b) can dis/enable the breakpoint at will according to your immediate needs, and (c) don't need to stop execution.
This and other very handy xcode tips can be culled from Joar Wingfors' 'Debugging with Xcode' talk.

Related

IntelliJ: breakpoint everytime an object appears in breakpoint

I've noticed an unexpected behavior in an object used in this really complicate framework.
What I want is that the debugger stops (like with breakpoints) every time that the object appears in an instruction, without manually add breakpoints in all the instruction where it is used/appears.
Can I do something like this in IntelliJ?
Field Breakpoint is what you are looking for.
Read breakpoint type overview to get an overview of the different breakpoint types.
Furthermore, it is possible to put a condition on a breakpoint - read configure breakpoints.

Modifying window style by editing binary?

CyLog’s WildRename is a good program for performing batch-renames on files. The problem with it is that while the main window is resizable, it does not have the maximize box which makes it a little frustrating to size and use. Moreover, they have not made any updates in a long time, so the program is essentially discontinued.
I ran WildRename and used WinSpy++ to modify the style of its window to manually include the WS_MINIMIZEBOX style and bam!, it was now functioning as expected.
The question now is how to make this permanent.
My first instinct was to fire up ResHacker, but the problem is that the style that needs to be modified is that of the main window of a non-dialog application, so ResHacker has no way of doing this.
The next thing I tried was to open it in a hex-editor, to find the address(es) of the string corresponding to the titlebar. I then opened the file in W32Dasm and located the address of the code that references the address of the titlebar string. I did all this in an attempt to find the location of where the main dialog is created so that I can modify the style passed to CreateWindow(). Unfortunately, I cannot find a call to CreateWindow anywhere near the reference to the titelbar string and none of the calls to CreateWindowEx that I can find seem to be (obviously) the ones used to create the main window.
Is there an easy/automated way of modifying the style of the main window (assuming a non-dialog application)?
You could use a debugger like OllyDBG to dump the exe memory after the edit with WinSpy++, then use that exe or compare the files to see where the change is if you want to see what you've missed
There has to be a call to CreateWindow/Ex(), especially if it not a dialog from a resource. You just need to look harder. I would use IDA instead of WinDasm. It will decompile the assembly into more understandable code, and it has a built-in debugger. You can put a breakpoint on the title string and see in real-time which code actually touches it, and then follow it back to the accessing code.

vb.net Add Watch stop when value changes

I know in the older versions of Visual Studio, there was an "Add Watch" option where you can choose to stop execution when the value of the field changed. I am using VS 2010, and I can't figure out how to hit the breakpoint when the value of the field changes.
Any ideas?
Data breakpoints is what I remember, your description matches. It used a processor feature, it requires the address of the variable and the size, the processor automatically generates a trap when it detects a write to the memory address. Very nice debugging tool.
Sadly no longer available in managed code, the garbage collector messes it up because it moves objects around while compacting the heap. Which changes their address. The interface between the garbage collector and the debugger isn't strong enough to allow the debugger to track these moves while the compacting is taking place at runtime. No doubt to avoid a serious amount of overhead.
The next best thing you got is a property setter. You can set a breakpoint on it.
Right click on the breakpoint and hit Condition. You should be able to do the same from here.
In vb.net 2010 (I am using the express edition) - set a breakpoint and run up to it. Right click the variable/control name you wish to watch then select add watch from the context menu.
The watch window will appear.
You can type variable names directly in to the watch window, providing they are in scope.
You can right click on a break point and then choose Condition. In the condition box type the name of the variable and select the 'Has Changed' radio button.

Watching variables in Xcode

I'm trying to watch a variable with Xcode. I'm following the instructions in here by pausing at a breakpoint, selecting Run > Variables View > .... but with the exception of "Enable Data Formatters" the rest of the options are all greyed out. Any ideas?
I'm using Xcode version 3.1.3.
I haven't gotten watchpoints created from the Run menu to work for me either, unfortunately. One thing to be aware of is that when a variable goes out of scope, the watchpoint may become invalid.
If you don't mind getting a little more in-depth, you can use some low-level gdb commands to set a watchpoint for the address of the memory itself. For example, in the guide you linked to, they show how to watch the variable path which is a pointer with the value 0xbfffeb70. To manually set a watchpoint for that address, click in the debugger console (where the debugging output is printed) after the "(gdb)" prompt and type something like this:
watch *((int*)0xbfffeb70)
The cryptic syntax is necessary because gdb expects inputs as C expressions. For a little more detail, visit this link and jump to the section titled "Using hardware watchpoints". (I'm testing on an Intel machine, not sure how PowerPC handles it.) When you set watchpoints this way, Xcode will alert you with a drop-down sheet when a watchpoint is reached and tell you how the value was changed, and gdb will print the same info in the console.
I just ran into this problem. Here is a solution: right click on the variable name and select "View variable in window" from the menu which appears. It should be near the bottom.
Add a breakpoint. Right click in the watch list of the debug area and choose "Add expression..."
If you are getting a different menu, you have to click off of the currently highlighted variable so that nothing is highlighted when you right click.
The Answers given here only work if you use the gdb compiler. For those of you who are looking for an option to set a watchpoint with the lldb compiler I have bad news:
It's not working jet (XCode 4.3.2 with lldb 3.1) even though the lldb docs say you can.
Check out this Email. The lldb commands compared to the gdbs can be found here
I was trying to figure this out in XCode 5. I finally found a "Variables view" button at the bottom right of the output console. It's the little rectangle that will be gray on the left, white on the right if it's not enabled. I'm not sure if this is in XCode 3, but I expect most people have upgraded anyway.

Watching variables in SSIS during debug

I have a project in SSIS and I've added an Execute SQL Task which sends its result out to a variable. I wanted to confirm the value because I was worried that it would try to write it out as a resultset object rather than an actual integer (in this case I'm returning a COUNT).
My first thought was just to run it in debug mode and add the global variable to my Watch window. Unfortunately, when I right-click on the Watch window, the option to "Add Variable" is greyed out. What am I missing here?
I've gotten around confirming that my variable is set correctly, so I'm not interested in methods like putting a script in to do a MsgBox with the value or anything like that. For future reference I'd like to be able to watch variables in debug mode. If there are some kind of constraints on that then I'd like to know the what and why of it all if anyone knows.
The help is woefully inadequate on this one and every "tutorial" that I can find just says, "Add the variable to the Watch window and debug" as though there should never be a problem doing that.
Thanks for any insight!
I believe you can only add variables to the Watch window while the debugger is stopped on a breakpoint. If you set a breakpoint on a step, you should be able to enter variables into the Watch window when the breakpoint is hit. You can select the first empty row in the Watch window and enter the variable name (you may or may not get some Intellisense there, I can't remember how well that works.)
Drag the variable from Variables pane to Watch pane and voila!
I know this is very old and possibly talking about an older version of Visual studio and so this might not have been an option before but anyway, my way would be when at a breakpoint use the locals window to see all current variable values ( Debug >> Windows >> Locals )
Visual Studio 2013: Yes to both adding to the watch windows during debugging and dragging variables or typing them in without "user::". But before any of that would work I also needed to go to Tools > Options, then Debugging > General and had to scroll right down to the bottom of the right hand pane to be able to tick "Use Managed Compatibility Mode". Then I had to stop and restart debugging. Finally the above advice worked. Many thanks to the above and to this article: Visual Studio 2015 Debugging: Can't expand local variables?