blob: bab5f835112374cad6fda625e317d53d54384c84 [file] [log] [blame]
Austin Schuh812d0d12021-11-04 20:16:48 -07001// 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 Silverman8fce7482020-01-05 13:18:21 -08004
5#include "wpi/StackTrace.h"
6
7#include "StackWalker.h"
8#include "wpi/ConvertUTF.h"
9#include "wpi/SmallString.h"
10
11namespace {
12class 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
23void 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
33namespace wpi {
34
Austin Schuh75263e32022-02-22 18:05:32 -080035std::string GetStackTraceDefault(int offset) {
Brian Silverman8fce7482020-01-05 13:18:21 -080036 // TODO: implement offset
37 std::string output;
38 StackTraceWalker walker(output);
39 return output;
40}
41
42} // namespace wpi