module.go raw

   1  package wasm
   2  
   3  import "debug/dwarf"
   4  
   5  // A Module represents a parsed WASM module.
   6  type Module struct {
   7  	// Sections contains the sections in the parsed file, in the order they
   8  	// appear in the file. A valid  but empty file will have zero sections.
   9  	//
  10  	// The items in the slice will be a mix of the SectionXXX types.
  11  	Sections []Section
  12  }
  13  
  14  // DWARF returns the DWARF debug information for this WebAssembly module.
  15  func (m *Module) DWARF() (*dwarf.Data, error) {
  16  	var abbrev, aranges, frame, info, line, pubnames, ranges, str []byte
  17  	for _, section := range m.Sections {
  18  		if section, ok := section.(*SectionCustom); ok {
  19  			switch section.SectionName {
  20  			case ".debug_abbrev":
  21  				abbrev = section.Payload
  22  			case ".debug_aranges":
  23  				aranges = section.Payload
  24  			case ".debug_frame":
  25  				frame = section.Payload
  26  			case ".debug_info":
  27  				info = section.Payload
  28  			case ".debug_line":
  29  				line = section.Payload
  30  			case ".debug_pubnames":
  31  				pubnames = section.Payload
  32  			case ".debug_ranges":
  33  				ranges = section.Payload
  34  			case ".debug_str":
  35  				str = section.Payload
  36  			}
  37  		}
  38  	}
  39  	return dwarf.New(abbrev, aranges, frame, info, line, pubnames, ranges, str)
  40  }
  41