Recognize `addressing_bits` kv in stop reply packet
authorJason Molenda <jason@molenda.com>
Thu, 4 May 2023 20:13:30 +0000 (13:13 -0700)
committerJason Molenda <jason@molenda.com>
Thu, 4 May 2023 20:14:10 +0000 (13:14 -0700)
If a remote stub provides the addressing_bits kv pair in
the stop reply packet, update the Process address masks with
that value as it possibly changes during the process runtime.
This is an unusual situation, most likely a JTAG remote stub
and some very early startup code that is setting up the page
tables.  Nearly all debug sessions will have a single address
mask that cannot change during the lifetime of a Process.

Differential Revision: https://reviews.llvm.org/D149803
rdar://61900565

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

index 570e70f9e54a91ad253626ae5cceff31b471dee6..b426978a9490737f2fcb6ad52bafd5917ace9704 100644 (file)
@@ -1636,6 +1636,24 @@ for this region.
 //                                  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
index 06f57967c5acb868d8391600ff522689034ba983..7047ae62d07c68970699bcd3dc42225f307e59c1 100644 (file)
@@ -2257,6 +2257,13 @@ StateType ProcessGDBRemote::SetThreadStopInfo(StringExtractor &stop_packet) {
         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))