Check tracefile is generated by binary execution

Message ID 1395733933-9366-1-git-send-email-yao@codesourcery.com
State Committed
Headers

Commit Message

Yao Qi March 25, 2014, 7:52 a.m. UTC
  In gdb.trace/tfile.exp, we execute binary to generate tracefile,

  remote_exec target "$binfile"

however, this fails on bare metal target.  This patch is to
handle binary execution failure by running binary in GDB.
The binary will do some io operation to generate tracefile, so
we need a check 'target_info exists gdb,nofileio'.

This patch is to check whether tracefile is generated.  tfile.exp can
be skipped if generation is failed, while test_tfind_tfile in
mi-traceframe-changed.exp is skipped if generated failed.  The rest of
the mi-traceframe-changed.exp can still be executed, because on some
bare metal targets, the remote stub may support tracepoint but doesn't
support fileio.

This patch is tested on nios2-elf and arm-none-eabi.

gdb/testsuite:

2014-03-25  Yao Qi  <yao@codesourcery.com>

	* lib/trace-support.exp (generate_tracefile): New procedure.
	* gdb.trace/tfile.exp: Skip the test if generate_tracefile
	return 0.
	* gdb.trace/mi-traceframe-changed.exp: Invoke test_tfind_tfile
	if generate_tracefile returns 1.
---
 gdb/testsuite/gdb.trace/mi-traceframe-changed.exp |   20 ++++++++-------
 gdb/testsuite/gdb.trace/tfile.exp                 |   10 ++++----
 gdb/testsuite/lib/trace-support.exp               |   27 +++++++++++++++++++++
 3 files changed, 43 insertions(+), 14 deletions(-)
  

Comments

Yao Qi April 1, 2014, 2:23 a.m. UTC | #1
On 03/25/2014 03:52 PM, Yao Qi wrote:
> In gdb.trace/tfile.exp, we execute binary to generate tracefile,
> 
>   remote_exec target "$binfile"
> 
> however, this fails on bare metal target.  This patch is to
> handle binary execution failure by running binary in GDB.
> The binary will do some io operation to generate tracefile, so
> we need a check 'target_info exists gdb,nofileio'.
> 
> This patch is to check whether tracefile is generated.  tfile.exp can
> be skipped if generation is failed, while test_tfind_tfile in
> mi-traceframe-changed.exp is skipped if generated failed.  The rest of
> the mi-traceframe-changed.exp can still be executed, because on some
> bare metal targets, the remote stub may support tracepoint but doesn't
> support fileio.
> 
> This patch is tested on nios2-elf and arm-none-eabi.
> 
> gdb/testsuite:
> 
> 2014-03-25  Yao Qi  <yao@codesourcery.com>
> 
> 	* lib/trace-support.exp (generate_tracefile): New procedure.
> 	* gdb.trace/tfile.exp: Skip the test if generate_tracefile
> 	return 0.
> 	* gdb.trace/mi-traceframe-changed.exp: Invoke test_tfind_tfile
> 	if generate_tracefile returns 1.

Ping.  https://sourceware.org/ml/gdb-patches/2014-03/msg00591.html
  
Yao Qi April 10, 2014, 2:55 a.m. UTC | #2
On 04/01/2014 10:23 AM, Yao Qi wrote:
> On 03/25/2014 03:52 PM, Yao Qi wrote:
>> In gdb.trace/tfile.exp, we execute binary to generate tracefile,
>>
>>   remote_exec target "$binfile"
>>
>> however, this fails on bare metal target.  This patch is to
>> handle binary execution failure by running binary in GDB.
>> The binary will do some io operation to generate tracefile, so
>> we need a check 'target_info exists gdb,nofileio'.
>>
>> This patch is to check whether tracefile is generated.  tfile.exp can
>> be skipped if generation is failed, while test_tfind_tfile in
>> mi-traceframe-changed.exp is skipped if generated failed.  The rest of
>> the mi-traceframe-changed.exp can still be executed, because on some
>> bare metal targets, the remote stub may support tracepoint but doesn't
>> support fileio.
>>
>> This patch is tested on nios2-elf and arm-none-eabi.
>>
>> gdb/testsuite:
>>
>> 2014-03-25  Yao Qi  <yao@codesourcery.com>
>>
>> 	* lib/trace-support.exp (generate_tracefile): New procedure.
>> 	* gdb.trace/tfile.exp: Skip the test if generate_tracefile
>> 	return 0.
>> 	* gdb.trace/mi-traceframe-changed.exp: Invoke test_tfind_tfile
>> 	if generate_tracefile returns 1.
> 
> Ping.  https://sourceware.org/ml/gdb-patches/2014-03/msg00591.html
> 

Ping^2.
  
Stan Shebs April 21, 2014, 11:03 p.m. UTC | #3
On 3/25/14 12:52 AM, Yao Qi wrote:
> In gdb.trace/tfile.exp, we execute binary to generate tracefile,
> 
>   remote_exec target "$binfile"
> 
> however, this fails on bare metal target.  This patch is to
> handle binary execution failure by running binary in GDB.
> The binary will do some io operation to generate tracefile, so
> we need a check 'target_info exists gdb,nofileio'.
> 
> This patch is to check whether tracefile is generated.  tfile.exp can
> be skipped if generation is failed, while test_tfind_tfile in
> mi-traceframe-changed.exp is skipped if generated failed.  The rest of
> the mi-traceframe-changed.exp can still be executed, because on some
> bare metal targets, the remote stub may support tracepoint but doesn't
> support fileio.
> 
> This patch is tested on nios2-elf and arm-none-eabi.

This is OK to push, thanks!

OK, one nit:

> -remote_exec target "$binfile"
> +if { ![generate_tracefile $binfile] } {
> +    unsupported "Unable to generate tfile"

"trace file" instead of "tfile" would be clearer to a test-running
person who is not familiar with the details of tracepoint operations.

Stan
stan@codesourcery.com
  
Yao Qi April 22, 2014, 2:20 a.m. UTC | #4
On 04/22/2014 07:03 AM, Stan Shebs wrote:
>> -remote_exec target "$binfile"
>> > +if { ![generate_tracefile $binfile] } {
>> > +    unsupported "Unable to generate tfile"
> "trace file" instead of "tfile" would be clearer to a test-running
> person who is not familiar with the details of tracepoint operations.

OK, fixed.  Patch is pushed in.
  

Patch

diff --git a/gdb/testsuite/gdb.trace/mi-traceframe-changed.exp b/gdb/testsuite/gdb.trace/mi-traceframe-changed.exp
index 4bcf379..a4c06b0 100644
--- a/gdb/testsuite/gdb.trace/mi-traceframe-changed.exp
+++ b/gdb/testsuite/gdb.trace/mi-traceframe-changed.exp
@@ -43,14 +43,6 @@  if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" \
 remote_file host delete $tfile_basic
 remote_file target delete $tfile_basic
 
-remote_exec target "$binfile"
-
-if {!$purely_local} {
-    # Copy tracefile from target to host.
-    remote_download host [remote_upload target tfile-basic.tf] \
-	tfile-basic.tf
-}
-
 proc test_tfind_tfile { } {
     with_test_prefix "tfile" {
 	global binfile
@@ -88,7 +80,17 @@  proc test_tfind_tfile { } {
     }
 }
 
-test_tfind_tfile
+# If tracefile is generated successfully, copy tracefile to host and
+# run tests.
+if [generate_tracefile $binfile] {
+    if {!$purely_local} {
+	# Copy tracefile from target to host.
+	remote_download host [remote_upload target tfile-basic.tf] \
+	    tfile-basic.tf
+    }
+
+    test_tfind_tfile
+}
 
 # Change to a different test case in order to run it on target, and get
 # several traceframes.
diff --git a/gdb/testsuite/gdb.trace/tfile.exp b/gdb/testsuite/gdb.trace/tfile.exp
index dcf807a..2918eba 100644
--- a/gdb/testsuite/gdb.trace/tfile.exp
+++ b/gdb/testsuite/gdb.trace/tfile.exp
@@ -34,8 +34,6 @@  if {![is_remote host] && ![is_remote target]} {
     set purely_local 0
 }
 
-gdb_exit
-gdb_start
 standard_testfile
 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
 	  executable \
@@ -45,7 +43,6 @@  if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
     untested ${testfile}.exp
     return -1
 }
-gdb_reinitialize_dir $srcdir/$subdir
 
 # Make sure we are starting fresh.
 remote_file host delete $tfile_basic
@@ -53,14 +50,17 @@  remote_file host delete $tfile_error
 remote_file target delete $tfile_basic
 remote_file target delete $tfile_error
 
-remote_exec target "$binfile"
+if { ![generate_tracefile $binfile] } {
+    unsupported "Unable to generate tfile"
+}
+
 if {!$purely_local} {
     # Copy tracefile from target to host through build.
     remote_download host [remote_upload target tfile-basic.tf] tfile-basic.tf
     remote_download host [remote_upload target tfile-error.tf] tfile-error.tf
 }
 
-gdb_load $binfile
+clean_restart $binfile
 
 # Program has presumably exited, now target a trace file it created.
 
diff --git a/gdb/testsuite/lib/trace-support.exp b/gdb/testsuite/lib/trace-support.exp
index 34c01cb..a076bac 100644
--- a/gdb/testsuite/lib/trace-support.exp
+++ b/gdb/testsuite/lib/trace-support.exp
@@ -327,3 +327,30 @@  proc get_in_proc_agent {} {
 	return $objdir/../gdbserver/libinproctrace.so
     }
 }
+
+# Execute BINFILE on target to generate tracefile.  Return 1 if
+# tracefile is generated successfully, return 0 otherwise.
+
+proc generate_tracefile { binfile } {
+    set status [remote_exec target "$binfile"]
+
+    if { [lindex $status 0] != 0 } {
+	# Failed to execute $binfile, for example on bare metal targets.
+	# Alternatively, load the binary and run it.  If target doesn't
+	# have fileio capabilities, tracefile can't be generated.  Skip
+	# the test.
+	if [target_info exists gdb,nofileio] {
+	    return 0
+	}
+
+	clean_restart $binfile
+
+	if ![runto_main] then {
+	    return 0
+	}
+	gdb_continue_to_end "" continue 1
+	gdb_exit
+    }
+
+    return 1
+}