Add line-level debug info (#4247)

Seems to work with lldb ( https://pastebin.com/igKkNECm ), though gdb
has /some/ trouble with the paths (they aren't complete - just using the
filename directly, not providing the working directory - might be some
quick hacks that can help there).
This commit is contained in:
David Blaikie
2024-08-26 15:49:31 +00:00
committed by GitHub
parent 5d73743971
commit 0ae2a3907e
104 changed files with 1586 additions and 1009 deletions
+10 -1
View File
@@ -12,12 +12,16 @@ namespace Carbon::Lower {
FunctionContext::FunctionContext(FileContext& file_context,
llvm::Function* function,
llvm::DISubprogram* di_subprogram,
llvm::raw_ostream* vlog_stream)
: file_context_(&file_context),
function_(function),
builder_(file_context.llvm_context(), llvm::ConstantFolder(),
Inserter(file_context.inst_namer())),
vlog_stream_(vlog_stream) {}
di_subprogram_(di_subprogram),
vlog_stream_(vlog_stream) {
function_->setSubprogram(di_subprogram_);
}
auto FunctionContext::GetBlock(SemIR::InstBlockId block_id)
-> llvm::BasicBlock* {
@@ -93,6 +97,10 @@ auto FunctionContext::LowerInst(SemIR::InstId inst_id) -> void {
auto inst = sem_ir().insts().Get(inst_id);
CARBON_VLOG() << "Lowering " << inst_id << ": " << inst << "\n";
builder_.getInserter().SetCurrentInstId(inst_id);
auto loc = file_context_->GetDiagnosticLoc(inst_id);
builder_.SetCurrentDebugLocation(
llvm::DILocation::get(builder_.getContext(), loc.line_number,
loc.column_number, di_subprogram_));
CARBON_KIND_SWITCH(inst) {
#define CARBON_SEM_IR_INST_KIND(Name) \
@@ -104,6 +112,7 @@ auto FunctionContext::LowerInst(SemIR::InstId inst_id) -> void {
}
builder_.getInserter().SetCurrentInstId(SemIR::InstId::Invalid);
builder_.SetCurrentDebugLocation(llvm::DebugLoc());
}
auto FunctionContext::GetBlockArg(SemIR::InstBlockId block_id,