我如何在nasm中包含调试信息? [英] How can I include debug information with nasm?
问题描述
我有这个源代码:
; hello.asm是针对Linux,英特尔,gcc
的nasm的第一个程序;
;汇编:nasm -f elf -l hello.lst hello.asm
;链接:gcc -o你好hello.o
;运行:hello
;输出是:Hello World
SECTION .data;数据部分
msg:dbHello World,10;要打印的字符串,10 = cr
len:equ $ -msg; $表示这里
; len是一个值,而不是地址
SECTION .text;代码部分
全球主要;使标签可用于链接器
main:;标准gcc入口点
mov edx,len; arg3,要打印的字符串的长度
mov ecx,msg; arg2,指向字符串
的指针mov ebx,1; arg1,在哪写,屏幕
mov eax,4;写命令为int 80 hex
int 0x80;中断80十六进制,调用内核
mov ebx,0;退出代码,0 =正常
mov eax,1;将命令退出到内核
int 0x80;中断80十六进制,调用内核
这段代码取自 here 。
我正在VirtualBox上运行 Ubuntu 12.04 32位以进行学习。
步骤如下:
- nasm -f elf -g -F stabs hello.asm
- ld -o hello hello.o
- gdb hello -tui
现在,当我只运行 hello 时,它可以正常运行,但gdb无法显示任何源代码。为什么?当我尝试在gdb中运行运行时,我会看到 Hello World 文字,但它没有显示源代码。
看起来stabs格式不适用于GDB,请尝试使用DWARF( http://en.wikipedia.org/wiki/DWARF )
使用
< blockquote>
nasm -f elf -g -F dwarf hello.asm
然后在gdb type p>
开始
然后
si
您将看到具有评论等内容的来源。正如Koray Tugay所说,gdb中很可能存在一个bug。
I have this source code:
; 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 code is taken from here.
I am running ubuntu 12.04 32-bit on VirtualBox for learning purposes.
Steps I follow are:
- nasm -f elf -g -F stabs hello.asm
- ld -o hello hello.o
- gdb hello -tui
Now when I only run hello it will run fine but gdb fails to show any source code. Why? When I tryp run in gdb I will see Hello World text just fine but it does not show the source.
It looks like stabs format doesn't work with GDB, try DWARF instead ( http://en.wikipedia.org/wiki/DWARF )
compile with
nasm -f elf -g -F dwarf hello.asm
then in gdb type
start
then
si
you will see sources with comments so on. as Koray Tugay said there is most probably a bug in gdb.
这篇关于我如何在nasm中包含调试信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!