From patchwork Tue Oct 8 13:20:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 175494 Delivered-To: patches@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp5695256ill; Tue, 8 Oct 2019 06:21:00 -0700 (PDT) X-Received: by 2002:a7b:cf1a:: with SMTP id l26mr4050570wmg.38.1570540860815; Tue, 08 Oct 2019 06:21:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570540860; cv=none; d=google.com; s=arc-20160816; b=D37F+2cbCJb1G5JQMIyDU4vXAwrpuomOSEGbqWkE5B3A7W+sDRXhMB5JW5R2OxuJUf vWhIEBSPGud3H3PD6MxPErsB5OeUGCGao9onaUMGUjmRqk5YH8FYj+xP6LSEk3jzVzMY hO5vwzCr6YxyPjts0doQTX0v+LBc/BBYP8QZYuKuPF85J67GAnLtDnzTqQelQ1A3J7o8 +qYru0n/72WjWE8Atyi7rbmglGH/FHgYTXW+IXuRyQeOtPxAeH50f0xxyTd5WSb/uuyw EkFEtDMdDxlHQXHprvUYgW3FPYsXEKATb+ErlhUNO2AQId2vGcU6YYQRhGpOOnAByLGt UaYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=8fqv4PyrK6g1lPHnpAokAojNoS9v/RKHcLgZ0jjPkiE=; b=PiCPTYs+t1W19ruGDlaWvi+ADwtS9XYWqVD5rm8ALIJwUXgbu3vnEh+/TbElHQNW8m fY2yMTTpgsiiHfmbSZyEJFiedi+qp2whYmzNPtcbh6mjZDdiICtTIdIinj/oVDH5gVPC Kbu7+TgECL4nRU/+spjngRBMb9ylzOzErv3cAuw/H6VTZhxEzV5Eb69ujNVuE802Ja5v dgiPScxWDAaKTV2p8bqtNf3MDxsfTFTh1fgvVS4R9bqs7OlR871GBaVXEtJqkotkpmu1 4RM/M7R6JJwV5PL64276lfstlMukBL5RKl1iJHB4RjpSBz5e0WRIHnDLXYsAMh9RDMlV P19w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ODVHXP4I; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id a6sor11909463wrs.26.2019.10.08.06.21.00 for (Google Transport Security); Tue, 08 Oct 2019 06:21:00 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ODVHXP4I; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8fqv4PyrK6g1lPHnpAokAojNoS9v/RKHcLgZ0jjPkiE=; b=ODVHXP4IDvSf3+dsD48e/xrpRuCOaDhFwY0ETdD0g+c6W5KI6m9f5yRoSTouZN8Yoa cB9QrWlm2xGRhKVVoBeZZyg4zDzEneA3xVJe9H71eyZaMqEYORdlxcqqgb8mV9mnQyBQ wkGpS65Ls4slhxHIvY/msOGOsyw9cpyhf974IFkicg2q/OrLJCni/+cv8ObjWiPG/cyG wqlLu0tpZaHiCDwX4YbwOAAas61/U8mSvyqhbB/NAsZD/n1cy4GgTxgi3HLRYQgacHu/ XDTPKtBpW8VVmLtKDLcgyCFXphNOPz/jkK12Y7b1CnFhi6H4/bNBk4Z7Euzp4z3OsEnb dzsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8fqv4PyrK6g1lPHnpAokAojNoS9v/RKHcLgZ0jjPkiE=; b=j6GF0SAhcMP+Panx64LHIQDC8UMYvYEfbK5eM5xqWXIN7O/dJBtLEQkktJfpFlWs1o IYf21F7Wh6J6vLxzI/91k/oElJletvT0WlIR4kEhiMWwuwh0nWNHBf/LDsgWxkDAYuIz vR+3Dq4zLULZ6vioqUp3u/8XSpw7VwWsrfuxk7PVGFydguHzWvcBcqzVz4p4BcdskEEW uTX2iRVVcOdv0WpBtN3hTUpFH9LIiUEPkiL5PwdCAJihZrcRa/Rf2tEZ+5HrEmNpWMPg 9L+TWsfqvpMpVb+N3Pr67glEhPjhZFe516e2ttjQ4flx1HRdHaSHnAjsM1NRh6pZppsr iTMA== X-Gm-Message-State: APjAAAXNwroHkuELslVno/qoqVKrDLn3+M4Hjeuj8WQ52kK2vTge967z 4u+6W0UDry9YcaLLXl+Acs7X5SzA X-Google-Smtp-Source: APXvYqyvHhta90BElIHenHWd9+x1QhxfjH3LN4NyrzJGbBqTx/jDrOa/9mKvHs9er1NZWeb6VecSvA== X-Received: by 2002:a5d:5183:: with SMTP id k3mr25134077wrv.55.1570540860341; Tue, 08 Oct 2019 06:21:00 -0700 (PDT) Return-Path: Received: from wychelm.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id t8sm18237214wrx.76.2019.10.08.06.20.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 06:20:59 -0700 (PDT) From: Daniel Thompson To: Jason Wessel , Douglas Anderson Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v2 1/5] kdb: Tidy up code to handle escape sequences Date: Tue, 8 Oct 2019 14:20:39 +0100 Message-Id: <20191008132043.7966-2-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191008132043.7966-1-daniel.thompson@linaro.org> References: <20191008132043.7966-1-daniel.thompson@linaro.org> MIME-Version: 1.0 kdb_read_get_key() has extremely complex break/continue control flow managed by state variables and is very hard to review or modify. In particular the way the escape sequence handling interacts with the general control flow is hard to follow. Separate out the escape key handling, without changing the control flow. This makes the main body of the code easier to review. Signed-off-by: Daniel Thompson --- kernel/debug/kdb/kdb_io.c | 127 ++++++++++++++++++++------------------ 1 file changed, 66 insertions(+), 61 deletions(-) -- 2.21.0 Reviewed-by: Douglas Anderson diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 3a5184eb6977..68e2c29f14f5 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -49,6 +49,63 @@ static int kgdb_transition_check(char *buffer) return 0; } +/* + * kdb_read_handle_escape + * + * Run a validity check on an accumulated escape sequence. + * + * Returns -1 if the escape sequence is unwanted, 0 if it is incomplete, + * otherwise it returns a mapped key value to pass to the upper layers. + */ +static int kdb_read_handle_escape(char *buf, size_t sz) +{ + char *lastkey = buf + sz - 1; + + switch (sz) { + case 1: + if (*lastkey == '\e') + return 0; + break; + + case 2: /* \e */ + if (*lastkey == '[') + return 0; + break; + + case 3: + switch (*lastkey) { + case 'A': /* \e[A, up arrow */ + return 16; + case 'B': /* \e[B, down arrow */ + return 14; + case 'C': /* \e[C, right arrow */ + return 6; + case 'D': /* \e[D, left arrow */ + return 2; + case '1': /* \e[<1,3,4>], may be home, del, end */ + case '3': + case '4': + return 0; + } + break; + + case 4: + if (*lastkey == '~') { + switch (buf[2]) { + case '1': /* \e[1~, home */ + return 1; + case '3': /* \e[3~, del */ + return 4; + case '4': /* \e[4~, end */ + return 5; + } + } + break; + } + + return -1; +} + static int kdb_read_get_key(char *buffer, size_t bufsize) { #define ESCAPE_UDELAY 1000 @@ -102,68 +159,16 @@ static int kdb_read_get_key(char *buffer, size_t bufsize) escape_delay = 2; continue; } - if (ped - escape_data == 1) { - /* \e */ - continue; - } else if (ped - escape_data == 2) { - /* \e */ - if (key != '[') - escape_delay = 2; - continue; - } else if (ped - escape_data == 3) { - /* \e[ */ - int mapkey = 0; - switch (key) { - case 'A': /* \e[A, up arrow */ - mapkey = 16; - break; - case 'B': /* \e[B, down arrow */ - mapkey = 14; - break; - case 'C': /* \e[C, right arrow */ - mapkey = 6; - break; - case 'D': /* \e[D, left arrow */ - mapkey = 2; - break; - case '1': /* dropthrough */ - case '3': /* dropthrough */ - /* \e[<1,3,4>], may be home, del, end */ - case '4': - mapkey = -1; - break; - } - if (mapkey != -1) { - if (mapkey > 0) { - escape_data[0] = mapkey; - escape_data[1] = '\0'; - } - escape_delay = 2; - } - continue; - } else if (ped - escape_data == 4) { - /* \e[<1,3,4> */ - int mapkey = 0; - if (key == '~') { - switch (escape_data[2]) { - case '1': /* \e[1~, home */ - mapkey = 1; - break; - case '3': /* \e[3~, del */ - mapkey = 4; - break; - case '4': /* \e[4~, end */ - mapkey = 5; - break; - } - } - if (mapkey > 0) { - escape_data[0] = mapkey; - escape_data[1] = '\0'; - } - escape_delay = 2; - continue; + + key = kdb_read_handle_escape(escape_data, + ped - escape_data); + if (key > 0) { + escape_data[0] = key; + escape_data[1] = '\0'; } + if (key) + escape_delay = 2; + continue; } break; /* A key to process */ } From patchwork Tue Oct 8 13:20:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 175495 Delivered-To: patches@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp5695270ill; Tue, 8 Oct 2019 06:21:02 -0700 (PDT) X-Received: by 2002:adf:bb0a:: with SMTP id r10mr28074831wrg.13.1570540861970; Tue, 08 Oct 2019 06:21:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570540861; cv=none; d=google.com; s=arc-20160816; b=FQi+YoFEw9Dmoo+RFhZfUx+VDSxTD4vQHqkldGgexsbhn1RuSa1EEtj/bKr0gxrW3o SUAwgEL8j573D0dvXFycaA9LNZKxdnHQeU3iCUjjDmC8N1pdXcU/Uq2oA8PDHKPpXyTn u2NoA4T+opavClhyrdfgHcNM24yL+d8WmluZ0LmkFZ0VFSaczYfT+Jcpcs8Q8BgQ18io IYM76DUAZRG8nnFGBMgYvn7LyFcwKxETni3XU4AsgAJSXSQQl7Ad+/N2jx1xqA8OxHp5 tpDcVFcjj6Luwg7si18KkGFbVPhRuvqsNl36KxARoSlI+sPoNljfSehTueA3tcuhxqiT gvmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=aow4Ms/uS5HYvl47E6APw8x/hPXJ5HEyt9xExUwySdY=; b=wTvUzpx7v7M5nw1TFDLYOpaPmM00XGI+PWD0i0aSF+FkgQFEVHJbJdtrCZ0zzZHrlC CHW7ZnPYVWpG4vz2EQgCmDV/UGU2M7Sat8NUgNFqZnQULvZXNhJECUuU8L+pTAxo8ov3 70tEpD72WW3kFssOlHH3c3pb9xRWfpaHLM1KIZiTLDqaqZVzIK+U5kqKsnE3zoutpu4h ZlznZaml4SS/j1n5JJ91RLZ0J3y7wBV/M1ULh2sR8JlBhn7W60QXewZ9D+oI7jTFkwfP zSboovVsZ9iQ5D1aMAJpMhkq9OSLeLLDpsW4xGHnzxsOtIKmNwuohmkVo4mU50i+inRp D2/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wwNfzBdw; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id r10sor12111022wrx.23.2019.10.08.06.21.01 for (Google Transport Security); Tue, 08 Oct 2019 06:21:01 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wwNfzBdw; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aow4Ms/uS5HYvl47E6APw8x/hPXJ5HEyt9xExUwySdY=; b=wwNfzBdwi+tFi4BAUOyHRxO6sorSM8lVJ0f9OAf/MSR66X2lKs83f5eUB33YApalVX DfbAID5zJHC+4shWyp8zC0I5X7YkdXjVNfcPkPirASMdmdzhHb88bim0n/2batTqVJRv kYf6f/zuRO1fawEMpXrpt5Vcy9AJeeCIMNkIN6DefjZgQuTONg9Ksi85K/qNK8d1fjOd 5Odbk25PcC6sEH/YXIndJQ3+1wr1dhQJ1tlKpH6m9Nz4M6cfo9oAL//ZU0WNas+QuqxW hxPYxi4BPjP2kqJTiBFgC1KlH/wbh1kGeQ+d+qSLmHkzQLK69ZjQzM/6pWFChJh9YXzs a/gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aow4Ms/uS5HYvl47E6APw8x/hPXJ5HEyt9xExUwySdY=; b=BcTwLuH0PDYi27JIK1z8v2q0nBlYhuTzLpx7n0TKjf5F1UcUNKmjG5q6UOq1IMSaaD HQPbpr1685VlqtLqwAuwcEE6b7CHw94BhhEPmZ6MBJsFoHt1GvCpxOgyh/kLeSG5J4ao IBdgv9nITDHg+lopFJVcc5AX5oaJfHFPWLw+PGvjEpD5V+JaXtkjO/YJeE0M3uZFniDq hqpx8mlvony8AZTKEt3N6iI0ur1cbbu0jawBHhFHJwU1OfDLPdnw539JC6QrEOsOca/e CLutSi4dd02rzssI1tyq5Udn+m379khHHQ9lUqMEvFyrt3Gsu5ibz2aT954/BOkpIPdf LFJg== X-Gm-Message-State: APjAAAWQHmWBS87yHFA7uwdB/hFvN4xoOvYg4IPtRIo0doYftYJap1Ox 28Ojw0lFs0yyOHDew1oAU1l/5MSO24FyOkLs X-Google-Smtp-Source: APXvYqyS4GHDWXh8kUnxEPgegNjfoS/nOujwEIaubur1wcA3ko8QUV+4bqOePx6mf8a6cIqbdxBmVQ== X-Received: by 2002:a5d:4c45:: with SMTP id n5mr28870355wrt.100.1570540861496; Tue, 08 Oct 2019 06:21:01 -0700 (PDT) Return-Path: Received: from wychelm.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id t8sm18237214wrx.76.2019.10.08.06.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 06:21:00 -0700 (PDT) From: Daniel Thompson To: Jason Wessel , Douglas Anderson Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v2 2/5] kdb: Simplify code to fetch characters from console Date: Tue, 8 Oct 2019 14:20:40 +0100 Message-Id: <20191008132043.7966-3-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191008132043.7966-1-daniel.thompson@linaro.org> References: <20191008132043.7966-1-daniel.thompson@linaro.org> MIME-Version: 1.0 Currently kdb_read_get_key() contains complex control flow that, on close inspection, turns out to be unnecessary. In particular: 1. It is impossible to enter the branch conditioned on (escape_delay == 1) except when the loop enters with (escape_delay == 2) allowing us to combine the branches. 2. Most of the code conditioned on (escape_delay == 2) simply modifies local data and then breaks out of the loop causing the function to return escape_data[0]. 3. Based on #2 there is not actually any need to ever explicitly set escape_delay to 2 because we it is much simpler to directly return escape_data[0] instead. 4. escape_data[0] is, for all but one exit path, known to be '\e'. Simplify the code based on these observations. There is a subtle (and harmless) change of behaviour resulting from this simplification: instead of letting the escape timeout after ~1998 milliseconds we now timeout after ~2000 milliseconds Signed-off-by: Daniel Thompson --- kernel/debug/kdb/kdb_io.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) -- 2.21.0 Reviewed-by: Douglas Anderson diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 68e2c29f14f5..78cb6e339408 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -122,25 +122,18 @@ static int kdb_read_get_key(char *buffer, size_t bufsize) touch_nmi_watchdog(); f = &kdb_poll_funcs[0]; } - if (escape_delay == 2) { - *ped = '\0'; - ped = escape_data; - --escape_delay; - } - if (escape_delay == 1) { - key = *ped++; - if (!*ped) - --escape_delay; - break; - } + key = (*f)(); + if (key == -1) { if (escape_delay) { udelay(ESCAPE_UDELAY); - --escape_delay; + if (--escape_delay == 0) + return '\e'; } continue; } + if (bufsize <= 2) { if (key == '\r') key = '\n'; @@ -148,28 +141,25 @@ static int kdb_read_get_key(char *buffer, size_t bufsize) *buffer = '\0'; return -1; } + if (escape_delay == 0 && key == '\e') { escape_delay = ESCAPE_DELAY; ped = escape_data; f_escape = f; } if (escape_delay) { - *ped++ = key; - if (f_escape != f) { - escape_delay = 2; - continue; - } + if (f_escape != f) + return '\e'; + *ped++ = key; key = kdb_read_handle_escape(escape_data, ped - escape_data); - if (key > 0) { - escape_data[0] = key; - escape_data[1] = '\0'; - } - if (key) - escape_delay = 2; - continue; + if (key < 0) + return '\e'; + if (key == 0) + continue; } + break; /* A key to process */ } return key; From patchwork Tue Oct 8 13:20:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 175496 Delivered-To: patches@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp5695299ill; Tue, 8 Oct 2019 06:21:03 -0700 (PDT) X-Received: by 2002:a7b:c387:: with SMTP id s7mr3571053wmj.22.1570540863468; Tue, 08 Oct 2019 06:21:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570540863; cv=none; d=google.com; s=arc-20160816; b=ic7EZbQamu7qzVjfiX/Cnz9HJjeQMH8+PCZtPLYCuE93/TUAk6CxhY34lAm3oR0Bu0 myw1Yd8ChLjNX3lJk1vrxn7X+y6uPg6jeycxwykGYrC4xroPpoorOZb1Ck2EyK0ZkxBE pqiFEYHSRS833NQHrRzdPc7+Hn3vTzeWDZ8654/ONONiOJXsx3Go+3jdFrG9y3a0sb9p Z3VaMa8k/BOVh36k8tAWHHKx0vyAg6FnL+O6Zbxl9X5ZnHPkOqcD2oBJsdIaQaW2OG5s hYb82tR23F790Kn5BN2/N+OF73+5ZHae/mER7izJ5eeoiAcj//ak+6CO2mHHvrghQlQf yX1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=NMLYLlRd8vaGiF3jciw9wbZQHk5ZOlFvcl94Sy7qkg4=; b=IT3ON9bjCoBmWopw45RFF/TaIl6S6rZzWoNFXQFVcMrqHWjG7yS3jr5lfb5WODKPHJ C66YKI5BXm/VGsBibFphDLdtkEJx7158kjI7GID7cSz1t7NUya+qGLLW3qSqcg2DUe8K z7FfbCjL3lQ8WDxqWRrONj34e5waVdyaVquTx0+9DRk7MJOArW7omjL4AkeggKqz/gG6 NC+XWYSiQP3OmWGCJF1vzD7YoIWGG0u2qGjvlTfESFTkJ/hbAATFgBA4/ZmjmT4JHaE7 /mjsefy67aEZs5NGXfnlwuQaUCyAk11pt8NfYDYuicCMDGo8tIXCYb8V2XSBdV28lyQA YSow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Xri8FTar; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id u2sor11908362wri.44.2019.10.08.06.21.03 for (Google Transport Security); Tue, 08 Oct 2019 06:21:03 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Xri8FTar; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NMLYLlRd8vaGiF3jciw9wbZQHk5ZOlFvcl94Sy7qkg4=; b=Xri8FTarDkqF/+gVzxi8Z1C8t3l+cY/LBwvDd8AM/lD01TIBPh2Ax8Ye7jrUK5VjUD gJC5tdWhaPPdZCcLfRW4CZjYLAnT17YFEKMw87Q7uUF1i+q1YxE4v/dYeiTh+QgIoNYx FtHyVPPWVXtJH1xRusubfoHJoCZyPBJtES89DoUpdmyV4NlUqRPmurRCMPfoivfs3UhZ GmzFrQZbbXuODOak2XTTxp4GSNJl+ua5nuNUN8sIKKpQvj1XCnArikM/DyMzeVeLej6R J37LpQfeb276fZwkABKDadNJslLGV9TQA3JlBV4xAPaiIRfLytvGobHmf9dMgWBbiIyj WW4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NMLYLlRd8vaGiF3jciw9wbZQHk5ZOlFvcl94Sy7qkg4=; b=D7hfqamMYX7XWIxf4HY6i9B2P8DcUTRQEl/UnaiENWjPLndW2XBDYl/bgcRsFS6FJ/ vhpin0oa8pEVYdecaq+HCs7B99JrB8SD7Gr3DP/OrGAjgngXQw4eoXX/p522Spf66nJB M5pL/4tO2aDM9jGCEqbSDjYAg1qhHf0rrU/mHXy+dqXM/tw/m2JJdj9E/cbcht1XzWLJ 6/eyTB6Sod6uSG7xqhtw6UtwCVsA1CDRB2otbKHjxqUdvDTL/TqsbOfIY21Gl/HXeOuF Qhzvc7OfEr+H6QYrCrSnFNFMSwH7mAxtdoVVLFH6jHuyhxvbIf/W4bjG2pZbvf/jtiEs cqiw== X-Gm-Message-State: APjAAAXw3CUDNrWuoxD9EehRmHGvEm4ArE3gBovIfjwR/bsx7GIsjYM8 +hem8NwNiC/C4y0vrQ+fo3/qDtRn X-Google-Smtp-Source: APXvYqwg7jDYE8hDC+1bJHrrQK5xqAb2IY7xmf6UM3OWEdgwCAq2KjDkHpqihKJYblsyf4uaAwuHvw== X-Received: by 2002:adf:bb0a:: with SMTP id r10mr28074897wrg.13.1570540862771; Tue, 08 Oct 2019 06:21:02 -0700 (PDT) Return-Path: Received: from wychelm.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id t8sm18237214wrx.76.2019.10.08.06.21.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 06:21:01 -0700 (PDT) From: Daniel Thompson To: Jason Wessel , Douglas Anderson Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v2 3/5] kdb: Remove special case logic from kdb_read() Date: Tue, 8 Oct 2019 14:20:41 +0100 Message-Id: <20191008132043.7966-4-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191008132043.7966-1-daniel.thompson@linaro.org> References: <20191008132043.7966-1-daniel.thompson@linaro.org> MIME-Version: 1.0 kdb_read() contains special case logic to force it exit after reading a single character. We can remove all the special case logic by directly calling the function to read a single character instead. This also allows us to tidy up the function prototype which, because it now matches getchar(), we can also rename in order to make its role clearer. Signed-off-by: Daniel Thompson --- kernel/debug/kdb/kdb_io.c | 56 ++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 33 deletions(-) -- 2.21.0 diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 78cb6e339408..a9e73bc9d1c3 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -106,7 +106,19 @@ static int kdb_read_handle_escape(char *buf, size_t sz) return -1; } -static int kdb_read_get_key(char *buffer, size_t bufsize) +/* + * kdb_getchar + * + * Read a single character from kdb console (or consoles). + * + * An escape key could be the start of a vt100 control sequence such as \e[D + * (left arrow) or it could be a character in its own right. The standard + * method for detecting the difference is to wait for 2 seconds to see if there + * are any other characters. kdb is complicated by the lack of a timer service + * (interrupts are off), by multiple input sources. Escape sequence processing + * has to be done as states in the polling loop. + */ +static int kdb_getchar(void) { #define ESCAPE_UDELAY 1000 #define ESCAPE_DELAY (2*1000000/ESCAPE_UDELAY) /* 2 seconds worth of udelays */ @@ -124,7 +136,6 @@ static int kdb_read_get_key(char *buffer, size_t bufsize) } key = (*f)(); - if (key == -1) { if (escape_delay) { udelay(ESCAPE_UDELAY); @@ -134,14 +145,6 @@ static int kdb_read_get_key(char *buffer, size_t bufsize) continue; } - if (bufsize <= 2) { - if (key == '\r') - key = '\n'; - *buffer++ = key; - *buffer = '\0'; - return -1; - } - if (escape_delay == 0 && key == '\e') { escape_delay = ESCAPE_DELAY; ped = escape_data; @@ -183,17 +186,7 @@ static int kdb_read_get_key(char *buffer, size_t bufsize) * function. It is not reentrant - it relies on the fact * that while kdb is running on only one "master debug" cpu. * Remarks: - * - * The buffer size must be >= 2. A buffer size of 2 means that the caller only - * wants a single key. - * - * An escape key could be the start of a vt100 control sequence such as \e[D - * (left arrow) or it could be a character in its own right. The standard - * method for detecting the difference is to wait for 2 seconds to see if there - * are any other characters. kdb is complicated by the lack of a timer service - * (interrupts are off), by multiple input sources and by the need to sometimes - * return after just one key. Escape sequence processing has to be done as - * states in the polling loop. + * The buffer size must be >= 2. */ static char *kdb_read(char *buffer, size_t bufsize) @@ -228,9 +221,7 @@ static char *kdb_read(char *buffer, size_t bufsize) *cp = '\0'; kdb_printf("%s", buffer); poll_again: - key = kdb_read_get_key(buffer, bufsize); - if (key == -1) - return buffer; + key = kdb_getchar(); if (key != 9) tab = 0; switch (key) { @@ -741,7 +732,7 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) /* check for having reached the LINES number of printed lines */ if (kdb_nextline >= linecount) { - char buf1[16] = ""; + char ch; /* Watch out for recursion here. Any routine that calls * kdb_printf will come back through here. And kdb_read @@ -776,39 +767,38 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) if (logging) printk("%s", moreprompt); - kdb_read(buf1, 2); /* '2' indicates to return - * immediately after getting one key. */ + ch = kdb_getchar(); kdb_nextline = 1; /* Really set output line 1 */ /* empty and reset the buffer: */ kdb_buffer[0] = '\0'; next_avail = kdb_buffer; size_avail = sizeof(kdb_buffer); - if ((buf1[0] == 'q') || (buf1[0] == 'Q')) { + if ((ch == 'q') || (ch == 'Q')) { /* user hit q or Q */ KDB_FLAG_SET(CMD_INTERRUPT); /* command interrupted */ KDB_STATE_CLEAR(PAGER); /* end of command output; back to normal mode */ kdb_grepping_flag = 0; kdb_printf("\n"); - } else if (buf1[0] == ' ') { + } else if (ch == ' ') { kdb_printf("\r"); suspend_grep = 1; /* for this recursion */ - } else if (buf1[0] == '\n') { + } else if (ch == '\n' || ch == '\r') { kdb_nextline = linecount - 1; kdb_printf("\r"); suspend_grep = 1; /* for this recursion */ - } else if (buf1[0] == '/' && !kdb_grepping_flag) { + } else if (ch == '/' && !kdb_grepping_flag) { kdb_printf("\r"); kdb_getstr(kdb_grep_string, KDB_GREP_STRLEN, kdbgetenv("SEARCHPROMPT") ?: "search> "); *strchrnul(kdb_grep_string, '\n') = '\0'; kdb_grepping_flag += KDB_GREPPING_FLAG_SEARCH; suspend_grep = 1; /* for this recursion */ - } else if (buf1[0] && buf1[0] != '\n') { + } else if (ch && ch != '\n') { /* user hit something other than enter */ suspend_grep = 1; /* for this recursion */ - if (buf1[0] != '/') + if (ch != '/') kdb_printf( "\nOnly 'q', 'Q' or '/' are processed at " "more prompt, input ignored\n"); From patchwork Tue Oct 8 13:20:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 175497 Delivered-To: patches@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp5695321ill; Tue, 8 Oct 2019 06:21:04 -0700 (PDT) X-Received: by 2002:a17:906:1f43:: with SMTP id d3mr20277637ejk.321.1570540864362; Tue, 08 Oct 2019 06:21:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570540864; cv=none; d=google.com; s=arc-20160816; b=QpcggA1xwjvq15RtVN6eWIXocF52si5yhzZuW7wrt5SqmkBkAz8zZn8CUiUtGDPjvd q9PrYveDtgOcKJhhc2T2B0yKXew9cOHYNbEl7Y6ydzvLKSEF5NBNqWKyiVOhMtN03abs HtZLYVR5M6QTf8RzXhRkRdYO6ezN+JYEsbZKh4LPxDAqavHgdtLqPXuL6yrKNs99vfcP +6g3x2TChro4+Dib8pYKv/GYhH8CQQqv+43AxNmC3GaFW3gCho9zaW+FGDHBse+dftH8 F0tx5avL82p4aqmrvi4h6PmVOSnrANdF1P0EWduDtAN2p3bQWnFN/1/uwGR8s0hRnL+T c2dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=zRFXe3/XZQCUi1W0+GR//OOmf/+747T61SkEsMl88/k=; b=WYz58KEjlONY60VVkg0Gq7Vno7GmIONr+tuEPVwM0x/H7Xb+UjQpEQUGGvBAcgQJZp mwDJu6BGlAwXH2jiP/claiwqr0LttihweYHgUZXaewirBcmKaHVFIQFUNAfodV+HazPU bPbkEOgbOTWkrDem3gCItsNsJqg42ICu1+Z2nbV/D6tcoui/+oqIffBNDHSfUwk9K4Yx naJle7Hxvah+it3hEwHfKW3ZdT9VfvBvjE9kj17cLfb2fUIGJbeB2++/xf+nmxhrE8AI Nab2PKl1yV28MDGJnqXmHnh49eHYMlv4teotegeLJg9w+lQGFYq7lyAYrI4zaDNOv6Nv e5hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tZfC1OM8; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id a26sor5842327ejg.14.2019.10.08.06.21.04 for (Google Transport Security); Tue, 08 Oct 2019 06:21:04 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tZfC1OM8; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zRFXe3/XZQCUi1W0+GR//OOmf/+747T61SkEsMl88/k=; b=tZfC1OM8yntNwmeY8DAkjskgZ4slX04meu2wTKakCs13kvAbXSBqEwTrQ9aC2yuPML OHcDHrf/kxg7FZQc/bw5zY+4gw2NEUUh+Kan7Efd79O7lwR4tYdG5Ez1HZlIt6tnd5g6 RQnyvNGFQZCIWBeImePzvn0xNbkGynWCXxsrKdMTufPSnkx0Nw6NgQD/t19klEMPlGia +hbI4WRCv7GGXO50twrjV6esz8V7EnR3akgbWjXhCwYSEvIvCzJ1AxoPB2Mg/6V1KdUE 19it6wJ7xMQ7755HDqWvENvwa/+R+1Kxtl2IQxVfBH7Tp1Eb6cujDx22F/QNnXvrxBnd zaSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zRFXe3/XZQCUi1W0+GR//OOmf/+747T61SkEsMl88/k=; b=ID5k2h64MA/vWlovf6k+QC8cCDqBlgxewPt+3pVYwS3OhLT2bi5zKlW38QVsOLIfnW 7hnVLCC/XeUli9HMfWRKHLYfP1SfmrDuVE+5K1pBDffglespn7wnRoa14tg+MSNKWwaP 1/Weg9AtUbruGEkohql/c0rGOtHGe2byaJuUJI0hh4fkWZKE+Tsklsj5Zrf85YWh/Koz ISC+U1QH6wMv6yLQzTTQskZMqVtG5162jKVNKg2jj1EdgGQiAWAq10YAwNvgwMskHVHC GMeyV7O9BMT131w8ORfUNpxplg4fnwLuwOwcIlfvA6VBpsa9cry44zk49jk7H0wXOqrv ligw== X-Gm-Message-State: APjAAAWgVFNPkbkrj6bMI/kvge6ccF4++4Do8d3mqCnoKOCNYDqW+riR pnx9gEH14+ZlUEID2gAQwsbQC/S1 X-Google-Smtp-Source: APXvYqwgrNAtVXxMcAt3CGH50mxfEVwuB6vCmi+Ycmt+f/kJStXemqbH+BSDPfEc5kcFu46toPhOYw== X-Received: by 2002:adf:9d87:: with SMTP id p7mr25812577wre.245.1570540863921; Tue, 08 Oct 2019 06:21:03 -0700 (PDT) Return-Path: Received: from wychelm.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id t8sm18237214wrx.76.2019.10.08.06.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 06:21:03 -0700 (PDT) From: Daniel Thompson To: Jason Wessel , Douglas Anderson Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v2 4/5] kdb: Improve handling of characters from different input sources Date: Tue, 8 Oct 2019 14:20:42 +0100 Message-Id: <20191008132043.7966-5-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191008132043.7966-1-daniel.thompson@linaro.org> References: <20191008132043.7966-1-daniel.thompson@linaro.org> MIME-Version: 1.0 Currently if an escape timer is interrupted by a character from a different input source then the new character is discarded and the function returns '\e' (which will be discarded by the level above). It is hard to see why this would ever be the desired behaviour. Fix this to return the new character rather then the '\e'. This is a bigger refactor that might be expected because the new character needs to go through escape sequence detection. Signed-off-by: Daniel Thompson --- kernel/debug/kdb/kdb_io.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) -- 2.21.0 diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index a9e73bc9d1c3..288dd1babf90 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -122,8 +122,8 @@ static int kdb_getchar(void) { #define ESCAPE_UDELAY 1000 #define ESCAPE_DELAY (2*1000000/ESCAPE_UDELAY) /* 2 seconds worth of udelays */ - char escape_data[5]; /* longest vt100 escape sequence is 4 bytes */ - char *ped = escape_data; + char buf[4]; /* longest vt100 escape sequence is 4 bytes */ + char *pbuf = buf; int escape_delay = 0; get_char_func *f, *f_escape = NULL; int key; @@ -145,27 +145,26 @@ static int kdb_getchar(void) continue; } - if (escape_delay == 0 && key == '\e') { - escape_delay = ESCAPE_DELAY; - ped = escape_data; + /* + * When the first character is received (or we get a change + * input source) we set ourselves up to handle an escape + * sequences (just in case). + */ + if (f_escape != f) { f_escape = f; - } - if (escape_delay) { - if (f_escape != f) - return '\e'; - - *ped++ = key; - key = kdb_read_handle_escape(escape_data, - ped - escape_data); - if (key < 0) - return '\e'; - if (key == 0) - continue; + pbuf = buf; + escape_delay = ESCAPE_DELAY; } - break; /* A key to process */ + *pbuf++ = key; + key = kdb_read_handle_escape(buf, pbuf - buf); + if (key < 0) /* no escape sequence; return first character */ + return buf[0]; + if (key > 0) + return key; } - return key; + + unreachable(); } /* From patchwork Tue Oct 8 13:20:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 175498 Delivered-To: patches@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp5695343ill; Tue, 8 Oct 2019 06:21:05 -0700 (PDT) X-Received: by 2002:adf:ed12:: with SMTP id a18mr7784584wro.270.1570540865676; Tue, 08 Oct 2019 06:21:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570540865; cv=none; d=google.com; s=arc-20160816; b=nDWXL0XDUtS5HWfOru3fwSBVEMT8n+h6uG/olHWNn0vrUNiX/kKQWcKpgNC2YESREz +bCKBU26maKOU4GhH9r+r+6veBG6DJzzFRfxAVCCegn7bDt2g4D74kYtu2ztnZ4LOPM5 bDDOs9DaHbygcWH0xRJ2q5Esao0GukqEYPQ8cxm+TR2S7RBNySfQhw+cTdWeZ7sjH78h eF1iXRnk/h0ELgvG+ihn9IWVOwIHW5j4DAc+Igo9eHofnQ0cWVLwrg+Qqvzw0MbiksNW oAbxys9ICQQ6SPLoOy2EfHDGgy31WLgecTNhAfHAHAm0Stp2msFa+PKPirkK/gffbm44 aPCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=4kY29G0Vv0LUgp77TY4nev0SFuE29dpeYRm9kekwuAs=; b=rGDchN9P9/7Wng1pXbbHnWeYF/NuIvHiiKv8L1JomdAcOTu5/owpBPZoi+lAj6DEBS ATAfmzUvK2X6J7y/f390MxAgqubyCvd5wcEFWRAPAwK4G3FxWk4UcZuwDcVPXv2c5k25 cotTdC8UUtpccdrRPZUz/PLtcvMkmPlCNCZVUxaSU+J+jQSNLZHR9E+P75NDdvdpxTn5 M+zIzBfZ97cz1utvBtMHn3ZzySb+gINdxjoZX1vuz+Gbbus0+Qj0+s81llyzFMlg871u Bji0w/dPFvgg4XzzaUeeQdOz/8xoWw/yz7jJCyYd4vit/zyiPJwl5Bk+ErTdO/r2fVji Hy3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y8G5bARZ; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id k6sor11983438wrx.6.2019.10.08.06.21.05 for (Google Transport Security); Tue, 08 Oct 2019 06:21:05 -0700 (PDT) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y8G5bARZ; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4kY29G0Vv0LUgp77TY4nev0SFuE29dpeYRm9kekwuAs=; b=y8G5bARZUMAphF+R/07LfBMyRQOM3WLFLZtB1WmAPqNPLZIXJUU3T+n8svaRVbVXXu fSX0iRlglv3HdI9U7Q0BG/VcvMgxpjLBtlcMUoDlKX06EOjfoI1Yy8KUHuOqyo2WjWP3 1BlNGvTlBgy1WaIf/OMofwgZxax85EDM4giKt1zHyXq8VvaKWpNU8TCcjlngahA/3rTG S6474/ShvWl1Qkw5H2YS++NelF3P9nlTN39EfmLrVTqDDDQvTHEXoXxFWPU8oc323mrS 0rCULt0aSfd+5qQPPs2jb+P37REdOfPhBv4VM663cw+IxpEopgie9YBNUsxqMIiyf766 b4ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4kY29G0Vv0LUgp77TY4nev0SFuE29dpeYRm9kekwuAs=; b=HF0d+CbPbBJRSzD39C8Mcv6G7ZGAGs7SYVs0vN06Ju7Bz6ialwWfj+0xobwMKVYODN KDk1GCXHQJ8r2DLHiY44xyYSUHQo4QyrSsMeq8oBInUJQlUSCAOPCDiuBhhTblQ5xvro Aie9sfzMDNlofXauM+A+tPDUvR7j60j2yExUQR+1BhLI7OTXnMNvf6/gcPzJmbLR2cLv yjHGZ05774OUogboV0Maw4nj+fZtAKSXu6TH8ict1ubRCsCU2JtxRo7IZmOGl7wJsTUf oXz7FtFzzs5Q6QVIn16ujTpfMB6gNfSoXETo8NHfW/Si4zadtgsbnt4JyTuD2NxCRR0N 8itQ== X-Gm-Message-State: APjAAAVF+rF7rUEUoZDxCk1B/xnOM9Kw+YYud2m5hGXXBJMw0TTaiUKo JbO5b0cecZUXGwqf0fqmX8OCQ57Q X-Google-Smtp-Source: APXvYqxNmkd7+lu3m5HT68bq8+K8jXZJIhwyxO8fds7XHqED0zcAr0wrmRONAo9NJoIqfRGy4qAdMA== X-Received: by 2002:adf:f684:: with SMTP id v4mr24398220wrp.155.1570540865110; Tue, 08 Oct 2019 06:21:05 -0700 (PDT) Return-Path: Received: from wychelm.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id t8sm18237214wrx.76.2019.10.08.06.21.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 06:21:04 -0700 (PDT) From: Daniel Thompson To: Jason Wessel , Douglas Anderson Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v2 5/5] kdb: Tweak escape handling for vi users Date: Tue, 8 Oct 2019 14:20:43 +0100 Message-Id: <20191008132043.7966-6-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191008132043.7966-1-daniel.thompson@linaro.org> References: <20191008132043.7966-1-daniel.thompson@linaro.org> MIME-Version: 1.0 Currently if sequences such as "\ehelp\r" are delivered to the console then the h gets eaten by the escape handling code. Since pressing escape becomes something of a nervous twitch for vi users (and that escape doesn't have much effect at a shell prompt) it is more helpful to emit the 'h' than the '\e'. We don't simply choose to emit the final character for all escape sequences since that will do odd things for unsupported escape sequences (in other words we retain the existing behaviour once we see '\e['). Signed-off-by: Daniel Thompson --- kernel/debug/kdb/kdb_io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.21.0 diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 288dd1babf90..b3fb88b1ee34 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -158,8 +158,8 @@ static int kdb_getchar(void) *pbuf++ = key; key = kdb_read_handle_escape(buf, pbuf - buf); - if (key < 0) /* no escape sequence; return first character */ - return buf[0]; + if (key < 0) /* no escape sequence; return best character */ + return buf[pbuf - buf != 2 ? 0 : 1]; if (key > 0) return key; }