From nobody Sat Feb 7 06:39:40 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1710776924; cv=none; d=zohomail.com; s=zohoarc; b=D5xdqvTap4cXfHFQbAK8F0xHHgvlGD0/GbO4paCLruGHSpKkBWZb/ssJaezAS01nth2vbYWlH5N9rBDVBYf5ybvG8OBwT4jH+5RNwnIg3vJQe+mpOz4eJa8Az6ItYC/d6ZDZ2TIICagWg76yygH4I6ZTJOtqBH87DDtqSBuNL+A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710776924; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=m8gtVyvP+veMtIIGlxTAH51MS2c3Qecwre8NmRVXGX0=; b=aZrI1n5WaTwnbiiOZ+cuiXQ9qMBvixI7fa5ewyhmuKkmoYIe3cLLwMwv6ojiFQSo2oQUUt8OC1jWiT5ex5EYzYNBt8O7zWwQvI7PQisq8HrCgzWiET5PJdEg+C/v8MWDB2X2KrdaXJo3RMiMCF7GwJ8c5GZ4XzkDlB1/tdBq91A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1710776924215879.6218541480815; Mon, 18 Mar 2024 08:48:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rmFDt-0006xw-M6; Mon, 18 Mar 2024 11:48: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 1rmFDl-0006dj-EE for qemu-devel@nongnu.org; Mon, 18 Mar 2024 11:48:19 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0: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 1rmFDb-0007wl-Pt for qemu-devel@nongnu.org; Mon, 18 Mar 2024 11:48:17 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6e6fb9a494aso2132723b3a.0 for ; Mon, 18 Mar 2024 08:48:06 -0700 (PDT) Received: from wheely.local0.net ([118.208.155.46]) by smtp.gmail.com with ESMTPSA id v22-20020a634816000000b005dc26144d96sm7332108pga.75.2024.03.18.08.47.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 08:48:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710776885; x=1711381685; 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=m8gtVyvP+veMtIIGlxTAH51MS2c3Qecwre8NmRVXGX0=; b=kvznyEBWX9UW8v3tutpaom+FZxmF8xYazxzSB8D4qExuMl1XOgQkMglm2fr8jbXMdW JaImtPBjvqK0Je+mEXLOSuVzkzdQyg98y/3nhsxgY2ve8p0PnbMRuZ7WRNe5fJj5QvUS MTjuz3Rkhoba1vj88HqcmmnDvztAmKHkayLwVpPOv97iW9GsGjWaT3jgwpFDOeuZck1V ljL2lJN8l2DzhMXSMAdhESuU8gmo1QqpAVRfA1p8feOAxRyJIBzc9m0HKKqEVAqhzpo3 lX/H+SYqqPEGzvYsZRIhcSM/NBdBY5kQWO4celytgPyxj6f4O3ORRgArtDYdIjqL6gG7 lmgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710776885; x=1711381685; 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=m8gtVyvP+veMtIIGlxTAH51MS2c3Qecwre8NmRVXGX0=; b=DudwX+jgBLmL4rV5YlpGiD4zvlewxKlHtGkF0ZqcfcgpFWizWzjW+mn0k13dvREeEH hezlf36a8QF0jGxR8itPU8FfZkaHe8byPnXqW+wJJj7cK4+t6wDncHMGKV4PLvL1pUBb /KS64kOU/dZTX9l5XxNksZ9hITMZjKuWZvT6vVqLXvT5b1gvjBw8CZs79/iLKUEeCEN9 VK35J4Rjf9j3ouNva4f7TVN1R8H+u1dAtWh6Azc4LCiEK5FRBsjFxumx0VK9Hg1KuJPY axW1OwemRvtkUVI1dUV/bXRRH3Le6q3Qqrcd8kHatSVREuzNI5s/LH43FPomlZZ7lUTh UhVg== X-Gm-Message-State: AOJu0YzAnvqXXcYX0UcZ3nSL4U7iAfRdX0Hbqw5himGFe3l7uCzRycPN BicoUzcuz2O2MIMJ6Qr5hDWeMKbatKOA+JsmZj8/Tj7qU0rcWI/Xn0sKA5L2UnI= X-Google-Smtp-Source: AGHT+IFswxqQ/0H+cTZPdXEgMz4qwDtL/gx6jUeM67U5cNtSjURwB4P2nAkNgy6xr9ur5wSQs9Q8Gg== X-Received: by 2002:a05:6a20:3d12:b0:1a3:64ec:46a6 with SMTP id y18-20020a056a203d1200b001a364ec46a6mr3475267pzi.4.1710776884912; Mon, 18 Mar 2024 08:48:04 -0700 (PDT) From: Nicholas Piggin To: qemu-devel@nongnu.org Cc: Nicholas Piggin , Pavel Dovgalyuk , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , John Snow , Cleber Rosa , Wainer dos Santos Moschetta , Beraldo Leal , Michael Tokarev Subject: [PATCH v5 16/24] tests/avocado: reverse_debugging.py verify addresses between record and replay Date: Tue, 19 Mar 2024 01:46:13 +1000 Message-ID: <20240318154621.2361161-17-npiggin@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240318154621.2361161-1-npiggin@gmail.com> References: <20240318154621.2361161-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=npiggin@gmail.com; helo=mail-pf1-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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1710776925750100005 Content-Type: text/plain; charset="utf-8" gdb is only attached in the replay phase, and the recorded trace is single-stepped to build up an address map that is used to then verify reverse-step and reverse-continue. This change attaches gdb in the record phase, and builds the address map by single-stepping the live machine. That address map is then verified by single-stepping the replay, and then used for the same reverse debug verification. This is a stronger verifcation between the record and the replay phases, as well as providing some testing of gdb operation in record mode. x86_64 has problems with taking the first step, it does not advance the icount, so a workaround is added for it. Signed-off-by: Nicholas Piggin --- tests/avocado/reverse_debugging.py | 68 +++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 10 deletions(-) diff --git a/tests/avocado/reverse_debugging.py b/tests/avocado/reverse_deb= ugging.py index e76cf54ad7..8a9578ad5a 100644 --- a/tests/avocado/reverse_debugging.py +++ b/tests/avocado/reverse_debugging.py @@ -35,6 +35,10 @@ class ReverseDebugging(LinuxKernelTest): STEPS =3D 10 endian_is_le =3D True =20 + # If first_step_workaround is true, check whether the first step moved + # icount, and if not then step again. + first_step_workaround =3D False + def run_vm(self, record, shift, args, replay_path, image_path, port): logger =3D logging.getLogger('replay') vm =3D self.get_vm() @@ -45,7 +49,7 @@ def run_vm(self, record, shift, args, replay_path, image_= path, port): else: logger.info('replaying the execution...') mode =3D 'replay' - vm.add_args('-gdb', 'tcp::%d' % port, '-S') + vm.add_args('-gdb', 'tcp::%d' % port, '-S') vm.add_args('-icount', 'shift=3D%s,rr=3D%s,rrfile=3D%s,rrsnapshot= =3Dinit' % (shift, mode, replay_path), '-net', 'none') @@ -87,6 +91,17 @@ def check_pc(self, g, addr): if pc !=3D addr: self.fail('Invalid PC (read %x instead of %x)' % (pc, addr)) =20 + @staticmethod + def gdb_cont(g): + g.cmd(b'c') + + @staticmethod + def gdb_cont_nowait(g): + # The avocado GDBRemote does not have a good way to disconnect or + # continue without waiting for a reply, so open-code our own here. + data =3D g.encode(b'c') + g._socket.send(data) + @staticmethod def gdb_step(g): g.cmd(b's', b'T05thread:01;') @@ -117,11 +132,40 @@ def reverse_debugging(self, shift=3D7, args=3DNone): replay_path =3D os.path.join(self.workdir, 'replay.bin') port =3D find_free_port() =20 + steps =3D [] + # record the log vm =3D self.run_vm(True, shift, args, replay_path, image_path, por= t) + logger.info('connecting to gdbstub') + g =3D gdb.GDBRemote('127.0.0.1', port, False, False) + g.connect() + r =3D g.cmd(b'qSupported') + if b'qXfer:features:read+' in r: + g.cmd(b'qXfer:features:read:target.xml:0,ffb') + + if self.vm_get_icount(vm) !=3D 0: + self.fail('icount does not start at zero') + + # save the addresses of the first STEPS instructions executed + logger.info('stepping forward') + for i in range(self.STEPS): + pc =3D self.get_pc(g) + logger.info('saving position %x' % pc) + steps.append(pc) + self.gdb_step(g) + if self.first_step_workaround and i =3D=3D 0 and self.vm_get_i= count(vm) =3D=3D 0: + logger.warn('failed to take first step, stepping again') + self.gdb_step(g) + if self.vm_get_icount(vm) !=3D self.STEPS: + self.fail('icount (%d) does not match number of instructions s= tepped' % self.vm_get_icount(vm)) + + logger.info('continue running') + self.gdb_cont_nowait(g) + while self.vm_get_icount(vm) <=3D self.STEPS: pass last_icount =3D self.vm_get_icount(vm) + logger.info('shutdown...') vm.shutdown() =20 logger.info("recorded log with %s+ steps" % last_icount) @@ -139,23 +183,23 @@ def reverse_debugging(self, shift=3D7, args=3DNone): if b'ReverseContinue+' not in r: self.fail('Reverse continue is not supported by QEMU') =20 + # Try single stepping logger.info('stepping forward') - steps =3D [] - # record first instruction addresses - for _ in range(self.STEPS): - pc =3D self.get_pc(g) - logger.info('saving position %x' % pc) - steps.append(pc) + for addr in steps: + # verify addresses match what initial execution saw + self.check_pc(g, addr) self.gdb_step(g) + logger.info('found position %x' % addr) =20 - # visit the recorded instruction in reverse order + # Try reverse stepping logger.info('stepping backward') for addr in steps[::-1]: self.gdb_bstep(g) + # verify addresses match what initial execution saw self.check_pc(g, addr) logger.info('found position %x' % addr) =20 - # visit the recorded instruction in forward order + # Step forward again logger.info('stepping forward') for addr in steps: self.check_pc(g, addr) @@ -175,7 +219,7 @@ def reverse_debugging(self, shift=3D7, args=3DNone): # continue - will return after pausing # This could stop at the end and get a T02 return, or by # re-executing one of the breakpoints and get a T05 return. - g.cmd(b'c') + self.gdb_cont(g) if self.vm_get_icount(vm) =3D=3D last_icount - 1: logger.info('reached the end (icount %s)' % (last_icount - 1)) else: @@ -201,6 +245,10 @@ class ReverseDebugging_X86_64(ReverseDebugging): =20 REG_PC =3D 0x10 REG_CS =3D 0x12 + + # The initial step does not change pc on x86 for some reason. + first_step_workaround =3D True + def get_pc(self, g): return self.get_reg_le(g, self.REG_PC) \ + self.get_reg_le(g, self.REG_CS) * 0x10 --=20 2.42.0