@@ -221,7 +221,7 @@ As an example, consider a crate `foo` with this directory structure:
221
221
Where ` main.rs ` contains:
222
222
223
223
``` rust
224
- #[debugger_visualizer(natvis_file = " ../Foo.natvis" )]
224
+ #! [debugger_visualizer(natvis_file = " ../Foo.natvis" )]
225
225
226
226
/// A rectangle in first quadrant
227
227
struct FancyRect {
@@ -286,13 +286,14 @@ Rust developers can add one or more pretty printers to their crate. This is done
286
286
in the Rust compiler via ` .py ` python scripts. Through the use of a new Rust attribute,
287
287
` #[debugger_visualizer] ` , the compiler will encode the contents of the ` .py ` file in
288
288
the crate metadata if the target is an ` rlib ` . If the target is an executable, the
289
- ` .debug_gdb_scripts ` section will include a reference to the pretty printer specified.
289
+ ` .debug_gdb_scripts ` section will include a reference to the pretty printer specified
290
+ by embedding the contents of the pretty printer directly into this section.
290
291
291
292
To provide pretty printers, developers create a file with the ` .py ` file
292
293
extension and reference it via the ` #[debugger_visualizer] ` attribute as follows:
293
294
294
295
``` rust
295
- #[debugger_visualizer(gdb_script_file = " ../foo.py" )]
296
+ #! [debugger_visualizer(gdb_script_file = " ../foo.py" )]
296
297
```
297
298
298
299
# Reference-level explanation
@@ -301,7 +302,33 @@ extension and reference it via the `#[debugger_visualizer]` attribute as follows
301
302
In rustc, a new built-in attribute ` #[debugger_visualizer] ` will be added which
302
303
instructs the compiler to take the specified file path for a debugger visualizer
303
304
and add it to the current binary being built. The file path specified must be
304
- relative to the location of the attribute.
305
+ relative to the location of the attribute and is resolved in a manner that is
306
+ identical to how paths are resolved in the ` include_str! ` macro. This attribute
307
+ will directly target modules which means the syntax ` #![debugger_visualizer] ` is
308
+ also valid when placed at the module level.
309
+
310
+ For example, the following uses of the attribute are valid:
311
+
312
+ Where ` main.rs ` contains:
313
+
314
+ ``` rust
315
+ #![debugger_visualizer(natvis_file = " ../main.natvis" )]
316
+
317
+ #[debugger_visualizer(natvis_file = " ../foo.natvis" )]
318
+ mod foo ;
319
+ ```
320
+
321
+ and ` bar.rs ` contains:
322
+
323
+ ``` rust
324
+ #![debugger_visualizer(natvis_file = " ../bar.natvis" )]
325
+ ```
326
+
327
+ In the first case, the attribute is applied to the crate as a top-level attribute
328
+ using the inner attribute syntax and also added to the module foo using the outer
329
+ attribute syntax. In the second case, the attribute is applied to the module bar
330
+ via a top-level attribute as well which also is valid since it is still targeting
331
+ a module.
305
332
306
333
The ` #[debugger_visualizer] ` attribute will reserve multiple keys to be able to
307
334
specify which type of visualizer is being applied. The following keys will be
@@ -317,17 +344,17 @@ For example, to specify that a `.natvis` file should be included in the binary
317
344
being built, the following attribute should be added to the Rust source:
318
345
319
346
``` rust
320
- #[debugger_visualizer(natvis_file = " ../foo.natvis" )]
347
+ #! [debugger_visualizer(natvis_file = " ../foo.natvis" )]
321
348
```
322
349
323
350
The same can be done to specify a GDB python debugger script:
324
351
325
352
``` rust
326
- #[debugger_visualizer(gdb_script_file = " ../foo.py" )]
353
+ #! [debugger_visualizer(gdb_script_file = " ../foo.py" )]
327
354
```
328
355
329
- Depending on the Rust target, the correct debugger visualizer will be selected and embedded
330
- in the output.
356
+ Depending on the Rust target, the correct debugger visualizer will be selected
357
+ and embedded in the output.
331
358
332
359
The Rust compiler will serialize the contents of the file specified via the
333
360
` #[debugger_visualizer] ` attribute and store it in the crate metadata. This attribute
@@ -346,9 +373,13 @@ would generate a PDB would have all applicable `.natvis` files embedded.
346
373
In the case of GDB pretty printer, ` #[debugger_visualizer(gdb_script_file = "../foo.py")] `
347
374
the compiler will ensure that the set of pretty printers specified will be added to the
348
375
` .debug_gdb_scripts ` section of the ` ELF ` generated. The ` .debug_gdb_scripts ` section
349
- takes a list of null-terminated entries which specify scripts to load within GDB. The
350
- Rust compiler currently embeds a visualizer for some types in the standard library via
351
- the ` .debug_gdb_scripts ` section.
376
+ takes a list of null-terminated entries which specify scripts to load within GDB. This
377
+ section supports listing files to load directly or embedding the contents of a script
378
+ that will be executed. The Rust compiler currently embeds a visualizer for some types
379
+ in the standard library via the ` .debug_gdb_scripts ` section using the former method.
380
+ This attribute will embed the contents of the debugger script so that it will not
381
+ need to reference a file in the search path. This has proven to be a more reliable
382
+ route than depending on file paths which can be unstable at times.
352
383
353
384
The ` CrateRoot ` type would need to be updated to account for debugger visualizer
354
385
files for crates within the dependency graph. The ` CrateRoot ` would contain
@@ -385,12 +416,9 @@ the set of visualizer files that were previously encoded and stored in the
385
416
contents written to a new file in the ` target ` directory. In the case of Natvis,
386
417
the path of this new file will be what is passed to the ` /NATVIS ` linker flag.
387
418
For example, in a debug build, the contents of the ` .natvis ` files that were encoded
388
- in the crate metadata will be written to new files in the directory ` target/debug/deps/visualizers ` .
389
- Each visualizer file that is written will have a new name to ensure it is unique
390
- across visualizer files for all crates with a naming scheme of ` <crate_name>-<hash>.<visualizer_extension> ` .
391
- The ` <visualizer_extension> ` value will be ` .natvis ` in the case of a Natvis file
392
- and ` .py ` in the case of a pretty printer. The ` <hash> ` value will be the hash of the
393
- contents of the visualizer file.
419
+ in the crate metadata will be written to new files in a temp directory where they will
420
+ be included from. Each visualizer file that is written will have a new name to
421
+ ensure it is unique across visualizer files for all crates.
394
422
395
423
# Drawbacks
396
424
[ drawbacks ] : #drawbacks
@@ -575,7 +603,9 @@ None.
575
603
576
604
## Inline Natvis XML fragments via an attribute
577
605
578
- Debugger visualizer support for Rust could be improved upon by adding support for in-source visualizer definitions via an attribute. Example:
606
+ Debugger visualizer support for Rust could be improved upon by adding support
607
+ for in-source visualizer definitions via the ` #[debugger_visualizer] ` attribute
608
+ or a new attribute. Example:
579
609
580
610
``` rust
581
611
/// A rectangle in first quadrant
@@ -595,6 +625,10 @@ struct FancyRect {
595
625
}
596
626
```
597
627
628
+ Currently the ` #[debugger_visualizer] ` attribute is only allowed to target modules
629
+ but can be updated to allow targeting types as well if the same attribute was to be
630
+ re-used to support this.
631
+
598
632
## Inline Natvis XML fragments via a macro
599
633
600
634
We may want to allow developers to provide Natvis descriptions using a
0 commit comments