[Fault-injection-developer] RFC: utility for fi_dbp
Status: Alpha
Brought to you by:
rustyl
From: Wang, S. <sta...@in...> - 2002-12-31 10:12:44
|
Hi, folks Here is utility for fi_dbp: Compile : gcc -lbfd -ldisasm -o fi_attach fi_attach.c Use: fi_attach $module.ko (after insmod the $module.ko) #include <stdio.h> #include <bfd.h> #include <libdis.h> #define CTL "/sys/fault_injection/interceptors/dbp_interceptor/ctl" int main(int argc, char **argv) { bfd *f; asection *sec, *mod; unsigned char *s; struct instr ins; char **matching; FILE * fp; int i; int counter=0; unsigned long addr[10000]; bfd_byte *data = 0; bfd_byte *modname = 0; unsigned int pos = 0; unsigned int size = 0; bfd_init(); bfd_set_default_target("elf32-i386"); f = bfd_openr(argv[1], "elf32-i386"); if (f == NULL) { fprintf(stderr, "bfd_openr ERROR!\n"); return 0; } if (bfd_check_format_matches (f, bfd_object, &matching)){ sec = bfd_get_section_by_name(f, ".text"); if (sec == NULL) { fprintf(stderr, "bfd_get_section_by_name ERROR!\n"); goto err; } mod = bfd_get_section_by_name(f, ".gnu.linkonce.modname"); if (mod == NULL) { fprintf(stderr, "bfd_get_section_by_name ERROR!\n"); goto err; } } else { fprintf(stderr, "Isn't bdf_object file!\n"); goto err; } data = (bfd_byte *) xmalloc ((size_t) bfd_section_size (f, sec)); bfd_get_section_contents (f, sec, (PTR) data, 0, bfd_section_size (f, sec)); modname = (bfd_byte *) xmalloc ((size_t) bfd_section_size (f, mod)); bfd_get_section_contents (f, mod, (PTR) modname, 0, bfd_section_size (f, mod)); s = data; disassemble_init(0,INTEL_SYNTAX); while(pos < sec->_raw_size) { size = disassemble_address(s+pos, &ins); if ( size > 0 ) { if (!strcmp(ins.mnemonic, "in") || !strcmp(ins.mnemonic, "out")) { addr[counter++] = pos; } pos += size; } else { fprintf(stderr, "ERROR!\n"); return -1; } } disassemble_cleanup(); fp = fopen (CTL, "w+"); fprintf(fp, "attach %s %i\n", (char *)modname, counter); fclose(fp); for (i=0;i<counter;i++) { fp = fopen (CTL, "w+"); fprintf(fp, "add %i\n", addr[i]); fclose(fp); } fp = fopen (CTL, "w+"); fprintf(fp, "end\n"); fclose(fp); err: bfd_close(f); return 0; } Your Sincerely, Stanley Wang SW Engineer, Intel Corporation. Intel China Software Lab. Tel: 021-52574545 ext. 1171 iNet: 8-752-1171 Opinions expressed are those of the author and do not represent Intel Corporation |