coredump

memset is not working with pointer to character

烂漫一生 提交于 2019-12-02 13:10:48
What is wrong with the following code? memset is supposed to work with Pointer to the block of memory to fill. But this code displays problem in console saying segmentation fault(core dumped) #include<iostream> #include <cstring> using namespace std; int main(int argc, char** argv) { char* name = "SAMPLE TEXT"; memset(name , '*', 6); cout << name << endl; return 0; } You have tripped over a very old backward-compatibility wart in C++, inherited from C and dating to the days when there was no such thing as const . String literals have type const char [n] , but, unless you tell your compiler you

memory corruption

风格不统一 提交于 2019-12-02 04:00:48
问题 i was running a small c program: #include<stdio.h> int main() { char *p; p = (char *)malloc(10); free(p); free(p); free(p); printf("\npointer is freed!!\n"); } basically i am freeing the memory which has already been freed. i think should result in a core dump!!is it not so? but it is printing the pointer is freed!! am i wrong some where? 回答1: As per the man page, "if free(ptr) has already been called before, undefined behavior occurs." It doesn't need to blow up; "not doing anything" is

memory corruption

爱⌒轻易说出口 提交于 2019-12-02 02:24:54
i was running a small c program: #include<stdio.h> int main() { char *p; p = (char *)malloc(10); free(p); free(p); free(p); printf("\npointer is freed!!\n"); } basically i am freeing the memory which has already been freed. i think should result in a core dump!!is it not so? but it is printing the pointer is freed!! am i wrong some where? As per the man page, "if free(ptr) has already been called before, undefined behavior occurs." It doesn't need to blow up; "not doing anything" is perfectly acceptable undefined behaviour. Also are nasal demons. Don't rely on it. There are multiple issues

GDB C++ - Inspecting STL Containers when looking at a core dump?

99封情书 提交于 2019-12-01 21:38:06
问题 I'm debugging a core dump of my program (post-mortem) inside gdb. I opened it with: gdb [program_name] [core_name] However when I attempt to inspect a STL vector, e.g. print vec->size() or print vec->at(0) I get the error "You can't do that without a process to debug" I'm just trying to inspect the contents and sizes of these containers. Is there any way to attach a dummy process to a core-dump gdb inspection so I can do this? 回答1: print the vector: (gdb) print *vec Then familiarize yourself

Segmentation fault (core dumped) in a simple C code

别来无恙 提交于 2019-12-01 20:20:25
I am new in C. I am referring to the book "The C Programming Language" by Brian W Kernighian and Dennis Ritchie. There is a code for pointer increment and assignment given in the book as follows. #include<stdio.h> int main() { char *s = "Goal"; char *t = "Home"; while(*s++ = *t++) printf(*s); return 0; } The code is saved and compiled using the command gcc ptr.c -o ptr -std=c99 Now on running the code by running command ./ptr I get the following error Segmentation fault (core dumped) The error seems to be inside the while loop condition. But the code is exactly as given in the book. What am I

GDB C++ - Inspecting STL Containers when looking at a core dump?

让人想犯罪 __ 提交于 2019-12-01 18:42:26
I'm debugging a core dump of my program (post-mortem) inside gdb. I opened it with: gdb [program_name] [core_name] However when I attempt to inspect a STL vector, e.g. print vec->size() or print vec->at(0) I get the error "You can't do that without a process to debug" I'm just trying to inspect the contents and sizes of these containers. Is there any way to attach a dummy process to a core-dump gdb inspection so I can do this? print the vector: (gdb) print *vec Then familiarize yourself with the internals of your implementation's vector and print the raw buffer. Often called "_M_buffer" or

How to limit the size of core dump file when generating it using GDB

老子叫甜甜 提交于 2019-12-01 16:42:59
I am running an embedded application on ARM9 board, where total flash size is 180MB only. I am able to run gdb , but when I do (gdb) generate-core-dump I get an error warning: Memory read failed for corefile section, 1048576 bytes at 0x4156c000. warning: Memory read failed for corefile section, 1048576 bytes at 0x50c00000. Saved corefile core.5546 The program is running. Quit anyway (and detach it)? (y or n) [answered Y; input not from terminal] Tamper Detected **********OUTSIDE ifelse 0********* length validation is failed I also set ulimit -c 50000 but still the core dump exceeds this limit.

Linux: handling a segmentation fault and getting a core dump

一世执手 提交于 2019-12-01 03:44:06
When my application crashes with a segmentation fault I'd like to get a core dump from the system. I do that by configuring before hand ulimit -c unlimited I would also like to have an indication in my application logs that a segmentation fault has occured. I do that by using sigaction() . If I do that however, the signal does not reach its default handling and a core dump is not saved. How can I have both the system core dump an a log line from my own signal handler at the same time? Overwrite the default signal handler for SIGSEGV to call your custom logging function. After it is logged,

Segmentation fault due to recursion

我与影子孤独终老i 提交于 2019-12-01 01:22:23
I'm writing a program that is to take a number between 1-10 and display all possible ways of arranging the numbers. Ex input: 3 output: 1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1 Whenever I input 9 or 10, the program gives a segmentation fault and dumps the core. I believe the issue is my recursive algorithm is being called too many times. Could someone help point out how I could limit the amount of recursive calls necessary? Here is my current code: void rearange(int numbers[11], int index, int num, int fact) { int temp = numbers[index]; numbers[index] = numbers[index-1]; numbers[index-1] = temp;

Linux: handling a segmentation fault and getting a core dump

眉间皱痕 提交于 2019-12-01 00:03:25
问题 When my application crashes with a segmentation fault I'd like to get a core dump from the system. I do that by configuring before hand ulimit -c unlimited I would also like to have an indication in my application logs that a segmentation fault has occured. I do that by using sigaction(). If I do that however, the signal does not reach its default handling and a core dump is not saved. How can I have both the system core dump an a log line from my own signal handler at the same time? 回答1: