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

"Debugging the compiler" #11

Closed
13 tasks done
nikomatsakis opened this issue Jan 18, 2018 · 8 comments · Fixed by #272
Closed
13 tasks done

"Debugging the compiler" #11

nikomatsakis opened this issue Jan 18, 2018 · 8 comments · Fixed by #272
Labels
E-easy Difficulty: might be a good place for a beginner

Comments

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Jan 18, 2018

This section should talk about the various tips and tricks for debugging the compiler, as well as perhaps some amount of "debug log conventions". It doesn't necessarily have to be a super long section, but here are some of the things I can think of:

  • How to use RUST_LOG and config.toml first and foremost (overlaps with "How to build the compiler and run what you built" #8)
  • Some of the handy -Zflags:
    • example: -Ztreat-err-as-bug, which causes errors to be reported as bugs. Useful when you are debugging an error that should not be happening because you can use RUST_BACKTRACE=1 then to get a backtrace of where the error was reported; also avoids dumping out more logs than you need.
    • example: -Zunpretty=hir-tree, which will dump out the HIR
    • example: -Zverbose, which dumps out extra
    • see -Zhelp for more
  • Conventions for logs ("loosely followed")
    • Use {:?} most of the time in debug logs
    • I tend to use debug!("foo(...)") at the start of a function foo and debug!("foo: ...") or logs within that function (- nikomatsakis)
  • Options to try and correlate node-ids and def-ids with the source
    • e.g., --pretty expanded,identified
  • Options to dump the MIR
    • -Zdump-mir and -Zdump-mir-graphviz
@mark-i-m mark-i-m added the E-help-wanted Call for participation: extra help is wanted label Jan 31, 2018
@mark-i-m
Copy link
Member

mark-i-m commented Mar 8, 2018

cc #78

@mark-i-m mark-i-m added the E-medium Difficulty: might require some prior knowledge or code reading label Mar 16, 2018
@nikomatsakis
Copy link
Contributor Author

I just noticed that there is a page on forge on this topic:

https://forge.rust-lang.org/debugging.html

So, as a start, moving that content into the rustc-guide and removing the page from forge would be easy enough!

@mark-i-m mark-i-m added the E-easy Difficulty: might be a good place for a beginner label Apr 5, 2018
@cg-cnu
Copy link
Contributor

cg-cnu commented Apr 6, 2018

Hey @nikomatsakis A rust beginner here and first time contributor to rust project. Might need some help in making the PR, but definitely interested in putting the time and working on it. Can I work on it 🙂

@mark-i-m mark-i-m removed the E-help-wanted Call for participation: extra help is wanted label Apr 6, 2018
@mark-i-m
Copy link
Member

mark-i-m commented Apr 6, 2018

@cg-cnu Definitely! Thanks! Let us know if you need help :)

@mark-i-m mark-i-m added E-help-wanted Call for participation: extra help is wanted and removed E-medium Difficulty: might require some prior knowledge or code reading E-help-wanted Call for participation: extra help is wanted labels Jan 23, 2019
@gnzlbg
Copy link
Contributor

gnzlbg commented Feb 12, 2019

I just tried to debug the compiler using debug!. There is such a huge amount of noise that's pretty much useless. Tons of lines of:

DEBUG 2019-02-12T02:35:41Z: syntax::source_map: byte pos BytePos(0) is on the line at byte pos BytePos(0)
DEBUG 2019-02-12T02:35:41Z: syntax::source_map: char pos CharPos(0) is on the line at char pos CharPos(0)
DEBUG 2019-02-12T02:35:41Z: syntax::source_map: byte is on line: 1
DEBUG 2019-02-12T02:35:41Z: syntax::source_map: byte pos BytePos(0) is on the line at byte pos BytePos(0)
DEBUG 2019-02-12T02:35:41Z: syntax::source_map: char pos CharPos(0) is on the line at char pos CharPos(0)
DEBUG 2019-02-12T02:35:41Z: syntax::source_map: byte is on line: 1

I wish there was an easy way to just use eprintln! or something without noise. Or do I have to go through the compiler and remove all debug! statements to be able to see the output of mine ?

@Mark-Simulacrum
Copy link
Member

Generally the intent is to be more specific than just RUST_LOG=syntax=debug; where you trying to debug something in syntax::source_map specifically? Otherwise I would expect you to not include it in the logging at all...

@gnzlbg
Copy link
Contributor

gnzlbg commented Feb 12, 2019

Generally the intent is to be more specific than just RUST_LOG=syntax=debug; where you trying to debug something in syntax::source_map specifically? No, it was late and I forgot that you could RUST_LOG=modulename too. Maybe it would be worth calling that out specifically in the guide.

@eddyb
Copy link
Member

eddyb commented Feb 13, 2019

We should really tell people to use RUST_LOG=rustc_foo::bar::baz, with the smallest module(s) (comma-separated if multiple) necessary for the debug!s they want.

IIRC RUST_LOG=syntax=debug and RUST_LOG=syntax does the same thing, but I could be wrong. Either way, the logging level should not be the important bit, but rather the relevant module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Difficulty: might be a good place for a beginner
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants