X-Git-Url: http://git.jankratochvil.net/?a=blobdiff_plain;f=debugger.c;h=94d8a641ac7c576822afc5ccaaf3742d04794498;hb=332e3308058ae9187d3e287de1831f6b97cba882;hp=457df8462dae4736818f8b17c9d1c1e4d75c49b0;hpb=da6b0f102bb60e5b73d0dd0c5555a16f7f7a5109;p=debugger.git diff --git a/debugger.c b/debugger.c index 457df84..94d8a64 100644 --- a/debugger.c +++ b/debugger.c @@ -19,7 +19,10 @@ #if 0 #define USLEEP (1000000 / 2) #endif -#define TIMEOUT_SECS 10 +#define TIMEOUT_SECS 20 +/* LOOPS_MIN is a safety as QEMU clock time sucks. + 100000 is 4s natively and 53s in QEMU. */ +#define LOOPS_MIN 500000 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) @@ -68,6 +71,7 @@ enum state STATE_STOPPED, STATE_PTRACED, STATE_ZOMBIE, + STATE_DEAD, STATE_LAST }; @@ -82,6 +86,7 @@ static const char *state_to_name (enum state state) case STATE_STOPPED: return "STATE_STOPPED"; case STATE_PTRACED: return "STATE_PTRACED"; case STATE_ZOMBIE: return "STATE_ZOMBIE"; + case STATE_DEAD: return "STATE_DEAD"; default: crash (); } /* NOTREACHED */ @@ -128,6 +133,9 @@ static enum state state_get (pid_t pid) found = STATE_PTRACED; else if (strcmp (line + length, "Z (zombie)\n") == 0) found = STATE_ZOMBIE; + /* FIXME: What does it mean? */ + else if (strcmp (line + length, "X (dead)\n") == 0) + found = STATE_DEAD; else { fprintf (stderr, "Found an unknown state: %s", line + length); @@ -147,6 +155,7 @@ static enum state state (pid_t pid, unsigned expect_mask, const char *expect_mas { enum state found; time_t timeout = time (NULL) + TIMEOUT_SECS; + unsigned loops = 0; /* Sanity check `1 << enum state' was not misplaced with `enum state'. */ assert (1 << (STATE_FIRST + 1) >= STATE_LAST); @@ -165,7 +174,7 @@ static enum state state (pid_t pid, unsigned expect_mask, const char *expect_mas if (((1 << found) & expect_mask) != 0) return found; } - while (time (NULL) < timeout); + while (loops++ < LOOPS_MIN || time (NULL) < timeout); fprintf (stderr, "Found for PID %d state %s but expecting (%s)\n", (int) pid, state_to_name (found), expect_mask_string);