From patchwork Fri Aug 31 20:51:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 145699 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1217054ljw; Fri, 31 Aug 2018 13:52:30 -0700 (PDT) X-Received: by 2002:a1c:385:: with SMTP id 127-v6mr5961520wmd.92.1535748750875; Fri, 31 Aug 2018 13:52:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535748750; cv=none; d=google.com; s=arc-20160816; b=P9x+Y02F9OY6b9hyPqrOFdbQiwAeMamduhSkmPEat4TtmqQdVByZlU3UCnO3ju7Dx+ yzTNSHX6N/rLkNTsFHbZKUqN0eH2PRF0n3e66DU0ZbQ43Mpwz60R/48TdJRPPRsFq3VC YXCTdmR0In6zRGWBi8XUHN/xwpwFJ8ug/f7zBthcc55JuAd0o/ARhMV12n12hAlcsyIW fXJdEMIj91r5KWWrOVt2JvndPmJsynj/mgn5XZl1hBK5FpI4PuOLCCwf94DcyO3mlAun TEuJjt9JN0PrsS1YSveMAsuUyNH04ZrcsE5pZ3BBrhiNyp97WO4w2wm1f3wc3whejkvQ RHpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=SDDwRURgW+9beihRIjWtwTATpIOmHeBgZf9tCXPLsIU=; b=JB4Rp9Qg2AQbg7e2iWGbNe4HoqAbkCrslIliDfosDSyUIFzSizZshAtqbbijHkeqlY z/IbBFqGWPZ8F/xK55xQ7V+zAAzywpERQZmEUc1KsQD8Zriu+tYwUKlbEZ8LqNnvDazS /HATEjiwKhawrYDkTDH5dDulWBwq4lp6B/FYH2qXPpV4w50k6AnKSSmI+1fnXmYtppmp JpTFW9w2uHY3bwTzfU9wihemPjznjSOC/qVyHBjWpUtwPOo7g+x5RGtECa607diMO/M4 RicUbSKkIUYpv+jW2HD6YXN+Jg4V0nsfNFkMUUsxlojZZe8d7XeVyvmo8WKlXVSEhaPG psQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Li8g6ySl; 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 u3-v6sor7762767wrw.12.2018.08.31.13.52.30 for (Google Transport Security); Fri, 31 Aug 2018 13:52:30 -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=Li8g6ySl; 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; bh=SDDwRURgW+9beihRIjWtwTATpIOmHeBgZf9tCXPLsIU=; b=Li8g6ySlDuN5rwxc0TZOM0Q8t7r30Q2vg7GCjfGQICD+y8o78ifgDawvOXmw+vyO8/ 11nzgw260iHZVCRNuA4a1WK9OmME+zrY0m67NA02E1glaVL0OkCa7BveXoCMi0GynMVQ a3Xr2exPhy3TQBTucl9j18vpcFs/DShaUFlS8= 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; bh=SDDwRURgW+9beihRIjWtwTATpIOmHeBgZf9tCXPLsIU=; b=NjLA6kV7UXg13qKD/GBmRqZXvVmbyjNaaGdenz+A1ZAZOg8Yvcy50RyTaAVU9Zh+Hi 0K2I6a7LZneVnYGC6dHykNZ8nG7fMYKNlka8wMgUCi0pqvphYADKpw1V4iaaMP2QnAQD Fmr7c+2DTxtrZuBmC6kvd3vrVzDLOBkaY0c0YaYIJHaib0ufLQi9xob6Oo/wi4LvLi78 Lb49sVNtVE6eLf8CF9JlTzp9/GxJaRMWyqTjiS/fNR1BtatwyMhnVM9eGudmZ61YSJbZ E0jm1jceMfGmYZgoxSrkTqZLBuKf/UTLupUfgVU19g8gEmzltTzT7jNYVXiNxhD1WbrD UuMw== X-Gm-Message-State: APzg51DMZ7lYu34zGWpRKpgFrQ7BGpU8rOdo6JgU0c41kQJKBGbTBfIk id25salrw8qkSfqvl3RuIVGSJ8a2 X-Google-Smtp-Source: ANB0VdYU4aCGAfMh8OLC3OkJYLrKkb7o26RcSC9GE9RDr8RddSd1WAowzpUaG8F7XH+uk79jxnmziQ== X-Received: by 2002:a5d:488c:: with SMTP id g12-v6mr12267068wrq.0.1535748750622; Fri, 31 Aug 2018 13:52:30 -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 u4-v6sm7659356wro.47.2018.08.31.13.52.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 31 Aug 2018 13:52:29 -0700 (PDT) From: Daniel Thompson To: Jason Wessel Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH 1/5] kdb: Tidy up code to handle escape sequences Date: Fri, 31 Aug 2018 21:51:38 +0100 Message-Id: <20180831205142.23609-2-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180831205142.23609-1-daniel.thompson@linaro.org> References: <20180831205142.23609-1-daniel.thompson@linaro.org> 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.17.1 diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index ed5d34925ad0..e54e1e185c47 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 Fri Aug 31 20:51:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 145700 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1217074ljw; Fri, 31 Aug 2018 13:52:32 -0700 (PDT) X-Received: by 2002:a1c:85cb:: with SMTP id h194-v6mr6049914wmd.54.1535748752322; Fri, 31 Aug 2018 13:52:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535748752; cv=none; d=google.com; s=arc-20160816; b=VrtJNv4QGNYpsrqRccqrTcVzTjaORZ3+UyWywyQ3zArMdIlHeY9aTwdnoZJGH0YLXu 13U6YPbPs9oak1E/aTrq/+SveBCiYQnumwQWJAgkhvN27W5vAoqAP9HQ3zw6CEw+eiqW mPlX8i/sTN0c86TD2h/sJ3wWlWXbUDf+vTVeBjJRis/n7LGR9fc8hMo0abn0B/fA8wSE ZE+5Ebjy8VFY7Z/VPBGRy/eUQIOI9IAeuyKjAWJFLJENiI8+NS3+FBWCvfzwjOe88KT1 ClaNA9dgYZoiz1tdlA7JVS3OJYnp9yvoMFAzd2Na/tM2EcSDzWdac8TL4K2G8EUPEqla /vAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HK5LT08ykmG5YwLnjISm/Y2crdQ/7wW+cXZ1BfyQFI8=; b=Y1ReSY9gFmRkPRbRDO3+Y3MRK9QcOdvNAS8Cd3UeyhQoEW8cqaa7ZPBAQJBssHr0ZX uiAB5WLIZPzS0hJipTXx8G94h5lfSmXMh6WjoHpK+ioMWTpHz0GUrahUfI/h5IBW8XGk kdcx+2AaTcZvw4cLeomiqcqk7snEZ4/z7Bgw7rmLNA4ZVa32lwNJvpVYwL+MyLIbz7wq UVvqp4echEhVUuxSLmpShS5OByvY9ZjqDGtGZs1BvFDStujgJtga/mB8ATWY81dWmrqI 0QJCZAHTINYMvcJdh3KWp1cuzvnrEUZwUSCcHbp3LnX8U1/hifOu/b9BDTL6XqtIVIhR wcgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R0hdD9u6; 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 k13-v6sor3192725wmd.18.2018.08.31.13.52.32 for (Google Transport Security); Fri, 31 Aug 2018 13:52:32 -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=R0hdD9u6; 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; bh=HK5LT08ykmG5YwLnjISm/Y2crdQ/7wW+cXZ1BfyQFI8=; b=R0hdD9u6TBA26WHr0G785Fv+iiZjdlo4tQoCdlURoSmI8I5e5471pL1xQ4uATFT7SJ 5MSUZgnlEmfDD8JaxBe81kzMO6iOYcQ2lxZ9Tw8Zezy02EbG7yEoIzRvNHyfdJwc6sfY 73B8keRHLKkH4BSiCoIyvSyXImGjjjnfMXHnM= 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; bh=HK5LT08ykmG5YwLnjISm/Y2crdQ/7wW+cXZ1BfyQFI8=; b=pOWcrYlArFvys4LB3sQnBBWgMMJK0vt4xF8e8Rq3SQYQXtyYrHIvmG0PND7SYr0Qc9 8SR6NuGEupnsifIfzY2THU2Uf007ZDC3OqCh39GO41Djk0ls/2hSbF1Gxc1w/RFurmBN feSQZqYRsFMu0c3bJ/fWp6J1eSIf5USVOfBOXJfb0euSMpNP0A9X+7ybwW+fees44MwI RUMZ252UoBXQVmZX2wcIgV+cTkZO7MF7frw4wWKcleGrG4dvnuAyEorSM7iIySogi/mP c/UJkXQbAU+s4LWlgu1flX5lj+z/1S0zQIZ7GtTV0q+gi+Rikml1wmFR9/5Ce6KJRD3p 3U8Q== X-Gm-Message-State: APzg51Bfqhm/wNd0xvjbZNCauqym0rPu6TFELDofWRwEJd0EccgG9Rzv wYB0HS2RW6GjlsYoM95ogIZ0mP97 X-Google-Smtp-Source: ANB0VdYoDCiDiofGxGikt2RZNgRDt3yxTWAlFjQjqwBKyMgvT5n0EusWgFqJole97bMaRUzoe5mw+g== X-Received: by 2002:a1c:f001:: with SMTP id a1-v6mr6040620wmb.160.1535748751991; Fri, 31 Aug 2018 13:52: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 u4-v6sm7659356wro.47.2018.08.31.13.52.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 31 Aug 2018 13:52:31 -0700 (PDT) From: Daniel Thompson To: Jason Wessel Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH 2/5] kdb: Simplify code to fetch characters from console Date: Fri, 31 Aug 2018 21:51:39 +0100 Message-Id: <20180831205142.23609-3-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180831205142.23609-1-daniel.thompson@linaro.org> References: <20180831205142.23609-1-daniel.thompson@linaro.org> 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.17.1 diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index e54e1e185c47..0ba490728459 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 Fri Aug 31 20:51:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 145701 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1217094ljw; Fri, 31 Aug 2018 13:52:33 -0700 (PDT) X-Received: by 2002:a1c:7915:: with SMTP id l21-v6mr6145342wme.136.1535748753811; Fri, 31 Aug 2018 13:52:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535748753; cv=none; d=google.com; s=arc-20160816; b=C1E06Jw/znH1lsrP5uVwuf/qTd2WYKZZJaYZFLARgBXJTsUJVXzvyEjcZUv7CElA89 FfevtcXsohDorEoaS56qItT7vvevwVEVedsuLtEPTEeXehdbKPLowi5rrlVpv/QRNXyS Sw1UhytTh5gPXaJ+eFXmiv++e5ldczM2Zfr8ZTvP+HQ5ab1Zq+4bf/QjQ3KR1J7faT5+ 7V+7/w79IyxNAOSyJeeKbEOCPNYUMVekJ8sxqekUNkF+VyGRONJc2Zb6i+QtymwftQpF wqd8zv0IHUF6RSHqa1HTflFneQXY3hy7e/85r2a83nB4jzg87dsiQqDCAQNIB2TiQcAP lH0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=DyGBnWZx2nlxc4vEWno/PWe6PjvhGEty03ow5mFqowE=; b=GHt1WBv2BSnrsq/O4Cgm2tiatxyO2JW1S6Ca6RP/GGWF0tX+/CuFt7CMalqZYfdgjR kLMPJb2tCWLtrxqCYRdcX+GyNywQrUyEX7x07h53QnI3rkezcHFplxJ2Gbu6mYBJV46w PjPhL50566JSN6mFW9hL8mDL/TxwGQCCq1bVNn0kwLUlYatvcCFcFS1Mw456V7ntwoOn k0K9CiJPZT7LQ7/qq5uc7f7+3Y0u1eXgy5wL/GrnLIp/2M9XUonFFy3MkHg67l96MxXv Z8wREsfHh+HAcxPppsILxnr2IalBTqVCADKr++TJgTUEYkrR4ig4lekUt1mNbcfJ+5HI Kq5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Fk12/YCz"; 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 m9-v6sor7828119wrw.24.2018.08.31.13.52.33 for (Google Transport Security); Fri, 31 Aug 2018 13:52:33 -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="Fk12/YCz"; 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; bh=DyGBnWZx2nlxc4vEWno/PWe6PjvhGEty03ow5mFqowE=; b=Fk12/YCzY6LvgACPt4jmmXv/w8T70WtF0fKOhYx4a4zaj4ka1srfoi26Cft7l0bSzT Xal7Wf0FngnMl/RFYksLmZRiu0O8e+YbmQBqCpZYC0uRTmIUoUqxvZPaD8Dwn/sufBOE zqr/kb9dw28sm3Nx5X3fh4Fqrc8iAelb8nflM= 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; bh=DyGBnWZx2nlxc4vEWno/PWe6PjvhGEty03ow5mFqowE=; b=j0wx1+ukBpSuJefwJefx0sMQoJKDmIfjH7MIx+tNv+EVYthMyE/SqFGHzQSGLYmMZl eJCIyWL2KZoCeUuMfO280zbzB8BUeYv6bhi4FGIUXY8iUc1LTOX0Wja9lmx5lCLPErCB xErHDmMqCxjBu11q8JiUdohZWUwQ5x4Gmh7NhufiZTDA3ko4B/CgFyVoN8uy1r99ntbW oQZ6BXN2n73S2srnr+TFGOsovIBeepLSBitH49a/2Si4QfFtRfJkpcENK+tTRLL2sKG2 R2o3VeKPT2IywZahvxU/l/Mte0uEK1aIVbs7m/yPVPHOIE86RPSBlHmpZOWNCI60cAOG ydZA== X-Gm-Message-State: APzg51CVFupOJpkbC9Zp9P3GM2v/e9hq68+G7hTzjHzVd3gPv0aFJ6ZY 5WBB77wvKmHwY7TZvsaMUDWNaqyhg5q9pQ== X-Google-Smtp-Source: ANB0VdaBOSnURcAyKixLkescAzgurtV4ZnSwKo2YfbMWneHfqCu3JC+KzERkjn6KVJkoJIv9G+nVNw== X-Received: by 2002:a5d:4a87:: with SMTP id o7-v6mr11265526wrq.132.1535748753541; Fri, 31 Aug 2018 13:52: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 u4-v6sm7659356wro.47.2018.08.31.13.52.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 31 Aug 2018 13:52:32 -0700 (PDT) From: Daniel Thompson To: Jason Wessel Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH 3/5] kdb: Remove special case logic from kdb_read() Date: Fri, 31 Aug 2018 21:51:40 +0100 Message-Id: <20180831205142.23609-4-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180831205142.23609-1-daniel.thompson@linaro.org> References: <20180831205142.23609-1-daniel.thompson@linaro.org> 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.17.1 diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 0ba490728459..f735d859f28b 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) { @@ -738,7 +729,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 @@ -773,39 +764,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 Fri Aug 31 20:51:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 145702 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1217111ljw; Fri, 31 Aug 2018 13:52:35 -0700 (PDT) X-Received: by 2002:a1c:4e16:: with SMTP id g22-v6mr6175521wmh.111.1535748755089; Fri, 31 Aug 2018 13:52:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535748755; cv=none; d=google.com; s=arc-20160816; b=PGn+KRNtLM5Z98kxJ7oP5RgXkaHGRGUK3QcC+bX7m3HqxAyHuY918ssBU5vo3tOq1V Gm4wqEJrYDKEBS1x/bfLHyZ9Szhw/Gx8j+XKKJqRzWYHDZBU2a+L4IjxazsUiFFaQhWA jt5/ovH7sPFa/wdYQk10w89NuPqKRK2OMkPY6nSE5GcfwdBfXPrZmGHQUwUfJ03q8aDv ZTt7YxoCitl0paaR08vArMLXpigfuxIm55pUN/CnslwJZSlWPuR8oOho4jCmVFkXxhBI 7Y16aQMrQHNe/8fM5aqcdpHAh3rFQyPtyYTA2fxVzQkIHVhELg8eDI9vRa7PajSaFYVH whQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=60/OBHwJ0Jhy0mtbYMzYiVyHmch8QP1Vwd6y9Ee0VNU=; b=fLvc5C4AjEMZKDb8GQexF7SWpbAWz5FndHfMCSRjuoeNNJjYOMohd8kfN7tUAo52Ol 8FVn2eNRXrJG6nv8nuQ8GTBTwqc29xCU3hQ5YWq8I4dpW3sYbkuDxWOijocnpmIXykh7 nzCSRb0CEqR2g5xjwePA3AoSD9uCN1EMOIehUIzJBqVhPWhexeSawHeCSdj/ZhLyLbDX 56ZYJM6yV2p1YwNH4BhY/Zlw7p0FQCNb4vU4mgHmm3AtrXsiiRrzm/LVgjkEKQUxw/tD sRi83/9KQnfDqOwp8ij/Iq8CcjJcAqXpBcRqIbqmNPg4D4jeGSaIFU40HtyqyswVoHNR VDVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cKvzXTQe; 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 j65-v6sor3237738wmj.16.2018.08.31.13.52.35 for (Google Transport Security); Fri, 31 Aug 2018 13:52:35 -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=cKvzXTQe; 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; bh=60/OBHwJ0Jhy0mtbYMzYiVyHmch8QP1Vwd6y9Ee0VNU=; b=cKvzXTQefoDzyp7THWxaYvcMxDN+AOPUggGDqy0lqEAM/YoaH0rheUt5vzyebXnEct BMs4+GceVKVjK/QO60yQt2aDWcKs5PG8tTGNmO0HysL7gpPTb6Fr/PJR7qyVmY1Z3si8 Nz9Na229P/uzgnhezmt2dsCkJCCqsArvYtl5M= 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; bh=60/OBHwJ0Jhy0mtbYMzYiVyHmch8QP1Vwd6y9Ee0VNU=; b=rD0HfeXnR8cJGshqW9LlyUvLGQPJNuREgtkT81Myi4rPRTZ0a2ojvTvVeCfm5tsckA ACylI13u852GIjqzwpXT0pDdboH3IleWANVi+RaUx9o7+30p5L+MsSCyEaFKpfW+fc3u zfHXw68kfiB3CZhhQXKAzl/KmkOY+rUL0NZjBNhIBzjcnTBtjSekmiAkLFev+8luLGOy rcxxact2vSFB2WqAWq3dARGfb0pND+Y4/z9dW6WoNjwXjIEbcDaCLGJYj2SIfvxWPJIn zWoLp78YNuD7y9BDGGWHhzpeBRmvYM9VxncNcL10yjIR5B4D8hvmnBgW5OLIrUhOiF3S 1JKg== X-Gm-Message-State: APzg51DrBE7jSKXX8DKdHO2/075s7XsUN6IE5NVPHu+IxT7gvLW/XN/R UYth6OwTHBf3jORtXNLZM1zTrNJu X-Google-Smtp-Source: ANB0VdaNyFdZW0UM9YzaFkjjdNKLuCwn8IBFdRFE+E/39Zn/RFWF71mbEve7rlgIBPnS55O8Z5zcUw== X-Received: by 2002:a1c:ee15:: with SMTP id m21-v6mr1335367wmh.112.1535748754811; Fri, 31 Aug 2018 13:52:34 -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 u4-v6sm7659356wro.47.2018.08.31.13.52.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 31 Aug 2018 13:52:33 -0700 (PDT) From: Daniel Thompson To: Jason Wessel Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH 4/5] kdb: Improve handling of characters from different input sources Date: Fri, 31 Aug 2018 21:51:41 +0100 Message-Id: <20180831205142.23609-5-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180831205142.23609-1-daniel.thompson@linaro.org> References: <20180831205142.23609-1-daniel.thompson@linaro.org> 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 | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) -- 2.17.1 diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index f735d859f28b..8f2470016250 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,22 @@ static int kdb_getchar(void) continue; } - if (escape_delay == 0 && key == '\e') { - escape_delay = ESCAPE_DELAY; - ped = escape_data; + /* Reset state on first character from an input source */ + 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 Fri Aug 31 20:51:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 145703 Delivered-To: patches@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1217137ljw; Fri, 31 Aug 2018 13:52:36 -0700 (PDT) X-Received: by 2002:a1c:6a06:: with SMTP id f6-v6mr5476830wmc.159.1535748756314; Fri, 31 Aug 2018 13:52:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535748756; cv=none; d=google.com; s=arc-20160816; b=kogB9SPR5WgVU8iW7A7mb4IxifC/nXTEKnKiehItkUGboadd9dYNdXGOe6isr4nB9P QAlPOygC2OSM9MSLtQ0z9bDxa47Eg2YwK8lSm6WtZ3FhjlmPo72IQmZnJ6CxEGE29Exk CZ4coTJczdtxclAKU1ZHqGCvbmz3S1cGyVyH9Mwofy58vSst0hVrjq95SOngpUsHzUos 9cbtrTj6yD8LMxeoSi0Du4AEpYkU7OWZMVoRKCrkacSg58s+hmzrFBXvAs0ykCkDo+KW LS7flDwv3uxFWq4yWvAJNf6PZBjro0WglZlZgmhh5rWg4Z1AC/8I88Kavf94zV2fk4xR 6czg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=LFaXeC2Evd+DuiB5BQjy+jnfA9tN+/uH8Nu3cT+zAnw=; b=kx4g722909mYbTnyJ7cvHkat98kZVmNzJpviJx+7x6W3MO95jU7U9k8EAxb7hfDpnM sRno2O+K0O2PO/5Nr/040v7zYgxEF0vMSXX4h9mVlhRd9NqVOj2Xad19Jadwd9HA/dJ8 zFMi/bi5KvODgdiThIztvMvn3vA8YMPJpAQ4CPtQW8bZShcPIhHfOL3HGLa+Oi238ney XbAEskjoUle2pK2X60srZCNw8sZIh7hIMXgUD2U3iY9iP4uzNB+4/F/CWtEl4w6RqaKH JVB8f/yfaT40vSVmkjAFg0uiZ66hzVLTFWpetwKd4zSCLJhyBStW+EZUa4FYjO7OtOX8 FWig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UWAhmCQg; 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 h7-v6sor7706045wru.5.2018.08.31.13.52.36 for (Google Transport Security); Fri, 31 Aug 2018 13:52: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=UWAhmCQg; 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; bh=LFaXeC2Evd+DuiB5BQjy+jnfA9tN+/uH8Nu3cT+zAnw=; b=UWAhmCQgMm/puX4vhN8WFvN8sLKez0w4aDfF1gQeVxVXxl/pbuZ25gNl4oGBKWfa8g o3as7YkCKXgtPdGsut7Ym5b675w8f8MjhecIrEeFJ88zH66zSzSXlRUHYM+79Vup4ERs Z3z5bWDdh9hflFp6HMc9R3Vu1qbOQX5S7SnM8= 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; bh=LFaXeC2Evd+DuiB5BQjy+jnfA9tN+/uH8Nu3cT+zAnw=; b=fXjMyKZn/pVgxYwIXMzXHtDb6hvXxvw14Ixq9xnMwlWhZ6J2S6BCWDJz2928kjGWmJ NnqMPGBIQ0D8OskElyBn33BtsDP8jcvZdqX0K12SXJBIfhX672q1jnPZYRsMaXsKk90F G2kd1/73w7lL+V8IzEJ3qmRNRoPgJL+UkoWs9MaYoQMEfoHBKPzaX809Xu2fA4EJ55/y qSLazAcUfVZEhBd8oSBkugLgXrTkCtkx9nLvkhpaUW500uE6gjB2rYnfINu+YVQIqcU/ raIv6Oj7Ld4+1OAUotYJR5XHBjMDgcvNv/BYYmE77AR+U+SlRKaxAKcA7JDv1SdJlm7c ju4g== X-Gm-Message-State: APzg51C1/4lrOlPv7fq7UwLjtewNVgLt/FFa12tQPKuO7ECid2Q1epUK F77UrqZFjXY0V+CPuDF8F9LP/lLG X-Google-Smtp-Source: ANB0VdZ1SDbAM8r/SmaYtxqLtwonYoylLFOLV89JnQL79LGX+Sppq5t/G+URUogD5AB5MSFqj6IcGg== X-Received: by 2002:adf:9c12:: with SMTP id f18-v6mr12578275wrc.93.1535748756069; Fri, 31 Aug 2018 13:52: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 u4-v6sm7659356wro.47.2018.08.31.13.52.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 31 Aug 2018 13:52:35 -0700 (PDT) From: Daniel Thompson To: Jason Wessel Cc: Daniel Thompson , kgdb-bugreport@lists.sourceforge.net, linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH 5/5] kdb: Tweak escape handling for vi users Date: Fri, 31 Aug 2018 21:51:42 +0100 Message-Id: <20180831205142.23609-6-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180831205142.23609-1-daniel.thompson@linaro.org> References: <20180831205142.23609-1-daniel.thompson@linaro.org> 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.17.1 diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 8f2470016250..6ee8f812d656 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -154,8 +154,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; }