LLDB equivalent to GDB's "info malloc-history <address>" command? - ios

I am trying to resolve a "message sent to deallocated instance " error in iOS.

See the LLDB-GDB command map (http://lldb.llvm.org/lldb-gdb.html) - you have to import a script, and the command is named malloc_info now. Obviously, malloc stack logging still needs to be turned on in the scheme options.
(lldb) script import lldb.macosx.heap
(lldb) malloc_info --stack-history 0x10010d680
Unfortunately, it doesn't show dealloc's - didn't GDBs malloc-history show that as well?

Use instruments, you'll get the exact line -
(In XCode) Run it through "Product" -> "Profile".
This will start Instruments, there you should choose "Zombies" and reproduce the bug event.
You'l get a pop-up once a zombie is called, press the chevron to see the exact line.
Problem is usually a bad __bridge (optional bridges __brige_retained / __bridge_transfer / __bridge)

You used to be able to use the malloc_history command-line tool from a shell and give it the process ID and address of interest. It appears this command is no longer installed by the latest Xcode's command line tools. :-(

Related

How can I print variables when debugging an extension?

I'm connecting to my UNNotificationServiceExtension implementation by using Debug > Attach to Process by PID or Name (which took me forever to figure out), though when my breakpoints are hit and I try to po a variable, I get output like the following:
(lldb) po response // `response` is a `NSURLResponse`, so I would expect it to be available to the debugger by way of `Foundation`.
warning: Swift error in module
MyExtensionProxy(0x00000001000e8000).
Debug info from this module will be unavailable in the debugger.
warning: Swift error in module
MyExtension(0x0000000100118000).
Debug info from this module will be unavailable in the debugger.
error: in auto-import:
failed to get module 'MySharedFramework' from AST context
(lldb)
I can't find any information on how to resolve these framework runtime errors, so debugging is just about impossible. How can I make these modules available in the debugger and be able to po my objects?
Using Xcode 8.1
Was just going trough the same process myself. Gonna post this here for you and all the other searches. After eliminating all possibilities this small thing did the trick -
When you click "Debug > Attach to Process by PID or Name" you get this little popup window to insert your PID or Process Name. In this window there's a combo box titled "Toolchain". For me, it was set to "Xcode 8.1". Clicking this combo box opens more possibilities, among them was "Xcode 8.1 (Swift 2.3)". Picking this setting allowed me to see runtime variables in my Swift modules.

Xcode 7.0.1 (7A1001) debugger "Unable to read data"

I am learning the Swift programming language using Xcode 7.0.1. Now I have an error in my application which I try to debug, but the debugger is useless to me, because it cannot show the values of variables.
See the picture below:
I am 100% sure the button has a label.
I did not find the solution so far.
There is a lot of information that you can get from the LLDB. You need to have this open and it provides window that you can issues commands to as you are debugging to inspect variables. e.g the command p is print.
From your example this would then be
"p operation " and the variable "operation" will be printed.
I am grossly simplifying the LLDB btw
LLDB Apple docmentation
LLDB commands

Is there a Quicklook debug command in LLDB?

Let's say I have a UIImage that I'm setting for a UIButton. I want to look at it in Quicklook. But oh no:
There's no way for me to quick look debug what the image is.
But I could do something from LLDB to get the image, like [getAppButton imageForState:0] (well, I could if it wasn't for the undoManager bit but that's not neither here nor there), but is there a way to quicklook that?
I'm not sure when this was introduced, but in Xcode 6.3.2 you can right click on the left panel in the debug area and choose Add Expression.... This pops up a text field where you can put in any arbitrary LLDB expression. After entering it, you can invoke quick look on the expression just like any other local variable in that pane.
You can also reference variables defined in LLDB, for example if you were to type:
(lldb) e UIImage *$img = [button imageForState:0]
You can then reference that $img as the expression in the left pane.
I don't think it is possible. At least I could not find a suitable command in Apple's documentation.
The only way I can think of, is modifying your code to assign the image in a UIImage variable and quick look that...
In Xcode 5.1, you can now add a method:
- (id)debugQuickLookObject
to any object and the returned value will be used for QuickLook. So in your case, you could subclass your button, and return your image.
You can now do that using chisel's visualize lldb command. It's very straightforward to set up, and it's a debugger super-power that's particularly handy if you work with images a lot.
Once you've installed chisel, update your ~/.lldbinit file and restart XCode. Then create a new breakpoint and add an action that uses the command to inspect an UIImage1.
Under the hood, the new python based lldb command writes the image buffer into a timestamp-based PNG file under /tmp/xcode_debug_images and then call system command open to use the default app to open up the image.
Keep in mind that lldb holds a strong reference to the data. So during your debug session, your app might appear to leak RAM. Remember to turn the breakpoint off when you are done.
Also, if you have a lot of images, you may not want to open them up all in Preview, which will freeze itself with more than 100 images. Comment this line off, and you should be fine:
https://github.com/facebook/chisel/blob/main/commands/FBVisualizationCommands.py#L60
On my M1 mac, the file is installed into /usr/local/opt/chisel/libexec/commands/FBVisualizationCommands.py

cocos2d: my APP crashes but XCode doesn't give me any crash report

It used to work fine but now I get this message when loading a certain scene and then the APP crashes.
2012-12-01 18:33:55.104 AppName[9561:707] cocos2d: CCSpriteFrameCache: Trying to use file 'art1-hd.png' as texture
I have no idea on where to start debugging this. Is there a way to get a more precise error message to understand why this happens?
Btw, I have changed my code signing identity to developer and XCode doesn't yet give me any trace of it on the console other than the plain message above. I checked as well the device logs on the Xcode-Organizer section but no trace.
I whish there was something like in Java + Eclipse, where I could get a precise STACKTRACE of where the crash happened.
Any suggestion on how to get a precise stacktrace (E.g. with function name generating the crash)?
PS: I have set strip debug symbols to "NO" in DEBUG, and to "YES" in Release, but I am builing on my own test iPod and hence I think it is automatically build for "Debug" (the section says build for running and testing which is confusing as the project settings allows only debug and release). But I think the problem is not here.. but in the issues above before the PS:
EDIT: If I look into the debug navigator I don't see any stacktrace of methods, as I want, but just threads.. I need to figure out how to use the global exceptions.
I have no idea on where to start debugging this.
You have the cocos2d source code. I would start there.
Search for "trying to use file" in CCSpriteFrameCache to understand what the cause of this message is (which I agree is confusing, why shouldn't you use that file?).
As for the stack trace, it's available as soon as you add a global exception breakpoint. If the breakpoint triggers in OpenAL code make sure to set it to catch only Objective-C exceptions.

malloc_history cannot examine process xxxxxx because the process does not exist in iOS

I added the below environment variables to my Project and set their values to YES.
NSDebugEnabled
NSZombieEnabled
MallocStackLogging
MallocStackLoggingNoCompact
I followed the Procedures in http://www.cocoadev.com/index.pl?DebuggingAutorelease
I was able to find the Problem based on the Log generated. My doubt is when I tried to find the stack trace to find where the object was allocated, I got the below information:
malloc_history cannot examine process 6963 because the process does not exist.
Am I missing anything here?
Below is the Log Created:
UPDATE:
I found the below link to be a good source of information on this:
strange GDB error unable to trace
I am yet to test this.
I've found for myself, that malloc_history is unable to track memory log of the device while successfully tracking the simulators memory log. Try to simulate the problem on simulator and then use the malloc_history tool. (at least I've found it as the only way yet)
Synatax:
Shell malloc_history process_id memory_address
Keep the track of processid Use the one when application starts.

Resources