mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
Add backtrace support for error reporting
Add some support for automatically showing backtraces in certain error situations in the server. Backtraces are shown on assertion failure; also, a new setting backtrace_functions can be set to a list of C function names, and all ereport()s and elog()s from the mentioned functions will have backtraces generated. Finally, the function errbacktrace() can be manually added to an ereport() call to generate a backtrace for that call. Authors: Peter Eisentraut, Álvaro Herrera Discussion: https://postgr.es/m//5f48cb47-bf1e-05b6-7aae-3bf2cd01586d@2ndquadrant.com Discussion: https://postgr.es/m/CAMsr+YGL+yfWE=JvbUbnpWtrRZNey7hJ07+zT4bYJdVp4Szdrg@mail.gmail.com
This commit is contained in:
@@ -18,6 +18,9 @@
|
||||
#include "postgres.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_EXECINFO_H
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ExceptionalCondition - Handles the failure of an Assert()
|
||||
@@ -42,6 +45,16 @@ ExceptionalCondition(const char *conditionName,
|
||||
/* Usually this shouldn't be needed, but make sure the msg went out */
|
||||
fflush(stderr);
|
||||
|
||||
#ifdef HAVE_BACKTRACE_SYMBOLS
|
||||
{
|
||||
void *buf[100];
|
||||
int nframes;
|
||||
|
||||
nframes = backtrace(buf, lengthof(buf));
|
||||
backtrace_symbols_fd(buf, nframes, fileno(stderr));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SLEEP_ON_ASSERT
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user