Author: jmolenda Date: Tue Sep 25 14:01:54 2018 New Revision: 343029 URL: http://llvm.org/viewvc/llvm-project?rev=343029&view=rev Log: Change the unwinder to not use a hard-coded limit on the max number of stack frames to backtrace, make it a setting, target.process.thread.max-backtrace-depth. Add a test case for the setting.
<rdar://problem/28759559> Added: lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/backtrace_limit/ lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/backtrace_limit/Makefile lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/backtrace_limit/TestBacktraceLimit.py lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/backtrace_limit/main.cpp Modified: lldb/trunk/include/lldb/Target/Thread.h lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.cpp lldb/trunk/source/Target/Thread.cpp Modified: lldb/trunk/include/lldb/Target/Thread.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Thread.h?rev=343029&r1=343028&r2=343029&view=diff ============================================================================== --- lldb/trunk/include/lldb/Target/Thread.h (original) +++ lldb/trunk/include/lldb/Target/Thread.h Tue Sep 25 14:01:54 2018 @@ -57,6 +57,8 @@ public: bool GetStepInAvoidsNoDebug() const; bool GetStepOutAvoidsNoDebug() const; + + uint64_t GetMaxBacktraceDepth() const; }; typedef std::shared_ptr<ThreadProperties> ThreadPropertiesSP; Added: lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/backtrace_limit/Makefile URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/backtrace_limit/Makefile?rev=343029&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/backtrace_limit/Makefile (added) +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/backtrace_limit/Makefile Tue Sep 25 14:01:54 2018 @@ -0,0 +1,6 @@ +LEVEL = ../../../make + +CXXFLAGS += -std=c++11 +CXX_SOURCES := main.cpp +ENABLE_THREADS := YES +include $(LEVEL)/Makefile.rules Added: lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/backtrace_limit/TestBacktraceLimit.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/backtrace_limit/TestBacktraceLimit.py?rev=343029&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/backtrace_limit/TestBacktraceLimit.py (added) +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/backtrace_limit/TestBacktraceLimit.py Tue Sep 25 14:01:54 2018 @@ -0,0 +1,31 @@ +""" +Test that the target.process.thread.max-backtrace-depth setting works. +""" + +import unittest2 +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class BacktraceLimitSettingTest(TestBase): + + mydir = TestBase.compute_mydir(__file__) + NO_DEBUG_INFO_TESTCASE = True + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + def test_backtrace_depth(self): + """Test that the max-backtrace-depth setting limits backtraces.""" + self.build() + self.main_source_file = lldb.SBFileSpec("main.cpp") + (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, + "Set a breakpoint here", self.main_source_file) + interp = self.dbg.GetCommandInterpreter() + result = lldb.SBCommandReturnObject() + interp.HandleCommand("settings set target.process.thread.max-backtrace-depth 30", result) + self.assertEqual(True, result.Succeeded()) + self.assertEqual(30, thread.GetNumFrames()) Added: lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/backtrace_limit/main.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/backtrace_limit/main.cpp?rev=343029&view=auto ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/backtrace_limit/main.cpp (added) +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/thread/backtrace_limit/main.cpp Tue Sep 25 14:01:54 2018 @@ -0,0 +1,13 @@ +int bottom () { + return 1; // Set a breakpoint here +} +int foo(int in) { + if (in > 0) + return foo(--in) + 5; + else + return bottom(); +} +int main() +{ + return foo(500); +} Modified: lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.cpp?rev=343029&r1=343028&r2=343029&view=diff ============================================================================== --- lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.cpp (original) +++ lldb/trunk/source/Plugins/Process/Utility/UnwindLLDB.cpp Tue Sep 25 14:01:54 2018 @@ -130,6 +130,8 @@ UnwindLLDB::CursorSP UnwindLLDB::GetOneM RegisterContextLLDBSP reg_ctx_sp(new RegisterContextLLDB( m_thread, prev_frame->reg_ctx_lldb_sp, cursor_sp->sctx, cur_idx, *this)); + uint64_t max_stack_depth = m_thread.GetMaxBacktraceDepth(); + // We want to detect an unwind that cycles erroneously and stop backtracing. // Don't want this maximum unwind limit to be too low -- if you have a // backtrace with an "infinitely recursing" bug, it will crash when the stack @@ -138,7 +140,7 @@ UnwindLLDB::CursorSP UnwindLLDB::GetOneM // unwind at 10,000 or something. Realistically anything over around 200,000 // is going to blow out the stack space. If we're still unwinding at that // point, we're probably never going to finish. - if (cur_idx > 300000) { + if (cur_idx >= max_stack_depth) { if (log) log->Printf("%*sFrame %d unwound too many frames, assuming unwind has " "gone astray, stopping.", Modified: lldb/trunk/source/Target/Thread.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Thread.cpp?rev=343029&r1=343028&r2=343029&view=diff ============================================================================== --- lldb/trunk/source/Target/Thread.cpp (original) +++ lldb/trunk/source/Target/Thread.cpp Tue Sep 25 14:01:54 2018 @@ -80,6 +80,8 @@ static PropertyDefinition g_properties[] nullptr, "A list of libraries that source stepping won't stop in."}, {"trace-thread", OptionValue::eTypeBoolean, false, false, nullptr, nullptr, "If true, this thread will single-step and log execution."}, + {"max-backtrace-depth", OptionValue::eTypeUInt64, false, 300000, nullptr, + nullptr, "Maximum number of frames to backtrace."}, {nullptr, OptionValue::eTypeInvalid, false, 0, nullptr, nullptr, nullptr}}; enum { @@ -87,7 +89,8 @@ enum { ePropertyStepOutAvoidsNoDebug, ePropertyStepAvoidRegex, ePropertyStepAvoidLibraries, - ePropertyEnableThreadTrace + ePropertyEnableThreadTrace, + ePropertyMaxBacktraceDepth }; class ThreadOptionValueProperties : public OptionValueProperties { @@ -165,6 +168,12 @@ bool ThreadProperties::GetStepOutAvoidsN nullptr, idx, g_properties[idx].default_uint_value != 0); } +uint64_t ThreadProperties::GetMaxBacktraceDepth() const { + const uint32_t idx = ePropertyMaxBacktraceDepth; + return m_collection_sp->GetPropertyAtIndexAsUInt64( + nullptr, idx, g_properties[idx].default_uint_value != 0); +} + //------------------------------------------------------------------ // Thread Event Data //------------------------------------------------------------------ _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits