| 143 | } |
| 144 | |
| 145 | int StackTracePrintPrivateData::bfdInitCtx(std::ostream& crashStream, struct BfdCtx* bfdCtx, const char * procName) |
| 146 | { |
| 147 | bfdCtx->handle = nullptr; |
| 148 | bfdCtx->symbol = nullptr; |
| 149 | |
| 150 | bfd* bfdHandle = bfd_openr(procName, 0); |
| 151 | if(bfdHandle == nullptr) |
| 152 | { |
| 153 | crashStream << "Failed to open bfd from " << procName << std::endl; |
| 154 | return 1; |
| 155 | } |
| 156 | |
| 157 | int r1 = bfd_check_format(bfdHandle, bfd_object); |
| 158 | int r2 = bfd_check_format_matches(bfdHandle, bfd_object, nullptr); |
| 159 | int r3 = bfd_get_file_flags(bfdHandle) & HAS_SYMS; |
| 160 | |
| 161 | if (!(r1 && r2 && r3)) |
| 162 | { |
| 163 | bfd_close(bfdHandle); |
| 164 | crashStream << "Failed to init bfd from " << procName << std::endl; |
| 165 | return 1; |
| 166 | } |
| 167 | |
| 168 | void* symbolTable = nullptr; |
| 169 | |
| 170 | unsigned dummy = 0; |
| 171 | if (bfd_read_minisymbols(bfdHandle, FALSE, &symbolTable, &dummy) == 0) |
| 172 | { |
| 173 | if (bfd_read_minisymbols(bfdHandle, TRUE, &symbolTable, &dummy) < 0) |
| 174 | { |
| 175 | free(symbolTable); |
| 176 | bfd_close(bfdHandle); |
| 177 | crashStream << "Failed to read symbols from " << procName << std::endl; |
| 178 | return 1; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | bfdCtx->handle = bfdHandle; |
| 183 | bfdCtx->symbol = static_cast<asymbol **>(symbolTable); |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | void StackTracePrintPrivateData::bfdCloseCtx(struct BfdCtx* bfdCtx) |
| 189 | { |