public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Joachim Protze <joachim.protze@wh2.tu-dresden.de>
To: gdb@sourceware.org
Subject: Re: Crashing gdb with python-prettyprinting
Date: Tue, 10 Aug 2010 10:57:00 -0000	[thread overview]
Message-ID: <4C613080.903@wh2.tu-dresden.de> (raw)
In-Reply-To: <4C5FF231.7030203@zih.tu-dresden.de>

I found a little mistake in my condensed version of the python part.
Appended the corrected versions.

-Joachim



----------------- pptest.c -----------------
enum test_enum{
  zero,
  one,
  two,
  three,
  four,
  five,
};

typedef int testint;

enum test_enum get_test_enum(int i){
  return (enum test_enum)i;
}

int main(int argc, char* argv[]){

  testint a, b, c, d, e, f;
  testint arr[]={0,1,2,3,4,5};

  a=0;
  b=1;
  c=2;
  d=3;
  e=4;
  f=5;

  return 0;
}

----------------- pptest.py -----------------
import gdb
import re

class pp_test:
    """testprinter with code interaction"""
    def __init__(self, id):
        self.id = id
    def to_string(self):
        return str(gdb.parse_and_eval("get_test_enum(%i)" % self.id))

def lookup_function (val):
    '''Look-up and return a pretty-printer that can print val.'''
    type = val.type;
    # If it points to a reference, get the reference.
    if type.code == gdb.TYPE_CODE_REF:
        type = type.target ()
    typename = str(type)
    for function in pp_dict:
        if function.search (typename):
            result = pp_dict[function] (val)
            return result
    return None

pp_dict = {}
pp_dict[re.compile('^testint$')] = lambda val: pp_test(val)
gdb.pretty_printers = []
gdb.pretty_printers.append (lookup_function)

      reply	other threads:[~2010-08-10 10:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-27 15:35 Joachim Protze
2010-07-30 19:12 ` Tom Tromey
2010-07-30 19:53   ` Petr Hluzín
2010-08-09 12:19   ` Joachim Protze
2010-08-10 10:57     ` Joachim Protze [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C613080.903@wh2.tu-dresden.de \
    --to=joachim.protze@wh2.tu-dresden.de \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).