Storage of variable in stack frame under Linux platform

Source: Internet
Author: User

Local variables are stored in the stack, the stack in memory is characterized by top-down growth, that is, from the high address to the low address, when the variable as a function parameter is passed as a value, the function parameters as the receiver will open a temporary space to copy the value of the argument, the following code:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7E/64/wKioL1b-ILyCJeKlAABJJbHIj1E243.png "title=" QQ picture 20160401152350.png "alt=" Wkiol1b-ilycjeklaabjjbhij1e243.png "/>


When the function stack_test is called in the main function, the local variable, a and B are passed, at which point the debug can get the storage location of a A/b.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7E/68/wKiom1b-IOnyJXUgAAAi8hugdjI249.png "title=" QQ picture 20160401152435.png "alt=" Wkiom1b-ionyjxugaaai8hugdji249.png "/>

After entering the function stack_test, temporarily opens up another space to copy the value of a, B, debugging can be derived

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7E/68/wKiom1b-IUjD6HJYAAAbhp1mLQI358.png "title=" QQ picture 20160401152422.png "alt=" Wkiom1b-iujd6hjyaaabhp1mlqi358.png "/>

Therefore, the formal parameter and the argument is not the same thing, but the value is the same, at this time, the output B, the value should be 0xbbbb, and then assign the address of a to the temporary pointer variable p, and then the P self-added, debugging can be

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7E/64/wKioL1b-IuqCEGOtAAAhW5ElhIw180.png "title=" QQ picture 20160401152444.png "alt=" Wkiol1b-iuqcegotaaahw5elhiw180.png "/>

So assigning a value of 0xdddd to the space pointed to by the pointer P is to change the B value in the function struct_test to 0XDDDD, but the B in the main function does not change, at this point the output B value is 0xdddd.


The following program:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/7E/6C/wKiom1b-ZIKwONWAAABD0hVCoS4676.png "title=" QQ picture 20160401152407.png "alt=" Wkiom1b-zikwonwaaabd0hvcos4676.png "/>

Running the program will restart the system because the function bug uses System ("reboot"); the system function calls fork to create a sub-process, in function stack_test, debugging can be

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7E/6C/wKiom1b-ZVKzIo5XAAAbhp1mLQI955.png "title=" QQ picture 20160401201941.png "alt=" Wkiom1b-zvkzio5xaaabhp1mlqi955.png "/>

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7E/69/wKioL1b-ZhXwYGCKAAAXMe5JkSY189.png "title=" QQ picture 20160401201947.png "alt=" Wkiol1b-zhxwygckaaaxme5jksy189.png "/>

The entry for the function bug is assigned to the pointer variable p,

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7E/6C/wKiom1b-ZdnR2iMhAAAT4xFmmzE287.png "title=" QQ picture 20160401202242.png "alt=" Wkiom1b-zdnr2imhaaat4xfmmze287.png "/>

The 0x8048414 is converted to decimal to a value of 134513684 of the space that *p points to, which is to assign an offset of 0x8048414 to *p

When the Stack_test function ends, it calls the bug function.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/7E/69/wKioL1b-ZwmA7YHdAAAn1GL6TTU187.png "title=" QQ picture 20160401202525.png "alt=" Wkiol1b-zwma7yhdaaan1gl6ttu187.png "/>

This article is from the "Knock Code good Sleep zzz" blog, please be sure to keep this source http://2627lounuo.blog.51cto.com/10696599/1759362

Storage of variable in stack frame under Linux platform

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.