Closed lks9 closed 1 year ago
On a second thought, maybe we could just remove the line number information altogether. Even if there are different functions with the same name, this should not be an issue for retracing in most cases.
Sorry, this is simply not done. Try it out:
cpp checksum.c -o checksum_inst.c
.../instrumenter.py checksum_inst.c
Now change anything in checksum.c
(add a new line before the main function).
cpp checksum.c -o checksum_inst2.c
.../instrumenter.py checksum_inst2.c
Traceback (most recent call last):
File "/home/lukas/Software/angr-dev/src-tracer/src_tracer/instrumenter.py", line 421, in traverse
self.visit_function(node)
File "/home/lukas/Software/angr-dev/src-tracer/src_tracer/instrumenter.py", line 102, in visit_function
func_num = self.func_num(node)
File "/home/lukas/Software/angr-dev/src-tracer/src_tracer/instrumenter.py", line 70, in func_num
num = self.database.get_number(line, file, name)
File "/home/lukas/Software/angr-dev/src-tracer/src_tracer/database.py", line 69, in get_number
return func_num[0]
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "../instrumenter.py", line 57, in <module>
instrumenter.parse(args.filename)
File "/home/lukas/Software/angr-dev/src-tracer/src_tracer/instrumenter.py", line 374, in parse
self.traverse(root)
File "/home/lukas/Software/angr-dev/src-tracer/src_tracer/instrumenter.py", line 449, in traverse
self.traverse(child, function_scope=function_scope)
File "/home/lukas/Software/angr-dev/src-tracer/src_tracer/instrumenter.py", line 446, in traverse
raise Exception(message)
Exception: Failed to annotate a CursorKind.FUNCTION_DECL
Currently, function numbers are based on (a) function name, (b) source file name, (c) line number. But this doesn't work well with adding any lines for retrace assertion checking. The usual steps are as follows:
We can't actually change the source code in 3, at least we can't refactor by changing control structures or function names.
However, after step 3, we insert new lines. So when recompiling in step 4, the functions might be on different lines. This ultimately results in different function numbers.
Suggestion:
--retrace
to the instrumenter. When that option is on:There is still a problem with having two functions with the same name in the same file name. In C, this is unlikely but not impossible when making nasty use of the pre-processor. In other languages, adding extra context like class name or function signature should help.
Also, if we allow a second trace mode compilation after 3, we might also run into problems. But in this case I recommend using the original source code from step 1 again. Assertions are ignored in trace mode anyways.