--- Quote Start ---
can you give me the complete C code?
# include ... bla bla bla
void ....bla bla bla
--- Quote End ---
No need of includes or extra functions.
Simply add the for loops in your main() and place a breakpoint or print address and data to jtag uart when the code hits the error condition.
--- Quote Start ---
And if I already know the specific addresses/data of error , what will be the next step?
--- Quote End ---
Error on specific addresses/data can show you the problem is on a single signal.
For example, if you always write 0x0000 and read 0x0040, write 0x5555 and read 0x5555, write 0xaaaa and read 0xaaea, you can easily understand that problem is with data[6] line which is apparently locked high. Then you can investigate on that specific signal.