1 // Copyright 2020 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // 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, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 15 // This facade provides an API for capturing the contents of a 16 // pw_cpu_exception_State struct in a platform-agnostic way. While this facade 17 // does not provide a means to directly access individual members of a 18 // pw_cpu_exception_State object, it does allow dumping CPU state without 19 // needing to know any specifics about the underlying architecture. 20 #pragma once 21 22 #include <cstdint> 23 #include <span> 24 25 // Forward declaration of pw_cpu_exception_State. Definition provided by 26 // backend. 27 struct pw_cpu_exception_State; 28 29 namespace pw::cpu_exception { 30 31 // Gets raw CPU state as a single contiguous block of data. The particular 32 // contents will depend on the specific backend and platform. 33 std::span<const uint8_t> RawFaultingCpuState( 34 const pw_cpu_exception_State& cpu_state); 35 36 // Writes CPU state as a formatted string to a string builder. 37 // NEVER depend on the format of this output. This is exclusively FYI human 38 // readable output. 39 void ToString(const pw_cpu_exception_State& cpu_state, 40 const std::span<char>& dest); 41 42 // Logs captured CPU state using pw_log at PW_LOG_LEVEL_INFO. 43 void LogCpuState(const pw_cpu_exception_State& cpu_state); 44 45 } // namespace pw::cpu_exception 46