Exemplo n.º 1
0
    def test_basic(self):

        self.cp.frame = sys._getframe()
        self.cp.setup()
        for expect, cmd in (
                ( (None, None, None),
                  "break '''c:\\tmp\\foo.bat''':1" ),
                ( (None, None, None),
                  'break """/Users/My Documents/foo.py""":2' ),
                ( ("<module>", osp.basename(__file__), 10),
                  "break 10" ),
                ( (None, None, None),
                   "break cmdproc.py:5" ) ,
                ( (None, None, None),
                   "break set_break()" ),
                ( ("<module>", osp.basename(__file__), 4, 'i==5'),
                   "break 4 if i==5" ),
                ( (None, None, None),
                  "break cmdproc.setup()" ),
                ):
            args = cmd.split(' ')
            self.cp.current_command = cmd
            got = canonic_tuple(parse_break_cmd(self.cp, args))
            self.assertEqual(expect, tuple(got[:len(expect)]), cmd)
            # print(got)


        self.cp.frame = sys._getframe()
        self.cp.setup()

        # WARNING: magic number after f_lineno is fragile on the number of tests!
        # FIXME: can reduce by using .format() before test?
        break_lineno = self.cp.frame.f_lineno + 9
        for expect, cmd in (
                ( (None, osp.basename(__file__), break_lineno, None),
                    "break" ),
                ( (None, osp.basename(__file__), break_lineno, 'True'),
                    "break if True" ),
                ):
            args = cmd.split(' ')
            self.cp.current_command = cmd
            got = canonic_tuple(parse_break_cmd(self.cp, args))
            self.assertEqual(expect, got[:len(expect)])
            print(parse_break_cmd(self.cp, args))

        print(break_lineno)
        pass
        return
Exemplo n.º 2
0
    def test_basic(self):

        self.cp.frame = sys._getframe()
        self.cp.setup()
        for expect, cmd in (
                ( (None, None, None, None),
                  "break '''c:\\tmp\\foo.bat''':1" ),
                ( (None, None, None, None),
                  'break """/Users/My Documents/foo.py""":2' ),
                ( (None, osp.basename(__file__), 10, None),
                  "break 10" ),
                ( (None, None, None, None),
                   "break cmdproc.py:5" ) ,
                ( (None, None, None, None),
                   "break set_break()" ),
                ( (None, osp.basename(__file__), 4, 'i==5'),
                   "break 4 if i==5" ),
                ( (None, None, None, None),
                  "break cmdproc.setup()" ),
                ):
            args = cmd.split(' ')
            self.cp.current_command = cmd
            got = canonic_tuple(parse_break_cmd(self.cp, args))
            self.assertEqual(expect, tuple(got))
            # print(got)


        self.cp.frame = sys._getframe()
        self.cp.setup()

        # WARNING: magic number after f_lineno is fragile on the number of tests!
        # FIXME: can reduce by using .format() before test?
        break_lineno = self.cp.frame.f_lineno + 9
        for expect, cmd in (
                ( (None, osp.basename(__file__), break_lineno, None),
                    "break" ),
                ( (None, osp.basename(__file__), break_lineno, 'True'),
                    "break if True" ),
                ):
            args = cmd.split(' ')
            self.cp.current_command = cmd
            got = canonic_tuple(parse_break_cmd(self.cp, args))
            self.assertEqual(expect, got)
            print(parse_break_cmd(self.cp, args))

        print(break_lineno)
        pass
        return
Exemplo n.º 3
0
 def run(self, args):
     func, filename, lineno, condition = Mcmdbreak.parse_break_cmd(
         self.proc, args)
     if not (func == None and filename == None):
         Mcmdbreak.set_break(self, func, filename, lineno, condition, True,
                             args)
     return
Exemplo n.º 4
0
 def lineinfo(self, arg):
     (func, filename, lineno, condition,
      offset) = parse_break_cmd(self.proc, ["info args"])
     if filename != None and lineno != None:
         return lineno, filename
     else:
         return None, None
