summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2019-12-19 15:45:16 -0800
committerGitHub <noreply@github.com>2019-12-19 15:45:16 -0800
commit05d785e6e476e55c05fda9b7e3fb38c15b25271e (patch)
tree946dca404bc9ebeb8c4797a25978081ea7ec2335 /src/tools
parent02e6ba2b139e6c7ac0a97baa2af75df4250e140f (diff)
downloadbinaryen-05d785e6e476e55c05fda9b7e3fb38c15b25271e.tar.gz
binaryen-05d785e6e476e55c05fda9b7e3fb38c15b25271e.tar.bz2
binaryen-05d785e6e476e55c05fda9b7e3fb38c15b25271e.zip
Binary format code section offset tracking (#2515)
Optionally track the binary format code section offsets, that is, when loading a binary, remember where each IR node was read from. This is necessary for DWARF debug info, as these are the offsets DWARF refers to. (Note that eventually we may want to do something else, like first read the DWARF and only then add debug info annotations into the IR in a more LLVM-like manner, but this is more straightforward and should be enough to update debug lines and ranges). This tracking adds noticeable overhead - every single IR node adds an entry in a map - so avoid it unless actually necessary. Specifically, if the user passes in -g and there are actually DWARF sections in the binary, and we are not about to remove those sections, then we need it. Print binary format code section offsets in text, when printing with -g. This will help debug and test dwarf support. It looks like ;; code offset: 0x7 as an annotation right before each node. Also add support for -g in wasm-opt tests (unlike a pass, it has just one - as a prefix). Helps #2400
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/wasm-emscripten-finalize.cpp7
-rw-r--r--src/tools/wasm-metadce.cpp1
-rw-r--r--src/tools/wasm-opt.cpp15
3 files changed, 22 insertions, 1 deletions
diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp
index b45b61b8f..a32a265cd 100644
--- a/src/tools/wasm-emscripten-finalize.cpp
+++ b/src/tools/wasm-emscripten-finalize.cpp
@@ -49,6 +49,7 @@ int main(int argc, const char* argv[]) {
std::string dataSegmentFile;
bool emitBinary = true;
bool debugInfo = false;
+ bool DWARF = false;
bool isSideModule = false;
bool legalizeJavaScriptFFI = true;
bool checkStackOverflow = false;
@@ -71,6 +72,11 @@ int main(int argc, const char* argv[]) {
"Emit names section in wasm binary (or full debuginfo in wast)",
Options::Arguments::Zero,
[&debugInfo](Options*, const std::string&) { debugInfo = true; })
+ .add("--dwarf",
+ "",
+ "Update DWARF debug info",
+ Options::Arguments::Zero,
+ [&DWARF](Options*, const std::string&) { DWARF = true; })
.add("--emit-text",
"-S",
"Emit text instead of binary for the output file",
@@ -164,6 +170,7 @@ int main(int argc, const char* argv[]) {
Module wasm;
ModuleReader reader;
+ reader.setDWARF(DWARF);
try {
reader.read(infile, wasm, inputSourceMapFilename);
} catch (ParseException& p) {
diff --git a/src/tools/wasm-metadce.cpp b/src/tools/wasm-metadce.cpp
index 7d91b3e6f..3b889b984 100644
--- a/src/tools/wasm-metadce.cpp
+++ b/src/tools/wasm-metadce.cpp
@@ -498,6 +498,7 @@ int main(int argc, const char* argv[]) {
std::cerr << "reading...\n";
}
ModuleReader reader;
+ reader.setDWARF(debugInfo);
try {
reader.read(options.extra["infile"], wasm);
} catch (ParseException& p) {
diff --git a/src/tools/wasm-opt.cpp b/src/tools/wasm-opt.cpp
index 7b04f5449..2fd78a3da 100644
--- a/src/tools/wasm-opt.cpp
+++ b/src/tools/wasm-opt.cpp
@@ -43,7 +43,7 @@
using namespace wasm;
// runs a command and returns its output TODO: portability, return code checking
-std::string runCommand(std::string command) {
+static std::string runCommand(std::string command) {
#ifdef __linux__
std::string output;
const int MAX_BUFFER = 1024;
@@ -59,6 +59,15 @@ std::string runCommand(std::string command) {
#endif
}
+static bool willRemoveDebugInfo(const std::vector<std::string>& passes) {
+ for (auto& pass : passes) {
+ if (pass == "strip" || pass == "strip-debug" || pass == "strip-dwarf") {
+ return true;
+ }
+ }
+ return false;
+}
+
//
// main
//
@@ -210,6 +219,10 @@ int main(int argc, const char* argv[]) {
if (!translateToFuzz) {
ModuleReader reader;
+ // Enable DWARF parsing if we were asked for debug info, and were not
+ // asked to remove it.
+ reader.setDWARF(options.passOptions.debugInfo &&
+ !willRemoveDebugInfo(options.passes));
try {
reader.read(options.extra["infile"], wasm, inputSourceMapFilename);
} catch (ParseException& p) {