[Lldb-commits] [lldb] b809c4c - [lldb] Add FixAnyAddress to ABI plugins

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 28 06:57:50 PDT 2022


Author: David Spickett
Date: 2022-04-28T14:57:40+01:00
New Revision: b809c4cdb70a100c85524555a14332f22ede1b7a

URL: https://github.com/llvm/llvm-project/commit/b809c4cdb70a100c85524555a14332f22ede1b7a
DIFF: https://github.com/llvm/llvm-project/commit/b809c4cdb70a100c85524555a14332f22ede1b7a.diff

LOG: [lldb] Add FixAnyAddress to ABI plugins

FixAnyAddress is to be used when we don't know or don't care
whether we're fixing a code or data address.

By using FixAnyAddress over the others, you document that no
specific choice was made.

On all existing platforms apart from Arm Thumb, you could use
either FixCodeAddress or FixDataAddress and be fine. Up until
now I've chosen to use FixDataAddress but if I had
chosen to use FixCodeAddress that would have broken Arm Thumb.

Hence FixAnyAddress, to give you the "safest" option when you're
in generic code.

Uses of FixDataAddress in memory region code have been changed
to FixAnyAddress. The functionality is unchanged.

Reviewed By: omjavaid, JDevlieghere

Differential Revision: https://reviews.llvm.org/D124000

Added: 
    

Modified: 
    lldb/include/lldb/Target/ABI.h
    lldb/source/Commands/CommandObjectMemory.cpp
    lldb/source/Target/Process.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Target/ABI.h b/lldb/include/lldb/Target/ABI.h
index 8ac6003554d5e..f0753172d3e71 100644
--- a/lldb/include/lldb/Target/ABI.h
+++ b/lldb/include/lldb/Target/ABI.h
@@ -126,6 +126,20 @@ class ABI : public PluginInterface {
   virtual lldb::addr_t FixDataAddress(lldb::addr_t pc) { return pc; }
   /// @}
 
+  /// Use this method when you do not know, or do not care what kind of address
+  /// you are fixing. On platforms where there would be a 
diff erence between the
+  /// two types, it will pick the safest option.
+  ///
+  /// Its purpose is to signal that no specific choice was made and provide an
+  /// alternative to randomly picking FixCode/FixData address. Which could break
+  /// platforms where there is a 
diff erence (only Arm Thumb at this time).
+  virtual lldb::addr_t FixAnyAddress(lldb::addr_t pc) {
+    // On Arm Thumb fixing a code address zeroes the bottom bit, so FixData is
+    // the safe choice. On any other platform (so far) code and data addresses
+    // are fixed in the same way.
+    return FixDataAddress(pc);
+  }
+
   llvm::MCRegisterInfo &GetMCRegisterInfo() { return *m_mc_register_info_up; }
 
   virtual void

diff  --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp
index 4e63802befdbd..e94306ce33bfe 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -1688,7 +1688,7 @@ class CommandObjectMemoryRegion : public CommandObjectParsed {
                // address size, etc.), the end of mappable memory will be lower
                // than that. So if we find any non-address bit set, we must be
                // at the end of the mappable range.
-               (abi && (abi->FixDataAddress(load_addr) != load_addr))) {
+               (abi && (abi->FixAnyAddress(load_addr) != load_addr))) {
       result.AppendErrorWithFormat("'%s' takes one argument:\nUsage: %s\n",
                                    m_cmd_name.c_str(), m_cmd_syntax.c_str());
       return false;

diff  --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 5cbe4b66fceb4..79adb2c9d1550 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -5831,7 +5831,7 @@ Process::AdvanceAddressToNextBranchInstruction(Address default_stop_addr,
 Status Process::GetMemoryRegionInfo(lldb::addr_t load_addr,
                                     MemoryRegionInfo &range_info) {
   if (const lldb::ABISP &abi = GetABI())
-    load_addr = abi->FixDataAddress(load_addr);
+    load_addr = abi->FixAnyAddress(load_addr);
   return DoGetMemoryRegionInfo(load_addr, range_info);
 }
 
@@ -5866,7 +5866,7 @@ Status Process::GetMemoryRegions(lldb_private::MemoryRegionInfos &region_list) {
       range_end != LLDB_INVALID_ADDRESS &&
       // If we have non-address bits and some are set then the end
       // is at or beyond the end of mappable memory.
-      !(abi && (abi->FixDataAddress(range_end) != range_end)));
+      !(abi && (abi->FixAnyAddress(range_end) != range_end)));
 
   return error;
 }


        


More information about the lldb-commits mailing list