|
| 1 | +############################################################################ |
| 2 | +# tools/gdb/rpmsg.py |
| 3 | +# |
| 4 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 5 | +# contributor license agreements. See the NOTICE file distributed with |
| 6 | +# this work for additional information regarding copyright ownership. The |
| 7 | +# ASF licenses this file to you under the Apache License, Version 2.0 (the |
| 8 | +# "License"); you may not use this file except in compliance with the |
| 9 | +# License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 16 | +# License for the specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | +# |
| 19 | +############################################################################ |
| 20 | + |
| 21 | +import gdb |
| 22 | + |
| 23 | +from . import utils |
| 24 | +from .lists import NxList |
| 25 | + |
| 26 | + |
| 27 | +class RPMsgDump(gdb.Command): |
| 28 | + """Dump rpmsg service""" |
| 29 | + |
| 30 | + CALLBACK_HEADER = ["rpmsg_cb_s at", "ns_match", "ns_bind"] |
| 31 | + ENDPOINT_HEADER = [ |
| 32 | + "endpoint_addr", |
| 33 | + "name", |
| 34 | + "addr", |
| 35 | + "dest_addr", |
| 36 | + "cb", |
| 37 | + "ns_bound_cb", |
| 38 | + "ns_unbind_cb", |
| 39 | + ] |
| 40 | + |
| 41 | + CALLBACK_FORAMTTER = "{:<20} {:<40} {:<40}" |
| 42 | + ENDPOINT_FORMATTER = "{:<20} {:<20} {:<12} {:<12} {:<40} {:<40} {:<40}" |
| 43 | + |
| 44 | + def __init__(self): |
| 45 | + if utils.get_symbol_value("CONFIG_RPMSG"): |
| 46 | + super(RPMsgDump, self).__init__("rpmsgdump", gdb.COMMAND_USER) |
| 47 | + |
| 48 | + def print_headers(self, headers, formatter): |
| 49 | + gdb.write(formatter.format(*headers) + "\n") |
| 50 | + gdb.write(formatter.format(*["-" * len(header) for header in headers]) + "\n") |
| 51 | + |
| 52 | + def dump_rdev_epts(self, endpoints_head): |
| 53 | + gdb.write(f"dump_rdev_epts:{endpoints_head}\n") |
| 54 | + self.print_headers(self.ENDPOINT_HEADER, self.ENDPOINT_FORMATTER) |
| 55 | + |
| 56 | + output = [] |
| 57 | + for endpoint in NxList(endpoints_head, "struct rpmsg_endpoint", "node"): |
| 58 | + output.append( |
| 59 | + self.ENDPOINT_FORMATTER.format( |
| 60 | + f"{endpoint}", |
| 61 | + f"{endpoint['name'].string()}", |
| 62 | + f"{endpoint['addr']}", |
| 63 | + f"{endpoint['dest_addr']}", |
| 64 | + f"{endpoint['cb']}", |
| 65 | + f"{endpoint['ns_bound_cb']}", |
| 66 | + f"{endpoint['ns_unbind_cb']}", |
| 67 | + ) |
| 68 | + ) |
| 69 | + |
| 70 | + gdb.write("\n".join(output) + "\n") |
| 71 | + |
| 72 | + def dump_rdev_bitmap(self, rdev): |
| 73 | + bitmap_values = [hex(bit) for bit in utils.ArrayIterator(rdev["bitmap"])] |
| 74 | + |
| 75 | + gdb.write( |
| 76 | + f"bitmap:{' '.join(bitmap_values):<20} bitmaplast: {rdev['bitmap']}\n" |
| 77 | + ) |
| 78 | + |
| 79 | + def dump_rdev(self, rdev): |
| 80 | + gdb.write(f"device:{rdev}\n") |
| 81 | + |
| 82 | + self.dump_rdev_bitmap(rdev) |
| 83 | + self.dump_rdev_epts(rdev["endpoints"]) |
| 84 | + |
| 85 | + def dump_rpmsg_cb(self): |
| 86 | + gdb.write("g_rpmsg_cb:\n") |
| 87 | + self.print_headers(self.CALLBACK_HEADER, self.CALLBACK_FORAMTTER) |
| 88 | + |
| 89 | + output = [] |
| 90 | + for cb in NxList(gdb.parse_and_eval("g_rpmsg_cb"), "struct rpmsg_cb_s", "node"): |
| 91 | + output.append( |
| 92 | + self.CALLBACK_FORAMTTER.format( |
| 93 | + str(cb), str(cb["ns_match"]), str(cb["ns_bind"]) |
| 94 | + ) |
| 95 | + ) |
| 96 | + gdb.write("\n".join(output) + "\n") |
| 97 | + |
| 98 | + def dump_rpmsg(self): |
| 99 | + gdb.write("g_rpmsg:\n") |
| 100 | + for rpmsg in NxList(gdb.parse_and_eval("g_rpmsg"), "struct rpmsg_s", "node"): |
| 101 | + self.dump_rdev(rpmsg["rdev"]) |
| 102 | + |
| 103 | + def invoke(self, args, from_tty): |
| 104 | + self.dump_rpmsg_cb() |
| 105 | + self.dump_rpmsg() |
0 commit comments