From 8171be8a66ffe63cf4845552b1a901645d08affd Mon Sep 17 00:00:00 2001 From: Yury Delendik Date: Wed, 26 Apr 2017 10:48:18 -0500 Subject: [PATCH] Extends wasm-as, wasm-dis and s2wasm to consume debug locations. --- src/asm2wasm.h | 4 +- src/passes/Print.cpp | 9 ++- src/s2wasm.h | 27 +++++++-- src/tools/wasm-as.cpp | 17 ++++++ src/tools/wasm-dis.cpp | 13 +++++ src/wasm-binary.h | 20 ++++++- src/wasm-s-parser.h | 20 ++++++- src/wasm.h | 4 +- src/wasm/wasm-binary.cpp | 50 ++++++++++++++++ src/wasm/wasm-s-parser.cpp | 58 +++++++++++++++++-- test/debugInfo.fromasm | 25 ++++---- test/debugInfo.fromasm.clamp | 25 ++++---- test/debugInfo.fromasm.clamp.no-opts | 29 +++++----- test/debugInfo.fromasm.clamp.no-opts.txtmap | 22 ++++--- test/debugInfo.fromasm.clamp.txtmap | 14 ++++- test/debugInfo.fromasm.imprecise | 25 ++++---- test/debugInfo.fromasm.imprecise.no-opts | 29 +++++----- ...debugInfo.fromasm.imprecise.no-opts.txtmap | 22 ++++--- test/debugInfo.fromasm.imprecise.txtmap | 13 ++++- test/debugInfo.fromasm.no-opts | 29 +++++----- test/debugInfo.fromasm.no-opts.txtmap | 22 ++++--- test/debugInfo.fromasm.txtmap | 14 ++++- test/dot_s/debug.wast | 4 ++ 23 files changed, 360 insertions(+), 135 deletions(-) diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 16e7c95e1e9..b8439bdbf8d 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -1382,13 +1382,13 @@ void Asm2WasmBuilder::processAsm(Ref ast) { while (i < expressionStack.size()) { exp = expressionStack[i]; if (debugLocations.count(exp) == 0) { - debugLocations[exp] = { fileIndex, lineNumber }; + debugLocations[exp] = { fileIndex, lineNumber, 0 }; break; } i++; } } else { - debugLocations[exp] = { fileIndex, lineNumber }; + debugLocations[exp] = { fileIndex, lineNumber, 0 }; } break; } diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 6aebd612bc9..95f60e5e2c3 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -45,6 +45,7 @@ struct PrintSExpression : public Visitor { Module* currModule = nullptr; Function* currFunction = nullptr; + Function::DebugLocation lastPrintedLocation; PrintSExpression(std::ostream& o) : o(o) { setMinify(false); @@ -58,8 +59,11 @@ struct PrintSExpression : public Visitor { auto iter = debugLocations.find(curr); if (iter != debugLocations.end()) { auto fileName = currModule->debugInfoFileNames[iter->second.fileIndex]; - o << ";; " << fileName << ":" << iter->second.lineNumber << '\n'; - doIndent(o, indent); + if (lastPrintedLocation != iter->second) { + lastPrintedLocation = iter->second; + o << ";;@ " << fileName << ":" << iter->second.lineNumber << ":" << iter->second.columnNumber << '\n'; + doIndent(o, indent); + } } } Visitor::visit(curr); @@ -599,6 +603,7 @@ struct PrintSExpression : public Visitor { } void visitFunction(Function *curr) { currFunction = curr; + lastPrintedLocation = { 0, 0, 0 }; printOpening(o, "func ", true); printName(curr->name); if (curr->type.is()) { diff --git a/src/s2wasm.h b/src/s2wasm.h index 6ba4750ec49..146e0bcfef2 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -44,6 +44,7 @@ class S2WasmBuilder { MixedArena* allocator; LinkerObject* linkerObj; std::unique_ptr symbolInfo; + std::unordered_map fileIndexMap; public: S2WasmBuilder(const char* input, bool debug) @@ -601,7 +602,9 @@ class S2WasmBuilder { size_t fileId = getInt(); skipWhitespace(); auto quoted = getQuoted(); - WASM_UNUSED(fileId); WASM_UNUSED(quoted); // TODO: use the fileId and quoted + uint32_t index = wasm->debugInfoFileNames.size(); + fileIndexMap[fileId] = index; + wasm->debugInfoFileNames.push_back(std::string(quoted.begin(), quoted.end())); s = strchr(s, '\n'); return; } @@ -665,22 +668,31 @@ class S2WasmBuilder { mustMatch(":"); + Function::DebugLocation debugLocation = {0,0,0}; + bool useDebugLocation = false; auto recordFile = [&]() { if (debug) dump("file"); size_t fileId = getInt(); skipWhitespace(); auto quoted = getQuoted(); - WASM_UNUSED(fileId); WASM_UNUSED(quoted); // TODO: use the fileId and quoted + uint32_t index = wasm->debugInfoFileNames.size(); + fileIndexMap[fileId] = index; + wasm->debugInfoFileNames.push_back(std::string(quoted.begin(), quoted.end())); s = strchr(s, '\n'); }; auto recordLoc = [&]() { if (debug) dump("loc"); size_t fileId = getInt(); skipWhitespace(); - size_t row = getInt(); + uint32_t row = getInt(); skipWhitespace(); - size_t column = getInt(); - WASM_UNUSED(fileId); WASM_UNUSED(row); WASM_UNUSED(column); // TODO: use the fileId, row and column + uint32_t column = getInt(); + auto iter = fileIndexMap.find(fileId); + if (iter == fileIndexMap.end()) { + abort_on("idx"); + } + useDebugLocation = true; + debugLocation = {iter->second, row, column}; s = strchr(s, '\n'); }; auto recordLabel = [&]() { @@ -746,7 +758,10 @@ class S2WasmBuilder { // parse body func->body = allocator->alloc(); std::vector bstack; - auto addToBlock = [&bstack](Expression* curr) { + auto addToBlock = [&](Expression* curr) { + if (useDebugLocation) { + func->debugLocations[curr] = debugLocation; + } Expression* last = bstack.back(); if (last->is()) { last = last->cast()->body; diff --git a/src/tools/wasm-as.cpp b/src/tools/wasm-as.cpp index 5bdf74b029b..c96e4d72340 100644 --- a/src/tools/wasm-as.cpp +++ b/src/tools/wasm-as.cpp @@ -30,6 +30,8 @@ using namespace wasm; int main(int argc, const char *argv[]) { bool debugInfo = false; std::string symbolMap; + std::string binaryMapFilename; + std::string binaryMapUrl; Options options("wasm-as", "Assemble a .wast (WebAssembly text format) into a .wasm (WebAssembly binary format)"); options.extra["validate"] = "wasm"; options @@ -51,6 +53,12 @@ int main(int argc, const char *argv[]) { .add("--debuginfo", "-g", "Emit names section and debug info", Options::Arguments::Zero, [&](Options *o, const std::string &arguments) { debugInfo = true; }) + .add("--binarymap-file", "-bm", "Emit binary map to the specified file", + Options::Arguments::One, + [&binaryMapFilename](Options *o, const std::string &argument) { binaryMapFilename = argument; }) + .add("--binarymap-url", "-bu", "Use specified string as binary map URL", + Options::Arguments::One, + [&binaryMapUrl](Options *o, const std::string &argument) { binaryMapUrl = argument; }) .add("--symbolmap", "-s", "Emit a symbol map (indexes => names)", Options::Arguments::One, [&](Options *o, const std::string &argument) { symbolMap = argument; }) @@ -87,12 +95,21 @@ int main(int argc, const char *argv[]) { BufferWithRandomAccess buffer(options.debug); WasmBinaryWriter writer(&wasm, buffer, options.debug); writer.setNamesSection(debugInfo); + std::unique_ptr binaryMapStream = nullptr; + if (binaryMapFilename.size()) { + binaryMapStream = make_unique(); + binaryMapStream->open(binaryMapFilename); + writer.setBinaryMap(binaryMapStream.get(), binaryMapUrl); + } if (symbolMap.size() > 0) writer.setSymbolMap(symbolMap); writer.write(); if (options.debug) std::cerr << "writing to output..." << std::endl; Output output(options.extra["output"], Flags::Binary, options.debug ? Flags::Debug : Flags::Release); buffer.writeTo(output); + if (binaryMapStream) { + binaryMapStream->close(); + } if (options.debug) std::cerr << "Done." << std::endl; } diff --git a/src/tools/wasm-dis.cpp b/src/tools/wasm-dis.cpp index 93c28691362..c33b4d333e0 100644 --- a/src/tools/wasm-dis.cpp +++ b/src/tools/wasm-dis.cpp @@ -28,6 +28,7 @@ using namespace cashew; using namespace wasm; int main(int argc, const char *argv[]) { + std::string binaryMapFilename; Options options("wasm-dis", "Un-assemble a .wasm (WebAssembly binary format) into a .wast (WebAssembly text format)"); options.add("--output", "-o", "Output file (stdout if not specified)", Options::Arguments::One, @@ -35,6 +36,9 @@ int main(int argc, const char *argv[]) { o->extra["output"] = argument; Colors::disable(); }) + .add("--binarymap-file", "-bm", "Consume binary map from the specified file to add location information", + Options::Arguments::One, + [&binaryMapFilename](Options *o, const std::string &argument) { binaryMapFilename = argument; }) .add_positional("INFILE", Options::Arguments::One, [](Options *o, const std::string &argument) { o->extra["infile"] = argument; @@ -46,8 +50,17 @@ int main(int argc, const char *argv[]) { if (options.debug) std::cerr << "parsing binary..." << std::endl; Module wasm; try { + std::unique_ptr binaryMapStream; WasmBinaryBuilder parser(wasm, input, options.debug); + if (binaryMapFilename.size()) { + binaryMapStream = make_unique(); + binaryMapStream->open(binaryMapFilename); + parser.setDebugLocations(binaryMapStream.get()); + } parser.read(); + if (binaryMapStream) { + binaryMapStream->close(); + } } catch (ParseException& p) { p.dump(std::cerr); Fatal() << "error in parsing wasm binary"; diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 27ed553a4fa..a6dcba8e31d 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -615,15 +615,17 @@ class WasmBinaryWriter : public Visitor { void recurse(Expression*& curr); std::vector breakStack; + Function::DebugLocation lastDebugLocation; void visit(Expression* curr) { if (binaryMap && currFunction) { // Dump the binaryMap debug info auto& debugLocations = currFunction->debugLocations; auto iter = debugLocations.find(curr); - if (iter != debugLocations.end()) { + if (iter != debugLocations.end() && iter->second != lastDebugLocation) { + lastDebugLocation = iter->second; auto fileName = wasm->debugInfoFileNames[iter->second.fileIndex]; - *binaryMap << o.size() << ":" << fileName << ":" <second.lineNumber << '\n'; + *binaryMap << o.size() << ":" << fileName << ":" << iter->second.lineNumber << ":" << iter->second.columnNumber << '\n'; } } Visitor::visit(curr); @@ -663,6 +665,8 @@ class WasmBinaryBuilder { MixedArena& allocator; std::vector& input; bool debug; + std::istream* binaryMap; + std::pair nextDebugLocation; size_t pos = 0; Index startIndex = -1; @@ -670,7 +674,7 @@ class WasmBinaryBuilder { std::set seenSections; public: - WasmBinaryBuilder(Module& wasm, std::vector& input, bool debug) : wasm(wasm), allocator(wasm.allocator), input(input), debug(debug) {} + WasmBinaryBuilder(Module& wasm, std::vector& input, bool debug) : wasm(wasm), allocator(wasm.allocator), input(input), debug(debug), binaryMap(nullptr), nextDebugLocation(0, {0,0,0}) {} void read(); void readUserSection(size_t payloadLen); @@ -759,6 +763,16 @@ class WasmBinaryBuilder { void readTableElements(); void readNames(size_t); + // Debug information reading helpers + void setDebugLocations(std::istream* binaryMap_) { + binaryMap = binaryMap_; + readNextDebugLocation(); + } + bool useDebugLocation; + Function::DebugLocation debugLocation; + std::unordered_map debugInfoFileIndices; + void readNextDebugLocation(); + // AST reading int depth = 0; // only for debugging diff --git a/src/wasm-s-parser.h b/src/wasm-s-parser.h index be1f6b6999f..4332f74af45 100644 --- a/src/wasm-s-parser.h +++ b/src/wasm-s-parser.h @@ -28,6 +28,16 @@ namespace wasm { +class SourceLocation +{ +public: + std::string filename; + uint32_t line; + uint32_t column; + SourceLocation(const std::string& filename_, uint32_t line_, uint32_t column_ = 0) + : filename(filename_), line(line_), column(column_) {} +}; + // // An element in an S-Expression: a list or a string // @@ -41,7 +51,7 @@ class Element { bool quoted_; public: - Element(MixedArena& allocator) : isList_(true), list_(allocator), line(-1), col(-1) {} + Element(MixedArena& allocator) : isList_(true), list_(allocator), line(-1), col(-1), loc(nullptr) {} bool isList() { return isList_; } bool isStr() { return !isList_; } @@ -49,6 +59,7 @@ class Element { bool quoted() { return isStr() && quoted_; } size_t line, col; + SourceLocation* loc; // list methods List& list(); @@ -61,14 +72,13 @@ class Element { cashew::IString str(); const char* c_str(); Element* setString(cashew::IString str__, bool dollared__, bool quoted__); - Element* setMetadata(size_t line_, size_t col_); + Element* setMetadata(size_t line_, size_t col_, SourceLocation* loc_); // printing friend std::ostream& operator<<(std::ostream& o, Element& e); void dump(); }; - // // Generic S-Expression parsing into lists // @@ -76,6 +86,7 @@ class SExpressionParser { char* input; size_t line; char* lineStart; + SourceLocation* loc; MixedArena allocator; @@ -87,6 +98,7 @@ class SExpressionParser { private: Element* parse(); void skipWhitespace(); + void parseDebugLocation(); Element* parseString(); }; @@ -102,6 +114,7 @@ class SExpressionWasmBuilder { int functionCounter; int globalCounter; std::map functionTypes; // we need to know function return types before we parse their contents + std::unordered_map debugInfoFileIndices; public: // Assumes control of and modifies the input. @@ -147,6 +160,7 @@ class SExpressionWasmBuilder { Expression* parseExpression(Element& s); private: + Expression* makeExpression(Element& s); Expression* makeBinary(Element& s, BinaryOp op, WasmType type); Expression* makeUnary(Element& s, UnaryOp op, WasmType type); Expression* makeSelect(Element& s); diff --git a/src/wasm.h b/src/wasm.h index 3caab9dbc52..dba08d92ead 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -527,7 +527,9 @@ class Function { std::map localIndices; struct DebugLocation { - uint32_t fileIndex, lineNumber; + uint32_t fileIndex, lineNumber, columnNumber; + bool operator==(const DebugLocation& other) const { return fileIndex == other.fileIndex && lineNumber == other.lineNumber && columnNumber == other.columnNumber; } + bool operator!=(const DebugLocation& other) const { return !(*this == other); } }; std::unordered_map debugLocations; diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index 47f1a925797..f3697048f8d 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -238,6 +238,7 @@ void WasmBinaryWriter::writeFunctions() { size_t start = o.size(); Function* function = wasm->functions[i].get(); currFunction = function; + lastDebugLocation = {0, 0, 0}; mappedLocals.clear(); numLocalsByType.clear(); if (debug) std::cerr << "writing" << function->name << std::endl; @@ -1353,6 +1354,7 @@ void WasmBinaryBuilder::readFunctions() { // process the function body if (debug) std::cerr << "processing function: " << i << std::endl; nextLabel = 0; + useDebugLocation = false; breaksToReturn = false; // process body assert(breakStack.empty()); @@ -1400,6 +1402,43 @@ void WasmBinaryBuilder::readExports() { } } +void WasmBinaryBuilder::readNextDebugLocation() { + if (binaryMap) { + std::string line; + while (std::getline(*binaryMap, line)) { + auto pos = line.begin(); + while (pos < line.end() && pos[0] != ':') pos++; + if (pos == line.end()) continue; + uint32_t position = atoi(std::string(line.begin(), pos).c_str()); + auto filenameStart = ++pos; + while (pos < line.end() && pos[0] != ':') pos++; + if (pos == line.end()) continue; + std::string file(filenameStart, pos); + auto iter = debugInfoFileIndices.find(file); + if (iter == debugInfoFileIndices.end()) { + Index index = wasm.debugInfoFileNames.size(); + wasm.debugInfoFileNames.push_back(file); + debugInfoFileIndices[file] = index; + } + uint32_t fileIndex = debugInfoFileIndices[file]; + auto lineNumberStart = ++pos; + while (pos < line.end() && pos[0] != ':') pos++; + if (pos == line.end()) { + // old format + uint32_t lineNumber = atoi(std::string(lineNumberStart, line.end()).c_str()); + nextDebugLocation = {position, {fileIndex, lineNumber, 0}}; + return; + } + uint32_t lineNumber = atoi(std::string(lineNumberStart, pos).c_str()); + auto columnNumberStart = ++pos; + uint32_t columnNumber = atoi(std::string(columnNumberStart, line.end()).c_str()); + + nextDebugLocation = {position, {fileIndex, lineNumber, columnNumber}}; + return; + } + nextDebugLocation.first = 0; + } +} Expression* WasmBinaryBuilder::readExpression() { assert(depth == 0); processExpressions(); @@ -1638,6 +1677,15 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) { throw ParseException("Reached function end without seeing End opcode"); } if (debug) std::cerr << "zz recurse into " << ++depth << " at " << pos << std::endl; + if (nextDebugLocation.first) { + while (nextDebugLocation.first && nextDebugLocation.first <= pos) { + if (nextDebugLocation.first < pos) + std::cerr << "skipping debug location info for " << nextDebugLocation.first << std::endl; + debugLocation = nextDebugLocation.second; + useDebugLocation = currFunction; // using only for function expressions + readNextDebugLocation(); + } + } uint8_t code = getInt8(); if (debug) std::cerr << "readExpression seeing " << (int)code << std::endl; switch (code) { @@ -1672,6 +1720,8 @@ BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) { throw ParseException("bad node code " + std::to_string(code)); } } + if (useDebugLocation && curr) + currFunction->debugLocations[curr] = debugLocation; if (debug) std::cerr << "zz recurse from " << depth-- << " at " << pos << std::endl; return BinaryConsts::ASTNodes(code); } diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index 9b053d5b8ce..2c78ac93691 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -71,9 +71,10 @@ Element* Element::setString(IString str__, bool dollared__, bool quoted__) { return this; } -Element* Element::setMetadata(size_t line_, size_t col_) { +Element* Element::setMetadata(size_t line_, size_t col_, SourceLocation* loc_) { line = line_; col = col_; + loc = loc_; return this; } @@ -93,7 +94,7 @@ void Element::dump() { } -SExpressionParser::SExpressionParser(char* input) : input(input) { +SExpressionParser::SExpressionParser(char* input) : input(input), loc(nullptr) { root = nullptr; line = 1; lineStart = input; @@ -104,6 +105,7 @@ SExpressionParser::SExpressionParser(char* input) : input(input) { Element* SExpressionParser::parse() { std::vector stack; + std::vector stackLocs; Element *curr = allocator.alloc(); while (1) { skipWhitespace(); @@ -111,7 +113,9 @@ Element* SExpressionParser::parse() { if (input[0] == '(') { input++; stack.push_back(curr); - curr = allocator.alloc()->setMetadata(line, input - lineStart - 1); + curr = allocator.alloc()->setMetadata(line, input - lineStart - 1, loc); + stackLocs.push_back(loc); + assert(stack.size() == stackLocs.size()); } else if (input[0] == ')') { input++; auto last = curr; @@ -119,7 +123,10 @@ Element* SExpressionParser::parse() { throw ParseException("s-expr stack empty"); } curr = stack.back(); + assert(stack.size() == stackLocs.size()); stack.pop_back(); + loc = stackLocs.back(); + stackLocs.pop_back(); curr->list().push_back(last); } else { curr->list().push_back(parseString()); @@ -129,6 +136,27 @@ Element* SExpressionParser::parse() { return curr; } +void SExpressionParser::parseDebugLocation() { + // Extracting debug location (if valid) + char* debugLoc = input + 3; // skipping ";;@" + while (debugLoc[0] && debugLoc[0] == ' ') debugLoc++; + char* debugLocEnd = debugLoc; + while (debugLocEnd[0] && debugLocEnd[0] != '\n') debugLocEnd++; + char* pos = debugLoc; + while (pos < debugLocEnd && pos[0] != ':') pos++; + if (pos >= debugLocEnd) + return; // no line number + std::string name(debugLoc, pos); + char* lineStart = ++pos; + while (pos < debugLocEnd && pos[0] != ':') pos++; + std::string lineStr(lineStart, pos); + if (pos >= debugLocEnd) + return; // no column number + std::string colStr(++pos, debugLocEnd); + void* buf = allocator.allocSpace(sizeof(SourceLocation)); + loc = new (buf) SourceLocation(name, atoi(lineStr.c_str()), atoi(colStr.c_str())); +} + void SExpressionParser::skipWhitespace() { while (1) { while (isspace(input[0])) { @@ -139,6 +167,9 @@ void SExpressionParser::skipWhitespace() { input++; } if (input[0] == ';' && input[1] == ';') { + if (input[2] == '@') { + parseDebugLocation(); + } while (input[0] && input[0] != '\n') input++; line++; lineStart = ++input; @@ -198,13 +229,13 @@ Element* SExpressionParser::parseString() { input++; } input++; - return allocator.alloc()->setString(IString(str.c_str(), false), dollared, true)->setMetadata(line, start - lineStart); + return allocator.alloc()->setString(IString(str.c_str(), false), dollared, true)->setMetadata(line, start - lineStart, loc); } while (input[0] && !isspace(input[0]) && input[0] != ')' && input[0] != '(' && input[0] != ';') input++; if (start == input) throw ParseException("expected string", line, input - lineStart); char temp = input[0]; input[0] = 0; - auto ret = allocator.alloc()->setString(IString(start, false), dollared, false)->setMetadata(line, start - lineStart); + auto ret = allocator.alloc()->setString(IString(start, false), dollared, false)->setMetadata(line, start - lineStart, loc); input[0] = temp; return ret; } @@ -583,6 +614,23 @@ WasmType SExpressionWasmBuilder::stringToWasmType(const char* str, bool allowErr } Expression* SExpressionWasmBuilder::parseExpression(Element& s) { + Expression* result = makeExpression(s); + if (s.loc) { + std::string& file = s.loc->filename; + auto& debugInfoFileNames = wasm.debugInfoFileNames; + auto iter = debugInfoFileIndices.find(file); + if (iter == debugInfoFileIndices.end()) { + Index index = debugInfoFileNames.size(); + debugInfoFileNames.push_back(file); + debugInfoFileIndices[file] = index; + } + uint32_t fileIndex = debugInfoFileIndices[file]; + currFunction->debugLocations[result] = {fileIndex, s.loc->line, s.loc->column}; + } + return result; +} + +Expression* SExpressionWasmBuilder::makeExpression(Element& s) { IString id = s[0]->str(); const char *str = id.str; const char *dot = strchr(str, '.'); diff --git a/test/debugInfo.fromasm b/test/debugInfo.fromasm index 84fb4aece99..7aa584c4371 100644 --- a/test/debugInfo.fromasm +++ b/test/debugInfo.fromasm @@ -11,21 +11,21 @@ (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) (func $add (param $0 i32) (param $1 i32) (result i32) - ;; tests/other_file.cpp:314159 + ;;@ tests/other_file.cpp:314159:0 (i32.add (get_local $1) (get_local $1) ) ) (func $ret (param $0 i32) (result i32) - ;; return.cpp:50 + ;;@ return.cpp:50:0 (set_local $0 (i32.shl (get_local $0) (i32.const 1) ) ) - ;; return.cpp:100 + ;;@ return.cpp:100:0 (i32.add (get_local $0) (i32.const 1) @@ -42,21 +42,21 @@ ) ) (func $opts (param $0 i32) (param $1 i32) (result i32) - ;; even-opted.cpp:1 + ;;@ even-opted.cpp:1:0 (set_local $0 (i32.add (get_local $0) (get_local $1) ) ) - ;; even-opted.cpp:2 + ;;@ even-opted.cpp:2:0 (set_local $1 (i32.shr_s (get_local $1) (get_local $0) ) ) - ;; even-opted.cpp:3 + ;;@ even-opted.cpp:3:0 (i32.add (call $i32s-rem (get_local $0) @@ -71,7 +71,7 @@ (local $3 i32) (local $4 i32) (if - ;; fib.c:3 + ;;@ fib.c:3:0 (i32.gt_s (get_local $0) (i32.const 0) @@ -91,21 +91,21 @@ (set_local $1 (i32.const 1) ) - ;; fib.c:8 + ;;@ fib.c:8:0 (return (get_local $1) ) ) ) (loop $while-in - ;; fib.c:4 + ;;@ fib.c:4:0 (set_local $1 (i32.add (get_local $3) (get_local $4) ) ) - ;; fib.c:3 + ;;@ fib.c:3:0 (set_local $2 (i32.add (get_local $2) @@ -113,7 +113,6 @@ ) ) (if - ;; fib.c:3 (i32.ne (get_local $2) (get_local $0) @@ -129,7 +128,7 @@ ) ) ) - ;; fib.c:8 + ;;@ fib.c:8:0 (get_local $1) ) (func $switch_reach (param $0 i32) (result i32) @@ -189,7 +188,7 @@ (get_local $0) ) ) - ;; /tmp/emscripten_test_binaryen2_28hnAe/src.c:59950 + ;;@ /tmp/emscripten_test_binaryen2_28hnAe/src.c:59950:0 (get_local $1) ) ) diff --git a/test/debugInfo.fromasm.clamp b/test/debugInfo.fromasm.clamp index 84fb4aece99..7aa584c4371 100644 --- a/test/debugInfo.fromasm.clamp +++ b/test/debugInfo.fromasm.clamp @@ -11,21 +11,21 @@ (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) (func $add (param $0 i32) (param $1 i32) (result i32) - ;; tests/other_file.cpp:314159 + ;;@ tests/other_file.cpp:314159:0 (i32.add (get_local $1) (get_local $1) ) ) (func $ret (param $0 i32) (result i32) - ;; return.cpp:50 + ;;@ return.cpp:50:0 (set_local $0 (i32.shl (get_local $0) (i32.const 1) ) ) - ;; return.cpp:100 + ;;@ return.cpp:100:0 (i32.add (get_local $0) (i32.const 1) @@ -42,21 +42,21 @@ ) ) (func $opts (param $0 i32) (param $1 i32) (result i32) - ;; even-opted.cpp:1 + ;;@ even-opted.cpp:1:0 (set_local $0 (i32.add (get_local $0) (get_local $1) ) ) - ;; even-opted.cpp:2 + ;;@ even-opted.cpp:2:0 (set_local $1 (i32.shr_s (get_local $1) (get_local $0) ) ) - ;; even-opted.cpp:3 + ;;@ even-opted.cpp:3:0 (i32.add (call $i32s-rem (get_local $0) @@ -71,7 +71,7 @@ (local $3 i32) (local $4 i32) (if - ;; fib.c:3 + ;;@ fib.c:3:0 (i32.gt_s (get_local $0) (i32.const 0) @@ -91,21 +91,21 @@ (set_local $1 (i32.const 1) ) - ;; fib.c:8 + ;;@ fib.c:8:0 (return (get_local $1) ) ) ) (loop $while-in - ;; fib.c:4 + ;;@ fib.c:4:0 (set_local $1 (i32.add (get_local $3) (get_local $4) ) ) - ;; fib.c:3 + ;;@ fib.c:3:0 (set_local $2 (i32.add (get_local $2) @@ -113,7 +113,6 @@ ) ) (if - ;; fib.c:3 (i32.ne (get_local $2) (get_local $0) @@ -129,7 +128,7 @@ ) ) ) - ;; fib.c:8 + ;;@ fib.c:8:0 (get_local $1) ) (func $switch_reach (param $0 i32) (result i32) @@ -189,7 +188,7 @@ (get_local $0) ) ) - ;; /tmp/emscripten_test_binaryen2_28hnAe/src.c:59950 + ;;@ /tmp/emscripten_test_binaryen2_28hnAe/src.c:59950:0 (get_local $1) ) ) diff --git a/test/debugInfo.fromasm.clamp.no-opts b/test/debugInfo.fromasm.clamp.no-opts index 9e3050695ed..054226a3a3c 100644 --- a/test/debugInfo.fromasm.clamp.no-opts +++ b/test/debugInfo.fromasm.clamp.no-opts @@ -11,15 +11,15 @@ (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) (func $add (param $x i32) (param $y i32) (result i32) - ;; tests/hello_world.c:5 + ;;@ tests/hello_world.c:5:0 (set_local $x (get_local $x) ) - ;; tests/hello_world.c:6 + ;;@ tests/hello_world.c:6:0 (set_local $y (get_local $y) ) - ;; tests/other_file.cpp:314159 + ;;@ tests/other_file.cpp:314159:0 (set_local $x (get_local $y) ) @@ -31,14 +31,14 @@ ) ) (func $ret (param $x i32) (result i32) - ;; return.cpp:50 + ;;@ return.cpp:50:0 (set_local $x (i32.shl (get_local $x) (i32.const 1) ) ) - ;; return.cpp:100 + ;;@ return.cpp:100:0 (return (i32.add (get_local $x) @@ -59,21 +59,21 @@ ) ) (func $opts (param $x i32) (param $y i32) (result i32) - ;; even-opted.cpp:1 + ;;@ even-opted.cpp:1:0 (set_local $x (i32.add (get_local $x) (get_local $y) ) ) - ;; even-opted.cpp:2 + ;;@ even-opted.cpp:2:0 (set_local $y (i32.shr_s (get_local $y) (get_local $x) ) ) - ;; even-opted.cpp:3 + ;;@ even-opted.cpp:3:0 (set_local $x (call $i32s-rem (get_local $x) @@ -102,7 +102,7 @@ (set_local $sp (get_global $STACKTOP) ) - ;; fib.c:3 + ;;@ fib.c:3:0 (set_local $$1 (i32.gt_s (get_local $$0) @@ -126,7 +126,7 @@ (set_local $$$0$lcssa (i32.const 1) ) - ;; fib.c:8 + ;;@ fib.c:8:0 (return (get_local $$$0$lcssa) ) @@ -134,21 +134,20 @@ ) (loop $while-in (block $while-out - ;; fib.c:4 + ;;@ fib.c:4:0 (set_local $$2 (i32.add (get_local $$$019) (get_local $$$01518) ) ) - ;; fib.c:3 + ;;@ fib.c:3:0 (set_local $$3 (i32.add (get_local $$$01617) (i32.const 1) ) ) - ;; fib.c:3 (set_local $$exitcond (i32.eq (get_local $$3) @@ -181,7 +180,7 @@ (br $while-in) ) ) - ;; fib.c:8 + ;;@ fib.c:8:0 (return (get_local $$$0$lcssa) ) @@ -278,7 +277,7 @@ (get_local $$p) ) ) - ;; /tmp/emscripten_test_binaryen2_28hnAe/src.c:59950 + ;;@ /tmp/emscripten_test_binaryen2_28hnAe/src.c:59950:0 (return (get_local $$rc$0) ) diff --git a/test/debugInfo.fromasm.clamp.no-opts.txtmap b/test/debugInfo.fromasm.clamp.no-opts.txtmap index eec2e7bd354..f7b8c313154 100644 --- a/test/debugInfo.fromasm.clamp.no-opts.txtmap +++ b/test/debugInfo.fromasm.clamp.no-opts.txtmap @@ -1,8 +1,14 @@ -164:tests/hello_world.c:5 -168:tests/hello_world.c:6 -172:tests/other_file.cpp:314159 -194:return.cpp:50 -201:return.cpp:100 -241:even-opted.cpp:1 -248:even-opted.cpp:2 -255:even-opted.cpp:3 +199:tests/hello_world.c:5:0 +203:tests/hello_world.c:6:0 +207:tests/other_file.cpp:314159:0 +229:return.cpp:50:0 +236:return.cpp:100:0 +275:even-opted.cpp:1:0 +282:even-opted.cpp:2:0 +289:even-opted.cpp:3:0 +321:fib.c:3:0 +349:fib.c:8:0 +357:fib.c:4:0 +364:fib.c:3:0 +410:fib.c:8:0 +556:/tmp/emscripten_test_binaryen2_28hnAe/src.c:59950:0 diff --git a/test/debugInfo.fromasm.clamp.txtmap b/test/debugInfo.fromasm.clamp.txtmap index bb25b4d8d30..5ab814a0d4a 100644 --- a/test/debugInfo.fromasm.clamp.txtmap +++ b/test/debugInfo.fromasm.clamp.txtmap @@ -1,2 +1,12 @@ -211:even-opted.cpp:2 -223:even-opted.cpp:3 +185:tests/other_file.cpp:314159:0 +199:return.cpp:50:0 +206:return.cpp:100:0 +241:even-opted.cpp:1:0 +248:even-opted.cpp:2:0 +255:even-opted.cpp:3:0 +276:fib.c:3:0 +300:fib.c:8:0 +306:fib.c:4:0 +313:fib.c:3:0 +339:fib.c:8:0 +436:/tmp/emscripten_test_binaryen2_28hnAe/src.c:59950:0 diff --git a/test/debugInfo.fromasm.imprecise b/test/debugInfo.fromasm.imprecise index 4919d624dab..638911cfc1c 100644 --- a/test/debugInfo.fromasm.imprecise +++ b/test/debugInfo.fromasm.imprecise @@ -10,42 +10,42 @@ (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) (func $add (param $0 i32) (param $1 i32) (result i32) - ;; tests/other_file.cpp:314159 + ;;@ tests/other_file.cpp:314159:0 (i32.add (get_local $1) (get_local $1) ) ) (func $ret (param $0 i32) (result i32) - ;; return.cpp:50 + ;;@ return.cpp:50:0 (set_local $0 (i32.shl (get_local $0) (i32.const 1) ) ) - ;; return.cpp:100 + ;;@ return.cpp:100:0 (i32.add (get_local $0) (i32.const 1) ) ) (func $opts (param $0 i32) (param $1 i32) (result i32) - ;; even-opted.cpp:1 + ;;@ even-opted.cpp:1:0 (set_local $0 (i32.add (get_local $0) (get_local $1) ) ) - ;; even-opted.cpp:2 + ;;@ even-opted.cpp:2:0 (set_local $1 (i32.shr_s (get_local $1) (get_local $0) ) ) - ;; even-opted.cpp:3 + ;;@ even-opted.cpp:3:0 (i32.add (i32.rem_s (get_local $0) @@ -60,7 +60,7 @@ (local $3 i32) (local $4 i32) (if - ;; fib.c:3 + ;;@ fib.c:3:0 (i32.gt_s (get_local $0) (i32.const 0) @@ -80,21 +80,21 @@ (set_local $1 (i32.const 1) ) - ;; fib.c:8 + ;;@ fib.c:8:0 (return (get_local $1) ) ) ) (loop $while-in - ;; fib.c:4 + ;;@ fib.c:4:0 (set_local $1 (i32.add (get_local $3) (get_local $4) ) ) - ;; fib.c:3 + ;;@ fib.c:3:0 (set_local $2 (i32.add (get_local $2) @@ -102,7 +102,6 @@ ) ) (if - ;; fib.c:3 (i32.ne (get_local $2) (get_local $0) @@ -118,7 +117,7 @@ ) ) ) - ;; fib.c:8 + ;;@ fib.c:8:0 (get_local $1) ) (func $switch_reach (param $0 i32) (result i32) @@ -178,7 +177,7 @@ (get_local $0) ) ) - ;; /tmp/emscripten_test_binaryen2_28hnAe/src.c:59950 + ;;@ /tmp/emscripten_test_binaryen2_28hnAe/src.c:59950:0 (get_local $1) ) ) diff --git a/test/debugInfo.fromasm.imprecise.no-opts b/test/debugInfo.fromasm.imprecise.no-opts index 4bea2c35520..1ec751ef4d0 100644 --- a/test/debugInfo.fromasm.imprecise.no-opts +++ b/test/debugInfo.fromasm.imprecise.no-opts @@ -11,15 +11,15 @@ (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) (func $add (param $x i32) (param $y i32) (result i32) - ;; tests/hello_world.c:5 + ;;@ tests/hello_world.c:5:0 (set_local $x (get_local $x) ) - ;; tests/hello_world.c:6 + ;;@ tests/hello_world.c:6:0 (set_local $y (get_local $y) ) - ;; tests/other_file.cpp:314159 + ;;@ tests/other_file.cpp:314159:0 (set_local $x (get_local $y) ) @@ -31,14 +31,14 @@ ) ) (func $ret (param $x i32) (result i32) - ;; return.cpp:50 + ;;@ return.cpp:50:0 (set_local $x (i32.shl (get_local $x) (i32.const 1) ) ) - ;; return.cpp:100 + ;;@ return.cpp:100:0 (return (i32.add (get_local $x) @@ -47,21 +47,21 @@ ) ) (func $opts (param $x i32) (param $y i32) (result i32) - ;; even-opted.cpp:1 + ;;@ even-opted.cpp:1:0 (set_local $x (i32.add (get_local $x) (get_local $y) ) ) - ;; even-opted.cpp:2 + ;;@ even-opted.cpp:2:0 (set_local $y (i32.shr_s (get_local $y) (get_local $x) ) ) - ;; even-opted.cpp:3 + ;;@ even-opted.cpp:3:0 (set_local $x (i32.rem_s (get_local $x) @@ -90,7 +90,7 @@ (set_local $sp (get_global $STACKTOP) ) - ;; fib.c:3 + ;;@ fib.c:3:0 (set_local $$1 (i32.gt_s (get_local $$0) @@ -114,7 +114,7 @@ (set_local $$$0$lcssa (i32.const 1) ) - ;; fib.c:8 + ;;@ fib.c:8:0 (return (get_local $$$0$lcssa) ) @@ -122,21 +122,20 @@ ) (loop $while-in (block $while-out - ;; fib.c:4 + ;;@ fib.c:4:0 (set_local $$2 (i32.add (get_local $$$019) (get_local $$$01518) ) ) - ;; fib.c:3 + ;;@ fib.c:3:0 (set_local $$3 (i32.add (get_local $$$01617) (i32.const 1) ) ) - ;; fib.c:3 (set_local $$exitcond (i32.eq (get_local $$3) @@ -169,7 +168,7 @@ (br $while-in) ) ) - ;; fib.c:8 + ;;@ fib.c:8:0 (return (get_local $$$0$lcssa) ) @@ -266,7 +265,7 @@ (get_local $$p) ) ) - ;; /tmp/emscripten_test_binaryen2_28hnAe/src.c:59950 + ;;@ /tmp/emscripten_test_binaryen2_28hnAe/src.c:59950:0 (return (get_local $$rc$0) ) diff --git a/test/debugInfo.fromasm.imprecise.no-opts.txtmap b/test/debugInfo.fromasm.imprecise.no-opts.txtmap index 00a07f11cd0..25ae6055e50 100644 --- a/test/debugInfo.fromasm.imprecise.no-opts.txtmap +++ b/test/debugInfo.fromasm.imprecise.no-opts.txtmap @@ -1,8 +1,14 @@ -163:tests/hello_world.c:5 -167:tests/hello_world.c:6 -171:tests/other_file.cpp:314159 -193:return.cpp:50 -200:return.cpp:100 -219:even-opted.cpp:1 -226:even-opted.cpp:2 -233:even-opted.cpp:3 +198:tests/hello_world.c:5:0 +202:tests/hello_world.c:6:0 +206:tests/other_file.cpp:314159:0 +228:return.cpp:50:0 +235:return.cpp:100:0 +253:even-opted.cpp:1:0 +260:even-opted.cpp:2:0 +267:even-opted.cpp:3:0 +298:fib.c:3:0 +326:fib.c:8:0 +334:fib.c:4:0 +341:fib.c:3:0 +387:fib.c:8:0 +533:/tmp/emscripten_test_binaryen2_28hnAe/src.c:59950:0 diff --git a/test/debugInfo.fromasm.imprecise.txtmap b/test/debugInfo.fromasm.imprecise.txtmap index c9f177cc8be..89e0f75c13a 100644 --- a/test/debugInfo.fromasm.imprecise.txtmap +++ b/test/debugInfo.fromasm.imprecise.txtmap @@ -1 +1,12 @@ -190:even-opted.cpp:2 +184:tests/other_file.cpp:314159:0 +198:return.cpp:50:0 +205:return.cpp:100:0 +220:even-opted.cpp:1:0 +227:even-opted.cpp:2:0 +234:even-opted.cpp:3:0 +254:fib.c:3:0 +278:fib.c:8:0 +284:fib.c:4:0 +291:fib.c:3:0 +317:fib.c:8:0 +414:/tmp/emscripten_test_binaryen2_28hnAe/src.c:59950:0 diff --git a/test/debugInfo.fromasm.no-opts b/test/debugInfo.fromasm.no-opts index 9e3050695ed..054226a3a3c 100644 --- a/test/debugInfo.fromasm.no-opts +++ b/test/debugInfo.fromasm.no-opts @@ -11,15 +11,15 @@ (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) (func $add (param $x i32) (param $y i32) (result i32) - ;; tests/hello_world.c:5 + ;;@ tests/hello_world.c:5:0 (set_local $x (get_local $x) ) - ;; tests/hello_world.c:6 + ;;@ tests/hello_world.c:6:0 (set_local $y (get_local $y) ) - ;; tests/other_file.cpp:314159 + ;;@ tests/other_file.cpp:314159:0 (set_local $x (get_local $y) ) @@ -31,14 +31,14 @@ ) ) (func $ret (param $x i32) (result i32) - ;; return.cpp:50 + ;;@ return.cpp:50:0 (set_local $x (i32.shl (get_local $x) (i32.const 1) ) ) - ;; return.cpp:100 + ;;@ return.cpp:100:0 (return (i32.add (get_local $x) @@ -59,21 +59,21 @@ ) ) (func $opts (param $x i32) (param $y i32) (result i32) - ;; even-opted.cpp:1 + ;;@ even-opted.cpp:1:0 (set_local $x (i32.add (get_local $x) (get_local $y) ) ) - ;; even-opted.cpp:2 + ;;@ even-opted.cpp:2:0 (set_local $y (i32.shr_s (get_local $y) (get_local $x) ) ) - ;; even-opted.cpp:3 + ;;@ even-opted.cpp:3:0 (set_local $x (call $i32s-rem (get_local $x) @@ -102,7 +102,7 @@ (set_local $sp (get_global $STACKTOP) ) - ;; fib.c:3 + ;;@ fib.c:3:0 (set_local $$1 (i32.gt_s (get_local $$0) @@ -126,7 +126,7 @@ (set_local $$$0$lcssa (i32.const 1) ) - ;; fib.c:8 + ;;@ fib.c:8:0 (return (get_local $$$0$lcssa) ) @@ -134,21 +134,20 @@ ) (loop $while-in (block $while-out - ;; fib.c:4 + ;;@ fib.c:4:0 (set_local $$2 (i32.add (get_local $$$019) (get_local $$$01518) ) ) - ;; fib.c:3 + ;;@ fib.c:3:0 (set_local $$3 (i32.add (get_local $$$01617) (i32.const 1) ) ) - ;; fib.c:3 (set_local $$exitcond (i32.eq (get_local $$3) @@ -181,7 +180,7 @@ (br $while-in) ) ) - ;; fib.c:8 + ;;@ fib.c:8:0 (return (get_local $$$0$lcssa) ) @@ -278,7 +277,7 @@ (get_local $$p) ) ) - ;; /tmp/emscripten_test_binaryen2_28hnAe/src.c:59950 + ;;@ /tmp/emscripten_test_binaryen2_28hnAe/src.c:59950:0 (return (get_local $$rc$0) ) diff --git a/test/debugInfo.fromasm.no-opts.txtmap b/test/debugInfo.fromasm.no-opts.txtmap index eec2e7bd354..f7b8c313154 100644 --- a/test/debugInfo.fromasm.no-opts.txtmap +++ b/test/debugInfo.fromasm.no-opts.txtmap @@ -1,8 +1,14 @@ -164:tests/hello_world.c:5 -168:tests/hello_world.c:6 -172:tests/other_file.cpp:314159 -194:return.cpp:50 -201:return.cpp:100 -241:even-opted.cpp:1 -248:even-opted.cpp:2 -255:even-opted.cpp:3 +199:tests/hello_world.c:5:0 +203:tests/hello_world.c:6:0 +207:tests/other_file.cpp:314159:0 +229:return.cpp:50:0 +236:return.cpp:100:0 +275:even-opted.cpp:1:0 +282:even-opted.cpp:2:0 +289:even-opted.cpp:3:0 +321:fib.c:3:0 +349:fib.c:8:0 +357:fib.c:4:0 +364:fib.c:3:0 +410:fib.c:8:0 +556:/tmp/emscripten_test_binaryen2_28hnAe/src.c:59950:0 diff --git a/test/debugInfo.fromasm.txtmap b/test/debugInfo.fromasm.txtmap index bb25b4d8d30..5ab814a0d4a 100644 --- a/test/debugInfo.fromasm.txtmap +++ b/test/debugInfo.fromasm.txtmap @@ -1,2 +1,12 @@ -211:even-opted.cpp:2 -223:even-opted.cpp:3 +185:tests/other_file.cpp:314159:0 +199:return.cpp:50:0 +206:return.cpp:100:0 +241:even-opted.cpp:1:0 +248:even-opted.cpp:2:0 +255:even-opted.cpp:3:0 +276:fib.c:3:0 +300:fib.c:8:0 +306:fib.c:4:0 +313:fib.c:3:0 +339:fib.c:8:0 +436:/tmp/emscripten_test_binaryen2_28hnAe/src.c:59950:0 diff --git a/test/dot_s/debug.wast b/test/dot_s/debug.wast index aa4f34d9e71..0cc0ae20c9e 100644 --- a/test/dot_s/debug.wast +++ b/test/dot_s/debug.wast @@ -18,18 +18,21 @@ ) (block $label$0 (loop $label$1 + ;;@ fib.c:3:17 (set_local $2 (i32.add (get_local $2) (i32.const 1) ) ) + ;;@ fib.c:3:3 (br_if $label$0 (i32.ge_s (get_local $2) (get_local $0) ) ) + ;;@ fib.c:4:11 (set_local $1 (i32.add (get_local $4) @@ -45,6 +48,7 @@ (br $label$1) ) ) + ;;@ fib.c:6:3 (return (get_local $4) )