From c26cd952ae342ac519fd9f98b67e6152f135c6ce Mon Sep 17 00:00:00 2001 From: Tom Rybka Date: Thu, 6 Jul 2023 09:11:49 -0700 Subject: symbolize_test: Add an indirection for getting the PC from function ptr. Don't assume that function ptr == PC. Adds a redirection mechanism, GetPCFromFnPtr, and enables more test cases for Emscripten/Wasm. On many (most?) platforms, the address of a function ptr is the same as its Program Counter (PC) for the purpose of most things, including symbolization. In Emscripten WebAssembly, the function ptr is just an index into a table of functions. However, the name section maps function names to their literal offsets into a Wasm binary. The WasmOffsetConverter is actually capable of both indirections, so we can effectively go from function ptr to offset into the binary (which is typically the "PC" for other Stack dumping things in Wasm, including `emscripten_pc_get_function`). More info: https://www.w3.org/TR/wasm-js-api-2/#exported-function-exotic-objects Also fix Emscripten symbolize handling for `nullptr` now that we have tests for that. PiperOrigin-RevId: 546006678 Change-Id: I0d4015ca9035b004158451b36c933cad009184ba --- absl/debugging/symbolize_emscripten.inc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'absl/debugging/symbolize_emscripten.inc') diff --git a/absl/debugging/symbolize_emscripten.inc b/absl/debugging/symbolize_emscripten.inc index c226c456..a0f344dd 100644 --- a/absl/debugging/symbolize_emscripten.inc +++ b/absl/debugging/symbolize_emscripten.inc @@ -50,6 +50,9 @@ bool Symbolize(const void* pc, char* out, int out_size) { if (!HaveOffsetConverter()) { return false; } + if (pc == nullptr || out_size <= 0) { + return false; + } const char* func_name = emscripten_pc_get_function(pc); if (func_name == nullptr) { return false; -- cgit v1.2.3