From patchwork Wed Jan 3 17:33:43 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: 759648 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp6615470wrw; Wed, 3 Jan 2024 09:49:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHDYbpDGmaWOANFHd1DQX2DeVDSAyI0NFeco2T9SkvzySQXB2qKK6tecC3+YfAx/HrZBPIK X-Received: by 2002:a25:688d:0:b0:dbd:4883:44ce with SMTP id d135-20020a25688d000000b00dbd488344cemr10891111ybc.32.1704304146741; Wed, 03 Jan 2024 09:49:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704304146; cv=none; d=google.com; s=arc-20160816; b=yJjvGMnSDE7Ufm6JrVElaJoRkcBa/qfU5+H3YAGsude89lFgYxDZw97upfTJqxbwlB qbN99WhMptk/2usK3d5rHbSioWq3J+XRz/X97c0xBXgy0R3yQxtMe8FQ+uDa8+/k/AQy Ag3p2nFNvuHJsMQGFOn0rSR8kIWIWFvDsoY8fmQJityoY2zV8Nvbr/4LN0sirxkIl1w5 /zUXhC/7BLq5XKPwhtJp09LX9DS8r7QNBGApP5iqo5QOqReHafLolnlATTNq2XB9bHvK ziHV7z39400Te6cwxOF9w5HQmf8phSumLZJdteThFauGg5PG7/cZz6Euw1laUbdI07Hp AAlQ== 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=s7b3xpykHeaHl4suIRJtcydNJ+7RVLNIDOZxUbbJygc=; fh=MptfaR+7adpcaME/63X0fm8Oaab8Ri8YJu2OQMap89k=; b=WaPac2XBqSQyB44yr8q+GLIpvgEJEr+AJyfbyHYVp1iXsDbIaQ5ctqhCt6tuJ++gzC bZ3ojabSK8zeqlpRsH7jnr+dcyky5nqxkEd1u1e7/jkpKc/pbq0krmmSxMirkWyVvOti M65kHtnQG4ve2E1e/MmGpGCgXu29VIRsYjZYm4Uc5smOnwjBcVE/7VXbEH0b6wRkEguJ n6sNUZ1t5up9IcdD0/46ZCiu25wxPqdCEvJ3Kr12RHOx7kqH6ptwY6XKyql5/YKBqlBK rUkS6XlrHOkJw9hvNEvNJvhmAKc0mxw2V95rv7nYQmCdbFMSOOBhoiVo0ldYciOrMnKB PwZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YzclKS91; 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 n19-20020a05622a11d300b004281a12a0d8si8242257qtk.280.2024.01.03.09.49.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 Jan 2024 09:49: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=YzclKS91; 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 1rL5DP-0007fH-IQ; Wed, 03 Jan 2024 12:39:39 -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 1rL5DB-0006Ys-Re for qemu-devel@nongnu.org; Wed, 03 Jan 2024 12:39:26 -0500 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rL5Cx-0000fe-RY for qemu-devel@nongnu.org; Wed, 03 Jan 2024 12:39:24 -0500 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-3367632ce7bso9142545f8f.2 for ; Wed, 03 Jan 2024 09:39:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704303550; x=1704908350; 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=s7b3xpykHeaHl4suIRJtcydNJ+7RVLNIDOZxUbbJygc=; b=YzclKS91ROCiEUliPREbJ5vhRAlB73+Wjwf5IUCj09NEb4igPTjVwdzZtGqYJyNB0j pKngCV8XMGc+JaptJLXYKK5bfZ9EcjbIiza2IvHSZILsb9t8PUjGDnYYGfoWDntAQwy8 leW35p4ZsWi+18Ui7IF7BaxMSF18azdmtbT2FhYyjGNLTq9dXRBwKxH8eRrYWuREFdgt iTfKDQ6sxNCEIfvqPLaxXZztRpUBafpsmJXIhi3PjaqApHPscXEvhGfNOEcmTVWYvwCN 5WY2qMZX+NwIxFpC3l43/WT+S0zQUES/hc/kteddsPrrrTkVdG80dZrg6wlnf692WfyC 1Qcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704303550; x=1704908350; 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=s7b3xpykHeaHl4suIRJtcydNJ+7RVLNIDOZxUbbJygc=; b=IlIuhKZIX0ye5aLntQtt65MzicjHda5E9oaWShT3KijD0q4d5w6+TH5uJECagl7Y4h TLE10MYk7lr9SGHA+ym8ZTxqQ7SHBHJ/V/c6LIzH5nSAx5AOIa1nUG3PtF7r60nreKBC Ya1Td+XUQignLXKu/Brfgw9PyHD7W8oZB68091gxhQKj8l2xgbn4+PXOfcEWMRgr2+HD nF+vZrHusnkApKux8P3sjAoshm7ygMtp+4dsQfOh5hWzUDvR0qxMe55k08nz6d8hsXTN Nm2st89xwjZjlfsD0MupAHd4ByKzKeabunjEHedvV+CyTKmjX/TAZgIVRv5HaHtkiEn9 PNyw== X-Gm-Message-State: AOJu0YzAXqCIhyutvJspSbCRMQnMQ3tI/HBERnXWUSKYheNhferxG0p7 VZ90Kvh7jTvDAINMrhd8ye8lH4YxAUpO8Q== X-Received: by 2002:a05:6000:1845:b0:337:39ee:2b85 with SMTP id c5-20020a056000184500b0033739ee2b85mr3828333wri.104.1704303550198; Wed, 03 Jan 2024 09:39:10 -0800 (PST) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id j18-20020a5d5652000000b00336ca349bdesm21896679wrw.47.2024.01.03.09.39.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 09:39:08 -0800 (PST) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 1FA005F9D3; Wed, 3 Jan 2024 17:33:53 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, Richard Henderson , Song Gao , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , David Hildenbrand , Aurelien Jarno , Yoshinori Sato , Yanan Wang , Bin Meng , Laurent Vivier , Michael Rolnik , Alexandre Iooss , David Woodhouse , Laurent Vivier , Paolo Bonzini , Brian Cain , Daniel Henrique Barboza , Beraldo Leal , Paul Durrant , Mahmoud Mandour , Thomas Huth , Liu Zhiwei , Cleber Rosa , kvm@vger.kernel.org, Peter Maydell , Wainer dos Santos Moschetta , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , qemu-arm@nongnu.org, Weiwei Li , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , John Snow , Daniel Henrique Barboza , Nicholas Piggin , Palmer Dabbelt , Marcel Apfelbaum , Ilya Leoshkevich , =?utf-8?q?C=C3=A9dric_Le_Goater?= , "Edgar E. Iglesias" , Eduardo Habkost , Pierrick Bouvier , qemu-riscv@nongnu.org, Alistair Francis , Akihiko Odaki Subject: [PATCH v2 37/43] gdbstub: expose api to find registers Date: Wed, 3 Jan 2024 17:33:43 +0000 Message-Id: <20240103173349.398526-38-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240103173349.398526-1-alex.bennee@linaro.org> References: <20240103173349.398526-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42d.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 Signed-off-by: Alex Bennée --- v2 - just make gdb_get_register_list return everything for a vCPU vAJB: This principle difference is the find registers is a single call which can return a) multiple registers and b) is agnostic to the gdb feature. This is because I haven't so far found any duplicate registers in the system so I thing the regname by itself should be enough. However I do expose the gdb feature name in case the caller wants to do some additional filtering. --- include/exec/gdbstub.h | 47 +++++++++++++++++++++++++++++++++++ gdbstub/gdbstub.c | 56 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 102 insertions(+), 1 deletion(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index da9ddfe54c5..7bddea8259e 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -111,6 +111,53 @@ void gdb_feature_builder_end(const GDBFeatureBuilder *builder); */ const GDBFeature *gdb_find_static_feature(const char *xmlname); +/** + * gdb_find_feature() - Find a feature associated with a CPU. + * @cpu: The CPU associated with the feature. + * @name: The feature's name. + * + * Return: The feature's number. + */ +int gdb_find_feature(CPUState *cpu, const char *name); + +/** + * gdb_find_feature_register() - Find a register associated with a CPU. + * @cpu: The CPU associated with the register. + * @feature: The feature's number returned by gdb_find_feature(). + * @name: The register's name. + * + * Return: The register's number. + */ +int gdb_find_feature_register(CPUState *cpu, int feature, const char *name); + +/** + * 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 420ab2a3766..b0230138246 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -490,7 +490,61 @@ const GDBFeature *gdb_find_static_feature(const char *xmlname) g_assert_not_reached(); } -static int gdb_read_register(CPUState *cpu, GByteArray *buf, int reg) +int gdb_find_feature(CPUState *cpu, const char *name) +{ + GDBRegisterState *r; + + for (guint i = 0; i < cpu->gdb_regs->len; i++) { + r = &g_array_index(cpu->gdb_regs, GDBRegisterState, i); + if (!strcmp(name, r->feature->name)) { + return i; + } + } + + return -1; +} + +int gdb_find_feature_register(CPUState *cpu, int feature, const char *name) +{ + GDBRegisterState *r; + + r = &g_array_index(cpu->gdb_regs, GDBRegisterState, feature); + + for (int i = 0; i < r->feature->num_regs; i++) { + if (r->feature->regs[i] && !strcmp(name, r->feature->regs[i])) { + return r->base_reg + i; + } + } + + return -1; +} + +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;