Skip to content

Commit add3b83

Browse files
Merge pull request #2350 from Thirumalai-Shaktivel/runtime_stacktrace_01
2 parents 8546abe + 10a3044 commit add3b83

16 files changed

+46
-42
lines changed

src/bin/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if (WITH_STACKTRACE AND APPLE AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
3333
add_custom_command(
3434
TARGET lpython
3535
POST_BUILD
36-
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/dwarf_convert.py lpython.dSYM/raw.txt lpython.dSYM/lines.txt lpython.dSYM/lines.dat
36+
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../libasr/dwarf_convert.py lpython.dSYM/raw.txt lpython.dSYM/lines.txt lpython.dSYM/lines.dat
3737
)
3838
endif()
3939
endif()

src/bin/lpython.cpp

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -736,17 +736,6 @@ int emit_llvm(const std::string &infile,
736736
LCompilers::PythonCompiler fe(compiler_options);
737737
LCompilers::Result<std::unique_ptr<LCompilers::LLVMModule>>
738738
res = fe.get_llvm3(*asr, pass_manager, diagnostics, infile);
739-
if (compiler_options.emit_debug_info) {
740-
if (!compiler_options.emit_debug_line_column) {
741-
diagnostics.add(LCompilers::diag::Diagnostic(
742-
"The `emit_debug_line_column` is not enabled; please use the "
743-
"`--debug-with-line-column` option to get the correct "
744-
"location information",
745-
LCompilers::diag::Level::Warning,
746-
LCompilers::diag::Stage::Semantic, {})
747-
);
748-
}
749-
}
750739
std::cerr << diagnostics.render(lm, compiler_options);
751740
if (!res.ok) {
752741
LCOMPILERS_ASSERT(diagnostics.has_error())
@@ -819,6 +808,18 @@ int compile_python_to_object_file(
819808
diagnostics.diagnostics.clear();
820809

821810
// ASR -> LLVM
811+
if (compiler_options.emit_debug_info) {
812+
#ifndef HAVE_RUNTIME_STACKTRACE
813+
diagnostics.add(LCompilers::diag::Diagnostic(
814+
"The `runtime stacktrace` is not enabled. To get the stacktraces, "
815+
"re-build LPython with `-DWITH_RUNTIME_STACKTRACE=yes`",
816+
LCompilers::diag::Level::Error,
817+
LCompilers::diag::Stage::Semantic, {})
818+
);
819+
std::cerr << diagnostics.render(lm, compiler_options);
820+
return 1;
821+
#endif
822+
}
822823
LCompilers::PythonCompiler fe(compiler_options);
823824
LCompilers::LLVMEvaluator e(compiler_options.target);
824825
std::unique_ptr<LCompilers::LLVMModule> m;
@@ -828,26 +829,6 @@ int compile_python_to_object_file(
828829
auto asr_to_llvm_end = std::chrono::high_resolution_clock::now();
829830
times.push_back(std::make_pair("ASR to LLVM", std::chrono::duration<double, std::milli>(asr_to_llvm_end - asr_to_llvm_start).count()));
830831

831-
if (compiler_options.emit_debug_info) {
832-
#ifdef HAVE_RUNTIME_STACKTRACE
833-
if (!compiler_options.emit_debug_line_column) {
834-
diagnostics.add(LCompilers::diag::Diagnostic(
835-
"The `emit_debug_line_column` is not enabled; please use the "
836-
"`--debug-with-line-column` option to get the correct "
837-
"location information",
838-
LCompilers::diag::Level::Warning,
839-
LCompilers::diag::Stage::Semantic, {})
840-
);
841-
}
842-
#else
843-
diagnostics.add(LCompilers::diag::Diagnostic(
844-
"The `runtime stacktrace` is not enabled. To get the stacktraces, "
845-
"re-build LPython with `-DWITH_RUNTIME_STACKTRACE=yes`",
846-
LCompilers::diag::Level::Warning,
847-
LCompilers::diag::Stage::Semantic, {})
848-
);
849-
#endif
850-
}
851832
std::cerr << diagnostics.render(lm, compiler_options);
852833
if (!res.ok) {
853834
LCOMPILERS_ASSERT(diagnostics.has_error())
@@ -1901,14 +1882,14 @@ int main(int argc, char *argv[])
19011882
#else
19021883
cmd += "llvm-dwarfdump --debug-line " + basename + ".out > ";
19031884
#endif
1904-
cmd += basename + "_ldd.txt && (cd src/bin; ./dwarf_convert.py ../../"
1885+
cmd += basename + "_ldd.txt && (cd src/libasr; ./dwarf_convert.py ../../"
19051886
+ basename + "_ldd.txt ../../" + basename + "_lines.txt ../../"
19061887
+ basename + "_lines.dat && ./dat_convert.py ../../"
19071888
+ basename + "_lines.dat)";
19081889
int status = system(cmd.c_str());
19091890
if ( status != 0 ) {
19101891
std::cerr << "Error in creating the files used to generate "
1911-
"the debug information. This might be caused because either"
1892+
"the debug information. This might be caused because either "
19121893
"`llvm-dwarfdump` or `Python` are not available. "
19131894
"Please activate the CONDA environment and compile again.\n";
19141895
return status;
File renamed without changes.
File renamed without changes.

src/libasr/runtime/lfortran_intrinsics.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ char** parse_fortran_format(char* format, int *count) {
372372
switch (tolower(format[index])) {
373373
case ',' :
374374
break;
375-
case '/' :
375+
case '/' :
376376
format_values_2[format_values_count++] = "/";
377377
break;
378378
case '"' :
@@ -2619,9 +2619,9 @@ LFORTRAN_API void print_stacktrace_addresses(char *filename, bool use_colors) {
26192619
get_local_info_dwarfdump(&d);
26202620

26212621
#ifdef HAVE_LFORTRAN_MACHO
2622-
for (int32_t i = d.local_pc_size-2; i >= 0; i--) {
2622+
for (int32_t i = d.local_pc_size-1; i >= 0; i--) {
26232623
#else
2624-
for (int32_t i = d.local_pc_size-3; i >= 0; i--) {
2624+
for (int32_t i = d.local_pc_size-2; i >= 0; i--) {
26252625
#endif
26262626
uint64_t index = bisection(d.addresses, d.stack_size, d.local_pc[i]);
26272627
if(use_colors) {

src/lpython/python_evaluator.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ Result<std::unique_ptr<LLVMModule>> PythonCompiler::get_llvm3(
5050
eval_count++;
5151
run_fn = "__lfortran_evaluate_" + std::to_string(eval_count);
5252

53+
if (compiler_options.emit_debug_info) {
54+
if (!compiler_options.emit_debug_line_column) {
55+
diagnostics.add(LCompilers::diag::Diagnostic(
56+
"The `emit_debug_line_column` is not enabled; please use the "
57+
"`--debug-with-line-column` option to get the correct "
58+
"location information",
59+
LCompilers::diag::Level::Error,
60+
LCompilers::diag::Stage::Semantic, {})
61+
);
62+
Error err;
63+
return err;
64+
}
65+
}
5366
// ASR -> LLVM
5467
std::unique_ptr<LCompilers::LLVMModule> m;
5568
Result<std::unique_ptr<LCompilers::LLVMModule>> res

tests/reference/run_dbg-test_assert_01-2f34744.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"stdout": null,
99
"stdout_hash": null,
1010
"stderr": "run_dbg-test_assert_01-2f34744.stderr",
11-
"stderr_hash": "5ded88da4106fc9a3cfbaad6f82cc820a79a6ef8cc1661ecfcb37924",
11+
"stderr_hash": "4811af471c73572b285e9ea01c8689abdd3cb32c717b3cd4876d2669",
1212
"returncode": 1
1313
}

tests/reference/run_dbg-test_assert_01-2f34744.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
File "tests/runtime_errors/test_assert_01.py", line 1
2+
def test():
13
File "tests/runtime_errors/test_assert_01.py", line 4
24
test()
35
File "tests/runtime_errors/test_assert_01.py", line 2

tests/reference/run_dbg-test_assert_02-c6de25a.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"stdout": null,
99
"stdout_hash": null,
1010
"stderr": "run_dbg-test_assert_02-c6de25a.stderr",
11-
"stderr_hash": "ddba8a92bcfd5a30016735589da0dc56f2785e7636afcc0edeca4139",
11+
"stderr_hash": "d5bfce55992e8d0630849442ee1f9b32864c64c328917c29fafc9424",
1212
"returncode": 1
1313
}

tests/reference/run_dbg-test_assert_02-c6de25a.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
File "tests/runtime_errors/test_assert_02.py", line 1
2+
def test():
13
File "tests/runtime_errors/test_assert_02.py", line 4
24
test()
35
File "tests/runtime_errors/test_assert_02.py", line 2

0 commit comments

Comments
 (0)