[PATCH] Add Windows support for backtrace_functions (MSVC only)

From: Bryan Green <dbryan(dot)green(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: [PATCH] Add Windows support for backtrace_functions (MSVC only)
Date: 2025-10-09 15:49:48
Message-ID: a692c0fe-caca-4c08-9c5d-debfd0ef2504@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I've implemented Windows support for the backtrace_functions configuration
parameter using the DbgHelp API. This brings Windows debugging capabilities
closer to parity with Unix/Linux platforms.

Currently, backtrace_functions only works on Unix-like systems. This patch
adds equivalent functionality for Windows MSVC builds using:
- CaptureStackBackTrace() for capturing the call stack
- SymFromAddrW() and SymGetLineFromAddrW64() for symbol resolution
- UTF-8 conversion to handle international file paths correctly

When PDB symbol files are available, backtraces show function names,
offsets,
file paths, and line numbers. Without PDB files, raw memory addresses
are shown.

Testing performed:
- MSVC build with PDB files: Backtraces include function names, offsets,
  source files, and line numbers
- MSVC build without PDB files: Backtraces show memory addresses only
- Verified backtraces appear in server logs when backtrace_functions is set
- Confirmed no crashes or memory leaks
- Passed all tests with Cirrus CI for all defined platforms.

The implementation is MSVC-specific. MinGW builds will use the existing
fallback message ("backtrace generation is not supported by this
installation").

The patch is attached. I'm happy to make revisions based on feedback.

Best regards,
Bryan Green

Attachment Content-Type Size
windows-backtrace-v1.patch text/plain 7.2 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Burd 2025-10-09 15:50:38 Re: Fix for compiler warning triggered in WinGetFuncArgInPartition()
Previous Message Andres Freund 2025-10-09 15:49:31 Re: compiling pg_bsd_indent