Re: Printing backtrace of postgres processes - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: Printing backtrace of postgres processes
Date
Msg-id 202401261041.tnf6wsga2zvm@alvherre.pgsql
Whole thread Raw
In response to Re: Printing backtrace of postgres processes  (vignesh C <vignesh21@gmail.com>)
Responses Re: Printing backtrace of postgres processes
List 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



pgsql-hackers by date:

Previous
From: Jelte Fennema-Nio
Date:
Subject: Re: proposal: psql: show current user in prompt
Next
From: Jelte Fennema-Nio
Date:
Subject: Re: [EXTERNAL] Re: Add non-blocking version of PQcancel