From patchwork Fri Nov 9 15:21:17 2018 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: 150662 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp80214ljp; Fri, 9 Nov 2018 07:27:45 -0800 (PST) X-Google-Smtp-Source: AJdET5f3lM2dueweGM/GWtEQH5lpqWBKxLrELN9PUL9C3+Jw44HA1Qgqqb2Prh+rGmkfUale+dhB X-Received: by 2002:a37:97c3:: with SMTP id z186-v6mr8685161qkd.249.1541777265728; Fri, 09 Nov 2018 07:27:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541777265; cv=none; d=google.com; s=arc-20160816; b=ceY7dsM2Zf9Nu1T0tqKLi1L/9jNV015JICMiLk1uO2foCA7llOE4LS+ZN4uZTL17mK AYXxFCc/5yZpO/G1iwxBI1kFwnxez0V9zeCu6ywFGksP0yXoaPqzCv6rfDAuCD239/SL Gi/Kvsylp3NEB0DrGVq+WOyssjnsiHq5uUVSps9WdefeZckE7bm/XoagLc3kmWcXAJDC vZTBy7XOqyj+UlgEIv+uPeftFjahhGL26QL4+hT9eESfpUd1O6fHyOfnChWSey4n6q4Y hx9fbun47S2lOPHtLa83Y9YP4/yx2So5jHcJQfGc4Piuv5sVmZblo9QHoMl9wlb1zrHL nCjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=w/xPzGFYDm1mbK9oUTpNs65d923WwAqDK1S68c4QRE0=; b=zn1lpFKXv11iYb+lZoqmjbXr5BPMx5GqtVZWEPCYyfw37uEEECC7a18a2vPS13erT7 ovfCmGtgelTfY+Fhu7eY3E7va/nkWHGOC7cPCwv3GWNVF/nwVCnWM7N7oTUoBjW5eBSN hqTWUVlcPx9KYwasUzOwix2LL0XM1WpCfAUKUSkU9BXoMYpZmzmmIO+ZIiq0aZwWfMK1 HacNQtlh64YW4UnFv9mggECi/Z1xuwCcmODcTZyvkYVwUBVzFwI1BEEmOroeRNZaOyfJ 5Ukjx//MgNeTNRVu4ZkN7evxIClAZTpIilVfLanI1L5a3wtwSgGFthN4tk8tSnmPNGjB 19CA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=OAcXXQBg; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id q4si3303165qkj.161.2018.11.09.07.27.45 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 09 Nov 2018 07:27:45 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=OAcXXQBg; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34745 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gL8hF-0007mI-1g for patch@linaro.org; Fri, 09 Nov 2018 10:27:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42452) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gL8bC-0001CM-4J for qemu-devel@nongnu.org; Fri, 09 Nov 2018 10:21:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gL8b8-0002yM-Pr for qemu-devel@nongnu.org; Fri, 09 Nov 2018 10:21:29 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:56306) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gL8b6-0002pn-VD for qemu-devel@nongnu.org; Fri, 09 Nov 2018 10:21:25 -0500 Received: by mail-wm1-x343.google.com with SMTP id s10-v6so2363853wmc.5 for ; Fri, 09 Nov 2018 07:21:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w/xPzGFYDm1mbK9oUTpNs65d923WwAqDK1S68c4QRE0=; b=OAcXXQBgf9q0VgEYhrhXR3SM/fQWBJ59lYHbvmMn1jmyVWDuhuqUMsYvgoqZpheJiI P3FagqkgTVbSM07G3AEAjQVSDJnqJHihcEYSfAXZHhvs/sV9jUxkyHlENljLBto0Ityx YSQNu9EKOKGxWML9FKh5K2c5C/UAg4P4IqTtk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w/xPzGFYDm1mbK9oUTpNs65d923WwAqDK1S68c4QRE0=; b=Y9RiHXkbtZCCIb3msyJlJbUy6thzBl7dtuVehnmmA/43rWIPIyZzIqahHKjFyyYj14 ziPklJBtA1bZ4A4scxGpTinIKpfbHeOXT/jkeJBa/4rSDaAQsWwplpVC3m0TEol7DJiV hhVRUp9ytuGNnWHXMPph62wdTZWzDZfiTKjXvo9UhHu+R7/0ePM61LZbfvg8ygdBY66T Z09+gTKj/3YL1W410y1RJ77VHRTyJ/xnjcKZAx+LD94yA3fTvmrDRSqEi9+9Jo0lw00i SoPR6EQACze3+rwR8X3utL4qXWTzIsEMo9xf5hpiQjge7vRJJzCSJxhj98pGYEfa5BGt zV+Q== X-Gm-Message-State: AGRZ1gJJ051fVnP5gknE4xAmstnMBro7w0Wf51gA2HgHpFHiR0eW0yek KAoTcBhW2vMj+QS8ief6k81CZg== X-Received: by 2002:a1c:dc86:: with SMTP id t128-v6mr5049386wmg.111.1541776883509; Fri, 09 Nov 2018 07:21:23 -0800 (PST) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id i7-v6sm5743780wrs.55.2018.11.09.07.21.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 09 Nov 2018 07:21:21 -0800 (PST) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 756133E0593; Fri, 9 Nov 2018 15:21:19 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Fri, 9 Nov 2018 15:21:17 +0000 Message-Id: <20181109152119.9242-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181109152119.9242-1-alex.bennee@linaro.org> References: <20181109152119.9242-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 Subject: [Qemu-devel] [PATCH v3 5/7] tests/guest-debug: don't use symbol resolution for PC checks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn?= =?utf-8?b?w6ll?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" It turns out symbol resolution isn't enough as modern kernels are often padded with check code at the start of functions. GDB seems to put the breakpoint at the first non-check instruction which causes comparisons with the symbol resolution to fail. For normal breakpoints we can detect the hit just by checking hit_count instead. For hardware breakpoints we fish the breakpoint address out of what gdb.execute() reported it was set at. Signed-off-by: Alex Bennée --- tests/guest-debug/test-gdbstub.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) -- 2.17.1 diff --git a/tests/guest-debug/test-gdbstub.py b/tests/guest-debug/test-gdbstub.py index c7e3986a24..3de174b74b 100644 --- a/tests/guest-debug/test-gdbstub.py +++ b/tests/guest-debug/test-gdbstub.py @@ -6,9 +6,10 @@ from __future__ import print_function # gdb ${KERNEL}.vmlinux -x ${QEMU_SRC}/tests/guest-debug/test-gdbstub.py import gdb +import re failcount = 0 - +addr_match = re.compile("(0x[0-9a-f]{4,16})") def report(cond, msg): "Report success/fail of test" @@ -37,26 +38,30 @@ def check_break(sym_name): gdb.execute("c") # hopefully we came back - end_pc = gdb.parse_and_eval('$pc') - print ("%s == %s %d" % (end_pc, sym.value(), bp.hit_count)) + hit = bp.hit_count bp.delete() - # can we test we hit bp? - return end_pc == sym.value() + # did we hit bp? + return hit > 0 # We need to do hbreak manually as the python interface doesn't export it +# As the resolution of sym_name might not exactly match where the +# breakpoint actually ends up we need to fish it out from result of +# gdb.execute. def check_hbreak(sym_name): "Setup hardware breakpoint, continue and check we stopped." - sym, ok = gdb.lookup_symbol(sym_name) - gdb.execute("hbreak %s" % (sym_name)) + result = gdb.execute("hbreak %s" % (sym_name), to_string=True) + addr_txt = addr_match.search(result).group() + addr = int(addr_txt, 16) + gdb.execute("c") # hopefully we came back end_pc = gdb.parse_and_eval('$pc') - print ("%s == %s" % (end_pc, sym.value())) + print ("%s == %s" % (end_pc, addr)) - if end_pc == sym.value(): + if end_pc == addr: gdb.execute("d 1") return True else: