From patchwork Sat Sep 16 08:01:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1835426 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=rEWKv5VV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RnkCM3KFwz1yfd for ; Sat, 16 Sep 2023 18:06:07 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qhQG2-0003Cw-QO; Sat, 16 Sep 2023 04:02:26 -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 1qhQFv-0003Bv-QV for qemu-devel@nongnu.org; Sat, 16 Sep 2023 04:02:19 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qhQFu-0005xt-Ai for qemu-devel@nongnu.org; Sat, 16 Sep 2023 04:02:19 -0400 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-68fac346f6aso2686121b3a.3 for ; Sat, 16 Sep 2023 01:02:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1694851337; x=1695456137; 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=21Z173hVFszR8s4nfjM3OYWaOyCmfZYL9fagBQvy26Q=; b=rEWKv5VVG4XNLwt7EJ/0xCI89XCLk1ND0ghIxOIjV1cijTL7T53gQAt0+H7UZgndzg hxgRDEDBsDWcydp5UijdY15WE9n1XtjLOohM21I9x7IpyxUqVF9kg5D1LwSceXoImdok AeI5HHzorX4HiDzIXoKJSc1PopFc0MKAMtgF/38osVb2okizPWHU7YPn+NgjmUNS8uv9 bE8CNDlp7ehlkdvLJky/oxme3lnEYvd5LJA2k+ItytomSUtblaMaf1U/u2CWGav8vaKa sIRTZq/7oEIGEMB7LGBjhMXmHt1TnKIviM2dAHyG+yT/P6vXPep2CElsi+BLWbPnTAw0 fkHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694851337; x=1695456137; 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=21Z173hVFszR8s4nfjM3OYWaOyCmfZYL9fagBQvy26Q=; b=iVaTAqSLBO20ATuf8UiYBhPeieN1Hh/DI5K1k2lYObfAvadN8tR5ByVBdYp262IiAi +WZly/B/jNTA+Mx3+l9PfiKCSZOmBaj4cVtsEoUa1RIEgFb3NMp90kpRGZsKWph4cx5D 9ryOX5PgX7I7CjDM8gRmYzH876urAazJhEykU5jwJ+tcEY0T1jsGpQeaxaK/wCUdf9UV RVvMvALc/vU02MKE7FH1x3k4rMX0+KA8Dr2mBZF1z+GFf8ynZLyx5CQ3qMospXAhhYED Ne4oRtOxDaK6b8LELyjMzvxnUyZcoqdB6FjQI6koS0e1tQb/vhu5O5fffG7fiqPxQHSj ZSig== X-Gm-Message-State: AOJu0YwOfnamvVM745TP24J+HMCtYMtzhchDABIsR6LCJKQk92PK1iB3 Tf2/xVJqln+2Fc6YpbDcKpBnfQ== X-Google-Smtp-Source: AGHT+IGgpl7byC9G6zNPznONiowPDkwA/x2kgtGgsz4q0jnazDB8LUm6k3j6Y12nZoeirGDLf3ML1w== X-Received: by 2002:a05:6a20:1442:b0:159:fe1d:2f09 with SMTP id a2-20020a056a20144200b00159fe1d2f09mr5451383pzi.6.1694851337104; Sat, 16 Sep 2023 01:02:17 -0700 (PDT) Received: from alarm.flets-east.jp ([2400:4050:a840:1e00:78d2:b862:10a7:d486]) by smtp.gmail.com with ESMTPSA id z21-20020aa791d5000000b0068a46cd4120sm4029484pfa.199.2023.09.16.01.02.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Sep 2023 01:02:16 -0700 (PDT) From: Akihiko Odaki To: Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Mikhail Tyutin , Aleksandr Anenkov , qemu-devel@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Akihiko Odaki , John Snow , Cleber Rosa Subject: [PATCH v8 01/19] gdbstub: Add num_regs member to GDBFeature Date: Sat, 16 Sep 2023 17:01:18 +0900 Message-ID: <20230916080149.129989-2-akihiko.odaki@daynix.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230916080149.129989-1-akihiko.odaki@daynix.com> References: <20230916080149.129989-1-akihiko.odaki@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2607:f8b0:4864:20::42f; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Currently the number of registers exposed to GDB is written as magic numbers in code. Derive the number of registers GDB actually see from XML files to replace the magic numbers in code later. Signed-off-by: Akihiko Odaki Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Alex Bennée --- include/exec/gdbstub.h | 1 + scripts/feature_to_c.py | 46 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 1a01c35f8e..a43aa34dad 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -13,6 +13,7 @@ typedef struct GDBFeature { const char *xmlname; const char *xml; + int num_regs; } GDBFeature; diff --git a/scripts/feature_to_c.py b/scripts/feature_to_c.py index bcbcb83beb..e04d6b2df7 100755 --- a/scripts/feature_to_c.py +++ b/scripts/feature_to_c.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-or-later -import os, sys +import os, sys, xml.etree.ElementTree def writeliteral(indent, bytes): sys.stdout.write(' ' * indent) @@ -39,10 +39,52 @@ def writeliteral(indent, bytes): with open(input, 'rb') as file: read = file.read() + parser = xml.etree.ElementTree.XMLPullParser(['start', 'end']) + parser.feed(read) + events = parser.read_events() + event, element = next(events) + if event != 'start': + sys.stderr.write(f'unexpected event: {event}\n') + exit(1) + if element.tag != 'feature': + sys.stderr.write(f'unexpected start tag: {element.tag}\n') + exit(1) + + regnum = 0 + regnums = [] + tags = ['feature'] + for event, element in events: + if event == 'end': + if element.tag != tags[len(tags) - 1]: + sys.stderr.write(f'unexpected end tag: {element.tag}\n') + exit(1) + + tags.pop() + if element.tag == 'feature': + break + elif event == 'start': + if len(tags) < 2 and element.tag == 'reg': + if 'regnum' in element.attrib: + regnum = int(element.attrib['regnum']) + + regnums.append(regnum) + regnum += 1 + + tags.append(element.tag) + else: + raise Exception(f'unexpected event: {event}\n') + + if len(tags): + sys.stderr.write('unterminated feature tag\n') + exit(1) + + base_reg = min(regnums) + num_regs = max(regnums) - base_reg + 1 if len(regnums) else 0 + sys.stdout.write(' {\n') writeliteral(8, bytes(os.path.basename(input), 'utf-8')) sys.stdout.write(',\n') writeliteral(8, read) - sys.stdout.write('\n },\n') + sys.stdout.write(f',\n {num_regs},\n }},\n') sys.stdout.write(' { NULL }\n};\n')