Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1325796ybh; Sun, 19 Jul 2020 16:12:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyq900jNILRA+to6DLwvXJevEHxu6a+sU35llFT0df4vYWWXDyvObdZ2zPSoN0rNgk44zz3 X-Received: by 2002:a17:906:2799:: with SMTP id j25mr18371646ejc.466.1595200354596; Sun, 19 Jul 2020 16:12:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595200354; cv=none; d=google.com; s=arc-20160816; b=tPLo8wWiulgBfZxY+aIlQQER7McnHuOeOLFxPCOHQyuJPtLfQCRNVbJVJshTvamn8s mkDJ5LKh9V+2cbpK7maptxxd7JfofpwAeiFcKKPa9a9thZk/aSQvXIZ9e492kcEoEU+g UN6o3V41yxHbTn8WujKjBSXe4j8zRAKYAZshm7N+FiG/Ubf3GYfi2CvwZUI3Dp1Z/Al/ ZdbdOwg9UyuQecEwE/abp6yEM4qM85NgAxstzCefiTuw8K8mMw2+ZWrUkFPeY7Ep7r8r rxd+IaQlEsnjnsEcbibJvwm5jTOt5f0dQRSc6lbTdR5rAicMBq/N6spU2WptS4ZczFyQ ZnSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QII4KCJwf9dMBviArk10YJa+Ll/mKwPyRSRRAQ8I9nQ=; b=iB79+NPh1NprzeziP+PfQBdIa1i3hH1fNOsMeSH19aIDfklWMf0Ex8RQWVqUk6tuy9 vb8kwJJWmMTSVe4FvlSNjh60GIhihBBmJrL8HoReWKTMAtQes75EKGS1gDQfvEzPr+5k jb+o82mt/M0dKUWST0xIVBCyG7LdvSgbRDMWjYgXWDbstz8x7XUV8AWVjCBrgN52qwyH VDCK0vPY9ESLLuse2M79j/ZQECLes2QYca73EpIi0tDKD4UUXlNBffRpspTuxo4x6tMu mK/GUBuMedQPtgkudt2mzMpSqXYIKJK041UhBBWIGDOg/zYJp56wZarSPVsgiywWfXdC oBlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MyZm2z9p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n27si9710209eje.543.2020.07.19.16.12.12; Sun, 19 Jul 2020 16:12:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MyZm2z9p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727065AbgGSXLp (ORCPT + 99 others); Sun, 19 Jul 2020 19:11:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727044AbgGSXLl (ORCPT ); Sun, 19 Jul 2020 19:11:41 -0400 Received: from mail-oo1-xc41.google.com (mail-oo1-xc41.google.com [IPv6:2607:f8b0:4864:20::c41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BDC3C0619D2 for ; Sun, 19 Jul 2020 16:11:41 -0700 (PDT) Received: by mail-oo1-xc41.google.com with SMTP id p26so2839100oos.7 for ; Sun, 19 Jul 2020 16:11:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QII4KCJwf9dMBviArk10YJa+Ll/mKwPyRSRRAQ8I9nQ=; b=MyZm2z9paEHiEIBVHHceHZNoe6oZKEFY3TWQVCHoTqN0shJPXDdp3E6UkRpvndSnER ntIw3e2qzWIEZ1ZdDlwcsVq4bry6GcB/ZS6/6apnTmvNQLLLjLL0lusiTE7nz2cGJlnv doyTke7HxhKjkCaivw8oXpS+nici6cVCT1qZf6V57u+vhnRFjGPi0+90a42W9TdioNfR 0BGLek+AZduzhRB33E55Iognz9bTUgLdFqZmMQ/IXAQlHGcqKoETndtRjUWY/IxoKX/Y UYlRmBJ493tWnws1ABP+K7JpQRkLYDQAavOOIaHm6kFo9h877lVEYvrJgG5Ngptd6P2W 3Inw== 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=QII4KCJwf9dMBviArk10YJa+Ll/mKwPyRSRRAQ8I9nQ=; b=JKuaTGvMNgpA3jnH2AXgQtAfaczgWD3o8oml2Jdv04tr64f3EPtKBO9ZulfrXu2vLY sfY/jbEuz0GxnOZVRo24SBig7QeC2cLiTo5cnHzutGK7ymfeDIdXnsisFzB1IcxOySXA IpSooyVx+nErmBLlfrVghVbW14cRET9XaX6nF5E5vk1RkPxGQbJfQHqOQFOHrDVo+Bzl IxXSLs+PzJ4k7e/qxztocTTHaICvgYJZqQhKCncP4Lhl+X/RWSmz1JsfRZ/7ZEwNzm8o X6d+SjVuVzUFYSmNhAco20gaIFzP5ppNGQlgwSPBn61uTtsHZ1FmYaPELj+RXiIaSPYk J0lg== X-Gm-Message-State: AOAM531YvXob681ZIj0oQuad0N9F9lWFDa0WZCDiGTFQXxnNLOsFgPga B8mNmrS7GjkuExhyPJzWOko= X-Received: by 2002:a4a:86c3:: with SMTP id y3mr17345911ooh.31.1595200300752; Sun, 19 Jul 2020 16:11:40 -0700 (PDT) Received: from frodo.hsd1.co.comcast.net ([2601:284:8204:6ba0::5e16]) by smtp.googlemail.com with ESMTPSA id q19sm2394680ooi.14.2020.07.19.16.11.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jul 2020 16:11:40 -0700 (PDT) From: Jim Cromie To: jbaron@akamai.com, linux-kernel@vger.kernel.org, akpm@linuxfoundation.org, gregkh@linuxfoundation.org Cc: linux@rasmusvillemoes.dk, Jim Cromie Subject: [PATCH v5 12/18] dyndbg: refactor parse_linerange out of ddebug_parse_query Date: Sun, 19 Jul 2020 17:10:52 -0600 Message-Id: <20200719231058.1586423-13-jim.cromie@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200719231058.1586423-1-jim.cromie@gmail.com> References: <20200719231058.1586423-1-jim.cromie@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make the code-block reusable to later handle "file foo.c:101-200" etc. This is a 99% code move, with reindent, function wrap&call, +pr_debug. no functional changes. Signed-off-by: Jim Cromie --- lib/dynamic_debug.c | 63 ++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 6d0159075308..7a66d5e07f41 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -291,6 +291,41 @@ static inline int parse_lineno(const char *str, unsigned int *val) return 0; } +static int parse_linerange(struct ddebug_query *query, const char *first) +{ + char *last = strchr(first, '-'); + + if (query->first_lineno || query->last_lineno) { + pr_err("match-spec: line used 2x\n"); + return -EINVAL; + } + if (last) + *last++ = '\0'; + if (parse_lineno(first, &query->first_lineno) < 0) + return -EINVAL; + if (last) { + /* range - */ + if (parse_lineno(last, &query->last_lineno) < 0) + return -EINVAL; + + /* special case for last lineno not specified */ + if (query->last_lineno == 0) + query->last_lineno = UINT_MAX; + + if (query->last_lineno < query->first_lineno) { + pr_err("last-line:%d < 1st-line:%d\n", + query->last_lineno, + query->first_lineno); + return -EINVAL; + } + } else { + query->last_lineno = query->first_lineno; + } + vpr_info("parsed line %d-%d\n", query->first_lineno, + query->last_lineno); + return 0; +} + static int check_set(const char **dest, char *src, char *name) { int rc = 0; @@ -348,34 +383,8 @@ static int ddebug_parse_query(char *words[], int nwords, UNESCAPE_SPECIAL); rc = check_set(&query->format, words[i+1], "format"); } else if (!strcmp(words[i], "line")) { - char *first = words[i+1]; - char *last = strchr(first, '-'); - if (query->first_lineno || query->last_lineno) { - pr_err("match-spec: line used 2x\n"); - return -EINVAL; - } - if (last) - *last++ = '\0'; - if (parse_lineno(first, &query->first_lineno) < 0) + if (parse_linerange(query, words[i+1])) return -EINVAL; - if (last) { - /* range - */ - if (parse_lineno(last, &query->last_lineno) < 0) - return -EINVAL; - - /* special case for last lineno not specified */ - if (query->last_lineno == 0) - query->last_lineno = UINT_MAX; - - if (query->last_lineno < query->first_lineno) { - pr_err("last-line:%d < 1st-line:%d\n", - query->last_lineno, - query->first_lineno); - return -EINVAL; - } - } else { - query->last_lineno = query->first_lineno; - } } else { pr_err("unknown keyword \"%s\"\n", words[i]); return -EINVAL; -- 2.26.2