This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
gdb + mmap + /dev/mem
- From: "rtainewbie" <rtainewbie at libero dot it>
- To: "gdb" <gdb at sources dot redhat dot com>
- Date: Fri, 1 Apr 2005 18:41:12 +0200
- Subject: gdb + mmap + /dev/mem
I am trying to debug a simple application running on GNU-Linux kernel 2.6.8.1
(see attachment).
This application works in a memory region not visible for linux (parameter
mem=XXX at boot time).
I map this region using mmap on /dev/mem device as root user.
When I debug it, accessing pointer to this region, the system freezes. So reboot
is necessary and no debug is possible.
The application work correcty but the only solution for debug it is running a
concurrent application that writes the content of this memory region using printf.
Does anybody know an easier and more confortable solution.
Thanks a lot.
____________________________________________________________
Navighi a 2 MEGA e i primi 3 mesi sono GRATIS.
Scegli Libero Adsl Flat senza limiti su http://www.libero.it
#include<stdio.h>
#include <sys/mman.h>
#include <syscall.h>
#include <errno.h>
int main()
{
int fd,i;
unsigned char * mem1, *mem2;
const int size = 2 * 1024 * 1024;
unsigned long addrphys = 254 * 1024 * 1024;
mlockall(MCL_CURRENT| MCL_FUTURE);
if ((fd = open("/dev/mem", 02) ) < 0)
{
printf("can't open /dev/mem \n");
exit (-1);
}
mem1 = (unsigned char *) mmap((void *)0,size ,PROT_READ | PROT_WRITE,MAP_SHARED , fd, addrphys);
if (mem1)
memset(mem1,0, size-1);
printf("%d",(int) mem1);
if (mem1)
{
for (i=0; i < (size-1); i++)
{
printf("%x ", *(mem1 +i));
}
printf("\n\r");
}
munmap((void *)mem1,size );
close(fd);
}