예제 #1
0
파일: __init__.py 프로젝트: coodie/mimiker
def addPrettyPrinters():
    pp = gdb.printing.RegexpCollectionPrettyPrinter('mimiker')
    pp.add_printer('mtx', 'mtx', sync.Mutex)
    pp.add_printer('condvar', 'condvar', sync.CondVar)
    pp.add_printer('thread', 'thread', thread.Thread)
    pp.add_printer('timeval', 'timeval', klog.TimeVal)
    gdb.printing.register_pretty_printer(gdb.current_objfile(), pp)
예제 #2
0
def _install():
  current_objfile = gdb.current_objfile()
  register_zircon_pretty_printers(current_objfile)
  if current_objfile is not None and _is_x86_64():
    gdb.unwinder.register_unwinder(current_objfile, _Amd64KernelExceptionUnwinder(), True)

  if not _is_x86_64() and not _is_arm64():
    print("Warning: Unsupported architecture, KASLR support will be experimental")
  gdb.events.stop.connect(_KASLR_stop_event)
예제 #3
0
def reload():
    ## Create the commands
    init_globals()
    BslShowAllocatorParameter ()
    BdeHelpCommand ()
    BslEclipseModeParameter ()

    ## Remove the pretty printer if it exists
    for printer in gdb.pretty_printers:
        if (printer.name == 'BDE'):
            gdb.pretty_printers.remove(printer)
            break

    ## Create the new pretty printer
    gdb.printing.register_pretty_printer(gdb.current_objfile(),
                                         build_pretty_printer())
예제 #4
0
파일: gdbhooks.py 프로젝트: realtux/gcc
                             OptMachineModePrinter)
    pp.add_printer_for_types(
        ['opt_scalar_int_mode', 'opt_scalar_float_mode', 'opt_scalar_mode'],
        'opt_mode', OptMachineModePrinter)
    pp.add_printer_for_regex(r'pod_mode<(\S+)>', 'pod_mode',
                             MachineModePrinter)
    pp.add_printer_for_types(['scalar_int_mode_pod', 'scalar_mode_pod'],
                             'pod_mode', MachineModePrinter)
    for mode in ('scalar_mode', 'scalar_int_mode', 'scalar_float_mode',
                 'complex_mode'):
        pp.add_printer_for_types([mode], mode, MachineModePrinter)

    return pp


gdb.printing.register_pretty_printer(gdb.current_objfile(),
                                     build_pretty_printer())


def find_gcc_source_dir():
    # Use location of global "g" to locate the source tree
    sym_g = gdb.lookup_global_symbol('g')
    path = sym_g.symtab.filename  # e.g. '../../src/gcc/context.h'
    srcdir = os.path.split(path)[0]  # e.g. '../../src/gcc'
    return srcdir


class PassNames:
    """Parse passes.def, gathering a list of pass class names"""
    def __init__(self):
        srcdir = find_gcc_source_dir()
예제 #5
0
		elif length:
	            offset = int(sp['offset'])
		    base = (seg['data'].address + offset).dereference()
	            result = result + base.string('','replace',length)
		else:
		    result = result + "[ZERO len!]"
	    else:
	        result = result + "[NULL seg!]"
	    sp = sp['next']
	return result

    def display_hint(self):
    	return 'string'

    @classmethod
    def matches(cls, value):
	t = value.type.unqualified()
    	return t.code == gdb.TYPE_CODE_PTR and \
	       t.target().strip_typedefs().tag == "macro" 

class MacroPrettyPrinter(gdb.printing.PrettyPrinter):
    def __init__(self, name):
    	super(MacroPrettyPrinter, self).__init__(name, [])
    def __call__(self, val):
        if MacroPrinter.matches(val):
	    return MacroPrinter(val)

gdb.printing.register_pretty_printer(gdb.current_objfile(), 
	MacroPrettyPrinter("macro"))

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import sys
import gdb
import os
import os.path

pythondir = '/home/johny/src/nodemcu-prebuilt-toolchains/build/esp32/../../esp32/share/gcc-5.2.0/python'
libdir = '/home/johny/src/nodemcu-prebuilt-toolchains/build/esp32/../../esp32/xtensa-esp32-elf/lib'

# This file might be loaded when there is no current objfile.  This
# can happen if the user loads it manually.  In this case we don't
# update sys.path; instead we just hope the user managed to do that
# beforehand.
if gdb.current_objfile () is not None:
    # Update module path.  We want to find the relative path from libdir
    # to pythondir, and then we want to apply that relative path to the
    # directory holding the objfile with which this file is associated.
    # This preserves relocatability of the gcc tree.

    # Do a simple normalization that removes duplicate separators.
    pythondir = os.path.normpath (pythondir)
    libdir = os.path.normpath (libdir)

    prefix = os.path.commonprefix ([libdir, pythondir])
    # In some bizarre configuration we might have found a match in the
    # middle of a directory name.
    if prefix[-1] != '/':
        prefix = os.path.dirname (prefix) + '/'
