Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* Printing of strings with special characters
@ 2010-03-04 11:57 Anton Kunze
  2010-03-04 18:09 ` Tom Tromey
  0 siblings, 1 reply; 12+ messages in thread
From: Anton Kunze @ 2010-03-04 11:57 UTC (permalink / raw)
  To: gdb

Hello,

i'am using gdb 7.0.1 with python and pretty printing on suse linux. If I
try to print string with german special characters I get only strings as
'\nnn'.

My gdbinit file contains following:
set charset ISO-8859-1
set target-wide-charset ISO-8859-1
set print pretty off
set print sevenbit-strings off
set print object on

python
import sys
sys.path.insert(0, '/home/anton/projects/debug/printers')

from qt4 import register_qt4_printers
register_qt4_printers (None)

from kde4 import register_kde4_printers
register_kde4_printers (None)

from libstdcxx import register_libstdcxx_printers
register_libstdcxx_printers (None)

end

Within my debug session I use the following commonds on gdb console:

set print sevenbit-strings off
print qsHtml
$4 = "h\366h\366h\366"
show print sevenbit-strings
Printing of 8-bit characters in strings as \nnn is off.

But the content of "qsHtml" variable is not as I expected. What can I do?

best regards



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

* Re: Printing of strings with special characters
  2010-03-04 11:57 Printing of strings with special characters Anton Kunze
@ 2010-03-04 18:09 ` Tom Tromey
  2010-03-04 21:25   ` Anton Kunze
  2010-03-05  8:33   ` Anton Kunze
  0 siblings, 2 replies; 12+ messages in thread
From: Tom Tromey @ 2010-03-04 18:09 UTC (permalink / raw)
  To: Anton Kunze; +Cc: gdb

>>>>> "Anton" == Anton Kunze <ak@technosis.de> writes:

Anton> i'am using gdb 7.0.1 with python and pretty printing on suse linux. If I
Anton> try to print string with german special characters I get only strings as
Anton> '\nnn'.

Anton> My gdbinit file contains following:
Anton> set charset ISO-8859-1
Anton> set target-wide-charset ISO-8859-1

This is almost certainly wrong.  You probably want `set
target-wide-charset UTF-32' -- which is the default on Linux.  At least,
that will be what you want if your code is using wchar_t.

Also, I recommend against using "set charset"; use target-charset
instead.  'set charset' sets the host charset in addition to the target
charset, but on systems with a decent locale implementation, you
basically will always want to use the result reported by the locale.

Anton> sys.path.insert(0, '/home/anton/projects/debug/printers')

Without the source to this we can't be completely sure about the
problem.

Anton> Within my debug session I use the following commonds on gdb console:

Anton> set print sevenbit-strings off
Anton> print qsHtml
Anton> $4 = "h\366h\366h\366"

What type is a qsHtml?  Specifically, what is the underlying character
type it uses?

Tom


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

* Re: Printing of strings with special characters
  2010-03-04 18:09 ` Tom Tromey
@ 2010-03-04 21:25   ` Anton Kunze
  2010-03-05  8:33   ` Anton Kunze
  1 sibling, 0 replies; 12+ messages in thread
From: Anton Kunze @ 2010-03-04 21:25 UTC (permalink / raw)
  Cc: gdb

