1 // Copyright 2019 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef SANDBOXED_API_SANDBOX2_UNWIND_UNWIND_H_ 16 #define SANDBOXED_API_SANDBOX2_UNWIND_UNWIND_H_ 17 18 #include <sys/types.h> 19 20 #include <cstdint> 21 #include <map> 22 #include <string> 23 #include <vector> 24 25 #include "absl/status/statusor.h" 26 #include "sandboxed_api/sandbox2/comms.h" 27 28 namespace sandbox2 { 29 30 // Used to map from an address to a human-readable symbol. 31 using SymbolMap = std::map<uint64_t, std::string>; 32 33 // Returns the symbol at `addr`, possibly with an offset into said symbol. 34 std::string GetSymbolAt(const SymbolMap& addr_to_symbol, uint64_t addr); 35 36 // Loads and returns a symbol map for a process with the provided `pid`. 37 absl::StatusOr<SymbolMap> LoadSymbolsMap(pid_t pid); 38 39 // Runs libunwind and the symbolizer and sends the results via comms. 40 bool RunLibUnwindAndSymbolizer(Comms* comms); 41 42 absl::StatusOr<std::vector<std::string>> RunLibUnwindAndSymbolizer( 43 pid_t pid, int max_frames); 44 45 } // namespace sandbox2 46 47 #endif // SANDBOXED_API_SANDBOX2_UNWIND_UNWIND_H_ 48