printing PGresult content with gdb

Started by Lana ABADIEalmost 2 years ago4 messagesgeneral
Jump to latest
#1Lana ABADIE
clipperDB@gmx.fr

<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>&nbsp;</div>

<div class="signature">Hi all</div>

<div class="signature">I don&#39;t know if it is the right mailing list, but i was wondering if one could introspect via gdb the content of PGresult.</div>

<div class="signature">In my case i got a coredump and when i tried to analyze the core and try to print the content of PGresult i got incomplete type</div>

<div class="signature">I&#39;m using libpq-13.3 (installed via libpq-13.3-1.el8_4.x86_64, RHEL8.5). Any help would be appreciated (i&#39;m trying to get the errMesg value of this field)</div>

<div class="signature">(gdb) p res<br/>
&#36;1 = (PGresult *) 0x7f0718000b80<br/>
(gdb) p *res<br/>
&#36;2 = &lt;incomplete type&gt;<br/>
(gdb) ptype res<br/>
type = struct pg_result {<br/>
&nbsp; &nbsp; &lt;incomplete type&gt;<br/>
} *<br/>
(gdb) explore res<br/>
&#39;res&#39; is a pointer to a value of type &#39;PGresult&#39;<br/>
Continue exploring it as a pointer to a single value [y/n]: y<br/>
The value of &#39;*res&#39; is of type &#39;PGresult&#39; which is a typedef of type &#39;pg_result&#39;<br/>
The value of &#39;*res&#39; is a struct/class of type &#39;pg_result&#39; with no fields.<br/>
(gdb)&nbsp;<br/>
thanks for your hints</div>

<div class="signature">doris</div></div></body></html>

#2Reid Thompson
jreidthompson@nc.rr.com
In reply to: Lana ABADIE (#1)
Re: printing PGresult content with gdb

On Tue, 2024-07-02 at 18:13 +0200, clipperDB@gmx.fr wrote:

 
Hi all
I don't know if it is the right mailing list, but i was wondering if
one could introspect via gdb the content of PGresult.
In my case i got a coredump and when i tried to analyze the core and
try to print the content of PGresult i got incomplete type
I'm using libpq-13.3 (installed via libpq-13.3-1.el8_4.x86_64,
RHEL8.5). Any help would be appreciated (i'm trying to get the
errMesg value of this field)
(gdb) p res
$1 = (PGresult *) 0x7f0718000b80
(gdb) p *res
$2 = <incomplete type>
(gdb) ptype res
type = struct pg_result {
    <incomplete type>
} *
(gdb) explore res
'res' is a pointer to a value of type 'PGresult'
Continue exploring it as a pointer to a single value [y/n]: y
The value of '*res' is of type 'PGresult' which is a typedef of type
'pg_result'
The value of '*res' is a struct/class of type 'pg_result' with no
fields.
(gdb) 
thanks for your hints
doris

https://wiki.postgresql.org/wiki/Developer_FAQ#Why_do_we_use_Node_and_List_to_make_data_structures.3F
may be of help.

Instead of printing values in gdb format, you can use the next two
commands to print out List, Node, and structure contents in a verbose
format that is easier to understand. Lists are unrolled into nodes, and
nodes are printed in detail. The first prints in a short format, and
the second in a long format:

(gdb) call print(any_pointer)
(gdb) call pprint(any_pointer)
The output appears in the server log file, or on your screen if you are
running a backend directly without a postmaster.

I found that from https://wiki.postgresql.org/wiki/Developer_FAQ#gdb

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Lana ABADIE (#1)
Re: printing PGresult content with gdb

clipperDB@gmx.fr writes:

I don't know if it is the right mailing list, but i was
wondering if one could introspect via gdb the content of PGresult.

You might have better luck with that if you install the debuginfo
RPM corresponding to your libpq RPM. PGresult's innards are not
exposed to applications by libpq-fe.h, so your own app's debug
data is not going to contain the details of the struct. But I think
it would be available to gdb if libpq's debug symbols were installed.

regards, tom lane

#4Lana ABADIE
clipperDB@gmx.fr
In reply to: Tom Lane (#3)
Re: printing PGresult content with gdb

<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>&nbsp;</div>

<div>&nbsp;
<div>&nbsp;
<div name="quote" style="margin:10px 5px 5px 10px; padding: 10px 0 10px 10px; border-left:2px solid #C3D9E5; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
<div style="margin:0 0 10px 0;"><b>Envoy&eacute;:</b>&nbsp;mercredi 3 juillet 2024 &agrave; 17:55<br/>
<b>De:</b>&nbsp;&quot;Tom Lane&quot; &lt;tgl@sss.pgh.pa.us&gt;<br/>
<b>&Agrave;:</b>&nbsp;clipperDB@gmx.fr<br/>
<b>Cc:</b>&nbsp;pgsql-general@lists.postgresql.org<br/>
<b>Objet:</b>&nbsp;Re: printing PGresult content with gdb</div>

<div name="quoted-content">clipperDB@gmx.fr writes:<br/>
&gt; I don&#39;t know if it is the right mailing list, but i was<br/>
&gt; wondering if one could introspect via gdb the content of PGresult.<br/>
<br/>
You might have better luck with that if you install the debuginfo<br/>
RPM corresponding to your libpq RPM. PGresult&#39;s innards are not<br/>
exposed to applications by libpq-fe.h, so your own app&#39;s debug<br/>
data is not going to contain the details of the struct. But I think<br/>
it would be available to gdb if libpq&#39;s debug symbols were installed.<br/>
<br/>
regards, tom lane</div>

<div name="quoted-content">&nbsp;</div>

<div name="quoted-content">thanks Tom</div>

<div name="quoted-content">Indeed installing the debuginfo rpm on my system solves the issue, i could print the content</div>

<div name="quoted-content">see trace below</div>

<div name="quoted-content">
<pre>(gdb) p *res
&#36;2 = {ntups = 0, numAttributes = 0, attDescs = 0x0, tuples = 0x0, tupArrSize = 0, numParameters = 0, paramDescs = 0x0, resultStatus = PGRES_FATAL_ERROR,&nbsp;
&nbsp; cmdStatus = &quot;&#92;000ELECT 3&#92;000&#92;061&quot;, &#39;&#92;000&#39; &lt;repeats 53 times&gt;, binary = 0, noticeHooks = {noticeRec = 0x7f0731f40770 &lt;defaultNoticeReceiver&gt;, noticeRecArg = 0x0,&nbsp;
&nbsp; &nbsp; noticeProc = 0x7f0731f40500 &lt;defaultNoticeProcessor&gt;, noticeProcArg = 0x0}, events = 0x0, nEvents = 0, client_encoding = 6,&nbsp;
&nbsp; errMsg = 0x7f07180076e8 &quot;server closed the connection unexpectedly&#92;n&#92;tThis probably means the server terminated abnormally&#92;n&#92;tbefore or while processing the request.&#92;n&quot;,&nbsp;
&nbsp; errFields = 0x0, errQuery = 0x0, null_field = &quot;&quot;, curBlock = 0x7f07180076e0, curOffset = 146, spaceLeft = 1902, memorySize = 2264}</pre>
</div>
</div>
</div>
</div></div></body></html>