From patchwork Fri Nov 3 19:59:48 2023 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: 740730 Delivered-To: patch@linaro.org Received: by 2002:adf:fd90:0:b0:32d:baff:b0ca with SMTP id d16csp12036wrr; Fri, 3 Nov 2023 13:10:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHM9UyVOgl7aCndO1ISU8KxIKuzqludZvTK8zPUzhEXNJB+g9N46u4Xsh+hGwFCLYbkWAA2 X-Received: by 2002:a05:6902:1366:b0:d9a:6b48:db71 with SMTP id bt6-20020a056902136600b00d9a6b48db71mr21560676ybb.62.1699042205825; Fri, 03 Nov 2023 13:10:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699042205; cv=none; d=google.com; s=arc-20160816; b=yBagW9Hul2u6/2EPqLqUi9Pd3HOA5/tr5UXFpDvyK9ihZinuh+S0EGw10TAwGoC+fr 5CNePWMCOMwO101bA+X8ymvyRrkdRjMkYmZ2BmNu07NMOgVucF0x7aklCgtxKP8sOMyJ 4Pxj7qBWwr5lpLEdSZw/RLFuC+pN+A/h3t6U5LoBcdflDjFqIxWiWfflVQjfLH8bxiar 9yXooFj8eLRISZygN4IJ3GyARsjg+RCZZvOHRQswi4gwEKkbMEgr3M2lQscgm/wYHD73 LHT2E216ExeuYG548jFDV229zY6j7mNzaXyEKv5mBlT0y/QU5iEkO5kg0om2I+ySENEP OjQw== 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=7sLTMALisCLY6Bva5cUZONqTNhvGsWtyZ83Zemwfzds=; fh=+DJyABPrPOszaX8covAxj8Yhupz9POTwrYeebio0HgM=; b=DiGvc9s15VoGSAinCylOjfoMKPGZHROdR6CzH87Gim5GbZhnk76sNowdKWcvrohWNb zoIh2PBjJLc8ZianTYFhypLH79D+ZXR771g97P3dT0pudrfMx/uRWgph+b77YRT9vziO kPIpaOKCgtGk1L7GOG9G3sd+aGxq4bLzezAEJ53a8Ugj9pnf6unRMG09U2vcD1yvgwfN pLPMpXou1QVIeJz0shqpTZY8yWiRoEDNz+NwhNJLR9GMdgbxH7E63kaWoGKeym2oCm45 7vTMRPon6IDVr8grUujeOV3s4K2n6pQNX4hSs7RlG8HWkQTFhmzk2r7rPVE7GynQPnE+ bMcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LYiZnNVa; 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 cz13-20020a056214088d00b0066d1a15d84csi2000896qvb.414.2023.11.03.13.10.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 Nov 2023 13:10:05 -0700 (PDT) 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=LYiZnNVa; 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 1qz0Qz-0003tV-1S; Fri, 03 Nov 2023 16:06:25 -0400 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 1qz0Qv-0003jg-SH for qemu-devel@nongnu.org; Fri, 03 Nov 2023 16:06:22 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qz0Qk-0006x7-Fk for qemu-devel@nongnu.org; Fri, 03 Nov 2023 16:06:20 -0400 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-32da4ffd7e5so1535317f8f.0 for ; Fri, 03 Nov 2023 13:06:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699041968; x=1699646768; 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=7sLTMALisCLY6Bva5cUZONqTNhvGsWtyZ83Zemwfzds=; b=LYiZnNVaNCk51B4cDg7R2AfUmz9FfH5JRpilM8B86SbwVLuttC+VQvdvoxjhRy21xG AEZqgs0tW1qmJMBpQyWH57tV5j/lwwsZLe8Pd1+R4ksAGblXsBrCOHvRMgsPyoPCjuW7 rs+cqPnlBY6Oy+RQdH1aw9yncyXAAomop/7RKE3qOlsyLJelm07KiLCpmOCZrDyvRNSK sgFlA45emwqlzetY0G3R8vNCbWRoauxuMPKsZn/kCEZtgunNgquVKoOpaptWO60QSuC0 C4du8Wl47/Dcdtbkkoig8hpjlrCB+ESWziERPl9LBuXXEbyVpk04xUQJapYHR6jXrJ2n 9qWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699041968; x=1699646768; 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=7sLTMALisCLY6Bva5cUZONqTNhvGsWtyZ83Zemwfzds=; b=kDtckI8rLj6rFKUBR7dAIcja3uTuOF7HR5TUEZw6GbGL2Od9/fiL66+cBCbRNZ7YUB s3/kVmO80kNJJROlOqU0IBcOLcUaXyHcl1pyQZVUPXUgyvGjeSio3CfO3fBvi9d3Lfbj 9X++yUmGZDA80h/Q7qFKhHpKEJ8AM3gYVChz0MY58lYbTPVIqcGGnHWNjLZEPHKe7pTk jdeSAIvxquzvEAMcm5qe8/sseNRMUPw6r/0N/HpdbcTIa4VrKBuTIjNZWf9jbR7dVF4g 4gsokt3YTFS94zSpaXAaIH6pJq9R6io4tuLnr5t1Mvmjd6vmnYNQXpjf/WCUJWHOTGUw g7lg== X-Gm-Message-State: AOJu0YxkpelD5LaZHlKrrmCNtxJHWQWZnW5NkNcwk+uVaY++FVzZJk4F G/D4v6DeWDsnRMBydOhhKvVwpg== X-Received: by 2002:a05:6000:2a9:b0:32f:7260:1220 with SMTP id l9-20020a05600002a900b0032f72601220mr4254287wry.17.1699041968323; Fri, 03 Nov 2023 13:06:08 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id j20-20020a5d4534000000b0032dc74c093dsm1333423wra.103.2023.11.03.13.06.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 13:06:05 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 09F0065751; Fri, 3 Nov 2023 19:59:59 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Peter Maydell , "Edgar E. Iglesias" , Song Gao , qemu-arm@nongnu.org, =?utf-8?q?Marc-Andr?= =?utf-8?q?=C3=A9_Lureau?= , Wainer dos Santos Moschetta , Weiwei Li , Marcel Apfelbaum , Ilya Leoshkevich , Daniel Henrique Barboza , Yanan Wang , =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?C=C3=A9dri?= =?utf-8?q?c_Le_Goater?= , Paolo Bonzini , David Hildenbrand , Brian Cain , qemu-ppc@nongnu.org, Palmer Dabbelt , qemu-riscv@nongnu.org, Eduardo Habkost , =?utf-8?q?Phi?= =?utf-8?q?lippe_Mathieu-Daud=C3=A9?= , Alistair Francis , Liu Zhiwei , Cleber Rosa , qemu-s390x@nongnu.org, Laurent Vivier , Yoshinori Sato , Nicholas Piggin , Thomas Huth , John Snow , Alexandre Iooss , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Mahmoud Mandour , Daniel Henrique Barboza , Bin Meng , Beraldo Leal , Richard Henderson , Michael Rolnik , Akihiko Odaki Subject: [PATCH 21/29] gdbstub: expose api to find registers Date: Fri, 3 Nov 2023 19:59:48 +0000 Message-Id: <20231103195956.1998255-22-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231103195956.1998255-1-alex.bennee@linaro.org> References: <20231103195956.1998255-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42c.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 find groups of registers. It returns a 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 --- 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 | 59 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index da9ddfe54c..b201eb4b84 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_find_registers() - Return list of registers matching pattern + * @cpu: The CPU being searched + * @reg_pattern: the pattern being searched for + * + * Returns a GArray of GDBRegDesc, caller frees + */ +GArray *gdb_find_registers(CPUState *cpu, const char *reg_pattern); + 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 7d7d887817..45882d1a6f 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -490,7 +490,64 @@ 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_find_registers(CPUState *cpu, const char *reg_pattern) +{ + g_autoptr(GPatternSpec) pat = g_pattern_spec_new(reg_pattern); + 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]; + if (name && g_pattern_match_string(pat, name)) { + 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;