Skip to content

Debug info handling for new EH try-catch #3496

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
merged 12 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 21 additions & 0 deletions src/passes/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1890,6 +1890,21 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
}
}

// Prints debug info for a delimiter in an expression.
void printDebugDelimiterLocation(Expression* curr, Index i) {
if (currFunction && debugInfo) {
auto iter = currFunction->delimiterLocations.find(curr);
if (iter != currFunction->delimiterLocations.end()) {
auto& locations = iter->second;
Colors::grey(o);
o << ";; code offset: 0x" << std::hex << locations[i] << std::dec
<< '\n';
restoreNormalColor(o);
doIndent(o, indent);
}
}
}

void visit(Expression* curr) {
printDebugLocation(curr);
OverriddenVisitor<PrintSExpression>::visit(curr);
Expand Down Expand Up @@ -2008,6 +2023,10 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
printFullLine(curr->condition);
maybePrintImplicitBlock(curr->ifTrue, false);
if (curr->ifFalse) {
// Note: debug info here is not used as LLVM does not emit ifs, and since
// LLVM is the main source of DWARF, effectively we never encounter ifs
// with DWARF.
printDebugDelimiterLocation(curr, BinaryLocations::Else);
maybePrintImplicitBlock(curr->ifFalse, false);
}
decIndent();
Expand Down Expand Up @@ -2368,6 +2387,7 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
o << "\n";
for (size_t i = 0; i < curr->catchEvents.size(); i++) {
doIndent(o, indent);
printDebugDelimiterLocation(curr, i);
o << "(catch ";
printName(curr->catchEvents[i], o);
incIndent();
Expand All @@ -2377,6 +2397,7 @@ struct PrintSExpression : public OverriddenVisitor<PrintSExpression> {
}
if (curr->hasCatchAll()) {
doIndent(o, indent);
printDebugDelimiterLocation(curr, curr->catchEvents.size());
o << "(catch_all";
incIndent();
maybePrintImplicitBlock(curr->catchBodies.back(), true);
Expand Down
5 changes: 3 additions & 2 deletions src/wasm/wasm-binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2837,8 +2837,9 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) {
startPos - codeSectionLocation;
}
break;
case BinaryConsts::Catch:
case BinaryConsts::CatchAll: {
case BinaryConsts::Catch: {
// TODO: add CatchAll, but the value of the constant is identical to Else
// case BinaryConsts::CatchAll: {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can add CatchAll handling in case BinaryConsts::Else:? We will know if that is not an Else but a CatchAll if we encountered a try but not an end yet. But because control flow sturctures can be nested, we would need a stack to track this, something like I used as procesStack in #3494...?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, yeah, a stack seems unavoidable. Looks like we already have a control flow stack here, luckily, which I was able to use, PTAL.

curr = nullptr;
if (DWARF && currFunction) {
assert(!controlFlowStack.empty());
Expand Down
Loading