DEV Community

Shaikhul Islam
Shaikhul Islam

Posted on

4 1

Spy PHP process with gdb + php5-dbg

In my previous post I briefly mentioned debugging a php process with gdb. In this post I am going to describe the steps and required tools to successfully get insights/stacktrace from a running PHP process.

First thing first, make sure you have install php5-dbg package. In this example I am using an Ubuntu box.

$ dpkg-query -l | grep php5-dbg

If not found install it first

$ sudo apt-get install php5-dbg

We also need a .gdbinit file. Get it from here according to php version.

Now it's time to start gdb with the php process.

$ sudo gdb -p PID

At the point gdb will pause the program, you need to type continue inside the gdb shell.

> cont

Wait for a while and then press Ctrl+C to get back to gdb shell.

Now source the .gdbinit, I put it into my home directory.

> source ~/.gdbinit

Type zbacktrace to see actual backtrace from the underlying php program.

> zbacktrace

After getting the stacktrace detach the program from gdb and then quit, if you dont detach the program, gdb will kill it when you quit gdb.

> detach
> q

You can check other commands available in the .gdbinit file.

This helped me today to get actual stacktrace of the php program instead of php interpreter calls that I got with bt command.

gdb is really an awesome sauce!

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay