NEXTSTEP

Title: Debugging code loaded by NSBundle 

Entry Number: 
Last Updated: Dec 06 1994
Document Revision:

Keywords: gdb, debug, NSBundle, NXBundle, stripAfterLoading:

Question

Q: I changed my code to use NSBundle instead of NXBundle, and when I try to set breakpoints in the code that was loaded in bundle, gdb can't find the source files.  What's the problem?

Q:  I am trying to send messages to my adaptor from gdb while debugging my EOF application but gdb tells me that the adaptor objects do not respond to any selectors.  What's the problem? 

Answer

A:  The NSBundle class has a class method called stripAfterLoading: that allows you to control whether or not symbols are stripped from bundles then they are loaded.  The default is YES, to strip symbols after loading the bundle.  Since EOF adaptors are bundles, they are affected by this flag.

Since NXBundle has no similar setting, merely switching from NXBundle to NSBundle will cause the symbols to be stripped out of your bundles when they are loaded unless you send call this method like this:

	[NSBundle stripAfterLoading:NO];

Note that the reason that the symbols are stripped is so that unnecessary information is not loaded with the bundle, so you should probably only do this when debugging an application.  You can accomplish this by surrounding the code with an #ifdef, like this:

	#ifdef DEBUG
	    [NSBundle stripAfterLoading:NO];
	#endif

Note that you need to call this before you load any bundles.  One way of ensuring this is to add it to your *_main.m file.  However if you do this, make sure you turn OFF the "Generate Main File on Save" option in ProjectBuilder's Attributes panel or your modified main file will be overwritten when you save the project.  Here is an example of a main file that does this:

	#import <appkit/appkit.h>

	void main(int argc, char *argv[]) {

	#ifdef DEBUG
	    [NSBundle stripAfterLoading:NO];
	#endif
	    [Application new];
	   if ([NXApp loadNibSection:"Detail.nib" owner:NXApp withNames:NO])
		    [NXApp run];
	    
	    [NXApp free];
	    exit(0);
	}
  
Valid for: EOF 1.0, NEXTSTEP 3.2 Developer