Skip to content

Commit d8a7847

Browse files
authored
Demangle in-VM backtraces from C++ and Rust plugins. (#299)
Before: Proxy-Wasm plugin in-VM backtrace: 0: 0x60c3 - rust_oom 1: 0x6d2c - __rg_oom 2: 0x38b1 - __rust_alloc_error_handler 3: 0x6cb3 - _ZN5alloc5alloc18handle_alloc_error8rt_error17hc05c98d79426d4d3E 4: 0x6ca5 - _ZN4core3ops8function6FnOnce9call_once17h104529aa81b44c4eE 5: 0x6d1e - _ZN4core10intrinsics17const_eval_select17hbbf517c24e8eee9cE 6: 0x6cc1 - _ZN5alloc5alloc18handle_alloc_error17hd51ecca19a6d9162E 7: 0x519 - _ZN5alloc7raw_vec19RawVec$LT$T$C$A$GT$11allocate_in17h4065aea9ced9d1eeE 8: 0x2b9 - _ZN5alloc7raw_vec19RawVec$LT$T$C$A$GT$16with_capacity_in17h2c8a17f6c910dc68E 9: 0x303a - _ZN5alloc3vec16Vec$LT$T$C$A$GT$16with_capacity_in17hb7917fc637d55bb8E After: Proxy-Wasm plugin in-VM backtrace: 0: 0x60c3 - rust_oom 1: 0x6d2c - __rg_oom 2: 0x38b1 - __rust_alloc_error_handler 3: 0x6cb3 - alloc::alloc::handle_alloc_error::rt_error::hc05c98d79426d4d3 4: 0x6ca5 - core::ops::function::FnOnce::call_once::h104529aa81b44c4e 5: 0x6d1e - core::intrinsics::const_eval_select::hbbf517c24e8eee9c 6: 0x6cc1 - alloc::alloc::handle_alloc_error::hd51ecca19a6d9162 7: 0x519 - alloc::raw_vec::RawVec$LT$T$C$A$GT$::allocate_in::h4065aea9ced9d1ee 8: 0x2b9 - alloc::raw_vec::RawVec$LT$T$C$A$GT$::with_capacity_in::h2c8a17f6c910dc68 9: 0x303a - alloc::vec::Vec$LT$T$C$A$GT$::with_capacity_in::hb7917fc637d55bb8 Signed-off-by: Piotr Sikora <[email protected]>
1 parent 3827786 commit d8a7847

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/bytecode_util.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
#include "include/proxy-wasm/bytecode_util.h"
1616

17+
#if !defined(_MSC_VER)
18+
#include <cxxabi.h>
19+
#endif
20+
1721
#include <cstring>
1822

1923
namespace proxy_wasm {
@@ -165,7 +169,16 @@ bool BytecodeUtil::getFunctionNameIndex(std::string_view bytecode,
165169
if (!parseVarint(pos, end, func_name_size) || pos + func_name_size > end) {
166170
return false;
167171
}
168-
ret.insert({func_index, std::string(pos, func_name_size)});
172+
auto func_name = std::string(pos, func_name_size);
173+
#if !defined(_MSC_VER)
174+
int status;
175+
char *data = abi::__cxa_demangle(func_name.c_str(), nullptr, nullptr, &status);
176+
if (data != nullptr) {
177+
func_name = std::string(data);
178+
::free(data);
179+
}
180+
#endif
181+
ret.insert({func_index, func_name});
169182
pos += func_name_size;
170183
}
171184
if (start + subsection_size != pos) {

test/runtime_test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ TEST_P(TestVm, WasmMemoryLimit) {
139139
EXPECT_TRUE(host->isErrorLogged("Uncaught RuntimeError: unreachable"));
140140
EXPECT_TRUE(host->isErrorLogged("Proxy-Wasm plugin in-VM backtrace:"));
141141
EXPECT_TRUE(host->isErrorLogged(" - rust_oom"));
142+
EXPECT_TRUE(host->isErrorLogged(" - alloc::alloc::handle_alloc_error"));
142143
}
143144
}
144145

@@ -160,6 +161,7 @@ TEST_P(TestVm, Trap) {
160161
if (engine_ == "v8") {
161162
EXPECT_TRUE(host->isErrorLogged("Uncaught RuntimeError: unreachable"));
162163
EXPECT_TRUE(host->isErrorLogged("Proxy-Wasm plugin in-VM backtrace:"));
164+
EXPECT_TRUE(host->isErrorLogged(" - std::panicking::begin_panic"));
163165
EXPECT_TRUE(host->isErrorLogged(" - trigger"));
164166
}
165167
}
@@ -182,6 +184,7 @@ TEST_P(TestVm, Trap2) {
182184
if (engine_ == "v8") {
183185
EXPECT_TRUE(host->isErrorLogged("Uncaught RuntimeError: unreachable"));
184186
EXPECT_TRUE(host->isErrorLogged("Proxy-Wasm plugin in-VM backtrace:"));
187+
EXPECT_TRUE(host->isErrorLogged(" - std::panicking::begin_panic"));
185188
EXPECT_TRUE(host->isErrorLogged(" - trigger2"));
186189
}
187190
}

0 commit comments

Comments
 (0)