public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Colors in gdb
@ 2013-01-10 13:59 Surya Kiran Gullapalli
  2013-01-10 20:50 ` psyprus
  2013-01-15 17:48 ` Tom Tromey
  0 siblings, 2 replies; 8+ messages in thread
From: Surya Kiran Gullapalli @ 2013-01-10 13:59 UTC (permalink / raw)
  To: gdb

Hello,

I'm using gdb-7.5 and I'd like to see gdb printing the data in colors
(the output from print command for regular types and pretty printers
as well)

I tried the python api to do the color printing by using ansi escape
sequences. They did not work. Is it supported in gdb ? If so, How ?

Thanks in advance,
Surya

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

* Re: Colors in gdb
  2013-01-10 13:59 Colors in gdb Surya Kiran Gullapalli
@ 2013-01-10 20:50 ` psyprus
  2013-01-15 17:48 ` Tom Tromey
  1 sibling, 0 replies; 8+ messages in thread
From: psyprus @ 2013-01-10 20:50 UTC (permalink / raw)
  To: Surya Kiran Gullapalli; +Cc: gdb

theres a gdbinit floating on the web that has color config if you need
an example check link below..   best bet to get what you want is to read
the gdbinit documentation.


http://www.scribd.com/doc/6765333/Gdbinit-Color


psy


On Thu, 2013-01-10 at 19:28 +0530, Surya Kiran Gullapalli wrote:
> Hello,
> 
> I'm using gdb-7.5 and I'd like to see gdb printing the data in colors
> (the output from print command for regular types and pretty printers
> as well)
> 
> I tried the python api to do the color printing by using ansi escape
> sequences. They did not work. Is it supported in gdb ? If so, How ?
> 
> Thanks in advance,
> Surya


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

* Re: Colors in gdb
  2013-01-10 13:59 Colors in gdb Surya Kiran Gullapalli
  2013-01-10 20:50 ` psyprus
@ 2013-01-15 17:48 ` Tom Tromey
  2013-01-15 18:47   ` Kevin Pouget
  1 sibling, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2013-01-15 17:48 UTC (permalink / raw)
  To: Surya Kiran Gullapalli; +Cc: gdb

>>>>> "Surya" == Surya Kiran Gullapalli <suryakiran.gullapalli@gmail.com> writes:

Surya> I tried the python api to do the color printing by using ansi escape
Surya> sequences. They did not work. Is it supported in gdb ? If so, How ?

It isn't directly.  I wouldn't mind clean patches to implement a feature
like this, though.

Tom

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

* Re: Colors in gdb
  2013-01-15 17:48 ` Tom Tromey
@ 2013-01-15 18:47   ` Kevin Pouget
  2013-01-15 19:02     ` Tom Tromey
  0 siblings, 1 reply; 8+ messages in thread
From: Kevin Pouget @ 2013-01-15 18:47 UTC (permalink / raw)
  To: Surya Kiran Gullapalli, Tom Tromey; +Cc: gdb

On Tue, Jan 15, 2013 at 6:48 PM, Tom Tromey <tromey@redhat.com> wrote:
>
> >>>>> "Surya" == Surya Kiran Gullapalli <suryakiran.gullapalli@gmail.com> writes:
>
> Surya> I tried the python api to do the color printing by using ansi escape
> Surya> sequences. They did not work. Is it supported in gdb ? If so, How ?
>
> It isn't directly.  I wouldn't mind clean patches to implement a feature
> like this, though.
>
> Tom

Hello,

I have colors in my gdb Python prompt since quite a while, I wonder
what could be different in the context of prompt printing and pretty
printing ?

the code I use comes from [1]

Kevin

1: http://gitorious.org/misc-gdb-stuff/misc-gdb-stuff/blobs/master/misc_gdb/gaudy_prompt.py

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

