Overview
Thedebug package contains several sub-packages that provide access to program debug information in various binary formats. These packages allow you to read and parse debug data from executables.
Sub-packages
debug/buildinfo
Provides access to information embedded in a Go binary about how it was built.Types
Type alias for runtime/debug.BuildInfo containing build information.
Functions
Returns build information embedded in a Go binary file at the given path.
Returns build information embedded in a Go binary file accessed through the given ReaderAt.
debug/dwarf
Provides access to DWARF debugging information loaded from executable files.Types
Represents the DWARF debugging information loaded from an executable file.
Represents a single entry in the DWARF debug information.
Identifies the kind of entry.Common tags:
TagArrayTypeTagClassTypeTagEntryPointTagEnumerationTypeTagFormalParameterTagMemberTagPointerTypeTagStructureTypeTagSubprogramTagTypedefTagVariable
Represents a type in the DWARF type information.
Methods on Data
Returns a new Reader for Data. The reader is positioned at byte offset 0 in the DWARF info section.
Returns the Type at the given offset in the DWARF type information.
debug/elf
Implements access to ELF object files.Types
Represents an open ELF file.
Represents a single section in an ELF file.
Functions
Opens the named file using os.Open and prepares it for use as an ELF binary.
Creates a new File for accessing an ELF binary in an underlying reader.
Methods on File
Closes the File.
Returns the DWARF debug information for the ELF file.
Returns a section with the given name, or nil if no such section exists.
debug/gosym
Provides access to the Go symbol and line number tables embedded in Go binaries generated by the gc compilers.Types
Represents a Go symbol table.
Represents a single symbol table entry.
debug/macho
Implements access to Mach-O object files (macOS binaries).Types
Represents an open Mach-O file.
Functions
Opens the named file using os.Open and prepares it for use as a Mach-O binary.
Creates a new File for accessing a Mach-O binary in an underlying reader.
debug/pe
Implements access to PE (Microsoft Windows Portable Executable) files.Types
Represents an open PE file.
Functions
Opens the named file using os.Open and prepares it for use as a PE binary.
Creates a new File for accessing a PE binary in an underlying reader.
debug/plan9obj
Implements access to Plan 9 a.out object files.Types
Represents an open Plan 9 a.out file.
Functions
Opens the named file using os.Open and prepares it for use as a Plan 9 a.out binary.
Examples
Reading Build Info
Reading ELF File
Reading DWARF Information
Reading PE File (Windows)
Use Cases
- Binary Analysis: Inspect compiled binaries to understand their structure
- Debugging Tools: Build custom debugging and profiling tools
- Build Information: Extract version and dependency information from binaries
- Symbol Resolution: Map addresses to function names and source locations
- Cross-platform Analysis: Analyze binaries from different platforms