James Kuszmaul | 4f3ad3c | 2019-12-01 16:35:21 -0800 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */ |
| 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #include "wpi/StackTrace.h" |
| 9 | |
| 10 | #include "StackWalker.h" |
| 11 | #include "wpi/ConvertUTF.h" |
| 12 | #include "wpi/SmallString.h" |
| 13 | |
| 14 | namespace { |
| 15 | class StackTraceWalker : public StackWalker { |
| 16 | public: |
| 17 | explicit StackTraceWalker(std::string& output) : m_output(output) {} |
| 18 | |
| 19 | void OnOutput(LPCTSTR szText) override; |
| 20 | |
| 21 | private: |
| 22 | std::string& m_output; |
| 23 | }; |
| 24 | } // namespace |
| 25 | |
| 26 | void StackTraceWalker::OnOutput(LPCTSTR szText) { |
| 27 | #ifdef _UNICODE |
| 28 | wpi::SmallString<128> utf8; |
| 29 | wpi::sys::windows::UTF16ToUTF8(szText, wcslen(szText), utf8); |
| 30 | m_output.append(utf8.data(), utf8.size()); |
| 31 | #else |
| 32 | m_output.append(szText); |
| 33 | #endif |
| 34 | } |
| 35 | |
| 36 | namespace wpi { |
| 37 | |
| 38 | std::string GetStackTrace(int offset) { |
| 39 | // TODO: implement offset |
| 40 | std::string output; |
| 41 | StackTraceWalker walker(output); |
| 42 | return output; |
| 43 | } |
| 44 | |
| 45 | } // namespace wpi |