使用gdb调试时出现的消息:单步执行,直到从函数_start退出 [英] Message while debugging using gdb: Single stepping until exit from function _start

查看:786
本文介绍了使用gdb调试时出现的消息:单步执行,直到从函数_start退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在linux上使用nasm编写汇编语言程序.问题是使用gdb进行调试时,它不会进入_start函数内部,并显示消息单步执行,直到退出函数_start为止",

I am writing assembly language program using nasm on linux. The problem is during debugging using gdb it does not step inside the _start function and gives the message "Single stepping until exit from function _start,"

此外,当我在第1行之后设置断点时,它会说:

Also, when I set break points after line 1 it says:

(gdb) break 2  
Note: breakpoints 1 and 2 also set at pc 0x4000b0.  
Breakpoint 3 at 0x4000b0: file new3.asm, line 2.  

(gdb) break 3  
Note: breakpoints 1, 2 and 3 also set at pc 0x4000b0.  
Breakpoint 4 at 0x4000b0: file new3.asm, line 3.  

我正在使用以下命令进行组装和链接:

I am assembling and linking it using the commands :

nasm -g  -f elf64 new3.asm  
ld  -g new3.o

然后我使用gdb new3.out对其进行调试. gdb版本是7.11.1

then i debug it using gdb new3.out. The gdb version is 7.11.1

程序在下面:

section .text  
    global _start   ;must be declared for linker (ld)   
_start:             ;tells linker entry point  
    call sum  
    mov edx,len     ;message length  
    mov ecx,msg     ;message to write  
    mov ebx,1       ;file descriptor (stdout)  
    mov eax,4       ;system call number (sys_write)  
    int 0x80        ;call kernel  
    mov eax,1       ;system call number (sys_exit)  
    int 0x80        ;call kernel  

sum:  
   mov     eax, ecx  
   add     eax, edx  
   add     eax, '0'  
   ret  
section .data  
msg db 'Hello, world!', 0xa  ;string to be printed  
len equ $ - msg     ;length of the string  

我如何进入_start进行调试,这是什么意思?

How i can step inside the _start for debugging and what is the meaning of this?

(gdb) break 3
Note: breakpoints 1, 2 and 3 also set at pc 0x4000b0.
Breakpoint 4 at 0x4000b0: file new3.asm, line 3.

推荐答案

使用nasm -f elf64 -F dwarf -g new3.asm生成侏儒调试信息,而不是默认值(刺伤). (使用nasm -felf64 -y查看默认值). yasm -felf64 -gdwarf2 new3.asm也可以. (实际上,即使您遗漏了-gdwarf2进行Yasm,实际上也可以执行单步操作:我想默认情况下它包含了足够的内容.)

Use nasm -f elf64 -F dwarf -g new3.asm to make dwarf debug info, not the default (stabs). (Use nasm -felf64 -y to see the default). yasm -felf64 -gdwarf2 new3.asm works, too. (Actually single stepping works even if you leave out -gdwarf2 for yasm: I guess it includes enough by default).

然后,gdb将能够按源代码行而不是仅凭指令(stepi)单步执行.您不需要ld -g,那什么也没做.

Then gdb will be able to single-step by source lines instead of just by instructions (stepi). You don't need ld -g, that doesn't do anything.

您可能还应该链接gcc -nostdlib -g new3.o,而不是直接链接ld.如果在ld命令行中添加了任何动态库,则二进制文件将损坏(因为ld的默认ELF解释器路径在现代x86-64多体系结构系统上无用).请参阅从asm构建可执行文件定义_startmain静态或动态的源.

You should probably also link with gcc -nostdlib -g new3.o, instead of ld directly. If you added any dynamic libs to your ld command line, you'd have a broken binary (because ld's default ELF interpreter path isn't useful on modern x86-64 multiarch systems). See Building an executable from asm source that defines _start vs. main, static or dynamic.

此外,请勿使用64位代码中的int 0x80 32位ABI.

Also, don't use the int 0x80 32-bit ABI from 64-bit code.

使用stepi(或si)来逐步执行指令,而不是源代码行.

Use stepi (or si) to step by instructions instead of by source lines.

使用b *0x4000b0根据数字地址设置断点.或使用标签名称,例如b _start在入口点设置断点.

Use b *0x4000b0 to set breakpoints based on numeric address. Or use label names, like b _start to set a breakpoint at the entry point.

请参阅标签Wiki的底部有关使用gdb调试asm的更多提示.

See the bottom of the x86 tag wiki for some more tips on debugging asm with gdb.

文件中的第一条指令在第4行,因此b 1b 4都在CALL指令上设置了一个断点也就不足为奇了.

The first instruction in your file is on line 4, so it's not surprising that b 1 and b 4 both set a breakpoint on the CALL instruction.

b 5确实在CALL之后的指令上设置了一个断点.即使gdb仅具有STABS调试信息(而不是DWARF或DWARF2),但单步操作却没有,这部分仍然起作用. IDK为什么.

b 5 does set a breakpoint on the instruction after CALL. This part does work even when gdb only has STABS debug info (not DWARF or DWARF2), but single-stepping doesn't. IDK why.

(gdb) b _start
Breakpoint 1 at 0x4000b0
(gdb) b 5
Breakpoint 2 at 0x4000b5: file new3.asm, line 5.
(gdb) r
Starting program: /home/peter/src/SO/a.out

Breakpoint 1, 0x00000000004000b0 in _start ()

这篇关于使用gdb调试时出现的消息:单步执行,直到从函数_start退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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