static enum bpf_perf_event_ret print_bpf_output(void *event, void *priv) { struct event_ring_info *ring = priv; struct perf_event_sample *e = event; struct { struct perf_event_header header; __u64 id; __u64 lost; } *lost = event; if (json_output) { jsonw_start_object(json_wtr); jsonw_name(json_wtr, "type"); jsonw_uint(json_wtr, e->header.type); jsonw_name(json_wtr, "cpu"); jsonw_uint(json_wtr, ring->cpu); jsonw_name(json_wtr, "index"); jsonw_uint(json_wtr, ring->key); if (e->header.type == PERF_RECORD_SAMPLE) { jsonw_name(json_wtr, "timestamp"); jsonw_uint(json_wtr, e->time); jsonw_name(json_wtr, "data"); print_data_json(e->data, e->size); } else if (e->header.type == PERF_RECORD_LOST) { jsonw_name(json_wtr, "lost"); jsonw_start_object(json_wtr); jsonw_name(json_wtr, "id"); jsonw_uint(json_wtr, lost->id); jsonw_name(json_wtr, "count"); jsonw_uint(json_wtr, lost->lost); jsonw_end_object(json_wtr); } jsonw_end_object(json_wtr); } else { if (e->header.type == PERF_RECORD_SAMPLE) { printf("== @%lld.%09lld CPU: %d index: %d =====\n", e->time / 1000000000ULL, e->time % 1000000000ULL, ring->cpu, ring->key); fprint_hex(stdout, e->data, e->size, " "); printf("\n"); } else if (e->header.type == PERF_RECORD_LOST) { printf("lost %lld events\n", lost->lost); } else { printf("unknown event type=%d size=%d\n", e->header.type, e->header.size); } } return LIBBPF_PERF_EVENT_CONT; }
void print_hex(uint8_t * data, uint32_t len) { fprint_hex(stdout, data, len); }
void print_blocks() { FILE* f=0; if (print_stats) { f=fopen(GetPath("/blkmap.lst").c_str(),"w"); print_stats=0; printf("writing blocks to %p\n",f); } for (size_t i=0;i<all_blocks.size();i++) { RuntimeBlockInfo* blk=all_blocks[i]; if (f) { fprintf(f,"block: %08X\n",blk); fprintf(f,"addr: %08X\n",blk->addr); fprintf(f,"hash: %s\n",blk->hash()); fprintf(f,"hash_rloc: %s\n",blk->hash(false,true)); fprintf(f,"code: %08X\n",blk->code); fprintf(f,"runs: %d\n",blk->runs); fprintf(f,"BlockType: %d\n",blk->BlockType); fprintf(f,"NextBlock: %08X\n",blk->NextBlock); fprintf(f,"BranchBlock: %08X\n",blk->BranchBlock); fprintf(f,"pNextBlock: %08X\n",blk->pNextBlock); fprintf(f,"pBranchBlock: %08X\n",blk->pBranchBlock); fprintf(f,"guest_cycles: %d\n",blk->guest_cycles); fprintf(f,"guest_opcodes: %d\n",blk->guest_opcodes); fprintf(f,"host_opcodes: %d\n",blk->host_opcodes); fprintf(f,"il_opcodes: %d\n",blk->oplist.size()); u32 hcode=0; s32 gcode=-1; u8* pucode=(u8*)blk->code; size_t j=0; fprintf(f,"{\n"); for (;j<blk->oplist.size();j++) { shil_opcode* op=&all_blocks[i]->oplist[j]; fprint_hex(f,"//h:",pucode,hcode,op->host_offs); if (gcode!=op->guest_offs) { gcode=op->guest_offs; u32 rpc=blk->addr+gcode; u16 op=ReadMem16(rpc); char temp[128]; OpDesc[op]->Dissasemble(temp,rpc,op); fprintf(f,"//g:%s\n",temp); } string s=op->dissasm(); fprintf(f,"//il:%d:%d:%s\n",op->guest_offs,op->host_offs,s.c_str()); } fprint_hex(f,"//h:",pucode,hcode,blk->host_code_size); fprintf(f,"}\n"); } all_blocks[i]->runs=0; } if (f) fclose(f); }
void dump_xlated_plain(struct dump_data *dd, void *buf, unsigned int len, bool opcodes, bool linum) { const struct bpf_prog_linfo *prog_linfo = dd->prog_linfo; const struct bpf_insn_cbs cbs = { .cb_print = print_insn, .cb_call = print_call, .cb_imm = print_imm, .private_data = dd, }; struct bpf_func_info *record; struct bpf_insn *insn = buf; struct btf *btf = dd->btf; unsigned int nr_skip = 0; bool double_insn = false; char func_sig[1024]; unsigned int i; record = dd->func_info; for (i = 0; i < len / sizeof(*insn); i++) { if (double_insn) { double_insn = false; continue; } if (btf && record) { if (record->insn_off == i) { btf_dumper_type_only(btf, record->type_id, func_sig, sizeof(func_sig)); if (func_sig[0] != '\0') printf("%s:\n", func_sig); record = (void *)record + dd->finfo_rec_size; } } if (prog_linfo) { const struct bpf_line_info *linfo; linfo = bpf_prog_linfo__lfind(prog_linfo, i, nr_skip); if (linfo) { btf_dump_linfo_plain(btf, linfo, "; ", linum); nr_skip++; } } double_insn = insn[i].code == (BPF_LD | BPF_IMM | BPF_DW); printf("% 4d: ", i); print_bpf_insn(&cbs, insn + i, true); if (opcodes) { printf(" "); fprint_hex(stdout, insn + i, 8, " "); if (double_insn && i < len - 1) { printf(" "); fprint_hex(stdout, insn + i + 1, 8, " "); } printf("\n"); } } }