static SiteInfo * get_info(SiteIndex index) { SiteInfo *info; info = (SiteInfo*)table_get_info(gdata->site_table, index); return info; }
/* Get the RefInfo structure from an entry */ static RefInfo * get_info(RefIndex index) { RefInfo *info; info = (RefInfo*)table_get_info(gdata->reference_table, index); return info; }
static ObjectInfo * get_info(ObjectIndex index) { ObjectInfo *info; info = (ObjectInfo*)table_get_info(gdata->object_table, index); return info; }
static FrameInfo * get_info(FrameIndex index) { FrameInfo *info; info = (FrameInfo*)table_get_info(gdata->frame_table, index); return info; }
/* Printf of a utf8 id for gdata->check_fd */ static void check_print_utf8(struct LookupTable *utab, char *prefix, HprofId id) { TableIndex uindex; if ( id == 0 ) { check_printf("%s0x%x", prefix, id); } else { uindex = table_find_entry(utab, &id, sizeof(id)); if ( uindex == 0 ) { check_printf("%s0x%x", prefix, id); } else { UmapInfo *umap; umap = (UmapInfo*)table_get_info(utab, uindex); HPROF_ASSERT(umap!=NULL); HPROF_ASSERT(umap->str!=NULL); check_printf("%s0x%x->", prefix, id); check_printf_str(umap->str); } } }
/* Given the heap dump data and the utf8 map, check/write the heap dump. */ static int check_heap_tags(struct LookupTable *utab, unsigned char *pstart, int nbytes) { int nrecords; unsigned char *p; unsigned char *psave; struct LookupTable *ctab; CmapInfo cmap; char *label; unsigned tag; HprofType ty; HprofId id, id2, fr, sup; int num_elements; int num_bytes; SerialNumber trace_serial_num; SerialNumber thread_serial_num; int npos; int i; int inst_size; ctab = table_initialize("temp ctab", 64, 64, 512, sizeof(CmapInfo)); /* First pass over heap records just fills in the CmapInfo table */ nrecords = 0; p = pstart; while ( p < (pstart+nbytes) ) { nrecords++; /*LINTED*/ npos = (int)(p - pstart); tag = read_u1(&p); switch ( tag ) { CASE_HEAP(HPROF_GC_ROOT_UNKNOWN) id = read_id(&p); break; CASE_HEAP(HPROF_GC_ROOT_JNI_GLOBAL) id = read_id(&p); id2 = read_id(&p); break; CASE_HEAP(HPROF_GC_ROOT_JNI_LOCAL) id = read_id(&p); thread_serial_num = read_u4(&p); fr = read_u4(&p); break; CASE_HEAP(HPROF_GC_ROOT_JAVA_FRAME) id = read_id(&p); thread_serial_num = read_u4(&p); fr = read_u4(&p); break; CASE_HEAP(HPROF_GC_ROOT_NATIVE_STACK) id = read_id(&p); thread_serial_num = read_u4(&p); break; CASE_HEAP(HPROF_GC_ROOT_STICKY_CLASS) id = read_id(&p); break; CASE_HEAP(HPROF_GC_ROOT_THREAD_BLOCK) id = read_id(&p); thread_serial_num = read_u4(&p); break; CASE_HEAP(HPROF_GC_ROOT_MONITOR_USED) id = read_id(&p); break; CASE_HEAP(HPROF_GC_ROOT_THREAD_OBJ) id = read_id(&p); thread_serial_num = read_u4(&p); trace_serial_num = read_u4(&p); break; CASE_HEAP(HPROF_GC_CLASS_DUMP) (void)memset((void*)&cmap, 0, sizeof(cmap)); id = read_id(&p); trace_serial_num = read_u4(&p); { HprofId ld, si, pr, re1, re2; sup = read_id(&p); ld = read_id(&p); si = read_id(&p); pr = read_id(&p); re1 = read_id(&p); re2 = read_id(&p); cmap.sup = sup; } inst_size = read_u4(&p); cmap.inst_size = inst_size; num_elements = read_u2(&p); for(i=0; i<num_elements; i++) { (void)read_u2(&p); ty = read_u1(&p); (void)read_val(&p, ty); } num_elements = read_u2(&p); for(i=0; i<num_elements; i++) { (void)read_id(&p); ty = read_u1(&p); (void)read_val(&p, ty); } num_elements = read_u2(&p); for(i=0; i<num_elements; i++) { HprofType ty; HprofId id; id = read_id(&p); ty = read_u1(&p); add_inst_field_to_cmap(&cmap, id, ty); } (void)table_create_entry(ctab, &id, sizeof(id), &cmap); break; CASE_HEAP(HPROF_GC_INSTANCE_DUMP) id = read_id(&p); trace_serial_num = read_u4(&p); id2 = read_id(&p); /* class id */ num_bytes = read_u4(&p); p += num_bytes; break; CASE_HEAP(HPROF_GC_OBJ_ARRAY_DUMP) id = read_id(&p); trace_serial_num = read_u4(&p); num_elements = read_u4(&p); id2 = read_id(&p); p += num_elements*(int)sizeof(HprofId); break; CASE_HEAP(HPROF_GC_PRIM_ARRAY_DUMP) id = read_id(&p); trace_serial_num = read_u4(&p); num_elements = read_u4(&p); ty = read_u1(&p); p += type_size[ty]*num_elements; break; default: label = "UNKNOWN"; check_printf("H#%d@%d %s: ERROR!\n", nrecords, npos, label); HPROF_ERROR(JNI_TRUE, "unknown heap record type"); break; } } CHECK_FOR_ERROR(p==pstart+nbytes); /* Scan again once we have our cmap */ nrecords = 0; p = pstart; while ( p < (pstart+nbytes) ) { nrecords++; /*LINTED*/ npos = (int)(p - pstart); tag = read_u1(&p); switch ( tag ) { CASE_HEAP(HPROF_GC_ROOT_UNKNOWN) id = read_id(&p); check_printf("H#%d@%d %s: id=0x%x\n", nrecords, npos, label, id); break; CASE_HEAP(HPROF_GC_ROOT_JNI_GLOBAL) id = read_id(&p); id2 = read_id(&p); check_printf("H#%d@%d %s: id=0x%x, id2=0x%x\n", nrecords, npos, label, id, id2); break; CASE_HEAP(HPROF_GC_ROOT_JNI_LOCAL) id = read_id(&p); thread_serial_num = read_u4(&p); fr = read_u4(&p); check_printf("H#%d@%d %s: id=0x%x, thread_serial_num=%u, fr=0x%x\n", nrecords, npos, label, id, thread_serial_num, fr); break; CASE_HEAP(HPROF_GC_ROOT_JAVA_FRAME) id = read_id(&p); thread_serial_num = read_u4(&p); fr = read_u4(&p); check_printf("H#%d@%d %s: id=0x%x, thread_serial_num=%u, fr=0x%x\n", nrecords, npos, label, id, thread_serial_num, fr); break; CASE_HEAP(HPROF_GC_ROOT_NATIVE_STACK) id = read_id(&p); thread_serial_num = read_u4(&p); check_printf("H#%d@%d %s: id=0x%x, thread_serial_num=%u\n", nrecords, npos, label, id, thread_serial_num); break; CASE_HEAP(HPROF_GC_ROOT_STICKY_CLASS) id = read_id(&p); check_printf("H#%d@%d %s: id=0x%x\n", nrecords, npos, label, id); break; CASE_HEAP(HPROF_GC_ROOT_THREAD_BLOCK) id = read_id(&p); thread_serial_num = read_u4(&p); check_printf("H#%d@%d %s: id=0x%x, thread_serial_num=%u\n", nrecords, npos, label, id, thread_serial_num); break; CASE_HEAP(HPROF_GC_ROOT_MONITOR_USED) id = read_id(&p); check_printf("H#%d@%d %s: id=0x%x\n", nrecords, npos, label, id); break; CASE_HEAP(HPROF_GC_ROOT_THREAD_OBJ) id = read_id(&p); thread_serial_num = read_u4(&p); trace_serial_num = read_u4(&p); CHECK_TRACE_SERIAL_NO(trace_serial_num); check_printf("H#%d@%d %s: id=0x%x, thread_serial_num=%u," " trace_serial_num=%u\n", nrecords, npos, label, id, thread_serial_num, trace_serial_num); break; CASE_HEAP(HPROF_GC_CLASS_DUMP) id = read_id(&p); trace_serial_num = read_u4(&p); CHECK_TRACE_SERIAL_NO(trace_serial_num); check_printf("H#%d@%d %s: id=0x%x, trace_serial_num=%u\n", nrecords, npos, label, id, trace_serial_num); { HprofId ld, si, pr, re1, re2; sup = read_id(&p); ld = read_id(&p); si = read_id(&p); pr = read_id(&p); re1 = read_id(&p); re2 = read_id(&p); check_printf(" su=0x%x, ld=0x%x, si=0x%x," " pr=0x%x, re1=0x%x, re2=0x%x\n", sup, ld, si, pr, re1, re2); } inst_size = read_u4(&p); check_printf(" instance_size=%d\n", inst_size); num_elements = read_u2(&p); for(i=0; i<num_elements; i++) { HprofType ty; unsigned cpi; jvalue val; cpi = read_u2(&p); ty = read_u1(&p); val = read_val(&p, ty); check_printf(" constant_pool %d: cpi=%d, ty=%d, val=", i, cpi, ty); check_printf_val(ty, val, 1); check_printf("\n"); } num_elements = read_u2(&p); check_printf(" static_field_count=%d\n", num_elements); for(i=0; i<num_elements; i++) { HprofType ty; HprofId id; jvalue val; id = read_id(&p); ty = read_u1(&p); val = read_val(&p, ty); check_printf(" static field %d: ", i); check_print_utf8(utab, "id=", id); check_printf(", ty=%d, val=", ty); check_printf_val(ty, val, 1); check_printf("\n"); } num_elements = read_u2(&p); check_printf(" instance_field_count=%d\n", num_elements); for(i=0; i<num_elements; i++) { HprofType ty; HprofId id; id = read_id(&p); ty = read_u1(&p); check_printf(" instance_field %d: ", i); check_print_utf8(utab, "id=", id); check_printf(", ty=%d\n", ty); } break; CASE_HEAP(HPROF_GC_INSTANCE_DUMP) id = read_id(&p); trace_serial_num = read_u4(&p); CHECK_TRACE_SERIAL_NO(trace_serial_num); id2 = read_id(&p); /* class id */ num_bytes = read_u4(&p); check_printf("H#%d@%d %s: id=0x%x, trace_serial_num=%u," " cid=0x%x, nbytes=%d\n", nrecords, npos, label, id, trace_serial_num, id2, num_bytes); /* This is a packed set of bytes for the instance fields */ if ( num_bytes > 0 ) { TableIndex cindex; int ifield; CmapInfo *map; cindex = table_find_entry(ctab, &id2, sizeof(id2)); HPROF_ASSERT(cindex!=0); map = (CmapInfo*)table_get_info(ctab, cindex); HPROF_ASSERT(map!=NULL); HPROF_ASSERT(num_bytes==map->inst_size); psave = p; ifield = 0; do { for(i=0;i<map->n_finfo;i++) { HprofType ty; HprofId id; jvalue val; ty = map->finfo[i].ty; id = map->finfo[i].id; HPROF_ASSERT(ty!=0); HPROF_ASSERT(id!=0); val = read_val(&p, ty); check_printf(" field %d: ", ifield); check_print_utf8(utab, "id=", id); check_printf(", ty=%d, val=", ty); check_printf_val(ty, val, 1); check_printf("\n"); ifield++; } id2 = map->sup; map = NULL; cindex = 0; if ( id2 != 0 ) { cindex = table_find_entry(ctab, &id2, sizeof(id2)); HPROF_ASSERT(cindex!=0); map = (CmapInfo*)table_get_info(ctab, cindex); HPROF_ASSERT(map!=NULL); } } while ( map != NULL ); HPROF_ASSERT(num_bytes==(p-psave)); } break; CASE_HEAP(HPROF_GC_OBJ_ARRAY_DUMP) id = read_id(&p); trace_serial_num = read_u4(&p); CHECK_TRACE_SERIAL_NO(trace_serial_num); num_elements = read_u4(&p); id2 = read_id(&p); check_printf("H#%d@%d %s: id=0x%x, trace_serial_num=%u, nelems=%d, eid=0x%x\n", nrecords, npos, label, id, trace_serial_num, num_elements, id2); for(i=0; i<num_elements; i++) { HprofId id; id = read_id(&p); check_printf(" [%d]: id=0x%x\n", i, id); } break; CASE_HEAP(HPROF_GC_PRIM_ARRAY_DUMP) id = read_id(&p); trace_serial_num = read_u4(&p); CHECK_TRACE_SERIAL_NO(trace_serial_num); num_elements = read_u4(&p); ty = read_u1(&p); psave = p; check_printf("H#%d@%d %s: id=0x%x, trace_serial_num=%u, " "nelems=%d, ty=%d\n", nrecords, npos, label, id, trace_serial_num, num_elements, ty); HPROF_ASSERT(HPROF_TYPE_IS_PRIMITIVE(ty)); if ( num_elements > 0 ) { int count; int long_form; int max_count; char *quote; quote = ""; long_form = 1; max_count = 8; count = 0; switch ( ty ) { case HPROF_CHAR: long_form = 0; max_count = 72; quote = "\""; /*FALLTHRU*/ case HPROF_INT: case HPROF_DOUBLE: case HPROF_LONG: case HPROF_BYTE: case HPROF_BOOLEAN: case HPROF_SHORT: case HPROF_FLOAT: check_printf(" val=%s", quote); for(i=0; i<num_elements; i++) { jvalue val; if ( i > 0 && count == 0 ) { check_printf(" %s", quote); } val = read_val(&p, ty); check_printf_val(ty, val, long_form); count += 1; if ( count >= max_count ) { check_printf("\"\n"); count = 0; } } if ( count != 0 ) { check_printf("%s\n", quote); } break; } } HPROF_ASSERT(type_size[ty]*num_elements==(p-psave)); break; default: label = "UNKNOWN"; check_printf("H#%d@%d %s: ERROR!\n", nrecords, npos, label); HPROF_ERROR(JNI_TRUE, "unknown heap record type"); break; } } CHECK_FOR_ERROR(p==pstart+nbytes); table_cleanup(ctab, &cmap_cleanup, NULL); return nrecords; }
static LoaderInfo * get_info(LoaderIndex index) { return (LoaderInfo*)table_get_info(gdata->loader_table, index); }
/* * This one handles all table-related commands * ipfw table NAME create ... * ipfw table NAME modify ... * ipfw table NAME destroy * ipfw table NAME swap NAME * ipfw table NAME lock * ipfw table NAME unlock * ipfw table NAME add addr[/masklen] [value] * ipfw table NAME add [addr[/masklen] value] [addr[/masklen] value] .. * ipfw table NAME delete addr[/masklen] [addr[/masklen]] .. * ipfw table NAME lookup addr * ipfw table {NAME | all} flush * ipfw table {NAME | all} list * ipfw table {NAME | all} info * ipfw table {NAME | all} detail */ void ipfw_table_handler(int ac, char *av[]) { int do_add, is_all; int atomic, error, tcmd; ipfw_xtable_info i; ipfw_obj_header oh; char *tablename; uint32_t set; void *arg; memset(&oh, 0, sizeof(oh)); is_all = 0; if (co.use_set != 0) set = co.use_set - 1; else set = 0; ac--; av++; NEED1("table needs name"); tablename = *av; if (table_check_name(tablename) == 0) { table_fill_ntlv(&oh.ntlv, *av, set, 1); oh.idx = 1; } else { if (strcmp(tablename, "all") == 0) is_all = 1; else errx(EX_USAGE, "table name %s is invalid", tablename); } ac--; av++; NEED1("table needs command"); tcmd = get_token(tablecmds, *av, "table command"); /* Check if atomic operation was requested */ atomic = 0; if (tcmd == TOK_ATOMIC) { ac--; av++; NEED1("atomic needs command"); tcmd = get_token(tablecmds, *av, "table command"); switch (tcmd) { case TOK_ADD: break; default: errx(EX_USAGE, "atomic is not compatible with %s", *av); } atomic = 1; } switch (tcmd) { case TOK_LIST: case TOK_INFO: case TOK_DETAIL: case TOK_FLUSH: break; default: if (is_all != 0) errx(EX_USAGE, "table name required"); } switch (tcmd) { case TOK_ADD: case TOK_DEL: do_add = **av == 'a'; ac--; av++; table_modify_record(&oh, ac, av, do_add, co.do_quiet, co.do_quiet, atomic); break; case TOK_CREATE: ac--; av++; table_create(&oh, ac, av); break; case TOK_MODIFY: ac--; av++; table_modify(&oh, ac, av); break; case TOK_DESTROY: if (table_destroy(&oh) != 0) err(EX_OSERR, "failed to destroy table %s", tablename); break; case TOK_FLUSH: if (is_all == 0) { if ((error = table_flush(&oh)) != 0) err(EX_OSERR, "failed to flush table %s info", tablename); } else { error = tables_foreach(table_flush_one, &oh, 1); if (error != 0) err(EX_OSERR, "failed to flush tables list"); } break; case TOK_SWAP: ac--; av++; NEED1("second table name required"); table_swap(&oh, *av); break; case TOK_LOCK: case TOK_UNLOCK: table_lock(&oh, (tcmd == TOK_LOCK)); break; case TOK_DETAIL: case TOK_INFO: arg = (tcmd == TOK_DETAIL) ? (void *)1 : NULL; if (is_all == 0) { if ((error = table_get_info(&oh, &i)) != 0) err(EX_OSERR, "failed to request table info"); table_show_info(&i, arg); } else { error = tables_foreach(table_show_info, arg, 1); if (error != 0) err(EX_OSERR, "failed to request tables list"); } break; case TOK_LIST: if (is_all == 0) { ipfw_xtable_info i; if ((error = table_get_info(&oh, &i)) != 0) err(EX_OSERR, "failed to request table info"); table_show_one(&i, NULL); } else { error = tables_foreach(table_show_one, NULL, 1); if (error != 0) err(EX_OSERR, "failed to request tables list"); } break; case TOK_LOOKUP: ac--; av++; table_lookup(&oh, ac, av); break; } }
static void tentry_fill_key(ipfw_obj_header *oh, ipfw_obj_tentry *tent, char *key, int add, uint8_t *ptype, uint32_t *pvmask, ipfw_xtable_info *xi) { uint8_t type, tflags; uint32_t vmask; int error; type = 0; tflags = 0; vmask = 0; if (xi->tablename[0] == '\0') error = table_get_info(oh, xi); else error = 0; if (error == 0) { if (co.test_only == 0) { /* Table found */ type = xi->type; tflags = xi->tflags; vmask = xi->vmask; } else { /* * We're running `ipfw -n` * Compatibility layer: try to guess key type * before failing. */ if (guess_key_type(key, &type) != 0) { /* Inknown key */ errx(EX_USAGE, "Cannot guess " "key '%s' type", key); } vmask = IPFW_VTYPE_LEGACY; } } else { if (error != ESRCH) errx(EX_OSERR, "Error requesting table %s info", oh->ntlv.name); if (add == 0) errx(EX_DATAERR, "Table %s does not exist", oh->ntlv.name); /* * Table does not exist * Compatibility layer: try to guess key type before failing. */ if (guess_key_type(key, &type) != 0) { /* Inknown key */ errx(EX_USAGE, "Table %s does not exist, cannot guess " "key '%s' type", oh->ntlv.name, key); } vmask = IPFW_VTYPE_LEGACY; } tentry_fill_key_type(key, tent, type, tflags); *ptype = type; *pvmask = vmask; }