diff options
author | Alon Zakai <alonzakai@gmail.com> | 2017-12-05 10:55:29 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-05 10:55:29 -0800 |
commit | 82d8dc7a9f5ca1c7989ab227bf32edfcd7e4a3c1 (patch) | |
tree | 4c80e609349117435eccccdc1a304c011078b029 /src | |
parent | 42acc22254c89b035bbaba512c86c1784545278d (diff) | |
download | binaryen-82d8dc7a9f5ca1c7989ab227bf32edfcd7e4a3c1.tar.gz binaryen-82d8dc7a9f5ca1c7989ab227bf32edfcd7e4a3c1.tar.bz2 binaryen-82d8dc7a9f5ca1c7989ab227bf32edfcd7e4a3c1.zip |
Handle debug info without a filename in asm2wasm (#1249)
* support debug info without a filename in asm2wasm input (which can happen if llvm doesn't know the file, only the line)
Diffstat (limited to 'src')
-rw-r--r-- | src/asm2wasm.h | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h index 6a3e15b29..5e751327b 100644 --- a/src/asm2wasm.h +++ b/src/asm2wasm.h @@ -262,6 +262,7 @@ struct Asm2WasmPreProcessor { char* out = copy; std::string DEBUGINFO_INTRINSIC = EMSCRIPTEN_DEBUGINFO.str; auto DEBUGINFO_INTRINSIC_SIZE = DEBUGINFO_INTRINSIC.size(); + const char* UNKNOWN_FILE = "(unknown)"; bool seenUseAsm = false; while (input[0]) { if (out + ADD_FACTOR >= end) { @@ -269,13 +270,35 @@ struct Asm2WasmPreProcessor { } if (startsWith(input, "//@line")) { char* linePos = input + 8; - char* lineEnd = strchr(input + 8, ' '); - char* filePos = strchr(lineEnd, '"') + 1; - char* fileEnd = strchr(filePos, '"'); - input = fileEnd + 1; + char* lineEnd = strpbrk(input + 8, " \n"); + if (!lineEnd) { + // comment goes to end of input + break; + } + input = lineEnd + 1; + std::string file; + if (*lineEnd == ' ') { + // we have a file + char* filePos = strpbrk(input, "\"\n"); + if (!filePos) { + // goes to end of input + break; + } + if (*filePos == '"') { + char* fileEnd = strpbrk(filePos + 1, "\"\n"); + input = fileEnd + 1; + *fileEnd = 0; + file = filePos + 1; + } else { + file = UNKNOWN_FILE; + input = filePos + 1; + } + } else { + // no file, we found \n + file = UNKNOWN_FILE; + } *lineEnd = 0; - *fileEnd = 0; - std::string line = linePos, file = filePos; + std::string line = linePos; auto iter = debugInfoFileIndices.find(file); if (iter == debugInfoFileIndices.end()) { Index index = debugInfoFileNames.size(); |