From a3e3f62fc9d8781e388c160edc54286ad5d79fba Mon Sep 17 00:00:00 2001 From: Pompolic <pompolic@special-circumstanc.es> Date: Wed, 1 Sep 2021 17:09:22 +0200 Subject: [PATCH] More cleanup/TODOs - handle parser names being None in HammerParserBacktrace - figured out subscripting, so the stringly typed code in the Env classes can be replaced --- gdb-port/parser-name-instrumentation-gdb.py | 2 +- gdb-port/parser-type-instrumentation-gdb.py | 22 ++++++--------------- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/gdb-port/parser-name-instrumentation-gdb.py b/gdb-port/parser-name-instrumentation-gdb.py index d968743..e13d113 100644 --- a/gdb-port/parser-name-instrumentation-gdb.py +++ b/gdb-port/parser-name-instrumentation-gdb.py @@ -394,7 +394,7 @@ class HammerParserBacktrace(gdb.Command): # but this addition is to avoid off-by-one errors index = -(depth+1) for p in parserstack[-1:index:-1]: - print("[" + str(hex(p.address)) + "] " + p.name) + print("[" + str(hex(p.address)) + "] " + p.name) # TODO: errors in perform_lowlevel_parse, if p.name is None if depth < len(parserstack): print("[...]") diff --git a/gdb-port/parser-type-instrumentation-gdb.py b/gdb-port/parser-type-instrumentation-gdb.py index 787cae5..c297877 100644 --- a/gdb-port/parser-type-instrumentation-gdb.py +++ b/gdb-port/parser-type-instrumentation-gdb.py @@ -51,17 +51,6 @@ 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: @@ -74,11 +63,12 @@ class HParserEnv: # 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: - # ... + # turns out subscripting is allowed if the pointer is de referenced first, so this should work: + # p_object = gdb.parse_and_eval("*parser") + # p_env = p_object['env'] + + # or: + # p_env = gdb.parse_and_eval("parser").dereference()['env'] vtable_p = gdb.parse_and_eval("((HParser*) " + str(parser_addr) + ")->vtable") try: -- GitLab