1717# pylint: disable=missing-docstring
1818
1919import argparse
20- from typing import Iterable
20+ from typing import Iterable , List , Optional
2121
2222import drgn
2323import sdb
@@ -30,19 +30,19 @@ class Filter(sdb.SingleInputCommand):
3030 EXAMPLES
3131 Print addresses greater than or equal to 4
3232
33- sdb> addr 0 1 2 3 4 5 6 | filter obj >= 4
33+ sdb> addr 0 1 2 3 4 5 6 | filter " obj >= 4"
3434 (void *)0x4
3535 (void *)0x5
3636 (void *)0x6
3737
3838 Find the SPA object of the ZFS pool named "jax" and print its 'spa_name'
3939
40- sdb> spa | filter obj.spa_name == "jax" | member spa_name
40+ sdb> spa | filter ' obj.spa_name == "jax"' | member spa_name
4141 (char [256])"jax"
4242
4343 Print the number of level 3 log statements in the kernel log buffer
4444
45- sdb> dmesg | filter obj.level == 3 | count
45+ sdb> dmesg | filter ' obj.level == 3' | count
4646 (unsigned long long)24
4747 """
4848 # pylint: disable=eval-used
@@ -52,19 +52,24 @@ class Filter(sdb.SingleInputCommand):
5252 @classmethod
5353 def _init_parser (cls , name : str ) -> argparse .ArgumentParser :
5454 parser = super ()._init_parser (name )
55- parser .add_argument ("expr" , nargs = argparse . REMAINDER )
55+ parser .add_argument ("expr" , nargs = 1 )
5656 return parser
5757
58- def __init__ (self , args : str = "" , name : str = "_" ) -> None :
58+ @staticmethod
59+ def _parse_expression (input_expr : str ) -> List [str ]:
60+ pass
61+
62+ def __init__ (self ,
63+ args : Optional [List [str ]] = None ,
64+ name : str = "_" ) -> None :
5965 super ().__init__ (args , name )
60- if not self .args .expr :
61- self .parser .error ("the following arguments are required: expr" )
66+ self .expr = self .args .expr [0 ].split ()
6267
6368 index = None
6469 operators = ["==" , "!=" , ">" , "<" , ">=" , "<=" ]
6570 for operator in operators :
6671 try :
67- index = self .args . expr .index (operator )
72+ index = self .expr .index (operator )
6873 # Use the first comparison operator we find.
6974 break
7075 except ValueError :
@@ -83,22 +88,22 @@ def __init__(self, args: str = "", name: str = "_") -> None:
8388 raise sdb .CommandInvalidInputError (
8489 self .name , "left hand side of expression is missing" )
8590
86- if index == len (self .args . expr ) - 1 :
91+ if index == len (self .expr ) - 1 :
8792 # If the index is found to be at the very end of the list,
8893 # this means there's no right hand side of the comparison to
8994 # compare the left hand side to. This is an error.
9095 raise sdb .CommandInvalidInputError (
9196 self .name , "right hand side of expression is missing" )
9297
9398 try :
94- self .lhs_code = compile (" " .join (self .args . expr [:index ]),
95- "<string>" , " eval" )
96- self .rhs_code = compile (" " .join (self .args . expr [index + 1 :]),
97- "<string>" , " eval" )
99+ self .lhs_code = compile (" " .join (self .expr [:index ]), "<string>" ,
100+ "eval" )
101+ self .rhs_code = compile (" " .join (self .expr [index + 1 :]), "<string>" ,
102+ "eval" )
98103 except SyntaxError as err :
99104 raise sdb .CommandEvalSyntaxError (self .name , err )
100105
101- self .compare = self .args . expr [index ]
106+ self .compare = self .expr [index ]
102107
103108 def _call_one (self , obj : drgn .Object ) -> Iterable [drgn .Object ]:
104109 try :
0 commit comments