-
Notifications
You must be signed in to change notification settings - Fork 8
/
dump_symbols.py
64 lines (58 loc) · 2.1 KB
/
dump_symbols.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# SPDX-License-Identifier: MIT
#
# Copyright 2024 Cisco Systems, Inc. and its affiliates
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.
import lldb
import json
symbols = {}
"""
(lldb) image lookup -a 0xffffff801172277f
Address: kernel[0xffffff800031277f] (kernel.__TEXT.__text + 989055)
Summary: kernel`vm_fault_deactivate_behind + 15 at vm_fault.c:501
"""
def parseLookup(lookup):
summary = lookup.split("\n")[1].strip()
print(summary)
name = summary.split(" ")[1].split("`")[1].split("(")[0]
print(name)
return name
def parseDump(dump,debugger):
result1 = lldb.SBCommandReturnObject()
ci = debugger.GetCommandInterpreter()
for line in dump.split("\n"):
if line.startswith("["):
parts = line.split()
if parts[0] == '[':
parts.pop(0)
if parts[3] == "Invalid":
continue
if len(parts) < 9:
continue
file_addr = parts[4]
load_addr = parts[5]
size = parts[6]
print(parts)
name = parts[8].split("(")[0]
if "___lldb_unnamed_symbol" in name:
ci.HandleCommand("image lookup -a " + load_addr,result1)
name = None
if result1.Succeeded():
name = parseLookup(result1.GetOutput())
if name == None:
continue
print("%s @ %s"%(name,load_addr))
symbols[load_addr] = name
def dumpSymbols(debugger, command, result, dict):
result1 = lldb.SBCommandReturnObject()
ci = debugger.GetCommandInterpreter()
ci.HandleCommand(command,result1)
if result1.Succeeded():
parseDump(result1.GetOutput(),debugger)
f = open("symbol-store.json","w")
json.dump(symbols,f)
f.close()
def __lldb_init_module (debugger, dict):
debugger.HandleCommand('command script add -f dump_symbols.dumpSymbols dumpSymbols')