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

Include column info in debuginfo #42921

Closed
est31 opened this issue Jun 27, 2017 · 5 comments
Closed

Include column info in debuginfo #42921

est31 opened this issue Jun 27, 2017 · 5 comments
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@est31
Copy link
Member

est31 commented Jun 27, 2017

I think that we should include column info in debuginfo, so that backtraces become more informative.

Often you do multiple function calls on a line, like ctr = ctr.inc().inc(); or let foo = wrap((), wrap((),())).

If one of these function calls generates a panic or something else that causes a backtrace, you can't know immediately which of the function calls actually caused the issue.

Apparently, right now we are setting the column number to zero: ae66285

The reason seems to be that GCC/Clang don't emit column numbers either and apparently GDB had issues with it. See #9641 and #10966. However, the change was from 2013, and maybe GDB support has changed since. Also, maybe if we ask kindly, GDB could consider adding support. AFAIK we already ship our copy of GDB so we might not even have to wait for a release to enable this per default.

Note that this is separate from panic locations, which doesn't use the LLVM debug info system but uses our own system instead. I'm preparing a PR to add line number info for panic's (without the RUST_BACKTRACE input) and want to file it soon. EDIT: #42938

cc @eddyb @michaelwoerister

@sfackler
Copy link
Member

We don't ship a GDB - just a wrapper that loads some python scripts into the system GDB.

@steveklabnik steveklabnik added A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 27, 2017
bors added a commit that referenced this issue Jul 2, 2017
Output column number info when panicking

Outputs the column number when panicking. Useful when you e.g. have code like `foo[i] = bar[k] + bar[l]` and you get a panic with index out of bounds, or when you have an expression like `a = b + c + d + e` and the addition overflows. Now you know which operation to blame!

The format is `file:line:column`, just like for compiler errors. Example output with the patch:

```
thread 'main' panicked at 'index out of bounds: the len is 5 but the index is 8', src/main.rs:3:8
```

As some of the API between the compiler and the library landscape gets broken, this is a bit hackier than I'd originally wanted it to be.

* `panic` and `panic_bounds_check` lang items got an additional column param, on stage0 I still have to use the previous version. After a SNAP this should be resolved.
* For `#[derive(RustcDeserialze)]`, stage0 requires a fixed signature for `std::rt::begin_panic`, so we can't change it right away. What we need to do instead is to keep the signature, and add a `begin_panic_new` function that we use in later stages instead. After a SNAP we can change the `begin_panic` function and rely on it instead of `begin_panic_new`, and one SNAP later we can remove `begin_panic_new`.
* Fortunately I didn't have to break anything about the panic hook API, I could easily extend it.

Note that debuginfo remains unchanged, so RUST_BACKTRACE output won't contain any column info. See issue #42921 for discussion on including the column in debuginfo.
@michaelwoerister
Copy link
Member

Does clang emit column information these days? If so, it should be fine to turn it on in rustc too.

@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 28, 2017
@tromey
Copy link
Contributor

tromey commented Aug 2, 2017

I don't think gdb should have any particular problem with columns -- it currently just ignores them.

@est31
Copy link
Member Author

est31 commented Sep 20, 2017

I've dug a little and it seems that Visual Studio expects column info to be in ranges, and otherwise is buggy... That's why it was apparently disabled for clang+msvc: https://reviews.llvm.org/rL279765 . LLVM seems to have no way of sending column ranges, so we can't improve on clang here unless we want to patch LLVM.

However, for other targets it should work... at least worth a try.

@est31
Copy link
Member Author

est31 commented Jul 2, 2018

Sooo I've had another look and it seems that clang outputs col info by default while gcc does not, at least for the x86_64-unknown-linux-gnu target family.

Test setup

a.c source code:

#include<stdio.h>

int main() {
	printf("Hello World0\n"); printf("Hello World1\n"); printf("Hello World2\n");
	printf("Hello World3\n");
	return 0;
}

Both compiled with $CC -g a.c. Then I did cargo run --example dwarfdump -- -l /path/to/a.out with the gimli dwarfdumper.

I got this for gcc:

Line Number Rows:
<pc>        [lno,col]
0x0000063a  [   3, 0] NS uri: "/path/to/a.c"
0x0000063e  [   4, 0] NS
0x00000662  [   5, 0] NS
0x0000066e  [   6, 0] NS
0x00000673  [   7, 0] NS
0x00000675  [   7, 0] NS ET

I got this for clang:

Line Number Rows:
<pc>        [lno,col]
0x004004d0  [   3, 0] NS uri: "/path/to/a.c"
0x004004e9  [   4, 2] NS PE
0x004004fa  [   4,28]
0x0040050e  [   4,54]
0x00400522  [   5, 2] NS
0x0040052e  [   6, 2] NS
0x00400539  [   6, 2] NS ET

pietroalbini added a commit to pietroalbini/rust that referenced this issue Jul 3, 2018
Emit column info in debuginfo for non msvc like targets

Fixes rust-lang#42921 everywhere except MSVC. This mimics clang behaviour.
pietroalbini added a commit to pietroalbini/rust that referenced this issue Jul 3, 2018
Emit column info in debuginfo for non msvc like targets

Fixes rust-lang#42921 everywhere except MSVC. This mimics clang behaviour.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants