libdwfl: Add dwfl_core_file_attach and dwfl_linux_proc_attach.

Rewrite __libdwfl_attach_state_for_pid and __libdwfl_attach_state_for_core
as public functions and don't call them from dwfl_linux_proc_report and
dwfl_core_file_report anymore. This lets the user attach state explicitly
independ from how the dwfl modules have been reported. Since attaching
state is an explicit action now the error can be returned directly and we
don't need to keep track of process_attach_error. dwfl_linux_proc_attach
lets the user can tell libdwfl whether caller takes care of ptrace
attaching and stopping the threads under inspection, or whether the
callback needs to take care of that and detaching again.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 23c5051..5c80e9b 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,9 @@
+2013-12-30  Mark Wielaard  <mjw@redhat.com>
+
+	* backtrace-dwarf.c (report_pid): Explicitly call
+	dwfl_linux_proc_attach and check for errors.
+	* backtrace.c (report_pid): Likewise.
+
 2013-12-21  Mark Wielaard  <mjw@redhat.com>
 
 	* backtrace.c (callback_verify): Only assert that case 5 is the last
diff --git a/tests/backtrace-dwarf.c b/tests/backtrace-dwarf.c
index aa12315..3a3e763 100644
--- a/tests/backtrace-dwarf.c
+++ b/tests/backtrace-dwarf.c
@@ -41,6 +41,12 @@
 
   if (dwfl_report_end (dwfl, NULL, NULL) != 0)
     error (2, 0, "dwfl_report_end: %s", dwfl_errmsg (-1));
+
+  result = dwfl_linux_proc_attach (dwfl, pid, false);
+  if (result < 0)
+    error (2, 0, "dwfl_linux_proc_attach: %s", dwfl_errmsg (-1));
+  else if (result > 0)
+    error (2, result, "dwfl_linux_proc_attach");
 }
 
 static Dwfl *
diff --git a/tests/backtrace.c b/tests/backtrace.c
index 8a7d6df..64f90c4 100644
--- a/tests/backtrace.c
+++ b/tests/backtrace.c
@@ -279,6 +279,12 @@
 
   if (dwfl_report_end (dwfl, NULL, NULL) != 0)
     error (2, 0, "dwfl_report_end: %s", dwfl_errmsg (-1));
+
+  result = dwfl_linux_proc_attach (dwfl, pid, false);
+  if (result < 0)
+    error (2, 0, "dwfl_linux_proc_attach: %s", dwfl_errmsg (-1));
+  else if (result > 0)
+    error (2, result, "dwfl_linux_proc_attach");
 }
 
 static Dwfl *