From patchwork Fri Oct 25 07:33: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: 177675 Delivered-To: patches@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3285949ill; Fri, 25 Oct 2019 00:33:44 -0700 (PDT) X-Received: by 2002:adf:a497:: with SMTP id g23mr1425173wrb.135.1571988823931; Fri, 25 Oct 2019 00:33:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571988823; cv=none; d=google.com; s=arc-20160816; b=tTQJaYLdClgoGQy4fz0eONx+khtAluaRyFzlOpxl51m9W+ZiPCj72vEdQFpmBUt3GN vJ3tr6XdK5g9gRsBAkOI75HOCnKhmj9cmPoSNZY5+MtXKvMgcTIFSSSocp8Mq+68apPq Xih+VoC7PPrZc+DxJq1aHBIEnHRmvsmRu60qtK2hfivlT/nh/LzAeo5gZEvJRsLPmLMN m3o0rmYJutF4ZMXlpeMDfHsgaY/OYHjjJAvpEC/4BKJnLLKU+KYFIvUTdwow15eqrbk+ irmfywdMNtQRbdEzxoYFoAZ6TF5B8/wx1ET9bWdgchrpJfdDORIZGFI4zI26AWT/G9bk zo6w== 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=K2G9g70k35Ma4xF7YfZ9Z31DwyEbpBEhJM1jJfvb0Ls=; b=jxVKo/55z0zGVi0vhXCh3ar9tqpaLePwId+G15tE3OAjhlkycusTw4otgb8Yk8J2GJ OcFrojFbtipkWZy6tCMpW0Rc55+xLjqdWXAIYZA9Z2Y4WJuqHxuc1j6kmrdXSQHdeHfz RYZ/DDZqMKQq8xgRvLVcuqsI+tEysJfssE57aVsc+fYaaj/IhMvr0vdG0+HDLz9bnDjx rIklCk4bzMyz8JtVHYo5x6cOSEDNjackz0vgIoIZmZAYaVJITCFPCdTkLx8w/QL/jpqK SxFdWytjk8gnaoCOoc5rBBfyB9t2IRYyNR4yueTLGSH6XTmLCnkdeE8Hcjd5um4W2atn RElA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KZPcyclU; 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 b73sor846283wme.6.2019.10.25.00.33.43 for (Google Transport Security); Fri, 25 Oct 2019 00:33:43 -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=KZPcyclU; 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=K2G9g70k35Ma4xF7YfZ9Z31DwyEbpBEhJM1jJfvb0Ls=; b=KZPcyclUjyY3yLuxdwofig+TMKb8hwaV/GkEcAnwSOzk46h9+ITKqyXeyxWpnIrWuX nDy7RdqY/pj3FifZQks815NKfP+KPn5CGujJofWfn2eHvm//5FawiG/ZIE0WF4Q6ZMjf sdgk8LCX96ssM3eihwYzq8pPN44a05KlVGxI2CSWb1d1qxakYWfvCZNsKuzYn4EVhTsQ mNisCKFMW1Nnn9Gw2WZpqru3/5txrIpYVrSwBF09yuJmL6nTE8ixDpPz7n2xANdjYbny 0ZRIWRinykxgRdKuuceIFRIngP4GJhTxKaVt0AU2PoIu1kKP16DK/0x/qNIJJiAooKh7 u/yw== 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=K2G9g70k35Ma4xF7YfZ9Z31DwyEbpBEhJM1jJfvb0Ls=; b=gW6pGAbp4JGLVfYj+vXdnYbyoRn++39trpPm2VwzM9ZsH8DS+W7mxVX5hAQ2w5wgeM HcPvrNdGp6etNwq8vMbY99vvgmweWZ3xNt6UEY16/Menni7mIplmDmej0X3XLMtu8ESZ oiiLVlAGiSONQ2mS/4iwOjavTCPhp0c//T1yH1Ynn5A5z0zk6jpjiRBQKiLAvfYol+5c 7Jy1OT9yznkN0FLAOnZfQDSDOw9FkmyRQJCjrIrTINqws7T1YUGOCt6mwWod6S+J1l08 8WMdLiUroH2/TE6STml9n9IehdECP9c0dioZTyfAoF/riaOPPoY2zWFlXMrT/RnNiSmG 9LTw== X-Gm-Message-State: APjAAAVZK6ZhZ8002kirPQFn/EL/Tbihuulp6BoCacFPVK1tZLvoyT88 EktPdJCEBeEafNr1RtiDAGgyqsRC X-Google-Smtp-Source: APXvYqyz5HgKF726DT+MGAt4cBrrtuTFCrfsKRMpI2Z6psLGtRU1rTjmt7F4Zu6P/chlp+WcoOAfaw== X-Received: by 2002:a1c:1d53:: with SMTP id d80mr1047271wmd.88.1571988823439; Fri, 25 Oct 2019 00:33:43 -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 a11sm1586602wmh.40.2019.10.25.00.33.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2019 00:33:42 -0700 (PDT) From: Daniel Thompson To: Douglas Anderson , Jason Wessel Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v4 1/5] kdb: Tidy up code to handle escape sequences Date: Fri, 25 Oct 2019 08:33:24 +0100 Message-Id: <20191025073328.643-2-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191025073328.643-1-daniel.thompson@linaro.org> References: <20191025073328.643-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 | 128 ++++++++++++++++++++------------------ 1 file changed, 67 insertions(+), 61 deletions(-) -- 2.21.0 diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 3a5184eb6977..cfc054fd8097 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -49,6 +49,65 @@ static int kgdb_transition_check(char *buffer) return 0; } +/** + * kdb_handle_escape() - validity check on an accumulated escape sequence. + * @buf: Accumulated escape characters to be examined. Note that buf + * is not a string, it is an array of characters and need not be + * nil terminated. + * @sz: Number of accumulated escape characters. + * + * Return: -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_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 +161,15 @@ 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_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 Fri Oct 25 07:33: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: 177676 Delivered-To: patches@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3285972ill; Fri, 25 Oct 2019 00:33:45 -0700 (PDT) X-Received: by 2002:a05:6000:142:: with SMTP id r2mr1501426wrx.30.1571988824991; Fri, 25 Oct 2019 00:33:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571988824; cv=none; d=google.com; s=arc-20160816; b=zhT4ClQ3YZSU7p8p7ziSlW3KrT825MyDj71KUaxCym1iTfCwWCRmjJQloWHsoQWqrp z4spnfm3auaqMy6emb5DmjEB3j6Okvbs3gkCg4m1yzeDf9j8tYhiM4BlQtoCout6kAxd PourRO0P9L2jAe4dA9mWsuXQLw3w8NFwGkg/viqKiAqbL0wchxiRyvaSFx8ac9Ekg6Oy fy+SqRJgY/9PzMNsGHVeELz/Jx6v0MwIgRF7lYRyTt76goc9Ho5kRL4zFAUs0FlfOHRR bajGcdMapxdRP3gV5kwLFrFKwGKB3g6IZOOGPDFk8MKWNSqwKjG0n313nM1GmaE6vu8r Qqmg== 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=N2ThTAgeoHW31mlsGh12ha2Pd6KE6BHGLEXeQ2AbFfI=; b=keu7ys+CmEmf5T5C0MkJoM+X1P8cNv/a3JDBU1sMkMFZcsjVlFPpCIrJ9G3LANCavF pCREWzSW5gsZpv5Ffs8xtgZwKIHkL00aDNNcU2aWHpCX6IfHliiTV/ZyDQT/0aL/rAlr +7pWK+ah81HjsiH2RY9njIUf4TtLFZNpz7nxDzoHbRPv0GhHtRsC2wFqu2ifXEAhQ6ij FRDcTPwI+v3cyYDLsfjytY98JOqQm5Pxyz8mv4ve+2+zq230k1MIer2Xutney+FRbHM+ l5Crc96YpNSvhfaoKWx1kDMrWkV/HQ+r/Q7CDJM+0SQo+sz9rxjx4M6TGOMrGkb9o/SP FFOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Cvs9FoyY; 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 s13sor857221wmj.23.2019.10.25.00.33.44 for (Google Transport Security); Fri, 25 Oct 2019 00:33:44 -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=Cvs9FoyY; 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=N2ThTAgeoHW31mlsGh12ha2Pd6KE6BHGLEXeQ2AbFfI=; b=Cvs9FoyYv3MIFrp8WsjkZyLWI7/e8F24s3eJ99R0F1t4im2+jVXGtFQuSpT7wg3scc wsdBc7PXrlNxj22obCjBZy14slZaCxrfheFn1+wmC8Xy1rZaOWc1eQ60VjEYGPp6b/xo iIkWjEJYecuOfoEUGTAsoCrjvgxigmHbtwl2qh4UB2czJI2aNxSxmZ+EedpO2rYEueBe mZWcnRQGeptOqWd2+S6GA59sILp53CTh9fm3jOrMTtjcObFTulfmEGsOM9IQDxcAoRzl j7AIrrWMZL7YrxHf+6bFe9NhFOXQ1RWVWS58lPGPx5ABi9/7dLBYS8ib4dqZ2AQvMOmR d80g== 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=N2ThTAgeoHW31mlsGh12ha2Pd6KE6BHGLEXeQ2AbFfI=; b=nbLpkIsUMHaATSrpXGTVj6SwiustwJepaA3rRUC34ojugrYPFgeITbT2RIKghJptV3 WtCcHl6P+Z+apen7FAYcl58ZYUzX1cD7dJl73pMeQCVcAmZtx+EcreTuxkRMgi4BmepI S5hjScOs0MSZB4fV22U5hoKd0aoR7z5c0ZXjJ0pTzmY53a5cb6LGoKkH0g9UXP9FEnT8 3zDAonDxIeLkn0cUB6acMFCfscerEB5DSxItsEh6EmhMe77b33piUfY0rcrzTdEJdUB1 +4Za8Sut7D1KyTpQigCPn5TTyEijC5ACqnclSSPVeyMH5GdiOjfa23o3p95vw4tXDrvV Y02w== X-Gm-Message-State: APjAAAVZ9OjYoBjV8rtikk6EfVtR8M6qT9cA+rEUwMPJ+6yvJhfVyyVn WGgvHxS0LSnoS1lFtlKLy4IEgtAa X-Google-Smtp-Source: APXvYqwyGKGRjS9F8gjBeH9bcpVse8C1AwyaGfdsUQNKHh5P4Ahfrc9NpXUS5b2AvwtLf8hZ5yKnQw== X-Received: by 2002:a7b:cd89:: with SMTP id y9mr2191028wmj.51.1571988824531; Fri, 25 Oct 2019 00:33:44 -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 a11sm1586602wmh.40.2019.10.25.00.33.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2019 00:33:43 -0700 (PDT) From: Daniel Thompson To: Douglas Anderson , Jason Wessel Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v4 2/5] kdb: Simplify code to fetch characters from console Date: Fri, 25 Oct 2019 08:33:25 +0100 Message-Id: <20191025073328.643-3-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191025073328.643-1-daniel.thompson@linaro.org> References: <20191025073328.643-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 cfc054fd8097..a92ceca29637 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -124,25 +124,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'; @@ -150,27 +143,24 @@ 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_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 Fri Oct 25 07:33: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: 177677 Delivered-To: patches@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3286000ill; Fri, 25 Oct 2019 00:33:46 -0700 (PDT) X-Received: by 2002:a1c:814b:: with SMTP id c72mr2148836wmd.167.1571988826434; Fri, 25 Oct 2019 00:33:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571988826; cv=none; d=google.com; s=arc-20160816; b=1LJXV/GfM2Msb8dZHBqglCPtkQoOPP9t5dtJPzcV97KSh3aLcCTb4HubsoyidZtEVC 3X1sQlXJbw8+7gL0HTHOe0zlK6oV7IoJmsepSPAExXIb7tUNXwcWLEToi6duHPPkA85P a81w9XZRROLuwZfNoFLsrNpwNpj66ZTszns4Zgo15hDungaE6vVxs7SmuDKZzXWaDbLL 6wXeM0EEJ2IxNf87hbWman0ca+6RJnHF9V7HiBn1zXx50FzEgKa7vnks/a1pkbpcNywC KIV/mKG4kiaPCiZt1K9echiLUiYfudsLBCsIPwMlUaDK0fSFwbDdtH7cZ9rFQcTkodUa +RFw== 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=HkL33ZCV1mwKrZNMBrW/BScRmTTWu1ZVGldNocshZY4=; b=gIDphj2qHi7lJk3ya8hMFyBSCDOa3/Cgmsj81YpIc94t+cMeo9PcCNIKesL+UWQ/tq nqD17poEI8GNiIFnfy/yLevCQFuPe+boFxqzxl2imsrslgWDGzKX/8aGcxjZKhmq2dxu O/yyNMj4pvzRBoCLRcfAGFQCSYMo/ujJ93+WdP9KCetHNOYuT4wzysTLXkWXINRRof8O qw1rZ0DLg7kYIb0gRU/LTpbBUnMpKidW+xIG1CpdGfns+G1WIs259k+Be7Jlu41Gkce6 aL+gqvcrIvVpfyhvTfzODPiPL4tMUFb98DS6l+Mo3D3M7AOLoTUVTMGOPh8o5ye+7K6y B/MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wTszrqKW; 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 q22sor872543wmq.2.2019.10.25.00.33.46 for (Google Transport Security); Fri, 25 Oct 2019 00:33:46 -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=wTszrqKW; 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=HkL33ZCV1mwKrZNMBrW/BScRmTTWu1ZVGldNocshZY4=; b=wTszrqKWv+gNXBfniMy1FiAztN7YCmh7vDjZqdoxpIOFlLqeGluOHlfbzgddFxUzEY B9fRk06+mdvGqQU2oHc2mGxcZQ47gdLNRXb5yhNDDBNviXIjlG/X17F0hpWt2sTnK4Wq vzvWARAEOiyKoX+RiSVtyUePPoKtOL2cyS/Zrno0AdPhBwE3kVG+d4vlrr81n6ygvYDV EyVioP88omrz607h9AAE5+DqdCMR9ULnYDhoGxqV5GENf+WC9XoZ0DbKzFDQClcqQMdA ROpdcqIBcbMd1vsYt+7/lJIO4jDcJCpPjMDDAr3SSlJ9MlK4v48adsMsQKaJ1wfvguNt h3Nw== 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=HkL33ZCV1mwKrZNMBrW/BScRmTTWu1ZVGldNocshZY4=; b=NMqivW05dJPCMfujFEgW97Ps0SVvvMem/mDIHMYKyqXkQDIz8EREbWKqQXr017mm7q OepGS9Q7Ji9TS6EAI2x0k3Mo6eo2ToqyIem03ABAruZbb54EAQJTGtafU5S9Mq8cOGI7 wnBuNCG+dbQqhM32E4LNFFaq1xhYnCP8fgqqI3Ez/V/kqrxGTz4IYRTtEhbWa3HnfcQc JtJhs9uZUv8zZUiG/EvEJ34DxNkF3GZLZkfsFqKDneRaLHHelN5BGleWCT7p6P8+BRpe Jlgn8QuuPDc+6gw+6VJHCKYmPtCYwIMF8UBemvXkHlbUojtIoThoWUpiveGChK5ROZko 4a+A== X-Gm-Message-State: APjAAAWCjoWzp2qbgip7EThCnRS9ZWj2Jzvrd+XxvLZri4f06gJ3SObb huuj/Ww9tjVfbC0X0sq0Z5jTMJ/L X-Google-Smtp-Source: APXvYqzQxgiLXS8gY18v0RCvqJDLb12Q1/CRObgkbL362pcH8m+Npf1+Al+yGV7+h05MQImtvA/Vfg== X-Received: by 2002:a1c:41c1:: with SMTP id o184mr2005976wma.57.1571988825822; Fri, 25 Oct 2019 00:33:45 -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 a11sm1586602wmh.40.2019.10.25.00.33.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2019 00:33:45 -0700 (PDT) From: Daniel Thompson To: Douglas Anderson , Jason Wessel Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v4 3/5] kdb: Remove special case logic from kdb_read() Date: Fri, 25 Oct 2019 08:33:26 +0100 Message-Id: <20191025073328.643-4-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191025073328.643-1-daniel.thompson@linaro.org> References: <20191025073328.643-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 Reviewed-by: Douglas Anderson --- kernel/debug/kdb/kdb_bt.c | 22 +++++++----- kernel/debug/kdb/kdb_io.c | 61 +++++++++++++++------------------- kernel/debug/kdb/kdb_private.h | 1 + 3 files changed, 42 insertions(+), 42 deletions(-) -- 2.21.0 diff --git a/kernel/debug/kdb/kdb_bt.c b/kernel/debug/kdb/kdb_bt.c index 7e2379aa0a1e..900187bd666a 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:"); + do { + ch = kdb_getchar(); + } while (!strchr("\r\n q", ch)); + 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 a92ceca29637..9b6933d585b5 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -108,7 +108,22 @@ static int kdb_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 */ @@ -126,7 +141,6 @@ static int kdb_read_get_key(char *buffer, size_t bufsize) } key = (*f)(); - if (key == -1) { if (escape_delay) { udelay(ESCAPE_UDELAY); @@ -136,14 +150,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; @@ -184,17 +190,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) @@ -229,9 +225,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) { @@ -742,7 +736,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 @@ -777,39 +771,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 Fri Oct 25 07:33:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 177678 Delivered-To: patches@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3286020ill; Fri, 25 Oct 2019 00:33:47 -0700 (PDT) X-Received: by 2002:a1c:3b42:: with SMTP id i63mr1926165wma.37.1571988827860; Fri, 25 Oct 2019 00:33:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571988827; cv=none; d=google.com; s=arc-20160816; b=zeBd6AI46qrYqNwM0STL2w9vhHAgWRCEZlRgW+PNE3cH9sxn/iJzG2kkIIP8PTt/J5 rh+rJGCOyEHsc27xNNtjzyUwAfsm34lMGkFNqFKwIN07mNfZ4Kc5SsWDXK2HkqkAjmd5 yqG8P5tI5r8hurF12CWBZbd+JS1bNY6G0KgTr5CZCUeCR5Jr2siqFyVtKBnhIZjksEGH 7uOgIGy6erzgEI5NbasuWIQ5/QT0wF/FrG8YCpmj546ZUa3HD1q4YCaHGWCn29Ge+Gl9 v8vtMHW5VH9/Tnj1PgVOOhap1TwkHXrl1rlrG0dX7hRhLrDJpSL3WLKlPvTdUksrBkXt RLyQ== 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=VxRxdqK8wDgtRtqhN/4fmGim8qsHy1Sh2vs1pQm0S1s=; b=m+qBJ1PilPCaurIW9MUJSa8xrVS8Vr4iIkqbddQSXb+7rY12FphtPj8ABT/88ms/bh NwPlUrmQp9P4JIlAeA/2A45rCO6Qan7rzsBUIq52lmErS+jzcwBgPXAvDvjnNYKdyGl1 5nu/81e9MTpWy4HonV4DkpKo+b2luYW6lquXAktIwFGb7mg1TnNisoG4ecKjO371YarA PW5x8nQt3cyi2NEFK3KHEZq6SmZaTquDUCTNR01CvGoZQIlgO1RotINcgCJakXWnU/qH ZnHhlF01lOzHNRb4rRxHrZrJc3ryw4PMYdnOnrlRflN3+ntPHJBTGiswabQF8k9ETpKI AIlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F5JEpHMe; 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 l14sor738815wru.29.2019.10.25.00.33.47 for (Google Transport Security); Fri, 25 Oct 2019 00:33:47 -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=F5JEpHMe; 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=VxRxdqK8wDgtRtqhN/4fmGim8qsHy1Sh2vs1pQm0S1s=; b=F5JEpHMej8YX8/tXiqp25sBGpi1nHuIwrK/ACEWIlTPQozJML/KptQdG5HGN4mB0mN Dmj9dtiWrZYX+yR4JK3i5Lrw7hKeW+ZMJhTepWlCKmhVeVGbDNAPXVaKRs49ut5Lchs0 pGD2ZDoyvmprP9o6AMdzq9FkIlo5jzFVLmfO6O0XiN/zFuzIo43Ms3rH2k8+GWNv37wk Aq9mXXxRAIzdsuXmoGscnLJrlSDOetxBr+G4c3kWFlddhFxWqp7ShmIBashpCE7vlqNI JqRXHfCVpcFEjLwlJbT8XxvWOLUMeeWwrzIKjnAHNEPWE1XG74iy+9G1Ok8qTXMOQYad KaDA== 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=VxRxdqK8wDgtRtqhN/4fmGim8qsHy1Sh2vs1pQm0S1s=; b=EGeyOcH19hnamNDBYT3wQ/66ccebo+qhqvSylOvOIUANtuCEIG9n/uGgssCtPCSkh5 1Sc2IdHL12kRsP3BaYHrOS5uR7JfN/hhU5ZoUVDxcOefr12r00IUiodBJMjLLmiaP/7F tXfcmpZY+4Bcemwtlc+8CzlMMfo48LdEnB/lrmETUdkT9+Z4m8OhRDUhvGJaqcnSgVpr 46YwCG30LIYwo6K9GtjLQRjRIOmZ9BGq02gW1IQWg0M5brdO6/ppWfcdcPc9qxjIQ4Xg UlUiGtv0WGUPDXGQvV+3iIVYzXd667paZTEWyonrDSmjb1PZIJ4kcmMYtbrBUEDY/nvf fkNQ== X-Gm-Message-State: APjAAAUWFEZYrsN4vaW0SdDxqxvVyI/wBsmFm4Q5oojPbqu4fJEdnfos xcEI2NvT2vTFDrI8bFu7hDm1kRuq X-Google-Smtp-Source: APXvYqwDI5MATscItj7Zxy/MypGFHIa/wSL6G9jo3i0hphS69xVNL/iB2urgVUDMDDWBUq8S5GQmGQ== X-Received: by 2002:a05:6000:118f:: with SMTP id g15mr1440429wrx.242.1571988827402; Fri, 25 Oct 2019 00:33:47 -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 a11sm1586602wmh.40.2019.10.25.00.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2019 00:33:46 -0700 (PDT) From: Daniel Thompson To: Douglas Anderson , Jason Wessel Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v4 4/5] kdb: Improve handling of characters from different input sources Date: Fri, 25 Oct 2019 08:33:27 +0100 Message-Id: <20191025073328.643-5-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191025073328.643-1-daniel.thompson@linaro.org> References: <20191025073328.643-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 Reviewed-by: Douglas Anderson --- kernel/debug/kdb/kdb_io.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) -- 2.21.0 diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 9b6933d585b5..f794c0ca4557 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -127,10 +127,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) { @@ -150,26 +150,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 Fri Oct 25 07:33:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 177679 Delivered-To: patches@linaro.org Received: by 2002:a92:409a:0:0:0:0:0 with SMTP id d26csp3286045ill; Fri, 25 Oct 2019 00:33:49 -0700 (PDT) X-Received: by 2002:adf:f306:: with SMTP id i6mr1424523wro.209.1571988829220; Fri, 25 Oct 2019 00:33:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571988829; cv=none; d=google.com; s=arc-20160816; b=TrdKLUSC2ggb18Bit9XOcHyOiRn6QQ9+vMfToWrUm6q8JSYhdKUvVCNMohYlnE1Urp BEvuIJn2Lfftf/l4CAe2LcfvIhFA1GXhvEQ/Egydq0M4DFdhtorFgHuwxKuxJFetUxHT e4S5EmPGhtdBQ7mC6VzZvsudZ2xmVGxeGm/Tpx7ixb7G8y3EUB7vKBkiN9Ir1m2EU/+N pAQRTN1WdbMKcS/3trj2xsN6s41u2EUb+6g0UxuTHTEwmNyBReFVRAuU0kg3b4GomO0n eEMRCDr1SG1/x7Sb40htcNGPw7TB7xoiTWpuKcxyNp03sFrx4ckQn4Or0oLMf7aI7IaK ttuw== 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=Q37OwpiVtbI5u9x13AdojV2Y5xWX2cctv9qNpKud8OE=; b=ndckHWKoHxxvdHnAJmP0QFLCe3Ci7Sq37FpaSWZVazXC+pkbgekG9/6kAwBL9BbgxQ wKGGpwUwPs63zNU/bdtGfWtXmpz1RHWoPuEPzrAYdrjYUwSirqNDMl9HoXHCzQKhFP6q WagzuuYc/F85pJTlFp2pCnhZEO8C8NCq/GrCHqhonzzZ99bqohX4aW5Nf8InWUkZugi8 y9oXKDQzq1lzNiIv4tVyuE2MqAck25fBUkrdb/eo6lAHp40SP+T80LwH2CND2P8J8U7w bwj2KWILCVvpJVKu3DqiYlKt6KaN4v2wI5QrMzyjfE8ihrBLNaBHd7xtCGQLjH00kLsU oYYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P4LngvYm; 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 a3sor737574wrv.58.2019.10.25.00.33.49 for (Google Transport Security); Fri, 25 Oct 2019 00:33:49 -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=P4LngvYm; 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=Q37OwpiVtbI5u9x13AdojV2Y5xWX2cctv9qNpKud8OE=; b=P4LngvYmSq6jPBLO+72WALO/I5hwPb8wBo/iX++QaE/PGzClMjrelf5trymgeACiL/ YTUcpEXbRYV250IAVK0n1KrbZZ2vDTGOOZ/DFhC10ZjdmHu4t+mfdEEAc8U3RLQOgvpf eTDeWOTe5ETiE4h/Srpkwxp763K0Vjr6b/J51TJzPuHZr1ZBOS3B+hi4ZzCV/MgcQBm1 9Zwm79mjbRVCsi3HBCz5KRqA8fTXJ/NieqY03Zso65gOZJQOeLFaPj7Cmbc+szocGMSD vab+i02s06FO9zY9qYJ2h2W8lCbMo7HLapAZFtjGnfqUuNJYuDVfs+KKClYXNEudclg9 7rRw== 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=Q37OwpiVtbI5u9x13AdojV2Y5xWX2cctv9qNpKud8OE=; b=KZdbSWYMlkyOghvk/NW2xurbgBJYeFzryAEWDqnrNtuz1daxk96B2jUWwS2eg8ppI3 wBK+CwIuLCdZncJ0Ge1pCZCkibwtMD6gc3FpwHHq0YBdJoc2jJSn25YdmDmMiu56nMQ1 6fOFt6u1KdhYGzH+GiPQL3dQZg7LaMo+ySXB3Ai1beWUfAWBfIt03x4QMYYQsSjIyaNK KIKzVwqLvl/76I+aJKg+GrWp8KRWrPcVEWfgsH7yp1TG+lJ2mu4pJpJ/d6Zw3hy180An KMqm1iSHT41tJlqakPDvCaQSFE4obOrBOdlp6cjUfW1aveK6pDMiB6WJFcOcXmyHcrJk H5SA== X-Gm-Message-State: APjAAAV69NXdrUgW4zogJ+cbod3D148oiZwnyo4mVWQHAfAZTiShWs8R 81fPKIGe1mUyOpYmMYhenUl9YaMS X-Google-Smtp-Source: APXvYqxVdg6EGKxAbF8m2sxB498qF0UJFQZ60UmPuvIvhtWcaHsRZj1iamepXusCBxdTqf7khttU6Q== X-Received: by 2002:adf:c402:: with SMTP id v2mr1570013wrf.323.1571988828803; Fri, 25 Oct 2019 00:33:48 -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 a11sm1586602wmh.40.2019.10.25.00.33.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2019 00:33:47 -0700 (PDT) From: Daniel Thompson To: Douglas Anderson , Jason Wessel Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH v4 5/5] kdb: Tweak escape handling for vi users Date: Fri, 25 Oct 2019 08:33:28 +0100 Message-Id: <20191025073328.643-6-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191025073328.643-1-daniel.thompson@linaro.org> References: <20191025073328.643-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 Reviewed-by: Douglas Anderson --- 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 f794c0ca4557..8bcdded5d61f 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -163,8 +163,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; }