def __lldb_init_module(debugger,dict):
     debugger.CreateCategory("JASSynth").AddTypeSynthetic(lldb.SBTypeNameSpecifier("JustAStruct"),
        lldb.SBTypeSynthetic.CreateWithClassName("synth.jasSynthProvider"))
     cat = lldb.debugger.CreateCategory("CCCSynth")
     cat.AddTypeSynthetic(
         lldb.SBTypeNameSpecifier("CCC"),
         lldb.SBTypeSynthetic.CreateWithClassName("synth.CCCSynthProvider",
                                                  lldb.eTypeOptionCascade))
     cat.AddTypeSummary(
         lldb.SBTypeNameSpecifier("CCC"),
         lldb.SBTypeSummary.CreateWithFunctionName("synth.ccc_summary",
                                                   lldb.eTypeOptionCascade))
Example #2
0
    def test_with_run_command(self):
        """Test that LLDB correctly cleans caches when language categories change."""
        # This is the function to remove the custom formats in order to have a
        # clean slate for the next test case.
        def cleanup():
            if hasattr(self, 'type_category') and hasattr(self, 'type_specifier'):
                self.type_category.DeleteTypeSummary(self.type_specifier)

        # Execute the cleanup function during test case tear down.
        self.addTearDownHook(cleanup)

        self.build()
        self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)

        lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)

        self.runCmd("run", RUN_SUCCEEDED)

        # The stop reason of the thread should be breakpoint.
        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
            substrs = ['stopped',
                       'stop reason = breakpoint'])

        self.expect("frame variable", substrs = ['(S)', 'object', '123', '456'], matching=True)
        
        self.type_category = self.dbg.GetCategory(lldb.eLanguageTypeC_plus_plus)
        type_summary = lldb.SBTypeSummary.CreateWithSummaryString("this is an object of type S")
        self.type_specifier = lldb.SBTypeNameSpecifier('S')
        self.type_category.AddTypeSummary(self.type_specifier, type_summary)

        self.expect("frame variable", substrs = ['this is an object of type S'], matching=True)
        
        self.type_category.DeleteTypeSummary(self.type_specifier)
        self.expect("frame variable", substrs = ['this is an object of type S'], matching=False)
        self.expect("frame variable", substrs = ['(S)', 'object', '123', '456'], matching=True)
Example #3
0
def __lldb_init_module(debugger, *rest):
    print "registering QString"
    summary = lldb.SBTypeSummary.CreateWithFunctionName(
        "qstring.utf16string_summary")
    summary.SetOptions(lldb.eTypeOptionHideChildren)
    debugger.GetDefaultCategory().AddTypeSummary(
        lldb.SBTypeNameSpecifier("QString", False), summary)
Example #4
0
def attach_summary_to_type(summary_fn, type_name, is_regex=False):
    global rust_category
    summary = lldb.SBTypeSummary.CreateWithFunctionName(
        'adapter.formatters.rust.' + summary_fn)
    summary.SetOptions(lldb.eTypeOptionCascade)
    assert rust_category.AddTypeSummary(
        lldb.SBTypeNameSpecifier(type_name, is_regex), summary)
Example #5
0
def attach_synthetic_to_type(synth_class, type_name, is_regex=False):
    global rust_category
    synth = lldb.SBTypeSynthetic.CreateWithClassName(
        'adapter.formatters.rust.' + synth_class)
    synth.SetOptions(lldb.eTypeOptionCascade)
    assert rust_category.AddTypeSynthetic(
        lldb.SBTypeNameSpecifier(type_name, is_regex), synth)
Example #6
0
def attach_summary_to_type(summary_fn, type_name, is_regex=False):
    global module, rust_category
    #log.debug('attaching summary %s to "%s", is_regex=%s', summary_fn.__name__, type_name, is_regex)
    summary = lldb.SBTypeSummary.CreateWithFunctionName(__name__ + '.' +
                                                        summary_fn.__name__)
    summary.SetOptions(lldb.eTypeOptionCascade)
    rust_category.AddTypeSummary(lldb.SBTypeNameSpecifier(type_name, is_regex),
                                 summary)
Example #7
0
def register_pretty_printer(obj, printer):
    gdb.pretty_printers.append(printer)
    if lldb.debugger.GetCategory(printer.name).IsValid():
        print('WARNING: A type category with name "%s" already exists.' %
              printer.name)
        return
    cat = lldb.debugger.CreateCategory(printer.name)
    type_options = (lldb.eTypeOptionCascade | lldb.eTypeOptionSkipPointers
                    | lldb.eTypeOptionSkipReferences
                    | lldb.eTypeOptionHideEmptyAggregates)
    for sp in printer.subprinters:
        cat.AddTypeSummary(
            lldb.SBTypeNameSpecifier('^%s(<.+>)?(( )?&)?$' % sp.name, True),
            lldb.SBTypeSummary.CreateWithFunctionName(
                'gdb.printing.type_summary_function', type_options))
        cat.AddTypeSynthetic(
            lldb.SBTypeNameSpecifier('^%s(<.+>)?(( )?&)?$' % sp.name, True),
            lldb.SBTypeSynthetic.CreateWithClassName(
                'gdb.printing.GdbPrinterSynthProvider', type_options))
    cat.SetEnabled(True)
