RE: single stepping mips remote programs built with gcc 4.0

Newman, Sarah R
2005-11-22T05:26:04Z

> On Thu, Nov 17, 2005 at 02:23:17PM -0800, Newman, Sarah R wrote:
> > I built it with the default options, that good enough?
> Something like
> > "-g -O2" it seems.
> >
> > I doubt that mips32_next_pc is getting compiled in because
> I can set a
> > breakpoint at mips_next_pc but not mips32_next_pc.
> > mips_software_single_step never gets called in this
> sequence, should it
> > be?
>
> Could you show me a session transcript? If mips_software_single_step
> isn't placing the breakpoint, what is?
>
> mips32_next_pc was probably inlined; you can retry with -g -O0 if you
> want.

mips32_next_pc is not being called.

It seems that when gdb is single stepping at the source code level it
tries to skip over the function prologues (I could be wrong.) I am
compiling with options "-g" and "-O2" and gcc 4.0 apparently removes the
prologues for very simple functions. I've been poking around
handle_inferior_event, mips_skip_prologue, and skip_prologue_using_sal
mostly. I still think the very different assembly produced by gcc 4.0
is causing problems. I may try comparing the 3.1 runtime behavior with
4.0 but I will have to recompile some libraries in order to do that and
it's late. :P

Additionally, in the below source code, if you try to to do an assembly
listing within gdb of either function A or B, it shows the function
following within the disassembly. IE disassembling function B displays
the code for A, and disassembling A displays the code for main, but main
is correctly displayed.

Some source code:

void b(int c){
printf("%d",c+2);
}

void a(void){
b(2);
}

int main(){
a();
return 0;
}

gcc 3.1 disassembly:
8000198c :
8000198c: 24850002 addiu a1,a0,2
80001990: 3c048403 lui a0,0x8403
80001994: 27bdffe8 addiu sp,sp,-24
80001998: afbf0010 sw ra,16(sp)
8000199c: 0c002b57 jal 8000ad5c <printf>
800019a0: 24848000 addiu a0,a0,-32768
800019a4: 8fbf0010 lw ra,16(sp)
800019a8: 00000000 nop
800019ac: 03e00008 jr ra
800019b0: 27bd0018 addiu sp,sp,24

800019b4 :
800019b4: 27bdffe8 addiu sp,sp,-24
800019b8: afbf0010 sw ra,16(sp)
800019bc: 0c000663 jal 8000198c
800019c0: 24040002 li a0,2
800019c4: 8fbf0010 lw ra,16(sp)
800019c8: 00000000 nop
800019cc: 03e00008 jr ra
800019d0: 27bd0018 addiu sp,sp,24

800019d4 :
800019d4: 27bdffe8 addiu sp,sp,-24
800019d8: afbf0010 sw ra,16(sp)
800019dc: 0c00066d jal 800019b4
800019e0: 00000000 nop
800019e4: 8fbf0010 lw ra,16(sp)
800019e8: 00001021 move v0,zero
800019ec: 03e00008 jr ra
800019f0: 27bd0018 addiu sp,sp,24

gcc 4.0 disassembly:
80001980 :
80001980: 24850002 addiu a1,a0,2
80001984: 3c048402 lui a0,0x8402
80001988: 08002b4a j 8000ad28 <printf>
8000198c: 24840100 addiu a0,a0,256

80001990 :
80001990: 08000660 j 80001980
80001994: 24040002 li a0,2

80001998 :
80001998: 27bdffe8 addiu sp,sp,-24
8000199c: afbf0010 sw ra,16(sp)
800019a0: 0c000664 jal 80001990
800019a4: 00000000 nop
800019a8: 8fbf0010 lw ra,16(sp)
800019ac: 00001021 move v0,zero
800019b0: 03e00008 jr ra
800019b4: 27bd0018 addiu sp,sp,24

--
run with 4.0 version:

(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0xffffffff80001998 in main at tmp.c:11
2 breakpoint keep y 0xffffffff800019b0 in main at tmp.c:14

(gdb) p/x $pc
$1 = 0x80001998

(gdb) step
(gdb) p/x $pc
$2 = 0x800019a0

(gdb) set debug remote 1
(gdb) step
Sending packet: $m80001998,4#70...Ack
Packet received: 27bdffe8
Sending packet: $M80001998,4:0005000d#43...Ack
Packet received: OK
Sending packet: $m800019b0,4#91...Ack
Packet received: 03e00008
Sending packet: $M800019b0,4:0005000d#64...Ack
Packet received: OK
Sending packet: $s#73...Ack
Packet received: S05
Sending packet: $p25#d7...Ack
Packet received: 800019a4
Sending packet: $s#73...Ack
Packet received: S05
Sending packet: $p25#d7...Ack
Packet received: 80001990
Sending packet: $p1d#05...Ack
Packet received: 8402ba60
Sending packet: $p1f#07...Ack
Packet received: 800019a8
Sending packet: $m8000199c,4#9b...Ack
Packet received: afbf0010
Sending packet: $m800019a0,4#90...Ack
Packet received: 0c000664
Sending packet: $m800019a4,4#94...Ack
Packet received: 00000000
Sending packet: $c#63...Ack
Packet received: S02
Sending packet: $p25#d7...Ack
Packet received: 800019b0

--
Backtrace taken right before the above continue:

#0 remote_resume (ptid={pid = -1, lwp = 0, tid = 0}, step=0,
siggnal=TARGET_SIGNAL_0) at ../../GDB-ISS/gdb/remote.c:2603
#1 0x004240bb in resume (step=0, sig=TARGET_SIGNAL_0)
at ../../GDB-ISS/gdb/infrun.c:624
#2 0x004278b7 in keep_going (ecs=0x22d810) at
../../GDB-ISS/gdb/infrun.c:2825
#3 0x00427606 in step_into_function (ecs=0x22d810)
at ../../GDB-ISS/gdb/infrun.c:2708
#4 0x00426d3a in handle_inferior_event (ecs=0x22d810)
at ../../GDB-ISS/gdb/infrun.c:2433
#5 0x0042467f in wait_for_inferior () at
../../GDB-ISS/gdb/infrun.c:1000
#6 0x004244c7 in proceed (addr=18446744073709551615,
siggnal=TARGET_SIGNAL_DEFAULT, step=1) at
../../GDB-ISS/gdb/infrun.c:825
#7 0x00417cc4 in step_1 (skip_subroutines=0, single_inst=0,
count_string=0x0)
at ../../GDB-ISS/gdb/infcmd.c:717
#8 0x004179ff in step_command (count_string=0x0, from_tty=1)
at ../../GDB-ISS/gdb/infcmd.c:606