[2/5] gdb/testsuite: Fix style.exp failures on targets without libopcodes styling

Message ID 20230419193046.548783-3-sandra@codesourcery.com
State New
Headers
Series gdb/testsuite: Miscellaneous fixes |

Commit Message

Sandra Loosemore April 19, 2023, 7:30 p.m. UTC
  Do not expect disassembler output to be styled by libopcodes if GDB
reports the target does not support that.
---
 gdb/testsuite/gdb.base/style.exp | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)
  

Comments

Tom Tromey April 21, 2023, 2:37 p.m. UTC | #1
>>>>> "Sandra" == Sandra Loosemore <sandra@codesourcery.com> writes:

Sandra> Do not expect disassembler output to be styled by libopcodes if GDB
Sandra> reports the target does not support that.

Sandra> +# Check whether libopcodes styling is supported for this target.
Sandra> +set have_libopcodes_styling 1
Sandra> +proc test_for_libopcodes_styling {} {
Sandra> +  global binfile
Sandra> +  global have_libopcodes_styling
Sandra> +  clean_restart ${binfile}
Sandra> +
Sandra> +  gdb_test_multiple "maint set libopcodes-styling enabled on" "" {
Sandra> +      -re "^maint set libopcodes-styling enabled on\r\n"
Sandra> +      {

The Tcl style usually puts the "{" at the end of the previous line.

Here it may not matter, so it's just stylistic.  However due to Tcl's
unusual lexing, it does matter in some spots, so IMO it's best to be
consistent.

Tcl represents the ultimate achievement of a certain style -- they
managed to enforce "{" placement in the language.  If only GNU were so
enterprising.

Tom
  
Sandra Loosemore April 21, 2023, 7:15 p.m. UTC | #2
On 4/21/23 08:37, Tom Tromey wrote:
>>>>>> "Sandra" == Sandra Loosemore <sandra@codesourcery.com> writes:
> 
> Sandra> Do not expect disassembler output to be styled by libopcodes if GDB
> Sandra> reports the target does not support that.
> 
> Sandra> +# Check whether libopcodes styling is supported for this target.
> Sandra> +set have_libopcodes_styling 1
> Sandra> +proc test_for_libopcodes_styling {} {
> Sandra> +  global binfile
> Sandra> +  global have_libopcodes_styling
> Sandra> +  clean_restart ${binfile}
> Sandra> +
> Sandra> +  gdb_test_multiple "maint set libopcodes-styling enabled on" "" {
> Sandra> +      -re "^maint set libopcodes-styling enabled on\r\n"
> Sandra> +      {
> 
> The Tcl style usually puts the "{" at the end of the previous line.
> 
> Here it may not matter, so it's just stylistic.  However due to Tcl's
> unusual lexing, it does matter in some spots, so IMO it's best to be
> consistent.
> 
> Tcl represents the ultimate achievement of a certain style -- they
> managed to enforce "{" placement in the language.  If only GNU were so
> enterprising.

Ack, I will fix this and resubmit this piece.  I don't write TCL often 
enough to remember all these things....

-Sandra
  

Patch

diff --git a/gdb/testsuite/gdb.base/style.exp b/gdb/testsuite/gdb.base/style.exp
index 60f909e2402..d6ce48237e4 100644
--- a/gdb/testsuite/gdb.base/style.exp
+++ b/gdb/testsuite/gdb.base/style.exp
@@ -24,6 +24,29 @@  if {[build_executable "failed to build" $testfile $srcfile {debug macros}]} {
     return -1
 }
 
+# Check whether libopcodes styling is supported for this target.
+set have_libopcodes_styling 1
+proc test_for_libopcodes_styling {} {
+  global binfile
+  global have_libopcodes_styling
+  clean_restart ${binfile}
+
+  gdb_test_multiple "maint set libopcodes-styling enabled on" "" {
+      -re "^maint set libopcodes-styling enabled on\r\n"
+      {
+	  exp_continue
+      }
+      -re "Use of libopcodes styling not supported on architecture \[^\r\n\]+\r\n"
+      {
+	  set have_libopcodes_styling 0
+	  exp_continue
+      }
+     -re "^$::gdb_prompt $"
+      {
+      }
+  }
+}
+
 # The tests in this file are run multiple times with GDB's styles
 # disabled one at a time.  This variable is the style that is
 # currently disabled.
@@ -68,6 +91,7 @@  proc clean_restart_and_disable { prefix args } {
 proc run_style_tests { } {
     global testfile srcfile hex binfile
     global currently_disabled_style decimal hex
+    global have_libopcodes_styling
 
     save_vars { env(TERM) } {
 	# We need an ANSI-capable terminal to get the output.
@@ -195,7 +219,7 @@  proc run_style_tests { } {
 	# symbol will be styled.  However, if pygments is not being
 	# used then we can know how the symbol name will be styled.
 	set main [limited_style main function]
-	if { $::python_disassembly_styling } {
+	if { $::python_disassembly_styling || !$have_libopcodes_styling } {
 	    set func "some_called_function"
 	} else {
 	    set func [limited_style some_called_function function]
@@ -495,6 +519,9 @@  if {[allow_python_tests] && [gdb_py_module_available "pygments"]} {
     set python_disassembly_styling false
 }
 
+# Check to see if libopcodes styling is available for this target
+test_for_libopcodes_styling
+
 # Run tests with all styles in their default state.
 with_test_prefix "all styles enabled" {
     run_style_tests