(t *testing.T)
| 329 | } |
| 330 | |
| 331 | func TestObjFile(t *testing.T) { |
| 332 | // If this test fails, check the address for main function in testdata/exe_linux_64 |
| 333 | // using the command 'nm -n '. Update the hardcoded addresses below to match |
| 334 | // the addresses from the output. |
| 335 | skipUnlessLinuxAmd64(t) |
| 336 | for _, tc := range []struct { |
| 337 | desc string |
| 338 | start, limit, offset uint64 |
| 339 | addr uint64 |
| 340 | }{ |
| 341 | {"fixed load address", 0x400000, 0x4006fc, 0, 0x40052d}, |
| 342 | // True user-mode ASLR binaries are ET_DYN rather than ET_EXEC so this case |
| 343 | // is a bit artificial except that it approximates the |
| 344 | // vmlinux-with-kernel-ASLR case where the binary *is* ET_EXEC. |
| 345 | {"simulated ASLR address", 0x500000, 0x5006fc, 0, 0x50052d}, |
| 346 | } { |
| 347 | t.Run(tc.desc, func(t *testing.T) { |
| 348 | bu := &Binutils{} |
| 349 | f, err := bu.Open(filepath.Join("testdata", "exe_linux_64"), tc.start, tc.limit, tc.offset, "") |
| 350 | if err != nil { |
| 351 | t.Fatalf("Open: unexpected error %v", err) |
| 352 | } |
| 353 | defer f.Close() |
| 354 | syms, err := f.Symbols(regexp.MustCompile("main"), 0) |
| 355 | if err != nil { |
| 356 | t.Fatalf("Symbols: unexpected error %v", err) |
| 357 | } |
| 358 | |
| 359 | m := findSymbol(syms, "main") |
| 360 | if m == nil { |
| 361 | t.Fatalf("Symbols: did not find main") |
| 362 | } |
| 363 | addr, err := f.ObjAddr(tc.addr) |
| 364 | if err != nil { |
| 365 | t.Fatalf("ObjAddr(%x) failed: %v", tc.addr, err) |
| 366 | } |
| 367 | if addr != m.Start { |
| 368 | t.Errorf("ObjAddr(%x) got %x, want %x", tc.addr, addr, m.Start) |
| 369 | } |
| 370 | gotFrames, err := f.SourceLine(tc.addr) |
| 371 | if err != nil { |
| 372 | t.Fatalf("SourceLine: unexpected error %v", err) |
| 373 | } |
| 374 | wantFrames := []plugin.Frame{ |
| 375 | {Func: "main", File: "/tmp/hello.c", Line: 3, StartLine: 3}, |
| 376 | } |
| 377 | if !reflect.DeepEqual(gotFrames, wantFrames) { |
| 378 | t.Fatalf("SourceLine for main: got %v; want %v\n", gotFrames, wantFrames) |
| 379 | } |
| 380 | }) |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | func TestMachoFiles(t *testing.T) { |
| 385 | // If this test fails, check the address for main function in testdata/exe_mac_64 |
nothing calls this directly
no test coverage detected
searching dependent graphs…