Copyright © tutorialspoint.com
Let us write another program which will cause a core dump due to non initialized memory.
To enable debugging, the program must be compiled with the -g option.
NOTE: We are using g++ compiler because we have used C++ source code. Now, when run this program on your linux machine, it produces the result:
Now lets debug it using gdb:
Unfortunately, the program did not crash in either of the user-defined functions main or setint, so there is no useful trace or local variable information. In this case, it may be more useful to single-step through the program.
The value of *ip is the value of the integer pointed to by ip. In this case it is an unusual value and is strong evidence that there is a problem. The problem in this case is that the pointer was never properly initialized, so it is pointing to some random area in memory (the address 0x40014e0). By pure luck, the process of assiging a value to *ip does not crash the program, but it creates some problem that crashes the program when it finishes. |
Copyright © tutorialspoint.com