All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	qemu-devel@nongnu.org
Cc: stefanha@redhat.com, den@openvz.org
Subject: Re: [Qemu-devel] [PATCH 1/4] scripts/qemugdb: get pthread_self from "info threads" command
Date: Wed, 4 Apr 2018 11:52:03 +0200	[thread overview]
Message-ID: <749bccbe-614a-143b-6520-d6e3f82b9da6@redhat.com> (raw)
In-Reply-To: <20180328173238.507470-2-vsementsov@virtuozzo.com>

On 28/03/2018 19:32, Vladimir Sementsov-Ogievskiy wrote:
> When debugging a coredump, pthread_self can't be obtained from
> function arch_prctl. Moreover if qemu crashed in coroutine, we
> can't find 'start_thread' in current stack-trace. So, add a method,
> actually proposed in 1138f24645e9e, which should work for gdb
> version >= 7.3.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>

New-enough gdb can also use gdb.selected_thread()
> ---
>  scripts/qemugdb/coroutine.py | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/qemugdb/coroutine.py b/scripts/qemugdb/coroutine.py
> index ab699794ab..ffaa45c464 100644
> --- a/scripts/qemugdb/coroutine.py
> +++ b/scripts/qemugdb/coroutine.py
> @@ -14,6 +14,7 @@
>  # GNU GPL, version 2 or (at your option) any later version.
>  
>  import gdb
> +import re
>  
>  VOID_PTR = gdb.lookup_type('void').pointer()
>  
> @@ -28,7 +29,17 @@ def get_fs_base():
>      return fs_base
>  
>  def pthread_self():
> -    '''Fetch pthread_self() from the glibc start_thread function.'''
> +    # Try read pthread_self from gdb command 'info threads'.
> +    # Will fail for old gdb.
> +    try:
> +        threads = gdb.execute('info threads', False, True)
> +        m = re.search('^\* 1    Thread (0x[0-9a-f]+)', threads, re.MULTILINE)

I don't think hard-coding "1" works here, and the spacing of the table
might differ as well.  However, looking for the asterisk seems safe from
a quick look at gdb source, and "Thread" looks like it isn't localized.

Paolo

> +        return int(m.group(1), 16)
> +    except TypeError:
> +        # gdb doesn't support third parameter for execute
> +        pass
> +
> +    # Try fetch pthread_self() from the glibc start_thread function.
>      f = gdb.newest_frame()
>      while f.name() != 'start_thread':
>          f = f.older()
> 

  reply	other threads:[~2018-04-04  9:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-28 17:32 [Qemu-devel] [PATCH 0/4] qemugdb: coroutine backtrace for coredump Vladimir Sementsov-Ogievskiy
2018-03-28 17:32 ` [Qemu-devel] [PATCH 1/4] scripts/qemugdb: get pthread_self from "info threads" command Vladimir Sementsov-Ogievskiy
2018-04-04  9:52   ` Paolo Bonzini [this message]
2018-04-04  9:57   ` Stefan Hajnoczi
2018-03-28 17:32 ` [Qemu-devel] [PATCH 2/4] scripts/qemugdb: improve "qemu coroutine" command Vladimir Sementsov-Ogievskiy
2018-04-04 10:37   ` Stefan Hajnoczi
2018-03-28 17:32 ` [Qemu-devel] [PATCH 3/4] scripts/qemugdb: add coredump.py for coredump patching Vladimir Sementsov-Ogievskiy
2018-03-28 17:32 ` [Qemu-devel] [PATCH 4/4] scripts/qemugdb: backtraces for coroutines in coredump Vladimir Sementsov-Ogievskiy
2018-04-04 10:36   ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=749bccbe-614a-143b-6520-d6e3f82b9da6@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=den@openvz.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=vsementsov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.