Tom Tromey schrieb:
>>>>>> "Anton" == Anton Kunze <ak@technosis.de> writes:
>>>>>>             
>
> Anton> i'am using gdb 7.0.1 with python and pretty printing on suse linux. If I
> Anton> try to print string with german special characters I get only strings as
> Anton> '\nnn'.
>
> Anton> My gdbinit file contains following:
> Anton> set charset ISO-8859-1
> Anton> set target-wide-charset ISO-8859-1
>
> This is almost certainly wrong.  You probably want `set
> target-wide-charset UTF-32' -- which is the default on Linux.  At least,
> that will be what you want if your code is using wchar_t.
>
> Also, I recommend against using "set charset"; use target-charset
> instead.  'set charset' sets the host charset in addition to the target
> charset, but on systems with a decent locale implementation, you
> basically will always want to use the result reported by the locale.
>
> Anton> sys.path.insert(0, '/home/anton/projects/debug/printers')
>
> Without the source to this we can't be completely sure about the
> problem.
>
> Anton> Within my debug session I use the following commonds on gdb console:
>
> Anton> set print sevenbit-strings off
> Anton> print qsHtml
> Anton> $4 = "h\366h\366h\366"
>
> What type is a qsHtml?  Specifically, what is the underlying character
> type it uses?
>
> Tom
>
>
>   
Hello Tom,
I will try tomorrow your examples for charset . The variable "qsHtml" is 
an QString and I'am using the kdevelop python pretty printers on eclipse 
cdt 
(http://websvn.kde.org/trunk/extragear/sdk/kdevelop/debuggers/gdb/printers/).
"std::string" and "const char*" has the same problem with special 
characters. It doesn't matter if I use python pretty printer or not.

best regards


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

* Re: Printing of strings with special characters
  2010-03-04 18:09 ` Tom Tromey
  2010-03-04 21:25   ` Anton Kunze
@ 2010-03-05  8:33   ` Anton Kunze
  2010-03-05 15:41     ` Tom Tromey
  1 sibling, 1 reply; 12+ messages in thread
From: Anton Kunze @ 2010-03-05  8:33 UTC (permalink / raw)
  Cc: gdb

Hello Tom,

it doesn't work with charset UTF-32:

here is my test code:
-------------------------------------------------------
std::string strTest = "höhöhö";
const char* szTest = "höhöhö";
--------------------------------------------------------

my gdbinit:
---------------------------------------------------------
set target-charset UTF-32
set target-wide-charset UTF-32
set print pretty off
set print sevenbit-strings off
set print object on
---------------------------------------------------------

gdb console input/output:
---------------------------------------------------------------------------------------------------------
show print sevenbit-strings
Printing of 8-bit characters in strings as \nnn is on.  // <----------this is weird

set print sevenbit-strings off
show print sevenbit-strings
Printing of 8-bit characters in strings as \nnn is off.
print strTest
$2 = {static npos = 4294967295, _M_dataplus = {<std::allocator<char>> ={<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No datafields>}, _M_p = 0x935dcd4 "\150\366\150", <incomplete sequence\366\150\366>}}
print szTest
$3 = 0x88db03a "\150\366\150", <incomplete sequence \366\150\366>
---------------------------------------------------------------------------------------------------------

UTF-16 doesn't work too.

best regards




Tom Tromey schrieb:

>>>>>> >>>>>> "Anton" == Anton Kunze <ak@technosis.de> writes:
>>>>>> >>>>>>             
>>>>>>             
> >
> > Anton> i'am using gdb 7.0.1 with python and pretty printing on suse linux. If I
> > Anton> try to print string with german special characters I get only strings as
> > Anton> '\nnn'.
> >
> > Anton> My gdbinit file contains following:
> > Anton> set charset ISO-8859-1
> > Anton> set target-wide-charset ISO-8859-1
> >
> > This is almost certainly wrong.  You probably want `set
> > target-wide-charset UTF-32' -- which is the default on Linux.  At least,
> > that will be what you want if your code is using wchar_t.
> >
> > Also, I recommend against using "set charset"; use target-charset
> > instead.  'set charset' sets the host charset in addition to the target
> > charset, but on systems with a decent locale implementation, you
> > basically will always want to use the result reported by the locale.
> >
> > Anton> sys.path.insert(0, '/home/anton/projects/debug/printers')
> >
> > Without the source to this we can't be completely sure about the
> > problem.
> >
> > Anton> Within my debug session I use the following commonds on gdb console:
> >
> > Anton> set print sevenbit-strings off
> > Anton> print qsHtml
> > Anton> $4 = "h\366h\366h\366"
> >
> > What type is a qsHtml?  Specifically, what is the underlying character
> > type it uses?
> >
> > Tom
> >
> >
> >   
>   




