Add methods to enable using formatv syntax in LLDB.
This adds formatv-backed formatting functions in various
places in LLDB such as StreamString, logging, constructing
error messages, etc. A couple of callsites are changed
from Printf style syntax to formatv style syntax to
illustrate its usage. Additionally, a FileSpec formatter
is introduced so that FileSpecs can be formatted natively.
Differential Revision: https://reviews.llvm.org/D27632
llvm-svn: 289922
diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp
index 5d8fcbe..caebd0c 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -9,6 +9,9 @@
#include "lldb/Symbol/ClangASTContext.h"
+#include "llvm/Support/FormatAdapters.h"
+#include "llvm/Support/FormatVariadic.h"
+
// C Includes
// C++ Includes
#include <mutex> // std::once
@@ -6739,10 +6742,7 @@
if (array) {
CompilerType element_type(getASTContext(), array->getElementType());
if (element_type.GetCompleteType()) {
- char element_name[64];
- ::snprintf(element_name, sizeof(element_name), "[%" PRIu64 "]",
- static_cast<uint64_t>(idx));
- child_name.assign(element_name);
+ child_name = llvm::formatv("[{0}]", idx);
child_byte_size = element_type.GetByteSize(
exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
child_byte_offset = (int32_t)idx * (int32_t)child_byte_size;
@@ -8883,8 +8883,8 @@
std::string base_class_type_name(base_class_qual_type.getAsString());
// Indent and print the base class type name
- s->Printf("\n%*s%s ", depth + DEPTH_INCREMENT, "",
- base_class_type_name.c_str());
+ s->Format("\n{0}{1}", llvm::fmt_repeat(" ", depth + DEPTH_INCREMENT),
+ base_class_type_name);
clang::TypeInfo base_class_type_info =
getASTContext()->getTypeInfo(base_class_qual_type);