Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Gunosy.go#3 debug

Gunosy.go#3 debug

debugパッケージの資料になります。

y_matsuwitter

June 27, 2014
Tweet

More Decks by y_matsuwitter

Other Decks in Programming

Transcript

  1. ڞ௨࢓༷UZQF'JMF UZQF'JMF GVOD/FX'JMF SJP3FBEFS"U  'JMF FSSPS  GVOD0QFO OBNFTUSJOH

     'JMF FSSPS  GVOD G 'JMF $MPTF FSSPS GVOD G 'JMF %8"3'  EXBSG%BUB FSSPS  GVOD G 'JMF %ZO4USJOH UBH%ZO5BH  <>TUSJOH FSSPS  GVOD G 'JMF *NQPSUFE-JCSBSJFT  <>TUSJOH FSSPS  GVOD G 'JMF *NQPSUFE4ZNCPMT  <>*NQPSUFE4ZNCPM FSSPS  GVOD G 'JMF 4FDUJPO OBNFTUSJOH  4FDUJPO GVOD G 'JMF 4FDUJPO#Z5ZQF UZQ4FDUJPO5ZQF  4FDUJPO GVOD G 'JMF 4ZNCPMT  <>4ZNCPM FSSPS
  2. func parse(file string, f *elf.File) *gosym.Table { sec := f.Section(".gosymtab")

    symdat, err := sec.Data() defer f.Close() if err != nil { log.Fatalf("reading %s gosymtab: %v", file, err) } pclndat, err := f.Section(".gopclntab").Data() if err != nil { log.Fatalf("reading %s gopclntab: %v", file, err) } ! pcln := gosym.NewLineTable(pclndat, f.Section(".text").Addr) tab, err := gosym.NewTable(symdat, pcln) if err != nil { log.Fatalf("parsing %s gosymtab: %v", file, err) } ! return tab } &-'ܗ͔ࣜΒ(P ͷγϯϘϧΛ୳͢ -JOFUBCMF Λ୳͢ HPTZN5BCMF Λ༻ҙ͢Δ
  3. func main() { fn := os.Args[1] f, err := elf.Open(os.Args[1])

    if err != nil { log.Fatal(err) } table := parse(fn, f) ! //func_ := table.LookupFunc("os.Open") ! for _, f := range table.Funcs { fmt.Println(f.Name) for _, p := range f.Params { fmt.Println("\t" + p.Name) } } } -PPLVQ'VOD Λࢀߟʹͨ͠ } ಛఆͷ'VOD Λ୳͢
  4. ࣮ߦ݁Ռൈਮ UFYU NBJOQBSTF NBJOdBOPO NBJOG NBJOpMF NBJONBJO NBJOJOJU UZQFIBTI<>JOUFSGBDF\^ NBJOQ

    NBJOT NBJOI UZQFFR<>JOUFSGBDF\^ NBJOR NBJOQ NBJOT NBJOFR ࠓճ࡞੒ͨ͠ ؔ਺ ҎԼ͸(Pͷ ඪ४͕ฒͿ