From nobody Wed Feb 11 09:01:12 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1770754475; cv=none; d=zohomail.com; s=zohoarc; b=ZMSc9BsvlG4QWJBF5zxDJS4R3UQmlgLHlGYXGxqGyJtfsOW7FJxdonX2ofkiEU/zydm5X8uI8j0QrUSuf+dsWuJ5ZkAzZXTdj8UGTVwwr0w9XEEx5QNn/Qud/QuBQlCFInBJtzl7PUcqAyc2mg/mbX8SfqYIUH2ur5JkmERsnoI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770754475; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=f6lfjFGTpP9sqItRbR9rxD4pmFfc0wMz2+PxtkzkfnQ=; b=VqX8RpshKjJC8PfOjSobwvgnf7DXtXAjlChTgD2NY9q++3Z+W9A1MuGi1NtB5UBEXAUex/aRJ3xh7Qgi4Bj+c4kJ36w0iRKT29F5m1Qywb029JFdm4F2teHpTqO3rqprxdbC+IbHNKOv2qMsHk8HhXLfmhBuiVblpQnHd1MbJV8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177075447522210.288557398979265; Tue, 10 Feb 2026 12:14:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vpu7X-0005ox-2d; Tue, 10 Feb 2026 15:14:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vpu7V-0005nX-5i for qemu-devel@nongnu.org; Tue, 10 Feb 2026 15:14:01 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vpu7T-0007nU-0b for qemu-devel@nongnu.org; Tue, 10 Feb 2026 15:14:00 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-2aae4816912so18824215ad.2 for ; Tue, 10 Feb 2026 12:13:58 -0800 (PST) Received: from pc.taild8403c.ts.net (216-71-219-44.dyn.novuscom.net. [216.71.219.44]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c6dcb5e3e8csm13930031a12.21.2026.02.10.12.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Feb 2026 12:13:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770754437; x=1771359237; darn=nongnu.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=f6lfjFGTpP9sqItRbR9rxD4pmFfc0wMz2+PxtkzkfnQ=; b=byyrD16t911RaHKcTnnf4F34A/v6HvcCCX7bwBq4thWDJ/xm8PW9IiIM5KcDjQ+zX7 Cdy/zUQvurvDJgpl+NNuVCFkFHAe68TxzHyLaJhtKOqND/+lEReTa+V4y7vsQKdgPLAe d6/79+dYo0K+BzmFCkKqxjlhSxOqZQ4Rj9DEZdw06f946trJUKFiCgWcHnfLcwvk5Sq3 hKFOLr3o93WNr9I+13PBNWl15lW8e4sey3Z5eAj70+fp+9vrQ8TuqRAo42zY/eXMb/Mh JZhUsoLS2BPsJ3oDgST81MpRTMSK0/lHp1xTQvRHjeUrZugN3or3MLCEQlM6QdbFUzd5 C7tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770754437; x=1771359237; 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=f6lfjFGTpP9sqItRbR9rxD4pmFfc0wMz2+PxtkzkfnQ=; b=G6RlZU5XQcU/9/Aspq3WXh2QLTh30h1EF+43L9LR/Zh04t6blygiyb0Lluev2cqznX SYtaIMwkdYQi7UPZRwC9HM/4OkCTX43urXCnAUNYsFfZDvRW745sswwAUsrXRN7dEHOF jeYGntwIpDGZe48PDWEe5ag5usKOoUJwkc/ZuTU6XHMBYFjdzkGVnR63tNNmwUHHz3dJ 7yuL6NQXHHi7aK2ngSKvm82yQuwvFaO5u6sZtWV5yoRfE6gUWN3E2icCgvuD0ewJpad7 qmtpOt9Wb5iomCnt0U1HH8eq9xiAG1PqFCAV2S1Rb3hiFub2rzeb6ZUeiJpRVMayoDv9 qC4w== X-Gm-Message-State: AOJu0Yyvgs3Px4debkCnMe3JJU3ZPUhVfvEiEfhvo2jTOLNgNndEz7Mk rmAol37vCLbR88rr1tKoGqyeT+Sw0BNNdhg7izPsgwDEWwgIAFnwnhMiNKwNZvfrHgfmzjT+a9a iIw6j X-Gm-Gg: AZuq6aKpUr1iVNm3P8xk8Wb7j/qrnz8j10sU3KuQwPXMD2kt9aaUeYVEiqNmlTctZe4 6p3DYgtht5AtLfKPDtRJYasD/fhwzdOym2aQqPaXL6VrafVvUWdZ5SXhuQ5pUxWV0GWQ3lgqNul y/n9TuViCjoGnWe+VdR3s4hsBZPTyNiGtIjxUAzNQDIYe+ic5R4q02dyXcj9nCZ1ZT5EKwWVi9e ophswsZuyWEixpo8yohQfq5Vls27yRFfmveCoLN2M3uTy/xXTEHNacWEg12c2waZPJaP4BYe0nn 65mSb5qes4gT0Vcc4ESRX9GS2CkUKGmoeGRtqjGIZ6eZBm9Jcxmkmn57Z8yVfAwg+cupveVezhH CVJ61N1VfmcAWVF8ygKySqxe6MBgUu6r5+1mOR1+vkyk7Dif4/ZUQxmFX3oMyxk8q7MaIL9Sn9j AZEWt9ziNqnvrNZvR9Il5QIXFLVuW43pstfiozCjJtJQdk7b8X7w6DxVTbg+NhnKA3bL7S5+y29 T3im7+6LKwPEEc= X-Received: by 2002:a17:903:b46:b0:2aa:f43d:7c42 with SMTP id d9443c01a7336-2ab27d13dd8mr2959015ad.24.1770754437398; Tue, 10 Feb 2026 12:13:57 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Alexandre Iooss , Pierrick Bouvier , alistair.francis@wdc.com, Mahmoud Mandour , manos.pitsidianakis@linaro.org, philmd@linaro.org, anjo@rev.ng, brian.cain@oss.qualcomm.com Subject: [PATCH 2/4] contrib/plugins/uftrace: add ops for walking frame pointers chain Date: Tue, 10 Feb 2026 12:13:42 -0800 Message-ID: <20260210201344.1403613-3-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260210201344.1403613-1-pierrick.bouvier@linaro.org> References: <20260210201344.1403613-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1770754478291158501 Content-Type: text/plain; charset="utf-8" x86_64 and aarch64 use same stack layout. However, other architectures might use different offset for return address and next frame pointer. Signed-off-by: Pierrick Bouvier Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- contrib/plugins/uftrace.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/contrib/plugins/uftrace.c b/contrib/plugins/uftrace.c index 1ed982999ed..21ac1402047 100644 --- a/contrib/plugins/uftrace.c +++ b/contrib/plugins/uftrace.c @@ -46,6 +46,8 @@ typedef struct { void (*init)(Cpu *cpu); void (*end)(Cpu *cpu); uint64_t (*get_frame_pointer)(Cpu *cpu); + uint64_t (*get_next_frame_pointer)(Cpu *cpu, uint64_t fp); + uint64_t (*get_next_return_address)(Cpu *cpu, uint64_t fp); uint8_t (*get_privilege_level)(Cpu *cpu); uint8_t (*num_privilege_levels)(void); const char *(*get_privilege_level_name)(uint8_t pl); @@ -421,7 +423,9 @@ static uint32_t cpu_read_register32(Cpu *cpu, struct qe= mu_plugin_register *reg) =20 static uint64_t cpu_read_memory64(Cpu *cpu, uint64_t addr) { - g_assert(addr); + if (!addr) { + return 0; + } GByteArray *buf =3D cpu->buf; g_byte_array_set_size(buf, 0); bool read =3D qemu_plugin_read_memory_vaddr(addr, buf, 8); @@ -449,10 +453,8 @@ static void cpu_unwind_stack(Cpu *cpu, uint64_t frame_= pointer, uint64_t pc) CallstackEntry e =3D {.frame_pointer =3D frame_pointer, .pc =3D pc= }; unwind[depth] =3D e; depth++; - if (frame_pointer) { - frame_pointer =3D cpu_read_memory64(cpu, frame_pointer); - } - pc =3D cpu_read_memory64(cpu, frame_pointer + 8); /* read previous= lr */ + frame_pointer =3D cpu->ops.get_next_frame_pointer(cpu, frame_point= er); + pc =3D cpu->ops.get_next_return_address(cpu, frame_pointer); } while (frame_pointer && pc && depth < UNWIND_STACK_MAX_DEPTH); #undef UNWIND_STACK_MAX_DEPTH =20 @@ -545,6 +547,16 @@ static uint64_t aarch64_get_frame_pointer(Cpu *cpu_) return cpu_read_register64(cpu_, cpu->reg_fp); } =20 +static uint64_t aarch64_get_next_frame_pointer(Cpu *cpu_, uint64_t fp) +{ + return cpu_read_memory64(cpu_, fp); +} + +static uint64_t aarch64_get_next_return_address(Cpu *cpu_, uint64_t fp) +{ + return cpu_read_memory64(cpu_, fp + 8); +} + static void aarch64_init(Cpu *cpu_) { Aarch64Cpu *cpu =3D g_new0(Aarch64Cpu, 1); @@ -580,6 +592,8 @@ static CpuOps aarch64_ops =3D { .init =3D aarch64_init, .end =3D aarch64_end, .get_frame_pointer =3D aarch64_get_frame_pointer, + .get_next_frame_pointer =3D aarch64_get_next_frame_pointer, + .get_next_return_address =3D aarch64_get_next_return_address, .get_privilege_level =3D aarch64_get_privilege_level, .num_privilege_levels =3D aarch64_num_privilege_levels, .get_privilege_level_name =3D aarch64_get_privilege_level_name, @@ -623,6 +637,16 @@ static uint64_t x64_get_frame_pointer(Cpu *cpu_) return cpu_read_register64(cpu_, cpu->reg_rbp); } =20 +static uint64_t x64_get_next_frame_pointer(Cpu *cpu_, uint64_t fp) +{ + return cpu_read_memory64(cpu_, fp); +} + +static uint64_t x64_get_next_return_address(Cpu *cpu_, uint64_t fp) +{ + return cpu_read_memory64(cpu_, fp + 8); +} + static void x64_init(Cpu *cpu_) { X64Cpu *cpu =3D g_new0(X64Cpu, 1); @@ -649,6 +673,8 @@ static CpuOps x64_ops =3D { .init =3D x64_init, .end =3D x64_end, .get_frame_pointer =3D x64_get_frame_pointer, + .get_next_frame_pointer =3D x64_get_next_frame_pointer, + .get_next_return_address =3D x64_get_next_return_address, .get_privilege_level =3D x64_get_privilege_level, .num_privilege_levels =3D x64_num_privilege_levels, .get_privilege_level_name =3D x64_get_privilege_level_name, @@ -710,7 +736,7 @@ static void track_callstack(unsigned int cpu_index, voi= d *udata) return; } =20 - uint64_t caller_fp =3D fp ? cpu_read_memory64(cpu, fp) : 0; + uint64_t caller_fp =3D cpu->ops.get_next_frame_pointer(cpu, fp); if (caller_fp =3D=3D top.frame_pointer) { /* call */ callstack_push(cs, (CallstackEntry){.frame_pointer =3D fp, .pc =3D= pc}); --=20 2.47.3