Nathan Fellman
Nathan Fellman

Reputation: 127428

Crash reporting in C for Linux

Following this question:
Good crash reporting library in c#

Is there any library like CrashRpt.dll that does the same on Linux? That is, generate a failure report including a core dump and any necessary environment and notify the developer about it?

Edit: This seems to be a duplicate of this question

Upvotes: 4

Views: 3349

Answers (7)

Martin Del Vecchio
Martin Del Vecchio

Reputation: 3818

Note: there are two interesting registers in an x86 seg-fault crash.

The first, EIP, specifies the code address at which the exception occurred. In RichQ's answer, he uses addr2line to show the source line that corresponds to the crash address. But EIP can be invalid; if you call a function pointer that is null, it can be 0x00000000, and if you corrupt your call stack, the return can pop any random value into EIP.

The second, CR2, specifies the data address which caused the segmentation fault. In RichQ's example, he is setting up i as a null pointer, then accessing it. In this case, CR2 would be 0x00000000. But if you change:

int j = *i

to:

int j = i[2];

Then you are trying to access address 0x00000008, and that's what would be found in CR2.

Upvotes: 0

Martin Del Vecchio
Martin Del Vecchio

Reputation: 3818

Nathan, I wasn't insisting that you were incorrect; I was just saying that in my (limited) experience with Linux, the segment base is always zero. Maybe that's a good question for me to ask...

Upvotes: 0

Nathan Fellman
Nathan Fellman

Reputation: 127428

@Martin

I do architectural validation for x86, so I'm very familiar with the architecture the processor provides, but very unfamiliar with how it's used. That's what I based my comment on. If CR2 can be counted on to give the correct answer, then I stand corrected.

Upvotes: 0

Martin Del Vecchio
Martin Del Vecchio

Reputation: 3818

Nathan, under what circumstances in a segment base non-zero? I've never seen that occur in my 5 years of Linux application development.

Thanks.

Upvotes: 0

T Percival
T Percival

Reputation: 8674

See Getting stack traces on Unix systems, automatically on Stack Overflow.

Upvotes: 3

Nathan Fellman
Nathan Fellman

Reputation: 127428

@Ionut
This handles generating the core dump, but it doesn't handle notifying the developer when other users had crashes.

Upvotes: 1

Ionut Anghelcovici
Ionut Anghelcovici

Reputation:

Compile your code with debug symbols, enter unlimit coredumpsize in your shell and you'll get a coredump in the same folder as the binary. Use gdb/ddd - open the program first and then open the core dump. You can check this out for additional info.

Upvotes: 2

Related Questions