File tree Expand file tree Collapse file tree 10 files changed +76
-23
lines changed Expand file tree Collapse file tree 10 files changed +76
-23
lines changed Original file line number Diff line number Diff line change @@ -1207,19 +1207,24 @@ This section only applies to the dbghelp backend (`CPPTRACE_GET_SYMBOLS_WITH_DBG
1207
1207
1208
1208
When loading a DLL at runtime with `LoadLibrary` after a stacktrace has already been generated,
1209
1209
symbols from that library may not be resolved correctly for subsequent stacktraces. To fix this,
1210
- call `cpptrace::experimental::load_symbols_for_file` with the same filename that was passed to
1211
- `LoadLibrary`.
1210
+ call `cpptrace::load_symbols_for_file` with the same path that was passed to `LoadLibrary`.
1212
1211
1213
1212
```cpp
1214
1213
HMODULE hModule = LoadLibrary("mydll.dll");
1215
1214
if (hModule) {
1216
- cpptrace::experimental:: load_symbols_for_file("mydll.dll");
1215
+ cpptrace::load_symbols_for_file("mydll.dll");
1217
1216
}
1218
1217
```
1219
1218
1220
1219
For backends other than dbghelp, ` load_symbols_for_file ` does nothing. For platforms other than
1221
1220
Windows, it is not declared.
1222
1221
1222
+ ``` cpp
1223
+ namespace cpptrace {
1224
+ void load_symbols_for_file(const std::string& filename);
1225
+ }
1226
+ ```
1227
+
1223
1228
# ABI Versioning
1224
1229
1225
1230
Since cpptrace vX, the library uses an inline ABI versioning namespace and all symbols part of the public interface are
Original file line number Diff line number Diff line change @@ -65,9 +65,9 @@ CPPTRACE_BEGIN_NAMESPACE
65
65
}
66
66
67
67
// dbghelp
68
- namespace experimental {
69
- CPPTRACE_EXPORT void load_symbols_for_file (const std::string& filename);
70
- }
68
+ # ifdef _MSC_VER
69
+ CPPTRACE_EXPORT void load_symbols_for_file (const std::string& filename);
70
+ # endif
71
71
CPPTRACE_END_NAMESPACE
72
72
73
73
#endif
Original file line number Diff line number Diff line change @@ -101,6 +101,7 @@ CPPTRACE_BEGIN_NAMESPACE
101
101
export using cpptrace::experimental::set_cache_mode;
102
102
export using cpptrace::experimental::set_dwarf_resolver_line_table_cache_size;
103
103
export using cpptrace::experimental::set_dwarf_resolver_disable_aranges;
104
- export using cpptrace::experimental::load_symbols_for_file;
105
104
}
105
+
106
+ export using cpptrace::load_symbols_for_file;
106
107
CPPTRACE_END_NAMESPACE
Original file line number Diff line number Diff line change @@ -154,17 +154,3 @@ namespace detail {
154
154
}
155
155
}
156
156
CPPTRACE_END_NAMESPACE
157
-
158
- /*
159
- Fallback definition for cpptrace::experimental::load_symbols_for_file. If
160
- CPPTRACE_GET_SYMBOLS_WITH_DBGHELP is defined, this function is defined in symbols_with_dbghelp.cpp.
161
- */
162
- #ifndef CPPTRACE_GET_SYMBOLS_WITH_DBGHELP
163
- CPPTRACE_BEGIN_NAMESPACE
164
- namespace experimental {
165
- void load_symbols_for_file (const std::string& filename) {
166
- (void )filename;
167
- }
168
- }
169
- CPPTRACE_END_NAMESPACE
170
- #endif
Original file line number Diff line number Diff line change @@ -451,7 +451,6 @@ namespace dbghelp {
451
451
CPPTRACE_END_NAMESPACE
452
452
453
453
CPPTRACE_BEGIN_NAMESPACE
454
- namespace experimental {
455
454
/*
456
455
When a module was loaded at runtime with LoadLibrary after SymInitialize was already called,
457
456
it is necessary to manually load the symbols from that module with SymLoadModuleEx.
@@ -508,7 +507,6 @@ namespace experimental {
508
507
);
509
508
}
510
509
}
511
- }
512
510
CPPTRACE_END_NAMESPACE
513
511
514
512
#endif
Original file line number Diff line number Diff line change @@ -89,4 +89,10 @@ CPPTRACE_BEGIN_NAMESPACE
89
89
void register_terminate_handler () {
90
90
std::set_terminate (terminate_handler);
91
91
}
92
+
93
+ #if defined(_MSC_VER) && !defined(CPPTRACE_GET_SYMBOLS_WITH_DBGHELP)
94
+ void load_symbols_for_file (const std::string&) {
95
+ // nop
96
+ }
97
+ #endif
92
98
CPPTRACE_END_NAMESPACE
Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.8 )
2
+
3
+ project (module_load_test VERSION 0.0.1 LANGUAGES CXX )
4
+
5
+ add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR} /../.. ${CMAKE_CURRENT_BINARY_DIR} /cpptrace )
6
+
7
+ set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON )
8
+
9
+ add_library (mydll SHARED mydll.cpp )
10
+ target_include_directories (mydll PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} )
11
+
12
+ add_executable (main main.cpp )
13
+ target_link_libraries (main PUBLIC cpptrace::cpptrace )
Original file line number Diff line number Diff line change
1
+ #include " cpptrace/basic.hpp"
2
+ #include " cpptrace/utils.hpp"
3
+ #include " mydll.hpp"
4
+
5
+ #include < windows.h>
6
+
7
+ #include < iostream>
8
+
9
+ #include < cpptrace/from_current.hpp>
10
+
11
+ int main () {
12
+ // generate a trace before LoadLibraryA to initialize dbghelp
13
+ cpptrace::generate_trace ().print ();
14
+
15
+ HMODULE lib = LoadLibraryA (" mydll.dll" );
16
+ if (!lib) {
17
+ std::cerr << " Failed to load DLL\n " ;
18
+ return 1 ;
19
+ }
20
+
21
+ auto foo = reinterpret_cast <decltype (::foo)*>(GetProcAddress (lib, " foo" ));
22
+ if (!foo) {
23
+ std::cerr << " Failed to get symbol\n " ;
24
+ return 1 ;
25
+ }
26
+
27
+ cpptrace::load_symbols_for_file (" mydll.dll" );
28
+
29
+ CPPTRACE_TRY {
30
+ foo ();
31
+ } CPPTRACE_CATCH (...) {
32
+ cpptrace::from_current_exception ().print ();
33
+ }
34
+
35
+ FreeLibrary (lib);
36
+ }
Original file line number Diff line number Diff line change
1
+ #include " mydll.hpp"
2
+
3
+ void foo () {
4
+ throw 0 ;
5
+ }
Original file line number Diff line number Diff line change
1
+ #pragma once
2
+
3
+ extern " C" void foo ();
You can’t perform that action at this time.
0 commit comments