hrydgard/ppsspp — pull request #4704 by unknownbrackets (2013-12-02 06:11:04+00:00)
Title: Improve function symbol detection

It's a little bit messy, probably should turn that func into a class/struct since it's getting awfully stateful...

Anyway, this makes some major changes to function detection:

When there's no text section, scan the initial load address -> the first stub address. There may be garbage, but almost always it's just functions. Impact of scanning garbage should be low...?

When there's already a symbol map, correctly step through them and insert into the func table so we can hash later.

Improves detection of this form of code:
```
// Something like...
if (a0 != 0)
*a0 = 0;
return 0;

func:
beq a0, zero, exit
li v0, 0
sw v0, 0(a0)

exit:
jr ra
nop
```

The branch to jr ra was preventing a function end.

Improves detection of this form of code:
```
// Something like...
if (a0 != 0)
{
*a0 = 0;
return 0;
}
else
return 0;

func:
beq a0, zero, func_fatal
nop
j func_safe
sw zero, 0(a0)

func_fatal:
jr ra
li v0, 0

func_safe:
jr ra
li v0, 0
```

Before it would end early (at the func_fatal return.)

And finally attempts to detect tail call and end the func early, e.g.:
```
// Something like
return otherFunc(a0 * 2 + a2, a3, a1);

addu a0, a0, a0
addu a0, a0, a2
move a2, a1
j otherFunc
move a1, a3
```

Before it would keep going until it hit a jr ra.

This *significantly* improves the accuracy, although I would guess it's still misdetecting sometimes. I find a lot more instances of common funcs in games with these changes, and all the cases I've noted where it guessed wrong seem okay.

-[Unknown]