RE: Why enforcing sw_breakpoint_from_kind() implementation in GDBserver targets

Aktemur, Tankut Baris
2020-06-12T11:04:26Z

On Thursday, June 11, 2020 1:44 PM, Shahab Vahedi wrote:
> Hi Tankut,
>
> It'd be great if we could have your feedback on this too.
>
> Cheers,
> Shahab

Hi,

Before the gdbserver target definitions were converted into C++ classes,
the `sw_breakpoint_from_kind` target op in linux-low was defined as follows
(the code snippet is from gdb 9.1):

/* Implementation of the target_ops method "sw_breakpoint_from_kind". */

static const gdb_byte *
linux_sw_breakpoint_from_kind (int kind, int *size)
{
gdb_assert (the_low_target.sw_breakpoint_from_kind != NULL);

return (*the_low_target.sw_breakpoint_from_kind) (kind, size);
}

So, the base linux target delegates the op to the low target and enforces
an implementation.

The `sw_breakpoint_from_kind` target op is invoked in linux_wait_1 as follows:

if (step_over_bkpt != null_ptid
&& event_child->stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT
&& (event_child->stepping
|| !single_step_breakpoint_inserted_here (event_child->stop_pc)))
{
...
breakpoint_kind =
the_target->breakpoint_kind_from_current_state (&stop_pc);
the_target->sw_breakpoint_from_kind (breakpoint_kind, &increment_pc);
...
}

There are two additional uses in mem-break.c, in bp_size and bp_opcode, which are used
in several functions in mem-break.c. These uses as well as the one from linux_wait_1
above do not guard against whether the target op is implemented. Therefore it had made
sense to enforce that the target op is implemented by the linux low target by making it
pure virtual. All the linux low targets except ia64 implemented the
`sw_breakpoint_from_kind` target op.

Regards
-Baris

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, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928