Debugging dynamic library with Xcode

I want to set breakpoints and debug a dynamic library.

It was a normal Makefile project, which I converted to XCode BSD Dynamic Library. Now it builds succesfully (I still have to copy the resulting .dylib to /usr/lib manually, any ideas how to automate this?)

However, I cannot figure out how to debug this library. Currently I'm doing following:
- Start the client program from command line, and figure out its process id
- Go to Xcode, and click Attach to process ID
- Then I I try to set breakpoints to the dynamic library code

However, the breakpoints don't activate.

Any ideas how to proceed?

Posted on Dec 24, 2009 8:51 AM

Reply
3 replies

Dec 25, 2009 2:03 AM in response to ericmeyers

Yes, I build it using Debug.

Ok let me give full description of my setup.


python_script (my_script.py)

python_runtime (/usr/bin/python)

python_bindings (py_library.so)

libraryunderdebug (library.dylib)

The python runtime loads python_bindings dynamically (using normal python dynamic runtime methods, maybe it is dlopen, I'm not sure). The python_bindings are linked directly against library underdebug.

When I am attaching to the process, it is already using code in the library I want to debug (library.dylib).

When I'm attaching to process, is it even possible to debug libraries with Xcode?

Or is the only choice to have a "main project", run it, and then debug the loaded libraries? This of course works.

Dec 25, 2009 8:57 AM in response to ssalminen

ssalminen wrote:

python_bindings (py_library.so)


Well that's strange. I'm not familiar with py_library.so. Did you write this? What causes it to be loaded? ctypes or is it just a regular Python extension? Are you sure py_library.so got loaded? Xcode or Activity Monitor can show you all the loaded libraries for a process.

libraryunderdebug (library.dylib)

The python runtime loads python_bindings dynamically (using normal python dynamic runtime methods, maybe it is dlopen, I'm not sure). The python_bindings are linked directly against library underdebug.


Ah, so you must have built py_library.so in order to link directly against library.dylib.

When I am attaching to the process, it is already using code in the library I want to debug (library.dylib).

When I'm attaching to process, is it even possible to debug libraries with Xcode?


Yes.

Or is the only choice to have a "main project", run it, and then debug the loaded libraries? This of course works.


No. You can debug any library that's part of the process. But The library has to have been "loaded" first.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Debugging dynamic library with Xcode

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.