Commit Graph
58 Commits
Author SHA1 Message Date
Clément Grégoire 8ccc76c66b Use CopyStringFast in FormatImageName 2025-10-24 13:10:23 +02:00
Clément Grégoire fe516e3596 IsKernelAddress helper 2025-10-24 13:10:23 +02:00
Clément Grégoire 2bdefc2aa3 Move drivers and modules caching to their own functions 2025-10-24 13:10:23 +02:00
Clément Grégoire 903cde50d9 Replace windows caches with ImageCache
- Introduce both s_imageCache and s_krnlCache on all platforms, even if unused (will be reused later to unify platforms handling)
- This means that what userland images that used to be unsorted are now sorted
2025-10-24 13:10:23 +02:00
Clément Grégoire e1e9fb680d Rename TRACY_USE_IMAGE_CACHE to TRACY_HAS_DL_ITERATE_PHDR_TO_REFRESH_IMAGE_CACHE
Windows is already using a cache, and the only platforms that won't have one for now are those without dl_iterate_phdr.
2025-10-24 13:10:23 +02:00
Clément Grégoire 3b5b32d307 Replace hardcoded string duplication by CopyStringFast
This can be CopyStringFast since we allocated the cache on the same thread.
2025-10-24 13:10:22 +02:00
Clément Grégoire 32f94a05cb Support adding new entries and keeping the image cache sorted
Image cache will remain potentially unsorted until first access or `Sort` is called explicitely.
2025-10-24 12:54:35 +02:00
Clément Grégoire 0b814a2532 Split ImageCache to seperate platform specific so that it can be used on other platforms 2025-10-24 12:50:27 +02:00
Clément Grégoire aa68c31780 Add path to ImageEntry in prevision of replacing KernelDriver use + add DestroyImageEntry for ImageEntry cleanup 2025-10-24 12:50:26 +02:00
Clément Grégoire 385f72f9dc Rename ImageCache::Contains to ContainsImage
The name was a bit misleading as it could be mistaken to mean "The cache contains the address" and not as "has an image with this start address". ie: that it could be mistaken to do GetImageForAddress( startAddress ) != nullptr.
2025-10-11 14:13:33 +02:00
Clément Grégoire 12026dae5b Make ImageEntry m_startAddress/m_endAddress uint64_t as it will later be used in server, and thus not pointing to current process memory 2025-10-11 14:10:18 +02:00
Clément Grégoire 9665f7ac42 Move ImageEntry to header in prevision of sharing it with other CPP files in the future 2025-10-11 13:52:03 +02:00
Bartosz Taudul 3bff910a27 Merge pull request #1121 from siliceum/feature/faster-module-caching-windows
Add faster module caching fallback by using GetModuleHandleExA
2025-08-01 20:44:19 +02:00
Gabriel Bon 1f6531f46d Add faster module caching fallback by using GetModuleHandleExA 2025-07-31 15:06:15 +02:00
Clément Grégoire 8c06fec09e Refactor libbacktrace usage with TRACY_USE_LIBBACKTRACE 2025-07-31 10:41:37 +02:00
Clément Grégoire 10c6e3dee1 Fix delay loading by not exporting variables
[`/DELAYLOAD`](https://learn.microsoft.com/en-us/cpp/build/reference/delayload-delay-load-import?view=msvc-170) only works with exported functions, not variables (as it patches thunks after the first load).
So instead of using exporting a pointer for `___tracy_RtlWalkFrameChain`, make it a function that will call said pointer. This only adds a `mov`+`jmp` instructions in optimized builds to the call, which is negligible compared to the actual cost of RtlWalkFrameChain. This also does not affect the reported callstack since it will use a `jmp` without touching the stack, so `___tracy_RtlWalkFrameChain` won't appear in the capture stacktrace.
2025-05-12 11:56:38 +02:00
Bartosz Taudul be40c1e38e Use strlen instead of pointer walking in the rest of places. 2024-06-16 18:20:16 +02:00
Bartosz Taudul 1ff73edd20 Add linux kernel symbol code retrieval. 2024-05-26 20:49:43 +02:00
Bartosz Taudul 82aecbdb31 Calculate size of kernel code sections. 2024-05-25 17:18:41 +02:00
Bartosz Taudul 64aad9e751 Load all kernel symbols, mark non-code sections with null name. 2024-05-25 17:18:41 +02:00
Bartosz Taudul d5064aa8ea Try to prevent reallocs when building kernel symbols table.
% wc -l /proc/kallsyms
419362 /proc/kallsyms
2024-05-25 17:18:41 +02:00
Bartosz Taudul c45683506c Merge pull request #783 from tiago-rodrigues/trodrigues/image_cache_deadlock_fix
Instead of calling dladdr inside the dl_iterate_phdr callback, do it outside to avoid deadlocks with other loader code
2024-05-04 11:33:54 +02:00
trodrigues 4bf9a8cecc Instead of calling dladdr inside the dl_iterate_phdr callback, do it outside to avoid deadlocks with other loader code 2024-05-03 16:05:59 -05:00
Elliot a26f076a0e fix build warnings when compiling with clang-cl 2024-03-11 14:44:44 -04:00
Bartosz Taudul 4226f7888e Manually allocate and free s_di_known.
Otherwise destructor will be called when main() returns while symbol
retrieval may still want to actively use the vector.
2024-02-26 23:03:37 +01:00
Bartosz Taudul e9911ab127 Fix includes. 2023-12-20 13:16:51 +01:00
Bartosz Taudul c39b7af4b3 Proper spelling of dbghelp. 2023-12-20 13:14:06 +01:00
Bartosz Taudul cc3cbfe6f2 No need for indirection of ImageEntry vector. 2023-12-12 19:27:53 +01:00
Bartosz Taudul 5decb91cd0 Don't clear image cache on refresh. 2023-12-12 19:23:27 +01:00
Bartosz Taudul 7fc7935359 Cosmetics. 2023-12-12 19:09:41 +01:00
Bartosz Taudul 073e04e967 Remove redundant include. 2023-12-12 19:04:43 +01:00
trodrigues ab1ec3f01c make sure we always copy the image name in ImageCache 2023-12-09 19:12:53 -06:00
trodrigues 15f1b6b0b4 make a copy of dli_fname after calling dladdr. Call ImageCache destructor. 2023-12-09 09:40:07 -06:00
trodrigues 55f53b9979 remove option to enable image cache, use it for TRACY_HAS_CALLSTACK == 3 to obtain image path and addreses instead of dladdr() 2023-12-05 20:01:12 -06:00
trodrigues a618b6e6f8 simplify return from tracy::FastVector iterator 2023-12-03 08:36:54 -06:00
Tiago Rodrigues a9d039e081 move under the tracy namespace, remove commented out code 2023-12-03 09:23:03 -05:00
Tiago Rodrigues 132419dba3 Add image cache to avoid calling dladdr() when doing offline symbol resolution. This cache can also be used in the runtime symbol resolution case to detect we should recreate "backtrace_state" when new images have been loaded 2023-11-29 13:23:58 -05:00
Tiago Rodrigues a1ca8dd06a fixes according to review comments 2023-11-24 16:32:45 -05:00
trodrigues 301c9fb720 revert #ifdef of a lot of code by TRACY_SYMBOL_OFFLINE_RESOLVE, it now only force enables the offline symbol resolving codepath. 2023-11-19 06:32:17 -08:00
Tiago Rodrigues 79618c5a1a Add support for using defining TRACY_SYMBOL_OFFLINE_RESOLVE to enable only the offline symbol resolving codepath 2023-11-19 06:32:17 -08:00
Tiago Rodrigues c302b509fe fix formatting 2023-11-19 06:32:17 -08:00
Tiago Rodrigues f4f75eac64 Add support for offline symbol resolving by setting the "TRACY_SYMBOL_OFFLINE_RESOLVE=1" env var
- Add a tool "tracy-edit" that allows loading a tracy capture, patching symbols and recompress the result
- Add offline symbol resolvers for linux (using addr2line) and windows (using dbghelper)
2023-11-19 06:32:16 -08:00
Tiago Rodrigues c373647dae fix coding style 2023-11-13 13:43:03 -05:00
Tiago Rodrigues 790d28911d Add env var "TRACY_NO_DBHELP_INIT_LOAD" to allow disabling dbghelp loading of DeviceDriver and ProcessModules at startup 2023-11-10 17:02:03 -05:00
Mathias Lang c6d9741136 Fix and test TRACY_DEMANGLE for TracyClient
The configuration wasn't tested and stopped compiling.
This fixes it and adds a test to ensure it doesn't break again.
2023-09-06 01:28:58 +02:00
Lectem ecdf6adc32 Fix race condition for symbols resolution on windows
There might have been new modules loaded by another thread between the `SymInitialize` and `EnumProcessModules` calls.
Since we register the enumerated modules into the cache, we need to make sure that symbols for this module are loaded.
The only way to do that is to call `SymLoadModuleEx`, just like we do when finding new modules after `InitCallstack`.
2023-02-14 15:32:37 +01:00
Bartosz Taudul 383ecb6a12 Remove CodeLocation query and CodeInformation response. 2022-10-11 22:56:23 +02:00
Bartosz Taudul 6f9dfc8469 Use dladdr, not libbacktrace in fast callstack decode path.
DecodeCallstackPtrFast() may be called outside the symbol processing thread,
for example in the crash handler. Using the less-capable dladdr functionality
doesn't have a big impact here. Callstack decoding in this context is used to
remove the uninteresting top part of the callstack, so that the callstack ends
at the crashing function, and not in the crash handler. Even if this
functionality would be impacted by this change, the damage done is close to
none.

The other alternative is to use locking each time a libbacktrace is to be
used, which does not seem to be worthy to do, considering that the problem
only occurs in a very rare code path.

NB everything was working when it was first implemented, because back then the
callstack decoding was still performed on the main thread, and not on a
separate, dedicated one.
2022-10-08 13:22:56 +02:00
Bartosz Taudul 7552341ff0 Increase possible inline stack size to 64 elements. 2022-10-04 22:16:20 +02:00
Bartosz Taudul 2cc5eff9a2 Normalize symbol paths on libbacktrace systems. 2022-09-02 01:23:29 +02:00