can not use gdb debug mac app - macos

I used homebrew installed gdb, and created code sign for it. It seems I have installed it completed. But when I use gdb command to debug the app in /Applicaions, it always prompted me no such file or directory, I have no idea about it. My system is 10.9.4, and GDB version is 7.7.1.
Wait for your help!

GDB does not automatically load application bundle directories. You need to give it the path to the main Mach-O executable. Something like /Applications/Reveal.app/Contents/MacOS/....
I don't know what the main executable for Reveal.app is named, but if it is named Reveal your command would look like this.
gdb /Applications/Reveal.app/Contents/MacOS/Reveal

Related

Mac .app Fails in a function call to 3rd party lib on Lion. But works when run from the .app/Contents/MacOs/executable

I am trying to run our App on Mac Lion. App is built on Snow Leopard 10.6.8, packaged using package maker. We are linking dynamically to libCurl(3rd party lib). On snow leopard it works. On Lion when I install and click the app icon it fails in call to curl_easy_perform (from libCurl). But when I right click the app icon, click show package contents, and goto /Applications/MyDir/OurApp.app/Contents/MacOS/OurApp and then try to run that unix executable, then it works. I used otool to check the lib paths and they all seem correct.
Can someone help me why it fails when I click the .app? I thought .app is a soft link to the main executable. so if the executable works, then .app should also work.
Do I have to tell the path of the lib in .app? if so, how?
The dynamic linker "dyld" and related programs such as "otool" are influenced by environment variables. Environment variables can vary by process: the Finder has a unique copy of environment variable settings, and so does each shell in a terminal window.
As you can see if you run "man dyld", there are many variables that can influence the behavior of these programs.
If you're seeing different behavior from the command line than in the Finder, I imagine that at least one of the special linker variables has been set in your terminal. It is probably instructing the linker to look in places for libraries that are different from the linker's defaults (or whatever the Finder uses).
You can run "env | sort" from your terminal to see what's been set.

How to debug native code using gdbserver

I have followed the instructions for debugging native code found here:
http://www.eweek.com/c/a/Linux-and-Open-Source/How-to-Set-Up-Android-Platform-Development-and-Debugging/
To do this, you have to launch gdbserver from an adb shell. I have copied gdbserver to the target filesystem, but can't make it executable (chmod gives permissions errors or 'bad mode' errors).
Do I need to root my device to start gdbserver? (How??)
Do I need to copy gdbserver manually?
Is there an easier way to do this? This is turning into a black hole of productivity. All I want to do is debug my jni code...
TIA for any help.
First of all, /sdcard is mounted with 'noexec' option. Thus, you cannot execute any executable file from /sdcard. You have to put gdbserver to an another file system, like /data/local/tmp.
Second, if you are developing it as an Android application, gdbserver requires proper permission to attach the target process for debug. There are two ways for that. Using run-as or getting root.
Please take a look at Running ndk-gdb with package not found error on motorola phone.

Debugging Thunderbird on Mac OS X with GDB

I tried today to find a bug in Thunderbird, or more specifically - the location where it crashes ( the Crash reporter jumps in ).
However when I try to run it in gdb, the program immediately exits with code 06.
And then the Crash reporter springs into action again.
This way, I can never get to the actual point where it dies.
Is there some option I have to pass to make it start successfully?
Thanks!
You need to set the DYLD_LIBRARY_PATH environment variable to tell the loader that this is where all the shared libraries are.
First go to the MacOS directory of you .app.
cd blah/dist/Daily.app/Contents/MacOS
And then set the DYLD_LIBRARY_PATH variable:
export DYLD_LIBRARY_PATH=`pwd`
And finally run the thunderbird executable.
gdb thunderbird
It should then run properly.
This is all mentioned in the Debugging Mozilla docs: Here.

Can I use my gdb to debug an XCode project

