示例#1
0
 def matcher_command(self, arg):
     if arg:
         try:
             parsed = matcher.parse(arg)
             unsimplified_str = str(parsed)
             self.out.show('Unsimplified: ' + unsimplified_str)
             self.out.show('  Simplified: ' + str(parsed.simplify()))
             self.out.show('    Reparsed: ' + str(matcher.parse(unsimplified_str).simplify()))
         except RuntimeError as e:
             self.out.error('Failed to parse "' + arg + '":\n    ' + str(e))
     else:
         self.out.show('No matcher to parse')
示例#2
0
 def parse_and_join(self, new_unparsed, old):
     try:
         parsed = matcher.parse(new_unparsed)
         if old:
             return matcher.join(parsed, old).simplify()
         else:
             return parsed.simplify()
     except RuntimeError as e:
         self.out.error('Failed to parse "' + new_unparsed + '":\n    ' + str(e))
         return old
示例#3
0
def main():
    import argparse
    parser = argparse.ArgumentParser(description='Debug Wayland protocol messages, see https://github.com/wmww/wayland-debug for additional info')
    parser.add_argument('--matcher-help', action='store_true', help='show how to write matchers and exit')
    parser.add_argument('-v', '--verbose', action='store_true', help='verbose output, mostly used for debugging this program')
    parser.add_argument('-l', '--load', dest='path', type=str, help='load Wayland events from a file instead of stdin')
    parser.add_argument('-s', '--supress', action='store_true', help='supress non-wayland output of the program')
    parser.add_argument('-c', '--color', action='store_true', help='force color output (default for interactive sessions)')
    parser.add_argument('-C', '--no-color', action='store_true', help='disable color output (default for non-interactive sessions)')
    parser.add_argument('-f', '--filter', dest='f', type=str, help='only show these objects/messages (see --matcher-help for syntax)')
    parser.add_argument('-b', '--break', dest='b', type=str, help='stop on these objects/messages (see --matcher-help for syntax)')
    parser.add_argument('-g', '--gdb', action='store_true', help='run inside gdb, all subsequent arguments are sent to gdb, when inside gdb start commands with \'wl\'')
    # NOTE: -d/--gdb is here only for the help text, it is processed without argparse in gdb_runner.main()

    args = parser.parse_args()

    assert not args.gdb, 'GDB argument should have been intercepted by gdb.runner.parse_args()'

    if check_gdb():
        out_stream, err_stream = gdb.plugin.output_streams()
    else:
        out_stream = stream.Std(sys.stdout)
        err_stream = stream.Std(sys.stderr)

    if args.no_color:
        set_color_output(False)
    elif args.color:
        set_color_output(True)

    verbose = bool(args.verbose)
    unprocessed_output = not bool(args.supress)
    output = Output(verbose, unprocessed_output, out_stream, err_stream)

    if verbose:
        set_verbose(True)
        output.log('Verbose output enabled')

    if args.no_color:
        if args.color:
            output.warn('Ignoring --color, since --no-color was also specified')
        output.log('Color output disabled')
    elif args.color:
        s = ''
        i = 0
        for i, c in enumerate('Color output enabled'):
            s += color('1;' + str(i % 6 + 31), c)
        output.log(s)

    if unprocessed_output:
        output.log('Showing unparsable output')

    if args.matcher_help:
        matcher.print_help()
        exit(1)

    filter_matcher = matcher.always
    if args.f:
        try:
            filter_matcher = matcher.parse(args.f).simplify()
            output.log('Filter matcher: ' + str(filter_matcher))
        except RuntimeError as e:
            output.error(e)

    stop_matcher = matcher.never
    if args.b:
        try:
            stop_matcher = matcher.parse(args.b).simplify()
            output.log('Break matcher: ' + str(stop_matcher))
        except RuntimeError as e:
            output.error(e)

    protocol.load_all(output)

    session = wl_session.Session(filter_matcher, stop_matcher, output)

    file_path = args.path

    if check_gdb():
        try:
            if file_path:
                output.warn('Ignoring load file because we\'re inside GDB')
            gdb.plugin.main(session)
        except:
            import traceback
            traceback.print_exc()
    elif file_path:
        file_input_main(session, file_path)
    else:
        if args.b:
            output.warn('Ignoring stop matcher when stdin is used for messages')
        piped_input_main(session)