diff options
-rw-r--r-- | src/asm2wasm.h | 35 | ||||
-rw-r--r-- | test/debugInfo.asm.js | 5 | ||||
-rw-r--r-- | test/debugInfo.fromasm | 5 | ||||
-rw-r--r-- | test/debugInfo.fromasm.clamp | 5 | ||||
-rw-r--r-- | test/debugInfo.fromasm.clamp.map | 2 | ||||
-rw-r--r-- | test/debugInfo.fromasm.clamp.no-opts | 5 | ||||
-rw-r--r-- | test/debugInfo.fromasm.clamp.no-opts.map | 2 | ||||
-rw-r--r-- | test/debugInfo.fromasm.imprecise | 5 | ||||
-rw-r--r-- | test/debugInfo.fromasm.imprecise.map | 2 | ||||
-rw-r--r-- | test/debugInfo.fromasm.imprecise.no-opts | 5 | ||||
-rw-r--r-- | test/debugInfo.fromasm.imprecise.no-opts.map | 2 | ||||
-rw-r--r-- | test/debugInfo.fromasm.map | 2 | ||||
-rw-r--r-- | test/debugInfo.fromasm.no-opts | 5 | ||||
-rw-r--r-- | test/debugInfo.fromasm.no-opts.map | 2 |
14 files changed, 69 insertions, 13 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(); diff --git a/test/debugInfo.asm.js b/test/debugInfo.asm.js index 29b08575a..bfdc85780 100644 --- a/test/debugInfo.asm.js +++ b/test/debugInfo.asm.js @@ -81,6 +81,9 @@ function () { switch_reach($p) | 0; return ($rc$0|0); //@line 59950 "/tmp/emscripten_test_binaryen2_28hnAe/src.c" } - return { add: add, ret: ret, opts: opts, fib: fib, switch_reach: switch_reach }; + function nofile() { + nofile(); //@line 1337 + } + return { add: add, ret: ret, opts: opts, fib: fib, switch_reach: switch_reach, nofile: nofile }; } diff --git a/test/debugInfo.fromasm b/test/debugInfo.fromasm index dcb2a8f74..70d5183e7 100644 --- a/test/debugInfo.fromasm +++ b/test/debugInfo.fromasm @@ -10,6 +10,7 @@ (export "opts" (func $opts)) (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) + (export "nofile" (func $nofile)) (func $add (; 0 ;) (param $0 i32) (param $1 i32) (result i32) ;;@ tests/other_file.cpp:314159:0 (i32.add @@ -188,4 +189,8 @@ ;;@ /tmp/emscripten_test_binaryen2_28hnAe/src.c:59950:0 (get_local $1) ) + (func $nofile (; 5 ;) + ;;@ (unknown):1337:0 + (call $nofile) + ) ) diff --git a/test/debugInfo.fromasm.clamp b/test/debugInfo.fromasm.clamp index dcb2a8f74..70d5183e7 100644 --- a/test/debugInfo.fromasm.clamp +++ b/test/debugInfo.fromasm.clamp @@ -10,6 +10,7 @@ (export "opts" (func $opts)) (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) + (export "nofile" (func $nofile)) (func $add (; 0 ;) (param $0 i32) (param $1 i32) (result i32) ;;@ tests/other_file.cpp:314159:0 (i32.add @@ -188,4 +189,8 @@ ;;@ /tmp/emscripten_test_binaryen2_28hnAe/src.c:59950:0 (get_local $1) ) + (func $nofile (; 5 ;) + ;;@ (unknown):1337:0 + (call $nofile) + ) ) diff --git a/test/debugInfo.fromasm.clamp.map b/test/debugInfo.fromasm.clamp.map index 838607f31..6fb01998b 100644 --- a/test/debugInfo.fromasm.clamp.map +++ b/test/debugInfo.fromasm.clamp.map @@ -1 +1 @@ -{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c"],"names":[],"mappings":"oKC8ylTA,QC7vlTA,OAkDA,UCnGA,OACA,OACA,uBCAA,wBAKA,MAJA,OADA,0BAKA,0FCsi1DA"}
\ No newline at end of file +{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)"],"names":[],"mappings":"iLC8ylTA,QC7vlTA,OAkDA,UCnGA,OACA,OACA,uBCAA,wBAKA,MAJA,OADA,0BAKA,0FCsi1DA,KCrvyDA"}
\ No newline at end of file diff --git a/test/debugInfo.fromasm.clamp.no-opts b/test/debugInfo.fromasm.clamp.no-opts index 8e4ebdd3f..83e1c4ec0 100644 --- a/test/debugInfo.fromasm.clamp.no-opts +++ b/test/debugInfo.fromasm.clamp.no-opts @@ -10,6 +10,7 @@ (export "opts" (func $opts)) (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) + (export "nofile" (func $nofile)) (func $add (; 0 ;) (param $x i32) (param $y i32) (result i32) ;;@ tests/hello_world.c:5:0 (set_local $x @@ -282,4 +283,8 @@ (get_local $$rc$0) ) ) + (func $nofile (; 6 ;) + ;;@ (unknown):1337:0 + (call $nofile) + ) ) diff --git a/test/debugInfo.fromasm.clamp.no-opts.map b/test/debugInfo.fromasm.clamp.no-opts.map index fc2087bb3..dc7e479dd 100644 --- a/test/debugInfo.fromasm.clamp.no-opts.map +++ b/test/debugInfo.fromasm.clamp.no-opts.map @@ -1 +1 @@ -{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c"],"names":[],"mappings":"6KAIA,IACA,ICyylTA,aC7vlTA,OAkDA,0BCnGA,OACA,OACA,uBCAA,4BAKA,QAJA,OADA,8CAKA,yICsi1DA"}
\ No newline at end of file +{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)"],"names":[],"mappings":"0LAIA,IACA,ICyylTA,aC7vlTA,OAkDA,0BCnGA,OACA,OACA,uBCAA,4BAKA,QAJA,OADA,8CAKA,yICsi1DA,OCrvyDA"}
\ No newline at end of file diff --git a/test/debugInfo.fromasm.imprecise b/test/debugInfo.fromasm.imprecise index 1cfc5d114..5db316589 100644 --- a/test/debugInfo.fromasm.imprecise +++ b/test/debugInfo.fromasm.imprecise @@ -9,6 +9,7 @@ (export "opts" (func $opts)) (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) + (export "nofile" (func $nofile)) (func $add (; 0 ;) (param $0 i32) (param $1 i32) (result i32) ;;@ tests/other_file.cpp:314159:0 (i32.add @@ -180,4 +181,8 @@ ;;@ /tmp/emscripten_test_binaryen2_28hnAe/src.c:59950:0 (get_local $1) ) + (func $nofile (; 5 ;) + ;;@ (unknown):1337:0 + (call $nofile) + ) ) diff --git a/test/debugInfo.fromasm.imprecise.map b/test/debugInfo.fromasm.imprecise.map index 2988459c5..b7ca07106 100644 --- a/test/debugInfo.fromasm.imprecise.map +++ b/test/debugInfo.fromasm.imprecise.map @@ -1 +1 @@ -{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c"],"names":[],"mappings":"oKC8ylTA,QC7vlTA,OAkDA,QCnGA,OACA,OACA,aCAA,wBAKA,MAJA,OADA,0BAKA,0FCsi1DA"}
\ No newline at end of file +{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)"],"names":[],"mappings":"iLC8ylTA,QC7vlTA,OAkDA,QCnGA,OACA,OACA,aCAA,wBAKA,MAJA,OADA,0BAKA,0FCsi1DA,KCrvyDA"}
\ No newline at end of file diff --git a/test/debugInfo.fromasm.imprecise.no-opts b/test/debugInfo.fromasm.imprecise.no-opts index cf6170324..22e2df1b0 100644 --- a/test/debugInfo.fromasm.imprecise.no-opts +++ b/test/debugInfo.fromasm.imprecise.no-opts @@ -10,6 +10,7 @@ (export "opts" (func $opts)) (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) + (export "nofile" (func $nofile)) (func $add (; 0 ;) (param $x i32) (param $y i32) (result i32) ;;@ tests/hello_world.c:5:0 (set_local $x @@ -270,4 +271,8 @@ (get_local $$rc$0) ) ) + (func $nofile (; 5 ;) + ;;@ (unknown):1337:0 + (call $nofile) + ) ) diff --git a/test/debugInfo.fromasm.imprecise.no-opts.map b/test/debugInfo.fromasm.imprecise.no-opts.map index 4dd296b9a..e37a63acc 100644 --- a/test/debugInfo.fromasm.imprecise.no-opts.map +++ b/test/debugInfo.fromasm.imprecise.no-opts.map @@ -1 +1 @@ -{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c"],"names":[],"mappings":"4KAIA,IACA,ICyylTA,aC7vlTA,OAkDA,SCnGA,OACA,OACA,sBCAA,4BAKA,QAJA,OADA,8CAKA,yICsi1DA"}
\ No newline at end of file +{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)"],"names":[],"mappings":"yLAIA,IACA,ICyylTA,aC7vlTA,OAkDA,SCnGA,OACA,OACA,sBCAA,4BAKA,QAJA,OADA,8CAKA,yICsi1DA,OCrvyDA"}
\ No newline at end of file diff --git a/test/debugInfo.fromasm.map b/test/debugInfo.fromasm.map index 838607f31..6fb01998b 100644 --- a/test/debugInfo.fromasm.map +++ b/test/debugInfo.fromasm.map @@ -1 +1 @@ -{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c"],"names":[],"mappings":"oKC8ylTA,QC7vlTA,OAkDA,UCnGA,OACA,OACA,uBCAA,wBAKA,MAJA,OADA,0BAKA,0FCsi1DA"}
\ No newline at end of file +{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)"],"names":[],"mappings":"iLC8ylTA,QC7vlTA,OAkDA,UCnGA,OACA,OACA,uBCAA,wBAKA,MAJA,OADA,0BAKA,0FCsi1DA,KCrvyDA"}
\ No newline at end of file diff --git a/test/debugInfo.fromasm.no-opts b/test/debugInfo.fromasm.no-opts index 8e4ebdd3f..83e1c4ec0 100644 --- a/test/debugInfo.fromasm.no-opts +++ b/test/debugInfo.fromasm.no-opts @@ -10,6 +10,7 @@ (export "opts" (func $opts)) (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) + (export "nofile" (func $nofile)) (func $add (; 0 ;) (param $x i32) (param $y i32) (result i32) ;;@ tests/hello_world.c:5:0 (set_local $x @@ -282,4 +283,8 @@ (get_local $$rc$0) ) ) + (func $nofile (; 6 ;) + ;;@ (unknown):1337:0 + (call $nofile) + ) ) diff --git a/test/debugInfo.fromasm.no-opts.map b/test/debugInfo.fromasm.no-opts.map index fc2087bb3..dc7e479dd 100644 --- a/test/debugInfo.fromasm.no-opts.map +++ b/test/debugInfo.fromasm.no-opts.map @@ -1 +1 @@ -{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c"],"names":[],"mappings":"6KAIA,IACA,ICyylTA,aC7vlTA,OAkDA,0BCnGA,OACA,OACA,uBCAA,4BAKA,QAJA,OADA,8CAKA,yICsi1DA"}
\ No newline at end of file +{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)"],"names":[],"mappings":"0LAIA,IACA,ICyylTA,aC7vlTA,OAkDA,0BCnGA,OACA,OACA,uBCAA,4BAKA,QAJA,OADA,8CAKA,yICsi1DA,OCrvyDA"}
\ No newline at end of file |