简体   繁体   English

临时数据如何存储在堆栈框架上

[英]How is temp data stored on the stack frame

Int test(){
    char buff[10]

    printf("Enter text: ");

    gets(buff);

    puts(buff);
}

I don't know how to phrase this question but I'm trying to understand how values are stored on on the buffer allocated for local variables on the stack frame. 我不知道如何表达这个问题,但是我试图了解如何将值存储在为堆栈帧上的局部变量分配的缓冲区中。

---------------
Return Address
---------------
old ebp
---------------
local variables
--------------- 

Is each block 4 bytes and divided in to 4 1 bytes? 每个块是4字节,又分成4个1字节吗?

------------------
 00 | 40 | 06 | 06
------------------
 ff | ff | de | 70 
------------------

Through gdb I saw the buffer allocated for test was 0x10 通过gdb,我看到分配给测试的缓冲区是0x10

I entered sssssssss : 我进入sssssssss

x/x $rbp = 0xffffde70
x/x $rbp + 8 = 0x00400606
x/s $rbp - 16 = "sssssssss"
x/s $rbp - 8 = "\ns"
x/s $rbp - 4 = ""

So how are the characters(in hex) that I entered stored? 那么我输入的字符(十六进制)如何存储? like how many on each block. 像每个区块有多少 It's a 64 system. 这是一个64系统。

 -----------------
 00 | 40 | 06 | 06
------------------
 ff | ff | de | 70 
------------------
    |    |    | 
------------------
    |    |    | s
------------------
 s  | s  | s  | s
------------------
 s  | s  | s  | s 
------------------

From a strict C point of view we don't know. 从严格的C角度来看,我们不知道。

The standard doesn't specify such things. 该标准未指定此类内容。 The standard doesn't even mention the concept of a stack. 该标准甚至没有提到堆栈的概念。 From a standard point of view the code is executed on an abstract machine (ie no description of how the machine does it. Only what the machine must do). 从标准的角度来看,代码是在抽象机器上执行的(即,没有关于机器如何执行的描述。只有机器必须执行的操作)。

So how it is done depends on the specific implementation and it (may) differ from system to system. 因此,如何完成取决于具体的实现,并且(可能)因系统而异。

You need to find the ABI document for the system you are using. 您需要找到所用系统的ABI文档。 The ABI document will describe how it is done on your system. ABI文档将描述如何在您的系统上完成。

See en.wikipedia.org/wiki/Application_binary_interface 参见en.wikipedia.org/wiki/Application_binary_interface

Maybe read Where is the x86-64 System V ABI documented? 也许阅读x86-64 System V ABI记录在哪里?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM