esp-idf/tools/esp_app_trace/pylibelf/util/__init__.py
Alexey Gerenkov 55f1a63faf esp32: Adds functionality for application tracing over JTAG
- Implements application tracing module which allows to send arbitrary
   data to host over JTAG. This feature is useful for analyzing
   program modules behavior, dumping run-time application data etc.
 - Implements printf-like logging functions on top of apptrace module.
   This feature is a kind of semihosted printf functionality with lower
   overhead and impact on system behaviour as compared to standard printf.
2017-04-17 23:26:29 +03:00

39 lines
1.0 KiB
Python

from .. import *
from ..types import *
from ..constants import *
from ctypes import *
import os
def _class(elf): return ord(elf_getident(elf, None).contents[EI_CLASS])
def is32(elf): return _class(elf) == ELFCLASS32
def is64(elf): return _class(elf) == ELFCLASS64
def select(elf, fname):
if is32(elf):
return globals()['elf32_' + fname]
else:
return globals()['elf64_' + fname]
def section_name(elfP, secP):
shstrndx = c_size_t()
r = elf_getshstrndx(elfP, byref(shstrndx))
shdr = select(elfP, 'getshdr')(secP)
return elf_strptr(elfP, shstrndx, shdr.contents.sh_name)
def section_type(elfP, secP):
return select(elfP, 'getshdr')(secP).contents.sh_type
def section_link(elfP, secP):
return select(elfP, 'getshdr')(secP).contents.sh_link
def section_hdr(elfP, secP):
return select(elfP, 'getshdr')(secP).contents
def open_elf(fname):
fd = os.open(fname, os.O_RDONLY)
return elf_begin(fd, ELF_C_READ, None)
def sym_name(elf, scn, sym):
return elf_strptr(elf, section_link(elf, scn), sym.st_name)