diff options
author | Jim Ingham <jingham@apple.com> | 2010-08-27 00:58:05 +0000 |
---|---|---|
committer | Jim Ingham <jingham@apple.com> | 2010-08-27 00:58:05 +0000 |
commit | 09b263e05cfa6ee42e7213c48114cc1458bccd09 (patch) | |
tree | 523c0c93609e8fb418296b89e7ec7e72722938a4 /lldb/source/Commands/CommandObjectThread.cpp | |
parent | 827edffafd21f64cb8abdd14ba05fa764a762157 (diff) | |
download | bcm5719-llvm-09b263e05cfa6ee42e7213c48114cc1458bccd09.tar.gz bcm5719-llvm-09b263e05cfa6ee42e7213c48114cc1458bccd09.zip |
Make:
bt all
show the backtrace for all threads, and:
bt 1 3 4
show the backtrace for threads 1, 3 and 4. If we want to come up with some fancier syntax for thread lists later, that will be great, but this will do for now.
llvm-svn: 112248
Diffstat (limited to 'lldb/source/Commands/CommandObjectThread.cpp')
-rw-r--r-- | lldb/source/Commands/CommandObjectThread.cpp | 86 |
1 files changed, 80 insertions, 6 deletions
diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp index f28def85067..1ed9794663f 100644 --- a/lldb/source/Commands/CommandObjectThread.cpp +++ b/lldb/source/Commands/CommandObjectThread.cpp @@ -324,8 +324,8 @@ public: CommandObjectThreadBacktrace () : CommandObject ("thread backtrace", - "Shows the stack for one or more threads.", - "thread backtrace [<thread-idx>] ...", + "Shows the stack for one or more threads. If no threads are specified, shows the currently selected thread. \nUse the thread-index \"all\" to see all threads.", + "thread backtrace [<thread-index>] ...", eFlagProcessMustBeLaunched | eFlagProcessMustBePaused), m_options() { @@ -349,13 +349,17 @@ public: CommandReturnObject &result ) { + + bool show_frame_info = true; + uint32_t num_frames_with_source = 0; // Don't show any frames with source when backtracing + + result.SetStatus (eReturnStatusSuccessFinishResult); + if (command.GetArgumentCount() == 0) { ExecutionContext exe_ctx(interpreter.GetDebugger().GetExecutionContext()); if (exe_ctx.thread) { - bool show_frame_info = true; - uint32_t num_frames_with_source = 0; // Don't show any frasmes with source when backtracing if (DisplayFramesForExecutionContext (exe_ctx.thread, interpreter, result.GetOutputStream(), @@ -375,10 +379,80 @@ public: result.SetStatus (eReturnStatusFailed); } } + else if (command.GetArgumentCount() == 1 && ::strcmp (command.GetArgumentAtIndex(0), "all") == 0) + { + Process *process = interpreter.GetDebugger().GetExecutionContext().process; + uint32_t num_threads = process->GetThreadList().GetSize(); + for (uint32_t i = 0; i < num_threads; i++) + { + ThreadSP thread_sp = process->GetThreadList().GetThreadAtIndex(i); + if (!DisplayFramesForExecutionContext (thread_sp.get(), + interpreter, + result.GetOutputStream(), + m_options.m_start, + m_options.m_count, + show_frame_info, + num_frames_with_source, + 3, + 3)) + { + result.AppendErrorWithFormat ("error displaying backtrace for thread: \"%d\"\n", i); + result.SetStatus (eReturnStatusFailed); + return false; + } + if (i < num_threads - 1) + result.AppendMessage(""); + } + } else { - result.AppendError ("backtrace doesn't take arguments (for now)"); - result.SetStatus (eReturnStatusFailed); + uint32_t num_args = command.GetArgumentCount(); + Process *process = interpreter.GetDebugger().GetExecutionContext().process; + std::vector<ThreadSP> thread_sps; + + for (uint32_t i = 0; i < num_args; i++) + { + bool success; + + uint32_t thread_idx = Args::StringToUInt32(command.GetArgumentAtIndex(i), 0, 0, &success); + if (!success) + { + result.AppendErrorWithFormat ("invalid thread specification: \"%s\"\n", command.GetArgumentAtIndex(i)); + result.SetStatus (eReturnStatusFailed); + return false; + } + + thread_sps.push_back(process->GetThreadList().FindThreadByIndexID(thread_idx)); + + if (!thread_sps[i]) + { + result.AppendErrorWithFormat ("no thread with index: \"%s\"\n", command.GetArgumentAtIndex(i)); + result.SetStatus (eReturnStatusFailed); + return false; + } + + } + + for (uint32_t i = 0; i < num_args; i++) + { + if (!DisplayFramesForExecutionContext (thread_sps[i].get(), + interpreter, + result.GetOutputStream(), + m_options.m_start, + m_options.m_count, + show_frame_info, + num_frames_with_source, + 3, + 3)) + { + result.AppendErrorWithFormat ("error displaying backtrace for thread: \"%s\"\n", command.GetArgumentAtIndex(i)); + result.SetStatus (eReturnStatusFailed); + return false; + } + + if (i < num_args - 1) + result.AppendMessage(""); + } } return result.Succeeded(); } |