Skip to content

Commit 5181795

Browse files
authored
Merge pull request #1468 from petrochenkov/debmac
Add docs for `#[collapse_debuginfo]` attribute
2 parents 5854fcc + 2d51a2a commit 5181795

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/attributes.md

+2
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ The following is an index of all built-in attributes.
275275
added in future.
276276
- Debugger
277277
- [`debugger_visualizer`] — Embeds a file that specifies debugger output for a type.
278+
- [`collapse_debuginfo`] — Controls how macro invocations are encoded in debuginfo.
278279

279280
[Doc comments]: comments.md#doc-comments
280281
[ECMA-334]: https://www.ecma-international.org/publications-and-standards/standards/ecma-334/
@@ -293,6 +294,7 @@ The following is an index of all built-in attributes.
293294
[`cfg_attr`]: conditional-compilation.md#the-cfg_attr-attribute
294295
[`cfg`]: conditional-compilation.md#the-cfg-attribute
295296
[`cold`]: attributes/codegen.md#the-cold-attribute
297+
[`collapse_debuginfo`]: attributes/debugger.md#the-collapse_debuginfo-attribute
296298
[`crate_name`]: crates-and-source-files.md#the-crate_name-attribute
297299
[`crate_type`]: linkage.md
298300
[`debugger_visualizer`]: attributes/debugger.md#the-debugger_visualizer-attribute

src/attributes/debugger.md

+29
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,32 @@ When the crate's debug executable is passed into GDB[^rust-gdb], `print bob` wil
139139
[Natvis documentation]: https://docs.microsoft.com/en-us/visualstudio/debugger/create-custom-views-of-native-objects
140140
[pretty printing documentation]: https://sourceware.org/gdb/onlinedocs/gdb/Pretty-Printing.html
141141
[_MetaListNameValueStr_]: ../attributes.md#meta-item-attribute-syntax
142+
143+
## The `collapse_debuginfo` attribute
144+
145+
The *`collapse_debuginfo` [attribute]* controls whether code locations from a macro definition are collapsed into a single location associated with the macro's call site,
146+
when generating debuginfo for code calling this macro.
147+
148+
The attribute uses the [_MetaListIdents_] syntax to specify its inputs, and can only be applied to macro definitions.
149+
150+
Accepted options:
151+
- `#[collapse_debuginfo(yes)]` — code locations in debuginfo are collapsed.
152+
- `#[collapse_debuginfo(no)]` — code locations in debuginfo are not collapsed.
153+
- `#[collapse_debuginfo(external)]` — code locations in debuginfo are collapsed only if the macro comes from a different crate.
154+
155+
The `external` behavior is the default for macros that don't have this attribute, unless they are built-in macros.
156+
For built-in macros the default is `yes`.
157+
158+
> **Note**: `rustc` has a `-C collapse-macro-debuginfo` CLI option to override both the default collapsing behavior and `#[collapse_debuginfo]` attributes.
159+
160+
```rust
161+
#[collapse_debuginfo(yes)]
162+
macro_rules! example {
163+
() => {
164+
println!("hello!");
165+
};
166+
}
167+
```
168+
169+
[attribute]: ../attributes.md
170+
[_MetaListIdents_]: ../attributes.md#meta-item-attribute-syntax

0 commit comments

Comments
 (0)