<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" id="owaParaStyle">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">I am trying to use gcore to generate a user application core from a kernel dump file. I compiled the latest crash-7.1.6 and crash-gcore-command-1.3.1 from https://people.redhat.com/anderson/.
 I installed a debug kernel (vmlinux-4.1.34-33-debug.gz from openSUSE Leap 42.1) and did a controlled (sysrq-trigger) crash. When I attempt to use gcore on the process in question, after reading <https://people.redhat.com/anderson/extensions/gcore_help_gcore.html>,
 I get a segmentation fault:<br>
<br>
    eje-code:~ # crash /boot/vmlinux-4.1.34-33-debug.gz /var/crash/2016-10-31-17\:01//vmcore<br>
<br>
    crash 7.1.6<br>
    Copyright (C) 2002-2016  Red Hat, Inc.<br>
    Copyright (C) 2004, 2005, 2006, 2010  IBM Corporation<br>
    Copyright (C) 1999-2006  Hewlett-Packard Co<br>
    Copyright (C) 2005, 2006, 2011, 2012  Fujitsu Limited<br>
    Copyright (C) 2006, 2007  VA Linux Systems Japan K.K.<br>
    Copyright (C) 2005, 2011  NEC Corporation<br>
    Copyright (C) 1999, 2002, 2007  Silicon Graphics, Inc.<br>
    Copyright (C) 1999, 2000, 2001, 2002  Mission Critical Linux, Inc.<br>
    This program is free software, covered by the GNU General Public License,<br>
    and you are welcome to change it and/or distribute copies of it under<br>
    certain conditions.  Enter "help copying" to see the conditions.<br>
    This program has absolutely no warranty.  Enter "help warranty" for details.<br>
<br>
    GNU gdb (GDB) 7.6                                               <br>
    Copyright (C) 2013 Free Software Foundation, Inc.<br>
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html><br>
    This is free software: you are free to change and redistribute it.<br>
    There is NO WARRANTY, to the extent permitted by law.  Type "show copying"<br>
    and "show warranty" for details.<br>
    This GDB was configured as "x86_64-unknown-linux-gnu"...<br>
<br>
    KERNEL: /boot/vmlinux-4.1.34-33-debug.gz  <br>
    DUMPFILE: /var/crash/2016-10-31-17:01//vmcore<br>
    CPUS: 4<br>
    DATE: Mon Oct 31 13:01:36 2016<br>
    UPTIME: 02:12:08<br>
    LOAD AVERAGE: 0.00, 0.00, 0.00<br>
    TASKS: 204<br>
    NODENAME: eje-code<br>
    RELEASE: 4.1.34-33-debug<br>
    VERSION: #1 SMP Thu Oct 20 08:03:29 UTC 2016 (fe18aba)<br>
    MACHINE: x86_64  (2094 Mhz)<br>
    MEMORY: 4 GB<br>
    PANIC: "sysrq: SysRq : Trigger a crash"<br>
    PID: 3260<br>
    COMMAND: "crashtest"<br>
    TASK: ffff88011a020550  [THREAD_INFO: ffff8800bcd98000]<br>
    CPU: 3<br>
    STATE: TASK_RUNNING (SYSRQ)<br>
<br>
    crash> extend /usr/lib64/crash/extensions/gcore.so<br>
    /usr/lib64/crash/extensions/gcore.so: shared object loaded<br>
    crash> gcore -f 0 -v 7 3260                            <br>
    gcore: Opening file core.3260.crashtest ... <br>
    gcore: done.<br>
    gcore: Writing ELF header ... <br>
    gcore:  done.<br>
    gcore: Retrieving and writing note information ... <br>
    Segmentation fault<br>
<br>
Sixty-four bytes of core get written before the segmentation fault (I'm guessing that's the ELF header).  I can gcore some other processes (although I get many "gcore: WARNING: page fault at 7ffca6a5d000" errors).  I tried this both with an echo from bash from
 the command line and a custom test program that just does a controlled crash in a function nested four deep.  The segmentation fault sometimes causes a hang (which I can end with Ctrl-C).<br>
<br>
It does the same thing if I specify the task address (in this case, "gcore ffff88011a020550").  I've tried it without any options, too, and with different combinations.<br>
<br>
I obtained a core dump of gcore and this is my debugging session:<br>
<br>
eje-code:~ # gdb /usr/lib64/crash/extensions/gcore.so /var/core/core.eje-code-crash-3074<br>
GNU gdb (GDB; openSUSE Leap 42.1) 7.11.1<br>
Copyright (C) 2016 Free Software Foundation, Inc.<br>
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html><br>
This is free software: you are free to change and redistribute it.<br>
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"<br>
and "show warranty" for details.<br>
This GDB was configured as "x86_64-suse-linux".<br>
Type "show configuration" for configuration details.<br>
For bug reporting instructions, please see:<br>
<http://bugs.opensuse.org/>.<br>
Find the GDB manual and other documentation resources online at:<br>
<http://www.gnu.org/software/gdb/documentation/>.<br>
For help, type "help".<br>
Type "apropos word" to search for commands related to "word"...<br>
Reading symbols from /usr/lib64/crash/extensions/gcore.so...done.<br>
<br>
warning: core file may not match specified executable file. [Not sure why ...]<br>
[New LWP 3074]<br>
[Thread debugging using libthread_db enabled]<br>
Using host libthread_db library "/lib64/libthread_db.so.1".<br>
Core was generated by `crash /boot/vmlinux-4.1.34-33-debug.gz /var/crash/2016-10-31-17:01//vmcore'.<br>
Program terminated with signal SIGSEGV, Segmentation fault.<br>
#0  0x0000000000000000 in ?? ()<br>
Missing separate debuginfos, use: zypper install glibc-debuginfo-2.19-17.4.x86_64 liblzma5-debuginfo-5.0.5-3.5.x86_64 libncurses5-debuginfo-5.9-53.4.x86_64 libz1-debuginfo-1.2.8-6.4.x86_64<br>
(gdb) bt<br>
#0  0x0000000000000000 in ?? ()<br>
#1  0x00007f1235eed4e4 in restore_regs_syscall_context (target=0x6939df8, regs=0xf6f280, active_regs=0x7ffefa968880)<br>
    at libgcore/gcore_x86.c:1656<br>
#2  0x00007f1235eedcb6 in genregs_get (target=0x6939df8, regset=0x7f12360f6460 <x86_64_regsets>, size=216,
<br>
    buf=0xf6f280) at libgcore/gcore_x86.c:1795<br>
#3  0x00007f1235ee6438 in fill_write_thread_core_info (fp=0x59efb10, tc=0x6939df8, dump_tc=0x6939df8, info=0xf6ee80,
<br>
    view=0x7f12360f5d80 <x86_64_regset_view>, offset=0x7ffefa968ab0, total=0xf6ee98) at libgcore/gcore_coredump.c:469<br>
#4  0x00007f1235ee682c in fill_write_note_info (fp=0x59efb10, info=0xf6ee80, phnum=20, offset=0x7ffefa968ab0)<br>
    at libgcore/gcore_coredump.c:566<br>
#5  0x00007f1235ee4dd1 in gcore_coredump () at libgcore/gcore_coredump.c:112<br>
#6  0x00007f1235eeeb8b in do_gcore (arg=0x0) at gcore.c:317<br>
#7  0x00007f1235eee926 in cmd_gcore () at gcore.c:253<br>
#8  0x0000000000472b8c in ?? ()<br>
#9  0x0000000000000000 in ?? ()<br>
(gdb) bt<br>
#0  0x0000000000000000 in ?? ()<br>
#1  0x00007f1235eed4e4 in restore_regs_syscall_context (target=0x6939df8, regs=0xf6f280, active_regs=0x7ffefa968880)<br>
    at libgcore/gcore_x86.c:1656<br>
#2  0x00007f1235eedcb6 in genregs_get (target=0x6939df8, regset=0x7f12360f6460 <x86_64_regsets>, size=216,
<br>
    buf=0xf6f280) at libgcore/gcore_x86.c:1795<br>
#3  0x00007f1235ee6438 in fill_write_thread_core_info (fp=0x59efb10, tc=0x6939df8, dump_tc=0x6939df8, info=0xf6ee80,
<br>
    view=0x7f12360f5d80 <x86_64_regset_view>, offset=0x7ffefa968ab0, total=0xf6ee98) at libgcore/gcore_coredump.c:469<br>
#4  0x00007f1235ee682c in fill_write_note_info (fp=0x59efb10, info=0xf6ee80, phnum=20, offset=0x7ffefa968ab0)<br>
    at libgcore/gcore_coredump.c:566<br>
#5  0x00007f1235ee4dd1 in gcore_coredump () at libgcore/gcore_coredump.c:112<br>
#6  0x00007f1235eeeb8b in do_gcore (arg=0x0) at gcore.c:317<br>
#7  0x00007f1235eee926 in cmd_gcore () at gcore.c:253<br>
#8  0x0000000000472b8c in ?? ()<br>
#9  0x0000000000000000 in ?? ()<br>
(gdb) up<br>
#1  0x00007f1235eed4e4 in restore_regs_syscall_context (target=0x6939df8, regs=0xf6f280, active_regs=0x7ffefa968880)<br>
    at libgcore/gcore_x86.c:1656<br>
1656                    regs->sp = gxt->get_old_rsp(target->processor);<br>
(gdb) print gxt<br>
$1 = (struct gcore_x86_table *) 0x215ea0 <gcore_x86_table><br>
(gdb) print *target<br>
$2 = {task = 18446612137045525840, thread_info = 18446612135482589184, pid = 3260, comm = "crashtest\000@XI\215u H",
<br>
  processor = 3, ptask = 18446612137046565648, mm_struct = 18446612137048351232, tc_next = 0x0}<br>
(gdb) print *regs<br>
$3 = {r15 = 0, r14 = 2, r13 = 2, r12 = 34324496, bp = 2, bx = 4196186, r11 = 582, r10 = 140728806957456,
<br>
  r9 = 140048302249728, r8 = 34324720, ax = 18446744073709551578, cx = 140048297135408, dx = 2, si = 140048302292992,
<br>
  di = 3, orig_ax = 1, ip = 140048297135408, cs = 51, flags = 582, sp = 140728806957864, ss = 43, fs_base = 0,
<br>
  gs_base = 0, ds = 0, es = 0, fs = 0, gs = 0}<br>
(gdb) print *gxt<br>
$4 = {get_old_rsp = 0x0, get_thread_struct_fpu = 0x0, get_thread_struct_fpu_size = 0x0, is_special_syscall = 0x0,
<br>
  is_special_ia32_syscall = 0x0, tsk_used_math = 0x0}<br>
=============================<br>
<br>
So not only is get_old_rsp zero, all the fields in gxt are zero.<br>
<br>
Looks like a kernel support issue. This field is filled in by gcore_x86_table_register_get_old_rsp() which looks up four symbols in various forms, none of which exist in my kernel:<br>
<br>
eje-code:~ # fgrep old_rsp /proc/kallsyms<br>
eje-code:~ # fgrep cpu_pda /proc/kallsyms<br>
eje-code:~ #<br>
<br>
old_rsp did exist in openSUSE 12.1 and 13.1 (3.11.10-29 for the latter).<br>
<br>
According to http://lists.openwall.net/linux-kernel/2015/03/17/766 old_rsp was renamed rsp_scratch.  I don't know if the semantics changed -- it doesn't appear so -- but I added code to accept this symbol as an alternative and the core dump generates and works
 (I can see a correct backtrace).  I do not warrant the work though. :-)  Someone may want to review my work, and check the other functions and see if they are supposed to be zero.  Since they haven't been invoked I don't know if they are supposed to be non-zero
 or not.<br>
<br>
Here is the diff:<br>
<br>
--- gcore_x86.c~        2014-11-06 04:58:47.000000000 -0500<br>
+++ gcore_x86.c 2016-10-31 16:01:00.989025841 -0400<br>
@@ -1351,6 +1351,26 @@ static ulong gcore_x86_64_get_old_rsp(in<br>
 }<br>
 <br>
 /**<br>
+ * gcore_x86_64_get_rsp_scratch() - get rsp at per-cpu area<br>
+ *<br>
+ * @cpu target CPU's CPU id<br>
+ *<br>
+ * Given a CPU id, returns a RSP value saved at per-cpu area for the<br>
+ * CPU whose id is the given CPU id.<br>
+ */<br>
+static ulong gcore_x86_64_get_rsp_scratch(int cpu)<br>
+{<br>
+       ulong old_rsp;<br>
+<br>
+       readmem(symbol_value("rsp_scratch") + kt->__per_cpu_offset[cpu],<br>
+               KVADDR, &old_rsp, sizeof(old_rsp),<br>
+               "gcore_x86_64_get_rsp_scratch: rsp_scratch",<br>
+               gcore_verbose_error_handle());<br>
+<br>
+       return old_rsp;<br>
+}<br>
+<br>
+/**<br>
  * gcore_x86_64_get_per_cpu__old_rsp() - get rsp at per-cpu area<br>
  *<br>
  * @cpu target CPU's CPU id<br>
@@ -1834,6 +1854,11 @@ static void gcore_x86_table_register_get<br>
 <br>
        else if (symbol_exists("_cpu_pda"))<br>
                gxt->get_old_rsp = gcore_x86_64_get_cpu__pda_oldrsp;<br>
+<br>
+       else if (symbol_exists("rsp_scratch"))<br>
+               gxt->get_old_rsp = gcore_x86_64_get_rsp_scratch;<br>
+<br>
+       if (!gxt->get_old_rsp) printf ("Warning: NO gxt->get_old_rsp\n");<br>
 }<br>
 #endif<br>
 <br>
<br>
</div>
</body>
</html>