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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
base / third_party / symbolize / patches / 005-expose-file-helpers.patch [blame]
diff --git a/base/third_party/symbolize/symbolize.cc b/base/third_party/symbolize/symbolize.cc
index e2f99a647bf88..3c72fd1183f48 100644
--- a/base/third_party/symbolize/symbolize.cc
+++ b/base/third_party/symbolize/symbolize.cc
@@ -141,12 +141,16 @@ _END_GOOGLE_NAMESPACE_
_START_GOOGLE_NAMESPACE_
-// Read up to "count" bytes from "offset" in the file pointed by file
-// descriptor "fd" into the buffer starting at "buf" while handling short reads
-// and EINTR. On success, return the number of bytes read. Otherwise, return
-// -1.
-static ssize_t ReadFromOffset(const int fd, void *buf, const size_t count,
- const size_t offset) {
+FileDescriptor::~FileDescriptor() {
+ if (fd_ >= 0) {
+ close(fd_);
+ }
+}
+
+ssize_t ReadFromOffset(const int fd,
+ void* buf,
+ const size_t count,
+ const size_t offset) {
SAFE_ASSERT(fd >= 0);
SAFE_ASSERT(count <= static_cast<size_t>(std::numeric_limits<ssize_t>::max()));
char *buf0 = reinterpret_cast<char *>(buf);
@@ -371,22 +375,6 @@ static bool GetSymbolFromObjectFile(const int fd,
}
namespace {
-// Thin wrapper around a file descriptor so that the file descriptor
-// gets closed for sure.
-struct FileDescriptor {
- const int fd_;
- explicit FileDescriptor(int fd) : fd_(fd) {}
- ~FileDescriptor() {
- if (fd_ >= 0) {
- close(fd_);
- }
- }
- int get() { return fd_; }
-
- private:
- FileDescriptor(const FileDescriptor &);
- void operator=(const FileDescriptor&);
-};
// Helper class for reading lines from file.
//
@@ -503,20 +491,11 @@ static char *GetHex(const char *start, const char *end, uint64_t *hex) {
return const_cast<char *>(p);
}
-// Searches for the object file (from /proc/self/maps) that contains
-// the specified pc. If found, sets |start_address| to the start address
-// of where this object file is mapped in memory, sets the module base
-// address into |base_address|, copies the object file name into
-// |out_file_name|, and attempts to open the object file. If the object
-// file is opened successfully, returns the file descriptor. Otherwise,
-// returns -1. |out_file_name_size| is the size of the file name buffer
-// (including the null-terminator).
-static ATTRIBUTE_NOINLINE int
-OpenObjectFileContainingPcAndGetStartAddress(uint64_t pc,
- uint64_t &start_address,
- uint64_t &base_address,
- char *out_file_name,
- size_t out_file_name_size) {
+int OpenObjectFileContainingPcAndGetStartAddress(uint64_t pc,
+ uint64_t& start_address,
+ uint64_t& base_address,
+ char* out_file_name,
+ size_t out_file_name_size) {
int object_fd;
int maps_fd;
diff --git a/base/third_party/symbolize/symbolize.h b/base/third_party/symbolize/symbolize.h
index 5959e579ffc93..11b24fbd06f5c 100644
--- a/base/third_party/symbolize/symbolize.h
+++ b/base/third_party/symbolize/symbolize.h
@@ -94,17 +94,54 @@
_START_GOOGLE_NAMESPACE_
+// Read up to "count" bytes from "offset" in the file pointed by file
+// descriptor "fd" into the buffer starting at "buf" while handling short reads
+// and EINTR. On success, return the number of bytes read. Otherwise, return
+// -1.
+ssize_t ReadFromOffset(const int fd,
+ void* buf,
+ const size_t count,
+ const size_t offset);
+
// Gets the section header for the given name, if it exists. Returns true on
// success. Otherwise, returns false.
bool GetSectionHeaderByName(int fd, const char *name, size_t name_len,
ElfW(Shdr) *out);
+// Searches for the object file (from /proc/self/maps) that contains
+// the specified pc. If found, sets |start_address| to the start address
+// of where this object file is mapped in memory, sets the module base
+// address into |base_address|, copies the object file name into
+// |out_file_name|, and attempts to open the object file. If the object
+// file is opened successfully, returns the file descriptor. Otherwise,
+// returns -1. |out_file_name_size| is the size of the file name buffer
+// (including the null-terminator).
+ATTRIBUTE_NOINLINE int OpenObjectFileContainingPcAndGetStartAddress(
+ uint64_t pc,
+ uint64_t& start_address,
+ uint64_t& base_address,
+ char* out_file_name,
+ size_t out_file_name_size);
+
_END_GOOGLE_NAMESPACE_
#endif /* __ELF__ */
_START_GOOGLE_NAMESPACE_
+// Thin wrapper around a file descriptor so that the file descriptor
+// gets closed for sure.
+struct FileDescriptor {
+ const int fd_;
+ explicit FileDescriptor(int fd) : fd_(fd) {}
+ ~FileDescriptor();
+ int get() { return fd_; }
+
+ private:
+ FileDescriptor(const FileDescriptor &);
+ void operator=(const FileDescriptor&);
+};
+
// Restrictions on the callbacks that follow:
// - The callbacks must not use heaps but only use stacks.
// - The callbacks must be async-signal-safe.