vlib: use libiberty to demangle backtrace if present 77/42677/2
authorDamjan Marion <[email protected]>
Fri, 4 Apr 2025 11:23:32 +0000 (13:23 +0200)
committerDave Wallace <[email protected]>
Fri, 4 Apr 2025 15:08:36 +0000 (15:08 +0000)
Only C++ for now.... but others like rust can be added easily

Type: improvement
Change-Id: Ic61766f9944c0c19711a40a4686d296605d6c10d
Signed-off-by: Damjan Marion <[email protected]>
Makefile
src/vlib/CMakeLists.txt
src/vlib/unix/main.c

index 15fdc83..6f9a735 100644 (file)
--- 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
index 3c354b7..1f1a139 100644 (file)
@@ -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
 )
index 11d0cb1..49aa5d3 100644 (file)
 #include <sys/resource.h>
 #include <unistd.h>
 
+#ifdef HAVE_LIBIBERTY
+#include <libiberty/demangle.h>
+#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);
            }