From 9fb64a91e452c7c6f5a3bbdf505d94af4c1ee8c2 Mon Sep 17 00:00:00 2001 From: pompolic <pompolic@special-circumstanc.es> Date: Tue, 2 Nov 2021 21:51:26 +0100 Subject: [PATCH] Different versions of GDB might render retq as ret --- gdb-port/README | 4 ++-- gdb-port/parser-name-instrumentation-gdb.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gdb-port/README b/gdb-port/README index 63a0435..e250f10 100644 --- a/gdb-port/README +++ b/gdb-port/README @@ -71,7 +71,7 @@ Print the "call stack" for parsers. A call to `perform_lowlevel_parse` correspon hammer-parser-mem-use <address> ``` -Print bytes allocated in the context of the parser located at `<address>`. +Print bytes allocated in the context of the parser located at `<address>`. The memory use is counted separately per arena, thus the result contains a dictionary keyed with adresses of arenas. The value belonging to the keys is the number of bytes allocated. ``` hammer-parser-mem-use-name <name> @@ -86,4 +86,4 @@ This tool is currently built and tested against the pdf parser. It makes a few a - Presence of an `init_parser()` function that declares the parser's H_RULEs. This will later be parameterized to support other parsers built with Hammer. - The parser using Hammer's Packrat backend -- `init_parser()`, `perform_lowlevel_parse()`, `h_packrat_parse()` returnin with a `RETQ` instruction +- The return instructions in `init_parser()`, `perform_lowlevel_parse()`, `h_packrat_parse()` will be rendered as "ret" or "retq" by GDB diff --git a/gdb-port/parser-name-instrumentation-gdb.py b/gdb-port/parser-name-instrumentation-gdb.py index 16391ce..85d15c8 100644 --- a/gdb-port/parser-name-instrumentation-gdb.py +++ b/gdb-port/parser-name-instrumentation-gdb.py @@ -448,7 +448,7 @@ def locate_perform_lowlevel_parse_retq(): p_l_p_address = int(p_l_p_sym.value().address) # The choice of disassembling only 400 instructions from the start is arbitrary. (This function is 310 bytes long on this particular machine.) There is probably a way to find out where a function ends. instructions = arch.disassemble(p_l_p_address, p_l_p_address+400) - results = [ ins["addr"] for ins in instructions if ins["asm"].startswith("retq ") ] + results = [ ins["addr"] for ins in instructions if ins["asm"].startswith("ret") ] return results[0] def locate_h_packrat_parse_retq(): @@ -457,7 +457,7 @@ def locate_h_packrat_parse_retq(): h_p_p_address = int(h_p_p_sym.value().address) # Same as with perform_lowlevel_parse, +450 is arbitrary instructions = arch.disassemble(h_p_p_address, h_p_p_address+450) - results = [ ins["addr"] for ins in instructions if ins["asm"].startswith("retq ") ] + results = [ ins["addr"] for ins in instructions if ins["asm"].startswith("ret") ] return results[0] def locate_init_parser_retq(): @@ -466,9 +466,9 @@ def locate_init_parser_retq(): i_p_address = int(i_p_sym.value().address) # Same as with perform_lowlevel_parse, +16000 is arbitrary instructions = arch.disassemble(i_p_address, i_p_address+16000) - results = [ ins["addr"] for ins in instructions if ins["asm"].startswith("retq ") ] + results = [ ins["addr"] for ins in instructions if ins["asm"].startswith("ret") ] return results[0] - +#TODO: regex match retq, ret, etc # Break on main so that libhammer.so gets to load main = gdb.Breakpoint("main") -- GitLab