diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2022-05-29 01:12:30 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-29 01:12:30 +0200 |
| commit | 239287f013b21d18c8ddd5bf5419629d43dca484 (patch) | |
| tree | 8370d6dac6dfdae06b82d23e097b46472e026673 /compiler/rustc_passes/src/debugger_visualizer.rs | |
| parent | 376163a77cda823c4e1bdedd48039609069e6b58 (diff) | |
| parent | 7ac62ce75cef963017245287f0a7b140e09589d7 (diff) | |
| download | rust-239287f013b21d18c8ddd5bf5419629d43dca484.tar.gz rust-239287f013b21d18c8ddd5bf5419629d43dca484.zip | |
Rollup merge of #97028 - ridwanabdillahi:pretty-printer, r=michaelwoerister
Add support for embedding pretty printers via `#[debugger_visualizer]` attribute Initial support for [RFC 3191](https://github.com/rust-lang/rfcs/pull/3191) in PR https://github.com/rust-lang/rust/pull/91779 was scoped to supporting embedding NatVis files using a new attribute. This PR implements the pretty printer support as stated in the RFC mentioned above. This change includes embedding pretty printers in the `.debug_gdb_scripts` just as the pretty printers for rustc are embedded today. Also added additional tests for embedded pretty printers. Additionally cleaned up error checking so all error checking is done up front regardless of the current target. RFC: https://github.com/rust-lang/rfcs/pull/3191
Diffstat (limited to 'compiler/rustc_passes/src/debugger_visualizer.rs')
| -rw-r--r-- | compiler/rustc_passes/src/debugger_visualizer.rs | 61 |
1 files changed, 25 insertions, 36 deletions
diff --git a/compiler/rustc_passes/src/debugger_visualizer.rs b/compiler/rustc_passes/src/debugger_visualizer.rs index 8305830bc98..e08683fe23b 100644 --- a/compiler/rustc_passes/src/debugger_visualizer.rs +++ b/compiler/rustc_passes/src/debugger_visualizer.rs @@ -21,9 +21,8 @@ fn check_for_debugger_visualizer<'tcx>( let attrs = tcx.hir().attrs(hir_id); for attr in attrs { if attr.has_name(sym::debugger_visualizer) { - let list = match attr.meta_item_list() { - Some(list) => list, - _ => continue, + let Some(list) = attr.meta_item_list() else { + continue }; let meta_item = match list.len() { @@ -34,45 +33,35 @@ fn check_for_debugger_visualizer<'tcx>( _ => continue, }; - let file = match (meta_item.name_or_empty(), meta_item.value_str()) { - (sym::natvis_file, Some(value)) => { + let visualizer_type = match meta_item.name_or_empty() { + sym::natvis_file => DebuggerVisualizerType::Natvis, + sym::gdb_script_file => DebuggerVisualizerType::GdbPrettyPrinter, + _ => continue, + }; + + let file = match meta_item.value_str() { + Some(value) => { match resolve_path(&tcx.sess.parse_sess, value.as_str(), attr.span) { Ok(file) => file, - Err(mut err) => { - err.emit(); - continue; - } + _ => continue, } } - (_, _) => continue, + None => continue, }; - if file.is_file() { - let contents = match std::fs::read(&file) { - Ok(contents) => contents, - Err(err) => { - tcx.sess - .struct_span_err( - attr.span, - &format!( - "Unable to read contents of file `{}`. {}", - file.display(), - err - ), - ) - .emit(); - continue; - } - }; - - debugger_visualizers.insert(DebuggerVisualizerFile::new( - Arc::from(contents), - DebuggerVisualizerType::Natvis, - )); - } else { - tcx.sess - .struct_span_err(attr.span, &format!("{} is not a valid file", file.display())) - .emit(); + match std::fs::read(&file) { + Ok(contents) => { + debugger_visualizers + .insert(DebuggerVisualizerFile::new(Arc::from(contents), visualizer_type)); + } + Err(err) => { + tcx.sess + .struct_span_err( + meta_item.span, + &format!("couldn't read {}: {}", file.display(), err), + ) + .emit(); + } } } } |
