View the initial stack content of a Linux Process

Source: Internet
Author: User
Article Title: view the initial stack content of a Linux Process. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

When I learned "Programmer self-cultivation", I was a little interested in its P172 page-12 "Linux Process initial stack" content. So I took some time to study it, suddenly, I tried a way to get the initial stack of the process ......

[Root @ cxj/] # cat a. c

# Include

# Include

Int main ()

{

Printf ("hello world \ n ");

Return 0;

}

[Root @ cxj/] # readelf-a. out | head-n 11

ELF Header:

Magic: 7f 45 4c 46 01 01 00 00 00 00 00 00 00 00 00 00

Class: ELF32

Data: 2's complement, little endian

Version: 1 (current)

OS/ABI: UNIX-System V

ABI Version: 0

Type: EXEC (Executable file)

Machine: Intel 80386

Version: 0x1

Entry point address: 0x80482f0% get Entry address

[Root @ cxj/] # gdb a. out % load the executable file

GNU gdb Red Hat Linux (6.6-35. fc8rh)

Copyright (C) 2006 Free Software Foundation, Inc.

GDB is free software, covered by the GNU General Public License, and you are

Welcome to change it and/or distribute copies of it under certain conditions.

Type "show copying" to see the conditions.

There is absolutely no warranty for GDB. Type "show warranty" for details.

This GDB was configured as "i386-redhat-linux-gnu "...

Using host libthread_db library "/lib/libthread_db.so.1 ".

(Gdb) B * 0x80482f0% set the entry address to a breakpoint

Breakpoint 1 at 0x80482f0

(Gdb) r % Start Process

Starting program:/a. out

Warning: Missing the separate debug info file:/usr/lib/debug/. build-id/ac/2eeb206486bb7315d6ac4cd64de0cb50838ff6. debug

Warning: Missing the separate debug info file:/usr/lib/debug/. build-id/ba/4ea1118691c81_26e9410cafb798f25cefad5. debug

Breakpoint 1, 0x080482f0 in _ start ()

(Gdb) I r esp % view stack top pointer (esp)

Esp 0xbf8e5a40 0xbf8e5a40

(Gdb) x/5570bw 0xbf8e5a40% view the content of the storage area from the position indicated by esp far enough. Here 5570 refers to view the 5570 "Words" starting from 0xbf8e5a40 (4 bytes here) content

% Here, 5570 is used only to make the content to be viewed later large enough.

% In fact, we can push a maximum of 0 x bytes from the current address and the number of bytes is 0 x aligned. [Experience, I did not go into the theoretical reasons]

% For example, if 0xbf8e5a40 is pushed to a maximum of 0 x bytes and the 0x1000 alignment is maintained, 0xbf8e8000 is obtained.

% The number of bytes in this area is converted to "word": (0xbf8e8000-0xbf8e5a40)/4 = 2416

% So replace 2416 with a value slightly greater than 5570 (to get an error) to get the error message of Cannot access memory at address 0 xXXXXXXXX (try again )))

% This error message can be used as a flag for out-of-bounds stack access to the current process.

%

% If the output structure shown below cannot be obtained using the "x/5570bw 0xbf8e5a40" command, try "x/5570x 0xbf8e5a40"

0xbf8e5a40: 0x00000001 0xbf8e7a98 0x00000000 0xbf8e7a9f

0xbf8e5a50: 0xbf8e7ad2 0xbf8e7aea 0xbf8e7afa 0xbf8e7b05

0xbf8e5a60: 0xbf8e7b13 0xbf8e7b30 0xbf8e7b46 0xbf8e7b64

0xbf8e5a70: 0xbf8e7b77 0xbf8e7b81 0xbf8e7bb0 0xbf8e7d73

0xbf8e5a80: 0xbf8e7d90 0xbf8e7d9b 0xbf8e7e30 0xbf8e7e4a

0xbf8e5a90: 0xbf8e7e59 0xbf8e7e88 0xbf8e7e8e 0xbf8e7ea3

0xbf8e5aa0: 0xbf8e7eb4 0xbf8e7ec7 0xbf8e7ed9 0xbf8e7ee6

0xbf8e5ab0: 0xbf8e7eef 0xbf8e7f22 0xbf8e7f2d 0xbf8e7f35

0xbf8e5ac0: 0xbf8e7f5f 0xbf8e7f6c 0xbf8e7f78 0xbf8e7f92

0xbf8e5ad0: 0xbf8e7fbe 0xbf8e7fe0 0x00000000 0x00000020

0xbf8e5ae0: 0x00110400 0x00000021 0x00110000 0x00000010

0xbf8e5af0: 0xbfebf3ff 0x00000006 0x00001000 0x00000011

0xbf8e5b00: 0x00000064 0x00000003 0x08048034 0x00000004

0xbf8e5b10: 0x00000020 0x00000005 0x00000008 0x00000007

0xbf8e5b20: 0x00000000 0x00000008 0x00000000 0x00000009

0xbf8e5b30: 0x080482f0 0x0000000b 0x00000000 0x0000000c

0xbf8e5b40: 0x00000000 0x0000000d 0x00000000 0x0000000e

0xbf8e5b50: 0x00000000 0x00000017 0x00000000 0x0000000f

0xbf8e5b60: 0xbf8e5b7b 0x00000000 0x00000000 0x00000000

0xbf8e5b70: 0x00000000 0x00000000 0x69000000 0x00363836

0xbf8e5b80: 0x00000000 0x00000000 0x00000000 0x00000000

0xbf8e5b90: 0x00000000 0x00000000 0x00000000 0x00000000

0xbf8e5ba0: 0x00000000 0x00000000 0x00000000 0x00000000

0xbf8e5bb0: 0x00000000 0x00000000 0x00000000 0x00000000

0xbf8e5bc0: 0x00000000 0x00000000 0x00000000 0x00000000

0xbf8e5bd0: 0x00000000 0x00000000 0x00000000 0x00000000

0xbf8e5be0: 0x00000000 0x00000000 0x00000000 0x00000000

0xbf8e5bf0: 0x00000000 0x00000000 0x00000000 0x00000000

0xbf8e5c00: 0x00000000 0x00000000 0x00000000 0x00000000

0xbf8e5c10: 0x00000000 0x00000000 0x00000000 0x00000000

[1] [2] [3] [4] [5] [6] Next page

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.