This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[commit libdwfl/] Introduce process_attach_error [Re: [tests patchv2] FYI unwinder: tests/ update]


On Thu, 28 Nov 2013 16:57:13 +0100, Mark Wielaard wrote:
> > diff --git a/libdwfl/dwfl_frame.c b/libdwfl/dwfl_frame.c
> > index f286350..4a7b3cd 100644
> > --- a/libdwfl/dwfl_frame.c
> > +++ b/libdwfl/dwfl_frame.c
> > @@ -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;
> >      }
> 
> Won't this return -1 and set the error to DWFL_E_NO_ERROR (0) in case no
> attach has ever been attempted?

Yes, you are right.


> Maybe check that dwfl->process_attach_error != DWFL_E_NO_ERROR first.
> And if it is then seterrno to DWFL_E_NO_ATTACH_STATE.
> Or initialize dwfl->process_attach_error to DWFL_E_NO_ATTACH_STATE in
> dwfl_begin?

I have done the latter.


> > +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));
> > +  if (error != DWFL_E_NOERROR)
> > +    {
> > +      dwfl->process_attach_error = error;
> > +      __libdwfl_seterrno (error);
> >        return false;
> >      }
> >    return true;
> 
> And depending on how to resolve the question above about dwfl_pid and
> dwfl_getthreads set dwfl->process_attach_error to DWFL_E_NOERROR?

Yes.

Checked in, the changes were very minor now.


Thanks,
Jan


5ef96c979ca45d0bf8c44f082df4da6b780010db Mon Sep 17 00:00:00 2001
From: Jan Kratochvil <jan.kratochvil@redhat.com>
Date: Sat, 30 Nov 2013 21:40:29 +0100
Subject: [PATCH] Introduce process_attach_error.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
---
 libdwfl/ChangeLog           | 12 +++++++++++
 libdwfl/dwfl_begin.c        |  1 +
 libdwfl/dwfl_frame.c        |  4 ++--
 libdwfl/libdwflP.h          |  1 +
 libdwfl/linux-core-attach.c | 50 ++++++++++++++++++++++++++++-----------------
 5 files changed, 47 insertions(+), 21 deletions(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 9937bbb..7e87e17 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -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...
diff --git a/libdwfl/dwfl_begin.c b/libdwfl/dwfl_begin.c
index 44c16a9..490da90 100644
--- a/libdwfl/dwfl_begin.c
+++ b/libdwfl/dwfl_begin.c
@@ -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;
diff --git a/libdwfl/dwfl_frame.c b/libdwfl/dwfl_frame.c
index f286350..4a7b3cd 100644
--- a/libdwfl/dwfl_frame.c
+++ b/libdwfl/dwfl_frame.c
@@ -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;
     }
 
diff --git a/libdwfl/libdwflP.h b/libdwfl/libdwflP.h
index b73f7b1..ba1c758 100644
--- a/libdwfl/libdwflP.h
+++ b/libdwfl/libdwflP.h
@@ -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;
 
diff --git a/libdwfl/linux-core-attach.c b/libdwfl/linux-core-attach.c
index 971d495..237c6f3 100644
--- a/libdwfl/linux-core-attach.c
+++ b/libdwfl/linux-core-attach.c
@@ -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;
-- 
1.8.3.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]