Example #8
0
def attach_synthetic_to_type(synth_class, type_name, is_regex=False):
	global module, d_category
	synth = lldb.SBTypeSynthetic.CreateWithClassName(__name__ + '.' + synth_class.__name__)
	synth.SetOptions(lldb.eTypeOptionCascade)
	ret = d_category.AddTypeSynthetic(lldb.SBTypeNameSpecifier(type_name, is_regex), synth)
	log.debug('attaching synthetic %s to "%s", is_regex=%s -> %s', synth_class.__name__, type_name, is_regex, ret)

	summary_fn = lambda valobj, dict: get_synth_summary(synth_class, valobj, dict)
	# LLDB accesses summary fn's by name, so we need to create a unique one.
	summary_fn.__name__ = '_get_synth_summary_' + synth_class.__name__
	setattr(module, summary_fn.__name__, summary_fn)
	attach_summary_to_type(summary_fn, type_name, is_regex)
Example #9
0
def attach_synthetic_to_type(synth_class, type_name, is_regex=False):
    global rust_category
    global module
    synth = lldb.SBTypeSynthetic.CreateWithClassName('adapter.formatters.rust.' + synth_class.__name__)
    synth.SetOptions(lldb.eTypeOptionCascade)
    rust_category.AddTypeSynthetic(lldb.SBTypeNameSpecifier(type_name, is_regex), synth)

    summary_fn = lambda valobj, dict: get_synth_summary(synth_class, valobj, dict)
    # LLDB accesses summary fn's by name, so we need to create a unique one.
    summary_fn.__name__ = '_get_synth_summary_' + synth_class.__name__
    setattr(module, summary_fn.__name__, summary_fn)
    attach_summary_to_type(summary_fn, type_name, is_regex)
Example #10
0
def attach(enoki_category, synth_class, type_name, summary=True, synth=True):
    if summary:

        def summary_func(instance, internal_dict):
            synth = synth_class(instance.GetNonSyntheticValue(), internal_dict)
            synth.update()
            return synth.get_summary()

        summary_func.__name__ = synth_class.__name__ + 'SummaryWrapper'
        setattr(sys.modules[__name__], summary_func.__name__, summary_func)

        summary = lldb.SBTypeSummary.CreateWithFunctionName(
            __name__ + '.' + summary_func.__name__)
        summary.SetOptions(lldb.eTypeOptionCascade)
        enoki_category.AddTypeSummary(
            lldb.SBTypeNameSpecifier(type_name, True), summary)

    if synth:
        synth = lldb.SBTypeSynthetic.CreateWithClassName(__name__ + '.' +
                                                         synth_class.__name__)
        synth.SetOptions(lldb.eTypeOptionCascade)
        enoki_category.AddTypeSynthetic(
            lldb.SBTypeNameSpecifier(type_name, True), synth)
Example #11
0
def attach_synthetic_to_type(synth_class, type_name, is_regex=False):
    global module, boltzmann_solver_category

    synth: lldb.SBTypeSynthetic = lldb.SBTypeSynthetic.CreateWithClassName(
        __name__ + "." + synth_class.__name__)
    synth.SetOptions(lldb.eTypeOptionCascade)
    boltzmann_solver_category.AddTypeSynthetic(
        lldb.SBTypeNameSpecifier(type_name, is_regex), synth)

    def summary_fn(valobj, dict):
        return get_synth_summary(synth_class, valobj, dict)

    # LLDB accesses summary fn's by name, so we need to create a unique one.
    summary_fn.__name__ = "_get_synth_summary_" + synth_class.__name__
    setattr(module, summary_fn.__name__, summary_fn)
    attach_summary_to_type(summary_fn, type_name, is_regex)
Example #12
0
def __lldb_init_module(debugger, dict):
    clearLog()
    log('********************************** init module 3')
    category = debugger.GetDefaultCategory()
    for type in ['uString', 'uObject', 'uType', 'uArray']:
        summary = lldb.SBTypeSummary.CreateWithFunctionName(moduleName + '.' +
                                                            type + 'Summary')
        isRegex = False
        debugger.GetDefaultCategory().AddTypeSummary(
            lldb.SBTypeNameSpecifier(type, isRegex), summary)
    for type in ['uStrong', 'uSStrong', 'uWeak', 'uSWeak']:
        summary = lldb.SBTypeSummary.CreateWithFunctionName(
            moduleName + '.firstChildSummary')
        isRegex = True
        category.AddTypeSummary(
            lldb.SBTypeNameSpecifier(type + '<.*>', isRegex), summary)

        synthetic = lldb.SBTypeSynthetic.CreateWithClassName(
            moduleName + '.FirstChildSynthProvider')
        synthetic.SetOptions(lldb.eTypeOptionCascade)
        category.AddTypeSynthetic(
            lldb.SBTypeNameSpecifier(type + '<.*>', isRegex), synthetic)
    summary = lldb.SBTypeSummary.CreateWithFunctionName(moduleName +
                                                        '.uObjectSummary')
    isRegex = True
    category.AddTypeSummary(lldb.SBTypeNameSpecifier('g::.+', isRegex),
                            summary)

    synthetic = lldb.SBTypeSynthetic.CreateWithClassName(
        moduleName + '.UObjectSynthProvider')
    synthetic.SetOptions(lldb.eTypeOptionCascade)
    category.AddTypeSynthetic(lldb.SBTypeNameSpecifier('uObject', False),
                              synthetic)

    synthetic = lldb.SBTypeSynthetic.CreateWithClassName(
        moduleName + '.UObjectSynthProvider')
    synthetic.SetOptions(lldb.eTypeOptionCascade)
    category.AddTypeSynthetic(lldb.SBTypeNameSpecifier('g::.+', True),
                              synthetic)

    synthetic = lldb.SBTypeSynthetic.CreateWithClassName(
        moduleName + '.UArraySynthProvider')
    synthetic.SetOptions(lldb.eTypeOptionCascade)
    category.AddTypeSynthetic(lldb.SBTypeNameSpecifier('uArray', False),
                              synthetic)
