From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17198 invoked by alias); 10 Apr 2012 01:38:09 -0000 Received: (qmail 17187 invoked by uid 22791); 10 Apr 2012 01:38:08 -0000 X-SWARE-Spam-Status: No, hits=-6.5 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,SPF_HELO_PASS,TW_BJ,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 10 Apr 2012 01:37:52 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q3A1bpso010164 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 9 Apr 2012 21:37:51 -0400 Received: from barimba (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q3A1bo1w018353 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Mon, 9 Apr 2012 21:37:50 -0400 From: Tom Tromey To: Siva Chandra Cc: gdb-patches@sourceware.org Subject: Re: [RFC - Python Scripting] New method gdb.Symtab.blocks_iterator - docs included References: Date: Tue, 10 Apr 2012 01:38:00 -0000 In-Reply-To: (Siva Chandra's message of "Tue, 10 Apr 2012 00:04:10 +0530") Message-ID: <87mx6k4b9t.fsf@fleche.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.95 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2012-04/txt/msg00170.txt.bz2 >>>>> "Siva" == Siva Chandra writes: Siva> While the work on Objfile.symtabs (or Objfile.iterator) is pending, I Siva> want to complete the API for the exploratory path Objfile => Symtabs Siva> => Blocks => Symbols. This patch adds the missing link Symtabs => Siva> Blocks. The method Symtab.blocks_iterator returns an iterator to Siva> iterate over the scope blocks of a symtab. The patch is attached and Siva> the ChangeLog is as follows: Thanks. Siva> + ** A new method 'blocks_iterator' on gdb.Symtab objects which returns Siva> + an iterator to iterate over the scope blocks (gdb.Block objects) of Siva> + the symbol table (gdb.Symtab object). It seems to me that the Symtab itself could provide the iterator so you could just write: for block in symtab: ... The precedent here is that gdb.Block is also an iterator over symbols. Alternatively, 'Symtab.blocks'. I find 'blocks_iterator' a bit too wordy somehow. What do you think of those? Siva> + /* The iterator holds a reference to the symtab_object. */ Siva> + Py_INCREF (self); Siva> + Siva> + iter = PyObject_New (symtab_blocks_iterator_object, Siva> + &symtab_blocks_iterator_object_type); Siva> + if (iter) Siva> + { Siva> + iter->symtab_obj = symtab_obj; Siva> + iter->iter_index = 0; Siva> + } Siva> + Siva> + return (PyObject *) iter; This leaks a reference to 'self' if PyObject_New fails. Moving the incref into the 'if' would fix it. Siva> + static void Siva> + symtab_blocks_iterator_dealloc (PyObject *self) Siva> + { Siva> + symtab_blocks_iterator_object *iter; Siva> + Siva> + /* Decrement the reference to the symtab_object. */ Siva> + if (self) Can you ever get here with self==NULL? I expect not, but I am not 100% sure. If not, remove the if. Siva> + { Siva> + iter = (symtab_blocks_iterator_object *) self; Siva> + Py_DECREF ((PyObject *) iter->symtab_obj); It might be a little cleaner if symtab_obj is just a plain PyObject* and you downcast it in the one place that uses it. Siva> + block_object = block_to_block_object (block, symtab->objfile); Siva> + if (! block_object) Siva> + { Siva> + PyErr_SetString (PyExc_RuntimeError, Siva> + _("Unable to get the next gdb.Block object.")); If block_to_block_object fails, then the error will already be set. I think it is generally better to propagate the original exception in cases like this. Otherwise, the new exception may obscure some more fundamental error. Siva> + (iter->iter_index)++; Also I'm curious if an error should invalidate the iterator in some way. Siva> ! # Proc to setup and get the symbol table in the Python environment. Siva> ! proc setup_python_env { line_no } { Siva> ! gdb_breakpoint $line_no Siva> ! gdb_continue_to_breakpoint "Block break here." Siva> ! gdb_py_test_silent_cmd "python def func_symbol(block): return block.function" "Define a func to get the function symbols" "0" If you run the same set of tests twice from a .exp you should use with_test_prefix to ensure the tests have unique names. Siva> + # Compile the source file as a C++ file and test again. Siva> + if { [prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}] } { We were recently discussing that it is preferable to give each executable its own name, so that if the test fails it is simpler to reproduce the problem from outside dejagnu. So, please choose a new name for the executable here. Tom