Skip to content

Commit c572806

Browse files
dschuffyurydelendik
authored andcommitted
debuginfo experiment
1 parent 2ddb7cb commit c572806

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/tools/asm2wasm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ int main(int argc, const char *argv[]) {
133133

134134
Asm2WasmPreProcessor pre;
135135
// wasm binaries can contain a names section, but not full debug info
136-
pre.debugInfo = passOptions.debugInfo && !emitBinary;
136+
pre.debugInfo = passOptions.debugInfo;
137137
auto input(
138138
read_file<std::vector<char>>(options.extra["infile"], Flags::Text, options.debug ? Flags::Debug : Flags::Release));
139139
char *start = pre.process(input.data());

src/wasm-binary.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ inline S32LEB binaryWasmType(WasmType type) {
534534
class WasmBinaryWriter : public Visitor<WasmBinaryWriter, void> {
535535
Module* wasm;
536536
BufferWithRandomAccess& o;
537+
Function* currFunction = nullptr;
537538
bool debug;
538539
bool debugInfo = true;
539540
std::string symbolMap;
@@ -607,6 +608,19 @@ class WasmBinaryWriter : public Visitor<WasmBinaryWriter, void> {
607608
void recurse(Expression*& curr);
608609
std::vector<Name> breakStack;
609610

611+
void visit(Expression* curr) {
612+
if (debugInfo && currFunction) {
613+
// show an annotation, if there is one
614+
auto& debugLocations = currFunction->debugLocations;
615+
auto iter = debugLocations.find(curr);
616+
if (iter != debugLocations.end()) {
617+
auto fileName = wasm->debugInfoFileNames[iter->second.fileIndex];
618+
std::cout << std::hex <<o.size() << ":" << fileName << ":" << std::dec <<iter->second.lineNumber << '\n';
619+
}
620+
}
621+
Visitor<WasmBinaryWriter>::visit(curr);
622+
}
623+
610624
void visitBlock(Block *curr);
611625
// emits a node, but if it is a block with no name, emit a list of its contents
612626
void recursePossibleBlockContents(Expression* curr);

src/wasm/wasm-binary.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ void WasmBinaryWriter::writeFunctions() {
236236
size_t sizePos = writeU32LEBPlaceholder();
237237
size_t start = o.size();
238238
Function* function = wasm->functions[i].get();
239+
currFunction = function;
239240
mappedLocals.clear();
240241
numLocalsByType.clear();
241242
if (debug) std::cerr << "writing" << function->name << std::endl;
@@ -258,6 +259,7 @@ void WasmBinaryWriter::writeFunctions() {
258259
if (debug) std::cerr << "body size: " << size << ", writing at " << sizePos << ", next starts at " << o.size() << std::endl;
259260
o.writeAt(sizePos, U32LEB(size));
260261
}
262+
currFunction = nullptr;
261263
finishSection(start);
262264
}
263265

0 commit comments

Comments
 (0)