This is the mail archive of the 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] Fix in_scope convenience function.


When reworking gdb.Symbol, I forgot to convert some references in I also took the opportunity to implement this suggestion
from Tromey:

> FWIW you could also make it a varargs-like function:
>   def invoke (self, *vars):
>     ...
> Then users would call:
>   $in_scope ("a", "b", "c")
> IMO this is a bit more natural.

Thiago Jung Bauermann
IBM Linux Technology Center

2008-12-16  Thiago Jung Bauermann  <>

	* python/lib/gdb/function/ Fix use of gdb.Symbol
	attributes.  Change to receive variable number of arguments.

diff --git a/gdb/python/lib/gdb/function/ b/gdb/python/lib/gdb/function/
index e9e589b..9d32ad4 100644
--- a/gdb/python/lib/gdb/function/
+++ b/gdb/python/lib/gdb/function/
@@ -18,26 +18,30 @@
 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."""
+    """Return True if all the given variables or macros are in scope.
+Takes one argument for each variable name to be checked."""
     def __init__ (self):
 	super (InScope, self).__init__ ("in_scope")
-    def invoke (self, var):
-	vars = set (var.string().split())
+    def invoke (self, *vars):
+        if len (vars) == 0:
+	    raise TypeError, "in_scope takes at least one argument"
+        # gdb.Value isn't hashable so it can't be put in a map.
+	# Convert to string first.
+	wanted = set (map (lambda x: x.string (), vars))
 	found = set ()
 	block = gdb.block_for_pc (gdb.selected_frame ().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 =
-		    if sym_name in vars:
-			found.add (sym_name)
+		if (sym.is_argument or sym.is_constant
+		      or sym.is_function or sym.is_variable):
+		    if in wanted:
+			found.add (
 	    block = block.superblock
-	return vars == found
+	return wanted == found
 InScope ()

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