diff --git a/util/grind/commands.g b/util/grind/commands.g index cb4e7d52b..d1c7eeeb2 100644 --- a/util/grind/commands.g +++ b/util/grind/commands.g @@ -19,6 +19,7 @@ extern char *Salloc(); extern char *strindex(); +extern char *strcpy(); extern FILE *db_in; extern int disable_intr; extern p_tree run_command, print_command; diff --git a/util/grind/do_comm.c b/util/grind/do_comm.c index 5c7d29c83..1be86d1b9 100644 --- a/util/grind/do_comm.c +++ b/util/grind/do_comm.c @@ -189,8 +189,8 @@ do_help(p) /* implementation of dump/restore commands */ -extern long pointer_size; extern p_tree get_from_item_list(); +extern t_addr get_dump(); struct dump { char *globals, *stack; @@ -209,12 +209,12 @@ do_dump(p) error("could not allocate enough memory"); return; } - if (! get_dump(&d->mglobal, &d->globals, &d->mstack, &d->stack)) { + p->t_address = get_dump(&d->mglobal, &d->globals, &d->mstack, &d->stack); + if (! p->t_address) { free((char *) d); return; } p->t_args[0] = (struct tree *) d; - p->t_address = (t_addr) get_int(d->mglobal.m_buf+PC_OFF*pointer_size, pointer_size, T_UNSIGNED); add_to_item_list(p); d->next = last_dump; last_dump = d; @@ -597,11 +597,11 @@ do_regs(p) } fprintf(db_out, "EM registers %d levels back:\n", n); fprintf(db_out, "\tLocalBase =\t0x%lx\n\tArgumentBase =\t0x%lx\n", - (long) buf[LB_OFF], (long) buf[AB_OFF]); + (long) buf[0], (long) buf[1]); fprintf(db_out, "\tProgramCounter=\t0x%lx\n\tHeapPointer = \t0x%lx\n", - (long) buf[PC_OFF], - (long) buf[HP_OFF]); - fprintf(db_out, "\tStackPointer =\t0x%lx\n", (long) buf[SP_OFF]); + (long) buf[2], + (long) buf[3]); + fprintf(db_out, "\tStackPointer =\t0x%lx\n", (long) buf[4]); } /* ------------------------------------------------------------- */ @@ -623,8 +623,8 @@ do_where(p) if (p && p->t_ival < 0) { for (;;) { buf = get_EM_regs(i++); - if (! buf || ! buf[AB_OFF]) break; - PC = buf[PC_OFF]; + if (! buf || ! buf[1]) break; + PC = buf[2]; sc = base_scope(get_scope_from_addr(PC)); if (! sc || sc->sc_start > PC) break; if (interrupted) return; @@ -640,8 +640,8 @@ do_where(p) if (interrupted) return; if (! (buf = get_EM_regs(i++))) break; - AB = buf[AB_OFF]; - PC = buf[PC_OFF]; + AB = buf[1]; + PC = buf[2]; if (! AB) break; sc = base_scope(get_scope_from_addr(PC)); if (! sc || sc->sc_start > PC) break; diff --git a/util/grind/message.h b/util/grind/message.h index 1466f86c0..cf4b96dd5 100644 --- a/util/grind/message.h +++ b/util/grind/message.h @@ -1,51 +1,65 @@ /* $Header$ */ -#define BUFLEN 24 /* size of buffer in message header */ +#define BUFLEN 32 /* size of buffer in message header */ + +#define M_DB_RUN 0100 /* set for commands that cause child to run */ +#define M_DB_SS 0200 /* debugger wants single stepping (to be orred + with SETSS(F) or CONT + */ + +#define m_type m_buf[0] + +#ifdef DEBUGGEE +#define PS sizeof(char *) +#define LS sizeof(long) +#else +#define PS pointer_size +#define LS long_size +#endif struct message_hdr { - int m_type; -/* Possible values of m_type: */ -#define M_DB_RUN 020000 /* set for commands that cause child to run */ -#define M_SETBP 0 /* set breakpoint at address in m_size */ -#define M_CLRBP 1 /* clear breakpoint at address in m_size */ -#define M_SETSS (2|M_DB_RUN) /* set single stepping, # of steps in m_size */ -#define M_SETSSF (3|M_DB_RUN) /* set single stepping, counting calls as one step */ -#define M_GETEMREGS 4 /* get EM registers, m_size contains level */ -#define M_GETBYTES 5 /* get data; m_size contains size, m_buf contains address */ -#define M_GETSTR 6 /* get string; m_buf contains address */ -#define M_SETBYTES 7 /* set data; m_buf contains address, m_size contains size */ -#define M_CALL 8 /* call function; - m_size contains size of parameter buffer, - m_buf contains address + size of function result - */ -#define M_CONT (9|M_DB_RUN) /* continue */ -#define M_SETEMREGS 10 /* set EM registers, m_size contains level - Actually, only the program counter is set. - */ -#define M_DB_SS 040000 /* debugger wants single stepping (to be orred with - SETSS(F) or CONT - */ -#define M_CLRSS 12 /* clear single stepping */ -#define M_DUMP 13 /* dump command */ -#define M_DGLOB 14 /* data area */ + char m_buf[BUFLEN]; +/* Possible values of m_buf[0]: */ +#define M_SETBP 0 /* set breakpoint at address in next PS bytes */ +#define M_CLRBP 1 /* clear breakpoint at address in next PS bytes */ +#define M_SETSS (2|M_DB_RUN) + /* set single stepping, # of steps in next LS bytes */ +#define M_SETSSF (3|M_DB_RUN) + /* set single stepping, + counting calls as one step + */ +#define M_GETEMREGS 4 /* get EM registers, level in next LS bytes */ +#define M_GETBYTES 5 /* get data; size in next LS bytes, + address in next PS bytes + */ +#define M_GETSTR 6 /* get string; max size in next LS bytes, + address in next PS bytes + */ +#define M_SETBYTES 7 /* get data; size in next LS bytes, + address in next PS bytes + */ +/* #define M_CALL 8 /* call function; not implemented */ +#define M_CONT (9|M_DB_RUN) + /* continue */ +#define M_SETEMREGS 10 /* set EM registers, level in next LS bytes; + Actually, only the program counter is set. + */ +#define M_CLRSS 12 /* clear single stepping */ +#define M_DUMP 13 /* dump command */ +#define M_DGLOB 14 /* data area */ #define M_DSTACK 15 /* stack area */ -#define M_SETTRACE 16 /* start tracing; range in m_mes */ -#define M_CLRTRACE 17 /* end tracing */ +#define M_SETTRACE 16 /* start tracing; range in next two PS bytes */ +#define M_CLRTRACE 17 /* end tracing */ -#define M_OK 50 /* answer of child to most messages */ -#define M_FAIL 51 /* answer of child when something goes wrong */ -#define M_DATA 52 /* answer of child when data requested */ -#define M_END_SS 53 /* when stopped because of user single stepping */ -#define M_INTR 54 /* sent on interrupt */ - long m_size; /* size */ - char m_buf[BUFLEN]; /* some of the data required included in message */ +#define M_OK 50 /* answer of child to most messages */ +#define M_FAIL 51 /* answer of child when something goes wrong */ +#define M_DATA 52 /* answer of child when data requested */ +#define M_END_SS 53 /* stopped because of user single stepping */ +#define M_INTR 54 /* sent on interrupt */ }; -#define LB_OFF 0 -#define AB_OFF 1 -#define PC_OFF 2 -#define HP_OFF 3 -#define SP_OFF 4 - -#define IN_FD 3 -#define OUT_FD 6 +#define LB_OFF (0*PS+LS+1) +#define AB_OFF (1*PS+LS+1) +#define PC_OFF (2*PS+LS+1) +#define HP_OFF (3*PS+LS+1) +#define SP_OFF (4*PS+LS+1) diff --git a/util/grind/run.c b/util/grind/run.c index 9ffb506d2..e5b1a0e22 100644 --- a/util/grind/run.c +++ b/util/grind/run.c @@ -48,17 +48,46 @@ static int uputm(), ugetm(); static t_addr curr_stop; p_tree run_command; +static +ITOBUF(p, l, sz) + register char *p; + long l; + int sz; +{ + register int i; + + p +=sz; + for (i = sz; i > 0; i--) { + *--p = l; + l >>= 8; + } +} + +static long +BUFTOI(p, sz) + register char *p; + int sz; +{ + register long l = 0; + register int i; + + for (i = sz; i>0; i--) { + l = (l << 8) | (*p++ & 0377); + } + return l; +} + int init_run() { /* take file descriptors so that listing cannot take them */ int i; - for (i = IN_FD; i <= OUT_FD; i++) close(i); + for (i = 3; i <= 6; i++) close(i); if (pipe(fild1) < 0 || pipe(fild2) < 0 || - fild1[0] != IN_FD || - fild2[1] != OUT_FD) { + fild1[0] != 3 || + fild2[1] != 6) { return 0; } to_child = fild1[1]; @@ -189,7 +218,7 @@ start_child(p) init_run(); return 0; } - curr_stop = m.m_size; + curr_stop = BUFTOI(m.m_buf+1, (int) PS); CurrentScope = get_scope_from_addr(curr_stop); } perform_items(); @@ -374,7 +403,7 @@ could_send(m, stop_message) if (! level) { child_interrupted = 0; interrupted = 0; - stopped("interrupted", (t_addr) answer.m_size); + stopped("interrupted", (t_addr) BUFTOI(answer.m_buf+1, (int)PS)); } return 1; } @@ -395,8 +424,8 @@ could_send(m, stop_message) level--; return 1; } - a = answer.m_size; - type = answer.m_type; + a = BUFTOI(answer.m_buf+1, (int)PS); + type = answer.m_type & 0377; if (m->m_type & M_DB_RUN) { /* run command */ CurrentScope = get_scope_from_addr((t_addr) a); @@ -408,7 +437,7 @@ could_send(m, stop_message) have gotten END_SS. So, continue. */ - if ((m->m_type & ~ M_DB_SS) != M_CONT) { + if ((m->m_type & 0177) != M_CONT) { m->m_type = M_CONT | (m->m_type & M_DB_SS); } continue; @@ -437,8 +466,8 @@ getbytes(size, from, to, kind) struct message_hdr m; m.m_type = kind; - m.m_size = size; - put_int(m.m_buf, pointer_size, (long)from); + ITOBUF(m.m_buf+1, size, (int) LS); + ITOBUF(m.m_buf+LS+1, (long)from, (int) PS); if (! could_send(&m, 0)) { return 0; @@ -452,7 +481,7 @@ getbytes(size, from, to, kind) error("interrupted"); return 0; case M_DATA: - return ureceive(to, answer.m_size); + return ureceive(to, BUFTOI(answer.m_buf+1, (int)LS)); default: assert(0); } @@ -476,7 +505,7 @@ get_string(size, from, to) { int retval = getbytes(size, from, to, M_GETSTR); - to[(int)answer.m_size] = 0; + to[(int)BUFTOI(answer.m_buf+1, (int)LS)] = 0; return retval; } @@ -488,8 +517,8 @@ set_bytes(size, from, to) struct message_hdr m; m.m_type = M_SETBYTES; - m.m_size = size; - put_int(m.m_buf, pointer_size, (long) to); + ITOBUF(m.m_buf+1, size, (int) LS); + ITOBUF(m.m_buf+LS+1, (long) to, (int) PS); if (! uputm(&m) || ! usend(from, size) || ! ugetm(&m)) { return; @@ -508,12 +537,13 @@ set_bytes(size, from, to) } } -int +t_addr get_dump(globmessage, globbuf, stackmessage, stackbuf) struct message_hdr *globmessage, *stackmessage; char **globbuf, **stackbuf; { struct message_hdr m; + long sz; m.m_type = M_DUMP; if (! could_send(&m, 0)) { @@ -533,27 +563,28 @@ get_dump(globmessage, globbuf, stackmessage, stackbuf) } *globmessage = answer; - *globbuf = malloc((unsigned) answer.m_size); - if (! ureceive(*globbuf, answer.m_size) || ! ugetm(stackmessage)) { + sz = BUFTOI(answer.m_buf+1, (int)LS); + *globbuf = malloc((unsigned) sz); + if (! ureceive(*globbuf, sz) || ! ugetm(stackmessage)) { if (*globbuf) free(*globbuf); return 0; } assert(stackmessage->m_type == M_DSTACK); - *stackbuf = malloc((unsigned) stackmessage->m_size); - if (! ureceive(*stackbuf, stackmessage->m_size)) { + sz = BUFTOI(stackmessage->m_buf+1, (int)LS); + *stackbuf = malloc((unsigned) sz); + if (! ureceive(*stackbuf, sz)) { if (*globbuf) free(*globbuf); if (*stackbuf) free(*stackbuf); return 0; } - put_int(globmessage->m_buf+SP_OFF*pointer_size, pointer_size, - get_int(stackmessage->m_buf+SP_OFF*pointer_size, pointer_size, T_UNSIGNED)); + ITOBUF(globmessage->m_buf+SP_OFF, BUFTOI(stackmessage->m_buf+SP_OFF, (int)PS), (int) PS); if (! *globbuf || ! *stackbuf) { error("could not allocate enough memory"); if (*globbuf) free(*globbuf); if (*stackbuf) free(*stackbuf); return 0; } - return 1; + return BUFTOI(globmessage->m_buf+PC_OFF, (int)PS); } int @@ -569,9 +600,12 @@ put_dump(globmessage, globbuf, stackmessage, stackbuf) start_child(run_command); restoring = 0; } - retval = uputm(globmessage) && usend(globbuf, globmessage->m_size) && - uputm(stackmessage) && usend(stackbuf, stackmessage->m_size) && - ugetm(&m) && stopped("restored", m.m_size); + retval = uputm(globmessage) + && usend(globbuf, BUFTOI(globmessage->m_buf+1, (int) LS)) + && uputm(stackmessage) + && usend(stackbuf, BUFTOI(stackmessage->m_buf+1, (int) LS)) + && ugetm(&m) + && stopped("restored", BUFTOI(m.m_buf+1, (int) PS)); return retval; } @@ -584,7 +618,7 @@ get_EM_regs(level) register t_addr *to = &buf[0]; m.m_type = M_GETEMREGS; - m.m_size = level; + ITOBUF(m.m_buf+1, (long) level, (int) LS); if (! could_send(&m, 0)) { return 0; @@ -601,11 +635,11 @@ get_EM_regs(level) default: assert(0); } - *to++ = (t_addr) get_int(answer.m_buf, pointer_size, T_UNSIGNED); - *to++ = (t_addr) get_int(answer.m_buf+pointer_size, pointer_size, T_UNSIGNED); - *to++ = (t_addr) get_int(answer.m_buf+2*pointer_size, pointer_size, T_UNSIGNED); - *to++ = (t_addr) get_int(answer.m_buf+3*pointer_size, pointer_size, T_UNSIGNED); - *to++ = (t_addr) get_int(answer.m_buf+4*pointer_size, pointer_size, T_UNSIGNED); + *to++ = (t_addr) BUFTOI(answer.m_buf+LB_OFF, (int)PS); + *to++ = (t_addr) BUFTOI(answer.m_buf+AB_OFF, (int)PS); + *to++ = (t_addr) BUFTOI(answer.m_buf+PC_OFF, (int)PS); + *to++ = (t_addr) BUFTOI(answer.m_buf+HP_OFF, (int)PS); + *to++ = (t_addr) BUFTOI(answer.m_buf+PC_OFF, (int)PS); return buf; } @@ -616,8 +650,7 @@ set_pc(PC) struct message_hdr m; m.m_type = M_SETEMREGS; - m.m_size = 0; - put_int(m.m_buf+PC_OFF*pointer_size, pointer_size, (long)PC); + ITOBUF(m.m_buf+PC_OFF, (long)PC, (int)PS); if (! could_send(&m, 0)) return 0; switch(answer.m_type) { case M_FAIL: @@ -641,7 +674,6 @@ send_cont(stop_message) struct message_hdr m; m.m_type = (M_CONT | (db_ss ? M_DB_SS : 0)); - m.m_size = 0; return could_send(&m, stop_message) && child_pid; } @@ -653,7 +685,7 @@ singlestep(type, count) struct message_hdr m; m.m_type = type | (db_ss ? M_DB_SS : 0); - m.m_size = count; + ITOBUF(m.m_buf+1, count, (int) LS); single_stepping = 1; if (could_send(&m, 1) && child_pid) return 1; single_stepping = 0; @@ -668,7 +700,7 @@ set_or_clear_breakpoint(a, type) struct message_hdr m; m.m_type = type; - m.m_size = a; + ITOBUF(m.m_buf+1, (long) a, (int) PS); if (debug) printf("%s breakpoint at 0x%lx\n", type == M_SETBP ? "setting" : "clearing", (long) a); if (child_pid && ! could_send(&m, 0)) { } @@ -684,8 +716,8 @@ set_or_clear_trace(start, end, type) struct message_hdr m; m.m_type = type; - put_int(m.m_buf, pointer_size, (long)start); - put_int(m.m_buf+pointer_size, pointer_size, (long)end); + ITOBUF(m.m_buf+1, (long)start, (int) PS); + ITOBUF(m.m_buf+PS+1, (long)end, (int) PS); if (debug) printf("%s trace at [0x%lx,0x%lx]\n", type == M_SETTRACE ? "setting" : "clearing", (long) start, (long) end); if (child_pid && ! could_send(&m, 0)) { return 0; diff --git a/util/grind/value.c b/util/grind/value.c index ae13d5fc1..8262f8fce 100644 --- a/util/grind/value.c +++ b/util/grind/value.c @@ -53,12 +53,12 @@ get_addr(sym, psize) if (! (EM_regs = get_EM_regs(i++))) { return 0; } - if (! EM_regs[AB_OFF]) { + if (! EM_regs[1]) { error("%s not available", sym->sy_idf->id_text); return 0; } - sc = base_scope(get_scope_from_addr(EM_regs[PC_OFF])); - if (! sc || sc->sc_start > EM_regs[PC_OFF]) { + sc = base_scope(get_scope_from_addr(EM_regs[2])); + if (! sc || sc->sc_start > EM_regs[2]) { error("%s not available", sym->sy_idf->id_text); sc = 0; return 0; @@ -68,7 +68,7 @@ get_addr(sym, psize) if (sym->sy_class == LOCVAR) { /* Either local variable or value parameter */ - return EM_regs[sym->sy_name.nm_value < 0 ? LB_OFF : AB_OFF] + + return EM_regs[sym->sy_name.nm_value < 0 ? 0 : 1] + (t_addr) sym->sy_name.nm_value; } @@ -87,7 +87,7 @@ get_addr(sym, psize) error("could not allocate enough memory"); break; } - if (! get_bytes(size, EM_regs[AB_OFF], AB)) { + if (! get_bytes(size, EM_regs[1], AB)) { break; } if ((size = tp->ty_size) == 0) {