Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 1 | // Copyright (c) FIRST and other WPILib contributors. |
| 2 | // Open Source Software; you can modify and/or share it under the terms of |
| 3 | // the WPILib BSD license file in the root directory of this project. |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 4 | |
| 5 | #include "wpi/StackTrace.h" |
| 6 | |
| 7 | #include "StackWalker.h" |
| 8 | #include "wpi/ConvertUTF.h" |
| 9 | #include "wpi/SmallString.h" |
| 10 | |
| 11 | namespace { |
| 12 | class StackTraceWalker : public StackWalker { |
| 13 | public: |
| 14 | explicit StackTraceWalker(std::string& output) : m_output(output) {} |
| 15 | |
| 16 | void OnOutput(LPCTSTR szText) override; |
| 17 | |
| 18 | private: |
| 19 | std::string& m_output; |
| 20 | }; |
| 21 | } // namespace |
| 22 | |
| 23 | void StackTraceWalker::OnOutput(LPCTSTR szText) { |
| 24 | #ifdef _UNICODE |
| 25 | wpi::SmallString<128> utf8; |
| 26 | wpi::sys::windows::UTF16ToUTF8(szText, wcslen(szText), utf8); |
| 27 | m_output.append(utf8.data(), utf8.size()); |
| 28 | #else |
| 29 | m_output.append(szText); |
| 30 | #endif |
| 31 | } |
| 32 | |
| 33 | namespace wpi { |
| 34 | |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame^] | 35 | std::string GetStackTraceDefault(int offset) { |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 36 | // TODO: implement offset |
| 37 | std::string output; |
| 38 | StackTraceWalker walker(output); |
| 39 | return output; |
| 40 | } |
| 41 | |
| 42 | } // namespace wpi |