From patchwork Wed Sep 9 14:17:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 249457 Delivered-To: patches@linaro.org Received: by 2002:a92:5b9c:0:0:0:0:0 with SMTP id c28csp459646ilg; Wed, 9 Sep 2020 07:18:06 -0700 (PDT) X-Received: by 2002:a1c:1f41:: with SMTP id f62mr3984811wmf.51.1599661086336; Wed, 09 Sep 2020 07:18:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599661086; cv=none; d=google.com; s=arc-20160816; b=HbZSTEnw6DVODsWUwCJyXdzgDvZ0hS9EzgDfF40azznx5z53xiXeuZ/8E3TPz4VNfa haJFdA8AcrMQLuqbLZoTGd5ElU/4Yr3sX3Qv4kV8OrWZoSxKQXEymIM+m+FKdOnEKDhY Oq7Wbzjmf724hElvCsKuq8h4B2G8JgjJVqtWQTeC4zc7gR+72emX4X2RrZR5j5D1XIiG ApDilY7ifpTXXaSDhO1c0l1MiTXDG6zUJyuYTG77/3OLd4fbcmzy+AmB/IKatrVuIVka A9WcDOxndzNJi4Ndkn6BGCZjeZhfecUJ2q+2U7NIf8TGp7xcZqqTMb9BO1KoVth++7kk /kow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=z9k53vYT+N1BhX48Rij3GUI6/3bZme1pQPIscVRVPBk=; b=jHGsJwzSYOne9SI/V7BAoixGjWmmIGxBJGtAbhJf183QNQtePZv+OSmvjRZvSiW5+I YCPivCZGXMsAUwKcFnHwe6tTgEe+nLWM7pSSqaJ5L8hZikGGIHRVisUBF7RIsXKG54mt h2SnkWBeNEPw+CfGXsx5sBr7LH95KGKrC6VCSoSoN0sk3e3/nN5CiFxqAo3yQW0/VdgS 8iR/KJWFpRSiAWTCZ8twab7Q74gIehon1uC/9YMOlv3I/ymRG1bv4n/oPHUq5jmWofCD vqhkk/LUzgYUS6zXTVcFZZktbMa/7k6uYtLoRX+HNn2bZrTRKtpnZkKmNQzKUhNFvxIP 2UHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=w7pR2L08; 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 j14sor1623337wrr.65.2020.09.09.07.18.06 for (Google Transport Security); Wed, 09 Sep 2020 07:18:06 -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=w7pR2L08; 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:mime-version :content-transfer-encoding; bh=z9k53vYT+N1BhX48Rij3GUI6/3bZme1pQPIscVRVPBk=; b=w7pR2L08zpdeRf35Al+3qzs7BazoxXi4K4IFvtwZqlJyksSS0c7H3PF2KZ2sgSSDpP FujlD1ob/vsHrx5wxZLDonYVVHtcd+AXdHbZfNbNzsCZkbidsTZ+Lr4Nfn2Nd9M9vZBu 6WI2b+ZvoxZ3zrP6nAIC6cjUK0kdYgTnytIoeXk4TNJlyjW7FMxZBxbkvHoOBZ82Zlrd kIL8pIbKnrXxflQBzM8bWpfk3tpF7rBN8mZm195zu+18tAAPCku7Da+vnsHdKAA/FT74 EElHBXICQCjxCOv9+mZ/k2kk1GjvOPKLrcQ7X/wJpKqivHZx1iP9jiI/2aQIvbMhY/jx h32Q== 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:mime-version :content-transfer-encoding; bh=z9k53vYT+N1BhX48Rij3GUI6/3bZme1pQPIscVRVPBk=; b=ulbc5PmbdrNDuSptDp8go+dlYgm1NlouxiS4xXVkbxZK/ET+uj1fygZgdIse6ftkQ6 zu/FnzzHYuIn2ymTijj2RbCH5yRY3qwT0/ABr+6q3hygvv02jUhi+AJfWZzwmPyFNLHm VQPWxGpYYPVRsPANiix245ZCQWFuFUooAOTm4lAUmRBrDiEcZ/nnFy+xBDJAcTr73Ycn vh1gEfv/l6aTqkS+5QOwS3GF33CnUJOOvOy2o6tXpmB5AN9yWpow/BkOOFEAKwsOl49v b3vjj2e0OCQ96WzSSp/TEGIyGV2l7nJlQNxJDvyv9EqjYN8IPS7LdhC5pY7OJJYy91C0 xp3A== X-Gm-Message-State: AOAM531H5gPACjuA29wgX64J+H6yYe9bk28CMA5qDuY27Cwc7zeN/8nc fFXuVG/fy9lgDk1KJEJb3Nh5keDI X-Google-Smtp-Source: ABdhPJzTIAjuCKugtfkjMCZdT9znBSCY0+3Irznm89yqpZg1M9XHZgxPVJURAeXo03ClvT2+A4cCiw== X-Received: by 2002:a5d:5042:: with SMTP id h2mr4138682wrt.409.1599661085905; Wed, 09 Sep 2020 07:18:05 -0700 (PDT) Return-Path: Received: from wychelm.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id q18sm4463736wre.78.2020.09.09.07.18.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 07:18:05 -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] kdb: Fix pager search for multi-line strings Date: Wed, 9 Sep 2020 15:17:08 +0100 Message-Id: <20200909141708.338273-1-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Currently using forward search doesn't handle multi-line strings correctly. The search routine replaces line breaks with \0 during the search and, for regular searches ("help | grep Common\n"), there is code after the line has been discarded or printed to replace the break character. However during a pager search ("help\n" followed by "/Common\n") when the string is matched we will immediately return to normal output and the code that should restore the \n becomes unreachable. Fix this by restoring the replaced character when we disable the search mode and update the comment acordingly. Fixes: fb6daa7520f9d ("kdb: Provide forward search at more prompt") Signed-off-by: Daniel Thompson --- Notes: In the long term the kdb pager code would probably benefit from a bigger rewrite since the way it handles newlines is still quirky and confusing. However this fix is easy to backport so I decided not to hold it back whilst we wait for code that is not yet written. kernel/debug/kdb/kdb_io.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) base-commit: f75aef392f869018f78cfedf3c320a6b3fcfda6b -- 2.25.4 Reviewed-by: Douglas Anderson diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c index 9d847ab851db..e240c97086e2 100644 --- a/kernel/debug/kdb/kdb_io.c +++ b/kernel/debug/kdb/kdb_io.c @@ -706,12 +706,16 @@ int vkdb_printf(enum kdb_msgsrc src, const char *fmt, va_list ap) size_avail = sizeof(kdb_buffer) - len; goto kdb_print_out; } - if (kdb_grepping_flag >= KDB_GREPPING_FLAG_SEARCH) + if (kdb_grepping_flag >= KDB_GREPPING_FLAG_SEARCH) { /* * This was a interactive search (using '/' at more - * prompt) and it has completed. Clear the flag. + * prompt) and it has completed. Replace the \0 with + * its original value to ensure multi-line strings + * are handled properly, and return to normal mode. */ + *cphold = replaced_byte; kdb_grepping_flag = 0; + } /* * at this point the string is a full line and * should be printed, up to the null.