This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RE: [PATCH v4 04/12] btrace: Use function segment index in call iterator.
- From: "Metzger, Markus T" <markus dot t dot metzger at intel dot com>
- To: "Wiederhake, Tim" <tim dot wiederhake at intel dot com>, "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Cc: "simon dot marchi at polymtl dot ca" <simon dot marchi at polymtl dot ca>
- Date: Thu, 11 May 2017 10:02:38 +0000
- Subject: RE: [PATCH v4 04/12] btrace: Use function segment index in call iterator.
- Authentication-results: sourceware.org; auth=none
- Dlp-product: dlpe-windows
- Dlp-reaction: no-action
- Dlp-version: 10.0.102.7
- References: <1494416867-19612-1-git-send-email-tim.wiederhake@intel.com> <1494416867-19612-5-git-send-email-tim.wiederhake@intel.com>
Hello Tim,
> /* See btrace.h. */
> @@ -2702,26 +2684,14 @@ btrace_find_call_by_number (struct
> btrace_call_iterator *it,
> const struct btrace_thread_info *btinfo,
> unsigned int number)
> {
> - const struct btrace_function *bfun;
> + const unsigned int length = btinfo->functions.size ();
>
> - for (bfun = btinfo->end; bfun != NULL; bfun = bfun->flow.prev)
> - {
> - unsigned int bnum;
> -
> - bnum = bfun->number;
> - if (number == bnum)
> - {
> - it->btinfo = btinfo;
> - it->function = bfun;
> - return 1;
> - }
> -
> - /* Functions are ordered and numbered consecutively. We could bail out
> - earlier. On the other hand, it is very unlikely that we search for
> - a nonexistent function. */
> - }
> + if ((number == 0) || (number > length))
> + return 0;
>
> - return 0;
> + it->btinfo = btinfo;
> + it->index = number - 1;
> + return 1;
> }
We have those +1 and -1 operations throughout the code. Should we introduce
some small helpers to document what we're doing? E.g.
static inline unsigned int btrace_call_number_from_index (unsigned int call_index)
{
return call_index + 1;
}
and
static inline unsigned int btrace_call_number_to_index (unsigned int call_number)
{
return call_number - 1;
}
Regards,
Markus.
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928