server icon indicating copy to clipboard operation
server copied to clipboard

MDEV-33616 Show correct function names in safemalloc backtrace

Open DaveGosselin-MariaDB opened this issue 1 year ago • 1 comments
trafficstars

Fix safemalloc's backtrace functionality to work on macOS.

DaveGosselin-MariaDB avatar May 29 '24 20:05 DaveGosselin-MariaDB

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 29 '24 20:05 CLAassistant

sorry, I've missed it when it was created. Why safemalloc backtrace functionality doesn't work on Mac OS X?

vuvova avatar Sep 14 '24 08:09 vuvova

sorry, I've missed it when it was created. Why safemalloc backtrace functionality doesn't work on Mac OS X?

The addr2line binary doesn't exist on macOS, so we cannot rely on it for address resolution during my_addr_resolve. addr2line is available via other third-party package systems (like ports) but we shouldn't assume it's on the system. Before this change, a test with a memory leak would produce a failure like this on macOS:

Error: Freeing unallocated data or underrun buffer 0x1278ebe38 at 0x101da0870, Printing to addr2line failed

With this change applied, the same error now resolves function names:

Error: Freeing unallocated data or underrun buffer 0x1318da038 at 0 mariadbd 0x0000000105ba484c sf_free + 52, 1 mariadbd 0x0000000105b8c420 my_free + 284, 2 mariadbd 0x00000001050a3a30 _ZN25Sys_var_gtid_binlog_state13global_updateEP3THDP7set_var + 376, 3 mariadbd 0x0000000104ccf294 _ZN7sys_var6updateEP3THDP7set_var + 156, 4 mariadbd 0x0000000104cd1dd8 _ZN7set_var6updateEP3THD + 64, 5 mariadbd 0x0000000104cd1620 _Z17sql_set_variablesP3THDP4ListI12set_var_baseEb + 408, 6 mariadbd 0x0000000104e65394 _Z21mysql_execute_commandP3THD + 30360, 7 mariadbd 0x0000000104e55ec8 _Z11mysql_parseP3THDPcjP12Parser_statebb + 1092

This isn't the most attractive output, but it is more helpful than a list of addresses.

DaveGosselin-MariaDB avatar Sep 16 '24 15:09 DaveGosselin-MariaDB

I closed this PR because (1) we can use objdump on macOS to decode the addresses and (2) I'm not sure of an acceptable fallback that will work across operating systems.

DaveGosselin-MariaDB avatar Sep 20 '24 15:09 DaveGosselin-MariaDB