Search memory for the given pattern.
| 166 | |
| 167 | |
| 168 | class FindAnywhere(gdb.Command): |
| 169 | """Search memory for the given pattern.""" |
| 170 | MAPPING_RE = re.compile(r"^\s*\[\d+\]\s+0x([0-9A-Fa-f]+)->0x([0-9A-Fa-f]+)") |
| 171 | LIVE_MAPPING_RE = re.compile(r"^\s+0x([0-9A-Fa-f]+)\s+0x([0-9A-Fa-f]+)") |
| 172 | |
| 173 | def __init__(self): |
| 174 | super(FindAnywhere, self).__init__("find-anywhere", gdb.COMMAND_DATA) |
| 175 | |
| 176 | def find(self, startAddr, endAddr, value): |
| 177 | try: |
| 178 | result = gdb.execute("find 0x%s, 0x%s, %s" % (startAddr, endAddr, value), |
| 179 | to_string=True) |
| 180 | if result.find("not found") == -1: |
| 181 | print(result) |
| 182 | except: |
| 183 | pass |
| 184 | |
| 185 | def invoke(self, value, from_tty): |
| 186 | for l in gdb.execute("maint info sections", to_string=True).split('\n'): |
| 187 | m = FindAnywhere.MAPPING_RE.match(l) |
| 188 | if m is None: |
| 189 | continue |
| 190 | self.find(m.group(1), m.group(2), value) |
| 191 | for l in gdb.execute("info proc mappings", to_string=True).split('\n'): |
| 192 | m = FindAnywhere.LIVE_MAPPING_RE.match(l) |
| 193 | if m is None: |
| 194 | continue |
| 195 | self.find(m.group(1), m.group(2), value) |
| 196 | |
| 197 | |
| 198 | FindAnywhere() |
no test coverage detected