Add file name styling to "info sharedlibrary"

Message ID 20190513162651.18605-1-tromey@adacore.com
State New
Headers show
Series
  • Add file name styling to "info sharedlibrary"
Related show

Commit Message

Tom Tromey May 13, 2019, 4:26 p.m.
This changes "info sharedlibrary" to add styling to the file name.

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-05-13  Tom Tromey  <tromey@adacore.com>

	* solib.c (info_sharedlibrary_command): Style the file name.

gdb/testsuite/ChangeLog
2019-05-13  Tom Tromey  <tromey@adacore.com>

	* gdb.base/info-shared.exp (check_info_shared): Add "info shared"
	styling test.
---
 gdb/ChangeLog                          |  4 ++++
 gdb/solib.c                            |  2 +-
 gdb/testsuite/ChangeLog                |  5 +++++
 gdb/testsuite/gdb.base/info-shared.exp | 24 ++++++++++++++++++++++++
 4 files changed, 34 insertions(+), 1 deletion(-)

-- 
2.20.1

Comments

Sergio Durigan Junior May 13, 2019, 6:17 p.m. | #1
On Monday, May 13 2019, Tom Tromey wrote:

> This changes "info sharedlibrary" to add styling to the file name.


Thanks for doing this.  The patch is almost obvious :-), and it makes
sense for me.

I've been left wondering if we shouldn't have a more automated way to
test styled output.  Seeing all those \033\\\[... makes me cringe a bit
;-).

Thanks!

> Tested on x86-64 Fedora 29.

>

> gdb/ChangeLog

> 2019-05-13  Tom Tromey  <tromey@adacore.com>

>

> 	* solib.c (info_sharedlibrary_command): Style the file name.

>

> gdb/testsuite/ChangeLog

> 2019-05-13  Tom Tromey  <tromey@adacore.com>

>

> 	* gdb.base/info-shared.exp (check_info_shared): Add "info shared"

> 	styling test.

> ---

>  gdb/ChangeLog                          |  4 ++++

>  gdb/solib.c                            |  2 +-

>  gdb/testsuite/ChangeLog                |  5 +++++

>  gdb/testsuite/gdb.base/info-shared.exp | 24 ++++++++++++++++++++++++

>  4 files changed, 34 insertions(+), 1 deletion(-)

>

> diff --git a/gdb/solib.c b/gdb/solib.c

> index 25555af2939..e0b1a921f82 100644

> --- a/gdb/solib.c

> +++ b/gdb/solib.c

> @@ -1104,7 +1104,7 @@ info_sharedlibrary_command (const char *pattern, int from_tty)

>  	else

>  	  uiout->field_string ("syms-read", so->symbols_loaded ? "Yes" : "No");

>  

> -	uiout->field_string ("name", so->so_name);

> +	uiout->field_string ("name", so->so_name, ui_out_style_kind::FILE);

>  

>  	uiout->text ("\n");

>        }

> diff --git a/gdb/testsuite/gdb.base/info-shared.exp b/gdb/testsuite/gdb.base/info-shared.exp

> index eb5ee9562ef..e1314bf5dd7 100644

> --- a/gdb/testsuite/gdb.base/info-shared.exp

> +++ b/gdb/testsuite/gdb.base/info-shared.exp

> @@ -144,3 +144,27 @@ check_info_shared "info sharedlibrary #7" 0 1

>  # Run to the last stop and check that both libraries are gone.

>  gdb_continue_to_breakpoint "library unload #2" "\\.?stop .*"

>  check_info_shared "info sharedlibrary #8" 0 0

> +

