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 324C6A00C2; Sat, 12 Feb 2022 19:44:46 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E7D11410D5; Sat, 12 Feb 2022 19:44:40 +0100 (CET) Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by mails.dpdk.org (Postfix) with ESMTP id 02ADB40140 for ; Sat, 12 Feb 2022 19:44:39 +0100 (CET) Received: by mail-pf1-f176.google.com with SMTP id d187so21979434pfa.10 for ; Sat, 12 Feb 2022 10:44:39 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=pyR6ZtjSewF3D/9tYzAWSC3Avs5WomenBqmqcQMPNNw=; b=nZPeH96wj2uAgsiT9HEOtmPYd02mpCLnVFD96cplNcFb7QmlUVNd1J1bbJVooYpudL QAL4bnumIlE3ULPfNlkOKUh3ZKZlLmzr7R4AY9bSTceW3e58k/Ab94Te1Q3D67GD4vDL TphuPkt9/UK9H2DVpr09Xp0VRWFNVb5paDsp2pC/OSAEDC4dx7Pk6Ro7dDdfC4xlTh/z 20SVoKyV9kjTRzxj8qumutXeVQvLTHkLFd9zgL8k1spabiOqAHO4d/BJeYQJuh2IYkxD fn0WhO1aadoIzOpIEeYuwk6MDivTeydpeFz6YbwYAJ0Hv57gmQJxpzYBWuc0BuAvUuzh ga+A== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=pyR6ZtjSewF3D/9tYzAWSC3Avs5WomenBqmqcQMPNNw=; b=iwG1dboapH55OtsS1BuVI1RKLjUQi7ST1331ynUfN+WesX2BPlEq0TsB7F/f6H9ShL zLIEtWuA3bLV4IagPK4FKHwdYCSQv0sHZ7ydM2tRR6QffW30tISg6Yy/VBGXW8vq3XDa rMjgqlJegOMLVlunfn92YVUXTqse4XngGH2UDJq2r7Fd7Kgsq47mActyoztLPL76q7F3 BW0tKt+LO1oCRnVn8gbyNCcYlGfn4JIGnJJrrXg3JZLzGOO1NVcpzlIP4d41MZXLqdmM V7gR8ZXNBwjp80c6vaf8vB4hJBAGYz+A2BlD4YCUfr+Lk/Y4AaPsQM2xc6LHlsQghEq6 qhOQ== X-Gm-Message-State: AOAM5324MJtg21jjOAHcmljhVq9X6oas29ebuDtRsfb9F6PHZw7NbEb8 3KjkeNWGJrQrfxv4YeT/eCROIM9ZTQ/vD8gt X-Google-Smtp-Source: ABdhPJxEK4sX9MVGbUf/ga4E1eI311r5GPXy5qMX1BwWnz9+0+Nj6c0NHCF4Cr16MAZiIKAa3BlaOQ== X-Received: by 2002:a63:945:: with SMTP id 66mr5836744pgj.432.1644691478721; Sat, 12 Feb 2022 10:44:38 -0800 (PST) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id 16sm20105141pfm.200.2022.02.12.10.44.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Feb 2022 10:44:38 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v2 1/2] eal_debug: do not use malloc in rte_dump_stack Date: Sat, 12 Feb 2022 10:44:32 -0800 Message-Id: <20220212184433.66791-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220212184433.66791-1-stephen@networkplumber.org> References: <20220129011039.264377-1-stephen@networkplumber.org> <20220212184433.66791-1-stephen@networkplumber.org> 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. Signed-off-by: Stephen Hemminger --- lib/eal/linux/eal_debug.c | 46 +++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/lib/eal/linux/eal_debug.c b/lib/eal/linux/eal_debug.c index 64dab4e0da24..51f24e3cccdf 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,47 @@ #define BACKTRACE_SIZE 256 -/* dump the stack of the calling core */ +/* Dump the stack of the calling core + * + * Note: this requires limiting what functions are used in this code to stay safe + * when called from a signal handler and malloc pool maybe corrupt. + */ 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; + for (i = 0; i < size; i++) { + void *pc = func[i]; + const char *fname; + Dl_info info; - while (size > 0) { - rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL, - "%d: [%s]\n", size, symb[size - 1]); - size --; - } + if (dladdr(pc, &info) == 0) { + /* If symbol information not found print in hex */ + rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL, + "%d: ?? [%p]\n", i, pc); + continue; + } - free(symb); + /* Is file name known? */ + fname = (info.dli_fname && *info.dli_fname) ? info.dli_fname : "(vdso)"; + + /* Is symbol name known? */ + if (info.dli_sname != 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); + } #endif /* RTE_BACKTRACE */ } -- 2.34.1