[Lldb-commits] [PATCH] D116896: [lldb] [gdb-remote] Support client fallback for servers without reg defs (WIP)

Michał Górny via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Sun Jan 9 10:45:33 PST 2022


mgorny created this revision.
mgorny added reviewers: labath, krytarowski, emaste.
Herald added subscribers: pengfei, arichardson.
mgorny requested review of this revision.

Provide minimal register definition defaults for working with servers
that implement neither target.xml nor qRegisterInfo packets.  This is
useful e.g. when interacting with FreeBSD's kernel minimal gdbserver
that does not send target.xml but uses the same layout for its supported
register subset as GDB.

The prerequisite for this is the ability to determine the correct
architecture, e.g. from the target executable.

For now, this is a proof-of-concept that only supports x86_64.
I'm working on tests.


https://reviews.llvm.org/D116896

Files:
  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
@@ -375,6 +375,46 @@
   return regnums.size();
 }
 
+static std::vector<DynamicRegisterInfo::Register> GetRegisters_x86_64() {
+  ConstString empty_alt_name;
+  ConstString reg_set{"general purpose registers"};
+
+#define R64(name)                                                              \
+  DynamicRegisterInfo::Register {                                              \
+    ConstString(#name), empty_alt_name, reg_set, 8, LLDB_INVALID_INDEX32,      \
+        lldb::eEncodingUint, lldb::eFormatHex, LLDB_INVALID_REGNUM,            \
+        LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, LLDB_INVALID_REGNUM, {}, {}, \
+  }
+#define R32(name)                                                              \
+  DynamicRegisterInfo::Register{                                               \
+      ConstString(#name),                                                      \
+      empty_alt_name,                                                          \
+      reg_set,                                                                 \
+      4,                                                                       \
+      LLDB_INVALID_INDEX32,                                                    \
+      lldb::eEncodingUint,                                                     \
+      lldb::eFormatHex,                                                        \
+      LLDB_INVALID_REGNUM,                                                     \
+      LLDB_INVALID_REGNUM,                                                     \
+      LLDB_INVALID_REGNUM,                                                     \
+      LLDB_INVALID_REGNUM,                                                     \
+      {},                                                                      \
+      {},                                                                      \
+  }
+
+  std::vector<DynamicRegisterInfo::Register> registers{
+      R64(rax), R64(rbx), R64(rcx), R64(rdx), R64(rsi), R64(rdi),
+      R64(rbp), R64(rsp), R64(r8),  R64(r9),  R64(r10), R64(r11),
+      R64(r12), R64(r13), R64(r14), R64(r15), R64(rip), R32(eflags),
+      R32(cs),  R32(ss),  R32(ds),  R32(es),  R32(fs),  R32(gs),
+  };
+
+#undef R32
+#undef R64
+
+  return registers;
+}
+
 void ProcessGDBRemote::BuildDynamicRegisterInfo(bool force) {
   if (!force && m_register_info_sp)
     return;
@@ -394,6 +434,7 @@
   //     2 - If the target definition doesn't have any of the info from the
   //     target.xml (registers) then proceed to read the target.xml.
   //     3 - Fall back on the qRegisterInfo packets.
+  //     4 - Use hardcoded defaults if available.
 
   FileSpec target_definition_fspec =
       GetGlobalPluginProperties().GetTargetDefinitionFile();
@@ -507,6 +548,18 @@
     }
   }
 
+  if (registers.empty()) {
+    switch (arch_to_use.GetMachine()) {
+    case llvm::Triple::x86:
+      break;
+    case llvm::Triple::x86_64:
+      registers = GetRegisters_x86_64();
+      break;
+    default:
+      break;
+    }
+  }
+
   AddRemoteRegisters(registers, arch_to_use);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116896.398446.patch
Type: text/x-patch
Size: 3331 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220109/b1efaa80/attachment.bin>


More information about the lldb-commits mailing list