From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 122516EC55; Mon, 12 Jul 2021 14:43:04 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 122516EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1626090184; bh=oNlS84iAOPIXecnXGT6FSr50nV4ndqIam2MwzXKpo+0=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=hyo9NVZ4w4ziLz0Enr3YUUVKEors5efVx+5rJHMTXFm/fgUb2+ax+aF7wy8hgc5jP 0iOIlEckCmnTamSrBFwIIu00krAyjte8HxDVN/R2LZwr9Go5kcBdeI+zad8ShAFlXy PsQ1zCN0s2eugVTgXLIL0Vv4nY2qtB1xgnQVcO0k= Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 55C746EC55 for ; Mon, 12 Jul 2021 14:43:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 55C746EC55 Received: by mail-lf1-f45.google.com with SMTP id q18so42740989lfc.7 for ; Mon, 12 Jul 2021 04:43:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=wH+ZKinWkHa3pEMzWCWs5U5WCN4fQjO+SGLcYi0yTV4=; b=Aoz+sF4QqGMFBsDszKgblyEu9wFBjIKxUxR87SFvzCQp62wzn+xHDwXpaWEnrbhuUd FsFBdaJi1+dqZB+uleJbj8cq3cM/cWynaUBy9E97YYJq05iBUHD4Y+sIo7heGfCg3oLh UX1FFtRQ5MkjTcLKUuUe9jhtjZ+PCUWTc+PrNvDpYcDi5dWa0OdAQMNTyY0Kz7L60Z20 5BoAJYnyKNaojt7olufdAzBN0CemMC93J/VlhD+WEyM8h8f9WkTMC+B1l8R1PAagHw0S hXsHdZR/J/uuoyjkVhpD7oAfsXK8AIlPUhXuLdkc8ZcxTNV6feNTq62zCRNhXzfTPl1Q XMkA== X-Gm-Message-State: AOAM531RJKezO+notk972vLOAUFGSuxtIiB03nps1ba9SWln3gY0/HVp caL/PHey2rN2pLWizbsfm3hU7Ik85ZOMmA== X-Google-Smtp-Source: ABdhPJwbkETlk2evPUQYWbUmV+RKJdtbvYLvmEIfAo4KN8yWSlZIfsMUNPQT/duFAwJAS6ZzE3kEGg== X-Received: by 2002:ac2:58f5:: with SMTP id v21mr11596994lfo.659.1626090181158; Mon, 12 Jul 2021 04:43:01 -0700 (PDT) Received: from grain.localdomain ([5.18.199.94]) by smtp.gmail.com with ESMTPSA id u16sm1553333ljj.113.2021.07.12.04.42.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 04:43:00 -0700 (PDT) Received: by grain.localdomain (Postfix, from userid 1000) id 8273D5A001E; Mon, 12 Jul 2021 14:42:59 +0300 (MSK) Date: Mon, 12 Jul 2021 14:42:59 +0300 To: Egor Elchinov via Tarantool-patches Message-ID: References: <33f4fb50a51ba31e09685d0c7f85b1f8543e7fbd.1625827535.git.elchinov.es@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <33f4fb50a51ba31e09685d0c7f85b1f8543e7fbd.1625827535.git.elchinov.es@gmail.com> User-Agent: Mutt/2.0.7 (2021-05-04) Subject: Re: [Tarantool-patches] [PATCH v2 1/4] fiber: add PoC for fiber creation backtrace X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Cyrill Gorcunov via Tarantool-patches Reply-To: Cyrill Gorcunov Cc: Egor Elchinov Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" On Fri, Jul 09, 2021 at 02:03:50PM +0300, Egor Elchinov via Tarantool-patches wrote: > +void > +backtrace_foreach_ip(backtrace_cb cb, void **ip_buf, int limit, > + void *cb_ctx) > +{ > +#ifndef TARGET_OS_DARWIN > + char proc_name[BACKTRACE_NAME_MAX]; > + unw_word_t ip = 0, offset = 0; > + unw_proc_info_t pi; > + int frame_no, ret = 0; > + char *proc = NULL; > + > + unw_accessors_t *acc = unw_get_accessors(unw_local_addr_space); > + > + /* > + * RIPs collecting comes from inside a helper routine > + * so we skip the collector function address itself thus > + * start fetching functions with frame number = 1. > + */ > + for (frame_no = 1; frame_no < limit && ip_buf[frame_no] != NULL; > + frame_no++) { > + ip = (unw_word_t)ip_buf[frame_no]; > + > + if (acc->get_proc_name == NULL) { > + ret = unw_get_proc_info_by_ip(unw_local_addr_space, > + ip, &pi, NULL); > + offset = ip - pi.start_ip; > + } else { > + ret = acc->get_proc_name(unw_local_addr_space, ip, > + proc_name, sizeof(proc_name), > + &offset, NULL); > + proc = proc_name; > + } > + if (ret != 0 || cb(frame_no - 1, (void *)ip, proc, > + (size_t)offset, cb_ctx) != 0) > + break; > + } > + > + if (ret != 0) > + say_debug("unwinding error: %s", unw_strerror(ret)); > +#else > + int frame_no, ret = 1; > + void *ip = NULL; > + size_t offset = 0; > + Dl_info dli; > + > + for (frame_no = 1; frame_no < limit && ip_buf[frame_no] != NULL; > + ++frame_no) { > + ip = ip_buf[frame_no]; > + ret = dladdr(ip, &dli); > + offset = (char *)ip - (char *)dli.dli_saddr; > + > + if (cb(frame_no - 1, ip, dli.dli_sname, offset, cb_ctx) != 0) > + break; Looks like you forgot to test for dladdr error if I'm not missing something obvious. So it could be like ret = dladdr(ip, &dli); if (ret == 0) break; offset = (char *)ip - (char *)dli.dli_saddr; if (cb(frame_no - 1, ip, dli.dli_sname, offset, cb_ctx) != 0) break; no? > + } > + > + if (ret == 0) > + say_debug("unwinding error: %i", ret); > +#endif > +}