crash-stack: Made default configuration without core dumps 55/76355/4
authorAdrian Szyndela <adrian.s@samsung.com>
Thu, 23 Jun 2016 12:56:54 +0000 (14:56 +0200)
committerAdrian Szyndela <adrian.s@samsung.com>
Fri, 5 Aug 2016 13:31:58 +0000 (15:31 +0200)
Crash-manager does not use crash-stack core dump configuration now.
Core dump support needs libebl, which is not included in elfutils
license exception. Thus, with core dump support, we would need
to change license to GPL2. This patch disables core dumps support.
It can be enabled by giving -DWITH_CORE_DUMP=ON to cmake (see
crash-worker.spec for an example).

Change-Id: Ic8ed970217c52b6dcbca8934d0d4ee4010245d77

packaging/crash-worker.spec
src/crash-stack/CMakeLists.txt
src/crash-stack/crash-stack.c

index 90be22e5820ec239f5ea3e2893806368134f6ea2..706308db592d4a3db9c4d8cb67734b0c78d3ff06 100644 (file)
@@ -23,11 +23,13 @@ BuildRequires:  libdw-devel libdw
 Requires(post): coreutils
 Requires(post): tar
 Requires(post): gzip
-Requires: libebl
 Requires: libunwind
 %if %{?crash_popup} == on
 Requires: /usr/bin/dbus-send
 %endif
+# If you need support for core dump files (see building below),
+# you should add this dependency
+# Requires: libebl
 
 %description
 crash-manager
@@ -69,6 +71,9 @@ export CFLAGS+=" -Werror"
           -DCRASH_STACK_PATH=%{_libexecdir}/crash-stack \
           -DCRASH_POPUP=%{crash_popup} \
           -DSYS_ASSERT=%{sys_assert}
+# to add support for core dump files add backslash at the end of above line
+# and uncomment below line:
+#         -DWITH_CORE_DUMP=ON
 
 make %{?jobs:-j%jobs}
 
index a95940fe439e2baf05cb179a0a108c0925a22bd0..b11c4d0afcd85fe024377d0fa475dfe2377984b9 100644 (file)
@@ -1,3 +1,4 @@
+option(WITH_CORE_DUMP "builds with support for core dump files (with GPL2 license)")
 set(CRASH_STACK_BIN "crash-stack")
 set(CRASH_STACK_SRCS crash-stack.c)
 
@@ -8,7 +9,15 @@ else()
 endif()
 
 add_executable(${CRASH_STACK_BIN} ${CRASH_STACK_SRCS})
-set_property(TARGET ${CRASH_STACK_BIN} APPEND PROPERTY COMPILE_FLAGS "-DUPGRADE_ARM_STACK_UNWIND")
-#set_property(TARGET ${CRASH_STACK_BIN} APPEND PROPERTY COMPILE_FLAGS "-DUPGRADE_ARM_STACK_UNWIND -DUNW_DEBUG")
+
+if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7l")
+  set_property(TARGET ${CRASH_STACK_BIN} APPEND_STRING PROPERTY COMPILE_FLAGS " -DUPGRADE_ARM_STACK_UNWIND")
+#  set_property(TARGET ${CRASH_STACK_BIN} APPEND_STRING PROPERTY COMPILE_FLAGS "-DUPGRADE_ARM_STACK_UNWIND -DUNW_DEBUG")
+endif()
+
+if (${WITH_CORE_DUMP} STREQUAL "ON")
+  set_property(TARGET ${CRASH_STACK_BIN} APPEND_STRING PROPERTY COMPILE_FLAGS " -DWITH_CORE_DUMP")
+endif()
+
 target_link_libraries(${CRASH_STACK_BIN} dw elf ebl dl stdc++)
 install(TARGETS ${CRASH_STACK_BIN} DESTINATION libexec)
index 321132c58ce3defe1b536d87d9bfd09c2119fcbf..609ac2f4faff02e4f99720e5953c38b8ec8be692 100644 (file)
@@ -2,7 +2,9 @@
 #include <stdio.h>
 #include <libelf.h>
 #include <elfutils/libdwfl.h>
+#ifdef WITH_CORE_DUMP
 #include <elfutils/libebl.h>
+#endif
 #include <errno.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -55,7 +57,6 @@ static int module_callback(Dwfl_Module *module, void **userdata,
                        mappings->elems++;
                }
        }
-       /*  fprintf(errfile, "Got module %s @0x%llx\n", name, (long long)address);*/
        return DWARF_CB_OK;
 }
 
