coredump: add %T in core_pattern to report the tid
Subsystems (2)
PATCH 1/1 coredump: add %T in core_pattern to report the tid
format_corename() can only pass the leader's pid to the core handler, but there is no simple way to figure out which thread originated the coredump.
As Jan explains, this also means that there is no simple way to create the backtrace of the crashed process:
As programs are mostly compiled with implicit gcc -fomit-frame-pointer one needs program's .eh_frame section (equivalently PT_GNU_EH_FRAME segment) or .debug_frame section. .debug_frame usually is present only in separate debug info files usually not even installed on the system. While .eh_frame is a part of the executable/library (and it is even always mapped for C++ exceptions unwinding) it no longer has to be present anywhere on the disk as the program could be upgraded in the meantime and the running instance has its executable file already unlinked from disk.
One possibility is to echo 0x3f >/proc/*/coredump_filter and dump all the file-backed memory including the executable's .eh_frame section. But that can create huge core files, for example even due to mmapped data files.
Other possibility would be to read .eh_frame from /proc/PID/mem at the core_pattern handler time of the core dump. For the backtrace one needs to read the register state first which can be done from core_pattern handler:
ptrace(PTRACE_SEIZE, tid, 0, PTRACE_O_TRACEEXIT)
close(0); // close pipe fd to resume the sleeping dumper
waitpid(); // should report EXIT
PTRACE_GETREGS or other requests
The remaining problem is how to get the 'tid' value of the crashed thread. It could be read from the first NT_PRSTATUS note of the core file but that makes the core_pattern handler complicated.
--- Documentation/sysctl/kernel.txt | 1 + fs/coredump.c | 4 ++++ 2 files changed, 5 insertions(+), 0 deletions(-)
Documentation/sysctl/kernel.txt +1 -0
@@ -189,6 +189,7 @@ core_pattern is used to specify a core dumpfile pattern name. %<NUL> '%' is dropped %% output one '%' %p pid + %T tid %P global pid (init PID namespace) %u uid %g gid
fs/coredump.c +4 -0
@@ -194,6 +194,10 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm) err =cn_printf (cn,"%d" ,task_tgid_vnr (current));break ; +case 'T' : + err =cn_printf (cn,"%d" , +task_pid_vnr (current)); +break ;/* global pid */ case 'P' : err = cn_printf(cn, "%d",
Signature · 1 line
1.5.5.1
Self-nack after discussion on debug-list, I'll send v2.
If we teach format_corename() to report task_pid_vnr() we should also allow to report the global tid from the root namespace, at least to make this consistent with %p/%P.
This means that %T was a bad choice, Martin suggests %i/%I.
Quoted 70 lines · Oleg Nesterov
format_corename()can only pass the leader's pid to the core handler, but there is no simple way to figure out which thread originated the coredump.As Jan explains, this also means that there is no simple way to create the backtrace of the crashed process:
As programs are mostly compiled with implicit gcc -fomit-frame-pointer one needs program's .eh_frame section (equivalently
PT_GNU_EH_FRAMEsegment) or .debug_frame section. .debug_frame usually is present only in separate debug info files usually not even installed on the system. While .eh_frame is a part of the executable/library (and it is even always mapped for C++ exceptions unwinding) it no longer has to be present anywhere on the disk as the program could be upgraded in the meantime and the running instance has its executable file already unlinked from disk.One possibility is to echo
0x3f>/proc/*/coredump_filter and dump all the file-backed memory including the executable's .eh_frame section. But that can create huge core files, for example even due to mmapped data files.Other possibility would be to read .eh_frame from
/proc/PID/memat thecore_patternhandler time of the core dump. For the backtrace one needs to read the register state first which can be done fromcore_patternhandler:
ptrace(PTRACE_SEIZE, tid, 0, PTRACE_O_TRACEEXIT)
close(0); // close pipe fd to resume the sleeping dumper
waitpid(); // should report EXIT
PTRACE_GETREGSor other requestsThe remaining problem is how to get the 'tid' value of the crashed thread. It could be read from the first
NT_PRSTATUSnote of the core file but that makes thecore_patternhandler complicated.Signed-off-by Jan Kratochvil <[email protected]>Signed-off-by Oleg Nesterov <[email protected]>--- Documentation/sysctl/kernel.txt | 1 + fs/coredump.c | 4 ++++ 2 files changed, 5 insertions(+), 0 deletions(-)Documentation/sysctl/kernel.txt +1
-0@@ -189,6 +189,7 @@ core_pattern is used to specify a core dumpfile pattern name. %<NUL> '%' is dropped %% output one '%' %p pid + %T tid %P global pid (init PID namespace) %u uid %g gidfs/coredump.c +4
-1@@ -194,6 +194,10 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm) err =cn_printf (cn,"%d" ,task_tgid_vnr (current));break ; +case 'T' : + err =cn_printf (cn,"%d" , +task_pid_vnr (current)); +break ;/* global pid */ case 'P' : err = cn_printf(cn, "%d", --1.5.5.1
PATCH v2 1/1 coredump: add %i/%I in core_pattern to report the tid of the crashed thread
In reply to Oleg Nesterovformat_corename() can only pass the leader's pid to the core handler, but there is no simple way to figure out which thread originated the coredump.
As Jan explains, this also means that there is no simple way to create the backtrace of the crashed process:
As programs are mostly compiled with implicit gcc -fomit-frame-pointer one needs program's .eh_frame section (equivalently PT_GNU_EH_FRAME segment) or .debug_frame section. .debug_frame usually is present only in separate debug info files usually not even installed on the system. While .eh_frame is a part of the executable/library (and it is even always mapped for C++ exceptions unwinding) it no longer has to be present anywhere on the disk as the program could be upgraded in the meantime and the running instance has its executable file already unlinked from disk.
One possibility is to echo 0x3f >/proc/*/coredump_filter and dump all the file-backed memory including the executable's .eh_frame section. But that can create huge core files, for example even due to mmapped data files.
Other possibility would be to read .eh_frame from /proc/PID/mem at the core_pattern handler time of the core dump. For the backtrace one needs to read the register state first which can be done from core_pattern handler:
ptrace(PTRACE_SEIZE, tid, 0, PTRACE_O_TRACEEXIT)
close(0); // close pipe fd to resume the sleeping dumper
waitpid(); // should report EXIT
PTRACE_GETREGS or other requests
The remaining problem is how to get the 'tid' value of the crashed thread. It could be read from the first NT_PRSTATUS note of the core file but that makes the core_pattern handler complicated.
Unfortunately %t is already used so this patch uses %i/%I.
--- Documentation/sysctl/kernel.txt | 2 ++ fs/coredump.c | 8 ++++++++ 2 files changed, 10 insertions(+), 0 deletions(-)
Documentation/sysctl/kernel.txt +2 -0
@@ -190,6 +190,8 @@ core_pattern is used to specify a core dumpfile pattern name. %% output one '%' %p pid %P global pid (init PID namespace) + %i tid + %I global tid (init PID namespace) %u uid %g gid %d dump mode, matches PR_SET_DUMPABLE and
fs/coredump.c +8 -0
@@ -199,6 +199,14 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm) err =cn_printf (cn,"%d" ,task_tgid_nr (current));break ; +case 'i' : + err =cn_printf (cn,"%d" , +task_pid_vnr (current)); +break ; +case 'I' : + err =cn_printf (cn,"%d" , +task_pid_nr (current)); +break ;/* uid */ case 'u' : err =cn_printf (cn,"%d" , cred->uid);
Signature · 1 line
1.5.5.1
Re: [PATCH v2] coredump: add %i/%I in core_pattern to report the tid of the crashed thread
Quoted 28 lines · On Mon, 22 Sep 2014 19:15:25 +0200 Oleg Nesterov <[email protected]> wrote:
format_corename()can only pass the leader's pid to the core handler, but there is no simple way to figure out which thread originated the coredump.As Jan explains, this also means that there is no simple way to create the backtrace of the crashed process:
As programs are mostly compiled with implicit gcc -fomit-frame-pointer one needs program's .eh_frame section (equivalently
PT_GNU_EH_FRAMEsegment) or .debug_frame section. .debug_frame usually is present only in separate debug info files usually not even installed on the system. While .eh_frame is a part of the executable/library (and it is even always mapped for C++ exceptions unwinding) it no longer has to be present anywhere on the disk as the program could be upgraded in the meantime and the running instance has its executable file already unlinked from disk.One possibility is to echo
0x3f>/proc/*/coredump_filter and dump all the file-backed memory including the executable's .eh_frame section. But that can create huge core files, for example even due to mmapped data files.Other possibility would be to read .eh_frame from
/proc/PID/memat thecore_patternhandler time of the core dump. For the backtrace one needs to read the register state first which can be done fromcore_patternhandler:
ptrace(PTRACE_SEIZE, tid, 0, PTRACE_O_TRACEEXIT)
close(0); // close pipe fd to resume the sleeping dumper
waitpid(); // should report EXIT
PTRACE_GETREGSor other requests
Quoted 5 lines
The remaining problem is how to get the 'tid' value of the crashed thread. It could be read from the first
NT_PRSTATUSnote of the core file but that makes thecore_patternhandler complicated.Unfortunately %t is already used so this patch uses %i/%I.
Is any userspace actually going to use this? If so, details?
Am wondering what is driving this change...
Re: [PATCH v2] coredump: add %i/%I in core_pattern to report the tid of the crashed thread
Quoted 34 lines · Andrew Morton
Quoted 32 lines · On Mon, 22 Sep 2014 19:15:25 +0200 Oleg Nesterov <[email protected]> wrote:
format_corename()can only pass the leader's pid to the core handler, but there is no simple way to figure out which thread originated the coredump.As Jan explains, this also means that there is no simple way to create the backtrace of the crashed process:
As programs are mostly compiled with implicit gcc -fomit-frame-pointer one needs program's .eh_frame section (equivalently
PT_GNU_EH_FRAMEsegment) or .debug_frame section. .debug_frame usually is present only in separate debug info files usually not even installed on the system. While .eh_frame is a part of the executable/library (and it is even always mapped for C++ exceptions unwinding) it no longer has to be present anywhere on the disk as the program could be upgraded in the meantime and the running instance has its executable file already unlinked from disk.One possibility is to echo
0x3f>/proc/*/coredump_filter and dump all the file-backed memory including the executable's .eh_frame section. But that can create huge core files, for example even due to mmapped data files.Other possibility would be to read .eh_frame from
/proc/PID/memat thecore_patternhandler time of the core dump. For the backtrace one needs to read the register state first which can be done fromcore_patternhandler:
ptrace(PTRACE_SEIZE, tid, 0, PTRACE_O_TRACEEXIT)
close(0); // close pipe fd to resume the sleeping dumper
waitpid(); // should report EXIT
PTRACE_GETREGSor other requestsThe remaining problem is how to get the 'tid' value of the crashed thread. It could be read from the first
NT_PRSTATUSnote of the core file but that makes thecore_patternhandler complicated.
Quoted 5 lines
Quoted 1 line
Unfortunately %t is already used so this patch uses %i/%I.
Is any userspace actually going to use this? If so, details?
Am wondering what is driving this change...
Automatic Bug Reporting Tool [1] is experimenting with this. It is using elfutils [2] unwinder for generating the backtraces. Apart from not needing matching executables as mentioned above, another advantage is that we can get the backtrace without saving the core (which might be quite large) to disk.
[1] https://github.com/abrt/abrt/wiki/overview
[2] https://fedorahosted.org/elfutils/