Exemplo n.º 5
0
 def run(self, args):
     force = True if args[0][-1] == '!' else False
     (func, filename, lineno,
      condition) = Mcmdbreak.parse_break_cmd(self.proc, args)
     if not (func == None and filename == None):
         Mcmdbreak.set_break(self, func, filename, lineno, condition,
                             False, args, force=force)
     return
Exemplo n.º 6
0
    def run(self, args):
        force = True if args[0][-1] == '!' else False

        (func, filename, lineno,
         condition) = Mcmdbreak.parse_break_cmd(self.proc, args)
        if not (func == None and filename == None):
            Mcmdbreak.set_break(self, func, filename, lineno, condition,
                                False, args, force=force)
        return
Exemplo n.º 7
0
 def run(self, args):
     if len(args) > 1:
         # FIXME: DRY this code. Better is to hook into tbreak.
         func, filename, lineno, condition, offset = parse_break_cmd(
             self.proc, args)
         if not set_break(self, func, filename, lineno, condition, True,
                          args):
             return False
     self.core.step_events = None  # All events
     self.core.step_ignore = -1
     self.proc.continue_running = True  # Break out of command read loop
     return True
Exemplo n.º 8
0
 def run(self, args):
     if len(args) > 1:
         # FIXME: DRY this code. Better is to hook into tbreak.
         func, filename, lineno, condition = \
           Mcmdbreak.parse_break_cmd(self, args[1:])
         if not Mcmdbreak.set_break(self, func, filename, lineno, condition,
                                    True, args):
             return False
     self.core.step_events = None  # All events
     self.core.step_ignore = -1
     self.proc.continue_running = True  # Break out of command read loop
     return True
Exemplo n.º 9
0
    def run(self, args):
        force = True if args[0][-1] == "!" else False

        (func, filename, lineno, condition,
         offset) = parse_break_cmd(self.proc, args)
        if not (func == None and filename == None):
            set_break(
                self,
                func,
                filename,
                lineno,
                condition,
                False,
                args,
                force=force,
                offset=offset,
            )
        return
Exemplo n.º 10
0
    def run(self, args):
        proc = self.proc
        if len(args) > 1:
            # FIXME: DRY this code. Better is to hook into tbreak.
            func, filename, lineno, condition = parse_break_cmd(proc, args)

            if not set_break(self, func, filename, lineno, condition, True,
                             args):
                return False
        elif args[0][-1] == "!":
            proc.vm.frame.event_flags = proc.vm.event_flags = 0  # ignore all events
        else:
            # Until we hook in breakpoints into the debugger proper, we'll
            # treat continue like step in the VM interpreter but not
            # from our filtering process
            proc.vm.frame.event_flags = PyVMEVENT_ALL
            proc.core.event_flags = (PyVMEVENT_LINE | PyVMEVENT_INSTRUCTION
                                     | PyVMEVENT_CALL | PyVMEVENT_FATAL)

        self.core.step_ignore = -1
        self.proc.continue_running = True  # Break out of command read loop
        self.return_status = "continue"  # Tell interpreter to continue running
Exemplo n.º 11
0
 def run(self, args):
     func, filename, lineno, condition = Mcmdbreak.parse_break_cmd(
         self, args[1:])
     Mcmdbreak.set_break(self, func, filename, lineno, condition, True,
                         args)
     return
Exemplo n.º 12
0
 def run(self, args):
     func, filename, lineno, condition = Mcmdbreak.parse_break_cmd(self.proc, args)
     if not (func == None and filename == None):
         Mcmdbreak.set_break(self, func, filename, lineno, condition,
                             True, args)
     return
Exemplo n.º 13
0
 def doit(cmd, a):
     cmd.current_command = ' '.join(a)
     print(Mcmdbreak.parse_break_cmd(cmd.proc, a))
