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 24 #include "pw_cpu_exception/state.h" 25 #include "pw_span/span.h" 26 27 namespace pw::cpu_exception { 28 29 // Gets raw CPU state as a single contiguous block of data. The particular 30 // contents will depend on the specific backend and platform. 31 span<const uint8_t> RawFaultingCpuState( 32 const pw_cpu_exception_State& cpu_state); 33 34 // Writes CPU state as a formatted string to a string builder. 35 // NEVER depend on the format of this output. This is exclusively FYI human 36 // readable output. 37 void ToString(const pw_cpu_exception_State& cpu_state, const span<char>& dest); 38 39 // Logs captured CPU state using pw_log at PW_LOG_LEVEL_INFO. 40 void LogCpuState(const pw_cpu_exception_State& cpu_state); 41 42 } // namespace pw::cpu_exception 43