Tom Tromey schrieb:
>>>>>> "Anton" == Anton Kunze <ak@technosis.de> writes:
>>>>>>             
>
> Anton> i'am using gdb 7.0.1 with python and pretty printing on suse linux. If I
> Anton> try to print string with german special characters I get only strings as
> Anton> '\nnn'.
>
> Anton> My gdbinit file contains following:
> Anton> set charset ISO-8859-1
> Anton> set target-wide-charset ISO-8859-1
>
> This is almost certainly wrong.  You probably want `set
> target-wide-charset UTF-32' -- which is the default on Linux.  At least,
> that will be what you want if your code is using wchar_t.
>
> Also, I recommend against using "set charset"; use target-charset
> instead.  'set charset' sets the host charset in addition to the target
> charset, but on systems with a decent locale implementation, you
> basically will always want to use the result reported by the locale.
>
> Anton> sys.path.insert(0, '/home/anton/projects/debug/printers')
>
> Without the source to this we can't be completely sure about the
> problem.
>
> Anton> Within my debug session I use the following commonds on gdb console:
>
> Anton> set print sevenbit-strings off
> Anton> print qsHtml
> Anton> $4 = "h\366h\366h\366"
>
> What type is a qsHtml?  Specifically, what is the underlying character
> type it uses?
>
> Tom
>
>
>   


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

* Re: Printing of strings with special characters
  2010-03-05  8:33   ` Anton Kunze
@ 2010-03-05 15:41     ` Tom Tromey
  2010-03-08  9:00       ` Anton Kunze
  0 siblings, 1 reply; 12+ messages in thread
From: Tom Tromey @ 2010-03-05 15:41 UTC (permalink / raw)
  To: Anton Kunze; +Cc: gdb

>>>>> "Anton" == Anton Kunze <ak@technosis.de> writes:

Anton> -------------------------------------------------------
Anton> std::string strTest = "höhöhö";
Anton> const char* szTest = "höhöhö";
Anton> --------------------------------------------------------

This works fine for me...

Anton> my gdbinit:
Anton> ---------------------------------------------------------
Anton> set target-charset UTF-32

This setting doesn't make sense.

Anton> set target-wide-charset UTF-32

In the most normal case on Linux, where you are doing "gdb program" and
then "run", you should simply not set these at all, because the defaults
are going to be correct: the target wide charset default is UTF-32,
which is what glibc always uses, and the target charset default will
come from your locale.

Your example works fine for me.

(gdb) p szTest
$2 = 0x80487a4 "höhöhö"

Try again with "gdb -nx".  If that doesn't work, then maybe there is a
bug.

Tom


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

* Re: Printing of strings with special characters
  2010-03-05 15:41     ` Tom Tromey
@ 2010-03-08  9:00       ` Anton Kunze
  2010-03-08 18:03         ` Tom Tromey
  2010-03-08 19:41         ` Tom Tromey
  0 siblings, 2 replies; 12+ messages in thread
From: Anton Kunze @ 2010-03-08  9:00 UTC (permalink / raw)
  To: tromey; +Cc: gdb

Tom> This setting doesn't make sense.

Hello Tom,
I have found out that I must use "set charset ISO-8859-1". Otherwise my
python pretty printer for QString doesn't works for strings with special
characters. Without this charset setting I see an empty string, if I use
this setting I see strings like this "h\366h\366h\366" . I'am using the
python printers from kdevelop:
http://websvn.kde.org/trunk/extragear/sdk/kdevelop/debuggers/gdb/printers/

Tom>Try again with "gdb -nx". If that doesn't work, then maybe there is
a bug.

In eclipse CDT I can't use gdb with argument '-nx' :-(

best regards



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

* Re: Printing of strings with special characters
  2010-03-08  9:00       ` Anton Kunze
@ 2010-03-08 18:03         ` Tom Tromey
  2010-03-09  7:49           ` Anton Kunze
  2010-03-08 19:41         ` Tom Tromey
  1 sibling, 1 reply; 12+ messages in thread
From: Tom Tromey @ 2010-03-08 18:03 UTC (permalink / raw)
  To: Anton Kunze; +Cc: gdb

>>>>> "Anton" == Anton Kunze <ak@technosis.de> writes:

Anton> In eclipse CDT I can't use gdb with argument '-nx' :-(

Oh, I don't think you mentioned that you were using Eclipse.

