int stub_main(int arch_reason) { int ret; int gdb_signal; gdb_signal = decode_signal(arch_reason); /* Do not announce stop reply if we were detached. */ if (isattached) { send_stop_reply(gdb_signal); } /* We are now attached. */ isattached = 1; do { int cmd; char *p; while (getpkt(&pktbuf[0], sizeof(pktbuf)) < 1); p = &pktbuf[0]; cmd = *p; if ('?' == cmd) { send_stop_reply(gdb_signal); ret = 0; } else if ('c' == cmd) { ret = handle_c(p); } else if ('s' == cmd) { ret = handle_s(p); } else if ('D' == cmd) { ret = handle_D(p); if (ret & CMD_LEAVE) { isattached = 0; } } else if ('g' == cmd) { ret = handle_g(p); } else if ('G' == cmd) { ret = handle_G(p); } else if ('P' == cmd) { ret = handle_P(p); } else if ('m' == cmd) { ret = handle_m(p); } else if ('M' == cmd) { ret = handle_M(p); } else { /* * For any command not supported by the stub, an empty * response ('$#00') should be returned. */ p = ""; ret = CMD_REPLY; } if (ret & CMD_REPLY) { putpkt(p); } } while (!(ret & CMD_LEAVE)); return ret; }
int trapcmd(int argc, char **argv) { char *action; char **ap; int signo; nextopt(nullstr); ap = argptr; if (!*ap) { for (signo = 0 ; signo < NSIG ; signo++) { if (trap[signo] != NULL) { out1fmt( "trap -- %s %s\n", single_quote(trap[signo]), signal_names[signo] ); } } return 0; } if (!ap[1]) action = NULL; else action = *ap++; while (*ap) { if ((signo = decode_signal(*ap, 0)) < 0) { outfmt(out2, "trap: %s: bad trap\n", *ap); return 1; } INTOFF; if (action) { if (action[0] == '-' && action[1] == '\0') action = NULL; else { if (*action) trapcnt++; action = savestr(action); } } if (trap[signo]) { if (*trap[signo]) trapcnt--; ckfree(trap[signo]); } trap[signo] = action; if (signo != 0) setsignal(signo); INTON; ap++; } return 0; }