public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [rfc] Fix PR 18208: update /proc/pid/coredump_filter by c code
@ 2015-04-24 15:29 Yao Qi
  2015-05-06 16:12 ` Pedro Alves
  0 siblings, 1 reply; 13+ messages in thread
From: Yao Qi @ 2015-04-24 15:29 UTC (permalink / raw)
  To: gdb-patches

From: Yao Qi <yao.qi@linaro.org>

Hi,
We see some fails in gdb.base/coredump-filter.exp when we do remote
gdbserver testing, like what I did for arm/aarch64 linux testing or
run it with board file remote-gdbserver-on-localhost

 $ make check RUNTESTFLAGS='--target_board=remote-gdbserver-on-localhost coredump-filter.exp'

we find that this line in the test doesn't work as expected,

 remote_exec target "sh -c \"echo $filter_flag > /proc/$ipid/coredump_filter\""

although such pattern has been used in gdb testsuite somewhere else,
but the special thing here is that we redirect the output to
/proc/$ipid/coredump_filter on the remote target.  DejaGNU will
redirect the output from the remote target to local, and looks tcl
gets confused by these two redirection.

After trying pass different parameters to remote_exec and hacking
remote_exec/rsh_exec/local_exec, I got no success, I decide
to give up, and try to update /proc/$ipid/coredump_filter by the c
code directly.

This patch adds a c function set_coredump_filter to update
coredump_filter, and GDB calls it.

Now this test passes on boardfile unix, native-gdbserver and
remote-gdbserver-on-localhost.  It also passes my board files for arm
and aarch64 testing.

gdb/testsuite:

2015-04-24  Yao Qi  <yao.qi@linaro.org>

	PR gdb/18208
	* gdb.base/coredump-filter.c (set_coredump_filter): New function.
	* gdb.base/coredump-filter.exp (do_save_core): Call inferior
	function set_coredump_filter, and remove remote_exec call.
	Remove argument ipid.  Callers update.
	(top level): Don't get inferior's PID.
---
 gdb/testsuite/gdb.base/coredump-filter.c   | 16 ++++++++++++++++
 gdb/testsuite/gdb.base/coredump-filter.exp | 15 ++++++---------
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/gdb/testsuite/gdb.base/coredump-filter.c b/gdb/testsuite/gdb.base/coredump-filter.c
index 192c469..18b9d9c 100644
--- a/gdb/testsuite/gdb.base/coredump-filter.c
+++ b/gdb/testsuite/gdb.base/coredump-filter.c
@@ -59,3 +59,19 @@ main (int argc, char *argv[])
 
   return 0; /* break-here */
 }
+
+/* Write V to /proc/self/coredump_filter.  Return 0 on success.  */
+
+int
+set_coredump_filter (int v)
+{
+  FILE *f = fopen("/proc/self/coredump_filter", "r+");
+
+  if (f == NULL)
+    return 1;
+
+  fprintf(f, "%#x", v);
+
+  fclose (f);
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/coredump-filter.exp b/gdb/testsuite/gdb.base/coredump-filter.exp
index f872de0..dbebaf0 100644
--- a/gdb/testsuite/gdb.base/coredump-filter.exp
+++ b/gdb/testsuite/gdb.base/coredump-filter.exp
@@ -34,10 +34,10 @@ if { ![runto_main] } {
 gdb_breakpoint [gdb_get_line_number "break-here"]
 gdb_continue_to_breakpoint "break-here" ".* break-here .*"
 
-proc do_save_core { filter_flag core ipid } {
-    verbose -log "writing $filter_flag to /proc/$ipid/coredump_filter"
+proc do_save_core { filter_flag core } {
+    verbose -log "writing $filter_flag to /proc/<inferior pid>/coredump_filter"
 
-    remote_exec target "sh -c \"echo $filter_flag > /proc/$ipid/coredump_filter\""
+    gdb_test "p set_coredump_filter ($filter_flag)" " = 0"
 
     # Generate a corefile.
     gdb_gcore_cmd "$core" "save corefile"
@@ -146,11 +146,8 @@ if { !$core_supported } {
     return -1
 }
 
-# Get the inferior's PID.
-set infpid ""
 gdb_test_multiple "info inferiors" "getting inferior pid" {
-    -re "process \($decimal\).*\r\n$gdb_prompt $" {
-	set infpid $expect_out(1,string)
+    -re "process $decimal.*\r\n$gdb_prompt $" {
     }
     -re "Remote target.*$gdb_prompt $" {
 	# If the target does not provide PID information (like usermode QEMU),
@@ -184,12 +181,12 @@ foreach item $all_anon_corefiles {
 # Generate corefiles for the "anon" case.
 foreach item $all_anon_corefiles {
     with_test_prefix "saving corefile for [lindex $item 0]" {
-	do_save_core [lindex $item 1] [subst [lindex $item 2]] $infpid
+	do_save_core [lindex $item 1] [subst [lindex $item 2]]
     }
 }
 
 with_test_prefix "saving corefile for non-Private-Shared-Anon-File" {
-    do_save_core "0x60" $non_private_shared_anon_file_core $infpid
+    do_save_core "0x60" $non_private_shared_anon_file_core
 }
 
 clean_restart $testfile
-- 
1.9.1

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2015-05-08 17:23 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-24 15:29 [rfc] Fix PR 18208: update /proc/pid/coredump_filter by c code Yao Qi
2015-05-06 16:12 ` Pedro Alves
2015-05-06 16:43   ` Luis Machado
2015-05-07  9:05     ` Yao Qi
2015-05-07 10:45       ` Luis Machado
2015-05-07 14:01         ` Luis Machado
2015-05-07 17:05           ` [PATCH] Fix coredump-filter.exp by correctly unsetting array (was: Re: [rfc] Fix PR 18208: update /proc/pid/coredump_filter by c code) Sergio Durigan Junior
2015-05-08 11:57             ` [PATCH] Fix coredump-filter.exp by correctly unsetting array Yao Qi
2015-05-08 17:23               ` Sergio Durigan Junior
2015-05-08 11:41           ` [rfc] Fix PR 18208: update /proc/pid/coredump_filter by c code Yao Qi
2015-05-08 14:40           ` Pedro Alves
2015-05-08 14:47             ` Luis Machado
2015-05-08  5:09   ` Sergio Durigan Junior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).