Skip to content

Commit 0f628fd

Browse files
committed
Revert "[lldb] Support custom LLVM formatting for variables (#81196)"
This reverts commit 7a8d15e.
1 parent 278774e commit 0f628fd

File tree

5 files changed

+10
-104
lines changed

5 files changed

+10
-104
lines changed

lldb/docs/use/variable.rst

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -460,15 +460,6 @@ summary strings, regardless of the format they have applied to their types. To
460460
do that, you can use %format inside an expression path, as in ${var.x->x%u},
461461
which would display the value of x as an unsigned integer.
462462

463-
Additionally, custom output can be achieved by using an LLVM format string,
464-
commencing with the ``:`` marker. To illustrate, compare ``${var.byte%x}`` and
465-
``${var.byte:x-}``. The former uses lldb's builtin hex formatting (``x``),
466-
which unconditionally inserts a ``0x`` prefix, and also zero pads the value to
467-
match the size of the type. The latter uses ``llvm::formatv`` formatting
468-
(``:x-``), and will print only the hex value, with no ``0x`` prefix, and no
469-
padding. This raw control is useful when composing multiple pieces into a
470-
larger whole.
471-
472463
You can also use some other special format markers, not available for formats
473464
themselves, but which carry a special meaning when used in this context:
474465

lldb/source/Core/FormatEntity.cpp

Lines changed: 10 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
#include "llvm/ADT/STLExtras.h"
5858
#include "llvm/ADT/StringRef.h"
5959
#include "llvm/Support/Compiler.h"
60-
#include "llvm/Support/Regex.h"
6160
#include "llvm/TargetParser/Triple.h"
6261

6362
#include <cctype>
@@ -659,38 +658,6 @@ static char ConvertValueObjectStyleToChar(
659658
return '\0';
660659
}
661660

662-
static llvm::Regex LLVMFormatPattern{"x[-+]?\\d*|n|d", llvm::Regex::IgnoreCase};
663-
664-
static bool DumpValueWithLLVMFormat(Stream &s, llvm::StringRef options,
665-
ValueObject &valobj) {
666-
std::string formatted;
667-
std::string llvm_format = ("{0:" + options + "}").str();
668-
669-
// Options supported by format_provider<T> for integral arithmetic types.
670-
// See table in FormatProviders.h.
671-
672-
auto type_info = valobj.GetTypeInfo();
673-
if (type_info & eTypeIsInteger && LLVMFormatPattern.match(options)) {
674-
if (type_info & eTypeIsSigned) {
675-
bool success = false;
676-
int64_t integer = valobj.GetValueAsSigned(0, &success);
677-
if (success)
678-
formatted = llvm::formatv(llvm_format.data(), integer);
679-
} else {
680-
bool success = false;
681-
uint64_t integer = valobj.GetValueAsUnsigned(0, &success);
682-
if (success)
683-
formatted = llvm::formatv(llvm_format.data(), integer);
684-
}
685-
}
686-
687-
if (formatted.empty())
688-
return false;
689-
690-
s.Write(formatted.data(), formatted.size());
691-
return true;
692-
}
693-
694661
static bool DumpValue(Stream &s, const SymbolContext *sc,
695662
const ExecutionContext *exe_ctx,
696663
const FormatEntity::Entry &entry, ValueObject *valobj) {
@@ -761,12 +728,9 @@ static bool DumpValue(Stream &s, const SymbolContext *sc,
761728
return RunScriptFormatKeyword(s, sc, exe_ctx, valobj, entry.string.c_str());
762729
}
763730

764-
auto split = llvm::StringRef(entry.string).split(':');
765-
auto subpath = split.first;
766-
auto llvm_format = split.second;
767-
731+
llvm::StringRef subpath(entry.string);
768732
// simplest case ${var}, just print valobj's value
769-
if (subpath.empty()) {
733+
if (entry.string.empty()) {
770734
if (entry.printf_format.empty() && entry.fmt == eFormatDefault &&
771735
entry.number == ValueObject::eValueObjectRepresentationStyleValue)
772736
was_plain_var = true;
@@ -775,19 +739,22 @@ static bool DumpValue(Stream &s, const SymbolContext *sc,
775739
target = valobj;
776740
} else // this is ${var.something} or multiple .something nested
777741
{
778-
if (subpath[0] == '[')
742+
if (entry.string[0] == '[')
779743
was_var_indexed = true;
780744
ScanBracketedRange(subpath, close_bracket_index,
781745
var_name_final_if_array_range, index_lower,
782746
index_higher);
783747

784748
Status error;
785749

786-
LLDB_LOG(log, "[Debugger::FormatPrompt] symbol to expand: {0}", subpath);
750+
const std::string &expr_path = entry.string;
751+
752+
LLDB_LOGF(log, "[Debugger::FormatPrompt] symbol to expand: %s",
753+
expr_path.c_str());
787754

788755
target =
789756
valobj
790-
->GetValueForExpressionPath(subpath, &reason_to_stop,
757+
->GetValueForExpressionPath(expr_path.c_str(), &reason_to_stop,
791758
&final_value_type, options, &what_next)
792759
.get();
793760

@@ -916,18 +883,8 @@ static bool DumpValue(Stream &s, const SymbolContext *sc,
916883
}
917884

918885
if (!is_array_range) {
919-
if (!llvm_format.empty()) {
920-
if (DumpValueWithLLVMFormat(s, llvm_format, *target)) {
921-
LLDB_LOGF(log, "dumping using llvm format");
922-
return true;
923-
} else {
924-
LLDB_LOG(
925-
log,
926-
"empty output using llvm format '{0}' - with type info flags {1}",
927-
entry.printf_format, target->GetTypeInfo());
928-
}
929-
}
930-
LLDB_LOGF(log, "dumping ordinary printable output");
886+
LLDB_LOGF(log,
887+
"[Debugger::FormatPrompt] dumping ordinary printable output");
931888
return target->DumpPrintableRepresentation(s, val_obj_display,
932889
custom_format);
933890
} else {
@@ -2270,13 +2227,6 @@ static Status ParseInternal(llvm::StringRef &format, Entry &parent_entry,
22702227
if (error.Fail())
22712228
return error;
22722229

2273-
auto [_, llvm_format] = llvm::StringRef(entry.string).split(':');
2274-
if (!LLVMFormatPattern.match(llvm_format)) {
2275-
error.SetErrorStringWithFormat("invalid llvm format: '%s'",
2276-
llvm_format.data());
2277-
return error;
2278-
}
2279-
22802230
if (verify_is_thread_id) {
22812231
if (entry.type != Entry::Type::ThreadID &&
22822232
entry.type != Entry::Type::ThreadProtocolID) {

lldb/test/API/functionalities/data-formatter/custom-printf-summary/Makefile

Lines changed: 0 additions & 2 deletions
This file was deleted.

lldb/test/API/functionalities/data-formatter/custom-printf-summary/TestCustomSummaryLLVMFormat.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

lldb/test/API/functionalities/data-formatter/custom-printf-summary/main.c

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)