Launching debugger on self on SIGSEGV

From: Gurjeet Singh <singh(dot)gurjeet(at)gmail(dot)com>
To: PGSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Launching debugger on self on SIGSEGV
Date: 2011-07-11 16:45:09
Message-ID: CABwTF4WeQctvrAqWLMWDXZYAjz_QAL04umgu1iZ8wAkuqBHJxw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

The attached patch registers a signal handler for SIGSEGV and launches
GDB in batch mode on its own pid so that the stack leading to the SEGV can
be dumped in the server logs. Also attached is an example of the stack
dumped by gdb in server log file (caused by a `kill -segv nnn` on the
backend).

Since this patch calls fork() inside a signal handler, I investigated a
bit and found that, per POSIX, fork() is asynch-signal-safe and hence it can
be called inside a handler.

This in itself might not be very useful because I haven't seen many
crash reports in the community, but it can be extended to dump stack on
Assert so that it helps developers and our beta testers. It can also be used
to dump stack of a process we are about to kill for deadlock reasons, and
before certain PANIC conditions too.

Right now it works only for gdb (setting the GUC to true actually check
for the presence of gdb), but it can be made generic, they way our
archive_command etc. work, so that we take a string and replace certain
parameters with binary path and pid so that any debugger can be used.

It also looks pretty easy to port it to Windows since all we really want
to do is create an external process with certain parameters, and
CreateProcess() is all we need. I haven't investigated seriously about that
but of there's interest in this patch then I can spend some time on that
too.

Regards,
--
Gurjeet Singh
EnterpriseDB Corporation
The Enterprise PostgreSQL Company

Attachment Content-Type Size
debugger_on_self.patch text/x-patch 3.4 KB
sample_gdb_log.log text/x-log 2.1 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2011-07-11 16:45:35 Re: reducing the overhead of frequent table locks, v4
Previous Message Tom Lane 2011-07-11 16:32:30 Re: Select For Update and Left Outer Join