2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Helge Norberg, helge.norberg@svt.se
22 #include "../../stdafx.h"
24 #include "../stack_trace.h"
25 #include "../../utf.h"
27 #include "../../compiler/vs/StackWalker.h"
29 #include <boost/algorithm/string/replace.hpp>
33 #include <tbb/enumerable_thread_specific.h>
34 #include <boost/algorithm/string/find.hpp>
38 std::wstring get_call_stack()
40 class log_call_stack_walker : public StackWalker
42 std::string str_ = "\n";
44 log_call_stack_walker()
51 auto result = std::move(str_);
58 virtual void OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUserName) override
61 virtual void OnLoadModule(LPCSTR img, LPCSTR mod, DWORD64 baseAddr, DWORD size, DWORD result, LPCSTR symType, LPCSTR pdbName, ULONGLONG fileVersion) override
64 virtual void OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr) override
67 virtual void OnOutput(LPCSTR szText) override
69 std::string str = szText;
71 auto include_path = boost::find_first(str, "\\include\\");
75 str.erase(str.begin(), include_path.end());
78 boost::ireplace_all(str, get_source_prefix(), "");
80 if (str.find("caspar::get_call_stack") == std::string::npos &&
81 str.find("StackWalker::ShowCallstack") == std::string::npos)
83 str_ += " " + std::move(str);
88 static tbb::enumerable_thread_specific<log_call_stack_walker> walkers;
91 auto& walker = walkers.local();
92 walker.ShowCallstack();
93 return u16(walker.flush());
97 return L"Bug in stacktrace code!!!";
101 const std::string& get_source_prefix()
103 static const std::string SOURCE_PREFIX = []
105 std::string result = CASPAR_SOURCE_PREFIX;
107 boost::replace_all(result, "/", "\\");
113 return SOURCE_PREFIX;