Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

How to get along with memory access errors?

Hello,

Im working long time with NIOS Processor and getting more and more in trouble with memory access errors. I tried several things to get allong with it, but the problem still resists and comes over again and again.

Typical Situation:

I have somewhere in my programm a memory access error, by crossing ranges of an array or using invalid pointers, have some buffer overflow or anything simular.

Because NIOS Processor doesn't have MMU, it does not detect anything!

Because NIOS C Compiler cannot check ranges or detect invalid pointers, i get not told about such errors in right time.

What gets caused by the Memory Access Error:

- Sometime, nothing

- Sometime, LIBC Functions never return or fail

- Sometime, LWIP Stack stops working, and my socket server waites forever

- Sometime, Stack gets corrupted and Programm hangs up or does strange things

- Sometime, everything hangs up

- Sometime, Some Data gets corrupted

The behaviour is not or hardly reproducable and it takes long time to find the reasonable error.

I tried several things to get along this :

- avoid using unsave string opartions

- used an own memory management to avoid libc dependency

- register every used memory block and manged them in a list

- reduce pointer and dynamical memory usage

- using more and more constant pointer and constant definitions

- using wrappers for all memory functions (strcpy, malloc, free, ...) and checked every write access to memory, compare with the list of registered memory blocks

- checked every pointer on function entry if valid and if it points to registered memory blocks - this worked fine but it doesn't found every error and it takes about 80% cpu usage

- tried to use ISS for running testcases, but it's limited and i have problems in combination with uCOS

- tried to apply a boundary check patch to the gcc compiler, but i failed (anyone succeed?)

- tried to work out a plattform independend layer and switch development to x86 plattform, but messed up with to much work and failed

- tried to start using uclinux but failed, i did not get running the linux kernel for our customized board

So, at this state, i feel helpless getting along memory access errors... http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/sad.gif

I&#39;m interessed, how you guys get along with such thing when programming on nios?

Regards, Marek

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I cannot believe, that nobody has had this kind of error yet ...?

    Anyone?

    I tried more things to get along with memory leaks:

    - tried to switch into Windows MSVC, but had following problems:

    - uCOS Port for Windows exists but has some strange behavier (cannot create threads inside other threads)

    - MS C Compiler is not c99 compatible

    - Socket API has small differences

    next try is, to compile example webserver of altera with gcc under cygwin

    Please tell me, how you guys get along with memory leaks... !

    regards
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    cleanertm,

    are you sure your hardware is working properly? Do you use a custom board?

    Mike
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    originally posted by mir@Jul 27 2006, 11:02 AM

    cleanertm,

    are you sure your hardware is working properly? do you use a custom board?

    mike

    <div align='right'><{post_snapback}> (index.php?act=findpost&pid=17181)

    --- quote end ---

    --- Quote End ---

    Not 100% sure, but nearly 99%, because the last software version (about half year old) is working much better with the same design. But i have to much changes in code, to fall back. Was my failure, to put to much changes into the code.

    But also, the older version is not totally stable, thats why only 99%. But i&#39;m very sure, that it must be a memory leak problem or/and race condition occurence...

    Last chance, i see, is to reproduce the call graph, after detecting the hangup, but this is not very easy and takes horrible much time to implement i guess:

    - Using -instrumentation feature of the compiler (insert entry and exit callbacks on fucntion calls)

    - logging every call in a 40MB memory area (hold 25 sec. execution, wors case)

    - after detecting hangup, connect to gdb-server and halt cpu

    - read out 40mb memory area over jtag interface

    - reconstruct call graph by the help of the symbol table from elf-file

    but this beats my time repository... http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/sad.gif