Hi Boris,

so far I have only been working with x86_64.

It only break with new versions of gdb because they introduced a check whether there seems to be a register that is not transmitted completely. This check shall prevent a buffer overflow which originated from the fact that they assumed a register to be contained completely in the G packet once they saw the first byte of it. When they passed this buffer to the next instance using it they possible read out of bounds, but this never caused any serious damage, so nobody noticed it. So I think, we have always been affected but it wasn't noticeable as long as the G packet was just too large, all the registers that were there have been transmitted correctly.

The reason the struct needs to be packed now, is that there are 7 32 bit registers in that struct (28 byte), but the compiler aligns that to 8 byte and adds 4 byte padding at the end which sums up to 32 byte. The additional 4 byte make gdb think there is a 24th register that should have been transmitted, but it misses some bytes (6 in particular, gdb expect register 24 to have a size of 10 byte) so it stops working.

I also know your original implementation of the RSP server. There cutting of 4 bytes of the register buffer solved the problem (See attached patch).
I hope that answers some of your questions.

Cheers,
Matthias


Am 03.05.2017 um 16:47 schrieb Nils Asmussen:
Hi Boris,

I have used remote GDB quite extensively over the last 2 years. Mostly
for x86_64, but also a bit for ARM (32 bit). It always worked fine and
still works fine. I'm running it on a 64-bit Arch Linux and they do not
(yet) use the mentioned patch, as I've just verified.

Best regards,
Nils


On 05/03/2017 04:20 PM, Boris Shingarov wrote:
Hi Matthias,

I want to understand this better.  The original RSP server in gem5
viewed the contents of G packet as an array of registers all of the same
width.  So, if an architecture defines some 64-bit registers and some
32-bit registers, this had lead to idiotic situations such as registers
having a fractional index.  So about a year ago, I re-wrote register
representation in the G packet to use C structs instead.  This new code
has been working well for me using both GDB and another RSP client which
we hope to present to the community (although that's quite another
story, for now what's relevant is just that there are two RSP clients
that I compared in how they talk to GEM5's RSP server).  My main ISAs I
was using at the time, were PPC and MIPS, but I do remember that I did
test all other ISAs which has separate register layout definitions.  You
don't say what ISA you are working with, but from your patch I presume
you are talking about x86_64, right?

What I am not quite getting is how it is only the newer GDB that
breaks.  If the fields in the struct are incorrectly packed, then
offsets of where register values are in the G packet, will be wrong no
matter which GDB version is on the client end.  So this raises two
interesting questions.  First, what is the extent of this problem across
versions of GDB -- have we always been affected?  Second, what is the
extent across ISAs -- does this also break ARM and others?  I mean,
these G packets have been used for some time, and at least *some* of it
worked to useful ends -- both in my own work, and I hear that others
have also used it for practical purposes.  I would like to better
understand where the limit of that "some" is.  Maybe others can chime in
saying things like "using remote GDB extensively and it works" or the
opposite? to have at least some kind of picture of whether people even
exercise that corner of the universe.

Boris


-----"gem5-users" <[email protected]
<mailto:[email protected]>> wrote: -----
To: <[email protected] <mailto:[email protected]>>
From: Matthias Hille
Sent by: "gem5-users"
Date: 05/02/2017 11:49AM
Subject: [gem5-users] Newer gdb versions break remote debugging

Hi all,

I noticed that newer gdb versions break the ability to attach a remote
debugger to debug simulated code.
The good thing is, I already figured out why. Starting with commit
9dc193c3be
<https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=9dc193c3be85aafa60ceff57d3b0430af607b4ce>
gdb does bounds checking for every register you sent to it via the
remote debugging protocol. If a register is not sent complete it will
output "Truncated register xy in remote 'g' packet" and that's what
actually happens with the current gem5 version.
Gem5 transmits 23 registers (17 64bit regs and 7 32bit regs) that should
result in a total amount of 164 bytes. But it actually send 168 bytes,
making gdb believe it will receive a 24th register. For the 24th
register gdb expects a size of 10 bytes and hence complains about it and
refuses to continue working.
The reason for the 4 byte overlap is that the structure used to keep
register contents is 8-bytes aligned.
So my current fix is packing that struct so gem5 won't send the padding
bytes. (Diff is attached)

I am not entirely sure if this breaks compilation for some of you. I
used #pragma pack() to tell the compiler to pack the struct, and most of
the compilers should support it.

Cheers,
Matthias
_______________________________________________
gem5-users mailing list
[email protected] <mailto:[email protected]>
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users


[attachment "remoteDebugFix.diff" removed by Boris Shingarov/Employee/LW-US]

<https://www.labware.com/2017NACEC>

<https://www.facebook.com/pages/LabWare-Inc/160466077336230><https://plus.google.com/116884607850969454032/posts>
<http://www.linkedin.com/company/labware>


_______________________________________________
gem5-users mailing list
[email protected]
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users

<http://www.linkedin.com/company/labware>
_______________________________________________
gem5-users mailing list
[email protected]
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users

From 61b387e8f07377c75ec8dd1177c3f95d6245644e Mon Sep 17 00:00:00 2001
From: Matthias Hille <[email protected]>
Date: Wed, 3 May 2017 11:18:54 +0200
Subject: [PATCH] x86: Fixed remote debugging of simulated code

GDB breaks if more bytes are sent than the transmitted registers
actually need.
---
 src/arch/x86/remote_gdb.hh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/arch/x86/remote_gdb.hh b/src/arch/x86/remote_gdb.hh
index 991452f74..45235af3a 100644
--- a/src/arch/x86/remote_gdb.hh
+++ b/src/arch/x86/remote_gdb.hh
@@ -124,7 +124,7 @@ class RemoteGDB : public BaseRemoteGDB
 
 const int GDB_REG_BYTES M5_VAR_USED =
     std::max(RemoteGDB::GDB32_NUMREGS * sizeof(uint32_t),
-             RemoteGDB::GDB64_NUMREGS * sizeof(uint64_t));
+             RemoteGDB::GDB64_NUMREGS * sizeof(uint64_t) - sizeof(uint32_t));
 
 }
 
-- 
2.11.0

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
gem5-users mailing list
[email protected]
http://m5sim.org/cgi-bin/mailman/listinfo/gem5-users

Reply via email to