ack/util/grind/dump.c

89 lines
1.6 KiB
C
Raw Normal View History

1990-08-31 18:22:53 +00:00
/* $Header$ */
#include <assert.h>
#include <alloc.h>
#include "operator.h"
#include "position.h"
#include "tree.h"
#include "message.h"
1990-09-25 17:40:47 +00:00
#include "type.h"
#include "expr.h"
1990-08-31 18:22:53 +00:00
extern long pointer_size;
extern p_tree get_from_item_list();
struct dump {
char *globals, *stack;
struct message_hdr mglobal, mstack;
1990-10-17 17:00:03 +00:00
struct dump *next;
1990-08-31 18:22:53 +00:00
};
1990-10-17 17:00:03 +00:00
static struct dump *last_dump;
1990-08-31 18:22:53 +00:00
/* dumping and restoring of child process.
*/
do_dump(p)
p_tree p;
{
1990-09-26 17:32:42 +00:00
struct dump *d = (struct dump *) malloc(sizeof(struct dump));
1990-08-31 18:22:53 +00:00
1990-09-26 17:32:42 +00:00
if (! d) {
error("could not allocate enough memory");
return;
}
1990-08-31 18:22:53 +00:00
if (! get_dump(&d->mglobal, &d->globals, &d->mstack, &d->stack)) {
free((char *) d);
return;
}
p->t_args[0] = (struct tree *) d;
1990-09-25 17:40:47 +00:00
p->t_address = (t_addr) get_int(d->mglobal.m_buf+PC_OFF*pointer_size, pointer_size, T_UNSIGNED);
1990-08-31 18:22:53 +00:00
add_to_item_list(p);
1990-10-17 17:00:03 +00:00
d->next = last_dump;
last_dump = d;
1990-08-31 18:22:53 +00:00
}
/* dumping and restoring of child process.
*/
do_restore(p)
p_tree p;
{
struct dump *d;
1990-10-17 17:00:03 +00:00
if (p->t_args[0]) {
p = get_from_item_list((int) p->t_args[0]->t_ival);
if (!p || p->t_oper != OP_DUMP) {
error("no such dump");
return;
}
d = (struct dump *) p->t_args[0];
1990-08-31 18:22:53 +00:00
}
1990-10-17 17:00:03 +00:00
else d = last_dump;
1990-08-31 18:22:53 +00:00
1990-10-17 17:00:03 +00:00
if (! d) {
error("no dumps");
return;
}
1990-08-31 18:22:53 +00:00
if (! put_dump(&d->mglobal, d->globals, &d->mstack, d->stack)) {
}
do_items();
}
free_dump(p)
p_tree p;
{
struct dump *d = (struct dump *) p->t_args[0];
free(d->globals);
free(d->stack);
1990-10-17 17:00:03 +00:00
if (d == last_dump) last_dump = d->next;
else {
register struct dump *d1 = last_dump;
while (d1->next != d) d1 = d1->next;
d1->next = d->next;
}
1990-08-31 18:22:53 +00:00
free((char *) d);
}