Skip to content

Sync Libasr for Runtime Stacktrace #2350

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
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
2 changes: 1 addition & 1 deletion src/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if (WITH_STACKTRACE AND APPLE AND CMAKE_CXX_COMPILER_ID MATCHES Clang)
add_custom_command(
TARGET lpython
POST_BUILD
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/dwarf_convert.py lpython.dSYM/raw.txt lpython.dSYM/lines.txt lpython.dSYM/lines.dat
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../libasr/dwarf_convert.py lpython.dSYM/raw.txt lpython.dSYM/lines.txt lpython.dSYM/lines.dat
)
endif()
endif()
Expand Down
47 changes: 14 additions & 33 deletions src/bin/lpython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,17 +736,6 @@ int emit_llvm(const std::string &infile,
LCompilers::PythonCompiler fe(compiler_options);
LCompilers::Result<std::unique_ptr<LCompilers::LLVMModule>>
res = fe.get_llvm3(*asr, pass_manager, diagnostics, infile);
if (compiler_options.emit_debug_info) {
if (!compiler_options.emit_debug_line_column) {
diagnostics.add(LCompilers::diag::Diagnostic(
"The `emit_debug_line_column` is not enabled; please use the "
"`--debug-with-line-column` option to get the correct "
"location information",
LCompilers::diag::Level::Warning,
LCompilers::diag::Stage::Semantic, {})
);
}
}
std::cerr << diagnostics.render(lm, compiler_options);
if (!res.ok) {
LCOMPILERS_ASSERT(diagnostics.has_error())
Expand Down Expand Up @@ -819,6 +808,18 @@ int compile_python_to_object_file(
diagnostics.diagnostics.clear();

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

if (compiler_options.emit_debug_info) {
#ifdef HAVE_RUNTIME_STACKTRACE
if (!compiler_options.emit_debug_line_column) {
diagnostics.add(LCompilers::diag::Diagnostic(
"The `emit_debug_line_column` is not enabled; please use the "
"`--debug-with-line-column` option to get the correct "
"location information",
LCompilers::diag::Level::Warning,
LCompilers::diag::Stage::Semantic, {})
);
}
#else
diagnostics.add(LCompilers::diag::Diagnostic(
"The `runtime stacktrace` is not enabled. To get the stacktraces, "
"re-build LPython with `-DWITH_RUNTIME_STACKTRACE=yes`",
LCompilers::diag::Level::Warning,
LCompilers::diag::Stage::Semantic, {})
);
#endif
}
std::cerr << diagnostics.render(lm, compiler_options);
if (!res.ok) {
LCOMPILERS_ASSERT(diagnostics.has_error())
Expand Down Expand Up @@ -1901,14 +1882,14 @@ int main(int argc, char *argv[])
#else
cmd += "llvm-dwarfdump --debug-line " + basename + ".out > ";
#endif
cmd += basename + "_ldd.txt && (cd src/bin; ./dwarf_convert.py ../../"
cmd += basename + "_ldd.txt && (cd src/libasr; ./dwarf_convert.py ../../"
+ basename + "_ldd.txt ../../" + basename + "_lines.txt ../../"
+ basename + "_lines.dat && ./dat_convert.py ../../"
+ basename + "_lines.dat)";
int status = system(cmd.c_str());
if ( status != 0 ) {
std::cerr << "Error in creating the files used to generate "
"the debug information. This might be caused because either"
"the debug information. This might be caused because either "
"`llvm-dwarfdump` or `Python` are not available. "
"Please activate the CONDA environment and compile again.\n";
return status;
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/libasr/runtime/lfortran_intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ char** parse_fortran_format(char* format, int *count) {
switch (tolower(format[index])) {
case ',' :
break;
case '/' :
case '/' :
format_values_2[format_values_count++] = "/";
break;
case '"' :
Expand Down Expand Up @@ -2619,9 +2619,9 @@ LFORTRAN_API void print_stacktrace_addresses(char *filename, bool use_colors) {
get_local_info_dwarfdump(&d);

#ifdef HAVE_LFORTRAN_MACHO
for (int32_t i = d.local_pc_size-2; i >= 0; i--) {
for (int32_t i = d.local_pc_size-1; i >= 0; i--) {
#else
for (int32_t i = d.local_pc_size-3; i >= 0; i--) {
for (int32_t i = d.local_pc_size-2; i >= 0; i--) {
#endif
uint64_t index = bisection(d.addresses, d.stack_size, d.local_pc[i]);
if(use_colors) {
Expand Down
13 changes: 13 additions & 0 deletions src/lpython/python_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ Result<std::unique_ptr<LLVMModule>> PythonCompiler::get_llvm3(
eval_count++;
run_fn = "__lfortran_evaluate_" + std::to_string(eval_count);

if (compiler_options.emit_debug_info) {
if (!compiler_options.emit_debug_line_column) {
diagnostics.add(LCompilers::diag::Diagnostic(
"The `emit_debug_line_column` is not enabled; please use the "
"`--debug-with-line-column` option to get the correct "
"location information",
LCompilers::diag::Level::Error,
LCompilers::diag::Stage::Semantic, {})
);
Error err;
return err;
}
}
// ASR -> LLVM
std::unique_ptr<LCompilers::LLVMModule> m;
Result<std::unique_ptr<LCompilers::LLVMModule>> res
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/run_dbg-test_assert_01-2f34744.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"stdout": null,
"stdout_hash": null,
"stderr": "run_dbg-test_assert_01-2f34744.stderr",
"stderr_hash": "5ded88da4106fc9a3cfbaad6f82cc820a79a6ef8cc1661ecfcb37924",
"stderr_hash": "4811af471c73572b285e9ea01c8689abdd3cb32c717b3cd4876d2669",
"returncode": 1
}
2 changes: 2 additions & 0 deletions tests/reference/run_dbg-test_assert_01-2f34744.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
File "tests/runtime_errors/test_assert_01.py", line 1
def test():
File "tests/runtime_errors/test_assert_01.py", line 4
test()
File "tests/runtime_errors/test_assert_01.py", line 2
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/run_dbg-test_assert_02-c6de25a.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"stdout": null,
"stdout_hash": null,
"stderr": "run_dbg-test_assert_02-c6de25a.stderr",
"stderr_hash": "ddba8a92bcfd5a30016735589da0dc56f2785e7636afcc0edeca4139",
"stderr_hash": "d5bfce55992e8d0630849442ee1f9b32864c64c328917c29fafc9424",
"returncode": 1
}
2 changes: 2 additions & 0 deletions tests/reference/run_dbg-test_assert_02-c6de25a.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
File "tests/runtime_errors/test_assert_02.py", line 1
def test():
File "tests/runtime_errors/test_assert_02.py", line 4
test()
File "tests/runtime_errors/test_assert_02.py", line 2
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/run_dbg-test_assert_03-bd7b7dd.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"stdout": null,
"stdout_hash": null,
"stderr": "run_dbg-test_assert_03-bd7b7dd.stderr",
"stderr_hash": "7f97899439260443b40867e81d7c481c2fc23ec84ee777e7b43984d8",
"stderr_hash": "cae7dd955478787917e9dbb0bc1f63631317b13da1d892c3ebab9097",
"returncode": 1
}
2 changes: 2 additions & 0 deletions tests/reference/run_dbg-test_assert_03-bd7b7dd.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
File "tests/runtime_errors/test_assert_03.py", line 1
def f():
File "tests/runtime_errors/test_assert_03.py", line 10
main()
File "tests/runtime_errors/test_assert_03.py", line 8
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/run_dbg-test_quit_01-30889cc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"stdout": null,
"stdout_hash": null,
"stderr": "run_dbg-test_quit_01-30889cc.stderr",
"stderr_hash": "f5a660003a2da017d3ced437825a1e6f1c0c046d73cf68d183c92a40",
"stderr_hash": "b3dac87462f9f0650e5a6af68791137ca9d29f9a64139ba7718a9f96",
"returncode": 10
}
2 changes: 2 additions & 0 deletions tests/reference/run_dbg-test_quit_01-30889cc.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
File "tests/runtime_errors/test_quit_01.py", line 1
def test():
File "tests/runtime_errors/test_quit_01.py", line 4
test()
File "tests/runtime_errors/test_quit_01.py", line 2
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/run_dbg-test_raise_01-dfd86ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"stdout": null,
"stdout_hash": null,
"stderr": "run_dbg-test_raise_01-dfd86ca.stderr",
"stderr_hash": "073aae20bbe7cf78e116825e3e825365b07230972ff7bcb3a5dddb93",
"stderr_hash": "76085f527077a81ba6457af8f982a497038168f555ab4027d0d6340e",
"returncode": 1
}
2 changes: 2 additions & 0 deletions tests/reference/run_dbg-test_raise_01-dfd86ca.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
File "tests/runtime_errors/test_raise_01.py", line 1
def test():
File "tests/runtime_errors/test_raise_01.py", line 4
test()
File "tests/runtime_errors/test_raise_01.py", line 2
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new location info (main_program Program node info) is useless for LPython, but it is required for LFortran.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I knew this would be an issue. It's fine for now, we can refine this as we go. Possibly not doing so many indirections in LPython.

Expand Down