예제 #7
0
파일: lean-gdb.py 프로젝트: avigad/lean
def register():
    gdb.printing.register_pretty_printer(
        gdb.current_objfile(),
        build_pretty_printer(),
        replace=True)
예제 #8
0
파일: nim-gdb.py 프로젝트: c-blake/Nim
import sys

# some feedback that the nim runtime support is loading, isn't a bad
# thing at all.
gdb.write("Loading Nim Runtime support.\n", gdb.STDERR)

# When error occure they occur regularly. This 'caches' known errors
# and prevents them from being reprinted over and over again.
errorSet = set()
def printErrorOnce(id, message):
  global errorSet
  if id not in errorSet:
    errorSet.add(id)
    gdb.write(message, gdb.STDERR)

nimobjfile = gdb.current_objfile() or gdb.objfiles()[0]
nimobjfile.type_printers = []

################################################################################
#####  Type pretty printers
################################################################################

type_hash_regex = re.compile("^\w*_([A-Za-z0-9]*)$")

def getNimRti(type_name):
  """ Return a ``gdb.Value`` object for the Nim Runtime Information of ``type_name``. """

  # Get static const TNimType variable. This should be available for
  # every non trivial Nim type.
  m = type_hash_regex.match(type_name)
  if m:
예제 #9
0
    if str(val.type).startswith("MVM"):
        try:
            val.cast(gdb.lookup_type("MVMObject" + (" *" if pointer else "")))
            return MVMObjectPPrinter(val, pointer)
        except Exception as e:
            print("couldn't cast this:", e)
            pass
    return None

def register_printers(objfile):
    objfile.pretty_printers.append(str_lookup_function)
    print("MoarVM string pretty printer registered")
    # XXX since this is currently nonfunctional, just ignore it for now
    # objfile.pretty_printers.append(mvmobject_lookup_function)
    # print("MoarVM Object pretty printer registered")

commands = []
def register_commands(objfile):
    commands.append(AnalyzeHeapCommand())
    print("moar-heap registered")
    commands.append(DiffHeapCommand())
    print("diff-moar-heap registered")

# We have to introduce our classes to gdb so that they can be used
if __name__ == "__main__":
    the_objfile = gdb.current_objfile()
    if the_objfile  == None:
        the_objfile = gdb.lookup_objfile("libmoar.so")
    register_printers(the_objfile)
    register_commands(the_objfile)
예제 #10
0
파일: printers.py 프로젝트: daniel-j-h/home
def register_tox_printers():
    import gdb.printing
    gdb.pretty_printers = []
    gdb.printing.register_pretty_printer(gdb.current_objfile(), build_pretty_printer())
예제 #11
0
def mvmobject_lookup_function(val):
    pointer = str(val.type).endswith("*")
    if str(val.type).startswith("MVM"):
        try:
            val.cast(gdb.lookup_type("MVMObject" + (" *" if pointer else "")))
            return MVMObjectPPrinter(val, pointer)
        except Exception as e:
            print "couldn't cast this:", e
            pass
    return None

def register_printers(objfile):
    objfile.pretty_printers.append(str_lookup_function)
    print "MoarVM string pretty printer registered"
    # XXX since this is currently nonfunctional, just ignore it for now
    # objfile.pretty_printers.append(mvmobject_lookup_function)
    # print "MoarVM Object pretty printer registered"

commands = []
def register_commands(objfile):
    commands.append(AnalyzeHeapCommand())
    print "moar-heap registered"
    commands.append(DiffHeapCommand())
    print "diff-moar-heap registered"

# We have to introduce our classes to gdb so that they can be used
if __name__ == "__main__":
    register_printers(gdb.current_objfile())
    register_commands(gdb.current_objfile())
import sys
import gdb

# Update module path.
dir_ = '/usr/share/glib-2.0/gdb'
if not dir_ in sys.path:
    sys.path.insert(0, dir_)

from glib_gdb import register
register (gdb.current_objfile ())
예제 #13
0
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import sys
import gdb
import os
import os.path

pythondir = '/var/lib/builds/sifive-tools/freedom-tools-master/obj/x86_64-linux-centos6/install/riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-centos6/share/gcc-8.3.0/python'
libdir = '/var/lib/builds/sifive-tools/freedom-tools-master/obj/x86_64-linux-centos6/install/riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-centos6/riscv64-unknown-elf/lib/rv32if/ilp32f'

# This file might be loaded when there is no current objfile.  This
# can happen if the user loads it manually.  In this case we don't
# update sys.path; instead we just hope the user managed to do that
# beforehand.
if gdb.current_objfile() is not None:
    # Update module path.  We want to find the relative path from libdir
    # to pythondir, and then we want to apply that relative path to the
    # directory holding the objfile with which this file is associated.
    # This preserves relocatability of the gcc tree.

    # Do a simple normalization that removes duplicate separators.
    pythondir = os.path.normpath(pythondir)
    libdir = os.path.normpath(libdir)

    prefix = os.path.commonprefix([libdir, pythondir])
    # In some bizarre configuration we might have found a match in the
    # middle of a directory name.
    if prefix[-1] != '/':
        prefix = os.path.dirname(prefix) + '/'
예제 #14
0
파일: mongo.py 프로젝트: piook/mongo
import re
import sys

import gdb

# pylint: disable=invalid-name,wildcard-import,broad-except
try:
    # Try to find and load the C++ pretty-printer library.
    import glob
    pp = glob.glob(
        "/opt/mongodbtoolchain/v3/share/gcc-*/python/libstdcxx/v6/printers.py")
    printers = pp[0]
    path = os.path.dirname(os.path.dirname(os.path.dirname(printers)))
    sys.path.insert(0, path)
    from libstdcxx.v6 import register_libstdcxx_printers
    register_libstdcxx_printers(gdb.current_objfile())
    print("Loaded libstdc++ pretty printers from '%s'" % printers)
except Exception as e:
    print("Failed to load the libstdc++ pretty printers: " + str(e))
# pylint: enable=invalid-name,wildcard-import

if sys.version_info[0] >= 3:
    # GDB only permits converting a gdb.Value instance to its numerical address when using the
    # long() constructor in Python 2 and not when using the int() constructor. We define the
    # 'long' class as an alias for the 'int' class in Python 3 for compatibility.
    long = int  # pylint: disable=redefined-builtin,invalid-name


def get_process_name():
    """Return the main binary we are attached to."""
    # The return from gdb.objfiles() could include the file extension of the debug symbols.
예제 #15
0
        if not found:
            gdb.Breakpoint (i)
            pass
        pass
    return

# Quit if not in gcc


TreeDebug()
TreeGenericExpr()
GimpleDebug()
RtxDebug()
CgnDebug()

VecGetLength()
VecGetItem()
register_pretty_printer(gdb.current_objfile(), TreePrettyPrinter(), True)
register_pretty_printer(gdb.current_objfile(), SymtabPrinterDispatcher(), True)
    
CgraphNodeCountCallers()
CgraphNodeCountCallees()
register_pretty_printer(gdb.current_objfile(), IPAPropPrinterDispatcher(),
                        True)

set_basic_breakpoints()

gdb.execute("set unwindonsignal on")
gdb.execute("skip file tree.h")
gdb.execute("set check type off")
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import sys
import gdb
import os
import os.path

pythondir = '/usr/share/gcc-4.8/python'
libdir = '/usr/lib/x86_64-linux-gnu'

# This file might be loaded when there is no current objfile.  This
# can happen if the user loads it manually.  In this case we don't
# update sys.path; instead we just hope the user managed to do that
# beforehand.
if gdb.current_objfile () is not None:
    # Update module path.  We want to find the relative path from libdir
    # to pythondir, and then we want to apply that relative path to the
    # directory holding the objfile with which this file is associated.
    # This preserves relocatability of the gcc tree.

    # Do a simple normalization that removes duplicate separators.
    pythondir = os.path.normpath (pythondir)
    libdir = os.path.normpath (libdir)

    prefix = os.path.commonprefix ([libdir, pythondir])
    # In some bizarre configuration we might have found a match in the
    # middle of a directory name.
    if prefix[-1] != '/':
        prefix = os.path.dirname (prefix) + '/'
예제 #17
0
import os.path, sys
import gdb

#
# Adjust the load path to include lsst.gdb, bypassing the regular lsstimport mechanism as
# the version of python running within gdb may not be the same as we are using for lsst processing
#
printerDir = os.path.join(os.environ["AFW_DIR"], "python", "lsst", "gdb")
if printerDir not in sys.path:
    sys.path.append(printerDir)

import afw.printers

afw.printers.register(gdb.current_objfile())
예제 #18
0
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
# librevenge
# Version: MPL 2.0 / LGPLv2.1+
#
# 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/.
#
# Alternatively, the contents of this file may be used under the terms
# of the GNU Lesser General Public License Version 2.1 or later
# (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
# applicable instead of those above.
#

# Auto-load of all the printers.

import sys

import gdb

pythondir = '${prefix}/share/librevenge/python'

if pythondir not in sys.path:
    sys.path.insert(0, pythondir)

import librevenge.v0_0.streams
librevenge.v0_0.streams.register_pretty_printers(gdb.current_objfile())

# vim:set filetype=python shiftwidth=4 softtabstop=4 expandtab:
예제 #19
0
	
	# If it points to a reference, get the reference.
	if type.code == gdb.TYPE_CODE_REF:
		type = type.target ()
		
	# Get the unqualified type, stripped of typedefs.
	type = type.unqualified ().strip_typedefs ()
	
	# Get the type name.
	typename = type.tag
	if typename == None:
		return None
		
	# Iterate over local dictionary of types to determine
	# if a printer is registered for that type. Return an
	# instantiation of the printer if found.
	for function in pretty_printers_dict:
		if function.search (typename):
			return pretty_printers_dict[function] (val)
	
	# Cannot find a pretty printer. Return None.
	return None

def build_dictionary ():
	pretty_printers_dict[re.compile('^PLCore::String$')] = lambda val: PLStringPrinter(val)

pretty_printers_dict = {}

build_dictionary ()
register_pl_printers(gdb.current_objfile ())
예제 #20
0
def addMutexPrettyPrinter():
    pp = gdb.printing.RegexpCollectionPrettyPrinter("mutexes")
    pp.add_printer('mtx', 'mtx', MutexPrettyPrinter)
    gdb.printing.register_pretty_printer(gdb.current_objfile(), pp)
예제 #21
0
파일: loader.py 프로젝트: avikivity/osv
#!/usr/bin/python2

import gdb
import re
import os, os.path
import struct
import json
import math
import itertools
import operator
from glob import glob
from collections import defaultdict

arch = 'x64'
build_dir = os.path.dirname(gdb.current_objfile().filename)
osv_dir = os.path.abspath(os.path.join(build_dir, '../..'))
mgmt_dir = os.path.join(osv_dir, 'mgmt')
external = os.path.join(osv_dir, 'external', arch)

sys.path.append(os.path.join(osv_dir, 'scripts'))

from osv.trace import Trace,TracePoint,BacktraceFormatter,format_time,format_duration
from osv import trace

virtio_driver_type = gdb.lookup_type('virtio::virtio_driver')

class status_enum_class(object):
    pass
status_enum = status_enum_class()

phys_mem = 0xffffc00000000000
예제 #22
0
def addThreadPrettyPrinter():
    pp = gdb.printing.RegexpCollectionPrettyPrinter("threads")
    pp.add_printer('thread', 'thread', ThreadPrettyPrinter)
    gdb.printing.register_pretty_printer(gdb.current_objfile(), pp)
예제 #23
0
    """A routine that returns the correct pretty printer for VAL
    if appropriate.  Returns None otherwise.
    """
    if val.type.tag == "type":
        return StructTypePrettyPrinter(val)
    elif val.type.tag == "main_type":
        return StructMainTypePrettyPrinter(val)
    return None


def register_pretty_printer(objfile):
    """A routine to register a pretty-printer against the given OBJFILE.
    """
    objfile.pretty_printers.append(type_lookup_function)


if __name__ == "__main__":
    if gdb.current_objfile() is not None:
        # This is the case where this script is being "auto-loaded"
        # for a given objfile.  Register the pretty-printer for that
        # objfile.
        register_pretty_printer(gdb.current_objfile())
    else:
        # We need to locate the objfile corresponding to the GDB
        # executable, and register the pretty-printer for that objfile.
        # FIXME: The condition used to match the objfile is too simplistic
        # and will not work on Windows.
        for objfile in gdb.objfiles():
            if os.path.basename(objfile.filename) == "gdb":
                objfile.pretty_printers.append(type_lookup_function)
예제 #24
0
import os.path, sys
import lsst.utils
import gdb
#
# Adjust the load path to include lsst.gdb, bypassing the regular lsstimport mechanism as
# the version of python running within gdb may not be the same as we are using for lsst processing
#
ipDiffimDir = lsst.utils.getPackageDir('ip_diffim')
printerDir = os.path.join(ipDiffimDir, "python", "lsst", "gdb")
if printerDir not in sys.path:
    sys.path.append(printerDir)

import ip.diffim.printers

ip.diffim.printers.register(gdb.current_objfile())
예제 #25
0
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import gdb

# Load the pretty-printers.
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers(gdb.current_objfile())

