Closed Bug 1360497 Opened 7 years ago Closed 7 years ago

Add -Zdebug-macros to RUSTFLAGS

Categories

(Firefox Build System :: General, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: hsivonen, Unassigned)

References

Details

Attachments

(1 file)

By default, rustc annotates lines expanded from a macro with the location of the macro invocation rather than the location of the line in the macro definition. In case of e.g. encoding_rs, this results in pretty useless panic stacks.

To make panic stacks useful on try and in the crash reporter, we should add -Zdebug-macros to RUSTFLAGS to override the default behavior and to get stacks with usefully actionable location info.

Additionally, accoding to https://github.com/rust-lang/rust/issues/39153#issuecomment-297685269 , it seems that this would be useful for correct profiling attribution, too.
Hmm. The patch doesn't appear to have the expected effect:
https://treeherder.mozilla.org/logviewer.html#?job_id=95143210&repo=try&lineNumber=2243
(No lines from macros.rs involved.)
(In reply to Henri Sivonen (:hsivonen) from comment #2)
> Hmm. The patch doesn't appear to have the expected effect:

Because I misread the "if" nesting in a hurry. Sigh.
Not what I hoped for in this case, but at least the flag seems to take effect with the current patch:
https://treeherder.mozilla.org/logviewer.html#?job_id=95476817&repo=try&lineNumber=4658
Attachment #8862777 - Flags: review?(ted)
It sounds like we have to make a choice between two suboptimal situations:
a) The current situation, where panic stacks/profiling are not very useful for code involving macros.
b) -Zdebug-macros, where anyone debugging Rust code will wind up stepping through macros from the standard library.
Comment on attachment 8862777 [details]
Bug 1360497 - Use line numbers from macro definition rather than macro invocation for code expanded from macros.

I'm going to let froynj make the call here.
Attachment #8862777 - Flags: review?(ted) → review?(nfroyd)
(In reply to Ted Mielczarek [:ted.mielczarek] from comment #7)
> b) -Zdebug-macros, where anyone debugging Rust code will wind up stepping
> through macros from the standard library.

Do we have a lot of code in Firefox where this is a problem? Does gdb's "skip file" not correctly skip over lines from a standard-library macro expansion if you tell it to skip over the file that defines the macro?
(In reply to Henri Sivonen (:hsivonen) from comment #9)
> (In reply to Ted Mielczarek [:ted.mielczarek] from comment #7)
> > b) -Zdebug-macros, where anyone debugging Rust code will wind up stepping
> > through macros from the standard library.
> 
> Do we have a lot of code in Firefox where this is a problem? Does gdb's
> "skip file" not correctly skip over lines from a standard-library macro
> expansion if you tell it to skip over the file that defines the macro?

FWIW, I think losing the line of assert macro invocation is a more significant adverse outcome of the proposed change than the impact on stepping over write!() and such when debugging.

Ideally, we'd get the macro invocation line for assert macros and the macro definition line for other macros and would use gdb skipping filters to decide at debug time what to skip when stepping.
Comment on attachment 8862777 [details]
Bug 1360497 - Use line numbers from macro definition rather than macro invocation for code expanded from macros.

https://reviewboard.mozilla.org/r/134660/#review145150

Sorry for taking so long to respond to this.

There is just no good solution here, and I'm not comfortable enabling something that we'll have to throw away shortly before we upgrade Rust, as it sounds like they're disabling `-Z` options in stable.  So we'd have to start with changing the command-line flags to provide a stable interface, and then add the appropriate flags (probably only enabled for `--enable-release` builds).  Permitting people to pass in their own `RUSTFLAGS` would be a reasonable change on its own, though, and then people who wanted `-Z debug-macros` or what have you could get the behavior they like locally.
Attachment #8862777 - Flags: review?(nfroyd) → review-
Marking WONTFIX per comment 11.

I started a discussion about a better alternative on the Rust Internals forum but the discussion didn't get much interest:
https://internals.rust-lang.org/t/stack-trace-friendly-debug-info-for-macros/5370
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → WONTFIX
See Also: → 1373070
Product: Core → Firefox Build System
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: