[RFC,5/8] Style locations when setting a breakpoint

Message ID 20180906211303.11029-6-tom@tromey.com
State New
Headers show
Series
  • add terminal styling to gdb
Related show

Commit Message

Tom Tromey Sept. 6, 2018, 9:13 p.m.
say_where does not use ui-out, so function and file names printed by
it were not styled.  This patch changes say_where to use the low-level
style code directly.
---
 gdb/breakpoint.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

-- 
2.13.6

Comments

Simon Marchi Oct. 6, 2018, 4:36 p.m. | #1
On 2018-09-06 5:13 p.m., Tom Tromey wrote:
> say_where does not use ui-out, so function and file names printed by

> it were not styled.  This patch changes say_where to use the low-level

> style code directly.

> ---

>  gdb/breakpoint.c | 12 +++++++++---

>  1 file changed, 9 insertions(+), 3 deletions(-)

> 

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

> index 4e7dac51574..62824351ed6 100644

> --- a/gdb/breakpoint.c

> +++ b/gdb/breakpoint.c

> @@ -68,6 +68,7 @@

>  #include "format.h"

>  #include "thread-fsm.h"

>  #include "tid-parse.h"

> +#include "cli/cli-style.h"

>  

>  /* readline include files */

>  #include "readline/readline.h"

> @@ -12203,9 +12204,14 @@ say_where (struct breakpoint *b)

>  	  /* If there is a single location, we can print the location

>  	     more nicely.  */

>  	  if (b->loc->next == NULL)

> -	    printf_filtered (": file %s, line %d.",

> -			     symtab_to_filename_for_display (b->loc->symtab),

> -			     b->loc->line_number);

> +	    {

> +	      puts_filtered (": file ");

> +	      set_output_style (gdb_stdout, file_name_style.style ());

> +	      puts_filtered (symtab_to_filename_for_display (b->loc->symtab));

> +	      set_output_style (gdb_stdout, ui_file_style ());

> +	      printf_filtered (", line %d.",

> +			       b->loc->line_number);

> +	    }


In general, I guess we'll want to use an RAII object that resets the output style,
in case the code between the two calls throws?

Simon

Patch

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 4e7dac51574..62824351ed6 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -68,6 +68,7 @@ 
 #include "format.h"
 #include "thread-fsm.h"
 #include "tid-parse.h"
+#include "cli/cli-style.h"
 
 /* readline include files */
 #include "readline/readline.h"
@@ -12203,9 +12204,14 @@  say_where (struct breakpoint *b)
 	  /* If there is a single location, we can print the location
 	     more nicely.  */
 	  if (b->loc->next == NULL)
-	    printf_filtered (": file %s, line %d.",
-			     symtab_to_filename_for_display (b->loc->symtab),
-			     b->loc->line_number);
+	    {
+	      puts_filtered (": file ");
+	      set_output_style (gdb_stdout, file_name_style.style ());
+	      puts_filtered (symtab_to_filename_for_display (b->loc->symtab));
+	      set_output_style (gdb_stdout, ui_file_style ());
+	      printf_filtered (", line %d.",
+			       b->loc->line_number);
+	    }
 	  else
 	    /* This is not ideal, but each location may have a
 	       different file name, and this at least reflects the