Bug 11036 - Python: provide access to "hidden" variables
Summary: Python: provide access to "hidden" variables
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: python (show other bugs)
Version: 7.0
: P2 normal
Target Milestone: 7.1
Assignee: Phil Muldoon
URL:
Keywords:
Depends on: 11069
Blocks:
  Show dependency treegraph
 
Reported: 2009-11-30 17:33 UTC by Andre'
Modified: 2010-02-28 21:59 UTC (History)
1 user (show)

See Also:
Host: i486-linux-gnu
Target: i486-linux-gnu
Build: i486-linux-gnu
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andre' 2009-11-30 17:33:41 UTC
It is possible to iterate over most local variables that are in scope using

 while not block.function is None: 
    for symbol in block:  
       value = frame.read_var(symbol.print_name)  [...] 
    block = block.superblock       

but that misses "hidden" variables (i.e. that are defined in multiple scopes)
as "read_var" always finds the innermost.
Comment 1 Phil Muldoon 2010-01-19 14:16:30 UTC
I chatted with andre on irc and we came up with this reproducer:

simple.c ----------

#include <stdio.h>

int main() 
{ 
  int i = 0; 
  { 
    double i = 1.0; 
    double f = 2.0;
    { 
      const char *i = "stuff";
      const char *f = "foo";
      const char *b = "bar";
      printf ("break");
    } 
  } 

  return 0;
}

symbol.py -----------------

frame = gdb.selected_frame()
block = frame.block()
count = 0

while True:
    if block is None:
        warn("UNEXPECTED 'None' BLOCK")
        break
    
    print "Block: ",  count
    for symbol in block:
        name = symbol.print_name        
        try:
            item = frame.read_var(name)
        except RuntimeError:
            continue
        print name," (",item.type,") =",item
    if not block.function is None:
        break
        
    block = block.superblock
    count = count + 1

GDB output:

./gdb ./simple -ex 'b 13' -ex 'run' -ex 'python execfile("./symbol.py")'

Breakpoint 1 at 0x400507: file ../../frame/simple.c, line 13.

Breakpoint 1, main () at ../../frame/simple.c:13
13	      printf ("break");

Block:  0
i  ( const char * ) = 0x400618 "stuff"
f  ( const char * ) = 0x40061e "foo"
b  ( const char * ) = 0x400622 "bar"
Block:  1
i  ( const char * ) = 0x400618 "stuff"
f  ( const char * ) = 0x40061e "foo"
Block:  2
i  ( const char * ) = 0x400618 "stuff"
Comment 2 Sourceware Commits 2010-02-28 21:57:05 UTC
Subject: Bug 11036

CVSROOT:	/cvs/src
Module name:	src
Changes by:	pmuldoon@sourceware.org	2010-02-28 21:56:51

Modified files:
	gdb            : ChangeLog 
	gdb/doc        : ChangeLog gdb.texinfo 
	gdb/python     : py-frame.c 
	gdb/testsuite  : ChangeLog 
	gdb/testsuite/gdb.python: py-frame.c py-frame.exp 

Log message:
	2010-02-28  Phil Muldoon  <pmuldoon@redhat.com>
	
	PR python/11036
	* python/py-frame.c (frapy_read_var): Add block argument and logic
	to cope with user provided blocks.
	
	2010-02-28  Phil Muldoon  <pmuldoon@redhat.com>
	
	* gdb.texinfo (Frames In Python): Add block parameter and
	description to read_var text.
	
	2010-02-28  Phil Muldoon  <pmuldoon@redhat.com>
	
	* gdb.python/py-frame.exp: Add read_var block tests.
	* gdb.python/py-frame.c (block): New function.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.11407&r2=1.11408
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/doc/ChangeLog.diff?cvsroot=src&r1=1.1015&r2=1.1016
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/doc/gdb.texinfo.diff?cvsroot=src&r1=1.674&r2=1.675
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/python/py-frame.c.diff?cvsroot=src&r1=1.3&r2=1.4
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.2155&r2=1.2156
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.python/py-frame.c.diff?cvsroot=src&r1=1.1&r2=1.2
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.python/py-frame.exp.diff?cvsroot=src&r1=1.3&r2=1.4

Comment 3 Phil Muldoon 2010-02-28 21:59:10 UTC
Fixed by the commit in comment #2