On Tue, Feb 26, 2019 at 11:34 PM Ian Lance Taylor <i...@golang.org> wrote:
>
> On Tue, Feb 26, 2019 at 6:08 PM Gargi Sharma <gs051...@gmail.com> wrote:
> >
> > I meant the Section and SectionByType calls.
>
> Those calls do different things.  They do more than just get the
> symbol table.  They aren't equivalent.
>
>
> > [ 6] .gosymtab         PROGBITS         00000000004d7758  000d7758
> >        0000000000000000  0000000000000000   A       0     0     1
> > [22] .symtab           SYMTAB           0000000000000000  002aa000
> >        0000000000012c30  0000000000000018          23   116     8
> >
> > From readelf, I see that the binary has both symtab and gosymtab. Is
> > gosymtab a superset of information of the .symtab? If yes, why do we
> > need the .symtab?
>
> I explained .gosymtab in my last message.  It is not a superset of
> .symtab.  It is different.
>
> In any case we need .symtab because that is what ELF tools expect.
Got it, I was really confused why we needed two different symbol tables.

I am trying to get the program counter if I know the line number. For
go binaries, I did this:

func getPCFromLine(line int, binary string) {
    symbolTableSection := executable.Section(".gosymtab")
    symbolTableData, _ := symbolTableSection.Data()

    lineTableForText := gosym.NewLineTable(pcToLineData,
    executable.Section(".text").Addr)

    newSymbolTable, _ := gosym.NewTable(symbolTableData, lineTableForText)

    pc, fn, _ := newSymbolTable.LineToPC(binary, line)
}

The above function was where I was trying to use
executable.Section(".symtab") and got this error:
panic: bad symbol type '0' at byte 0x4

I am assuming if I want to do something similar for non-go binaries, I
will have to look inside .symtab to get this information.

Thanks!

gargi

>
> > My code panics when I try to read the actual .symtab (doing a
> > section.data() for Section(.symtab)), which I don't understand as
> > well.
>
> Why not use the Symbols method?

>
> Perhaps we can help you if you show us a small self-contained example.
>
> Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to