From eb8726874efcf8f880ae5b6cdcd4315d6858e121 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Fri, 4 Apr 2025 13:23:32 +0200 Subject: [PATCH] vlib: use libiberty to demangle backtrace if present Only C++ for now.... but others like rust can be added easily Type: improvement Change-Id: Ic61766f9944c0c19711a40a4686d296605d6c10d Signed-off-by: Damjan Marion --- Makefile | 1 + src/vlib/CMakeLists.txt | 15 ++++++++++++++- src/vlib/unix/main.c | 20 ++++++++++++++++++-- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 15fdc836470..6f9a735db22 100644 --- a/Makefile +++ b/Makefile @@ -106,6 +106,7 @@ DEB_DEPENDS += iperf ethtool # for 'make test TEST=vm_vpp_interfaces' DEB_DEPENDS += libpcap-dev DEB_DEPENDS += tshark DEB_DEPENDS += jq # for extracting test summary from .json report (hs-test) +DEB_DEPENDS += libiberty-dev DEB_DEPENDS += nasm libnuma-dev # for make-ext-deps LIBFFI=libffi6 # works on all but 20.04 and debian-testing diff --git a/src/vlib/CMakeLists.txt b/src/vlib/CMakeLists.txt index 3c354b764dd..1f1a1396d0d 100644 --- a/src/vlib/CMakeLists.txt +++ b/src/vlib/CMakeLists.txt @@ -71,6 +71,19 @@ set(PLATFORM_SOURCES ) endif() +set(VLIB_LIBS vppinfra svm ${CMAKE_DL_LIBS} ${EPOLL_LIB}) + +vpp_find_path(LIBIBERTY_INCLUDE_DIR libiberty/demangle.h) +vpp_find_library(LIBIBERTY_LIB NAMES iberty libiberty) + +if (LIBIBERTY_INCLUDE_DIR AND LIBUNWIND_LIB) + message(STATUS "libiberty found at ${LIBIBERTY_LIB}") + list(APPEND VLIB_LIBS ${LIBIBERTY_LIB}) + add_definitions(-DHAVE_LIBIBERTY) +else() + message(WARNING "libiberty not found - stack trace demangle disabled") +endif() + add_vpp_library(vlib SOURCES buffer.c @@ -159,7 +172,7 @@ add_vpp_library(vlib API_FILES pci/pci_types.api - LINK_LIBRARIES vppinfra svm ${CMAKE_DL_LIBS} ${EPOLL_LIB} + LINK_LIBRARIES ${VLIB_LIBS} DEPENDS api_headers ) diff --git a/src/vlib/unix/main.c b/src/vlib/unix/main.c index 11d0cb1160c..49aa5d3a8ab 100644 --- a/src/vlib/unix/main.c +++ b/src/vlib/unix/main.c @@ -54,6 +54,10 @@ #include #include +#ifdef HAVE_LIBIBERTY +#include +#endif + /** Default CLI pager limit is not configured in startup.conf */ #define UNIX_CLI_DEFAULT_PAGER_LIMIT 100000 @@ -226,8 +230,20 @@ unix_signal_handler (int signum, siginfo_t * si, ucontext_t * uc) { if (color) syslog_msg = format (syslog_msg, ANSI_FG_YELLOW); - syslog_msg = - format (syslog_msg, " %s + 0x%x", sf->name, sf->offset); +#if HAVE_LIBIBERTY + if (strncmp (sf->name, "_Z", 2) == 0) + { + char *demangled = cplus_demangle (sf->name, DMGL_AUTO); + syslog_msg = format (syslog_msg, " %s", + demangled ? demangled : sf->name); + if (demangled) + free (demangled); + } + else +#endif + syslog_msg = format (syslog_msg, " %s", sf->name); + + syslog_msg = format (syslog_msg, " + 0x%x", sf->offset); if (color) syslog_msg = format (syslog_msg, ANSI_FG_DEFAULT); } -- 2.16.6