MCPcopy Create free account
hub / github.com/google/pprof / TestPEFile

Function TestPEFile

internal/binutils/binutils_test.go:492–541  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

490}
491
492func TestPEFile(t *testing.T) {
493 // If this test fails, check the address for main function in testdata/exe_windows_64.exe
494 // using the command 'nm -n '. Update the hardcoded addresses below to match
495 // the addresses from the output.
496 skipUnlessWindowsAmd64(t)
497 for _, tc := range []struct {
498 desc string
499 start, limit, offset uint64
500 addr uint64
501 }{
502 {"fake mapping", 0, math.MaxUint64, 0, 0x140001594},
503 {"fixed load address", 0x140000000, 0x140002000, 0, 0x140001594},
504 {"simulated ASLR address", 0x150000000, 0x150002000, 0, 0x150001594},
505 } {
506 t.Run(tc.desc, func(t *testing.T) {
507 bu := &Binutils{}
508 f, err := bu.Open(filepath.Join("testdata", "exe_windows_64.exe"), tc.start, tc.limit, tc.offset, "")
509 if err != nil {
510 t.Fatalf("Open: unexpected error %v", err)
511 }
512 defer f.Close()
513 syms, err := f.Symbols(regexp.MustCompile("main"), 0)
514 if err != nil {
515 t.Fatalf("Symbols: unexpected error %v", err)
516 }
517
518 m := findSymbol(syms, "main")
519 if m == nil {
520 t.Fatalf("Symbols: did not find main")
521 }
522 addr, err := f.ObjAddr(tc.addr)
523 if err != nil {
524 t.Fatalf("ObjAddr(%x) failed: %v", tc.addr, err)
525 }
526 if addr != m.Start {
527 t.Errorf("ObjAddr(%x) got %x, want %x", tc.addr, addr, m.Start)
528 }
529 gotFrames, err := f.SourceLine(tc.addr)
530 if err != nil {
531 t.Fatalf("SourceLine: unexpected error %v", err)
532 }
533 wantFrames := []plugin.Frame{
534 {Func: "main", File: "hello.c", Line: 3, Column: 12, StartLine: 3},
535 }
536 if !reflect.DeepEqual(gotFrames, wantFrames) {
537 t.Fatalf("SourceLine for main: got %v; want %v\n", gotFrames, wantFrames)
538 }
539 })
540 }
541}
542
543func TestOpenMalformedELF(t *testing.T) {
544 // Test that opening a malformed ELF file will report an error containing

Callers

nothing calls this directly

Calls 7

OpenMethod · 0.95
skipUnlessWindowsAmd64Function · 0.85
findSymbolFunction · 0.85
CloseMethod · 0.65
SymbolsMethod · 0.65
ObjAddrMethod · 0.65
SourceLineMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…