Example #13
0
def use_function(function):
    jni_category = lldb.debugger.CreateCategory("JNI types")
    jstring_summary = lldb.SBTypeSummary.CreateWithFunctionName(function)
    jni_category.AddTypeSummary(lldb.SBTypeNameSpecifier("jstring"),
                                jstring_summary)
    jni_category.SetEnabled(True)
Example #14
0
File: lldbnim.py Project: dsrw/enu
def __lldb_init_module(debugger, internal_dict):

    lldb.formatters.Logger._lldb_formatters_debug_level = 2

    category = debugger.GetDefaultCategory()
    category.SetEnabled(True)


    category.AddTypeSummary(lldb.SBTypeNameSpecifier("NI8"), \
                            lldb.SBTypeSummary.CreateWithFunctionName('lldbnim.NimNI8_SummaryFormatter'))
    category.AddTypeSummary(lldb.SBTypeNameSpecifier("NU8"), \
                            lldb.SBTypeSummary.CreateWithFunctionName('lldbnim.NimNU_SummaryFormatter'))
    category.AddTypeSummary(lldb.SBTypeNameSpecifier("NU16"), \
                            lldb.SBTypeSummary.CreateWithFunctionName('lldbnim.NimNU_SummaryFormatter'))
    category.AddTypeSummary(lldb.SBTypeNameSpecifier("NU32"), \
                            lldb.SBTypeSummary.CreateWithFunctionName('lldbnim.NimNU_SummaryFormatter'))
    category.AddTypeSummary(lldb.SBTypeNameSpecifier("NU64"), \
                            lldb.SBTypeSummary.CreateWithFunctionName('lldbnim.NimNU_SummaryFormatter'))



    category.AddTypeSummary(lldb.SBTypeNameSpecifier("^tyEnum_.*$", True), \
                            lldb.SBTypeSummary.CreateWithFunctionName('lldbnim.NimEnum_SummaryFormatter'))

    category.AddTypeSynthetic( \
        lldb.SBTypeNameSpecifier("NimStringDesc"), \
        lldb.SBTypeSynthetic.CreateWithClassName("lldbnim.NimSeqProvider",
                                                 lldb.eTypeOptionCascade))

    category.AddTypeSummary(lldb.SBTypeNameSpecifier('NimStringDesc'), \
                            lldb.SBTypeSummary.CreateWithFunctionName('lldbnim.NimStringDesc_SummaryFormatter'))

    category.AddTypeSynthetic( \
        lldb.SBTypeNameSpecifier("^tySequence__.*$", True), \
        lldb.SBTypeSynthetic.CreateWithClassName("lldbnim.NimSeqProvider",
                                                 lldb.eTypeOptionCascade))

    category.AddTypeSummary( \
        lldb.SBTypeNameSpecifier("^tySequence__.*$", True), \
        lldb.SBTypeSummary.CreateWithFunctionName('lldbnim.NimSeq_SummaryFormatter'))

    category.AddTypeSummary( \
        lldb.SBTypeNameSpecifier("^tyArray__.*$", True), \
        lldb.SBTypeSummary.CreateWithFunctionName('lldbnim.NimArray_SummaryFormatter'))

    category.AddTypeSynthetic( \
        lldb.SBTypeNameSpecifier("^tyObject_Table__.*$", True), \
        lldb.SBTypeSynthetic.CreateWithClassName("lldbnim.NimTableProvider",
                                                 lldb.eTypeOptionCascade))

    category.AddTypeSummary( \
        lldb.SBTypeNameSpecifier("^tyObject_Table__.*$", True), \
        lldb.SBTypeSummary.CreateWithFunctionName('lldbnim.NimTable_SummaryFormatter'))
