Tarantool development patches archive
 help / color / mirror / Atom feed
From: Mergen Imeev via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: v.shpilevoy@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v1 1/1] sql: remove registerTrace() from mem.c
Date: Wed, 24 Nov 2021 15:22:33 +0300	[thread overview]
Message-ID: <2746684244053070165bf106f754866fea02096e.1637756342.git.imeevma@gmail.com> (raw)

This patch changes the way values are displayed in debug information.
---
https://github.com/tarantool/tarantool/issues/3050
https://github.com/tarantool/tarantool/tree/imeevma/gh-3050-drop-registerTrace

 src/box/sql/mem.c  | 119 ---------------------------------------------
 src/box/sql/mem.h  |   3 --
 src/box/sql/vdbe.c |  13 +++--
 3 files changed, 8 insertions(+), 127 deletions(-)

diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c
index 530bde615..b7bf5e892 100644
--- a/src/box/sql/mem.c
+++ b/src/box/sql/mem.c
@@ -2595,125 +2595,6 @@ sqlVdbeCheckMemInvariants(Mem * p)
 	}
 	return 1;
 }
-
-/*
- * Write a nice string representation of the contents of cell pMem
- * into buffer zBuf, length nBuf.
- */
-void
-sqlVdbeMemPrettyPrint(Mem *pMem, char *zBuf)
-{
-	char *zCsr = zBuf;
-	int f = pMem->flags;
-
-	if (pMem->type == MEM_TYPE_BIN) {
-		int i;
-		char c;
-		if ((f & MEM_Static) != 0) {
-			c = 't';
-			assert((f & MEM_Ephem) == 0);
-		} else if (f & MEM_Ephem) {
-			c = 'e';
-			assert((f & MEM_Static) == 0);
-		} else {
-			c = 's';
-		}
-
-		sql_snprintf(100, zCsr, "%c", c);
-		zCsr += sqlStrlen30(zCsr);
-		sql_snprintf(100, zCsr, "%d[", pMem->n);
-		zCsr += sqlStrlen30(zCsr);
-		for(i=0; i<16 && i<pMem->n; i++) {
-			sql_snprintf(100, zCsr, "%02X", ((int)pMem->z[i] & 0xFF));
-			zCsr += sqlStrlen30(zCsr);
-		}
-		for(i=0; i<16 && i<pMem->n; i++) {
-			char z = pMem->z[i];
-			if (z<32 || z>126) *zCsr++ = '.';
-			else *zCsr++ = z;
-		}
-		sql_snprintf(100, zCsr, "]%s", "(8)");
-		zCsr += sqlStrlen30(zCsr);
-		*zCsr = '\0';
-	} else if (pMem->type == MEM_TYPE_STR) {
-		int j, k;
-		zBuf[0] = ' ';
-		if ((f & MEM_Static) != 0) {
-			zBuf[1] = 't';
-			assert((f & MEM_Ephem) == 0);
-		} else if (f & MEM_Ephem) {
-			zBuf[1] = 'e';
-			assert((f & MEM_Static) == 0);
-		} else {
-			zBuf[1] = 's';
-		}
-		k = 2;
-		sql_snprintf(100, &zBuf[k], "%d", pMem->n);
-		k += sqlStrlen30(&zBuf[k]);
-		zBuf[k++] = '[';
-		for(j=0; j<15 && j<pMem->n; j++) {
-			u8 c = pMem->z[j];
-			if (c>=0x20 && c<0x7f) {
-				zBuf[k++] = c;
-			} else {
-				zBuf[k++] = '.';
-			}
-		}
-		zBuf[k++] = ']';
-		sql_snprintf(100,&zBuf[k],"(8)");
-		k += sqlStrlen30(&zBuf[k]);
-		zBuf[k++] = 0;
-	}
-}
-
-/*
- * Print the value of a register for tracing purposes:
- */
-static void
-memTracePrint(Mem *p)
-{
-	switch (p->type) {
-	case MEM_TYPE_NULL:
-		printf(" NULL");
-		return;
-	case MEM_TYPE_INT:
-		printf(" i:%lld", p->u.i);
-		return;
-	case MEM_TYPE_UINT:
-		printf(" u:%"PRIu64"", p->u.u);
-		return;
-	case MEM_TYPE_DOUBLE:
-		printf(" r:%g", p->u.r);
-		return;
-	case MEM_TYPE_INVALID:
-		printf(" undefined");
-		return;
-	case MEM_TYPE_BOOL:
-		printf(" bool:%s", SQL_TOKEN_BOOLEAN(p->u.b));
-		return;
-	case MEM_TYPE_UUID:
-		printf(" uuid:%s", tt_uuid_str(&p->u.uuid));
-		return;
-	case MEM_TYPE_DEC:
-		printf(" decimal:%s", decimal_str(&p->u.d));
-		return;
-	default: {
-		char zBuf[200];
-		sqlVdbeMemPrettyPrint(p, zBuf);
-		printf(" %s", zBuf);
-		if ((p->type & (MEM_TYPE_MAP | MEM_TYPE_ARRAY)) != 0)
-			printf(" subtype=0x%02x", SQL_SUBTYPE_MSGPACK);
-		return;
-	}
-	}
-}
-
-void
-registerTrace(int iReg, Mem *p) {
-	printf("REG[%d] = ", iReg);
-	memTracePrint(p);
-	printf("\n");
-}
 #endif
 
 static int
diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h
index e59f8ea44..ba36d17a7 100644
--- a/src/box/sql/mem.h
+++ b/src/box/sql/mem.h
@@ -784,9 +784,6 @@ mem_mp_type(const struct Mem *mem);
 
 #ifdef SQL_DEBUG
 int sqlVdbeCheckMemInvariants(struct Mem *);
-void sqlVdbeMemPrettyPrint(Mem * pMem, char *zBuf);
-void
-registerTrace(int iReg, Mem *p);
 
 /*
  * Return true if a memory cell is not marked as invalid.  This macro
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 0c4e38557..1d68d387f 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -253,7 +253,8 @@ allocateCursor(
 
 #ifdef SQL_DEBUG
 #  define REGISTER_TRACE(P,R,M)					\
-	if(P->sql_flags&SQL_VdbeTrace) registerTrace(R,M);
+	if ((P->sql_flags & SQL_VdbeTrace) != 0)		\
+		printf("REG[%d] = %s\n", R, mem_str(M));
 #else
 #  define REGISTER_TRACE(P,R,M)
 #endif
@@ -4393,11 +4394,13 @@ default: {          /* This is really OP_Noop and OP_Explain */
 		if ((p->sql_flags & SQL_VdbeTrace) != 0) {
 			u8 opProperty = sqlOpcodeProperty[pOrigOp->opcode];
 			if (rc!=0) printf("rc=%d\n",rc);
-			if (opProperty & (OPFLG_OUT2)) {
-				registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]);
+			if ((opProperty & OPFLG_OUT2) != 0) {
+				REGISTER_TRACE(p, pOrigOp->p2,
+					       &aMem[pOrigOp->p2]);
 			}
-			if (opProperty & OPFLG_OUT3) {
-				registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
+			if ((opProperty & OPFLG_OUT3) != 0) {
+				REGISTER_TRACE(p, pOrigOp->p3,
+					       &aMem[pOrigOp->p3]);
 			}
 		}
 #endif  /* SQL_DEBUG */
-- 
2.25.1


             reply	other threads:[~2021-11-24 12:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-24 12:22 Mergen Imeev via Tarantool-patches [this message]
2021-11-30 21:00 ` Vladislav Shpilevoy via Tarantool-patches
2021-12-01  7:59   ` Mergen Imeev via Tarantool-patches
2021-12-02 23:46     ` Vladislav Shpilevoy via Tarantool-patches
2021-12-03 14:48       ` Mergen Imeev via Tarantool-patches
2021-12-01  8:06 Mergen Imeev via Tarantool-patches
2021-12-02 10:42 ` Kirill Yukhin via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2746684244053070165bf106f754866fea02096e.1637756342.git.imeevma@gmail.com \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v1 1/1] sql: remove registerTrace() from mem.c' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox