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 ()
