mirror of
https://git.suyu.dev/suyu/breakpad.git
synced 2026-01-01 04:04:32 +01:00
core_handler: coredump handler to produce minidump
On Linux, it is possible to register a core handler via /proc/sys/kernel/core_pattern. Doing so invokes the core handler when a process crash. The core_handler uses /proc/<pid>/mem to access the process memory. This way it is not necessary to process the full coredump which takes time and consumes memory. In order to profit from this core handler, for example, one can integrate dump_syms into Yocto and generate an archive with the breakpad symbols of all the binaries in the rootfs. Minidumps are especially useful on embedded systems since they are lightweight and provide contextual information. Change-Id: I9298d81159029cefb81c915831db54884310ad05 Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/2536917 Reviewed-by: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
parent
e3d485f73f
commit
bd4a28c08b
7 changed files with 361 additions and 41 deletions
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace google_breakpad {
|
||||
|
||||
|
|
@ -95,16 +96,29 @@ size_t ElfCoreDump::Note::AlignedSize(size_t size) {
|
|||
|
||||
// Implementation of ElfCoreDump.
|
||||
|
||||
ElfCoreDump::ElfCoreDump() {}
|
||||
ElfCoreDump::ElfCoreDump() : proc_mem_fd_(-1) {}
|
||||
|
||||
ElfCoreDump::ElfCoreDump(const MemoryRange& content)
|
||||
: content_(content) {
|
||||
: content_(content), proc_mem_fd_(-1) {}
|
||||
|
||||
ElfCoreDump::~ElfCoreDump() {
|
||||
if (proc_mem_fd_ != -1) {
|
||||
close(proc_mem_fd_);
|
||||
proc_mem_fd_ = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void ElfCoreDump::SetContent(const MemoryRange& content) {
|
||||
content_ = content;
|
||||
}
|
||||
|
||||
void ElfCoreDump::SetProcMem(int fd) {
|
||||
if (proc_mem_fd_ != -1) {
|
||||
close(proc_mem_fd_);
|
||||
}
|
||||
proc_mem_fd_ = fd;
|
||||
}
|
||||
|
||||
bool ElfCoreDump::IsValid() const {
|
||||
const Ehdr* header = GetHeader();
|
||||
return (header &&
|
||||
|
|
@ -163,6 +177,16 @@ bool ElfCoreDump::CopyData(void* buffer, Addr virtual_address, size_t length) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* fallback: if available, read from /proc/<pid>/mem */
|
||||
if (proc_mem_fd_ != -1) {
|
||||
off_t offset = virtual_address;
|
||||
ssize_t r = pread(proc_mem_fd_, buffer, length, offset);
|
||||
if (r < ssize_t(length)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -106,6 +106,8 @@ class ElfCoreDump {
|
|||
// Constructor that takes the core dump content from |content|.
|
||||
explicit ElfCoreDump(const MemoryRange& content);
|
||||
|
||||
~ElfCoreDump();
|
||||
|
||||
// Sets the core dump content to |content|.
|
||||
void SetContent(const MemoryRange& content);
|
||||
|
||||
|
|
@ -139,9 +141,15 @@ class ElfCoreDump {
|
|||
// an empty note if no note is found.
|
||||
Note GetFirstNote() const;
|
||||
|
||||
// Sets the mem fd.
|
||||
void SetProcMem(const int fd);
|
||||
|
||||
private:
|
||||
// Core dump content.
|
||||
MemoryRange content_;
|
||||
|
||||
// Descriptor for /proc/<pid>/mem.
|
||||
int proc_mem_fd_;
|
||||
};
|
||||
|
||||
} // namespace google_breakpad
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue