Sometimes when I press the "step into" button in the Xcode debugger, it instead steps over the method call.
This happens even though the method is a method I wrote, and the source code is in the same project.
Can anyone explain how to prevent this?
This may also happen when the method is being called on a nil object.
From Apple's developer docs:
A nil value is the safest way to initialize an object pointer if you don’t have another value to use, because it’s perfectly acceptable in Objective-C to send a message to nil. If you do send a message to nil, obviously nothing happens.
This is not necessarily so obvious if you've used pretty much any other language, because they largely don't include this "feature."
I have had issues with LLDB. Switching to GDB corrected this. Product->Edit Scheme->Run->Debugger.
You may need to Clean your targets in XCode. Under the Build menu try Cleaning All and see if that resolves your issue.
Related
It's been bothering me since Xcode 6, that whenever I set 'All Exceptions' without any other breakpoints, Xcode would stop at start when I init a UILabel view wrapper in RootVC.
If I try to remove the causing line, another "random" line would trigger it again. Thoughts on what caused the exception?
This breakpoint comes from an exception that was thrown by TFileDescriptorContext. All Exceptions halts also on C++ exceptions.
It gives you a good indication where the problem comes from. Take a look if all fonts that are listed in Info.plist are part of your application bundle.
"Normally" you are not interested in C++ exceptions when you are in Objective-C, so feel free to ignore them.
Edit: This problem has been discussed several times here on SO. Updating when I can find the posts again which might give you even a deeper insight.
Im using XCode 4 and seeing a problem with debugging that did not exist in 3.x.
I am putting a breakpoint at a line where I call an object method.
Product *p = [[Product alloc] init];
[p print]; <-- Put a breakpoint here
After control stops at that line, I try to step into the method (F7). But nothing happens. System just skips over the line and goes to the next line (same behavior as Step Over).
Step into works fine for plain C language projects. The problem is with Objective-C methods. How do I fix this problem? Thanks.
Not sure if this will help -- Go into system preferences, and under the Keyboard general settings ensure that the "Use all F1 F2 etc. as standard function keys" option is checked.
F7 started to work for me after I checked that.
Hope that helps...
Check that the instance is not nil before trying to step into it's instance method. As embarrassing as it may seem, we all do it occasionally.
Stepping into ObjC method calls is not always possible. The way it was explained to me, there are internal runtime data structures that must be in a consistent state in order to reliably step into an ObjC method. If those internals happen to be in an inconsistent state when the program stops at your breakpoint, stepping in in the debugger will fail, and it will step over the call instead. This was also true in Xcode 3, and really has little or nothing to do with Xcode, but is an ObjC runtime and debugger issue. I estimate anecdotally (working in Xcode full-time for 3+ years) that stepping into an ObjC method call fails ~5% of the time. I find that it happens most often when it will be the most inconvenient to me. :)
That said, if you're NEVER able to step into ANY ObjC method call, then there's likely another problem, as I've been able to step into ObjC method calls many times with Xcode 4, and don't see this problem any more or less often than I did with Xcode 3.
fn+f7 always works for me. Although step into in Obj-C is kinda weird from time to time. You'd better set more breakpoints if you know where the code is heading.
I don't know enough about OSX to understand why this is fubar but I just tried changing the default key bindings to f13-f17 for all the usual bindings of pause/continue, step into/out of etc. Works for me. Pretty sucky QA on the XCode4 team possibly?
Switching to the gdb debugger works for me. Go to Edit Schemes, the Info tab for the Run phase, change from LLDB to GDB.
It's still not perfect. In particular it seems you have to use "Step into instruction" (with the appropriate key, or holding ctrl while hitting the step button) a lot if nothing happens, and to see registers and so on you have to use the gdb command line within the Xcode windows.
Remove the particular file and add the file again. This fixes my problem.
I'm not sure if this is possible. Here is an example situation:
Something is printing to my console and I don't know where it is coming from in the code. I did a quick search using the Finder in Xcode on terms such as 'NSLog' and 'print'. Nothing relevant came up.
Is there any quick way that Xcode has of finding where the source of the output is coming from ?
Kind of like when you right click on a method and you have all the options of exploring different parts of the code associated with that method.
Also: are there other functions that print besides NSLog and print?
Thanks so much!
Try running in the debugger, with breakpoints set on printf, NSLog, etc. When you hit a breakpoint do a backtrace (bt) to see where it's being called from
There's a plugin LinkedLog for that. You replace all NSLogs with LLogs and then will be able to just tap on link in Xcode's console to get to the line caused it to appear.
Didn't try it myself, but definitely will.
I cannot open a new window in QT. I new in QT so I think I am missing something. I only write the code below and settings windows just shows itself and closes. I have commented out destructor but still problem persists.
SettingsWindow s;
s.show();
What do I do wrong ? By the way I cannot either debug it, debuger does not stop when it reaches to the first line for example.
Thanks
This can't possibly be the only code you wrote.
However, judging from your description the first thing that comes to mind is probably a missing call to QApplication::exec(). Somewhere in the code you haven't shown here there's an instance of QApplication, probably named app. After calling show on your window, make sure there's a call to exec.
Since you are using a non-pointer var, your window is destroy when it go our of scope (at the end of the function). If you use a pointer when exiting the function the memory is not deleted so you Windows will still be shown. But you will not be able to clean memory when closing the window if you can't anymore access to your pointer.
Maybe you need to create your window as member of the calling class in order to be able to destroy the window AND clean memory once you don't need anymore to display it (for example in the calling class destructor).
I'm trying to learn how to write a Firefox plugin.
I downloaded the npruntime example from Mozilla compiled it and ran it.
Getting properties from the plugin worked well but when I tried to
call a method, Firefox freezed.
I thought maybe something is wrong with the example, so I wrote my own basic scriptable plugin that has one property and one method which returns a string.
The property worked well, but calling the method caused Firefox to freeze, again.
Am I missing something?
I tried debugging the plugin and everything seems fine. All the right
functions are called and the value is returned properly.If I try to stop the process while Firefox hangs, I get stopped at a Windows DLL, not in my code and not in Firefox code.
If anyone can point me to the right direction...
Thanks.
I hope that you've got it solved. If this is not the case, I've just discovered that the example (I assume that was the damned "npruntime sample") was flawed.
In returning a string, the example used the function strdup to allocate a string passed with a NP_something method.
Fact is that NPAPI takes care of the allocated string from that point on and, when tries to destroy it, it cannot since strdup uses malloc and not NPN_MemAlloc.
The solution is to NEVER use malloc or new for objects that we pass to NPAPI functions.
In the npruntime sample the error is at line 452:
STRINGZ_TO_NPVARIANT(strdup("foo return val"), *result);
and line 466:
STRINGZ_TO_NPVARIANT(strdup("default method return val"), *result);
I've corrected it with this code:
char* src = "foo return val";
char* out = (char *)NPN_MemAlloc(strlen(src) + 1);
strcpy(out, src);
STRINGZ_TO_NPVARIANT(out, *result);
and it worked.
But one would think that such a flaw in a sample should be corrected by mozilla SDK maintainers.
I developed npruntime for every browser.
It worked well in every browser, but firefox got freezing only in Windows 7.
I solved the problem editing the firefox config "dom.ipc.plugins.enabled" to false.
I don't know it will work, but it deserves to try.