Пример #1
0
//--------------------------------------------------------------------------
int idaapi debmod_t::dbg_update_bpts(
      update_bpt_info_t *bpts,
      int nadd,
      int ndel)
{
  // Write breakpoints to the process
  int cnt = 0;
  update_bpt_info_t *b;
  update_bpt_info_t *end = bpts + nadd;
  for ( b=bpts; b != end; b++ )
  {
    int code = b->code;
    if ( code != BPT_OK )
      continue;
    uchar len;
    char buf[32];
    int nread = 0;
    ea_t ea = b->ea;
    if ( b->type == BPT_SOFT )
    {
      len = bpt_code.size();
#ifdef __ARM__
      if ( (ea & 1) != 0 ) // T bit is set, use a thumb breakpoint
      {
        ea--;
        len = 2;
      }
#endif
      nread = len;
      if ( (debugger_flags & DBG_FLAG_CAN_CONT_BPT) == 0 )
      { // we must save the original bytes before adding the bpt
        QASSERT(30017, sizeof(buf) >= len);
        if ( dbg_read_memory(ea, buf, len) <= 0 )
          code = BPT_READ_ERROR;
      }
    }
    else
    {
      len = b->size;
    }
    if ( code == BPT_OK )
      code = dbg_add_bpt(b->type, ea, len) ? BPT_OK : BPT_WRITE_ERROR;

    b->code = code;
    if ( code == BPT_OK )
    {
      cnt++;
      if ( nread > 0 )
        b->orgbytes = bytevec_t(buf, nread);
    }
  }

  // Delete breakpoints from the process.
  end += ndel;
  for ( ; b != end; b++ )
  {
    b->code = BPT_OK;
    int len = b->type == BPT_SOFT ? b->orgbytes.size() : b->size;
    if ( dbg_del_bpt(b->type, b->ea, b->orgbytes.begin(), len) > 0 )
      cnt++;
    else
      b->code = BPT_WRITE_ERROR;
  }

  return cnt;
}
Пример #2
0
//--------------------------------------------------------------------------
int idaapi debmod_t::dbg_update_bpts(
      update_bpt_info_t *ubpts,
      int nadd,
      int ndel)
{
  // Write breakpoints to the process
  int cnt = 0;
  update_bpt_info_t *b;
  update_bpt_info_t *end = ubpts + nadd;
  for ( b=ubpts; b != end; b++ )
  {
    int code = b->code;
    if ( code != BPT_OK )
      continue; // should be BPT_SKIP
    int len;
    uchar buf[32];
    memset(buf, 0, sizeof(buf));
    int nread = 0;
    ea_t ea = b->ea;
    if ( b->type == BPT_SOFT )
    {
      len = bpt_code.size();
      nread = read_bpt_orgbytes(&ea, &len, buf, sizeof(buf));
      if ( nread < 0 )
        code = BPT_READ_ERROR;
    }
    else
    {
      len = b->size;
    }
    if ( code == BPT_OK )
    {
      switch ( dbg_add_bpt(b->type, ea, len) )
      {
        case 2:
          code = BPT_PAGE_OK;
          break;
        case 1:
          code = BPT_OK;
          break;
        default:
          code = BPT_WRITE_ERROR;
          break;
      }
    }

    b->code = code;
    if ( code == BPT_OK )
    {
      cnt++;
      if ( nread > 0 )
        b->orgbytes = bytevec_t(buf, nread);
    }
  }

  // Delete breakpoints from the process.
  end += ndel;
  for ( ; b != end; b++ )
  {
    b->code = BPT_OK;
    int len = b->type == BPT_SOFT ? b->orgbytes.size() : b->size;
    if ( dbg_del_bpt(b->type, b->ea, b->orgbytes.begin(), len) > 0 )
      cnt++;
    else
      b->code = BPT_WRITE_ERROR;
  }

  return cnt;
}