summaryrefslogtreecommitdiffstats
path: root/src/build/debug/Hostboot/Ps.pm
blob: 4895a63f735374bfeccbf5d45e9306066184dbaa (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/build/debug/Hostboot/Ps.pm $
#
# OpenPOWER HostBoot Project
#
# COPYRIGHT International Business Machines Corp. 2011,2014
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
#
# IBM_PROLOG_END_TAG
use strict;

package Hostboot::Ps;
use Exporter;
our @EXPORT_OK = ('main');

use constant PS_TASKMGR_SYMBOLNAME =>
                "Singleton<TaskManager>::instance()::instance";
use constant PS_TASKMGR_TRACKER_LIST_OFFSET => 8 * 4;
use constant PS_TRACKER_LIST_HEAD_OFFSET => 0;
use constant PS_TRACKER_LIST_TAIL_OFFSET => 8 + PS_TRACKER_LIST_HEAD_OFFSET;
use constant PS_TRACKER_LIST_SIZE => 8 * 3;

use constant PS_TRACKER_PREV_OFFSET => 0;
use constant PS_TRACKER_NEXT_OFFSET => 8 + PS_TRACKER_PREV_OFFSET;
use constant PS_TRACKER_PARENT_OFFSET => 8 + PS_TRACKER_NEXT_OFFSET;
use constant PS_TRACKER_CHILDREN_LIST_OFFSET => 8 + PS_TRACKER_PARENT_OFFSET;
use constant PS_TRACKER_TID_OFFSET =>
                PS_TRACKER_CHILDREN_LIST_OFFSET + PS_TRACKER_LIST_SIZE;
use constant PS_TRACKER_TASK_OFFSET => 8 + PS_TRACKER_TID_OFFSET;
use constant PS_TRACKER_STATUS_OFFSET => 8 + PS_TRACKER_TASK_OFFSET;
use constant PS_TRACKER_RETVAL_OFFSET => 8 + PS_TRACKER_STATUS_OFFSET;
use constant PS_TRACKER_WAITINFO_OFFSET => 8 + PS_TRACKER_RETVAL_OFFSET;
use constant PS_TRACKER_ENTRYPOINT_OFFSET => 8 + PS_TRACKER_WAITINFO_OFFSET;

use constant PS_TASK_STATE_OFFSET => 8*43;
use constant PS_TASK_STATEEXTRA_OFFSET => 8 + PS_TASK_STATE_OFFSET;

sub main
{
    # Find symbol containing kernel list of task objects.
    #   (Tasks who's parent is the kernel)
    my ($symAddr, $symSize) = ::findSymbolAddress(PS_TASKMGR_SYMBOLNAME);
    if (not defined $symAddr)
    {
        ::userDisplay "Couldn't find ".PS_TASKMGR_SYMBOLNAME;
        die;
    }

    # Pass address of list to 'displayList' function.
    $symAddr += PS_TASKMGR_TRACKER_LIST_OFFSET;
    displayList($symAddr,0);
}

# Display a list of task objects.
sub displayList
{
    my ($listAddr, $level) = @_;

    my $firstDisplayed = 0;

    # Task lists are FIFO, so start from the 'tail'.
    my $node = ::read64(PS_TRACKER_LIST_TAIL_OFFSET + $listAddr);
    while (0 != $node)
    {
        if ($firstDisplayed)
        {
            ::userDisplay makeTabs($level)."\n";
        }
        else
        {
            $firstDisplayed = 1;
        }

        # Display tracker object for this node.
        displayTracker($node, $level);
        # Follow pointer to the next node.
        $node = ::read64(PS_TRACKER_PREV_OFFSET + $node);
    }
}

sub displayTracker
{
    my ($trackAddr, $level) = @_;

    # Read TID.
    my $tid = ::read16(PS_TRACKER_TID_OFFSET + $trackAddr);

    # Determine entry-point symbol name / module.
    my $entryPoint = ::read64(PS_TRACKER_ENTRYPOINT_OFFSET + $trackAddr);
    my $entryPointName = ::findSymbolByAddress($entryPoint);
    if (not $entryPointName) { $entryPointName = sprintf "0x%x",$entryPoint; }
    my $moduleName = ::findModuleByAddress($entryPoint);

    # Find task object, read task state if task is still running.
    my $taskAddr = ::read64(PS_TRACKER_TASK_OFFSET + $trackAddr);
    my $state = "";
    if ($taskAddr)
    {
        $state = pack("C",::read8(PS_TASK_STATE_OFFSET + $taskAddr));
    }
    else
    {
        $state = "Z";
    }
    my $stateExtra = "";  # Parse state extra debug info if it exists.
    if (($state ne "R") and ($state ne "r") and
        ($state ne "E") and ($state ne "Z"))
    {
        $stateExtra = sprintf "(0x%x)",
                              ::read64(PS_TASK_STATEEXTRA_OFFSET + $taskAddr);
    }
    elsif ($state eq "Z")
    {
        # If task has exited, read status and retval.
        my $status = ::read32(PS_TRACKER_STATUS_OFFSET + $trackAddr);
        my $retval = ::read64(PS_TRACKER_RETVAL_OFFSET + $trackAddr);
        if ($status) { $stateExtra = "(Crashed)"; }
        elsif ($retval) { $stateExtra = (sprintf "(0x%x)", $retval); }
    }
    # Map state to an verbose description.
    my %states = ( "R" => "Running",
                   "r" => "Ready",
                   "E" => "Ended",
                   "f" => "Block on Futex",
                   "M" => "Block on Message",
                   "u" => "Block on Userspace Request",
                   "s" => "Block on Sleeping",
                   "j" => "Block on Join",
                   "Z" => "Zombie",
                 );
    $state = $states{$state};

    # Display task info obtained.
    ::userDisplay makeTabs($level)."-+ TID $tid   State: $state$stateExtra\n";
    ::userDisplay makeTabs($level)." |     $entryPointName [$moduleName]\n";

    # Display list of children tasks.
    displayList($trackAddr + PS_TRACKER_CHILDREN_LIST_OFFSET, $level + 1);
}

sub makeTabs
{
    my $level = shift;

    my $result = "";
    while (0 != $level)
    {
        $result = $result." |";
        $level = $level - 1;
    }

    return $result;
}

sub helpInfo
{
    my %info = (
        name => "Ps",
        intro => ["Displays a tree of all tasks and their current state."],
    );
}
OpenPOWER on IntegriCloud