CVS: htdocs/cgi-bin disassemble.py,1.6,1.7

Chris Liechti <[email protected]>
Newsgroups gmane.comp.hardware.texas-instruments.msp430.gcc.cvs
Message-ID <[email protected]>
Update of /cvsroot/mspgcc/htdocs/cgi-bin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17540/htdocs/cgi-bin

Modified Files:
	disassemble.py 
Log Message:
improved use as command line tool

Index: disassemble.py
===================================================================
RCS file: /cvsroot/mspgcc/htdocs/cgi-bin/disassemble.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -w -d -r1.6 -r1.7
--- disassemble.py	10 Mar 2004 18:42:32 -0000	1.6
+++ disassemble.py	1 Aug 2004 16:03:21 -0000	1.7
@@ -241,21 +241,39 @@
         
         if args:
             insn, words, cycles = disassemble(map(myint, args))
-            print "Parameter disassemble: %s  (%d words %d cycles)" % (insn, words, cycles)
+            sys.stdout.write("Parameter disassemble: %s  (%d words %d cycles)\n" % (insn, words, cycles))
             
         if options.binary is not None:
-            print "---- file: %s ----" % options.binary
+            sys.stderr.write("---- file: %s ----\n" % options.binary)
+            if options.binary:
+                import msp430, msp430.memory
+                data = msp430.memory.Memory()
+                try:
+                    data.loadFile(options.binary)
+                except msp430.elf.ELFException:
+                    sys.stderr.write("Attention: parsing binary file\n")
             memory = file(options.binary, 'rb').read()
             if len(memory) & 1: 
-                print "odd length!!, cutting off last byte"
+                        sys.stderr.write("odd length!!, cutting off last byte\n")
                 memory = memory[:-1]
             memwords = [struct.unpack("<H", memory[x:x+2])[0] for x in range(0, len(memory), 2) ]
-            #~ print len(words)
             offset = 0
             while offset < len(memwords):
                 insn, words, cycles = disassemble(memwords[offset:])
                 bytes = ' '.join(['%04x' % x for x in memwords[offset:offset+words]])
-                print "0x%04x:  %-16s   %-36s  (%d words %d cycles)" % (options.startadr+offset*2, bytes, insn, words, cycles)
+                        sys.stdout.write("0x%04x:  %-16s %-36s  (%d cycles)\n" % (options.startadr+offset*2, bytes, insn, cycles))
+                        offset += words
+                else:
+                    memwords = []
+                    for seg in data:
+                        memwords = [struct.unpack("<H", seg.data[x:x+2])[0] for x in range(0, len(seg.data), 2) ]
+                        sys.stdout.write("----- Address 0x%04x:\n" % seg.startaddress)
+                        options.startadr = seg.startaddress
+                        offset = 0
+                        while offset < len(memwords):
+                            insn, words, cycles = disassemble(memwords[offset:])
+                            bytes = ' '.join(['%04x' % x for x in memwords[offset:offset+words]])
+                            sys.stdout.write("0x%04x:  %-16s %-36s  (%d cycles)\n" % (options.startadr+offset*2, bytes, insn, cycles))
                 offset += words
     else:
         import cgi, os



-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on
Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
one more big change to announce. We are now OSTG- Open Source Technology
Group. Come see the changes on the new OSTG site. www.ostg.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.