Closed abmusse closed 4 years ago
I added some print statements to help diagnose the issue:
size_t backtrace(void** frames, size_t count)
{
size_t i;
int debug = 0;
// We ignore the current stack frame (this function)
void** sp = getsp()[0];
// Walk the stack up to count times or we hit the bottom
// of the stack (whichever is first)
for(i = 0; i < count && sp; ++i, sp = (void**) sp[0]) {
if(debug){
fprintf(stderr, "loop\n");
}
void *lr = sp[2];
frames[i] = lr;
// This might be a signal handler frame, which means the back chain is
// useless (missing/in the weeds), so look at what's in the frame. In
// this case, what would be the back chain is in one of the fields of
// the frame. We need to guess if this is a signal handler frame
// though; our heuristic is the address being lower than the base of
// text; the signal trampoline is around ~0x3680 under PASE, but AIX
// has it at a different address around ~0x4800. The value we use for
// the displacement is verified to be the proper offset by GDB, and we
// employ a similar heuristic.
// XXX: What about syscalls?
if (lr < (void*)TEXTORG) {
debug = 1;
sp = (void*)((uint64_t)sp + TRAMPOLINE_OFFSET);
}
if (debug) {
fprintf(stderr, "i: %d, count: %d, lr: %p, sp: %p\n", i, count, lr, sp);
}
}
if (debug) {
fprintf(stderr, "Backtrace\n");
}
return i;
When I ran mysql_install_db
gain I got the following output:
...
i: 9, count: 10, lr: 0, sp: 1929a98b8
Backtrace
i: 9, count: 10, lr: 0, sp: 1929a98b8
Backtrace
i: 6, count: 10, lr: 0, sp: 192a0c8b8
loop
/QOpenSys/pkgs/bin/mysql_install_db[2]: 8628789 Memory fault(coredump)
Each time if (lr < (void*)TEXTORG)
check was entered lr = 0
. Right before the memory fault error lr = 0
and we re-enter the loop and attempt to access invalid memory with void *lr = sp[2];
therefore causing the memory fault.
I was able to resolve this issue by ensuring lr !=0 before adding the offset to the stack pointer:
if (lr < (void*)TEXTORG && lr != 0) {
sp = (void*)((uint64_t)sp + TRAMPOLINE_OFFSET);
}
This time when I ran mysql_install_db
I did not run into the memory fault.
While running
mysql_install_db
I ran into the following error:/QOpenSys/pkgs/bin/mysql_install_db[2]: 8628721 Memory fault(coredump)
Examining the core file I found: