summaryrefslogtreecommitdiffstats
path: root/lldb/source/Commands/CommandObjectStatus.cpp
blob: 501e0b23c84d38f425b3179d6ca2666ff5a16ebe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//===-- CommandObjectStatus.cpp ---------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "CommandObjectStatus.h"

// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
#include "CommandObjectThread.h"

#include "lldb/Core/State.h"

#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandReturnObject.h"

#include "lldb/Target/Process.h"
#include "lldb/Target/Thread.h"

using namespace lldb;
using namespace lldb_private;

//-------------------------------------------------------------------------
// CommandObjectStatus
//-------------------------------------------------------------------------

CommandObjectStatus::CommandObjectStatus () :
    CommandObject ("status",
                   "Shows the current status and location of executing process.",
                   "status",
                   0)
{
}

CommandObjectStatus::~CommandObjectStatus()
{
}


bool
CommandObjectStatus::Execute
(
    Args& command,
    CommandContext *context,
    CommandInterpreter *interpreter,
    CommandReturnObject &result
)
{
    StreamString &output_stream = result.GetOutputStream();
    result.SetStatus (eReturnStatusSuccessFinishNoResult);
    ExecutionContext exe_ctx(context->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
            {
                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 (interpreter, &exe_ctx, result, true, true);
                }
                else
                {
                    result.AppendError ("No valid thread found in current process.");
                    result.SetStatus (eReturnStatusFailed);
                }
            }
        }
    }
    else
    {
        result.AppendError ("No current location or status available.");
        result.SetStatus (eReturnStatusFailed);
    }
    return result.Succeeded();
}

OpenPOWER on IntegriCloud