This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[python] Add the in_scope.py script.


I didn't test this patch, I hope it's ok. :-)
Do I need to make install to be able to use the require facility?

Is there a way to make GDB use the python library from the build
directory? Perhaps by putting some code in $BUILD/gdb/.gdbinit?

Also, the other scripts have an "import gdb" line. Is it necessary when
the script is loaded from the library dir? I added it to this script,
just in case.


2008-11-24  Thiago Jung Bauermann  <bauerman@br.ibm.com>

	* Makefile.in (PY_FILES): Add in_scope.py.
	* python/lib/gdb/function/in_scope.py: New file.

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 6ef02bf..497e26e 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1923,8 +1923,8 @@ PY_DIRS = gdb gdb/command gdb/function gdb/libstdcxx gdb/libstdcxx/v6
 # Note that we should only install files in the "gdb" module.
 PY_FILES = gdb/backtrace.py gdb/command/alias.py \
     gdb/command/backtrace.py gdb/command/require.py \
-    gdb/function/caller_is.py gdb/FrameIterator.py \
-    gdb/__init__.py gdb/libstdcxx/v6/printers.py
+    gdb/function/caller_is.py gdb/function/in_scope.py \
+    gdb/FrameIterator.py gdb/__init__.py gdb/libstdcxx/v6/printers.py
 
 # Install the Python library.  Python library files go under
 # $(GDB_DATADIR_PATH)/python.  We create a dummy __init__.py for
diff --git a/gdb/python/lib/gdb/function/in_scope.py b/gdb/python/lib/gdb/function/in_scope.py
new file mode 100644
index 0000000..f110b6a
--- /dev/null
+++ b/gdb/python/lib/gdb/function/in_scope.py
@@ -0,0 +1,43 @@
+# In-scope function.
+
+# Copyright (C) 2008 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import gdb
+
+class InScope (gdb.Function):
+    """Check if all the given variables or macros are in scope.
+Receives as argument a list of names separated by whitespace."""
+
+    def __init__ (self):
+	super (InScope, self).__init__ ("in_scope")
+
+    def invoke (self, var):
+	vars = set (var.string().split())
+	found = set ()
+	block = gdb.get_block_for_pc (gdb.get_selected_frame ().get_pc ())
+	while block:
+	    for sym in block:
+		if (sym.is_argument () or sym.is_constant ()
+		      or sym.is_function () or sym.is_variable ()):
+		    sym_name = sym.get_print_name ()
+		    if sym_name in vars:
+			found.add (sym_name)
+
+	    block = block.get_superblock ()
+
+	return vars == found
+
+InScope ()
-- 
1.5.6.5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]