From patchwork Fri Feb 23 16:21:54 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: 775159 Delivered-To: patch@linaro.org Received: by 2002:adf:a356:0:b0:33b:4db1:f5b3 with SMTP id d22csp439154wrb; Fri, 23 Feb 2024 08:47:08 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCU1eKmzsqgilVHVe6CqQeht22/g+cHp2An+KqH27XpGlXgJSPCba6QQZlY7zQMJB4jF+gD6ZtFfEdO1lejaQQqw X-Google-Smtp-Source: AGHT+IEflNbujIWQSXlT76dlWs47s299ui+EFNpN4wcBFCNWcFof9mTj+0AEs8zt/hpf2yVLFRKb X-Received: by 2002:a05:6830:651b:b0:6e4:63e3:3f9e with SMTP id cm27-20020a056830651b00b006e463e33f9emr416607otb.11.1708706828608; Fri, 23 Feb 2024 08:47:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1708706828; cv=none; d=google.com; s=arc-20160816; b=UTXMTxh2li9/w6yQUCRsVLRFtX9gY56glgR8KV0A+6GHgen4nG21tABN5CdZYR5X40 c0YT4EZS0I0jmulxNRyx092cQdvJDlAbOicI8jIxn21l9GnajOpXgN0BJ2MjhueUPkqM wrBOvPuaBlu0TdboD4eD9AK1jzzNmQwV3cPLUDI7IFnJm2wfh5hGUKTOrG7PMOuScO1B zg4j/dfBGHsEkSevILMqC1V2sdMpR7quHDY8x+G8bUBVCddI7lzgsBbQkYcYRcV0vcoZ zFXMsqgl9THQYXekvoQyM1XEFfXO42W0gOUepGzHEPJDe4GI4ET+LVOCEzYnRBl0xR7K RGxQ== 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=2IXDtwkhE3u9iDHwRQ543d03t9X1toYDqf9u6DZTCZM=; b=UzD3SYzr6lEIP6g6KzWoLubcQ9/pLxxKnwGgff720bID8DTQFYfc79miAO0YMeS6jR 9mjBnMb6A2GX3qVmsmpBgq6+5+YiKHC4wvTGpd+gz79506wEouqknEtxn+MLOxH4SRfn ucCx0JpWIV7IHs5+0cipho8WL7s/n4npdHv8pLkdXI/yPZrvBN0wJSYWV26BkOqSZMD/ ZMDq/ZwyqkbKDiQYaHWM0fbS4W3caUKkGClh71OZYzvAauZf5PUMJU+gQ9RpyER4SnBR 1VMQan2CIny22XkUQc+VlAFwXmiBgWQaibRneZQQc33jOkAH79tMHwGLJMvQuhv4D5G7 j4jw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D5Qbc2mI; 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 b11-20020ac85bcb000000b0042e15265636si2437170qtb.86.2024.02.23.08.47.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 23 Feb 2024 08:47:08 -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=D5Qbc2mI; 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 1rdYfn-0000aq-Kg; Fri, 23 Feb 2024 11:45:19 -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 1rdYQC-00061F-5b for qemu-devel@nongnu.org; Fri, 23 Feb 2024 11:29:12 -0500 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rdYPs-0007H7-Nc for qemu-devel@nongnu.org; Fri, 23 Feb 2024 11:29:11 -0500 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-4127700a384so3855725e9.3 for ; Fri, 23 Feb 2024 08:28:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708705731; x=1709310531; 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=D5Qbc2mIwW/V4XLgzIGHp/kNEzVRFTHk5RKMvL8jgiQ9S6k9CQa+9GB/u6jfgGTfiT tMcCEmrqqj2t/jiHcp8ssU+PdBN59xTfdw9oMtNT6vsr6KGa8CDj12NgyUmIfcxPBc5+ bP3E4YTEpr7Eo7j6K5GMLUOFcs70A2fqzPndt2n5p9bT7t/8Eb4nthb4uc2fuLDhoU7y GXw3QQslqhORFIz5NqrgUsYrbqby/7ZOjpS4zhz5v0t8AoI5+btEH83vBG/Ct/ee7Bfc WtQVHkDoX+UkIBjyTMo/pqtUNIQfLkSOVURjgqpdnneQkv4ddr0gTQu4XJqzmWJpdlj/ JWQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708705731; x=1709310531; 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=KA78dPG1IfNCeffoKCxsHPunHvgD+rQiZI9OrZ1Iomm9c2ADih9f8mQERdMCP/ssAl cEq7252M8nHBlx2jWQYNWX+mQzNm+CiJu1We2DzwnOItGWisAHgJ2O8p0bxYVwY03bJj d9BdvO1mgIZPtYlUNPd/HAg46waYKDG86K4PNVWvzW90m38igx4r0nHKC9X8eUnXZdDZ gxcFp67Sz3xczRzXYCuD55zH64UytDVS+CbtPbDAOslG6EZmDA7lZ1ehUB+AD6gLPZoV kTWXhDW6Kq5fEpZEw4GD+qhPHHkUdJmmF1ni1zbMw2wcmpjXVKTM++44xm8ngaDDBP77 GjhQ== X-Gm-Message-State: AOJu0YxrvsSCK3AVo7HOiXykvwuLFFt0NLlgZRnzjtme9LyebJ1IlZ2h iV00nfJYEjYTfyh/7fzo54Le9KjP8HQcSkI+3Y+vYSFtKS/owmdvm7SMswUh0Eg= X-Received: by 2002:a05:600c:4504:b0:411:c9c0:eddf with SMTP id t4-20020a05600c450400b00411c9c0eddfmr184267wmo.36.1708705731296; Fri, 23 Feb 2024 08:28:51 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id m4-20020a05600c4f4400b004128d6ddad3sm3029019wmq.0.2024.02.23.08.28.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 08:28:46 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 58E415F934; Fri, 23 Feb 2024 16:22:04 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Song Gao , qemu-s390x@nongnu.org, Liu Zhiwei , Pierrick Bouvier , Thomas Huth , Daniel Henrique Barboza , Bin Meng , Yanan Wang , Laurent Vivier , qemu-ppc@nongnu.org, David Hildenbrand , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Ilya Leoshkevich , Cleber Rosa , Nicholas Piggin , Marcel Apfelbaum , Eduardo Habkost , Richard Henderson , =?utf-8?q?Philippe_Mathie?= =?utf-8?q?u-Daud=C3=A9?= , Alexandre Iooss , Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , Daniel Henrique Barboza , qemu-arm@nongnu.org, qemu-riscv@nongnu.org, Palmer Dabbelt , Mahmoud Mandour , John Snow , Weiwei Li , Alistair Francis , Yoshinori Sato , Brian Cain , Paolo Bonzini , "Edgar E. Iglesias" , Michael Rolnik , Akihiko Odaki Subject: [PATCH v2 19/27] gdbstub: expose api to find registers Date: Fri, 23 Feb 2024 16:21:54 +0000 Message-Id: <20240223162202.1936541-20-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240223162202.1936541-1-alex.bennee@linaro.org> References: <20240223162202.1936541-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x329.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;