Exemplo n.º 14
0
    def run(self, args):
        func, filename, lineno, condition = Mcmdbreak.parse_break_cmd(
            self, args[1:])
        Mcmdbreak.set_break(self, func, filename, lineno, condition, True,
                            args)
        return


if __name__ == '__main__':
    from trepan import debugger as Mdebugger
    d = Mdebugger.Trepan()
    command = TempBreakCommand(d.core.processor)
    command.proc.frame = sys._getframe()
    command.proc.setup()

    print(Mcmdbreak.parse_break_cmd(command, []))
    print(Mcmdbreak.parse_break_cmd(command, ['10']))
    print(Mcmdbreak.parse_break_cmd(command, [__file__ + ':10']))

    def foo():
        return 'bar'

    print(Mcmdbreak.parse_break_cmd(command, ['foo']))
    print(Mcmdbreak.parse_break_cmd(command, ['os.path']))
    print(Mcmdbreak.parse_break_cmd(command, ['os.path', '5+1']))
    print(Mcmdbreak.parse_break_cmd(command, ['os.path.join']))
    print(Mcmdbreak.parse_break_cmd(command, ['if', 'True']))
    print(Mcmdbreak.parse_break_cmd(command, ['foo', 'if', 'True']))
    print(Mcmdbreak.parse_break_cmd(command, ['os.path:10', 'if', 'True']))
    command.run(['tbreak'])
    command.run(['tbreak', 'command.run'])
Exemplo n.º 15
0
 def doit(args):
     command.proc.current_command = " ".join(args)
     print(parse_break_cmd(command.proc, args))
Exemplo n.º 16
0
 def parse_break_cmd(self, proc, cmd):
     proc.current_command = cmd
     args = cmd.split(' ')
     return Mcmdbreak.parse_break_cmd(proc, args)
Exemplo n.º 17
0
    def test_parse_break_cmd(self):
        import inspect, types
        d = debugger.Debugger()
        cp = d.core.processor
        cp.curframe = inspect.currentframe()
        self.cmd = Mbreak.BreakCommand(cp)
        self.cmd.msg = self.msg
        self.cmd.errmsg = self.errmsg

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd, [])
        self.assertEqual((None, True, True),
                         (fn, fi.endswith('test-break.py'), li > 1))

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd, ['11-1'])
        self.assertEqual((None, True, 10),
                         (fn, fi.endswith('test-break.py'), li))

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd,
                                                     [__file__ + ':10'])
        self.assertEqual((None, True, 10),
                         (fn, isinstance(fi, types.StringType), li))

        def foo():
            return 'bar'

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd, ['foo'])
        self.assertEqual((foo, True, True),
                         (fn, fi.endswith('test-break.py'), li > 1))

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd, ['food'])
        self.assertEqual((None, None, None, None), (fn, fi, li, cond))

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd, ['os.path'])
        self.assertEqual((None, True, None),
                         (fn, isinstance(fi, types.StringType), li))

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd,
                                                     ['os.path', '5+1'])
        self.assertEqual((None, True, 6),
                         (fn, isinstance(fi, types.StringType), li))

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd,
                                                     ['os.path.join'])
        self.assertEqual((os.path.join, True, True),
                         (fn, isinstance(fi, types.StringType), li > 1))

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd, ['if', 'True'])
        self.assertEqual((None, True, True),
                         (fn, fi.endswith('test-break.py'), li > 1))

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd,
                                                     ['foo', 'if', 'True'])
        self.assertEqual((foo, True, True),
                         (fn, fi.endswith('test-break.py'), li > 1))

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(
            self.cmd, ['os.path:10', 'if', 'True'])
        self.assertEqual((True, 10), (isinstance(fi, types.StringType), li))

        # FIXME:
        # Try a breakpoint with a symlink in the filename.
        # Also, add a unit test for canonic.

        return
Exemplo n.º 18
0
 def do_parse(cmd, a):
     name = "break"
     cmd.proc.current_command = name + " " + " ".join(a)
     print(a, "\n\t", parse_break_cmd(cmd.proc, [name] + a))
