diff options
author | Pavel Labath <pavel@labath.sk> | 2020-02-13 14:30:04 +0100 |
---|---|---|
committer | Pavel Labath <pavel@labath.sk> | 2020-02-26 10:18:58 +0100 |
commit | d4eca120ac0af2a805c19301412bf843a71c14b5 (patch) | |
tree | f111c7bb6449c3b1b9119fa4ebfa819ee5895e16 /lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp | |
parent | 4feca71df0ca96237342d0e3ef41e3cdbfa0e27c (diff) | |
download | llvm-d4eca120ac0af2a805c19301412bf843a71c14b5.zip llvm-d4eca120ac0af2a805c19301412bf843a71c14b5.tar.gz llvm-d4eca120ac0af2a805c19301412bf843a71c14b5.tar.bz2 |
[lldb/gdb-remote] Add support for the qOffsets packet
Summary:
This packet is necessary to make lldb work with the remote-gdb stub in
user mode qemu when running position-independent binaries. It reports
the relative position (load bias) of the loaded executable wrt. the
addresses in the file itself.
Lldb needs to know this information in order to correctly set the load
address of the executable. Normally, lldb would be able to find this out
on its own by following the breadcrumbs in the process auxiliary vector,
but we can't do this here because qemu does not support the
qXfer:auxv:read packet.
This patch does not implement full scope of the qOffsets packet (it only
supports packets with identical code, data and bss offsets), because it
is not fully clear how should the different offsets be handled and I am
not aware of a producer which would make use of this feature (qemu will
always
<https://github.com/qemu/qemu/blob/master/linux-user/elfload.c#L2436>
return the same value for code and data offsets). In fact, even gdb
ignores the offset for the bss sections, and uses the "data" offset
instead. So, until the we need more of this packet, I think it's best
to stick to the simplest solution possible. This patch simply rejects
replies with non-uniform offsets.
Reviewers: clayborg, jasonmolenda
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D74598
Diffstat (limited to 'lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp')
-rw-r--r-- | lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp index f81a7f2..6fba1cb 100644 --- a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp +++ b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp @@ -552,3 +552,29 @@ TEST_F(GDBRemoteCommunicationClientTest, SendGetTraceConfigPacket) { incorrect_custom_params2); ASSERT_FALSE(result4.get().Success()); } + +TEST_F(GDBRemoteCommunicationClientTest, GetQOffsets) { + const auto &GetQOffsets = [&](llvm::StringRef response) { + std::future<Optional<QOffsets>> result = std::async( + std::launch::async, [&] { return client.GetQOffsets(); }); + + HandlePacket(server, "qOffsets", response); + return result.get(); + }; + EXPECT_EQ((QOffsets{false, {0x1234, 0x1234}}), + GetQOffsets("Text=1234;Data=1234")); + EXPECT_EQ((QOffsets{false, {0x1234, 0x1234, 0x1234}}), + GetQOffsets("Text=1234;Data=1234;Bss=1234")); + EXPECT_EQ((QOffsets{true, {0x1234}}), GetQOffsets("TextSeg=1234")); + EXPECT_EQ((QOffsets{true, {0x1234, 0x2345}}), + GetQOffsets("TextSeg=1234;DataSeg=2345")); + + EXPECT_EQ(llvm::None, GetQOffsets("E05")); + EXPECT_EQ(llvm::None, GetQOffsets("Text=bogus")); + EXPECT_EQ(llvm::None, GetQOffsets("Text=1234")); + EXPECT_EQ(llvm::None, GetQOffsets("Text=1234;Data=1234;")); + EXPECT_EQ(llvm::None, GetQOffsets("Text=1234;Data=1234;Bss=1234;")); + EXPECT_EQ(llvm::None, GetQOffsets("TEXTSEG=1234")); + EXPECT_EQ(llvm::None, GetQOffsets("TextSeg=0x1234")); + EXPECT_EQ(llvm::None, GetQOffsets("TextSeg=12345678123456789")); +} |