Note that `-ex "hammer-parse-stop-at-pos 50"` is not strictly necessary, but by default the tool will print memory stats and exit.
To enable the GUI, in the gdb console:
To enable the GUI, in the gdb console:
```
```
...
@@ -118,6 +120,12 @@ hammer-parser-average-mem
...
@@ -118,6 +120,12 @@ hammer-parser-average-mem
Prints the average number of bytes used separately for each HArena.
Prints the average number of bytes used separately for each HArena.
```
hammer-parser-dump-memory-stats
```
Prints memory usage statistics for all parsers encountered up to that point. (If a HParser is not explicitly named in an H_RULE in one of the parser initializing functions, and has not been applied on the input yet, it will not appear in the statistics. For example: given the `H_RULE(foo, h_choice(h_uint8(), h_uint16(), NULL))`, `foo` will appear in the statistics if it's been declared in `init_parser()`, but the unnamed `h_uint8()` will only appear if it's been applied at least once.)
# Limitations
# Limitations
This tool is currently built and tested against the pdf parser. It makes a few assumptions:
This tool is currently built and tested against the pdf parser. It makes a few assumptions:
print("["+str(hex(top_level_parse.h_do_parse_parser.address))+"] "+top_level_parse.h_do_parse_parser.name+" [current]")#TODO: GUI widget should reflect this
print("")
depth=min(len(parserstack),maxsize)
ifdepth>0:# if stack not empty
# unsure what the idiomatic python is for handling negative indices starting with -1,
# but this addition is to avoid off-by-one errors
index=-(depth+1)
forpinparserstack[-1:index:-1]:
print("["+str(hex(p.address))+"] "+p.name)# TODO: errors in perform_lowlevel_parse, if p.name is None