[minicoredumper] gdb corrupt stack
John Ogness
john.ogness at linutronix.de
Wed Jul 5 15:37:47 CEST 2017
Hi Marco,
On 2017-07-05, Marco.Felsch at preh.de <Marco.Felsch at preh.de> wrote:
> On 03.07.2017 17:06, Marco.Felsch at preh.de wrote:
>> I had cross compiled the minicoredumper for the aarch64.
>> Generating the core file works fine but analyze the the core file
>> with gdb on a remote host isn't possible.
>
> After some debugging I found the problem. Since linux-v4.9 it is not
> possible to get the stack from the /proc/stat file system since commit
> 0a1eb2d47 [0].
>
> So the below code should be changed to use ptrace:
>
> /* find 29th item: man proc(5) */
> p = buf;
> for (i = 0; i < 28; i++) {
> p = strchr(p, ' ');
> if (!p)
> goto out_err;
> p++;
> }
>
> /* read stack pointer */
> if (sscanf(p, "%lu ", addr) != 1)
> goto out_err;
Thank you for pointing this out. The reason why I implemented the use of
/proc/stat instead of ptrace(2) is because it offered a simple
cross-platform interface to the stack pointer. The kernel has the
convenient KSTK_ESP macro that isn't available to userspace.
I expect we'll have to include our own KSTK_ESP macro to read the
correct register for each platform. :-/
John Ogness
> [0] https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/commit/fs/proc/array.c?h=linux-4.9.y&id=0a1eb2d474edfe75466be6b4677ad84e5e8ca3f5
More information about the minicoredumper
mailing list