Bug 16797

Summary: GDB for mips-elf target will crash the remote embedded target
Product: gdb Reporter: ggs334 <guosheng_gao>
Component: tdepAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: critical CC: tromey
Priority: P2    
Version: 7.7   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description ggs334 2014-04-02 08:48:13 UTC
In the function mips-tdep.c:heuristic_pro_start(struct *gdbarch, CORE_ADDR pc)
If the pc value < instlen,
Are we still need to search back for previous return.

static CORE_ADDR
heuristic_proc_start (struct gdbarch *gdbarch, CORE_ADDR pc)
{
  CORE_ADDR start_pc;
  CORE_ADDR fence;
  int instlen;
  int seen_adjsp = 0;
  struct inferior *inf;

  pc = gdbarch_addr_bits_remove (gdbarch, pc);
  start_pc = pc;
  fence = start_pc - heuristic_fence_post;
  if (start_pc == 0)
    return 0;

  if (heuristic_fence_post == UINT_MAX || fence < VM_MIN_ADDRESS)
    fence = VM_MIN_ADDRESS;

  instlen = mips_pc_is_mips (pc) ? MIPS_INSN32_SIZE : MIPS_INSN16_SIZE;

  inf = current_inferior ();

/* Search back for previous return.  */ 
/* if pc (start_pc ) < instlen, the first value of start_pc -= instlen will skip over 0xffffffff, 
In this case, GDB will try to read the memory at string address, which will crash the remote embedded target. 
Is this true ? */
  for (start_pc -= instlen;; start_pc -= instlen)
    if (start_pc < fence)
      {