Does it work if you run `gdb -nx' from the command line?
That would be interesting because it would mean there is probably a bug
in Eclipse.

Tom


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

* Re: Printing of strings with special characters
  2010-03-08  9:00       ` Anton Kunze
  2010-03-08 18:03         ` Tom Tromey
@ 2010-03-08 19:41         ` Tom Tromey
  2010-03-09  7:54           ` Anton Kunze
  2010-03-09 10:29           ` André Pönitz
  1 sibling, 2 replies; 12+ messages in thread
From: Tom Tromey @ 2010-03-08 19:41 UTC (permalink / raw)
  To: Anton Kunze; +Cc: gdb

>>>>> "Anton" == Anton Kunze <ak@technosis.de> writes:

Anton> http://websvn.kde.org/trunk/extragear/sdk/kdevelop/debuggers/gdb/printers/

Also, the QStringPrinter code seems suspect to me:

class QStringPrinter:

    def __init__(self, val):
        self.val = val

    def to_string(self):
        ret = ""
        i = 0
        while i < self.val['d']['size']:
            if self.val['d']['data'][i] > 256:
                #TODO: fix this properly
                ret += '?'
            else:
                ret += chr(self.val['d']['data'][i])
            i = i + 1
        return ret

This is constructing a string by hand, and using '?' to replace some
characters.

It is better to use Value.string or Value.lazy_string.  From the
qstring.h in code search, I gather that this is UTF-16-encoded, so this
should probably read:

  return self.val['d']['data'].string(encoding = 'UTF-16', length = self.val['d']['size'])

... though I have never really used Qt, so take with a grain of salt.

Use lazy_string if you have a newer gdb.

Tom


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

* Re: Printing of strings with special characters
  2010-03-08 18:03         ` Tom Tromey
@ 2010-03-09  7:49           ` Anton Kunze
  0 siblings, 0 replies; 12+ messages in thread
From: Anton Kunze @ 2010-03-09  7:49 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb

Hello Tom,

I will test this on command line in the next days.

best regards

Tom Tromey schrieb:
>>>>>> "Anton" == Anton Kunze <ak@technosis.de> writes:
>>>>>>             
>
> Anton> In eclipse CDT I can't use gdb with argument '-nx' :-(
>
> Oh, I don't think you mentioned that you were using Eclipse.
>
> Does it work if you run `gdb -nx' from the command line?
> That would be interesting because it would mean there is probably a bug
> in Eclipse.
>
> Tom
>
>
>   

-- 
Anton Kunze
Entwicklung
_____________________________
Technosis GmbH
Kattrepelsbrücke 1
20095 Hamburg
Tel. +49 - (0)40-33 44 1990
Fax +49 - (0)40-33 44 1999
eMail:   ak@technosis.de
_____________________________
Supporthotline: +49-(0)40-3344-1991
Support-eMail: support@technosis.de

Technosis GmbH, Geschäftsführer: Heiko Gerdau, Tobias Dittmar, Dierk
Rathjen, Sitz Hamburg; HRB 89145 Amtsgericht Hamburg


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

* Re: Printing of strings with special characters
  2010-03-08 19:41         ` Tom Tromey
