From 7260f6206f4f38273b5bef39361543c7245c99dd Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Mon, 18 Apr 2011 08:33:37 +0000 Subject: 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 " 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 --- lldb/source/Commands/CommandObjectFile.cpp | 235 ----------------------------- 1 file changed, 235 deletions(-) delete mode 100644 lldb/source/Commands/CommandObjectFile.cpp (limited to 'lldb/source/Commands/CommandObjectFile.cpp') 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(); -} -- cgit v1.2.3