[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Mar 27 16:33:34 PDT 2025
================
@@ -0,0 +1,273 @@
+//===-- DILParser.cpp -----------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+// This implements the recursive descent parser for the Data Inspection
+// Language (DIL), and its helper functions, which will eventually underlie the
+// 'frame variable' command. The language that this parser recognizes is
+// described in lldb/docs/dil-expr-lang.ebnf
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/ValueObject/DILParser.h"
+#include "lldb/Target/ExecutionContextScope.h"
+#include "lldb/Utility/DiagnosticsRendering.h"
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/DILEval.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatAdapters.h"
+#include <cstdlib>
+#include <limits.h>
+#include <memory>
+#include <sstream>
+#include <string>
+
+namespace lldb_private::dil {
+
+std::string FormatDiagnostics(llvm::StringRef text, const std::string &message,
+ uint32_t loc, uint16_t err_len) {
+ DiagnosticDetail::SourceLocation sloc = {
+ FileSpec{}, /*line=*/1, static_cast<uint16_t>(loc + 1),
+ err_len, false, /*in_user_input=*/true};
+ std::string arrow_str = "^";
+ std::string rendered_msg =
+ llvm::formatv("<user expression 0>:1:{0}: {1}\n 1 | {2}\n | ^",
+ loc + 1, message, text);
+ DiagnosticDetail detail;
+ detail.source_location = sloc;
+ detail.severity = lldb::eSeverityError;
+ detail.message = message;
+ detail.rendered = rendered_msg;
+ std::vector<DiagnosticDetail> diagnostics;
+ diagnostics.push_back(detail);
+ StreamString diag_stream(true);
+ RenderDiagnosticDetails(diag_stream, 7, true, diagnostics);
+ std::string ret_str = text.str() + "\n" + diag_stream.GetString().str();
+ return ret_str;
+}
+
+llvm::Expected<ASTNodeUP>
+DILParser::Parse(llvm::StringRef dil_input_expr, DILLexer lexer,
+ std::shared_ptr<StackFrame> frame_sp,
+ lldb::DynamicValueType use_dynamic, bool use_synthetic,
+ bool fragile_ivar, bool check_ptr_vs_member) {
+ Status error;
+ DILParser parser(dil_input_expr, lexer, frame_sp, use_dynamic, use_synthetic,
+ fragile_ivar, check_ptr_vs_member, error);
+ return parser.Run();
----------------
cmtice wrote:
Done, with my hack for now.
https://github.com/llvm/llvm-project/pull/120971
More information about the lldb-commits
mailing list