简体   繁体   English

GDB抱怨没有可用的来源

[英]GDB complains No Source Available

I'm running on Ubuntu 12.10 64bit. 我正在使用Ubuntu 12.10 64bit。

I am trying to debug a simple assembly program in GDB. 我正在尝试在GDB中调试一个简单的汇编程序。 However GDB's gui mode (-tui) seems unable to find the source code of my assembly file. 但是GDB的gui模式(-tui)似乎无法找到我的汇编文件的源代码。 I've rebuilt the project in the currently directory and searched google to no avail, please help me out here. 我在目前的目录中重建了该项目并搜索谷歌无济于事,请在这里帮助我。

My commands: 我的命令:

nasm -f elf64 -g -F dwarf hello.asm

gcc -g hello.o -o hello

gdb -tui hello

Debug information seems to be loaded, I can set a breakpoint at main() but the top half the screen still says ' [ No Source Available ] '. 似乎加载了调试信息,我可以在main()处设置断点,但屏幕的上半部分仍然显示' [No Source Available] '。

Here is hello.asm if you're interested: 如果你有兴趣,这是hello.asm:

;  hello.asm  a first program for nasm for Linux, Intel, gcc
;
; assemble: nasm -f elf -l hello.lst  hello.asm
; link:     gcc -o hello  hello.o
; run:          hello 
; output is:    Hello World 

    SECTION .data       ; data section
msg:    db "Hello World",10 ; the string to print, 10=cr
len:    equ $-msg       ; "$" means "here"
                ; len is a value, not an address

    SECTION .text       ; code section
        global main     ; make label available to linker 
main:               ; standard  gcc  entry point

    mov edx,len     ; arg3, length of string to print
    mov ecx,msg     ; arg2, pointer to string
    mov ebx,1       ; arg1, where to write, screen
    mov eax,4       ; write command to int 80 hex
    int 0x80        ; interrupt 80 hex, call kernel

    mov ebx,0       ; exit code, 0=normal
    mov eax,1       ; exit command to kernel
    int 0x80        ; interrupt 80 hex, call kernel

This statement is false. 这句话是错误的。

The assembler does produce line number information (note the -g -F dwarf) bits. 汇编程序确实生成行号信息(注意-g -F矮人)位。

On the other hand he assembles what is obviously 32-bit code as 64 bits, which may or may not work. 另一方面,他将明显的32位代码组装为64位,这可能有效,也可能无效。

Now if there are bugs in NASM's debugging output we need to know that. 现在,如果NASM的调试输出中存在错误,我们需要知道。

A couple of quick experiments shows that addr2line (but not gdb!) does decode NASM-generated line number information correctly using stabs but not using dwarf, so there is probably something wrong in the way NASM generates DWARF... but also something odd with gdb. 几个快速实验表明,addr2line(但不是gdb!) 确实使用stabs正确解码NASM生成的行号信息,但不使用dwarf,因此NASM生成DWARF的方式可能有些不对... GDB。

GNU addr2line version 2.22.52.0.1-10.fc17 20120131, GNU gdb (GDB) Fedora (7.4.50.20120120-52.fc17)). GNU addr2line版本2.22.52.0.1-10.fc17 20120131,GNU gdb(GDB)Fedora(7.4.50.20120120-52.fc17))。

The problem in this case is that the assembler isn't producing line-number information for the debugger. 这种情况下的问题是汇编程序没有为调试器生成行号信息。 So although the source is there (if you do "list" in gdb, it shows a listing of the source file - at least when I follow your steps, it does), but the debugger needs line-number information from the file to know what line corresponds to what address. 所以尽管源代码存在(如果你在gdb中执行“list”,它会显示源文件的列表 - 至少当我按照你的步骤进行时,它确实如此),但调试器需要从文件中获取行号信息才能知道什么线对应于什么地址。 It can't do that with the information given. 它不能用给出的信息做到这一点。

As far as I can find, there isn't a way to get NASM to issue the .loc directive that is used by as when using gcc for example. 至于我能找到,没有办法让NASM发行所使用的.loc指令as当使用gcc的例子。 But as isn't able to take your source file without generating a gazillion errors [even with -msyntax=intel -mmnemonic=intel -- you would think that should work]. 但是as无法在不产生大量错误的情况下获取源文件[即使使用-msyntax = intel -mmnemonic = intel - 你会认为这应该有效]。

So unless someone more clever can come up with a way to generate the .loc entries which gives the debugger line number information, I'm not entirely sure how we can answer your question in a way that you'll be happy with. 因此,除非有更聪明的人能想出一种生成.loc条目的方法来提供调试器行号信息,否则我不能完全确定我们如何能够以您满意的方式回答您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM