【问题标题】:Cannot Access Memory At 0xe, kdbg on Ubuntu无法在 0xe 访问内存,Ubuntu 上的 kdbg
【发布时间】:2014-12-31 09:59:25
【问题描述】:

我正在学习 Jeff Duntemann 的书:Step by Step Assembly。以下是提供的源代码:

SECTION .data           ; Section containing initialised data

    EatMsg: db "Eat at Joe's!",10
    EatLen: equ $-EatMsg    

SECTION .bss            ; Section containing uninitialized data 

SECTION .text           ; Section containing code

global  _start          ; Linker needs this to find the entry point!

_start:
    nop         ; This no-op keeps gdb happy...
    mov eax,4       ; Specify sys_write call
    mov ebx,1       ; Specify File Descriptor 1: Standard Output
    mov ecx,EatMsg      ; Pass offset of the message
    mov edx,EatLen      ; Pass the length of the message
    int 80H         ; Make kernel call

    MOV eax,1       ; Code for Exit Syscall
    mov ebx,0       ; Return a code of zero 
    int 80H         ; Make kernel call

我在 64 位 MacOS Yosemite 之上的 VirtualBoxVM 上运行 Ubuntu 12.04 32 位。

我在打电话:

kdbg eatsyscall

启动 KDBG。

watches 部分我有 2 个表达式:EatMsgEatLen

当我使用 KDBG 为 EatMsg 运行代码时,我看到:544497989,但对于 EatLen,我看到:Cannot Access Memory At 0xe

我有两个问题:

这个 544497989 的值是什么?为什么我看到 EatLen 的“无法访问”消息?

【问题讨论】:

    标签: ubuntu assembly kdbg


    【解决方案1】:

    544497989EatMsg 的地址,它只是内存位置,即一个巨大的数字。如果你知道 C 或 C++,如果你的声明是 char * eatMsg = "Eat at Joe's!";,它相当于 &eatMsg

    EatLenEatMsg的长度:$代表“此时的地址”,是EatMsg的所有字节之后的下一个位置。所以$-EatMsg 是“EatMsg 的所有字节后的地址减去EatMsg 开头的地址”=“EatMsg 的长度”= 14 十进制 = 0x0E 十六进制。

    您的调试器可能将此长度解释为地址。诸如此类的小值不能作为地址引用。您应该仅将其显示为一个值,而不是将其解释为地址。

    【讨论】:

    • 但是 544497989 不是 2 的幂。地址不应该是 2 的幂吗?
    • 一点也不。对于某些数据和架构,需要 2(或 4 或 8)的 倍数,但对于 db 则不是这样。
    • 实际上,544497989(十进制),表示为十六进制是 20746145h - 空格的 ascii 代码,'t','a','E' - 它看起来“向后”,因为多字节值是存储“小端”。如果您一次检查一个字节,它将以“正确”的顺序出现。
    • @FrankKotler 不错!实际上,OP 可能显示的是EatMsg 的内容而不是地址。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多