Fixed instrumentation function for string methods so that it works for all string methods.
@@ -109,7 +109,7 @@ class DynamicSeedingInstrumentation:
]
self._logger.info("Instrumented endswith function")
- def _instrument_isalnum_function(self, block: BasicBlock, functionname: str):
+ def _instrument_string_function_without_arg(self, block: BasicBlock, function_name: str):
"""Instruments the isalnum function in bytecode.
Args:
@@ -126,7 +126,7 @@ class DynamicSeedingInstrumentation:
Instr("LOAD_METHOD", DynamicSeeding.add_value_for_strings.__name__, lineno=lineno),
Instr("ROT_THREE", lineno=lineno),
Instr("ROT_THREE", lineno=lineno),
- Instr("LOAD_CONST", functionname, lineno=lineno),
+ Instr("LOAD_CONST", function_name, lineno=lineno),
Instr("CALL_METHOD", 2, lineno=lineno),
Instr("POP_TOP", lineno=lineno),
]
@@ -140,9 +140,12 @@ class DynamicSeedingInstrumentation:
function_name: The name of the function for which the method will be called.
"""
- method_name = "_instrument_" + function_name + "_function"
- method_to_call = getattr(self, method_name)
- method_to_call(block, function_name)
+ if function_name == "startswith":
+ self._instrument_startswith_function(block)
+ elif function_name == "endswith":
+ self._instrument_endswith_function(block)
+ else:
+ self._instrument_string_function_without_arg(block, function_name)
def _instrument_compare_op(self, block: BasicBlock):
""" Instruments the compare operations in bytecode. Stores the values extracted at runtime.
