Skip to content

Add debug infomation support based on datamodel. - #7177

Merged
sklam merged 32 commits into
numba:masterfrom
stuartarchibald:wip/dwarf_datamodel_1
Oct 27, 2021
Merged

sklam merged 32 commits into
numba:masterfrom
stuartarchibald:wip/dwarf_datamodel_1

Conversation

@stuartarchibald

Copy link
Copy Markdown
Contributor

This:

  1. Adds debug info for types that are based on DataModel by emitting information to make them appear as structures.
  2. Fixes another bug in lineinfo emission where decref calls at the end of basic blocks were having line information associated with them from the variable declaration site.

Impact of 1. (and 2.!, to sort the lineinfo out) is demonstrated in the following:

$ cat debuginfo_structures.py
from numba import njit
import numpy as np

@njit(debug=True)
def foo():
    x = np.arange(21, dtype=np.float32).reshape((7, 3))
    y = (1, 2, 'x', 4)
    z = "some string" + str(10) + "some other string"
    return x, y, z

foo()

then running the above under gdb:

$ NUMBA_OPT=0 gdb -q  -ex 'b "_ZN8__main__7foo$241E"' -ex 'r' --args python debuginfo_structures.py 
<snip>

Breakpoint 1, __main__::foo$241 () at debuginfo_structures.py:4
4       @njit(debug=True)

(gdb) n
6           x = np.arange(21, dtype=np.float32).reshape((7, 3))
(gdb) n
7           y = (1, 2, 'x', 4)
(gdb) n
8           z = "some string" + str(10) + "some other string"
(gdb) n
9           return x, y, z

(gdb) info locals
x = {meminfo = 0x555556c4a150 "\001", parent = 0x0, nitems = 21, itemsize = 4, data = 0x555556c4a180, shape = {7, 3}, 
  strides = {12, 4}}
y = {f0 = 1, f1 = 2, f2 = 0x0, f3 = 4}
z = {data = 0x555556c4a540 "some string10some other string", length = 30, kind = 1, is_ascii = 1, hash = 18446744073709551615, 
  meminfo = 0x555556c4a510 "\001", parent = 0x0}

(gdb) whatis x
type = array(float32, 2d, C) ({i8*, i8*, i64, i64, float*, [2 x i64], [2 x i64]})

(gdb) whatis y
type = Tuple(Literal[int](1), Literal[int](2), Literal[str](x), Literal[int](4)) ({i64, i64, i8*, i64})

(gdb) whatis z
type = unicode_type ({i8*, i64, i32, i32, i64, i8*, i8*})

(gdb) x.nitems
$1 = 21

(gdb) x/21f x.data # we know there's 21 items in x and x is float32 from whatis above
0x555556c4a180: 0       1       2       3
0x555556c4a190: 4       5       6       7
0x555556c4a1a0: 8       9       10      11
0x555556c4a1b0: 12      13      14      15
0x555556c4a1c0: 16      17      18      19
0x555556c4a1d0: 20
(gdb) c

Continuing.
[Inferior 1 (process 4124) exited normally]
(gdb) q

Note that:

  1. Calling whatis on the variables will yield their Numba typing domain type repr and also their datamodel layout in LLVM IR.
  2. That the structures are behaving like C structs and the members can be inspected.

@stuartarchibald stuartarchibald added this to the Numba 0.55 RC milestone Sep 15, 2021
This:
* Adds a new env var ``NUMBA_EXTEND_VARIABLE_LIFETIMES`` which when
  set extends the lifetime of variables to the end of the block in
  which their lifetime ends.
* Fixes up the Dels and their location information in the case of
  the above being set.
* Wires the above into the post processor call in the legalizer. The
  legalizer is the only place which should change the variable life
  times as it is the last thing that is executed in the pipeline
  before lowering. Changing the lifetimes in general will break
  optimisation passes that rely on lifetime analysis via Del nodes.

Fixes numba#7420
As title.
This adds testing of the DWARF emission with gdb. It uses the gdb
machine interface wrapped in pexpect to assert interaction
behaviours. Some minor refactoring of the original gdb support is
made to keep the gdb helper functions all in one place (the new
gdb_support.py).
@stuartarchibald

Copy link
Copy Markdown
Contributor Author

