kernel: Add core dump facility

* Add function core_dump_write_core_file(). It writes a core file for
  the current thread's team. The file format is similar to that of
  other OSs (i.e. ELF with PT_LOAD segments and a PT_NOTE segment), but
  most of the notes are Haiku specific (infos for team, areas, images,
  threads). More data will probably need to be added.
* Add team flag TEAM_FLAG_DUMP_CORE, thread flag
  THREAD_FLAGS_TRAP_FOR_CORE_DUMP, and Team property coreDumpCondition,
  a condition variable available while a core dump is progress. A
  thread that finds its flag THREAD_FLAGS_TRAP_FOR_CORE_DUMP set before
  exiting the kernel to userland calls core_dump_trap_thread(), which
  blocks on the condition variable until the core dump has finished. We
  need the team's threads to stop so we can get their CPU state (and
  have a generally unchanging team state while writing the core file).
* Add user debugger message B_DEBUG_WRITE_CORE_FILE. It causes
  core_dump_write_core_file() to be called for the team.
* Dumping core as an immediate effect of a terminal signal has not been
  implemented yet, but that should be fairly straight forward.
This commit is contained in:
Ingo Weinhold
2016-04-24 18:22:14 +02:00
parent ac1f1a926e
commit 467fe4ca0c
13 changed files with 1698 additions and 29 deletions
+19 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2005, Ingo Weinhold, [email protected].
* Copyright 2005-2016 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _DEBUGGER_H
@@ -163,7 +163,9 @@ typedef enum {
// install_team_debugger()
B_DEBUG_START_PROFILER, // start/stop sampling
B_DEBUG_STOP_PROFILER //
B_DEBUG_STOP_PROFILER, //
B_DEBUG_WRITE_CORE_FILE // write a core file
} debug_nub_message;
// messages sent to the debugger
@@ -412,6 +414,20 @@ typedef struct {
thread_id thread; // thread to profile
} debug_nub_stop_profiler;
// B_DEBUG_WRITE_CORE_FILE
typedef struct {
port_id reply_port; // port to send the reply to
char path[B_PATH_NAME_LENGTH];
// path of the core file; must not exist
// yet; must be absolute
} debug_nub_write_core_file;
typedef struct {
status_t error; // B_OK on success
} debug_nub_write_core_file_reply;
// reply is debug_profiler_update
// union of all messages structures sent to the debug nub thread
@@ -433,6 +449,7 @@ typedef union {
debug_nub_get_signal_handler get_signal_handler;
debug_nub_start_profiler start_profiler;
debug_nub_stop_profiler stop_profiler;
debug_nub_write_core_file write_core_file;
} debug_nub_message_data;
+123 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 Haiku, Inc. All rights reserved.
* Copyright 2002-2016 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _ELF_H
@@ -153,6 +153,9 @@ typedef struct {
#define ELFDATA2LSB 1 /* little endian */
#define ELFDATA2MSB 2 /* big endian */
/* ELF version (EI_VERSION) */
#define EV_NONE 0 /* invalid */
#define EV_CURRENT 1 /* current version */
/*** section header ***/
@@ -578,6 +581,125 @@ typedef struct {
#define VER_FLG_WEAK 0x2 /* weak version identifier */
/*** core files ***/
/* note section header */
typedef struct {
Elf32_Word n_namesz; /* length of the note's name */
Elf32_Word n_descsz; /* length of the note's descriptor */
Elf32_Word n_type; /* note type */
} Elf32_Nhdr;
typedef struct {
Elf64_Word n_namesz; /* length of the note's name */
Elf64_Word n_descsz; /* length of the note's descriptor */
Elf64_Word n_type; /* note type */
} Elf64_Nhdr;
/* values for note name */
#define ELF_NOTE_CORE "CORE"
#define ELF_NOTE_HAIKU "Haiku"
/* values for note type (n_type) */
/* ELF_NOTE_CORE/... */
#define NT_FILE 0x46494c45 /* mapped files */
/* ELF_NOTE_HAIKU/... */
#define NT_TEAM 0x7465616d /* team */
#define NT_AREAS 0x61726561 /* areas */
#define NT_IMAGES 0x696d6167 /* images */
#define NT_THREADS 0x74687264 /* threads */
/* NT_TEAM: Elf32_Note_Team; char[] args */
typedef struct {
int32 nt_id; /* team ID */
int32 nt_uid; /* team owner ID */
int32 nt_gid; /* team group ID */
} Elf32_Note_Team;
typedef Elf32_Note_Team Elf64_Note_Team;
/* NT_AREAS: uint32 count; Elf32_Note_Area_Entry[count]; char[] names */
typedef struct {
int32 na_id; /* area ID */
uint32 na_lock; /* lock type (B_NO_LOCK, ...) */
uint32 na_protection; /* protection (B_READ_AREA | ...) */
uint32 na_base; /* area base address */
uint32 na_size; /* area size */
uint32 na_ram_size; /* physical memory used */
} Elf32_Note_Area_Entry;
/* NT_AREAS: uint64 count; Elf64_Note_Area_Entry[count]; char[] names */
typedef struct {
int32 na_id; /* area ID */
uint32 na_lock; /* lock type (B_NO_LOCK, ...) */
uint32 na_protection; /* protection (B_READ_AREA | ...) */
uint32 na_pad1;
uint64 na_base; /* area base address */
uint64 na_size; /* area size */
uint64 na_ram_size; /* physical memory used */
} Elf64_Note_Area_Entry;
/* NT_IMAGES: uint32 count; Elf32_Note_Image_Entry[count]; char[] names */
typedef struct {
int32 ni_id; /* image ID */
int32 ni_type; /* image type (B_APP_IMAGE, ...) */
uint32 ni_init_routine; /* address of init function */
uint32 ni_term_routine; /* address of termination function */
int32 ni_device; /* device ID of mapped file */
int64 ni_node; /* node ID of mapped file */
uint32 ni_text_base; /* base address of text segment */
uint32 ni_text_size; /* size of text segment */
uint32 ni_data_base; /* base address of data segment */
uint32 ni_data_size; /* size of data segment */
} Elf32_Note_Image_Entry;
/* NT_IMAGES: uint64 count; Elf64_Note_Image_Entry[count]; char[] names */
typedef struct {
int32 ni_id; /* image ID */
int32 ni_type; /* image type (B_APP_IMAGE, ...) */
uint64 ni_init_routine; /* address of init function */
uint64 ni_term_routine; /* address of termination function */
uint32 ni_pad1;
int32 ni_device; /* device ID of mapped file */
int64 ni_node; /* node ID of mapped file */
uint64 ni_text_base; /* base address of text segment */
uint64 ni_text_size; /* size of text segment */
uint64 ni_data_base; /* base address of data segment */
uint64 ni_data_size; /* size of data segment */
} Elf64_Note_Image_Entry;
/* NT_THREADS:
* uint32 count;
* uint32 cpuStateSize;
* {Elf32_Note_Thread_Entry, uint8[cpuStateSize] cpuState}[count];
* char[] names
*/
typedef struct {
int32 nth_id; /* thread ID */
int32 nth_state; /* thread state (B_THREAD_RUNNING, ...) */
int32 nth_priority; /* thread priority */
uint32 nth_stack_base; /* thread stack base address */
uint32 nth_stack_end; /* thread stack end address */
} Elf32_Note_Thread_Entry;
/* NT_THREADS:
* uint64 count;
* uint64 cpuStateSize;
* {Elf64_Note_Thread_Entry, uint8[cpuStateSize] cpuState}[count];
* char[] names
*/
typedef struct {
int32 nth_id; /* thread ID */
int32 nth_state; /* thread state (B_THREAD_RUNNING, ...) */
int32 nth_priority; /* thread priority */
uint32 nth_pad1;
uint64 nth_stack_base; /* thread stack base address */
uint64 nth_stack_end; /* thread stack end address */
} Elf64_Note_Thread_Entry;
/*** inline functions ***/
#ifdef __cplusplus