Skip to content

Instantly share code, notes, and snippets.

@Creased
Created March 25, 2021 08:09
Show Gist options
  • Save Creased/a7911eabf60dbdaa6b8096ca591c1b8d to your computer and use it in GitHub Desktop.
Save Creased/a7911eabf60dbdaa6b8096ca591c1b8d to your computer and use it in GitHub Desktop.
Create symbol file from kallsyms

Generate symbol file:

python kernel_syms.py
as -o kernal_syms.o kernel_syms.s

Load the symbols into gdb:

# in gdb
symbol-file kernel_syms.o
#!/usr/bin/env python3
import re
infos = dict()
with open('kallsyms', 'rt') as syms_fd, open('kernel_syms.s', 'wt') as out_fd:
out_fd.write('.text\n')
syms = syms_fd.read()
for line in syms.split('\n'):
info = re.search(r'^(?P<addr>[0-9a-fA-F]+) . (?P<sym>\w+)', line)
if info:
addr, sym = info.groups()
addr = int(addr, 16)
if sym not in infos:
infos[sym] = addr
infos = dict(sorted(infos.items(), key=lambda item: item[1]))
for sym, addr in infos.items():
out_fd.write(f'\t.org 0x{addr:x}\n{sym}:\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment