summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKunhoon Baik <knhoon.baik@samsung.com>2016-12-12 19:34:28 -0800
committerKunhoon Baik <knhoon.baik@samsung.com>2016-12-12 19:43:59 -0800
commit1e57cc1f993d99969a77e52df8308f6f8792fb36 (patch)
treed196c07c048f5c476fc69be5a52c226eea86df21
parent1124a5e6b86fb45cac31c954a66bcd2f9559af10 (diff)
downloadcrash-worker-1e57cc1f993d99969a77e52df8308f6f8792fb36.tar.gz
crash-worker-1e57cc1f993d99969a77e52df8308f6f8792fb36.tar.bz2
crash-worker-1e57cc1f993d99969a77e52df8308f6f8792fb36.zip
Revert "crash-pipe: read and parse core"submit/tizen_3.0/20161213.034539
This reverts commit b3661520e5b660ce7352381e6bfa5d25647357e4. Change-Id: I01557e7b7bf4ed5f8c278e2e168d8aaa04f8d49e
-rw-r--r--src/crash-pipe/CMakeLists.txt1
-rw-r--r--src/crash-pipe/crash-pipe-arch.h39
-rw-r--r--src/crash-pipe/crash-pipe-armv7l.c73
-rw-r--r--src/crash-pipe/crash-pipe-x86_64.c69
-rw-r--r--src/crash-pipe/crash-pipe.c326
5 files changed, 14 insertions, 494 deletions
diff --git a/src/crash-pipe/CMakeLists.txt b/src/crash-pipe/CMakeLists.txt
index f85257d..7405769 100644
--- a/src/crash-pipe/CMakeLists.txt
+++ b/src/crash-pipe/CMakeLists.txt
@@ -1,6 +1,5 @@
set(CRASH_PIPE_BIN "crash-pipe")
set(CRASH_PIPE_SRCS crash-pipe.c)
-set(CRASH_PIPE_SRCS ${CRASH_PIPE_SRCS} crash-pipe-${CMAKE_SYSTEM_PROCESSOR}.c)
add_executable(${CRASH_PIPE_BIN} ${CRASH_PIPE_SRCS})
install(TARGETS ${CRASH_PIPE_BIN} DESTINATION libexec)
diff --git a/src/crash-pipe/crash-pipe-arch.h b/src/crash-pipe/crash-pipe-arch.h
deleted file mode 100644
index 19b8094..0000000
--- a/src/crash-pipe/crash-pipe-arch.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/* crash-pipe: handle core file passed from stdin
- *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Author: Łukasz Stelmach <l.stelmach@samsung.com>
- */
-
-#if defined(__x86_64__) || defined(__aarch64__)
-#define elf_ehdr Elf64_Ehdr
-#define elf_phdr Elf64_Phdr
-#define elf_nhdr Elf64_Nhdr
-#define elf_addr_t Elf64_Addr
-#define _ELFCLASS ELFCLASS64
-#elif defined(__i386__) || defined(__arm__)
-#define elf_ehdr Elf32_Ehdr
-#define elf_phdr Elf32_Phdr
-#define elf_nhdr Elf32_Nhdr
-#define elf_addr_t Elf32_Addr
-#define _ELFCLASS ELFCLASS32
-#else
-#error "Unsupported architecture"
-#endif
-
-unsigned long arch_get_bp(elf_gregset_t*);
-unsigned long arch_get_ip(elf_gregset_t*);
-unsigned long arch_get_sp(elf_gregset_t*);
-void arch_dump_registers(elf_gregset_t*);
diff --git a/src/crash-pipe/crash-pipe-armv7l.c b/src/crash-pipe/crash-pipe-armv7l.c
deleted file mode 100644
index a7273f4..0000000
--- a/src/crash-pipe/crash-pipe-armv7l.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/* crash-pipe: handle core file passed from stdin
- *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Author: Łukasz Stelmach <l.stelmach@samsung.com>
- */
-#define _GNU_SOURCE
-
-#define REG_FP 11
-#define REG_IP 12
-#define REG_SP 13
-#define REG_LR 14
-#define REG_PC 15
-#define REG_SPSR 16
-
-#include <stdio.h>
-#include <sys/procfs.h>
-
-unsigned long arch_get_bp(elf_gregset_t* r)
-{
- struct user_regs *regs = (struct user_regs *)r;
- return regs->uregs[REG_FP];
-}
-
-unsigned long arch_get_ip(elf_gregset_t* r)
-{
- struct user_regs *regs = (struct user_regs *)r;
- return regs->uregs[REG_IP];
-}
-
-unsigned long arch_get_sp(elf_gregset_t* r)
-{
- struct user_regs *regs = (struct user_regs *)r;
- return regs->uregs[REG_SP];
-}
-
-void arch_dump_registers(elf_gregset_t* r)
-{
- struct user_regs *regs = (struct user_regs*)r;
- printf("\nRegister Information\n");
- printf("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n",
- regs->uregs[REG_PC], regs->uregs[REG_LR],
- regs->uregs[REG_SPSR]
- );
- printf("sp : %08lx ip : %08lx fp : %08lx\n",
- regs->uregs[REG_SP], regs->uregs[REG_IP],
- regs->uregs[REG_FP]
- );
- printf("r10: %08lx r9 : %08lx r8 : %08lx\n",
- regs->uregs[10], regs->uregs[9],
- regs->uregs[8]
- );
- printf("r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
- regs->uregs[7], regs->uregs[6],
- regs->uregs[5], regs->uregs[4]
- );
- printf("r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
- regs->uregs[3], regs->uregs[2],
- regs->uregs[1], regs->uregs[0]
- );
-}
diff --git a/src/crash-pipe/crash-pipe-x86_64.c b/src/crash-pipe/crash-pipe-x86_64.c
deleted file mode 100644
index 81d36d5..0000000
--- a/src/crash-pipe/crash-pipe-x86_64.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/* crash-pipe: handle core file passed from stdin
- *
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Author: Łukasz Stelmach <l.stelmach@samsung.com>
- */
-#define _GNU_SOURCE
-
-#include <sys/procfs.h>
-#include <stdio.h>
-
-unsigned long arch_get_bp(elf_gregset_t* r)
-{
- struct user_regs_struct *regs = (struct user_regs_struct *)r;
- return regs->rbp;
-}
-
-unsigned long arch_get_ip(elf_gregset_t* r)
-{
- struct user_regs_struct *regs = (struct user_regs_struct *)r;
- return regs->rip;
-}
-
-unsigned long arch_get_sp(elf_gregset_t* r)
-{
- struct user_regs_struct *regs = (struct user_regs_struct *)r;
- return regs->rsp;
-}
-
-void arch_dump_registers(elf_gregset_t* r)
-{
- struct user_regs_struct *regs = (struct user_regs_struct *)r;
-#define _PRINT_REGISTERS(a,b,c) \
- printf("%3s: %016lx %3s: %016lx %3s: %016lx\n", \
- #a, regs->a, \
- #b, regs->b, \
- #c, regs->c)
- printf("\nRegister Information\n");
-#ifdef __x86_64__
- printf("rip: %04lx:[<%016lx>]\n",
- regs->cs & 0xffff,
- regs->rip);
- printf("rsp: %04lx:%016lx eflags: %08lx\n",
- regs->ss,
- regs->rsp,
- regs->eflags);
- _PRINT_REGISTERS(rax, rbx, rcx);
- _PRINT_REGISTERS(rdx, rsi, rdi);
- _PRINT_REGISTERS(rbp, r8, r9);
- _PRINT_REGISTERS(r10, r11, r12);
- _PRINT_REGISTERS(r13, r14, r15);
-#else
- printf("Unsupported architecture\n")
-#endif
- printf("\n");
-#undef _PRINT_REGISTERS
-}
diff --git a/src/crash-pipe/crash-pipe.c b/src/crash-pipe/crash-pipe.c
index 1f91e9a..187995b 100644
--- a/src/crash-pipe/crash-pipe.c
+++ b/src/crash-pipe/crash-pipe.c
@@ -32,11 +32,6 @@
#include <fcntl.h>
#include <getopt.h>
#include <limits.h>
-#include <elf.h>
-#include <signal.h>
-#include <sys/procfs.h>
-
-#include "crash-pipe-arch.h"
#define NELEMS(arr) (sizeof(arr)/sizeof(arr[0]))
#define BUF_SIZE (BUFSIZ)
@@ -46,30 +41,12 @@
#define STR_ANONY "[anony]"
#define STR_ANONY_LEN 8
-#define roundup(x,y) ( \
-{ \
- (((x) + (y-1))/y) * y; \
-} \
-)
-
enum {
OPT_HELP,
OPT_REPORT,
OPT_SAVE_CORE,
};
-struct file_mapping {
- long start;
- long end;
- long file_ofs;
-};
-
-typedef struct {
- long count;
- long page_size;
- struct file_mapping mappings[0];
-} mapped_files_t;
-
struct addr_node {
long *startaddr;
long *endaddr;
@@ -87,16 +64,6 @@ const struct option opts[] = {
static char *argv0 = "";
-static int core_input;
-static int core_output;
-static char* core_buffer;
-static int core_bytes;
-#define CORE_BUFFER_SIZE 16384
-
-static unsigned long sp;
-static unsigned long stack_start;
-static unsigned long stack_end;
-
static void usage(void)
{
fprintf(stderr, "usage: %s [--help] [--save-core FILE_NAME] [--report] PID UID GID SIGNAL DUMPTIME EXE\n",
@@ -458,286 +425,39 @@ static void report(int argc, char *argv[])
}
}
-static int open_core(const char *core_path)
+static int save_core(const char *core_path)
{
int fd;
+ static char buf[4096];
+ int readb, remaining;
+ int ret = 0;
+
fd = open(core_path, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
if (fd == -1) {
syslog(LOG_ERR, "crash-pipe: Unable to save core file to %s: %m\n", core_path);
return -errno;
}
- return fd;
-}
-
-static int save_core(int fd, const char* header, int headersz)
-{
- char *buf[4096];
- int readb, remaining;
- int ret = 0;
- int n;
+ while ((readb = read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
+ int n;
- for (n = 0, remaining = headersz ; remaining > 0; remaining -= n) {
- n = write(fd, header, remaining);
- if (n == -1) {
- ret = -errno;
- syslog(LOG_ERR, "crash-pipe:%d: Error while saving core file: %m.\n", __LINE__);
- return ret;
- }
- }
-
- while ((readb = read(core_input, buf, sizeof(buf))) > 0) {
for (n = 0, remaining = readb ; remaining > 0; remaining -= n) {
n = write(fd, buf, remaining);
if (n == -1) {
ret = -errno;
- syslog(LOG_ERR, "crash-pipe:%d: Error while saving core file: %m.\n", __LINE__);
- return ret;
+ syslog(LOG_ERR, "crash-pipe: Error while saving core file %s: %m. Removing core.\n", core_path);
+ (void)unlink(core_path); // XXX check errors here too
+ goto out;
}
}
}
- return ret;
-}
-
+out:
+ close(fd);
-static int read_n_bytes_of_core(char* b, int remaining)
-{
- int ret=0;
- int readb;
- while(remaining > 0) {
- readb = read(core_input, b, remaining);
- if (readb < 0){
- syslog(LOG_ERR, "crash-pipe:%d: Error reading core: %m.", __LINE__);
- return readb;
- }
- remaining -= readb;
- b += readb;
- ret += readb;
- }
- core_bytes += ret;
return ret;
}
-static void dump_siginfo(siginfo_t *si)
-{
- const char* const signal_table[] = {
- [SIGHUP]="SIGHUP", [SIGINT]="SIGINT", [SIGQUIT]="SIGQUIT",
- [SIGILL]="SIGILL", [SIGTRAP]="SIGTRAP", [SIGABRT]="SIGABRT",
- [SIGIOT]="SIGIOT", [SIGBUS]="SIGBUS", [SIGFPE]="SIGFPE",
- [SIGKILL]="SIGKILL", [SIGUSR1]="SIGUSR1", [SIGSEGV]="SIGSEGV",
- [SIGUSR2]="SIGUSR2", [SIGPIPE]="SIGPIPE", [SIGALRM]="SIGALRM",
- [SIGTERM]="SIGTERM", [SIGSTKFLT]="SIGSTKFLT", [SIGCHLD]="SIGCHLD",
- [SIGCONT]="SIGCONT", [SIGSTOP]="SIGSTOP", [SIGTSTP]="SIGTSTP",
- [SIGTTIN]="SIGTTIN", [SIGTTOU]="SIGTTOU", [SIGURG]="SIGURG",
- [SIGXCPU]="SIGXCPU", [SIGXFSZ]="SIGXFSZ", [SIGVTALRM]="SIGVTALRM",
- [SIGPROF]="SIGPROF", [SIGWINCH]="SIGWINCH", [SIGIO]="SIGIO",
- [SIGPWR]="SIGPWR", [SIGSYS]="SIGSYS", [SIGUNUSED]="SIGUNUSED",
- };
- printf("Signal: %d\n"
- "\t(%s)\n"
- "\tsi_code: %d\n",
- si->si_signo,
- signal_table[si->si_signo],
- si->si_code);
- switch (si->si_code) {
- case SI_TKILL:
- case SI_USER:
- printf("\tsignal sent by %s (sent by pid %d, uid %d)",
- si->si_code == SI_TKILL ? "tkill" : "kill",
- si->si_pid, si->si_uid);
- break;
- case SI_KERNEL:
- printf("\tsignal sent by the kernel\n");
- break;
- }
- printf("\n");
-}
-
-static void dump_auxv(elf_addr_t *elf_info)
-{
- int i;
- const char* const at_table[] = {
- [AT_IGNORE] = "IGNORE", [AT_EXECFD] = "EXECFD",
- [AT_PHDR] = "PHDR", [AT_PHENT] = "PHENT",
- [AT_PHNUM] = "PHNUM", [AT_PAGESZ] = "PAGESZ",
- [AT_BASE] = "BASE", [AT_FLAGS] = "FLAGS",
- [AT_ENTRY] = "ENTRY", [AT_NOTELF] = "NOTELF",
- [AT_UID] = "UID", [AT_EUID] = "EUID",
- [AT_GID] = "GID", [AT_EGID] = "EGID",
- [AT_CLKTCK] = "CLKTCK", [AT_PLATFORM] = "PLATFORM",
- [AT_HWCAP] = "HWCAP", [AT_FPUCW] = "FPUCW",
- [AT_DCACHEBSIZE] = "DCACHEBSIZE",
- [AT_ICACHEBSIZE] = "ICACHEBSIZE",
- [AT_UCACHEBSIZE] = "UCACHEBSIZE",
- [AT_IGNOREPPC] = "IGNOREPPC",
- [AT_SECURE] = "SECURE",
- [AT_BASE_PLATFORM] = "BASE_PLATFORM",
- [AT_RANDOM] = "RANDOM", [AT_HWCAP2] = "HWCAP2",
- [AT_EXECFN] = "EXECFN", [AT_SYSINFO] = "SYSINFO",
- [AT_SYSINFO_EHDR] = "SYSINFO_EHDR",
- [AT_L1I_CACHESHAPE] = "L1I_CACHESHAPE",
- [AT_L1D_CACHESHAPE] = "L1D_CACHESHAPE",
- [AT_L2_CACHESHAPE] = "L2_CACHESHAPE",
- [AT_L3_CACHESHAPE] = "L3_CACHESHAPE"};
-
- printf("Auxiliary vector:\n");
- for (i = 0; elf_info[i] != AT_NULL;) {
- elf_addr_t k = elf_info[i++];
- elf_addr_t v = elf_info[i++];
- switch (k) {
- case AT_PAGESZ:
- case AT_CLKTCK:
- case AT_PHENT:
- case AT_PHNUM:
- case AT_FLAGS:
- case AT_UID:
- case AT_EUID:
- case AT_GID:
- case AT_EGID:
- case AT_SECURE:
- printf("\t%-14s: %d\n", at_table[k], v);
- break;
- default:
- printf("\t%-14s: 0x%x\n", at_table[k], v);
- }
- }
- printf("\n");
-}
-
-static void dump_files(mapped_files_t *mf)
-{
- long i;
- char *fn = (char*)&mf->mappings[mf->count];
- printf("Mapped files:\n");
-
- for (i=0; i < mf->count; i++) {
- printf("%lx-%lx %lx %s\n",
- mf->mappings[i].start,
- mf->mappings[i].end,
- mf->mappings[i].file_ofs * mf->page_size,
- fn);
- fn += strlen(fn) + 1;
- }
-
- printf("\n");
-}
-
-static void dump_prstatus(struct elf_prstatus* prstatus)
-{
- arch_dump_registers(&prstatus->pr_reg);
- printf("\n");
-}
-
-static int parse_core()
-{
- int i;
- char *b;
- elf_ehdr *eh;
- elf_phdr *ph, *phi;
- elf_nhdr *nh, *nhi;
- int readb;
-
- eh = (void*)(b = core_buffer);
-
- readb = read_n_bytes_of_core(b, sizeof(*eh));
- if (readb < 0){
- syslog(LOG_ERR, "crash-pipe:%d: Error reading core: %m.", __LINE__);
- return readb;
- }
- b += readb;
-
- if (memcmp(eh->e_ident, ELFMAG, 4) != 0 ||
- eh->e_ident[EI_CLASS] != _ELFCLASS ||
- (eh->e_ident[EI_OSABI] != ELFOSABI_LINUX &&
- eh->e_ident[EI_OSABI] != ELFOSABI_NONE) ||
- eh->e_type != ET_CORE) {
- syslog(LOG_ERR, "crash-pipe:%d: Unsupported core format.", __LINE__);
- return -1;
- }
-
- /* Read everything up to programme headers */
- readb = read_n_bytes_of_core(b, eh->e_phoff - (b - core_buffer));
- if (readb < 0){
- syslog(LOG_ERR, "crash-pipe:%d: Error reading core: %m.", __LINE__);
- return readb;
- }
- b += readb;
-
- readb = read_n_bytes_of_core(b, eh->e_phentsize * eh->e_phnum);
- if (readb < 0) {
- syslog(LOG_ERR, "crash-pipe:%d: Error reading core: %m.", __LINE__);
- return readb;
- }
- ph = (elf_phdr*)b;
- b += readb;
-
- for (nh = NULL, phi = ph, i=0; i < eh->e_phnum; i++, phi++) {
- if (phi->p_type == PT_NOTE) {
- readb = read_n_bytes_of_core(b,
- phi->p_offset - (b - core_buffer) +
- phi->p_filesz);
- if (read < 0){
- syslog(LOG_ERR, "crash-pipe:%d: Error reading core: %m.", __LINE__);
- return readb;
- }
- nh = (elf_nhdr*)b;
- b += readb;
- break;
- }
- }
-
- if (nh == NULL) {
- syslog(LOG_ERR, "crash-pipe:%d: Note programme header not found.", __LINE__);
- return -1;
- }
-
- for (nhi = nh;
- (uintptr_t)nhi < (uintptr_t)(core_buffer + ph->p_offset + ph->p_filesz);
- nhi = (elf_nhdr*)((uintptr_t)nhi + sizeof(*nh) +
- roundup(nhi->n_namesz, 4) +
- roundup(nhi->n_descsz, 4))) {
- void *data = (void*)((uintptr_t)nhi + sizeof(*nh) +
- roundup(nhi->n_namesz, 4));
-
- switch (nhi->n_type) {
- case NT_SIGINFO:
- dump_siginfo((siginfo_t*)data);
- break;
- case NT_FILE:
- dump_files((mapped_files_t*)data);
- break;
- case NT_AUXV:
- dump_auxv((elf_addr_t*)data);
- break;
- case NT_PRSTATUS:
- dump_prstatus((struct elf_prstatus*)data);
- sp = arch_get_sp(&(((struct elf_prstatus*)data)->pr_reg));
- break;
- case NT_FPREGSET:
- case NT_PRPSINFO:
- case NT_X86_XSTATE:
- default:
- printf("offset: 0x%08x note type: 0x%08x\n",
- ((uintptr_t)nhi - (uintptr_t)core_buffer),
- nhi->n_type);
- }
- }
-
- for (phi = ph, i=0; i < eh->e_phnum; i++, phi++) {
- if (phi->p_flags == (PF_R | PF_W) &&
- phi->p_vaddr < sp &&
- phi->p_vaddr + phi->p_memsz > sp) {
- stack_start = phi->p_vaddr;
- stack_end = phi->p_vaddr + phi->p_memsz;
- printf("Stack location: ");
- printf("%lx-%lx\n", stack_start, stack_end);
-
- }
- }
-
- return readb;
-}
int main(int argc, char *argv[])
{
@@ -750,8 +470,6 @@ int main(int argc, char *argv[])
argv0 = argv[0];
- core_input = STDIN_FILENO;
-
while ((c = getopt_long_only(argc, argv, "", opts, NULL)) != -1) {
if (c == OPT_HELP) {
@@ -771,27 +489,11 @@ int main(int argc, char *argv[])
argc -= optind;
argv += optind;
- core_buffer = malloc(CORE_BUFFER_SIZE);
- if (core_buffer == NULL) {
- syslog(LOG_ERR, "crash-pipe:%d: Unable to allocate memory: %m\n", __LINE__);
- return EXIT_FAILURE;
- }
- memset(core_buffer, 0, CORE_BUFFER_SIZE);
-
- parse_core();
-
if (opt_report)
report(argc, argv);
- if (opt_save_core) {
- core_output = open_core(opt_save_core);
- if (core_output < 0);
- ret = save_core(core_output, core_buffer, core_bytes);
- close(core_output);
- if (ret < 0)
- unlink(opt_save_core);
- }
+ if (opt_save_core)
+ ret = save_core(opt_save_core);
- free(core_buffer);
return ret >= 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}