# Load the xmethods if GDB supports them.
def gdb_has_xmethods():
    try:
        import gdb.xmethod
        return True
    except ImportError:
        return False

if gdb_has_xmethods():
    from xmethods import register_libstdcxx_xmethods
    register_libstdcxx_xmethods(gdb.current_objfile())
예제 #26
0
파일: lean-gdb.py 프로젝트: sakas--/lean
    """Print a lean::rb_map object."""

    def __init__(self, val):
        self.val = val

    def children(self):
        for (_, child) in LeanRBTreePrinter(self.val['m_map']).children():
            yield ('', child['first'])
            yield ('', child['second'])

    def to_string(self):
        return 'lean::rb_map' # full type is way too verbose

    def display_hint(self):
        return 'map'

def build_pretty_printer():
    pp = gdb.printing.RegexpCollectionPrettyPrinter("lean")
    pp.add_printer('name', '^lean::name$', LeanNamePrinter)
    pp.add_printer('expr', '^lean::expr$', LeanExprPrinter)
    pp.add_printer('list', '^lean::list', LeanListPrinter)
    pp.add_printer('buffer', '^lean::buffer', LeanBufferPrinter)
    pp.add_printer('rb_tree', '^lean::rb_tree', LeanRBTreePrinter)
    pp.add_printer('rb_map', '^lean::rb_map', LeanRBMapPrinter)
    return pp

gdb.printing.register_pretty_printer(
    gdb.current_objfile(),
    build_pretty_printer(),
    replace=True)
import sys
import gdb

# Update module path.
dir_ = '/home/sub77/workbench/pre/share/glib-2.0/gdb'
if not dir_ in sys.path:
    sys.path.insert(0, dir_)

from gobject import register
register (gdb.current_objfile ())
import os.path
import sys
import lsst.utils
import gdb
#
# Adjust the load path to include lsst.gdb, bypassing the regular lsstimport mechanism as
# the version of python running within gdb may not be the same as we are using for lsst processing
#

measAlgorithmsDir = lsst.utils.getPackageDir('meas_algorithms')
printerDir = os.path.join(measAlgorithmsDir, "python", "lsst", "gdb")
if printerDir not in sys.path:
    sys.path.append(printerDir)

import meas.algorithms.printers  # noqa E402

meas.algorithms.printers.register(gdb.current_objfile())
예제 #29
0
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import sys
import gdb
import os
import os.path

pythondir = '/user/mipsswt/build-2015.06-05/install-mips-mti-linux-gnu/share/gcc-4.9.2/python'
libdir = '/user/mipsswt/build-2015.06-05/install-mips-mti-linux-gnu/mips-mti-linux-gnu/lib/mipsel-r2-hard/lib32'

# This file might be loaded when there is no current objfile.  This
# can happen if the user loads it manually.  In this case we don't
# update sys.path; instead we just hope the user managed to do that
# beforehand.
if gdb.current_objfile () is not None:
    # Update module path.  We want to find the relative path from libdir
    # to pythondir, and then we want to apply that relative path to the
    # directory holding the objfile with which this file is associated.
    # This preserves relocatability of the gcc tree.

    # Do a simple normalization that removes duplicate separators.
    pythondir = os.path.normpath (pythondir)
    libdir = os.path.normpath (libdir)

    prefix = os.path.commonprefix ([libdir, pythondir])
    # In some bizarre configuration we might have found a match in the
    # middle of a directory name.
    if prefix[-1] != '/':
        prefix = os.path.dirname (prefix) + '/'
예제 #30
0
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import sys
import gdb
import os
import os.path

pythondir = '/builds/idf/crosstool-NG/builds/xtensa-esp32-elf/share/gcc-5.2.0/python'
libdir = '/builds/idf/crosstool-NG/builds/xtensa-esp32-elf/xtensa-esp32-elf/lib'

# This file might be loaded when there is no current objfile.  This
# can happen if the user loads it manually.  In this case we don't
# update sys.path; instead we just hope the user managed to do that
# beforehand.
if gdb.current_objfile() is not None:
    # Update module path.  We want to find the relative path from libdir
    # to pythondir, and then we want to apply that relative path to the
    # directory holding the objfile with which this file is associated.
    # This preserves relocatability of the gcc tree.

    # Do a simple normalization that removes duplicate separators.
    pythondir = os.path.normpath(pythondir)
    libdir = os.path.normpath(libdir)

    prefix = os.path.commonprefix([libdir, pythondir])
    # In some bizarre configuration we might have found a match in the
    # middle of a directory name.
    if prefix[-1] != '/':
        prefix = os.path.dirname(prefix) + '/'