On Mar 31, 2006, at 2:05 PM, Albert Pion wrote:
How do I get a program listing with my C source code included as
comments? I've tried about everything I can think of (including
the --Wa,-alhd option) but have been unable to get it to work.
Attached is a Ruby (http://www.ruby-lang.org) script to post-process
the output of avr-objdump into a legal assembly language program with
C program text as asm comments.
Its output looks like this:
.text
.global __bad_interrupt
.func __bad_interrupt
__bad_interrupt :
.weak __vector_default
.set __vector_default, __vectors
XJMP __vector_default
jmp 0x0 <__heap_end>
SerialCommandProcessor_setCurrentObject: ; (0x000000ca)
;; /* SerialCommandProcessor functions ------------------- */
;;
;; void
;; SerialCommandProcessor_setCurrentObject
(SerialCommandProcessor me, IOObject obj)
;; {
movw r30, r24
;; me->currentObject = (obj == NULL) ? me->topObject : obj;
cp r22, r1
cpc r23, r1
brne .+4 ;
SerialCommandProcessor_setCurrentObject+0xc (0xd6)
ldd r22, Z+2 ; (0x02)
ldd r23, Z+3 ; (0x03)
std Z+1, r23 ; (0x01)
st Z, r22
ret
Run it like so:
avr-objdump -S myProg.elf | ruby simplifyListing.rb > myProg.asm
--
Ned Konz
[EMAIL PROTECTED]
#!/usr/bin/ruby
# takes output of avr-objdump and turns it into real assembly code.
# Ned Konz <[EMAIL PROTECTED]>
# Sat Apr 1 08:55:32 PST 2006
# :beginning, :ccode, :asmcomment, :code
$state = :beginning
def outputLine(line)
case line
when /^;;\s/
if $state == :beginning
line.sub!(/^;*\s*(.+)/, ";;\t/* \\1 */")
else
$state = :ccode
end
when /^;/
$state = :asmcomment
when /^\s*$/
if $state == :ccode || $state == :beginning
line = ";;"
end
else
$state = :code
end
line.sub!(/\t;\s*([^;]*)\s*;\s*(.*)/, "\t; \\1 (\\2)") if $state != :beginning
line.sub!(/;\s*([a-f0-9]{8})\s*$/, "; (0x\\1)")
line.sub!(/;\s*(0x[a-f0-9]{2,8})\s*$/, "; (\\1)")
puts line
end
ARGF.each do | f |
f.each_line do | line |
line.sub!(/(0x[a-z0-9]{2,4})\s+<([^>]+)>/, "\\2 ; \\1")
line.sub!(/\tcall\t0x.... /, "\tcall ")
line.sub!(/\tjmp\t0x.... /, "\tjmp ")
line.sub!(/; 0x[0-9a-f]+ /, "; ")
line.sub!(/^<([^>]+)>:/, "\\1 :")
case line
# asm directive
when /^\s+(\.\w+|vector|XJMP)(\s+.*)?/
outputLine line
# asm label
when /^\s*(\w+)\s*:$/
outputLine "#{$1} :"
# line number (-l option to avr-objdump)
when /^(\/.*):([0-9]+)$/
puts "#line #{$2} \"#{$1}\""
$state = :code
# label
when /^([0-9a-fA-F]{8}) <([^>]+)>/
outputLine "#{$2}: ; #{$1}"
# instruction
when /^\s+[0-9a-fA-F]{1,4}:\t([0-9a-fA-F]{2}\s){2,} *\t/
outputLine line[22 ... -1]
# instruction, no opcodes
when /^\s+[0-9a-fA-F]{1,4}:\t*\t/
outputLine line[5 ... -1]
# table
when /^\s+[0-9a-fA-F]{1,4}:\t([0-9a-fA-F]{2}\s)[^\t]+$/
outputLine line[10 ... -1]
# blank line
when /^\s*$/
outputLine ""
# C code
else
outputLine ";;\t" + line
end
end
end
_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list