@ 2010-03-09  7:54           ` Anton Kunze
  2010-03-09 19:56             ` Niko Sams
  2010-03-09 10:29           ` André Pönitz
  1 sibling, 1 reply; 12+ messages in thread
From: Anton Kunze @ 2010-03-09  7:54 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb

Hello Tom,

for my example string 'höhö' this code works for me, the 'ö' character
is number 246 in ASCII. I will start with some testing routines in the
next days.

best regards

Tom Tromey schrieb:
>>>>>> "Anton" == Anton Kunze <ak@technosis.de> writes:
>>>>>>             
>
> Anton> http://websvn.kde.org/trunk/extragear/sdk/kdevelop/debuggers/gdb/printers/
>
> Also, the QStringPrinter code seems suspect to me:
>
> class QStringPrinter:
>
>     def __init__(self, val):
>         self.val = val
>
>     def to_string(self):
>         ret = ""
>         i = 0
>         while i < self.val['d']['size']:
>             if self.val['d']['data'][i] > 256:
>                 #TODO: fix this properly
>                 ret += '?'
>             else:
>                 ret += chr(self.val['d']['data'][i])
>             i = i + 1
>         return ret
>
> This is constructing a string by hand, and using '?' to replace some
> characters.
>
> It is better to use Value.string or Value.lazy_string.  From the
> qstring.h in code search, I gather that this is UTF-16-encoded, so this
> should probably read:
>
>   return self.val['d']['data'].string(encoding = 'UTF-16', length = self.val['d']['size'])
>
> ... though I have never really used Qt, so take with a grain of salt.
>
> Use lazy_string if you have a newer gdb.
>
> Tom
>
>
>   

-- 
Anton Kunze
Entwicklung
_____________________________
Technosis GmbH
Kattrepelsbrücke 1
20095 Hamburg
Tel. +49 - (0)40-33 44 1990
Fax +49 - (0)40-33 44 1999
eMail:   ak@technosis.de
_____________________________
Supporthotline: +49-(0)40-3344-1991
Support-eMail: support@technosis.de

Technosis GmbH, Geschäftsführer: Heiko Gerdau, Tobias Dittmar, Dierk
Rathjen, Sitz Hamburg; HRB 89145 Amtsgericht Hamburg


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

* Re: Printing of strings with special characters
  2010-03-08 19:41         ` Tom Tromey
  2010-03-09  7:54           ` Anton Kunze
@ 2010-03-09 10:29           ` André Pönitz
  1 sibling, 0 replies; 12+ messages in thread
From: André Pönitz @ 2010-03-09 10:29 UTC (permalink / raw)
  To: gdb

On Monday 08 March 2010 20:41:00 Tom Tromey wrote:
> >>>>> "Anton" == Anton Kunze <ak@technosis.de> writes:
> 
> Anton> http://websvn.kde.org/trunk/extragear/sdk/kdevelop/debuggers/gdb/printers/
> 
> Also, the QStringPrinter code seems suspect to me:
> 
> class QStringPrinter:
> 
>     def __init__(self, val):
>         self.val = val
> 
>     def to_string(self):
>         ret = ""
>         i = 0
>         while i < self.val['d']['size']:
>             if self.val['d']['data'][i] > 256:
>                 #TODO: fix this properly
>                 ret += '?'
>             else:
>                 ret += chr(self.val['d']['data'][i])
>             i = i + 1
>         return ret
> 
> This is constructing a string by hand, and using '?' to replace some
> characters.
> 
> It is better to use Value.string or Value.lazy_string.  From the
> qstring.h in code search, I gather that this is UTF-16-encoded, so this
> should probably read:
> 
>   return self.val['d']['data'].string(encoding = 'UTF-16', length = self.val['d']['size'])

I think I tried something like that when I started to use gdb/python and it
did not really work for corrupted data (like uninitialized objects or "real" 
corruption). 

At least I ended up transferring the raw data to the frontend and let that
decide on how to present it.

Andre'


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

* Re: Printing of strings with special characters
  2010-03-09  7:54           ` Anton Kunze
@ 2010-03-09 19:56             ` Niko Sams
  0 siblings, 0 replies; 12+ messages in thread
From: Niko Sams @ 2010-03-09 19:56 UTC (permalink / raw)
  To: Anton Kunze; +Cc: Tom Tromey, gdb

On Tue, Mar 9, 2010 at 08:54, Anton Kunze <ak@technosis.de> wrote:
> Hello Tom,
>
> for my example string 'höhö' this code works for me, the 'ö' character
> is number 246 in ASCII. I will start with some testing routines in the
> next days.
If you manage to fix the QString pretty printer, please send a patch
to kdevelop-devel@kdevelop.org, we would like to integrate it.

thanks,
Niko


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

end of thread, other threads:[~2010-03-09 19:56 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-04 11:57 Printing of strings with special characters Anton Kunze
2010-03-04 18:09 ` Tom Tromey
2010-03-04 21:25   ` Anton Kunze
2010-03-05  8:33   ` Anton Kunze
2010-03-05 15:41     ` Tom Tromey
2010-03-08  9:00       ` Anton Kunze
2010-03-08 18:03         ` Tom Tromey
2010-03-09  7:49           ` Anton Kunze
2010-03-08 19:41         ` Tom Tromey
2010-03-09  7:54           ` Anton Kunze
2010-03-09 19:56             ` Niko Sams
2010-03-09 10:29           ` André Pönitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox