]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Introduce process_attach_error.
authorJan Kratochvil <jan.kratochvil@redhat.com>
Sat, 30 Nov 2013 20:40:29 +0000 (21:40 +0100)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Sat, 30 Nov 2013 20:40:29 +0000 (21:40 +0100)
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
libdwfl/ChangeLog
libdwfl/dwfl_begin.c
libdwfl/dwfl_frame.c
libdwfl/libdwflP.h
libdwfl/linux-core-attach.c

index 9937bbbb8bb7908483e800dffeaaa6ddb8895c13..7e87e17396edc3f546d38c4475219f40e0ddc101 100644 (file)
@@ -1,3 +1,15 @@
+2013-11-30  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       Introduce process_attach_error.
+       * dwfl_begin.c (dwfl_begin): Initialize process_attach_error.
+       * dwfl_frame.c (dwfl_pid, dwfl_getthreads): Use PROCESS_ATTACH_ERROR if
+       PROCESS is NULL.
+       * libdwflP.h (struct Dwfl): New field process_attach_error.
+       * linux-core-attach.c (__libdwfl_attach_state_for_core): Rename to ...
+       (attach_state_for_core): ... here, make it static, change return type,
+       no longer use __libdwfl_seterrno.
+       (__libdwfl_attach_state_for_core): New wrapper for it.
+
 2013-11-27  Mark Wielaard  <mjw@redhat.com>
 
        * dwfl_module_addrsym.c (dwfl_module_addrsym): Rename to and call...
index 44c16a9212b8b971f9c2e119116bbae5540eb4a3..490da90549167720f5ab589f8726007210d6963a 100644 (file)
@@ -44,6 +44,7 @@ dwfl_begin (const Dwfl_Callbacks *callbacks)
     {
       dwfl->callbacks = callbacks;
       dwfl->offline_next_address = OFFLINE_REDZONE;
+      dwfl->process_attach_error = DWFL_E_NO_ATTACH_STATE;
     }
 
   return dwfl;
index f2863503d0a1256e43cc8ef87032d2e67f2ee29c..4a7b3cdb4da9d7031e79a970561192bf1cdae2ae 100644 (file)
@@ -200,7 +200,7 @@ dwfl_pid (Dwfl *dwfl)
 {
   if (dwfl->process == NULL)
     {
-      __libdwfl_seterrno (DWFL_E_NO_ATTACH_STATE);
+      __libdwfl_seterrno (dwfl->process_attach_error);
       return -1;
     }
   return dwfl->process->pid;
@@ -235,7 +235,7 @@ dwfl_getthreads (Dwfl *dwfl, int (*callback) (Dwfl_Thread *thread, void *arg),
   Dwfl_Process *process = dwfl->process;
   if (process == NULL)
     {
-      __libdwfl_seterrno (DWFL_E_NO_ATTACH_STATE);
+      __libdwfl_seterrno (dwfl->process_attach_error);
       return -1;
     }
 
index b73f7b1dd840d3624d249f078c968223caa0062b..ba1c758d5867884cfe22d0e9b13524ac4978097a 100644 (file)
@@ -108,6 +108,7 @@ struct Dwfl
   Dwfl_Module *modulelist;    /* List in order used by full traversals.  */
 
   Dwfl_Process *process;
+  Dwfl_Error process_attach_error;
 
   GElf_Addr offline_next_address;
 
index 971d495f82c7a642dbdb55f772c1c84e1343c7d8..237c6f36357a37f01bba82a669c5edeace001d82 100644 (file)
@@ -264,37 +264,30 @@ static const Dwfl_Thread_Callbacks core_thread_callbacks =
   NULL, /* core_thread_detach */
 };
 
-bool
-internal_function
-__libdwfl_attach_state_for_core (Dwfl *dwfl, Elf *core)
+static Dwfl_Error
+attach_state_for_core (Dwfl *dwfl, Elf *core)
 {
   Ebl *ebl = ebl_openbackend (core);
   if (ebl == NULL)
-    {
-      __libdwfl_seterrno (DWFL_E_LIBEBL);
-      return false;
-    }
+    return DWFL_E_LIBEBL;
   size_t nregs = ebl_frame_nregs (ebl);
   if (nregs == 0)
     {
       ebl_closebackend (ebl);
-      __libdwfl_seterrno (DWFL_E_LIBEBL);
-      return false;
+      return DWFL_E_NO_UNWIND;
     }
   GElf_Ehdr ehdr_mem, *ehdr = gelf_getehdr (core, &ehdr_mem);
   if (ehdr == NULL)
     {
       ebl_closebackend (ebl);
-      __libdwfl_seterrno (DWFL_E_LIBELF);
-      return false;
+      return DWFL_E_LIBELF;
     }
   assert (ehdr->e_type == ET_CORE);
   size_t phnum;
   if (elf_getphdrnum (core, &phnum) < 0)
     {
       ebl_closebackend (ebl);
-      __libdwfl_seterrno (DWFL_E_LIBELF);
-      return false;
+      return DWFL_E_LIBELF;
     }
   pid_t pid = -1;
   Elf_Data *note_data = NULL;
@@ -311,8 +304,7 @@ __libdwfl_attach_state_for_core (Dwfl *dwfl, Elf *core)
   if (note_data == NULL)
     {
       ebl_closebackend (ebl);
-      __libdwfl_seterrno (DWFL_E_LIBELF);
-      return NULL;
+      return DWFL_E_LIBELF;
     }
   size_t offset = 0;
   GElf_Nhdr nhdr;
@@ -355,15 +347,13 @@ __libdwfl_attach_state_for_core (Dwfl *dwfl, Elf *core)
     {
       /* No valid NT_PRPSINFO recognized in this CORE.  */
       ebl_closebackend (ebl);
-      __libdwfl_seterrno (DWFL_E_BADELF);
-      return false;
+      return DWFL_E_BADELF;
     }
   struct core_arg *core_arg = malloc (sizeof *core_arg);
   if (core_arg == NULL)
     {
       ebl_closebackend (ebl);
-      __libdwfl_seterrno (DWFL_E_NOMEM);
-      return false;
+      return DWFL_E_NOMEM;
     }
   core_arg->core = core;
   core_arg->note_data = note_data;
@@ -372,8 +362,30 @@ __libdwfl_attach_state_for_core (Dwfl *dwfl, Elf *core)
   if (! INTUSE(dwfl_attach_state) (dwfl, core, pid, &core_thread_callbacks,
                                   core_arg))
     {
+      Dwfl_Error error = dwfl_errno ();
+      assert (error != DWFL_E_NOERROR);
       free (core_arg);
       ebl_closebackend (ebl);
+      return error;
+    }
+  return DWFL_E_NOERROR;
+}
+
+bool
+internal_function
+__libdwfl_attach_state_for_core (Dwfl *dwfl, Elf *core)
+{
+  if (dwfl->process != NULL)
+    {
+      __libdwfl_seterrno (DWFL_E_ATTACH_STATE_CONFLICT);
+      return false;
+    }
+  Dwfl_Error error = attach_state_for_core (dwfl, core);
+  assert ((dwfl->process != NULL) == (error == DWFL_E_NOERROR));
+  dwfl->process_attach_error = error;
+  if (error != DWFL_E_NOERROR)
+    {
+      __libdwfl_seterrno (error);
       return false;
     }
   return true;