[Lldb-commits] [lldb] [LLDB] Add AST node classes, functions, etc. for Data Inspection Lang… (PR #95738)

via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 14 07:55:26 PDT 2024


================
@@ -0,0 +1,560 @@
+//===-- DILAST.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
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Core/DILAST.h"
+#include "lldb/API/SBType.h"
+#include "lldb/Core/ValueObjectRegister.h"
+#include "lldb/Core/ValueObjectVariable.h"
+#include "lldb/Symbol/TypeList.h"
+#include "lldb/Symbol/VariableList.h"
+#include "lldb/Target/LanguageRuntime.h"
+#include "lldb/Target/RegisterContext.h"
+#include "llvm/ADT/StringRef.h"
+
+#include <vector>
+
+namespace lldb_private {
+
+namespace DIL {
+
+lldb::ValueObjectSP
+GetDynamicOrSyntheticValue(lldb::ValueObjectSP in_valobj_sp,
+                           lldb::DynamicValueType use_dynamic,
+                           bool use_synthetic) {
+  Status error;
+
+  if (!in_valobj_sp) {
+    error.SetErrorString("invalid value object");
+    return in_valobj_sp;
+  }
+
+  lldb::ValueObjectSP value_sp = in_valobj_sp;
+
+  Target *target = value_sp->GetTargetSP().get();
+  // If this ValueObject holds an error, then it is valuable for that.
+  if (value_sp->GetError().Fail())
+    return value_sp;
+
+  if (!target)
+    return lldb::ValueObjectSP();
+
+  if (use_dynamic != lldb::eNoDynamicValues) {
+    lldb::ValueObjectSP dynamic_sp = value_sp->GetDynamicValue(use_dynamic);
+    if (dynamic_sp)
+      value_sp = dynamic_sp;
+  }
+
+  if (use_synthetic) {
+    lldb::ValueObjectSP synthetic_sp = value_sp->GetSyntheticValue();
+    if (synthetic_sp)
+      value_sp = synthetic_sp;
+  }
+
+  if (!value_sp)
+    error.SetErrorString("invalid value object");
+
+  return value_sp;
+}
+
+CompilerType DILASTNode::GetDereferencedResultType() const {
+  auto type = result_type();
+  return type.IsReferenceType() ? type.GetNonReferenceType() : type;
+}
+
+std::optional<MemberInfo>
----------------
cmtice wrote:

This function is called from the parser when it is trying to parse what ought to be a field/member name (i.e. it's gotten through <stuff-before-field-reference> <dot-or-arrow> field_name).  The "stuff-before-field-reference" can be a simple variable name, or something more complex; in this case it was an array subscript, 'c_arr[0]'. (The full command was 'frame variable c_arr[0].field_').  This function determines if the 'stuff-before-field-reference' has a valid field/member with the given name, and the index of that child/member (or set of potential valid indices) and returns that in the "idx" parameter, along with the full information about the field, which gets returned in the MemberInfo struct (the main return value).  This information is later used by the evaluator (once we have finished parsing the entire input) to actually find and return the value the user was asking for.

Since  whether or not the field/member name is valid really depends on the type, I do not understand why you seem to feel it is wrong to use the type (the second parameter) of the "stuff-before-field-reference" to check to see if it is valid and (if it's valid) what its position is?


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


More information about the lldb-commits mailing list