Debugging quality-of-life improvements (#810)

* Debugging quality-of-life improvements

- Use std::abort for `CHECK`/`FATAL` failures, which acts as a debugger breakpoint as well as automatically printing a stack trace.
- Re-enable printing continuations in `--trace` mode.
- Log the source location of each step in `--trace` mode.

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
This commit is contained in:
Geoff Romer
2021-09-08 09:25:16 -07:00
committed by GitHub
co-authored by Jon Meow
parent f931a8cead
commit 33dd9a873d
5 changed files with 56 additions and 60 deletions
+19 -39
View File
@@ -4,18 +4,31 @@
package(default_visibility = ["//executable_semantics:__pkg__"])
# These currently have to be a single build rule because of a dependency cycle
# in printing.
cc_library(
name = "action",
srcs = ["action.cpp"],
hdrs = ["action.h"],
name = "action_frame_and_value",
srcs = [
"action.cpp",
"frame.cpp",
"value.cpp",
],
hdrs = [
"action.h",
"frame.h",
"value.h",
],
deps = [
":address",
":dictionary",
":field_path",
":stack",
":value",
"//common:ostream",
"//executable_semantics/ast:expression",
"//executable_semantics/ast:function_definition",
"//executable_semantics/ast:statement",
"//executable_semantics/common:arena",
"//executable_semantics/common:error",
"@llvm-project//llvm:Support",
],
)
@@ -56,27 +69,13 @@ cc_library(
],
)
cc_library(
name = "frame",
srcs = ["frame.cpp"],
hdrs = ["frame.h"],
deps = [
":action",
":address",
":dictionary",
":stack",
"//common:ostream",
"@llvm-project//llvm:Support",
],
)
cc_library(
name = "heap",
srcs = ["heap.cpp"],
hdrs = ["heap.h"],
deps = [
":action_frame_and_value",
":address",
":value",
"//common:ostream",
"@llvm-project//llvm:Support",
],
@@ -91,11 +90,9 @@ cc_library(
"interpreter.h",
],
deps = [
":action",
":action_frame_and_value",
":address",
":frame",
":heap",
":value",
"//common:check",
"//common:ostream",
"//executable_semantics/ast:declaration",
@@ -129,20 +126,3 @@ cc_library(
"@llvm-project//llvm:Support",
],
)
cc_library(
name = "value",
srcs = ["value.cpp"],
hdrs = ["value.h"],
deps = [
":address",
":field_path",
":stack",
"//common:ostream",
"//executable_semantics/ast:function_definition",
"//executable_semantics/ast:statement",
"//executable_semantics/common:arena",
"//executable_semantics/common:error",
"@llvm-project//llvm:Support",
],
)
@@ -362,7 +362,8 @@ auto Interpreter::StepLvalue() -> Transition {
Ptr<Action> act = stack.Top()->todo.Top();
Ptr<const Expression> exp = cast<LValAction>(*act).Exp();
if (tracing_output) {
llvm::outs() << "--- step lvalue " << *exp << " --->\n";
llvm::outs() << "--- step lvalue " << *exp << " (" << exp->SourceLoc()
<< ") --->\n";
}
switch (exp->Tag()) {
case Expression::Kind::IdentifierExpression: {
@@ -449,7 +450,8 @@ auto Interpreter::StepExp() -> Transition {
Ptr<Action> act = stack.Top()->todo.Top();
Ptr<const Expression> exp = cast<ExpressionAction>(*act).Exp();
if (tracing_output) {
llvm::outs() << "--- step exp " << *exp << " --->\n";
llvm::outs() << "--- step exp " << *exp << " (" << exp->SourceLoc()
<< ") --->\n";
}
switch (exp->Tag()) {
case Expression::Kind::IndexExpression: {
@@ -647,7 +649,8 @@ auto Interpreter::StepPattern() -> Transition {
Ptr<Action> act = stack.Top()->todo.Top();
Ptr<const Pattern> pattern = cast<PatternAction>(*act).Pat();
if (tracing_output) {
llvm::outs() << "--- step pattern " << *pattern << " --->\n";
llvm::outs() << "--- step pattern " << *pattern << " ("
<< pattern->SourceLoc() << ") --->\n";
}
switch (pattern->Tag()) {
case Pattern::Kind::AutoPattern: {
@@ -745,7 +748,7 @@ auto Interpreter::StepStmt() -> Transition {
if (tracing_output) {
llvm::outs() << "--- step stmt ";
stmt->PrintDepth(1, llvm::outs());
llvm::outs() << " --->\n";
llvm::outs() << " (" << stmt->SourceLoc() << ") --->\n";
}
switch (stmt->Tag()) {
case Statement::Kind::Match: {
+9 -4
View File
@@ -9,6 +9,7 @@
#include "common/check.h"
#include "executable_semantics/common/arena.h"
#include "executable_semantics/common/error.h"
#include "executable_semantics/interpreter/frame.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Casting.h"
@@ -232,11 +233,15 @@ void Value::Print(llvm::raw_ostream& out) const {
case Value::Kind::VariableType:
out << cast<VariableType>(*this).Name();
break;
case Value::Kind::ContinuationValue:
out << "continuation";
// TODO: Find a way to print useful information about the continuation
// without creating a dependency cycle.
case Value::Kind::ContinuationValue: {
out << "{";
llvm::ListSeparator sep(" :: ");
for (Ptr<Frame> frame : cast<ContinuationValue>(*this).Stack()) {
out << sep << *frame;
}
out << "}";
break;
}
case Value::Kind::StringType:
out << "String";
break;