================ @@ -1085,6 +1085,19 @@ std::string VariableDescription::GetResult(llvm::StringRef context) { return description.trim().str(); } +lldb::addr_t GetMemoryReference(lldb::SBValue v) { + if (!v.GetType().IsPointerType() && !v.GetType().IsArrayType()) { + return LLDB_INVALID_ADDRESS; + } + + lldb::SBValue deref = v.Dereference(); + if (!deref.IsValid()) { + return LLDB_INVALID_ADDRESS; + } + + return deref.GetLoadAddress(); ---------------- clayborg wrote:
We can return the address of a SBValue by calling `v.GetLoadAddress();`. But as you know, if the value is a pointer, then we want to dereference it. We want to dereference reference values as well. This code should be: ``` std::optional<lldb::addr_t> GetMemoryReference(lldb::SBValue v) { SBType v_type = v.GetType(); // Dereference and pointers or C++ references. if (v_type.IsPointerType() || v_type.IsReferenceType()) v = v.Dereference(); lldb::addr_t load_addr = v.GetLoadAddress(); if (load_addr != LLDB_INVALID_ADDRESS) return load_addr; return std::nullopt; } ``` Any value that lives in memory should return a valid load address. If a variable lives in a register, or is a constant, then `v.GetLoadAddress()` will return `LLDB_INVALID_ADDRESS`. Also, no need to check if `v.Dereference();` succeeded, because if it doesn't, then the `SBValue` will be invalid and also return `LLDB_INVALID_ADDRESS` https://github.com/llvm/llvm-project/pull/104317 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits