Skip to content
Advertisement

How to set breakpoints in a php script using gdb

I am trying to debug a php scripts via console with GDB but I am not able to set breakpoints. This is what I’ve done. I’ve created a script with this content:

JavaScript

And this is my temptative to debug it

JavaScript

Now that I am inside gdb, I put a breakpoint in line 2.

JavaScript

But if I run CANCELLAMI script

JavaScript

the whole script is executed.

Advertisement

Answer

Short answer: If you want to debug PHP scripts use xdebug.


Currently, gdb can only really debug compiled languages. It has a lot of knowledge baked in about executable file formats, debug info formats, how to unwind stack frames, and low-level stuff like that. What it doesn’t have is a way to associate these things with higher-level constructs in interpreters.

Now, it is possible to debug scripts this way, if you know enough about the interpreter. You can step through the interpreter and understand what it is doing. I’ve done this before — it is doable but not exactly pleasant. It’s hard enough that it’s only really worth doing if you are trying to find a bug in the interpreter triggered by some particular script.

Occasionally the idea arises that gdb could debug scripts. This is a good idea, but it is a reasonably large amount of work. As far as I know, nobody is currently working on it.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement