diff options
author | Jan Kratochvil <jan.kratochvil@redhat.com> | 2013-11-30 21:40:29 +0100 |
---|---|---|
committer | Jan Kratochvil <jan.kratochvil@redhat.com> | 2013-11-30 21:40:29 +0100 |
commit | 5ef96c979ca45d0bf8c44f082df4da6b780010db (patch) | |
tree | fce8ce1e8dbeaea1cc4ba30c72581374f43cf12a | |
parent | 819c349f6339512d6961a6172c539fdf2c2f1328 (diff) | |
download | elfutils-5ef96c979ca45d0bf8c44f082df4da6b780010db.tar.gz |
Introduce process_attach_error.
Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
-rw-r--r-- | libdwfl/ChangeLog | 12 | ||||
-rw-r--r-- | libdwfl/dwfl_begin.c | 1 | ||||
-rw-r--r-- | libdwfl/dwfl_frame.c | 4 | ||||
-rw-r--r-- | libdwfl/libdwflP.h | 1 | ||||
-rw-r--r-- | libdwfl/linux-core-attach.c | 50 |
5 files changed, 47 insertions, 21 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 9937bbbb..7e87e173 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 44c16a92..490da905 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 f2863503..4a7b3cdb 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 b73f7b1d..ba1c758d 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 971d495f..237c6f36 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; |