From nobody Fri Apr 3 06:25:00 2026 Received: from mail-yx1-f48.google.com (mail-yx1-f48.google.com [74.125.224.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23A4D40B6EC for ; Mon, 9 Mar 2026 17:56:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773078969; cv=none; b=O8jhAQDYLe5bhGdESDv/YKwPHRGgUIj6mfW22UMbOXhp0h+hupTVQnX0An1YDQHtDR7RoMFUHDiQHj/77172VhRgbxE006uh/gt2JWz6cc/KU/O8u3rjNJKzvC8HtZpMqqjy5xlEnfJoVqe08jb+tD28BMaRlF6l90lsj9Tg4tA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773078969; c=relaxed/simple; bh=yfqm2QIm9DrBHUBV2T+7awknKmkDXbJNSO4jPUJtrEw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kAxinJn5giegtNlcrS+3I+8RKIc0fScwqypjkwqZOPQrTcQv30H5tHFbKh84qKuGiRJYKYLyf8bS/YYTT74nj5LZpS2RZ7y5/0+fP9qARtiCimblE4JX49WvPbtzLawvWNiBlC/gHndQIOqS1DwOcn8f+JNh5OExHkyufmi5P4s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ncsu.edu; spf=pass smtp.mailfrom=ncsu.edu; dkim=pass (2048-bit key) header.d=ncsu.edu header.i=@ncsu.edu header.b=ebqiCELc; arc=none smtp.client-ip=74.125.224.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ncsu.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ncsu.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ncsu.edu header.i=@ncsu.edu header.b="ebqiCELc" Received: by mail-yx1-f48.google.com with SMTP id 956f58d0204a3-64c9a6d6b70so10238328d50.3 for ; Mon, 09 Mar 2026 10:56:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ncsu.edu; s=google; t=1773078965; x=1773683765; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Icb2OeUbMfEBKUBW7i3iadIMPsLzVm7CTfwwfYCzkE4=; b=ebqiCELcg+zrBS777S3ABGM73wthsfcTxvO9/0Xgs1TizbLlqw870debfi2AsyEGsk 8qki/M44WhuLQdT3jqG9syEqUxK2Hrh9pd6ilOeMXa45CR8K2cVRbERc51l70XXAOdIX I4HOloVN4Lfc0LYJjvT+5hWYysSuPjwlACrpXD5qAK8IwmpwIK8o6KtnQv/Yu1OZCV4J DOSSTC21o3Zn0X1dB+R5OuLyZ7A1jqw8P3CI6Dv9QcfB5zw/EcjWgveb9QxAKysfcjBC ldrBAa0CubgXisjpy9S+cUVWkTQYVgXqK5eu7ql0fh7Hlq7JSkMTwh6QcCXL9dx5ZRX9 HIwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773078965; x=1773683765; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Icb2OeUbMfEBKUBW7i3iadIMPsLzVm7CTfwwfYCzkE4=; b=G3njwyyws4AjGMtWryLHXhD2Q89ZbhyvDRtLFscOH0aCRXaCq0VNADraD6ygzO3lJ1 a8yvPDEUqR6nW8epdQS/w5sAjceolDGul/RCBzBeAAPuGlDxdmWy5u+IXId/GUHIy0ly GtLRMhvhJbM7zIVYjD33juyx0kjNhdaqTRLkiAGW58rAr+l7kGmvNUmsryY16xgpWcUJ 4SjSrpJ8Tk+IjO05l1SOMzYj7qBYu0oF1LLTOMU2me836lSYgOdtpXasCGZ3wx9ycRCi SYbzQdkQLs27X0xIgen/Appw784zmSTz07TZzJzdkDCgGXuxOBiQgLnDQL7QPiiWf4f9 CMDA== X-Forwarded-Encrypted: i=1; AJvYcCWCjDVHn+Z5DUpV0Ni6XG7EbYyzpht+CAtFA7iavo3Mk/0AEIJhNHR8P2gdJM4S4aPcLbP+uevtx1MEH/o=@vger.kernel.org X-Gm-Message-State: AOJu0YwS9tPHS/our8sJe5wnfSYkDvjIxAHxWWIAN15fPeStuu187Ybt vk0bOjiXV2OTBvHiq7leh8OdYTZRtgA3McGLOD3meM9qDUW1T7oRzWeNmeVEEq7GHQ== X-Gm-Gg: ATEYQzzI1zjC9sisBA6FM9Tx/4mrNsnkvq7XUdoiPaLYe0RK0HuNbgAb+sy0yjj5fRt 52nBHYAIckIze+f42Uvvc5cXx31YcSELeBsjES2hX3E+afV1gAJY4EhUES5Lfzj86y9aiXYzWIG jXB445eybJz+Mg8cNo9fIgkQbwEcnVQkV+lscOjT5fEAfYcsWT024IlAUvpAYsX4DumO/O866PQ aLoctbSGf5lJnM5iAU+ERlJXi1f7IGxyHlD4FYDbo5PX/rjjdVYJFG3OhiBm55pKXeu5AVpA5n+ 1F0UO2V1z6kPh6EKjZqFneBpPOaLCOZwa59DtmO3ikxUtqESzkhPG6uY9JT2PZzQEmYBTY854s+ DCtbxJHWhoev/f7sTRVnR+L+WiOutZuWeamm1BfBuDkuLtsUxXG3UsTyntoc140B5O1M7SSXJms zrF66GULhlmjbsy1O454vVcl1yjLVmkQwpm86VJft6AftjUOlfDVYaWTF0 X-Received: by 2002:a05:690e:e27:b0:649:c308:90ab with SMTP id 956f58d0204a3-64d1418d3admr9582783d50.32.1773078964886; Mon, 09 Mar 2026 10:56:04 -0700 (PDT) Received: from um773-cachyos.sd.ncsu.edu ([152.7.255.206]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-64d176e70e7sm4992535d50.20.2026.03.09.10.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Mar 2026 10:56:04 -0700 (PDT) From: Zecheng Li To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim Cc: Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Zecheng Li , xliuprof@google.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 11/11] perf dwarf-aux: Collect all variable locations for insn tracking Date: Mon, 9 Mar 2026 13:55:24 -0400 Message-ID: <20260309175546.916039-12-zli94@ncsu.edu> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260309175546.916039-1-zli94@ncsu.edu> References: <20260309175546.916039-1-zli94@ncsu.edu> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Previously, only the first DWARF location entry was collected for each variable. This was based on the assumption that instruction tracking could reconstruct the remaining state. However, variables may have different locations across different address ranges, and relying solely on instruction tracking can miss valid type information. Change __die_collect_vars_cb() to iterate over all location entries using dwarf_getlocations() in a loop. This ensures that variables with multiple location ranges are properly tracked, improving type coverage. Signed-off-by: Zecheng Li --- tools/perf/util/dwarf-aux.c | 60 ++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c index 0710c875416f..92db2fccc788 100644 --- a/tools/perf/util/dwarf-aux.c +++ b/tools/perf/util/dwarf-aux.c @@ -1645,6 +1645,7 @@ static int __die_collect_vars_cb(Dwarf_Die *die_mem, = void *arg) Dwarf_Op *ops; size_t nops; struct die_var_type *vt; + ptrdiff_t off; =20 if (tag !=3D DW_TAG_variable && tag !=3D DW_TAG_formal_parameter) return DIE_FIND_CB_SIBLING; @@ -1652,41 +1653,40 @@ static int __die_collect_vars_cb(Dwarf_Die *die_mem= , void *arg) if (dwarf_attr(die_mem, DW_AT_location, &attr) =3D=3D NULL) return DIE_FIND_CB_SIBLING; =20 - /* - * Only collect the first location as it can reconstruct the - * remaining state by following the instructions. - * start =3D 0 means it covers the whole range. - */ - if (dwarf_getlocations(&attr, 0, &base, &start, &end, &ops, &nops) <=3D 0) - return DIE_FIND_CB_SIBLING; - - if (!check_allowed_ops(ops, nops)) - return DIE_FIND_CB_SIBLING; - if (__die_get_real_type(die_mem, &type_die) =3D=3D NULL) return DIE_FIND_CB_SIBLING; =20 - vt =3D malloc(sizeof(*vt)); - if (vt =3D=3D NULL) - return DIE_FIND_CB_END; - - /* Usually a register holds the value of a variable */ - vt->is_reg_var_addr =3D false; + /* + * Collect all location entries as variables may have different + * locations across different address ranges. + */ + off =3D 0; + while ((off =3D dwarf_getlocations(&attr, off, &base, &start, &end, &ops,= &nops)) > 0) { + if (!check_allowed_ops(ops, nops)) + continue; =20 - if (((ops->atom >=3D DW_OP_breg0 && ops->atom <=3D DW_OP_breg31) || - ops->atom =3D=3D DW_OP_bregx || ops->atom =3D=3D DW_OP_fbreg) && - !is_breg_access_indirect(ops, nops)) - /* The register contains an address of the variable. */ - vt->is_reg_var_addr =3D true; + vt =3D malloc(sizeof(*vt)); + if (vt =3D=3D NULL) + return DIE_FIND_CB_END; =20 - vt->die_off =3D dwarf_dieoffset(&type_die); - vt->addr =3D start; - vt->end =3D end; - vt->has_range =3D (end !=3D 0 || start !=3D 0); - vt->reg =3D reg_from_dwarf_op(ops); - vt->offset =3D offset_from_dwarf_op(ops); - vt->next =3D *var_types; - *var_types =3D vt; + /* Usually a register holds the value of a variable */ + vt->is_reg_var_addr =3D false; + + if (((ops->atom >=3D DW_OP_breg0 && ops->atom <=3D DW_OP_breg31) || + ops->atom =3D=3D DW_OP_bregx || ops->atom =3D=3D DW_OP_fbreg) && + !is_breg_access_indirect(ops, nops)) + /* The register contains an address of the variable. */ + vt->is_reg_var_addr =3D true; + + vt->die_off =3D dwarf_dieoffset(&type_die); + vt->addr =3D start; + vt->end =3D end; + vt->has_range =3D (end !=3D 0 || start !=3D 0); + vt->reg =3D reg_from_dwarf_op(ops); + vt->offset =3D offset_from_dwarf_op(ops); + vt->next =3D *var_types; + *var_types =3D vt; + } =20 return DIE_FIND_CB_SIBLING; } --=20 2.53.0