bug 985566 - add some pretty printers to .gdbinit r=froydnj r=glandium

This commit is contained in:
Trevor Saunders 2014-03-19 13:53:16 -04:00 коммит произвёл Trevor Saunders
Родитель 1d6a94e5d0
Коммит b31db5b19b
9 изменённых файлов: 151 добавлений и 0 удалений

Просмотреть файл

@ -179,3 +179,5 @@ end
def ft
call $arg0->DumpFrameTree()
end
source .gdbinit_python

5
.gdbinit_python Normal file
Просмотреть файл

@ -0,0 +1,5 @@
python
import sys
sys.path.append('python/gdbpp/')
import gdbpp
end

6
build/.gdbinit_python.in Normal file
Просмотреть файл

@ -0,0 +1,6 @@
#filter substitution
python
import sys
sys.path.append('@topsrcdir@/python/gdbpp')
import gdbpp
end

Просмотреть файл

@ -60,6 +60,8 @@ if CONFIG['MOZ_DMD']:
# Put a useful .gdbinit in the bin directory, to be picked up automatically
# by GDB when we debug executables there.
FINAL_TARGET_FILES += ['/.gdbinit']
FINAL_TARGET_PP_FILES += ['.gdbinit_python.in']
OBJDIR_FILES += ['!/dist/bin/.gdbinit_python']
# Install the clang-cl runtime library for ASAN next to the binaries we produce.
if CONFIG['MOZ_ASAN'] and CONFIG['CLANG_CL']:

Просмотреть файл

@ -0,0 +1,26 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import gdb
import gdb.printing
class GeckoPrettyPrinter(object):
pp = gdb.printing.RegexpCollectionPrettyPrinter('GeckoPrettyPrinters')
def __init__(self, name, regexp):
self.name = name
self.regexp = regexp
def __call__(self, wrapped):
GeckoPrettyPrinter.pp.add_printer(self.name, self.regexp, wrapped)
return wrapped
import gdbpp.owningthread
import gdbpp.smartptr
import gdbpp.string
import gdbpp.tarray
gdb.printing.register_pretty_printer(None, GeckoPrettyPrinter.pp)

Просмотреть файл

@ -0,0 +1,24 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import gdb
from gdbpp import GeckoPrettyPrinter
@GeckoPrettyPrinter('nsAutoOwningThread', '^nsAutoOwningThread$')
class owning_thread_printer(object):
def __init__(self, value):
self.value = value
def to_string(self):
prthread_type = gdb.lookup_type('PRThread').pointer()
prthread = self.value['mThread'].cast(prthread_type)
name = prthread['name']
# if the thread doesn't have a name try to get its thread id (might not
# work on !linux)
name = prthread['tid']
return name if name else '(PRThread *) %s' % prthread

Просмотреть файл

@ -0,0 +1,40 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import gdb
from gdbpp import GeckoPrettyPrinter
@GeckoPrettyPrinter('nsWeakPtr', '^nsCOMPtr<nsIWeakReference>$')
class weak_ptr_printer(object):
def __init__(self, value):
self.value = value
def to_string(self):
proxy = self.value['mRawPtr']
if not proxy:
return '[(%s) 0x0]' % proxy.type
ref_type = proxy.dynamic_type
weak_ptr = proxy.cast(ref_type).dereference()['mReferent']
if not weak_ptr:
return '[(%s) %s]' % (weak_ptr.type, weak_ptr)
return '[(%s) %s]' % (weak_ptr.dynamic_type, weak_ptr)
@GeckoPrettyPrinter('nsAutoPtr', 'nsAutoPtr<.*>')
@GeckoPrettyPrinter('nsCOMPtr', 'nsCOMPtr<.*>')
@GeckoPrettyPrinter('RefPtr', 'RefPtr<.*>')
class smartptr_printer(object):
def __init__(self, value):
self.value = value['mRawPtr']
def to_string(self):
if not self.value:
type_name = str(self.value.type)
else:
type_name = str(self.value.dereference().dynamic_type.pointer())
return '[(%s) %s]' % (type_name, str(self.value))

Просмотреть файл

@ -0,0 +1,19 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import gdb
from gdbpp import GeckoPrettyPrinter
@GeckoPrettyPrinter('nsString', '^ns.*String$')
class string_printer(object):
def __init__(self, value):
self.value = value
def to_string(self):
return self.value['mData']
def display_hint(self):
return 'string'

Просмотреть файл

@ -0,0 +1,27 @@
# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import gdb
import itertools
from gdbpp import GeckoPrettyPrinter
@GeckoPrettyPrinter('TArray', '.*TArray<.*>$')
class tarray_printer(object):
def __init__(self, value):
self.value = value
self.elem_type = value.type.template_argument(0)
def children(self):
length = self.value['mHdr'].dereference()['mLength']
data = self.value['mHdr'] + 1
elements = data.cast(self.elem_type.pointer())
return (('%d' % i, (elements + i).dereference()) for i in range(0, int(length)))
def to_string(self):
return str(self.value.type)
def display_hint(self):
return 'array'