From patchwork Fri Feb 16 16:30:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 773363 Delivered-To: patch@linaro.org Received: by 2002:a5d:4943:0:b0:33b:4db1:f5b3 with SMTP id r3csp28039wrs; Fri, 16 Feb 2024 08:39:06 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCX5XIZsNBrcPy9408vL77Zu7EKPz5cZ6c1+91aeitds3EXKIIFy8ns3aXrRSs7k+B1soRfXyTSLyWjXYMVAvkYL X-Google-Smtp-Source: AGHT+IH6Qtwb3T+3ZSF/2koxOFn9K+lfZxNE2IItbrRiblH+iH4XButDt1NEu3dLtKsL9Zt6RDLf X-Received: by 2002:a05:620a:a54:b0:787:2b67:23f8 with SMTP id j20-20020a05620a0a5400b007872b6723f8mr5949007qka.32.1708101546033; Fri, 16 Feb 2024 08:39:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708101546; cv=none; d=google.com; s=arc-20160816; b=CcERxQPqUuWHB7S/lDU10TNvutBE9PX3wHXWIKKLR1jSXn62xz6unojkuiSuIZhJ50 wGwOlahti+0BTz24XLxA3YmN4ACnxq3BPvc6l83VxDK6tft7G8BWrAGb+y3kZmxOL4N6 VhRXlcPbI0OPFl2Y2eKlucqQ+ogAA1iEHpJO0dxDlVqDgncW4AyVq6AV40EFJznFsStw Y1epdKQeaJuP/uySJQ5nhYCORiY1Bkdr7oKRpkY8+Lf59DKSTla8C9q9ayrl2R3Fk//y 6g2ef87pt5JAr4oiO2I5qs7Jb/iRmr9i26mtWyzQss/jxCHpF57SiEbijkXD0s1Q81SP 87lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pTAh5Ga1/WCguB9K86wBQIKOB8LucCe9FRfIk+dLcDE=; fh=edBBzxC9D4aeJQkoOTUe3r9rrX1lOuBdxVr2qjfDcVQ=; b=lE7EM3eOBeC8LnGOIxOHpaolmF83Ky2+QC+4/nNMmEBfZ+HGiI6JV84bRnTtg2aRzT LJHQxLa/nHr5/QE64hnV2GmSv0pZxjKVefnsLEjJxIMxcIcujsUi21qJtV739Qhq3MT6 bFF/OA5JW0psw4SgQKLSvI8k0hnNm3mZLuZ/dbXLbUTarzF1IxgWPHJ1f980mnL2Kkdm QqOIrtnEhxAzPCTdfJ8UOPpyycC5mViHmjfOyhJHpP04n91BlQcoTlsitw1NVzaIhjJK qDFm1ljsFuMiepdhe0SKEgh4KSN+mpZH+v3YWQtlx0TVK639C2k5/C+0f5Cj8/vkhpZZ +NhQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CgvQ5w2G; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x17-20020a05620a449100b00785da09de76si278116qkp.72.2024.02.16.08.39.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 16 Feb 2024 08:39:06 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CgvQ5w2G; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rb1Dh-0001Kx-9p; Fri, 16 Feb 2024 11:37:49 -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 1rb1De-0001Hh-Ri for qemu-devel@nongnu.org; Fri, 16 Feb 2024 11:37:46 -0500 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rb1DV-00044E-4d for qemu-devel@nongnu.org; Fri, 16 Feb 2024 11:37:46 -0500 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-33d26da3e15so149032f8f.1 for ; Fri, 16 Feb 2024 08:37:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708101455; x=1708706255; 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=pTAh5Ga1/WCguB9K86wBQIKOB8LucCe9FRfIk+dLcDE=; b=CgvQ5w2Gx4wB8CDP8vaTVBGcGz9xHay+XB97NEKqh9nOZvGpi1A9FqkMPQ3oCJFR+Q 9/NSdWGdX1xVzgYgG5x7pDXEHNwwXlJJ6Xfo/f0IkE5/GDL4SCECLAPynNFBbmli8ETg egxevGdMgObJLgZoiXJi93Px5yMCye+O7Fsj9n82Mrg0D4Lf0YMlb6JaZ/c8X4MDg4HF veRCWX50w277km1RFTb6xrCcmqxY/hX03sLsiAM19FWLtMSyhm4bWg5nMW3V2K1vqVjR k1MH1BuoK8XYMmVTY4K1v84Bf/6/nWGwH7ZWJ0uG5x706v5DPWlxGtUyZqN4VsPDMMuj 0wmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708101455; x=1708706255; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pTAh5Ga1/WCguB9K86wBQIKOB8LucCe9FRfIk+dLcDE=; b=tQhq1V0fZcJ3y+VUpAsb1c0nBJk7clbkq8Fnkcwv3Qz6WGqC3nst274pRsElcJynG7 OC1a0R6wr1003Fd8DzMIP2jCHi2d0y8EeZVjIpA4RTtbfOFjU2ChphK86ax+amshmFAw Ad0Oym+gAfe0UmOqDw4eAiwZD70rBeWC3ebaeUdnp2AgNvZKBvVeby3jB+Ianefe5xUo scGCkmthvjCk7/TOW8sCicPvM0sEem+P9Ccl+qQ/cfPonBYszgvRVZ1fEB8cEKlbUcEo YY5atNYUqHfzfpvKmZ3876fabAZ7+Pq///Uw4L4fBakXWstQi91TKXQwBaksCZshpuBl H7xQ== X-Gm-Message-State: AOJu0YyWsJUh3mXGFp5aUQduYJcFN0l6epeGblHnmmshbHOiFnnN8/ad 1pTYEn0COvKSMuv7R2zjoOVj1fjRQflGKxcjtMQSi/giGYIrlG6vm8dZ8wqh6u4= X-Received: by 2002:adf:e947:0:b0:33d:2567:995c with SMTP id m7-20020adfe947000000b0033d2567995cmr820513wrn.1.1708101455066; Fri, 16 Feb 2024 08:37:35 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id t12-20020a5d460c000000b0033b48190e5esm2633756wrq.67.2024.02.16.08.37.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 08:37:32 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 06B685F9E3; Fri, 16 Feb 2024 16:30:28 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Yoshinori Sato , David Hildenbrand , Weiwei Li , Richard Henderson , Michael Rolnik , Ilya Leoshkevich , Peter Maydell , qemu-ppc@nongnu.org, Paolo Bonzini , qemu-riscv@nongnu.org, Cleber Rosa , Thomas Huth , Song Gao , qemu-arm@nongnu.org, Pierrick Bouvier , John Snow , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?C=C3=A9dri?= =?utf-8?q?c_Le_Goater?= , Nicholas Piggin , qemu-s390x@nongnu.org, Laurent Vivier , "Edgar E. Iglesias" , Daniel Henrique Barboza , Yanan Wang , Palmer Dabbelt , Marcel Apfelbaum , Brian Cain , Mahmoud Mandour , Alexandre Iooss , Bin Meng , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Daniel Henrique Barboza , Eduardo Habkost , Alistair Francis , Liu Zhiwei , Akihiko Odaki Subject: [PATCH 17/23] gdbstub: expose api to find registers Date: Fri, 16 Feb 2024 16:30:19 +0000 Message-Id: <20240216163025.424857-18-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240216163025.424857-1-alex.bennee@linaro.org> References: <20240216163025.424857-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x436.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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Expose an internal API to QEMU to return all the registers for a vCPU. The list containing the details required to called gdb_read_register(). Based-on: <20231025093128.33116-15-akihiko.odaki@daynix.com> Cc: Akihiko Odaki Message-Id: <20240103173349.398526-38-alex.bennee@linaro.org> Signed-off-by: Alex Bennée --- v3 - rm unused api functions left over --- include/exec/gdbstub.h | 28 ++++++++++++++++++++++++++++ gdbstub/gdbstub.c | 27 ++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index da9ddfe54c5..eb14b91139b 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -111,6 +111,34 @@ void gdb_feature_builder_end(const GDBFeatureBuilder *builder); */ const GDBFeature *gdb_find_static_feature(const char *xmlname); +/** + * gdb_read_register() - Read a register associated with a CPU. + * @cpu: The CPU associated with the register. + * @buf: The buffer that the read register will be appended to. + * @reg: The register's number returned by gdb_find_feature_register(). + * + * Return: The number of read bytes. + */ +int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); + +/** + * typedef GDBRegDesc - a register description from gdbstub + */ +typedef struct { + int gdb_reg; + const char *name; + const char *feature_name; +} GDBRegDesc; + +/** + * gdb_get_register_list() - Return list of all registers for CPU + * @cpu: The CPU being searched + * + * Returns a GArray of GDBRegDesc, caller frees array but not the + * const strings. + */ +GArray *gdb_get_register_list(CPUState *cpu); + void gdb_set_stop_cpu(CPUState *cpu); /* in gdbstub-xml.c, generated by scripts/feature_to_c.py */ diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index a55b5e6581a..2909bc8c69f 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -490,7 +490,32 @@ const GDBFeature *gdb_find_static_feature(const char *xmlname) g_assert_not_reached(); } -static int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg) +GArray *gdb_get_register_list(CPUState *cpu) +{ + GArray *results = g_array_new(true, true, sizeof(GDBRegDesc)); + + /* registers are only available once the CPU is initialised */ + if (!cpu->gdb_regs) { + return results; + } + + for (int f = 0; f < cpu->gdb_regs->len; f++) { + GDBRegisterState *r = &g_array_index(cpu->gdb_regs, GDBRegisterState, f); + for (int i = 0; i < r->feature->num_regs; i++) { + const char *name = r->feature->regs[i]; + GDBRegDesc desc = { + r->base_reg + i, + name, + r->feature->name + }; + g_array_append_val(results, desc); + } + } + + return results; +} + +int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg) { CPUClass *cc = CPU_GET_CLASS(cpu); GDBRegisterState *r;