From: | Peter Eisentraut <peter(at)eisentraut(dot)org> |
---|---|
To: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | backtrace_on_internal_error |
Date: | 2023-12-05 10:55:05 |
Message-ID: | ba76c6bc-f03f-4285-bf16-47759cfcab9e@eisentraut.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
We have backtrace support for server errors. You can activate that
either by setting backtrace_functions or by explicitly attaching
errbacktrace() to an ereport() call.
I would like an additional mode that essentially triggers a backtrace
anytime elog() (for internal errors) is called. This is not well
covered by backtrace_functions, because there are many equally-worded
low-level errors in many functions. And if you find out where the error
is, then you need to manually rewrite the elog() to ereport() to attach
the errbacktrace(), which is annoying. Having a backtrace automatically
on every elog() call would be very helpful during development for
various kinds of common errors from palloc, syscache, node support, etc.
I think the implementation would be very simple, something like
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 6aeb855e49..45d40abe92 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -498,9 +498,11 @@ errfinish(const char *filename, int lineno, const
char *funcname)
/* Collect backtrace, if enabled and we didn't already */
if (!edata->backtrace &&
- edata->funcname &&
- backtrace_functions &&
- matches_backtrace_functions(edata->funcname))
+ ((edata->funcname &&
+ backtrace_functions &&
+ matches_backtrace_functions(edata->funcname)) ||
+ (edata->sqlerrcode == ERRCODE_INTERNAL_ERROR &&
+ backtrace_on_internal_error)))
set_backtrace(edata, 2);
/*
where backtrace_on_internal_error would be a GUC variable.
Would others find this useful? Any other settings or variants in this
area that should be considered while we're here?
From | Date | Subject | |
---|---|---|---|
Next Message | Thomas Munro | 2023-12-05 11:03:53 | UBSan pointer overflow in xlogreader.c |
Previous Message | Andrei Lepikhov | 2023-12-05 10:55:00 | Re: POC, WIP: OR-clause support for indexes |