@@ -86,22 +87,6 @@ static void getvalue(Elf *core, const void *from, size_t size, void *to)
                fprintf(errfile, "failed to get value from core file\n");
 }
 
-static void updateMapping(Mappings *mappings, uint64_t mapping_start, uint64_t mapping_end,
-               uint64_t offset, const char *name)
-{
-       int i;
-       for (i = 0; i < mappings->elems; i++) {
-               if (mappings->tab[i].m_start == mapping_start) {
-                       mappings->tab[i].m_end = mapping_end;
-                       mappings->tab[i].m_name = name;
-                       mappings->tab[i].m_offset = offset;
-                       mappings->tab[i].m_fd = open(name, O_RDONLY);
-                       mappings->tab[i].m_elf = elf_begin(mappings->tab[i].m_fd, ELF_C_READ_MMAP, NULL);
-                       return;
-               }
-       }
-}
-
 static void parse_note_file(Elf *elf, const char *desc, uint64_t *values_cnt, uint64_t *page_size,
                size_t *addr_size, const char **values, const char **filenames)
 {
@@ -244,7 +229,7 @@ static Dwfl *open_dwfl_with_pid(pid_t pid)
                return NULL;
        }
 
-#if _ELFUTILS_PREREQ(0, 158)
+#if _ELFUTILS_PREREQ(0,158)
        if (dwfl_linux_proc_attach(dwfl, pid, true) < 0) {
                fprintf(errfile, "process %d : dwfl attach failed (%s)\n", pid, dwfl_errmsg(-1));
                dwfl_end(dwfl);
@@ -254,6 +239,10 @@ static Dwfl *open_dwfl_with_pid(pid_t pid)
        return dwfl;
 }
 
+/*
+ * This function will open core file regardless of WITH_CORE_DUMP setting.
+ * It may help with detecting issues with using dwfl even without support for dumps.
+ */
 static Dwfl *open_dwfl_with_core(Elf *core, const char *core_file_name)
 {
        static const Dwfl_Callbacks core_callbacks = {
@@ -269,7 +258,7 @@ static Dwfl *open_dwfl_with_core(Elf *core, const char *core_file_name)
                return NULL;
        }
 
-#if _ELFUTILS_PREREQ(0, 158)
+#if _ELFUTILS_PREREQ(0,158)
        if (dwfl_core_file_report(dwfl, core, NULL) < 0)
 #else
                if (dwfl_core_file_report(dwfl, core) < 0)
@@ -280,7 +269,7 @@ static Dwfl *open_dwfl_with_core(Elf *core, const char *core_file_name)
                        return NULL;
                }
 
-#if _ELFUTILS_PREREQ(0, 158)
+#if _ELFUTILS_PREREQ(0,158)
        if (dwfl_core_file_attach(dwfl, core) < 0) {
                fprintf(errfile, "%s : dwfl attach failed (%s)\n", core_file_name, dwfl_errmsg(-1));
                dwfl_end(dwfl);
@@ -315,8 +304,28 @@ static int get_registers_ptrace(pid_t pid)
        return 0;
 }
 
+#ifdef WITH_CORE_DUMP
+static void updateMapping(Mappings *mappings, uint64_t mapping_start, uint64_t mapping_end,
+               uint64_t offset, const char *name)
+{
+       int i;
+       for (i = 0; i < mappings->elems; i++) {
+               if (mappings->tab[i].m_start == mapping_start) {
+                       mappings->tab[i].m_end = mapping_end;
+                       mappings->tab[i].m_name = name;
+                       mappings->tab[i].m_offset = offset;
+                       mappings->tab[i].m_fd = open(name, O_RDONLY);
+                       mappings->tab[i].m_elf = elf_begin(mappings->tab[i].m_fd, ELF_C_READ_MMAP, NULL);
+                       return;
+               }
+       }
+}
+#endif
+
 static Elf_Data *get_registers_core(Elf *core, const char *core_file_name, Mappings *mappings)
 {
+       Elf_Data *notes = NULL;
+#ifdef WITH_CORE_DUMP
        GElf_Phdr mem;
        GElf_Phdr *phdr = gelf_getphdr(core, 0, &mem);
 
@@ -421,6 +430,9 @@ static Elf_Data *get_registers_core(Elf *core, const char *core_file_name, Mappi
                pos = new_pos;
        }
        ebl_closebackend(ebl);
+#else
+       fprintf(errfile, "Configured without support for core dump files\n");
+#endif
        return notes;
 }