From patchwork Mon Jun 20 14:17:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 70455 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp1534790qgy; Mon, 20 Jun 2016 07:17:46 -0700 (PDT) X-Received: by 10.55.50.14 with SMTP id y14mr21532895qky.42.1466432265980; Mon, 20 Jun 2016 07:17:45 -0700 (PDT) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id x31si39944298qtc.116.2016.06.20.07.17.45; Mon, 20 Jun 2016 07:17:45 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 5D41A650B5; Mon, 20 Jun 2016 14:17:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 9C86062BD4; Mon, 20 Jun 2016 14:17:39 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 3A07662BD6; Mon, 20 Jun 2016 14:17:38 +0000 (UTC) Received: from mail-lf0-f53.google.com (mail-lf0-f53.google.com [209.85.215.53]) by lists.linaro.org (Postfix) with ESMTPS id 18FE46172E for ; Mon, 20 Jun 2016 14:17:37 +0000 (UTC) Received: by mail-lf0-f53.google.com with SMTP id l188so38663508lfe.2 for ; Mon, 20 Jun 2016 07:17:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=fuGWJUxNmcMpNrhPxBvporyIzvE+2rBnoa718D5TLoU=; b=Xhh9mbrSBv1zVkZ0iYuxBSZbD3enbatEP3SanZcaT7JyzPYr1GwzdgtD1C4yOT8vo2 ctwJmjkaUso7Oj5A6SSbjUFmpANBhrblXX6/49cCZ3ORaJWCtEo3p/XFBh4Hbo5Gg5KO 8rmZcfswDdBGRwv2VwLB8GtJot+TTMH6BfqKF8Jyt+siTx4AMMbrmZslOGX5ckCpczld phFlyDGK//lDyZD6C1WsgSBMeW0Z7KO1cTAdXw0yxQDsdoPplywIV2ZSAc7FCHnB9gCT ntvQrCPPS/YCtrvPwH7qeLZ2MOYOgL0GM85ABskeJM6LypZkis9GmSuKE3gqaO7MypIn 4BKA== X-Gm-Message-State: ALyK8tKKvOXlBLk+8u2Hu/PJC1AlcIUcuzMdug4puIQFbrs2c2lRdJwj4rIPhImv/yXyZrEwikI= X-Received: by 10.46.33.152 with SMTP id h24mr3808802lji.38.1466432255855; Mon, 20 Jun 2016 07:17:35 -0700 (PDT) Received: from localhost.localdomain ([83.220.239.96]) by smtp.gmail.com with ESMTPSA id s87sm2937493lfg.46.2016.06.20.07.17.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 20 Jun 2016 07:17:35 -0700 (PDT) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Mon, 20 Jun 2016 17:17:27 +0300 Message-Id: <1466432247-31413-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.7.1.250.gff4ea60 X-Topics: patch Subject: [lng-odp] [PATCH] linux-generic: add stacktrace X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Add initial version for more verbose stacktrace for linux- generic odp platform. Usage: export ODP_STACKTRACE_ENABLE=y Thread 0 terminated with signal=11 (SIGSEGV) ./test/performance/odp_scheduling[0x4250b3] /lib/x86_64-linux-gnu/libpthread.so.0(+0x10330)[0x7f7ae5cc1330] ./test/performance/odp_scheduling[0x40a064] ./test/performance/odp_scheduling(main+0x2c1)[0x40a5dc] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7f7ae590df45] ./test/performance/odp_scheduling[0x408ed9] odp_stacktrace.c:57:fault_handler():Program interrupted Aborted Then convert address to function symbol with add2line: addr2line -e ./test/performance/odp_scheduling 0x4250b3 /opt/Linaro/odp3.git/platform/linux-generic/odp_stacktrace.c:49 Signed-off-by: Maxim Uvarov --- platform/linux-generic/Makefile.am | 1 + .../linux-generic/include/odp_debug_internal.h | 2 + platform/linux-generic/odp_init.c | 3 + platform/linux-generic/odp_stacktrace.c | 75 ++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 platform/linux-generic/odp_stacktrace.c diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 469869e..3598adc 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -171,6 +171,7 @@ __LIB__libodp_linux_la_SOURCES = \ odp_spinlock.c \ odp_spinlock_recursive.c \ odp_system_info.c \ + odp_stacktrace.c \ odp_thread.c \ odp_thrmask.c \ odp_ticketlock.c \ diff --git a/platform/linux-generic/include/odp_debug_internal.h b/platform/linux-generic/include/odp_debug_internal.h index 02ae87a..a43705f 100644 --- a/platform/linux-generic/include/odp_debug_internal.h +++ b/platform/linux-generic/include/odp_debug_internal.h @@ -83,6 +83,8 @@ extern "C" { #define ODP_PRINT(fmt, ...) \ odp_global_data.log_fn(ODP_LOG_PRINT, " " fmt, ##__VA_ARGS__) +void _odp_stracktrace_init(void); + #ifdef __cplusplus } #endif diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c index f58f410..492dd67 100644 --- a/platform/linux-generic/odp_init.c +++ b/platform/linux-generic/odp_init.c @@ -32,6 +32,9 @@ int odp_init_global(odp_instance_t *instance, odp_global_data.abort_fn = params->abort_fn; } + if (getenv("ODP_STACKTRACE_ENABLE")) + _odp_stracktrace_init(); + if (odp_cpumask_init_global(params)) { ODP_ERR("ODP cpumask init failed.\n"); goto init_failed; diff --git a/platform/linux-generic/odp_stacktrace.c b/platform/linux-generic/odp_stacktrace.c new file mode 100644 index 0000000..76a8803 --- /dev/null +++ b/platform/linux-generic/odp_stacktrace.c @@ -0,0 +1,75 @@ +/* Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +static odp_spinlock_t print_lock; + +static void fault_handler(int signal) +{ + size_t num_stack_frames; + const char *signal_name; + void *bt_array[4096]; + sigset_t sigset; + + /* disable all signals */ + sigfillset(&sigset); + sigprocmask(SIG_BLOCK, &sigset, NULL); + + switch (signal) { + case SIGILL: + signal_name = "SIGILL"; break; + case SIGFPE: + signal_name = "SIGFPE"; break; + case SIGSEGV: + signal_name = "SIGSEGV"; break; + case SIGTERM: + signal_name = "SIGTERM"; break; + case SIGBUS: + signal_name = "SIGBUS"; break; + default: + signal_name = "UNKNOWN"; break; + } + + odp_spinlock_lock(&print_lock); + num_stack_frames = backtrace(bt_array, 100); + fprintf(stderr, "\nThread %d terminated with signal=%u (%s)\n", + odp_thread_id(), signal, signal_name); + backtrace_symbols_fd(bt_array, num_stack_frames, fileno(stderr)); + fflush(NULL); + sync(); + odp_spinlock_unlock(&print_lock); + + ODP_ABORT("Program interrupted\n"); +} + +void _odp_stracktrace_init(void) +{ + struct sigaction signal_action; + + odp_spinlock_init(&print_lock); + + memset(&signal_action, 0, sizeof(signal_action)); + signal_action.sa_handler = fault_handler; + sigfillset(&signal_action.sa_mask); + + sigaction(SIGILL, &signal_action, NULL); + sigaction(SIGFPE, &signal_action, NULL); + sigaction(SIGSEGV, &signal_action, NULL); + sigaction(SIGTERM, &signal_action, NULL); + sigaction(SIGBUS, &signal_action, NULL); +}