1#
2# %CopyrightBegin%
3#
4# Copyright Ericsson AB 2013-2016. All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18# %CopyrightEnd%
19#
20
21def get_thread_name(t):
22    f = gdb.newest_frame();
23    while f:
24        if f.name() == "async_main":
25            return "async";
26        elif f.name() == "erts_sys_main_thread":
27            return "main";
28        elif f.name() == "signal_dispatcher_thread_func":
29            return "signal_dispatcher";
30        elif f.name() == "sys_msg_dispatcher_func":
31            return "sys_msg_dispatcher";
32        elif f.name() == "child_waiter":
33            return "child_waiter";
34        elif f.name() == "sched_thread_func":
35            return "scheduler";
36        elif f.name() == "aux_thread":
37            return "aux";
38        f = f.older();
39    return "unknown";
40
41
42curr_thread = gdb.selected_thread();
43
44for i in gdb.inferiors():
45    gdb.write(" Id   Thread Name           Frame\n");
46    for t in i.threads():
47        t.switch();
48        if curr_thread == t:
49            gdb.write("*");
50        else:
51            gdb.write(" ");
52        gdb.write("{0:<3}  {1:20} {2}\n".format(
53                t.num,get_thread_name(t),
54                gdb.newest_frame().name()));
55
56curr_thread.switch();
57