From 9951ad78c80e144c166a7d476cad7ffdf84332a9 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Wed, 13 Aug 2014 14:55:49 -0700 Subject: Debug debugging --- src/strings/astring.py | 35 +++++++++++++++++++++++++++++++---- src/strings/literal.py | 23 +++++++++++++++++++++++ src/strings/rstring.py | 44 +++++++++++++++++++++++++++++++++++--------- src/strings/vstring.py | 13 +++++++++++-- src/strings/xstring.py | 19 ++++++++++++++----- src/strings/zstring.py | 19 ++++++++++++++----- 6 files changed, 128 insertions(+), 25 deletions(-) create mode 100644 src/strings/literal.py (limited to 'src/strings') diff --git a/src/strings/astring.py b/src/strings/astring.py index 063e721..47e4e55 100644 --- a/src/strings/astring.py +++ b/src/strings/astring.py @@ -1,6 +1,4 @@ class AString(object): - ''' print an AString - ''' __slots__ = ('_value') name = 'tmwa::strings::AString' enabled = True @@ -14,11 +12,40 @@ class AString(object): def children(self): b = self._value['data'] s = self._value['special'] + b = b[0].address if s == 255: - b = b.cast(gdb.lookup_type('strings::RString').pointer()) + b = b.cast(gdb.lookup_type('tmwa::strings::RString').pointer()) yield 'allocated', b.dereference() else: - b = b.cast(b.type.target().pointer()) n = 255 d = n - s yield 'contained', b.lazy_string(length=d) + + str256 = '0123456789abcdef' * 16 + + tests = [ + ('tmwa::AString(""_s)', '{allocated = ""}'), + ('tmwa::AString(tmwa::ZString(""_s))', '{allocated = ""}'), + ('tmwa::AString(tmwa::RString(""_s))', '{allocated = ""}'), + ('tmwa::AString(tmwa::RString(tmwa::ZString(""_s)))', '{allocated = ""}'), + ('tmwa::AString("Hello"_s)', '{allocated = "Hello"}'), + ('tmwa::AString(tmwa::ZString("Hello"_s))', '{contained = "Hello"}'), + ('tmwa::AString(tmwa::RString("Hello"_s))', '{allocated = "Hello"}'), + ('tmwa::AString(tmwa::RString(tmwa::ZString("Hello"_s)))', '{allocated = "Hello" = {count = 0}}'), + ('tmwa::AString("' + str256[:-2] + '"_s)', '{allocated = "' + str256[:-2] + '"}'), + ('tmwa::AString(tmwa::ZString("' + str256[:-2] + '"_s))', '{contained = "' + str256[:-2] + '"}'), + ('tmwa::AString(tmwa::RString("' + str256[:-2] + '"_s))', '{allocated = "' + str256[:-2] + '"}'), + ('tmwa::AString(tmwa::RString(tmwa::ZString("' + str256[:-2] + '"_s)))', '{allocated = "' + str256[:-2] + '" = {count = 0}}'), + ('tmwa::AString("' + str256[:-1] + '"_s)', '{allocated = "' + str256[:-1] + '"}'), + ('tmwa::AString(tmwa::ZString("' + str256[:-1] + '"_s))', '{contained = "' + str256[:-1] + '"}'), + ('tmwa::AString(tmwa::RString("' + str256[:-1] + '"_s))', '{allocated = "' + str256[:-1] + '"}'), + ('tmwa::AString(tmwa::RString(tmwa::ZString("' + str256[:-1] + '"_s)))', '{allocated = "' + str256[:-1] + '" = {count = 0}}'), + ('tmwa::AString("' + str256 + '"_s)', '{allocated = "' + str256 + '"}'), + ('tmwa::AString(tmwa::ZString("' + str256 + '"_s))', '{allocated = "' + str256 + '" = {count = 0}}'), + ('tmwa::AString(tmwa::RString("' + str256 + '"_s))', '{allocated = "' + str256 + '"}'), + ('tmwa::AString(tmwa::RString(tmwa::ZString("' + str256 + '"_s)))', '{allocated = "' + str256 + '" = {count = 0}}'), + ('tmwa::AString("' + str256 + 'x"_s)', '{allocated = "' + str256 + 'x"}'), + ('tmwa::AString(tmwa::ZString("' + str256 + 'x"_s))', '{allocated = "' + str256 + 'x" = {count = 0}}'), + ('tmwa::AString(tmwa::RString("' + str256 + 'x"_s))', '{allocated = "' + str256 + 'x"}'), + ('tmwa::AString(tmwa::RString(tmwa::ZString("' + str256 + 'x"_s)))', '{allocated = "' + str256 + 'x" = {count = 0}}'), + ] diff --git a/src/strings/literal.py b/src/strings/literal.py new file mode 100644 index 0000000..5031ff9 --- /dev/null +++ b/src/strings/literal.py @@ -0,0 +1,23 @@ +class LString(object): + __slots__ = ('_value') + name = 'tmwa::strings::LString' + enabled = True + + def __init__(self, value): + self._value = value + + def to_string(self): + v = self._value + b = v['_b']['_ptr'] + e = v['_e']['_ptr'] + d = e - b + return b.lazy_string(length=d) + + test_extra = ''' + using tmwa::operator "" _s; + ''' + + tests = [ + ('""_s', '""'), + ('"Hello, World!"_s', '"Hello, World!"'), + ] diff --git a/src/strings/rstring.py b/src/strings/rstring.py index 8021ec2..fd26801 100644 --- a/src/strings/rstring.py +++ b/src/strings/rstring.py @@ -1,6 +1,4 @@ class RString(object): - ''' print a RString - ''' __slots__ = ('_value') name = 'tmwa::strings::RString' enabled = True @@ -8,12 +6,40 @@ class RString(object): def __init__(self, value): self._value = value + def to_string(self): + v = self._value + e = v['maybe_end'] + if e: + b = v['u']['begin'] + d = e - b + return b.lazy_string(length=d) + else: + r = v['u']['owned'].dereference() + b = r['body'] + b = b[0].address + d = r['size'] + return b.lazy_string(length=d) + def children(self): - yield 'count', self._value['owned'].dereference()['count'] + v = self._value + if v['maybe_end']: + pass + else: + yield 'count', v['u']['owned'].dereference()['count'] - def to_string(self): - r = self._value['owned'].dereference() - b = r['body'] - b = b.cast(b.type.target().pointer()) - d = r['size'] - return b.lazy_string(length=d) + str256 = '0123456789abcdef' * 16 + + tests = [ + ('tmwa::RString(""_s)', '""'), + ('tmwa::RString(tmwa::ZString(""_s))', '""'), + ('tmwa::RString("Hello"_s)', '"Hello"'), + ('tmwa::RString(tmwa::ZString("Hello"_s))', '"Hello" = {count = 0}'), + ('tmwa::RString("' + str256[:-2] + '"_s)', '"' + str256[:-2] + '"'), + ('tmwa::RString(tmwa::ZString("' + str256[:-2] + '"_s))', '"' + str256[:-2] + '" = {count = 0}'), + ('tmwa::RString("' + str256[:-1] + '"_s)', '"' + str256[:-1] + '"'), + ('tmwa::RString(tmwa::ZString("' + str256[:-1] + '"_s))', '"' + str256[:-1] + '" = {count = 0}'), + ('tmwa::RString("' + str256 + '"_s)', '"' + str256 + '"'), + ('tmwa::RString(tmwa::ZString("' + str256 + '"_s))', '"' + str256 + '" = {count = 0}'), + ('tmwa::RString("' + str256 + 'x"_s)', '"' + str256 + 'x"'), + ('tmwa::RString(tmwa::ZString("' + str256 + 'x"_s))', '"' + str256 + 'x" = {count = 0}'), + ] diff --git a/src/strings/vstring.py b/src/strings/vstring.py index fa975b2..945e3ee 100644 --- a/src/strings/vstring.py +++ b/src/strings/vstring.py @@ -1,6 +1,4 @@ class VString(object): - ''' print a VString - ''' __slots__ = ('_value') name = 'tmwa::strings::VString' enabled = True @@ -15,3 +13,14 @@ class VString(object): s = self._value['_special'] d = n - s return b.lazy_string(length=d) + + str256 = '0123456789abcdef' * 16 + + tests = [ + ('tmwa::VString<255>(""_s)', '""'), + ('tmwa::VString<255>("Hello"_s)', '"Hello"'), + ('tmwa::VString<255>("' + str256[:-2] + '"_s)', '"' + str256[:-2] + '"'), + ('tmwa::VString<255>("' + str256[:-1] + '"_s)', '"' + str256[:-1] + '"'), + ('tmwa::VString<255>("' + str256 + '"_s)', '"' + str256[:-1] + '"'), + ('tmwa::VString<255>("' + str256 + 'x"_s)', '"' + str256[:-1] + '"'), + ] diff --git a/src/strings/xstring.py b/src/strings/xstring.py index fa0abcb..d289485 100644 --- a/src/strings/xstring.py +++ b/src/strings/xstring.py @@ -1,6 +1,4 @@ class XString(object): - ''' print a XString - ''' __slots__ = ('_value') name = 'tmwa::strings::XString' enabled = True @@ -8,11 +6,22 @@ class XString(object): def __init__(self, value): self._value = value - def children(self): - yield 'base', self._value['_base'] - def to_string(self): b = self._value['_b']['_ptr'] e = self._value['_e']['_ptr'] d = e - b return b.lazy_string(length=d) + + def children(self): + yield 'base', self._value['_base'] + + str256 = '0123456789abcdef' * 16 + + tests = [ + ('tmwa::XString(""_s)', '"" = {base = 0x0}'), + ('tmwa::XString("Hello"_s)', '"Hello" = {base = 0x0}'), + ('tmwa::XString("' + str256[:-2] + '"_s)', '"' + str256[:-2] + '" = {base = 0x0}'), + ('tmwa::XString("' + str256[:-1] + '"_s)', '"' + str256[:-1] + '" = {base = 0x0}'), + ('tmwa::XString("' + str256 + '"_s)', '"' + str256 + '" = {base = 0x0}'), + ('tmwa::XString("' + str256 + 'x"_s)', '"' + str256 + 'x" = {base = 0x0}'), + ] diff --git a/src/strings/zstring.py b/src/strings/zstring.py index dca5f4e..7f9ea2a 100644 --- a/src/strings/zstring.py +++ b/src/strings/zstring.py @@ -1,6 +1,4 @@ class ZString(object): - ''' print a ZString - ''' __slots__ = ('_value') name = 'tmwa::strings::ZString' enabled = True @@ -8,11 +6,22 @@ class ZString(object): def __init__(self, value): self._value = value - def children(self): - yield 'base', self._value['_base'] - def to_string(self): b = self._value['_b']['_ptr'] e = self._value['_e']['_ptr'] d = e - b return b.lazy_string(length=d) + + def children(self): + yield 'base', self._value['_base'] + + str256 = '0123456789abcdef' * 16 + + tests = [ + ('tmwa::ZString(""_s)', '"" = {base = 0x0}'), + ('tmwa::ZString("Hello"_s)', '"Hello" = {base = 0x0}'), + ('tmwa::ZString("' + str256[:-2] + '"_s)', '"' + str256[:-2] + '" = {base = 0x0}'), + ('tmwa::ZString("' + str256[:-1] + '"_s)', '"' + str256[:-1] + '" = {base = 0x0}'), + ('tmwa::ZString("' + str256 + '"_s)', '"' + str256 + '" = {base = 0x0}'), + ('tmwa::ZString("' + str256 + 'x"_s)', '"' + str256 + 'x" = {base = 0x0}'), + ] -- cgit v1.2.3-70-g09d2