
Implement debugging function for 386 on linux with reference to AMD64. There are a few remaining problems that need to be solved in another time. 1. The stacktrace of cgo are not exactly as expected. 2. Not implement `core` for now. 3. Not implement `call` for now. Can't not find `runtime·debugCallV1` or similar function in $GOROOT/src/runtime/asm_386.s. Update #20
41 lines
841 B
Go
41 lines
841 B
Go
package linutil
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/binary"
|
|
)
|
|
|
|
const (
|
|
_AT_NULL = 0
|
|
_AT_ENTRY = 9
|
|
)
|
|
|
|
// EntryPointFromAuxv searches the elf auxiliary vector for the entry point
|
|
// address.
|
|
// For a description of the auxiliary vector (auxv) format see:
|
|
// System V Application Binary Interface, AMD64 Architecture Processor
|
|
// Supplement, section 3.4.3.
|
|
// System V Application Binary Interface, Intel386 Architecture Processor
|
|
// Supplement (fourth edition), section 3-28.
|
|
func EntryPointFromAuxv(auxv []byte, ptrSize int) uint64 {
|
|
rd := bytes.NewBuffer(auxv)
|
|
|
|
for {
|
|
tag, err := readUintRaw(rd, binary.LittleEndian, ptrSize)
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
val, err := readUintRaw(rd, binary.LittleEndian, ptrSize)
|
|
if err != nil {
|
|
return 0
|
|
}
|
|
|
|
switch tag {
|
|
case _AT_NULL:
|
|
return 0
|
|
case _AT_ENTRY:
|
|
return val
|
|
}
|
|
}
|
|
}
|