Skip to content

Commit ef158f2

Browse files
committed
feat(debuginfo.rs): Add Comments on functions of LLVM Origin
1 parent eaeb544 commit ef158f2

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

src/base.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol, target_info: Lock
158158
if env::var("CG_GCCJIT_KEEP_INTERMEDIATES").as_deref() == Ok("1") {
159159
context.set_keep_intermediates(true);
160160
}
161-
162161
if env::var("CG_GCCJIT_VERBOSE").as_deref() == Ok("1") {
163162
context.add_driver_option("-v");
164163
}

src/debuginfo.rs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'gcc, 'tcx> {
5151
}
5252
}
5353

54-
pub fn compute_mir_scopes<'gcc, 'tcx>(
54+
/// Generate the `debug_context` in an MIR Body.
55+
/// # Souce of Origin
56+
/// Copied from `create_scope_map.rs` of rustc_codegen_llvm
57+
fn compute_mir_scopes<'gcc, 'tcx>(
5558
cx: &CodegenCx<'gcc, 'tcx>,
5659
instance: Instance<'tcx>,
5760
mir: &Body<'tcx>,
@@ -81,6 +84,12 @@ pub fn compute_mir_scopes<'gcc, 'tcx>(
8184
assert!(instantiated.count() == mir.source_scopes.len());
8285
}
8386

87+
/// Update the `debug_context`, adding new scope to it,
88+
/// if it's not added as is denoted in `instantiated`.
89+
///
90+
/// # Souce of Origin
91+
/// Copied from `create_scope_map.rs` of rustc_codegen_llvm
92+
/// FIXME(tempdragon/?): Add Scope Support Here.
8493
fn make_mir_scope<'gcc, 'tcx>(
8594
cx: &CodegenCx<'gcc, 'tcx>,
8695
instance: Instance<'tcx>,
@@ -123,6 +132,39 @@ fn make_mir_scope<'gcc, 'tcx>(
123132
}
124133

125134
let loc = cx.lookup_debug_loc(scope_data.span.lo());
135+
136+
/*
137+
// FIXME(?): Uncommented when the scope is supported.
138+
let file_metadata = file_metadata(cx, &loc.file);
139+
140+
let parent_dbg_scope = match scope_data.inlined {
141+
Some((callee, _)) => {
142+
// FIXME(eddyb) this would be `self.monomorphize(&callee)`
143+
// if this is moved to `rustc_codegen_ssa::mir::debuginfo`.
144+
let callee = cx.tcx.instantiate_and_normalize_erasing_regions(
145+
instance.args,
146+
ty::ParamEnv::reveal_all(),
147+
ty::EarlyBinder::bind(callee),
148+
);
149+
debug_context.inlined_function_scopes.entry(callee).or_insert_with(|| {
150+
let callee_fn_abi = cx.fn_abi_of_instance(callee, ty::List::empty());
151+
cx.dbg_scope_fn(callee, callee_fn_abi, None)
152+
})
153+
}
154+
None => parent_scope.dbg_scope,
155+
};
156+
157+
let dbg_scope = unsafe {
158+
llvm::LLVMRustDIBuilderCreateLexicalBlock(
159+
DIB(cx),
160+
parent_dbg_scope,
161+
file_metadata,
162+
loc.line,
163+
loc.col,
164+
)
165+
};
166+
*/
167+
126168
let dbg_scope = ();
127169

128170
let inlined_at = scope_data.inlined.map(|(_, callsite_span)| {
@@ -144,8 +186,13 @@ fn make_mir_scope<'gcc, 'tcx>(
144186
instantiated.insert(scope);
145187
}
146188

147-
/// Copied from LLVM backend
148189
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
190+
/// Look up the file, the 1-based indexing line number and column number.
191+
/// # Argument
192+
/// - `pos`: `BytePos`, the starting position of a piece of code
193+
/// # Source of Origin
194+
/// Copied from LLVM backend(with a return type from struct to tuple).
195+
/// No need to change since you may end up something like this.
149196
pub fn lookup_debug_loc(&self, pos: BytePos) -> (Lrc<SourceFile>, u32, u32) {
150197
match self.sess().source_map().lookup_line(pos) {
151198
Ok(SourceFileAndLine { sf: file, line }) => {
@@ -216,7 +263,6 @@ impl<'gcc, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
216263
}
217264

218265
fn debuginfo_finalize(&self) {
219-
// TODO(antoyo): Get the debug flag/predicate to allow optional generation of debuginfo.
220266
self.context.set_debug_info(true)
221267
}
222268

0 commit comments

Comments
 (0)