From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C09B3A00C4; Sat, 29 Jan 2022 02:10:45 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 20CCB40140; Sat, 29 Jan 2022 02:10:45 +0100 (CET) Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by mails.dpdk.org (Postfix) with ESMTP id 5EFD040041 for ; Sat, 29 Jan 2022 02:10:44 +0100 (CET) Received: by mail-pf1-f181.google.com with SMTP id i65so7702083pfc.9 for ; Fri, 28 Jan 2022 17:10:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=BpWABhmkMuSGYGe5fk/nZGiH3rW1kyhIyiVlMWRnM5k=; b=MMWYgDMqpNKH5HhdEjwpBHPWcTlv0KF4gql4yFxGgoZrjGwYqKbSrzr0oviweQXPLO abOZldkUPl5Oyiy+BCyCVWUtteFFqF47ReCEmLmNujHlgF4OHjRdIwtu2ov1iP/rgAbK 1FLktPAq+OcVofjnmsrk3WYF42GfEJTlJgBp/o78H2uzfl3PvnaYWckJ5Ga4zbo/alFM clETwiIIznSTR7G5Q+QHMjuaujZTCVdPjuYnWkyffHYpymwlpepDjB8jd0HEQrUPMSwI TVIa/qOzHTAEMOFSKT0DFdt7rVmmeFmeO901/h/fQux7H9ujVdBlO7Rd9sa+Zw8IV9vf uh8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=BpWABhmkMuSGYGe5fk/nZGiH3rW1kyhIyiVlMWRnM5k=; b=Svkpf3dlACUkkTaCSSDiMbbUDiWfbTtLUUwu3UzKKGNdGmRlzSSagwZvCz7WbllkwC k3wu7Paf2E7cpodlvro2kYocvy7/dtRY7Lz3++xUdusSwBg8zC4gyeGAf8kf7LAjTBI/ vloZdhMr4ih0elxxT4UeMmEq/jL9W/tY64WW7D2pyGdZw/1Uwv+syxhrPbMkszI9XWUf g2877PWrF4m6OOHs50Xv57iIZbpQ9vSCW/cHRnTfdT7oaQFrmozSty2oYiiLObjmDhv/ CgotJtAWaXDqziQqoWHuNfzyyYUyBLFBoNfuuMlm7MwPNNGF+rVsE9Gbn/hiteIXIeK3 67+w== X-Gm-Message-State: AOAM532q7EJ0GeXAKPbUiPygD41fcS94JRydTI0nlVKvxyhiHa7L1mBI elfTqj440MP99j1Rdn1FEnHPHBEXDqtcwg== X-Google-Smtp-Source: ABdhPJx+1LkKX4tcy2+joiB3cE32J7worYx65wXJlHxPlzsEqUVgO3RRJlgNjqD0OHRRjZR/E2lx7w== X-Received: by 2002:a63:4b4d:: with SMTP id k13mr8396122pgl.423.1643418642972; Fri, 28 Jan 2022 17:10:42 -0800 (PST) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id on5sm3717677pjb.26.2022.01.28.17.10.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jan 2022 17:10:42 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [RFC] eal_debug: do not use malloc in rte_dump_stack Date: Fri, 28 Jan 2022 17:10:39 -0800 Message-Id: <20220129011039.264377-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The glibc backtrace_symbols() calls malloc which makes it dangerous to use rte_dump_stack() in a signal handler that is handling errors that maybe due to memory corruption. Instead, use dladdr() to lookup up symbols incrementally. The format of the messages is based on what X org server has been doing for many years. It changes from bottom up to top down order. Bugzilla ID: 929 Signed-off-by: Stephen Hemminger --- lib/eal/linux/eal_debug.c | 45 ++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/lib/eal/linux/eal_debug.c b/lib/eal/linux/eal_debug.c index 64dab4e0da24..bf232f72f402 100644 --- a/lib/eal/linux/eal_debug.c +++ b/lib/eal/linux/eal_debug.c @@ -4,6 +4,7 @@ #ifdef RTE_BACKTRACE #include +#include #endif #include #include @@ -18,26 +19,44 @@ #define BACKTRACE_SIZE 256 -/* dump the stack of the calling core */ +/* Dump the stack of the calling core + * + * Note: this requires some careful usage in order to + * stay safe in case where called from a signal + * handler and the malloc pool may be corrupted. + */ void rte_dump_stack(void) { #ifdef RTE_BACKTRACE void *func[BACKTRACE_SIZE]; - char **symb = NULL; - int size; + int i, size; size = backtrace(func, BACKTRACE_SIZE); - symb = backtrace_symbols(func, size); - - if (symb == NULL) - return; - while (size > 0) { - rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL, - "%d: [%s]\n", size, symb[size - 1]); - size --; + for (i = 0; i < size; i++) { + void *pc = func[i]; + const char *fname; + Dl_info info; + + if (dladdr(pc, &info) == 0) { + rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL, + "%d: ?? [%p]\n", i, pc); + continue; + } + + fname = (info.dli_fname && *info.dli_fname) ? info.dli_fname : "(vdso)"; + if (info.dli_saddr != NULL) + rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL, + "%d: %s (%s+%#tx) [%p]\n", + i, fname, info.dli_sname, + (ptrdiff_t)((uintptr_t)pc - (uintptr_t)info.dli_saddr), + pc); + else + rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL, + "%d: %s (%p+%#tx) [%p]\n", + i, fname, info.dli_fbase, + (ptrdiff_t)((uintptr_t)pc - (uintptr_t)info.dli_fbase), + pc); } - free(symb); #endif /* RTE_BACKTRACE */ } -- 2.34.1