> +with_test_prefix styled {

> +    save_vars { env(TERM) } {

> +	# We need an ANSI-capable terminal to get the output.

> +	setenv TERM ansi

> +

> +	clean_restart $testfile

> +

> +	gdb_test_no_output "set style enabled off"

> +	if {![runto_main]} {

> +	    return 0

> +	}

> +	gdb_breakpoint "stop"

> +	gdb_continue_to_breakpoint "library load #1" "\\.?stop .*"

> +

> +	# Simple test for "info sharedlibrary" styling.  Look for styled

> +	# addresses and file name.

> +	set addr "\033\\\[34m${hex}\033\\\[m"

> +	set sofile "\033\\\[32m\[^\033\]+\033\\\[m"

> +	gdb_test_no_output "set style enabled on"

> +	gdb_test "info sharedlibrary" \

> +	    "$addr\[ \t\]+$addr.*$sofile\r\n.*"

> +    }

> +}

> -- 

> 2.20.1


-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/
Tom Tromey May 14, 2019, 1:42 p.m. | #2
>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:


Sergio> Thanks for doing this.  The patch is almost obvious :-), and it makes
Sergio> sense for me.

Thanks, I'm going to check it in.

Sergio> I've been left wondering if we shouldn't have a more automated way to
Sergio> test styled output.  Seeing all those \033\\\[... makes me cringe a bit
Sergio> ;-).

Good point, I'll send a follow-up patch for this.

Tom
Sergio Durigan Junior May 14, 2019, 5:08 p.m. | #3
On Tuesday, May 14 2019, Tom Tromey wrote:

>>>>>> "Sergio" == Sergio Durigan Junior <sergiodj@redhat.com> writes:

> Sergio> I've been left wondering if we shouldn't have a more automated way to

> Sergio> test styled output.  Seeing all those \033\\\[... makes me cringe a bit

> Sergio> ;-).

>

> Good point, I'll send a follow-up patch for this.


Oh, great, thanks Tom.  FWIW, I wasn't trying to force you to do that
right; it was just a thought that occurred to me.

-- 
Sergio
GPG key ID: 237A 54B1 0287 28BF 00EF  31F4 D0EB 7628 65FC 5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

Patch

diff --git a/gdb/solib.c b/gdb/solib.c
index 25555af2939..e0b1a921f82 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -1104,7 +1104,7 @@  info_sharedlibrary_command (const char *pattern, int from_tty)
 	else
 	  uiout->field_string ("syms-read", so->symbols_loaded ? "Yes" : "No");
 
-	uiout->field_string ("name", so->so_name);
+	uiout->field_string ("name", so->so_name, ui_out_style_kind::FILE);
 
 	uiout->text ("\n");
       }
diff --git a/gdb/testsuite/gdb.base/info-shared.exp b/gdb/testsuite/gdb.base/info-shared.exp
index eb5ee9562ef..e1314bf5dd7 100644
--- a/gdb/testsuite/gdb.base/info-shared.exp
+++ b/gdb/testsuite/gdb.base/info-shared.exp
@@ -144,3 +144,27 @@  check_info_shared "info sharedlibrary #7" 0 1
 # Run to the last stop and check that both libraries are gone.
 gdb_continue_to_breakpoint "library unload #2" "\\.?stop .*"
 check_info_shared "info sharedlibrary #8" 0 0
+
+with_test_prefix styled {
+    save_vars { env(TERM) } {
+	# We need an ANSI-capable terminal to get the output.
+	setenv TERM ansi
+
+	clean_restart $testfile
+
+	gdb_test_no_output "set style enabled off"
+	if {![runto_main]} {
+	    return 0
+	}
+	gdb_breakpoint "stop"
+	gdb_continue_to_breakpoint "library load #1" "\\.?stop .*"
+
+	# Simple test for "info sharedlibrary" styling.  Look for styled
+	# addresses and file name.
+	set addr "\033\\\[34m${hex}\033\\\[m"
+	set sofile "\033\\\[32m\[^\033\]+\033\\\[m"
+	gdb_test_no_output "set style enabled on"
+	gdb_test "info sharedlibrary" \
+	    "$addr\[ \t\]+$addr.*$sofile\r\n.*"
+    }
+}