|
| 1 | +use std::collections::BTreeSet; |
| 2 | +use std::fmt::Write as _; |
| 3 | +use std::fmt::{Debug, Display}; |
| 4 | +use std::fs; |
| 5 | +use std::io::{self, Write}; |
| 6 | +use std::path::{Path, PathBuf}; |
| 7 | + |
1 | 8 | use super::graphviz::write_mir_fn_graphviz;
|
2 | 9 | use crate::transform::MirSource;
|
3 | 10 | use either::Either;
|
4 | 11 | use rustc_data_structures::fx::FxHashMap;
|
5 | 12 | use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
6 | 13 | use rustc_index::vec::Idx;
|
7 | 14 | use rustc_middle::mir::interpret::{
|
8 |
| - read_target_uint, AllocId, Allocation, ConstValue, GlobalAlloc, |
| 15 | + read_target_uint, AllocId, Allocation, ConstValue, GlobalAlloc, Pointer, |
9 | 16 | };
|
10 | 17 | use rustc_middle::mir::visit::Visitor;
|
11 | 18 | use rustc_middle::mir::*;
|
12 | 19 | use rustc_middle::ty::{self, TyCtxt, TypeFoldable, TypeVisitor};
|
13 | 20 | use rustc_target::abi::Size;
|
14 |
| -use std::collections::BTreeSet; |
15 |
| -use std::fmt::Display; |
16 |
| -use std::fmt::Write as _; |
17 |
| -use std::fs; |
18 |
| -use std::io::{self, Write}; |
19 |
| -use std::path::{Path, PathBuf}; |
20 | 21 |
|
21 | 22 | const INDENT: &str = " ";
|
22 | 23 | /// Alignment for lining up comments following MIR statements
|
@@ -635,7 +636,7 @@ pub fn write_allocations<'tcx>(
|
635 | 636 | /// After the hex dump, an ascii dump follows, replacing all unprintable characters (control
|
636 | 637 | /// characters or characters whose value is larger than 127) with a `.`
|
637 | 638 | /// This also prints relocations adequately.
|
638 |
| -pub fn write_allocation<Tag, Extra>( |
| 639 | +pub fn write_allocation<Tag: Copy + Debug, Extra>( |
639 | 640 | tcx: TyCtxt<'tcx>,
|
640 | 641 | alloc: &Allocation<Tag, Extra>,
|
641 | 642 | w: &mut dyn Write,
|
@@ -679,7 +680,7 @@ fn write_allocation_newline(
|
679 | 680 | /// The `prefix` argument allows callers to add an arbitrary prefix before each line (even if there
|
680 | 681 | /// is only one line). Note that your prefix should contain a trailing space as the lines are
|
681 | 682 | /// printed directly after it.
|
682 |
| -fn write_allocation_bytes<Tag, Extra>( |
| 683 | +fn write_allocation_bytes<Tag: Copy + Debug, Extra>( |
683 | 684 | tcx: TyCtxt<'tcx>,
|
684 | 685 | alloc: &Allocation<Tag, Extra>,
|
685 | 686 | w: &mut dyn Write,
|
@@ -715,14 +716,20 @@ fn write_allocation_bytes<Tag, Extra>(
|
715 | 716 | if i != line_start {
|
716 | 717 | write!(w, " ")?;
|
717 | 718 | }
|
718 |
| - if let Some(&(_, target_id)) = alloc.relocations().get(&i) { |
| 719 | + if let Some(&(tag, target_id)) = alloc.relocations().get(&i) { |
719 | 720 | // Memory with a relocation must be defined
|
720 | 721 | let j = i.bytes_usize();
|
721 | 722 | let offset =
|
722 | 723 | alloc.inspect_with_undef_and_ptr_outside_interpreter(j..j + ptr_size.bytes_usize());
|
723 | 724 | let offset = read_target_uint(tcx.data_layout.endian, offset).unwrap();
|
| 725 | + let offset = Size::from_bytes(offset); |
724 | 726 | let relocation_width = |bytes| bytes * 3;
|
725 |
| - let mut target = format!("{}+{}", target_id, offset); |
| 727 | + let ptr = Pointer::new_with_tag(target_id, offset, tag); |
| 728 | + let mut target = format!("{:?}", ptr); |
| 729 | + if target.len() > relocation_width(ptr_size.bytes_usize() - 1) { |
| 730 | + // This is too long, try to save some space. |
| 731 | + target = format!("{:#?}", ptr); |
| 732 | + } |
726 | 733 | if ((i - line_start) + ptr_size).bytes_usize() > BYTES_PER_LINE {
|
727 | 734 | // This branch handles the situation where a relocation starts in the current line
|
728 | 735 | // but ends in the next one.
|
|
0 commit comments