ptrace problem

"Gaurav Khurana" <[email protected]> Wed, 10 Nov 2004 14:45:43 +0530
Newsgroups gmane.linux.ports.sh.devel,gmane.linux.ports.sh.general
Message-ID <33BC33A9E76474479B76AD0DE8A169728DE4@exch-ntd.nec.noida.hcltech.com>
Hi,
I am trying to debug a program on BigSurIV board with uClinux-2.4.x and
uClibc using gdbserver. When gdbserver traces a new process and finds
the value of the registers from the user area, the values it receives
are not correct. It receives the values moved left by 1 place. It gets
the value of pr as pc and r1 as r0, r2 as r1 etc. It also writes the
values of the registers in the same manner. But if I subtract 4 (i.e.
size of any general purpose register) from the address of any register
stored in user area (in the ptrace system call) it gives the correct
values and the gdbserver works correctly.

I have also verified this by writing a small debug program which uses
ptrace system call to debug a process. I have also verified that the
address where the user area of a new process is copied from the parent
process is same as from where ptrace reads.

linux-2.4.x/arch/sh/kernel/process.c :-
copy_thread( ... ) {
...
childregs =3D ((struct pt_regs *)(THREAD_SIZE + (unsigned long) p)) - 1;
*childregs =3D *regs;
...
}


linux-2.4.x/arch/sh/kernel/ptrace.c :-
get_stack_long( ... ) {
...
stack =3D (unsigned char *)task + THREAD_SIZE - sizeof(struct pt_regs);
...
}

The debugger works correctly if I change the above line both in
get_stack_long and put_stack_long (in arch/sh/kernel/ptrace.c) to :-
stack =3D (unsigned char *)task + THREAD_SIZE - sizeof(struct pt_regs) -
sizeof(struct pt_regs *);

Since the values of stack and childregs are same. So the values of
*(struct pt_regs *)stack and *childregs should also be same. But this is
not coming out to be so and *(struct pt_regs *)(stack - 4) has same as
value as *childregs.

Any clues to what could be the problem ??

Thanks,
Gaurav Khurana


-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE
FREE OODBMS DOWNLOAD - A multidimensional database that combines
robust object and relational technologies, making it a perfect match
for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8