Kdbg中显示的值是错误的-NASM [英] The value displayed in Kdbg is wrong -- NASM

查看:95
本文介绍了Kdbg中显示的值是错误的-NASM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何测试k的值是否正确?

How can I test to see if the value of k is correct?

section .data
    k dw 5
    m dw 110
    rez dw 0 
section .bss
    tabela resq 3 
section .text
global _start
extern uslov
_start:
    mov qword [tabela], k
    mov qword [tabela + 8], m
    mov qword [tabela + 16], rez

    mov rbx, tabela
    call uslov
mov rax, 60
mov rdi, 0
syscall

当我尝试检查kdbg中的k,m,rez的值时,m和rez的值都很好,但k的值完全不同,现在起初我以为它是随机的,但是读起来似乎很困难rez的值是8字节数字而不是2字节数字,并且还从m和rez中读取了所有6个字节,又读了6个字节,这是错误的,那么如何正确显示呢?

When I try to inspect the values of k,m,rez in kdbg the values of m and rez are just fine but the value of k is totally different, now at first i thought it was random, but it seems as tough it reads the value of rez as an 8 byte number instead of a 2 byte number and also reads in 6 more bytes taking in all the set 1's from m and rez which is wrong, so how can I display it correctly ?

截屏:

推荐答案

当我使用以下命令行进行编译时,我可以使用您的源代码重现此内容(删除对uslov的未定义引用):

I can reproduce this with your source (removing undefined references to uslov) when I compile using this command line:

nasm -f elf64 test.asm -o test.o
ld test.o -o test

然后,在GDB中,我确实可以看到k似乎具有sizeof(k)==4:

Then, in GDB I can indeed see that k appears to have sizeof(k)==4:

gdb ./test -ex 'tb _start' -ex r -ex 'p sizeof(k)'
Reading symbols from ./test...done.
Starting program: /tmp/test

Temporary breakpoint 1, 0x00000000004000b0 in _start ()
$1 = 4

这是因为最终二进制文件仅有的有关k的信息是它是数据区域中的符号.参见:

This is because the only information the final binary has about k is that it's a symbol in data area. See:

(gdb) ptype k
type = <data variable, no debug info>

调试器(KDbg在后台使用GDB)无法知道其大小,因此它只是猜测默认大小为sizeof(int).即使通过-F dwarf -g选项在NASM中启用了调试信息,它似乎也没有放置任何实际的调试信息.

The debugger (KDbg uses GDB under the hood) can't know its size, so it just guesses the default size to be sizeof(int). Even if you enable debug info in NASM via -F dwarf -g options, it still doesn't appear to put any actual debug info.

因此,获取以正确大小显示的变量的唯一方法是手动指定变量,例如(short)k而不是k.

So, your only way to get the variables displayed with the right size is to manually specify it, like (short)k instead of k.

这篇关于Kdbg中显示的值是错误的-NASM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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