xiaoxiang781216 commented on code in PR #9859: URL: https://github.com/apache/nuttx/pull/9859#discussion_r1270186010
########## tools/gdb/thread.py: ########## @@ -0,0 +1,270 @@ +############################################################################ +# tools/gdb/thread.py +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you 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. +# +############################################################################ + +import gdb + +UINT16_MAX = 0xFFFF + +g_tcbinfo = gdb.parse_and_eval("g_tcbinfo") +saved_regs = None + + +def save_regs(): + global saved_regs + + if saved_regs is not None: + return + arch = gdb.selected_frame().architecture() + saved_regs = [] + i = 0 + for reg in arch.registers(): + if i >= g_tcbinfo["basic_num"]: + break + + saved_regs.append(gdb.parse_and_eval("$%s" % reg.name)) + i += 1 + + +def restore_regs(): + global saved_regs + + if saved_regs is None: + return + + arch = gdb.selected_frame().architecture() + i = 0 + for reg in arch.registers(): + if i >= g_tcbinfo["basic_num"]: + break + + gdb.execute("set $%s=%d" % (reg.name, int(saved_regs[i]))) + i += 1 + + saved_regs = None + + +class Nxsetregs(gdb.Command): + """ + Set registers to the specified values. + Usage: nxsetregs [regs] + + Etc: nxsetregs + nxsetregs g_current_regs[0] + nxsetregs tcb->xcp.regs + Nxsetregs g_pidhash[0].tcb->xcp.regs + + Default regs is g_current_regs[0],if regs is NULL, it will not set registers. + + """ + + def __init__(self): + super(Nxsetregs, self).__init__("nxsetregs", gdb.COMMAND_USER) + + def invoke(self, args, from_tty): + current_regs = gdb.parse_and_eval("g_current_regs") + arg = args.split(" ") + + if arg[0] != "": + regs = gdb.parse_and_eval("%s" % arg[0]).cast( + gdb.lookup_type("char").pointer() + ) + else: + if current_regs[0] == 0: + return + + regs = current_regs[0].cast(gdb.lookup_type("char").pointer()) + + if regs == 0: + gdb.write("regs is NULL\n") + return + + save_regs() + arch = gdb.selected_frame().architecture() + i = 0 + for reg in arch.registers(): + if i >= g_tcbinfo["basic_num"]: + return + + if g_tcbinfo["reg_off"]["p"][i] != UINT16_MAX: + value = gdb.Value(regs + g_tcbinfo["reg_off"]["p"][i]).cast( + gdb.lookup_type("uintptr_t").pointer() + )[0] + gdb.execute("set $%s = 0x%x" % (reg.name, value)) + + i += 1 + + +def get_pc_value(tcb): + arch = gdb.selected_frame().architecture() + i = 0 + for reg in arch.registers(): + if reg.name == "pc" or reg.name == "rip" or reg.name == "eip": + break + i += 1 + + regs = tcb["xcp"]["regs"].cast(gdb.lookup_type("char").pointer()) + value = gdb.Value(regs + g_tcbinfo["reg_off"]["p"][i]).cast( + gdb.lookup_type("uintptr_t").pointer() + )[0] + + return int(value) + + +class Nxinfothreads(gdb.Command): + def __init__(self): + super(Nxinfothreads, self).__init__("info threads", gdb.COMMAND_USER) + + def invoke(self, args, from_tty): + g_npidhash = gdb.parse_and_eval("g_npidhash") + g_pidhash = gdb.parse_and_eval("g_pidhash") + g_statenames = gdb.parse_and_eval("g_statenames") + print("%-4s %-21s %-80s %-30s" % ("Id", "Thread", "Info", "Frame")) + for i in range(0, g_npidhash): + if g_pidhash[i] == 0: + continue + + if g_pidhash[i]["task_state"] == 3: + gdb.write("*") + pc = int(gdb.parse_and_eval("$pc")) + else: + gdb.write(" ") + pc = get_pc_value(g_pidhash[i]) + + id = "%s" % i Review Comment: remove ########## tools/gdb/thread.py: ########## @@ -0,0 +1,270 @@ +############################################################################ +# tools/gdb/thread.py +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you 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. +# +############################################################################ + +import gdb + +UINT16_MAX = 0xFFFF + +g_tcbinfo = gdb.parse_and_eval("g_tcbinfo") +saved_regs = None + + +def save_regs(): + global saved_regs + + if saved_regs is not None: + return + arch = gdb.selected_frame().architecture() + saved_regs = [] + i = 0 + for reg in arch.registers(): + if i >= g_tcbinfo["basic_num"]: + break + + saved_regs.append(gdb.parse_and_eval("$%s" % reg.name)) + i += 1 + + +def restore_regs(): + global saved_regs + + if saved_regs is None: + return + + arch = gdb.selected_frame().architecture() + i = 0 + for reg in arch.registers(): + if i >= g_tcbinfo["basic_num"]: + break + + gdb.execute("set $%s=%d" % (reg.name, int(saved_regs[i]))) + i += 1 + + saved_regs = None + + +class Nxsetregs(gdb.Command): + """ + Set registers to the specified values. + Usage: nxsetregs [regs] + + Etc: nxsetregs + nxsetregs g_current_regs[0] + nxsetregs tcb->xcp.regs + Nxsetregs g_pidhash[0].tcb->xcp.regs + + Default regs is g_current_regs[0],if regs is NULL, it will not set registers. + + """ + + def __init__(self): + super(Nxsetregs, self).__init__("nxsetregs", gdb.COMMAND_USER) + + def invoke(self, args, from_tty): + current_regs = gdb.parse_and_eval("g_current_regs") + arg = args.split(" ") + + if arg[0] != "": + regs = gdb.parse_and_eval("%s" % arg[0]).cast( + gdb.lookup_type("char").pointer() + ) + else: + if current_regs[0] == 0: + return + + regs = current_regs[0].cast(gdb.lookup_type("char").pointer()) + + if regs == 0: + gdb.write("regs is NULL\n") + return + + save_regs() + arch = gdb.selected_frame().architecture() + i = 0 + for reg in arch.registers(): + if i >= g_tcbinfo["basic_num"]: + return + + if g_tcbinfo["reg_off"]["p"][i] != UINT16_MAX: + value = gdb.Value(regs + g_tcbinfo["reg_off"]["p"][i]).cast( + gdb.lookup_type("uintptr_t").pointer() + )[0] + gdb.execute("set $%s = 0x%x" % (reg.name, value)) + + i += 1 + + +def get_pc_value(tcb): + arch = gdb.selected_frame().architecture() + i = 0 + for reg in arch.registers(): + if reg.name == "pc" or reg.name == "rip" or reg.name == "eip": + break + i += 1 + + regs = tcb["xcp"]["regs"].cast(gdb.lookup_type("char").pointer()) + value = gdb.Value(regs + g_tcbinfo["reg_off"]["p"][i]).cast( + gdb.lookup_type("uintptr_t").pointer() + )[0] + + return int(value) + + +class Nxinfothreads(gdb.Command): + def __init__(self): + super(Nxinfothreads, self).__init__("info threads", gdb.COMMAND_USER) + + def invoke(self, args, from_tty): + g_npidhash = gdb.parse_and_eval("g_npidhash") + g_pidhash = gdb.parse_and_eval("g_pidhash") + g_statenames = gdb.parse_and_eval("g_statenames") + print("%-4s %-21s %-80s %-30s" % ("Id", "Thread", "Info", "Frame")) + for i in range(0, g_npidhash): + if g_pidhash[i] == 0: + continue + + if g_pidhash[i]["task_state"] == 3: + gdb.write("*") + pc = int(gdb.parse_and_eval("$pc")) + else: + gdb.write(" ") Review Comment: id = "%s" % i ########## tools/gdb/thread.py: ########## @@ -0,0 +1,270 @@ +############################################################################ +# tools/gdb/thread.py +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you 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. +# +############################################################################ + +import gdb + +UINT16_MAX = 0xFFFF + +g_tcbinfo = gdb.parse_and_eval("g_tcbinfo") +saved_regs = None + + +def save_regs(): + global saved_regs + + if saved_regs is not None: + return + arch = gdb.selected_frame().architecture() + saved_regs = [] + i = 0 + for reg in arch.registers(): + if i >= g_tcbinfo["basic_num"]: + break + + saved_regs.append(gdb.parse_and_eval("$%s" % reg.name)) + i += 1 + + +def restore_regs(): + global saved_regs + + if saved_regs is None: + return + + arch = gdb.selected_frame().architecture() + i = 0 + for reg in arch.registers(): + if i >= g_tcbinfo["basic_num"]: + break + + gdb.execute("set $%s=%d" % (reg.name, int(saved_regs[i]))) + i += 1 + + saved_regs = None + + +class Nxsetregs(gdb.Command): + """ + Set registers to the specified values. + Usage: nxsetregs [regs] + + Etc: nxsetregs + nxsetregs g_current_regs[0] + nxsetregs tcb->xcp.regs + Nxsetregs g_pidhash[0].tcb->xcp.regs + + Default regs is g_current_regs[0],if regs is NULL, it will not set registers. + + """ + + def __init__(self): + super(Nxsetregs, self).__init__("nxsetregs", gdb.COMMAND_USER) + + def invoke(self, args, from_tty): + current_regs = gdb.parse_and_eval("g_current_regs") + arg = args.split(" ") + + if arg[0] != "": + regs = gdb.parse_and_eval("%s" % arg[0]).cast( + gdb.lookup_type("char").pointer() + ) + else: + if current_regs[0] == 0: + return + + regs = current_regs[0].cast(gdb.lookup_type("char").pointer()) + + if regs == 0: + gdb.write("regs is NULL\n") + return + + save_regs() + arch = gdb.selected_frame().architecture() + i = 0 + for reg in arch.registers(): + if i >= g_tcbinfo["basic_num"]: + return + + if g_tcbinfo["reg_off"]["p"][i] != UINT16_MAX: + value = gdb.Value(regs + g_tcbinfo["reg_off"]["p"][i]).cast( + gdb.lookup_type("uintptr_t").pointer() + )[0] + gdb.execute("set $%s = 0x%x" % (reg.name, value)) + + i += 1 + + +def get_pc_value(tcb): + arch = gdb.selected_frame().architecture() + i = 0 + for reg in arch.registers(): + if reg.name == "pc" or reg.name == "rip" or reg.name == "eip": + break + i += 1 + + regs = tcb["xcp"]["regs"].cast(gdb.lookup_type("char").pointer()) + value = gdb.Value(regs + g_tcbinfo["reg_off"]["p"][i]).cast( + gdb.lookup_type("uintptr_t").pointer() + )[0] + + return int(value) + + +class Nxinfothreads(gdb.Command): + def __init__(self): + super(Nxinfothreads, self).__init__("info threads", gdb.COMMAND_USER) + + def invoke(self, args, from_tty): + g_npidhash = gdb.parse_and_eval("g_npidhash") + g_pidhash = gdb.parse_and_eval("g_pidhash") + g_statenames = gdb.parse_and_eval("g_statenames") + print("%-4s %-21s %-80s %-30s" % ("Id", "Thread", "Info", "Frame")) + for i in range(0, g_npidhash): + if g_pidhash[i] == 0: + continue + + if g_pidhash[i]["task_state"] == 3: + gdb.write("*") Review Comment: id = "*%s" % i -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
