Reference: http://www.dwarfstd.org/
core.internal.backtrace.dwarf
Generates a human-readable stack-trace on POSIX targets using DWARF
The common use case for printing a stack trace is when toString is called on a Throwable (see object.d). It will iterate on what is likely to be the default trace handler (see core.runtime : defaultTraceHandler). The class returned by defaultTraceHandler is what ends up calling into this module, through the use of core.internal.traits : externDFunc.
The entry point of this module is traceHandlerOpApplyImpl, and the only really "public" symbol (since all rt symbols are private). In the future, this implementation should probably be made idiomatic, so that it can for example work with attributes.
Resilience: As this module is used for diagnostic, it should handle failures as gracefully as possible. Having the runtime error out on printing the stack trace one is trying to debug would be quite a terrible UX. For this reason, this module works on a "best effort" basis and will sometimes print mangled symbols, or "???" when it cannot do anything more useful.
Source_of_data: This module uses two main sources for generating human-readable data. First, it uses backtrace_symbols to obtain the name of the symbols (functions or methods) associated with the addresses. Since the names are mangled, it will also call into core.demangle, and doesn't need to use any DWARF information for this, however a future extension could make use of the call frame information (See DWARF4 "6.4 Call Frame Information", PDF page 126).
The other piece of data used is the DWARF .debug_line section, which contains the line informations of a program, necessary to associate the instruction address with its (file, line) information.
Since debug lines informations are quite large, they are encoded using a program that is to be fed to a finite state machine. See runStateMachine and readLineNumberProgram for more details.
DWARF_
Version
Copyright
License
Types 12
const(void) * addressAddress of the instruction for which this location is for.const(char)[] procedureThe name of the procedure, or function, this address is in.const(char)[] filePath to the file this location references, relative to `directory`const(char)[] directoryDirectory where `file` residesint lineLine within the file that correspond to this `location`.void toString(scope void delegate(scope const char[]) sink) constFormat this location into a human-readable stringA callback type for runStateMachine
The callback is called when certain specific opcode are encountered (a.k.a when a complete LocationInfo is encountered). See runStateMachine implementation and the DWARF specs for more detail.
Parameters
address | The address that the LocationInfo describes |
info | The LocationInfo itself, describing address |
isEndSequence | Whether the end of a sequence has been reached |
const(void) * addressuint operationIndexuint fileIndexuint lineuint columnuint isauint discriminatorbool isStatementbool isBasicBlockbool isEndSequencebool isPrologueEndbool isEpilogueBeginint fileint lineulong unitLengthushort dwarfVersionubyte addressSizeubyte segmentSelectorSizeulong headerLengthubyte minimumInstructionLengthubyte maximumOperationsPerInstructionbool defaultIsStatementbyte lineBaseubyte lineRangeubyte opcodeBaseconst(ubyte)[] standardOpcodeLengthsArray!(const(char)[]) includeDirectoriesArray!SourceFile sourceFilesconst(ubyte)[] programconst(char)[] filesize_t dirIndexFunctions 10
int traceHandlerOpApplyImpl(size_t numFrames,
scope const(void) * delegate(size_t) getNthAddress,
scope const(char)[] delegate(size_t) getNthFuncName,
scope int delegate(ref size_t, ref const(char[])) dg)int processCallstack(Location[] locations, const(ubyte)[] debugLineSectionData,
size_t baseAddress, scope int delegate(ref size_t, ref const(char[])) dg)void resolveAddresses(const(ubyte)[] debugLineSectionData, Location[] locations, size_t baseAddress) @nogc nothrowResolve the addresses of `locations` using `debugLineSectionData`bool runStateMachine(ref const(LineNumberProgram) lp, scope RunStateMachineCallback callback) @nogc nothrowRun the state machine to generate line number matrixArray!EntryFormatPair readEntryFormat(ref const(ubyte)[] buffer) @nogc nothrowReads a DWARF v5 directory/file name entry format.