How to add a breakpoint to objc_exception_throw? - objective-c

this was the answer from the brad larson on this
SO question
If you add two breakpoints, you should be able to debug these exceptions. To do this, go to Run | Show | Breakpoints and create two global breakpoints (I do them globally because they are so useful in all my applications). The first should be named "objc_exception_throw" and its location should be "libobjc.A.dylib". The second should be "-[NSException raise]" and its location should be "CoreFoundation".
Now, if you start debugging your application with breakpoints enabled, it should break on the throw of these exceptions. You should then be able to see the chain of events that led to the exception within the debugger.
now in this answer i want to ask how do i add location mentioned???

I think Brad's answer is pretty clear; hopefully this can help if you're not finding it clear.
In Xcode, from the top menu click on Run > Show > Breakpoints. A new window pops up.
Select "global breakpoints" in the left hand menu. There should be a box on the right under the "Breakpoint" column with the text "Double-Click for symbol". Single-click in this box and type in "objc_exception_throw".
Then, single-click in the space next to "objc_exception_throw" under the "location" column. A box will appear for you to type in the location (in this case, "libobjc.A.dylib"). I've made a screenshot that will hopefully help:

In Xcode 4 this great breakpoint can be added via "+" button on Breakpoints section (⌘ + 6)

in Xcode 6 -- from top menu
Debug > Breakpoints > Create Exception Breakpoint

I would also like to recommend adding the +[NSException raise:format:arguments:] breakpoint and its location should be CoreFoundation.

Related

Add conditional breakpoint in Intellij without gutter

I prefer not to display gutter icons - they are to me simply distracting. However, I may need to do so (?) for Conditional Breakpoints ?
There does not seem to be any action available for Add Conditional Breakpoint .. The following reference - along with others viewed - only refer to right clicking on the red breakpoint gutter icon.. None mention a menu / keyboard action for same. Did I miss it?
https://www.eviltester.com/2016/08/convert-breakpoint-into-conditional.html
Update : Here are the options for breakpoint from Actions popup dialog - none speak to me as being related to `conditional breakpoint':
My version is Ultimate 2018.3
Hit CtrlshiftA (or ⌘shiftA on Mac) and type "breakpoint".
You'll find two actions named "Toggle line breakpoint" (allowing to add or remove a breakpoint), and "Edit breakpoint" (allowing to edit the breakpoint you added, to add a condition for example).
Note: The "Edit breakpoint" action only appears if there is a breakpoint to edit on that line.
CTRL+SHIFT+F8 opens a dialog where you can create new or edit existing breakpoints without touching the gutter.
See https://www.jetbrains.com/help/idea/using-breakpoints.html

Is it possible to navigate to "next issue" within a project?

Is there a command to navigate to a next problem in a whole project but in a file. It happens all the time that you have an error somewhere and you need to trace your project in a Project View to find it.
How cool would it be to navigate where you need just right away!
Update:
Not only compilation errors count, but also syntax.
You can use "Analyze"->"Inspect Code". It will shows all issues in the whole project.
CTRL + F9 (Make Project). This will also automatically scroll to your first error in the project. It will give you a list of your errors and you can then use CTRL + ALT + DOWN to go through the errors.
Also once you fix them, you can do the shortcut again as it might reveal more (compilation) issues that were hidden by the first ones.

Is there a way to set a breakpoint at the start of any NSLog statement?

Some part of a big code base is printing out weird NSLog statements, and I'm trying to detect where it's coming from. Is there a way to put 1 breakpoint at the start of every NSLog call so I can see where it's being called from, rather than manually have to put breakpoints on all places that call NSLog?
In Xcode 6:
Step 1:
On the Navigator on the left, go to Breakpoint Navigator (command ⌘ + 7):
Step 2:
Click the + button on the bottom left (Add a new breakpoint),
then choose Add Symbolic Breakpoint...:
Step 3:
In Symbol, type NSLog.
Alternatively, you can do the same thing in Debug → Breakpoints → Create Symbolic Breakpoint.
Fo Xcode 5, see this.
If you want to break on a certain log message you can use:
This example will break on every log containing the word "Warning".
Update:
On newer devices use $x0.
Simulator and older use $r0.
$arg0 should do for all cases.
In the breakpoint navigator (command+6) add (on the bottom, there is a Plus symbol) a symbolic breakpoint and use NSLog as symbol.
According to this you can set that kind of breakpoint by doing so in the lldb console:
breakpoint set --name NSLog
One way to do this using Xcode could be to put a breakpoint in the main function or on you AppDelegate applicationDidFinishLaunchin (read: as soon as possible).
Then, you run your app, and when it pauses on said breakpoint, you have access to the lldb console: you type the above line and hit return, and lldb prints something like this:
Breakpoint 3: where = Foundation`NSLog, address = 0x32a3da08
At this point, you resume your app, and it will pause again when NSLog is called (pay attention to the call stack using the Debug Navigator).

How do you watch or evaluate an expression in xcode like visual studio's immediate window?

In MS visual studio we just right click add watch.
How does one do this in Xcode?
Use the po command in the Debug area
Set up a breakpoint on the relevant area of code, then when the program stops at the breakpoint, enter commands in the Console in the Debug Area.
The relevant command is po (print object) followed by the expression you want to evaluate.
If the Debug window is not visible in XCode, you can show it via the top menu:
'View' -> 'Debug Area' -> 'Activate Console' (XCode v8.x)
Example
To evaluate an expression like var1/var2 where var1 and var2 are both doubles, enter the following in the Console:
po var1/var2
The Console will return something like:
(double) $2 = 3.085 [no Objective-C description available]
Showing object properties
You can also return a particular property of an object currently used in the code at that breakpoint:
po [bankInfo city]
And it will return something like:
(id) $4 = 0x000069e8 Testville
Note though that the Console doesn't seem to like the dot notation and prefers the square brackets when applicable. For example, this returns an error for me:
po bankInfo.city
I hope this is what you've been looking for.
Gabe's answer is almost there but missing one crucial detail: Select Debugger Output . By default the bottom option is set to Target Output, so the po command doesn't show you anything.
Here is a sandwich app from a tutorial I'm debugging:
Being an xcode newbie and coming from a MS Visual Studio Background, I wanted exactly what the OP was looking for. While playing around from reading Gabe's answer I selected Debugger Output and got what I wanted.
My seniors told to use NSLog(#variable)..........
Set some breakpoints in the begginning of the looping and functions. Once u click on the breakpoint(one similar to arrow) button in the editor window the "Build and debug tool" will get enabled. You can then go to the debugger by clicking the debugger icon. on the right of the debugger window variables will be visible select self->then the instance variable u r going to set watch point.Right click on that and select "watch variable".A trigger point will be set and you will be notified with the value of the variable when changed.
As fas as i understand you would like to see when a variable is changing. For this make a breakpoint and right click on it and choose Edit Breakpoint. A window will appear:
Make sure you choose the right action like Debugger Command or Log Message and check the tick down at the options Automatically continue after evaluating. So you get some kind of action (e.g. logging, sound, etc) and wont stop at the breakpoint.
If you want to know when the variable changes, use a "watch":
Set a breakpoint somewhere in the class in question;
Run the app in the debugger and let it stop at your breakpoint; and
Go to the "Variables" view in the left side of the bottom "Debug" panel and right click on the property in question and choose "Watch".
For example, here, I've stopped at a breakpoint in viewDidLoad, and added a "watch" for total:
(This is Swift, but the same is true for Objective-C, too.)
Now, if I "continue" execution (), Xcode will pause whenever this property changes and I can see at what line of code total is changing, the stack trace to get to that point, etc.

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.