uint32_t addr_byte_size) = 0;
/// Return a new persistent variable name with the specified prefix.
- ConstString GetNextPersistentVariableName(Target &target,
- llvm::StringRef prefix);
-
- virtual llvm::StringRef
- GetPersistentVariablePrefix(bool is_error = false) const = 0;
+ virtual ConstString GetNextPersistentVariableName(bool is_error = false) = 0;
virtual void
RemovePersistentVariable(lldb::ExpressionVariableSP variable) = 0;
void RegisterExecutionUnit(lldb::IRExecutionUnitSP &execution_unit_sp);
+protected:
+ virtual llvm::StringRef
+ GetPersistentVariablePrefix(bool is_error = false) const = 0;
+
private:
LLVMCastKind m_kind;
lldb::ExpressionVariableSP GetPersistentVariable(ConstString name);
- /// Return the next available number for numbered persistent variables.
- unsigned GetNextPersistentVariableIndex() {
- return m_next_persistent_variable_index++;
- }
-
lldb::addr_t GetPersistentSymbol(ConstString name);
/// This method will return the address of the starting function for
if (!persistent_state)
return nullptr;
- auto prefix = persistent_state->GetPersistentVariablePrefix();
- ConstString name =
- persistent_state->GetNextPersistentVariableName(*target_sp, prefix);
+ ConstString name = persistent_state->GetNextPersistentVariableName();
ValueObjectSP const_result_sp =
ValueObjectConstResult::Create(target_sp.get(), GetValue(), name);
}
}
}
-
-ConstString PersistentExpressionState::GetNextPersistentVariableName(
- Target &target, llvm::StringRef Prefix) {
- llvm::SmallString<64> name;
- {
- llvm::raw_svector_ostream os(name);
- os << Prefix << target.GetNextPersistentVariableIndex();
- }
- return ConstString(name);
-}
return;
}
- ConstString name =
- m_delegate
- ? m_delegate->GetName()
- : persistent_state->GetNextPersistentVariableName(
- *target_sp, persistent_state->GetPersistentVariablePrefix());
+ ConstString name = m_delegate
+ ? m_delegate->GetName()
+ : persistent_state->GetNextPersistentVariableName();
lldb::ExpressionVariableSP ret = persistent_state->CreatePersistentVariable(
exe_scope, name, m_type, map.GetByteOrder(), map.GetAddressByteSize());
}
return m_ast_importer_sp;
}
+
+ConstString
+ClangPersistentVariables::GetNextPersistentVariableName(bool is_error) {
+ llvm::SmallString<64> name;
+ {
+ llvm::raw_svector_ostream os(name);
+ os << GetPersistentVariablePrefix(is_error)
+ << m_next_persistent_variable_id++;
+ }
+ return ConstString(name);
+}
void RemovePersistentVariable(lldb::ExpressionVariableSP variable) override;
- llvm::StringRef GetPersistentVariablePrefix(bool is_error) const override {
- return "$";
- }
+ virtual ConstString GetNextPersistentVariableName(bool is_error = false);
/// Returns the next file name that should be used for user expressions.
std::string GetNextExprFileName() {
return m_hand_loaded_clang_modules;
}
+protected:
+ llvm::StringRef
+ GetPersistentVariablePrefix(bool is_error = false) const override {
+ return "$";
+ }
+
private:
/// The counter used by GetNextExprFileName.
uint32_t m_next_user_file_id = 0;
}
ConstString ClangUserExpression::ResultDelegate::GetName() {
- auto prefix = m_persistent_state->GetPersistentVariablePrefix();
- return m_persistent_state->GetNextPersistentVariableName(*m_target_sp,
- prefix);
+ return m_persistent_state->GetNextPersistentVariableName(false);
}
void ClangUserExpression::ResultDelegate::DidDematerialize(
if (!persistent_expression_state)
return {};
- auto prefix = persistent_expression_state->GetPersistentVariablePrefix();
ConstString persistent_variable_name =
- persistent_expression_state->GetNextPersistentVariableName(target,
- prefix);
+ persistent_expression_state->GetNextPersistentVariableName();
lldb::ValueObjectSP const_valobj_sp;
--- /dev/null
+C_SOURCES := main.c
+CFLAGS_EXTRAS := -std=c99
+
+include Makefile.rules
--- /dev/null
+"""
+Make sure running internal expressions doesn't
+influence the result variable numbering.
+"""
+
+
+
+import lldb
+import lldbsuite.test.lldbutil as lldbutil
+from lldbsuite.test.lldbtest import *
+
+
+class TestExpressionResultNumbering(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ NO_DEBUG_INFO_TESTCASE = True
+
+ def test_sample_rename_this(self):
+ self.build()
+ self.main_source_file = lldb.SBFileSpec("main.c")
+ self.do_numbering_test()
+
+ def do_numbering_test(self):
+ (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
+ "Set a breakpoint here", self.main_source_file)
+
+ bkpt = target.BreakpointCreateBySourceRegex("Add conditions to this breakpoint",
+ self.main_source_file)
+ self.assertEqual(bkpt.GetNumLocations(), 1, "Set the breakpoint")
+
+ bkpt.SetCondition("call_me(value) < 6")
+
+ # Get the number of the last expression:
+ result = thread.frames[0].EvaluateExpression("call_me(200)")
+ self.assertTrue(result.GetError().Success(), "Our expression succeeded")
+ name = result.GetName()
+ ordinal = int(name[1:])
+
+ process.Continue()
+
+ # The condition evaluation had to run a 4 expressions, but we haven't
+ # run any user expressions.
+ result = thread.frames[0].EvaluateExpression("call_me(200)")
+ self.assertTrue(result.GetError().Success(), "Our expression succeeded the second time")
+ after_name = result.GetName()
+ after_ordinal = int(after_name[1:])
+ self.assertEqual(ordinal + 1, after_ordinal)
--- /dev/null
+#include <stdio.h>
+
+int
+call_me(int input)
+{
+ return input;
+}
+
+int
+main()
+{
+ int value = call_me(0); // Set a breakpoint here
+ while (value < 10)
+ {
+ printf("Add conditions to this breakpoint: %d.\n", value++);
+ }
+ return 0;
+}