How to debug objective-c program (pbcopy supplied by Apple) using gdb?

I need to debug an objective-c program. When setting a breakpoint on the main () function, I have:

Reading symbols from /usr/bin/pbcopy...done.
(gdb) break main
Function "main" not defined.

      

Calling "start" from response to the same error. I suspect the way of doing things is different from max os x?

What is the equivalent with the c object program?

By the way, how to split into exit () function?

Edit: I'm trying to hack the [NSApplication run] suggested by Lyndsey

(gdb) file pbcopy
Reading symbols for shared libraries ........ done
Reading symbols from /usr/bin/pbcopy...done.
(gdb) break -[NSApplication run]
Breakpoint 1 at 0x35a8356
(gdb) run
Starting program: /usr/bin/pbcopy 
Reading symbols for shared libraries +++++++.................................................................... done
Breakpoint 1 at 0x95a97356

helo
^C
Program received signal SIGINT, Interrupt.
0x9574eeda in read$UNIX2003 ()
(gdb) bt
#0  0x9574eeda in read$UNIX2003 ()
#1  0x94d4e5b6 in _NSReadFromFileDescriptor ()
#2  0x94d4e4b6 in -[NSConcreteFileHandle readDataOfLength:] ()
#3  0x94d7f2fa in -[NSConcreteFileHandle readDataToEndOfFile] ()
#4  0x00002a11 in ?? ()
#5  0x00002736 in ?? ()
(gdb) info breakpoints
Num Type           Disp Enb Address    What
1   breakpoint     keep y   0x95a97356 <-[NSApplication run]+6>
(gdb) 

      

It's rather strange how gdb finds the address of the symbol but doesn't break it ... By the way, it seems that GDB changed the address of the breakpoint after loading the dynamic library. But this does not bother me, since I believe that I need to move. When I see the stack, do I see a lot? which allow me to assume that the usual way of starting the application is not used here (big guess ...: /)

+1


a source to share


2 answers


pbcopy is a command line tool, not an application, so there is no reason why you would ever call it [NSApplication run]. The breakpoint decides because it is (for whatever reason) tied to the AppKit framework.

Since this is a chipped binary file, the breaks into C function names won't work very well. If you really want to get your bearings, your best bet is to dump the build and figure out where you want to break based on that.



If you explain what you are trying to accomplish in general, you can get more detailed guidance on how to proceed.

+3


a source


Is your Objective-C app built using the Cocoa Project Template? If so, which one? Many have a basic function.

Can you post your main function? In your main function, enter:

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


        #error Yes, I'm compiled!



    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

      

Now, build your application, did you receive an error message? If not, then for some reason your code with the main function doesn't actually compile. Make sure you have it.

Edit May 14, 2009 @ 5:22 EST : you can use b - [NSApplication run] to break when application starts.

+2


a source







All Articles