[Lldb-commits] [lldb] [lldb] Support custom printf formatting for variables (PR #81196)
Dave Lee via lldb-commits
lldb-commits at lists.llvm.org
Thu Feb 8 14:02:00 PST 2024
https://github.com/kastiglione created https://github.com/llvm/llvm-project/pull/81196
None
>From 81a2034ff2b41e30a1f5b82c86b4d5d4c429ed52 Mon Sep 17 00:00:00 2001
From: Dave Lee <davelee.com at gmail.com>
Date: Thu, 8 Feb 2024 13:59:12 -0800
Subject: [PATCH] [lldb] Support custom printf formatting for variables
---
lldb/source/Core/FormatEntity.cpp | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/lldb/source/Core/FormatEntity.cpp b/lldb/source/Core/FormatEntity.cpp
index fa5eadc6ff4e9..0e92920393530 100644
--- a/lldb/source/Core/FormatEntity.cpp
+++ b/lldb/source/Core/FormatEntity.cpp
@@ -883,8 +883,29 @@ static bool DumpValue(Stream &s, const SymbolContext *sc,
}
if (!is_array_range) {
- LLDB_LOGF(log,
- "[Debugger::FormatPrompt] dumping ordinary printable output");
+ if (!entry.printf_format.empty()) {
+ auto type_info = target->GetTypeInfo();
+ if (type_info & eTypeIsInteger) {
+ if (type_info & eTypeIsSigned) {
+ bool success = false;
+ auto integer = target->GetValueAsSigned(0, &success);
+ if (success) {
+ LLDB_LOGF(log, "dumping using printf format");
+ s.Printf(entry.printf_format.c_str(), integer);
+ return true;
+ }
+ } else {
+ bool success = false;
+ auto integer = target->GetValueAsUnsigned(0, &success);
+ if (success) {
+ LLDB_LOGF(log, "dumping using printf format");
+ s.Printf(entry.printf_format.c_str(), integer);
+ return true;
+ }
+ }
+ }
+ }
+ LLDB_LOGF(log, "dumping ordinary printable output");
return target->DumpPrintableRepresentation(s, val_obj_display,
custom_format);
} else {
More information about the lldb-commits
mailing list