Message ID | 20180328173238.507470-2-vsementsov@virtuozzo.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
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() >
On Wed, Mar 28, 2018 at 08:32:35PM +0300, 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> > --- > scripts/qemugdb/coroutine.py | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
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) + 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()
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> --- scripts/qemugdb/coroutine.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)