-
Notifications
You must be signed in to change notification settings - Fork 495
Expand file tree
/
Copy pathgo_binary_parse_profiling.cc
More file actions
78 lines (67 loc) · 3.1 KB
/
go_binary_parse_profiling.cc
File metadata and controls
78 lines (67 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Copyright 2018- The Pixie Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "src/common/base/base.h"
#include "src/common/base/env.h"
#include "src/stirling/source_connectors/socket_tracer/uprobe_symaddrs.h"
using px::StatusOr;
using px::stirling::GoOffsetLocator;
using px::stirling::PopulateGoTLSDebugSymbols;
using px::stirling::obj_tools::DwarfReader;
using px::stirling::obj_tools::ElfReader;
using px::stirling::obj_tools::ReadGoBuildInfo;
//-----------------------------------------------------------------------------
// This utility is designed to isolate parsing the debug symbols of a Go binary. This
// verifies that the go version detection code is functioning as well. This is useful
// for debugging when the Go elf/DWARF parsing is not working correctly and has been the
// source of a few PEM crashes (gh#1300, gh#1646). This makes it easy for asking end users to run
// against their binaries when they are sensitive (proprietary) and we can't debug them ourselves.
//-----------------------------------------------------------------------------
int main(int argc, char** argv) {
px::EnvironmentGuard env_guard(&argc, argv);
if (argc < 2) {
LOG(FATAL) << absl::Substitute("Expected binary argument to be provided. Instead received $0",
*argv);
}
std::string binary(argv[1]);
StatusOr<std::unique_ptr<ElfReader>> elf_reader_status = ElfReader::Create(binary);
if (!elf_reader_status.ok()) {
LOG(WARNING) << absl::Substitute(
"Failed to parse elf binary $0 with"
"Message = $1",
binary, elf_reader_status.msg());
}
std::unique_ptr<ElfReader> elf_reader = elf_reader_status.ConsumeValueOrDie();
StatusOr<std::unique_ptr<DwarfReader>> dwarf_reader_status =
DwarfReader::CreateIndexingAll(binary);
if (!dwarf_reader_status.ok()) {
VLOG(1) << absl::Substitute(
"Failed to get binary $0 debug symbols. "
"Message = $1",
binary, dwarf_reader_status.msg());
}
std::unique_ptr<DwarfReader> dwarf_reader = dwarf_reader_status.ConsumeValueOrDie();
auto build_info_s = ReadGoBuildInfo(elf_reader.get());
const auto& [go_version, build_info] = build_info_s.ConsumeValueOrDie();
std::unique_ptr<GoOffsetLocator> go_offset_locator =
std::make_unique<GoOffsetLocator>(dwarf_reader.get(), build_info, go_version);
struct go_tls_symaddrs_t symaddrs;
auto status = PopulateGoTLSDebugSymbols(go_offset_locator.get(), &symaddrs);
if (!status.ok()) {
LOG(ERROR) << absl::Substitute("debug symbol parsing failed with: $0", status.msg());
}
}