8a7a77b failed on windows 64 py 37 np 117, doesn't seem related but capturing the output:

Starting: Test slice of test files
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.182.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
========================== Starting Command Output ===========================
"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\d7d104a6-8d26-4603-820b-57bcb9ecb958.cmd""
...................................................................s..........s.............s....s...................................................s..................................................sss..ss...............s.......................................................................s.......................................................................................................................................................................................sssssss.ssss........F.FF
skipped CUDA tests
skipped CUDA tests
Parallel: 469. Serial: 33
======================================================================
FAIL: test_float32_numpy2_fastmath_usecase (numba.tests.test_svml.TestSVMLGeneration)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\a\1\s\numba\tests\test_svml.py", line 245, in test_runner
    self.assertEqual(p.exitcode, 0, msg="process ended unexpectedly")
AssertionError: None != 0 : process ended unexpectedly

======================================================================
FAIL: test_float64_range4_fastmath_usecase (numba.tests.test_svml.TestSVMLGeneration)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\a\1\s\numba\tests\test_svml.py", line 245, in test_runner
    self.assertEqual(p.exitcode, 0, msg="process ended unexpectedly")
AssertionError: None != 0 : process ended unexpectedly

======================================================================
FAIL: test_int32_prange4_usecase (numba.tests.test_svml.TestSVMLGeneration)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\a\1\s\numba\tests\test_svml.py", line 245, in test_runner
    self.assertEqual(p.exitcode, 0, msg="process ended unexpectedly")
AssertionError: None != 0 : process ended unexpectedly

----------------------------------------------------------------------
Ran 502 tests in 840.808s

FAILED (failures=3, skipped=23)
##[error]Cmd.exe exited with code '1'.
Finishing: Test slice of test files

@stuartarchibald

Copy link
Copy Markdown
Contributor Author

@sklam have merged in mainline so as to test with the changes to name mangling.

@sklam

sklam commented Oct 25, 2021

Copy link
Copy Markdown
Member

https://github.com/sklam/numba/tree/wip/dwarf_like_c fixes the GDB breakpoint stopping at function def line (def foo():) instead of the first line of the function body.

@stuartarchibald

Copy link
Copy Markdown
Contributor Author

https://github.com/sklam/numba/tree/wip/dwarf_like_c fixes the GDB breakpoint stopping at function def line (def foo():) instead of the first line of the function body.

Thanks @sklam, well found! I've a couple of other fixes along with this to make the code gen match more what would be generated from C too. Think I'll combine with those and hopefully this issue will be resolved.

@sklam sklam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good. The improved GDB support will be a great help for users and developers to understand the emitted code.

@sklam

sklam commented Oct 26, 2021

Copy link
Copy Markdown
Member

I think we just need to verify that we didn't break cuda-gdb

@sklam sklam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cuda NvvmDIBuilder has became out-of-sync with the usage

@gmarkall

Copy link
Copy Markdown
Member

cuda NvvmDIBuilder has became out-of-sync with the usage

I think we should get rid of it - NVVM uses the normal DIBuilder for NVVM 7. I seem to recall we don't support debug with NVVM 3.4 anymore, but will check if that was something in an unmerged PR.

@sklam

sklam commented Oct 26, 2021

Copy link
Copy Markdown
Member

CC @stuartarchibald @gmarkall

d8ef5b1 fixes the debuginfo emission for the CUDA target.

@sklam sklam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From OOB discussion, we will address the CUDA issues separately in #7514.

@sklam

sklam commented Oct 27, 2021

Copy link
Copy Markdown
Member

Checking buildfarm: numba_smoketest_cpu_yaml_58

@sklam sklam added Pending BuildFarm For PRs that have been reviewed but pending a push through our buildfarm BuildFarm Passed For PRs that have been through the buildfarm and passed 5 - Ready to merge Review and testing done, is ready to merge and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author Pending BuildFarm For PRs that have been reviewed but pending a push through our buildfarm labels Oct 27, 2021
@sklam

sklam commented Oct 27, 2021

Copy link
Copy Markdown
Member

Buildfarm passed. Manually confirmed execution of GDB test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 - Ready to merge Review and testing done, is ready to merge BuildFarm Passed For PRs that have been through the buildfarm and passed Effort - long Long size effort needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants