From patchwork Mon Oct 14 15:46:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 176257 Delivered-To: patches@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp4682852ill; Mon, 14 Oct 2019 08:46:32 -0700 (PDT) X-Received: by 2002:a1c:804d:: with SMTP id b74mr15976842wmd.170.1571067991977; Mon, 14 Oct 2019 08:46:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571067991; cv=none; d=google.com; s=arc-20160816; b=L5YgUjZd1wgYwQEDRknnDQrMmEs/wPvXFYn1m1/OkfFPswmGO91KLBcRy5fmVZLIp5 JGCo8aW5z+L+Ttov0TLqSGdxnJL2eIrU3UtR3ZQA0q1wk8JFd+m+KXXNaHA0Arvhg/hJ Ls13ndfW6XcD8Wl2Miu9dq5TVXjAdU5FVgmmzwob0H9sU3VNSOCL4Ma2TBMMKUN2wBlP ru2yaad2cGHRGBnBE4TQ9M+q6e9md5StrHcYT7lhsBSsZsujbx2Pk4D+40F1sHAmFvmR kXz0au+CNmmhdcEWA5VXuJgBfSVM2xGb7E15ff2Yw56bFelTUERQq2RfcsfxfkoBxHes IO5w== 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=jevXkkwcX0tlcqUocBLqbbviGRXh0qF+AVQ/mfDGUjk=; b=d8Liqh54gZEUXY7UGt57bsOZtVwYHUY0CTBwLUEylhq/LIuXNMfU2A3jftgsljd21b oiH2O8zj3VJEgf+C77EYCu/wuKOfezx10XZBxKPdjHlTmKFgg1xhymWXROaYZTU7NTPT h/nSxofp8uA9jqhEhsLZXy2XHIXvHvGxq3hEQw3HRGTBcIkoampcppkt2JMLJ4Vd/Zm5 vBdoaUCVSh1pRZ60i9EESLKmZf5o0Ozr7ONDJZMTtzPV2JvaiJrAJ08lZDMUIF4hb+iH hviBg+Yrso0RR3/l37R5qdVScQCe4z/OilMUwBvwS+0cp8IZlMtJwzPtLWzgoVpJVUGf OI+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tI5ziScF; 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 h15sor12068109wrs.31.2019.10.14.08.46.31 for (Google Transport Security); Mon, 14 Oct 2019 08:46:31 -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=tI5ziScF; 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=jevXkkwcX0tlcqUocBLqbbviGRXh0qF+AVQ/mfDGUjk=; b=tI5ziScFn2BLsrXBgfvUTIl08iV6sOgpXr5k+1Pj1kKR3aqoRMExitDKDlLxjX2GXl G59aID6ez6Ymar1kpnivugXNbl5TecFb49b3Ktws91ZWOqgcmaJNJRwT8ouoxOtqjpb4 C+kfoMT7NwZ1NtmjvsF/3fk70DsbnkwPM5OLjjh41VCuOc80tl3zbxCpNDgKBZ5SRUFc wHgqig4h0/LXG/rprIZbvk/Bddsn5CabXMytCxzESJD9PW9sqHjy4BJSTHqTTMA7mFUn pizDZ2FrKM2MSTvISU1Fnq6vbuRj2WcbRrb+TBhldU8aWxhS1vw/piJ7dLP6RDicl3OS hzqw== 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=jevXkkwcX0tlcqUocBLqbbviGRXh0qF+AVQ/mfDGUjk=; b=r7eo2Aob0a/QHtWMA2quX9p6QeLxoaJ+Xk7MkldU1SoSMpBrWeSTp778pYram5heaD J1nZt8y3FKu+kJeIzvAXkdrOgH5JOeIfiO7p3qCxjGg6nMi9grsQ2QYkY4StoMPr/+0c D106nnf25VLeqyXW/04caDmOAOIpS3h6RBsw9nDqFl5kgh4K2TxiP8TNdAp6FOwBmn2Z kujtxA3fZnCRsPdG8I+gPOZTgRK1gGeSWUay4yVD21jVI5lnf18ROHOrABZNB9OlCA90 3YYziKpXQbYDwr5GaUiVaCLmhL6OyV0+b2Gmwh6rBxWMZdWSzHrrwP2NgV8pmAeJ2P78 o8vA== X-Gm-Message-State: APjAAAUNlqAaYpZPm/25DColog5HdNdOkPWvElj+x73MzZhV6r8QeOxo KtuRFCK3LC22Ov6niywRZkxtYnw6o+MdIbP7 X-Google-Smtp-Source: APXvYqwrhpQluePggjAgvaGAIAcAXqpG1HIcFcJRG+3p3ceuWTCqXStrR4+HdCNFx4yifdG69aY9Wg== X-Received: by 2002:adf:ed88:: with SMTP id c8mr7828592wro.214.1571067991501; Mon, 14 Oct 2019 08:46:31 -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 q22sm16539738wmj.5.2019.10.14.08.46.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2019 08:46:30 -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 v3 1/5] kdb: Tidy up code to handle escape sequences Date: Mon, 14 Oct 2019 16:46:22 +0100 Message-Id: <20191014154626.351-2-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191014154626.351-1-daniel.thompson@linaro.org> References: <20191014154626.351-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 Reviewed-by: Douglas Anderson --- kernel/debug/kdb/kdb_io.c | 127 ++++++++++++++++++++------------------ 1 file changed, 66 insertions(+), 61 deletions(-) -- 2.21.0 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 Mon Oct 14 15:46:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 176258 Delivered-To: patches@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp4682865ill; Mon, 14 Oct 2019 08:46:33 -0700 (PDT) X-Received: by 2002:a1c:1f54:: with SMTP id f81mr16268102wmf.142.1571067993169; Mon, 14 Oct 2019 08:46:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571067993; cv=none; d=google.com; s=arc-20160816; b=rJWTunB1yqffX5ryIm4Qf4kdG7clgLbYVxljonAqWnaqIei6DduculIcykUP5xikY4 y0MQQPKp0wRLCfKTTg57gqADvUhvIukho9EXPKWbZa4kOaQDeJtmtWrmLowsAxRqQdyf d39zIRNcyRUN1qPYi+o962o1TJ34Xl5uml12Pxu2BOy9dySGAlmsBEPjm1cyz/YFfxB5 NCpRev/0GzssY+wFdNXlqWvqC9STNNxsEG6eqSToHvXkK79zHa+udBWkruacd5AM6YvI P/+oiqy/mCYm7Tr6G9aBOc82Iy2DMYFRCFpfSvaDcjC9ilmVJFRgxOqFpNvAH8VHSrc2 XcxQ== 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=7kINXNWWBt4SCXZfRMWNijcHokD4yWzFteamr/of+Do=; b=manB9DmLBcBLfkS1Ffn6Z2+biIwCODlaumaU4ZLuWjHJSOpKNV3IO6vKxUfRAuKTEc 7c4/Ki+DpenBTaIdJIA7HEfZjICkL+AUmzq87NVR5ZVaXns0voGdi1QuHhGqXdNuwMHH mBbNWj3LjeNE2FqLpmhQLb+PmHyaq6V0xsy0hxJzyjV5YcsOmTJ3XjseANYlliHD3mvY Ym0lZVgDIliORLdw1SiaT4iIBNMWlW7pPrIi/M/veedosaEYWLSvKaXEIWqse737wqfP D/0U+MtG+mdZuCymIfR4u0gFMbOhRBzZak4P3lYbF+i1fKojk4xsOcU95lK5LhJ5iTyz wGwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wDcXON+1; 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 t1sor12297513wru.46.2019.10.14.08.46.32 for (Google Transport Security); Mon, 14 Oct 2019 08:46:33 -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=wDcXON+1; 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=7kINXNWWBt4SCXZfRMWNijcHokD4yWzFteamr/of+Do=; b=wDcXON+1m4xAvti7aNKoc4cwF+oGVBwBFrv+CuaZGoSXIxoadjTCogRb+8Gi3on6Ph X63WBulioLHClOM0wy48u5QXBnY3CrsffaJ2GHcPloBlVAj++z0zpW/CDqgyaHy5fWTP Pwpdx1VDGTtMbhaW1dOfkNWCcevpdo4dOOOzoIHkYWHV1zahTUyITHbfcmukOpiGFMlO IFRLoBaAzPD07oiavJbvoyFk5kL4bPekWz+AATsk+e/gpmdjWIk/IV5vEINYtMuCVGhC NnEdyHXGWrKNpAucuRa884MReYJfDNCM0GK1o+cHtotwrwIeG9gwhmmf3adlrbyyvx0n 4Sxw== 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=7kINXNWWBt4SCXZfRMWNijcHokD4yWzFteamr/of+Do=; b=SoFP+ge4/tU6AUSlXqMY8wFYQMIZmxegAhkkQw7k5X2cC/Ko3IxB/gW532cCh8uOe/ CgjfPq6LoWx8iQZ5POMixStvYu+79R3lkfwj64s0fnp8I9tOLnLP4Vd1NBREymncbWvp W1ZaN3p6eNVtPJSJhzk0+JPQ+cx52TgFP8mxyzUHk606Ym81U4cRmjHqfXVPWH5+NWDc eQk9fYig9qNLXhilD21uZoi0OHwN/lGLaIIugJ+6zMDZC2zQmwAG6xj3fWQIGFkqOkZH tIFjPG14QBfQ8YHul/08Z1zVrWmm/gnXqjcZLBhfu9tsRACfoRoRRqai18qPfqSigOfn +zNg== X-Gm-Message-State: APjAAAUcpFsX7gXpcGK6AkIGh30m3wHax2QIgiGKR98jxQ8OPgg0crpm QBcSQp8IfmQUZ8x8RFc+ZDoIp6EO X-Google-Smtp-Source: APXvYqy0ovnoys29DS6SHPRM492SOwp8R433s33wX1W4a85GrfH/w2L+Td6L/d9LtZee3kn3EjlN3w== X-Received: by 2002:a5d:4f8b:: with SMTP id d11mr10159794wru.25.1571067992613; Mon, 14 Oct 2019 08:46:32 -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 q22sm16539738wmj.5.2019.10.14.08.46.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2019 08:46:31 -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 v3 2/5] kdb: Simplify code to fetch characters from console Date: Mon, 14 Oct 2019 16:46:23 +0100 Message-Id: <20191014154626.351-3-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191014154626.351-1-daniel.thompson@linaro.org> References: <20191014154626.351-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 Reviewed-by: Douglas Anderson --- kernel/debug/kdb/kdb_io.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) -- 2.21.0 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 Mon Oct 14 15:46:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 176259 Delivered-To: patches@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp4682872ill; Mon, 14 Oct 2019 08:46:34 -0700 (PDT) X-Received: by 2002:a1c:e057:: with SMTP id x84mr15039781wmg.72.1571067994189; Mon, 14 Oct 2019 08:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571067994; cv=none; d=google.com; s=arc-20160816; b=ul1W0WOd1IRNDtE+BGc0uuOh41VVHQ+hFkuhEFndWk/xvvJ+dFcOvXtPp3Z9jNNtfs +CuHoCDuz+EKz3QfFK8FmRiJh1X2Rzci+G0/UgZbgFD+lSSbkf11ExMdCR+UA+G0KEqS JJPw9xBs7D9Kl7HY97bmKnAZpcWrCtYaCWuMoPnhh4aRKTBSbhxiiHQdoXSJsSCdeQ5B i9jjXiMUC/HHhPl4pDzInCa4SFAD/NDtzOhNLhBmrS0bD3ROHoIZJsgOAhz8N6DGp18C AY5Eaks6C8JmezHTrl7l+aRAnGp0WlIQZCEC7e/QUkc0qDJw1RIP/Fe0xr6EM4sY5jYA olPg== 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=VzbHotXa2CNe+yOSdOVLXrQNHA0n+J4DgMTdXlIpchk=; b=EnHnYYJSo0/yRChCnZcOB9GEvJtR4fRQs2e29+unuFWs/PBGycU4nx5kZkFUcBcMzz g2jLyXj21nnlAZelWtI1SqwYc7Vg0Yo78FGAINaDFhyK3VOgYZKvyprtCtXKo7/56ds+ P72BEDMxGOLlACj/SeFawQFq0vzU8J4Zmnx+Oz174+q7vJCZiFtk/StjqLZiZGb+PdVb f1FT3iGH93PwM4jP4FvFjVtkPXWJDrymjGGAtQ06TpDyxpMwFadFj3D9Ne0TJZIsiKIL wXm3BS3ZhAoNmUZ+Lf+yLZx5acmeiILMJ9UMiuZ/bofsCqzcDjkjxWx4eoYa/IoPWPko 6EUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JZ0zW2yk; 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 g189sor10679031wme.12.2019.10.14.08.46.34 for (Google Transport Security); Mon, 14 Oct 2019 08:46:34 -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=JZ0zW2yk; 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=VzbHotXa2CNe+yOSdOVLXrQNHA0n+J4DgMTdXlIpchk=; b=JZ0zW2ykyoUjwTVOOpVM0OAoNndUncqcPcM3iZQM6ogeifeEz5Ud/6+rgPXaf2ClAM Aju0uPZ0zRZ7yhzjv6bkbyZOdyY4YZ9wzITr38I6Ep2kqzIHmW2lghUCTTSrO79faAu0 FgxD8cm+7jGYL5Fvax3e+TvPJ5QAQeXQyV2/2Wisp3nueC1tPXY0djOqPbaueYKxBL0R 9p0fJ2EKJRybayba0NVlzcMwUwEe7eVt3IEzKIQFk2+uxL7yJPpQ4qWGMzvsuzC0sEdr fV8Pjm/CrIrha2kjdoaADiVt+nwaFJb/TEMzvTmasKJgdweqarshhZmJ26o7OrDVJ+Z+ 1vdw== 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=VzbHotXa2CNe+yOSdOVLXrQNHA0n+J4DgMTdXlIpchk=; b=OSmL1R4t1H8EqwSmod1GHiuXTg5XkRphF9zEAsj41jKTO8BXZic7Np2GMNDotGB7oF JX/nPmW80PrTRVddmuVYWKF7GemiQ5bl+lH/tZfb5JnkEp6FcmPYk0GUrXJeamUt4HiP LCDQi/btsVTsR7CsBxdgwrb0pqtZ5K0/9Jk/YHVy3Dkn0c29jzf0oj6JvQCu0HCXTDe3 cRmzWw/5qsICa/ztwapakTTl+KowLy6FtBPpz+tgnXFDI2Z5WByKm2MIFVNJz4ZW7n+p yl3ctis4nWfmune8TFI6SS/jV6+HBrgdgyf/scbDbq+kZyvBwA6sVPCtQAdvYwi5MPhZ rW/g== X-Gm-Message-State: APjAAAWMyMWFmBI1Cv06PgBaKbF6FtSZ4Lw9WC7948xeM7/sT1zAxC1W v69Bw7D73OaliWolu5UR87AES6X0 X-Google-Smtp-Source: APXvYqxE+dOkNfiWJwLl4yuWYmrcDvkahTPo50r3LUg8jfCJu+reTdEf/UpEq1yy6Sv/6BL65hhf8g== X-Received: by 2002:a1c:48d6:: with SMTP id v205mr14942664wma.35.1571067993614; Mon, 14 Oct 2019 08:46:33 -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 q22sm16539738wmj.5.2019.10.14.08.46.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2019 08:46:32 -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 v3 3/5] kdb: Remove special case logic from kdb_read() Date: Mon, 14 Oct 2019 16:46:24 +0100 Message-Id: <20191014154626.351-4-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191014154626.351-1-daniel.thompson@linaro.org> References: <20191014154626.351-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. This does involve some extra code to handle btaprompt properly but we don't mind the new lines of code here because the old code had some interesting problems (bad newline handling, treating unexpected characters like ). Signed-off-by: Daniel Thompson --- kernel/debug/kdb/kdb_bt.c | 22 +++++++---- kernel/debug/kdb/kdb_io.c | 67 +++++++++++++++------------------- kernel/debug/kdb/kdb_private.h | 1 + 3 files changed, 45 insertions(+), 45 deletions(-) -- 2.21.0 Reviewed-by: Douglas Anderson diff --git a/kernel/debug/kdb/kdb_bt.c b/kernel/debug/kdb/kdb_bt.c index 7e2379aa0a1e..b6dc4d7470fd 100644 --- a/kernel/debug/kdb/kdb_bt.c +++ b/kernel/debug/kdb/kdb_bt.c @@ -81,9 +81,10 @@ static int kdb_bt1(struct task_struct *p, unsigned long mask, int argcount, int btaprompt) { - char buffer[2]; - if (kdb_getarea(buffer[0], (unsigned long)p) || - kdb_getarea(buffer[0], (unsigned long)(p+1)-1)) + char ch; + + if (kdb_getarea(ch, (unsigned long)p) || + kdb_getarea(ch, (unsigned long)(p+1)-1)) return KDB_BADADDR; if (!kdb_task_state(p, mask)) return 0; @@ -91,12 +92,17 @@ kdb_bt1(struct task_struct *p, unsigned long mask, kdb_ps1(p); kdb_show_stack(p, NULL); if (btaprompt) { - kdb_getstr(buffer, sizeof(buffer), - "Enter to end, to continue:"); - if (buffer[0] == 'q') { - kdb_printf("\n"); + kdb_printf("Enter to end, or to continue:"); + ch = kdb_getchar(); + while (!strchr("\r\n q", ch)) + ch = kdb_getchar(); + kdb_printf("\n"); + + /* reset the pager */ + kdb_nextline = 1; + + if (ch == 'q') return 1; - } } touch_nmi_watchdog(); return 0; diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 78cb6e339408..39476616295e 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -50,14 +50,14 @@ static int kgdb_transition_check(char *buffer) } /* - * kdb_read_handle_escape + * kdb_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) +static int kdb_handle_escape(char *buf, size_t sz) { char *lastkey = buf + sz - 1; @@ -106,7 +106,22 @@ 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 a kdb console (or consoles). + * + * Other than polling the various consoles that are currently enabled, + * most of the work done in this function is dealing with escape sequences. + * + * 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. + * + * Return: The key pressed or a control code derived from an escape sequence. + */ +char kdb_getchar(void) { #define ESCAPE_UDELAY 1000 #define ESCAPE_DELAY (2*1000000/ESCAPE_UDELAY) /* 2 seconds worth of udelays */ @@ -124,7 +139,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 +148,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; @@ -152,7 +158,7 @@ static int kdb_read_get_key(char *buffer, size_t bufsize) return '\e'; *ped++ = key; - key = kdb_read_handle_escape(escape_data, + key = kdb_handle_escape(escape_data, ped - escape_data); if (key < 0) return '\e'; @@ -183,17 +189,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 +224,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 +735,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 +770,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') { - /* user hit something other than enter */ + } else if (ch) { + /* user hit something unexpected */ 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"); diff --git a/kernel/debug/kdb/kdb_private.h b/kernel/debug/kdb/kdb_private.h index 2118d8258b7c..55d052061ef9 100644 --- a/kernel/debug/kdb/kdb_private.h +++ b/kernel/debug/kdb/kdb_private.h @@ -210,6 +210,7 @@ extern void kdb_ps1(const struct task_struct *p); extern void kdb_print_nameval(const char *name, unsigned long val); extern void kdb_send_sig(struct task_struct *p, int sig); extern void kdb_meminfo_proc_show(void); +extern char kdb_getchar(void); extern char *kdb_getstr(char *, size_t, const char *); extern void kdb_gdb_state_pass(char *buf); From patchwork Mon Oct 14 15:46:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 176260 Delivered-To: patches@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp4682905ill; Mon, 14 Oct 2019 08:46:36 -0700 (PDT) X-Received: by 2002:a5d:51d2:: with SMTP id n18mr26224798wrv.225.1571067996169; Mon, 14 Oct 2019 08:46:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571067996; cv=none; d=google.com; s=arc-20160816; b=vAyXvK5nlALISYuF94QS7BLW5/T3QUfgDMpBkrdkQrtEM3wox1qIaJUX7U3baOygn9 NH4Eej4IjKbno6uXV4sTjOxTHVZgOYdS2d0B6bIkfFA3pOlVDx/RS4r6Vlk0JQEkXbBX vomxqwJf45FAsLPzIDG4a5ToNeBOHWXzdYmJWO0xDC9Nr3EqEoo5TfLXm6VupVN154hP DruH/RUaFVDy2uWG191DvqRtWPmNUrJm9NAc0hmBIY4C7LZ+MO36Co5h2OYtjXwIaku9 VAPECRObkKL6q2dRJN6X1qE3/dSwOpWL9RVfyEyEOsjfbrAhCiGvtS1yRPK+MGEB/lJJ h8LA== 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=NXVuAHcqUdvW3hoXUr87/ZG8r6N5TpAF9zjL4wdSLjs=; b=DLKvtnM8osdQcuG1ATmhAkasl9qjmayLix9ZxrPUdUukK+asMqb3t1SLhitP8r9Xh0 fN6oh9fEglUps8Cr4FTaXaVIckLIbh4D8C6FyR8dZzpy4xShLPKax/eVEsyuQJmYdizf dSLYLn1rt2mmeolAG4xy+t0LeKmhs713NR6A67fg4M9MeV5FjbDnPvq9Ys122W1JZPQD RYCJOP4ONEU6aTCLeoErT1CJVwJxq44nhW8mpe9e+tDOWVm0Nb8cuwZeZX+qagARi5ao vtNjKbDwf9HLEGprSFuG9mqHzGd67XZ/SFYE4hvzYEItFoxCAg3AeBv+IPKcKkRCwSzZ O2Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z0fLFZdi; 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 i11sor12530583wrb.17.2019.10.14.08.46.36 for (Google Transport Security); Mon, 14 Oct 2019 08:46:36 -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=z0fLFZdi; 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=NXVuAHcqUdvW3hoXUr87/ZG8r6N5TpAF9zjL4wdSLjs=; b=z0fLFZdiPdt8jFM79h6y29ec5MdAp59EkR64ijJkc1qehMaqn2x6FJkeo/NnmuHEHk j0o5v8iPg0+KK7JLooF72uFuacfEAcb5FywnYGz7gOgd/bdQjzM6xIdbn517084et/Xp Bq9Xot8YchrJLHTDzrMGZvXI0Q7d5flJhYIIQifqmAN2SKlNNbYDtyYTLoM83wZjUy9M HMEivEnl+VO0Sw0i7PmvinffXtQ6t0u+p+lPg5N9W6YSlxKWX/msc+74g9VSRDOp6Jra Ei0/RMsmyksc/XTq8VdmV1LYgxKtE8T6SUbWEuQ1FrPqweF1N6srFJdGMEz+FfxIRraP 31PA== 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=NXVuAHcqUdvW3hoXUr87/ZG8r6N5TpAF9zjL4wdSLjs=; b=FIMR0/PdNyDpxepj6NLGH0z+rLqMtYQzRQ2MBEIDkNDhs83/48lO2wBOV9zs3zDCWZ hhXlWGOWRWTz+WjODOEaVuMeZQjiRAQJI2GmAZldrVwFgiFO3gnCPRgVBJk3P3gCu8je mil37bjpoOrkoi5FFZuFymFCd0h4YSyTvFR3rKvIHqDkLWBM7cDGiIyIGV/EjeuJxdX6 9ypUGE0LBkVnE6nYGjo9Ez5CeH0d9KaDonoJBfJit1I8XNM4liXCtfnyEego7gux6+HY 3rhPRK6PkDakxM+mK4lUfwDDEBpyzdpyEJsQByBxrTpTleRsgexEwNcWmVVAdmu/Gmd+ dbIw== X-Gm-Message-State: APjAAAWi811lfYDzOkrqr/6uXkPSiG2FHPOmw5cuoIjz2mWwyqH9uwfL yz3IREI4vBXBtZyilgdOTCIv+Zku X-Google-Smtp-Source: APXvYqx5FADHfzYt8ud++1U/l8HJVf0n/fufR09PMBReCszMIQDI28Ic5gABp6oUYxd229QF8PVDnQ== X-Received: by 2002:adf:fa12:: with SMTP id m18mr26744805wrr.248.1571067995742; Mon, 14 Oct 2019 08:46:35 -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 q22sm16539738wmj.5.2019.10.14.08.46.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2019 08:46:34 -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 v3 4/5] kdb: Improve handling of characters from different input sources Date: Mon, 14 Oct 2019 16:46:25 +0100 Message-Id: <20191014154626.351-5-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191014154626.351-1-daniel.thompson@linaro.org> References: <20191014154626.351-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 than the '\e'. This is a bigger refactor than 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 | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 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 39476616295e..f9839566c7d6 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -125,10 +125,10 @@ char 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; + get_char_func *f, *f_prev = NULL; int key; for (f = &kdb_poll_funcs[0]; ; ++f) { @@ -148,27 +148,26 @@ char kdb_getchar(void) continue; } - if (escape_delay == 0 && key == '\e') { + /* + * 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_prev != f) { + f_prev = f; + pbuf = buf; escape_delay = ESCAPE_DELAY; - ped = escape_data; - f_escape = f; - } - if (escape_delay) { - if (f_escape != f) - return '\e'; - - *ped++ = key; - key = kdb_handle_escape(escape_data, - ped - escape_data); - if (key < 0) - return '\e'; - if (key == 0) - continue; } - break; /* A key to process */ + *pbuf++ = key; + key = kdb_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 Mon Oct 14 15:46:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 176261 Delivered-To: patches@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp4682932ill; Mon, 14 Oct 2019 08:46:37 -0700 (PDT) X-Received: by 2002:adf:9bc7:: with SMTP id e7mr28267099wrc.203.1571067997259; Mon, 14 Oct 2019 08:46:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571067997; cv=none; d=google.com; s=arc-20160816; b=b061gwdiNV/bzUNtVn+LKRO6qMn3VQhOM6e5PdlgtilZ8B/tZb3lXQxalUmqhoRw6s rPr3nw4YyAPpa2CLAvSxoYRJXdENmT1IMDDl92h/p7AHYAya7OuE67SAB32G23PoLzUC NZiY5SPdfi4dsc0CTOdp9V+ZeOyDdOlzzT4JUV2X5/Ne4Pcnde4vE84Q2LFCvJpCZiJ3 0xx56/bEGswv5ZY9LGBlGK7/R+cBEVusKgT+4HDKU19AJP0RCSxWC38GvxJh55cIMER9 B9yImgEis+inEjNLtz68S1Zk1egkZeOgXxFllw+scf+a2CyIAL8iIzOzoPdrRVUTMk3O 64vA== 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=1Av3ioNZKtn1IoIkmuPv2cbQ6HyfD+1rS28OweGIOdo=; b=d/OMu2+MtGOYI4BJF1W7s+kR3DxamRGa2+yvHQtJreWFBRa9EIgARC46HiFNDoIAAO jzHixsfHFJsFwCxuViywkPHOZXma+BlN0Dqnt0tSQKp1xPzJNYT6zk/0ACpmugVuqB0f Sg4xMFmF3Mt6GZObh3gfprd3AHN4UYMiQg0qSM9/HyrOi5WircKVKIBLWdwnmvSiaAEY dGdzqoLax9e0dDC6CQO/pZYFt86yj8PXImpKR+wxnU06jl+zssLOSHQwsWreCE8KxsB1 5rZkahN6yp0d4e015b9sbOQD9YshBEgIAse+DYJDqvMcj1e7dCDURSXyaIABIzwIut+M j1gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YM1MA4Ug; 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 i8sor12270030wrp.3.2019.10.14.08.46.37 for (Google Transport Security); Mon, 14 Oct 2019 08:46:37 -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=YM1MA4Ug; 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=1Av3ioNZKtn1IoIkmuPv2cbQ6HyfD+1rS28OweGIOdo=; b=YM1MA4Ug496qhJG5JvBKwtecmdfgxLvwt5inayWrP/lErf4KHykJ7C09zxlGL0sWGR 0BnL+DDPzZ1Ou6v+pY6BgmI+BkfA78ismkjLcC6D2QSxNMhAOLEdIMUDYx5gQLr652V1 uVl2mEp4TXv7sAqmay1F1z/HsX4N4Sr0bs6/d5bYPqBsaHPxgjSDzqufNnCbIUMpKGCp 1ElUPBkbaWpiV8m2jBrqZCkeNk+J4bHJvy0gNwI/KQy3DQ6D+mmqKgIr+F1qwg6I9LOK 9ddvnBHnmgIdnTjWTelfyj2NDxWX2akx+aLMXaYRmYL+10Vwxzpb0Y+5um9HeV4sSNYz hm/A== 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=1Av3ioNZKtn1IoIkmuPv2cbQ6HyfD+1rS28OweGIOdo=; b=r9Mt3c0Bh8mk2Qj6xVcGmkU8xeLGlD51gVXKqObUe8D4VWVptBtX85iQZ+ir7U4hT5 ze2wxSg9IWgAI4cigdbHzqSLrRwpYy8Menjt6SYwQmyiMocEGKtgzmotFj2RsY2ze2nH zOp88GEoxV+3ZZxpEzVJsuJdAnjH6a3hTmeHpXr2+Rm2L6LTW40PBVaudMeS2shQ1tYZ TuV320GjJCPRpJf4d/Pu+NQYhGHunM8B1Okayo7cGsou1H3fAfx2z6G+9m3sEuKH/YkQ 93hlPqrTAtx5Y+fkhDmhPb7ggkydA+zqNnpTwSBtW9ngF5Ovq/jIo2C72zyan8guXZIs vTDw== X-Gm-Message-State: APjAAAVSypuprnBY2mhTgyZysXrtiUrsOuLpxjtp3B8/Roflt2qiyMu+ sURjNH2EiM5+RKUw6KXNJxjCT98i X-Google-Smtp-Source: APXvYqzYJrKpnk39yJydikl6aLQWQKXotCoJvyK9bK+1KGh5xXAPc24eb58KOqbLaiBk+LpAw9+nCQ== X-Received: by 2002:a5d:5271:: with SMTP id l17mr27011147wrc.19.1571067996855; Mon, 14 Oct 2019 08:46:36 -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 q22sm16539738wmj.5.2019.10.14.08.46.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2019 08:46:36 -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 v3 5/5] kdb: Tweak escape handling for vi users Date: Mon, 14 Oct 2019 16:46:26 +0100 Message-Id: <20191014154626.351-6-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191014154626.351-1-daniel.thompson@linaro.org> References: <20191014154626.351-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 Reviewed-by: Douglas Anderson diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index f9839566c7d6..5e71bb2596ed 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -161,8 +161,8 @@ char kdb_getchar(void) *pbuf++ = key; key = kdb_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 ? 1 : 0]; if (key > 0) return key; }