# Debugging a PHP Extension via GDB

- Thread: https://externals.io/message/48051
- Original archive: https://news-web.php.net/php.internals/48051
- Started by sebastian@garbage-group.de on 2010-04-22T13:51:34+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #48051 — sebastian@garbage-group.de — 2010-04-22T13:51:34+00:00

URL: https://externals.io/message/48051#48051

Hello everybody,

[I hope this is the right list for this question, if not, it'd be great
if you could point me to the right direction].

I'm currently developing a PHP Extension which is built as dynamic
library, and not directly into PHP core. I'm trying to figure out how to
set break-points inside the extension with GDB, so debugging is easier.

So far, I started gdb with "gdb /my/path/to/php" (which has debug
symbols enabled); and then tried to set a breakpoint into my extension via:

break /path/to/php/extension/objectmonitor/objectmonitor.c:80

GDB then asks:

No source file named /path/to/php/extension/objectmonitor/objectmonitor.c.
Make breakpoint pending on future shared library load? (y or [n]) y

When I run php with a script via "run index.php", the system does not
stop at the set break-point.

Do you have any hints how to make this work? This really would help me
tremendously.

Regards,
Sebastian

---

## #48053 — Alexey Zakhlestin — 2010-04-22T14:16:38+00:00

URL: https://externals.io/message/48051#48053 · In reply to: #48051

> Hello everybody,
> 
> [I hope this is the right list for this question, if not, it'd be great
> if you could point me to the right direction].
> 
> I'm currently developing a PHP Extension which is built as dynamic
> library, and not directly into PHP core. I'm trying to figure out how to
> set break-points inside the extension with GDB, so debugging is easier.
> 
> So far, I started gdb with "gdb /my/path/to/php" (which has debug
> symbols enabled); and then tried to set a breakpoint into my extension via:
> 
> break /path/to/php/extension/objectmonitor/objectmonitor.c:80
> 
> GDB then asks:
> 
> No source file named /path/to/php/extension/objectmonitor/objectmonitor.c.
> Make breakpoint pending on future shared library load? (y or [n]) y
> 
> When I run php with a script via "run index.php", the system does not
> stop at the set break-point.
> 
> Do you have any hints how to make this work? This really would help me
> tremendously.

Do you use debug-build of PHP? There won't be symbols in "regular" build

---

## #48055 — Derick Rethans — 2010-04-22T14:24:56+00:00

URL: https://externals.io/message/48051#48055 · In reply to: #48051

> Hello everybody,
> 
> [I hope this is the right list for this question, if not, it'd be great
> if you could point me to the right direction].
> 
> I'm currently developing a PHP Extension which is built as dynamic
> library, and not directly into PHP core. I'm trying to figure out how to
> set break-points inside the extension with GDB, so debugging is easier.
> 
> So far, I started gdb with "gdb /my/path/to/php" (which has debug
> symbols enabled); and then tried to set a breakpoint into my extension via:
> 
> break /path/to/php/extension/objectmonitor/objectmonitor.c:80

Try just "break objectmonitor.c:80".

Derick

-- 
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug

---

## #48056 — sebastian@garbage-group.de — 2010-04-22T14:25:37+00:00

URL: https://externals.io/message/48051#48056

Hey,

thanks for your quick replies.

I'm definitely using a debug build, both PHP core and my extension.
Somehow I think I need to load the symbol table of the shared library
into GDB, but I don't know how to do this...

Regards,
Sebastian

---

## #48058 — mathieu.suen — 2010-04-22T15:25:28+00:00

URL: https://externals.io/message/48051#48058

One quick but ugly way is to add it in assembler in your C file:

__asm__("int3");

or something like this.


Sebastian Kurfürst wrote:
> Hi Derick,
>   
> > […]
> Thanks, just tried that, but same issue:
>
> (gdb) break objectmonitor.c:80
> No source file named objectmonitor.c.
> Make breakpoint pending on future shared library load? (y or [n]) y
> Breakpoint 1 (objectmonitor.c:80) pending.
> (gdb) run index.php
>
> -- and does not stop on breakpoint.
>
> Greets,
> Sebastian
>
>   


-- Mathieu Suen

---

## #48063 — Stanislav Malyshev — 2010-04-22T22:01:22+00:00

URL: https://externals.io/message/48051#48063 · In reply to: #48051

Hi!

> So far, I started gdb with "gdb /my/path/to/php" (which has debug
> symbols enabled); and then tried to set a breakpoint into my extension via:
>
> break /path/to/php/extension/objectmonitor/objectmonitor.c:80
>
> GDB then asks:
>
> No source file named /path/to/php/extension/objectmonitor/objectmonitor.c.
> Make breakpoint pending on future shared library load? (y or [n]) y

That's probably because the module is not loaded yet and for some reason 
gdb doesn't set the breakpoint correctly when it is (gdb is, 
unfortunately, very far from perfect when it comes to dealing with 
dynamic loading). What I would advise is to do this:

1. Set the breakpoint in compile_file() or execute(). If you need to 
catch earlier phases, you can try php_request_startup().
2. By that time .so should be in, so try setting the breakpont
3. Continue execution.

Alternatively, you could just set the breakpoint in php_dl(), step 
through it up to a point where your .so loads and add the breakpoint 
then. It's a bit tedious, but should work.
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com
