summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r--src/wasm/wasm-binary.cpp51
1 files changed, 28 insertions, 23 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index d7c052a9f..d4fda5915 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -398,8 +398,10 @@ void WasmBinaryWriter::writeFunctions() {
bool DWARF = Debug::hasDWARFSections(*getModule());
ModuleUtils::iterDefinedFunctions(*wasm, [&](Function* func) {
assert(binaryLocationTrackedExpressionsForFunc.empty());
- size_t sourceMapLocationsSizeAtFunctionStart = sourceMapLocations.size();
BYN_TRACE("write one at" << o.size() << std::endl);
+ // Do not smear any debug location from the previous function.
+ writeNoDebugLocation();
+ size_t sourceMapLocationsSizeAtFunctionStart = sourceMapLocations.size();
size_t sizePos = writeU32LEBPlaceholder();
size_t start = o.size();
BYN_TRACE("writing" << func->name << std::endl);
@@ -1373,6 +1375,28 @@ void WasmBinaryWriter::writeDebugLocation(const Function::DebugLocation& loc) {
lastDebugLocation = loc;
}
+void WasmBinaryWriter::writeNoDebugLocation() {
+ // Emit an indication that there is no debug location there (so that
+ // we do not get "smeared" with debug info from anything before or
+ // after us).
+ //
+ // We don't need to write repeated "no debug info" indications, as a
+ // single one is enough to make it clear that the debug information
+ // before us is valid no longer. We also don't need to write one if
+ // there is nothing before us.
+ if (!sourceMapLocations.empty() &&
+ sourceMapLocations.back().second != nullptr) {
+ sourceMapLocations.emplace_back(o.size(), nullptr);
+
+ // Initialize the state of debug info to indicate there is no current
+ // debug info relevant. This sets |lastDebugLocation| to a dummy value,
+ // so that later places with debug info can see that they differ from
+ // it (without this, if we had some debug info, then a nullptr for none,
+ // and then the same debug info, we could get confused).
+ initializeDebugInfo();
+ }
+}
+
void WasmBinaryWriter::writeDebugLocation(Expression* curr, Function* func) {
if (sourceMap) {
auto& debugLocations = func->debugLocations;
@@ -1381,25 +1405,8 @@ void WasmBinaryWriter::writeDebugLocation(Expression* curr, Function* func) {
// There is debug information here, write it out.
writeDebugLocation(iter->second);
} else {
- // This expression has no debug location. We need to emit an indication
- // of that (so that we do not get "smeared" with debug info from anything
- // before or after us).
- //
- // We don't need to write repeated "no debug info" indications, as a
- // single one is enough to make it clear that the debug information before
- // us is valid no longer. We also don't need to write one if there is
- // nothing before us.
- if (!sourceMapLocations.empty() &&
- sourceMapLocations.back().second != nullptr) {
- sourceMapLocations.emplace_back(o.size(), nullptr);
-
- // Initialize the state of debug info to indicate there is no current
- // debug info relevant. This sets |lastDebugLocation| to a dummy value,
- // so that later places with debug info can see that they differ from
- // it (without this, if we had some debug info, then a nullptr for none,
- // and then the same debug info, we could get confused).
- initializeDebugInfo();
- }
+ // This expression has no debug location.
+ writeNoDebugLocation();
}
}
// If this is an instruction in a function, and if the original wasm had
@@ -2687,12 +2694,11 @@ void WasmBinaryReader::readFunctions() {
readVars();
- std::swap(func->prologLocation, debugLocation);
+ func->prologLocation = debugLocation;
{
// process the function body
BYN_TRACE("processing function: " << i << std::endl);
nextLabel = 0;
- debugLocation.clear();
willBeIgnored = false;
// process body
assert(breakStack.empty());
@@ -2931,7 +2937,6 @@ void WasmBinaryReader::readNextDebugLocation() {
if (nextDebugPos == 0) {
// We reached the end of the source map; nothing left to read.
- debugLocation.clear();
return;
}