Пример #1
0
 def _gdb_has_numpy(self):
     """Returns True if gdb has NumPy support, False otherwise"""
     driver = GdbMIDriver(
         __file__,
         debug=False,
     )
     has_numpy = driver.supports_numpy()
     driver.quit()
     return has_numpy
Пример #2
0
    def test(self):
        rdt_a = np.dtype([("x", np.int16), ("y", np.float64)], align=True)

        @njit(debug=True)
        def foo():
            a = 1.234
            b = (1, 2, 3)
            c = ('a', b, 4)
            d = np.arange(5.)
            e = np.array([[1, 3j], [2, 4j]])
            f = "Some string" + "           L-Padded string".lstrip()
            g = 11 + 22j
            h = np.arange(24).reshape((4, 6))[::2, ::3]
            i = np.zeros(2, dtype=rdt_a)
            return a, b, c, d, e, f, g, h, i

        foo()

        extension = collect_gdbinfo().extension_loc
        driver = GdbMIDriver(__file__,
                             init_cmds=['-x', extension],
                             debug=False)
        driver.set_breakpoint(line=29)
        driver.run()
        driver.check_hit_breakpoint(1)

        # Ideally the function would be run to get the string repr of locals
        # but not everything appears in DWARF e.g. string literals. Further,
        # str on NumPy arrays seems to vary a bit in output. Therefore a custom
        # match is used.

        driver.stack_list_variables(1)
        output = driver._captured.after.decode('UTF-8')
        done_str = output.splitlines()[0]
        pat = r'^\^done,variables=\[\{(.*)\}\]$'
        lcls_strs = re.match(pat, done_str).groups()[0].split('},{')
        lcls = {
            k: v
            for k, v in [
                re.match(r'name="(.*)",value="(.*)"', x).groups()
                for x in lcls_strs
            ]
        }
        expected = dict()
        expected['a'] = r'1\.234'
        expected['b'] = r'\(1, 2, 3\)'
        expected['c'] = r'\(0x0, \(1, 2, 3\), 4\)'
        expected['d'] = r'\\n\[0. 1. 2. 3. 4.\]'
        expected['e'] = r'\\n\[\[1.\+0.j 0.\+3.j\]\\n \[2.\+0.j 0.\+4.j\]\]'
        expected['f'] = "'Some stringL-Padded string'"
        expected['g'] = r"11\+22j"
        expected['h'] = r'\\n\[\[ 0  3\]\\n \[12 15\]\]'
        expected['i'] = r'\\n\[\(0, 0.\) \(0, 0.\)\]'

        for k, v in expected.items():
            self.assertRegex(lcls[k], v)

        driver.quit()
 def test(self):
     call_foo()
     driver = GdbMIDriver(__file__)
     # A specific foo, the first one, it has uid=2
     vsym = "__main__::foo_factory::_3clocals_3e::foo[abi:v2]"
     driver.set_breakpoint(symbol=vsym)
     driver.run()
     driver.check_hit_breakpoint(number=1)
     driver.assert_regex_output(r'^.*foo\[abi:v2\].*line="11"')
     driver.stack_list_arguments(2)
     expect = ('[frame={level="0",args=[{name="x",type="Literal[int](10)",'
               'value="10"}]}]')
     driver.assert_output(expect)
     # Now break on any foo
     driver.set_breakpoint(symbol="foo")
     driver.cont()
     driver.check_hit_breakpoint(number=2)
     driver.assert_regex_output(r'^.*foo\[abi:v3\].*line="11"')
     driver.stack_list_arguments(2)
     expect = ('[frame={level="0",args=[{name="x",type="Literal[int](20)",'
               'value="20"}]}]')
     driver.assert_output(expect)
     # and again, hit the third foo
     driver.cont()
     driver.check_hit_breakpoint(number=2)
     driver.assert_regex_output(r'^.*foo\[abi:v4\].*line="11"')
     driver.stack_list_arguments(2)
     expect = ('[frame={level="0",args=[{name="x",type="Literal[int](30)",'
               'value="30"}]}]')
     driver.assert_output(expect)
     driver.quit()
Пример #4
0
    def test(self):
        @njit(debug=True)
        def foo(x):
            z = np.ones_like(x)  # break here
            return x, z

        tmp = np.ones(5)
        foo(tmp)

        driver = GdbMIDriver(__file__)
        driver.set_breakpoint(line=15)
        driver.run()
        driver.check_hit_breakpoint(1)
        driver.stack_list_arguments(2)
        llvm_intp = f"i{types.intp.bitwidth}"
        expect = (
            '[frame={level="0",args=[{name="x",type="array(float64, 1d, C) '
            f'({{i8*, i8*, {llvm_intp}, {llvm_intp}, double*, '
            f'[1 x {llvm_intp}], [1 x {llvm_intp}]}})"}}]}}]')
        driver.assert_output(expect)
        driver.stack_list_variables(1)
        # 'z' should be zero-init
        expect = ('{name="z",value="{meminfo = 0x0, parent = 0x0, nitems = 0, '
                  'itemsize = 0, data = 0x0, shape = {0}, strides = {0}}"}')
        driver.assert_output(expect)
        driver.set_breakpoint(line=16)
        driver.cont()
        driver.check_hit_breakpoint(2)
        driver.stack_list_variables(1)
        # 'z' should be populated
        expect = (r'^.*\{name="z",value="\{meminfo = 0x[0-9a-f]+ .*, '
                  r'parent = 0x0, nitems = 5, itemsize = 8, '
                  r'data = 0x[0-9a-f]+, shape = \{5\}, strides = \{8\}\}.*$')
        driver.assert_regex_output(expect)
        driver.quit()
Пример #5
0
 def test(self):
     foo(120)
     sz = types.intp.bitwidth
     driver = GdbMIDriver(__file__)
     driver.set_breakpoint(symbol="__main__::foo")
     driver.run()  # will hit cpython symbol match
     driver.check_hit_breakpoint(number=1)
     driver.cont()  # will hit njit symbol match
     driver.check_hit_breakpoint(number=1, line=10)  # Ensure line number
     driver.stack_list_arguments(2)
     expect = ('[frame={level="0",args=[{name="x",type="int%s",'
               'value="120"}]}]' % sz)
     driver.assert_output(expect)
     driver.quit()
Пример #6
0
    def test(self):
        @njit(debug=True)
        def foo(x):
            z = 7 + x  # break here
            return x, z

        foo(120)

        sz = types.intp.bitwidth
        driver = GdbMIDriver(__file__)
        driver.set_breakpoint(line=14)
        driver.run()
        driver.check_hit_breakpoint(1)
        driver.stack_list_arguments(2)
        expect = ('[frame={level="0",args=[{name="x",type="int%s",'
                  'value="120"}]}]' % sz)
        driver.assert_output(expect)
        driver.stack_list_variables(1)
        expect = '[{name="x",arg="1",value="120"},{name="z",value="0"}]'
        driver.assert_output(expect)
        driver.next()
        driver.stack_list_variables(1)
        expect = '[{name="x",arg="1",value="120"},{name="z",value="127"}]'
        driver.assert_output(expect)
        driver.quit()