xiaoxiang781216 commented on code in PR #15536: URL: https://github.com/apache/nuttx/pull/15536#discussion_r1914589636
########## tools/gdb/nuttxgdb/kasan.py: ########## @@ -0,0 +1,145 @@ +############################################################################ +# tools/gdb/nuttxgdb/kasan.py +# +# SPDX-License-Identifier: Apache-2.0 +# +# 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 itertools + +import gdb + +from . import utils + + +class KASanGeneric: + def __init__(self, begin, end, shadow, bitwidth, scale, shift=0): + self.begin = begin + self.end = end + self.shadow = shadow + self.bitwidth = bitwidth + self.scale = scale + self.shift = shift + + def check_addr(self, addr): + distance = (addr - self.begin) / self.scale + index = distance / self.bitwidth + bit = distance % self.bitwidth + return True if self.shadow[index] >> bit & 0x01 else False + + def is_member(self, addr): + if self.begin <= self.untag_addr(addr) <= self.end: + return True + return False + + def get_tag(self, addr): + return addr >> self.shift + + def untag_addr(self, addr): + return addr + + +class KASanSwtags(KASanGeneric): + def check_addr(self, addr): + tag = self.get_tag(addr) + untag_addr = self.untag_addr(addr) + distance = untag_addr - self.begin + index = distance / self.scale + return False if self.shadow[index] == tag else True + + def untag_addr(self, addr): + mask = ~(0xFF << self.shift) + return addr & mask + + +class KASan(gdb.Command): + + def __init__(self): + super().__init__("kasandebug", gdb.COMMAND_USER) Review Comment: ```suggestion super().__init__("kasan", gdb.COMMAND_USER) ``` -- 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: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org