def __lldb_init_module(debugger, dict):
    debugger.CreateCategory("JASSynth").AddTypeSynthetic(
        lldb.SBTypeNameSpecifier("JustAStruct"),
        lldb.SBTypeSynthetic.CreateWithClassName("jas_synth.jasSynthProvider"))
    def test_formatters_api(self):
        """Test Python APIs for working with formatters"""
        self.build()
        self.setTearDownCleanup()

        """Test Python APIs for working with formatters"""
        self.runCmd("file " + self.getBuildArtifact("a.out"),
                    CURRENT_EXECUTABLE_SET)

        lldbutil.run_break_set_by_file_and_line(
            self, "main.cpp", self.line, num_expected_locations=1,
            loc_exact=True)

        self.runCmd("run", RUN_SUCCEEDED)

        # The stop reason of the thread should be breakpoint.
        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
                    substrs=['stopped',
                             'stop reason = breakpoint'])

        # This is the function to remove the custom formats in order to have a
        # clean slate for the next test case.
        def cleanup():
            self.runCmd('type format clear', check=False)
            self.runCmd('type summary clear', check=False)
            self.runCmd('type filter clear', check=False)
            self.runCmd('type synthetic clear', check=False)
            self.runCmd('type category delete foobar', check=False)
            self.runCmd('type category delete JASSynth', check=False)
            self.runCmd('type category delete newbar', check=False)

        # Execute the cleanup function during test case tear down.
        self.addTearDownHook(cleanup)

        format = lldb.SBTypeFormat(lldb.eFormatHex)
        category = self.dbg.GetDefaultCategory()
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("int"), format)

        self.expect("frame variable foo.A",
                    substrs=['0x00000001'])
        self.expect("frame variable foo.E", matching=False,
                    substrs=['b8cca70a'])

        category.AddTypeFormat(lldb.SBTypeNameSpecifier("long"), format)
        self.expect("frame variable foo.A",
                    substrs=['0x00000001'])
        self.expect("frame variable foo.E",
                    substrs=['b8cca70a'])

        format.SetFormat(lldb.eFormatOctal)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("int"), format)
        self.expect("frame variable foo.A",
                    substrs=[' 01'])
        self.expect("frame variable foo.E",
                    substrs=['b8cca70a'])

        category.DeleteTypeFormat(lldb.SBTypeNameSpecifier("int"))
        category.DeleteTypeFormat(lldb.SBTypeNameSpecifier("long"))
        self.expect("frame variable foo.A", matching=False,
                    substrs=[' 01'])
        self.expect("frame variable foo.E", matching=False,
                    substrs=['b8cca70a'])

        summary = lldb.SBTypeSummary.CreateWithSummaryString(
            "the hello world you'll never see")
        summary.SetSummaryString('hello world')
        new_category = self.dbg.GetCategory("foobar")
        self.assertFalse(
            new_category.IsValid(),
            "getting a non-existing category worked")
        new_category = self.dbg.CreateCategory("foobar")
        new_category.SetEnabled(True)
        new_category.AddTypeSummary(
            lldb.SBTypeNameSpecifier(
                "^.*t$",
                True,  # is_regexp
            ), summary)

        self.expect("frame variable foo.A",
                    substrs=['hello world'])
        self.expect("frame variable foo.E", matching=False,
                    substrs=['hello world'])
        self.expect("frame variable foo.B",
                    substrs=['hello world'])
        self.expect("frame variable foo.F",
                    substrs=['hello world'])
        new_category.SetEnabled(False)
        self.expect("frame variable foo.A", matching=False,
                    substrs=['hello world'])
        self.expect("frame variable foo.E", matching=False,
                    substrs=['hello world'])
        self.expect("frame variable foo.B", matching=False,
                    substrs=['hello world'])
        self.expect("frame variable foo.F", matching=False,
                    substrs=['hello world'])
        self.dbg.DeleteCategory(new_category.GetName())
        self.expect("frame variable foo.A", matching=False,
                    substrs=['hello world'])
        self.expect("frame variable foo.E", matching=False,
                    substrs=['hello world'])
        self.expect("frame variable foo.B", matching=False,
                    substrs=['hello world'])
        self.expect("frame variable foo.F", matching=False,
                    substrs=['hello world'])

        filter = lldb.SBTypeFilter(0)
        filter.AppendExpressionPath("A")
        filter.AppendExpressionPath("D")
        self.assertEqual(
            filter.GetNumberOfExpressionPaths(), 2,
            "filter with two items does not have two items")

        category.AddTypeFilter(lldb.SBTypeNameSpecifier("JustAStruct"), filter)
        self.expect("frame variable foo",
                    substrs=['A = 1', 'D = 6.28'])
        self.expect("frame variable foo", matching=False,
                    substrs=['B = ', 'C = ', 'E = ', 'F = '])

        category.DeleteTypeFilter(
            lldb.SBTypeNameSpecifier(
                "JustAStruct", True))
        self.expect("frame variable foo",
                    substrs=['A = 1', 'D = 6.28'])
        self.expect("frame variable foo", matching=False,
                    substrs=['B = ', 'C = ', 'E = ', 'F = '])

        category.DeleteTypeFilter(
            lldb.SBTypeNameSpecifier(
                "JustAStruct", False))
        self.expect("frame variable foo",
                    substrs=['A = 1', 'D = 6.28'])
        self.expect("frame variable foo", matching=True,
                    substrs=['B = ', 'C = ', 'E = ', 'F = '])

        self.runCmd("command script import --allow-reload ./synth.py")

        self.expect("frame variable foo", matching=False,
                    substrs=['X = 1'])

        self.dbg.GetCategory("JASSynth").SetEnabled(True)
        self.expect("frame variable foo", matching=True,
                    substrs=['X = 1'])

        self.dbg.GetCategory("CCCSynth").SetEnabled(True)
        self.expect(
            "frame variable ccc",
            matching=True,
            substrs=[
                'CCC object with leading value (int) a = 111',
                'a = 111',
                'b = 222',
                'c = 333'])

        foo_var = self.dbg.GetSelectedTarget().GetProcess(
        ).GetSelectedThread().GetSelectedFrame().FindVariable('foo')
        self.assertTrue(foo_var.IsValid(), 'could not find foo')
        self.assertTrue(
            foo_var.GetDeclaration().IsValid(),
            'foo declaration is invalid')

        self.assertEqual(
            foo_var.GetNumChildren(), 2,
            'synthetic value has wrong number of child items (synth)')
        self.assertEqual(
            foo_var.GetChildMemberWithName('X').GetValueAsUnsigned(), 1,
            'foo_synth.X has wrong value (synth)')
        self.assertFalse(
            foo_var.GetChildMemberWithName('B').IsValid(),
            'foo_synth.B is valid but should not (synth)')

        self.dbg.GetCategory("JASSynth").SetEnabled(False)
        foo_var = self.dbg.GetSelectedTarget().GetProcess(
        ).GetSelectedThread().GetSelectedFrame().FindVariable('foo')
        self.assertTrue(foo_var.IsValid(), 'could not find foo')

        self.assertFalse(
            foo_var.GetNumChildren() == 2,
            'still seeing synthetic value')

        filter = lldb.SBTypeFilter(0)
        filter.AppendExpressionPath("A")
        filter.AppendExpressionPath("D")
        category.AddTypeFilter(lldb.SBTypeNameSpecifier("JustAStruct"), filter)
        self.expect("frame variable foo",
                    substrs=['A = 1', 'D = 6.28'])

        foo_var = self.dbg.GetSelectedTarget().GetProcess(
        ).GetSelectedThread().GetSelectedFrame().FindVariable('foo')
        self.assertTrue(foo_var.IsValid(), 'could not find foo')

        self.assertEqual(
            foo_var.GetNumChildren(), 2,
            'synthetic value has wrong number of child items (filter)')
        self.assertEqual(
            foo_var.GetChildMemberWithName('X').GetValueAsUnsigned(), 0,
            'foo_synth.X has wrong value (filter)')
        self.assertEqual(
            foo_var.GetChildMemberWithName('A').GetValueAsUnsigned(), 1,
            'foo_synth.A has wrong value (filter)')

        self.assertTrue(filter.ReplaceExpressionPathAtIndex(
            0, "C"), "failed to replace an expression path in filter")
        self.expect("frame variable foo",
                    substrs=['A = 1', 'D = 6.28'])
        category.AddTypeFilter(lldb.SBTypeNameSpecifier("JustAStruct"), filter)
        self.expect("frame variable foo",
                    substrs=["C = 'e'", 'D = 6.28'])
        category.AddTypeFilter(lldb.SBTypeNameSpecifier("FooType"), filter)
        filter.ReplaceExpressionPathAtIndex(1, "F")
        self.expect("frame variable foo",
                    substrs=["C = 'e'", 'D = 6.28'])
        category.AddTypeFilter(lldb.SBTypeNameSpecifier("JustAStruct"), filter)
        self.expect("frame variable foo",
                    substrs=["C = 'e'", 'F = 0'])
        self.expect("frame variable bar",
                    substrs=["C = 'e'", 'D = 6.28'])

        foo_var = self.dbg.GetSelectedTarget().GetProcess(
        ).GetSelectedThread().GetSelectedFrame().FindVariable('foo')
        self.assertTrue(foo_var.IsValid(), 'could not find foo')
        self.assertEqual(
            foo_var.GetChildMemberWithName('C').GetValueAsUnsigned(), ord('e'),
            'foo_synth.C has wrong value (filter)')

        chosen = self.dbg.GetFilterForType(
            lldb.SBTypeNameSpecifier("JustAStruct"))
        self.assertEqual(
            chosen.count, 2,
            "wrong filter found for JustAStruct")
        self.assertEqual(
            chosen.GetExpressionPathAtIndex(0), 'C',
            "wrong item at index 0 for JustAStruct")
        self.assertEqual(
            chosen.GetExpressionPathAtIndex(1), 'F',
            "wrong item at index 1 for JustAStruct")

        self.assertFalse(
            category.DeleteTypeFilter(
                lldb.SBTypeNameSpecifier("NoSuchType")),
            "deleting a non-existing filter worked")
        self.assertFalse(
            category.DeleteTypeSummary(
                lldb.SBTypeNameSpecifier("NoSuchType")),
            "deleting a non-existing summary worked")
        self.assertFalse(
            category.DeleteTypeFormat(
                lldb.SBTypeNameSpecifier("NoSuchType")),
            "deleting a non-existing format worked")
        self.assertFalse(
            category.DeleteTypeSynthetic(
                lldb.SBTypeNameSpecifier("NoSuchType")),
            "deleting a non-existing synthetic worked")

        self.assertFalse(
            category.DeleteTypeFilter(
                lldb.SBTypeNameSpecifier("")),
            "deleting a filter for '' worked")
        self.assertFalse(
            category.DeleteTypeSummary(
                lldb.SBTypeNameSpecifier("")),
            "deleting a summary for '' worked")
        self.assertFalse(
            category.DeleteTypeFormat(
                lldb.SBTypeNameSpecifier("")),
            "deleting a format for '' worked")
        self.assertFalse(
            category.DeleteTypeSynthetic(
                lldb.SBTypeNameSpecifier("")),
            "deleting a synthetic for '' worked")

        try:
            self.assertFalse(
                category.AddTypeSummary(
                    lldb.SBTypeNameSpecifier("NoneSuchType"),
                    None),
                "adding a summary valued None worked")
        except:
            pass
        else:
            self.assertFalse(True, "adding a summary valued None worked")

        try:
            self.assertFalse(
                category.AddTypeFilter(
                    lldb.SBTypeNameSpecifier("NoneSuchType"),
                    None),
                "adding a filter valued None worked")
        except:
            pass
        else:
            self.assertFalse(True, "adding a filter valued None worked")

        try:
            self.assertFalse(
                category.AddTypeSynthetic(
                    lldb.SBTypeNameSpecifier("NoneSuchType"),
                    None),
                "adding a synthetic valued None worked")
        except:
            pass
        else:
            self.assertFalse(True, "adding a synthetic valued None worked")

        try:
            self.assertFalse(
                category.AddTypeFormat(
                    lldb.SBTypeNameSpecifier("NoneSuchType"),
                    None),
                "adding a format valued None worked")
        except:
            pass
        else:
            self.assertFalse(True, "adding a format valued None worked")

        self.assertFalse(
            category.AddTypeSummary(
                lldb.SBTypeNameSpecifier("EmptySuchType"),
                lldb.SBTypeSummary()),
            "adding a summary without value worked")
        self.assertFalse(
            category.AddTypeFilter(
                lldb.SBTypeNameSpecifier("EmptySuchType"),
                lldb.SBTypeFilter()),
            "adding a filter without value worked")
        self.assertFalse(
            category.AddTypeSynthetic(
                lldb.SBTypeNameSpecifier("EmptySuchType"),
                lldb.SBTypeSynthetic()),
            "adding a synthetic without value worked")
        self.assertFalse(
            category.AddTypeFormat(
                lldb.SBTypeNameSpecifier("EmptySuchType"),
                lldb.SBTypeFormat()),
            "adding a format without value worked")

        self.assertFalse(
            category.AddTypeSummary(
                lldb.SBTypeNameSpecifier(""),
                lldb.SBTypeSummary.CreateWithSummaryString("")),
            "adding a summary for an invalid type worked")
        self.assertFalse(
            category.AddTypeFilter(
                lldb.SBTypeNameSpecifier(""),
                lldb.SBTypeFilter(0)),
            "adding a filter for an invalid type worked")
        self.assertFalse(
            category.AddTypeSynthetic(
                lldb.SBTypeNameSpecifier(""),
                lldb.SBTypeSynthetic.CreateWithClassName("")),
            "adding a synthetic for an invalid type worked")
        self.assertFalse(
            category.AddTypeFormat(
                lldb.SBTypeNameSpecifier(""),
                lldb.SBTypeFormat(
                    lldb.eFormatHex)),
            "adding a format for an invalid type worked")

        new_category = self.dbg.CreateCategory("newbar")
        new_category.AddTypeSummary(
            lldb.SBTypeNameSpecifier("JustAStruct"),
            lldb.SBTypeSummary.CreateWithScriptCode("return 'hello scripted world';"))
        self.expect("frame variable foo", matching=False,
                    substrs=['hello scripted world'])
        new_category.SetEnabled(True)
        self.expect("frame variable foo", matching=True,
                    substrs=['hello scripted world'])

        self.expect("frame variable foo_ptr", matching=True,
                    substrs=['hello scripted world'])
        new_category.AddTypeSummary(
            lldb.SBTypeNameSpecifier("JustAStruct"),
            lldb.SBTypeSummary.CreateWithScriptCode(
                "return 'hello scripted world';",
                lldb.eTypeOptionSkipPointers))
        self.expect("frame variable foo", matching=True,
                    substrs=['hello scripted world'])

        frame = self.dbg.GetSelectedTarget().GetProcess(
        ).GetSelectedThread().GetSelectedFrame()
        foo_ptr = frame.FindVariable("foo_ptr")
        summary = foo_ptr.GetTypeSummary()

        self.assertFalse(
            summary.IsValid(),
            "summary found for foo* when none was planned")

        self.expect("frame variable foo_ptr", matching=False,
                    substrs=['hello scripted world'])

        new_category.AddTypeSummary(
            lldb.SBTypeNameSpecifier("JustAStruct"),
            lldb.SBTypeSummary.CreateWithSummaryString(
                "hello static world",
                lldb.eTypeOptionNone))

        summary = foo_ptr.GetTypeSummary()

        self.assertTrue(
            summary.IsValid(),
            "no summary found for foo* when one was in place")
        self.assertEqual(
            summary.GetData(), "hello static world",
            "wrong summary found for foo*")

        self.expect("frame variable e1", substrs=["I am an empty Empty1 {}"])
        self.expect("frame variable e2", substrs=["I am an empty Empty2"])
        self.expect(
            "frame variable e2",
            substrs=["I am an empty Empty2 {}"],
            matching=False)

        self.assertTrue(
            self.dbg.GetCategory(
                lldb.eLanguageTypeObjC) is not None,
            "ObjC category is None")
