1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_symbolizer: 2*61c4878aSAndroid Build Coastguard Worker 3*61c4878aSAndroid Build Coastguard Worker============= 4*61c4878aSAndroid Build Coastguard Workerpw_symbolizer 5*61c4878aSAndroid Build Coastguard Worker============= 6*61c4878aSAndroid Build Coastguard Worker 7*61c4878aSAndroid Build Coastguard Worker.. warning:: 8*61c4878aSAndroid Build Coastguard Worker This module is under construction and may not be ready for use. 9*61c4878aSAndroid Build Coastguard Worker 10*61c4878aSAndroid Build Coastguard Workerpw_symbolizer provides python-based tooling for symbolizing addresses emitted by 11*61c4878aSAndroid Build Coastguard Workeron-device firmware. 12*61c4878aSAndroid Build Coastguard Worker 13*61c4878aSAndroid Build Coastguard Worker----- 14*61c4878aSAndroid Build Coastguard WorkerUsage 15*61c4878aSAndroid Build Coastguard Worker----- 16*61c4878aSAndroid Build Coastguard WorkerSymbolizer 17*61c4878aSAndroid Build Coastguard Worker========== 18*61c4878aSAndroid Build Coastguard WorkerThe ``Symbolizer`` abstract base class is an interface for translating addresses 19*61c4878aSAndroid Build Coastguard Workerto human-readable source locations. Different architectures and operating 20*61c4878aSAndroid Build Coastguard Workersystems can require vastly different implementations, so this interface is 21*61c4878aSAndroid Build Coastguard Workerprovided to allow Pigweed tooling to symbolize addresses without requiring 22*61c4878aSAndroid Build Coastguard WorkerPigweed to provide explicit support for all possible implementations. 23*61c4878aSAndroid Build Coastguard Worker 24*61c4878aSAndroid Build Coastguard Worker``Symbolizer`` Also provides a helper function for producing nicely formatted 25*61c4878aSAndroid Build Coastguard Workerstack trace style dumps. 26*61c4878aSAndroid Build Coastguard Worker 27*61c4878aSAndroid Build Coastguard Worker.. code-block:: py 28*61c4878aSAndroid Build Coastguard Worker 29*61c4878aSAndroid Build Coastguard Worker import pw_symbolizer 30*61c4878aSAndroid Build Coastguard Worker 31*61c4878aSAndroid Build Coastguard Worker symbolizer = pw_symbolizer.LlvmSymbolizer(Path('device_fw.elf')) 32*61c4878aSAndroid Build Coastguard Worker print(symbolizer.dump_stack_trace(backtrace_addresses)) 33*61c4878aSAndroid Build Coastguard Worker 34*61c4878aSAndroid Build Coastguard WorkerWhich produces output like this: 35*61c4878aSAndroid Build Coastguard Worker 36*61c4878aSAndroid Build Coastguard Worker.. code-block:: none 37*61c4878aSAndroid Build Coastguard Worker 38*61c4878aSAndroid Build Coastguard Worker Stack Trace (most recent call first): 39*61c4878aSAndroid Build Coastguard Worker 1: at device::system::logging_thread_context (0x08004BE0) 40*61c4878aSAndroid Build Coastguard Worker in threads.cc:0 41*61c4878aSAndroid Build Coastguard Worker 2: at device::system::logging_thread (0x0800B508) 42*61c4878aSAndroid Build Coastguard Worker in ??:? 43*61c4878aSAndroid Build Coastguard Worker 3: at device::system::logging_thread_context (0x08004CB8) 44*61c4878aSAndroid Build Coastguard Worker in threads.cc:0 45*61c4878aSAndroid Build Coastguard Worker 4: at device::system::logging_thread (0x0800B3C0) 46*61c4878aSAndroid Build Coastguard Worker in ??:? 47*61c4878aSAndroid Build Coastguard Worker 5: at device::system::logging_thread (0x0800B508) 48*61c4878aSAndroid Build Coastguard Worker in ??:? 49*61c4878aSAndroid Build Coastguard Worker 6: at (0x0800BAF7) 50*61c4878aSAndroid Build Coastguard Worker in ??:? 51*61c4878aSAndroid Build Coastguard Worker 7: at common::log::LoggingThread::Run() (0x0800BAD1) 52*61c4878aSAndroid Build Coastguard Worker in out/common/log/logging_thread.cc:26 53*61c4878aSAndroid Build Coastguard Worker 8: at pw::thread::threadx::Context::ThreadEntryPoint(unsigned long) (0x0800539D) 54*61c4878aSAndroid Build Coastguard Worker in out/pigweed/pw_thread_threadx/thread.cc:41 55*61c4878aSAndroid Build Coastguard Worker 9: at device::system::logging_thread_context (0x08004CB8) 56*61c4878aSAndroid Build Coastguard Worker in threads.cc:0 57*61c4878aSAndroid Build Coastguard Worker 10: at device::system::logging_thread_context (0x08004BE0) 58*61c4878aSAndroid Build Coastguard Worker in threads.cc:0 59*61c4878aSAndroid Build Coastguard Worker 60*61c4878aSAndroid Build Coastguard WorkerFakeSymbolizer 61*61c4878aSAndroid Build Coastguard Worker============== 62*61c4878aSAndroid Build Coastguard WorkerThe ``FakeSymbolizer`` is utility class that implements the ``Symbolizer`` 63*61c4878aSAndroid Build Coastguard Workerinterface with a fixed database of address to ``Symbol`` mappings. This is 64*61c4878aSAndroid Build Coastguard Workeruseful for testing, or as a no-op ``Symbolizer``. 65*61c4878aSAndroid Build Coastguard Worker 66*61c4878aSAndroid Build Coastguard Worker.. code-block:: py 67*61c4878aSAndroid Build Coastguard Worker 68*61c4878aSAndroid Build Coastguard Worker import pw_symbolizer 69*61c4878aSAndroid Build Coastguard Worker 70*61c4878aSAndroid Build Coastguard Worker known_symbols = ( 71*61c4878aSAndroid Build Coastguard Worker pw_symbolizer.Symbol(0x0800A200, 'foo()', 'src/foo.c', 41), 72*61c4878aSAndroid Build Coastguard Worker pw_symbolizer.Symbol(0x08000004, 'boot_entry()', 'src/vector_table.c', 5), 73*61c4878aSAndroid Build Coastguard Worker ) 74*61c4878aSAndroid Build Coastguard Worker symbolizer = pw_symbolizer.FakeSymbolizer(known_symbols) 75*61c4878aSAndroid Build Coastguard Worker sym = symbolizer.symbolize(0x0800A200) 76*61c4878aSAndroid Build Coastguard Worker print(f'This fake symbolizer knows about: {sym}') 77*61c4878aSAndroid Build Coastguard Worker 78*61c4878aSAndroid Build Coastguard WorkerLlvmSymbolizer 79*61c4878aSAndroid Build Coastguard Worker============== 80*61c4878aSAndroid Build Coastguard WorkerThe ``LlvmSymbolizer`` is a python layer that wraps ``llvm-symbolizer`` to 81*61c4878aSAndroid Build Coastguard Workerproduce symbols from provided addresses. This module requires either: 82*61c4878aSAndroid Build Coastguard Worker 83*61c4878aSAndroid Build Coastguard Worker* ``llvm-symbolizer`` is available on the system ``PATH``. 84*61c4878aSAndroid Build Coastguard Worker* ``llvm_symbolizer_binary`` argument is specified and points to the executable. 85*61c4878aSAndroid Build Coastguard Worker 86*61c4878aSAndroid Build Coastguard WorkerThis object also defines a ``close`` to ensure the background process is 87*61c4878aSAndroid Build Coastguard Workercleaned up deterministically. 88*61c4878aSAndroid Build Coastguard Worker 89*61c4878aSAndroid Build Coastguard Worker.. code-block:: py 90*61c4878aSAndroid Build Coastguard Worker 91*61c4878aSAndroid Build Coastguard Worker import pw_symbolizer 92*61c4878aSAndroid Build Coastguard Worker 93*61c4878aSAndroid Build Coastguard Worker symbolizer = pw_symbolizer.LlvmSymbolizer(Path('device_fw.elf')) 94*61c4878aSAndroid Build Coastguard Worker sym = symbolizer.symbolize(0x2000ac21) 95*61c4878aSAndroid Build Coastguard Worker print(f'You have a bug here: {sym}') 96