Skip to content

Implement line debuginfo #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ target-lexicon = "0.2.0"
#goblin = "0.0.17"
ar = "0.6.1"
bitflags = "1.0.3"
byteorder = "1.2.6"
byteorder = "1.2.7"
libc = "0.2.45"
tempfile = "3.0.4"
env_logger = "0.6"
gimli = { git = "https://github.com/gimli-rs/gimli.git" }
faerie = "0.7.1"
indexmap = "1.0.2"

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

#[patch."https://github.com/gimli-rs/gimli.git"]
#gimli = { path = "../" }

[profile.dev.overrides."*"]
opt-level = 3
35 changes: 35 additions & 0 deletions abc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// compile using g++ -std=c++11 -g -c abc.cpp -o abc.o

struct Opaque;

struct MyType {
unsigned int field_a;
int field_b;
void* field_c;
float field_d;
//double field_e;
//long long field_f;
bool field_g;
char field_h;
Opaque* field_i;
};

MyType bcd(int x, MyType a) {
MyType b = a;
MyType c = b;
MyType d = c;
MyType e = d;
MyType f = e;
MyType g = f;
MyType h = g;
MyType i = h;
MyType j = i;
MyType k = j;
MyType l = k;
MyType m = l;
return b;
}
int main() {
bcd(42, {});
return 0;
}
11 changes: 11 additions & 0 deletions example/mini_core_hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,18 @@ struct Unique<T: ?Sized> {

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

fn take_f32(f: f32) {}
fn take_unique(u: Unique<()>) {}

fn main() {
take_unique(Unique {
pointer: 0 as *const (),
_marker: PhantomData,
});
take_f32(0.1);

//return;

unsafe {
let hello: &[u8] = b"Hello\0" as &[u8; 6];
let ptr: *const u8 = hello as *const [u8] as *const u8;
Expand Down
Binary file added mini_core_hello_world
Binary file not shown.
20 changes: 19 additions & 1 deletion src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
let func_id = cx.module
.declare_function(&name, linkage, &sig)
.unwrap();
let mut debug_context = cx.debug_context.as_mut().map(|debug_context| FunctionDebugContext::new(
tcx,
debug_context,
mir,
&name,
&sig,
));

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

// Step 6. Codegen function
with_unimpl_span(fx.mir.span, || {
crate::abi::codegen_fn_prelude(&mut fx, start_ebb);
codegen_fn_content(&mut fx);
});
let source_info_set = fx.source_info_set.clone();

// Step 7. Write function to file for debugging
#[cfg(debug_assertions)]
Expand All @@ -119,8 +128,12 @@ fn trans_fn<'a, 'clif, 'tcx: 'a, B: Backend + 'static>(
// Step 9. Define function
cx.caches.context.func = func;
cx.module
.define_function(func_id, &mut cx.caches.context)
.define_function_peek_compiled(func_id, &mut cx.caches.context, |size, context, isa| {
debug_context.as_mut().map(|x| x.define(tcx, size, context, isa, &source_info_set));
})
.unwrap();
//let module = &mut cx.module;
//let caches = &cx.caches;
cx.caches.context.clear();
}

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

fx.bcx.ins().nop();
for stmt in &bb_data.statements {
fx.set_debug_loc(stmt.source_info);
trans_stmt(fx, ebb, stmt);
}

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

fx.set_debug_loc(bb_data.terminator().source_info);

match &bb_data.terminator().kind {
TerminatorKind::Goto { target } => {
let ebb = fx.get_ebb(*target);
Expand Down Expand Up @@ -322,6 +338,8 @@ fn trans_stmt<'a, 'tcx: 'a>(
) {
let _print_guard = PrintOnPanic(|| format!("stmt {:?}", stmt));

fx.set_debug_loc(stmt.source_info);

#[cfg(debug_assertions)]
match &stmt.kind {
StatementKind::StorageLive(..) | StatementKind::StorageDead(..) => {} // Those are not very useful
Expand Down
6 changes: 6 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ pub struct FunctionCx<'a, 'tcx: 'a, B: Backend> {
pub clif_comments: crate::pretty_clif::CommentWriter,
pub constants: &'a mut crate::constant::ConstantCx,
pub caches: &'a mut Caches<'tcx>,
pub source_info_set: indexmap::IndexSet<SourceInfo>,
}

impl<'a, 'tcx: 'a, B: Backend + 'a> fmt::Debug for FunctionCx<'a, 'tcx, B> {
Expand Down Expand Up @@ -617,4 +618,9 @@ impl<'a, 'tcx: 'a, B: Backend + 'a> FunctionCx<'a, 'tcx, B> {
pub fn get_local_place(&mut self, local: Local) -> CPlace<'tcx> {
*self.local_map.get(&local).unwrap()
}

pub fn set_debug_loc(&mut self, source_info: mir::SourceInfo) {
let (index, _) = self.source_info_set.insert_full(source_info);
self.bcx.set_srcloc(SourceLoc::new(index as u32));
}
}
Loading