mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-22 09:12:24 +03:00
nvgpu: posix: Add support for backtrace
Add support for backtrace prints when BUG() is being called. To support backtrace calls, the -rdynamic compiler flag is now being used. On host, it fully works as expected, on target only exported symbols (in libnvgpu-drv.export) are visible. JIRA NVGPU-1246 Change-Id: Ia075ac99228e8377bdb3142fef2e56c2fea2d967 Signed-off-by: Nicolas Benech <nbenech@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1943478 Reviewed-by: svc-misra-checker <svc-misra-checker@nvidia.com> Reviewed-by: Philip Elcan <pelcan@nvidia.com> GVS: Gerrit_Virtual_Submit Reviewed-by: Alex Waterman <alexw@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
committed by
mobile promotions
parent
3e6779d554
commit
5b5a1cb014
@@ -50,6 +50,7 @@ ifneq ($(NV_BUILD_CONFIGURATION_OS_IS_QNX),1)
|
||||
NV_COMPONENT_SYSTEM_SHARED_LIBRARIES += pthread
|
||||
endif
|
||||
NV_COMPONENT_CFLAGS += -D__NVGPU_POSIX__
|
||||
_NV_TOOLCHAIN_CFLAGS += -rdynamic -g
|
||||
|
||||
NV_COMPONENT_SYSTEMIMAGE_DIR := $(NV_SYSTEMIMAGE_TEST_EXECUTABLE_DIR)/nvgpu_unit
|
||||
systemimage:: $(NV_COMPONENT_SYSTEMIMAGE_DIR)
|
||||
|
||||
@@ -26,6 +26,11 @@
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#include <setjmp.h>
|
||||
#ifndef _QNX_SOURCE
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
|
||||
#define BACKTRACE_MAXSIZE 1024
|
||||
|
||||
static _Thread_local bool expect_bug;
|
||||
static _Thread_local jmp_buf *jmp_handler;
|
||||
@@ -42,14 +47,25 @@ void bug_handler_cancel(void)
|
||||
jmp_handler = NULL;
|
||||
}
|
||||
|
||||
static void __dump_stack(unsigned int skip_frames)
|
||||
static void __dump_stack(int skip_frames)
|
||||
{
|
||||
#ifndef _QNX_SOURCE
|
||||
void *trace[BACKTRACE_MAXSIZE];
|
||||
int i;
|
||||
int trace_size = backtrace(trace, BACKTRACE_MAXSIZE);
|
||||
char **trace_syms = backtrace_symbols(trace, trace_size);
|
||||
|
||||
for (i = skip_frames; i < trace_size; i++) {
|
||||
nvgpu_err(NULL, "[%d] %s", i - skip_frames, trace_syms[i]);
|
||||
}
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
void dump_stack(void)
|
||||
{
|
||||
__dump_stack(0);
|
||||
/* Skip this function and __dump_stack() */
|
||||
__dump_stack(2);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -63,8 +79,12 @@ void __bug(const char *fmt, ...)
|
||||
/* Perform a long jump to where "setjmp()" was called. */
|
||||
longjmp(*jmp_handler, 1);
|
||||
}
|
||||
/* If BUG is unexpected, raise a SIGSEGV signal and kill the thread */
|
||||
/*
|
||||
* If BUG was unexpected, raise a SIGSEGV signal, dump the stack and
|
||||
* kill the thread.
|
||||
*/
|
||||
nvgpu_err(NULL, "BUG detected!");
|
||||
dump_stack();
|
||||
(void) raise(SIGSEGV);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ $(OUT)/nvgpu_unit: $(OUT)/libnvgpu-drv.so $(CORE_OBJS)
|
||||
-o $(OUT)/nvgpu_unit $(CORE_OBJS) $(LIB_PATHS) $(LIBS)
|
||||
|
||||
$(OUT)/libnvgpu-drv.so: $(OBJS)
|
||||
$(CC) -shared -o $(OUT)/libnvgpu-drv.so $(OBJS) -lgcov
|
||||
$(CC) -shared -o $(OUT)/libnvgpu-drv.so $(OBJS) -lgcov -rdynamic
|
||||
|
||||
# Default build target for all the nvgpu driver object files we want to build in
|
||||
# userspace. These get bundled into libnvgpu-drv.so.
|
||||
|
||||
@@ -45,6 +45,7 @@ NV_COMPONENT_SYSTEM_SHARED_LIBRARIES += gcov
|
||||
endif
|
||||
|
||||
NV_COMPONENT_CFLAGS += -D__NVGPU_POSIX__
|
||||
_NV_TOOLCHAIN_CFLAGS += -rdynamic
|
||||
|
||||
NV_UNIT_SH=unit.sh
|
||||
NV_COMPONENT_SYSTEMIMAGE_DIR := $(NV_SYSTEMIMAGE_TEST_EXECUTABLE_DIR)/nvgpu_unit
|
||||
|
||||
Reference in New Issue
Block a user