summaryrefslogtreecommitdiffstats
path: root/lldb/source/Commands
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2011-04-18 08:33:37 +0000
committerGreg Clayton <gclayton@apple.com>2011-04-18 08:33:37 +0000
commit7260f6206f4f38273b5bef39361543c7245c99dd (patch)
tree54c9177272ba4f605a5bc538750f46116a39c376 /lldb/source/Commands
parent48f75ad67813037ea12d5d10d887ef1014d9c307 (diff)
downloadbcm5719-llvm-7260f6206f4f38273b5bef39361543c7245c99dd.tar.gz
bcm5719-llvm-7260f6206f4f38273b5bef39361543c7245c99dd.zip
Centralized a lot of the status information for processes,
threads, and stack frame down in the lldb_private::Process, lldb_private::Thread, lldb_private::StackFrameList and the lldb_private::StackFrame classes. We had some command line commands that had duplicate versions of the process status output ("thread list" and "process status" for example). Removed the "file" command and placed it where it should have been: "target create". Made an alias for "file" to "target create" so we stay compatible with GDB commands. We can now have multple usable targets in lldb at the same time. This is nice for comparing two runs of a program or debugging more than one binary at the same time. The new command is "target select <target-idx>" and also to see a list of the current targets you can use the new "target list" command. The flow in a debug session can be: (lldb) target create /path/to/exe/a.out (lldb) breakpoint set --name main (lldb) run ... hit breakpoint (lldb) target create /bin/ls (lldb) run /tmp Process 36001 exited with status = 0 (0x00000000) (lldb) target list Current targets: target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped ) * target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited ) (lldb) target select 0 Current targets: * target #0: /tmp/args/a.out ( arch=x86_64-apple-darwin, platform=localhost, pid=35999, state=stopped ) target #1: /bin/ls ( arch=x86_64-apple-darwin, platform=localhost, pid=36001, state=exited ) (lldb) bt * thread #1: tid = 0x2d03, 0x0000000100000b9a a.out`main + 42 at main.c:16, stop reason = breakpoint 1.1 frame #0: 0x0000000100000b9a a.out`main + 42 at main.c:16 frame #1: 0x0000000100000b64 a.out`start + 52 Above we created a target for "a.out" and ran and hit a breakpoint at "main". Then we created a new target for /bin/ls and ran it. Then we listed the targest and selected our original "a.out" program, so we showed two concurent debug sessions going on at the same time. llvm-svn: 129695
Diffstat (limited to 'lldb/source/Commands')
-rw-r--r--lldb/source/Commands/CommandObjectExpression.cpp23
-rw-r--r--lldb/source/Commands/CommandObjectFile.cpp235
-rw-r--r--lldb/source/Commands/CommandObjectFile.h95
-rw-r--r--lldb/source/Commands/CommandObjectFrame.cpp19
-rw-r--r--lldb/source/Commands/CommandObjectPlatform.cpp117
-rw-r--r--lldb/source/Commands/CommandObjectPlatform.h58
-rw-r--r--lldb/source/Commands/CommandObjectProcess.cpp55
-rw-r--r--lldb/source/Commands/CommandObjectTarget.cpp408
-rw-r--r--lldb/source/Commands/CommandObjectThread.cpp310
-rw-r--r--lldb/source/Commands/CommandObjectThread.h36
10 files changed, 489 insertions, 867 deletions
diff --git a/lldb/source/Commands/CommandObjectExpression.cpp b/lldb/source/Commands/CommandObjectExpression.cpp
index 82d2197e7cc..ee14839372b 100644
--- a/lldb/source/Commands/CommandObjectExpression.cpp
+++ b/lldb/source/Commands/CommandObjectExpression.cpp
@@ -13,7 +13,6 @@
// C++ Includes
// Other libraries and framework includes
// Project includes
-#include "CommandObjectThread.h" // For DisplayThreadInfo.
#include "lldb/Interpreter/Args.h"
#include "lldb/Core/Value.h"
#include "lldb/Core/InputReader.h"
@@ -32,6 +31,7 @@
#include "lldb/Target/Process.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Target.h"
+#include "lldb/Target/Thread.h"
#include "llvm/ADT/StringRef.h"
using namespace lldb;
@@ -281,10 +281,25 @@ CommandObjectExpression::EvaluateExpression
if (exe_results == eExecutionInterrupted && !m_options.unwind_on_error)
{
+ uint32_t start_frame = 0;
+ uint32_t num_frames = 1;
+ uint32_t num_frames_with_source = 0;
if (m_exe_ctx.thread)
- lldb_private::DisplayThreadInfo (m_interpreter, result->GetOutputStream(), m_exe_ctx.thread, false, true);
- else
- lldb_private::DisplayThreadsInfo (m_interpreter, &m_exe_ctx, *result, true, true);
+ {
+ m_exe_ctx.thread->GetStatus (result->GetOutputStream(),
+ start_frame,
+ num_frames,
+ num_frames_with_source);
+ }
+ else if (m_exe_ctx.process)
+ {
+ bool only_threads_with_stop_reason = true;
+ m_exe_ctx.process->GetThreadStatus (result->GetOutputStream(),
+ only_threads_with_stop_reason,
+ start_frame,
+ num_frames,
+ num_frames_with_source);
+ }
}
if (result_valobj_sp)
diff --git a/lldb/source/Commands/CommandObjectFile.cpp b/lldb/source/Commands/CommandObjectFile.cpp
deleted file mode 100644
index 563cbe298dc..00000000000
--- a/lldb/source/Commands/CommandObjectFile.cpp
+++ /dev/null
@@ -1,235 +0,0 @@
-//===-- CommandObjectFile.cpp -----------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "CommandObjectFile.h"
-
-// C Includes
-// C++ Includes
-// Other libraries and framework includes
-// Project includes
-#include "lldb/Interpreter/Args.h"
-#include "lldb/Core/Debugger.h"
-#include "lldb/Core/Timer.h"
-#include "lldb/Core/Debugger.h"
-#include "lldb/Interpreter/CommandInterpreter.h"
-#include "lldb/Interpreter/CommandReturnObject.h"
-#include "lldb/Interpreter/CommandCompletions.h"
-#include "lldb/Target/Process.h"
-
-using namespace lldb;
-using namespace lldb_private;
-
-FileOptionGroup::FileOptionGroup() :
- m_arch_str ()
-{
-}
-
-FileOptionGroup::~FileOptionGroup ()
-{
-}
-
-OptionDefinition g_file_option_table[] =
-{
- { LLDB_OPT_SET_1 , false, "arch" , 'a', required_argument, NULL, 0, eArgTypeArchitecture , "Specify the architecture for the target."},
-};
-const uint32_t k_num_file_options = sizeof(g_file_option_table)/sizeof(OptionDefinition);
-
-uint32_t
-FileOptionGroup::GetNumDefinitions ()
-{
- return k_num_file_options;
-}
-
-const OptionDefinition *
-FileOptionGroup::GetDefinitions ()
-{
- return g_file_option_table;
-}
-
-bool
-FileOptionGroup::GetArchitecture (Platform *platform, ArchSpec &arch)
-{
- if (m_arch_str.empty())
- arch.Clear();
- else
- arch.SetTriple(m_arch_str.c_str(), platform);
- return arch.IsValid();
-}
-
-
-Error
-FileOptionGroup::SetOptionValue (CommandInterpreter &interpreter,
- uint32_t option_idx,
- const char *option_arg)
-{
- Error error;
- char short_option = (char) g_file_option_table[option_idx].short_option;
-
- switch (short_option)
- {
- case 'a':
- m_arch_str.assign (option_arg);
- break;
-
- default:
- error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
- break;
- }
-
- return error;
-}
-
-void
-FileOptionGroup::OptionParsingStarting (CommandInterpreter &interpreter)
-{
- m_arch_str.clear();
-}
-
-//-------------------------------------------------------------------------
-// CommandObjectFile
-//-------------------------------------------------------------------------
-
-CommandObjectFile::CommandObjectFile(CommandInterpreter &interpreter) :
- CommandObject (interpreter,
- "file",
- "Set the file to be used as the main executable by the debugger.",
- NULL),
- m_option_group (interpreter),
- m_file_options (),
- m_platform_options(true) // Do include the "--platform" option in the platform settings by passing true
-{
- CommandArgumentEntry arg;
- CommandArgumentData file_arg;
-
- // Define the first (and only) variant of this arg.
- file_arg.arg_type = eArgTypeFilename;
- file_arg.arg_repetition = eArgRepeatPlain;
-
- // There is only one variant this argument could be; put it into the argument entry.
- arg.push_back (file_arg);
-
- // Push the data for the first argument into the m_arguments vector.
- m_arguments.push_back (arg);
-
- m_option_group.Append (&m_file_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Append (&m_platform_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
- m_option_group.Finalize();
-}
-
-CommandObjectFile::~CommandObjectFile ()
-{
-}
-
-Options *
-CommandObjectFile::GetOptions ()
-{
- return &m_option_group;
-}
-
-bool
-CommandObjectFile::Execute
-(
- Args& command,
- CommandReturnObject &result
-)
-{
- const char *file_path = command.GetArgumentAtIndex(0);
- Timer scoped_timer(__PRETTY_FUNCTION__, "(lldb) file '%s'", file_path);
- const int argc = command.GetArgumentCount();
- if (argc == 1)
- {
- FileSpec file_spec (file_path, true);
-
- bool select = true;
- PlatformSP platform_sp;
-
- Error error;
-
- if (!m_platform_options.platform_name.empty())
- {
- platform_sp = m_platform_options.CreatePlatformWithOptions(m_interpreter, select, error);
- if (!platform_sp)
- {
- result.AppendError(error.AsCString());
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
- ArchSpec file_arch;
-
- if (!m_file_options.m_arch_str.empty())
- {
- if (!platform_sp)
- platform_sp = m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform();
- if (!m_file_options.GetArchitecture(platform_sp.get(), file_arch))
- {
- result.AppendErrorWithFormat("invalid architecture '%s'", m_file_options.m_arch_str.c_str());
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
- }
-
- if (! file_spec.Exists() && !file_spec.ResolveExecutableLocation())
- {
- result.AppendErrorWithFormat ("File '%s' does not exist.\n", file_path);
- result.SetStatus (eReturnStatusFailed);
- return false;
- }
-
- TargetSP target_sp;
- Debugger &debugger = m_interpreter.GetDebugger();
- error = debugger.GetTargetList().CreateTarget (debugger, file_spec, file_arch, true, target_sp);
-
- if (target_sp)
- {
- debugger.GetTargetList().SetSelectedTarget(target_sp.get());
- result.AppendMessageWithFormat ("Current executable set to '%s' (%s).\n", file_path, target_sp->GetArchitecture().GetArchitectureName());
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- else
- {
- result.AppendError(error.AsCString());
- result.SetStatus (eReturnStatusFailed);
- }
- }
- else
- {
- result.AppendErrorWithFormat("'%s' takes exactly one executable path argument.\n", m_cmd_name.c_str());
- result.SetStatus (eReturnStatusFailed);
- }
- return result.Succeeded();
-
-}
-
-int
-CommandObjectFile::HandleArgumentCompletion
-(
- Args &input,
- int &cursor_index,
- int &cursor_char_position,
- OptionElementVector &opt_element_vector,
- int match_start_point,
- int max_return_elements,
- bool &word_complete,
- StringList &matches
-)
-{
- std::string completion_str (input.GetArgumentAtIndex(cursor_index));
- completion_str.erase (cursor_char_position);
-
- CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
- CommandCompletions::eDiskFileCompletion,
- completion_str.c_str(),
- match_start_point,
- max_return_elements,
- NULL,
- word_complete,
- matches);
- return matches.GetSize();
-}
diff --git a/lldb/source/Commands/CommandObjectFile.h b/lldb/source/Commands/CommandObjectFile.h
deleted file mode 100644
index f3ef2d94a15..00000000000
--- a/lldb/source/Commands/CommandObjectFile.h
+++ /dev/null
@@ -1,95 +0,0 @@
-//===-- CommandObjectFile.h -------------------------------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef liblldb_CommandObjectFile_h_
-#define liblldb_CommandObjectFile_h_
-
-// C Includes
-// C++ Includes
-#include <vector>
-// Other libraries and framework includes
-// Project includes
-#include "lldb/Interpreter/Options.h"
-#include "lldb/Core/ArchSpec.h"
-#include "lldb/Interpreter/CommandObject.h"
-#include "CommandObjectPlatform.h"
-
-namespace lldb_private {
-
-//-------------------------------------------------------------------------
-// CommandObjectFile
-//-------------------------------------------------------------------------
-
-class FileOptionGroup : public OptionGroup
-{
-public:
-
- FileOptionGroup ();
-
- virtual
- ~FileOptionGroup ();
-
-
- virtual uint32_t
- GetNumDefinitions ();
-
- virtual const OptionDefinition*
- GetDefinitions ();
-
- virtual Error
- SetOptionValue (CommandInterpreter &interpreter,
- uint32_t option_idx,
- const char *option_value);
-
- virtual void
- OptionParsingStarting (CommandInterpreter &interpreter);
-
- bool
- GetArchitecture (Platform *platform, ArchSpec &arch);
-
- std::string m_arch_str; // Save the arch triple in case a platform is specified after the architecture
-};
-
-class CommandObjectFile : public CommandObject
-{
-public:
-
- CommandObjectFile (CommandInterpreter &interpreter);
-
- virtual
- ~CommandObjectFile ();
-
- virtual bool
- Execute (Args& command,
- CommandReturnObject &result);
-
- virtual Options *
- GetOptions ();
-
-
- virtual int
- HandleArgumentCompletion (Args &input,
- int &cursor_index,
- int &cursor_char_position,
- OptionElementVector &opt_element_vector,
- int match_start_point,
- int max_return_elements,
- bool &word_complete,
- StringList &matches);
-
-
-private:
- OptionGroupOptions m_option_group;
- FileOptionGroup m_file_options;
- PlatformOptionGroup m_platform_options;
-};
-
-} // namespace lldb_private
-
-#endif // liblldb_CommandObjectFile_h_
diff --git a/lldb/source/Commands/CommandObjectFrame.cpp b/lldb/source/Commands/CommandObjectFrame.cpp
index bdcd7039b99..97dbdf30e17 100644
--- a/lldb/source/Commands/CommandObjectFrame.cpp
+++ b/lldb/source/Commands/CommandObjectFrame.cpp
@@ -37,8 +37,6 @@
#include "lldb/Target/Thread.h"
#include "lldb/Target/Target.h"
-#include "CommandObjectThread.h"
-
using namespace lldb;
using namespace lldb_private;
@@ -243,14 +241,15 @@ public:
already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
}
- if (DisplayFrameForExecutionContext (exe_ctx.thread,
- exe_ctx.frame,
- m_interpreter,
- result.GetOutputStream(),
- true,
- !already_shown,
- 3,
- 3))
+ bool show_frame_info = true;
+ bool show_source = !already_shown;
+ uint32_t source_lines_before = 3;
+ uint32_t source_lines_after = 3;
+ if (exe_ctx.frame->GetStatus(result.GetOutputStream(),
+ show_frame_info,
+ show_source,
+ source_lines_before,
+ source_lines_after))
{
result.SetStatus (eReturnStatusSuccessFinishResult);
return result.Succeeded();
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index 252865162a0..f9462f62421 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -19,7 +19,7 @@
#include "lldb/Interpreter/Args.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
-#include "lldb/Interpreter/Options.h"
+#include "lldb/Interpreter/OptionGroupPlatform.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
@@ -28,94 +28,8 @@ using namespace lldb;
using namespace lldb_private;
-PlatformSP
-PlatformOptionGroup::CreatePlatformWithOptions (CommandInterpreter &interpreter, bool select, Error& error)
-{
- PlatformSP platform_sp;
- if (!platform_name.empty())
- {
- platform_sp = Platform::Create (platform_name.c_str(), error);
-
- if (platform_sp)
- {
- interpreter.GetDebugger().GetPlatformList().Append (platform_sp, select);
- if (os_version_major != UINT32_MAX)
- {
- platform_sp->SetOSVersion (os_version_major,
- os_version_minor,
- os_version_update);
- }
- }
- }
- return platform_sp;
-}
-
-void
-PlatformOptionGroup::OptionParsingStarting (CommandInterpreter &interpreter)
-{
- platform_name.clear();
- os_version_major = UINT32_MAX;
- os_version_minor = UINT32_MAX;
- os_version_update = UINT32_MAX;
-}
-
-static OptionDefinition
-g_option_table[] =
-{
- { LLDB_OPT_SET_ALL, false, "platform" , 'p', required_argument, NULL, 0, eArgTypePlatform, "Specify name of the platform to use for this target, creating the platform if necessary."},
- { LLDB_OPT_SET_ALL, false, "sdk-version", 'v', required_argument, NULL, 0, eArgTypeNone, "Specify the initial SDK version to use prior to connecting." }
-};
-
-static const uint32_t k_option_table_size = sizeof(g_option_table)/sizeof (OptionDefinition);
-
-const OptionDefinition*
-PlatformOptionGroup::GetDefinitions ()
-{
- if (m_include_platform_option)
- return g_option_table;
- return g_option_table + 1;
-}
-
-uint32_t
-PlatformOptionGroup::GetNumDefinitions ()
-{
- if (m_include_platform_option)
- return k_option_table_size;
- return k_option_table_size - 1;
-}
-
-
-Error
-PlatformOptionGroup::SetOptionValue (CommandInterpreter &interpreter,
- uint32_t option_idx,
- const char *option_arg)
-{
- Error error;
- if (!m_include_platform_option)
- --option_idx;
-
- char short_option = (char) g_option_table[option_idx].short_option;
-
- switch (short_option)
- {
- case 'p':
- platform_name.assign (option_arg);
- break;
-
- case 'v':
- if (Args::StringToVersion (option_arg, os_version_major, os_version_minor, os_version_update) == option_arg)
- error.SetErrorStringWithFormat ("invalid version string '%s'", option_arg);
- break;
-
- default:
- error.SetErrorStringWithFormat ("Unrecognized option '%c'.\n", short_option);
- break;
- }
- return error;
-}
-
//----------------------------------------------------------------------
-// "platform create <platform-name>"
+// "platform select <platform-name>"
//----------------------------------------------------------------------
class CommandObjectPlatformSelect : public CommandObject
{
@@ -147,7 +61,7 @@ public:
if (platform_name && platform_name[0])
{
const bool select = true;
- m_platform_options.platform_name.assign (platform_name);
+ m_platform_options.SetPlatformName (platform_name);
Error error;
PlatformSP platform_sp (m_platform_options.CreatePlatformWithOptions (m_interpreter, select, error));
if (platform_sp)
@@ -175,6 +89,29 @@ public:
return result.Succeeded();
}
+
+ virtual int
+ HandleCompletion (Args &input,
+ int &cursor_index,
+ int &cursor_char_position,
+ int match_start_point,
+ int max_return_elements,
+ bool &word_complete,
+ StringList &matches)
+ {
+ std::string completion_str (input.GetArgumentAtIndex(cursor_index));
+ completion_str.erase (cursor_char_position);
+
+ CommandCompletions::PlatformPluginNames (m_interpreter,
+ completion_str.c_str(),
+ match_start_point,
+ max_return_elements,
+ NULL,
+ word_complete,
+ matches);
+ return matches.GetSize();
+ }
+
virtual Options *
GetOptions ()
{
@@ -183,7 +120,7 @@ public:
protected:
OptionGroupOptions m_option_group;
- PlatformOptionGroup m_platform_options;
+ OptionGroupPlatform m_platform_options;
};
//----------------------------------------------------------------------
diff --git a/lldb/source/Commands/CommandObjectPlatform.h b/lldb/source/Commands/CommandObjectPlatform.h
index 00199158666..f3bd7584864 100644
--- a/lldb/source/Commands/CommandObjectPlatform.h
+++ b/lldb/source/Commands/CommandObjectPlatform.h
@@ -35,64 +35,6 @@ public:
DISALLOW_COPY_AND_ASSIGN (CommandObjectPlatform);
};
-
-//-------------------------------------------------------------------------
-// PlatformOptionGroup
-//
-// Make platform options available to to any other command in case they
-// need them. The "file" command needs them, and by exposing them we can
-// reuse the platform command options for any command, we can keep things
-// consistent.
-//-------------------------------------------------------------------------
-class PlatformOptionGroup : public OptionGroup
-{
-public:
-
- PlatformOptionGroup (bool include_platform_option) :
- platform_name (),
- os_version_major (UINT32_MAX),
- os_version_minor (UINT32_MAX),
- os_version_update (UINT32_MAX),
- m_include_platform_option (include_platform_option)
- {
- }
-
- virtual
- ~PlatformOptionGroup ()
- {
- }
-
- virtual uint32_t
- GetNumDefinitions ();
-
- virtual const OptionDefinition*
- GetDefinitions ();
-
- virtual Error
- SetOptionValue (CommandInterpreter &interpreter,
- uint32_t option_idx,
- const char *option_value);
-
- lldb::PlatformSP
- CreatePlatformWithOptions (CommandInterpreter &interpreter,
- bool select,
- Error &error);
-
- virtual void
- OptionParsingStarting (CommandInterpreter &interpreter);
-
- // Instance variables to hold the values for command options.
-
- std::string platform_name;
- uint32_t os_version_major;
- uint32_t os_version_minor;
- uint32_t os_version_update;
-protected:
- bool m_include_platform_option;
-};
-
-
-
} // namespace lldb_private
#endif // liblldb_CommandObjectPlatform_h_
diff --git a/lldb/source/Commands/CommandObjectProcess.cpp b/lldb/source/Commands/CommandObjectProcess.cpp
index aed04bd6a81..5446cc66f96 100644
--- a/lldb/source/Commands/CommandObjectProcess.cpp
+++ b/lldb/source/Commands/CommandObjectProcess.cpp
@@ -16,10 +16,9 @@
#include "lldb/Interpreter/Args.h"
#include "lldb/Interpreter/Options.h"
#include "lldb/Core/State.h"
+#include "lldb/Host/Host.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
-#include "CommandObjectThread.h"
-#include "lldb/Host/Host.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
@@ -1491,52 +1490,26 @@ public:
CommandReturnObject &result
)
{
- Stream &output_stream = result.GetOutputStream();
+ Stream &strm = result.GetOutputStream();
result.SetStatus (eReturnStatusSuccessFinishNoResult);
ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
if (exe_ctx.process)
{
- const StateType state = exe_ctx.process->GetState();
- if (StateIsStoppedState(state))
- {
- if (state == eStateExited)
- {
- int exit_status = exe_ctx.process->GetExitStatus();
- const char *exit_description = exe_ctx.process->GetExitDescription();
- output_stream.Printf ("Process %d exited with status = %i (0x%8.8x) %s\n",
- exe_ctx.process->GetID(),
- exit_status,
- exit_status,
- exit_description ? exit_description : "");
- }
- else
- {
- if (state == eStateConnected)
- output_stream.Printf ("Connected to remote target.\n");
- else
- output_stream.Printf ("Process %d %s\n", exe_ctx.process->GetID(), StateAsCString (state));
- if (exe_ctx.thread == NULL)
- exe_ctx.thread = exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get();
- if (exe_ctx.thread != NULL)
- {
- DisplayThreadsInfo (m_interpreter, &exe_ctx, result, true, true);
- }
- else
- {
- result.AppendError ("No valid thread found in current process.");
- result.SetStatus (eReturnStatusFailed);
- }
- }
- }
- else
- {
- output_stream.Printf ("Process %d is running.\n",
- exe_ctx.process->GetID());
- }
+ const bool only_threads_with_stop_reason = true;
+ const uint32_t start_frame = 0;
+ const uint32_t num_frames = 1;
+ const uint32_t num_frames_with_source = 1;
+ exe_ctx.process->GetStatus(strm);
+ exe_ctx.process->GetThreadStatus (strm,
+ only_threads_with_stop_reason,
+ start_frame,
+ num_frames,
+ num_frames_with_source);
+
}
else
{
- result.AppendError ("No current location or status available.");
+ result.AppendError ("No process.");
result.SetStatus (eReturnStatusFailed);
}
return result.Succeeded();
diff --git a/lldb/source/Commands/CommandObjectTarget.cpp b/lldb/source/Commands/CommandObjectTarget.cpp
index 5a90bfb1288..6332976a875 100644
--- a/lldb/source/Commands/CommandObjectTarget.cpp
+++ b/lldb/source/Commands/CommandObjectTarget.cpp
@@ -18,9 +18,12 @@
#include "lldb/Interpreter/Args.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/InputReader.h"
+#include "lldb/Core/State.h"
#include "lldb/Core/Timer.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"
+#include "lldb/Interpreter/OptionGroupArchitecture.h"
+#include "lldb/Interpreter/OptionGroupPlatform.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/StackFrame.h"
#include "lldb/Target/Thread.h"
@@ -29,6 +32,360 @@
using namespace lldb;
using namespace lldb_private;
+
+
+static void
+DumpTargetInfo (uint32_t target_idx, Target *target, const char *prefix_cstr, bool show_stopped_process_status, Stream &strm)
+{
+ ArchSpec &target_arch = target->GetArchitecture();
+
+ ModuleSP exe_module_sp (target->GetExecutableModule ());
+ char exe_path[PATH_MAX];
+ bool exe_valid = false;
+ if (exe_module_sp)
+ exe_valid = exe_module_sp->GetFileSpec().GetPath (exe_path, sizeof(exe_path));
+
+ if (!exe_valid)
+ ::strcpy (exe_path, "<none>");
+
+ strm.Printf ("%starget #%u: %s", prefix_cstr ? prefix_cstr : "", target_idx, exe_path);
+
+ uint32_t properties = 0;
+ if (target_arch.IsValid())
+ {
+ strm.Printf ("%sarch=%s", properties++ > 0 ? ", " : " ( ", target_arch.GetTriple().str().c_str());
+ properties++;
+ }
+ PlatformSP platform_sp (target->GetPlatform());
+ if (platform_sp)
+ strm.Printf ("%splatform=%s", properties++ > 0 ? ", " : " ( ", platform_sp->GetName());
+
+ ProcessSP process_sp (target->GetProcessSP());
+ bool show_process_status = false;
+ if (process_sp)
+ {
+ lldb::pid_t pid = process_sp->GetID();
+ StateType state = process_sp->GetState();
+ if (show_stopped_process_status)
+ show_process_status = StateIsStoppedState(state);
+ const char *state_cstr = StateAsCString (state);
+ if (pid != LLDB_INVALID_PROCESS_ID)
+ strm.Printf ("%spid=%i", properties++ > 0 ? ", " : " ( ", pid);
+ strm.Printf ("%sstate=%s", properties++ > 0 ? ", " : " ( ", state_cstr);
+ }
+ if (properties > 0)
+ strm.PutCString (" )\n");
+ else
+ strm.EOL();
+ if (show_process_status)
+ {
+ const bool only_threads_with_stop_reason = true;
+ const uint32_t start_frame = 0;
+ const uint32_t num_frames = 1;
+ const uint32_t num_frames_with_source = 1;
+ process_sp->GetStatus (strm);
+ process_sp->GetThreadStatus (strm,
+ only_threads_with_stop_reason,
+ start_frame,
+ num_frames,
+ num_frames_with_source);
+
+ }
+}
+
+static uint32_t
+DumpTargetList (TargetList &target_list, bool show_stopped_process_status, Stream &strm)
+{
+ const uint32_t num_targets = target_list.GetNumTargets();
+ if (num_targets)
+ {
+ TargetSP selected_target_sp (target_list.GetSelectedTarget());
+ strm.PutCString ("Current targets:\n");
+ for (uint32_t i=0; i<num_targets; ++i)
+ {
+ TargetSP target_sp (target_list.GetTargetAtIndex (i));
+ if (target_sp)
+ {
+ bool is_selected = target_sp.get() == selected_target_sp.get();
+ DumpTargetInfo (i,
+ target_sp.get(),
+ is_selected ? "* " : " ",
+ show_stopped_process_status,
+ strm);
+ }
+ }
+ }
+ return num_targets;
+}
+#pragma mark CommandObjectTargetCreate
+
+//-------------------------------------------------------------------------
+// "target create"
+//-------------------------------------------------------------------------
+
+class CommandObjectTargetCreate : public CommandObject
+{
+public:
+ CommandObjectTargetCreate(CommandInterpreter &interpreter) :
+ CommandObject (interpreter,
+ "target create",
+ "Create a target using the argument as the main executable.",
+ NULL),
+ m_option_group (interpreter),
+ m_file_options (),
+ m_platform_options(true) // Do include the "--platform" option in the platform settings by passing true
+ {
+ CommandArgumentEntry arg;
+ CommandArgumentData file_arg;
+
+ // Define the first (and only) variant of this arg.
+ file_arg.arg_type = eArgTypeFilename;
+ file_arg.arg_repetition = eArgRepeatPlain;
+
+ // There is only one variant this argument could be; put it into the argument entry.
+ arg.push_back (file_arg);
+
+ // Push the data for the first argument into the m_arguments vector.
+ m_arguments.push_back (arg);
+
+ m_option_group.Append (&m_file_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Append (&m_platform_options, LLDB_OPT_SET_ALL, LLDB_OPT_SET_1);
+ m_option_group.Finalize();
+ }
+
+ ~CommandObjectTargetCreate ()
+ {
+ }
+
+ Options *
+ GetOptions ()
+ {
+ return &m_option_group;
+ }
+
+ bool
+ Execute (Args& command, CommandReturnObject &result)
+ {
+ const int argc = command.GetArgumentCount();
+ if (argc == 1)
+ {
+ const char *file_path = command.GetArgumentAtIndex(0);
+ Timer scoped_timer(__PRETTY_FUNCTION__, "(lldb) target create '%s'", file_path);
+ FileSpec file_spec (file_path, true);
+
+ bool select = true;
+ PlatformSP platform_sp;
+
+ Error error;
+
+ if (m_platform_options.PlatformWasSpecified ())
+ {
+ platform_sp = m_platform_options.CreatePlatformWithOptions(m_interpreter, select, error);
+ if (!platform_sp)
+ {
+ result.AppendError(error.AsCString());
+ result.SetStatus (eReturnStatusFailed);
+ return false;
+ }
+ }
+ ArchSpec file_arch;
+
+ const char *arch_cstr = m_file_options.GetArchitectureName();
+ if (arch_cstr)
+ {
+ if (!platform_sp)
+ platform_sp = m_interpreter.GetDebugger().GetPlatformList().GetSelectedPlatform();
+ if (!m_file_options.GetArchitecture(platform_sp.get(), file_arch))
+ {
+ result.AppendErrorWithFormat("invalid architecture '%s'\n", arch_cstr);
+ result.SetStatus (eReturnStatusFailed);
+ return false;
+ }
+ }
+
+ if (! file_spec.Exists() && !file_spec.ResolveExecutableLocation())
+ {
+ result.AppendErrorWithFormat ("File '%s' does not exist.\n", file_path);
+ result.SetStatus (eReturnStatusFailed);
+ return false;
+ }
+
+ TargetSP target_sp;
+ Debugger &debugger = m_interpreter.GetDebugger();
+ error = debugger.GetTargetList().CreateTarget (debugger, file_spec, file_arch, true, target_sp);
+
+ if (target_sp)
+ {
+ debugger.GetTargetList().SetSelectedTarget(target_sp.get());
+ result.AppendMessageWithFormat ("Current executable set to '%s' (%s).\n", file_path, target_sp->GetArchitecture().GetArchitectureName());
+ result.SetStatus (eReturnStatusSuccessFinishNoResult);
+ }
+ else
+ {
+ result.AppendError(error.AsCString());
+ result.SetStatus (eReturnStatusFailed);
+ }
+ }
+ else
+ {
+ result.AppendErrorWithFormat("'%s' takes exactly one executable path argument.\n", m_cmd_name.c_str());
+ result.SetStatus (eReturnStatusFailed);
+ }
+ return result.Succeeded();
+
+ }
+
+ int
+ HandleArgumentCompletion (Args &input,
+ int &cursor_index,
+ int &cursor_char_position,
+ OptionElementVector &opt_element_vector,
+ int match_start_point,
+ int max_return_elements,
+ bool &word_complete,
+ StringList &matches)
+ {
+ std::string completion_str (input.GetArgumentAtIndex(cursor_index));
+ completion_str.erase (cursor_char_position);
+
+ CommandCompletions::InvokeCommonCompletionCallbacks (m_interpreter,
+ CommandCompletions::eDiskFileCompletion,
+ completion_str.c_str(),
+ match_start_point,
+ max_return_elements,
+ NULL,
+ word_complete,
+ matches);
+ return matches.GetSize();
+ }
+private:
+ OptionGroupOptions m_option_group;
+ OptionGroupArchitecture m_file_options;
+ OptionGroupPlatform m_platform_options;
+
+};
+
+#pragma mark CommandObjectTargetList
+
+//----------------------------------------------------------------------
+// "target list"
+//----------------------------------------------------------------------
+
+class CommandObjectTargetList : public CommandObject
+{
+public:
+ CommandObjectTargetList (CommandInterpreter &interpreter) :
+ CommandObject (interpreter,
+ "target list",
+ "List all current targets in the current debug session.",
+ NULL,
+ 0)
+ {
+ }
+
+ virtual
+ ~CommandObjectTargetList ()
+ {
+ }
+
+ virtual bool
+ Execute (Args& args, CommandReturnObject &result)
+ {
+ if (args.GetArgumentCount() == 0)
+ {
+ Stream &strm = result.GetOutputStream();
+
+ bool show_stopped_process_status = false;
+ if (DumpTargetList (m_interpreter.GetDebugger().GetTargetList(), show_stopped_process_status, strm) == 0)
+ {
+ strm.PutCString ("No targets.\n");
+ }
+ }
+ else
+ {
+ result.AppendError ("the 'target list' command takes no arguments\n");
+ result.SetStatus (eReturnStatusFailed);
+ }
+ return result.Succeeded();
+ }
+};
+
+
+#pragma mark CommandObjectTargetSelect
+
+//----------------------------------------------------------------------
+// "target select"
+//----------------------------------------------------------------------
+
+class CommandObjectTargetSelect : public CommandObject
+{
+public:
+ CommandObjectTargetSelect (CommandInterpreter &interpreter) :
+ CommandObject (interpreter,
+ "target select",
+ "Select a target as the current target by target index.",
+ NULL,
+ 0)
+ {
+ }
+
+ virtual
+ ~CommandObjectTargetSelect ()
+ {
+ }
+
+ virtual bool
+ Execute (Args& args, CommandReturnObject &result)
+ {
+ if (args.GetArgumentCount() == 1)
+ {
+ bool success = false;
+ const char *target_idx_arg = args.GetArgumentAtIndex(0);
+ uint32_t target_idx = Args::StringToUInt32 (target_idx_arg, UINT32_MAX, 0, &success);
+ if (success)
+ {
+ TargetList &target_list = m_interpreter.GetDebugger().GetTargetList();
+ const uint32_t num_targets = target_list.GetNumTargets();
+ if (target_idx < num_targets)
+ {
+ TargetSP target_sp (target_list.GetTargetAtIndex (target_idx));
+ if (target_sp)
+ {
+ Stream &strm = result.GetOutputStream();
+ target_list.SetSelectedTarget (target_sp.get());
+ bool show_stopped_process_status = false;
+ DumpTargetList (target_list, show_stopped_process_status, strm);
+ }
+ else
+ {
+ result.AppendErrorWithFormat ("target #%u is NULL in target list\n", target_idx);
+ result.SetStatus (eReturnStatusFailed);
+ }
+ }
+ else
+ {
+ result.AppendErrorWithFormat ("index %u is out of range, valid target indexes are 0 - %u\n",
+ target_idx,
+ num_targets - 1);
+ result.SetStatus (eReturnStatusFailed);
+ }
+ }
+ else
+ {
+ result.AppendErrorWithFormat("invalid index string value '%s'\n", target_idx_arg);
+ result.SetStatus (eReturnStatusFailed);
+ }
+ }
+ else
+ {
+ result.AppendError ("'target select' takes a single argument: a target index\n");
+ result.SetStatus (eReturnStatusFailed);
+ }
+ return result.Succeeded();
+ }
+};
+
+
#pragma mark CommandObjectTargetImageSearchPaths
class CommandObjectTargetImageSearchPathsAdd : public CommandObject
@@ -77,7 +434,7 @@ public:
uint32_t argc = command.GetArgumentCount();
if (argc & 1)
{
- result.AppendError ("add requires an even number of arguments");
+ result.AppendError ("add requires an even number of arguments\n");
result.SetStatus (eReturnStatusFailed);
}
else
@@ -98,9 +455,9 @@ public:
else
{
if (from[0])
- result.AppendError ("<path-prefix> can't be empty");
+ result.AppendError ("<path-prefix> can't be empty\n");
else
- result.AppendError ("<new-path-prefix> can't be empty");
+ result.AppendError ("<new-path-prefix> can't be empty\n");
result.SetStatus (eReturnStatusFailed);
}
}
@@ -108,7 +465,7 @@ public:
}
else
{
- result.AppendError ("invalid target");
+ result.AppendError ("invalid target\n");
result.SetStatus (eReturnStatusFailed);
}
return result.Succeeded();
@@ -144,7 +501,7 @@ public:
}
else
{
- result.AppendError ("invalid target");
+ result.AppendError ("invalid target\n");
result.SetStatus (eReturnStatusFailed);
}
return result.Succeeded();
@@ -241,9 +598,9 @@ public:
else
{
if (from[0])
- result.AppendError ("<path-prefix> can't be empty");
+ result.AppendError ("<path-prefix> can't be empty\n");
else
- result.AppendError ("<new-path-prefix> can't be empty");
+ result.AppendError ("<new-path-prefix> can't be empty\n");
result.SetStatus (eReturnStatusFailed);
return false;
}
@@ -251,7 +608,7 @@ public:
}
else
{
- result.AppendError ("insert requires at least three arguments");
+ result.AppendError ("insert requires at least three arguments\n");
result.SetStatus (eReturnStatusFailed);
return result.Succeeded();
}
@@ -259,7 +616,7 @@ public:
}
else
{
- result.AppendError ("invalid target");
+ result.AppendError ("invalid target\n");
result.SetStatus (eReturnStatusFailed);
}
return result.Succeeded();
@@ -291,7 +648,7 @@ public:
{
if (command.GetArgumentCount() != 0)
{
- result.AppendError ("list takes no arguments");
+ result.AppendError ("list takes no arguments\n");
result.SetStatus (eReturnStatusFailed);
return result.Succeeded();
}
@@ -301,7 +658,7 @@ public:
}
else
{
- result.AppendError ("invalid target");
+ result.AppendError ("invalid target\n");
result.SetStatus (eReturnStatusFailed);
}
return result.Succeeded();
@@ -345,7 +702,7 @@ public:
{
if (command.GetArgumentCount() != 1)
{
- result.AppendError ("query requires one argument");
+ result.AppendError ("query requires one argument\n");
result.SetStatus (eReturnStatusFailed);
return result.Succeeded();
}
@@ -361,7 +718,7 @@ public:
}
else
{
- result.AppendError ("invalid target");
+ result.AppendError ("invalid target\n");
result.SetStatus (eReturnStatusFailed);
}
return result.Succeeded();
@@ -790,7 +1147,7 @@ public:
InputReaderSP reader_sp (new InputReader(m_interpreter.GetDebugger()));
if (!reader_sp)
{
- result.AppendError("out of memory");
+ result.AppendError("out of memory\n");
result.SetStatus (eReturnStatusFailed);
target->RemoveStopHookByID (new_hook_sp->GetID());
return false;
@@ -815,7 +1172,7 @@ public:
}
else
{
- result.AppendError ("invalid target");
+ result.AppendError ("invalid target\n");
result.SetStatus (eReturnStatusFailed);
}
@@ -902,14 +1259,14 @@ public:
lldb::user_id_t user_id = Args::StringToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success);
if (!success)
{
- result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".", command.GetArgumentAtIndex(i));
+ result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
result.SetStatus(eReturnStatusFailed);
return false;
}
success = target->RemoveStopHookByID (user_id);
if (!success)
{
- result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".", command.GetArgumentAtIndex(i));
+ result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -919,7 +1276,7 @@ public:
}
else
{
- result.AppendError ("invalid target");
+ result.AppendError ("invalid target\n");
result.SetStatus (eReturnStatusFailed);
}
@@ -971,14 +1328,14 @@ public:
lldb::user_id_t user_id = Args::StringToUInt32 (command.GetArgumentAtIndex(i), 0, 0, &success);
if (!success)
{
- result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".", command.GetArgumentAtIndex(i));
+ result.AppendErrorWithFormat ("invalid stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
result.SetStatus(eReturnStatusFailed);
return false;
}
success = target->SetStopHookActiveStateByID (user_id, m_enable);
if (!success)
{
- result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".", command.GetArgumentAtIndex(i));
+ result.AppendErrorWithFormat ("unknown stop hook id: \"%s\".\n", command.GetArgumentAtIndex(i));
result.SetStatus(eReturnStatusFailed);
return false;
}
@@ -988,7 +1345,7 @@ public:
}
else
{
- result.AppendError ("invalid target");
+ result.AppendError ("invalid target\n");
result.SetStatus (eReturnStatusFailed);
}
return result.Succeeded();
@@ -1032,7 +1389,7 @@ public:
}
else
{
- result.AppendError ("invalid target");
+ result.AppendError ("invalid target\n");
result.SetStatus (eReturnStatusFailed);
}
@@ -1104,11 +1461,16 @@ CommandObjectMultiwordTarget::CommandObjectMultiwordTarget (CommandInterpreter &
"A set of commands for operating on debugger targets.",
"target <subcommand> [<subcommand-options>]")
{
- LoadSubCommand ("image-search-paths", CommandObjectSP (new CommandObjectMultiwordImageSearchPaths (interpreter)));
+
+ LoadSubCommand ("create", CommandObjectSP (new CommandObjectTargetCreate (interpreter)));
+ LoadSubCommand ("list", CommandObjectSP (new CommandObjectTargetList (interpreter)));
+ LoadSubCommand ("select", CommandObjectSP (new CommandObjectTargetSelect (interpreter)));
LoadSubCommand ("stop-hook", CommandObjectSP (new CommandObjectMultiwordTargetStopHooks (interpreter)));
+ LoadSubCommand ("image-search-paths", CommandObjectSP (new CommandObjectMultiwordImageSearchPaths (interpreter)));
}
CommandObjectMultiwordTarget::~CommandObjectMultiwordTarget ()
{
}
+
diff --git a/lldb/source/Commands/CommandObjectThread.cpp b/lldb/source/Commands/CommandObjectThread.cpp
index fd90720b1e8..9f25b49e8e1 100644
--- a/lldb/source/Commands/CommandObjectThread.cpp
+++ b/lldb/source/Commands/CommandObjectThread.cpp
@@ -38,205 +38,6 @@ using namespace lldb;
using namespace lldb_private;
-bool
-lldb_private::DisplayThreadInfo
-(
- CommandInterpreter &interpreter,
- Stream &strm,
- Thread *thread,
- bool only_threads_with_stop_reason,
- bool show_source
-)
-{
- if (thread)
- {
- if (only_threads_with_stop_reason)
- {
- if (thread->GetStopInfo() == NULL)
- return false;
- }
-
- strm.Indent();
- strm.Printf("%c ", thread->GetProcess().GetThreadList().GetSelectedThread().get() == thread ? '*' : ' ');
-
- // Show one frame with only the first showing source
- if (show_source)
- {
- bool already_shown = false;
- StackFrameSP frame_sp = thread->GetStackFrameAtIndex(0);
- SymbolContext frame_sc(frame_sp->GetSymbolContext (eSymbolContextLineEntry));
- if (interpreter.GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0)
- {
- already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
- }
-
- DisplayFramesForExecutionContext (thread,
- interpreter,
- strm,
- 0, // Start at first frame
- 1, // Number of frames to show
- false,// Don't show the frame info since we already displayed most of it above...
- !already_shown, // Show source for the first frame
- 3, // lines of source context before
- 3); // lines of source context after
- }
- else
- {
- thread->DumpUsingSettingsFormat (strm, 0);
- }
-
- return true;
- }
- return false;
-}
-
-size_t
-lldb_private::DisplayThreadsInfo
-(
- CommandInterpreter &interpreter,
- ExecutionContext *exe_ctx,
- CommandReturnObject &result,
- bool only_threads_with_stop_reason,
- bool show_source
-)
-{
- StreamString strm;
-
- size_t num_thread_infos_dumped = 0;
-
- if (!exe_ctx->process)
- return 0;
-
- const size_t num_threads = exe_ctx->process->GetThreadList().GetSize();
- if (num_threads > 0)
- {
-
- for (uint32_t i = 0; i < num_threads; i++)
- {
- Thread *thread = exe_ctx->process->GetThreadList().GetThreadAtIndex(i).get();
- if (thread)
- {
- if (DisplayThreadInfo (interpreter,
- strm,
- thread,
- only_threads_with_stop_reason,
- show_source))
- ++num_thread_infos_dumped;
- }
- }
- }
-
- if (num_thread_infos_dumped > 0)
- {
- if (num_thread_infos_dumped < num_threads)
- result.GetOutputStream().Printf("%u of %u threads stopped with reasons:\n", num_thread_infos_dumped, num_threads);
-
- result.AppendMessage (strm.GetString().c_str());
- result.SetStatus (eReturnStatusSuccessFinishNoResult);
- }
- return num_thread_infos_dumped;
-}
-
-
-size_t
-lldb_private::DisplayFramesForExecutionContext
-(
- Thread *thread,
- CommandInterpreter &interpreter,
- Stream& strm,
- uint32_t first_frame,
- uint32_t num_frames,
- bool show_frame_info,
- uint32_t num_frames_with_source,
- uint32_t source_lines_before,
- uint32_t source_lines_after
-)
-{
- if (thread == NULL)
- return 0;
-
- size_t num_frames_displayed = 0;
-
- if (num_frames == 0)
- return 0;
-
- thread->DumpUsingSettingsFormat (strm, num_frames > 1 ? UINT32_MAX : first_frame);
- strm.IndentMore();
-
- StackFrameSP frame_sp;
- uint32_t frame_idx = 0;
- uint32_t last_frame;
-
- // Don't let the last frame wrap around...
- if (num_frames == UINT32_MAX)
- last_frame = UINT32_MAX;
- else
- last_frame = first_frame + num_frames;
-
- for (frame_idx = first_frame; frame_idx < last_frame; ++frame_idx)
- {
- frame_sp = thread->GetStackFrameAtIndex (frame_idx);
- if (frame_sp.get() == NULL)
- break;
-
- if (DisplayFrameForExecutionContext (thread,
- frame_sp.get(),
- interpreter,
- strm,
- show_frame_info,
- num_frames_with_source > first_frame - frame_idx,
- source_lines_before,
- source_lines_after) == false)
- break;
-
- ++num_frames_displayed;
- }
-
- strm.IndentLess();
- return num_frames_displayed;
-}
-
-bool
-lldb_private::DisplayFrameForExecutionContext
-(
- Thread *thread,
- StackFrame *frame,
- CommandInterpreter &interpreter,
- Stream& strm,
- bool show_frame_info,
- bool show_source,
- uint32_t source_lines_before,
- uint32_t source_lines_after
-)
-{
- // thread and frame must be filled in prior to calling this function
- if (thread && frame)
- {
- if (show_frame_info)
- {
- strm.Indent();
- frame->DumpUsingSettingsFormat (&strm);
- }
-
- SymbolContext sc (frame->GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry));
-
- if (show_source && sc.comp_unit && sc.line_entry.IsValid())
- {
- interpreter.GetDebugger().GetSourceManager().DisplaySourceLinesWithLineNumbers (
- sc.line_entry.file,
- sc.line_entry.line,
- 3,
- 3,
- "->",
- &strm);
-
- }
- return true;
- }
- return false;
-}
-
-
//-------------------------------------------------------------------------
// CommandObjectThreadBacktrace
//-------------------------------------------------------------------------
@@ -300,7 +101,7 @@ public:
void
OptionParsingStarting ()
{
- m_count = -1;
+ m_count = UINT32_MAX;
m_start = 0;
}
@@ -353,27 +154,21 @@ public:
virtual bool
Execute (Args& command, 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);
-
+ Stream &strm = result.GetOutputStream();
+
+ // Don't show source context when doing backtraces.
+ const uint32_t num_frames_with_source = 0;
if (command.GetArgumentCount() == 0)
{
ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
if (exe_ctx.thread)
{
- if (DisplayFramesForExecutionContext (exe_ctx.thread,
- m_interpreter,
- result.GetOutputStream(),
- m_options.m_start,
- m_options.m_count,
- show_frame_info,
- num_frames_with_source,
- 3,
- 3))
+ if (exe_ctx.thread->GetStatus (strm,
+ m_options.m_start,
+ m_options.m_count,
+ num_frames_with_source))
{
result.SetStatus (eReturnStatusSuccessFinishResult);
}
@@ -391,22 +186,15 @@ public:
for (uint32_t i = 0; i < num_threads; i++)
{
ThreadSP thread_sp = process->GetThreadList().GetThreadAtIndex(i);
- if (!DisplayFramesForExecutionContext (thread_sp.get(),
- m_interpreter,
- result.GetOutputStream(),
- m_options.m_start,
- m_options.m_count,
- show_frame_info,
- num_frames_with_source,
- 3,
- 3))
+ if (thread_sp->GetStatus (strm,
+ m_options.m_start,
+ m_options.m_count,
+ num_frames_with_source))
{
result.AppendErrorWithFormat ("error displaying backtrace for thread: \"0x%4.4x\"\n", i);
result.SetStatus (eReturnStatusFailed);
return false;
}
- if (i < num_threads - 1)
- result.AppendMessage("");
}
}
else
@@ -440,15 +228,10 @@ public:
for (uint32_t i = 0; i < num_args; i++)
{
- if (!DisplayFramesForExecutionContext (thread_sps[i].get(),
- m_interpreter,
- result.GetOutputStream(),
- m_options.m_start,
- m_options.m_count,
- show_frame_info,
- num_frames_with_source,
- 3,
- 3))
+ if (!thread_sps[i]->GetStatus (strm,
+ m_options.m_start,
+ m_options.m_count,
+ num_frames_with_source))
{
result.AppendErrorWithFormat ("error displaying backtrace for thread: \"%s\"\n", command.GetArgumentAtIndex(i));
result.SetStatus (eReturnStatusFailed);
@@ -1335,11 +1118,13 @@ public:
process->GetThreadList().SetSelectedThreadByID(new_thread->GetID());
result.SetStatus (eReturnStatusSuccessFinishNoResult);
- DisplayThreadInfo (m_interpreter,
- result.GetOutputStream(),
- new_thread,
- false,
- true);
+ const uint32_t start_frame = 0;
+ const uint32_t num_frames = 1;
+ const uint32_t num_frames_with_source = 1;
+ new_thread->GetStatus (result.GetOutputStream(),
+ start_frame,
+ num_frames,
+ num_frames_with_source);
return result.Succeeded();
}
@@ -1381,41 +1166,16 @@ public:
ExecutionContext exe_ctx(m_interpreter.GetExecutionContext());
if (exe_ctx.process)
{
- const StateType state = exe_ctx.process->GetState();
-
- if (StateIsStoppedState(state))
- {
- if (state == eStateExited)
- {
- int exit_status = exe_ctx.process->GetExitStatus();
- const char *exit_description = exe_ctx.process->GetExitDescription();
- strm.Printf ("Process %d exited with status = %i (0x%8.8x) %s\n",
- exe_ctx.process->GetID(),
- exit_status,
- exit_status,
- exit_description ? exit_description : "");
- }
- else
- {
- strm.Printf ("Process %d state is %s\n", exe_ctx.process->GetID(), StateAsCString (state));
- if (exe_ctx.thread == NULL)
- exe_ctx.thread = exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get();
- if (exe_ctx.thread != NULL)
- {
- DisplayThreadsInfo (m_interpreter, &exe_ctx, result, false, false);
- }
- else
- {
- result.AppendError ("no valid thread found in current process");
- result.SetStatus (eReturnStatusFailed);
- }
- }
- }
- else
- {
- result.AppendError ("process is currently running");
- result.SetStatus (eReturnStatusFailed);
- }
+ const bool only_threads_with_stop_reason = false;
+ const uint32_t start_frame = 0;
+ const uint32_t num_frames = 0;
+ const uint32_t num_frames_with_source = 0;
+ exe_ctx.process->GetStatus(strm);
+ exe_ctx.process->GetThreadStatus (strm,
+ only_threads_with_stop_reason,
+ start_frame,
+ num_frames,
+ num_frames_with_source);
}
else
{
diff --git a/lldb/source/Commands/CommandObjectThread.h b/lldb/source/Commands/CommandObjectThread.h
index 7fc58261ed0..52902ee36c7 100644
--- a/lldb/source/Commands/CommandObjectThread.h
+++ b/lldb/source/Commands/CommandObjectThread.h
@@ -29,42 +29,6 @@ public:
};
-
-bool
-DisplayThreadInfo (CommandInterpreter &interpreter,
- Stream &strm,
- Thread *thread,
- bool only_threads_with_stop_reason,
- bool show_source);
-
-size_t
-DisplayThreadsInfo (CommandInterpreter &interpreter,
- ExecutionContext *exe_ctx,
- CommandReturnObject &result,
- bool only_threads_with_stop_reason,
- bool show_source);
-
-size_t
-DisplayFramesForExecutionContext (Thread *thread,
- CommandInterpreter &interpreter,
- Stream& strm,
- uint32_t first_frame,
- uint32_t num_frames,
- bool show_frame_info,
- uint32_t num_frames_with_source,
- uint32_t source_lines_before,
- uint32_t source_lines_after);
-
-bool
-DisplayFrameForExecutionContext (Thread *thread,
- StackFrame *frame,
- CommandInterpreter &interpreter,
- Stream& strm,
- bool show_frame_info,
- bool show_source,
- uint32_t source_lines_before,
- uint32_t source_lines_after);
-
} // namespace lldb_private
#endif // liblldb_CommandObjectThread_h_
OpenPOWER on IntegriCloud