PostgreSQL Source Code git master
Loading...
Searching...
No Matches
fe-trace.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * fe-trace.c
4 * functions for libpq protocol tracing
5 *
6 * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * IDENTIFICATION
10 * src/interfaces/libpq/fe-trace.c
11 *
12 *-------------------------------------------------------------------------
13 */
14
15#include "postgres_fe.h"
16
17#include <ctype.h>
18#include <limits.h>
19#include <sys/time.h>
20#include <time.h>
21
22#ifdef WIN32
23#include "win32.h"
24#else
25#include <unistd.h>
26#endif
27
28#include "libpq-fe.h"
29#include "libpq-int.h"
30#include "port/pg_bswap.h"
31
32
33/* Enable tracing */
34void
36{
37 if (conn == NULL)
38 return;
40 if (debug_port == NULL)
41 return;
42
44 conn->traceFlags = 0;
45}
46
47/* Disable tracing */
48void
50{
51 if (conn == NULL)
52 return;
53 if (conn->Pfdebug)
54 {
56 conn->Pfdebug = NULL;
57 }
58
59 conn->traceFlags = 0;
60}
61
62/* Set flags for current tracing session */
63void
65{
66 if (conn == NULL)
67 return;
68 /* If PQtrace() failed, do nothing. */
69 if (conn->Pfdebug == NULL)
70 return;
71 conn->traceFlags = flags;
72}
73
74/*
75 * Print the current time, with microseconds, into a caller-supplied
76 * buffer.
77 * Cribbed from get_formatted_log_time, but much simpler.
78 */
79static void
81{
82 struct timeval tval;
83 time_t now;
84 struct tm tmbuf;
85
87
88 /*
89 * MSVC's implementation of timeval uses a long for tv_sec, however,
90 * localtime() expects a time_t pointer. Here we'll assign tv_sec to a
91 * local time_t variable so that we pass localtime() the correct pointer
92 * type.
93 */
94 now = tval.tv_sec;
96 "%Y-%m-%d %H:%M:%S",
98 /* append microseconds */
100 ".%06u", (unsigned int) (tval.tv_usec));
101}
102
103/*
104 * pqTraceOutputByte1: output a 1-char message to the log
105 */
106static void
108{
109 const char *v = data + *cursor;
110
111 /*
112 * Show non-printable data in hex format, including the terminating \0
113 * that completes ErrorResponse and NoticeResponse messages.
114 */
115 if (!isprint((unsigned char) *v))
116 fprintf(pfdebug, " \\x%02x", (unsigned char) *v);
117 else
118 fprintf(pfdebug, " %c", *v);
119 *cursor += 1;
120}
121
122/*
123 * pqTraceOutputInt16: output a 2-byte integer message to the log
124 */
125static int
127{
128 uint16 tmp;
129 int result;
130
131 memcpy(&tmp, data + *cursor, 2);
132 *cursor += 2;
133 result = (int) pg_ntoh16(tmp);
134 fprintf(pfdebug, " %d", result);
135
136 return result;
137}
138
139/*
140 * pqTraceOutputInt32: output a 4-byte integer message to the log
141 *
142 * If 'suppress' is true, print a literal NNNN instead of the actual number.
143 */
144static int
146{
147 int result;
148
149 memcpy(&result, data + *cursor, 4);
150 *cursor += 4;
152 if (suppress)
153 fprintf(pfdebug, " NNNN");
154 else
155 fprintf(pfdebug, " %d", result);
156
157 return result;
158}
159
160/*
161 * pqTraceOutputString: output a string message to the log
162 *
163 * If 'suppress' is true, print a literal "SSSS" instead of the actual string.
164 */
165static void
167{
168 int len;
169
170 if (suppress)
171 {
172 fprintf(pfdebug, " \"SSSS\"");
173 *cursor += strlen(data + *cursor) + 1;
174 }
175 else
176 {
177 len = fprintf(pfdebug, " \"%s\"", data + *cursor);
178
179 /*
180 * This is a null-terminated string. So add 1 after subtracting 3
181 * which is the double quotes and space length from len.
182 */
183 *cursor += (len - 3 + 1);
184 }
185}
186
187/*
188 * pqTraceOutputNchar: output a string of exactly len bytes message to the log
189 *
190 * If 'suppress' is true, print a literal 'BBBB' instead of the actual bytes.
191 */
192static void
193pqTraceOutputNchar(FILE *pfdebug, int len, const char *data, int *cursor, bool suppress)
194{
195 int i,
196 next; /* first char not yet printed */
197 const char *v = data + *cursor;
198
199 if (suppress)
200 {
201 fprintf(pfdebug, " 'BBBB'");
202 *cursor += len;
203 return;
204 }
205
206 fprintf(pfdebug, " \'");
207
208 for (next = i = 0; i < len; ++i)
209 {
210 if (isprint((unsigned char) v[i]))
211 continue;
212 else
213 {
214 fwrite(v + next, 1, i - next, pfdebug);
215 fprintf(pfdebug, "\\x%02x", (unsigned char) v[i]);
216 next = i + 1;
217 }
218 }
219 if (next < len)
220 fwrite(v + next, 1, len - next, pfdebug);
221
222 fprintf(pfdebug, "\'");
223 *cursor += len;
224}
225
226/*
227 * Output functions by protocol message type
228 */
229
230static void
231pqTraceOutput_NotificationResponse(FILE *f, const char *message, int *cursor, bool regress)
232{
233 fprintf(f, "NotificationResponse\t");
234 pqTraceOutputInt32(f, message, cursor, regress);
235 pqTraceOutputString(f, message, cursor, false);
236 pqTraceOutputString(f, message, cursor, false);
237}
238
239static void
240pqTraceOutput_Bind(FILE *f, const char *message, int *cursor)
241{
242 int nparams;
243
244 fprintf(f, "Bind\t");
245 pqTraceOutputString(f, message, cursor, false);
246 pqTraceOutputString(f, message, cursor, false);
247 nparams = pqTraceOutputInt16(f, message, cursor);
248
249 for (int i = 0; i < nparams; i++)
250 pqTraceOutputInt16(f, message, cursor);
251
252 nparams = pqTraceOutputInt16(f, message, cursor);
253
254 for (int i = 0; i < nparams; i++)
255 {
256 int nbytes;
257
258 nbytes = pqTraceOutputInt32(f, message, cursor, false);
259 if (nbytes == -1)
260 continue;
261 pqTraceOutputNchar(f, nbytes, message, cursor, false);
262 }
263
264 nparams = pqTraceOutputInt16(f, message, cursor);
265 for (int i = 0; i < nparams; i++)
266 pqTraceOutputInt16(f, message, cursor);
267}
268
269static void
270pqTraceOutput_Close(FILE *f, const char *message, int *cursor)
271{
272 fprintf(f, "Close\t");
273 pqTraceOutputByte1(f, message, cursor);
274 pqTraceOutputString(f, message, cursor, false);
275}
276
277static void
278pqTraceOutput_CommandComplete(FILE *f, const char *message, int *cursor)
279{
280 fprintf(f, "CommandComplete\t");
281 pqTraceOutputString(f, message, cursor, false);
282}
283
284static void
285pqTraceOutput_CopyData(FILE *f, const char *message, int *cursor, int length,
286 bool suppress)
287{
288 fprintf(f, "CopyData\t");
289 pqTraceOutputNchar(f, length - *cursor + 1, message, cursor, suppress);
290}
291
292static void
293pqTraceOutput_DataRow(FILE *f, const char *message, int *cursor)
294{
295 int nfields;
296 int len;
297 int i;
298
299 fprintf(f, "DataRow\t");
300 nfields = pqTraceOutputInt16(f, message, cursor);
301 for (i = 0; i < nfields; i++)
302 {
303 len = pqTraceOutputInt32(f, message, cursor, false);
304 if (len == -1)
305 continue;
306 pqTraceOutputNchar(f, len, message, cursor, false);
307 }
308}
309
310static void
311pqTraceOutput_Describe(FILE *f, const char *message, int *cursor)
312{
313 fprintf(f, "Describe\t");
314 pqTraceOutputByte1(f, message, cursor);
315 pqTraceOutputString(f, message, cursor, false);
316}
317
318/* shared code NoticeResponse / ErrorResponse */
319static void
320pqTraceOutputNR(FILE *f, const char *type, const char *message, int *cursor,
321 bool regress)
322{
323 fprintf(f, "%s\t", type);
324 for (;;)
325 {
326 char field;
327 bool suppress;
328
329 pqTraceOutputByte1(f, message, cursor);
330 field = message[*cursor - 1];
331 if (field == '\0')
332 break;
333
334 suppress = regress && (field == 'L' || field == 'F' || field == 'R');
335 pqTraceOutputString(f, message, cursor, suppress);
336 }
337}
338
339static void
340pqTraceOutput_ErrorResponse(FILE *f, const char *message, int *cursor, bool regress)
341{
342 pqTraceOutputNR(f, "ErrorResponse", message, cursor, regress);
343}
344
345static void
346pqTraceOutput_NoticeResponse(FILE *f, const char *message, int *cursor, bool regress)
347{
348 pqTraceOutputNR(f, "NoticeResponse", message, cursor, regress);
349}
350
351static void
352pqTraceOutput_Execute(FILE *f, const char *message, int *cursor, bool regress)
353{
354 fprintf(f, "Execute\t");
355 pqTraceOutputString(f, message, cursor, false);
356 pqTraceOutputInt32(f, message, cursor, false);
357}
358
359static void
360pqTraceOutput_CopyFail(FILE *f, const char *message, int *cursor)
361{
362 fprintf(f, "CopyFail\t");
363 pqTraceOutputString(f, message, cursor, false);
364}
365
366static void
367pqTraceOutput_GSSResponse(FILE *f, const char *message, int *cursor,
368 int length, bool regress)
369{
370 fprintf(f, "GSSResponse\t");
371 pqTraceOutputNchar(f, length - *cursor + 1, message, cursor, regress);
372}
373
374static void
375pqTraceOutput_PasswordMessage(FILE *f, const char *message, int *cursor)
376{
377 fprintf(f, "PasswordMessage\t");
378 pqTraceOutputString(f, message, cursor, false);
379}
380
381static void
382pqTraceOutput_SASLInitialResponse(FILE *f, const char *message, int *cursor,
383 bool regress)
384{
385 int initialResponse;
386
387 fprintf(f, "SASLInitialResponse\t");
388 pqTraceOutputString(f, message, cursor, false);
389 initialResponse = pqTraceOutputInt32(f, message, cursor, false);
390 if (initialResponse != -1)
392}
393
394static void
395pqTraceOutput_SASLResponse(FILE *f, const char *message, int *cursor,
396 int length, bool regress)
397{
398 fprintf(f, "SASLResponse\t");
399 pqTraceOutputNchar(f, length - *cursor + 1, message, cursor, regress);
400}
401
402static void
403pqTraceOutput_FunctionCall(FILE *f, const char *message, int *cursor, bool regress)
404{
405 int nfields;
406 int nbytes;
407
408 fprintf(f, "FunctionCall\t");
409 pqTraceOutputInt32(f, message, cursor, regress);
410 nfields = pqTraceOutputInt16(f, message, cursor);
411
412 for (int i = 0; i < nfields; i++)
413 pqTraceOutputInt16(f, message, cursor);
414
415 nfields = pqTraceOutputInt16(f, message, cursor);
416
417 for (int i = 0; i < nfields; i++)
418 {
419 nbytes = pqTraceOutputInt32(f, message, cursor, false);
420 if (nbytes == -1)
421 continue;
422 pqTraceOutputNchar(f, nbytes, message, cursor, false);
423 }
424
425 pqTraceOutputInt16(f, message, cursor);
426}
427
428static void
429pqTraceOutput_CopyInResponse(FILE *f, const char *message, int *cursor)
430{
431 int nfields;
432
433 fprintf(f, "CopyInResponse\t");
434 pqTraceOutputByte1(f, message, cursor);
435 nfields = pqTraceOutputInt16(f, message, cursor);
436
437 for (int i = 0; i < nfields; i++)
438 pqTraceOutputInt16(f, message, cursor);
439}
440
441static void
442pqTraceOutput_CopyOutResponse(FILE *f, const char *message, int *cursor)
443{
444 int nfields;
445
446 fprintf(f, "CopyOutResponse\t");
447 pqTraceOutputByte1(f, message, cursor);
448 nfields = pqTraceOutputInt16(f, message, cursor);
449
450 for (int i = 0; i < nfields; i++)
451 pqTraceOutputInt16(f, message, cursor);
452}
453
454static void
455pqTraceOutput_BackendKeyData(FILE *f, const char *message, int *cursor, int length,
456 bool regress)
457{
458 fprintf(f, "BackendKeyData\t");
459 pqTraceOutputInt32(f, message, cursor, regress);
460 pqTraceOutputNchar(f, length - *cursor + 1, message, cursor, regress);
461}
462
463static void
464pqTraceOutput_Parse(FILE *f, const char *message, int *cursor, bool regress)
465{
466 int nparams;
467
468 fprintf(f, "Parse\t");
469 pqTraceOutputString(f, message, cursor, false);
470 pqTraceOutputString(f, message, cursor, false);
471 nparams = pqTraceOutputInt16(f, message, cursor);
472
473 for (int i = 0; i < nparams; i++)
474 pqTraceOutputInt32(f, message, cursor, regress);
475}
476
477static void
478pqTraceOutput_Query(FILE *f, const char *message, int *cursor)
479{
480 fprintf(f, "Query\t");
481 pqTraceOutputString(f, message, cursor, false);
482}
483
484static void
485pqTraceOutput_Authentication(FILE *f, const char *message, int *cursor,
486 int length, bool suppress)
487{
488 int authType = 0;
489
490 memcpy(&authType, message + *cursor, 4);
492 *cursor += 4;
493 switch (authType)
494 {
495 case AUTH_REQ_OK:
496 fprintf(f, "AuthenticationOk");
497 break;
498 /* AUTH_REQ_KRB4 not supported */
499 /* AUTH_REQ_KRB5 not supported */
501 fprintf(f, "AuthenticationCleartextPassword");
502 break;
503 /* AUTH_REQ_CRYPT not supported */
504 case AUTH_REQ_MD5:
505 fprintf(f, "AuthenticationMD5Password");
506 break;
507 case AUTH_REQ_GSS:
508 fprintf(f, "AuthenticationGSS");
509 break;
511 fprintf(f, "AuthenticationGSSContinue\t");
512 pqTraceOutputNchar(f, length - *cursor + 1, message, cursor,
513 suppress);
514 break;
515 case AUTH_REQ_SSPI:
516 fprintf(f, "AuthenticationSSPI");
517 break;
518 case AUTH_REQ_SASL:
519 fprintf(f, "AuthenticationSASL\t");
520 while (message[*cursor] != '\0')
521 pqTraceOutputString(f, message, cursor, false);
522 pqTraceOutputString(f, message, cursor, false);
523 break;
525 fprintf(f, "AuthenticationSASLContinue\t");
526 pqTraceOutputNchar(f, length - *cursor + 1, message, cursor,
527 suppress);
528 break;
530 fprintf(f, "AuthenticationSASLFinal\t");
531 pqTraceOutputNchar(f, length - *cursor + 1, message, cursor,
532 suppress);
533 break;
534 default:
535 fprintf(f, "Unknown authentication message %d", authType);
536 }
537}
538
539static void
540pqTraceOutput_ParameterStatus(FILE *f, const char *message, int *cursor)
541{
542 fprintf(f, "ParameterStatus\t");
543 pqTraceOutputString(f, message, cursor, false);
544 pqTraceOutputString(f, message, cursor, false);
545}
546
547static void
548pqTraceOutput_ParameterDescription(FILE *f, const char *message, int *cursor, bool regress)
549{
550 int nfields;
551
552 fprintf(f, "ParameterDescription\t");
553 nfields = pqTraceOutputInt16(f, message, cursor);
554
555 for (int i = 0; i < nfields; i++)
556 pqTraceOutputInt32(f, message, cursor, regress);
557}
558
559static void
560pqTraceOutput_RowDescription(FILE *f, const char *message, int *cursor, bool regress)
561{
562 int nfields;
563
564 fprintf(f, "RowDescription\t");
565 nfields = pqTraceOutputInt16(f, message, cursor);
566
567 for (int i = 0; i < nfields; i++)
568 {
569 pqTraceOutputString(f, message, cursor, false);
570 pqTraceOutputInt32(f, message, cursor, regress);
571 pqTraceOutputInt16(f, message, cursor);
572 pqTraceOutputInt32(f, message, cursor, regress);
573 pqTraceOutputInt16(f, message, cursor);
574 pqTraceOutputInt32(f, message, cursor, false);
575 pqTraceOutputInt16(f, message, cursor);
576 }
577}
578
579static void
581{
582 int nparams;
583
584 fprintf(f, "NegotiateProtocolVersion\t");
585 pqTraceOutputInt32(f, message, cursor, false);
586 nparams = pqTraceOutputInt32(f, message, cursor, false);
587 for (int i = 0; i < nparams; i++)
588 {
589 pqTraceOutputString(f, message, cursor, false);
590 }
591}
592
593static void
594pqTraceOutput_FunctionCallResponse(FILE *f, const char *message, int *cursor)
595{
596 int len;
597
598 fprintf(f, "FunctionCallResponse\t");
599 len = pqTraceOutputInt32(f, message, cursor, false);
600 if (len != -1)
601 pqTraceOutputNchar(f, len, message, cursor, false);
602}
603
604static void
605pqTraceOutput_CopyBothResponse(FILE *f, const char *message, int *cursor, int length)
606{
607 fprintf(f, "CopyBothResponse\t");
608 pqTraceOutputByte1(f, message, cursor);
609
610 while (length > *cursor)
611 pqTraceOutputInt16(f, message, cursor);
612}
613
614static void
615pqTraceOutput_ReadyForQuery(FILE *f, const char *message, int *cursor)
616{
617 fprintf(f, "ReadyForQuery\t");
618 pqTraceOutputByte1(f, message, cursor);
619}
620
621/*
622 * Print the given message to the trace output stream.
623 */
624void
625pqTraceOutputMessage(PGconn *conn, const char *message, bool toServer)
626{
627 char id;
628 int length;
629 char *prefix = toServer ? "F" : "B";
630 int logCursor = 0;
631 bool regress;
632
634 {
635 char timestr[128];
636
638 fprintf(conn->Pfdebug, "%s\t", timestr);
639 }
641
642 id = message[logCursor++];
643
644 memcpy(&length, message + logCursor, 4);
645 length = (int) pg_ntoh32(length);
646 logCursor += 4;
647
648 /*
649 * In regress mode, suppress the length of ErrorResponse and
650 * NoticeResponse. The F (file name), L (line number) and R (routine
651 * name) fields can change as server code is modified, and if their
652 * lengths differ from the originals, that would break tests.
653 */
654 if (regress && !toServer && (id == PqMsg_ErrorResponse || id == PqMsg_NoticeResponse))
655 fprintf(conn->Pfdebug, "%s\tNN\t", prefix);
656 else
657 fprintf(conn->Pfdebug, "%s\t%d\t", prefix, length);
658
659 switch (id)
660 {
662 fprintf(conn->Pfdebug, "ParseComplete");
663 /* No message content */
664 break;
666 fprintf(conn->Pfdebug, "BindComplete");
667 /* No message content */
668 break;
670 fprintf(conn->Pfdebug, "CloseComplete");
671 /* No message content */
672 break;
675 break;
676 case PqMsg_Bind:
678 break;
679 case PqMsg_CopyDone:
680 fprintf(conn->Pfdebug, "CopyDone");
681 /* No message content */
682 break;
684 /* Close(F) and CommandComplete(B) use the same identifier. */
686 if (toServer)
688 else
690 break;
691 case PqMsg_CopyData:
693 length, regress);
694 break;
695 case PqMsg_Describe:
696 /* Describe(F) and DataRow(B) use the same identifier. */
698 if (toServer)
700 else
702 break;
703 case PqMsg_Execute:
704 /* Execute(F) and ErrorResponse(B) use the same identifier. */
706 if (toServer)
708 else
710 break;
711 case PqMsg_CopyFail:
713 break;
718
719 /*
720 * These messages share a common type byte, so we discriminate by
721 * having the code store the auth type separately.
722 */
724 {
727 &logCursor, length, regress);
728 break;
731 &logCursor);
732 break;
736 break;
739 &logCursor, length, regress);
740 break;
741 default:
742 fprintf(conn->Pfdebug, "UnknownAuthenticationResponse");
743 break;
744 }
746 break;
749 break;
752 break;
753 case PqMsg_Flush:
754 /* Flush(F) and CopyOutResponse(B) use the same identifier */
756 if (toServer)
757 fprintf(conn->Pfdebug, "Flush"); /* no message content */
758 else
760 break;
762 fprintf(conn->Pfdebug, "EmptyQueryResponse");
763 /* No message content */
764 break;
767 length, regress);
768 break;
769 case PqMsg_NoData:
770 fprintf(conn->Pfdebug, "NoData");
771 /* No message content */
772 break;
775 break;
776 case PqMsg_Parse:
778 break;
779 case PqMsg_Query:
781 break;
784 length, regress);
785 break;
787 fprintf(conn->Pfdebug, "PortalSuspended");
788 /* No message content */
789 break;
790 case PqMsg_Sync:
791 /* ParameterStatus(B) and Sync(F) use the same identifier */
793 if (toServer)
794 fprintf(conn->Pfdebug, "Sync"); /* no message content */
795 else
797 break;
800 break;
803 break;
806 break;
809 break;
812 break;
813 case PqMsg_Terminate:
814 fprintf(conn->Pfdebug, "Terminate");
815 /* No message content */
816 break;
819 break;
820 default:
821 fprintf(conn->Pfdebug, "Unknown message: %02x", id);
822 break;
823 }
824
825 fputc('\n', conn->Pfdebug);
826
827 /*
828 * Verify the printing routine did it right. Note that the one-byte
829 * message identifier is not included in the length, but our cursor does
830 * include it.
831 */
832 if (logCursor - 1 != length)
834 "mismatched message length: consumed %d, expected %d\n",
835 logCursor - 1, length);
836}
837
838/*
839 * Print special messages (those containing no type byte) to the trace output
840 * stream.
841 */
842void
844{
845 int length;
846 int version;
847 bool regress;
848 int logCursor = 0;
849
851
853 {
854 char timestr[128];
855
857 fprintf(conn->Pfdebug, "%s\t", timestr);
858 }
859
860 memcpy(&length, message + logCursor, 4);
861 length = (int) pg_ntoh32(length);
862 logCursor += 4;
863
864 fprintf(conn->Pfdebug, "F\t%d\t", length);
865
866 if (length < 8)
867 {
868 fprintf(conn->Pfdebug, "Unknown message\n");
869 return;
870 }
871
872 memcpy(&version, message + logCursor, 4);
873 version = (int) pg_ntoh32(version);
874
875 if (version == CANCEL_REQUEST_CODE && length >= 16)
876 {
877 fprintf(conn->Pfdebug, "CancelRequest\t");
881 pqTraceOutputNchar(conn->Pfdebug, length - logCursor, message,
883 }
884 else if (version == NEGOTIATE_SSL_CODE)
885 {
886 fprintf(conn->Pfdebug, "SSLRequest\t");
889 }
890 else if (version == NEGOTIATE_GSS_CODE)
891 {
892 fprintf(conn->Pfdebug, "GSSENCRequest\t");
895 }
896 else
897 {
898 fprintf(conn->Pfdebug, "StartupMessage\t");
901 while (message[logCursor] != '\0')
902 {
903 /* XXX should we suppress anything in regress mode? */
904 pqTraceOutputString(conn->Pfdebug, message, &logCursor, false);
905 pqTraceOutputString(conn->Pfdebug, message, &logCursor, false);
906 }
907 }
908
909 fputc('\n', conn->Pfdebug);
910}
911
912/*
913 * Trace a single-byte backend response received for a known request
914 * type the frontend previously sent. Only useful for the simplest of
915 * FE/BE interaction workflows such as SSL/GSS encryption requests.
916 */
917void
919 char response)
920{
922 {
923 char timestr[128];
924
926 fprintf(conn->Pfdebug, "%s\t", timestr);
927 }
928
929 fprintf(conn->Pfdebug, "B\t1\t%s\t %c\n", responseType, response);
930}
Datum now(PG_FUNCTION_ARGS)
Definition timestamp.c:1613
static int32 next
Definition blutils.c:225
#define Assert(condition)
Definition c.h:1002
uint16_t uint16
Definition c.h:682
uint32 result
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
#define fprintf(file, fmt, msg)
Definition cubescan.l:21
static void pqTraceOutput_RowDescription(FILE *f, const char *message, int *cursor, bool regress)
Definition fe-trace.c:560
static void pqTraceOutput_GSSResponse(FILE *f, const char *message, int *cursor, int length, bool regress)
Definition fe-trace.c:367
static void pqTraceOutputString(FILE *pfdebug, const char *data, int *cursor, bool suppress)
Definition fe-trace.c:166
static void pqTraceOutput_FunctionCall(FILE *f, const char *message, int *cursor, bool regress)
Definition fe-trace.c:403
static void pqTraceOutput_CopyInResponse(FILE *f, const char *message, int *cursor)
Definition fe-trace.c:429
static void pqTraceOutput_Authentication(FILE *f, const char *message, int *cursor, int length, bool suppress)
Definition fe-trace.c:485
static void pqTraceOutput_Parse(FILE *f, const char *message, int *cursor, bool regress)
Definition fe-trace.c:464
static void pqTraceOutput_NoticeResponse(FILE *f, const char *message, int *cursor, bool regress)
Definition fe-trace.c:346
void PQtrace(PGconn *conn, FILE *debug_port)
Definition fe-trace.c:35
static void pqTraceOutput_ParameterDescription(FILE *f, const char *message, int *cursor, bool regress)
Definition fe-trace.c:548
static void pqTraceOutputNchar(FILE *pfdebug, int len, const char *data, int *cursor, bool suppress)
Definition fe-trace.c:193
static void pqTraceOutput_DataRow(FILE *f, const char *message, int *cursor)
Definition fe-trace.c:293
static void pqTraceOutput_SASLResponse(FILE *f, const char *message, int *cursor, int length, bool regress)
Definition fe-trace.c:395
static void pqTraceOutput_Query(FILE *f, const char *message, int *cursor)
Definition fe-trace.c:478
static void pqTraceOutput_CopyData(FILE *f, const char *message, int *cursor, int length, bool suppress)
Definition fe-trace.c:285
static int pqTraceOutputInt16(FILE *pfdebug, const char *data, int *cursor)
Definition fe-trace.c:126
static void pqTraceOutput_SASLInitialResponse(FILE *f, const char *message, int *cursor, bool regress)
Definition fe-trace.c:382
static void pqTraceOutput_NegotiateProtocolVersion(FILE *f, const char *message, int *cursor)
Definition fe-trace.c:580
static void pqTraceOutput_CopyBothResponse(FILE *f, const char *message, int *cursor, int length)
Definition fe-trace.c:605
static void pqTraceOutput_Bind(FILE *f, const char *message, int *cursor)
Definition fe-trace.c:240
static void pqTraceOutput_ErrorResponse(FILE *f, const char *message, int *cursor, bool regress)
Definition fe-trace.c:340
static void pqTraceOutputNR(FILE *f, const char *type, const char *message, int *cursor, bool regress)
Definition fe-trace.c:320
static void pqTraceOutput_Close(FILE *f, const char *message, int *cursor)
Definition fe-trace.c:270
static void pqTraceOutputByte1(FILE *pfdebug, const char *data, int *cursor)
Definition fe-trace.c:107
static void pqTraceOutput_Describe(FILE *f, const char *message, int *cursor)
Definition fe-trace.c:311
void pqTraceOutputMessage(PGconn *conn, const char *message, bool toServer)
Definition fe-trace.c:625
static void pqTraceOutput_NotificationResponse(FILE *f, const char *message, int *cursor, bool regress)
Definition fe-trace.c:231
static void pqTraceOutput_CommandComplete(FILE *f, const char *message, int *cursor)
Definition fe-trace.c:278
void PQsetTraceFlags(PGconn *conn, int flags)
Definition fe-trace.c:64
static void pqTraceOutput_BackendKeyData(FILE *f, const char *message, int *cursor, int length, bool regress)
Definition fe-trace.c:455
static void pqTraceOutput_ParameterStatus(FILE *f, const char *message, int *cursor)
Definition fe-trace.c:540
static void pqTraceOutput_Execute(FILE *f, const char *message, int *cursor, bool regress)
Definition fe-trace.c:352
void PQuntrace(PGconn *conn)
Definition fe-trace.c:49
static void pqTraceOutput_CopyOutResponse(FILE *f, const char *message, int *cursor)
Definition fe-trace.c:442
static void pqTraceOutput_ReadyForQuery(FILE *f, const char *message, int *cursor)
Definition fe-trace.c:615
static int pqTraceOutputInt32(FILE *pfdebug, const char *data, int *cursor, bool suppress)
Definition fe-trace.c:145
void pqTraceOutputNoTypeByteMessage(PGconn *conn, const char *message)
Definition fe-trace.c:843
void pqTraceOutputCharResponse(PGconn *conn, const char *responseType, char response)
Definition fe-trace.c:918
static void pqTraceFormatTimestamp(char *timestr, size_t ts_len)
Definition fe-trace.c:80
static void pqTraceOutput_CopyFail(FILE *f, const char *message, int *cursor)
Definition fe-trace.c:360
static void pqTraceOutput_PasswordMessage(FILE *f, const char *message, int *cursor)
Definition fe-trace.c:375
static void pqTraceOutput_FunctionCallResponse(FILE *f, const char *message, int *cursor)
Definition fe-trace.c:594
int i
Definition isn.c:77
#define PQTRACE_SUPPRESS_TIMESTAMPS
Definition libpq-fe.h:495
#define PQTRACE_REGRESS_MODE
Definition libpq-fe.h:497
#define AUTH_RESPONSE_PASSWORD
Definition libpq-int.h:338
#define AUTH_RESPONSE_SASL
Definition libpq-int.h:340
#define AUTH_RESPONSE_SASL_INITIAL
Definition libpq-int.h:339
#define AUTH_RESPONSE_GSS
Definition libpq-int.h:337
static struct pg_tm tm
Definition localtime.c:148
#define pg_ntoh32(x)
Definition pg_bswap.h:125
#define pg_ntoh16(x)
Definition pg_bswap.h:124
const void size_t len
const void * data
#define snprintf
Definition port.h:261
#define CANCEL_REQUEST_CODE
Definition pqcomm.h:122
#define NEGOTIATE_GSS_CODE
Definition pqcomm.h:129
#define NEGOTIATE_SSL_CODE
Definition pqcomm.h:128
static int fb(int x)
#define PqMsg_CloseComplete
Definition protocol.h:40
#define AUTH_REQ_SSPI
Definition protocol.h:105
#define AUTH_REQ_SASL_CONT
Definition protocol.h:107
#define PqMsg_CopyDone
Definition protocol.h:64
#define PqMsg_NotificationResponse
Definition protocol.h:41
#define PqMsg_BindComplete
Definition protocol.h:39
#define PqMsg_CopyData
Definition protocol.h:65
#define PqMsg_ParameterDescription
Definition protocol.h:58
#define PqMsg_FunctionCall
Definition protocol.h:23
#define PqMsg_GSSResponse
Definition protocol.h:30
#define AUTH_REQ_GSS
Definition protocol.h:103
#define PqMsg_SASLResponse
Definition protocol.h:33
#define AUTH_REQ_MD5
Definition protocol.h:101
#define PqMsg_Describe
Definition protocol.h:21
#define AUTH_REQ_OK
Definition protocol.h:96
#define PqMsg_FunctionCallResponse
Definition protocol.h:53
#define PqMsg_SASLInitialResponse
Definition protocol.h:32
#define PqMsg_ReadyForQuery
Definition protocol.h:55
#define PqMsg_AuthenticationRequest
Definition protocol.h:50
#define PqMsg_CopyInResponse
Definition protocol.h:45
#define PqMsg_EmptyQueryResponse
Definition protocol.h:47
#define PqMsg_RowDescription
Definition protocol.h:52
#define PqMsg_CopyBothResponse
Definition protocol.h:54
#define PqMsg_ParameterStatus
Definition protocol.h:51
#define PqMsg_NoData
Definition protocol.h:56
#define PqMsg_NegotiateProtocolVersion
Definition protocol.h:59
#define PqMsg_PortalSuspended
Definition protocol.h:57
#define AUTH_REQ_PASSWORD
Definition protocol.h:99
#define AUTH_REQ_GSS_CONT
Definition protocol.h:104
#define PqMsg_Parse
Definition protocol.h:25
#define PqMsg_Bind
Definition protocol.h:19
#define PqMsg_PasswordMessage
Definition protocol.h:31
#define PqMsg_Sync
Definition protocol.h:27
#define PqMsg_CopyFail
Definition protocol.h:29
#define PqMsg_Flush
Definition protocol.h:24
#define PqMsg_BackendKeyData
Definition protocol.h:48
#define PqMsg_CommandComplete
Definition protocol.h:42
#define PqMsg_Query
Definition protocol.h:26
#define PqMsg_ErrorResponse
Definition protocol.h:44
#define PqMsg_DataRow
Definition protocol.h:43
#define AUTH_REQ_SASL
Definition protocol.h:106
#define PqMsg_NoticeResponse
Definition protocol.h:49
#define PqMsg_Terminate
Definition protocol.h:28
#define PqMsg_Execute
Definition protocol.h:22
#define PqMsg_Close
Definition protocol.h:20
#define PqMsg_CopyOutResponse
Definition protocol.h:46
#define AUTH_REQ_SASL_FIN
Definition protocol.h:108
#define PqMsg_ParseComplete
Definition protocol.h:38
PGconn * conn
Definition streamutil.c:52
Definition type.h:139
char current_auth_response
Definition libpq-int.h:526
FILE * Pfdebug
Definition libpq-int.h:453
int traceFlags
Definition libpq-int.h:454
const char * type
int gettimeofday(struct timeval *tp, void *tzp)