Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Quickly locate the mistakes by gdb location     - Effect MongoDB plan cache (Database)

- Linux C source code (Ascii HexToBinary: Converts hexadecimal string format ASCII codes) (Programming)

- How to fix the Ubuntu Error script returned error exit status 1 (Linux)

- Source code is installed MySQL 5.6.28 (Database)

- MySQL service failed to start thinking of settlement under CentOS7 (Database)

- Hadoop safe hftp (Server)

- linux raid levels and concepts introduced (Linux)

- Let OS X support NTFS write file (Linux)

- Compile and install Ubuntu Linux 4.0.5 kernel, network and fix vmware kernel module compilation error (Linux)

- Nginx start, stop, smooth start, smooth upgrade (Server)

- Oracle Linux 6.4 installed Oracle 11gR2 + RAC + ASM (Database)

- Java development specifications summary (Programming)

- Oracle 12c of the auto-increment Identity Columns (Database)

- Nine artifact control disk partition under Linux (Linux)

- MySQL optimization tabs (Database)

- Security: set limits on password (Linux)

- MySQL use benchmarking tool sysbench (Database)

- Linux and Windows virtual machine shared folders ---- Linux install VMware tools (Linux)

- Oracle Database Restore (Database)

- Setting Derby as Linux / Windows running as a service from the start (Server)

 
         
  Quickly locate the mistakes by gdb location
     
  Add Date : 2018-11-21      
         
         
         
  Sometimes we have some C / C ++ code, due to an illegal memory operation, the program is running, the emergence of a "Segmentation fault (core dumped)" - mistakes.

Oh, I think this problem will often encounter a lot of people. Encounter this problem is very silent, and just a hint of the "mistakes" and then nothing, if we just look at the code to find the pain too bitter, because we believe that they write the code no problem, the reality is the reality . Then, we may be positioned by the print segment to the wrong location, so there will be a problem, if the large amount of code, we need to print a lot of information to find "mistakes" position (this approach is really stupid), but often sometimes the "mistakes" alone will not be able to print to find out. Next, to introduce through gdb quickly locate the "mistakes" position.

GDB is a debugging tool GNU open source released under a powerful UNIX. Perhaps you prefer the kind of graphical interface, such as VC, BCB and other IDE's debugger, but if you are doing software under the UNIX platform, you will find the GDB debugging tools than VC, BCB graphical debugger more powerful functions. The so-called "inch a director, has a short foot" is the truth.

First, make sure to install the gdb debugger, the terminal can "which gdb" Views:

Compile C / C ++ code, preceded by the -g parameter representative to the standard debugging information in the executable file.

Then, through the "./" to run an executable program, if there is "mistakes", under normal circumstances, it will generate a core file in the same directory the program (such as RedHat), but some environments but does not generate core files (such as ubuntu), to generate core files with your current system environment settings are related. When a program Ben collapse, copy the image of the storage process in the current process core files working directory. core file is just a memory image (plus debugging information at the same time), it is mainly used for debugging.

In redhat 6 (64-bit) Environmental Testing:

C ++ test code as follows:

#include
using namespace std;

void test ()
{
 int * i = NULL;
 * I = 250;
}

int main (int argc, char * argv [])
{
 test ();
 
 return 0;
}

1) Compile (plus -g), execution, production a core * file:

2) start gdb, use core. * Files quickly locate the "mistakes" position.

#gdb -q program name [corefile]. As in this example: gdb -q a.out core.6922, enter gdb interface where a "mistakes" position.

In ubuntu 14.04 (64-bit) Environmental Testing:

C test code as follows:

#include < stdio.h>
#include < string.h>

void test ()
{
 char * p = NULL;
 strcpy (p, "123");
}

int main (int argc, char * argv [])
{
 printf ( "111111111111 \ n");
 test ();
 printf ( "2222222222222 \ n");
 
 return 0;
}

1) Compile (plus -g), the implementation of the program, found the same directory does not produce core files:

2) to generate core files with your current system environment settings of a relationship, you can use the following statement to set it generate core file: ulimit -c unlimited. core file is generated in the general location of the program is the same path, file name in ubuntu under generally core.

3) to debug the core file with gdb: gdb a.out core

4) knock "where" character in gdb interface for more detailed information.
     
         
         
         
  More:      
 
- FastDFS installation and deployment (Server)
- Java concurrent programming combat (using synchronized synchronization method) (Programming)
- Oracle Database Delete Delete million or more common method of heap table data (Database)
- How to compile and install wxWidgets in Ubuntu / Debian / Linux Mint (Linux)
- On Android running ClojureScript (Linux)
- Linux - EXT2 file system is described in detail (Linux)
- DupeGuru- find and remove duplicate files (Linux)
- RedHat6.4 installation tutorial --- Minimal Edition (Linux)
- To compile and install MySQL 5.7.7 RC under CentOS 7.1 (Database)
- CentOS7 yum install third-party source EPEL (Linux)
- Installed FFmpeg 2.6.3 on Ubuntu / Debian / Fedora system (Linux)
- Linux performance monitoring and common commands Introduction (Linux)
- Netfilter / Iptables Comments (Linux)
- RHEL5 / 6 Installation Notes (Linux)
- How to make GRub instead of the default Ubuntu software center (Linux)
- SSH without password (Linux)
- Zabbix monitoring of the switch (Server)
- HttpClient4 usage upgrade from HttpClient3 (Programming)
- Using the Linux folder wc statistics number of lines of code for all files (including subdirectories) (Linux)
- CentOS7 installation configuration Redis-3.0.0 (Database)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.