GDB Debug Two Stack Overflow

Source: Internet
Author: User

A segment error often occurs in a Linux application that is caused by access to illegal memory, such as stack Overflow, array out-of-bounds access, and malloc/free memory. When a segment error occurs under Linux, a function call relationship is recorded in which a segment error occurs when a core dump file is generated.

ubuntu14.04 default occurs when a segment error does not produce a core dump file that requires additional configuration through the command

ulimit-c Check to see if the core dump file size is allowed. If you only need temporary use of the command Ulimit-c Unlimited temporarily open then a segment error occurs when the core file is generated in the current directory.

If you want the configuration to take effect and specify the core file generation path and some other information, you can use the following command


Add in the etc/sysctl.conf directory

Kernel.core_pattern=/var/coredump/%t-%e-%p-%c.core

Kernel.core_uses_pid=0

#sysctl-P



1. Stack Overflow

On Ubuntu, the default stack space size of 8192KB application stack exceeds this value, a segment error can be obtained by command ulimit-s to see the size of the stack that is set. ubuntu14.04 32-bit Execute the following procedure

#include <stdio.h> #include <unistd.h> #include <string.h>void call_fault (void) {char array[9 * 1024 * 1  024]; memset (array, 0, sizeof (array));}  void Call_test (void) {int A;  A = 1; Call_fault ();}  int main () {call_test (); return 0;}

[Email protected]:test_work#gcc-g-wall stack_out.c

[Email protected]:test_work#./a.out

Segmentation fault (core dumped)

The core file is generated in the current directory after execution

[Email protected]:test_work# gdb./a.out Core -----> Commissioning Start

GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1

Copyright (C) Free Software Foundation, Inc.

License gplv3+: GNU GPL version 3 or later

This was free software:you was free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law. Type "Show copying"

and "Show warranty" for details.

This GDB is configured as "I686-linux-gnu".

Type "Show Configuration" for configuration details.

For bugs reporting instructions, please see:

Find the GDB manual and other documentation resources online at:

For help, type ' help '.

Type "Apropos word" to search for commands related to "word" ...

Reading symbols from./a.out...done.


Warning:exec file is newer than core file.

[New LWP 12155]

Core is generated by './a.out '.

Program terminated with signal SIGSEGV, segmentation fault.

#0 0X080484BC in __libc_csu_init () ----> No valid information is given from the information above

(GDB) bt full

Python Exception <class ' gdb. Memoryerror ' > Cannot access memory at address 0XBF359D20:

#0 0X080484BC in __libc_csu_init ()

No symbol table info available.

Cannot access memory at address 0XBF359D20 ----> From here, the stack frame seems to be broken. The valid information given is that there is no access to the address 0XBF359D20 first to look at the program memory address mapping

(GDB)

(GDB) Info proc mappings ----> stack has been corrupted unable to get stack information

Mapped Address spaces:


Start Addr End Addr Size Offset objfile

0x8048000 0x8049000 0x1000 0x0/root/work/test_work/a.out

0x8049000 0x804a000 0x1000 0x0/root/work/test_work/a.out

0x804a000 0x804b000 0x1000 0x1000/root/work/test_work/a.out

0xb757d000 0xb7725000 0x1a8000 0x0/lib/i386-linux-gnu/libc-2.19.so

0xb7725000 0xb7727000 0x2000 0x1a8000/lib/i386-linux-gnu/libc-2.19.so

0xb7727000 0xb7728000 0x1000 0x1aa000/lib/i386-linux-gnu/libc-2.19.so

0xb7747000 0xb7767000 0x20000 0x0/lib/i386-linux-gnu/ld-2.19.so

0xb7767000 0xb7768000 0x1000 0x1f000/lib/i386-linux-gnu/ld-2.19.so

(GDB)

(GDB) I reg

EAX 0x8048610134514192

ECX 0x8048615134514197

edx 0x1420

EBX 0xb7727000-1217236992

ESP 0XBF359D100xbf359d10 -----> see where the stack pointer points

EBP 0xbfc59d380xbfc59d38

ESI 0x00

EDI 0x00

EIP 0X80484BC0X80484BC <__libc_csu_init+12>

EFlags 0x10246[PF ZF IF RF]

CS 0x73115

SS 0x7b123

DS 0x7b123

ES 0x7b123

FS 0x00

GS 0x3351


After exiting GdB, execute gdb./a.out

(GDB) Quit ----> Exit gdb

[Email protected]:test_work# gdb./a.out

GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1

Copyright (C) Free Software Foundation, Inc.

License gplv3+: GNU GPL version 3 or later

This was free software:you was free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law. Type "Show copying"

and "Show warranty" for details.

This GDB is configured as "I686-linux-gnu".

Type "Show Configuration" for configuration details.

For bugs reporting instructions, please see:

Find the GDB manual and other documentation resources online at:

For help, type ' help '.

Type "Apropos word" to search for commands related to "word" ...

Reading symbols from./a.out...done.

(GDB) ESP 0XBF359D100XBF359D10

Undefined command: "ESP". Try "Help".

(GDB) Start

Temporary breakpoint 1 at 0x80484a2:file stack_out.c, line 22.

Starting program:/root/work/test_work/a.out

Temporary breakpoint 1, Main () at stack_out.c:22

call_test ();

(GDB) Info proc Mappings

Process 12403

Mapped Address spaces:


Start Addr End Addr Size Offset objfile

0x8048000 0x8049000 0x1000 0x0/root/work/test_work/a.out

0x8049000 0x804a000 0x1000 0x0/root/work/test_work/a.out

0x804a000 0x804b000 0x1000 0x1000/root/work/test_work/a.out

0xb7e13000 0xb7e14000 0x1000 0x0

0xb7e14000 0xb7fbc000 0x1a8000 0x0/lib/i386-linux-gnu/libc-2.19.so

0xb7fbc000 0xb7fbe000 0x2000 0x1a8000/lib/i386-linux-gnu/libc-2.19.so

0xb7fbe000 0xb7fbf000 0x1000 0x1aa000/lib/i386-linux-gnu/libc-2.19.so

0xb7fbf000 0xb7fc2000 0x3000 0x0

0xb7fd8000 0xb7fda000 0x2000 0x0

0xb7fda000 0xb7fdc000 0x2000 0x0 [Vvar]

0xb7fdc000 0xb7fde000 0x2000 0x0 [VDSO]

0xb7fde000 0xb7ffe000 0x20000 0x0/lib/i386-linux-gnu/ld-2.19.so

0xb7ffe000 0xb7fff000 0x1000 0x1f000/lib/i386-linux-gnu/ld-2.19.so

0xb7fff000 0xb8000000 0x1000 0x20000/lib/i386-linux-gnu/ld-2.19.so

0xbffdf000 0xc0000000 0x21000 0x0 [stack] -----> can see the range of stacks

(GDB)

With the debug information above to know but a segment error occurred is that the SP pointer is pointing to the 0XBF359D10 that has exceeded the lower bounds of the stack.



This article is from the "12128867" blog, please be sure to keep this source http://12138867.blog.51cto.com/12128867/1914119

GDB Debug Two Stack Overflow

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.