* Re: Colors in gdb
  2013-01-15 18:47   ` Kevin Pouget
@ 2013-01-15 19:02     ` Tom Tromey
  2013-01-20 15:13       ` Matt Rice
  0 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2013-01-15 19:02 UTC (permalink / raw)
  To: Kevin Pouget; +Cc: Surya Kiran Gullapalli, gdb

>>>>> "Kevin" == Kevin Pouget <kevin.pouget@gmail.com> writes:

Kevin> I have colors in my gdb Python prompt since quite a while, I wonder
Kevin> what could be different in the context of prompt printing and pretty
Kevin> printing ?

For ordinary printing, there's just no place to hook into gdb.

For printing via Python pretty-printers, strings are further processed
by gdb before printing, and in particular the escape sequences are
turned into plain text.


For backtraces it could be done by writing one's own "bt" in Python.  I
vaguely recall that somebody did this once.

Tom

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

* Re: Colors in gdb
  2013-01-15 19:02     ` Tom Tromey
@ 2013-01-20 15:13       ` Matt Rice
  2013-01-20 15:29         ` Robert Dewar
  0 siblings, 1 reply; 8+ messages in thread
From: Matt Rice @ 2013-01-20 15:13 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Kevin Pouget, Surya Kiran Gullapalli, gdb

[-- Attachment #1: Type: text/plain, Size: 2950 bytes --]

On Tue, Jan 15, 2013 at 11:02 AM, Tom Tromey <tromey@redhat.com> wrote:
>>>>>> "Kevin" == Kevin Pouget <kevin.pouget@gmail.com> writes:
>
> Kevin> I have colors in my gdb Python prompt since quite a while, I wonder
> Kevin> what could be different in the context of prompt printing and pretty
> Kevin> printing ?
>
> For ordinary printing, there's just no place to hook into gdb.

its worth noting that the standard python print function works with
escape sequences,

> For printing via Python pretty-printers, strings are further processed
> by gdb before printing, and in particular the escape sequences are
> turned into plain text.

attached is a silly modification to the example pretty printer from the docs[1]:
it contains an additional method 'to_color_string', tested like:

py print gdb.default_visualizer(gdb.parse_and_eval("x")).to_color_string()

which could be easily shoved into a 'define'
or something (would be nice if it fell back to normal to_string method)

maybe i'm old in not liking the idea of making these work with the
standard 'print' command, because the escape sequences are terminal
type dependent, which is IMO fine for a prompt set by a gdbinit, but
less so for a pretty printer distributed with a library...
this opinion is only strengthened by considering a std::string
containing an escape sequence.

until there is a common cross platform escape sequence generator deal at least
(IIRC there is one, but it either requires a newer python, and/or is a
3rd party module not a standard python one)

so I probably should have included something like the 'color_dict'
from gaudy_prompt, as an argument to to_color_string, with a default
argument of a 'no_colors' dict, that way one could just implement
to_string() as calling to_color_string, there are some issues in that
the gaudy_prompt color dicts generate '\[ and \] as
\001 and \002 escape sequences to inform readline about non-printing
characters, these escape sequences get printed as junk since py print
doesn't grok them.  I suppose they should be replaced with classes
(readline colors class subclassing a colors class)

i'm fairly steadfast that just having random escape sequences embedded
in pretty printers as i implemented it is entirely the wrong thing to
do, and we need some level of indirection that can be set in .gdbinit
that pretty printers can query

it would probably be a good idea to settle on a declaration for a
to_color_string method so it isn't done totally ad-hoc for each
pretty-printer that wants to do so.
I'll leave coming up with that declaration to someone actually
implementing one that is not a silly example...

FWIW running the pretty printers this way doesn't set the gdb numbered
convenience variable, like print does.

since the pretty printing API needs to remain compatible, please keep
us in the loop :)

[1] http://sourceware.org/gdb/current/onlinedocs/gdb/Writing-a-Pretty_002dPrinter.html#Writing-a-Pretty_002dPrinter

