This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: [PATCH v4 3/9] btrace: Use binary search to find instruction.


> -----Original Message-----
> From: Wiederhake, Tim
> Sent: Wednesday, January 4, 2017 1:46 PM
> To: gdb-patches@sourceware.org
> Cc: Metzger, Markus T <markus.t.metzger@intel.com>
> Subject: [PATCH v4 3/9] btrace: Use binary search to find instruction.

Hello Tim,

> @@ -1818,6 +1820,11 @@ btrace_fetch (struct thread_info *tp)
> 
>        btrace_clear_history (btinfo);
>        btrace_compute_ftrace (tp, &btrace);
> +
> +      VEC_truncate (btrace_fun_p, btinfo->functions, 0);
> +
> +      for (bfun = btinfo->begin; bfun != NULL; bfun = bfun->flow.next)
> +	VEC_safe_push (btrace_fun_p, btinfo->functions, bfun);

I'd truncate BTINFO->FUNCTIONS before calling btrace_compute_ftrace.

The function may throw - either due to errors or because the user lost patience
and interrupted trace processing.  This would leave us with stale pointers.

We should really run this loop also in case btrace_compute_ftrace was
interrupted.  The trace will be incomplete but we won't discard what we
already computed.


> +  for (;;)
> +    {
> +      const unsigned int average = lower + (upper - lower) / 2;
> +
> +      bfun = VEC_index (btrace_fun_p, btinfo->functions, average);
> +
> +      if (number < bfun->insn_offset)
> +	{
> +	  upper = average - 1;
> +	  continue;
> +	}
> +
> +      if (number >= bfun->insn_offset + ftrace_call_num_insn (bfun))
> +	{
> +	  lower = average + 1;
> +	  continue;
> +	}
> +
> +      break;
> +    }

It is OK to assume that there are no holes in the numbering.  We may want
to spell this out in a comment.

Thanks,
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]