请教斑竹:关于uclinux的gdbserver
你好 ,斑竹,我看看了一下论坛,你那里应该有如何修改uclinux for arm 下的gdbserver的详细步骤,可否发给我参考。我现在遇到的问题就是gdbserver不能使用,我的邮箱:[email protected] .万分感谢 这是 罗翚<[email protected]>完成的工作,一直还没有合成到skyeye中。很对不起罗翚的贡献!
零. 启
某Uclinux开发包带的gdbserver是for m68k的.修改目标是提供一个可用的支持at91
的gdbserver.由于该开发包配套的uclinux kernel2.4.17的ptrace存在问题,也需要
相应的修改.
一. gdbserver的修改
将uClinux disc自带的gdbserver for m68k改成了for arm-uclinux的版本.
只需要加一个调测魔数的转换就可以支持
断点.改动量很小.我描述一下gdbserver for arm-uclinux的具体思路:
没有经过多次调试,可能有很多问题
1)增加和tm-m68k.h对应的tm-arm.h,需要有如下定义:
#define REGISTER_RAW_SIZE(x) 4
#define REGISTER_BYTES (17*4)
#define REGISTER_BYTE(x) (4*x)
#define NUM_REGS 17
#define MAX_REGISTER_RAW_SIZE 4
#define NUM_FREGS 0
#define PC_REGNUM 15
#define SP_REGNUM 13
#define FP_REGNUM 14
2)low-linux.c用如下的arm_register_u_addr代替m68k_linux_register_u_addr
static int regmap[] =
{
0, 1, 2, 3,
4, 5, 6, 7,
8, 9, 10, 11,
12, 13, 14, 15,
16, 17
}; //p.357
int
arm_register_u_addr (blockend, regnum)
int blockend;
int regnum;
{
return (blockend + 4 * regmap);
}
3)支持断点,在server.c中
extern unsigned int code_end;
extern unsigned int code_start;
#define ARM_BREAKPOINT 0xe7ffdefe
#define ARM_LINUX_BREAKPOINT 0xef9f0001
void bp_opcode_conv(unsigned long addr, unsigned long *p_op)
{
if( addr < code_start || addr > code_end ) return ;
if( *p_op != ARM_BREAKPOINT) return ;
*p_op = ARM_LINUX_BREAKPOINT;
}
main()中增加一行
case 'M':
decode_M_packet (&own_buf, &mem_addr, &len, mem_buf);
bp_opcode_conv( (unsigned long) mem_addr,
(unsigned long*)mem_buf ); //added ...
.....
二. ptrace的修改
本修改针对uclinux kernel2.4.17.对于其他版本,可以按照本文思想进行修改.
a.uclinux2.4.17 for at91(我测试的版本)缺省运行的flat程序是在USER26Mode下,
不是USER32Mode.这样,gdbserver/skyeye(client)的单步运行就会出问题.
我修改了arch/armnommu/kernel/ptrace.c,以支持这种情况.
b.uclinux的ptrace没有对内存读写做限制,很容易搞到进程外内存
//added by telpro
#define REG_SP 13
int in_arm26_mode(struct task_struct *child)
{
long psr;
psr = get_stack_long(child, REG_PSR) ;
return ((psr & 0x1f) <= 3);
}
#define FIXPC(child, x) \
do { \
if(in_arm26_mode(child)) x = x & 0x0ffffffc; \
}while(0)
//do as arch/armnommu/kernel/process.c
//a dirty version, FIXME...telpro
int is_addr_access( struct task_struct *child,
unsigned long addr )
{
unsigned long sp;
if ( addr >= child->mm->start_code &&
addr < child->mm->end_code )
return 1;
if ( addr >= child->mm->start_data &&
addr < child->mm->brk )
return 1;
sp = get_stack_long(child, REG_SP) ;
//actually <sp is r/w also.
if ( addr >= sp &&
addr < child->mm->start_stack )
return 1;
return 0;
}
int ptrace_set_bpt(struct task_struct *child)
{
struct pt_regs *regs;
unsigned long pc, insn;
int res;
regs = get_user_regs(child);
pc = instruction_pointer(regs);
//26bit , added by telpro
FIXPC(child, pc);
res = read_tsk_long(child, pc, &insn);
if (!res) {
struct debug_info *dbg = &child->thread.debug;
unsigned long alt;
dbg->nsaved = 0;
alt = get_branch_address(child, pc, insn);
if (alt) {
FIXPC(child, alt); //added by telpro
res = add_breakpoint_arm(child, dbg, alt);
}
.........
}
static int do_ptrace(int request, struct task_struct *child, long addr, long data)
中加入
case PTRACE_PEEKTEXT:
case PTRACE_PEEKDATA:
/*added by telpro*/
if (!is_addr_access(child, addr) ) {
ret = -EIO;
break;
}
ret = read_tsk_long(child, addr, &tmp);
....
case PTRACE_POKETEXT:
case PTRACE_POKEDATA:
/*added by telpro*/
if (!is_addr_access(child, addr) ) {
ret = -EIO;
break;
}
ret = write_tsk_long(child, addr, data);
break;
.......
case PTRACE_PEEKUSR:
ret = -EIO;
if ((addr & 3) || addr < 0 || addr >= sizeof(struct user))
break;
tmp = 0; /* Default return condition */
if (addr < sizeof(struct pt_regs)) {
tmp = get_stack_long(child, (int)addr >> 2);
//added by telpro, for at91
if(addr == 14*4 || addr == 15*4 ) {
FIXPC(child, tmp);
}
} else if (addr == 49*4) {
tmp = child->mm->start_code;
} else if (addr == 50*4) {
tmp = child->mm->start_data;
} else if (addr == 51*4) {
.....
三.已知问题
a.现在对USER26MOde的应用程序不是支持得很好,
r14,r15是按照USER32Mode显示的结果. 这是不对的.
完整的解决需要修改client端软件,也就是skyeye与gdbserver配合的部分.
不过,USER26总感觉是一种淘汰模式,xscale这些已经不支持它了.
因此,也不想花大力气去解决.
b.Thumb模式不支持
页:
[1]