I have a XCode which builds and runs under XCode.
I would like to know if it is possible to debug it using a gdb I build under Mac OSX (gdb 7 to be specified). If yes, can you please tell me how can I do that?
Thank you.
gdb-7.0 reverse debugging currently can only work with two classes of targets:
1) a remote simulator/emulator/virtual-machine that supports going backwards, or
2) the built in "process record" target, which at present has only been ported to x86-linux, x86-64 linux, and moxie linux.
Well, now -- I take that back. I recently discovered that process record can work with any remote x86 target, so if you're connecting with your macintosh target via "target remote", you might just be able to do it!
There is an online tutorial for process record here:
http://www.sourceware.org/gdb/wiki/ProcessRecord/Tutorial
More info about process record here:
http://www.sourceware.org/gdb/wiki/ProcessRecord
And about gdb reverse debugging here:
http://www.sourceware.org/gdb/wiki/ReverseDebug
So you want to use your own version of gdb to debug your executable? Easy!
Open Terminal, and do something like this:
$ cd <directory where Xcode project lives>
$ cd build/Debug (for example - depends on project configuration)
$ /usr/local/bin/my-gdb ./MyExecutable
Of course, specifying the actual path to your custom gdb version.
XCode's debugger is gdb (likely with Apple-specific modifications.) When you debug an application you can get to the gdb command line by opening the Console from the Run menu.
What requirements are imposed on your application that would require you to debug with your own version of gdb?

Installing debug version of Qt on Mac OSX

I need to step through the Qt code to help solve a bug in my C++ application. I've downloaded qt-mac-opensource-src-4.5.2.tar from here and followed the install instructions that came with this:
unpacked the file to /tmp.
typed ./configure -debug.
typed make.
typed sudo make install.
edited the PATH environment variable as instructed.
set the DYLD_IMAGE_SUFFIX environment variable to _debug.
This installed Qt and my Qt application runs, but I still can't step into the Qt code.
I'm using Xcode 3.1.3 and tried changing the Executable Info to "use debug suffix when loading frameworks". This generated a lot of warnings like:
warning: Could not find object file "/private/tmp/qt-mac-opensource-src-4.5.2/src/corelib/.obj/debug-shared/qmalloc.o" - no debug information available for "global/qmalloc.cpp".
warning: Could not find object file "/private/tmp/qt-mac-opensource-src-4.5.2/src/corelib/.obj/debug-shared/qnumeric.o" - no debug information available for "global/qnumeric.cpp".
and also a lot of non-qt related warnings.
I'd shutdown the Macbook Pro overnight, which I can only assume clears the tmp directory as the unpacked file is no longer there.
I think I could fix it by rebuilding Qt without frameworks, but this is more of a work-around than a fix that will probably come back to bite me. I'm also a bit reluctant to do this, when each rebuild takes between 3 and 4 hours.
Alternatively, would downloading the binaries and debug libs work?
I'd be grateful for any suggestions on what I'm missing and how I address this.
Thanks.
With the help of Qt support, I've now resolved this.
There were a couple of issues:
The Qt debug "make install" doesn't currently generate dSYM files for the _debug stuff. They've raised a bug about this. To get round this:
4a. cd /usr/local/Trolltech/Qt-4.5.2/lib
4b. Type /usr/bin/dsymutil -o QtGui.framework/QtGui_debug.dSYM QtGui.framework/Versions/4/QtGui_debug
4c. Repeat for each Qt framework.
The tmp directory does indeed get wiped on each reboot. To get round this:
7- Copy the entire contents of /tmp/qt-mac-opensource-src-4.5.2 to a new directory ~/Qt .
I also added both the frameworks and source code to the Xcode project.
Have a look at this http://doc.trolltech.com/4.5/debug.html
There is a section especially for debugging under MacOSX and Xcode...
I guess you need to generate a makefile with debug option using qmake !
In OS X 10.6 and 10.6.1, setting DYLD_IMAGE_SUFFIX to _debug will cause problems. Hopefully this will be addressed by a future update of OS X 10.6.

Resources