Thread: format_datum debugging function
Hi Hackers, Often in a debugger I've wanted to way to print Datums, in particular non-trivial ones like range types. This came up a lot when I was working on multiranges, and I've wished for it lately while working on UPDATE/DELETE FOR PORTION OF. But all the obvious approaches are inlined functions or preprocessor macros, so they aren't available. Usually I wind up giving up on gdb and adding elog statements. Once or twice I've copy/pasted from the three or four levels of nested macros to make gdb do what I wanted, but it's a pain. I assumed printing a Datum was easy, and I was the only one who didn't know how to do it. But perhaps not. The conversation about print.c [1] made me think I should propose a way to make it easier. This function takes a Datum and the appropriate out function, and returns a char *. So you can do this: (gdb) call format_datum(range_out, $1) $2 = 0x59162692d938 "[1,4)" I assume a patch like this doesn't need documentation. Does it need a test? Anything else? [1] https://www.postgresql.org/message-id/flat/7d023c20-6679-44bd-b5f7-44106659bd5a%40eisentraut.org Yours, -- Paul ~{:-) pj@illuminatedcomputing.com
Hi Paul, > [...] This function takes a Datum and the appropriate out function, and returns a char *. So you > can do this: > > (gdb) call format_datum(range_out, $1) > $2 = 0x59162692d938 "[1,4)" > > I assume a patch like this doesn't need documentation. Does it need a test? Anything else? I think you forgot to attach the patch. Or is it just a proposal? -- Best regards, Aleksander Alekseev
On 8/12/24 04:32, Aleksander Alekseev wrote: >> [...] This function takes a Datum and the appropriate out function, and returns a char *. So you >> can do this: >> >> (gdb) call format_datum(range_out, $1) >> $2 = 0x59162692d938 "[1,4)" >> >> I assume a patch like this doesn't need documentation. Does it need a test? Anything else? > > I think you forgot to attach the patch. Or is it just a proposal? Sorry, patch attached here. Yours, -- Paul ~{:-) pj@illuminatedcomputing.com
Attachment
On Mon, 12 Aug 2024 at 23:15, Paul Jungwirth <pj@illuminatedcomputing.com> wrote: > On 8/12/24 04:32, Aleksander Alekseev wrote: > >> (gdb) call format_datum(range_out, $1) > >> $2 = 0x59162692d938 "[1,4)" > >> > >> I assume a patch like this doesn't need documentation. Does it need a test? Anything else? > > > > I think you forgot to attach the patch. Or is it just a proposal? > > Sorry, patch attached here. +1 for the idea. And the code looks trivial enough. I think this should also contain a print_datum function too though.
On 12.08.24 23:15, Paul Jungwirth wrote: > On 8/12/24 04:32, Aleksander Alekseev wrote: >>> [...] This function takes a Datum and the appropriate out function, >>> and returns a char *. So you >>> can do this: >>> >>> (gdb) call format_datum(range_out, $1) >>> $2 = 0x59162692d938 "[1,4)" >>> >>> I assume a patch like this doesn't need documentation. Does it need a >>> test? Anything else? >> >> I think you forgot to attach the patch. Or is it just a proposal? > > Sorry, patch attached here. I don't think it's safe to call output functions at arbitrary points from a debugger. But if you're okay with that during development, say, then I think you could just call OidOutputFunctionCall(F_RANGE_OUT, $1)?