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!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more