Cocotron Source Level Debugging with Insight-GDB
By Dr. Rolf Jansen
1. Download MinGW, MSYS, Insight-GDB and 7zip
Download the MinGW installer from Sourceforge: MinGW-5.1.3.exe
Download the MSYS installer from Sourceforge: MSYS-1.0.10.exe
Download Insight-GDB from Sourceforge: insight-6.6-mingw.tar.bz2
Download the open source compression and decompression utility 7zip: 7z457.exe
If you want to use WinZip instead for decompression and unarchiving of Insight-GDB, then you need to pay attention to the special warning on the MinGW site: http://www.mingw.org/download.shtml#hdr5
2. Install 7zip using the downloaded installer 7z457.exe, then restart Windows, so that the 7zip context menu can be used.
3. Install MinGW using the installer MinGW-5.1.3.exe




You can take a coffee break now, while the MinGW installer is downloading and installing the basic components.
4. Install MSYS using the installer MSYS-1.0.10.exe
Then answer the post-installer questions in the console window. The answers are: "y", "y" and "c:/mingw".
5. Install Insight-GDB from the insight-6.6-mingw.tar.bz2 archive, using 7zip for decompression and unarchiving
- extract the .bz2 into the .tar archive using the 7zip contextual menu
- open the just extracted .tar archive using 7zip, for modification before extracting
- rename the directory inside the archive from "insight-mingw" to "mingw".

This is necesarray, because otherwise the contents would be extracted in separate directory and not into the mingw directory tree.
- extract the directory tree of the .tar-archive into the respective mingw directories. Push the blue "—"-Extract button and enter the target path in the upcoming dialog box. Important, the target path is "C:\" only:
Confirm that some files should be overwritten by the contents of the archive.
6. Cleaning-Up
- move the MSYS starter to a convenient location, where you can find it later
- move all archives and installers from the download location to the trash, since they are needed no longer
7. Preparation of your files for debugging
IMPORTANT: Compile and build Cocotron and then your Application with the Debug configuration. Make sure that for the following the "Debug" and not the "Release" flavours of your executable and the frameworks are used.
In order to source level debug your code and Cocotron, GDB at the Windows XP machine needs to have access to the respective source files, that were used to compile the code.
For this, the most easy approach is, to copy the whole project directory of your application and the whole source tree of cocotron into your MSYS home directory, which you will find at: "c:\msys\home\yourwinxpusername".
For example, my Windows XP user name is Rolf, and my application is named CVA, and I would copy the needed files by the way of a network share from my Mac to the Win XP machine. There might be other suitable ways, though.
8. Create a GDB command file
Since cocotron has a lot of sub-directories, we need to tell GDB, where to find everything. This is best done by the way of a command file. While there, it is also a good idea to specify the executable to be debugged. My GDB command file contains the following entries:
dir ~/cocotron/Foundation/CoreFoundation dir ~/cocotron/Foundation/NSArray dir ~/cocotron/Foundation/NSAttributedString dir ~/cocotron/Foundation/NSAutoreleasePool dir ~/cocotron/Foundation/NSCharacterSet dir ~/cocotron/Foundation/NSConnection dir ~/cocotron/Foundation/NSData dir ~/cocotron/Foundation/NSDate dir ~/cocotron/Foundation/NSDecimal dir ~/cocotron/Foundation/NSDictionary dir ~/cocotron/Foundation/NSException dir ~/cocotron/Foundation/NSHTTPCookie dir ~/cocotron/Foundation/NSIndexSet dir ~/cocotron/Foundation/NSKeyValueCoding dir ~/cocotron/Foundation/NSKeyedArchiving dir ~/cocotron/Foundation/NSLock dir ~/cocotron/Foundation/NSMetadata dir ~/cocotron/Foundation/NSNetService dir ~/cocotron/Foundation/NSNotification dir ~/cocotron/Foundation/NSNotificationCenter dir ~/cocotron/Foundation/NSNotificationQueue dir ~/cocotron/Foundation/NSNumber dir ~/cocotron/Foundation/NSObject dir ~/cocotron/Foundation/NSPortNameServer dir ~/cocotron/Foundation/NSPredicate dir ~/cocotron/Foundation/NSPropertyList dir ~/cocotron/Foundation/NSRunLoop dir ~/cocotron/Foundation/NSScanner dir ~/cocotron/Foundation/NSSet dir ~/cocotron/Foundation/NSStream dir ~/cocotron/Foundation/NSString dir ~/cocotron/Foundation/NSStringsFileFormat dir ~/cocotron/Foundation/NSThread dir ~/cocotron/Foundation/NSTimeZone dir ~/cocotron/Foundation/NSTimer dir ~/cocotron/Foundation/NSURL dir ~/cocotron/Foundation/NSUndoManager dir ~/cocotron/Foundation/NSUserDefaults dir ~/cocotron/Foundation/NSValue dir ~/cocotron/Foundation/NSValueTransformer dir ~/cocotron/Foundation/NSZone dir ~/cocotron/Foundation/objc dir ~/cocotron/Foundation/platform_win32 dir ~/cocotron/Foundation/xml dir ~/cocotron/AppKit/CoreGraphics.subproj dir ~/cocotron/AppKit/ImageIO dir ~/cocotron/AppKit/NSAnimation dir ~/cocotron/AppKit/NSColor.subproj dir ~/cocotron/AppKit/NSColorPanel.nib dir ~/cocotron/AppKit/NSColorPicker.subproj dir ~/cocotron/AppKit/NSController dir ~/cocotron/AppKit/NSDrawer.subproj dir ~/cocotron/AppKit/NSEvent.subproj dir ~/cocotron/AppKit/NSFontPanel.nib dir ~/cocotron/AppKit/NSInterfacePart dir ~/cocotron/AppKit/NSKeyBinding.subproj dir ~/cocotron/AppKit/NSKeyValueBinding dir ~/cocotron/AppKit/NSMenu.subproj dir ~/cocotron/AppKit/NSSegmentedControl dir ~/cocotron/AppKit/NSSystemInfoPanel dir ~/cocotron/AppKit/NSTextTable dir ~/cocotron/AppKit/NSTextView.subproj dir ~/cocotron/AppKit/NSToolbar.subproj dir ~/cocotron/AppKit/OpenGL.subproj dir ~/cocotron/AppKit/RTF.subproj dir ~/cocotron/AppKit/Win32.subproj dir ~/cocotron/AppKit/X11.subproj dir ~/cocotron/AppKit/nib.subproj dir ~/cocotron/objc dir ~/cocotron/Foundation dir ~/cocotron/AppKit dir ~/CVA file ~/CVA/build/Windows/Debug/CVA.app/Contents/Windows/CVA.exe
Copy these entries into a pure test file, and change CVA to the name of your application. Save the file as gdb-cmd.txt into your MSYS home directory.
9. Start MSYS using the MSYS starter at your desktop
At the command line, you might want to check that everything is there, so enter:
ls -R
Then start Insight-GDB with the following command:
insight gdbcmd.txt
Insight should start and display the file which contains the main() of your program.
At this stage, GDB loaded only the symbol table of your application. The symbol tables of the coocotron frameworks are loaded only, after the program has started. So set a breakpoint at line #12 by clicking at the dash in front of 12 and start the debugging session, by clicking on the blue runner icon.
Before continuing you program, you might want to use the function browser, which you would choose from the menu View, to set more breakpoints. NOTE: There seems to be a bug in Insight, so never press the "Select All" button with an empty Function Filter, since this will freeze Insight.
After you set the breakpoints to your debugging needs, press continue, or step in/out your application and cocotron.
