72 lines · c
1//===-- Variables.h -----------------------------------------------------*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLDB_TOOLS_LLDB_DAP_VARIABLES_H10#define LLDB_TOOLS_LLDB_DAP_VARIABLES_H11 12#include "lldb/API/SBValue.h"13#include "lldb/API/SBValueList.h"14#include "llvm/ADT/DenseMap.h"15 16#define VARREF_FIRST_VAR_IDX (int64_t)417#define VARREF_LOCALS (int64_t)118#define VARREF_GLOBALS (int64_t)219#define VARREF_REGS (int64_t)320 21namespace lldb_dap {22 23struct Variables {24 lldb::SBValueList locals;25 lldb::SBValueList globals;26 lldb::SBValueList registers;27 28 /// Check if \p var_ref points to a variable that should persist for the29 /// entire duration of the debug session, e.g. repl expandable variables30 static bool IsPermanentVariableReference(int64_t var_ref);31 32 /// \return a new variableReference.33 /// Specify is_permanent as true for variable that should persist entire34 /// debug session.35 int64_t GetNewVariableReference(bool is_permanent);36 37 /// \return the expandable variable corresponding with variableReference38 /// value of \p value.39 /// If \p var_ref is invalid an empty SBValue is returned.40 lldb::SBValue GetVariable(int64_t var_ref) const;41 42 /// Insert a new \p variable.43 /// \return variableReference assigned to this expandable variable.44 int64_t InsertVariable(lldb::SBValue variable, bool is_permanent);45 46 lldb::SBValueList *GetTopLevelScope(int64_t variablesReference);47 48 lldb::SBValue FindVariable(uint64_t variablesReference, llvm::StringRef name);49 50 /// Clear all scope variables and non-permanent expandable variables.51 void Clear();52 53private:54 /// Variable_reference start index of permanent expandable variable.55 static constexpr int64_t PermanentVariableStartIndex = (1ll << 32);56 57 /// Variables that are alive in this stop state.58 /// Will be cleared when debuggee resumes.59 llvm::DenseMap<int64_t, lldb::SBValue> m_referencedvariables;60 61 /// Variables that persist across entire debug session.62 /// These are the variables evaluated from debug console REPL.63 llvm::DenseMap<int64_t, lldb::SBValue> m_referencedpermanent_variables;64 65 int64_t m_next_temporary_var_ref{VARREF_FIRST_VAR_IDX};66 int64_t m_next_permanent_var_ref{PermanentVariableStartIndex};67};68 69} // namespace lldb_dap70 71#endif72