gdb_handlesig (CPUState *env, int sig)

{

  GDBState *s;

  char buf[256];

  int n;



  s = &gdbserver_state;

  if (gdbserver_fd < 0 || s->fd < 0)

    return sig;



  /* disable single step if it was enabled */

  cpu_single_step(env, 0);

  tb_flush(env);



  if (sig != 0)

    {

      snprintf(buf, sizeof(buf), "S%02x", sig);

      put_packet(s, buf);

    }

  /* put_packet() might have detected that the peer terminated the 

     connection.  */

  if (s->fd < 0)

      return sig;



  sig = 0;

  s->state = RS_IDLE;

  s->running_state = 0;

  while (s->running_state == 0) {

      n = read (s->fd, buf, 256);

      if (n > 0)

        {

          int i;



          for (i = 0; i < n; i++)

            gdb_read_byte (s, buf[i]);

        }

      else if (n == 0 || errno != EAGAIN)

        {

          /* XXX: Connection closed.  Should probably wait for annother

             connection before continuing.  */

          return sig;

        }

  }

  sig = s->signal;

  s->signal = 0;

  return sig;

}

gdb_handlesig (CPUState *env, int sig)

{

  GDBState *s;

  char buf[256];

  int n;



  s = &gdbserver_state;

  if (gdbserver_fd < 0 || s->fd < 0)

    return sig;



  

  cpu_single_step(env, 0);

  tb_flush(env);



  if (sig != 0)

    {

      snprintf(buf, sizeof(buf), "S%02x", sig);

      put_packet(s, buf);

    }

  



  if (s->fd < 0)

      return sig;



  sig = 0;

  s->state = RS_IDLE;

  s->running_state = 0;

  while (s->running_state == 0) {

      n = read (s->fd, buf, 256);

      if (n > 0)

        {

          int i;



          for (i = 0; i < n; i++)

            gdb_read_byte (s, buf[i]);

        }

      else if (n == 0 || errno != EAGAIN)

        {

          



          return sig;

        }

  }

  sig = s->signal;

  s->signal = 0;

  return sig;

}

FUNC_0 (CPUState *VAR_0, int VAR_1)

{

  GDBState *s;

  char VAR_2[256];

  int VAR_3;



  s = &gdbserver_state;

  if (gdbserver_fd < 0 || s->fd < 0)

    return VAR_1;



  

  cpu_single_step(VAR_0, 0);

  tb_flush(VAR_0);



  if (VAR_1 != 0)

    {

      snprintf(VAR_2, sizeof(VAR_2), "S%02x", VAR_1);

      put_packet(s, VAR_2);

    }

  



  if (s->fd < 0)

      return VAR_1;



  VAR_1 = 0;

  s->state = RS_IDLE;

  s->running_state = 0;

  while (s->running_state == 0) {

      VAR_3 = read (s->fd, VAR_2, 256);

      if (VAR_3 > 0)

        {

          int VAR_4;



          for (VAR_4 = 0; VAR_4 < VAR_3; VAR_4++)

            gdb_read_byte (s, VAR_2[VAR_4]);

        }

      else if (VAR_3 == 0 || errno != EAGAIN)

        {

          



          return VAR_1;

        }

  }

  VAR_1 = s->signal;

  s->signal = 0;

  return VAR_1;

}

FUNC_0 (CPUState *VAR_0, int VAR_1)
{ GDBState *s; char VAR_2[256]; int VAR_3; s = &gdbserver_state; if (gdbserver_fd < 0 || s->fd < 0)
return VAR_1; cpu_single_step(VAR_0, 0); tb_flush(VAR_0); if (VAR_1 != 0)
{ snprintf(VAR_2, sizeof(VAR_2), "S%02x", VAR_1); put_packet(s, VAR_2); } if (s->fd < 0)
return VAR_1; VAR_1 = 0; s->state = RS_IDLE; s->running_state = 0; while (s->running_state == 0) { VAR_3 = read (s->fd, VAR_2, 256); if (VAR_3 > 0)
{ int VAR_4; for (VAR_4 = 0; VAR_4 < VAR_3; VAR_4++) gdb_read_byte (s, VAR_2[VAR_4]); } else if (VAR_3 == 0 || errno != EAGAIN)
{ return VAR_1; } } VAR_1 = s->signal; s->signal = 0; return VAR_1; }