+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...
{
if (dwfl->process == NULL)
{
- __libdwfl_seterrno (DWFL_E_NO_ATTACH_STATE);
+ __libdwfl_seterrno (dwfl->process_attach_error);
return -1;
}
return dwfl->process->pid;
Dwfl_Process *process = dwfl->process;
if (process == NULL)
{
- __libdwfl_seterrno (DWFL_E_NO_ATTACH_STATE);
+ __libdwfl_seterrno (dwfl->process_attach_error);
return -1;
}
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;
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;
{
/* 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;
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;