From nobody Mon Sep 28 13:59:30 2026 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (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 5E18F351C35 for ; Fri, 21 Aug 2026 05:02:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787288557; cv=none; b=S6kYzRQViEyQsPkkLHQjJBgffMbJJ2lNeSR9aXgfPjE42D0MVJCy+40nxpS1pCSLhdZeuxaAvYbN23R/3n/HLpPc0DFOHtimBOdyXG/mgTNTk2/H+nEE7X/oIWxnTDE/xg/7xADpc08ZsB09LftZUy8Zt9KP6FjVt+PleHudR0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787288557; c=relaxed/simple; bh=bZbm6XOK98Prr6KSnd5pF4eIfpTE8UabYOUOPHg+Lq8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LDaPEMqc3xuGbmupiI5OB/f6gbSF2IpNsDylf+JHU8skuaISevybJKWsjipKf2yBevTl2/6vGxoasnQY8d3kY9Hxx+m7p4rUoKO/qTtRgQ31LjlU9ruQFpFzjTJbZA4k4tUmeTSKra94qjRtAJY1NrXqKIKS/OIPqEsWd2Y2dGA= 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=FyvsO/Op; arc=none smtp.client-ip=209.85.219.46 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="FyvsO/Op" Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-908a2ca5becso5646816d6.0 for ; Thu, 20 Aug 2026 22:02:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ncsu.edu; s=google; t=1787288554; x=1787893354; 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:content-type; bh=JgYq+HSuWV0wHdSKUb0LnpK8mur76MdWfMhpvbEJMks=; b=FyvsO/OpA+CIsh3iVjrOw8boeSCt+/JbFoaqfStxl6pKjelP2mD54rzhWRGCDr8rQF 490Ecae5a7ZS9Xxy+mFCcoLS7yNKm36qXEtYfLBdi80GTMjhFVsPSCDSs+8OtjpgyS1M rNxEg1CgNzqXcgAz48WpPFtjMZmTnSX030yqsVY7/3xfBnh5h/10yvcJCO+UqThqFBkO LubgHABHbJqfSyAPJYzYJ83nIavT5LkmEBP1/2NF0Utislaf4Iovu8yD2ueLx7r+ra+k wTZBzWD7UWZREA2YO8ki244divT8Rg3P5M8XGbmVpK5tlE0w+Oa7XtWriVdXvz1PvEjN vg3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787288554; x=1787893354; 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:content-type; bh=JgYq+HSuWV0wHdSKUb0LnpK8mur76MdWfMhpvbEJMks=; b=SII9zq3mgm2Tq5vi+M9dKqkvF6TyLGSPDXFJYotXKTV2bi+bCR5gzahF0DJPddOyT0 EJG1GnPq+xEQGCSFuOAbFfW6ntOQjYrAWjs2SFy+rqIPAR+ce4MKil+IwXDrOxbj/c7f VrhUS7tXNGIxvAYl/aR3H/w9+htTL0vFKvzUkG9xrMc5GKTjX2WyD8RoRpZoKNmlYnV0 GMkTJ6Uv6krqDhKzsUVOApgynx+9F31ml7LNU8F0BldwlDKf8Ti0bSxPSSG7X1VkIPk5 FOTPdCxV6ghG+Zo7/jaDablLqHCSTZMUcpq65+SMlWdhFz6Ue8VYfU9QZZHOdjrNCUjF n9WA== X-Forwarded-Encrypted: i=1; AHgh+RqZH2J7MsuUNQlrVaTOWxTBwxsgcuSK3cDpGqMUhINY+iRIhPskx5tbIgznR8ynjfdpFI0Do1tsknWRb5E=@vger.kernel.org X-Gm-Message-State: AFuF++kmrCeYMbk1iALnbB3xe3NgtUL5eFVLZeQ59qhNaz2RReWJN8u5 RRxi9OFCx+JZtW09IYM3k+NCJOwBZ2n16PiJwFJcEs9E8w1qKLcB+5BcvQLECTTcTw== X-Gm-Gg: AR+sD10DxK6LoTjEv6Mjy+G8V/IG5zyg+xZcw531R6XqY9jkGRYKIQeYCycAtNfLdX6 jnjBk7uePuGYC5Nf1JNO1Ip0QVT3GlUFtPVM8ECZGDmLeL1VcQT/gpRhmKjtSCIKE5zNzCsk9e6 +hxDCaEysJ2nzOpg2sX6ou1KCOg8yU2kfzWIJHOz6DxAjRJGAeD/nge4JYuf4/+8s1v6+mfcCwW kjt+tfLrsJSQKBBOAvF2rcUKpLjJC83BrqpQv1sPvOdQ0sqJjGnCdP/vcxOO1/0K+DI4422ZS4w LuQXva9mmmejl0QNmxCjqUVSMg0gQuvLIpAVN5DY9XWtmk6uqhXMFvsANaDj7h5RFBEeu8Vp9b3 rQtNxL7eByOkMrBTZUSuYpxWYVrSzZVuPuLM9BKV/gonwSG/xcQ2QVX14Y75/Wd6NRjGeU9tcwp CoQHF3ul16RWbEVGOf6maccC33KiN9VcOLrFT848MBfxjcXx2P+OPsIyNHlGQFF/2Xsp8moVEPX lBVrvJRlMFKTkAlavbE X-Received: by 2002:ad4:5749:0:b0:90c:4e70:e5e0 with SMTP id 6a1803df08f44-90c80943eebmr34589566d6.6.1787288554166; Thu, 20 Aug 2026 22:02:34 -0700 (PDT) Received: from home.localdomain ([136.61.118.42]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-90c5eec1e7fsm54368116d6.12.2026.08.20.22.02.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2026 22:02:33 -0700 (PDT) From: Yanbo Zhao To: Namhyung Kim , Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Zecheng Li , Xu Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Yanbo Zhao Subject: [PATCH 1/3] perf dwarf-aux: Add die_is_compound_type() to handle C++ class types Date: Fri, 21 Aug 2026 01:02:05 -0400 Message-Id: <20260821050207.4517-2-yzhao62@ncsu.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260821050207.4517-1-yzhao62@ncsu.edu> References: <20260821050207.4517-1-yzhao62@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" Introduce the die_is_compound_type() helper which checks for DW_TAG_structure_type, DW_TAG_union_type, and DW_TAG_class_type, and convert all the existing open-coded struct/union tag checks to use it: - die_get_member_type() in dwarf-aux.c. - __add_member_cb(), is_compound_type(), and set_stack_state() in annotate-data.c. Also accept DW_TAG_inheritance in the member lookup callbacks (__die_find_member_offset_cb() and __add_member_cb()) so that member lookup by offset descends into C++ base class subobjects. This extends the existing member type resolution and data type profiling state handling to C++ classes with inheritance without changing behavior for C struct/union types. Signed-off-by: Yanbo Zhao --- tools/perf/util/annotate-data.c | 29 ++++++----------------------- tools/perf/util/dwarf-aux.c | 17 ++++++++++++----- tools/perf/util/dwarf-aux.h | 3 +++ 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index 4e4c58764082..ee6bd2d0012d 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -230,9 +230,9 @@ static int __add_member_cb(Dwarf_Die *die, void *arg) Dwarf_Word size, loc, bit_size =3D 0; Dwarf_Attribute attr; struct strbuf sb; - int tag; + int tag =3D dwarf_tag(die); =20 - if (dwarf_tag(die) !=3D DW_TAG_member) + if (tag !=3D DW_TAG_member && tag !=3D DW_TAG_inheritance) return DIE_FIND_CB_SIBLING; =20 member =3D zalloc(sizeof(*member)); @@ -292,15 +292,8 @@ static int __add_member_cb(Dwarf_Die *die, void *arg) INIT_LIST_HEAD(&member->children); list_add_tail(&member->node, &parent->children); =20 - tag =3D dwarf_tag(&die_mem); - switch (tag) { - case DW_TAG_structure_type: - case DW_TAG_union_type: + if (die_is_compound_type(&die_mem)) die_find_child(&die_mem, __add_member_cb, member, &die_mem); - break; - default: - break; - } return DIE_FIND_CB_SIBLING; } =20 @@ -464,9 +457,7 @@ static const char *match_result_str(enum type_match_res= ult tmr) =20 static bool is_compound_type(Dwarf_Die *type_die) { - int tag =3D dwarf_tag(type_die); - - return tag =3D=3D DW_TAG_structure_type || tag =3D=3D DW_TAG_union_type; + return die_is_compound_type(type_die); } =20 /* returns if Type B has better information than Type A */ @@ -584,7 +575,6 @@ struct type_state_stack *find_stack_state(struct type_s= tate *state, void set_stack_state(struct type_state_stack *stack, int offset, u8 kind, Dwarf_Die *type_die, int ptr_offset) { - int tag; Dwarf_Word size; =20 if (kind =3D=3D TSR_KIND_POINTER) { @@ -605,17 +595,10 @@ void set_stack_state(struct type_state_stack *stack, = int offset, u8 kind, return; } =20 - tag =3D dwarf_tag(type_die); - - switch (tag) { - case DW_TAG_structure_type: - case DW_TAG_union_type: + if (die_is_compound_type(type_die)) stack->compound =3D (kind !=3D TSR_KIND_PERCPU_POINTER); - break; - default: + else stack->compound =3D false; - break; - } } =20 struct type_state_stack *findnew_stack_state(struct type_state *state, diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c index d7160f87ac7d..88ba0ec23a68 100644 --- a/tools/perf/util/dwarf-aux.c +++ b/tools/perf/util/dwarf-aux.c @@ -60,6 +60,14 @@ const char *cu_get_comp_dir(Dwarf_Die *cu_die) return dwarf_formstring(&attr); } =20 +bool die_is_compound_type(Dwarf_Die *type_die) +{ + int tag =3D dwarf_tag(type_die); + + return tag =3D=3D DW_TAG_structure_type || tag =3D=3D DW_TAG_union_type || + tag =3D=3D DW_TAG_class_type; +} + /* Unlike dwarf_getsrc_die(), cu_getsrc_die() only returns statement line = */ static Dwarf_Line *cu_getsrc_die(Dwarf_Die *cu_die, Dwarf_Addr addr) { @@ -2053,7 +2061,7 @@ static int __die_find_member_offset_cb(Dwarf_Die *die= _mem, void *arg) Dwarf_Word offset =3D (long)arg; int tag =3D dwarf_tag(die_mem); =20 - if (tag !=3D DW_TAG_member) + if (tag !=3D DW_TAG_member && tag !=3D DW_TAG_inheritance) return DIE_FIND_CB_SIBLING; =20 /* Unions might not have location */ @@ -2104,7 +2112,7 @@ Dwarf_Die *die_get_member_type(Dwarf_Die *type_die, i= nt offset, =20 tag =3D dwarf_tag(type_die); /* If it's not a compound type, return the type directly */ - if (tag !=3D DW_TAG_structure_type && tag !=3D DW_TAG_union_type) { + if (!die_is_compound_type(type_die)) { Dwarf_Word size; =20 if (dwarf_aggregate_size(type_die, &size) < 0) @@ -2119,7 +2127,7 @@ Dwarf_Die *die_get_member_type(Dwarf_Die *type_die, i= nt offset, =20 mb_type =3D *type_die; /* TODO: Handle union types better? */ - while (tag =3D=3D DW_TAG_structure_type || tag =3D=3D DW_TAG_union_type) { + while (die_is_compound_type(&mb_type)) { member =3D die_find_child(&mb_type, __die_find_member_offset_cb, (void *)(long)offset, die_mem); if (member =3D=3D NULL) @@ -2130,8 +2138,7 @@ Dwarf_Die *die_get_member_type(Dwarf_Die *type_die, i= nt offset, =20 tag =3D dwarf_tag(&mb_type); =20 - if (tag =3D=3D DW_TAG_structure_type || tag =3D=3D DW_TAG_union_type || - tag =3D=3D DW_TAG_array_type) { + if (die_is_compound_type(&mb_type) || tag =3D=3D DW_TAG_array_type) { Dwarf_Word loc; =20 /* Update offset for the start of the member struct */ diff --git a/tools/perf/util/dwarf-aux.h b/tools/perf/util/dwarf-aux.h index 161f0bf980b6..855c45fec5bb 100644 --- a/tools/perf/util/dwarf-aux.h +++ b/tools/perf/util/dwarf-aux.h @@ -23,6 +23,9 @@ const char *cu_find_realpath(Dwarf_Die *cu_die, const cha= r *fname); /* Get DW_AT_comp_dir (should be NULL with older gcc) */ const char *cu_get_comp_dir(Dwarf_Die *cu_die); =20 +/* Check if DIE is a compound type (structure, union, or class) */ +bool die_is_compound_type(Dwarf_Die *type_die); + /* Get a line number and file name for given address */ int cu_find_lineinfo(Dwarf_Die *cudie, Dwarf_Addr addr, const char **fname, int *lineno); --=20 2.25.1 From nobody Mon Sep 28 13:59:30 2026 Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44]) (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 957B83F4854 for ; Fri, 21 Aug 2026 05:02:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787288558; cv=none; b=FST9T1pBxWzHMfUhkEEUbkb9iaNu0sWphx/bCmXlDme5P1zePb/exqqFrJAT8Zjp8veMPcGjyovTnYCMa0L1AS1IbjXDiMSgcuZ0l6ZVyUyWCJtzEohw3whaS2eRAu7nmr3uh46MMLtq9WjB0rDqA40YyufWz3NuJfhhWDJVkq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787288558; c=relaxed/simple; bh=D/tw0w8eAa3nSDuVMYf/sW/Q8H627uckPE9TlM6qwqM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Px8aJpbxqWri0J/H46bgBWe1j3ekeVH/WOPY7/SdsGVTB0/zEZKnkmazdaOIqLxp2LDpNlIBNdcilTifHGN5m9c+3kUotqRqo9eJPRFXHkjJ7JT43GfpUMuYSSAEY+g10zMVmZ6Fd/vAa5TPX3MrEanBO8Mxv89l+3xsMImzoCU= 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=If27CtRH; arc=none smtp.client-ip=209.85.219.44 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="If27CtRH" Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-9034b6b7674so4292866d6.0 for ; Thu, 20 Aug 2026 22:02:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ncsu.edu; s=google; t=1787288555; x=1787893355; 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:content-type; bh=OzB1aNn1o04f40kFNNF+EY0tTOWmlsfUCuB6g5UoRcM=; b=If27CtRHZF8OX3cWBs/mmaNyu7MaFc6NlQf1Edgt/pwXj72K0WPbRd/FoZq3ekfa4r YpFcfs2Jkq1vJcTdbJB44dLZP+mipGqT6yC9mM+SNwERZbjuOs6lTXlAvNaHr7vs8r77 qE4kidgKNkfUrtVoQz3Ho4zTScUOds/Kw0h8ktdjOYcQ6OaXxQae86oLza9NeC2+UUGg yksNXOmV69znZsWukkt4XmD6wpGn9h5/QPJuzwrAieg3mdKt29ok/0JhUBL+IwCGmPHT ZwnS5mlTpuYd4ZRCDqOwwvWKary/bf2mpow73mijhh2AC7MB8GncIGS6nQ4MojBQ59ct 3LYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787288555; x=1787893355; 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:content-type; bh=OzB1aNn1o04f40kFNNF+EY0tTOWmlsfUCuB6g5UoRcM=; b=IZsHdXaVhtsKT9lNRJSjREuwm85HE1R6FIeDlH5bVyWXelwbKTo87vkbJfr4JFp0Rb QUQtWiL3EEHG3lYenbJY8dk1T9SwJ75+nGLQ3cZ9bACeau8YIKMLgEzK+K5tevj2pjcu /lnS8kS+lHNut3dpAIzu6yWiLA2aAa+5H4FSn8972WU4BYL6guEYUJoK0sfKlsK5qMrH YyYFgy+8mX3jP40G8dbN1PxzDh1h3urAFP1vMyt3/MEk8Q3dN9N4AxHxRiLyHdtZ9QgU vLAEThX82NJ8xQvHbKLAJm2VrJtbqRrOwgk2OqqM1FLPArrIHM46I7nV+u2bWUsVb0qw GqzA== X-Forwarded-Encrypted: i=1; AHgh+RreKija++2+nPv7BvP+Uu0B1pR6kp7iWE+dV6EOo49HVWw3OmAJzIz4xhHlnsBgovZaur2cHoSaPxn+VJE=@vger.kernel.org X-Gm-Message-State: AFuF++kUnNwiaJzTywRqm/ETcb+SeqokqpTF+lxtW2g2xxwFIhv3UYZO HufkmLk1IK+dwqR/PUTkJERa9UciylB00uec2S8cJBMYHSHYu+L5QQQwRqKTbgbAug== X-Gm-Gg: AR+sD10W86cdYt+ptfozYakJJb8d4wZGkx7SrGiOhWzOEIIcmKnDp0ZwR+kaGwfSAUk ZDtBu4t5nb72zB9Lw7dUBtebTqxEDmzNFRuUhmAAXMXEEkzY9FxZMKJ1M8A8vJ7H5uJq1tV6WVe TO5+G1eG0lM17noiLXv+IEFQ8AbWkq/IG48oVxcNv55XA9ktt/3yELJpn9qZ5fZlnUw0GrUhDBm OLc7scfvxagHEUahmy+fFiMxhZ0+SBrRbb4xJWUroZkO3xD+AY9Ytw+GNfZOX2BZiJj9kqqMn1L Sp9RSINyrmzIJNpwkuA0dQcsz4G7lvXt70oOktw05qnpJw6HeG8jvxQL2VmF03p//VrmmPgNbpk IIw3v4IQp8wFHwtjk6Yln2RvRjlx/rloh1D4vyEYb11RaSm6MjjJDjOXQhnvkxJBNDq8CtmrTqj SoCqE35iYq6QVPZtia/fOcEhsRlbC9EhtwpWEr/vke+qoRJDU/QdQEtYtEnzoKzrNAYhb6ZnOlc capgDG6rKrAjXbht65R X-Received: by 2002:a05:6214:124d:b0:8ee:5e59:7b04 with SMTP id 6a1803df08f44-90c80e00b57mr32278996d6.18.1787288555148; Thu, 20 Aug 2026 22:02:35 -0700 (PDT) Received: from home.localdomain ([136.61.118.42]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-90c5eec1e7fsm54368116d6.12.2026.08.20.22.02.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2026 22:02:34 -0700 (PDT) From: Yanbo Zhao To: Namhyung Kim , Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Zecheng Li , Xu Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Yanbo Zhao Subject: [PATCH 2/3] perf dwarf-aux: Add C++ class, inheritance and vtable helpers Date: Fri, 21 Aug 2026 01:02:06 -0400 Message-Id: <20260821050207.4517-3-yzhao62@ncsu.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260821050207.4517-1-yzhao62@ncsu.edu> References: <20260821050207.4517-1-yzhao62@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" Add DWARF helper functions for C++ virtual function support: - cu_get_language() and cu_is_cplusplus() to detect source language. - die_get_base_class() and die_get_vtable_index() for virtual table inspection. - die_get_parent() to retrieve enclosing scopes. - die_find_member_by_offset() and die_find_virtual_func() to locate class members and virtual function DIEs. - die_is_vptr_member() to check if a member is a virtual table pointer. - Define DW_AT_vtable_elem_index and DW_LANG_C_plus_plus_17/20 fallbacks for older elfutils that lack these DWARF 5 constants. Signed-off-by: Yanbo Zhao --- tools/perf/util/dwarf-aux.c | 192 ++++++++++++++++++++++++++++++++++++ tools/perf/util/dwarf-aux.h | 24 +++++ 2 files changed, 216 insertions(+) diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c index 88ba0ec23a68..e991eed963a8 100644 --- a/tools/perf/util/dwarf-aux.c +++ b/tools/perf/util/dwarf-aux.c @@ -12,6 +12,19 @@ #include "dwarf-regs.h" #include "strbuf.h" #include "string2.h" +#include "symbol.h" + +#ifndef DW_AT_vtable_elem_index +#define DW_AT_vtable_elem_index 0x8c +#endif + +/* Added in DWARF 5, may be missing in older elfutils */ +#ifndef DW_LANG_C_plus_plus_17 +#define DW_LANG_C_plus_plus_17 0x2a +#endif +#ifndef DW_LANG_C_plus_plus_20 +#define DW_LANG_C_plus_plus_20 0x2b +#endif =20 /** * cu_find_realpath - Find the realpath of the target file @@ -60,6 +73,37 @@ const char *cu_get_comp_dir(Dwarf_Die *cu_die) return dwarf_formstring(&attr); } =20 +Dwarf_Word cu_get_language(Dwarf_Die *cu_die) +{ + Dwarf_Attribute attr; + Dwarf_Word lang; + + if (dwarf_attr(cu_die, DW_AT_language, &attr) =3D=3D NULL) + return 0; + + if (dwarf_formudata(&attr, &lang) !=3D 0) + return 0; + + return lang; +} + +bool cu_is_cplusplus(Dwarf_Die *cu_die) +{ + Dwarf_Word lang =3D cu_get_language(cu_die); + + switch (lang) { + case DW_LANG_C_plus_plus: + case DW_LANG_C_plus_plus_03: + case DW_LANG_C_plus_plus_11: + case DW_LANG_C_plus_plus_14: + case DW_LANG_C_plus_plus_17: + case DW_LANG_C_plus_plus_20: + return true; + default: + return false; + } +} + bool die_is_compound_type(Dwarf_Die *type_die) { int tag =3D dwarf_tag(type_die); @@ -68,6 +112,90 @@ bool die_is_compound_type(Dwarf_Die *type_die) tag =3D=3D DW_TAG_class_type; } =20 +static int __die_find_inheritance_cb(Dwarf_Die *die_mem, void *arg) +{ + int tag =3D dwarf_tag(die_mem); + + if (tag =3D=3D DW_TAG_inheritance) { + *(Dwarf_Die *)arg =3D *die_mem; + return DIE_FIND_CB_END; + } + + return DIE_FIND_CB_SIBLING; +} + +Dwarf_Die *die_get_base_class(Dwarf_Die *class_die, Dwarf_Die *base_die, i= nt *offset) +{ + Dwarf_Die inherit_die; + Dwarf_Attribute attr; + Dwarf_Word loc; + + if (die_find_child(class_die, __die_find_inheritance_cb, + &inherit_die, &inherit_die) =3D=3D NULL) + return NULL; + + if (__die_get_real_type(&inherit_die, base_die) =3D=3D NULL) + return NULL; + + if (dwarf_attr_integrate(&inherit_die, DW_AT_data_member_location, &attr)= && + dwarf_formudata(&attr, &loc) =3D=3D 0) { + *offset =3D loc; + } else { + *offset =3D 0; + } + + return base_die; +} + +int die_get_vtable_index(Dwarf_Die *func_die, int *index) +{ + Dwarf_Attribute attr; + Dwarf_Word idx; + + /* Try DW_AT_vtable_elem_index first (DWARF 5+) */ + if (dwarf_attr(func_die, DW_AT_vtable_elem_index, &attr) && + dwarf_formudata(&attr, &idx) =3D=3D 0) { + *index =3D idx; + return 0; + } + + /* Fallback to DW_AT_vtable_elem_location (older DWARF) */ + if (dwarf_attr(func_die, DW_AT_vtable_elem_location, &attr)) { + Dwarf_Op *expr; + size_t expr_len; + + /* Compile often emits it as a simple constant expression or block */ + if (dwarf_getlocation(&attr, &expr, &expr_len) =3D=3D 0 && expr_len > 0)= { + if (expr[0].atom =3D=3D DW_OP_constu) { + *index =3D expr[0].number; + return 0; + } + if (expr[0].atom >=3D DW_OP_lit0 && expr[0].atom <=3D DW_OP_lit31) { + *index =3D expr[0].atom - DW_OP_lit0; + return 0; + } + } + } + + return -1; +} + +Dwarf_Die *die_get_parent(Dwarf_Die *die, Dwarf_Die *parent_die) +{ + Dwarf_Die *scopes =3D NULL; + int n =3D dwarf_getscopes_die(die, &scopes); + + if (n <=3D 1) { + free(scopes); + return NULL; + } + + /* scopes[0] is the DIE itself, scopes[1] is the parent */ + *parent_die =3D scopes[1]; + free(scopes); + return parent_die; +} + /* Unlike dwarf_getsrc_die(), cu_getsrc_die() only returns statement line = */ static Dwarf_Line *cu_getsrc_die(Dwarf_Die *cu_die, Dwarf_Addr addr) { @@ -2164,6 +2292,70 @@ Dwarf_Die *die_get_member_type(Dwarf_Die *type_die, = int offset, return die_mem; } =20 +Dwarf_Die *die_find_member_by_offset(Dwarf_Die *type_die, int offset, Dwar= f_Die *member_die) +{ + if (!die_is_compound_type(type_die)) + return NULL; + + return die_find_child(type_die, __die_find_member_offset_cb, + (void *)(long)offset, member_die); +} + +struct find_virtual_func_data { + int index; + Dwarf_Die func_die; + bool found; +}; + +static int __die_find_virtual_func_cb(Dwarf_Die *die_mem, void *arg) +{ + struct find_virtual_func_data *ad =3D arg; + int tag =3D dwarf_tag(die_mem); + + if (tag =3D=3D DW_TAG_subprogram) { + int idx; + + if (die_get_vtable_index(die_mem, &idx) =3D=3D 0 && idx =3D=3D ad->index= ) { + ad->func_die =3D *die_mem; + ad->found =3D true; + return DIE_FIND_CB_END; + } + } + + if (tag =3D=3D DW_TAG_inheritance) { + Dwarf_Die base_type; + + if (__die_get_real_type(die_mem, &base_type)) { + if (die_find_child(&base_type, + __die_find_virtual_func_cb, + ad, &ad->func_die)) + return DIE_FIND_CB_END; + } + } + + return DIE_FIND_CB_SIBLING; +} + +Dwarf_Die *die_find_virtual_func(Dwarf_Die *class_die, int index, Dwarf_Di= e *die_mem) +{ + struct find_virtual_func_data ad =3D { + .index =3D index, + .found =3D false, + }; + + if (die_find_child(class_die, __die_find_virtual_func_cb, &ad, die_mem)) + return die_mem; + + return NULL; +} + +bool die_is_vptr_member(Dwarf_Die *die) +{ + const char *name =3D dwarf_diename(die); + + return name && strstarts(name, "_vptr"); +} + /** * die_deref_ptr_type - Return type info for pointer access * @ptr_die: a pointer type DIE diff --git a/tools/perf/util/dwarf-aux.h b/tools/perf/util/dwarf-aux.h index 855c45fec5bb..0f30f44ad863 100644 --- a/tools/perf/util/dwarf-aux.h +++ b/tools/perf/util/dwarf-aux.h @@ -23,9 +23,33 @@ const char *cu_find_realpath(Dwarf_Die *cu_die, const ch= ar *fname); /* Get DW_AT_comp_dir (should be NULL with older gcc) */ const char *cu_get_comp_dir(Dwarf_Die *cu_die); =20 +/* Get source language of CU */ +Dwarf_Word cu_get_language(Dwarf_Die *cu_die); + +/* Check if CU is C++ */ +bool cu_is_cplusplus(Dwarf_Die *cu_die); + /* Check if DIE is a compound type (structure, union, or class) */ bool die_is_compound_type(Dwarf_Die *type_die); =20 +/* Get base class of a class DIE */ +Dwarf_Die *die_get_base_class(Dwarf_Die *class_die, Dwarf_Die *base_die, i= nt *offset); + +/* Get vtable index of a virtual function */ +int die_get_vtable_index(Dwarf_Die *func_die, int *index); + +/* Get parent DIE */ +Dwarf_Die *die_get_parent(Dwarf_Die *die, Dwarf_Die *parent_die); + +/* Find member DIE by offset */ +Dwarf_Die *die_find_member_by_offset(Dwarf_Die *type_die, int offset, Dwar= f_Die *member_die); + +/* Find virtual function by vtable index */ +Dwarf_Die *die_find_virtual_func(Dwarf_Die *class_die, int index, Dwarf_Di= e *die_mem); + +/* Check if member DIE is a vtable pointer (_vptr) */ +bool die_is_vptr_member(Dwarf_Die *die); + /* Get a line number and file name for given address */ int cu_find_lineinfo(Dwarf_Die *cudie, Dwarf_Addr addr, const char **fname, int *lineno); --=20 2.25.1 From nobody Mon Sep 28 13:59:30 2026 Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) (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 CD1F137267E for ; Fri, 21 Aug 2026 05:02:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787288560; cv=none; b=c0D79NSmVq6YhbKI7jwNHF8ctMm2qrDJfo99LzYFzImqpk9ahZt/XTYZdbTDuR7/PZiPSx12kx4GLabIjb17XueR8ceiOQhgurd0bE5i54Z6FkiYEbifPuLFSTNf4JfN5kwpQ0d8t+Zd13rseW/FDUMSW9WfNHwdbKQPYe06PDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787288560; c=relaxed/simple; bh=8JI029aHHVd4hzfZslrLMNIc0yKFwbk2r2Yl5nBhqZQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZoKOxRO7AMYmUyQRu5LFpu0ht8ewzJYIOsYKaFP5WR3Lcj8xry3/XoyxI6MGuzVmng1l6DVqgoNbHEY9cEtJ7n5IHe27s4KiiKGrw8Z6bGgCRiC1hD8xQEr9mgw6JjRQMv5xeNKHWfSrZPo0HtXpazcP1emRKeTrfqyCkq/E0v0= 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=Qnu+ekyl; arc=none smtp.client-ip=209.85.160.170 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="Qnu+ekyl" Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-51bfe810293so2760751cf.1 for ; Thu, 20 Aug 2026 22:02:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ncsu.edu; s=google; t=1787288556; x=1787893356; 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:content-type; bh=wPbluY6yf1PyMOHReNPfj1WTJm+vQ4UBgCAO3CQP2eE=; b=Qnu+ekylt6PGtIVMUl1w2UAPs6kXzOPHHvwG3npk3y9wlxRipB9EGFmaJf1hXBmV0c CrsFK/LmqBO8zEZKicW/i0l5XTk/+GMRVD61HZGQrw1aMRknKRVjkcYT4g+3i7V8oGLJ GUO3QMrPWr/KQElJdc4zUJ+DksGYYR7iz1fcVw3d94zPC0kD0vNyV7AG4aG2nv9PlonO xgIfhC2J0HF2H2ar+3Io097+04DyeV9G3aPpYb2U5qYJoj2fcHn7xXpQfj19xYu4/YQT w3NTuE1Ha/mGE6KjX37UpbZJiBElsoRdB+nM6uzLWjxJBB1sojC3k0N2vuyy3va2XC5W puBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787288556; x=1787893356; 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:content-type; bh=wPbluY6yf1PyMOHReNPfj1WTJm+vQ4UBgCAO3CQP2eE=; b=f4dewFI813BBjncM7X/44JcYa/h/zConDfFgfWjuYDgaT2880UODtPjHZlJzAWOxku VJneinKpUDPkOmZ923yLSsSZvwpuIXJIBCcFdY/eOKS3kV5IFs8DsNHem+22cgalyvbd hnu4Cx5H9bEKZjdkIMuV3lcivDxjg0KGVW2Go+2RmSmOrY2hWMXR6rXXjrONybs8FobF dLvGoaxEEYzowYRmLkvNGW0YsGzG3j7lkcVuCDMVMGn5vZBGE/1PPsMb/Cmthhoum8ir jZZ+OpLRbHClT9SHr8dOfEOeTtHlOvkXXriwRINbfOGGXLppvVmtgQsY4FMQfWXxwct0 dESg== X-Forwarded-Encrypted: i=1; AHgh+RqllQ9dexhozqU5sdgJKXjtEOMZByGiYfUIT3o3ULVKuSiFJWzxOTJGllQV8hEB/y7WmGBddQMCgAbZDnI=@vger.kernel.org X-Gm-Message-State: AOJu0YyzJpO1pPCkJJJqZR1JjxYAC+R+oqC5OaaPOq3J5zjxwzjPGZ8L er+qnt2ccUXtBOAA46427MueJUrVRxBIaPZ8GKEe1xHJ7VrRfHULweQ4Yl2PBNnFAg== X-Gm-Gg: AR+sD13dzbmjgX2dNvoSREAE6CliwKXPgiFXF5TxCWJFSev1TTL2wTMN30V1zgXbl+O XMqb6z6LN4sp/CoEQOt9tkVOnUzwkJ7uzioscD2jNzKTwCTk9Lkmcu06eI5uvi4vNQmwxSwUsxk pDhWRdO6jnYivU1gukG6ziiuhG+a4tKYg3GT2k26mdJcjo+ZQzPaVpVzscOypyeIzDed28PmLFB 9D5UEz5SJPMFJwlogKCsyL4E0NWcUlE+yRfjsuvZp+AyO/PqsBgBy2gitAIDKDMFu4upcSkK0eQ Ab+hkGJKf0IuF2qRnpCttMYZryGSypQtnUNfY9YB/IwcPmPNFc7bkxfHqjM2Trg7oALA0Qq2kk5 9ok6K9d8bRDBRDYZiuJnNF7dv9Onip5e+TPhf+MHvwIz65QbY/v0RPoSrwL4s6/SaJLBFr3uQ2p sHkqrz2qhS0JQoyyZTxBwGdnA34HDIbzmmeaXvZo7RJkdVEkgFqXBm4ih2ZGldGuKyLcoPEmjYm u2qeyuHz/XvMfXb+zHvXg== X-Received: by 2002:a05:622a:1485:b0:52d:c1a:797a with SMTP id d75a77b69052e-52df56e48f6mr35689151cf.8.1787288556178; Thu, 20 Aug 2026 22:02:36 -0700 (PDT) Received: from home.localdomain ([136.61.118.42]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-90c5eec1e7fsm54368116d6.12.2026.08.20.22.02.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2026 22:02:35 -0700 (PDT) From: Yanbo Zhao To: Namhyung Kim , Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Zecheng Li , Xu Liu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Yanbo Zhao Subject: [PATCH 3/3] perf disasm & annotate x86: Track C++ vptr and resolve virtual function calls Date: Fri, 21 Aug 2026 01:02:07 -0400 Message-Id: <20260821050207.4517-4-yzhao62@ncsu.edu> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260821050207.4517-1-yzhao62@ncsu.edu> References: <20260821050207.4517-1-yzhao62@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" Implement disassembler and x86 type profiling support for C++ virtual dispatch and indirect call resolution: - In call__parse() for indirect calls, duplicate and store ops->raw into ops->target.raw so instruction location extraction can retrieve target operand registers and offsets. - In extract_reg_offset(), skip any leading '*' prefix (e.g. *%rax). - Add TSR_KIND_VTABLE_PTR to enum type_state_kind and handle it in pr_debug_type_name(). - In update_insn_state_x86() for mov instructions, inspect member name and identify '_vptr' access, setting register kind to TSR_KIND_VTABLE_PTR via die_is_vptr_member() helper. - For call instructions targeting virtual function tables, look up the virtual function DIE via die_find_virtual_func() before register state invalidation. Only the primary vtable is handled for now (TODO: multiple inheritance). - Update the receiver ('this' pointer) register to the C++ class DIE upon virtual call resolution when CU is C++. The register number comes from the new type_state::arg0_reg field initialized per arch like ret_reg, instead of being hardcoded. - Move caller-saved register invalidation after reading target operands to prevent losing state required for virtual call resolution. Signed-off-by: Yanbo Zhao --- tools/perf/util/annotate-arch/annotate-x86.c | 103 ++++++++++++++++--- tools/perf/util/annotate-data.c | 7 ++ tools/perf/util/annotate-data.h | 3 + tools/perf/util/annotate.c | 4 + tools/perf/util/disasm.c | 1 + 5 files changed, 105 insertions(+), 13 deletions(-) diff --git a/tools/perf/util/annotate-arch/annotate-x86.c b/tools/perf/util= /annotate-arch/annotate-x86.c index 7e6136536393..cfb37a6130ba 100644 --- a/tools/perf/util/annotate-arch/annotate-x86.c +++ b/tools/perf/util/annotate-arch/annotate-x86.c @@ -11,6 +11,8 @@ #include "../map.h" #include "../string2.h" // strstarts #include "../symbol.h" +#include "../hist.h" +#include "../dwarf-aux.h" =20 /* * x86 instruction nmemonic table to parse disasm lines for annotate. @@ -234,6 +236,11 @@ static void update_insn_state_x86(struct type_state *s= tate, struct symbol *func =3D dl->ops.target.sym; const char *call_name; u64 call_addr; + Dwarf_Die target_func_die; + bool resolved_statically =3D false; + Dwarf_Die class_die; + bool has_class_die =3D false; + struct annotated_op_loc *target_op; =20 /* Try to resolve the call target name */ if (func) @@ -245,12 +252,42 @@ static void update_insn_state_x86(struct type_state *= state, if (call_name && !strcmp(call_name, "__fentry__")) return; =20 + /* + * 1. Resolve target statically (virtual call fallback) FIRST + * (before invalidation) + */ + target_op =3D &loc.ops[INSN_OP_TARGET]; + + if (target_op->mem_ref && has_reg_type(state, target_op->reg1)) { + struct type_state_reg *reg =3D &state->regs[target_op->reg1]; + + if (reg->ok && reg->kind =3D=3D TSR_KIND_VTABLE_PTR) { + /* TODO: handle multiple inheritance (non-primary vtables) */ + int vtable_index =3D target_op->offset / 8; + Dwarf_Die target_class_die =3D reg->type; + + if (die_find_virtual_func(&target_class_die, vtable_index, + &target_func_die) && + die_get_type(&target_func_die, &type_die)) { + resolved_statically =3D true; + class_die =3D target_class_die; + has_class_die =3D true; + } + } + } + + /* Fallback to name-based resolution for direct calls */ + if (!resolved_statically && call_name) { + if (die_find_func_rettype(cu_die, call_name, &type_die)) + resolved_statically =3D true; + } + if (call_name) pr_debug_dtp("call [%x] %s\n", insn_offset, call_name); else pr_debug_dtp("call [%x] \n", insn_offset); =20 - /* Invalidate caller-saved registers after call */ + /* 2. Invalidate caller-saved registers after we read them for resolutio= n */ call_addr =3D map__rip_2objdump(dloc->ms->map, dloc->ms->sym->start + dl->al.offset); for (unsigned i =3D 0; i < ARRAY_SIZE(state->regs); i++) { @@ -264,8 +301,8 @@ static void update_insn_state_x86(struct type_state *st= ate, invalidate_reg_state(reg); } =20 - /* Update register with the return type (if any) */ - if (call_name && die_find_func_rettype(cu_die, call_name, &type_die)) { + /* 3. Apply resolved types to registers */ + if (resolved_statically) { tsr =3D &state->regs[state->ret_reg]; tsr->type =3D type_die; tsr->kind =3D TSR_KIND_TYPE; @@ -275,6 +312,20 @@ static void update_insn_state_x86(struct type_state *s= tate, pr_debug_dtp("call [%x] return -> reg%d", insn_offset, state->ret_reg); pr_debug_type_name(&type_die, tsr->kind); + + /* Update receiver ('this' pointer) register if C++ */ + if (has_class_die && cu_is_cplusplus(cu_die)) { + struct type_state_reg *recv_tsr =3D &state->regs[state->arg0_reg]; + + if (recv_tsr->ok && + (recv_tsr->kind =3D=3D TSR_KIND_TYPE || + recv_tsr->kind =3D=3D TSR_KIND_POINTER)) { + recv_tsr->type =3D class_die; + pr_debug_dtp("call [%x] update receiver reg%d to C++ class", + insn_offset, state->arg0_reg); + pr_debug_type_name(&class_die, recv_tsr->kind); + } + } } return; } @@ -622,17 +673,43 @@ static void update_insn_state_x86(struct type_state *= state, } /* And then dereference the pointer if it has one */ else if (has_reg_type(state, sreg) && state->regs[sreg].ok && - state->regs[sreg].kind =3D=3D TSR_KIND_TYPE && - die_deref_ptr_type(&state->regs[sreg].type, - src->offset + state->regs[sreg].offset, &type_die)) { - tsr->type =3D type_die; - tsr->kind =3D TSR_KIND_TYPE; - tsr->offset =3D 0; - tsr->ok =3D true; + state->regs[sreg].kind =3D=3D TSR_KIND_TYPE) { + Dwarf_Die class_type; + Dwarf_Die member; + int total_offset =3D src->offset + state->regs[sreg].offset; + bool is_vptr =3D false; + + if (die_get_real_type(&state->regs[sreg].type, &class_type) && + die_is_compound_type(&class_type) && + die_find_member_by_offset(&class_type, total_offset, &member) && + die_is_vptr_member(&member)) { + tsr->type =3D class_type; + tsr->kind =3D TSR_KIND_VTABLE_PTR; + tsr->offset =3D 0; + tsr->ok =3D true; =20 - pr_debug_dtp("mov [%x] %#x(reg%d) -> reg%d", - insn_offset, src->offset, sreg, dst->reg1); - pr_debug_type_name(&tsr->type, tsr->kind); + pr_debug_dtp("mov [%x] %#x(reg%d) -> reg%d (vptr)", + insn_offset, src->offset, + sreg, dst->reg1); + pr_debug_type_name(&class_type, tsr->kind); + is_vptr =3D true; + } + + if (!is_vptr) { + if (die_deref_ptr_type(&state->regs[sreg].type, + total_offset, &type_die)) { + tsr->type =3D type_die; + tsr->kind =3D TSR_KIND_TYPE; + tsr->offset =3D 0; + tsr->ok =3D true; + + pr_debug_dtp("mov [%x] %#x(reg%d) -> reg%d", + insn_offset, src->offset, sreg, dst->reg1); + pr_debug_type_name(&tsr->type, tsr->kind); + } else { + invalidate_reg_state(tsr); + } + } } /* Handle dereference of TSR_KIND_POINTER registers */ else if (has_reg_type(state, sreg) && state->regs[sreg].ok && diff --git a/tools/perf/util/annotate-data.c b/tools/perf/util/annotate-dat= a.c index ee6bd2d0012d..875e5ba2fe9f 100644 --- a/tools/perf/util/annotate-data.c +++ b/tools/perf/util/annotate-data.c @@ -28,6 +28,8 @@ =20 /* register number of the stack pointer */ #define X86_REG_SP 7 +/* register number of the first integer argument (%rdi) */ +#define X86_REG_DI 5 =20 static void delete_var_types(struct die_var_type *var_types); =20 @@ -66,6 +68,10 @@ void pr_debug_type_name(Dwarf_Die *die, enum type_state_= kind kind) pr_info(" pointer"); /* it also prints the type info */ break; + case TSR_KIND_VTABLE_PTR: + pr_info(" C++ vtable pointer"); + /* it also prints the type info */ + break; case TSR_KIND_CANARY: pr_info(" stack canary\n"); return; @@ -177,6 +183,7 @@ static void init_type_state(struct type_state *state, c= onst struct arch *arch) state->regs[10].caller_saved =3D true; state->regs[11].caller_saved =3D true; state->ret_reg =3D 0; + state->arg0_reg =3D X86_REG_DI; state->stack_reg =3D X86_REG_SP; } } diff --git a/tools/perf/util/annotate-data.h b/tools/perf/util/annotate-dat= a.h index c26130744260..785e1d1777ce 100644 --- a/tools/perf/util/annotate-data.h +++ b/tools/perf/util/annotate-data.h @@ -36,6 +36,7 @@ enum type_state_kind { TSR_KIND_CONST, TSR_KIND_PERCPU_POINTER, TSR_KIND_POINTER, + TSR_KIND_VTABLE_PTR, TSR_KIND_CANARY, }; =20 @@ -224,6 +225,8 @@ struct type_state { struct list_head stack_vars; /* return value register */ int ret_reg; + /* first integer argument register (holds 'this' for C++ methods) */ + int arg0_reg; /* stack pointer register */ int stack_reg; }; diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c index df70e95a8470..b4c6b45b4da3 100644 --- a/tools/perf/util/annotate.c +++ b/tools/perf/util/annotate.c @@ -2509,6 +2509,10 @@ static int extract_reg_offset(const struct arch *arc= h, const char *str, if (arch->objdump.register_char =3D=3D 0) return -1; =20 + /* Skip leading '*' for indirect call/jmp operands (e.g. *%rax) */ + if (*str =3D=3D '*') + str++; + /* * It should start from offset, but it's possible to skip 0 * in the asm. So 0(%rax) should be same as (%rax). diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index 6cfdbabbb8c7..01266eeddbb4 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -279,6 +279,7 @@ static int call__parse(const struct arch *arch, struct = ins_operands *ops, struct return 0; =20 indirect_call: + ops->target.raw =3D strdup(ops->raw); tok =3D strchr(endptr, '*'); if (tok !=3D NULL) { endptr++; --=20 2.25.1