Example #17
0
def TypePrintFormating(debugger):
    #
    # Set the default print formatting for EFI types in lldb.
    # seems lldb defaults to decimal.
    #
    category = debugger.GetDefaultCategory()
    FormatBool = lldb.SBTypeFormat(lldb.eFormatBoolean)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("BOOLEAN"), FormatBool)

    FormatHex  = lldb.SBTypeFormat(lldb.eFormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT64"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT64"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT32"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT32"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT16"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT16"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT8"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT8"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINTN"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("INTN"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("CHAR8"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("CHAR16"), FormatHex)

    category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_PHYSICAL_ADDRESS"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("PHYSICAL_ADDRESS"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_STATUS"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_TPL"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_LBA"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_BOOT_MODE"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_FV_FILETYPE"), FormatHex)

    #
    # Smart type printing for EFI
    #
    debugger.HandleCommand("type summary add EFI_GUID --python-function lldbefi.EFI_GUID_TypeSummary")
    debugger.HandleCommand("type summary add EFI_STATUS --python-function lldbefi.EFI_STATUS_TypeSummary")
    debugger.HandleCommand("type summary add EFI_TPL --python-function lldbefi.EFI_TPL_TypeSummary")
    debugger.HandleCommand("type summary add EFI_DEVICE_PATH_PROTOCOL --python-function lldbefi.EFI_DEVICE_PATH_PROTOCOL_TypeSummary")

    debugger.HandleCommand("type summary add CHAR16 --python-function lldbefi.CHAR16_TypeSummary")
    debugger.HandleCommand('type summary add --regex "CHAR16 \[[0-9]+\]" --python-function lldbefi.CHAR16_TypeSummary')
    debugger.HandleCommand("type summary add CHAR8 --python-function lldbefi.CHAR8_TypeSummary")
    debugger.HandleCommand('type summary add --regex "CHAR8 \[[0-9]+\]" --python-function lldbefi.CHAR8_TypeSummary')

    debugger.HandleCommand(
      'setting set frame-format "frame #${frame.index}: ${frame.pc}'
      '{ ${module.file.basename}{:${function.name}()${function.pc-offset}}}'
      '{ at ${line.file.fullpath}:${line.number}}\n"'
      )
