Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssa: add llvm debug info #794

Merged
merged 49 commits into from
Sep 22, 2024
Merged

ssa: add llvm debug info #794

merged 49 commits into from
Sep 22, 2024

Conversation

cpunion
Copy link
Contributor

@cpunion cpunion commented Sep 13, 2024

  • Step debuging

    • Instruction debug location
    • Breakpints with function name, filename and line
  • Golang support (must use DW_LANG_C currently)

    • Parameters
    • Global variables
    • Local variables
    • Types, fields, function
  • Tools

    • Debug switch (use LLGO_DEBUG temporary)
    • LLDB go plugin, loading golang support automaticlly
image
Details

# github.com/goplus/llgo/cl/_testdata/debug
Breakpoint 1: no locations (pending).
Breakpoint set in dummy target, will get copied into future targets.
(lldb) command script import _lldb/llgo_plugin.py
(lldb) target create "./cl/_testdata/debug/out"
Current executable set to '/Users/lijie/source/goplus/llgo/cl/_testdata/debug/out' (arm64).
(lldb) r
Process 21992 launched: '/Users/lijie/source/goplus/llgo/cl/_testdata/debug/out' (arm64)
globalInt: 301
s: 0x100123e40
0x100123be0
5 8
called function with struct
1 2 3 4 5 6 7 8 9 10 +1.100000e+01 +1.200000e+01 true (+1.300000e+01+1.400000e+01i) (+1.500000e+01+1.600000e+01i) [3/3]0x1001129a0 [3/3]0x100112920 hello 0x1001149b0 0x100123ab0 0x100123d10 0x1001149e0 (0x100116810,0x1001149d0) 0x10011bf00 0x10010fa80 (0x100116840,0x100112940) 0x10001b4a4
9
1 (0x1001167e0,0x100112900)
called function with types
0x100123e40
0x1000343d0
Process 21992 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x000000010001b3b4 out`main at in.go:225:12
   222 		//   s.i8: '\x01'
   223 		//   s.i16: 2
   224 		s.i8 = 0x12
-> 225 		println(s.i8)
   226 		// Expected:
   227 		//   all variables: globalInt globalStruct globalStructPtr s i err
   228 		//   s.i8: '\x12'
(lldb) v
var i int = <variable not available>
var s github.com/goplus/llgo/cl/_testdata/debug.StructWithAllTypeFields = {
  i8 = '\x12',
  i16 = 2,
  i32 = 3,
  i64 = 4,
  i = 5,
  u8 = '\x06',
  u16 = 7,
  u32 = 8,
  u64 = 9,
  u = 10,
  f32 = 11,
  f64 = 12,
  b = true,
  c64 = {real = 13, imag = 14},
  c128 = {real = 15, imag = 16},
  slice = []int{21, 22, 23},
  arr = [3]int{24, 25, 26},
  arr2 = [3]github.com/goplus/llgo/cl/_testdata/debug.E{{i = 27}, {i = 28}, {i = 29}},
  s = "hello",
  e = {i = 30},
  pf = 0x0000000100123d10,
  pi = 0x00000001001149e0,
  intr = {type = 0x0000000100116810, data = 0x00000001001149d0},
  m = {count = 4296130304},
  c = {},
  err = {type = 0x0000000100116840, data = 0x0000000100112940},
  fn = {f = 0x000000010001b4a4, data = 0x00000001001149c0},
  pad1 = 100,
  pad2 = 200
}
var globalStructPtr *github.com/goplus/llgo/cl/_testdata/debug.StructWithAllTypeFields = <variable not available>
var globalStruct github.com/goplus/llgo/cl/_testdata/debug.StructWithAllTypeFields = {
  i8 = '\x01',
  i16 = 2,
  i32 = 3,
  i64 = 4,
  i = 5,
  u8 = '\x06',
  u16 = 7,
  u32 = 8,
  u64 = 9,
  u = 10,
  f32 = 11,
  f64 = 12,
  b = true,
  c64 = {real = 13, imag = 14},
  c128 = {real = 15, imag = 16},
  slice = []int{21, 22, 23},
  arr = [3]int{24, 25, 26},
  arr2 = [3]github.com/goplus/llgo/cl/_testdata/debug.E{{i = 27}, {i = 28}, {i = 29}},
  s = "hello",
  e = {i = 30},
  pf = 0x0000000100123d10,
  pi = 0x00000001001149e0,
  intr = {type = 0x0000000100116810, data = 0x00000001001149d0},
  m = {count = 4296130304},
  c = {},
  err = {type = 0x0000000100116840, data = 0x0000000100112940},
  fn = {f = 0x000000010001b4a4, data = 0x00000001001149c0},
  pad1 = 100,
  pad2 = 200
}
var globalInt int = 301
var err error = {type = 0x0000000100112900, data = 0x000000000000001a}

@cpunion cpunion force-pushed the llvm-debug branch 2 times, most recently from 88b6890 to d988781 Compare September 13, 2024 08:17
@cpunion cpunion marked this pull request as draft September 13, 2024 08:18
@cpunion cpunion changed the title ssa: add llvm debug info [WIP] ssa: add llvm debug info Sep 13, 2024
Copy link

codecov bot commented Sep 13, 2024

Codecov Report

Attention: Patch coverage is 97.95918% with 10 lines in your changes missing coverage. Please review.

Project coverage is 97.58%. Comparing base (4bf5dd1) to head (5dadf9a).
Report is 131 commits behind head on main.

Files with missing lines Patch % Lines
ssa/di.go 97.50% 9 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #794      +/-   ##
==========================================
+ Coverage   97.54%   97.58%   +0.03%     
==========================================
  Files          19       20       +1     
  Lines        4683     5169     +486     
==========================================
+ Hits         4568     5044     +476     
- Misses         97      106       +9     
- Partials       18       19       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cpunion cpunion force-pushed the llvm-debug branch 17 times, most recently from 8954c1b to 5f2a0fb Compare September 18, 2024 12:43
di diBuilder
cu CompilationUnit

glbDbgVars map[Expr]bool
Copy link
Member

@xushiwei xushiwei Sep 21, 2024

Choose a reason for hiding this comment

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

move debug related fields together

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

RunArgs []string // only valid for ModeRun
Mode Mode
GenExpect bool // only valid for ModeCmpTest
BuildOptions BuildOptions
Copy link
Member

Choose a reason for hiding this comment

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

move this field before GenExpect for byte alignment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed BuildOptions

@cpunion cpunion force-pushed the llvm-debug branch 5 times, most recently from 530f75c to 163afd0 Compare September 22, 2024 01:44
@xushiwei xushiwei merged commit 9e88484 into goplus:main Sep 22, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants