移植GDBzz.txt 通过break指令替换现有指令
关键代码段:
GDB:
//
_initialize_mips_linux_nat->
linux_trad_target->
inf_ptrace_trad_target->
inf_ptrace_target->
inf_child_target->
In fact Linux & BSD all call
inf_ptrace_target->
inf_child_target:
to_insert_breakpoint = memory_insert_breakpoint
//
insert_single_step_breakpoint->
deprecated_insert_raw_breakpoint->
target_insert_breakpoint=memory_insert_breakpoint
//
handle_inferior_event->
maybe_software_singlestep->
gdbarch_software_single_step->
mips_software_single_step
//
mips_software_single_step
mips_insert_breakpoint
//
memory_insert_breakpoint =
default_memory_insert_breakpoint
mips_breakpoint_from_pc(what for insert)
displaced_step_at_entry_point->
gdbarch_breakpoint_from_pc:mips_breakpoint_from_pc
//
default_memory_insert_breakpoint->
target_write_memory->target_write->
target_write_with_progress->target_write_partial->
target_xfer_partial->memory_xfer_partial
Linux:
linux_xfer_partial->linux_proc_xfer_partial :read (proc mem)
inf_ptrace_xfer_partial (PTRACE_POKETEXT)
BSD:
inf_ptrace_xfer_partial (ptrace (PT_WRITE_I) )
/* The IDT board uses an unusual breakpoint value, and
sometimes gets confused when it sees the usual MIPS
breakpoint instruction. */
static gdb_byte big_breakpoint[] = { 0, 0x5, 0, 0xd };
static gdb_byte pmon_big_breakpoint[] = { 0, 0, 0, 0xd };
static gdb_byte idt_big_breakpoint[] = { 0, 0, 0x0a, 0xd };
/* Likewise, IRIX appears to expect a different breakpoint,
although this is not apparent until you try to use pthreads. */
static gdb_byte irix_big_breakpoint[] = { 0, 0, 0, 0xd };
等待:
Linux:
_initialize_mips_linux_nat:linux_nat_add_target:linux_nat_wait
linux_nat_stopped_by_watchpoint = mips_linux_stopped_by_watchpoint(是否由watchpoint触发)
mips_linux_stopped_data_address
BSD:
_initialize_mipsnbsd_nat:inf_ptrace_target inf_ptrace_wait waitpid
////////////////
Low Level Get REGS: mips_read_pc->regcache_cooked_read_signed->
regcache_cooked_read->regcache_raw_read->target_fetch_registers->to_fetch_registers
mips_print_registers_info
mips_read_pc : mips64_linux_fetch_registers ptrace PTRACE_GETREGS
mipsnbsd_fetch_inferior_registers ptrace PT_GETREGS
Linux KERNEL:
set_except_vector(9, handle_bp);
handle_bp
[arch/mips/kernel/genex.S]
BUILD_HANDLER bp bp sti silent /* #9 */
do_/handler = do_bp
(kernel: notify_die)
do_trap_or_bp
force_sig(SIGTRAP, current);
BSD Kernel:
MipsKernGenException (exception.S):
PTR_LA gp, _C_LABEL(_gp)
PTR_LA k0, _C_LABEL(trap)
jalr k0
-> register_t trap(struct trapframe *trapframe):
case T_BREAK + T_USER:
->trapsignal