On 05/07/2015 12:45 PM, Antoine Tremblay wrote:
Just fyi, I'm working on doing this at the moment, my investigation is
still incomplete...
So far I mainly plan to port the arm_get_next code to gdbserver, to
accomplish 1. , the code doesn't have so many deps so it should be ok
2. by looking at $cpsr
3. should be fine as 1 and 2 are done...
I don't know however yet the best strategy to share the code but I'm
guessing I could make the parts that don't have any deps to gdbarch etc
in a shared function with gdb/gdbserver... Any pointers on this are
welcome...
Yeah, sharing is good.
Maybe adding an abstraction layer object, like:
struct get_next_pc;
struct get_next_pc_ops
{
void (*read_memory) (struct get_next_pc *self, ...);
void (*read_register) (struct get_next_pc *self, ...);
...
};
struct get_next_pcs
{
struct get_next_pc_ops *vtable;
VEC(CORE_ADDR) *result;
enum bfd_endian byte_order;
enum bfd_endian byte_order_for_code;
whatever_type whatever_other_context;
...
};
And then both GDB and GDBserver would instantiate
a struct get_next_pc object, like:
struct get_next_pc_ops gdb_get_next_pc_ops = {
gdb_get_next_pc_read_memory,
gdb_get_next_pc_read_register,
...
}
struct gdb_get_next_pcs
{
struct get_next_pc base;
// add whatever other context only gdb needs.
};
int
arm_software_single_step (struct frame_info *frame)
{
struct gdbarch *gdbarch = get_frame_arch (frame);
struct gdb_get_next_pc next_pc;
CORE_ADDR pc;
next_pc.vtable = gdb_get_next_pc_ops;
next_pc.byte_order = gdbarch_byte_order (gdbarch);
next_pc.byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
// arm_get_next_pcs is the existing gdb code adjusted to the
// new interface.
arm_get_next_pcs (&next_pc);
// walk result vec (a VEC of CORE_ADDRs) and insert breakpoints.
// alternatively add a insert_breakpoint callback to struct get_next_pc_ops
// and insert breakpoints from within arm_get_next_pcs, as currently.
for (i = 0;
VEC_iterate (CORE_ADDR, next_pcs.result, i, pc);
++i)
{
arm_insert_single_step_breakpoint (gdbarch, aspace, pc);
}
return 1;
}