From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id C6230A04F2; Sun, 7 Jun 2020 11:36:42 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A8AA71C0D2; Sun, 7 Jun 2020 11:36:41 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by dpdk.org (Postfix) with ESMTP id B6CFF1BFB5 for ; Sun, 7 Jun 2020 11:36:40 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE2 (envelope-from talshn@mellanox.com) with ESMTPS (AES256-SHA encrypted); 7 Jun 2020 12:36:36 +0300 Received: from l-wincomp04-vm.labs.mlnx (l-wincomp04-vm.mtl.labs.mlnx [10.237.1.5]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 0579aaO5031885; Sun, 7 Jun 2020 12:36:36 +0300 From: talshn@mellanox.com To: dev@dpdk.org Cc: thomas@monjalon.net, pallavi.kadam@intel.com, dmitry.kozliuk@gmail.com, david.marchand@redhat.com, ranjit.menon@intel.com, navasile@linux.microsoft.com, harini.ramakrishnan@microsoft.com, ocardona@microsoft.com, bruce.richardson@intel.com, Tal Shnaiderman Date: Sun, 7 Jun 2020 12:35:29 +0300 Message-Id: <20200607093529.15456-3-talshn@mellanox.com> X-Mailer: git-send-email 2.16.1.windows.4 In-Reply-To: <20200607093529.15456-1-talshn@mellanox.com> References: <20200607093529.15456-1-talshn@mellanox.com> Subject: [dpdk-dev] [PATCH 2/2] eal/windows: support debug calls X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Tal Shnaiderman Support the debug functions in eal_common_debug.c for Windows. Implementation of rte_dump_stack to get a backtrace similarly to Unix and of rte_eal_cleanup in eal.c. Signed-off-by: Tal Shnaiderman --- config/meson.build | 1 + lib/librte_eal/common/meson.build | 1 + lib/librte_eal/windows/eal.c | 7 ++++ lib/librte_eal/windows/eal_debug.c | 77 +++++++++++++++++++++++++++++++++----- 4 files changed, 77 insertions(+), 9 deletions(-) diff --git a/config/meson.build b/config/meson.build index 43ab113106..51a953c7d3 100644 --- a/config/meson.build +++ b/config/meson.build @@ -268,6 +268,7 @@ if is_windows if cc.get_id() == 'gcc' add_project_arguments('-D__USE_MINGW_ANSI_STDIO', language: 'c') endif + add_project_link_arguments('-lDbgHelp', language: 'c') endif if get_option('b_lto') diff --git a/lib/librte_eal/common/meson.build b/lib/librte_eal/common/meson.build index 2bde920597..a1c362895b 100644 --- a/lib/librte_eal/common/meson.build +++ b/lib/librte_eal/common/meson.build @@ -8,6 +8,7 @@ if is_windows 'eal_common_bus.c', 'eal_common_class.c', 'eal_common_devargs.c', + 'eal_common_debug.c', 'eal_common_errno.c', 'eal_common_launch.c', 'eal_common_lcore.c', diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c index d084606a66..7278f2f07c 100644 --- a/lib/librte_eal/windows/eal.c +++ b/lib/librte_eal/windows/eal.c @@ -221,6 +221,13 @@ rte_eal_init_alert(const char *msg) RTE_LOG(ERR, EAL, "%s\n", msg); } +int +rte_eal_cleanup(void) +{ + eal_cleanup_config(&internal_config); + return 0; +} + /* Launch threads, called at application init(). */ int rte_eal_init(int argc, char **argv) diff --git a/lib/librte_eal/windows/eal_debug.c b/lib/librte_eal/windows/eal_debug.c index 669be6ff97..fda217bee4 100644 --- a/lib/librte_eal/windows/eal_debug.c +++ b/lib/librte_eal/windows/eal_debug.c @@ -5,16 +5,75 @@ #include #include #include +#include - /* call abort(), it will generate a coredump if enabled */ -void -__rte_panic(const char *funcname, const char *format, ...) +#include + +#define BACKTRACE_SIZE 256 + +/* dump the stack of the calling core */ +void rte_dump_stack(void) { - va_list ap; + PVOID stack_trace[BACKTRACE_SIZE] = {0}; + USHORT frame_num; + BOOL ret; + HANDLE process = GetCurrentProcess(); + + ret = SymInitialize(process, NULL, TRUE); + if (!ret) { + RTE_LOG_WIN32_ERR("SymInitialize()"); + return; + } + + SymSetOptions(SYMOPT_LOAD_LINES | SYMOPT_UNDNAME); + + frame_num = RtlCaptureStackBackTrace(0, BACKTRACE_SIZE, + stack_trace, NULL); + + while (frame_num > 0) { + DWORD64 address = (DWORD64)(stack_trace[frame_num - 1]); + DWORD64 sym_disp = 0; + DWORD error_code = 0, lin_disp; + char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR)]; + PSYMBOL_INFO symbol_info = (PSYMBOL_INFO)buffer; + IMAGEHLP_LINE64 line; + + symbol_info->SizeOfStruct = sizeof(SYMBOL_INFO); + symbol_info->MaxNameLen = MAX_SYM_NAME; + line.SizeOfStruct = sizeof(IMAGEHLP_LINE64); + + ret = SymFromAddr(process, address, &sym_disp, symbol_info); + if (!ret) { + error_code = GetLastError(); + if (error_code == ERROR_INVALID_ADDRESS) { + /* Missing symbols, print message */ + rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL, + "%d: []\n", frame_num--); + continue; + } else { + RTE_LOG_WIN32_ERR("SymFromAddr()"); + goto end; + } + } + + ret = SymGetLineFromAddr64(process, address, &lin_disp, &line); + if (!ret) { + error_code = GetLastError(); + /* If ERROR_INVALID_ADDRESS tag unknown and proceed */ + if (error_code != ERROR_INVALID_ADDRESS) { + RTE_LOG_WIN32_ERR("SymGetLineFromAddr64()"); + goto end; + } + } - rte_log(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, "PANIC in %s():\n", funcname); - va_start(ap, format); - rte_vlog(RTE_LOG_CRIT, RTE_LOGTYPE_EAL, format, ap); - va_end(ap); - abort(); + rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL, + "%d: [%s (%s+0x%0llx)[0x%0llX]]\n", frame_num, + error_code ? "" : line.FileName, + symbol_info->Name, sym_disp, symbol_info->Address); + frame_num--; + } +end: + ret = SymCleanup(process); + if (!ret) + RTE_LOG_WIN32_ERR("SymCleanup()"); } -- 2.16.1.windows.4