gdb
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem - Memory access violation


From: Sandeep222
Subject: Problem - Memory access violation
Date: Mon, 11 May 2009 02:39:11 -0700 (PDT)

Hi,

I am trying to customize GDB to build specific application and I am in a
position when I am not able to proceed any further. Any help will be greatly
appreciated. 

Let us assume a user program is executing using GDB.  

1) I give a command ‘traze e’… Which is defined by me in GDB internals, ‘e’
represents enable. Inside function ‘traze e’, it will set a 15th bit flag in
embedded target board. That indicates that program counter values from that
user source’s location must be stored serially in an array, eg, pc_int[100],
which is defined in user code. 

 
2) suppose I have given breakpoint after say ‘current location +10’. I say
(gdb)continue. GDB will execute until breakpoint is present. The pc values
of executed instructions keep storing in that array pc_int by an interrupt
method (leave this, not necessary). 

(gdb)traze e

(gdb)b +10

(gdb)continue

 

3)Now I say 

(gdb) traze d 0xffee245ab 

Where the hex value input is the base address of array pc_int. 

 
This command should perform the operation of passing contents of pc_int one
by one (in this case, 10 pc values) to another function(inside GDB, of
course) which returns line number and file name information of the pc value
which is stored. 

Problems I face:

Using the base address of pc_int array in GDB command line, I am not able to
access pc_int’s values (pc_int[0], pc_int[1], etc) since it gives me error
‘Segmentation fault’. It has access violations probably since it is not
supposed to access any other memory location… in this case, I am trying to
access user program’s memory from GDB. 

What I thought: Probably go through print command, how it works
(printcmd.c), print_command(). And see how it is able to get values and
prints in stdout. I am trying to see how it gets value but finding it very
difficult to comprehend since the storage of value is complicated process.
It stores in a structure in value.h. struct value{}. Now I have no clue how
to proceed… how to access the memory pointed by base address?? Etc…

Source.c

 
Static void fileinfo_store(char *arg); //returns filename and line number of
pc values I pass

/* newly inserted traze command */

static void traze_command (char *arg, int from_tty)

{

  if (!arg || !*arg)

    error (_("traze command requires an argument")); 

  if (*arg=='e')

    printf ("Successful\n");

  else if (*arg=='d') // IF I GIVE COMMAND ‘traze d’, ENTER HERE

{

arg++;  //CHARACTER AFTER ‘d’, I.E, THE ADDRESS 0X3FFE4055

addr_arg=strtoul(arg,NULL,16); //STRING ADDRESS TO UNSIGNED LONG CONVERSION

ptr=(int *)addr_arg; // MAKE IT A INTEGER POINTER

while(*ptr!=0) /*Here it gives segmentation fault, since I am tryin to
access a different memory, user program's memory... */

  {

char pc_in_char[11]; // I need to pass contents of the pointer as a string
to fileinfo_store

pc_in_char[0]=’*’; //necessary content of first location

sprintf(&pc_in_char[1], “%x”, *ptr);// required string

fileinfo_store(pc_in_char);//do operation until contents are 0

ptr++;

  }

}

  else

    printf ("Unsuccessful\n");

}

Thanks a lot. 
Regards, 
Sandeep



-- 
View this message in context: 
http://www.nabble.com/Problem---Memory-access-violation-tp23480127p23480127.html
Sent from the Gnu - gdb - General mailing list archive at Nabble.com.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]