Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- CommandObjectStatus.cpp ---------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "CommandObjectStatus.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | #include "CommandObjectThread.h" |
| 17 | |
| 18 | #include "lldb/Core/State.h" |
| 19 | |
| 20 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 21 | #include "lldb/Interpreter/CommandReturnObject.h" |
| 22 | |
| 23 | #include "lldb/Target/Process.h" |
| 24 | #include "lldb/Target/Thread.h" |
| 25 | |
| 26 | using namespace lldb; |
| 27 | using namespace lldb_private; |
| 28 | |
| 29 | //------------------------------------------------------------------------- |
| 30 | // CommandObjectStatus |
| 31 | //------------------------------------------------------------------------- |
| 32 | |
| 33 | CommandObjectStatus::CommandObjectStatus () : |
| 34 | CommandObject ("status", |
| 35 | "Shows the current status and location of executing process.", |
| 36 | "status", |
| 37 | 0) |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | CommandObjectStatus::~CommandObjectStatus() |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | |
| 46 | bool |
| 47 | CommandObjectStatus::Execute |
| 48 | ( |
| 49 | Args& command, |
| 50 | CommandContext *context, |
| 51 | CommandInterpreter *interpreter, |
| 52 | CommandReturnObject &result |
| 53 | ) |
| 54 | { |
| 55 | StreamString &output_stream = result.GetOutputStream(); |
| 56 | result.SetStatus (eReturnStatusSuccessFinishNoResult); |
| 57 | ExecutionContext exe_ctx(context->GetExecutionContext()); |
| 58 | if (exe_ctx.process) |
| 59 | { |
| 60 | const StateType state = exe_ctx.process->GetState(); |
| 61 | if (StateIsStoppedState(state)) |
| 62 | { |
| 63 | if (state == eStateExited) |
| 64 | { |
| 65 | int exit_status = exe_ctx.process->GetExitStatus(); |
| 66 | const char *exit_description = exe_ctx.process->GetExitDescription(); |
| 67 | output_stream.Printf ("Process %d exited with status = %i (0x%8.8x) %s\n", |
| 68 | exe_ctx.process->GetID(), |
| 69 | exit_status, |
| 70 | exit_status, |
| 71 | exit_description ? exit_description : ""); |
| 72 | } |
| 73 | else |
| 74 | { |
| 75 | output_stream.Printf ("Process %d %s\n", exe_ctx.process->GetID(), StateAsCString (state)); |
| 76 | if (exe_ctx.thread == NULL) |
| 77 | exe_ctx.thread = exe_ctx.process->GetThreadList().GetThreadAtIndex(0).get(); |
| 78 | if (exe_ctx.thread != NULL) |
| 79 | { |
| 80 | DisplayThreadsInfo (interpreter, &exe_ctx, result, true, true); |
| 81 | } |
| 82 | else |
| 83 | { |
| 84 | result.AppendError ("No valid thread found in current process."); |
| 85 | result.SetStatus (eReturnStatusFailed); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | else |
| 91 | { |
| 92 | result.AppendError ("No current location or status available."); |
| 93 | result.SetStatus (eReturnStatusFailed); |
| 94 | } |
| 95 | return result.Succeeded(); |
| 96 | } |
| 97 | |