如何使用GCC将源代码行与汇编输出内联? [英] How can I get the source lines inline with the assembly output using GCC?

查看:134
本文介绍了如何使用GCC将源代码行与汇编输出内联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经尝试了像<$ c这样的GCC选项。

我想让C源代码行与程序集输出内联,以查看正在生成的代码。 $ c> -S -Wa,-ahlms (甚至 -Wa, - gstabs

哦!顺便说一句,我在Mac上,所以我没有 objdump



(对不起, )
$ b

gcc pc -clisp.c -S -g -fverbose -asm -fnested-functions的输出

  .globl _getBool 
_getBool:
LFB32:
LM21 :
pushl%ebp#
LCFI30:
movl%esp,%ebp#,
LCFI31:
subl $ 8,%esp#,
LCFI32:
LM22:
movzbl 8(%ebp),%eax#atom.pred,D.4112
movzbl%al,%eax#D.4112,D.4113
andl $ -16,%eax#,D.4114
sarl $ 4,%eax#,D.4115
testl%eax,%eax#D.4115
setne%al#,tmp64
movzbl%al,%eax#tmp64,D.4111
leave
ret
LFE32:


解决方案

也许调试+后处理步骤?

  gcc< source.c> -S -g -fverbose -asm 

查找 .file 11。 c来告诉你文件编号到文件名映射。
然后在 .loc 1 8 0 行之后添加源代码。我不知道如何使用单个shell命令来做到这一点,但一个简短的脚本应该能够做到这一点:

  #!/ usr / bin / env python 

import re
import sys

filename = sys.argv [1]

f = open(filename)
lines = f.readlines()
f.close()

FILE_RE = re.compile(r\ s + \.file(\ (* .d +)(\ d +))
$(+) b $ b output = []
files = {}
用于行内行:
output.append(行)
mo = FILE_RE.match(行)
如果mo不是None:
files [mo.group(1)] = open(mo.group(2))。readlines()
print mo.group(1),=,mo .group(2)
continue
mo = LOC_RE.match(line)
如果mo不是None:
print mo.group(1),=,mo。 group(2)
source = files [mo.group(1)] [int(mo.group(2)) - 1]
output.append(\ t#+ source)

f = open(文件名+。2,w)
f.writelines(o utput)
f.close()


I'd like to get the C source lines inline with the assembly output to see what code is being generated.

I have tried GCC options like -S -Wa,-ahlms (and even -Wa,--gstabs 'cause I read it somewhere).

Oh! BTW, I am on a Mac so I don't have objdump.

(Sorry this is short, I have to get off the train!)

Output of gcc pc-clisp.c -S -g -fverbose-asm -fnested-functions

.globl _getBool
_getBool:
LFB32:
LM21:
    pushl   %ebp    #
LCFI30:
    movl    %esp, %ebp      #,
LCFI31:
    subl    $8, %esp        #,
LCFI32:
LM22:
    movzbl  8(%ebp), %eax   # atom.pred, D.4112
    movzbl  %al, %eax       # D.4112, D.4113
    andl    $-16, %eax      #, D.4114
    sarl    $4, %eax        #, D.4115
    testl   %eax, %eax      # D.4115
    setne   %al     #, tmp64
    movzbl  %al, %eax       # tmp64, D.4111
    leave
    ret
LFE32:

解决方案

Maybe debug + a post-process step?

gcc <source.c> -S -g -fverbose-asm

Find .file 1 "1.c" to tell you the file number to file name mapping. Then add source after the .loc 1 8 0 lines. I'm not sure how to do it with a single shell command, but a short script should be able to do it:

#!/usr/bin/env python

import re
import sys

filename = sys.argv[1]

f = open(filename)
lines = f.readlines()
f.close()

FILE_RE=re.compile(r"\s+\.file (\d+) \"(.*)\"")
LOC_RE =re.compile(r"\s+\.loc (\d+) (\d+)")

output = []
files = {}
for line in lines:
    output.append(line)
    mo = FILE_RE.match(line)
    if mo is not None:
       files[mo.group(1)] = open(mo.group(2)).readlines()
       print mo.group(1),"=",mo.group(2)
       continue
    mo = LOC_RE.match(line)
    if mo is not None:
       print mo.group(1),"=",mo.group(2)
       source = files[mo.group(1)][int(mo.group(2))-1]
       output.append("\t#"+source)

f = open(filename+".2","w")
f.writelines(output)
f.close()

这篇关于如何使用GCC将源代码行与汇编输出内联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