[Lldb-commits] [lldb] [lldb-vscode] Show value addresses in a short format (PR #66534)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 15 12:34:26 PDT 2023


================
@@ -228,7 +228,24 @@ void SetValueForKey(lldb::SBValue &v, llvm::json::Object &object,
     strm << "<error: " << error.GetCString() << ">";
   } else {
     auto tryDumpSummaryAndValue = [&strm](lldb::SBValue value) {
-      llvm::StringRef val = value.GetValue();
+      std::string val;
+      // Whenever the value is a non-synthetic address, we format it ourselves
+      // to use as few chars as possible because the variables pane on VS Code
+      // is by default narrow.
+      if (!value.IsSynthetic() && value.GetType().IsPointerOrReferenceType()) {
+        lldb::addr_t address = value.GetValueAsUnsigned(LLDB_INVALID_ADDRESS);
+        if (address == LLDB_INVALID_ADDRESS) {
+          val = "<invalid address>";
+        } else if (address == 0) {
+          val = "<null>";
+        } else {
+          llvm::raw_string_ostream os(val);
+          os << llvm::format_hex(address, 0);
+        }
----------------
clayborg wrote:

I wouldn't mess with the values or try to display them in any fancy way, I would always use:
```
llvm::raw_string_ostream os(val);
os << llvm::format_hex(address, 0);
```
Users might encode -1 into their pointers as a special value and you wouldn't want to see "<invalid address>" as the value. Also I would rather see "0x0" instead of "<null>".

https://github.com/llvm/llvm-project/pull/66534


More information about the lldb-commits mailing list