1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
8 #include <rte_windows.h>
12 #define BACKTRACE_SIZE 256
14 /* dump the stack of the calling core */
18 PVOID stack_trace[BACKTRACE_SIZE] = {0};
21 HANDLE process = GetCurrentProcess();
23 ret = SymInitialize(process, NULL, TRUE);
25 RTE_LOG_WIN32_ERR("SymInitialize()");
29 SymSetOptions(SYMOPT_LOAD_LINES | SYMOPT_UNDNAME);
31 frame_num = RtlCaptureStackBackTrace(0, BACKTRACE_SIZE,
34 while (frame_num > 0) {
35 DWORD64 address = (DWORD64)(stack_trace[frame_num - 1]);
37 DWORD error_code = 0, lin_disp;
38 char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)];
39 PSYMBOL_INFO symbol_info = (PSYMBOL_INFO)buffer;
42 symbol_info->SizeOfStruct = sizeof(SYMBOL_INFO);
43 symbol_info->MaxNameLen = MAX_SYM_NAME;
44 line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
46 ret = SymFromAddr(process, address, &sym_disp, symbol_info);
48 error_code = GetLastError();
49 if (error_code == ERROR_INVALID_ADDRESS) {
50 /* Missing symbols, print message */
51 rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL,
52 "%d: [<missing_symbols>]\n", frame_num--);
55 RTE_LOG_WIN32_ERR("SymFromAddr()");
60 ret = SymGetLineFromAddr64(process, address, &lin_disp, &line);
62 error_code = GetLastError();
63 /* If ERROR_INVALID_ADDRESS tag unknown and proceed */
64 if (error_code != ERROR_INVALID_ADDRESS) {
65 RTE_LOG_WIN32_ERR("SymGetLineFromAddr64()");
70 rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL,
71 "%d: [%s (%s+0x%0llx)[0x%0llX]]\n", frame_num,
72 error_code ? "<unknown>" : line.FileName,
73 symbol_info->Name, sym_disp, symbol_info->Address);
77 ret = SymCleanup(process);
79 RTE_LOG_WIN32_ERR("SymCleanup()");