void cos_init(void *d) { cgraph_init(); }
int cmd_cgraph(char **arg) { char *offset_text, *len_text, *addr_text;; address_t offset, len, addr; uint8_t *memory; struct call_graph graph; /* Figure out what the arguments are */ offset_text = get_arg(arg); len_text = get_arg(arg); addr_text = get_arg(arg); if (!(offset_text && len_text)) { printc_err("cgraph: offset and length must be " "specified\n"); return -1; } if (expr_eval(offset_text, &offset) < 0) { printc_err("cgraph: invalid offset: %s\n", offset_text); return -1; } offset &= ~1; if (expr_eval(len_text, &len) < 0) { printc_err("cgraph: invalid length: %s\n", len_text); return -1; } len &= ~1; if (addr_text && expr_eval(addr_text, &addr) < 0) { printc_err("cgraph: invalid address: %s\n", addr_text); return -1; } /* Grab the memory to be analysed */ memory = malloc(len); if (!memory) { printc_err("cgraph: couldn't allocate memory: %s\n", last_error()); return -1; } if (device_readmem(offset, memory, len) < 0) { printc_err("cgraph: couldn't fetch memory\n"); free(memory); return -1; } /* Produce and display the call graph */ if (cgraph_init(offset, len, memory, &graph) < 0) { printc_err("cgraph: couldn't build call graph\n"); free(memory); return -1; } free(memory); if (addr_text) cgraph_func_info(&graph, addr); else cgraph_summary(&graph); cgraph_destroy(&graph); return 0; }