public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug python/17152] New: when python pretty printer is used watch command prints new value in the old value filed
@ 2014-07-14 10:29 skwllsp at gmail dot com
  2014-07-14 10:32 ` [Bug python/17152] " skwllsp at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: skwllsp at gmail dot com @ 2014-07-14 10:29 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=17152

            Bug ID: 17152
           Summary: when python pretty printer is used watch command
                    prints new value in the old value filed
           Product: gdb
           Version: 7.7
            Status: NEW
          Severity: normal
          Priority: P2
         Component: python
          Assignee: unassigned at sourceware dot org
          Reporter: skwllsp at gmail dot com

If no python pretty printer is used then my type unsigned char is correctly
printed:

Hardware watchpoint 2: value

Old value = "\000\000\000"
New value = "He\000"
0x0000003a1d889974 in memcpy () from /lib64/libc.so.6


When I use my own python pretty printer watch command prints new value in the
old value filed:

Hardware watchpoint 2: value

Old value = (72,101,0,0,)
New value = (72,101,0,0,)
0x0000003a1d889974 in memcpy () from /lib64/libc.so.6


Here is a test C++ program:
$ cat change_uchar_array4.cpp
#include <string.h>

unsigned char value[4];

int main()
{
  memcpy(value, "He",2);
  return 0;
}

Here is my python pretty printer:
$ cat my_uchar4_printer.py
class CustomPrinter(object):
    def __init__(self, val):
        self.val = val

    def to_string(self):
        res = '('
        for m in xrange(4):
          res += str(int(self.val[m])) + ","
        res += ')'
        return res

    def display_hint(self):
        return 'array'

def lookup_type (val):
    if str(val.type) == 'unsigned char [4]':
        return CustomPrinter(val)
    return None

gdb.pretty_printers.append (lookup_type)



$ gdb --version
GNU gdb (GDB) 7.7.1

Here the test itself:
$ gdb -q -x my_uchar4_printer.py  -ex "set pagination off" -ex "start" -ex
"watch value"  -ex "c"  ./change_uchar_array4
Reading symbols from ./change_uchar_array4...done.
Temporary breakpoint 1 at 0x4005a8: file change_uchar_array4.cpp, line 7.
Starting program: /home/change_uchar_array4

Temporary breakpoint 1, main () at change_uchar_array4.cpp:7
7         memcpy(value, "He",2);
Hardware watchpoint 2: value
Continuing.
Hardware watchpoint 2: value

Old value = (72,101,0,0,)
New value = (72,101,0,0,)
0x0000003a1d889974 in memcpy () from /lib64/libc.so.6

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug python/17152] when python pretty printer is used watch command prints new value in the old value filed
  2014-07-14 10:29 [Bug python/17152] New: when python pretty printer is used watch command prints new value in the old value filed skwllsp at gmail dot com
@ 2014-07-14 10:32 ` skwllsp at gmail dot com
  2014-07-14 10:33 ` skwllsp at gmail dot com
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: skwllsp at gmail dot com @ 2014-07-14 10:32 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=17152

--- Comment #1 from Sergey Kurenkov <skwllsp at gmail dot com> ---
Created attachment 7710
  --> https://sourceware.org/bugzilla/attachment.cgi?id=7710&action=edit
Python pretty printer

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug python/17152] when python pretty printer is used watch command prints new value in the old value filed
  2014-07-14 10:29 [Bug python/17152] New: when python pretty printer is used watch command prints new value in the old value filed skwllsp at gmail dot com
  2014-07-14 10:32 ` [Bug python/17152] " skwllsp at gmail dot com
@ 2014-07-14 10:33 ` skwllsp at gmail dot com
  2014-07-14 10:59 ` skwllsp at gmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: skwllsp at gmail dot com @ 2014-07-14 10:33 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=17152

--- Comment #2 from Sergey Kurenkov <skwllsp at gmail dot com> ---
Created attachment 7711
  --> https://sourceware.org/bugzilla/attachment.cgi?id=7711&action=edit
