Add RETURN context same as JUMP for dynamic relative jumps
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2020-12-28 22:45:31 +01:00
parent 76a55261ea
commit 0135a5fa37

View file

@ -120,18 +120,25 @@ void OutputContext::analyze() {
if(justReturn || justAbsolute){
if(!e.second.empty() && justReturn){
auto& instruction = image.findConstInstructionByAddress(e.first - 1, true);
if(instruction != nullptr && instruction->getCommand() == Instruction::Instruction::CommandOp::JUMP){
auto& jumpInstruction = dynamic_cast<const Instruction::Jump&>(*instruction);
if(instruction != nullptr && (instruction->getCommand() == Instruction::Instruction::CommandOp::JUMP || instruction->getCommand() == Instruction::Instruction::CommandOp::RETURN)){
std::string locText = "RETURN location for call";
bool foundReturn = false;
uint32_t addressLocation = instruction->getAddress() - 1;
if(instruction->getCommand() == Instruction::Instruction::CommandOp::JUMP){
auto& jumpInstruction = dynamic_cast<const Instruction::Jump&>(*instruction);
locText = "RETURN location for " + getLabel(jumpInstruction.jumpAddress);
}
while (true){
auto& instructionBefore = image.findConstInstructionByAddress(addressLocation, true);
if(instructionBefore != nullptr && instructionBefore->getCommand() == Instruction::Instruction::CommandOp::WRITE){
auto& writeInstruction = dynamic_cast<const Instruction::Write&>(*instructionBefore);
if(writeInstruction.data.size() == 1 && writeInstruction.data[0] == e.first){ //Return value!
//TODO: mark join?
addComment(writeInstruction.getAddress() + 4, "RETURN location for " + getLabel(jumpInstruction.jumpAddress));
addComment(writeInstruction.getAddress() + 4, locText);
foundReturn = true;
break;
}