From patchwork Tue Mar 14 10:08:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Pen X-Patchwork-Id: 738606 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vj9Sv4xhsz9s1h for ; Tue, 14 Mar 2017 21:09:35 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=profitbricks-com.20150623.gappssmtp.com header.i=@profitbricks-com.20150623.gappssmtp.com header.b="ZNLhGIq5"; dkim-atps=neutral Received: from localhost ([::1]:57504 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnjOX-0006yo-2l for incoming@patchwork.ozlabs.org; Tue, 14 Mar 2017 06:09:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnjO2-0006xb-EU for qemu-devel@nongnu.org; Tue, 14 Mar 2017 06:09:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnjNy-0007Vh-Cc for qemu-devel@nongnu.org; Tue, 14 Mar 2017 06:09:02 -0400 Received: from mail-wr0-x229.google.com ([2a00:1450:400c:c0c::229]:34368) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cnjNy-0007Ug-5G for qemu-devel@nongnu.org; Tue, 14 Mar 2017 06:08:58 -0400 Received: by mail-wr0-x229.google.com with SMTP id l37so120572232wrc.1 for ; Tue, 14 Mar 2017 03:08:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profitbricks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=44FGG6qpkrriSWstS8f9i8sxp2zKEUKsL0aBcdqnui0=; b=ZNLhGIq51SWJkknQL9k/5m/3QACbd4p9RDtZzQTStGnOwdZuuP+ljSobO7A2JXfMhu yRlAdzSCg83i9mBK7e1NU7+gAsQdKfBe5kr1OyniK8zbP15gSpFa1aNxMY/dC5ukIDSL +Y9vxpVO2S/7JoCVyVfnBR6+/NqtnfMJR3gKt1gboMKy+f+DhOLizbuHJG8IXb7DN5dQ RAMzVsHMjYdB+YaE/XgOH4yMb2bA6QY4+IXuPg/XJPtCsLUDXUUKa3SI0d0Bo1DUuCnq 7/vJKG0ABi3HU4Dw5u4pjnGds4g5UWdfaPrM8P1yf9SvPvH0COKKTsNIofMng4kqcyPt WEZA== 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; bh=44FGG6qpkrriSWstS8f9i8sxp2zKEUKsL0aBcdqnui0=; b=dcR1kamwaV6YO/+zqh+d39lRCBL0O3yhg23LVjgqY+vmIkXreHHzfvSCKb2gmalkFM /YZ3y+AIgKOMrCZLU85Y8SHKMv+pLZKrkPQNOmFUBV8dYvVoYOV5dYV2YoTj4Sb2xloY bWc40PVGncHECgAaz5cvxA6IPqmJTl8lsRVHtKIWURPy0OAnhpg8NOzSf9sQuYZGMU3P RscFfP2StTeBaaSvT10fpeTVcfp9yX9okiOMaDzyeNrPu5PSUyT++zTPJFYQ8h+lzy+f u+gkBWMIJ0mFwykyre/PsOUZ/AYDAk4C44JAvxgkKn1Xz5x5w08XaKrT4peLYtUytoBh jXeA== X-Gm-Message-State: AMke39lIwwr+i/hR41/ZmtH6veU/9DImx3hPhqMZAYVQlsR/6Lzm/3kah6R5lmFIAqgIEjDd X-Received: by 10.223.153.17 with SMTP id x17mr31808825wrb.55.1489486136880; Tue, 14 Mar 2017 03:08:56 -0700 (PDT) Received: from pb.pb.local ([62.217.45.26]) by smtp.gmail.com with ESMTPSA id 40sm28555118wry.22.2017.03.14.03.08.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Mar 2017 03:08:56 -0700 (PDT) From: Roman Pen To: Date: Tue, 14 Mar 2017 11:08:38 +0100 Message-Id: <20170314100838.12647-2-roman.penyaev@profitbricks.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170314100838.12647-1-roman.penyaev@profitbricks.com> References: <20170314100838.12647-1-roman.penyaev@profitbricks.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::229 Subject: [Qemu-devel] [PATCH 1/1] scripts/qemugdb/coroutine.py: get pthread pointer from '(gdb) thread info $id' output 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: Paolo Bonzini , Stefan Hajnoczi , Roman Pen , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This is a first step towards coroutines debugging using corefiles. It is much simpler to follow single path and always parse the line * 1 Thread 0x7f4475e33700 (LWP 7806) ^^^^^^^^^^^^^^ of a '(gdb) thread info $id' and get pthread pointer instead of rely on libc debugging information, which is not always the case. For sure under corefile debugging it is not possible to invoke any syscalls, like arch_prctl(), so avoid doing that. That will simplify the script. The other problem which is left unsolved for coroutines debugging using corefiles is gdb restriction to modify registers (that is only possible for live process, not for a corefile). This problem is solved in the next patch for a gdb project itself. Signed-off-by: Roman Pen Cc: Stefan Hajnoczi Cc: qemu-devel@nongnu.org --- scripts/qemugdb/coroutine.py | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/scripts/qemugdb/coroutine.py b/scripts/qemugdb/coroutine.py index ab699794abf6..1cfe3cd97e80 100644 --- a/scripts/qemugdb/coroutine.py +++ b/scripts/qemugdb/coroutine.py @@ -14,31 +14,22 @@ # GNU GPL, version 2 or (at your option) any later version. import gdb +import re VOID_PTR = gdb.lookup_type('void').pointer() -def get_fs_base(): - '''Fetch %fs base value using arch_prctl(ARCH_GET_FS). This is - pthread_self().''' - # %rsp - 120 is scratch space according to the SystemV ABI - old = gdb.parse_and_eval('*(uint64_t*)($rsp - 120)') - gdb.execute('call arch_prctl(0x1003, $rsp - 120)', False, True) - fs_base = gdb.parse_and_eval('*(uint64_t*)($rsp - 120)') - gdb.execute('set *(uint64_t*)($rsp - 120) = %s' % old, False, True) - return fs_base - def pthread_self(): - '''Fetch pthread_self() from the glibc start_thread function.''' - f = gdb.newest_frame() - while f.name() != 'start_thread': - f = f.older() - if f is None: - return get_fs_base() + '''Get pthread_self() from '(gdb) info thread $id' output''' + num = gdb.selected_thread().num + thr = gdb.execute('info thread %d' % num, to_string=True) + thr = thr.split('\n')[1] try: - return f.read_var("arg") - except ValueError: - return get_fs_base() + return re.search('Thread ([0-9a-zx]+)', thr).group(1) + except: + raise ValueError("Unable to find pthread address in 'info thread %d' output.\n" + "Probably version mismatch of libthread_db.so library?" % + num) def get_glibc_pointer_guard(): '''Fetch glibc pointer guard value'''