[-- Attachment #2: foo.py --]
[-- Type: application/octet-stream, Size: 1119 bytes --]

from curses import *

def colorize(str, color):
  return tparm(tigetstr("setaf"), color) + str + tigetstr("sgr0")

class fooPrinter:
  """Print a foo object."""
     
  def __init__(self, val):
     self.val = val
     
  def to_string(self):
     return ("a=<" + str(self.val["a"]) +
             "> b=<" + str(self.val["b"]) + ">")

  def to_color_string(self):
     return (colorize("a", COLOR_RED) + colorize("=", COLOR_BLUE) + colorize("<", COLOR_GREEN) + str(self.val["a"]) +
             colorize(">", COLOR_GREEN) + "b=<" + str(self.val["b"]) + ">")
     
class barPrinter:
  """Print a bar object."""
     
  def __init__(self, val):
     self.val = val
     
  def to_string(self):
     return ("x=<" + str(self.val["x"]) +
                     "> y=<" + str(self.val["y"]) + ">")
import gdb.printing
     
def build_pretty_printer():
   pp = gdb.printing.RegexpCollectionPrettyPrinter("my_library")
   pp.add_printer('foo', '^foo$', fooPrinter)
   pp.add_printer('bar', '^bar$', barPrinter)
   return pp

gdb.printing.register_pretty_printer(gdb.current_objfile(),build_pretty_printer())
setupterm(None, 1);

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

* Re: Colors in gdb
  2013-01-20 15:13       ` Matt Rice
@ 2013-01-20 15:29         ` Robert Dewar
  2013-01-20 15:39           ` shawn wilson
  0 siblings, 1 reply; 8+ messages in thread
From: Robert Dewar @ 2013-01-20 15:29 UTC (permalink / raw)
  To: Matt Rice; +Cc: Tom Tromey, Kevin Pouget, Surya Kiran Gullapalli, gdb

On 1/20/2013 10:13 AM, Matt Rice wrote:

> maybe i'm old in not liking the idea of making these work with the
> standard 'print' command, because the escape sequences are terminal
> type dependent, which is IMO fine for a prompt set by a gdbinit, but
> less so for a pretty printer distributed with a library...
> this opinion is only strengthened by considering a std::string
> containing an escape sequence.

I strongly dislike ANY color stuff creeping into gdb output. Color
stuff is a big menace when stuff is saved to files, or pasted and
emailed etc etc.

> i'm fairly steadfast that just having random escape sequences embedded
> in pretty printers as i implemented it is entirely the wrong thing to
> do, and we need some level of indirection that can be set in .gdbinit
> that pretty printers can query

I agree

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

* Re: Colors in gdb
  2013-01-20 15:29         ` Robert Dewar
@ 2013-01-20 15:39           ` shawn wilson
  0 siblings, 0 replies; 8+ messages in thread
From: shawn wilson @ 2013-01-20 15:39 UTC (permalink / raw)
  To: Robert Dewar
  Cc: Matt Rice, Tom Tromey, Kevin Pouget, Surya Kiran Gullapalli, gdb

On Sun, Jan 20, 2013 at 10:29 AM, Robert Dewar <dewar@adacore.com> wrote:
> On 1/20/2013 10:13 AM, Matt Rice wrote:
>
>> maybe i'm old in not liking the idea of making these work with the
>> standard 'print' command, because the escape sequences are terminal
>> type dependent, which is IMO fine for a prompt set by a gdbinit, but
>> less so for a pretty printer distributed with a library...
>> this opinion is only strengthened by considering a std::string
>> containing an escape sequence.
>
>
> I strongly dislike ANY color stuff creeping into gdb output. Color
> stuff is a big menace when stuff is saved to files, or pasted and
> emailed etc etc.
>
>

Most programs will properly deal with colors (ANSI) if you let them. ie, less -R
Though, I agree, color should *never* be the default.

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

end of thread, other threads:[~2013-01-20 15:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-10 13:59 Colors in gdb Surya Kiran Gullapalli
2013-01-10 20:50 ` psyprus
2013-01-15 17:48 ` Tom Tromey
2013-01-15 18:47   ` Kevin Pouget
2013-01-15 19:02     ` Tom Tromey
2013-01-20 15:13       ` Matt Rice
2013-01-20 15:29         ` Robert Dewar
2013-01-20 15:39           ` shawn wilson

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).