Exemplo n.º 19
0
    def test_parse_break_cmd(self):
        import inspect, types
        d               = debugger.Debugger()
        cp              = d.core.processor
        cp.curframe     = inspect.currentframe()
        self.cmd        = Mbreak.BreakCommand(cp)
        self.cmd.msg    = self.msg
        self.cmd.errmsg = self.errmsg

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd, [])
        self.assertEqual((None, True, True),
                         (fn, fi.endswith('test-break.py'), li > 1))

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd, ['11-1'])
        self.assertEqual((None, True, 10),
                         (fn, fi.endswith('test-break.py'), li))

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd,
                                                     [__file__ + ':10'])
        self.assertEqual((None, True, 10),
                         (fn, isinstance(fi, types.StringType), li))

        def foo():
            return 'bar'
        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd, ['foo'])
        self.assertEqual((foo, True, True),
                         (fn, fi.endswith('test-break.py'), li > 1))

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd, ['food'])
        self.assertEqual((None, None, None, None), (fn, fi, li, cond))

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd, ['os.path'])
        self.assertEqual((None, True, None),
                         (fn, isinstance(fi, types.StringType), li))

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd,
                                                     ['os.path', '5+1'])
        self.assertEqual((None, True, 6),
                         (fn, isinstance(fi, types.StringType), li))

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd,
                                                     ['os.path.join'])
        self.assertEqual((os.path.join, True, True),
                         (fn, isinstance(fi, types.StringType), li > 1))

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd, ['if', 'True'])
        self.assertEqual((None, True, True),
                         (fn, fi.endswith('test-break.py'), li > 1))

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd,
                                                  ['foo', 'if', 'True'])
        self.assertEqual((foo, True, True),
                         (fn, fi.endswith('test-break.py'), li > 1))

        fn, fi, li, cond = Mcmdbreak.parse_break_cmd(self.cmd,
                                                     ['os.path:10', 'if',
                                                      'True'])
        self.assertEqual((True, 10),
                         (isinstance(fi, types.StringType), li))

        # FIXME:
        # Try a breakpoint with a symlink in the filename.
        # Also, add a unit test for canonic.

        return
Exemplo n.º 20
0
    def run(self, args):
        func, filename, lineno, condition = Mcmdbreak.parse_break_cmd(self,
                args[1:])
        Mcmdbreak.set_break(self, func, filename, lineno, condition,
                            False, args)
        return

if __name__ == '__main__':
    import sys
    from trepan import debugger as Mdebugger
    d = Mdebugger.Debugger()
    command = BreakCommand(d.core.processor)
    command.proc.frame = sys._getframe()
    command.proc.setup()

    print(Mcmdbreak.parse_break_cmd(command, []))
    print(Mcmdbreak.parse_break_cmd(command, ['10']))
    print(Mcmdbreak.parse_break_cmd(command, [__file__ + ':10']))

    def foo():
        return 'bar'
    print(Mcmdbreak.parse_break_cmd(command, ['foo']))
    print(Mcmdbreak.parse_break_cmd(command, ['os.path']))
    print(Mcmdbreak.parse_break_cmd(command, ['os.path', '5+1']))
    print(Mcmdbreak.parse_break_cmd(command, ['os.path.join']))
    print(Mcmdbreak.parse_break_cmd(command, ['if', 'True']))
    print(Mcmdbreak.parse_break_cmd(command, ['foo', 'if', 'True']))
    print(Mcmdbreak.parse_break_cmd(command, ['os.path:10', 'if', 'True']))
    command.run(['break'])
    command.run(['break', 'command.run'])
    command.run(['break', '10'])
Exemplo n.º 21
0
 def run(self, args):
     func, filename, lineno, condition = Mcmdbreak.parse_break_cmd(self,
             args[1:])
     Mcmdbreak.set_break(self, func, filename, lineno, condition,
                         False, args)
     return