I started using the watchdog timer (functions wdt_enable() and wdt_reset()). I hoped that after the watchdog timer generates the reset I would be able to read the Watchdog Reset Flag (WDRF) from the MCUCSR register (ATmega8A Data Sheet).
However I found that all MSUSR bits are always set to zero after the reset. My understanding from various threads on this forum is that this is the standard behavior of the Arduino bootloader. I guess it is implemented that way for a reason and there is no way I can check the WDRF value?
The only purpose why WDRF value interests me is to know if there was an error.
That's correct. If you install AVRDude's MegaCore, it includes a version of Optiboot that has features to better preserve the content of MCUCSR for the application. You will need to burn the new bootloader onto your Mega (getting back 7k of flash space in the process!)
I have never replaced (burned) the bootloader, so that's something to learn first. I will check some articles how to do that.
Meanwhile I looked into the boards.txt from Arduino IDE subfolder to see what 's there and among other information I found that for Arduino Mega 2560 board there is defined the current bootloader file as mega.menu.cpu.atmega2560.bootloader.file=stk500v2/stk500boot_v2_mega2560.hex. So I guess that's the file I will be replacing? But I need to read about the whole process first.