vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.76k stars 2.16k forks source link

Make V panics use addr2line on non-Linux systems #11071

Closed medvednikov closed 3 years ago

medvednikov commented 3 years ago

Right now the developer only knows the line at which the panic happened. The backtrace is not helpful:

================ V panic ================
   module: builtin
 function: slice()
  message: array.slice: invalid slice index (1 > -1)
     file: vlib/builtin/array.v:329
   v hash: 1178427
=========================================
0   vself                               0x0000000108956e8a array_slice + 410
1   vself                               0x000000010896f4c9 main__main + 473
2   vself                               0x00000001089712fa main + 42
3   vself                               0x0000000108955954 start + 52
medvednikov commented 3 years ago

In this particular example, the exact line of code in main() should be pointed out as well.

Gladear commented 3 years ago

I think using -g display the correct lines, doesn't it ?

brightly-salty commented 3 years ago

I'm not sure that fixes the issue. This particular panic was with v self, which, if I understand cmd/v/v.v correctly, automatically adds -g, and the above still does not contain line numbers.

medvednikov commented 3 years ago

@Gladear -g makes line numbers visible when debugging with valgrind/gdb etc. This is for getting line numbers in backtraces.

spytheman commented 3 years ago

@Gladear is right: -g includes V line number information, so that the panic backtrace will show them. image

spytheman commented 3 years ago

If you want to debug v itself, compile it with v -g self (or with v -g -o v cmd/v, after all V is a normal V program).

spytheman commented 3 years ago

I'm not sure that fixes the issue. This particular panic was with v self, which, if I understand cmd/v/v.v correctly, automatically adds -g, and the above still does not contain line numbers.

The code for v self is in cmd/tools/vself.v . It boils down to compiling to a temporary file v2 or v2.exe with whatever options the user has specified, then moving that temporary into v. It does not add -g by itself.

spytheman commented 3 years ago

You can try for yourself with this program:

// line 1
// line 2
// line 3
fn abc() {
    panic('some message')
}

fn main() {
    abc()
}

... which will produce this C code with -g ( shown through ./v -g -o - a.v |bat -lc ):

image

medvednikov commented 3 years ago

Right, addr2line is indeed used with -g, but only on Linux, that's why neither me nor the person who submitted this got the line numbers.

There's atos on BSDs, it should be used.