Skip to content

Commit 3e8ed85

Browse files
authored
Merge pull request rust-lang#291 from bjorn3/debuginfo_line
Implement line debuginfo
2 parents 9e609db + c4d010b commit 3e8ed85

10 files changed

+632
-19
lines changed

Cargo.lock

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ target-lexicon = "0.2.0"
2323
#goblin = "0.0.17"
2424
ar = "0.6.1"
2525
bitflags = "1.0.3"
26-
byteorder = "1.2.6"
26+
byteorder = "1.2.7"
2727
libc = "0.2.45"
2828
tempfile = "3.0.4"
2929
env_logger = "0.6"
30+
gimli = { git = "https://github.com/gimli-rs/gimli.git" }
31+
faerie = "0.7.1"
32+
indexmap = "1.0.2"
3033

3134
# Uncomment to use local checkout of cranelift
3235
#[patch."https://github.com/CraneStation/cranelift.git"]
@@ -35,5 +38,8 @@ env_logger = "0.6"
3538
#cranelift-simplejit = { path = "../cranelift/lib/simplejit" }
3639
#cranelift-faerie = { path = "../cranelift/lib/faerie" }
3740

41+
#[patch."https://github.com/gimli-rs/gimli.git"]
42+
#gimli = { path = "../" }
43+
3844
[profile.dev.overrides."*"]
3945
opt-level = 3

abc.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// compile using g++ -std=c++11 -g -c abc.cpp -o abc.o
2+
3+
struct Opaque;
4+
5+
struct MyType {
6+
unsigned int field_a;
7+
int field_b;
8+
void* field_c;
9+
float field_d;
10+
//double field_e;
11+
//long long field_f;
12+
bool field_g;
13+
char field_h;
14+
Opaque* field_i;
15+
};
16+
17+
MyType bcd(int x, MyType a) {
18+
MyType b = a;
19+
MyType c = b;
20+
MyType d = c;
21+
MyType e = d;
22+
MyType f = e;
23+
MyType g = f;
24+
MyType h = g;
25+
MyType i = h;
26+
MyType j = i;
27+
MyType k = j;
28+
MyType l = k;
29+
MyType m = l;
30+
return b;
31+
}
32+
int main() {
33+
bcd(42, {});
34+
return 0;
35+
}

example/mini_core_hello_world.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,18 @@ struct Unique<T: ?Sized> {
115115

116116
impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
117117

118+
fn take_f32(f: f32) {}
119+
fn take_unique(u: Unique<()>) {}
120+
118121
fn main() {
122+
take_unique(Unique {
123+
pointer: 0 as *const (),
124+
_marker: PhantomData,
125+
});
126+
take_f32(0.1);
127+
128+
//return;
129+
119130
unsafe {
120131
let hello: &[u8] = b"Hello\0" as &[u8; 6];
121132
let ptr: *const u8 = hello as *const [u8] as *const u8;

mini_core_hello_world

25.1 KB
Binary file not shown.

src/base.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
6969
let func_id = cx.module
7070
.declare_function(&name, linkage, &sig)
7171
.unwrap();
72+
let mut debug_context = cx.debug_context.as_mut().map(|debug_context| FunctionDebugContext::new(
73+
tcx,
74+
debug_context,
75+
mir,
76+
&name,
77+
&sig,
78+
));
7279

7380
// Step 3. Make FunctionBuilder
7481
let mut func = Function::with_name_signature(ExternalName::user(0, 0), sig);
@@ -101,13 +108,15 @@ fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
101108
clif_comments,
102109
constants: &mut cx.ccx,
103110
caches: &mut cx.caches,
111+
source_info_set: indexmap::IndexSet::new(),
104112
};
105113

106114
// Step 6. Codegen function
107115
with_unimpl_span(fx.mir.span, || {
108116
crate::abi::codegen_fn_prelude(&mut fx, start_ebb);
109117
codegen_fn_content(&mut fx);
110118
});
119+
let source_info_set = fx.source_info_set.clone();
111120

112121
// Step 7. Write function to file for debugging
113122
#[cfg(debug_assertions)]
@@ -119,8 +128,12 @@ fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
119128
// Step 9. Define function
120129
cx.caches.context.func = func;
121130
cx.module
122-
.define_function(func_id, &mut cx.caches.context)
131+
.define_function_peek_compiled(func_id, &mut cx.caches.context, |size, context, isa| {
132+
debug_context.as_mut().map(|x| x.define(tcx, size, context, isa, &source_info_set));
133+
})
123134
.unwrap();
135+
//let module = &mut cx.module;
136+
//let caches = &cx.caches;
124137
cx.caches.context.clear();
125138
}
126139

@@ -154,6 +167,7 @@ fn codegen_fn_content<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx, impl Backend>)
154167

155168
fx.bcx.ins().nop();
156169
for stmt in &bb_data.statements {
170+
fx.set_debug_loc(stmt.source_info);
157171
trans_stmt(fx, ebb, stmt);
158172
}
159173

@@ -169,6 +183,8 @@ fn codegen_fn_content<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx, impl Backend>)
169183
fx.add_comment(inst, terminator_head);
170184
}
171185

186+
fx.set_debug_loc(bb_data.terminator().source_info);
187+
172188
match &bb_data.terminator().kind {
173189
TerminatorKind::Goto { target } => {
174190
let ebb = fx.get_ebb(*target);
@@ -322,6 +338,8 @@ fn trans_stmt<'a, 'tcx: 'a>(
322338
) {
323339
let _print_guard = PrintOnPanic(|| format!("stmt {:?}", stmt));
324340

341+
fx.set_debug_loc(stmt.source_info);
342+
325343
#[cfg(debug_assertions)]
326344
match &stmt.kind {
327345
StatementKind::StorageLive(..) | StatementKind::StorageDead(..) => {} // Those are not very useful

src/common.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ pub struct FunctionCx<'a, 'tcx: 'a, B: Backend> {
539539
pub clif_comments: crate::pretty_clif::CommentWriter,
540540
pub constants: &'a mut crate::constant::ConstantCx,
541541
pub caches: &'a mut Caches<'tcx>,
542+
pub source_info_set: indexmap::IndexSet<SourceInfo>,
542543
}
543544

544545
impl<'a, 'tcx: 'a, B: Backend + 'a> fmt::Debug for FunctionCx<'a, 'tcx, B> {
@@ -617,4 +618,9 @@ impl<'a, 'tcx: 'a, B: Backend + 'a> FunctionCx<'a, 'tcx, B> {
617618
pub fn get_local_place(&mut self, local: Local) -> CPlace<'tcx> {
618619
*self.local_map.get(&local).unwrap()
619620
}
621+
622+
pub fn set_debug_loc(&mut self, source_info: mir::SourceInfo) {
623+
let (index, _) = self.source_info_set.insert_full(source_info);
624+
self.bcx.set_srcloc(SourceLoc::new(index as u32));
625+
}
620626
}

0 commit comments

Comments
 (0)