From patchwork Wed Dec 14 02:52:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Donglin Peng X-Patchwork-Id: 33026 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp499991wrn; Tue, 13 Dec 2022 18:55:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf5OUHgUYv4HzaQzZKJCPloPcjXJL1HSAFLHHG3CBQo1vd8MSIIjwqVbdsBRrumnyC+9zMyo X-Received: by 2002:a17:90b:5205:b0:215:ddd1:d28f with SMTP id sg5-20020a17090b520500b00215ddd1d28fmr24068391pjb.9.1670986537205; Tue, 13 Dec 2022 18:55:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670986537; cv=none; d=google.com; s=arc-20160816; b=IOoNEvRvCz432+v8mVK26iAWkztD4OkWw39xsbjcYTfVjUUtL7trplGU2Ryvn53b5C J6p9WqKHbQfiCBQjJ3KDbG7VxV1kHMN1FGU6ZRn8Vh/UmjEahQtF6JSH5FUOVO4DyR3H ve3IKpIZys/o7i+6jnink0lHYWlqTIYSBvbdokyM5sSj5MIj80dzuQr82rmi24KLK06B 1r0lqmSXB0cbKed9MPpO6IZ3ZyH1QEDcFX4kYKjy20+VBkOF6If3ECLZJemUveLqX+c+ 0vMkAbEFPjMVH74lr+pX0J777dmE8awf00ClA++am3zapy2fTdSWwEQp1D3o9rW8GqEH t+BQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=XcHaJrtlRfUwYPTK4kJLL2u6ZuEblPsEK62crrbzYPI=; b=BZoq/xt616S+MhqNMNkd6KYpTz4++6D6px01T89qr9nVbJ+xshktdHEoMuRKuT2u4p gM4CqlETCr7muu9J/MBGyX7FuQFqjoDSvjEfZp1+8ntBhWhrbw87+kGBLLn3jQN9cJUD e22DohrH6mJGYOTHc0f+rbxSIs/s2XT64laqK/NxlOdihExEyYpwTHUWYHyXUA195IXJ 6QLE94UbkEQb3PRGnEZflNQuHeZGL0s5V17kTHZauE28v4wVXNO8HGyD2kBIT7hmE2a1 C7clLYwliyeFNQoWBQWI+hAaXkuBYvPc2SBrFu0S95dCIj/4jZkpM9AVWJnh85WBk87N NngA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=N2dHZ9eA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x5-20020a654145000000b004794d65bc1esi7333606pgp.399.2022.12.13.18.55.15; Tue, 13 Dec 2022 18:55:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=N2dHZ9eA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S237203AbiLNCxd (ORCPT + 99 others); Tue, 13 Dec 2022 21:53:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237099AbiLNCw7 (ORCPT ); Tue, 13 Dec 2022 21:52:59 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22F3065CE for ; Tue, 13 Dec 2022 18:52:43 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id t2so1968191ply.2 for ; Tue, 13 Dec 2022 18:52:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=XcHaJrtlRfUwYPTK4kJLL2u6ZuEblPsEK62crrbzYPI=; b=N2dHZ9eAI2dH7pfB/08LBYO7pUpwpDW4Wy142jTM4YqjtM2E3y8UEZ0G2+HQFOb7/5 5jwoh+re26kk5KXPPX56Mu9hd+gihHltN66R7uOzcvDHueMFyKGUXDHMaIadXO9UsLMd mmrlUlOoUKm/T1fBypIojBpuqo57SCXJmRCCLpEuWpOVZM8ahdmn9et5dQMhAKjFs/g/ nTMtvqr5ko2iZN6RphOa7zezvz8H6bYxwhQ+Dz7OhOU5dCSadoRxD84Ex+dnrBFYndhJ Eqesy0ZMoRAal2PXvo5pC/8hVoXaTkkNs8BPvyuHENzemvslOOJinbv5x4xyvdvqOjC4 Eitg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XcHaJrtlRfUwYPTK4kJLL2u6ZuEblPsEK62crrbzYPI=; b=oqKBxlG/q1pF2UOMjIyyyBnAc+CTkRKn5W0QYDfZ49s9M2q+U7WMN/++pLSDzYgvw+ LAcmX9dIr4eUdC3UPGEB5ZvYFoRIm07utGBuW4RIdAp8Rqki1eIQokLG6JQWPBhDMkNH O7WB8YLlZzMobvPTyKsNmlW44YcdqtE2TBeHLZCxZzLR7So3/Ym6FH94a5A4hUxvRkag 7OrgOyiZhWqk2VagS16qx1LZhTz184sQVnQIok9MVBG/+oOMj2jzVp+WiVvb4HYbw82H BsAi4e0VKGB7ZjPjSWaYSlebDEPZDdB70TdDy++a+M8Ecc7rNPeKUu+wjGKrXCA3WDRb fx+w== X-Gm-Message-State: ANoB5pmS7TlN58Q5KUmM5Mminpj+N1WajmR5iTS+Uht7DgyIQLoEhyaG UBPujzqBsLDL4g/HgWmj3hU= X-Received: by 2002:a05:6a21:9212:b0:9f:2dd1:c2bc with SMTP id tl18-20020a056a21921200b0009f2dd1c2bcmr27401857pzb.49.1670986363493; Tue, 13 Dec 2022 18:52:43 -0800 (PST) Received: from ubuntu.localdomain ([118.73.12.140]) by smtp.gmail.com with ESMTPSA id r19-20020a63d913000000b00478e7f87f3bsm7304690pgg.67.2022.12.13.18.52.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 18:52:42 -0800 (PST) From: Donglin Peng To: rostedt@goodmis.org Cc: mhiramat@kernel.org, xiehuan09@gmail.com, linux-kernel@vger.kernel.org, Donglin Peng , kernel test robot Subject: [PATCH v2] tracing/probe: add a char type to print the character value of traced arguments Date: Tue, 13 Dec 2022 18:52:18 -0800 Message-Id: <20221214025218.8737-1-dolinux.peng@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752156379292431724?= X-GMAIL-MSGID: =?utf-8?q?1752156379292431724?= There are scenes that we want to show the character value of traced arguments other than a decimal or hexadecimal or string value for debug convinience. Add a new type named 'char' to do it. For example: echo 'p:myprobe xxxx +0($arg1):char' > kprobe_events echo 'p:myprobe xxxx +0($arg1):char[2]' > kprobe_events Signed-off-by: Donglin Peng Reported-by: kernel test robot Acked-by: Masami Hiramatsu (Google) --- Changes in v2: - fix build warnings reported by kernel test robot - modify commit log --- Documentation/trace/kprobetrace.rst | 3 ++- kernel/trace/trace_probe.c | 2 ++ kernel/trace/trace_probe.h | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Documentation/trace/kprobetrace.rst b/Documentation/trace/kprobetrace.rst index 4274cc6a2f94..007972a3c5c4 100644 --- a/Documentation/trace/kprobetrace.rst +++ b/Documentation/trace/kprobetrace.rst @@ -58,7 +58,7 @@ Synopsis of kprobe_events NAME=FETCHARG : Set NAME as the argument name of FETCHARG. FETCHARG:TYPE : Set TYPE as the type of FETCHARG. Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal types - (x8/x16/x32/x64), "string", "ustring" and bitfield + (x8/x16/x32/x64), "char", "string", "ustring" and bitfield are supported. (\*1) only for the probe on function entry (offs == 0). @@ -80,6 +80,7 @@ E.g. 'x16[4]' means an array of x16 (2bytes hex) with 4 elements. Note that the array can be applied to memory type fetchargs, you can not apply it to registers/stack-entries etc. (for example, '$stack1:x8[8]' is wrong, but '+8($stack):x8[8]' is OK.) +Char type can be used to show the character value of traced arguments. String type is a special type, which fetches a "null-terminated" string from kernel space. This means it will fail and store NULL if the string container has been paged out. "ustring" type is an alternative of string for user-space. diff --git a/kernel/trace/trace_probe.c b/kernel/trace/trace_probe.c index 36dff277de46..a4abf7f6c295 100644 --- a/kernel/trace/trace_probe.c +++ b/kernel/trace/trace_probe.c @@ -50,6 +50,7 @@ DEFINE_BASIC_PRINT_TYPE_FUNC(x8, u8, "0x%x") DEFINE_BASIC_PRINT_TYPE_FUNC(x16, u16, "0x%x") DEFINE_BASIC_PRINT_TYPE_FUNC(x32, u32, "0x%x") DEFINE_BASIC_PRINT_TYPE_FUNC(x64, u64, "0x%Lx") +DEFINE_BASIC_PRINT_TYPE_FUNC(char, u8, "%c") int PRINT_TYPE_FUNC_NAME(symbol)(struct trace_seq *s, void *data, void *ent) { @@ -93,6 +94,7 @@ static const struct fetch_type probe_fetch_types[] = { ASSIGN_FETCH_TYPE_ALIAS(x16, u16, u16, 0), ASSIGN_FETCH_TYPE_ALIAS(x32, u32, u32, 0), ASSIGN_FETCH_TYPE_ALIAS(x64, u64, u64, 0), + ASSIGN_FETCH_TYPE_ALIAS(char, u8, u8, 0), ASSIGN_FETCH_TYPE_ALIAS(symbol, ADDR_FETCH_TYPE, ADDR_FETCH_TYPE, 0), ASSIGN_FETCH_TYPE_END diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h index de38f1c03776..8c86aaa8b0c9 100644 --- a/kernel/trace/trace_probe.h +++ b/kernel/trace/trace_probe.h @@ -164,6 +164,7 @@ DECLARE_BASIC_PRINT_TYPE_FUNC(x16); DECLARE_BASIC_PRINT_TYPE_FUNC(x32); DECLARE_BASIC_PRINT_TYPE_FUNC(x64); +DECLARE_BASIC_PRINT_TYPE_FUNC(char); DECLARE_BASIC_PRINT_TYPE_FUNC(string); DECLARE_BASIC_PRINT_TYPE_FUNC(symbol);