HCM

Happy Coding Monkey

GDB made easy

2022-06-14


gdbgui

Pros:

Cons

install

pip install gdbgui
pip install werkzeug==2.0.0

run

gdbgui -r --host 0.0.0.0 -g "sudo gdb -p $(pgrep mysqld-debug) -x ./gdb.init"

open

http://host_ip:5000/

GDB dashboard

Pros:

Just a gdb init file with Python script. Remember append config file in /root/.gdbinit if we use gdb to attach a process.

VSCode + GDB

Pros:

Cons:

Install

need install an extension first https://marketplace.visualstudio.com/items?itemName=rioj7.command-variable

Attach script(launch.json):

{
"version": "0.2.0",
"configurations": [
    {
        "name": "gdb - Attach to process",
        "type": "cppdbg",
        "request": "attach",
        "MIMode": "gdb",
        "program": "/home/poweruser/code/mysql-57-bld/sql/mysqld",
        "processId": "${input:readPID}",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true,
                "set follow-fork-mode": "child"
            }
        ],
    }
],
"inputs": [
    {
      "id": "readPID",
      "type": "command",
      "command": "extension.commandvariable.file.content",
      "args": {
        "fileName": "/home/poweruser/sandboxes/dev_5_7_37/data/mysql_sandbox5737.pid"
      }
    }
]
}

other options:

1. "procreessId": "${command:pickProcess}",
2. "preLaunchTask": "writePID", # need to define pre-launch task in task.json

References