diff --git a/gdb-port/parser-name-instrumentation-gdb.py b/gdb-port/parser-name-instrumentation-gdb.py index 076a438a689769bcec418c4db9329e79fe8a6ef9..d9687433442a191c3623f22ee4a88b4ddc6c607e 100644 --- a/gdb-port/parser-name-instrumentation-gdb.py +++ b/gdb-port/parser-name-instrumentation-gdb.py @@ -1,6 +1,7 @@ # TODO: handlers for filters # TODO: postordinate parser fails to get named # TODO: step-to-parser command +# TODO: stop splicing gdb.parse_and_eval commands together in parser-type-instrumentation # quick way to get locals from frame.block() # {local.name : local for local in block} @@ -349,6 +350,7 @@ class InitParserBreakpoint(gdb.Breakpoint): # This will also catch locals that aren't parsers, but it's not a problem in practice, # since h_parse() will never be called on them + # If it becomes a problem after all, gdb.parse_and_eval() might be used to filter them out for p in block: top_level_parse.parser_objs[int(p.value(frame))] = Parser(p.name, int(p.value(frame))) diff --git a/gdb-port/parser-type-instrumentation-gdb.py b/gdb-port/parser-type-instrumentation-gdb.py index befdd88e7a9a4158d05ac03b0886e9eea413ce1c..787cae597c00b02247b8e7a3c3df70462810eebc 100644 --- a/gdb-port/parser-type-instrumentation-gdb.py +++ b/gdb-port/parser-type-instrumentation-gdb.py @@ -1,7 +1,3 @@ -# These need to be constructed in HDoParseBreakpoint (or at least in a scope where 'parser' is visible) -# TODO: these can learn of parsers before the parser name instrumentation does -# TopLevelParse should be amenable to adding parsers to the dict through here - parser_name_defaults = { 'action_vt': '(Unnamed action)', 'and_vt': '(Unnamed and)', @@ -55,6 +51,17 @@ class VTTypes: #vt_types = VTTypes() +# Helper function to get a field from a struct via the gdb.Value interface +# TODO: test type checks through the Value API + +#def get_field_of_gdb_val(val, field): + # TODO: throw exception if field is not a string + # TODO: throw exception val's type doesn't have fields (==is not a struct?) + # for f in val: + # if f == field: + # return f + # return None + # TODO: maybe save vtable type here on init, or potentially in Parser class HParserEnv: @@ -66,6 +73,13 @@ class HParserEnv: parser_addr = parser.address # TODO: do this without passing a string to gdb.parse_and_eval() # perhaps using gdb.Value would be the best + + # Something like: + # parser_val = gdb.Value(parser_addr) + # parser_val.type = gdb.Type("HParser*") + # for field in parser_val: + # ... + vtable_p = gdb.parse_and_eval("((HParser*) " + str(parser_addr) + ")->vtable") try: name = parser_name_defaults[self.top_level_parse.vt_types.lookup_by_address(vtable_p).name]