1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

docs: update debugging information

This commit is contained in:
Delyan Angelov
2021-01-13 12:50:35 +02:00
parent 219486f0a5
commit cf93be918f
3 changed files with 137 additions and 58 deletions

View File

@@ -410,7 +410,7 @@ y := x + 3.14 // x is of type `f32` - no promotion
a := 75 // a is of type `int` - default for int literal
b := 14.7 // b is of type `f64` - default for float literal
c := u + a // c is of type `int` - automatic promotion of `u`'s value
d := b + x // d is of type `f64` - automatic promotion of `x`'s value
d := b + x // d is of type `f64` - automatic promotion of `x`'s value
```
### Strings
@@ -2982,12 +2982,26 @@ To cast a `voidptr` to a V reference, use `user := &User(user_void_ptr)`.
To debug issues in the generated C code, you can pass these flags:
- `-g` - produces a less optimized executable with more debug information in it.
V will enforce line numbers from the .v files in the stacktraces, that the
executable will produce on panic. It is usually better to pass -g, unless
you are writing low level code, in which case use the next option `-cg`.
- `-cg` - produces a less optimized executable with more debug information in it.
The executable will use C source line numbers in this case. It is frequently
used in combination with `-keepc`, so that you can inspect the generated
C program in case of panic, or so that your debugger (`gdb`, `lldb` etc.)
can show you the generated C source code.
- `-showcc` - prints the C command that is used to build the program.
- `-show-c-output` - prints the output, that your C compiler produced
while compiling your program.
- `-keepc` - do not delete the generated C source code file after a successful
compilation. Also keep using the same file path, so it is more stable,
and easier to keep opened in an editor/IDE.
For the best debugging experience, you can pass all of them at the same time:
`v -cg -showcc yourprogram.v`,
then just run your debugger (gdb/lldb) or IDE on the produced executable `yourprogram`.
For best debugging experience if you are writing a low level wrapper for an existing
C library, you can pass several of these flags at the same time:
`v -keepc -cg -showcc yourprogram.v`, then just run your debugger (gdb/lldb) or IDE
on the produced executable `yourprogram`.
If you just want to inspect the generated C code,
without further compilation, you can also use the `-o` flag (e.g. `-o file.c`).
@@ -3238,7 +3252,7 @@ To improve safety and maintainability, operator overloading is limited:
- Operator functions can't modify their arguments.
- When using `<`, `>`, `>=`, `<=`, `==` and `!=` operators, the return type must be `bool`.
- Both arguments must have the same type (just like with all operators in V).
- Assignment operators (`*=`, `+=`, `/=`, etc)
- Assignment operators (`*=`, `+=`, `/=`, etc)
are auto generated when the operators are defined though they must return the same type.
## Inline assembly