Example #18
0
def TypePrintFormating(debugger):
    #
    # Set the default print formating for EFI types in lldb.
    # seems lldb defaults to decimal.
    #
    category = debugger.GetDefaultCategory()
    FormatBool = lldb.SBTypeFormat(lldb.eFormatBoolean)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("BOOLEAN"), FormatBool)

    FormatHex = lldb.SBTypeFormat(lldb.eFormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT64"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT64"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT32"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT32"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT16"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT16"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT8"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT8"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINTN"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("INTN"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("CHAR8"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("CHAR16"), FormatHex)

    category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_PHYSICAL_ADDRESS"),
                           FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("PHYSICAL_ADDRESS"),
                           FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_STATUS"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_TPL"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_LBA"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_BOOT_MODE"),
                           FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_FV_FILETYPE"),
                           FormatHex)

    #
    # Smart type printing for EFI
    #
    debugger.HandleCommand(
        "type summary add EFI_GUID --python-function lldbefi.EFI_GUID_TypeSummary"
    )
    debugger.HandleCommand(
        "type summary add EFI_STATUS --python-function lldbefi.EFI_STATUS_TypeSummary"
    )
    debugger.HandleCommand(
        "type summary add EFI_TPL --python-function lldbefi.EFI_TPL_TypeSummary"
    )
    debugger.HandleCommand(
        "type summary add EFI_DEVICE_PATH_PROTOCOL --python-function lldbefi.EFI_DEVICE_PATH_PROTOCOL_TypeSummary"
    )

    debugger.HandleCommand(
        "type summary add CHAR16 --python-function lldbefi.CHAR16_TypeSummary")
    debugger.HandleCommand(
        'type summary add --regex "CHAR16 \[[0-9]+\]" --python-function lldbefi.CHAR16_TypeSummary'
    )
    debugger.HandleCommand(
        "type summary add CHAR8 --python-function lldbefi.CHAR8_TypeSummary")
    debugger.HandleCommand(
        'type summary add --regex "CHAR8 \[[0-9]+\]" --python-function lldbefi.CHAR8_TypeSummary'
    )
Example #19
0
    def __call__(self, debugger, command, exe_ctx, result):
        self.debugger = debugger


        category = debugger.GetDefaultCategory()
        FormatBool = lldb.SBTypeFormat(lldb.eFormatBoolean)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("BOOLEAN"), FormatBool)

        FormatHex  = lldb.SBTypeFormat(lldb.eFormatHex)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT64"), FormatHex)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT64"), FormatHex)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT32"), FormatHex)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT32"), FormatHex)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT16"), FormatHex)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT16"), FormatHex)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT8"), FormatHex)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT8"), FormatHex)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINTN"), FormatHex)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("INTN"), FormatHex)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("CHAR8"), FormatHex)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("CHAR16"), FormatHex)

        category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_PHYSICAL_ADDRESS"), FormatHex)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("PHYSICAL_ADDRESS"), FormatHex)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_STATUS"), FormatHex)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_TPL"), FormatHex)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_LBA"), FormatHex)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_BOOT_MODE"), FormatHex)
        category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_FV_FILETYPE"), FormatHex)



        args = shlex.split(command)
        try:
            opts, args = getopt.getopt(args, "o", ["offset-by-headers"])
        except (getopt.GetoptError) as err:
            self.usage ()
            return
        for opt, arg in opts:
            if opt == "-o":
                self.offset_by_headers = True

        self.typetarget   = None
        self.activetarget = None

        # FIXME: Use ReadCStringFromMemory.
        # FIXME: Support executing code.
        if len(args) >= 1 and args[0] != '':
            gdb.execute ("symbol-file")
            gdb.execute ("symbol-file %s" % args[0])
        else:
            for i in range(0, self.debugger.GetNumTargets()):
                target      = self.debugger.GetTargetAtIndex(i)
                target_name = str(target)
                print('Target {} is "{}"'.format(i, target_name))
                if target_name.find('GdbSyms') >= 0:
                    self.typetarget = target
                elif target_name.find('No executable module.') >= 0:
                    self.activetarget = target

        if not self.typetarget:
            print('Cannot find GdbSyms target!')
            return

        if not self.activetarget:
            print('Cannot find target with full memory access!')
            return

        # Force into full memory target.
        self.debugger.SetSelectedTarget(self.activetarget)

        est = self.search_est ()
        if est == self.EINVAL:
            print ("No EFI_SYSTEM_TABLE...")
            return


        print ("EFI_SYSTEM_TABLE @ 0x%x" % est.GetValueAsUnsigned())
        self.parse_est (est)
Example #20
0
def lldb_type_formaters(debugger, mod_name):
    '''Teach lldb about EFI types'''

    category = debugger.GetDefaultCategory()
    FormatBool = lldb.SBTypeFormat(lldb.eFormatBoolean)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("BOOLEAN"), FormatBool)

    FormatHex = lldb.SBTypeFormat(lldb.eFormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT64"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT64"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT32"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT32"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT16"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT16"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT8"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT8"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINTN"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("INTN"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("CHAR8"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("CHAR16"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier(
        "EFI_PHYSICAL_ADDRESS"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier(
        "PHYSICAL_ADDRESS"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_LBA"), FormatHex)
    category.AddTypeFormat(
        lldb.SBTypeNameSpecifier("EFI_BOOT_MODE"), FormatHex)
    category.AddTypeFormat(lldb.SBTypeNameSpecifier(
        "EFI_FV_FILETYPE"), FormatHex)

    #
    # Smart type printing for EFI
    #

    debugger.HandleCommand(
        f'type summary add GUID - -python-function '
        f'{mod_name}.EFI_GUID_TypeSummary')
    debugger.HandleCommand(
        f'type summary add EFI_GUID --python-function '
        f'{mod_name}.EFI_GUID_TypeSummary')
    debugger.HandleCommand(
        f'type summary add EFI_STATUS --python-function '
        f'{mod_name}.EFI_STATUS_TypeSummary')
    debugger.HandleCommand(
        f'type summary add EFI_TPL - -python-function '
        f'{mod_name}.EFI_TPL_TypeSummary')
    debugger.HandleCommand(
        f'type summary add EFI_BOOT_MODE --python-function '
        f'{mod_name}.EFI_BOOT_MODE_TypeSummary')

    debugger.HandleCommand(
        f'type summary add CHAR16 --python-function '
        f'{mod_name}.CHAR16_TypeSummary')

    # W605 this is the correct escape sequence for the lldb command
    debugger.HandleCommand(
        f'type summary add --regex "CHAR16 \[[0-9]+\]" '  # noqa: W605
        f'--python-function {mod_name}.CHAR16_TypeSummary')

    debugger.HandleCommand(
        f'type summary add CHAR8 --python-function '
        f'{mod_name}.CHAR8_TypeSummary')

    # W605 this is the correct escape sequence for the lldb command
    debugger.HandleCommand(
        f'type summary add --regex "CHAR8 \[[0-9]+\]"  '  # noqa: W605
        f'--python-function {mod_name}.CHAR8_TypeSummary')
Example #21
0
import lldb


def Struct_SummaryFormatter(valobj, internal_dict):
    return 'A data formatter at work'


category = lldb.debugger.CreateCategory("TSLSFormatters")
category.SetEnabled(True)
summary = lldb.SBTypeSummary.CreateWithFunctionName(
    "tslsformatters.Struct_SummaryFormatter", lldb.eTypeOptionCascade)
spec = lldb.SBTypeNameSpecifier("Struct", False)
category.AddTypeSummary(spec, summary)