You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 22.04中GDB无法查看x86_64汇编源码的问题及解决

更新

根据Michael Petch的建议,切换至nasm 2.16.01版本后,问题已解决。

原帖内容

使用全新安装的Ubuntu 22.04、nasm 2.15.05和gdb 12.1。调试x64汇编程序时,是否需要特殊操作才能查看源码?此前适用于x86汇编的步骤在x64下完全失效。

以下是详细测试过程:

x86/helloWorld.asm

section .data
msg:     db     'Hello, World!',0       ; define string as label

section .text
global start                            ; must be declared for linker

start:                                  ; entry point
        mov     eax, 4                  ; system call number (sys_write)
        mov     ebx, 1                  ; file descriptor (stdout)
        mov     ecx, msg                ; message
        mov     edx, 13                 ; message length
        int     0x80                    ; call kernel

        mov     eax, 1                  ; system call number (sys_exit)
        int     0x80                    ; call kernel

使用以下命令汇编并链接:
nasm -f elf32 -g -F dwarf helloWorld.asm
ld -m elf_i386 -e start -o helloWorld helloWorld.o

启动gdb:gdb helloWorld

在gdb中设置断点:

(gdb) break helloWorld.asm:9
Breakpoint 1 at 0x8049000: file helloWorld.asm, line 9.

使用lay n进入寄存器/源码拆分布局,寄存器不可用,源码区显示helloWorld.asm内容,一切正常。

x64/helloWorld.asm

section .data
msg:     db     'Hello, World!',0       ; define string as label

section .bss

section .text
global start                            ; must be declared for linker

start:                                  ; entry point
        mov     rax, 1                  ; system call number (sys_write)
        mov     rdi, 1                  ; file descriptor (stdout)
        mov     rsi, msg                ; message
        mov     rdx, 13                 ; message length
        syscall                         ; call kernel

        mov     rax, 60                 ; system call number (sys_exit)
        mov     rdi, 0                  ; 0 = success exit code
        syscall                         ; call kernel

使用以下命令汇编并链接:
nasm -f elf64 -g -F dwarf helloWorld.asm
ld -m elf_x86_64 -e start -o helloWorld helloWorld.o

启动gdb:gdb helloWorld

在gdb中设置断点:

(gdb) break helloWorld.asm:9
No line 9 in file "helloWorld.asm".
Make breakpoint pending on future shared library load? (y or [n])

使用lay n进入寄存器/源码拆分布局,寄存器不可用,源码区显示[ No Source Available ]。

执行(gdb) list时源码会显示,但执行下一步操作后又消失。

架构设置正常:

(gdb) show architecture
The target architecture is set to "auto" (currently "i386:x86-64").

请问为何GDB会将我的源码文件识别为待加载的共享库,且源码视图无法正常工作?该如何解决?

已尝试以下操作:

  • 重新安装gdb和Linux系统
  • 确认调试x64程序时GDB可访问源码文件(helloWorld和helloWorld.asm均存在)
  • 手动指定源码文件(无效果)

预期:

  • 可无阻碍地进行调试操作

内容的提问来源于stack exchange,提问作者0x706173696D75

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 04:13:26