Re: Printing backtrace of postgres processes

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: vignesh C <vignesh21(at)gmail(dot)com>
Cc: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, torikoshia <torikoshia(at)oss(dot)nttdata(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Printing backtrace of postgres processes
Date: 2024-01-26 10:41:04
Message-ID: 202401261041.tnf6wsga2zvm@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2022-Jan-27, vignesh C wrote:

> diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
> index 0ee6974f1c..855ccc8902 100644
> --- a/doc/src/sgml/func.sgml
> +++ b/doc/src/sgml/func.sgml

> + You can get the file name and line number from the logged details by using
> + gdb/addr2line in linux platforms (users must ensure gdb/addr2line is
> + already installed).

This doesn't read great. I mean, what is gdb/addr2line? I think you
mean either GDB or addr2line; this could be clearer.

> diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
> index 7402696986..522a525741 100644
> --- a/src/backend/utils/error/elog.c
> +++ b/src/backend/utils/error/elog.c
> @@ -944,9 +943,10 @@ errbacktrace(void)
> * Compute backtrace data and add it to the supplied ErrorData. num_skip
> * specifies how many inner frames to skip. Use this to avoid showing the
> * internal backtrace support functions in the backtrace. This requires that
> - * this and related functions are not inlined.
> + * this and related functions are not inlined. If the edata pointer is valid,
> + * backtrace information will be set in edata.
> */
> -static void
> +void
> set_backtrace(ErrorData *edata, int num_skip)
> {
> StringInfoData errtrace;

This seems like a terrible API choice, and the comment change is no
good. I suggest you need to create a function that deals only with a
StringInfo, maybe
append_backtrace(StringInfo buf, int num_skip)
which is used by set_backtrace to print the backtrace in
edata->backtrace, and a new function log_backtrace() that does the
ereport(LOG_SERVER_ONLY) thing.

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
"Before you were born your parents weren't as boring as they are now. They
got that way paying your bills, cleaning up your room and listening to you
tell them how idealistic you are." -- Charles J. Sykes' advice to teenagers

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jelte Fennema-Nio 2024-01-26 10:44:24 Re: [EXTERNAL] Re: Add non-blocking version of PQcancel
Previous Message Jelte Fennema-Nio 2024-01-26 10:40:00 Re: proposal: psql: show current user in prompt