public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug python/11765] New: Pretty printer lookup fails with lambda functions
@ 2010-06-29  4:12 wittman at acm dot org
  2010-06-29 15:07 ` [Bug python/11765] " tromey at redhat dot com
  2010-07-01  4:34 ` wittman at acm dot org
  0 siblings, 2 replies; 3+ messages in thread
From: wittman at acm dot org @ 2010-06-29  4:12 UTC (permalink / raw)
  To: gdb-prs

When multiple lambda functions are added to the current objfile's pretty
printers, all but one are never invoked.  (It appears that the second-to-last
lambda function added is instead invoked once for each function added.)

To reproduce:

simple.c:
  int main(int argc, char *argv[]) { return 0; }

a.out-gdb.py:
  def test(i):
    print 'test(%d)' % i
    return None

  for i in range(0, 5):
    gdb.current_objfile().pretty_printers.append(lambda val: test(i))

run:
gcc -g simple.c && gdb -ex 'b main' -ex r a.out

-- 
           Summary: Pretty printer lookup fails with lambda functions
           Product: gdb
           Version: 7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: python
        AssignedTo: unassigned at sourceware dot org
        ReportedBy: wittman at acm dot org
                CC: gdb-prs at sourceware dot org
 GCC build triplet: x86_64-linux-gnu
  GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu


http://sourceware.org/bugzilla/show_bug.cgi?id=11765

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug python/11765] Pretty printer lookup fails with lambda functions
  2010-06-29  4:12 [Bug python/11765] New: Pretty printer lookup fails with lambda functions wittman at acm dot org
@ 2010-06-29 15:07 ` tromey at redhat dot com
  2010-07-01  4:34 ` wittman at acm dot org
  1 sibling, 0 replies; 3+ messages in thread
From: tromey at redhat dot com @ 2010-06-29 15:07 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From tromey at redhat dot com  2010-06-29 15:07 -------
I think the problem here is that python lambdas do not capture
their environment.  That is, this is not a gdb bug.

I slightly (but not importantly) modified your example and tried "print 5".
I see:

(gdb) p 5
$1 = test 4
test 4
test 4
test 4
test 4
test 4
test 4
test 4
test 4
test 4
5

Now see what happens if I change "i":

(gdb) python i = 23
(gdb) print 5
$2 = test 23
test 23
test 23
test 23
test 23
test 23
test 23
test 23
test 23
test 23
5


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://sourceware.org/bugzilla/show_bug.cgi?id=11765

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

* [Bug python/11765] Pretty printer lookup fails with lambda functions
  2010-06-29  4:12 [Bug python/11765] New: Pretty printer lookup fails with lambda functions wittman at acm dot org
  2010-06-29 15:07 ` [Bug python/11765] " tromey at redhat dot com
@ 2010-07-01  4:34 ` wittman at acm dot org
  1 sibling, 0 replies; 3+ messages in thread
From: wittman at acm dot org @ 2010-07-01  4:34 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From wittman at acm dot org  2010-07-01 04:34 -------
Looking into it some more, it appears that lambdas do capture the variables
used.  The iteration variable in the list comprehension has global scope,
however, so the same reference is captured for every function.

Passing this lambda expression does work as expected, since the variable is
local to each lambda:
  lambda val, n=i: test(n)

Still not a bug in gdb, but good to know.


-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=11765

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


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

end of thread, other threads:[~2010-07-01  4:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-29  4:12 [Bug python/11765] New: Pretty printer lookup fails with lambda functions wittman at acm dot org
2010-06-29 15:07 ` [Bug python/11765] " tromey at redhat dot com
2010-07-01  4:34 ` wittman at acm 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).