MIPS: Implement remote_gdb.cc for remote debugging in SE mode
Review Request #835 - Created Aug. 30, 2011 and submitted
| Information | |
|---|---|
| Deyuan Guo | |
| gem5 | |
| Reviewers | |
| Default | |
| ali, gblack, nate, stever | |
Implement gem5/src/arch/mips/remote_gdb.cc. So a mips-cross-gdb can connect with gem5(MIPS_SE), and do some remote debugging.
Build gem5 for MIPS_SE and make gem5 wait at beginning: modify "rgdb_wait = -1" to "rgdb_wait = 0" in src/sim/system.cc; scons build/MIPS_SE/gem5.opt CPU_MODELS=O3CPU ---- Build GDB-7.3 mips-cross: ./configure --target=mips-linux-gnu --prefix=xxx/gdb-7.3-install/ make make install ---- Run: ./build/MIPS_SE/gem5.opt configs/example/se.py --detailed --caches ./mips-linux-gnu-gdb xxx/gem5/tests/test-progs/hello/bin/mips/linux/hello (gdb) target remote :7000 (gdb) info registers (gdb) disassemble (gdb) si (gdb) break main (gdb) c (gdb) quit Testing done.
Posted (Aug. 31, 2011, 10:22 a.m.)
Hi Deyuan, Thanks for the submission. There are just a couple of minor issues I'd like you to address if you could. Also you posted some ways you tested gdb but you didn't provide any of the output. Would you mind doing that too? Thanks, Ali
-
src/arch/mips/remote_gdb.cc (Diff revision 1) -
You don't really need the else, you can just end this here. If the panic is called the rest of the code will never be reached.
-
src/arch/mips/remote_gdb.cc (Diff revision 1) -
Can you use a constant for 15 here?
-
src/arch/mips/remote_gdb.cc (Diff revision 1) -
Same here.. also the random +19 isn't great
-
src/arch/mips/remote_gdb.cc (Diff revision 1) -
Also in these functions
-
src/arch/mips/remote_gdb.cc (Diff revision 1) -
Do you mean for this to be a single =? If you're just doing please pull out the notTakenBkpt and set it above, then pass notTakenBkpt to the function.
-
src/arch/mips/remote_gdb.cc (Diff revision 1) -
Same.
Review request changed
Updated (Aug. 31, 2011, 1:03 p.m.)
Change Summary:
Thanks for Ali's advice, I modified these codes.
Here are the gdb outputs, and these output are using MIPS_SE/AtomicSimpleCPU.
I found that with O3CPU, si(stepi) can not stop when meeting a branch instruction, but with AtomicSimpleCPU it doesn't have this problem.
GNU gdb (GDB) 7.3
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=mips-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/guody/M5/m5-new/gem5/tests/test-progs/hello/bin/mips/linux/hello...done.
(gdb) target remote :7000
Remote debugging using :7000
0x004001a4 in _ftext ()
(gdb) info registers
zero at v0 v1 a0 a1 a2 a3
R0 00000000 00000000 00000000 00000000 00000001 7fffe004 00000000 00000000
t0 t1 t2 t3 t4 t5 t6 t7
R8 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
s0 s1 s2 s3 s4 s5 s6 s7
R16 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
t8 t9 k0 k1 gp sp s8 ra
R24 00000000 00000000 00000000 00000000 00000000 7fffe000 00000000 00000000
sr lo hi bad cause pc
00000000 00000000 00000000 00000000 00000000 004001a4
fsr fir
00000000 00000000
(gdb) info float
f0: 0x00000000 flt: 0 dbl: 0
f1: 0x00000000 flt: 0
f2: 0x00000000 flt: 0 dbl: 0
f3: 0x00000000 flt: 0
f4: 0x00000000 flt: 0 dbl: 0
f5: 0x00000000 flt: 0
f6: 0x00000000 flt: 0 dbl: 0
f7: 0x00000000 flt: 0
f8: 0x00000000 flt: 0 dbl: 0
f9: 0x00000000 flt: 0
f10: 0x00000000 flt: 0 dbl: 0
f11: 0x00000000 flt: 0
f12: 0x00000000 flt: 0 dbl: 0
f13: 0x00000000 flt: 0
f14: 0x00000000 flt: 0 dbl: 0
f15: 0x00000000 flt: 0
f16: 0x00000000 flt: 0 dbl: 0
f17: 0x00000000 flt: 0
f18: 0x00000000 flt: 0 dbl: 0
f19: 0x00000000 flt: 0
f20: 0x00000000 flt: 0 dbl: 0
f21: 0x00000000 flt: 0
f22: 0x00000000 flt: 0 dbl: 0
f23: 0x00000000 flt: 0
f24: 0x00000000 flt: 0 dbl: 0
f25: 0x00000000 flt: 0
f26: 0x00000000 flt: 0 dbl: 0
f27: 0x00000000 flt: 0
f28: 0x00000000 flt: 0 dbl: 0
f29: 0x00000000 flt: 0
f30: 0x00000000 flt: 0 dbl: 0
f31: 0x00000000 flt: 0
(gdb) disassemble
Dump of assembler code for function _ftext:
0x004001a0 <+0>: move zero,ra
=> 0x004001a4 <+4>: bal 0x4001ac <_ftext+12>
0x004001a8 <+8>: nop
0x004001ac <+12>: lui gp,0xfc1
0x004001b0 <+16>: addiu gp,gp,-12828
0x004001b4 <+20>: addu gp,gp,ra
0x004001b8 <+24>: move ra,zero
0x004001bc <+28>: lw a0,-32616(gp)
0x004001c0 <+32>: lw a1,0(sp)
0x004001c4 <+36>: addiu a2,sp,4
0x004001c8 <+40>: li at,-8
0x004001cc <+44>: and sp,sp,at
0x004001d0 <+48>: addiu sp,sp,-32
0x004001d4 <+52>: lw a3,-31232(gp)
0x004001d8 <+56>: lw t0,-29704(gp)
0x004001dc <+60>: nop
0x004001e0 <+64>: sw t0,16(sp)
0x004001e4 <+68>: sw v0,20(sp)
0x004001e8 <+72>: sw sp,24(sp)
0x004001ec <+76>: lw t9,-31012(gp)
0x004001f0 <+80>: nop
0x004001f4 <+84>: jalr t9
0x004001f8 <+88>: nop
End of assembler dump.
(gdb) si
0x004001ac in _ftext ()
(gdb) disassemble
Dump of assembler code for function _ftext:
0x004001a0 <+0>: move zero,ra
0x004001a4 <+4>: bal 0x4001ac <_ftext+12>
0x004001a8 <+8>: nop
=> 0x004001ac <+12>: lui gp,0xfc1
0x004001b0 <+16>: addiu gp,gp,-12828
0x004001b4 <+20>: addu gp,gp,ra
0x004001b8 <+24>: move ra,zero
0x004001bc <+28>: lw a0,-32616(gp)
0x004001c0 <+32>: lw a1,0(sp)
0x004001c4 <+36>: addiu a2,sp,4
0x004001c8 <+40>: li at,-8
0x004001cc <+44>: and sp,sp,at
0x004001d0 <+48>: addiu sp,sp,-32
0x004001d4 <+52>: lw a3,-31232(gp)
0x004001d8 <+56>: lw t0,-29704(gp)
0x004001dc <+60>: nop
0x004001e0 <+64>: sw t0,16(sp)
0x004001e4 <+68>: sw v0,20(sp)
0x004001e8 <+72>: sw sp,24(sp)
0x004001ec <+76>: lw t9,-31012(gp)
0x004001f0 <+80>: nop
0x004001f4 <+84>: jalr t9
0x004001f8 <+88>: nop
End of assembler dump.
(gdb) si
0x004001b0 in _ftext ()
(gdb) disassemble
Dump of assembler code for function _ftext:
0x004001a0 <+0>: move zero,ra
0x004001a4 <+4>: bal 0x4001ac <_ftext+12>
0x004001a8 <+8>: nop
0x004001ac <+12>: lui gp,0xfc1
=> 0x004001b0 <+16>: addiu gp,gp,-12828
0x004001b4 <+20>: addu gp,gp,ra
0x004001b8 <+24>: move ra,zero
0x004001bc <+28>: lw a0,-32616(gp)
0x004001c0 <+32>: lw a1,0(sp)
0x004001c4 <+36>: addiu a2,sp,4
0x004001c8 <+40>: li at,-8
0x004001cc <+44>: and sp,sp,at
0x004001d0 <+48>: addiu sp,sp,-32
0x004001d4 <+52>: lw a3,-31232(gp)
0x004001d8 <+56>: lw t0,-29704(gp)
0x004001dc <+60>: nop
0x004001e0 <+64>: sw t0,16(sp)
0x004001e4 <+68>: sw v0,20(sp)
0x004001e8 <+72>: sw sp,24(sp)
0x004001ec <+76>: lw t9,-31012(gp)
0x004001f0 <+80>: nop
0x004001f4 <+84>: jalr t9
0x004001f8 <+88>: nop
End of assembler dump.
(gdb) break main
Breakpoint 1 at 0x400408
(gdb) c
Continuing.
Breakpoint 1, 0x00400408 in main ()
(gdb) info registers
zero at v0 v1 a0 a1 a2 a3
R0 00000000 fffffff8 1000a590 10000000 00000001 7fffe004 7fffe00c 00000000
t0 t1 t2 t3 t4 t5 t6 t7
R8 2f2f2f2f 7efefeff 81010100 0000002f 0047c1a0 00000000 00000000 00000000
s0 s1 s2 s3 s4 s5 s6 s7
R16 10000da0 00000000 7fffdeb2 00000001 7fffe004 1000a590 00000000 0040fe40
t8 t9 k0 k1 gp sp s8 ra
R24 00000000 004003e0 00000000 00000000 1000cf90 7fffddb8 7fffddb8 0040fbc0
sr lo hi bad cause pc
00000000 6666666f 00000022 00000000 00000000 00400408
fsr fir
00000000 00000000
(gdb) disassemble
Dump of assembler code for function main:
0x004003e0 <+0>: lui gp,0xfc1
0x004003e4 <+4>: addiu gp,gp,-13392
0x004003e8 <+8>: addu gp,gp,t9
0x004003ec <+12>: addiu sp,sp,-32
0x004003f0 <+16>: sw ra,28(sp)
0x004003f4 <+20>: sw s8,24(sp)
0x004003f8 <+24>: move s8,sp
0x004003fc <+28>: sw gp,16(sp)
0x00400400 <+32>: sw a0,32(s8)
0x00400404 <+36>: sw a1,36(s8)
=> 0x00400408 <+40>: lw a0,-32736(gp)
0x0040040c <+44>: nop
0x00400410 <+48>: addiu a0,a0,-26160
0x00400414 <+52>: lw t9,-32408(gp)
0x00400418 <+56>: nop
0x0040041c <+60>: jalr t9
0x00400420 <+64>: nop
0x00400424 <+68>: lw gp,16(s8)
0x00400428 <+72>: move v0,zero
0x0040042c <+76>: move sp,s8
0x00400430 <+80>: lw ra,28(sp)
0x00400434 <+84>: lw s8,24(sp)
0x00400438 <+88>: jr ra
0x0040043c <+92>: addiu sp,sp,32
End of assembler dump.
(gdb) quit
A debugging session is active.
Inferior 1 [Remote target] will be killed.
Quit anyway? (y or n) y
Diff: |
Revision 2 (+341 -17) |
|---|
Review request changed
Updated (Aug. 31, 2011, 1:09 p.m.)
Change Summary:
Sorry I don't know how to use the "Parent Diff". It caused some problems.. I have to update my patch again, with no "Parent Diff"..
Diff: |
Revision 3 (+341 -17) |
|---|
Posted (Aug. 31, 2011, 9:03 p.m.)
First, thank you for taking the time to share your work with everybody. It's easy to skip that step, and I'm glad you didn't. It'll be great to have this checked in and to fill in that gap in our MIPS support. Before then, though, there are some style problems that we'll need to fix, but they should be fairly easy to clean up. I haven't mentioned every single instance where something needs to be fixed since that would be annoying for both of us. Please look to see if a comment I made in one place applies elsewhere and fix those places as well.
-
src/arch/mips/remote_gdb.hh (Diff revision 3) -
Where do these constants come from? If there's a header file we can grab them from that would be nice, or if not then these constants are fine. Since they're not macros they shouldn't be in all caps though. I just checked, and in 2009 somebody put into the style guide that constants should have the same format as regular variables. There are many examples of capitalizing the first letter of each word in the name, though, so I think you should be consistent with the existing code.
-
src/arch/mips/remote_gdb.hh (Diff revision 3) -
Your indentation is off here. Make sure you're using spaces and not tabs. I'm not sure if that's the problem, but just in case.
-
src/arch/mips/remote_gdb.cc (Diff revision 3) -
There are a lot of header files here, and I'm guessing a few aren't necessary. Please prune this down to what you're actually using.
-
src/arch/mips/remote_gdb.cc (Diff revision 3) -
Spaces around the operators. Since you repeat this pattern over and over here, it would be good to use a simple helper function to glue the halves together.
-
src/arch/mips/remote_gdb.cc (Diff revision 3) -
This line is too long.
-
src/arch/mips/remote_gdb.cc (Diff revision 3) -
So is this one.
-
src/arch/mips/remote_gdb.cc (Diff revision 3) -
And this one.
-
src/arch/mips/remote_gdb.cc (Diff revision 3) -
Spaces around operators, and a helper function would be good here too.
-
src/arch/mips/remote_gdb.cc (Diff revision 3) -
Since MIPS has a delay slot as you mention on the next line, lets just say next NPC (or whatever the correct term is) and not need the next line to clarify.
-
src/arch/mips/remote_gdb.cc (Diff revision 3) -
It shouldn't be necessary to override this if you're just using the base class implementation. Is there a reason you need this function?
Review request changed
Updated (Sept. 1, 2011, 8:41 p.m.)
Change Summary:
Thank you, Gabe! I've learned a lot from you. I fixed these codes, and they look better than before.. Please let me know if there are some other style problems.
Diff: |
Revision 4 (+347 -17) |
|---|
Posted (Sept. 2, 2011, 5:48 p.m.)
This is looking pretty good. There are still some minor adjustments to be made, but not too much.
-
src/arch/mips/remote_gdb.hh (Diff revision 4) -
This would be better as / 2. Any compiler worth anything will figure out that a shift will work better, and it's clearer what your intention is.
-
src/arch/mips/remote_gdb.hh (Diff revision 4) -
I think lo and hi should be uint32_t. If int was somehow less than 32 bits wide (weird bug possible) you'd chop off some bits. Also, the return types should go on the line before the function name, and functions defined inside a class definition are implicitly inline so you don't need to have that on there. It would look more like this: uint64_t pack(uint32_t lo, uint32_t hi) { ... } -
src/arch/mips/remote_gdb.cc (Diff revision 4) -
You could just return the result of the condition of the if and simplify this a little.
-
src/arch/mips/remote_gdb.cc (Diff revision 4) -
Yeah, that looks better :-)
Review request changed
Updated (Sept. 3, 2011, 11:30 p.m.)
Change Summary:
Thank you so much again, Gabe! I've taken your advice and fixed the related codes.
Diff: |
Revision 5 (+348 -17) |
|---|
Review request changed
Updated (Sept. 4, 2011, 12:10 a.m.)
