crash-stack: separate libunw code 51/104551/1
authorRafal Pietruch <r.pietruch@samsung.com>
Mon, 12 Dec 2016 16:19:07 +0000 (17:19 +0100)
committerRafal Pietruch <r.pietruch@samsung.com>
Tue, 13 Dec 2016 13:06:12 +0000 (14:06 +0100)
Change-Id: I1f24781316a78439db862c3ab0d2492fea095c1c

src/crash-stack/CMakeLists.txt
src/crash-stack/crash-stack-arm.c
src/crash-stack/crash-stack-libunw.c [new file with mode: 0644]

index 6ad84d12df68aff6b176b09bfdb15f13681e98d8..34c44eaee6e1e206f28fd97c6e9d1b5f3a9a1938 100644 (file)
@@ -7,6 +7,7 @@ set(CRASH_STACK_BIN "crash-stack")
 set(CRASH_STACK_SRCS crash-stack.c crash-stack-libelf-helpers.c)
 # Add architecture dependent source files
 if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7l")
+  set(CRASH_STACK_SRCS ${CRASH_STACK_SRCS} crash-stack-libunw.c)
   set(CRASH_STACK_SRCS ${CRASH_STACK_SRCS} crash-stack-arm.c)
 else()
   if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64")
index 7d82911937728f9db90374935eff72d3d8f90505..1a9f5b006aeae584d47bb1e8e288b3808eebcff1 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
- * Author: Adrian Szyndela <adrian.s@samsung.com>
- *         Rafal Pietruch <r.pietruch@samsung.com>
+ * Authors: Adrian Szyndela <adrian.s@samsung.com>
+ *          Rafal Pietruch <r.pietruch@samsung.com>
  */
 /**
  * @file crash-stack-arm.c
  * @brief unwinding call stacks, functions specific for ARM
  */
 #include "crash-stack.h"
-#include <libunwind-ptrace.h>
 
 #include <string.h>
 #include <sys/ptrace.h>
@@ -37,8 +36,6 @@
 #define REG_PC 15
 #define REG_SPSR 16
 
-#define MAXPROCNAMELEN 512
-
 /**
  * @brief Important registers for unwinding stack on ARM
  */
@@ -88,56 +85,6 @@ void _crash_stack_set_ptrace_registers(void *regbuf)
        }
 }
 
-void _create_crash_stack(Dwfl *dwfl, Elf *core, pid_t pid, Mappings *mappings, Callstack *callstack)
-{
-       // reimplemented based on libunwind tests/test-ptrace.c file
-       unw_addr_space_t as = 0;
-       void *ui = 0;
-       do {
-               callstack->elems = 0;
-
-               as = unw_create_addr_space(&_UPT_accessors, 0);
-               if (!as)
-                       break;
-
-               ui = _UPT_create(pid);
-               if (!ui)
-                       break;
-
-               unw_cursor_t cursor;
-               if (unw_init_remote(&cursor, as, ui) < 0)
-                       break;
-
-               char proc_name[MAXPROCNAMELEN];
-               int n;
-               // MaxDeep as proposed in libunwind tests/test-ptrace.c file
-               // guard against bad unwind info in old libraries
-               static const int MaxDeep = 64;
-               for (n = 0; n < MaxDeep; ++n) {
-
-                       unw_word_t ip;
-                       if (unw_get_reg(&cursor, UNW_REG_IP, &ip) < 0)
-                               break;
-                       callstack->tab[callstack->elems] = ip;
-
-                       proc_name[0] = '\0';
-                       unw_word_t off;
-                       unw_get_proc_name(&cursor, proc_name, sizeof(proc_name), &off);
-                       if (strlen(proc_name) > 0)
-                               callstack->proc_name[callstack->elems] = strdup(proc_name);
-
-                       ++callstack->elems;
-                       if (unw_step(&cursor) <= 0)
-                               break;
-               }
-       } while (0);
-
-       if (ui)
-               _UPT_destroy(ui);
-       if (as)
-               unw_destroy_addr_space(as);
-}
-
 void _crash_stack_print_regs(FILE* outputfile)
 {
        fprintf(outputfile, "\nRegister Information\n");
diff --git a/src/crash-stack/crash-stack-libunw.c b/src/crash-stack/crash-stack-libunw.c
new file mode 100644 (file)
index 0000000..dca2af8
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ *
+ * 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: Rafal Pietruch <r.pietruch@samsung.com>
+ */
+/**
+ * @file crash-stack-libunw.c
+ * @brief unwinding call stacks, functions specific for archs that use only libunwind
+ */
+#include "crash-stack.h"
+#include <libunwind-ptrace.h>
+
+#include <string.h>
+
+#define MAXPROCNAMELEN 512
+
+void _create_crash_stack(Dwfl *dwfl, Elf *core, pid_t pid, Mappings *mappings, Callstack *callstack)
+{
+       // reimplemented based on libunwind tests/test-ptrace.c file
+       unw_addr_space_t as = 0;
+       void *ui = 0;
+       do {
+               callstack->elems = 0;
+
+               as = unw_create_addr_space(&_UPT_accessors, 0);
+               if (!as)
+                       break;
+
+               ui = _UPT_create(pid);
+               if (!ui)
+                       break;
+
+               unw_cursor_t cursor;
+               if (unw_init_remote(&cursor, as, ui) < 0)
+                       break;
+
+               char proc_name[MAXPROCNAMELEN];
+               int n;
+               // MaxDeep as proposed in libunwind tests/test-ptrace.c file
+               // guard against bad unwind info in old libraries
+               static const int MaxDeep = 64;
+               for (n = 0; n < MaxDeep; ++n) {
+
+                       unw_word_t ip;
+                       if (unw_get_reg(&cursor, UNW_REG_IP, &ip) < 0)
+                               break;
+                       callstack->tab[callstack->elems] = ip;
+
+                       proc_name[0] = '\0';
+                       unw_word_t off;
+                       unw_get_proc_name(&cursor, proc_name, sizeof(proc_name), &off);
+                       if (strlen(proc_name) > 0)
+                               callstack->proc_name[callstack->elems] = strdup(proc_name);
+
+                       ++callstack->elems;
+                       if (unw_step(&cursor) <= 0)
+                               break;
+               }
+       } while (0);
+
+       if (ui)
+               _UPT_destroy(ui);
+       if (as)
+               unw_destroy_addr_space(as);
+}