gcc 无法在SASM中使用调试

kmb7vmvb  于 2023-08-06  发布在  其他
关注(0)|答案(1)|浏览(111)

我正在学习NASM并尝试调试此代码:

; jump.asm
extern printf
section .data
    number1 dq 42
    number2 dq 41
    fmt1 db "NUMBER1 >= NUMBER2",10,0
    fmt2 db "NUMBER1 < NUMBER2",10,0
section .bss
section .text
    global main
main:
    mov rbp,rsp
    push rbp
    mov rbp,rsp
    mov rax, [number1]
    mov rbx, [number2]
    cmp rax,rbx
    jge greater
    mov rdi,fmt2
    mov rax,0
    call printf
    jmp exit
greater:
    mov rdi,fmt1
    mov rax,0
    call printf
exit:
    mov rsp,rbp
    pop rbp
    ret

字符串
它构建得很好,并按预期执行。但是无论我在哪里放置断点并尝试使用调试选项-调试不执行,构建日志:

Build log:
[01:29:05] Build started...
[01:29:05] Built successfully.
[01:29:05] Debugging started...
GDB error
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /tmp/SASM/SASMprog.exe...
(gdb) Dump of assembler code for function main:
   0x0000000000401150 <+0>: mov    %rsp,%rbp
   0x0000000000401153 <+3>: push   %rbp
   0x0000000000401154 <+4>: mov    %rsp,%rbp
   0x0000000000401157 <+7>: mov    0x404040,%rax
   0x000000000040115f <+15>:    mov    0x404048,%rbx
   0x0000000000401167 <+23>:    cmp    %rbx,%rax
   0x000000000040116a <+26>:    jge    0x401182 <greater>
   0x000000000040116c <+28>:    movabs $0x404064,%rdi
   0x0000000000401176 <+38>:    mov    $0x0,%eax
   0x000000000040117b <+43>:    call   0x401040 <printf@plt>
   0x0000000000401180 <+48>:    jmp    0x401196 <exit>
End of assembler dump.
(gdb) Breakpoint 1 at 0x401150: file /tmp/SASM/program.asm, line 12.
(gdb) Working directory /home/snorlax212/asm.
(gdb) Starting program: /tmp/SASM/SASMprog.exe 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, main () at /tmp/SASM/program.asm:12
12      mov rbp,rsp
(gdb) $1 = 0
(gdb) [01:29:15] Debugging finished.


在终端中进行GDB调试(gdb jump/break main/step)工作正常。有人知道该怎么做吗?
SASM构建选项:This!版本:

snorlax212@snorlax212-pc:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.2 LTS
Release:    22.04
Codename:   jammy
snorlax212@snorlax212-pc:~$ nasm --version
NASM version 2.16.01
snorlax212@snorlax212-pc:~$ gdb --version
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
snorlax212@snorlax212-pc:~$ gcc --version
gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


尝试添加-F dwarf选项,-m64 -fno-pie选项-没有帮助。

e0bqpujr

e0bqpujr1#

我遇到了同样的错误,因为书上说要改变构建配置。当我删除汇编选项中的“-g”时,调试工作正常。见屏幕截图....
x1c 0d1x的数据

相关问题