Skip to content
Snippets Groups Projects
Commit e6b2ccea authored by Leon Weiss's avatar Leon Weiss
Browse files

Add feedback why the backward search has been stopped

parent 9e3f3356
No related branches found
No related tags found
1 merge request!47Improve jump table detection and debugging output
...@@ -59,17 +59,19 @@ void calc_preds(FileIR_t* firp) ...@@ -59,17 +59,19 @@ void calc_preds(FileIR_t* firp)
} }
// search for an expression in prior instructions. // search for an expression in prior instructions. Return whether expression was found.
bool backup_until(const string &insn_type_regex_str, // what to search for // If an assignment is found, stopped_because_set is set to this instruction and false is returned
bool backup_until_or_move(const string &insn_type_regex_str, // what to search for
Instruction_t *& prev, // output param -- the instruction we found. Instruction_t *& prev, // output param -- the instruction we found.
Instruction_t* orig, // where to start the search. Instruction_t* orig, // where to start the search.
Instruction_t *& stopped_because_set, // output param -- the instruction that stopped the search because of stop_if_set. nullptr if the search was not stopped because of this reason
const string & stop_if_set="", // stop if an operand that's written matches this expression. const string & stop_if_set="", // stop if an operand that's written matches this expression.
const string & stop_if_opcode="", // stop if an opcode matches this expression const string & stop_if_opcode="", // stop if an opcode matches this expression
bool recursive=false, // search recursively? bool recursive=false, // search recursively?
uint32_t max_insns=10000u, // max number of instructions to search through. uint32_t max_insns=10000u, // max number of instructions to search through.
uint32_t max_recursions=5u) // make number of blocks to recusive into uint32_t max_recursions=5u) // make number of blocks to recusive into
{ {
stopped_because_set = static_cast<Instruction_t *>(nullptr);
const auto find_or_build_regex=[&] (const string& s) -> regex_t& const auto find_or_build_regex=[&] (const string& s) -> regex_t&
{ {
// declare a freer for regexs so they go away when the program ends. // declare a freer for regexs so they go away when the program ends.
...@@ -130,8 +132,10 @@ bool backup_until(const string &insn_type_regex_str, // what to search for ...@@ -130,8 +132,10 @@ bool backup_until(const string &insn_type_regex_str, // what to search for
{ {
for(const auto &operand : disasm->getOperands()) for(const auto &operand : disasm->getOperands())
{ {
if(operand->isWritten() && regexec(&stop_operand_expression, operand->getString().c_str(), 0, nullptr, 0) == 0) if(operand->isWritten() && regexec(&stop_operand_expression, operand->getString().c_str(), 0, nullptr, 0) == 0) {
return false; stopped_because_set = prev;
return false;
}
} }
} }
// if we have a stop_if_opcode expresison, check the opcode to see if it matches. // if we have a stop_if_opcode expresison, check the opcode to see if it matches.
...@@ -156,14 +160,16 @@ bool backup_until(const string &insn_type_regex_str, // what to search for ...@@ -156,14 +160,16 @@ bool backup_until(const string &insn_type_regex_str, // what to search for
{ {
for(const auto &operand : disasm->getOperands()) for(const auto &operand : disasm->getOperands())
{ {
if(operand->isWritten() && regexec(&stop_operand_expression, operand->getString().c_str(), 0, nullptr, 0) == 0) if(operand->isWritten() && regexec(&stop_operand_expression, operand->getString().c_str(), 0, nullptr, 0) == 0) {
return false; stopped_because_set = pred;
return false;
}
} }
} }
// if we have a stop_if_opcode expresison, check the opcode to see if it matches. // if we have a stop_if_opcode expresison, check the opcode to see if it matches.
if(stop_if_opcode!="" && regexec(&stop_opcode_expression, disasm->getMnemonic().c_str(), 0, nullptr, 0) == 0) if(stop_if_opcode!="" && regexec(&stop_opcode_expression, disasm->getMnemonic().c_str(), 0, nullptr, 0) == 0)
return false; return false;
if(backup_until(insn_type_regex_str, prev, pred, stop_if_set, stop_if_opcode, recursive, max_insns, max_recursions/mypreds.size())) if(backup_until_or_move(insn_type_regex_str, prev, pred, stopped_because_set, stop_if_set, stop_if_opcode, recursive, max_insns, max_recursions/mypreds.size()))
return true; return true;
// reset for next call // reset for next call
...@@ -173,5 +179,28 @@ bool backup_until(const string &insn_type_regex_str, // what to search for ...@@ -173,5 +179,28 @@ bool backup_until(const string &insn_type_regex_str, // what to search for
return false; return false;
} }
// search for an expression in prior instructions.
bool backup_until(const string &insn_type_regex_str, // what to search for
Instruction_t *& prev, // output param -- the instruction we found.
Instruction_t* orig, // where to start the search.
const string & stop_if_set="", // stop if an operand that's written matches this expression.
const string & stop_if_opcode="", // stop if an opcode matches this expression
bool recursive=false, // search recursively?
uint32_t max_insns=10000u, // max number of instructions to search through.
uint32_t max_recursions=5u) // make number of blocks to recusive into
{
// This function is just a proxy to keep the old API intact
auto discard = static_cast<Instruction_t *>(nullptr);
return backup_until_or_move(insn_type_regex_str,
prev,
orig,
discard,
stop_if_set,
stop_if_opcode,
recursive,
max_insns,
max_recursions);
}
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment