diff --git a/gdb-port/parser-name-instrumentation-gdb.py b/gdb-port/parser-name-instrumentation-gdb.py index e13d1133550eac2b796601427e23bf940ef15920..ce4479ce9b9c24c15aa279f726ce509d788eb8cf 100644 --- a/gdb-port/parser-name-instrumentation-gdb.py +++ b/gdb-port/parser-name-instrumentation-gdb.py @@ -2,6 +2,7 @@ # 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 +# TODO: "current parser" on GUI is the one on top of the stack, while the argument of h_do_parse is not yet accounted for # quick way to get locals from frame.block() # {local.name : local for local in block} diff --git a/gdb-port/parser-type-instrumentation-gdb.py b/gdb-port/parser-type-instrumentation-gdb.py index c2978777f44736c4e560c5c1826d963d2453cef7..d23371dcc43624e4c2ca8dfb977ef5e512352a97 100644 --- a/gdb-port/parser-type-instrumentation-gdb.py +++ b/gdb-port/parser-type-instrumentation-gdb.py @@ -53,6 +53,7 @@ class VTTypes: # TODO: maybe save vtable type here on init, or potentially in Parser +# At this point in time, the parser Env classes are created in perform_lowlevel_parse. Ideally they could be initialized anywhere a HParser local named "parser" is accessible. class HParserEnv: def __init__(self, parser, top_level_parse): self.top_level_parse = top_level_parse @@ -217,16 +218,20 @@ class ChoiceEnv(HParserEnv): self.member_parsers = [] #frame = gdb.selected_frame() - h_sequence_p = gdb.parse_and_eval("(HSequence*) parser->env") - num_parsers = gdb.parse_and_eval("((HSequence *) parser->env)->len") - # TODO: should GDB do the array indexing operation, or should the Python code? - # TODO: top_level_parse.create_or_get_parser(address) - #[gdb.parse_and_eval("((HSequence*) parser->env)->p_array[" + str(index) + "]") for index in range(0, num_parsers)] - # TODO: maybe the loop can be replaced with a list comprehension - #[top_level_parse.add_or_get_parser(gdb.parse_and_eval("((HSequence*) parser->env)->p_array[" + str(index) +"]")) for index in range(0, num_parsers)] + h_sequence_t = gdb.lookup_type("HSequence") + h_sequence_p_t = h_sequence_t.pointer() + + # Get the parser object + parser_obj = gdb.parse_and_eval("*parser") + # Get parser_obj.env, cast it to HSequence *, then dereference + p_env = parser_obj['env'].cast(h_sequence_p_t).dereference() + # Get length of HSequence + num_parsers = p_env['len'] + # Get the array of parsers in the sequence + p_array = p_env['p_array'] for index in range(0, num_parsers): - parser_p = gdb.parse_and_eval("((HSequence*) parser->env)->p_array[" + str(index) + "]") + parser_p = p_array[index] parser_obj = top_level_parse.add_or_get_parser(parser_p) if parser_obj.name is None: parser_obj.name_parser( self.name_from_vtable(parser_obj) )