0

I write a program on c. Also to check it I compile on gcc it with -fprofile-arcs -ftest-coverage( for gcov) and check program by valgrind. I need to malloc does not alllocate memory. So I use rlimit with key RLIMIT_AS. But if l set a small size of rlim_cur , then memory does not allocate, but gcov cannot create itself files for check coverage. And valgrind cannot execute because of limit of memory. If I set big size, memory is allocated. But I cannot found a " gold middle". Because , how i understood, it is mutually exclusive. How can I solve this problem? It is necessarily to working gcov and valgrind

user3533019
  • 193
  • 1
  • 2
  • 9
  • So you are trying to simulate an out of memory condition? – Eric J. Apr 17 '14 at 23:39
  • 1
    You could play `LD_PRELOAD` tricks to make your own `malloc` (which might fail after allocating a given amount of memory). – Basile Starynkevitch Apr 17 '14 at 23:40
  • I do not know how do it, only as rlimrt function. – user3533019 Apr 17 '14 at 23:42
  • This is good advice, but it is not what I need. – user3533019 Apr 17 '14 at 23:44
  • 1
    `LD_PRELOAD` is the way to go. See [this previous answer](http://stackoverflow.com/a/6083624/3515931) for a 'how to' -- you can add an additional exported function to set a value to make the next malloc fail, and modify the code in the routine to check for it and then return the fail conditions to check your code (or any other mod you can dream up) -- just remember the real malloc() needs to be available in the wrapper most of the time because LD_PRELOAD effects ALL processes loaded after the env variable is set, not just the one you want to test. – JohnH Apr 18 '14 at 00:02

0 Answers0