[Lldb-commits] [PATCH] D149803: Use the `addressing_bits` kv in the stop packet from the remote stub, if present

Jason Molenda via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed May 3 17:35:41 PDT 2023


jasonmolenda created this revision.
jasonmolenda added a reviewer: bulbazord.
jasonmolenda added a project: LLDB.
Herald added subscribers: JDevlieghere, kristof.beyls.
Herald added a project: All.
jasonmolenda requested review of this revision.
Herald added a subscriber: lldb-commits.

On an AArch64 system using pointer authentication, where lldb needs to disregard signing in the top bits, lldb needs to know how many bits are used for addressing (and therefore are significant).  This is normally a fixed value, and can be communicated in the `qHostInfo` packet's `addressing_bits` kv pair.

On a firmware debug session with early startup code that is setting up the page tables, the value will change during the lifetime of the process.  To support this correctly, the remote stub (a JTAG type debugger) can specify the current number of addressing bits in every stop packet, or include it in the stop packet when the value has changed.  It's a bit of a specialized environment where this is needed -- for all user process debugging, the value will not change during the lifetime of the process.

This patch has lldb read the value from the stop packet and set the Process addressing masks if it is present.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149803

Files:
  lldb/docs/lldb-gdb-remote.txt
  lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp


Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -2257,6 +2257,13 @@
         StreamString ostr;
         ostr.Printf("%" PRIu64 " %" PRIu64, pid_tid->first, pid_tid->second);
         description = std::string(ostr.GetString());
+      } else if (key.compare("addressing_bits") == 0) {
+        uint64_t addressing_bits;
+        if (!value.getAsInteger(0, addressing_bits)) {
+          addr_t address_mask = ~((1ULL << addressing_bits) - 1);
+          SetCodeAddressMask(address_mask);
+          SetDataAddressMask(address_mask);
+        }
       } else if (key.size() == 2 && ::isxdigit(key[0]) && ::isxdigit(key[1])) {
         uint32_t reg = UINT32_MAX;
         if (!key.getAsInteger(16, reg))
Index: lldb/docs/lldb-gdb-remote.txt
===================================================================
--- lldb/docs/lldb-gdb-remote.txt
+++ lldb/docs/lldb-gdb-remote.txt
@@ -1636,6 +1636,24 @@
 //                                  Example:
 //                                  thread-pcs:dec14,2cf872b0,2cf8681c,2d02d68c,2cf716a8;
 //
+//  "addressing_bits" unsigned optional  Specifies how many bits in addresses 
+//                                       are significant for addressing, base 
+//                                       10.  If bits 38..0 in a 64-bit 
+//                                       pointer are significant for 
+//                                       addressing, then the value is 39.  
+//                                       This is needed on e.g. AArch64
+//                                       v8.3 ABIs that use pointer 
+//                                       authentication in the high bits.
+//                                       This value is normally sent in the
+//                                       qHostInfo packet response, and if the
+//                                       value cannot change during the process
+//                                       lifetime, it does not need to be 
+//                                       duplicated here in the stop packet.
+//                                       For a firmware environment with early
+//                                       start code that may be changing the
+//                                       page table setup, a dynamically set
+//                                       value may be needed.
+//
 // BEST PRACTICES:
 //  Since register values can be supplied with this packet, it is often useful
 //  to return the PC, SP, FP, LR (if any), and FLAGS registers so that separate


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149803.519312.patch
Type: text/x-patch
Size: 2735 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230504/5b93dcee/attachment.bin>


More information about the lldb-commits mailing list