PDA

View Full Version : How to set DYLD_IMAGE_SUFFIX=_debug in Mac?



bibbinator
17th October 2009, 17:17
Hello,
The Qt doc (http://doc.trolltech.com/4.5/debug.html) says that to debug the Qt libraries I need to set DYLD_IMAGE_SUFFIX=_debug. The examples show I need to basically invoke gdb from the command line adding this environment variable in front of the invocation to get it to work.

Is there any way to do this so that I can debug from Creator without starting a terminal session of gdb?

I tried creating a gdb startup script and putting:

shell DYLD_IMAGE_SUFFIX=_debug

into it but this didn't work. Seems like this is a good candidate for a checkbox in the Creator debugger prefs? Or am I missing something here?

Thanks,
Brett

wysota
18th October 2009, 11:53
You can set the variable while invoking creator or you can make a bash script that you will set as debugger executable. In the script invoke gdb while setting the environment variable you need.

#!/bin/bash

DYLD_IMAGE_SUFFIX=_debug /usr/bin/gdb $@

bibbinator
18th October 2009, 15:21
Thanks for your reply.

If I make a bash script as you suggest, how do I set it as the debugger executable?

Thanks,
Brett

wysota
18th October 2009, 16:46
If I make a bash script as you suggest, how do I set it as the debugger executable?

What do you mean? There are settings in QtCreator for that...

bibbinator
18th October 2009, 17:03
I'm not sure which/where you mean though. Are you saying I change the field "Gdb location" in the debugging preferences that point to the script you mentioned? Or is there somewhere else to specify it?

Thanks

wysota
18th October 2009, 18:58
Yes, that's exactly what I mean.

bibbinator
19th October 2009, 03:23
Thanks again for your continued help wysota, I managed to get it working. Some step-by-step info in case other people end up here with the same question.

1. Create a script with the lines from wysota:

#!/bin/bash
DYLD_IMAGE_SUFFIX=_debug /usr/bin/gdb $@

2. Save the file. Can be named anything, but the Mac OS X convention seems to be using ".command" as the file extension to have it show up as a terminal script. So I called mine GdbWithQtDebug.command for example.

3. Open terminal and navigate to the same directory as the file. Type "ls" (without quotes) to see where you are now, and use "cd <directory name you want to switch>" (without quotes and <>) to move to a sub-directory.

4. Once you're in the right directory, type "chmod 755 <your script name>" (without quotes and <>) to make it executable. If you don't do this, you will get errors that it can't be run.

5. Launch QtCreator and open the preferences dialog. Expand the debugger section and click on the "Gdb" entry. In the right pane, where it says "Gdb location:" click the Choose... button and choose the script you just created. Click OK to save the changes.

6. Go to the Build menu and under Set Build Configuration you should choose Debug so that you can debug both your code and Qt.

7. Rebuild if needed and then debug.