From: Jan-Benedict G. <jb...@us...> - 2005-03-11 21:29:45
|
Update of /cvsroot/linux-vax/usr/visualize_asm In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21512 Added Files: address.c graphic.c graphic_dot.c parse_backend.c parse_disassembly.c parse_i386.c parse_vax.c regexp_helper.c address.h graphic.h parse.h regexp_helper.h LICENSE Makefile i386.dis vax.dis README Log Message: - About 10..15 hours of hacking, and this li'l tool showed up. Stuff regular expressions into it (those that describe a given assembler language) and it'll probably draw you a nice draw out of objdump -d -w disassembler. --- NEW FILE: i386.dis --- synaptics.o: file format elf32-i386 Disassembly of section .text: 00000000 <synaptics_send_cmd>: 0: 83 ec 10 sub $0x10,%esp 3: 0f b6 44 24 18 movzbl 0x18(%esp),%eax 8: 89 5c 24 0c mov %ebx,0xc(%esp) c: 8b 5c 24 14 mov 0x14(%esp),%ebx 10: 89 44 24 04 mov %eax,0x4(%esp) 14: 89 1c 24 mov %ebx,(%esp) 17: e8 fc ff ff ff call 18 <synaptics_send_cmd+0x18> 1c: 85 c0 test %eax,%eax 1e: ba ff ff ff ff mov $0xffffffff,%edx 23: 75 27 jne 4c <synaptics_send_cmd+0x4c> 25: b8 e9 03 00 00 mov $0x3e9,%eax 2a: 89 44 24 08 mov %eax,0x8(%esp) 2e: 8b 44 24 1c mov 0x1c(%esp),%eax [...1421 lines suppressed...] 12aa: 5b pop %ebx 12ab: 5e pop %esi 12ac: 5f pop %edi 12ad: 5d pop %ebp 12ae: c3 ret 12af: 90 nop 12b0: 89 34 24 mov %esi,(%esp) 12b3: e8 b8 f3 ff ff call 670 <synaptics_pt_create> 12b8: eb a1 jmp 125b <synaptics_init+0x6b> 12ba: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 12c0: 31 c0 xor %eax,%eax 12c2: eb 8e jmp 1252 <synaptics_init+0x62> 12c4: c7 04 24 80 02 00 00 movl $0x280,(%esp) 12cb: e8 fc ff ff ff call 12cc <synaptics_init+0xdc> 12d0: 89 1c 24 mov %ebx,(%esp) 12d3: e8 fc ff ff ff call 12d4 <synaptics_init+0xe4> 12d8: b8 ff ff ff ff mov $0xffffffff,%eax 12dd: eb c8 jmp 12a7 <synaptics_init+0xb7> 12df: c7 04 24 c0 02 00 00 movl $0x2c0,(%esp) 12e6: eb e3 jmp 12cb <synaptics_init+0xdb> --- NEW FILE: graphic_dot.c --- #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "graphic.h" static int section_block_opened = 0; static int function_block_opened = 0; static char *last_anchor = NULL; #define CLUSTER "cluster: " static unsigned char * alloc_sprintf_valist (unsigned char *format, va_list args) { char buf[1]; char *real_buf; size_t len; len = vsnprintf (buf, 0, format, args) + 5; real_buf = malloc (len); if (!real_buf) return NULL; vsnprintf (real_buf, len, format, args); return real_buf; } static int dot_set_last_anchor (unsigned char *format, ...) { unsigned char *buf; va_list args; if (!format) { if (last_anchor) free (last_anchor); last_anchor = NULL; return 0; } va_start (args, format); { buf = alloc_sprintf_valist (format, args); } va_end (args); if (buf) { if (last_anchor) { free (last_anchor); last_anchor = NULL; } last_anchor = buf; return 0; } else return -1; } static unsigned char * dot_section_name (void) { unsigned char *section_name; section_name = get_section_name (); if (!section_name) section_name = "*unknown*"; return section_name; } static int dot_close_code_block (void) { return 0; } static int dot_close_function_block (void) { dot_close_code_block (); if (function_block_opened) { printf ("\t\t}\n"); function_block_opened = 0; } dot_set_last_anchor (NULL); return 0; } static int dot_close_section_block (void) { dot_close_function_block (); if (section_block_opened) { printf ("\t}\n"); section_block_opened = 0; } return 0; } static int dot_start_output (unsigned char *filename) { /* XXX escape filename */ printf ("digraph \"%s\" {\n", filename); printf ("\tstyle=bold;\n"); return 0; } static int dot_finish_output (void) { dot_close_section_block (); printf ("}\n"); return 0; } static int dot_start_section (unsigned char *name) { dot_close_section_block (); printf ("\tsubgraph \"%sSection %s\" {\n", CLUSTER, name); printf ("\t\tlabel=\"Section \\\"%s\\\"\";\n", name); section_block_opened = 1; return 0; } static int dot_start_function (unsigned char *name, uint64_t address) { dot_close_function_block (); printf ("\t\tsubgraph \"%s%s:%s\" {\n", CLUSTER, dot_section_name (), name); printf ("\t\t\tlabel=\"Function %s()\";\n", name); dot_set_last_anchor (NULL); function_block_opened = 1; return 0; } static int dot_push_normal_code (unsigned char *code, uint64_t address) { if (last_anchor) printf ("\t\t\t\"%s\" -> \"%s:0x%016llx\";\n", last_anchor, dot_section_name (), address); printf ("\t\t\t\"%s:0x%016llx\" [shape=box,label=\"%s\"];\n", dot_section_name (), address, code); dot_set_last_anchor ("%s:0x%016llx", dot_section_name (), address); return 0; } static int dot_push_jump (unsigned char *code, uint64_t address, uint64_t jump_address) { dot_close_code_block (); printf ("\t\t\t\"%s:0x%016llx\" [shape=parallelogram,label=\"%s\"];\n", dot_section_name (), address, code); /* Edge from previous item to us. */ if (last_anchor) printf ("\t\t\t\"%s\" -> \"%s:0x%016llx\";\n", last_anchor, dot_section_name (), address); /* Edge from us to jump_address */ printf ("\t\t\t\"%s:0x%016llx\" -> \"%s:0x%016llx\";\n", dot_section_name (), address, dot_section_name (), jump_address); dot_set_last_anchor (NULL); return 0; } static int dot_push_cond_jump (unsigned char *code, uint64_t address, uint64_t jump_address) { dot_close_code_block (); printf ("\t\t\t\"%s:0x%016llx\" [shape=diamond,label=\"%s\"];\n", dot_section_name (), address, code); /* Edge from previous item to us. */ if (last_anchor) printf ("\t\t\t\"%s\" -> \"%s:0x%016llx\";\n", last_anchor, dot_section_name (), address); /* Edge from us to jump_address */ printf ("\t\t\t\"%s:0x%016llx\" -> \"%s:0x%016llx\";\n", dot_section_name (), address, dot_section_name (), jump_address); dot_set_last_anchor ("%s:0x%016llx", dot_section_name (), address); return 0; } static int dot_push_ret (unsigned char *code, uint64_t address) { if (last_anchor) printf ("\t\t\t\"%s\" -> \"%s:0x%016llx\";\n", last_anchor, dot_section_name (), address); printf ("\t\t\t\"%s:0x%016llx\" [shape=box,label=\"%s\"];\n", dot_section_name (), address, code); dot_set_last_anchor (NULL); return 0; } struct graphic_implementation graphic_dot = { .start_output = &dot_start_output, .finish_output = &dot_finish_output, .start_section = &dot_start_section, .start_function = &dot_start_function, .push_normal_code = &dot_push_normal_code, .push_jump = &dot_push_jump, .push_cond_jump = &dot_push_cond_jump, .push_ret = &dot_push_ret, }; --- NEW FILE: vax.dis --- ./diag_led.o: file format elf32-vax Disassembly of section .text: 00000000 <diag_led_get_base>: 0: 00 00 Entry mask 0x0000 = < > 2: d4 ef 00 00 00 00 clrf 8 <diag_led_get_base+0x8> 8: 9e ef 00 00 00 00 50 movab e <diag_led_get_base+0xe>,r0 f: d4 51 clrf r1 11: d1 ef 00 00 00 00 50 cmpl 17 <diag_led_get_base+0x17>,r0 18: 12 02 bneq 1c <diag_led_get_base+0x1c> 1a: d6 51 incl r1 1c: d5 51 tstl r1 1e: 12 18 bneq 38 <diag_led_get_base+0x38> 20: 9e ef 00 00 00 00 50 movab 26 <diag_led_get_base+0x26>,r0 27: d4 51 clrf r1 29: d1 ef 00 00 00 00 50 cmpl 2f <diag_led_get_base+0x2f>,r0 30: 12 02 bneq 34 <diag_led_get_base+0x34> 32: d6 51 incl r1 34: d5 51 tstl r1 36: 13 0f beql 47 <diag_led_get_base+0x47> 38: d0 01 ef c9 ff ff ff movl $0x1,8 <diag_led_get_base+0x8> 3f: d0 8f 10 00 08 20 50 movl $0x20080010,r0 46: 04 ret 47: 9e ef 00 00 00 00 50 movab 4d <diag_led_get_base+0x4d>,r0 4e: d4 51 clrf r1 50: d1 ef 00 00 00 00 50 cmpl 56 <diag_led_get_base+0x56>,r0 57: 12 02 bneq 5b <diag_led_get_base+0x5b> 59: d6 51 incl r1 5b: d5 51 tstl r1 5d: 13 0f beql 6e <diag_led_get_base+0x6e> 5f: d0 01 ef a2 ff ff ff movl $0x1,8 <diag_led_get_base+0x8> 66: d0 8f 30 00 14 20 50 movl $0x20140030,r0 6d: 04 ret 6e: 9f ef ef 00 00 00 pushab 163 <diag_led_off+0x3f> 74: fb 01 ef 00 00 00 00 calls $0x1,7b <diag_led_get_base+0x7b> 7b: d4 50 clrf r0 7d: 04 ret 0000007e <diag_led_set_state>: 7e: 00 00 Entry mask 0x0000 = < > 80: 90 ac 04 52 movb 0x4(ap),r2 84: d5 ef 76 ff ff ff tstl 0 <diag_led_get_base> 8a: 12 04 bneq 90 <diag_led_set_state+0x12> 8c: d2 12 50 mcoml $0x12,r0 8f: 04 ret 90: d5 ef 72 ff ff ff tstl 8 <diag_led_get_base+0x8> 96: 13 0f beql a7 <diag_led_set_state+0x29> 98: d0 ef 62 ff ff ff 51 movl 0 <diag_led_get_base>,r1 9f: 92 52 50 mcomb r2,r0 a2: 90 50 61 movb r0,(r1) a5: 11 0a brb b1 <diag_led_set_state+0x33> a7: d0 ef 53 ff ff ff 50 movl 0 <diag_led_get_base>,r0 ae: 90 52 60 movb r2,(r0) b1: 90 52 ef 4c ff ff ff movb r2,4 <diag_led_get_base+0x4> b8: d4 50 clrf r0 ba: 04 ret bb: 01 nop 000000bc <diag_led_get_state>: bc: 00 00 Entry mask 0x0000 = < > be: d5 ef 3c ff ff ff tstl 0 <diag_led_get_base> c4: 12 17 bneq dd <diag_led_get_state+0x21> c6: 9f ef d1 00 00 00 pushab 19d <diag_led_knight_rider+0x35> cc: fb 01 ef 00 00 00 00 calls $0x1,d3 <diag_led_get_state+0x17> d3: fb 00 ef 00 00 00 00 calls $0x0,da <diag_led_get_state+0x1e> da: d4 50 clrf r0 dc: 04 ret dd: 9a ef 21 ff ff ff 50 movzbl 4 <diag_led_get_base+0x4>,r0 e4: 04 ret e5: 01 nop 000000e6 <diag_led_on>: e6: 40 00 Entry mask 0x0040 = < r6 > e8: d0 ac 04 56 movl 0x4(ap),r6 ec: d1 56 07 cmpl r6,$0x7 ef: 1b 18 blequ 109 <diag_led_on+0x23> f1: 9f ef e2 00 00 00 pushab 1d9 <diag_led_knight_rider+0x71> f7: fb 01 ef 00 00 00 00 calls $0x1,fe <diag_led_on+0x18> fe: fb 00 ef 00 00 00 00 calls $0x0,105 <diag_led_on+0x1f> 105: d2 15 50 mcoml $0x15,r0 108: 04 ret 109: fb 00 ef 00 00 00 00 calls $0x0,110 <diag_led_on+0x2a> 110: 78 56 01 51 ashl r6,$0x1,r1 114: c2 03 5e subl2 $0x3,sp 117: 89 50 51 7e bisb3 r0,r1,-(sp) 11b: fb 01 ef 00 00 00 00 calls $0x1,122 <diag_led_on+0x3c> 122: 04 ret 123: 01 nop 00000124 <diag_led_off>: 124: 40 00 Entry mask 0x0040 = < r6 > 126: d0 ac 04 56 movl 0x4(ap),r6 12a: d1 56 07 cmpl r6,$0x7 12d: 1b 18 blequ 147 <diag_led_off+0x23> 12f: 9f ef a4 00 00 00 pushab 1d9 <diag_led_knight_rider+0x71> 135: fb 01 ef 00 00 00 00 calls $0x1,13c <diag_led_off+0x18> 13c: fb 00 ef 00 00 00 00 calls $0x0,143 <diag_led_off+0x1f> 143: d2 15 50 mcoml $0x15,r0 146: 04 ret 147: fb 00 ef 00 00 00 00 calls $0x0,14e <diag_led_off+0x2a> 14e: 9c 56 8f fe ff ff ff 51 rotl r6,$0xfffffffe,r1 156: 92 50 50 mcomb r0,r0 159: c2 03 5e subl2 $0x3,sp 15c: 8b 50 51 7e bicb3 r0,r1,-(sp) 160: fb 01 ef 00 00 00 00 calls $0x1,167 <diag_led_off+0x43> 167: 04 ret 00000168 <diag_led_knight_rider>: 168: c0 03 Entry mask 0x03c0 = < r9 r8 r7 r6 > 16a: d4 58 clrf r8 16c: d0 8f c0 1f 98 19 59 movl $0x19981fc0,r9 173: d4 56 clrf r6 175: 78 56 01 50 ashl r6,$0x1,r0 179: c2 03 5e subl2 $0x3,sp 17c: 90 50 7e movb r0,-(sp) 17f: fb 01 ef 00 00 00 00 calls $0x1,186 <diag_led_knight_rider+0x1e> 186: d0 1d 52 movl $0x1d,r2 189: d0 ef 00 00 00 00 53 movl 18f <diag_led_knight_rider+0x27>,r3 190: 7a 59 53 00 50 emul r9,r3,$0x0,r0 195: d0 51 50 movl r1,r0 198: f5 50 fd sobgtr r0,198 <diag_led_knight_rider+0x30> 19b: d7 52 decl r2 19d: 1e f1 bcc 190 <diag_led_knight_rider+0x28> 19f: f3 06 56 d2 aobleq $0x6,r6,175 <diag_led_knight_rider+0xd> 1a3: d0 07 56 movl $0x7,r6 1a6: d0 8f c0 1f 98 19 57 movl $0x19981fc0,r7 1ad: 78 56 01 50 ashl r6,$0x1,r0 1b1: c2 03 5e subl2 $0x3,sp 1b4: 90 50 7e movb r0,-(sp) 1b7: fb 01 ef 53 53 41 47 calls $0x1,47415511 <Letext+0x4741532e> 1be: d0 1d 52 movl $0x1d,r2 1c1: d0 ef 00 00 00 00 53 movl 1c7 <diag_led_knight_rider+0x5f>,r3 1c8: 7a 57 53 00 50 emul r7,r3,$0x0,r0 1cd: d0 51 50 movl r1,r0 1d0: f5 50 fd sobgtr r0,1d0 <diag_led_knight_rider+0x68> 1d3: d7 52 decl r2 1d5: 1e f1 bcc 1c8 <diag_led_knight_rider+0x60> 1d7: d7 56 decl r6 1d9: d1 56 01 cmpl r6,$0x1 1dc: 14 cf bgtr 1ad <diag_led_knight_rider+0x45> 1de: f3 09 58 91 aobleq $0x9,r8,173 <diag_led_knight_rider+0xb> 1e2: 04 ret Disassembly of section .init.text: 00000000 <diag_led_probe>: 0: 40 00 Entry mask 0x0040 = < r6 > 2: fb 00 ef f7 ff ff ff calls $0x0,0 <diag_led_probe> 9: d0 50 56 movl r0,r6 c: 12 04 bneq 12 <diag_led_probe+0x12> e: d2 12 50 mcoml $0x12,r0 11: 04 ret 12: dd 01 pushl $0x1 14: dd 56 pushl r6 16: fb 02 ef 00 00 00 00 calls $0x2,1d <diag_led_probe+0x1d> 1d: d0 50 ef dc ff ff ff movl r0,0 <diag_led_probe> 24: 12 13 bneq 39 <diag_led_probe+0x39> 26: dd 56 pushl r6 28: 9f ef c5 01 00 00 pushab 1f3 <Letext+0x10> 2e: fb 02 ef 00 00 00 00 calls $0x2,35 <diag_led_probe+0x35> 35: d2 0b 50 mcoml $0xb,r0 38: 04 ret 39: dd ef c1 ff ff ff pushl 0 <diag_led_probe> 3f: dd 56 pushl r6 41: 9f ef cf 01 00 00 pushab 216 <Letext+0x33> 47: fb 03 ef 00 00 00 00 calls $0x3,4e <diag_led_probe+0x4e> 4e: fb 00 ef 13 01 00 00 calls $0x0,168 <diag_led_knight_rider> 55: c2 03 5e subl2 $0x3,sp 58: 94 7e clrb -(sp) 5a: fb 01 ef 00 00 00 00 calls $0x1,61 <diag_led_probe+0x61> 61: d4 50 clrf r0 63: 04 ret 00000064 <diag_led_init>: 64: 00 00 Entry mask 0x0000 = < > 66: 9f ef ac ff ff ff pushab 18 <diag_led_probe+0x18> 6c: fb 01 ef 00 00 00 00 calls $0x1,73 <diag_led_init+0xf> 73: 04 ret Disassembly of section .exit.text: 00000000 <diag_led_exit>: 0: 00 00 Entry mask 0x0000 = < > 2: d5 ef f8 ff ff ff tstl 0 <diag_led_exit> 8: 13 20 beql 2a <diag_led_exit+0x2a> a: dd ef f0 ff ff ff pushl 0 <diag_led_exit> 10: 9f ef 31 02 00 00 pushab 247 <Letext+0x64> 16: fb 02 ef 00 00 00 00 calls $0x2,1d <diag_led_exit+0x1d> 1d: dd ef dd ff ff ff pushl 0 <diag_led_exit> 23: fb 01 ef 00 00 00 00 calls $0x1,2a <diag_led_exit+0x2a> 2a: 04 ret --- NEW FILE: LICENSE --- GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the program's name and a brief idea of what it does.> Copyright (C) <year> <name of author> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. <signature of Ty Coon>, 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. --- NEW FILE: graphic.h --- #ifndef _GRAPHICS_H #define _GRAPHICS_H #include <stdint.h> struct graphic_implementation { int (*start_output) (unsigned char *filename); int (*finish_output) (void); int (*start_section) (unsigned char *name); int (*start_function) (unsigned char *name, uint64_t address); int (*push_normal_code) (unsigned char *code, uint64_t address); int (*push_jump) (unsigned char *code, uint64_t address, uint64_t jump_address); int (*push_cond_jump) (unsigned char *code, uint64_t address, uint64_t jump_address); int (*push_ret) (unsigned char *code, uint64_t address); }; extern int graphic_init (unsigned char *name); extern int graphic_start_output (unsigned char *filename); extern int graphic_finish_output (void); extern int graphic_start_section (unsigned char *name); extern int graphic_start_function (unsigned char *name, uint64_t address); extern int graphic_push_normal_code (unsigned char *code, uint64_t address); extern int graphic_push_jump (unsigned char *code, uint64_t address, uint64_t jump_address); extern int graphic_push_cond_jump (unsigned char *code, uint64_t address, uint64_t jump_address); extern int graphic_push_ret (unsigned char *code, uint64_t address); extern unsigned char *get_section_name (void); #endif /* GRAPHICS_H */ --- NEW FILE: graphic.c --- #include <stdio.h> #include <stdlib.h> #include <string.h> #include "graphic.h" extern struct graphic_implementation graphic_dot; static struct graphic_implementation *graphic = NULL; static unsigned char *section_name = NULL; int graphic_init (unsigned char *name) { if (strcmp (name, "dot") == 0) graphic = &graphic_dot; else { fprintf (stderr, "Warning: Didn't recognize graphic " "subsystem \"%s\"!\n", name); return -1; } return 0; } int graphic_start_output (unsigned char *filename) { if (graphic && graphic->start_output) return (graphic->start_output) (filename); return -1; } int graphic_finish_output (void) { if (graphic && graphic->finish_output) return (graphic->finish_output) (); return -1; } int graphic_start_section (unsigned char *name) { if (section_name) { free (section_name); section_name = NULL; } section_name = strdup (name); if (graphic && graphic->start_section) return (graphic->start_section) (name); return -1; } int graphic_start_function (unsigned char *name, uint64_t address) { if (graphic && graphic->start_function) return (graphic->start_function) (name, address); return -1; } int graphic_push_normal_code (unsigned char *code, uint64_t address) { if (graphic && graphic->push_normal_code) return (graphic->push_normal_code) (code, address); return -1; } int graphic_push_jump (unsigned char *code, uint64_t address, uint64_t jump_address) { if (graphic && graphic->push_jump) return (graphic->push_jump) (code, address, jump_address); return -1; } int graphic_push_cond_jump (unsigned char *code, uint64_t address, uint64_t jump_address) { if (graphic && graphic->push_cond_jump) return (graphic->push_cond_jump) (code, address, jump_address); return -1; } int graphic_push_ret (unsigned char *code, uint64_t address) { if (graphic && graphic->push_ret) return (graphic->push_ret) (code, address); return -1; } unsigned char * get_section_name (void) { return section_name; } --- NEW FILE: parse_disassembly.c --- #include <regex.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include "parse.h" #include "graphic.h" static void kill_newline (unsigned char *line) { int i = 0; while (line[i]) { if (line[i] == '\n' || line[i] == '\r') { line[i] = '\0'; break; } i++; } } int main (int argc, char *argv[]) { int ret; char line[1000]; unsigned char *parser; unsigned char *filename = NULL; FILE *stream; struct arch_parser_table *table; if (argc == 2) { parser = argv[1]; } else if (argc == 3) { parser = argv[1]; if (strcmp (argv[2], "-")) filename = argv[2]; } else { fprintf (stderr, "%s <backend> [filename]\n", argv[0]); fprintf (stderr, "Eg.:\t%s vax < disass.txt\n", argv[0]); fprintf (stderr, "\tobjdump -d -w /path/to/file.o | %s vax\n", argv[0]); exit (EXIT_FAILURE); } if (filename) { stream = fopen (filename, "r"); if (!stream) { fprintf (stderr, "Couldn't open %s\n", filename); return EXIT_FAILURE; } } else stream = stdin; if (strcmp (parser, "vax") == 0) table = vax_parser; else if (strcmp (parser, "i386") == 0) table = i386_parser; else { fprintf (stderr, "Backend %s unknown\n", parser); exit (EXIT_FAILURE); } if (graphic_init ("dot") != 0) { fprintf (stderr, "Couldn't init graphics\n"); return -1; } graphic_start_output (filename? filename: (unsigned char *) "<stdin>"); while (fgets (line, sizeof (line), stream)) { kill_newline (line); /* * Try to parse the line. */ ret = parse_line (line, table); if (ret) fprintf (stderr, "\"%s\" didn't parse...\n", line); } graphic_finish_output (); return EXIT_SUCCESS; } --- NEW FILE: parse_i386.c --- #include "parse.h" /* * * * If you add additional codes here, please note them in Whats_Implemented.txt * * */ struct arch_parser_table i386_parser[] = { { .regexp = "^.*: file format .*$", .type = "ignore", .arg = { MATCH_UNUSED, MATCH_UNUSED, MATCH_UNUSED, }, }, { .regexp = "^$", .type = "ignore", .arg = { MATCH_UNUSED, MATCH_UNUSED, MATCH_UNUSED, }, }, { .regexp = "^Disassembly of section ([^:]+):$", .type = "section", .arg = { 0, 1, MATCH_UNUSED, }, }, { .regexp = "^[[:space:]]*([[:xdigit:]]+) <([^>]+)>:$", .type = "function", .arg = { 0, 2, 1, }, }, { .regexp = "^[[:space:]]*([[:xdigit:]]+):[[:xdigit:][:space:]]+ret[[:space:]]*$", .type = "ret", .arg = { 0, 1, MATCH_UNUSED, }, }, { .regexp = "^[[:space:]]*([[:xdigit:]]+): [[:xdigit:] ]+ (jmp)[[:space:]]+([[:xdigit:]]+) <.*>$", .type = "jump", .arg = { 0, 1, 3, }, }, { .regexp = "^[[:space:]]*([[:xdigit:]]+): [[:xdigit:] ]+ (ja|jb|jns|jle|je|jne|js)[[:space:]]+([[:xdigit:]]+) <.*>$", .type = "condjump", .arg = { 0, 1, 3, }, }, { .regexp = "^[[:space:]]*([[:xdigit:]]+):[[:space:]]+.*$", .type = "code", .arg = { 0, 1, MATCH_UNUSED, }, }, { }, }; --- NEW FILE: Makefile --- #!/usr/bin/make -f CC = gcc CFLAGS = -g -Wall -Werror -D_GNU_SOURCE all: $(CC) $(CFLAGS) -c -o parse_vax.o parse_vax.c $(CC) $(CFLAGS) -c -o parse_i386.o parse_i386.c $(CC) $(CFLAGS) -c -o parse_disassembly.o parse_disassembly.c $(CC) $(CFLAGS) -c -o graphic.o graphic.c $(CC) $(CFLAGS) -c -o graphic_dot.o graphic_dot.c $(CC) $(CFLAGS) -c -o address.o address.c $(CC) $(CFLAGS) -c -o regexp_helper.o regexp_helper.c $(CC) $(CFLAGS) -c -o parse_backend.o parse_backend.c $(CC) $(CFLAGS) -o disassemble parse_disassembly.o \ parse_vax.o \ parse_i386.o \ graphic.o \ graphic_dot.o \ address.o \ regexp_helper.o \ parse_backend.o vax: all ./disassemble vax vax.dis > xx 2> yy && dot -Tps < xx > xx.ps && poster -mA4 -p6x4A4 < xx.ps > xxx.ps i386: all ./disassemble i386 i386.dis > xx 2> yy && dot -Tps < xx > xx.ps && poster -mA4 -p6x4A4 < xx.ps > xxx.ps clean: -rm -f *.o core disassemble xx yy xx.* yy.* xxx.* --- NEW FILE: address.c --- #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include "address.h" uint64_t uint64_from_hex_address (unsigned char *hex) { return strtoll (hex, NULL, 16); } --- NEW FILE: README --- Notes to disasm-visualizer-0.0.1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If you're a user... ~~~~~~~~~~~~~~~~~~~ I only implemented a parser backend for VAX disassembly. If you want to visualize something else, you need to write it on your own. As for the drawing backend, I decided to first of all implement a "dot" backend. It'll generate "dot" files which can be visualized with "dot", which is part of the graphviz package. Invocation is like this: vax-linux-objdump -d -w /path/to/vax_object_file.o | ./visualize vax - > output.dot dot -Tps < output.dot > output.ps gv output.ps For a nice display, you may want to use "poster" (package: "poster") to bring the output nicely readable onto a number of pages in large scale :) If you need a different architecture's disassembler output supported... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You need to provide a parse_<your architecture>.c, which contains a number of regexp's and actions to take on them. Look at the VAX file, and look at the description in parse.h. It's really quite easy. The second step is to make this backend known to the frontend. Just put it into parse_disassembly.c:main(), there's also a (single) check for the VAX backend which you simply must extend. If you need a different graphic output... ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Conceptually, this beast should easily support output to different formats than "dot". If you've got some luck, "dot" (the program) can even convert the "dot" format to whatever you need. At least, DIA, GIF, JPEG and a number of other formats are already supported! If this doesn't work for you, you need to implement a new backend. This isn't really hard, too. Look at graphic.h: you need to provide an own implementation of "struct graphic_implementation". For a first start, look at graphic_dot.c. Most formats should be hierarchical, too, so it's probably only something like exchanging keywords... After you've done that, you must make your implementation known to graphic.c:graphic_init(). Then, hack parse_disassembly.c:main() to also select your implementation. Done. Fri, 11 Mar 2005 13:34:49 +0100 -- Jan-Benedict Glaw <jb...@lu...> --- NEW FILE: regexp_helper.h --- #ifndef _REGEX_HELPER_H #define _REGEX_HELPER_H extern int try_regexp (unsigned char *regexp, unsigned char *line, int num_returns, ...); #endif /* _REGEX_HELPER_H */ --- NEW FILE: regexp_helper.c --- #include <regex.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> struct result_catcher { int match_index; unsigned char **result; }; int try_regexp (unsigned char *regexp, unsigned char *line, unsigned int num_returns, ...) { int regex_ret; regex_t regex; regmatch_t *match; struct result_catcher *catch = NULL; va_list args; int largest_match = 0; /* * Get memory for result catcher structures */ if (num_returns) { int i; catch = malloc (num_returns * sizeof (struct result_catcher)); if (!catch) return -1; /* * Set all values */ va_start (args, num_returns); { for (i = 0; i < num_returns; i++) { catch[i].match_index = va_arg (args, int); catch[i].result = va_arg (args, unsigned char **); if (largest_match < catch[i].match_index) largest_match = catch[i].match_index; } } va_end (args); } /* * Compile the regex */ regex_ret = regcomp (®ex, regexp, REG_EXTENDED); if (regex_ret != 0) return -1; /* * If we need to supply a result, actually work towards getting * it at all... */ if (num_returns) { match = malloc ((largest_match + 1) * sizeof (regmatch_t)); if (!match) { regfree (®ex); if (catch) free (catch); return -1; } } else match = NULL; /* * Execute the regex */ regex_ret = regexec (®ex, line, match? largest_match + 1: 0, match, 0); if (regex_ret == 0) { int i; unsigned int failure = 0; for (i = 0; i < num_returns; i++) if (match[i].rm_so == -1 || match[i].rm_eo == -1) failure++; if (failure) { if (catch) free (catch); if (match) free (match); for (i = 0; i < num_returns; i++) *(catch[i].result) = NULL; regfree (®ex); return -1; } else { for (i = 0; i < num_returns; i++) *(catch[i].result) = strndup (line + match[catch[i].match_index].rm_so, match[catch[i].match_index].rm_eo - match[catch[i].match_index].rm_so); if (catch) free (catch); if (match) free (match); regfree (®ex); return 0; } } else { int i; if (catch) free (catch); if (match) free (match); for (i = 0; i < num_returns; i++) *(catch[i].result) = NULL; regfree (®ex); return -1; } } --- NEW FILE: address.h --- #ifndef _ADDRESS_H #define _ADDRESS_H #include <stdint.h> extern uint64_t uint64_from_hex_address (unsigned char *hex); #endif /* ADDRESS_H */ --- NEW FILE: parse.h --- #ifndef _PARSE_H #define _PARSE_H #define NUM_MATCHES 3 struct arch_parser_table { unsigned char *regexp; unsigned char *type; /* condjump, jump, ignore, ... */ unsigned int arg[NUM_MATCHES]; #define MATCH_UNUSED ((unsigned int)-1) }; extern int parse_line (unsigned char *line, struct arch_parser_table *table); extern struct arch_parser_table vax_parser[]; extern struct arch_parser_table i386_parser[]; /* * If you build your own parsing table, this is the HowTo: * { .regexp = "^[[:space:]]*([[:xdigit:]]+): [[:xdigit:] ]+ (sobgtr|blbc) [^,]+,([[:xdigit:]]+) <.*>$", .type = "condjump", .arg = { 0, 1, 3, }, }, * * If the above regexp matches, then you could think of it as a call to a * "condjump" function, which gets three arguments supplied. These * arguments are fugured out automatically from the regexp. You only * have to supply the match index from within the regexp. condjump()'s * first argument (which is "0"), shall be the 0th match of the regexp * (which is the whole line in this case). The second argument shall be * the 1st match of the regexp, which the first thing within (...), so * it's the address of the line in this example. condump()'s 3rd argument * is the match #3 in this example, which is the hexadecimal jump address * of the assembler output. * * Addresses _must_ always be in hex format, without leading "0x", but * leading '0's are allowed. * * If you add additional regexps, or whole architectures, blease note them * in Whats_Implemented.txt!!! * * * Here's the full list of supported callback function: * * condjump (<assembler code>, <address of line>, <jump target address>); * jump (<assembler code>, <address of line>, <jump target address>); * ret (<assembler code>, <address of line>, MATCH_UNUSED); * ignore (MATCH_UNUSED, MATCH_UNUSED, MATCH_UNUSED); * section (<assembler code>, <section name>, MATCH_UNUSED); * function (<assembler code>, <function name>, <function address>); * code (<assembler code>, <address of line>, MATCH_UNUSED); * */ #endif /* PARSE_H */ --- NEW FILE: parse_backend.c --- #include <regex.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include "address.h" #include "graphic.h" #include "parse.h" #include "regexp_helper.h" #ifndef ARRAY_SIZE # define ARRAY_SIZE(x) ( sizeof (x) / sizeof ((x)[0]) ) #endif static int parse_condjump (unsigned char *line, unsigned char *line_address_hex, unsigned char *jump_address_hex) { uint64_t line_address; uint64_t jump_address; if (!line || !line_address || !jump_address) return -1; line_address = uint64_from_hex_address (line_address_hex); jump_address = uint64_from_hex_address (jump_address_hex); return graphic_push_cond_jump (line, line_address, jump_address); } static int parse_jump (unsigned char *line, unsigned char *line_address_hex, unsigned char *jump_address_hex) { uint64_t line_address; uint64_t jump_address; if (!line || !line_address || !jump_address) return -1; line_address = uint64_from_hex_address (line_address_hex); jump_address = uint64_from_hex_address (jump_address_hex); return graphic_push_jump (line, line_address, jump_address); } static int parse_ret (unsigned char *line, unsigned char *line_address_hex, unsigned char *unused1) { uint64_t line_address; if (!line || !line_address_hex) return -1; line_address = uint64_from_hex_address (line_address_hex); return graphic_push_ret (line, line_address); } static int parse_ignore (unsigned char *line, unsigned char *unused1, unsigned char *unused2) { return 0; } static int parse_section (unsigned char *line, unsigned char *section_name, unsigned char *unused1) { if (!line || !section_name) return -1; return graphic_start_section (section_name); } static int parse_function (unsigned char *line, unsigned char *function_name, unsigned char *function_address_hex) { uint64_t function_address; if (!line || !function_name || !function_address) return -1; function_address = uint64_from_hex_address (function_address_hex); return graphic_start_function (function_name, function_address); } static int parse_code (unsigned char *line, unsigned char *line_address_hex, unsigned char *unused1) { uint64_t line_address; if (!line || !line_address_hex) return -1; line_address = uint64_from_hex_address (line_address_hex); return graphic_push_normal_code (line, line_address); } static struct parser_func_table_entry { unsigned char *name; int (*parser_function) (unsigned char *arg1, unsigned char *arg2, unsigned char *arg3); } function_table[] = { { .name = "condjump", &parse_condjump, }, { .name = "jump", &parse_jump, }, { .name = "ret", &parse_ret, }, { .name = "ignore", &parse_ignore, }, { .name = "section", &parse_section, }, { .name = "function", &parse_function, }, { .name = "code", &parse_code, }, }; static void * find_parse_function (unsigned char *name) { int i; for (i = 0; i < ARRAY_SIZE (function_table); i++) if (strcmp (function_table[i].name, name) == 0) return function_table[i].parser_function; return NULL; } int parse_line (unsigned char *line, struct arch_parser_table *arch) { unsigned char *arg[NUM_MATCHES]; int (*parse_function) (unsigned char *, unsigned char *, unsigned char *); int ret; int i; unsigned int num_returns; unsigned int returns[NUM_MATCHES]; while (arch->regexp && arch->type) { num_returns = 0; /* * First get the backend function for this arch's match */ parse_function = find_parse_function (arch->type); if (!parse_function) { fprintf (stderr, "Didn't find parse function for <%s>\n", arch->type); arch++; continue; } /* * Execute the regex to see if it fires */ for (i = 0; i < NUM_MATCHES; i++) { if (arch->arg[i] != MATCH_UNUSED) { returns[i] = arch->arg[i]; num_returns++; } else arg[i] = NULL; } /* * Try to match the regexp. */ switch (num_returns) { case 0: ret = try_regexp (arch->regexp, line, num_returns); break; case 1: ret = try_regexp (arch->regexp, line, num_returns, returns[0], &arg[0]); break; case 2: ret = try_regexp (arch->regexp, line, num_returns, returns[0], &arg[0], returns[1], &arg[1]); break; case 3: ret = try_regexp (arch->regexp, line, num_returns, returns[0], &arg[0], returns[1], &arg[1], returns[2], &arg[2]); break; default: fprintf (stderr, "This needs to be modified " "for %d returns!!!\n", num_returns); exit (EXIT_FAILURE); break; } /* * If the regexp fired, the result needs to be dispatched. */ if (ret == 0) { if (NUM_MATCHES != 3) { fprintf (stderr, "This needs to be modified " "for %d possible matches!!!\n", NUM_MATCHES); exit (EXIT_FAILURE); } ret = (*parse_function) (arg[0], arg[1], arg[2]); for (i = 0; i < NUM_MATCHES; i++) if (arg[i]) free (arg[i]); if (ret == 0) return 0; } arch++; } return -1; } --- NEW FILE: parse_vax.c --- #include "parse.h" /* * * * If you add additional codes here, please note them in Whats_Implemented.txt * * */ struct arch_parser_table vax_parser[] = { { .regexp = "^.*: file format .*$", .type = "ignore", .arg = { MATCH_UNUSED, MATCH_UNUSED, MATCH_UNUSED, }, }, { .regexp = "^$", .type = "ignore", .arg = { MATCH_UNUSED, MATCH_UNUSED, MATCH_UNUSED, }, }, { .regexp = "^Disassembly of section ([^:]+):$", .type = "section", .arg = { 0, 1, MATCH_UNUSED, }, }, { .regexp = "^[[:space:]]*([[:xdigit:]]+) <([^>]+)>:$", .type = "function", .arg = { 0, 2, 1, }, }, { .regexp = "^[[:space:]]*([[:xdigit:]]+):[[:xdigit:][:space:]]+ret$", .type = "ret", .arg = { 0, 1, MATCH_UNUSED, }, }, { .regexp = "^[[:space:]]*([[:xdigit:]]+): [[:xdigit:] ]+ (sobgtr|blbc) [^,]+,([[:xdigit:]]+) <.*>$", .type = "condjump", .arg = { 0, 1, 3, }, }, { .regexp = "^[[:space:]]*([[:xdigit:]]+): [[:xdigit:] ]+ (bbss|bbs|bbc|aoblss|aobleq) [^,]+,[^,]+,([[:xdigit:]]+) <.*>$", .type = "condjump", .arg = { 0, 1, 3, }, }, { .regexp = "^[[:space:]]*([[:xdigit:]]+): [[:xdigit:] ]+ (brb|brw) ([[:xdigit:]]+) <.*>$", .type = "jump", .arg = { 0, 1, 3, }, }, { .regexp = "^[[:space:]]*([[:xdigit:]]+): [[:xdigit:] ]+ (bneq|blss|beql|bleq|bgeq|blequ|bcc|bgtr) ([[:xdigit:]]+) <.*>$", .type = "condjump", .arg = { 0, 1, 3, }, }, { .regexp = "^[[:space:]]*([[:xdigit:]]+):[[:space:]]+.*$", .type = "code", .arg = { 0, 1, MATCH_UNUSED, }, }, { }, }; |