Logging objc_msgSend() on iPhone - iphone

I recently ran into a problem for which there were no working solutions on Google. I'd like to log an applications's Objective-C messages to the console or to a file. I didn't write the application so I don't have the source code to recompile with logging included. I have a jailbroken iPhone so no restrictions on how to realize this. I even considered doing this through a MobileSubstrate extension (may I hook objc_msgSend for that application to do some logging?), but had not very much ideas. Can you please help me out with this?

There is a logging mechanism for ObjC messages, but I'm not sure whether you'll get method names without symbol files. Assuming that your jailbroken phone will allow you to run any app under control of the debugger (gdb), you should be able to start the app, set a breakpoint early during the initialization, then do this:
(gdb) call (void)instrumentObjcMessageSends(YES)
The log file will be written to a text file in the tmp folder. More details here:
http://www.dribin.org/dave/blog/archives/2006/04/22/tracing_objc/

Related

How to view logs from iPhone?

I have place several NSLog() in my iOS application, is it possible to see all the logs later on my Mac that was generated when the app ran on iPhone handset even when iPhone was not connected with Mac.
Thanks
No. You can however redirect NSLog to a file, using something like this: http://blog.coriolis.ch/2009/01/09/redirect-nslog-to-a-file-on-the-iphone/
Then you can access the file via Xcode, or upload it with your app. File usage and privacy issues apply.
Keep in mind that NSLog is supposed to be turned off in published apps, so you may want to use a different logging app. A number of NSLog alternatives are available.
Unfortunately this is not possible.
The only thing that you can get is a Crash Log.
If you need a better logging system, I suggest to take a look to CocoaLumberjack, a very powerful logging framework that gives you the opportunity to save log in files and, eventually, send them to a server.
You also have many different levels like: log info, log error, log warning, etc...
You can view crash logs from your iPhone in the Organizer.
If you want to view your own log statements, you could consider TestFlight ( http://testflightapp.com ). They offer an SDK which includes features for remote logging.
I'm fairly certain that's not possible. The device needs to be connected to the Mac in order to run in Xcode's debug mode, and you need to be in debug mode to view the console, which contains your NSLogs.
There is a crash log for every crash that occurs on the phone, which is readable after connecting to your mac. These NSLog's don't appear in this log nor do they appear anywhere else in a (semi) permanent manner.
It's possible using custom macros and a custom class which will write each message in the documents directory in a file.
If the file sharing is enabled in the app you can later download them in iTunes.
Seeing the logs in mac might not be possible. But you can send the log to testflight using TFLog(). But you will need to distribute your app through testflightapp. And integrate the sdk. I think that is what you are looking for. try out - testflightapp.com

Is there a way to automatically include the console output with the crash log on ios

The crash log returned when your app has an error on iOS is wonderful however it would be 100 times better if it contained the console output from when your app started as part of the log. Is there a way to automatically have that information in the crash log, or have a semi-automatic system that testers could use when sending in crash logs?
I think you might want to take a look at http://apphance.com. It's exactly what you are looking for - including capability of sending problem reports from device by testers, including screenshots, you can track history of session including full console logs, you can even see crashes from out-of-memory problems which are otherwise difficult to get without physical access to the device. It's closed beta for now but soon it will be open for everyone. You can request access directly at the page.
Disclaimer: I am CTO of Polidea, company which is behind apphance and co-creator of the service.
#Medran i am not sure if this will help but if you can get the Brad Larsons videos on Advance iPhone App Development than there he says some thing about .dSYM file that will help you find the places where crash occurs. .dSYM file is made when you build your app using Xcode. See if you can find that file in your project folder its named something like this MYapp.app.dSYM

How to use the backgrounder SpringBoardHooks?

I would love to use these hooks for a jailbreak iPhone app. This would allow the app to request to be backgrounded, providing that Backgrounder is installed. Seeing previous questions on StackOverflow, I think I'm not the only one who could use this.
What are the steps required? Do I need to extract the private SpringBoard api's, or do I even need to follow procedures for compiling MobileSubstrate pluginss?
I would prefer creating a minimal header file that allows me to send this message to Backgrounder, but I have basically no idea how to go about this. Suggestions are very welcome!
Backgrounder uses MobileSubstrate to hook some functions on SprindBoard and UIApplication, the problem with iOS 4.2 (I don't have a 4.1 version to try it) is that you can ignore the applicationSuspend event but after 10 secs springboard will kill your application.
I've been looking for the same thing you're asking and until now I know:
- I can use MobileSubstrate to hook SpringBoard's functions like Backgrounder does
OR
- There must be a way to tell Springboard your app is like Safari or it's being debugged.
I just need to find that thing that makes MobileSafari different. But if you want try using MobileSubstrate, you can check backgrounder on github and:
http://modmyi.com/forums/iphone-ipod-touch-sdk-development-discussion/728944-tutorial-how-compile-mobile-substrate-extension-xcode.html

Does Apple ship debugging symbols for the iPhone Simulator APIs?

I am a bit of a iPhone/Mac OS newb.
When I look at a backtrace in the debugger and UIKit or other Apple Libraries are on the call stack I can't see their function arguments because of missing debug symbols.
Does Apple Ship debugging symbols for the iPhone Simulator libraries like UIKit?
Thanks.
No. The OS-level components do not ship with debug symbols, nor have those symbols available to you. On the Mac, the only case I can think of where a special debug version of a framework was made available was for Core Data, but that was more for logging of SQL and other database-related actions.
You can extract a little more information about what's going on in the Simulator using DTrace scripts and custom instruments, which can probe for even private methods and classes. For example, I created a couple of scripts and a custom instrument here that logs out every method that is called in the process of starting up an iPhone application in the Simulator. I describe how that works in this article on MacResearch.

XCode Test Automation For IPhone

I would like to have my iphone test app to be tested automatically in an IPhone. The following are the steps I would like to have:
compile, link and code sign the iphone app (Xcodebuild)
upload the newly built app to iphone
run the uploaded app in iphone automatically
collect the result from the gdb console
close the app
Right now, I have problem with step 2 and 3 where I cannot do it automatically (I can do it from XCode via "Build and Debug" button. This, however, will require manual clicking).
I did some research on automator and it does not answer my problem. Another option I am thinking about is to have the app compiled for iphone simulator and run it from there, but I am not sure how accurate the test result will be comparing to the real device.
I am new to Mac/IPhone development, perhaps someone has a better way of testing this. Any feedback and input are welcome. Thanks.
The comment section does not provide a good way of display the solution properly. Here is the summary of answer.
The task of building IPhone app, uploading and trigger the debug process on IPhone is done via AppleScript. Here is how the AppleScript looks like:
tell application "Xcode"
open "Users:chuan:Desktop:iphone_manual_client:iphone_manual_client.xcodeproj"
tell project "iphone_manual_client"
clean
build
(* for some reasons, debug will hang even the debug process has completed.
The try block is created to suppress the AppleEvent timeout error
*)
try
debug
end try
end tell
quit
end tell
AppleScript accepts ":" instead of "/" for file and folder separator.
The GDB console output can be captured by setting the GDB option to write it to file. this is done by typing the following command in Terminal:
defaults write com.apple.Xcode PBXGDBDebuggerLogToFile YES
defaults write com.apple.Xcode PBXGDBDebuggerLogFileName <path to my gdb output file>
Lastly, many thanks to various ppl who have helped to solve this problem.
The tool you probably want to use for the build and install is Applescript. Something like:
tell application "Xcode" to launch
I'm not pretending that this is a complete answer; there are still a lot of things to work out. But Applescript is going to be one of your key tools I believe.
Check out UISpec http://code.google.com/p/uispec/
It's a full automation test framework being developed for the iphone.
Check out iphone_testify, it works well with OCUnit and Google Toolbox For Mac, and I think it could be possible extend it for something like UISpec.
Regards
There's a command line tool "xcodebuild" you can call to kick off an XCode build without it being open. There are flags you can use to set targets and so on.
Dr Nic's testing with Ruby may help with some of this
Could you add a build phase to the target that runs a script to upload the binary to the iphone?
Right click the target, Add->New Build Phase->New Run Script Build Phase
xcodebuild will just build the binary and it will not upload the newly compiled binary to iphone.
actually it can upload (after signing it), but not run too bad...
maybe it can be run using gdb once connected to target but how (ip?, usb? usbnet?) ?