This week I used GDB debugging with hosted AROS for the first time. I had a bug that was difficult to find using debug log printing. The AROS crew is kind enough to supply some macros to GDB to ease the debugging process. When GDB initially loads the hosted AROS process it only loads the symbols present in the boot ELF executable file. To be able to see symbols for stuff that has been loaded inside AROS you have to load the symbol table manually to the correct memory address. The GDB macro findaddr can be used to identify memory and where it should have its symbol table loaded. This is described in the AROS docs. The bug was an embarrassingly simple case of not initializing a variable.
Other than this I have implemented a memory dump function to aid debugging. It simply dumps a list of all memory mappings currently in Emumiga to the debug console.
I stumbled upon a new thing when I was working on getting Clock running. Clock uses stack memory to set up some structures that gets converted into mappings when they are used with a syscall. This is OK behavior of course. The problem is that I have not implemented a garbage collection of mappings yet. So when the stack frame was released it did not remove the mapping. A later stack frame overlapped this memory and everything broke down. I solved it by always clearing the stack memory below SP when an instruction increases it or sets it to some value directly. No need to clear anything when decreasing SP. This affects all instructions that uses addressing mode (SP)+ and the instructions MOVEA, SUBA, ADDA, EXG, LEA, MOVEM and UNLK when they use SP. RTS is also increasing SP, but I skipped that one. There should never be mappings set up covering the return address.