kermitfrog / Amiga-Re-Engineering

GNU General Public License v3.0
14 stars 1 forks source link

Debugging with Ghidra #1

Closed Pyrdacor closed 6 months ago

Pyrdacor commented 3 years ago

Hi there. I finally could compile fs-uae on Windows. Took quiet some time.

Is there an easy way to just see current values for some addresses in ghidra? The dump stuff and setup is a bit too much for me at the moment. I just want to check some values while running the game.

kermitfrog commented 3 years ago

Yes! ... Well not super easy, but less work... I actually described part of it here: https://github.com/Pyrdacor/Ambermoon.net/issues/70 Instead of sending in the output, of the d command, you can use it directly in ghidra. For example d 071795EE 8 gives me

071795EE 6006                     BT .B #$00000006 == $071795f6 (T)
071795F0 4eb9 0717 95fc           JSR $071795fc
071795F6 4cdf 1cff                MOVEM.L (A7)+,D0-D7/A2-A4
071795FA 4e75                     RTS 
071795FC 48e7 c000                MOVEM.L D0-D1,-(A7)
07179600 4eb9 0717 7146           JSR $07177146
07179606 4a80                     TST.L D0
07179608 6710                     BEQ.B #$00000010 == $0717961a (F)

Then in Ghidra's menu, open "Search" -> "For Instruction Patterns". In this window click on the icon left of the house (see the Readme.md here for a screenshot / details). Choose hex as input mode and enter the middle parts (you can copy it and delete the rest in the window, or use a tool like cut for it), so you get this:

60 06
4e b9 07 17 95 fc
4c df 1c ff
4e 75
48 e7 c0 00
4e b9 07 17 71 46
4a 80
67 10

Then you might need to mask absolute addresses by clicking on them to get this preview:

60 06
4e b9 [........] [........] [........] [........]
4c df 1c ff
4e 75
48 e7 c0 00
4e b9 [........] [........] [........] [........]
4a 80
67 10

Click on "Search all" and if all goes well, you should get a list with exactly one result. Subtract the location from the PC value (here: 071795EE) and you got your offset. Add this to the address in ghidra and you get the address for your breakpoints.