14#include "arcane/utils/String.h"
15#include "arcane/utils/IStackTraceService.h"
16#include "arcane/utils/ISymbolizerService.h"
17#include "arcane/utils/NotImplementedException.h"
18#include "arcane/utils/StringBuilder.h"
20#include "arccore/base/internal/DependencyInjection.h"
22#include "arcane/core/AbstractService.h"
59 _getStack(first_function, frames);
64 return _getStackSymbols(frames);
74 ::SymSetOptions(SYMOPT_DEFERRED_LOADS | SYMOPT_INCLUDE_32BIT_MODULES | SYMOPT_UNDNAME | SYMOPT_LOAD_LINES);
75 if (!::SymInitialize(::GetCurrentProcess(),
nullptr,
true)) {
86 bool m_is_init =
false;
87 bool m_is_good =
false;
93void DbgHelpSymContainer::
97 PVOID addrs[FixedStackFrameArray::MAX_FRAME] = { 0 };
98 USHORT nb_frame = CaptureStackBackTrace(first_function + 2, FixedStackFrameArray::MAX_FRAME, addrs, NULL);
99 for (USHORT i = 0; i < nb_frame; i++) {
100 frames.
addFrame(StackFrame((intptr_t)addrs[i]));
107String DbgHelpSymContainer::
114 int nb_frame = frames.size();
115 for (USHORT i = 0; i < nb_frame; i++) {
116 DWORD64 addr = (DWORD64)frames[i].address();
120 ULONG64 buffer[(
sizeof(SYMBOL_INFO) + 1024 +
sizeof(ULONG64) - 1) /
sizeof(ULONG64)] = { 0 };
121 SYMBOL_INFO* info = (SYMBOL_INFO*)buffer;
122 info->SizeOfStruct =
sizeof(SYMBOL_INFO);
123 info->MaxNameLen = 1024;
126 DWORD64 displacement = 0;
127 if (::SymFromAddr(::GetCurrentProcess(), addr, &displacement, info)) {
130 DWORD line_displacement = 0;
131 IMAGEHLP_LINE64 line = {};
132 line.SizeOfStruct =
sizeof(IMAGEHLP_LINE64);
133 BOOL has_line = SymGetLineFromAddr64(GetCurrentProcess(), addr, &line_displacement, &line);
134 sb.append(std::string_view(info->Name, info->NameLen));
138 sb.append(line.FileName);
140 sb.append(String::fromNumber(line.LineNumber));
145 return sb.toString();
153 std::shared_ptr<DbgHelpSymContainer> m_sym_container;
154 std::shared_ptr<DbgHelpSymContainer> _getStaticContainer()
156 if (!m_sym_container.get())
157 m_sym_container = std::make_shared<DbgHelpSymContainer>();
158 return m_sym_container;
171class DbgHelpStackTraceService
181 explicit DbgHelpStackTraceService(
ITraceMng* tm)
197 std::shared_ptr<DbgHelpSymContainer> m_sym_container;
200 if (!m_sym_container.get())
201 m_sym_container = _getStaticContainer();
202 return m_sym_container.get();
214 String text = c->getStackSymbols(frames.view());
236class DbgHelpSymbolizerService
245 explicit DbgHelpSymbolizerService(
ITraceMng* tm)
258 return _getContainer()->getStackSymbols(frames);
263 std::shared_ptr<DbgHelpSymContainer> m_sym_container;
266 if (!m_sym_container.get())
267 m_sym_container = _getStaticContainer();
268 return m_sym_container.get();
284 DependencyInjection::ProviderProperty(
"DbgHelpStackTraceService"),
289 DependencyInjection::ProviderProperty(
"DbgHelpSymbolizerService"),
This file contains the various service factories and macros for registering services.
#define ARCANE_SERVICE_INTERFACE(ainterface)
Macro to declare an interface when registering a service.
Constant view of an array of type T.
Function call tracing service using 'DbgHelp'.
StackTrace stackTrace(int first_function) override
Character string indicating the call stack.
StackTrace stackTraceFunction(int function_index) override
Name of a function in the call stack.
Function call tracing service using libunwind.
String stackTrace(ConstArrayView< StackFrame > frames) override
Information for the call stack frames.
Stores a fixed maximum size list of StackFrame.
void addFrame(const StackFrame &frame)
Adds a frame to the list of frames. If nbFrame() is greater than or equal to MAX_FRAME,...
virtual ITraceMng * traceMng() const =0
Trace manager.
Interface of a function call tracing service.
Interface of a source code symbol retrieval service.
IApplication * application() const
Access to the associated IApplication.
Structure containing the information to create a service.
Service creation properties.
Information about function call stacks.
Unicode character string.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
#define ARCANE_REGISTER_SERVICE(aclass, a_service_property,...)
Macro for registering a service.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
@ ST_Application
The service is used at the application level.