C++ test program

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug python/17152] when python pretty printer is used watch command prints new value in the old value filed
  2014-07-14 10:29 [Bug python/17152] New: when python pretty printer is used watch command prints new value in the old value filed skwllsp at gmail dot com
  2014-07-14 10:32 ` [Bug python/17152] " skwllsp at gmail dot com
  2014-07-14 10:33 ` skwllsp at gmail dot com
@ 2014-07-14 10:59 ` skwllsp at gmail dot com
  2014-07-14 12:18 ` skwllsp at gmail dot com
  2023-08-31 16:20 ` tromey at sourceware dot org
  4 siblings, 0 replies; 6+ messages in thread
From: skwllsp at gmail dot com @ 2014-07-14 10:59 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=17152

--- Comment #3 from Sergey Kurenkov <skwllsp at gmail dot com> ---
What is expected for the test program is to see in gdb initial value (0,0,0,0,)
in the field "Old value =". In this test the initial value is printed right
after start of the program:

$ gdb -q -x my_uchar4_printer.py  -ex "set pagination off" -ex "start" -ex
"watch value" -ex "print value"  -ex "c"  ./change_uchar_array4
Reading symbols from ./change_uchar_array4...done.
Temporary breakpoint 1 at 0x4005a8: file change_uchar_array4.cpp, line 7.
Starting program: /home/change_uchar_array4

Temporary breakpoint 1, main () at change_uchar_array4.cpp:7
7         memcpy(value, "He",2);
Hardware watchpoint 2: value
$1 = (0,0,0,0,)
Continuing.
Hardware watchpoint 2: value

Old value = (72,101,0,0,)
New value = (72,101,0,0,)
0x0000003a1d889974 in memcpy () from /lib64/libc.so.6

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug python/17152] when python pretty printer is used watch command prints new value in the old value filed
  2014-07-14 10:29 [Bug python/17152] New: when python pretty printer is used watch command prints new value in the old value filed skwllsp at gmail dot com
                   ` (2 preceding siblings ...)
  2014-07-14 10:59 ` skwllsp at gmail dot com
@ 2014-07-14 12:18 ` skwllsp at gmail dot com
  2023-08-31 16:20 ` tromey at sourceware dot org
  4 siblings, 0 replies; 6+ messages in thread
From: skwllsp at gmail dot com @ 2014-07-14 12:18 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=17152

--- Comment #4 from Sergey Kurenkov <skwllsp at gmail dot com> ---
OS:

$ uname -a
Linux host 2.6.32-431.el6.x86_64 #1 SMP Sun Nov 10 22:19:54 EST 2013 x86_64
x86_64 x86_64 GNU/Linux

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

* [Bug python/17152] when python pretty printer is used watch command prints new value in the old value filed
  2014-07-14 10:29 [Bug python/17152] New: when python pretty printer is used watch command prints new value in the old value filed skwllsp at gmail dot com
                   ` (3 preceding siblings ...)
  2014-07-14 12:18 ` skwllsp at gmail dot com
@ 2023-08-31 16:20 ` tromey at sourceware dot org
  4 siblings, 0 replies; 6+ messages in thread
From: tromey at sourceware dot org @ 2023-08-31 16:20 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=17152

Tom Tromey <tromey at sourceware dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
                 CC|                            |tromey at sourceware dot org

--- Comment #5 from Tom Tromey <tromey at sourceware dot org> ---
This works for me now:

Old value = (0,0,0,0,)
New value = (72,101,0,0,)


However, I suspect the bug was that the array value was
lazy, and not resolved until too late.
The fix in these cases is to call fetch_lazy in
the pretty-printer constructor.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2023-08-31 16:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-14 10:29 [Bug python/17152] New: when python pretty printer is used watch command prints new value in the old value filed skwllsp at gmail dot com
2014-07-14 10:32 ` [Bug python/17152] " skwllsp at gmail dot com
2014-07-14 10:33 ` skwllsp at gmail dot com
2014-07-14 10:59 ` skwllsp at gmail dot com
2014-07-14 12:18 ` skwllsp at gmail dot com
2023-08-31 16:20 ` tromey at sourceware dot org

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