Skip to content

Commit 157e517

Browse files
Add an option:--debug-with-line-columnto convert linear location to line+column in the debug info
1 parent c6aa952 commit 157e517

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

src/bin/lpython.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,8 @@ int main(int argc, char *argv[])
11351135
"to look for the module")->allow_extra_args(false);
11361136
// app.add_option("-J", arg_J, "Where to save mod files");
11371137
app.add_flag("-g", compiler_options.emit_debug_info, "Compile with debugging information");
1138+
app.add_flag("--debug-with-line-column", compiler_options.emit_debug_line_column,
1139+
"Convert the linear location info into line + column in the debugging information");
11381140
// app.add_option("-D", compiler_options.c_preprocessor_defines, "Define <macro>=<value> (or 1 if <value> omitted)")->allow_extra_args(false);
11391141
app.add_flag("--version", arg_version, "Display compiler version information");
11401142

src/libasr/codegen/asr_to_llvm.cpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
162162
std::unique_ptr<llvm::IRBuilder<>> builder;
163163
Platform platform;
164164
bool emit_debug_info;
165+
bool emit_debug_line_column;
165166
Allocator &al;
166167

167168
llvm::Value *tmp;
@@ -243,7 +244,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
243244
diag{diagnostics},
244245
context(context),
245246
builder(std::make_unique<llvm::IRBuilder<>>(context)),
246-
platform{platform}, emit_debug_info{emit_debug_info},
247+
platform{platform},
248+
emit_debug_info{emit_debug_info},
249+
emit_debug_line_column{emit_debug_line_column},
247250
al{al},
248251
prototype_only(false),
249252
llvm_utils(std::make_unique<LLVMUtils>(context, builder.get())),
@@ -372,8 +375,12 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
372375
template <typename T>
373376
void debug_emit_loc(const T &x) {
374377
Location loc = x.base.base.loc;
375-
uint64_t line = loc.first;
376-
uint64_t column = 0;
378+
uint32_t line, column;
379+
if (emit_debug_line_column) {
380+
} else {
381+
line = loc.first;
382+
column = 0;
383+
}
377384
builder->SetCurrentDebugLocation(
378385
llvm::DILocation::get(debug_current_scope->getContext(),
379386
line, column, debug_current_scope));
@@ -385,8 +392,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
385392
debug_CU->getFilename(),
386393
debug_CU->getDirectory());
387394
llvm::DIScope *FContext = debug_Unit;
388-
uint64_t LineNo, ScopeLine;
389-
LineNo = ScopeLine = 0;
395+
uint32_t line, column;
396+
if (emit_debug_line_column) {
397+
} else {
398+
line = 0;
399+
}
390400
std::string fn_debug_name = x.m_name;
391401
llvm::DIBasicType *return_type_info = nullptr;
392402
if constexpr (std::is_same_v<T, ASR::Function_t>){
@@ -405,7 +415,7 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
405415
DBuilder->getOrCreateTypeArray(return_type_info));
406416
SP = DBuilder->createFunction(
407417
FContext, fn_debug_name, llvm::StringRef(), debug_Unit,
408-
LineNo, return_type, ScopeLine,
418+
line, return_type, 0, // TODO: ScopeLine
409419
llvm::DINode::FlagPrototyped,
410420
llvm::DISubprogram::SPFlagDefinition);
411421
debug_current_scope = SP;
@@ -2602,17 +2612,22 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
26022612
if (emit_debug_info) {
26032613
// Reset the debug location
26042614
builder->SetCurrentDebugLocation(nullptr);
2605-
uint64_t LineNo = v->base.base.loc.first;
2615+
uint32_t line, column;
2616+
if (emit_debug_line_column) {
2617+
} else {
2618+
line = v->base.base.loc.first;
2619+
column = 0;
2620+
}
26062621
std::string type_name;
26072622
uint32_t type_size, type_encoding;
26082623
get_type_debug_info(v->m_type, type_name, type_size,
26092624
type_encoding);
26102625
llvm::DILocalVariable *debug_var = DBuilder->createParameterVariable(
2611-
debug_current_scope, v->m_name, ++debug_arg_count, debug_Unit, LineNo,
2626+
debug_current_scope, v->m_name, ++debug_arg_count, debug_Unit, line,
26122627
DBuilder->createBasicType(type_name, type_size, type_encoding), true);
26132628
DBuilder->insertDeclare(ptr, debug_var, DBuilder->createExpression(),
26142629
llvm::DILocation::get(debug_current_scope->getContext(),
2615-
LineNo, 0, debug_current_scope), builder->GetInsertBlock());
2630+
line, 0, debug_current_scope), builder->GetInsertBlock());
26162631
}
26172632

26182633
if( ASR::is_a<ASR::Struct_t>(*v->m_type) ) {

src/libasr/utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct CompilerOptions {
3939
std::string target = "";
4040
std::string arg_o = "";
4141
bool emit_debug_info = false;
42+
bool emit_debug_line_column = false;
4243
std::string import_path = "";
4344
Platform platform;
4445

0 commit comments

Comments
 (0)