]> git.ipfire.org Git - thirdparty/haproxy.git/commit
DEV: gdb: add a utility to find the post-mortem address from a core
authorWilly Tarreau <w@1wt.eu>
Sat, 14 Feb 2026 09:41:44 +0000 (10:41 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 14 Feb 2026 13:46:33 +0000 (14:46 +0100)
commit5689605c8e70f77aac71aa234d17565bb972643e
tree442f14d8cc91bdd17aeac7c79670843397796282
parentd71e2e73eacfaaa41e2b7b098c63f9ef3568ec35
DEV: gdb: add a utility to find the post-mortem address from a core

More and more often, core dumps retrieved on systems that build with
-fPIE by default are becoming unexploitable. Even functions and global
symbols get relocated and gdb cannot figure their final position.
Ironically the post_mortem struct lying in its own section that was
meant to ease its finding is not exempt from this problem.

The only remaining way is to inspect the core to search for the
post-mortem magic, figure its offset from the file and look up the
corresponding virtual address with objdump. This is quite a hassle.

This patch implements a simple utility that opens a 64-bit core dump,
scans the program headers looking for a data segment which contains
the post-mortem magic, and prints it on stdout. It also places the
"pm_init" command alone on its own line to ease copy-pasting into the
gdb console. With this, at least the other commands in this directory
work again and allow to inspect the program's state. E.g:

  $ ./getpm core.57612
  Found post-mortem magic in segment 5:
    Core File Offset: 0xfc600 (0xd5000 + 0x27600)
    Runtime VAddr:    0x5613e52b6600 (0x5613e528f000 + 0x27600)
    Segment Size:     0x28000

  In gdb, copy-paste this line:

     pm_init 0x5613e52b6600

It's worth noting that the program has so few dependencies that it even
builds with nolibc, allowing to upload a static executable into containers
being debugged and lacking development tools and compilers. The build
procedure is indicated inthe source code.
Makefile
dev/gdb/pm-from-core.c [new file with mode: 0644]