blob: de31b2a256ea214f15a11113d04eb5de8546fd09 [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
James Kuszmaulcf324122023-01-14 14:07:17 -080011#if defined(_MSC_VER)
12
Brian Silverman8fce7482020-01-05 13:18:21 -080013namespace {
14class StackTraceWalker : public StackWalker {
15 public:
16 explicit StackTraceWalker(std::string& output) : m_output(output) {}
17
18 void OnOutput(LPCTSTR szText) override;
19
20 private:
21 std::string& m_output;
22};
23} // namespace
24
25void StackTraceWalker::OnOutput(LPCTSTR szText) {
26#ifdef _UNICODE
27 wpi::SmallString<128> utf8;
28 wpi::sys::windows::UTF16ToUTF8(szText, wcslen(szText), utf8);
29 m_output.append(utf8.data(), utf8.size());
30#else
31 m_output.append(szText);
32#endif
33}
34
35namespace wpi {
36
Austin Schuh75263e32022-02-22 18:05:32 -080037std::string GetStackTraceDefault(int offset) {
Brian Silverman8fce7482020-01-05 13:18:21 -080038 // TODO: implement offset
39 std::string output;
40 StackTraceWalker walker(output);
41 return output;
42}
43
44} // namespace wpi
James Kuszmaulcf324122023-01-14 14:07:17 -080045
46#endif // defined(_MSC_VER)