0

gcc version is 4.1.2 used to compile the program in debug mode

valgrind --log-file="log.txt" -v prog

program throws error of unable to attach to shared memory at address

without valgrind the program is starting properly

Not sure if this is because of old gcc version.

Also please let me know if there is any workaround without upgrading compiler if that is the reason.

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
Medicine
  • 1,923
  • 2
  • 23
  • 33
  • How do you select the address at which shared memory is created? If you have a calculated address, rather than letting the system pick the address for you, could it be that `valgrind` is using space at that address? – Jonathan Leffler Jan 07 '15 at 20:00
  • no shared memory is allocated before valgrind starts up. so valgrind shouldn't take that space. – Medicine Jan 07 '15 at 20:41
  • But is the space that `valgrind` uses where you'd normally locate the shared memory? There are two modes for shared memory allocation: allocate at a user-defined address or at a system-chosen address. If you let the system specify the shared memory address, then I have nothing for you. If you choose the address, then maybe the address you're choosing is already in use by `valgrind`. Or is the trouble that `valgrind` doesn't get you to the point where you can allocate shared memory? You should probably identify the platform and version number as well. – Jonathan Leffler Jan 07 '15 at 21:05
  • Consider using strace as another tool for debugging, you can strace valgrind as it in turn runs your program. The loader will use mmap to map shared libraries, so it might take some sleuthing to figure out who is making each of the mmap calls http://stackoverflow.com/questions/174942/how-should-strace-be-used – amdn Jan 07 '15 at 21:26

1 Answers1

1

I also faced exactly the same problem that Valgrind was not able to access the shared memory region which was used by the program Valgrind was operating on. With the help of the link given below, I figured out that shmat needs to be provided an address such that the address of the shared region does not conflict with Valgrind.

Link: shmat-calls-fails-with-invalid-argument-under-valgrind.

so I did the following and it worked i.e., Valgrind is now working fine with the program using shared region.

#define SHMEM_REGION_ADDRESS 0x000007FC9000


int shmid = shmget(key,PMO_SIZE,0666|IPC_CREAT);

// shmat to attach to shared memory at the specified address

void *shmem_ptr =  shmat(shmid,(void*)(SHMEM_REGION_ADDRESS),0);
Useless
  • 64,155
  • 6
  • 88
  • 132
NUM
  • 37
  • 2