static int do_sbufl_fill_from_file(struct sbuf *sb, FILE *fp, gzFile zp, int phase1, struct cntr *cntr) { int ars; struct iobuf rbuf; //free_sbufl(sb); iobuf_init(&rbuf); if((ars=read_stat(NULL /* no async */, &rbuf, fp, zp, sb, cntr))) return ars; if((ars=read_fp(fp, zp, &rbuf))) return ars; iobuf_copy(&sb->path, &rbuf); if(sbuf_is_link(sb)) { if((ars=read_fp(fp, zp, &rbuf))) return ars; iobuf_copy(&sb->link, &rbuf); if(!cmd_is_link(rbuf.cmd)) return unexpected(&rbuf, __func__); } else if(!phase1 && sbuf_is_filedata(sb)) { if((ars=read_fp(fp, zp, &rbuf))) return ars; iobuf_copy(&(sb->burp1->endfile), &rbuf); if(!cmd_is_endfile(rbuf.cmd)) return unexpected(&rbuf, __func__); } return 0; }
/* mon_backtrace prints the current stack backtrace. */ int mon_backtrace(int argc, char **argv) { int *fp = NULL; int pc = 0; (void) argc; (void) argv; fp = read_fp(); pc = fp[0]; while (fp != NULL) { int lr = fp[-1]; struct DebugInfo info = get_debug_info(pc); if ((int) fp == lr) break; kprintf(" fp: %x, lr: %x\n", fp, lr); kprintf(" %s:%s:%d\n", info.file, info.function, info.source_line_number); if (info.arg_count != 0) print_arguments(&info, fp); pc = lr; fp = (int *) fp[-3]; } return 0; }
static int read_stat(struct asfd *asfd, struct iobuf *rbuf, FILE *fp, gzFile zp, struct sbuf *sb, struct cntr *cntr) { while(1) { iobuf_free_content(rbuf); if(fp || zp) { int asr; if((asr=read_fp(fp, zp, rbuf))) { //logp("read_fp returned: %d\n", asr); return asr; } if(rbuf->buf[rbuf->len]=='\n') rbuf->buf[rbuf->len]='\0'; } else { if(asfd->read(asfd)) { break; } if(rbuf->cmd==CMD_WARNING) { logp("WARNING: %s\n", rbuf->buf); cntr_add(cntr, rbuf->cmd, 0); continue; } } if(rbuf->cmd==CMD_DATAPTH) { iobuf_copy(&(sb->burp1->datapth), rbuf); rbuf->buf=NULL; } else if(rbuf->cmd==CMD_ATTRIBS) { iobuf_copy(&sb->attr, rbuf); rbuf->buf=NULL; attribs_decode(sb); return 0; } else if((rbuf->cmd==CMD_GEN && !strcmp(rbuf->buf, "backupend")) || (rbuf->cmd==CMD_GEN && !strcmp(rbuf->buf, "restoreend")) || (rbuf->cmd==CMD_GEN && !strcmp(rbuf->buf, "phase1end")) || (rbuf->cmd==CMD_GEN && !strcmp(rbuf->buf, "backupphase2")) || (rbuf->cmd==CMD_GEN && !strcmp(rbuf->buf, "estimateend"))) { iobuf_free_content(rbuf); return 1; } else return unexpected(rbuf, __func__); } iobuf_free_content(rbuf); return -1; }
struct frame_info * get_current_frame (void) { if (current_frame == NULL) { if (target_has_stack) current_frame = create_new_frame (read_fp (), read_pc ()); else error ("No stack."); } return current_frame; }
static int init_fp(struct capn *c, FILE *f, struct capn_stream *z, int packed) { /* * Initialize 'c' from the contents of 'f', assuming the message has been * serialized with the standard framing format. From https://capnproto.org/encoding.html: * * When transmitting over a stream, the following should be sent. All integers are unsigned and little-endian. * (4 bytes) The number of segments, minus one (since there is always at least one segment). * (N * 4 bytes) The size of each segment, in words. * (0 or 4 bytes) Padding up to the next word boundary. * The content of each segment, in order. */ struct capn_segment *s = NULL; uint32_t i, segnum, total = 0; uint32_t hdr[1024]; uint8_t zbuf[ZBUF_SZ]; char *data = NULL; capn_init_malloc(c); /* Read the first four bytes to know how many headers we have */ if (read_fp(&segnum, 4, f, z, zbuf, packed)) goto err; segnum = capn_flip32(segnum); if (segnum > 1023) goto err; segnum++; /* The wire encoding was zero-based */ /* Read the header list */ if (read_fp(hdr, 8 * (segnum/2) + 4, f, z, zbuf, packed)) goto err; for (i = 0; i < segnum; i++) { uint32_t n = capn_flip32(hdr[i]); if (n > INT_MAX/8 || n > UINT32_MAX/8 || UINT32_MAX - total < n*8) goto err; hdr[i] = n*8; total += hdr[i]; } /* Allocate space for the data and the capn_segment structs */ s = (struct capn_segment*) calloc(1, total + (sizeof(*s) * segnum)); if (!s) goto err; /* Now read the data and setup the capn_segment structs */ data = (char*) (s+segnum); if (read_fp(data, total, f, z, zbuf, packed)) goto err; for (i = 0; i < segnum; i++) { s[i].len = s[i].cap = hdr[i]; s[i].data = data; data += s[i].len; capn_append_segment(c, &s[i]); } /* Set the entire region to be freed on the last segment */ s[segnum-1].user = s; return 0; err: memset(c, 0, sizeof(*c)); free(s); return -1; }