From patchwork Mon Jun 12 23:41:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 106955 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp210323vqr; Mon, 12 Jun 2023 17:12:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Mw2QtD6fOkyF9fOz0lL8sFKE4uKVXqt3jKnJ6nfKw8NcaUOzIPmDvQDUxia5Zg1rLzSnn X-Received: by 2002:a17:906:7947:b0:969:e95e:e4f3 with SMTP id l7-20020a170906794700b00969e95ee4f3mr11127091ejo.55.1686615174797; Mon, 12 Jun 2023 17:12:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686615174; cv=none; d=google.com; s=arc-20160816; b=Dj09Rb7xDrw/oTp9J0w3u/VwIU7iMReGV5JHiwUJbHx6M5OguVFOeopirM5EE25eT+ IpzdA50E0TkQaR15J5PD2u4iaELfzKYbV8AaQCTtMoZPf42kyV7n6BzmuiKMKMyUxwZZ 5OCF9UDdwT0PZCidoMnZ32W4wg5k0xZ+ITvzQ9N9J0vayXExzIFFIE5QNJhcdZqHsC0h G2J2841ErJsZ4MFKg2uV/m7vyq8/DAKt+BbL5SHYe7lrCSd2fh9uDoXHwkPfwqJAQ+3s +7HLNToOf6BSCVWKXEeUQRFpPa1Qbb5FX5vXHYpy09hKCGXV1MlnCkFYdNe9Tt8Du6P2 BuJA== 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:sender:dkim-signature; bh=tO4BEzDA5SKQ1mdhJE03WlcR/YP5mBsUNepj0gTUsj4=; b=U0Gg+cMW2p4WO4I3DjeqJ/foCV5KWYCD1q7ODtpJ4O0EVIWsUHsg8O6wRG9Sl8UQ11 y6DpJiqfBYl9qzfkJKmAhvFgruJWjUS7d3GJqAI+2wIcxzWTGS7pfBBh7DH5gA7csb9Z +FtCamecVDMFASuyLJ6yzitscme8NYTAbH7PHrVpQu5IYE0MjHSS/yqrlGqz4n6iQlRo lOsL2Dk5bSR6FOZer9rW2FLtCMn5gI+mTxtq6ZwtqflVR2kJGOPDmDxiYyRcHQtEoqwp XL30litev5eXdgDhy8PauuO5yuNIPQ6G8MO8TQjfX9nIMb0JSWfGRyhTJ91dHm1zC7Gr dn3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=IbNtXXLw; 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=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kb19-20020a1709070f9300b009572d0759a8si5861171ejc.225.2023.06.12.17.12.25; Mon, 12 Jun 2023 17:12:54 -0700 (PDT) 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=20221208 header.b=IbNtXXLw; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229807AbjFLXlO (ORCPT + 99 others); Mon, 12 Jun 2023 19:41:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238088AbjFLXlK (ORCPT ); Mon, 12 Jun 2023 19:41:10 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72A52131; Mon, 12 Jun 2023 16:41:06 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6563ccf5151so5393667b3a.0; Mon, 12 Jun 2023 16:41:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686613266; x=1689205266; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=tO4BEzDA5SKQ1mdhJE03WlcR/YP5mBsUNepj0gTUsj4=; b=IbNtXXLwsAM5WoJd86ZKQwz4shGA/1q1CC81HOR5uAxaxd+s4ckX6wYWKpXxlMhUj1 E05p9tGl38qtBj+hWQLavaSsU1fwmORdBg+5a9QDJrhIqyNLqnUr1shpP4CTeptmswu2 2b95/4ONvKCZ1Y2qjKsvkFEDuzxZ7r9oBSTHYONlo4+P+k40WE91mdpItsbp5zhQkyMc 1h6aKT/YNR+xu4iN5qgSzw2ZKSSOYlwgTUfomXOfXp2J27MTOH3S8tFfNISHndC4dnRX 9K7xrveuPfthECwaA8Ywod4miAoK7h6xp8LxBSJQdU84wz+U8+xOvn69JVcQlerXiiVC D2vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686613266; x=1689205266; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=tO4BEzDA5SKQ1mdhJE03WlcR/YP5mBsUNepj0gTUsj4=; b=O9559XQMD9q7NPUCRza34Q05vzEZH4BR1yuhr1kN0EXUEtEAzibwY+hndixNc4vnAL Y0apmUzN+Yar8KhiFIZbAqscPPrt0bIW/j7eRUhmDTcI6iGqZAX0GprqdGGXz9NU+tOQ J0BIj+kMghuBM7fvV+BYZzsAEjPLmn2L+WQ/ZXSZWMHWbqQLDQjFHpwCuI3sgWVYO4PJ pUIXCrvXNNVK9PJiT0PTHkxedewHrDVcLKpGB9YICv/oUnfU65RU44NHzL0Scx2OtOrp YcypUaaIw+t6oZUJee2CLJEhBWbimwGCwmCfnleqeI1JrFqjJJPXf3NaOTJpux0WnlQy zrxg== X-Gm-Message-State: AC+VfDwfTyUe7XHCL4as5VhF4/+2i6NDbl4KsXS1aQAhU6HWWg3ExVPs 0FI++KenFDVMqRS2Eib1130= X-Received: by 2002:a05:6a20:549f:b0:10c:1047:68ba with SMTP id i31-20020a056a20549f00b0010c104768bamr14647373pzk.35.1686613265809; Mon, 12 Jun 2023 16:41:05 -0700 (PDT) Received: from moohyul.svl.corp.google.com ([2620:15c:2a3:200:1e19:385a:b5d0:f4a2]) by smtp.gmail.com with ESMTPSA id t12-20020a62ea0c000000b00643355ff6a6sm7565619pfh.99.2023.06.12.16.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 16:41:05 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Masami Hiramatsu Subject: [PATCH 1/2] perf dwarf-aux: Fix off-by-one in die_get_varname() Date: Mon, 12 Jun 2023 16:41:01 -0700 Message-ID: <20230612234102.3909116-1-namhyung@kernel.org> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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?1768544193455622243?= X-GMAIL-MSGID: =?utf-8?q?1768544193455622243?= The die_get_varname() returns "(unknown_type)" string if it failed to find a type for the variable. But it had a space before the opening parenthesis and it made the closing parenthesis cut off due to the off-by-one in the string length (14). Signed-off-by: Namhyung Kim --- tools/perf/util/dwarf-aux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c index e4593a71556b..1ac88b79687d 100644 --- a/tools/perf/util/dwarf-aux.c +++ b/tools/perf/util/dwarf-aux.c @@ -1103,7 +1103,7 @@ int die_get_varname(Dwarf_Die *vr_die, struct strbuf *buf) ret = die_get_typename(vr_die, buf); if (ret < 0) { pr_debug("Failed to get type, make it unknown.\n"); - ret = strbuf_add(buf, " (unknown_type)", 14); + ret = strbuf_add(buf, "(unknown_type)", 14); } return ret < 0 ? ret : strbuf_addf(buf, "\t%s", dwarf_diename(vr_die)); From patchwork Mon Jun 12 23:41:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 106954 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp206828vqr; Mon, 12 Jun 2023 17:04:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5K4mxQg8eb/lhrZETovU9laaxzO13Cr5Qoq9BT/n40akxO71P4q0xH4XKrGzbyIkDiHeIs X-Received: by 2002:a17:907:25ca:b0:971:55e2:82c3 with SMTP id ae10-20020a17090725ca00b0097155e282c3mr8305700ejc.20.1686614698663; Mon, 12 Jun 2023 17:04:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686614698; cv=none; d=google.com; s=arc-20160816; b=BG/knnP0DgLnaJwQL0398HhEhEk1Qj/lSvI5Lv6GkMLAQBoBeAvFMKX/EJ7hwhCit6 HRtsYEOspxovLgJSwiF86ybHWtAUmoBDvNq2/Qi74R7U73jQd9TeyxxERVQVglWwSvlN dPaThXOLBj2HOcTx4UstRPkrp0/nkMm7aa/DqfQwFx8blos0dzXh1INUNEiAqVNquZhX Ej/RaRsxY8sJh0KlUYFhLFdaMKq6ILuRVpYByduau0RPWgs/6sEk3pDWUTbwR8U+Uyvu FSxK6G6e8zULJ/wQqzMwvPb778CInoUYmEOIRKiGDIX3VBYUHQpOPnoFV0xN+N/ltUZ+ bqww== 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 :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=2idTz1dI6R8Bw9mKAT+NEGNVBgEcKr2rXGyUpAj9+VU=; b=vYRGISD8hSYxVx8F9OkPpPEqNiV5l3dloAavTqfZtklLhXUibK7djo649Ock2MPHQU rc29cPbZmODgs2kXSdcgH2yyMrAE3+9LiDqbi4K2LeR8r/Vhtv7ZjLMEAGAZ6cGAHVHi zMe09Ij8wiVkoDIvEJGEiMZwWgl92SyZKQuP/Ot9pbVPbfEIiaCCh108LQDJ3uWHhjaa EAd9Vuia2OMu46Lr6S1HOPD3eXakH7LdrCqBW0b4z2ctS+oz3OKsjalIlKc1Mxajr677 2iB6caYP7KnNnRtVNMpTq8fJIJ7sNvn6QMbyqnNV/rL/l4r36J7+V3DH7LF7kfxrxDTw hB7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=mB7cvxai; 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=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b8-20020a170906194800b009788caf5bc8si6051467eje.857.2023.06.12.17.04.09; Mon, 12 Jun 2023 17:04:58 -0700 (PDT) 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=20221208 header.b=mB7cvxai; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238008AbjFLXlS (ORCPT + 99 others); Mon, 12 Jun 2023 19:41:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238039AbjFLXlK (ORCPT ); Mon, 12 Jun 2023 19:41:10 -0400 Received: from mail-oa1-x36.google.com (mail-oa1-x36.google.com [IPv6:2001:4860:4864:20::36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0BB7124; Mon, 12 Jun 2023 16:41:07 -0700 (PDT) Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-1a6b7060862so191157fac.2; Mon, 12 Jun 2023 16:41:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686613267; x=1689205267; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=2idTz1dI6R8Bw9mKAT+NEGNVBgEcKr2rXGyUpAj9+VU=; b=mB7cvxaim/8ZW9lHIU6lPRBtBVdQGyUyF7w/Ves7I7UzY9aln8lv2zFB8x6FiAsoQx evbQJQlxpWjEMLrfL05DdfpvfCKwiCayTx8Cihk32yBvYSvP6vUkjx5kX6Ulaq5L4i2o iflgiWkANNwHQrkF59utzROQChv2vSRy47uBfgVsNt/aUHDprnSjyx6qOzEATxjsXSSf ZQSE7au3F3SwDnx9Z7EDfc4TQl0jMqmBh4HGj8cVygjsOs5zb9ShcNDij2Lt2gQHAInF LZZZq/4JvuOkTln9n5GXrLwd6CDpMURymHyBXCYeKBaHOPaignGE83NFu8k1M5B0G9Qc 6VrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686613267; x=1689205267; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=2idTz1dI6R8Bw9mKAT+NEGNVBgEcKr2rXGyUpAj9+VU=; b=K0p0lA5Bk0JLLaiIegJV9rqz+q/tBPBXjgzyCJFqby03MAo9QQR2Pi3C5LbEskUgIz HHJEWd/wO8HabovFCqexTd+p58NqqgkAovYMB9XxgUkBvSMcLFMh/lvXQxypHJIPdrvi x4DIlM2T3bG+jYcnL0csXDqYNv/Wn7sUnZkdOzEUvqk/a2e+bW2Q/+XeuCinDQaojlEN qsNeVBkYcpjYomIagsSsg/1EoGHseHEX87/9mz0hxHbfDJbtbYj53uS6WdybUbcWNldm rOsSwERSQQvOuoq942TfsiEUz1Dt75J+v/6Ii9pauuqUDUk143x/d+8soUKLZyzXr05n 4Ufw== X-Gm-Message-State: AC+VfDzAWThQyAb7elIbvZ8G16EUXyC5/FenfzjvxqT+eTGSrvH+eVQj g/aZLsaxgwhzMkt+8XCc/KjQtOF/Iac= X-Received: by 2002:a05:6871:555:b0:177:809e:ead3 with SMTP id t21-20020a056871055500b00177809eead3mr7199845oal.41.1686613266879; Mon, 12 Jun 2023 16:41:06 -0700 (PDT) Received: from moohyul.svl.corp.google.com ([2620:15c:2a3:200:1e19:385a:b5d0:f4a2]) by smtp.gmail.com with ESMTPSA id t12-20020a62ea0c000000b00643355ff6a6sm7565619pfh.99.2023.06.12.16.41.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 16:41:06 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa Cc: Ian Rogers , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Masami Hiramatsu Subject: [PATCH 2/2] perf dwarf-aux: Allow unnamed struct/union/enum Date: Mon, 12 Jun 2023 16:41:02 -0700 Message-ID: <20230612234102.3909116-2-namhyung@kernel.org> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog In-Reply-To: <20230612234102.3909116-1-namhyung@kernel.org> References: <20230612234102.3909116-1-namhyung@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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?1768543694596672602?= X-GMAIL-MSGID: =?utf-8?q?1768543694596672602?= It's possible some struct/union/enum type don't have type name. Allow the empty name after "struct"/"union"/"enum" string rather than fail. Signed-off-by: Namhyung Kim --- tools/perf/util/dwarf-aux.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c index 1ac88b79687d..759434552653 100644 --- a/tools/perf/util/dwarf-aux.c +++ b/tools/perf/util/dwarf-aux.c @@ -1074,16 +1074,18 @@ int die_get_typename(Dwarf_Die *vr_die, struct strbuf *buf) /* Function pointer */ return strbuf_add(buf, "(function_type)", 15); } else { - if (!dwarf_diename(&type)) - return -ENOENT; + const char *name = dwarf_diename(&type); + if (tag == DW_TAG_union_type) tmp = "union "; else if (tag == DW_TAG_structure_type) tmp = "struct "; else if (tag == DW_TAG_enumeration_type) tmp = "enum "; + else if (name == NULL) + return -ENOENT; /* Write a base name */ - return strbuf_addf(buf, "%s%s", tmp, dwarf_diename(&type)); + return strbuf_addf(buf, "%s%s", tmp, name ?: ""); } ret = die_get_typename(&type, buf); return ret ? ret : strbuf_addstr(buf, tmp);