[PATCH 5/6] getch: debugging

Simon Glass sjg at chromium.org
Sat Jun 17 12:49:52 CEST 2023


Signed-off-by: Simon Glass <sjg at chromium.org>
---

 common/cli_getch.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/common/cli_getch.c b/common/cli_getch.c
index 61d4cb261b81..cd44415a9f67 100644
--- a/common/cli_getch.c
+++ b/common/cli_getch.c
@@ -6,8 +6,11 @@
  * Copyright 2022 Google LLC
  */
 
+#define LOG_CATEGORY LOGC_CORE
+
 #include <common.h>
 #include <cli.h>
+#include <log.h>
 
 /**
  * enum cli_esc_state_t - indicates what to do with an escape character
@@ -134,6 +137,8 @@ static int cli_ch_esc(struct cli_ch_state *cch, int ichar,
 
 int cli_ch_process(struct cli_ch_state *cch, int ichar)
 {
+	log_debug(" [ichar=%x, esc_len=%d] ", ichar, cch->esc_len);
+
 	/*
 	 * ichar=0x0 when error occurs in U-Boot getchar() or when the caller
 	 * wants to check if there are more characters saved in the escape
@@ -141,12 +146,18 @@ int cli_ch_process(struct cli_ch_state *cch, int ichar)
 	 */
 	if (!ichar) {
 		if (cch->emitting) {
-			if (cch->emit_upto < cch->esc_len)
-				return cch->esc_save[cch->emit_upto++];
+			if (cch->emit_upto < cch->esc_len) {
+				int ch;
+
+				ch = cch->esc_save[cch->emit_upto++];
+				log_debug(" [->%x] ", ch);
+				return ch;
+			}
 			cch->emit_upto = 0;
 			cch->emitting = false;
 			cch->esc_len = 0;
 		}
+		log_debug(" [->0] ");
 		return 0;
 	} else if (ichar == -ETIMEDOUT) {
 		/*
@@ -156,15 +167,19 @@ int cli_ch_process(struct cli_ch_state *cch, int ichar)
 		 */
 		if (cch->esc_len) {
 			cch->esc_len = 0;
+			log_debug(" [->esc] ");
 			return '\e';
 		}
 
 		/* Otherwise there is nothing to return */
+		log_debug(" [->0] ");
 		return 0;
 	}
 
-	if (ichar == '\n' || ichar == '\r')
+	if (ichar == '\n' || ichar == '\r') {
+		log_debug(" [->nl] ");
 		return '\n';
+	}
 
 	/* handle standard linux xterm esc sequences for arrow key, etc. */
 	if (cch->esc_len != 0) {
@@ -186,6 +201,7 @@ int cli_ch_process(struct cli_ch_state *cch, int ichar)
 			cch->esc_save[cch->esc_len++] = ichar;
 			ichar = cch->esc_save[cch->emit_upto++];
 			cch->emitting = true;
+			log_debug(" [->reject %x] ", ichar);
 			return ichar;
 		case ESC_CONVERTED:
 			/* valid escape sequence, return the resulting char */
@@ -205,5 +221,6 @@ int cli_ch_process(struct cli_ch_state *cch, int ichar)
 		return 0;
 	}
 
+	log_debug(" [->%x] ", ichar);
 	return ichar;
 }
-- 
2.41.0.162.gfafddb0af9-goog



More information about the U-Boot mailing list