Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4838997ybg; Tue, 29 Oct 2019 13:11:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqzgj9T5HLlk6y70Ze6PZO5LjXHVRVi5FqHaxJ+r0CFKUWemKFVJ85knKx4OyjD//Vkyz4dU X-Received: by 2002:a17:906:4056:: with SMTP id y22mr5370016ejj.188.1572379904681; Tue, 29 Oct 2019 13:11:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572379904; cv=none; d=google.com; s=arc-20160816; b=YNb5DOQccsmhDwd+G21TPtpz5RqM3gnd6Wbooz0bDBWVoRM07oWNzmKEF2EDBYqem+ PL2BsAfq8kjZZ6GPVeWHZCyY8jsiCMS8btcr8NzZhozvPkqjkZP0NcN3Q8MjjJdYqOGL 7CSvTQXqawEu3gniBMERRlQheel8+rm24OqDEVX+pyTw9GRlIjG5lyY09ovNqhPV143j cAsXt3AlD7qYnFvxMbP+bFo3zCqukjsEuYKPgqEmhFCg9Rnkrf+q4xKRkBgn9mHbyBEK TdAUJQGFkpoydysU14UH5AjYj48C4l+WuvGuQWXGioiTSUjj0Lj1lBs7HQzIkvy9MCid Lk8A== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=oVfyTtri7OsgAKkzr9aOQARMtmuPqT5/gZLQ61yYxW0=; b=m4YuQDAz6tG3EoEfR/iA41gBJf0cUohY3Cwv5I99d2TRFmRiZzUvfQy1a2FXHhMNCN yB+OJYuBmo21MT3pHvbA/P++cqojAtlWZkyrDd9/yUZ5Q1e+5OpRoymGAIXUkPaYUJPZ id44Oe451W/tDqdhEPRTthA1/bzYVp6RG9Pf2d8PLwEzYWpfJpsey0ih2L8+shEc72Zu cWyYnw4A29ggcQf12h5bQBj16DM3lFCwCgWDWJEDqqtNp6zIYhv7f/oriY9k84Af/mvD PX89RVn+1gaM35vO3DSk+4fabQYN3CJ69dVu1+C9xfp0vsVfFTdX7HSH7QhVRBEXoJDD xtEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Jum/qRib"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id 14si10648171edz.130.2019.10.29.13.11.17; Tue, 29 Oct 2019 13:11:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Jum/qRib"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728502AbfJ2UAr (ORCPT + 99 others); Tue, 29 Oct 2019 16:00:47 -0400 Received: from mail-io1-f66.google.com ([209.85.166.66]:36575 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727518AbfJ2UAq (ORCPT ); Tue, 29 Oct 2019 16:00:46 -0400 Received: by mail-io1-f66.google.com with SMTP id c16so16222415ioc.3 for ; Tue, 29 Oct 2019 13:00:46 -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:mime-version :content-transfer-encoding; bh=oVfyTtri7OsgAKkzr9aOQARMtmuPqT5/gZLQ61yYxW0=; b=Jum/qRibMSfK/0pAGq3H3xR2clcvx0FhHJIRI5IHQtxNimsKjqk+ESA0VZp+PT3vcn qUwaaIf9YkgxQt1N3aLw7S18bcUQGjEpXVG8lugKwh0SSr3Q3GezzGDriC2FeXm2wKyI PUS7LoYBWop07plidoS1KKL62hh472+JxBrcF21NsqzuRL18nQbsFAk1ElDlAr3zp1Cx f6r1Tyehx/HtgD30UqZA5l/hGw1YMAyETMu2LF2ocxqQuM0S8ydn4hnp+ZP+fVHBb7zN tkshhtEcKKJjNus9AXictn+cczkFtj2CpU1kY2IaaqHPmHfEB+wn8ONfY3JprehQTdQ5 Kwlg== 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=oVfyTtri7OsgAKkzr9aOQARMtmuPqT5/gZLQ61yYxW0=; b=BUXiRBFbbFZuow4Oxf7hQw07H72ejQdf3kwQTIWWSsvBWXDqtP48WHNDLubeIo9mSt ScY8q9NksJs9WNogXJHXz0Q5XudUB0ay8/PCKGifFAcEELdfUUAaa+68sQPyTsVWVgoP GnuhgTNqi3cF2A2RsAK/yd4v3xEGgV/uKvM0yx8XJGj+XTnpy+2XLOHNezL1fW/jGMQc cYEqf9YwyVRoJs9Il2jrAqjS/cQvhbg4c2fx/iATGV8vVNsw0OwcxfDRItxzSKtvRXNx MQH0BrmGcS47bB8niYHNCXlUhad8iOTkkx2n2TqFGzyVwbsDgzbcD+3Ju1v/VXpkJY/c 3I/A== X-Gm-Message-State: APjAAAUy0MnaVAYauDToOekyr9BD0UHrJkcbDtGiW9AS9QCPyl6xDJJ3 u5qvg5wvniaCwYTxGwwwsgI= X-Received: by 2002:a6b:ba44:: with SMTP id k65mr5317027iof.190.1572379245990; Tue, 29 Oct 2019 13:00:45 -0700 (PDT) Received: from localhost.localdomain (c-24-9-77-57.hsd1.co.comcast.net. [24.9.77.57]) by smtp.googlemail.com with ESMTPSA id v13sm2203622ili.65.2019.10.29.13.00.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2019 13:00:45 -0700 (PDT) From: Jim Cromie To: jbaron@akamai.com, linux-kernel@vger.kernel.org Cc: linux@rasmusvillemoes.dk, greg@kroah.com, Jim Cromie Subject: [PATCH 08/16] dyndbg: refactor parse_linerange out of ddebug_parse_query Date: Tue, 29 Oct 2019 14:00:43 -0600 Message-Id: <20191029200043.9988-1-jim.cromie@gmail.com> X-Mailer: git-send-email 2.21.0 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 handle "file foo.c:101-200" etc. Signed-off-by: Jim Cromie --- lib/dynamic_debug.c | 61 +++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 3ac77c49d623..2d0aad5af972 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -277,6 +277,39 @@ 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; + } + return 0; +} + static int check_set(const char **dest, char *src, char *name) { int rc = 0; @@ -335,34 +368,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"); + if (parse_linerange(query, words[i+1])) 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; - } } else { pr_err("unknown keyword \"%s\"\n", words[i]); return -EINVAL; -- 2.21.0