282 Commits
Author SHA1 Message Date
ed ee086a06f8 Merge tag 'v0.9.14-alpha' into odin
# Conflicts:
#	src/df/core/df_core.mdesk
#	src/df/core/generated/df_core.meta.c
#	src/df/core/generated/df_core.meta.h
#	src/df/gfx/df_gfx.mdesk
#	src/df/gfx/df_view_rules.c
#	src/df/gfx/generated/df_gfx.meta.c
#	src/font_cache/font_cache.c
#	src/raddbg/generated/raddbg.meta.h

Need to redo the view rules
2024-11-24 19:12:20 -05:00
Nikita Smith b99e10224f simplified chunk size tracking 2024-11-15 16:14:00 -08:00
Nikita Smith 435f6c4ef6 append .lib to defaultlibs 2024-11-15 16:14:00 -08:00
Nikita Smith b631d431fa create section layout without copying chunk data and perform chunk data
copy in parallel given layout
2024-11-15 16:14:00 -08:00
Nikita Smith 2562d04fbf changed build.bat to handle extra natvis for radlink and removed
'Unset' part since we use setlocal that prevents local variable
from leaking to the environment.
2024-11-15 16:14:00 -08:00
Nikita Smith b52a008748 remove debug trap 2024-11-15 16:14:00 -08:00
Nikita Smith b16d930d13 natvis for linker types 2024-11-15 16:14:00 -08:00
Ryan Fleury 26be351354 eliminate per-build version numbers, just use base layer to define defaults; bump to 14 2024-11-15 15:36:12 -08:00
Ryan Fleury 77b2172a85 restrict cursor line info committing by selected module 2024-11-15 15:00:15 -08:00
Ryan Fleury f1c5c97a1b fix stale detection in background fuzzy search results 2024-11-15 14:53:03 -08:00
Ryan Fleury 6be2792659 search cache eviction 2024-11-15 14:40:05 -08:00
Ryan Fleury c42e7837ac fix 64-bit bitfield type value evaluation mask/shift 2024-11-15 11:44:51 -08:00
Ryan Fleury fe657987d6 restrict module for line info visualization; it is not generally useful to do all modules, and in large projects it is too slow to do serially: 2024-11-15 11:19:46 -08:00
Ryan Fleury 48c7bb788e fix incorrect completion parameters hash storage in dbgi matching work, pt. 2 2024-11-15 11:15:25 -08:00
Ryan Fleury 080a001183 fix incorrect completion parameters hash storage in dbgi matching work 2024-11-15 11:12:58 -08:00
Ryan Fleury 81c7c7a7c4 per-target option of automatically debugging subprocesses, or not 2024-11-14 14:18:35 -08:00
Ryan Fleury 95fe497056 fix incorrect advance logic on invalid page reads in cached process memory reading path 2024-11-14 13:08:17 -08:00
Ryan Fleury 8994cb04bc adjust default font size settings by dpi relative to standard 2024-11-14 12:07:19 -08:00
Ryan Fleury ce90b63079 oops........ 2024-11-14 10:58:52 -08:00
Ryan Fleury 6cf9b82857 strip out completion counter from dbgi parsing layer 2024-11-14 10:47:45 -08:00
Ryan Fleury cefbd40e2c fix rw lock r/w mismatch 2024-11-14 10:26:51 -08:00
Ryan Fleury 420f089fda eliminate incorrect cases of async_push_work, where pushes which could occur on worker threads may try to write to a cache that is currently being held, when the push occurs (when all threads are saturated) - async_push_work must never be called from within a cache locking mechanism 2024-11-14 09:55:03 -08:00
Ryan Fleury ff45952f07 re-introduce timeout-based re-requests for dbgi & fs layers; further adjust pre-emptive conversion heuristic 2024-11-14 09:29:01 -08:00
Ryan Fleury fa4f9621b0 adjust pre-emptive conversion heuristics; fix deadlock scenario in match work 2024-11-14 09:10:07 -08:00
Ryan Fleury 4c0ebc851c async priorities, strip out incorrect ring position calculations 2024-11-13 18:23:18 -08:00
Ryan Fleury 5a79518dcb fix debug directory tree cache clearing rule 2024-11-13 16:05:22 -08:00
Ryan Fleury 713cc2c693 entering the 7th circle of DLL hell 2024-11-13 15:48:38 -08:00
Ryan Fleury dcec3c07d9 pass over pre-emptive debug info conversion heuristic, to be friendlier to ue-style root project directories, with what feels like 1000s and 1000s of sub-directories with DLLs hidden in various folders 2024-11-13 14:40:08 -08:00
Ryan Fleury b03c1766c6 just make commit granularity 64 bit; it matches the expected usage pattern in a few spots 2024-11-13 12:18:48 -08:00
Ryan Fleury 4278f7db1e extend pre-emptive conversion rule to do limited children directory checking as well 2024-11-13 11:47:17 -08:00
Ryan Fleury ff90a90744 fix lru eviction in async name match store 2024-11-12 14:36:40 -08:00
Ryan Fleury 626665911d fix incorrect order of work queueing in file stream task kickoff 2024-11-12 14:15:28 -08:00
Ryan Fleury f09f059af2 eliminate thread expression strings in scheduler process expansion 2024-11-12 13:47:04 -08:00
Ryan Fleury e95afcd5aa fix ring buffer stomping in async match 2024-11-12 13:20:42 -08:00
Nikita Smith a8b1805749 updated prof markup usage sites 2024-11-12 13:18:17 -08:00
Nikita Smith a8b2266fc0 added macro for sending notes to telemetry 2024-11-12 13:18:17 -08:00
Nikita Smith bc446d8520 dynamic profile zone with raddbg sprintf 2024-11-12 13:18:17 -08:00
Ryan Fleury 9808157f45 switch match tasks to atomically update match nodes, rather than push results into a queue 2024-11-12 13:00:23 -08:00
Ryan Fleury 0ec6b8e8a8 more work on match store experiment; consume ring buffer results on begin - this experiment is not exactly the right approach, though. because the ui thread definitionally learns about these identifiers faster than the matches can (always) be completed, there is a permanent writer-going-faster-than-reader problem. the correct approach will need to account for this. 2024-11-12 13:00:23 -08:00
Ryan Fleury 3e0c150ccb more work on background name matching & plugging it into syntax highlighting path 2024-11-12 13:00:23 -08:00
Nikita Smith fd1906b034 safe cast commit size 2024-11-12 10:36:45 -08:00
Nikita Smith 2bbf3ff987 switch to data size formatter 2024-11-12 10:36:45 -08:00
Nikita Smith 880d7a4139 data size formatter for stb_sprintf 2024-11-12 10:36:45 -08:00
Nikita Smith c6caec657d moved cstring and find needle string ops to the main layer 2024-11-12 10:36:45 -08:00
Nikita Smith 3d7fc6fce5 moved memory and count string formatters to the main layer and
replaced str8_from_memory_size with more accurate data size units
2024-11-12 10:36:44 -08:00
Nikita Smith 0d0951bf08 squash some image-related steps into finalize image 2024-11-12 10:36:44 -08:00
Nikita Smith 3a190ae2c3 show an early warning for /DEBUG:FASTLINK 2024-11-12 10:36:44 -08:00
Ryan Fleury 420c2ec208 fix dbgi key array copy 2024-11-11 16:15:15 -08:00
Ryan Fleury f9abd3efb9 first half of first pass at asynchronous name matching; simplify current name matching path used in syntax highlighting & deduplicate between code slice & code labels 2024-11-11 16:06:01 -08:00
Ryan Fleury 5893ab94cb cancellation mechanism for debug info fuzzy searching 2024-11-11 10:38:52 -08:00
Ryan Fleury ff2e9df705 fix incorrect match range list copying in new searcher threads 2024-11-11 10:02:06 -08:00
Ryan Fleury 5aeee47f98 oops - fix busted render handle compare 2024-11-11 09:48:11 -08:00
Ryan Fleury 31f25d0fe7 eliminate attempts at clever read-only synchronization in file stream & ctrl layer, just fall back to simple locking mechanism 2024-11-10 11:25:55 -08:00
Nikita Smith bd4f82c8e8 cursed early return 2024-11-08 16:46:11 -08:00
Nikita Smith 680ea2ffdc added /RAD_IDLE_WORKERS 2024-11-08 16:09:56 -08:00
Nikita Smith f7d7f6633f expose file API to enable IO detouring 2024-11-08 16:09:56 -08:00
Ryan Fleury 04c1488cd4 xxhash for ev & ui hashes 2024-11-08 15:02:52 -08:00
Ryan Fleury 5232ba298d cache cons type byte size, and more generally, do not require full type calculation in order to calculate byte sizes 2024-11-08 15:02:52 -08:00
Ryan Fleury 65ada18d1d fix render layer guid linking w/out font provider layer; eliminate generation number on render handles; sketch out tester scratch program for text drawing performance 2024-11-08 15:02:52 -08:00
Nikita Smith 8e6a0ae4db errors and warnings fixes 2024-11-08 11:43:05 -08:00
Nikita Smith e297460697 add necessary Linux impls for linker
NOTE: Current OS API for semaphores doesn't work well with Linux/pthreads
way, for example, on Linux it's up to user program to allocate shared memory
and store there sem_t and detect when to release it. (Windows does this under
the hood when process that created shared semaphore exits)
2024-11-08 11:43:05 -08:00
Nikita Smith cf8c0e7442 clang and gcc bit ops 2024-11-08 11:43:05 -08:00
Nikita Smith 776c8daa27 updated build.sh to define git hash 2024-11-08 11:43:05 -08:00
Nikita Smith 69b43c76d4 default to llvm-mt on non-windows platforms 2024-11-08 11:43:05 -08:00
Nikita Smith d114a0e961 tidy up guid on linux 2024-11-08 11:43:05 -08:00
Nikita Smith d177e39a54 build.sh add radlink target 2024-11-08 11:43:05 -08:00
Ryan Fleury 158dd742ad eliminate entry point 'mode'/type; just gather argc/argv as part of command line parse 2024-11-08 10:33:28 -08:00
Ryan Fleury 0773b6d282 switch to xxhash for font cache hashes 2024-11-08 09:04:16 -08:00
Nikita Smith 15d43d7c99 removed dependency on os_ext 2024-11-07 14:12:41 -08:00
Nikita Smith 7650a83d1e further simplify linker/os_ext/os_core.c 2024-11-07 14:08:21 -08:00
Nikita Smith daeb08e79f moved os_folder_exists to the main layer and deleted win32 layer from linker folder 2024-11-07 13:55:15 -08:00
Nikita Smith ef5287d2a9 switch to os_full_path_from_path 2024-11-07 13:41:47 -08:00
Nikita Smith db04792073 moved getter for process start time w32 2024-11-07 13:33:37 -08:00
Nikita Smith 4091373517 moved operating system -> string to base 2024-11-07 11:54:25 -08:00
Nikita Smith 214be8c433 moved Guid struct and related helpers to base 2024-11-07 11:54:25 -08:00
Nikita Smith f807dc4785 override entry point 2024-11-07 11:54:25 -08:00
Nikita Smith 0dd05169ee add ability to override entry point type 2024-11-07 11:54:25 -08:00
Nikita Smith ce9d43a92e pass over coff header 2024-11-07 11:54:25 -08:00
Nikita Smith 0886963d93 promote section definition number to 32-bit when linking big obj 2024-11-07 11:54:25 -08:00
Nikita Smith 27cd7a21a3 coff section definition for big obj 2024-11-07 11:54:24 -08:00
Nikita Smith 7bb88f480e mask compute typo 2024-11-07 11:54:24 -08:00
Nikita Smith fad817fb9e apply communal variable rule for largest comdat only 2024-11-07 11:54:24 -08:00
Nikita Smith 1d42f1bd66 speed up export table build with hash table 2024-11-07 11:54:24 -08:00
Ryan Fleury a5dd35b874 eliminate dbgi search layer usage 2024-11-07 10:14:17 -08:00
Ryan Fleury a89af7f6fd scratch that - *now* fix the arrayification 2024-11-07 10:07:36 -08:00
Ryan Fleury 5a19ab9c31 fix new search path arrayification 2024-11-07 10:06:49 -08:00
Ryan Fleury e204fe28c1 eliminate deadlocking mechanism in dbgi search cache lookup/mutation; replace with simpler but possibly worse mechanism for now 2024-11-07 09:57:25 -08:00
Ryan Fleury d036eb9fc5 eliminate old dbgi_search layer 2024-11-05 15:08:58 -08:00
Ryan Fleury 1621e504ce first half pass at new dbgi fuzzy searching functionality; distributes search amongst sub-tasks 2024-11-05 15:07:06 -08:00
Ryan Fleury 44b8c9e87c eliminate r/w lock promotion concept 2024-11-04 13:30:10 -08:00
Ryan Fleury 4a0e21d447 collapse user clock indices into base-layer-provided clock counter; fuzzy_search -> dbgi_search 2024-11-04 13:12:52 -08:00
Ryan Fleury 3cd32fa235 correctly prepare paths for windows launches in demon 2024-11-03 14:45:21 -08:00
Ryan Fleury c3a672cd02 fix incorrect async work ordering in dbgi layer 2024-11-03 12:48:34 -08:00
Ryan Fleury 9ce0bc5dbf [geo] move to async layer 2024-11-03 12:17:18 -08:00
Ryan Fleury ffb21277e9 [tex] move to async layer 2024-11-03 12:13:20 -08:00
Ryan Fleury a40edbba51 dasm, ctrl memstream, & more moving to async layer, rather than per-layer thread pools 2024-11-03 12:11:24 -08:00
Ryan Fleury c2855a9a46 eliminate txt layer parsing threads; use async layer 2024-11-03 11:12:24 -08:00
Ryan Fleury 61e7aaadeb implement 'work stealing' mechanism for falling back to synchronous task execution, if all work threads are taken 2024-11-01 16:41:43 -07:00
Ryan Fleury 5a0efe1261 move dbgi layer to async task layer 2024-11-01 15:30:17 -07:00
Ryan Fleury 6d55d21643 fix clang builds 2024-11-01 15:22:26 -07:00
Ryan Fleury 4164b30aac move breakpad converter to async layer; eliminate task system 2024-11-01 15:18:40 -07:00
Ryan Fleury aded54c97f fix pointer stability of async task output slot; finish moving converter to async system 2024-11-01 15:02:45 -07:00
Ryan Fleury 79bcbe4b39 switch rdi_from_pdb to new async layer, off of old task system 2024-11-01 14:44:56 -07:00
Ryan Fleury 86d9b792d8 shift file streaming layer to using async layer for background work, remove file stream layer thread pool 2024-10-31 11:44:54 -07:00
Nikita Smith f3a36ece13 rebase fixes 2024-10-30 15:56:55 -07:00
Nikita Smith c5d198e3e9 build linker with branch name and full commit hash 2024-10-30 15:56:10 -07:00
Nikita Smith eba7500f73 /rad_pdb_hash_type_names:lenient
Less aggressive optimization for type names. When lenient enabled, linker
replaces only mangled names and compiler generated lambda types.
2024-10-30 15:56:10 -07:00
Nikita Smith 339f43919c remove bogus leaf align 2024-10-30 15:56:09 -07:00
Nikita Smith f3fbf10754 replace type names with hashes 2024-10-30 15:56:09 -07:00
Nikita Smith 4a2e1dd8d0 switch to thread safe hash trie map
Initial implementation of the symbol table allowed us to push symbols
from one thread at a time and required a wonky lock-step and spread out
logic for replacing symbols. And because it was a externally chained
hash table we had to guesstimate optimal capacity for small and big targets.
We erred on the side of larger capacity to prevent degradation and
rehashing, however this meant small targets had to spent unreasonable
amount of time memory allocing slots. With hash trie we can dynamically
scale up to 4 ^ 32 items and atomically replace symbols when needed. Neat!
2024-10-30 15:43:53 -07:00
Nikita Smith ee65ea3692 fast-path for string matching 2024-10-30 15:42:39 -07:00
Nikita Smith baead67a99 minor fixes 2024-10-30 15:42:39 -07:00
Nikita Smith e085dae636 pass over atomic operations
- use cast to volatile trick for atomic loads on x64 windows
- removed unnecessary includes on windows
- upgraded clang and gcc code paths to use modern atomics

Removed WIN32_LEAN_AND_MEAN because we were already compiling without it
and there is code path in os_gfx_win32.c that relies on including full
windows.h
2024-10-30 15:42:39 -07:00
Nikita Smith eba6765541 set LF endings for shell scripts so they are executable after checkout 2024-10-30 15:42:39 -07:00
Nikita Smith 002e479a2d index on dev: 62880e6 set explicitly heap and stack reserve and size 2024-10-30 15:42:39 -07:00
Nikita Smith 8848080729 set explicitly heap and stack reserve and size 2024-10-30 15:42:39 -07:00
Nikita Smith e1166abc63 typo in str8 compar name 2024-10-30 15:42:39 -07:00
Nikita Smith 6ffc065712 set dynamic base on /fixed:no 2024-10-30 15:42:39 -07:00
Nikita Smith 15b1ebcd21 coff section align from byte size helper 2024-10-30 15:42:39 -07:00
Ryan Fleury 37b27a9cff correctly bounds-check cursor before doing snapping operations 2024-10-30 06:20:11 -07:00
Ryan Fleury 327fec3155 fix rdi_from_pdb build 2024-10-29 16:50:37 -07:00
Ryan Fleury d0b97a3010 first pass at more comprehensive async layer, for replacing task system & providing single mechanism for async work, which is currently done ad-hoc in various layers 2024-10-29 16:27:21 -07:00
Ryan Fleury 1b5321ad8e fix incorrect tooltip 2024-10-28 21:38:09 -07:00
Ryan Fleury 4769d0a8d4 narrow scope of name resolution for debugger collections; default launching to not attach to child processes, set up msgs to parameterize this 2024-10-28 15:37:28 -07:00
Ryan Fleury 41cddf96b8 preemptive adjacent pdb conversion on initial module load; tighten up c/c++ lexer for smaller string lexes 2024-10-28 13:52:36 -07:00
Ryan Fleury 100d3523d3 clamp floating root positions by window lower bound as well 2024-10-24 11:48:45 -07:00
Ryan Fleury f0b1b46840 clamp thread tooltip callstack symbol names 2024-10-24 11:45:45 -07:00
Ryan Fleury e9666e2edd adjust disasm lexer to account for compiler-autogenerated symbol names 2024-10-24 11:41:59 -07:00
Ryan Fleury 8f932bdbf7 oops 2024-10-24 11:29:13 -07:00
Ryan Fleury c3c9539f9b prioritize string/symbol content in single-line pointer visualization; only use address-first when descending. also fix signed/unsigned visualization of character numeric values 2024-10-24 11:25:27 -07:00
Ryan Fleury 13341a458a fix incorrect kill-single-process ui path 2024-10-23 13:23:22 -07:00
Ryan Fleury 62659c5161 introduce dedicated kill-all path; fix exit conditions for single-stepping stuck threads to be robust toward unexpected kills; fix exit conditions for kill-single-process path, to be more robust to halts; correctly report stop cause 2024-10-23 13:19:37 -07:00
Ryan Fleury 1ecabff7b6 prefer usage of pdbs in dbgi layer, if rdi path is not baked in, but pdb path *is* - otherwise the dbgi layer can simply choose a stale rdi file with no way to generate a new one. 2024-10-23 11:49:47 -07:00
Ryan Fleury 45f5a2d18f accept / command line arguments on windows 2024-10-23 11:19:07 -07:00
Ryan Fleury bcd16a4f29 only plug in jumping immediates to jump_dest_vaddr paths in stepping; ctrl flow info analysis path stops when it has to read memory or registers 2024-10-23 11:07:51 -07:00
Ryan Fleury 6d7858d445 parameterize tester with test data root folder; wrap tester run in top-levels cript 2024-10-22 17:51:21 -07:00
Ryan Fleury c67f1a8b4a fix empty file edge case in hash store / text cache 2024-10-22 16:19:11 -07:00
Nikita Smith 340396f9f7 fix arena usage 2024-10-22 15:07:49 -07:00
Nikita Smith eb6aabe2d1 set block base pos 2024-10-22 15:06:39 -07:00
Nikita Smith 9ec7fb61ed implemented /noimplib /noexp 2024-10-22 11:02:59 -07:00
Nikita Smith dcffefd0c6 typo in string table lookup 2024-10-22 10:58:41 -07:00
Nikita Smith 5be2b5dfd9 alias for amd64 machine 2024-10-22 10:19:37 -07:00
Nikita Smith 7260baea85 implemented /PDBALTPATH and /RAD_DEBUGALTPATH 2024-10-21 18:03:28 -07:00
Nikita Smith a802f2186b actually push new block to list 2024-10-21 14:35:55 -07:00
Nikita Smith a43678e311 voff -> line search fix
when line table contains duplicate virtual offsets we have to return
index of last virtual offset so following property is true:
'line_length = virtual_offsets[index + 1] - virtual_offsets[index]'
2024-10-21 13:32:04 -07:00
Ryan Fleury edee84dd03 fix maximum munch rule application in text cache lexers 2024-10-21 10:37:04 -07:00
Ryan Fleury 4a211de2b3 do not bake path normalization into eval string <-> file path; this incorrectly assumes the normalization base directory, which is not correct when serializing/deserializing/etc. instead, just normalize on find-code-location. 2024-10-21 09:56:32 -07:00
Ryan Fleury d0915ec9a7 eval expressions: unary +, correctly lex exponentiated numerics 2024-10-21 09:23:31 -07:00
Ryan Fleury 52245a8e5a maintain explicit casts in cstring -> string paths 2024-10-21 08:51:19 -07:00
Nikita Smith dbcecd99af fix sizeof array types 2024-10-19 20:39:40 -07:00
Nikita Smith 68c0906570 print register name 2024-10-19 20:39:40 -07:00
Nikita Smith 26611c5454 moved IO related code to stand-alone file, piped all read/and writes
through new API, /rad_log now can enable read and/or write logs with
"io", "io_reads", "io_writes" parameters.
2024-10-19 16:36:32 -07:00
Nikita Smith 05d4faeb49 remove unsued func 2024-10-19 15:13:10 -07:00
Nikita Smith d5c2e50e9a rename import table regular -> static 2024-10-19 15:11:51 -07:00
Nikita Smith 800a2349e5 pass over COFF resource reader and writer 2024-10-19 13:44:36 -07:00
Nikita Smith 46390ba0b8 reworked manifest handling
- manifest files wont be created unless symbols are resolved
- delay mt.exe presence check until we launch it
- create explicit case that writes manifests to disk
- moved manifest dependency collection step to happen after obj input
- removed /rad_delete_manifest
2024-10-18 23:37:30 -07:00
Nikita Smith f1a0e7233d cstring helper for wide chars 2024-10-18 22:56:55 -07:00
Nikita Smith 9d60dcc099 updated radlink benches in readme 2024-10-18 17:12:31 -07:00
Nikita Smith f792da5d31 manifest... 2024-10-18 16:53:30 -07:00
Ryan Fleury 1344270b5a adjust versions 2024-10-18 16:40:25 -07:00
Ryan Fleury c03844fb1a fix build, make icon unique to raddbg 2024-10-18 16:32:49 -07:00
Nikita Smith d04e86c007 rename merged manifest 2024-10-18 16:23:51 -07:00
Ryan Fleury 669574df5a fix incorrect ordering of inline sites & concrete frames in call stack view 2024-10-18 16:07:25 -07:00
Nikita Smith 3aa4b2ea03 fix udt resolution & emit correct null type 2024-10-18 16:01:17 -07:00
Nikita Smith 2f5e55d52f switch check typo 2024-10-18 16:01:17 -07:00
Nikita Smith 14ad67d59a assign correct file path node to source file
* disabled debug check for sortness too while I'm here
2024-10-18 16:01:17 -07:00
Nikita Smith b2bdb893a0 print file path node idx 2024-10-18 16:01:17 -07:00
Ryan Fleury 98dfedfff5 limit the amount of line info visualization voff gathering; otherwise we can just spend tons of time gathering inline site voffs forever... 2024-10-18 15:16:34 -07:00
Ryan Fleury 1f633a029c skip redundant expansion tasks in eval viz block tree build 2024-10-18 13:58:24 -07:00
Ryan Fleury b3d6b2913e fix enum value committing 2024-10-18 13:47:51 -07:00
Ryan Fleury 53c624a27c respect view rule radix in enum evaluations 2024-10-18 13:37:14 -07:00
Ryan Fleury 1865c33704 specify collection qualifier for collection tabs; do not resolve to anything else 2024-10-18 13:32:29 -07:00
Ryan Fleury e17a089564 fix incorrect 0 member (should be nil) 2024-10-18 12:14:40 -07:00
Ryan Fleury eb9212b6f7 fix string cmd query params 2024-10-18 12:00:13 -07:00
Nikita Smith 0ac090cab2 delete unused files 2024-10-18 11:07:00 -07:00
Nikita Smith 7827e1b1c7 fix bounds check condition in assert 2024-10-18 11:07:00 -07:00
Nikita Smith 36f3924160 don't allocate .reloc section when there are no pages 2024-10-18 11:05:51 -07:00
Nikita Smith 00dd4ad6ec check if subsystem was specified 2024-10-18 11:05:01 -07:00
Nikita Smith 7f7f7f2873 reserve space for null string 2024-10-18 11:03:46 -07:00
Nikita Smith c8a5fc4806 Changed debug directory parser to handle multiple entries. Added
parser for RDI debug info entry. Changed debug info lookup order so
debugger tries to load path specified in exe first and if debug info
is missing then debugger will do heuristic searches.
2024-10-17 18:51:35 -07:00
Nikita Smith 652dcafbbf demon helper for reading cstrings 2024-10-17 18:46:59 -07:00
Ryan Fleury 72f987533c Merge branch 'dev' of https://github.com/EpicGames/raddebugger into dev 2024-10-17 16:50:50 -07:00
Ryan Fleury 5fd835c4d4 note 2024-10-17 16:50:25 -07:00
Nikita Smith c50d9276ba build inline lines accels 2024-10-17 16:25:54 -07:00
Nikita Smith 1214cb0968 dumper for CodeView inline sites 2024-10-17 16:25:54 -07:00
Nikita Smith 3099759c0b stringizers for inline site range kind 2024-10-17 16:25:54 -07:00
Nikita Smith 95d31f5608 fix off-by-one in inline site decode 2024-10-17 16:25:54 -07:00
Ryan Fleury 687323fc2e fix soft-halt with thread freezes; fix disabling/tooltips of top-bar controls 2024-10-17 16:12:31 -07:00
Ryan Fleury 51dce36ede notes 2024-10-17 14:51:41 -07:00
Ryan Fleury b61f4d550f Merge branch 'dev' of https://github.com/EpicGames/raddebugger into dev 2024-10-17 14:51:28 -07:00
Ryan Fleury d8d8762869 adjust entity rows in watch views to use single-click for select, double-click for their primary operation, and add in operation for breakpoints/watch-pins 2024-10-17 14:51:07 -07:00
Nikita Smith d2db4542cb check type server signature against signature in obj 2024-10-17 14:05:34 -07:00
Ryan Fleury 7adf08cc7b parameterize string eval commit path by whether or not the surrounding ui expects the string to be manually escaped or not by the user (it is not in the case of things like the meta-entity views) 2024-10-17 12:57:53 -07:00
Ryan Fleury a202999655 fix over-ambitious thread selection in frontend 2024-10-17 12:43:32 -07:00
Ryan Fleury ae3a43c694 fix file-path-parameterized commands w/ ipc 2024-10-17 12:32:20 -07:00
Ryan Fleury 2f7434cd92 always use pending-file when doing a file switch 2024-10-17 12:29:06 -07:00
Ryan Fleury b02c67bfa6 close stdout/stderr/stdin handles 2024-10-17 12:20:03 -07:00
Ryan Fleury 992be37801 fix unclamped-by-line token ranges in code slice widget mouse -> token path 2024-10-17 12:13:32 -07:00
Ryan Fleury 4727a01b9f fix kill/halt button & text 2024-10-17 12:01:02 -07:00
Ryan Fleury e376ad8113 stdout/stderr/stdin file path overrides for targets 2024-10-17 11:25:47 -07:00
Ryan Fleury 23ad094a68 allow escaped-identifier lookup for type names 2024-10-17 10:46:14 -07:00
Nikita Smith 2b407b5861 changed write file to accept 1MiB blocks to improve file write speed on windows 2024-10-16 22:27:46 -07:00
Nikita Smith 79390f4a95 align msf pages on page size 2024-10-16 22:27:46 -07:00
Nikita Smith aedfb556be fix aligned arena push 2024-10-16 22:27:46 -07:00
Ryan Fleury 78039c86a0 include no_addr in view rule system for docs/inheritance rules 2024-10-16 15:41:21 -07:00
Ryan Fleury 186e8cbabe shift disasm view to rounding/sizing equally 2024-10-16 14:58:13 -07:00
Ryan Fleury 5ec0a0e406 fix incorrect inline site baking 2024-10-16 14:29:08 -07:00
Martins MozeikoandRyan Fleury 9c016004c2 Setup symbol path in win32 exception handler to the .exe folder
Otherwise it was trying lookup .pdb files only in the current folder,
as that is how .exe's are built (/pdbaltpath). This change now makes
exception handler to load .pdb from the same folder as where .exe is.
2024-10-16 14:13:26 -07:00
Ryan Fleury 9c1f8ef37b file name disambiguation for tab titles 2024-10-16 14:12:21 -07:00
Ryan Fleury 938af75efb normalize paths when doing file-path <-> eval string 2024-10-16 13:33:47 -07:00
Ryan Fleury 38173a7154 adjust pointer visualization; don't follow 0 pointers, go back to showing address first; adjust find-code-location snapping rule to only require a disasm snap / focus if no file location is specified 2024-10-16 13:23:10 -07:00
Ryan Fleury 74ee3b9850 option to rdi_from_pdb for deterministic generation; omits non-intrinsic, build-dependent information 2024-10-16 12:47:10 -07:00
Ryan Fleury 2edb65b5bd fix remaining non-determinism in pdb -> rdi generation! 2024-10-16 12:07:02 -07:00
Nikita Smith 9e6aa8506f README.md tweaks 2024-10-16 10:48:51 -07:00
Nikita Smith 648fa7cdab update hash in config 2024-10-16 10:23:53 -07:00
Nikita Smith 6612f4a32d hash image only when we have debug info building 2024-10-16 10:15:16 -07:00
Ryan Fleury e65bc121ed more work on pdb -> rdi determinism; almost done hitting all of the issues... 2024-10-16 08:52:27 -07:00
Ryan Fleury e1575f815c Merge branch 'dev' of https://github.com/EpicGames/raddebugger into dev 2024-10-15 18:05:14 -07:00
Ryan Fleury 0b50d8718e oops - reenable 2024-10-15 18:05:05 -07:00
Ryan Fleury 4671458e8e further debugging / logging / work on tester, trynig to get to the bottom of nondeterministic rdi generation 2024-10-15 17:41:18 -07:00
Nikita Smith bb86072dfa updated git actions 2024-10-15 17:32:21 -07:00
Nikita Smith d5988d0066 updated README 2024-10-15 17:26:50 -07:00
Nikita Smith 932df7bf68 linker 2024-10-15 17:25:22 -07:00
Nikita Smith 0cf553e39a minor fixes 2024-10-15 17:24:29 -07:00
Nikita Smith 1bcd66329f factored parser code out of pdb 2024-10-15 16:28:51 -07:00
Nikita Smith c3e2e2e91b factored parser code out of msf 2024-10-15 16:28:47 -07:00
Nikita Smith c34d7e2062 added missing LF_ENDPRECOMP type, fixed case for S_OBJNAME symbol,
merged leaf id kinds into main leaf enum, renamed public flags enum,
removed type dependency on PDB string table and PDB coff section array
2024-10-15 16:24:29 -07:00
Nikita Smith b1d6ebf77b added masm language enum and type kind count 2024-10-15 16:20:18 -07:00
Nikita Smith 9535652cfb define null path style 2024-10-15 16:19:27 -07:00
Nikita Smith 3ae1d8e401 bunch of tiny tweaks and changes from internal repo 2024-10-15 16:18:43 -07:00
Nikita Smith 7e98df22d7 temp arena change that lets us bypass memory decommits 2024-10-15 14:43:36 -07:00
Ryan Fleury 65b5176468 allocate extra slot for nil in global vmap baking; was causing overwrites of keys/markers before! 2024-10-15 12:42:43 -07:00
Ryan Fleury e61dfd793a stdout redirection support in os command line launch helper; do rdi dumps in determinism test 2024-10-15 12:20:25 -07:00
Ryan Fleury 97abec11a2 begin setting up tester for automated tests 2024-10-15 11:46:07 -07:00
Ryan Fleury b223a61cad tweaks & language fix 2024-10-15 10:17:37 -07:00
Ryan Fleury 94fb5056c2 resolve ptr-addition integer to value 2024-10-15 10:07:10 -07:00
Ryan Fleury 88dced7d2a notes 2024-10-15 09:00:54 -07:00
Ryan Fleury e92543d3f8 round to 4K rather than 16K boundaries for starting disasm address 2024-10-14 21:46:03 -07:00
Ryan Fleury 078cbf6afd fix incorrect auto disasm starting address 2024-10-14 20:56:25 -07:00
Martins MozeikoandRyan Fleury 3d34a26205 avx512 register support in codeview -> rdi conversion 2024-10-14 20:54:26 -07:00
ed e9abd2ab3a Merge remote-tracking branch 'EpicGamesExt/dev' into odin
Had to change odin's slice view rule to odin slice since there is now an offical slice definition.

# Conflicts:
#	src/df/core/df_core.mdesk
#	src/df/core/generated/df_core.meta.c
2024-07-03 21:31:26 -04:00
ed b6f9766fe5 Compile fixes reported from Odin community discord
Multiple people were having compilation issues this resolves it.
2024-07-03 21:19:09 -04:00
ed b6dca789df compile fixes 2024-06-26 23:23:40 -04:00
ed 2fe6a0884c Merge tag 'v0.9.11-alpha' into odin
# Conflicts:
#	src/df/gfx/generated/df_gfx.meta.c
2024-06-26 23:07:46 -04:00
ed d1391c5f91 Merge remote-tracking branch 'EpicGames/dev' into odin 2024-06-19 23:04:56 -04:00
ed fc8dfcc506 Merge remote-tracking branch 'EpicGames/dev' into odin 2024-06-13 21:12:26 -04:00
ed 1028318de2 Merge remote-tracking branch 'EpicGames/dev' into odin 2024-06-11 18:52:08 -04:00
ed 4fdd2aee71 Compile fixes 2024-06-04 13:29:05 -04:00
ed 245560552e Merge remote-tracking branch 'EpicGames/dev' into odin 2024-06-04 13:25:19 -04:00
ed 1101854de5 new def_core.meta 2024-05-30 13:33:14 -04:00
ed 0bbf33514b Merge remote-tracking branch 'EpicGames/dev' into odin_dll_calls_not_working
# Conflicts:
#	src/df/core/generated/df_core.meta.c
2024-05-30 13:33:03 -04:00
ed 9086233d89 compile fixes 2024-05-26 11:16:20 -04:00
ed ad1b2fa23d Merge tag 'v0.9.10-alpha' into odin 2024-05-26 11:12:40 -04:00
ed f67098f54b Merge remote-tracking branch 'EpicGames/master' into odin
# Conflicts:
#	src/df/core/df_core.mdesk
#	src/df/core/generated/df_core.meta.c
2024-05-18 12:03:19 -04:00
ed ea4e671a44 Merge remote-tracking branch 'EpicGames/master' into odin 2024-05-14 22:27:18 -04:00
ed 0c4c18c64f Fixes for latest merge into with last changes for odin support from gingerBill 2024-05-07 18:44:00 -04:00
ed ba9d68951d Merge branch 'master' into odin
# Conflicts:
#	src/df/core/generated/df_core.meta.c
#	src/df/gfx/df_gfx.mdesk
#	src/df/gfx/df_view_rules.c
#	src/df/gfx/generated/df_gfx.meta.c
#	src/df/gfx/generated/df_gfx.meta.h
2024-05-07 18:27:10 -04:00
ed 340d504f10 Merge remote-tracking branch 'gingerbill/master' into odin 2024-04-02 15:48:04 -04:00
gingerBill e8f03562bf Add hash row under key 2024-04-01 15:42:20 +01:00
gingerBillandGitHub c946f88b2a Merge pull request #1 from EpicGamesExt/master
Update
2024-04-01 15:14:55 +01:00
gingerBill 56e7bae038 Minor clean up 2024-04-01 15:13:22 +01:00
gingerBill c1741b4f39 odin_map visualization with nested key-value pairs 2024-04-01 14:51:30 +01:00
ed ba41543543 Merge remote-tracking branch 'gingerbill/master' into odin
# Conflicts:
#	src/df/core/df_core.mdesk
#	src/df/core/generated/df_core.meta.c
#	src/df/core/generated/df_core.meta.h
#	src/df/gfx/df_gfx.c
#	src/df/gfx/df_view_rule_hooks.c
#	src/font_cache/font_cache.c
#	src/txti/txti.c
#	src/txti/txti.h
2024-03-30 13:02:37 -04:00
gingerBill 5ae60aedc5 Correct brace style 2024-03-30 14:13:06 +00:00
gingerBill f23979e20a Mock out logic for map iteration 2024-03-30 14:00:27 +00:00
gingerBill 57fb0eb833 VERY basic map support with map cell info 2024-03-30 13:47:18 +00:00
gingerBill 5d2d13d9d9 Dumb map rendering showing keys only (including dummy ones) 2024-03-30 11:59:04 +00:00
gingerBill 8342cfbd53 Add slice view 2024-03-30 10:46:51 +00:00
ed 2721adf088 remove hmh comment from build script (remnant of copy & paste) 2024-02-12 11:52:08 -05:00
ed ffcecd659e Merge remote-tracking branch 'gingerbill/master' into odin 2024-02-12 11:32:35 -05:00
gingerBill 0ccfb51102 Very bad odin_map view rule, only renders keys currently 2024-02-12 15:51:31 +00:00
gingerBill f41f8dd719 Remove dbg_printf 2024-02-12 14:33:57 +00:00
gingerBill fa6b04ab24 Support String8 like strings 2024-02-12 14:32:49 +00:00
gingerBill 156615a3ba Add view rule slice 2024-02-12 14:16:23 +00:00
gingerBill 57a35c6b28 Make tabs 4-spaces (1 was too little) 2024-02-12 12:35:43 +00:00
ed 76ce8a79c2 Made ease of use scripts for building and cleaning 2024-02-09 17:50:42 -05:00
ed 932db741fa Merge remote-tracking branch 'leidegre/feature/odin' into build_scripts 2024-02-09 16:08:40 -05:00
John LeidegrenandGitHub 0add3ef72c Merge branch 'master' into feature/odin 2024-01-21 15:59:23 +01:00
John LeidegrenandGitHub e417a96ce4 Fixed typo 2024-01-20 17:53:49 +01:00
John Leidegren b2262532a7 Fixed mistakes 2024-01-20 15:21:55 +01:00
John Leidegren b24326f502 Fixed formatting 2024-01-20 14:27:38 +01:00
John Leidegren 66c1fa337c Adds syntax colors to .odin files 2024-01-20 14:23:23 +01:00
247 changed files with 92328 additions and 12441 deletions
+1
View File
@@ -0,0 +1 @@
*.sh text=auto eol=lf
+2
View File
@@ -28,3 +28,5 @@ jobs:
call build rdi_from_pdb clang debug || exit /b 1 call build rdi_from_pdb clang debug || exit /b 1
call build rdi_from_dwarf clang debug || exit /b 1 call build rdi_from_dwarf clang debug || exit /b 1
call build rdi_dump clang debug || exit /b 1 call build rdi_dump clang debug || exit /b 1
call build radlink msvc debug || exit /b 1
call build radlink clang debug || exit /b 1
+41 -2
View File
@@ -158,6 +158,45 @@ like remote debugging, porting to different architectures, further improving
the debugger's features (like improving the visualization engine), and so on. the debugger's features (like improving the visualization engine), and so on.
But for now, we're mostly focused on those first two phases. But for now, we're mostly focused on those first two phases.
---
# The RAD Linker
The RAD Linker is a new performance linker for generating x64 PE/COFF binaries. It is designed to be very fast when creating gigantic executables. It generates standard PDB files for debugging, but it can also optionally create RAD Debugger debug info too (useful for huge executables that otherwise create broken PDBs that overflow internal 32-bit tables).
The RAD Linker is primarily optimized to handle huge linking projects - in our test cases (where debug info is multiple gigabytes), we see 50% faster link times.
The command line syntax is fully compatible with MSVC and you can get a full list of implemented switches from `/help`.
Our current designed-for use case for the linker is to help with the compile-debug cycle of huge projects. We don't yet have support for dead-code-elimination or link-time-optimizations, but these features are on the road map.
By default, the RAD linker spawns as many threads as there are cores, so if you plan to run multiple linkers in parallel, you can limit the number of thread workers via `/rad_workers`.
We also have support for large memory pages, which, when enabled, reduce link time by
another 25%. To link with large pages, you need to explicitly request them via `/rad_large_pages`. Large pages are off by default, since Windows support for large pages is a bit buggy - we recommend they only be used in Docker or VM images where the environment is reset after each link. In a standard Windows environment, using large pages otherwise will fragment memory quickly forcing a reboot. We are working on a Linux port of the linker that will be able to build with large pages robustly.
## Short Term Roadmap
- Porting linker to Linux (for Windows executables, just running on Linux).
- Debug info features
- Get DWARF debug info converter up-and-running.
- Smooth out rough edges in RADDBGI builder.
- Improve build speed further (especially for tiny and mid sizes projects).
- Other features to come
- Dead-code-elimination via `/opt:ref`.
- Link Time Optimizations with the help of clang (we won't support LTCG from MSVC compiler since it is undocumented).
## To build the RAD Linker
- Setup development environment, [see](#Development-Setup-Instructions)
- Run `build radlink release` or if you have clang installed `build radlink release clang`. We favor latter option for better code generation.
If build was successful linker executable is placed in `build` folder under `radlink.exe`.
## Benchmarks
![AMD Ryzen Threadripper PRO 3995WX 64-Cores, 256 GiB RAM (Windows x64)](https://github.com/user-attachments/assets/a95b382a-76b4-4a4c-b809-b61fe25e667a)
---
## Top-Level Directory Descriptions ## Top-Level Directory Descriptions
- `data`: Small binary files which are used when building, either to embed - `data`: Small binary files which are used when building, either to embed
@@ -202,6 +241,8 @@ not depend on any other layers in the codebase. The folders which contain these
layers are prefixed with `lib_`, like `lib_rdi_format`. layers are prefixed with `lib_`, like `lib_rdi_format`.
A list of the layers in the codebase and their associated namespaces is below: A list of the layers in the codebase and their associated namespaces is below:
- `async` (`ASYNC_`): Implements a system for asynchronous work to be queued
and executed on a thread pool.
- `base` (no namespace): Universal, codebase-wide constructs. Strings, math, - `base` (no namespace): Universal, codebase-wide constructs. Strings, math,
memory allocators, helper macros, command-line parsing, and so on. Depends memory allocators, helper macros, command-line parsing, and so on. Depends
on no other codebase layers. on no other codebase layers.
@@ -336,8 +377,6 @@ A list of the layers in the codebase and their associated namespaces is below:
as-needed basis. Higher level drawing features are implemented in the `draw` as-needed basis. Higher level drawing features are implemented in the `draw`
layer. layer.
- `scratch` (no namespace): Scratch space for small and transient test programs. - `scratch` (no namespace): Scratch space for small and transient test programs.
- `task_system` (`TS_`): Implements a system for kicking off asynchronous tasks
and obtaining artifacts from those tasks once they've completed.
- `texture_cache` (`TEX_`): Implements an asynchronously-filled cache for GPU - `texture_cache` (`TEX_`): Implements an asynchronously-filled cache for GPU
texture data, filled by data sourced in the `hash_store` layer's cache. Used texture data, filled by data sourced in the `hash_store` layer's cache. Used
for asynchronously preparing data for visualization. for asynchronously preparing data for visualization.
+24 -15
View File
@@ -1,5 +1,5 @@
@echo off @echo off
setlocal setlocal enabledelayedexpansion
cd /D "%~dp0" cd /D "%~dp0"
:: --- Usage Notes (2024/1/10) ------------------------------------------------ :: --- Usage Notes (2024/1/10) ------------------------------------------------
@@ -48,13 +48,24 @@ set cl_debug= call cl /Od /Ob1 /DBUILD_DEBUG=1 %cl_common% %auto_compile_fl
set cl_release= call cl /O2 /DBUILD_DEBUG=0 %cl_common% %auto_compile_flags% set cl_release= call cl /O2 /DBUILD_DEBUG=0 %cl_common% %auto_compile_flags%
set clang_debug= call clang -g -O0 -DBUILD_DEBUG=1 %clang_common% %auto_compile_flags% set clang_debug= call clang -g -O0 -DBUILD_DEBUG=1 %clang_common% %auto_compile_flags%
set clang_release= call clang -g -O2 -DBUILD_DEBUG=0 %clang_common% %auto_compile_flags% set clang_release= call clang -g -O2 -DBUILD_DEBUG=0 %clang_common% %auto_compile_flags%
set cl_link= /link /MANIFEST:EMBED /INCREMENTAL:NO /natvis:"%~dp0\src\natvis\base.natvis" /pdbaltpath:%%%%_PDB%%%% logo.res set cl_link= /link /MANIFEST:EMBED /INCREMENTAL:NO /pdbaltpath:%%%%_PDB%%%%
set clang_link= -fuse-ld=lld -Xlinker /MANIFEST:EMBED -Xlinker /natvis:"%~dp0\src\natvis\base.natvis" logo.res -Xlinker /pdbaltpath:%%%%_PDB%%%% set clang_link= -fuse-ld=lld -Xlinker /MANIFEST:EMBED -Xlinker /pdbaltpath:%%%%_PDB%%%%
set cl_out= /out: set cl_out= /out:
set clang_out= -o set clang_out= -o
:: --- NATVIS -----------------------------------------------------------------
set natvis= /NATVIS:"%~dp0\src\natvis\base.natvis"
if "%radlink%"=="1" set natvis= %natvis% /NATVIS:"%~dp0\src\linker\linker.natvis"
if "%clang%"=="1" (
set result=
for %%n in (%natvis%) do set result= !result! -Xlinker %%n
set natvis= !result!
)
:: --- Per-Build Settings ----------------------------------------------------- :: --- Per-Build Settings -----------------------------------------------------
set link_dll=-DLL set link_dll=-DLL
set link_icon=logo.res
if "%msvc%"=="1" set only_compile=/c if "%msvc%"=="1" set only_compile=/c
if "%clang%"=="1" set only_compile=-c if "%clang%"=="1" set only_compile=-c
if "%msvc%"=="1" set EHsc=/EHsc if "%msvc%"=="1" set EHsc=/EHsc
@@ -76,6 +87,9 @@ if "%clang%"=="1" set out=%clang_out%
if "%debug%"=="1" set compile=%compile_debug% if "%debug%"=="1" set compile=%compile_debug%
if "%release%"=="1" set compile=%compile_release% if "%release%"=="1" set compile=%compile_release%
:: --- Append NATVIS to link line ---------------------------------------------
set compile_link= %compile_link% %natvis%
:: --- Prep Directories ------------------------------------------------------- :: --- Prep Directories -------------------------------------------------------
if not exist build mkdir build if not exist build mkdir build
if not exist local mkdir local if not exist local mkdir local
@@ -86,7 +100,8 @@ pushd build
popd popd
:: --- Get Current Git Commit Id ---------------------------------------------- :: --- Get Current Git Commit Id ----------------------------------------------
for /f %%i in ('call git describe --always --dirty') do set compile=%compile% -DBUILD_GIT_HASH=\"%%i\" for /f %%i in ('call git describe --always --dirty') do set compile=%compile% -DBUILD_GIT_HASH=\"%%i\"
for /f %%i in ('call git rev-parse HEAD') do set compile=%compile% -DBUILD_GIT_HASH_FULL=\"%%i\"
:: --- Build & Run Metaprogram ------------------------------------------------ :: --- Build & Run Metaprogram ------------------------------------------------
if "%no_meta%"=="1" echo [skipping metagen] if "%no_meta%"=="1" echo [skipping metagen]
@@ -99,12 +114,16 @@ if not "%no_meta%"=="1" (
:: --- Build Everything (@build_targets) -------------------------------------- :: --- Build Everything (@build_targets) --------------------------------------
pushd build pushd build
if "%raddbg%"=="1" set didbuild=1 && %compile% ..\src\raddbg\raddbg_main.c %compile_link% %out%raddbg.exe || exit /b 1 if "%raddbg%"=="1" set didbuild=1 && %compile% ..\src\raddbg\raddbg_main.c %compile_link% %link_icon% %out%raddbg.exe || exit /b 1
if "%radlink%"=="1" set didbuild=1 && %compile% ..\src\linker\lnk.c %compile_link% %out%radlink.exe || exit /b 1
if "%rdi_from_pdb%"=="1" set didbuild=1 && %compile% ..\src\rdi_from_pdb\rdi_from_pdb_main.c %compile_link% %out%rdi_from_pdb.exe || exit /b 1 if "%rdi_from_pdb%"=="1" set didbuild=1 && %compile% ..\src\rdi_from_pdb\rdi_from_pdb_main.c %compile_link% %out%rdi_from_pdb.exe || exit /b 1
if "%rdi_from_dwarf%"=="1" set didbuild=1 && %compile% ..\src\rdi_from_dwarf\rdi_from_dwarf.c %compile_link% %out%rdi_from_dwarf.exe || exit /b 1 if "%rdi_from_dwarf%"=="1" set didbuild=1 && %compile% ..\src\rdi_from_dwarf\rdi_from_dwarf.c %compile_link% %out%rdi_from_dwarf.exe || exit /b 1
if "%rdi_dump%"=="1" set didbuild=1 && %compile% ..\src\rdi_dump\rdi_dump_main.c %compile_link% %out%rdi_dump.exe || exit /b 1 if "%rdi_dump%"=="1" set didbuild=1 && %compile% ..\src\rdi_dump\rdi_dump_main.c %compile_link% %out%rdi_dump.exe || exit /b 1
if "%rdi_breakpad_from_pdb%"=="1" set didbuild=1 && %compile% ..\src\rdi_breakpad_from_pdb\rdi_breakpad_from_pdb_main.c %compile_link% %out%rdi_breakpad_from_pdb.exe || exit /b 1 if "%rdi_breakpad_from_pdb%"=="1" set didbuild=1 && %compile% ..\src\rdi_breakpad_from_pdb\rdi_breakpad_from_pdb_main.c %compile_link% %out%rdi_breakpad_from_pdb.exe || exit /b 1
if "%tester%"=="1" set didbuild=1 && %compile% ..\src\tester\tester_main.c %compile_link% %out%tester.exe || exit /b 1
if "%ryan_scratch%"=="1" set didbuild=1 && %compile% ..\src\scratch\ryan_scratch.c %compile_link% %out%ryan_scratch.exe || exit /b 1 if "%ryan_scratch%"=="1" set didbuild=1 && %compile% ..\src\scratch\ryan_scratch.c %compile_link% %out%ryan_scratch.exe || exit /b 1
if "%textperf%"=="1" set didbuild=1 && %compile% ..\src\scratch\textperf.c %compile_link% %out%textperf.exe || exit /b 1
if "%parse_inline_sites%"=="1" set didbuild=1 && %compile% ..\src\scratch\parse_inline_sites.c %compile_link% %out%parse_inline_sites.exe || exit /b 1
if "%mule_main%"=="1" set didbuild=1 && del vc*.pdb mule*.pdb && %compile_release% %only_compile% ..\src\mule\mule_inline.cpp && %compile_release% %only_compile% ..\src\mule\mule_o2.cpp && %compile_debug% %EHsc% ..\src\mule\mule_main.cpp ..\src\mule\mule_c.c mule_inline.obj mule_o2.obj %compile_link% %no_aslr% %out%mule_main.exe || exit /b 1 if "%mule_main%"=="1" set didbuild=1 && del vc*.pdb mule*.pdb && %compile_release% %only_compile% ..\src\mule\mule_inline.cpp && %compile_release% %only_compile% ..\src\mule\mule_o2.cpp && %compile_debug% %EHsc% ..\src\mule\mule_main.cpp ..\src\mule\mule_c.c mule_inline.obj mule_o2.obj %compile_link% %no_aslr% %out%mule_main.exe || exit /b 1
if "%mule_module%"=="1" set didbuild=1 && %compile% ..\src\mule\mule_module.cpp %compile_link% %link_dll% %out%mule_module.dll || exit /b 1 if "%mule_module%"=="1" set didbuild=1 && %compile% ..\src\mule\mule_module.cpp %compile_link% %link_dll% %out%mule_module.dll || exit /b 1
if "%mule_hotload%"=="1" set didbuild=1 && %compile% ..\src\mule\mule_hotload_main.c %compile_link% %out%mule_hotload.exe & %compile% ..\src\mule\mule_hotload_module_main.c %compile_link% %link_dll% %out%mule_hotload_module.dll || exit /b 1 if "%mule_hotload%"=="1" set didbuild=1 && %compile% ..\src\mule\mule_hotload_main.c %compile_link% %out%mule_hotload.exe & %compile% ..\src\mule\mule_hotload_module_main.c %compile_link% %link_dll% %out%mule_hotload_module.dll || exit /b 1
@@ -118,16 +137,6 @@ if "%mule_peb_trample%"=="1" (
) )
popd popd
:: --- Unset ------------------------------------------------------------------
for %%a in (%*) do set "%%a=0"
set raddbg=
set compile=
set compile_link=
set out=
set msvc=
set debug=
set release=
:: --- Warn On No Builds ------------------------------------------------------ :: --- Warn On No Builds ------------------------------------------------------
if "%didbuild%"=="" ( if "%didbuild%"=="" (
echo [WARNING] no valid build target specified; must use build target names as arguments to this script, like `build raddbg` or `build rdi_from_pdb`. echo [WARNING] no valid build target specified; must use build target names as arguments to this script, like `build raddbg` or `build rdi_from_pdb`.
+7 -2
View File
@@ -14,13 +14,17 @@ if [ -v gcc ]; then compiler="${CC:-gcc}"; echo "[gcc compile]"; fi
# --- Unpack Command Line Build Arguments ------------------------------------- # --- Unpack Command Line Build Arguments -------------------------------------
auto_compile_flags='' auto_compile_flags=''
# --- Get Current Git Commit Id -----------------------------------------------
git_hash=$(git rev-parse HEAD)
git_hash_full=$(git rev-parse HEAD)
# --- Compile/Link Line Definitions ------------------------------------------- # --- Compile/Link Line Definitions -------------------------------------------
clang_common='-I../src/ -I../local/ -g -Wno-unknown-warning-option -fdiagnostics-absolute-paths -Wall -Wno-missing-braces -Wno-unused-function -Wno-writable-strings -Wno-unused-value -Wno-unused-variable -Wno-unused-local-typedef -Wno-deprecated-register -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-single-bit-bitfield-constant-conversion -Wno-compare-distinct-pointer-types -Wno-initializer-overrides -Wno-incompatible-pointer-types-discards-qualifiers -Wno-for-loop-analysis -Xclang -flto-visibility-public-std -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf' clang_common="-I../src/ -I../local/ -g -DBUILD_GIT_HASH=\"$git_hash\" -DBUILD_GIT_HASH_FULL=\"$git_hash_full\" -Wno-unknown-warning-option -fdiagnostics-absolute-paths -Wall -Wno-missing-braces -Wno-unused-function -Wno-writable-strings -Wno-unused-value -Wno-unused-variable -Wno-unused-local-typedef -Wno-deprecated-register -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-single-bit-bitfield-constant-conversion -Wno-compare-distinct-pointer-types -Wno-initializer-overrides -Wno-incompatible-pointer-types-discards-qualifiers -Wno-for-loop-analysis -Xclang -flto-visibility-public-std -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf"
clang_debug="$compiler -g -O0 -DBUILD_DEBUG=1 ${clang_common} ${auto_compile_flags}" clang_debug="$compiler -g -O0 -DBUILD_DEBUG=1 ${clang_common} ${auto_compile_flags}"
clang_release="$compiler -g -O2 -DBUILD_DEBUG=0 ${clang_common} ${auto_compile_flags}" clang_release="$compiler -g -O2 -DBUILD_DEBUG=0 ${clang_common} ${auto_compile_flags}"
clang_link="-lpthread -lm -lrt -ldl" clang_link="-lpthread -lm -lrt -ldl"
clang_out="-o" clang_out="-o"
gcc_common='-I../src/ -I../local/ -g -Wno-unknown-warning-option -Wall -Wno-missing-braces -Wno-unused-function -Wno-attributes -Wno-unused-value -Wno-unused-variable -Wno-unused-local-typedef -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-compare-distinct-pointer-types -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf' gcc_common="-I../src/ -I../local/ -g -DBUILD_GIT_HASH=\"$git_hash\" -DBUILD_GIT_HASH_FULL=\"$git_hash_full\" -Wno-unknown-warning-option -Wall -Wno-missing-braces -Wno-unused-function -Wno-attributes -Wno-unused-value -Wno-unused-variable -Wno-unused-local-typedef -Wno-deprecated-declarations -Wno-unused-but-set-variable -Wno-compare-distinct-pointer-types -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf"
gcc_debug="$compiler -g -O0 -DBUILD_DEBUG=1 ${gcc_common} ${auto_compile_flags}" gcc_debug="$compiler -g -O0 -DBUILD_DEBUG=1 ${gcc_common} ${auto_compile_flags}"
gcc_release="$compiler -g -O2 -DBUILD_DEBUG=0 ${gcc_common} ${auto_compile_flags}" gcc_release="$compiler -g -O2 -DBUILD_DEBUG=0 ${gcc_common} ${auto_compile_flags}"
gcc_link="-lpthread -lm -lrt -ldl" gcc_link="-lpthread -lm -lrt -ldl"
@@ -59,6 +63,7 @@ fi
# --- Build Everything (@build_targets) --------------------------------------- # --- Build Everything (@build_targets) ---------------------------------------
cd build cd build
if [ -v raddbg ]; then didbuild=1 && $compile ../src/raddbg/raddbg_main.c $compile_link $link_os_gfx $out raddbg; fi if [ -v raddbg ]; then didbuild=1 && $compile ../src/raddbg/raddbg_main.c $compile_link $link_os_gfx $out raddbg; fi
if [ -v radlink ]; then didbuild=1 && $compile ../src/linker/lnk.c $compile_link $out radlink; fi
if [ -v rdi_from_pdb ]; then didbuild=1 && $compile ../src/rdi_from_pdb/rdi_from_pdb_main.c $compile_link $out rdi_from_pdb; fi if [ -v rdi_from_pdb ]; then didbuild=1 && $compile ../src/rdi_from_pdb/rdi_from_pdb_main.c $compile_link $out rdi_from_pdb; fi
if [ -v rdi_from_dwarf ]; then didbuild=1 && $compile ../src/rdi_from_dwarf/rdi_from_dwarf.c $compile_link $out rdi_from_dwarf; fi if [ -v rdi_from_dwarf ]; then didbuild=1 && $compile ../src/rdi_from_dwarf/rdi_from_dwarf.c $compile_link $out rdi_from_dwarf; fi
if [ -v rdi_dump ]; then didbuild=1 && $compile ../src/rdi_dump/rdi_dump_main.c $compile_link $out rdi_dump; fi if [ -v rdi_dump ]; then didbuild=1 && $compile ../src/rdi_dump/rdi_dump_main.c $compile_link $out rdi_dump; fi
+2
View File
@@ -49,6 +49,8 @@ commands =
.f1 = { .win = "build raddbg telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, .f1 = { .win = "build raddbg telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
.f2 = { .win = "build rdi_from_pdb", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, .f2 = { .win = "build rdi_from_pdb", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
.f3 = { .win = "pushd build && raddbg.exe --user:local_dev.raddbg_user --project:local_dev.raddbg_project --xuto_run && popd",.linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, .f3 = { .win = "pushd build && raddbg.exe --user:local_dev.raddbg_user --project:local_dev.raddbg_project --xuto_run && popd",.linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
// .f1 = { .win = "build textperf release telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
// .f3 = { .win = "pushd build && textperf.exe --capture && popd",.linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
//- rjf: local target builds //- rjf: local target builds
.build_raddbg = { .win = "build raddbg", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, .build_raddbg = { .win = "build raddbg", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
+21
View File
@@ -0,0 +1,21 @@
@echo off
setlocal
cd /D "%~dp0"
echo --- getting test data folder path ---------------------------------------------
if not exist .\local\test_data_path.txt (
echo error: You must first store the full path of your test data folder inside of `local/test_data_path.txt`.
goto :EOF
)
set /p test_data_folder=<.\local\test_data_path.txt
echo test data path: %test_data_folder%
echo:
echo --- building all testing executables ------------------------------------------
call build rdi_from_pdb rdi_dump raddbg radlink tester
echo:
echo --- running tests -------------------------------------------------------------
pushd build
call tester.exe --test_data:%test_data_folder%
popd
+15
View File
@@ -0,0 +1,15 @@
Clear-Host
$path_root = git rev-parse --show-toplevel
if ($IsWindows) {
$devshell = Join-Path $path_root 'scripts/helpers/devshell.ps1'
& $devshell -arch amd64
}
Push-Location $path_root
$build_bat = Join-Path $path_root 'build.bat'
& $build_bat @args
Pop-Location
+10
View File
@@ -0,0 +1,10 @@
Clear-Host
$path_root = git rev-parse --show-toplevel
$build_dir = Join-Path $path_root 'build'
if (Test-Path $build_dir) {
Get-ChildItem -Path $build_dir -Recurse | Remove-Item -Force -Recurse
Write-Host "Build directory cleaned."
} else {
Write-Host "Build directory does not exist."
}
+28
View File
@@ -0,0 +1,28 @@
if ($env:VCINSTALLDIR) {
return
}
$ErrorActionPreference = "Stop"
# Use vswhere to find the latest Visual Studio installation
$vswhere_out = & "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath
if ($null -eq $vswhere_out) {
Write-Host "ERROR: Visual Studio installation not found"
exit 1
}
# Find Launch-VsDevShell.ps1 in the Visual Studio installation
$vs_path = $vswhere_out
$vs_devshell = Join-Path $vs_path "\Common7\Tools\Launch-VsDevShell.ps1"
if ( -not (Test-Path $vs_devshell) ) {
Write-Host "ERROR: Launch-VsDevShell.ps1 not found in Visual Studio installation"
Write-Host Tested path: $vs_devshell
exit 1
}
# Launch the Visual Studio Developer Shell
Push-Location
write-host @args
& $vs_devshell @args
Pop-Location
+240
View File
@@ -0,0 +1,240 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: Top-Level Layer Initialization
internal void
async_init(void)
{
Arena *arena = arena_alloc();
async_shared = push_array(arena, ASYNC_Shared, 1);
async_shared->arena = arena;
for EachEnumVal(ASYNC_Priority, p)
{
ASYNC_Ring *ring = &async_shared->rings[p];
ring->ring_size = MB(8);
ring->ring_base = push_array_no_zero(arena, U8, ring->ring_size);
ring->ring_mutex = os_mutex_alloc();
ring->ring_cv = os_condition_variable_alloc();
}
async_shared->ring_mutex = os_mutex_alloc();
async_shared->ring_cv = os_condition_variable_alloc();
async_shared->work_threads_count = Max(1, os_get_system_info()->logical_processor_count-1);
async_shared->work_threads = push_array(arena, OS_Handle, async_shared->work_threads_count);
for EachIndex(idx, async_shared->work_threads_count)
{
async_shared->work_threads[idx] = os_thread_launch(async_work_thread__entry_point, (void *)idx, 0);
}
}
////////////////////////////////
//~ rjf: Top-Level Accessors
internal U64
async_thread_count(void)
{
return async_shared->work_threads_count;
}
////////////////////////////////
//~ rjf: Work Kickoffs
internal B32
async_push_work_(ASYNC_WorkFunctionType *work_function, ASYNC_WorkParams *params)
{
// rjf: choose ring
ASYNC_Ring *ring = &async_shared->rings[params->priority];
// rjf: build work package
ASYNC_Work work = {0};
work.work_function = work_function;
work.input = params->input;
work.output = params->output;
work.semaphore = params->semaphore;
work.completion_counter = params->completion_counter;
// rjf: loop; try to write into user -> writer ring buffer. if we're on a
// worker thread, determine if we need to execute this task locally on this
// thread, and skip ring buffer if so.
B32 queued_in_ring_buffer = 0;
B32 need_to_execute_on_this_thread = 0;
OS_MutexScope(ring->ring_mutex) for(;;)
{
U64 num_available_work_threads = (async_shared->work_threads_count - ins_atomic_u64_eval(&async_shared->work_threads_live_count));
if(num_available_work_threads == 0 && async_work_thread_depth > 0)
{
need_to_execute_on_this_thread = 1;
break;
}
U64 unconsumed_size = ring->ring_write_pos - ring->ring_read_pos;
U64 available_size = ring->ring_size - unconsumed_size;
if(available_size >= sizeof(work))
{
queued_in_ring_buffer = 1;
if(!os_handle_match(params->semaphore, os_handle_zero()))
{
os_semaphore_take(params->semaphore, max_U64);
}
ring->ring_write_pos += ring_write_struct(ring->ring_base, ring->ring_size, ring->ring_write_pos, &work);
break;
}
if(os_now_microseconds() >= params->endt_us)
{
break;
}
os_condition_variable_wait(ring->ring_cv, ring->ring_mutex, params->endt_us);
}
// rjf: broadcast ring buffer cv if we wrote successfully
if(queued_in_ring_buffer)
{
os_condition_variable_broadcast(ring->ring_cv);
os_condition_variable_broadcast(async_shared->ring_cv);
}
// rjf: if we did not queue successfully, and we have determined that
// we need to execute this work on the current thread, then execute the
// work before returning
if(need_to_execute_on_this_thread)
{
async_execute_work(work);
}
// rjf: return success signal
B32 result = (queued_in_ring_buffer || need_to_execute_on_this_thread);
return result;
}
////////////////////////////////
//~ rjf: Task-Based Work Helper
internal void
async_task_list_push(Arena *arena, ASYNC_TaskList *list, ASYNC_Task *t)
{
ASYNC_TaskNode *n = push_array(arena, ASYNC_TaskNode, 1);
SLLQueuePush(list->first, list->last, n);
n->v = t;
list->count += 1;
}
internal ASYNC_Task *
async_task_launch_(Arena *arena, ASYNC_WorkFunctionType *work_function, ASYNC_WorkParams *params)
{
ASYNC_Task *task = push_array(arena, ASYNC_Task, 1);
task->semaphore = os_semaphore_alloc(1, 1, str8_zero());
ASYNC_WorkParams params_refined = {0};
MemoryCopyStruct(&params_refined, params);
params_refined.endt_us = max_U64;
params_refined.semaphore = task->semaphore;
if(params_refined.output == 0)
{
params_refined.output = &task->output;
}
async_push_work_(work_function, &params_refined);
return task;
}
internal void *
async_task_join(ASYNC_Task *task)
{
void *result = 0;
if(task != 0 && !os_handle_match(task->semaphore, os_handle_zero()))
{
os_semaphore_take(task->semaphore, max_U64);
os_semaphore_release(task->semaphore);
MemoryZeroStruct(&task->semaphore);
result = (void *)ins_atomic_u64_eval(&task->output);
}
return result;
}
////////////////////////////////
//~ rjf: Work Execution
internal ASYNC_Work
async_pop_work(void)
{
ProfBeginFunction();
ASYNC_Work work = {0};
B32 done = 0;
ASYNC_Priority taken_priority = ASYNC_Priority_Low;
OS_MutexScope(async_shared->ring_mutex) for(;!done;)
{
for(ASYNC_Priority priority = ASYNC_Priority_High;; priority = (ASYNC_Priority)(priority - 1))
{
ASYNC_Ring *ring = &async_shared->rings[priority];
OS_MutexScope(ring->ring_mutex)
{
U64 unconsumed_size = ring->ring_write_pos - ring->ring_read_pos;
if(unconsumed_size >= sizeof(work))
{
ring->ring_read_pos += ring_read_struct(ring->ring_base, ring->ring_size, ring->ring_read_pos, &work);
done = 1;
taken_priority = priority;
}
}
if(done)
{
break;
}
if(priority == ASYNC_Priority_Low)
{
break;
}
}
if(!done)
{
os_condition_variable_wait(async_shared->ring_cv, async_shared->ring_mutex, max_U64);
}
}
os_condition_variable_broadcast(async_shared->ring_cv);
os_condition_variable_broadcast(async_shared->rings[taken_priority].ring_cv);
ProfEnd();
return work;
}
internal void
async_execute_work(ASYNC_Work work)
{
//- rjf: run work
async_work_thread_depth += 1;
void *work_out = work.work_function(async_work_thread_idx, work.input);
async_work_thread_depth -= 1;
//- rjf: store output
if(work.output != 0)
{
ins_atomic_u64_eval_assign((U64 *)work.output, (U64)work_out);
}
//- rjf: release semaphore
if(!os_handle_match(work.semaphore, os_handle_zero()))
{
os_semaphore_drop(work.semaphore);
}
//- rjf: increment completion counter
if(work.completion_counter != 0)
{
ins_atomic_u64_inc_eval(work.completion_counter);
}
}
////////////////////////////////
//~ rjf: Work Thread Entry Point
internal void
async_work_thread__entry_point(void *p)
{
U64 thread_idx = (U64)p;
ThreadNameF("[async] work thread #%I64u", thread_idx);
async_work_thread_idx = thread_idx;
for(;;)
{
ASYNC_Work work = async_pop_work();
ins_atomic_u64_inc_eval(&async_shared->work_threads_live_count);
async_execute_work(work);
ins_atomic_u64_dec_eval(&async_shared->work_threads_live_count);
}
}
+144
View File
@@ -0,0 +1,144 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef ASYNC_H
#define ASYNC_H
////////////////////////////////
//~ rjf: Work Function Type
#define ASYNC_WORK_SIG(name) void *name(U64 thread_idx, void *input)
#define ASYNC_WORK_DEF(name) internal ASYNC_WORK_SIG(name)
typedef ASYNC_WORK_SIG(ASYNC_WorkFunctionType);
////////////////////////////////
//~ rjf: Work Types
typedef enum ASYNC_Priority
{
ASYNC_Priority_Low,
ASYNC_Priority_High,
ASYNC_Priority_COUNT
}
ASYNC_Priority;
typedef struct ASYNC_WorkParams ASYNC_WorkParams;
struct ASYNC_WorkParams
{
void *input;
void **output;
OS_Handle semaphore;
U64 *completion_counter;
U64 endt_us;
ASYNC_Priority priority;
};
typedef struct ASYNC_Work ASYNC_Work;
struct ASYNC_Work
{
ASYNC_WorkFunctionType *work_function;
void *input;
void **output;
OS_Handle semaphore;
U64 *completion_counter;
};
////////////////////////////////
//~ rjf: Task-Based Work Types
typedef struct ASYNC_Task ASYNC_Task;
struct ASYNC_Task
{
OS_Handle semaphore;
void *output;
};
typedef struct ASYNC_TaskNode ASYNC_TaskNode;
struct ASYNC_TaskNode
{
ASYNC_TaskNode *next;
ASYNC_Task *v;
};
typedef struct ASYNC_TaskList ASYNC_TaskList;
struct ASYNC_TaskList
{
ASYNC_TaskNode *first;
ASYNC_TaskNode *last;
U64 count;
};
////////////////////////////////
//~ rjf: Shared State Bundle
typedef struct ASYNC_Ring ASYNC_Ring;
struct ASYNC_Ring
{
U64 ring_size;
U8 *ring_base;
U64 ring_write_pos;
U64 ring_read_pos;
OS_Handle ring_mutex;
OS_Handle ring_cv;
};
typedef struct ASYNC_Shared ASYNC_Shared;
struct ASYNC_Shared
{
Arena *arena;
// rjf: user -> work thread ring buffers
ASYNC_Ring rings[ASYNC_Priority_COUNT];
OS_Handle ring_mutex;
OS_Handle ring_cv;
// rjf: work threads
OS_Handle *work_threads;
U64 work_threads_count;
U64 work_threads_live_count;
};
////////////////////////////////
//~ rjf: Globals
thread_static B32 async_work_thread_depth = 0;
thread_static U64 async_work_thread_idx = 0;
global ASYNC_Shared *async_shared = 0;
////////////////////////////////
//~ rjf: Top-Level Layer Initialization
internal void async_init(void);
////////////////////////////////
//~ rjf: Top-Level Accessors
internal U64 async_thread_count(void);
////////////////////////////////
//~ rjf: Work Kickoffs
internal B32 async_push_work_(ASYNC_WorkFunctionType *work_function, ASYNC_WorkParams *params);
#define async_push_work(function, ...) async_push_work_((function), &(ASYNC_WorkParams){.endt_us = max_U64, .priority = ASYNC_Priority_High, __VA_ARGS__})
////////////////////////////////
//~ rjf: Task-Based Work Helper
internal void async_task_list_push(Arena *arena, ASYNC_TaskList *list, ASYNC_Task *t);
internal ASYNC_Task *async_task_launch_(Arena *arena, ASYNC_WorkFunctionType *work_function, ASYNC_WorkParams *params);
#define async_task_launch(arena, work_function, ...) async_task_launch_((arena), (work_function), &(ASYNC_WorkParams){.endt_us = max_U64, __VA_ARGS__})
internal void *async_task_join(ASYNC_Task *task);
#define async_task_join_struct(task, T) (T *)async_task_join(task)
////////////////////////////////
//~ rjf: Work Execution
internal ASYNC_Work async_pop_work(void);
internal void async_execute_work(ASYNC_Work work);
////////////////////////////////
//~ rjf: Work Thread Entry Point
internal void async_work_thread__entry_point(void *p);
#endif // ASYNC_H
+53 -9
View File
@@ -52,12 +52,16 @@ arena_alloc_(ArenaParams *params)
Arena *arena = (Arena *)base; Arena *arena = (Arena *)base;
arena->current = arena; arena->current = arena;
arena->flags = params->flags; arena->flags = params->flags;
arena->cmt_size = (U32)params->commit_size; arena->cmt_size = params->commit_size;
arena->res_size = params->reserve_size; arena->res_size = params->reserve_size;
arena->base_pos = 0; arena->base_pos = 0;
arena->pos = ARENA_HEADER_SIZE; arena->pos = ARENA_HEADER_SIZE;
arena->cmt = commit_size; arena->cmt = commit_size;
arena->res = reserve_size; arena->res = reserve_size;
#if ARENA_FREE_LIST
arena->free_size = 0;
arena->free_last = 0;
#endif
AsanPoisonMemoryRegion(base, commit_size); AsanPoisonMemoryRegion(base, commit_size);
AsanUnpoisonMemoryRegion(base, ARENA_HEADER_SIZE); AsanUnpoisonMemoryRegion(base, ARENA_HEADER_SIZE);
return arena; return arena;
@@ -85,18 +89,46 @@ arena_push(Arena *arena, U64 size, U64 align)
// rjf: chain, if needed // rjf: chain, if needed
if(current->res < pos_pst && !(arena->flags & ArenaFlag_NoChain)) if(current->res < pos_pst && !(arena->flags & ArenaFlag_NoChain))
{ {
U64 res_size = current->res_size; Arena *new_block = 0;
U64 cmt_size = current->cmt_size;
if(size + ARENA_HEADER_SIZE > res_size) #if ARENA_FREE_LIST
Arena *prev_block;
for(new_block = arena->free_last, prev_block = 0; new_block != 0; prev_block = new_block, new_block = new_block->prev)
{ {
res_size = size + ARENA_HEADER_SIZE; if(new_block->res >= AlignPow2(size, align))
cmt_size = size + ARENA_HEADER_SIZE; {
if(prev_block)
{
prev_block->prev = new_block->prev;
}
else
{
arena->free_last = new_block->prev;
}
arena->free_size -= new_block->res_size;
AsanUnpoisonMemoryRegion((U8*)new_block + ARENA_HEADER_SIZE, new_block->res_size - ARENA_HEADER_SIZE);
break;
}
} }
Arena *new_block = arena_alloc(.reserve_size = res_size, #endif
.commit_size = cmt_size,
.flags = current->flags); if(new_block == 0)
{
U64 res_size = current->res_size;
U64 cmt_size = current->cmt_size;
if(size + ARENA_HEADER_SIZE > res_size)
{
res_size = AlignPow2(size + ARENA_HEADER_SIZE, align);
cmt_size = AlignPow2(size + ARENA_HEADER_SIZE, align);
}
new_block = arena_alloc(.reserve_size = res_size,
.commit_size = cmt_size,
.flags = current->flags);
}
new_block->base_pos = current->base_pos + current->res; new_block->base_pos = current->base_pos + current->res;
SLLStackPush_N(arena->current, new_block, prev); SLLStackPush_N(arena->current, new_block, prev);
current = new_block; current = new_block;
pos_pre = AlignPow2(current->pos, align); pos_pre = AlignPow2(current->pos, align);
pos_pst = pos_pre + size; pos_pst = pos_pre + size;
@@ -155,11 +187,23 @@ arena_pop_to(Arena *arena, U64 pos)
{ {
U64 big_pos = ClampBot(ARENA_HEADER_SIZE, pos); U64 big_pos = ClampBot(ARENA_HEADER_SIZE, pos);
Arena *current = arena->current; Arena *current = arena->current;
#if ARENA_FREE_LIST
for(Arena *prev = 0; current->base_pos >= big_pos; current = prev)
{
prev = current->prev;
current->pos = ARENA_HEADER_SIZE;
arena->free_size += current->res_size;
SLLStackPush_N(arena->free_last, current, prev);
AsanPoisonMemoryRegion((U8*)current + ARENA_HEADER_SIZE, current->res_size - ARENA_HEADER_SIZE);
}
#else
for(Arena *prev = 0; current->base_pos >= big_pos; current = prev) for(Arena *prev = 0; current->base_pos >= big_pos; current = prev)
{ {
prev = current->prev; prev = current->prev;
os_release(current, current->res); os_release(current, current->res);
} }
#endif
arena->current = current; arena->current = current;
U64 new_pos = big_pos - current->base_pos; U64 new_pos = big_pos - current->base_pos;
AssertAlways(new_pos <= current->pos); AssertAlways(new_pos <= current->pos);
+7 -3
View File
@@ -7,12 +7,12 @@
//////////////////////////////// ////////////////////////////////
//~ rjf: Constants //~ rjf: Constants
#define ARENA_HEADER_SIZE 64 #define ARENA_HEADER_SIZE 128
//////////////////////////////// ////////////////////////////////
//~ rjf: Types //~ rjf: Types
typedef U32 ArenaFlags; typedef U64 ArenaFlags;
enum enum
{ {
ArenaFlag_NoChain = (1<<0), ArenaFlag_NoChain = (1<<0),
@@ -34,12 +34,16 @@ struct Arena
Arena *prev; // previous arena in chain Arena *prev; // previous arena in chain
Arena *current; // current arena in chain Arena *current; // current arena in chain
ArenaFlags flags; ArenaFlags flags;
U32 cmt_size; U64 cmt_size;
U64 res_size; U64 res_size;
U64 base_pos; U64 base_pos;
U64 pos; U64 pos;
U64 cmt; U64 cmt;
U64 res; U64 res;
#if ARENA_FREE_LIST
U64 free_size;
Arena *free_last;
#endif
}; };
StaticAssert(sizeof(Arena) <= ARENA_HEADER_SIZE, arena_header_size_check); StaticAssert(sizeof(Arena) <= ARENA_HEADER_SIZE, arena_header_size_check);
+21 -3
View File
@@ -98,9 +98,10 @@ cmd_line_from_string_list(Arena *arena, String8List command_line)
next = node->next; next = node->next;
String8 option_name = node->string; String8 option_name = node->string;
// NOTE(rjf): Look at -- or - at the start of an argument to determine if it's // NOTE(rjf): Look at --, -, or / (only on Windows) at the start of an
// a flag option. All arguments after a single "--" (with no trailing string // argument to determine if it's a flag option. All arguments after a
// on the command line will be considered as input files. // single "--" (with no trailing string on the command line will be
// considered as input files.
B32 is_option = 1; B32 is_option = 1;
if(after_passthrough_option == 0) if(after_passthrough_option == 0)
{ {
@@ -117,6 +118,11 @@ cmd_line_from_string_list(Arena *arena, String8List command_line)
{ {
option_name = str8_skip(option_name, 1); option_name = str8_skip(option_name, 1);
} }
else if(operating_system_from_context() == OperatingSystem_Windows &&
str8_match(str8_prefix(node->string, 1), str8_lit("/"), 0))
{
option_name = str8_skip(option_name, 1);
}
else else
{ {
is_option = 0; is_option = 0;
@@ -184,6 +190,18 @@ cmd_line_from_string_list(Arena *arena, String8List command_line)
} }
} }
// rjf: fill argc/argv
parsed.argc = command_line.node_count;
parsed.argv = push_array(arena, char *, parsed.argc);
{
U64 idx = 0;
for(String8Node *n = command_line.first; n != 0; n = n->next)
{
parsed.argv[idx] = (char *)push_str8_copy(arena, n->string).str;
idx += 1;
}
}
return parsed; return parsed;
} }
+2
View File
@@ -34,6 +34,8 @@ struct CmdLine
String8List inputs; String8List inputs;
U64 option_table_size; U64 option_table_size;
CmdLineOpt **option_table; CmdLineOpt **option_table;
U64 argc;
char **argv;
}; };
//////////////////////////////// ////////////////////////////////
+2 -2
View File
@@ -155,11 +155,11 @@
#endif #endif
#if !defined(BUILD_VERSION_MINOR) #if !defined(BUILD_VERSION_MINOR)
# define BUILD_VERSION_MINOR 0 # define BUILD_VERSION_MINOR 9
#endif #endif
#if !defined(BUILD_VERSION_PATCH) #if !defined(BUILD_VERSION_PATCH)
# define BUILD_VERSION_PATCH 0 # define BUILD_VERSION_PATCH 14
#endif #endif
#define BUILD_VERSION_STRING_LITERAL Stringify(BUILD_VERSION_MAJOR) "." Stringify(BUILD_VERSION_MINOR) "." Stringify(BUILD_VERSION_PATCH) #define BUILD_VERSION_STRING_LITERAL Stringify(BUILD_VERSION_MAJOR) "." Stringify(BUILD_VERSION_MINOR) "." Stringify(BUILD_VERSION_PATCH)
+11 -23
View File
@@ -143,12 +143,6 @@ bswap_u64(U64 x)
#if COMPILER_MSVC || (COMPILER_CLANG && OS_WINDOWS) #if COMPILER_MSVC || (COMPILER_CLANG && OS_WINDOWS)
internal U64
count_bits_set16(U16 val)
{
return __popcnt16(val);
}
internal U64 internal U64
count_bits_set32(U32 val) count_bits_set32(U32 val)
{ {
@@ -195,46 +189,40 @@ clz64(U64 mask)
#elif COMPILER_CLANG || COMPILER_GCC #elif COMPILER_CLANG || COMPILER_GCC
internal U64
count_bits_set16(U16 val)
{
NotImplemented;
return 0;
}
internal U64 internal U64
count_bits_set32(U32 val) count_bits_set32(U32 val)
{ {
NotImplemented; return __builtin_popcount(val);
return 0;
} }
internal U64 internal U64
count_bits_set64(U64 val) count_bits_set64(U64 val)
{ {
NotImplemented; return __builtin_popcountll(val);
return 0;
} }
internal U64 internal U64
ctz32(U32 val) ctz32(U32 val)
{ {
NotImplemented; return __builtin_ctz(val);
return 0;
} }
internal U64 internal U64
clz32(U32 val) clz32(U32 val)
{ {
NotImplemented; return __builtin_clz(val);
return 0; }
internal U64
ctz64(U64 val)
{
return __builtin_ctzll(val);
} }
internal U64 internal U64
clz64(U64 val) clz64(U64 val)
{ {
NotImplemented; return __builtin_clzll(val);
return 0;
} }
#else #else
+59 -30
View File
@@ -40,6 +40,12 @@
# define thread_static __thread # define thread_static __thread
#endif #endif
#if COMPILER_MSVC
# define force_inline __forceinline
#elif COMPILER_CLANG || COMPILER_GCC
# define force_inline __attribute__((always_inline))
#endif
//////////////////////////////// ////////////////////////////////
//~ rjf: Linkage Keyword Macros //~ rjf: Linkage Keyword Macros
@@ -172,42 +178,49 @@
//////////////////////////////// ////////////////////////////////
//~ rjf: Atomic Operations //~ rjf: Atomic Operations
#if OS_WINDOWS #if COMPILER_MSVC
# include <windows.h>
# include <tmmintrin.h>
# include <wmmintrin.h>
# include <intrin.h> # include <intrin.h>
# if ARCH_X64 # if ARCH_X64
# define ins_atomic_u64_eval(x) InterlockedAdd64((volatile __int64 *)(x), 0) # define ins_atomic_u64_eval(x) *((volatile U64 *)(x))
# define ins_atomic_u64_inc_eval(x) InterlockedIncrement64((volatile __int64 *)(x)) # define ins_atomic_u64_inc_eval(x) InterlockedIncrement64((volatile __int64 *)(x))
# define ins_atomic_u64_dec_eval(x) InterlockedDecrement64((volatile __int64 *)(x)) # define ins_atomic_u64_dec_eval(x) InterlockedDecrement64((volatile __int64 *)(x))
# define ins_atomic_u64_eval_assign(x,c) InterlockedExchange64((volatile __int64 *)(x),(c)) # define ins_atomic_u64_eval_assign(x,c) InterlockedExchange64((volatile __int64 *)(x),(c))
# define ins_atomic_u64_add_eval(x,c) InterlockedAdd64((volatile __int64 *)(x), c) # define ins_atomic_u64_add_eval(x,c) InterlockedAdd64((volatile __int64 *)(x), c)
# define ins_atomic_u64_eval_cond_assign(x,k,c) InterlockedCompareExchange64((volatile __int64 *)(x),(k),(c)) # define ins_atomic_u64_eval_cond_assign(x,k,c) InterlockedCompareExchange64((volatile __int64 *)(x),(k),(c))
# define ins_atomic_u32_eval(x,c) InterlockedAdd((volatile LONG *)(x), 0) # define ins_atomic_u32_eval(x) *((volatile U32 *)(x))
# define ins_atomic_u32_eval_assign(x,c) InterlockedExchange((volatile LONG *)(x),(c)) # define ins_atomic_u32_inc_eval(x) InterlockedIncrement((volatile LONG *)x)
# define ins_atomic_u32_eval_assign(x,c) InterlockedExchange((volatile LONG *)(x),(c))
# define ins_atomic_u32_eval_cond_assign(x,k,c) InterlockedCompareExchange((volatile LONG *)(x),(k),(c)) # define ins_atomic_u32_eval_cond_assign(x,k,c) InterlockedCompareExchange((volatile LONG *)(x),(k),(c))
# define ins_atomic_ptr_eval_assign(x,c) (void*)ins_atomic_u64_eval_assign((volatile __int64 *)(x), (__int64)(c)) # define ins_atomic_u32_add_eval(x,c) InterlockedAdd((volatile LONG *)(x), c)
# else # else
# error Atomic intrinsics not defined for this operating system / architecture combination. # error Atomic intrinsics not defined for this compiler / architecture combination.
# endif
#elif OS_LINUX
# if ARCH_X64
# define ins_atomic_u64_eval(x) __sync_fetch_and_add((volatile U64 *)(x), 0)
# define ins_atomic_u64_inc_eval(x) __sync_fetch_and_add((volatile U64 *)(x), 1)
# define ins_atomic_u64_dec_eval(x) __sync_fetch_and_sub((volatile U64 *)(x), 1)
# define ins_atomic_u64_eval_assign(x,c) __sync_lock_test_and_set((volatile U64 *)(x),(c))
# define ins_atomic_u64_add_eval(x,c) __sync_fetch_and_add((volatile U64 *)(x), c)
# define ins_atomic_u64_eval_cond_assign(x,k,c) __sync_val_compare_and_swap((volatile U64 *)(x),(c),(k))
# define ins_atomic_u32_eval(x,c) __sync_fetch_and_add((volatile U32 *)(x), 0)
# define ins_atomic_u32_eval_assign(x,c) __sync_lock_test_and_set((volatile U32 *)(x),(c))
# define ins_atomic_u32_eval_cond_assign(x,k,c) __sync_val_compare_and_swap((volatile U32 *)(x),(c),(k))
# define ins_atomic_ptr_eval_assign(x,c) (void*)ins_atomic_u64_eval_assign((volatile U64 *)(x), (U64)(c))
# else
# error Atomic intrinsics not defined for this operating system / architecture combination.
# endif # endif
#elif COMPILER_CLANG || COMPILER_GCC
# define ins_atomic_u64_eval(x) __atomic_load_n(x, __ATOMIC_SEQ_CST)
# define ins_atomic_u64_inc_eval(x) (__atomic_fetch_add((volatile U64 *)(x), 1, __ATOMIC_SEQ_CST) + 1)
# define ins_atomic_u64_dec_eval(x) (__atomic_fetch_sub((volatile U64 *)(x), 1, __ATOMIC_SEQ_CST) - 1)
# define ins_atomic_u64_eval_assign(x,c) __atomic_exchange_n(x, c, __ATOMIC_SEQ_CST)
# define ins_atomic_u64_add_eval(x,c) (__atomic_fetch_add((volatile U64 *)(x), c, __ATOMIC_SEQ_CST) + (c))
# define ins_atomic_u64_eval_cond_assign(x,k,c) ({ U64 _new = (c); __atomic_compare_exchange_n((volatile U64 *)(x),&_new,(k),0,__ATOMIC_SEQ_CST,__ATOMIC_SEQ_CST); _new; })
# define ins_atomic_u32_eval(x) __atomic_load_n(x, __ATOMIC_SEQ_CST)
# define ins_atomic_u32_inc_eval(x) (__atomic_fetch_add((volatile U32 *)(x), 1, __ATOMIC_SEQ_CST) + 1)
# define ins_atomic_u32_add_eval(x,c) (__atomic_fetch_add((volatile U32 *)(x), c, __ATOMIC_SEQ_CST) + (c))
# define ins_atomic_u32_eval_assign(x,c) __atomic_exchange_n(x, c, __ATOMIC_SEQ_CST)
# define ins_atomic_u32_eval_cond_assign(x,k,c) ({ U32 _new = (c); __atomic_compare_exchange_n((volatile U32 *)(x),&_new,(k),0,__ATOMIC_SEQ_CST,__ATOMIC_SEQ_CST); _new; })
#else #else
# error Atomic intrinsics not defined for this operating system. # error Atomic intrinsics not defined for this compiler / architecture.
#endif
#if ARCH_64BIT
# define ins_atomic_ptr_eval_cond_assign(x,k,c) (void*)ins_atomic_u64_eval_cond_assign((volatile U64 *)(x), (U64)(k), (U64)(c))
# define ins_atomic_ptr_eval_assign(x,c) (void*)ins_atomic_u64_eval_assign((volatile U64 *)(x), (U64)(c))
# define ins_atomic_ptr_eval(x) (void*)ins_atomic_u64_eval((volatile U64 *)x)
#elif ARCH_32BIT
# define ins_atomic_ptr_eval_cond_assign(x,k,c) (void*)ins_atomic_u32_eval_cond_assign((volatile U32 *)(x), (U32)(k), (U32)(c))
# define ins_atomic_ptr_eval_assign(x,c) (void*)ins_atomic_u32_eval_assign((volatile U32 *)(x), (U32)(c))
# define ins_atomic_ptr_eval(x) (void*)ins_atomic_u32_eval((volatile U32 *)x)
#else
# error Atomic intrinsics for pointers not defined for this architecture.
#endif #endif
//////////////////////////////// ////////////////////////////////
@@ -479,6 +492,23 @@ struct TxtRng
TxtPt max; TxtPt max;
}; };
////////////////////////////////
//~ Globally Unique Ids
typedef union Guid Guid;
union Guid
{
struct
{
U32 data1;
U16 data2;
U16 data3;
U8 data4[8];
};
U8 v[16];
};
StaticAssert(sizeof(Guid) == 16, g_guid_size_check);
//////////////////////////////// ////////////////////////////////
//~ NOTE(allen): Constants //~ NOTE(allen): Constants
@@ -745,7 +775,6 @@ internal U16 bswap_u16(U16 x);
internal U32 bswap_u32(U32 x); internal U32 bswap_u32(U32 x);
internal U64 bswap_u64(U64 x); internal U64 bswap_u64(U64 x);
internal U64 count_bits_set16(U16 val);
internal U64 count_bits_set32(U32 val); internal U64 count_bits_set32(U32 val);
internal U64 count_bits_set64(U64 val); internal U64 count_bits_set64(U64 val);
+25 -22
View File
@@ -1,22 +1,24 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
global U64 global_update_tick_idx = 0;
internal void internal void
main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **arguments, U64 arguments_count) main_thread_base_entry_point(int arguments_count, char **arguments)
{ {
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
ThreadNameF("[main thread]"); ThreadNameF("[main thread]");
//- rjf: set up telemetry //- rjf: set up telemetry
#if PROFILE_TELEMETRY #if PROFILE_TELEMETRY
local_persist U8 tm_data[MB(64)]; local_persist char tm_data[MB(64)];
tmLoadLibrary(TM_RELEASE); tmLoadLibrary(TM_RELEASE);
tmSetMaxThreadCount(256); tmSetMaxThreadCount(256);
tmInitialize(sizeof(tm_data), (char *)tm_data); tmInitialize(sizeof(tm_data), tm_data);
#endif #endif
//- rjf: parse command line //- rjf: parse command line
String8List command_line_argument_strings = os_string_list_from_argcv(scratch.arena, (int)arguments_count, arguments); String8List command_line_argument_strings = os_string_list_from_argcv(scratch.arena, arguments_count, arguments);
CmdLine cmdline = cmd_line_from_string_list(scratch.arena, command_line_argument_strings); CmdLine cmdline = cmd_line_from_string_list(scratch.arena, command_line_argument_strings);
//- rjf: begin captures //- rjf: begin captures
@@ -26,9 +28,16 @@ main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **argum
ProfBeginCapture(arguments[0]); ProfBeginCapture(arguments[0]);
} }
#if PROFILE_TELEMETRY
tmMessage(0, TMMF_ICON_NOTE, BUILD_TITLE);
#endif
//- rjf: initialize all included layers //- rjf: initialize all included layers
#if defined(TASK_SYSTEM_H) && !defined(TS_INIT_MANUAL) #if defined(ASYNC_H) && !defined(ASYNC_INIT_MANUAL)
ts_init(); async_init();
#endif
#if defined(RDI_FROM_PDB_H) && !defined(P2R_INIT_MANUAL)
p2r_init();
#endif #endif
#if defined(HASH_STORE_H) && !defined(HS_INIT_MANUAL) #if defined(HASH_STORE_H) && !defined(HS_INIT_MANUAL)
hs_init(); hs_init();
@@ -45,12 +54,9 @@ main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **argum
#if defined(DASM_CACHE_H) && !defined(DASM_INIT_MANUAL) #if defined(DASM_CACHE_H) && !defined(DASM_INIT_MANUAL)
dasm_init(); dasm_init();
#endif #endif
#if defined(DBGI_H) && !defined(DBGI_INIT_MANUAL) #if defined(DBGI_H) && !defined(DI_INIT_MANUAL)
di_init(); di_init();
#endif #endif
#if defined(FUZZY_SEARCH_H) && !defined(FZY_INIT_MANUAL)
fzy_init();
#endif
#if defined(DEMON_CORE_H) && !defined(DMN_INIT_MANUAL) #if defined(DEMON_CORE_H) && !defined(DMN_INIT_MANUAL)
dmn_init(); dmn_init();
#endif #endif
@@ -90,6 +96,7 @@ main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **argum
{ {
ProfEndCapture(); ProfEndCapture();
} }
scratch_end(scratch); scratch_end(scratch);
} }
@@ -102,22 +109,18 @@ supplement_thread_base_entry_point(void (*entry_point)(void *params), void *para
tctx_release(); tctx_release();
} }
internal U64
update_tick_idx(void)
{
U64 result = ins_atomic_u64_eval(&global_update_tick_idx);
return result;
}
internal B32 internal B32
update(void) update(void)
{ {
ProfTick(0); ProfTick(0);
#if defined(TEXT_CACHE_H) ins_atomic_u64_inc_eval(&global_update_tick_idx);
txt_user_clock_tick();
#endif
#if defined(DASM_CACHE_H)
dasm_user_clock_tick();
#endif
#if defined(GEO_CACHE_H)
geo_user_clock_tick();
#endif
#if defined(TEXTURE_CACHE_H)
tex_user_clock_tick();
#endif
#if OS_FEATURE_GRAPHICAL #if OS_FEATURE_GRAPHICAL
B32 result = frame(); B32 result = frame();
#else #else
+2 -1
View File
@@ -4,8 +4,9 @@
#ifndef BASE_ENTRY_POINT_H #ifndef BASE_ENTRY_POINT_H
#define BASE_ENTRY_POINT_H #define BASE_ENTRY_POINT_H
internal void main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **arguments, U64 arguments_count); internal void main_thread_base_entry_point(int argc, char **argv);
internal void supplement_thread_base_entry_point(void (*entry_point)(void *params), void *params); internal void supplement_thread_base_entry_point(void (*entry_point)(void *params), void *params);
internal U64 update_tick_idx(void);
internal B32 update(void); internal B32 update(void);
#endif // BASE_ENTRY_POINT_H #endif // BASE_ENTRY_POINT_H
+24
View File
@@ -195,6 +195,30 @@ read_only global Type B32__type = {TypeKind_B32, 0, sizeof(B32), &type_nil, st
read_only global Type B64__type = {TypeKind_B64, 0, sizeof(B64), &type_nil, str8_lit_comp("B64")}; read_only global Type B64__type = {TypeKind_B64, 0, sizeof(B64), &type_nil, str8_lit_comp("B64")};
read_only global Type F32__type = {TypeKind_F32, 0, sizeof(F32), &type_nil, str8_lit_comp("F32")}; read_only global Type F32__type = {TypeKind_F32, 0, sizeof(F32), &type_nil, str8_lit_comp("F32")};
read_only global Type F64__type = {TypeKind_F64, 0, sizeof(F64), &type_nil, str8_lit_comp("F64")}; read_only global Type F64__type = {TypeKind_F64, 0, sizeof(F64), &type_nil, str8_lit_comp("F64")};
read_only global Type *type_kind_type_table[] =
{
&type_nil,
type(void),
type(U8),
type(U16),
type(U32),
type(U64),
type(S8),
type(S16),
type(S32),
type(S64),
type(B8),
type(B16),
type(B32),
type(B64),
type(F32),
type(F64),
&type_nil,
&type_nil,
&type_nil,
&type_nil,
&type_nil,
};
//- rjf: Rng1U64 //- rjf: Rng1U64
struct_members(Rng1U64) struct_members(Rng1U64)
+36 -14
View File
@@ -43,26 +43,48 @@
# define ProfLockTake(...) tmAcquiredLock(0, 0, __VA_ARGS__) # define ProfLockTake(...) tmAcquiredLock(0, 0, __VA_ARGS__)
# define ProfLockDrop(...) tmReleasedLock(0, __VA_ARGS__) # define ProfLockDrop(...) tmReleasedLock(0, __VA_ARGS__)
# define ProfColor(color) tmZoneColorSticky(color) # define ProfColor(color) tmZoneColorSticky(color)
# define ProfBeginV(...) \
if (TM_API_PTR) { \
static tm_uint64 file_id = 0; TM_API_PTR->_tmStaticString(&file_id, __FILE__); \
Temp scratch = scratch_begin(0,0); \
String8 string = push_str8f(scratch.arena, __VA_ARGS__); \
tm_uint64 hash = TM_API_PTR->_tmHash((char*)string.str, string.size); \
hash = TM_API_PTR->_tmSendDynamicString(hash, (char*)string.str); \
TM_API_PTR->_tmEnterZoneFast_Core(0, 0, file_id, __LINE__, hash); \
scratch_end(scratch); \
}
# define ProfNoteV(...) \
if (TM_API_PTR) { \
static tm_uint64 file_id = 0; TM_API_PTR->_tmStaticString(&file_id, __FILE__); \
Temp scratch = scratch_begin(0,0); \
String8 string = push_str8f(scratch.arena, __VA_ARGS__); \
tm_uint64 hash = TM_API_PTR->_tmHash((char*)string.str, string.size); \
hash = TM_API_PTR->_tmSendDynamicString(hash, (char*)string.str); \
TM_API_PTR->_tmMessageFast_Core(0, TMMF_ICON_NOTE, file_id, __LINE__, hash); \
scratch_end(scratch); \
}
#endif #endif
//////////////////////////////// ////////////////////////////////
//~ rjf: Zeroify Undefined Defines //~ rjf: Zeroify Undefined Defines
#if !defined(ProfBegin) #if !defined(ProfBegin)
# define ProfBegin(...) (0) # define ProfBegin(...) (0)
# define ProfBeginDynamic(...) (0) # define ProfBeginDynamic(...) (0)
# define ProfEnd(...) (0) # define ProfEnd(...) (0)
# define ProfTick(...) (0) # define ProfTick(...) (0)
# define ProfIsCapturing(...) (0) # define ProfIsCapturing(...) (0)
# define ProfBeginCapture(...) (0) # define ProfBeginCapture(...) (0)
# define ProfEndCapture(...) (0) # define ProfEndCapture(...) (0)
# define ProfThreadName(...) (0) # define ProfThreadName(...) (0)
# define ProfMsg(...) (0) # define ProfMsg(...) (0)
# define ProfBeginLockWait(...) (0) # define ProfBeginLockWait(...) (0)
# define ProfEndLockWait(...) (0) # define ProfEndLockWait(...) (0)
# define ProfLockTake(...) (0) # define ProfLockTake(...) (0)
# define ProfLockDrop(...) (0) # define ProfLockDrop(...) (0)
# define ProfColor(...) (0) # define ProfColor(...) (0)
# define ProfBeginV(...) (0)
# define ProfNoteV(...) (0)
#endif #endif
//////////////////////////////// ////////////////////////////////
+297 -42
View File
@@ -215,12 +215,42 @@ str32_cstring(U32 *c){
internal String8 internal String8
str8_cstring_capped(void *cstr, void *cap) str8_cstring_capped(void *cstr, void *cap)
{ {
char *ptr = (char*)cstr; char *ptr = (char *)cstr;
char *opl = (char*)cap; char *opl = (char *)cap;
for (;ptr < opl && *ptr != 0; ptr += 1); for (;ptr < opl && *ptr != 0; ptr += 1);
U64 size = (U64)(ptr - (char *)cstr); U64 size = (U64)(ptr - (char *)cstr);
String8 result = {(U8*)cstr, size}; String8 result = str8((U8*)cstr, size);
return(result); return result;
}
internal String16
str16_cstring_capped(void *cstr, void *cap)
{
U16 *ptr = (U16 *)cstr;
U16 *opl = (U16 *)cap;
for (;ptr < opl && *ptr != 0; ptr += 1);
U64 size = (U64)(ptr - (U16 *)cstr);
String16 result = str16(cstr, size);
return result;
}
internal String8
str8_cstring_capped_reverse(void *raw_start, void *raw_cap)
{
U8 *start = raw_start;
U8 *ptr = raw_cap;
for(; ptr > start; )
{
ptr -= 1;
if (*ptr == '\0')
{
break;
}
}
U64 size = (U64)(ptr - start);
String8 result = str8(start, size);
return result;
} }
//////////////////////////////// ////////////////////////////////
@@ -263,31 +293,41 @@ backslashed_from_str8(Arena *arena, String8 string)
//~ rjf: String Matching //~ rjf: String Matching
internal B32 internal B32
str8_match(String8 a, String8 b, StringMatchFlags flags){ str8_match(String8 a, String8 b, StringMatchFlags flags)
{
B32 result = 0; B32 result = 0;
if (a.size == b.size || (flags & StringMatchFlag_RightSideSloppy)){ if(a.size == b.size && flags == 0)
B32 case_insensitive = (flags & StringMatchFlag_CaseInsensitive); {
result = MemoryMatch(a.str, b.str, b.size);
}
else if(a.size == b.size || (flags & StringMatchFlag_RightSideSloppy))
{
B32 case_insensitive = (flags & StringMatchFlag_CaseInsensitive);
B32 slash_insensitive = (flags & StringMatchFlag_SlashInsensitive); B32 slash_insensitive = (flags & StringMatchFlag_SlashInsensitive);
U64 size = Min(a.size, b.size); U64 size = Min(a.size, b.size);
result = 1; result = 1;
for (U64 i = 0; i < size; i += 1){ for(U64 i = 0; i < size; i += 1)
{
U8 at = a.str[i]; U8 at = a.str[i];
U8 bt = b.str[i]; U8 bt = b.str[i];
if (case_insensitive){ if(case_insensitive)
{
at = char_to_upper(at); at = char_to_upper(at);
bt = char_to_upper(bt); bt = char_to_upper(bt);
} }
if (slash_insensitive){ if(slash_insensitive)
{
at = char_to_correct_slash(at); at = char_to_correct_slash(at);
bt = char_to_correct_slash(bt); bt = char_to_correct_slash(bt);
} }
if (at != bt){ if(at != bt)
{
result = 0; result = 0;
break; break;
} }
} }
} }
return(result); return result;
} }
internal U64 internal U64
@@ -322,6 +362,22 @@ str8_find_needle(String8 string, U64 start_pos, String8 needle, StringMatchFlags
return(result); return(result);
} }
internal U64
str8_find_needle_reverse(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags)
{
U64 result = 0;
for(S64 i = string.size - start_pos - needle.size; i >= 0; --i)
{
String8 haystack = str8_substr(string, rng_1u64(i, i + needle.size));
if(str8_match(haystack, needle, flags))
{
result = (U64)i + needle.size;
break;
}
}
return result;
}
internal B32 internal B32
str8_ends_with(String8 string, String8 end, StringMatchFlags flags){ str8_ends_with(String8 string, String8 end, StringMatchFlags flags){
String8 postfix = str8_postfix(string, end.size); String8 postfix = str8_postfix(string, end.size);
@@ -544,21 +600,121 @@ try_s64_from_str8_c_rules(String8 string, S64 *x){
//- rjf: integer -> string //- rjf: integer -> string
internal String8 internal String8
str8_from_memory_size(Arena *arena, U64 z){ str8_from_memory_size(Arena *arena, U64 size)
String8 result = {0}; {
if (z < KB(1)){ String8 result;
result = push_str8f(arena, "%llu b", z);
if(size < KB(1))
{
result = push_str8f(arena, "%llu Bytes", size);
} }
else if (z < MB(1)){ else if(size < MB(1))
result = push_str8f(arena, "%llu.%02llu Kb", z/KB(1), ((100*z)/KB(1))%100); {
result = push_str8f(arena, "%llu.%02llu KiB", size / KB(1), ((size * 100) / KB(1)) % 100);
} }
else if (z < GB(1)){ else if(size < GB(1))
result = push_str8f(arena, "%llu.%02llu Mb", z/MB(1), ((100*z)/MB(1))%100); {
result = push_str8f(arena, "%llu.%02llu MiB", size / MB(1), ((size * 100) / MB(1)) % 100);
} }
else{ else if(size < TB(1))
result = push_str8f(arena, "%llu.%02llu Gb", z/GB(1), ((100*z)/GB(1))%100); {
result = push_str8f(arena, "%llu.%02llu GiB", size / GB(1), ((size * 100) / GB(1)) % 100);
} }
return(result); else
{
result = push_str8f(arena, "%llu.%02llu TiB", size / TB(1), ((size * 100) / TB(1)) % 100);
}
return result;
}
internal String8
str8_from_count(Arena *arena, U64 count)
{
String8 result;
if(count < 1 * 1000)
{
result = push_str8f(arena, "%llu", count);
}
else if(count < 1000000)
{
U64 frac = ((count * 100) / 1000) % 100;
if(frac > 0)
{
result = push_str8f(arena, "%llu.%02lluK", count / 1000, frac);
}
else
{
result = push_str8f(arena, "%lluK", count / 1000);
}
}
else if(count < 1000000000)
{
U64 frac = ((count * 100) / 1000000) % 100;
if(frac > 0)
{
result = push_str8f(arena, "%llu.%02lluM", count / 1000000, frac);
}
else
{
result = push_str8f(arena, "%lluM", count / 1000000);
}
}
else
{
U64 frac = ((count * 100) * 1000000000) % 100;
if(frac > 0)
{
result = push_str8f(arena, "%llu.%02lluB", count / 1000000000, frac);
}
else
{
result = push_str8f(arena, "%lluB", count / 1000000000, frac);
}
}
return result;
}
internal String8
str8_from_bits_u32(Arena *arena, U32 x)
{
U8 c0 = 'a' + ((x >> 28) & 0xf);
U8 c1 = 'a' + ((x >> 24) & 0xf);
U8 c2 = 'a' + ((x >> 20) & 0xf);
U8 c3 = 'a' + ((x >> 16) & 0xf);
U8 c4 = 'a' + ((x >> 12) & 0xf);
U8 c5 = 'a' + ((x >> 8) & 0xf);
U8 c6 = 'a' + ((x >> 4) & 0xf);
U8 c7 = 'a' + ((x >> 0) & 0xf);
String8 result = push_str8f(arena, "%c%c%c%c%c%c%c%c", c0, c1, c2, c3, c4, c5, c6, c7);
return result;
}
internal String8
str8_from_bits_u64(Arena *arena, U64 x)
{
U8 c0 = 'a' + ((x >> 60) & 0xf);
U8 c1 = 'a' + ((x >> 56) & 0xf);
U8 c2 = 'a' + ((x >> 52) & 0xf);
U8 c3 = 'a' + ((x >> 48) & 0xf);
U8 c4 = 'a' + ((x >> 44) & 0xf);
U8 c5 = 'a' + ((x >> 40) & 0xf);
U8 c6 = 'a' + ((x >> 36) & 0xf);
U8 c7 = 'a' + ((x >> 32) & 0xf);
U8 c8 = 'a' + ((x >> 28) & 0xf);
U8 c9 = 'a' + ((x >> 24) & 0xf);
U8 ca = 'a' + ((x >> 20) & 0xf);
U8 cb = 'a' + ((x >> 16) & 0xf);
U8 cc = 'a' + ((x >> 12) & 0xf);
U8 cd = 'a' + ((x >> 8) & 0xf);
U8 ce = 'a' + ((x >> 4) & 0xf);
U8 cf = 'a' + ((x >> 0) & 0xf);
String8 result = push_str8f(arena,
"%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, ca, cb, cc, cd, ce, cf);
return result;
} }
internal String8 internal String8
@@ -685,27 +841,28 @@ f64_from_str8(String8 string)
{ {
// rjf: find starting pos of numeric string, as well as sign // rjf: find starting pos of numeric string, as well as sign
F64 sign = +1.0; F64 sign = +1.0;
//U64 first_numeric = 0;
if(string.str[0] == '-') if(string.str[0] == '-')
{ {
//first_numeric = 1;
sign = -1.0; sign = -1.0;
} }
else if(string.str[0] == '+') else if(string.str[0] == '+')
{ {
//first_numeric = 1;
sign = 1.0; sign = 1.0;
} }
// rjf: gather numerics // rjf: gather numerics
U64 num_valid_chars = 0; U64 num_valid_chars = 0;
char buffer[64]; char buffer[64];
B32 exp = 0;
for(U64 idx = 0; idx < string.size && num_valid_chars < sizeof(buffer)-1; idx += 1) for(U64 idx = 0; idx < string.size && num_valid_chars < sizeof(buffer)-1; idx += 1)
{ {
if(char_is_digit(string.str[idx], 10) || string.str[idx] == '.') if(char_is_digit(string.str[idx], 10) || string.str[idx] == '.' || string.str[idx] == 'e' ||
(exp && (string.str[idx] == '+' || string.str[idx] == '-')))
{ {
buffer[num_valid_chars] = string.str[idx]; buffer[num_valid_chars] = string.str[idx];
num_valid_chars += 1; num_valid_chars += 1;
exp = 0;
exp = (string.str[idx] == 'e');
} }
} }
@@ -1138,7 +1295,9 @@ str8_path_list_resolve_dots_in_place(String8List *path, PathStyle style){
internal String8 internal String8
str8_path_list_join_by_style(Arena *arena, String8List *path, PathStyle style){ str8_path_list_join_by_style(Arena *arena, String8List *path, PathStyle style){
StringJoin params = {0}; StringJoin params = {0};
switch (style){ switch(style)
{
case PathStyle_Null:{}break;
case PathStyle_Relative: case PathStyle_Relative:
case PathStyle_WindowsAbsolute: case PathStyle_WindowsAbsolute:
{ {
@@ -1151,9 +1310,8 @@ str8_path_list_join_by_style(Arena *arena, String8List *path, PathStyle style){
params.sep = str8_lit("/"); params.sep = str8_lit("/");
}break; }break;
} }
String8 result = str8_list_join(arena, path, &params); String8 result = str8_list_join(arena, path, &params);
return(result); return result;
} }
internal String8TxtPtPair internal String8TxtPtPair
@@ -1412,6 +1570,35 @@ str32_from_8(Arena *arena, String8 in){
return(str32(str, size)); return(str32(str, size));
} }
////////////////////////////////
//~ String -> Enum Conversions
read_only global struct
{
String8 string;
OperatingSystem os;
} g_os_enum_map[] =
{
{ str8_lit_comp(""), OperatingSystem_Null },
{ str8_lit_comp("Windows"), OperatingSystem_Windows, },
{ str8_lit_comp("Linux"), OperatingSystem_Linux, },
{ str8_lit_comp("Mac"), OperatingSystem_Mac, },
};
StaticAssert(ArrayCount(g_os_enum_map) == OperatingSystem_COUNT, g_os_enum_map_count_check);
internal OperatingSystem
operating_system_from_string(String8 string)
{
for(U64 i = 0; i < ArrayCount(g_os_enum_map); ++i)
{
if(str8_match(g_os_enum_map[i].string, string, StringMatchFlag_CaseInsensitive))
{
return g_os_enum_map[i].os;
}
}
return OperatingSystem_Null;
}
//////////////////////////////// ////////////////////////////////
//~ rjf: Basic Types & Space Enum -> String Conversions //~ rjf: Basic Types & Space Enum -> String Conversions
@@ -1444,18 +1631,14 @@ string_from_side(Side side){
} }
internal String8 internal String8
string_from_operating_system(OperatingSystem os){ string_from_operating_system(OperatingSystem os)
local_persist String8 strings[] = { {
str8_lit_comp("Null"), String8 result = g_os_enum_map[OperatingSystem_Null].string;
str8_lit_comp("Windows"), if(os < ArrayCount(g_os_enum_map))
str8_lit_comp("Linux"), {
str8_lit_comp("Mac"), result = g_os_enum_map[os].string;
};
String8 result = str8_lit("error");
if (os < OperatingSystem_COUNT){
result = strings[os];
} }
return(result); return result;
} }
internal String8 internal String8
@@ -1565,6 +1748,78 @@ string_from_elapsed_time(Arena *arena, DateTime dt){
return(result); return(result);
} }
////////////////////////////////
//~ Globally UNique Ids
internal String8
string_from_guid(Arena *arena, Guid guid)
{
String8 result = push_str8f(arena, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
guid.data1,
guid.data2,
guid.data3,
guid.data4[0],
guid.data4[1],
guid.data4[2],
guid.data4[3],
guid.data4[4],
guid.data4[5],
guid.data4[6],
guid.data4[7]);
return result;
}
internal B32
try_guid_from_string(String8 string, Guid *guid_out)
{
Temp scratch = scratch_begin(0,0);
B32 is_parsed = 0;
String8List list = str8_split_by_string_chars(scratch.arena, string, str8_lit("-"), StringSplitFlag_KeepEmpties);
if(list.node_count == 5)
{
String8 data1_str = list.first->string;
String8 data2_str = list.first->next->string;
String8 data3_str = list.first->next->next->string;
String8 data4_hi_str = list.first->next->next->next->string;
String8 data4_lo_str = list.first->next->next->next->next->string;
if(str8_is_integer(data1_str, 16) &&
str8_is_integer(data2_str, 16) &&
str8_is_integer(data3_str, 16) &&
str8_is_integer(data4_hi_str, 16) &&
str8_is_integer(data4_lo_str, 16))
{
U64 data1 = u64_from_str8(data1_str, 16);
U64 data2 = u64_from_str8(data2_str, 16);
U64 data3 = u64_from_str8(data3_str, 16);
U64 data4_hi = u64_from_str8(data4_hi_str, 16);
U64 data4_lo = u64_from_str8(data4_lo_str, 16);
if(data1 <= max_U32 &&
data2 <= max_U16 &&
data3 <= max_U16 &&
data4_hi <= max_U16 &&
data4_lo <= 0xffffffffffff)
{
guid_out->data1 = (U32)data1;
guid_out->data2 = (U16)data2;
guid_out->data3 = (U16)data3;
U64 data4 = (data4_hi << 48) | data4_lo;
MemoryCopy(&guid_out->data4[0], &data4, sizeof(data4));
is_parsed = 1;
}
}
}
scratch_end(scratch);
return is_parsed;
}
internal Guid
guid_from_string(String8 string)
{
Guid guid = {0};
try_guid_from_string(string, &guid);
return guid;
}
//////////////////////////////// ////////////////////////////////
//~ rjf: Basic Text Indentation //~ rjf: Basic Text Indentation
+20 -1
View File
@@ -86,6 +86,7 @@ enum
typedef enum PathStyle typedef enum PathStyle
{ {
PathStyle_Null,
PathStyle_Relative, PathStyle_Relative,
PathStyle_WindowsAbsolute, PathStyle_WindowsAbsolute,
PathStyle_UnixAbsolute, PathStyle_UnixAbsolute,
@@ -192,6 +193,8 @@ internal String8 str8_cstring(char *c);
internal String16 str16_cstring(U16 *c); internal String16 str16_cstring(U16 *c);
internal String32 str32_cstring(U32 *c); internal String32 str32_cstring(U32 *c);
internal String8 str8_cstring_capped(void *cstr, void *cap); internal String8 str8_cstring_capped(void *cstr, void *cap);
internal String16 str16_cstring_capped(void *cstr, void *cap);
internal String8 str8_cstring_capped_reverse(void *raw_start, void *raw_cap);
//////////////////////////////// ////////////////////////////////
//~ rjf: String Stylization //~ rjf: String Stylization
@@ -205,6 +208,7 @@ internal String8 backslashed_from_str8(Arena *arena, String8 string);
internal B32 str8_match(String8 a, String8 b, StringMatchFlags flags); internal B32 str8_match(String8 a, String8 b, StringMatchFlags flags);
internal U64 str8_find_needle(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags); internal U64 str8_find_needle(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags);
internal U64 str8_find_needle_reverse(String8 string, U64 start_pos, String8 needle, StringMatchFlags flags);
internal B32 str8_ends_with(String8 string, String8 end, StringMatchFlags flags); internal B32 str8_ends_with(String8 string, String8 end, StringMatchFlags flags);
//////////////////////////////// ////////////////////////////////
@@ -237,7 +241,10 @@ internal B32 try_u64_from_str8_c_rules(String8 string, U64 *x);
internal B32 try_s64_from_str8_c_rules(String8 string, S64 *x); internal B32 try_s64_from_str8_c_rules(String8 string, S64 *x);
//- rjf: integer -> string //- rjf: integer -> string
internal String8 str8_from_memory_size(Arena *arena, U64 z); internal String8 str8_from_memory_size(Arena *arena, U64 size);
internal String8 str8_from_count(Arena *arena, U64 count);
internal String8 str8_from_bits_u32(Arena *arena, U32 x);
internal String8 str8_from_bits_u64(Arena *arena, U64 x);
internal String8 str8_from_u64(Arena *arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_separator); internal String8 str8_from_u64(Arena *arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_separator);
internal String8 str8_from_s64(Arena *arena, S64 s64, U32 radix, U8 min_digits, U8 digit_group_separator); internal String8 str8_from_s64(Arena *arena, S64 s64, U32 radix, U8 min_digits, U8 digit_group_separator);
@@ -309,6 +316,11 @@ internal String16 str16_from_8(Arena *arena, String8 in);
internal String8 str8_from_32(Arena *arena, String32 in); internal String8 str8_from_32(Arena *arena, String32 in);
internal String32 str32_from_8(Arena *arena, String8 in); internal String32 str32_from_8(Arena *arena, String8 in);
////////////////////////////////
//~ String -> Enum Conversions
internal OperatingSystem operating_system_from_string(String8 string);
//////////////////////////////// ////////////////////////////////
//~ rjf: Basic Types & Space Enum -> String Conversions //~ rjf: Basic Types & Space Enum -> String Conversions
@@ -326,6 +338,13 @@ internal String8 push_date_time_string(Arena *arena, DateTime *date_time);
internal String8 push_file_name_date_time_string(Arena *arena, DateTime *date_time); internal String8 push_file_name_date_time_string(Arena *arena, DateTime *date_time);
internal String8 string_from_elapsed_time(Arena *arena, DateTime dt); internal String8 string_from_elapsed_time(Arena *arena, DateTime dt);
////////////////////////////////
//~ Globally Unique Ids
internal String8 string_from_guid(Arena *arena, Guid guid);
internal B32 try_guid_from_string(String8 string, Guid *guid_out);
internal Guid guid_from_string(String8 string);
//////////////////////////////// ////////////////////////////////
//~ rjf: Basic Text Indentation //~ rjf: Basic Text Indentation
+22 -10
View File
@@ -80,6 +80,13 @@ cv_numeric_from_data_range(U8 *first, U8 *opl)
return result; return result;
} }
internal U64
cv_read_numeric(String8 data, U64 offset, CV_NumericParsed *out)
{
*out = cv_numeric_from_data_range(data.str + offset, data.str + data.size);
return out->encoded_size;
}
internal B32 internal B32
cv_numeric_fits_in_u64(CV_NumericParsed *num) cv_numeric_fits_in_u64(CV_NumericParsed *num)
{ {
@@ -186,7 +193,7 @@ cv_decode_inline_annot_u32(String8 data, U64 offset, U32 *out_value)
} }
// 2 bytes // 2 bytes
else if((header & 0xC0) == 0x80 && cursor+2 <= data.size) else if((header & 0xC0) == 0x80 && cursor+1 <= data.size)
{ {
U8 second_byte; U8 second_byte;
cursor += str8_deserial_read_struct(data, cursor, &second_byte); cursor += str8_deserial_read_struct(data, cursor, &second_byte);
@@ -411,7 +418,7 @@ cv_leaf_from_data(Arena *arena, String8 leaf_data, CV_TypeId itype_first)
//~ CodeView C13 Parser Functions //~ CodeView C13 Parser Functions
internal CV_C13Parsed * internal CV_C13Parsed *
cv_c13_parsed_from_data(Arena *arena, String8 c13_data, PDB_Strtbl *strtbl, PDB_CoffSectionArray *sections) cv_c13_parsed_from_data(Arena *arena, String8 c13_data, String8 strtbl, COFF_SectionHeaderArray sections)
{ {
ProfBeginFunction(); ProfBeginFunction();
@@ -483,19 +490,21 @@ cv_c13_parsed_from_data(Arena *arena, String8 c13_data, PDB_Strtbl *strtbl, PDB_
CV_C13SubSecLinesHeader *hdr = (CV_C13SubSecLinesHeader*)(first + read_off); CV_C13SubSecLinesHeader *hdr = (CV_C13SubSecLinesHeader*)(first + read_off);
read_off += sizeof(*hdr); read_off += sizeof(*hdr);
// extract top level info // rjf: extract section index
U32 sec_idx = hdr->sec; U32 sec_idx = hdr->sec;
B32 has_cols = !!(hdr->flags & CV_C13SubSecLinesFlag_HasColumns);
U64 secrel_off = hdr->sec_off;
U64 secrel_opl = secrel_off + hdr->len;
U64 sec_base_off = sections->sections[sec_idx - 1].voff;
// rjf: bad section index -> skip // rjf: bad section index -> skip
if(sec_idx < 1 || sections->count < sec_idx) if(sec_idx < 1 || sections.count < sec_idx)
{ {
continue; continue;
} }
// extract top level info
B32 has_cols = !!(hdr->flags & CV_C13SubSecLinesFlag_HasColumns);
U64 secrel_off = hdr->sec_off;
U64 secrel_opl = secrel_off + hdr->len;
U64 sec_base_off = sections.v[sec_idx - 1].voff;
// read files // read files
for(;read_off+sizeof(CV_C13File) <= read_off_opl;) for(;read_off+sizeof(CV_C13File) <= read_off_opl;)
{ {
@@ -511,7 +520,8 @@ cv_c13_parsed_from_data(Arena *arena, String8 c13_data, PDB_Strtbl *strtbl, PDB_
{ {
CV_C13Checksum *checksum = (CV_C13Checksum*)(c13_data.str + file_chksms->off + file_off); CV_C13Checksum *checksum = (CV_C13Checksum*)(c13_data.str + file_chksms->off + file_off);
U32 name_off = checksum->name_off; U32 name_off = checksum->name_off;
file_name = pdb_strtbl_string_from_off(strtbl, name_off); file_name = str8_cstring_capped((char*)(strtbl.str + name_off),
(char*)(strtbl.str + strtbl.size));
} }
// array layouts // array layouts
@@ -587,7 +597,8 @@ cv_c13_parsed_from_data(Arena *arena, String8 c13_data, PDB_Strtbl *strtbl, PDB_
{ {
CV_C13Checksum *checksum = (CV_C13Checksum*)(c13_data.str + file_chksms->off + hdr->file_off); CV_C13Checksum *checksum = (CV_C13Checksum*)(c13_data.str + file_chksms->off + hdr->file_off);
U32 name_off = checksum->name_off; U32 name_off = checksum->name_off;
file_name = pdb_strtbl_string_from_off(strtbl, name_off); file_name = str8_cstring_capped((char*)(strtbl.str + name_off),
(char*)(strtbl.str + strtbl.size));
} }
// rjf: parse extra files // rjf: parse extra files
@@ -608,6 +619,7 @@ cv_c13_parsed_from_data(Arena *arena, String8 c13_data, PDB_Strtbl *strtbl, PDB_
SLLQueuePush(node->inlinee_lines_first, node->inlinee_lines_last, n); SLLQueuePush(node->inlinee_lines_first, node->inlinee_lines_last, n);
n->v.inlinee = hdr->inlinee; n->v.inlinee = hdr->inlinee;
n->v.file_name = file_name; n->v.file_name = file_name;
n->v.file_off = hdr->file_off;
n->v.first_source_ln = hdr->first_source_ln; n->v.first_source_ln = hdr->first_source_ln;
n->v.extra_file_count = extra_file_count; n->v.extra_file_count = extra_file_count;
n->v.extra_files = extra_files; n->v.extra_files = extra_files;
+138 -34
View File
@@ -9,9 +9,15 @@
//////////////////////////////// ////////////////////////////////
//~ rjf: CodeView Format Shared Types //~ rjf: CodeView Format Shared Types
typedef U32 CV_TypeId; #define CV_TypeIndex_Max max_U32
typedef U32 CV_ItemId; typedef U32 CV_TypeIndex;
typedef CV_TypeIndex CV_TypeId;
typedef CV_TypeIndex CV_ItemId;
#define CV_ModIndex_Max max_U16
#define CV_ModIndex_Invalid CV_ModIndex_Max
typedef U16 CV_ModIndex; typedef U16 CV_ModIndex;
typedef U16 CV_SectionIndex; typedef U16 CV_SectionIndex;
typedef U16 CV_Reg; typedef U16 CV_Reg;
@@ -898,7 +904,95 @@ X(YMM14D3, 683, zmm14, 24, 8)\
X(YMM15D0, 684, zmm15, 0, 8)\ X(YMM15D0, 684, zmm15, 0, 8)\
X(YMM15D1, 685, zmm15, 8, 8)\ X(YMM15D1, 685, zmm15, 8, 8)\
X(YMM15D2, 686, zmm15, 16, 8)\ X(YMM15D2, 686, zmm15, 16, 8)\
X(YMM15D3, 687, zmm15, 24, 8) X(YMM15D3, 687, zmm15, 24, 8)\
X(XMM16, 694, zmm16, 0, 16)\
X(XMM17, 695, zmm17, 0, 16)\
X(XMM18, 696, zmm18, 0, 16)\
X(XMM19, 697, zmm19, 0, 16)\
X(XMM20, 698, zmm20, 0, 16)\
X(XMM21, 699, zmm21, 0, 16)\
X(XMM22, 700, zmm22, 0, 16)\
X(XMM23, 701, zmm23, 0, 16)\
X(XMM24, 702, zmm24, 0, 16)\
X(XMM25, 703, zmm25, 0, 16)\
X(XMM26, 704, zmm26, 0, 16)\
X(XMM27, 705, zmm27, 0, 16)\
X(XMM28, 706, zmm28, 0, 16)\
X(XMM29, 707, zmm29, 0, 16)\
X(XMM30, 708, zmm30, 0, 16)\
X(XMM31, 709, zmm31, 0, 16)\
X(YMM16, 710, zmm16, 0, 32)\
X(YMM17, 711, zmm17, 0, 32)\
X(YMM18, 712, zmm18, 0, 32)\
X(YMM19, 713, zmm19, 0, 32)\
X(YMM20, 714, zmm20, 0, 32)\
X(YMM21, 715, zmm21, 0, 32)\
X(YMM22, 716, zmm22, 0, 32)\
X(YMM23, 717, zmm23, 0, 32)\
X(YMM24, 718, zmm24, 0, 32)\
X(YMM25, 719, zmm25, 0, 32)\
X(YMM26, 720, zmm26, 0, 32)\
X(YMM27, 721, zmm27, 0, 32)\
X(YMM28, 722, zmm28, 0, 32)\
X(YMM29, 723, zmm29, 0, 32)\
X(YMM30, 724, zmm30, 0, 32)\
X(YMM31, 725, zmm31, 0, 32)\
X(ZMM0, 726, zmm0, 0, 64)\
X(ZMM1, 727, zmm1, 0, 64)\
X(ZMM2, 728, zmm2, 0, 64)\
X(ZMM3, 729, zmm3, 0, 64)\
X(ZMM4, 730, zmm4, 0, 64)\
X(ZMM5, 731, zmm5, 0, 64)\
X(ZMM6, 732, zmm6, 0, 64)\
X(ZMM7, 733, zmm7, 0, 64)\
X(ZMM8, 734, zmm8, 0, 64)\
X(ZMM9, 735, zmm9, 0, 64)\
X(ZMM10, 736, zmm10, 0, 64)\
X(ZMM11, 737, zmm11, 0, 64)\
X(ZMM12, 738, zmm12, 0, 64)\
X(ZMM13, 739, zmm13, 0, 64)\
X(ZMM14, 740, zmm14, 0, 64)\
X(ZMM15, 741, zmm15, 0, 64)\
X(ZMM16, 742, zmm16, 0, 64)\
X(ZMM17, 743, zmm17, 0, 64)\
X(ZMM18, 744, zmm18, 0, 64)\
X(ZMM19, 745, zmm19, 0, 64)\
X(ZMM20, 746, zmm20, 0, 64)\
X(ZMM21, 747, zmm21, 0, 64)\
X(ZMM22, 748, zmm22, 0, 64)\
X(ZMM23, 749, zmm23, 0, 64)\
X(ZMM24, 750, zmm24, 0, 64)\
X(ZMM25, 751, zmm25, 0, 64)\
X(ZMM26, 752, zmm26, 0, 64)\
X(ZMM27, 753, zmm27, 0, 64)\
X(ZMM28, 754, zmm28, 0, 64)\
X(ZMM29, 755, zmm29, 0, 64)\
X(ZMM30, 756, zmm30, 0, 64)\
X(ZMM31, 757, zmm31, 0, 64)\
X(K0, 758, k0, 0, 8)\
X(K1, 759, k1, 0, 8)\
X(K2, 760, k2, 0, 8)\
X(K3, 761, k3, 0, 8)\
X(K4, 762, k4, 0, 8)\
X(K5, 763, k5, 0, 8)\
X(K6, 764, k6, 0, 8)\
X(K7, 765, k7, 0, 8)\
X(ZMM0H, 766, zmm0, 32, 32)\
X(ZMM1H, 767, zmm1, 32, 32)\
X(ZMM2H, 768, zmm2, 32, 32)\
X(ZMM3H, 769, zmm3, 32, 32)\
X(ZMM4H, 770, zmm4, 32, 32)\
X(ZMM5H, 771, zmm5, 32, 32)\
X(ZMM6H, 772, zmm6, 32, 32)\
X(ZMM7H, 773, zmm7, 32, 32)\
X(ZMM8H, 774, zmm8, 32, 32)\
X(ZMM9H, 775, zmm9, 32, 32)\
X(ZMM10H, 776, zmm10, 32, 32)\
X(ZMM11H, 777, zmm11, 32, 32)\
X(ZMM12H, 778, zmm12, 32, 32)\
X(ZMM13H, 779, zmm13, 32, 32)\
X(ZMM14H, 780, zmm14, 32, 32)\
X(ZMM15H, 781, zmm15, 32, 32)
typedef U16 CV_Regx64; typedef U16 CV_Regx64;
typedef enum CV_Regx64Enum typedef enum CV_Regx64Enum
@@ -917,7 +1011,7 @@ X(C11, 2)\
X(C13, 4)\ X(C13, 4)\
X(RESERVED, 5) X(RESERVED, 5)
typedef U16 CV_Signature; typedef U32 CV_Signature;
typedef enum CV_SignatureEnum typedef enum CV_SignatureEnum
{ {
#define X(N,c) CV_Signature_##N = c, #define X(N,c) CV_Signature_##N = c,
@@ -1164,8 +1258,8 @@ struct CV_SymAnnotation
//- (SymKind: OBJNAME) //- (SymKind: OBJNAME)
typedef struct CV_SymObjname CV_SymObjname; typedef struct CV_SymObjName CV_SymObjName;
struct CV_SymObjname struct CV_SymObjName
{ {
U32 sig; U32 sig;
// U8[] name (null terminated) // U8[] name (null terminated)
@@ -1286,19 +1380,19 @@ struct CV_SymData32
//- (SymKind: PUB32) //- (SymKind: PUB32)
typedef U32 CV_PubFlags; typedef U32 CV_Pub32Flags;
enum enum
{ {
CV_PubFlag_Code = (1 << 0), CV_Pub32Flag_Code = (1 << 0),
CV_PubFlag_Function = (1 << 1), CV_Pub32Flag_Function = (1 << 1),
CV_PubFlag_ManagedCode = (1 << 2), CV_Pub32Flag_ManagedCode = (1 << 2),
CV_PubFlag_MSIL = (1 << 3), CV_Pub32Flag_MSIL = (1 << 3),
}; };
typedef struct CV_SymPub32 CV_SymPub32; typedef struct CV_SymPub32 CV_SymPub32;
struct CV_SymPub32 struct CV_SymPub32
{ {
CV_PubFlags flags; CV_Pub32Flags flags;
U32 off; U32 off;
CV_SectionIndex sec; CV_SectionIndex sec;
// U8[] name (null terminated) // U8[] name (null terminated)
@@ -1607,6 +1701,24 @@ struct CV_SymDiscarded
}; };
//- (SymKind: COMPILE3) //- (SymKind: COMPILE3)
typedef U32 CV_Compile3Flags;
enum
{
CV_Compile3Flag_EC = (1 << 8),
CV_Compile3Flag_NoDbgInfo = (1 << 9),
CV_Compile3Flag_LTCG = (1 << 10),
CV_Compile3Flag_NoDataAlign = (1 << 11),
CV_Compile3Flag_ManagedPresent = (1 << 12),
CV_Compile3Flag_SecurityChecks = (1 << 13),
CV_Compile3Flag_HotPatch = (1 << 14),
CV_Compile3Flag_CVTCIL = (1 << 15),
CV_Compile3Flag_MSILModule = (1 << 16),
CV_Compile3Flag_SDL = (1 << 17),
CV_Compile3Flag_PGO = (1 << 18),
CV_Compile3Flag_EXP = (1 << 19),
CV_Compile3Flag_Language_Shift = 0, CV_Compile3Flag_Language_Mask = 0xff,
};
typedef U32 CV_Compile3Flags; typedef U32 CV_Compile3Flags;
#define CV_Compile3Flags_ExtractLanguage(f) (((f) )&0xFF) #define CV_Compile3Flags_ExtractLanguage(f) (((f) )&0xFF)
@@ -1715,6 +1827,8 @@ struct CV_SymDefrangeFramepointerRel
//- (SymKind: DEFRANGE_SUBFIELD_REGISTER) //- (SymKind: DEFRANGE_SUBFIELD_REGISTER)
#define CV_DefrangeSubfieldRegister_ExtractParentOffset(x) ((x) & 0x1FFF)
typedef struct CV_SymDefrangeSubfieldRegister CV_SymDefrangeSubfieldRegister; typedef struct CV_SymDefrangeSubfieldRegister CV_SymDefrangeSubfieldRegister;
struct CV_SymDefrangeSubfieldRegister struct CV_SymDefrangeSubfieldRegister
{ {
@@ -1968,24 +2082,6 @@ struct CV_SymInlinees
// (type info) // (type info)
// //
#define CV_LeafIDKindXList(X) \
X(FUNC_ID, 0x1601)\
X(MFUNC_ID, 0x1602)\
X(BUILDINFO, 0x1603)\
X(SUBSTR_LIST, 0x1604)\
X(STRING_ID, 0x1605)\
X(UDT_SRC_LINE, 0x1606)\
X(UDT_MOD_SRC_LINE, 0x1607)
typedef U16 CV_LeafIDKind;
typedef enum CV_LeafIDKindEnum
{
#define X(N,c) CV_LeafIDKind_##N = c,
CV_LeafIDKindXList(X)
#undef X
}
CV_LeafIDKindEnum;
#define CV_TypeId_Variadic 0 #define CV_TypeId_Variadic 0
#define CV_BasicPointerKindXList(X) \ #define CV_BasicPointerKindXList(X) \
@@ -2197,10 +2293,18 @@ struct CV_LeafPreComp
{ {
U32 start_index; U32 start_index;
U32 count; U32 count;
U32 signature; U32 sig;
// U8[] name (null terminated) // U8[] name (null terminated)
}; };
//- (LeafKind; END_PRECOMP)
typedef struct CV_LeafEndPreComp CV_LeafEndPreComp;
struct CV_LeafEndPreComp
{
U32 sig;
};
//- (LeafKind: TYPESERVER) //- (LeafKind: TYPESERVER)
typedef struct CV_LeafTypeServer CV_LeafTypeServer; typedef struct CV_LeafTypeServer CV_LeafTypeServer;
@@ -2916,6 +3020,7 @@ typedef struct CV_C13InlineeLinesParsed CV_C13InlineeLinesParsed;
struct CV_C13InlineeLinesParsed struct CV_C13InlineeLinesParsed
{ {
CV_ItemId inlinee; CV_ItemId inlinee;
U32 file_off;
String8 file_name; String8 file_name;
U32 first_source_ln; U32 first_source_ln;
U32 extra_file_count; U32 extra_file_count;
@@ -2979,6 +3084,7 @@ internal U64 cv_hash_from_string(String8 string);
internal U64 cv_hash_from_item_id(CV_ItemId item_id); internal U64 cv_hash_from_item_id(CV_ItemId item_id);
internal CV_NumericParsed cv_numeric_from_data_range(U8 *first, U8 *opl); internal CV_NumericParsed cv_numeric_from_data_range(U8 *first, U8 *opl);
internal U64 cv_read_numeric(String8 data, U64 offset, CV_NumericParsed *out);
internal B32 cv_numeric_fits_in_u64(CV_NumericParsed *num); internal B32 cv_numeric_fits_in_u64(CV_NumericParsed *num);
internal B32 cv_numeric_fits_in_s64(CV_NumericParsed *num); internal B32 cv_numeric_fits_in_s64(CV_NumericParsed *num);
@@ -3010,8 +3116,6 @@ internal CV_LeafParsed *cv_leaf_from_data(Arena *arena, String8 leaf_data, CV_Ty
//////////////////////////////// ////////////////////////////////
//~ CodeView C13 Parser Functions //~ CodeView C13 Parser Functions
typedef struct PDB_Strtbl PDB_Strtbl; internal CV_C13Parsed *cv_c13_parsed_from_data(Arena *arena, String8 c13_data, String8 strtbl, COFF_SectionHeaderArray sections);
typedef struct PDB_CoffSectionArray PDB_CoffSectionArray;
internal CV_C13Parsed *cv_c13_parsed_from_data(Arena *arena, String8 c13_data, struct PDB_Strtbl *strtbl, struct PDB_CoffSectionArray *sections);
#endif // CODEVIEW_H #endif // CODEVIEW_H
+9 -1
View File
@@ -246,7 +246,7 @@ cv_string_from_arch:
{MANTYPREF - 0x1028} {MANTYPREF - 0x1028}
{UNAMESPACE_ST - 0x1029} {UNAMESPACE_ST - 0x1029}
{ST_MAX - 0x1100} {ST_MAX - 0x1100}
{OBJNAME Objname 0x1101} {OBJNAME ObjName 0x1101}
{THUNK32 Thunk32 0x1102} {THUNK32 Thunk32 0x1102}
{BLOCK32 Block32 0x1103} {BLOCK32 Block32 0x1103}
{WITH32 - 0x1104} {WITH32 - 0x1104}
@@ -462,6 +462,7 @@ CV_BasicTypeTable:
@table(name header_type_name val) @table(name header_type_name val)
CV_LeafKindTable: CV_LeafKindTable:
{ {
{NOTYPE - 0x0000}
{MODIFIER_16t - 0x0001} {MODIFIER_16t - 0x0001}
{POINTER_16t - 0x0002} {POINTER_16t - 0x0002}
{ARRAY_16t - 0x0003} {ARRAY_16t - 0x0003}
@@ -586,6 +587,13 @@ CV_LeafKindTable:
{VECTOR - 0x151b} {VECTOR - 0x151b}
{MATRIX - 0x151c} {MATRIX - 0x151c}
{VFTABLE - 0x151d} {VFTABLE - 0x151d}
{FUNC_ID FuncId 0x1601}
{MFUNC_ID MFuncId 0x1602}
{BUILDINFO BuildInfo 0x1603}
{SUBSTR_LIST SubstrList 0x1604}
{STRING_ID StringId 0x1605}
{UDT_SRC_LINE UDTSrcLine 0x1606}
{UDT_MOD_SRC_LINE UDTModSrcLine 0x1607}
{CLASS2 Struct2 0x1608} {CLASS2 Struct2 0x1608}
{STRUCT2 Struct2 0x1609} {STRUCT2 Struct2 0x1609}
} }
+26 -14
View File
@@ -408,11 +408,11 @@ cv_stringize_sym_range(Arena *arena, String8List *out,
case CV_SymKind_OBJNAME: case CV_SymKind_OBJNAME:
{ {
if (sizeof(CV_SymObjname) > cap){ if (sizeof(CV_SymObjName) > cap){
str8_list_push(arena, out, str8_lit(" bad symbol range\n")); str8_list_push(arena, out, str8_lit(" bad symbol range\n"));
} }
else{ else{
CV_SymObjname *objname = (CV_SymObjname*)first; CV_SymObjName *objname = (CV_SymObjName*)first;
// sig // sig
str8_list_pushf(arena, out, " sig=%u\n", objname->sig); str8_list_pushf(arena, out, " sig=%u\n", objname->sig);
@@ -568,22 +568,22 @@ cv_stringize_sym_range(Arena *arena, String8List *out,
CV_SymPub32 *pub32 = (CV_SymPub32*)first; CV_SymPub32 *pub32 = (CV_SymPub32*)first;
// flags // flags
CV_PubFlags flags = pub32->flags; CV_Pub32Flags flags = pub32->flags;
str8_list_push(arena, out, str8_lit(" flags=")); str8_list_push(arena, out, str8_lit(" flags="));
if (flags == 0){ if (flags == 0){
str8_list_push(arena, out, str8_lit("0|")); str8_list_push(arena, out, str8_lit("0|"));
} }
else{ else{
if (flags&CV_PubFlag_Code){ if (flags&CV_Pub32Flag_Code){
str8_list_push(arena, out, str8_lit("Code|")); str8_list_push(arena, out, str8_lit("Code|"));
} }
if (flags&CV_PubFlag_Function){ if (flags&CV_Pub32Flag_Function){
str8_list_push(arena, out, str8_lit("Function|")); str8_list_push(arena, out, str8_lit("Function|"));
} }
if (flags&CV_PubFlag_ManagedCode){ if (flags&CV_Pub32Flag_ManagedCode){
str8_list_push(arena, out, str8_lit("ManagedCode|")); str8_list_push(arena, out, str8_lit("ManagedCode|"));
} }
if (flags&CV_PubFlag_MSIL){ if (flags&CV_Pub32Flag_MSIL){
str8_list_push(arena, out, str8_lit("MSIL|")); str8_list_push(arena, out, str8_lit("MSIL|"));
} }
} }
@@ -2004,7 +2004,7 @@ cv_stringize_leaf_range(Arena *arena, String8List *out,
} }
}break; }break;
case CV_LeafIDKind_FUNC_ID: case CV_LeafKind_FUNC_ID:
{ {
if (sizeof(CV_LeafFuncId) > cap){ if (sizeof(CV_LeafFuncId) > cap){
str8_list_push(arena, out, str8_lit(" bad leaf range\n")); str8_list_push(arena, out, str8_lit(" bad leaf range\n"));
@@ -2020,7 +2020,7 @@ cv_stringize_leaf_range(Arena *arena, String8List *out,
} }
}break; }break;
case CV_LeafIDKind_MFUNC_ID: case CV_LeafKind_MFUNC_ID:
{ {
if (sizeof(CV_LeafMFuncId) > cap){ if (sizeof(CV_LeafMFuncId) > cap){
str8_list_push(arena, out, str8_lit(" bad leaf range\n")); str8_list_push(arena, out, str8_lit(" bad leaf range\n"));
@@ -2036,7 +2036,7 @@ cv_stringize_leaf_range(Arena *arena, String8List *out,
} }
}break; }break;
case CV_LeafIDKind_BUILDINFO: case CV_LeafKind_BUILDINFO:
{ {
if (sizeof(CV_LeafBuildInfo) > cap){ if (sizeof(CV_LeafBuildInfo) > cap){
str8_list_push(arena, out, str8_lit(" bad leaf range\n")); str8_list_push(arena, out, str8_lit(" bad leaf range\n"));
@@ -2057,7 +2057,7 @@ cv_stringize_leaf_range(Arena *arena, String8List *out,
} }
}break; }break;
case CV_LeafIDKind_SUBSTR_LIST: case CV_LeafKind_SUBSTR_LIST:
{ {
if (sizeof(CV_LeafSubstrList) > cap){ if (sizeof(CV_LeafSubstrList) > cap){
str8_list_push(arena, out, str8_lit(" bad leaf range\n")); str8_list_push(arena, out, str8_lit(" bad leaf range\n"));
@@ -2078,7 +2078,7 @@ cv_stringize_leaf_range(Arena *arena, String8List *out,
} }
}break; }break;
case CV_LeafIDKind_STRING_ID: case CV_LeafKind_STRING_ID:
{ {
if (sizeof(CV_LeafStringId) > cap){ if (sizeof(CV_LeafStringId) > cap){
str8_list_push(arena, out, str8_lit(" bad leaf range\n")); str8_list_push(arena, out, str8_lit(" bad leaf range\n"));
@@ -2093,7 +2093,7 @@ cv_stringize_leaf_range(Arena *arena, String8List *out,
} }
}break; }break;
case CV_LeafIDKind_UDT_SRC_LINE: case CV_LeafKind_UDT_SRC_LINE:
{ {
if (sizeof(CV_LeafUDTSrcLine) > cap){ if (sizeof(CV_LeafUDTSrcLine) > cap){
str8_list_push(arena, out, str8_lit(" bad leaf range\n")); str8_list_push(arena, out, str8_lit(" bad leaf range\n"));
@@ -2243,7 +2243,7 @@ cv_stringize_leaf_range(Arena *arena, String8List *out,
//case CV_LeafIDKind_SUBSTR_LIST: //case CV_LeafIDKind_SUBSTR_LIST:
//case CV_LeafIDKind_STRING_ID: //case CV_LeafIDKind_STRING_ID:
//case CV_LeafIDKind_UDT_SRC_LINE: //case CV_LeafIDKind_UDT_SRC_LINE:
case CV_LeafIDKind_UDT_MOD_SRC_LINE: case CV_LeafKind_UDT_MOD_SRC_LINE:
{ {
str8_list_push(arena, out, str8_lit(" no stringizer path\n")); str8_list_push(arena, out, str8_lit(" no stringizer path\n"));
@@ -2328,3 +2328,15 @@ cv_stringize_c13_parsed(Arena *arena, String8List *out, CV_C13Parsed *c13){
str8_list_push(arena, out, str8_lit("\n")); str8_list_push(arena, out, str8_lit("\n"));
} }
} }
internal String8
cv_string_from_inline_range_kind(CV_InlineRangeKind kind)
{
String8 result = str8_zero();
switch (kind) {
case CV_InlineRangeKind_Expr: result = str8_lit("Expr"); break;
case CV_InlineRangeKind_Stmt: result = str8_lit("Stmt"); break;
}
return result;
}
+2
View File
@@ -79,4 +79,6 @@ internal void cv_stringize_leaf_array(Arena *arena, String8List *out,
internal void cv_stringize_c13_parsed(Arena *arena, String8List *out, CV_C13Parsed *c13); internal void cv_stringize_c13_parsed(Arena *arena, String8List *out, CV_C13Parsed *c13);
internal String8 cv_string_from_inline_range_kind(CV_InlineRangeKind kind);
#endif // CODEVIEW_STRINGIZE_H #endif // CODEVIEW_STRINGIZE_H
+16 -1
View File
@@ -447,6 +447,7 @@ String8 result = str8_lit("<Unknown CV_LeafKind>");
switch(v) switch(v)
{ {
default:{}break; default:{}break;
case CV_LeafKind_NOTYPE:{result = str8_lit("NOTYPE");}break;
case CV_LeafKind_MODIFIER_16t:{result = str8_lit("MODIFIER_16t");}break; case CV_LeafKind_MODIFIER_16t:{result = str8_lit("MODIFIER_16t");}break;
case CV_LeafKind_POINTER_16t:{result = str8_lit("POINTER_16t");}break; case CV_LeafKind_POINTER_16t:{result = str8_lit("POINTER_16t");}break;
case CV_LeafKind_ARRAY_16t:{result = str8_lit("ARRAY_16t");}break; case CV_LeafKind_ARRAY_16t:{result = str8_lit("ARRAY_16t");}break;
@@ -571,6 +572,13 @@ case CV_LeafKind_BINTERFACE:{result = str8_lit("BINTERFACE");}break;
case CV_LeafKind_VECTOR:{result = str8_lit("VECTOR");}break; case CV_LeafKind_VECTOR:{result = str8_lit("VECTOR");}break;
case CV_LeafKind_MATRIX:{result = str8_lit("MATRIX");}break; case CV_LeafKind_MATRIX:{result = str8_lit("MATRIX");}break;
case CV_LeafKind_VFTABLE:{result = str8_lit("VFTABLE");}break; case CV_LeafKind_VFTABLE:{result = str8_lit("VFTABLE");}break;
case CV_LeafKind_FUNC_ID:{result = str8_lit("FUNC_ID");}break;
case CV_LeafKind_MFUNC_ID:{result = str8_lit("MFUNC_ID");}break;
case CV_LeafKind_BUILDINFO:{result = str8_lit("BUILDINFO");}break;
case CV_LeafKind_SUBSTR_LIST:{result = str8_lit("SUBSTR_LIST");}break;
case CV_LeafKind_STRING_ID:{result = str8_lit("STRING_ID");}break;
case CV_LeafKind_UDT_SRC_LINE:{result = str8_lit("UDT_SRC_LINE");}break;
case CV_LeafKind_UDT_MOD_SRC_LINE:{result = str8_lit("UDT_MOD_SRC_LINE");}break;
case CV_LeafKind_CLASS2:{result = str8_lit("CLASS2");}break; case CV_LeafKind_CLASS2:{result = str8_lit("CLASS2");}break;
case CV_LeafKind_STRUCT2:{result = str8_lit("STRUCT2");}break; case CV_LeafKind_STRUCT2:{result = str8_lit("STRUCT2");}break;
} }
@@ -592,7 +600,7 @@ case CV_SymKind_OEM:{result = sizeof(CV_SymOEM);}break;
case CV_SymKind_VFTABLE32:{result = sizeof(CV_SymVPath32);}break; case CV_SymKind_VFTABLE32:{result = sizeof(CV_SymVPath32);}break;
case CV_SymKind_FRAMEPROC:{result = sizeof(CV_SymFrameproc);}break; case CV_SymKind_FRAMEPROC:{result = sizeof(CV_SymFrameproc);}break;
case CV_SymKind_ANNOTATION:{result = sizeof(CV_SymAnnotation);}break; case CV_SymKind_ANNOTATION:{result = sizeof(CV_SymAnnotation);}break;
case CV_SymKind_OBJNAME:{result = sizeof(CV_SymObjname);}break; case CV_SymKind_OBJNAME:{result = sizeof(CV_SymObjName);}break;
case CV_SymKind_THUNK32:{result = sizeof(CV_SymThunk32);}break; case CV_SymKind_THUNK32:{result = sizeof(CV_SymThunk32);}break;
case CV_SymKind_BLOCK32:{result = sizeof(CV_SymBlock32);}break; case CV_SymKind_BLOCK32:{result = sizeof(CV_SymBlock32);}break;
case CV_SymKind_LABEL32:{result = sizeof(CV_SymLabel32);}break; case CV_SymKind_LABEL32:{result = sizeof(CV_SymLabel32);}break;
@@ -696,6 +704,13 @@ case CV_LeafKind_ONEMETHOD:{result = sizeof(CV_LeafOneMethod);}break;
case CV_LeafKind_NESTTYPEEX:{result = sizeof(CV_LeafNestTypeEx);}break; case CV_LeafKind_NESTTYPEEX:{result = sizeof(CV_LeafNestTypeEx);}break;
case CV_LeafKind_TYPESERVER2:{result = sizeof(CV_LeafTypeServer2);}break; case CV_LeafKind_TYPESERVER2:{result = sizeof(CV_LeafTypeServer2);}break;
case CV_LeafKind_INTERFACE:{result = sizeof(CV_LeafStruct);}break; case CV_LeafKind_INTERFACE:{result = sizeof(CV_LeafStruct);}break;
case CV_LeafKind_FUNC_ID:{result = sizeof(CV_LeafFuncId);}break;
case CV_LeafKind_MFUNC_ID:{result = sizeof(CV_LeafMFuncId);}break;
case CV_LeafKind_BUILDINFO:{result = sizeof(CV_LeafBuildInfo);}break;
case CV_LeafKind_SUBSTR_LIST:{result = sizeof(CV_LeafSubstrList);}break;
case CV_LeafKind_STRING_ID:{result = sizeof(CV_LeafStringId);}break;
case CV_LeafKind_UDT_SRC_LINE:{result = sizeof(CV_LeafUDTSrcLine);}break;
case CV_LeafKind_UDT_MOD_SRC_LINE:{result = sizeof(CV_LeafUDTModSrcLine);}break;
case CV_LeafKind_CLASS2:{result = sizeof(CV_LeafStruct2);}break; case CV_LeafKind_CLASS2:{result = sizeof(CV_LeafStruct2);}break;
case CV_LeafKind_STRUCT2:{result = sizeof(CV_LeafStruct2);}break; case CV_LeafKind_STRUCT2:{result = sizeof(CV_LeafStruct2);}break;
} }
+8
View File
@@ -381,6 +381,7 @@ CV_BasicType_PTR = 0xf0,
typedef U16 CV_LeafKind; typedef U16 CV_LeafKind;
typedef enum CV_LeafKindEnum typedef enum CV_LeafKindEnum
{ {
CV_LeafKind_NOTYPE = 0x0000,
CV_LeafKind_MODIFIER_16t = 0x0001, CV_LeafKind_MODIFIER_16t = 0x0001,
CV_LeafKind_POINTER_16t = 0x0002, CV_LeafKind_POINTER_16t = 0x0002,
CV_LeafKind_ARRAY_16t = 0x0003, CV_LeafKind_ARRAY_16t = 0x0003,
@@ -505,6 +506,13 @@ CV_LeafKind_BINTERFACE = 0x151a,
CV_LeafKind_VECTOR = 0x151b, CV_LeafKind_VECTOR = 0x151b,
CV_LeafKind_MATRIX = 0x151c, CV_LeafKind_MATRIX = 0x151c,
CV_LeafKind_VFTABLE = 0x151d, CV_LeafKind_VFTABLE = 0x151d,
CV_LeafKind_FUNC_ID = 0x1601,
CV_LeafKind_MFUNC_ID = 0x1602,
CV_LeafKind_BUILDINFO = 0x1603,
CV_LeafKind_SUBSTR_LIST = 0x1604,
CV_LeafKind_STRING_ID = 0x1605,
CV_LeafKind_UDT_SRC_LINE = 0x1606,
CV_LeafKind_UDT_MOD_SRC_LINE = 0x1607,
CV_LeafKind_CLASS2 = 0x1608, CV_LeafKind_CLASS2 = 0x1608,
CV_LeafKind_STRUCT2 = 0x1609, CV_LeafKind_STRUCT2 = 0x1609,
} CV_LeafKindEnum; } CV_LeafKindEnum;
+413 -137
View File
@@ -97,15 +97,17 @@ coff_header_info_from_data(String8 data)
COFF_HeaderInfo info = {0}; COFF_HeaderInfo info = {0};
if (coff_is_big_obj(data)) { if (coff_is_big_obj(data)) {
COFF_HeaderBigObj *big_header = (COFF_HeaderBigObj*)data.str; COFF_HeaderBigObj *big_header = (COFF_HeaderBigObj*)data.str;
info.machine = big_header->machine; info.type = COFF_DataType_BIG_OBJ;
info.section_array_off = sizeof(COFF_HeaderBigObj); info.machine = big_header->machine;
info.section_count_no_null = big_header->section_count; info.section_array_off = sizeof(COFF_HeaderBigObj);
info.string_table_off = big_header->pointer_to_symbol_table + sizeof(COFF_Symbol32) * big_header->number_of_symbols; info.section_count_no_null = big_header->section_count;
info.symbol_size = sizeof(COFF_Symbol32); info.string_table_off = big_header->pointer_to_symbol_table + sizeof(COFF_Symbol32) * big_header->number_of_symbols;
info.symbol_off = big_header->pointer_to_symbol_table; info.symbol_size = sizeof(COFF_Symbol32);
info.symbol_count = big_header->number_of_symbols; info.symbol_off = big_header->pointer_to_symbol_table;
info.symbol_count = big_header->number_of_symbols;
} else if (coff_is_obj(data)) { } else if (coff_is_obj(data)) {
COFF_Header *header = (COFF_Header*)data.str; COFF_Header *header = (COFF_Header*)data.str;
info.type = COFF_DataType_OBJ;
info.machine = header->machine; info.machine = header->machine;
info.section_array_off = sizeof(COFF_Header); info.section_array_off = sizeof(COFF_Header);
info.section_count_no_null = header->section_count; info.section_count_no_null = header->section_count;
@@ -143,6 +145,30 @@ coff_align_size_from_section_flags(COFF_SectionFlags flags)
return align; return align;
} }
internal COFF_SectionFlags
coff_section_flag_from_align_size(U64 align)
{
COFF_SectionFlags flags = 0;
switch (align) {
case 1: flags = COFF_SectionAlign_1BYTES; break;
case 2: flags = COFF_SectionAlign_2BYTES; break;
case 4: flags = COFF_SectionAlign_4BYTES; break;
case 8: flags = COFF_SectionAlign_8BYTES; break;
case 16: flags = COFF_SectionAlign_16BYTES; break;
case 32: flags = COFF_SectionAlign_32BYTES; break;
case 64: flags = COFF_SectionAlign_64BYTES; break;
case 128: flags = COFF_SectionAlign_128BYTES; break;
case 256: flags = COFF_SectionAlign_256BYTES; break;
case 512: flags = COFF_SectionAlign_512BYTES; break;
case 1024: flags = COFF_SectionAlign_1024BYTES; break;
case 2048: flags = COFF_SectionAlign_2048BYTES; break;
case 4096: flags = COFF_SectionAlign_4096BYTES; break;
case 8192: flags = COFF_SectionAlign_8192BYTES; break;
}
flags <<= COFF_SectionFlag_ALIGN_SHIFT;
return flags;
}
internal COFF_SymbolValueInterpType internal COFF_SymbolValueInterpType
coff_interp_symbol(COFF_Symbol32 *symbol) coff_interp_symbol(COFF_Symbol32 *symbol)
{ {
@@ -387,12 +413,34 @@ coff_word_size_from_machine(COFF_MachineType machine)
{ {
U64 result = 0; U64 result = 0;
switch (machine) { switch (machine) {
case COFF_MachineType_X64: result = 8; break; case COFF_MachineType_X64: result = 8; break;
case COFF_MachineType_X86: result = 4; break; case COFF_MachineType_X86: result = 4; break;
} }
return result; return result;
} }
internal U64
coff_default_exe_base_from_machine(COFF_MachineType machine)
{
U64 exe_base = 0;
switch (coff_word_size_from_machine(machine)) {
case 4: exe_base = 0x400000; break;
case 8: exe_base = 0x140000000; break;
}
return exe_base;
}
internal U64
coff_default_dll_base_from_machine(COFF_MachineType machine)
{
U64 dll_base = 0;
switch (coff_word_size_from_machine(machine)) {
case 4: dll_base = 0x10000000; break;
case 8: dll_base = 0x180000000; break;
}
return dll_base;
}
internal String8 internal String8
coff_make_import_lookup(Arena *arena, U16 hint, String8 name) coff_make_import_lookup(Arena *arena, U16 hint, String8 name)
{ {
@@ -421,6 +469,147 @@ coff_make_ordinal_64(U16 hint)
//////////////////////////////// ////////////////////////////////
internal String8
coff_make_import_header_by_name(Arena *arena,
String8 dll_name,
COFF_MachineType machine,
COFF_TimeStamp time_stamp,
String8 name,
U16 hint,
COFF_ImportHeaderType type)
{
struct {
U16 sig1;
U16 sig2;
U16 version;
COFF_MachineType machine;
COFF_TimeStamp time_stamp;
U32 sizeof_data;
U16 hint_ordinal;
U16 flags;
} import_header = {
COFF_MachineType_UNKNOWN, // sig1
max_U16, // sig2
0, // version
machine,
time_stamp,
safe_cast_u32(name.size + dll_name.size + 2), // sizeof_data
0, // hint_ordinal
0, // flags
};
import_header.flags |= (U16)(type & COFF_IMPORT_HEADER_TYPE_MASK) << COFF_IMPORT_HEADER_TYPE_SHIFT;
import_header.flags |= COFF_ImportHeaderNameType_NAME << COFF_IMPORT_HEADER_NAME_TYPE_SHIFT;
import_header.hint_ordinal = hint;
// alloc memory
U64 buffer_size = sizeof(import_header) + import_header.sizeof_data;
U8 *buffer = push_array_no_zero(arena, U8, buffer_size);
// copy header
MemoryCopy(buffer, &import_header, sizeof(import_header));
// copy function name
U8 *func_name = buffer + sizeof(import_header);
MemoryCopy(func_name, name.str, name.size);
func_name[name.size] = 0;
// copy dll name
U8 *dll_name_buffer = buffer + sizeof(import_header) + name.size + 1;
MemoryCopy(dll_name_buffer, dll_name.str, dll_name.size);
dll_name_buffer[dll_name.size] = 0;
String8 import_data = str8(buffer, buffer_size);
return import_data;
}
internal String8
coff_make_import_header_by_ordinal(Arena *arena,
String8 dll_name,
COFF_MachineType machine,
COFF_TimeStamp time_stamp,
U16 ordinal,
COFF_ImportHeaderType type)
{
struct {
U16 sig1;
U16 sig2;
U16 version;
COFF_MachineType machine;
COFF_TimeStamp time_stamp;
U32 sizeof_data;
U16 hint_ordinal;
U16 flags;
} import_header = {
COFF_MachineType_UNKNOWN, // sig1
max_U16, // sig2
0, // version
machine,
time_stamp,
safe_cast_u32(/* name.size + */ dll_name.size + 2), // sizeof_data
0, // hint_ordinal
0, // flags
};
import_header.flags |= (U16)(type & COFF_IMPORT_HEADER_TYPE_MASK) << COFF_IMPORT_HEADER_TYPE_SHIFT;
import_header.flags |= COFF_ImportHeaderNameType_ORDINAL << COFF_IMPORT_HEADER_NAME_TYPE_SHIFT;
import_header.hint_ordinal = ordinal;
// alloc memory
U64 buffer_size = sizeof(import_header) + import_header.sizeof_data;
U8 *buffer = push_array_no_zero(arena, U8, buffer_size);
// copy header
MemoryCopyStruct(buffer, &import_header);
// no function name write zero
U8 *func_name = buffer + sizeof(import_header);
func_name[0] = 0;
// copy dll name
U8 *dll_name_buffer = buffer + sizeof(import_header) + /* name.size */ + 1;
MemoryCopy(dll_name_buffer, dll_name.str, dll_name.size);
dll_name_buffer[dll_name.size] = 0;
String8 import_data = str8(buffer, buffer_size);
return import_data;
}
////////////////////////////////
//~ Resources
internal String8
coff_resource_string_from_str16(Arena *arena, String16 string)
{
AssertAlways(string.size <= max_U16);
U16 size16 = (U16)string.size;
U16 *buffer = push_array_no_zero(arena, U16, size16 + 1);
MemoryCopy(buffer + 0, &size16, sizeof(size16));
MemoryCopy(buffer + 1, string.str, size16 * sizeof(string.str[0]));
return str8_array(buffer, size16 + 1);
}
internal String8
coff_resource_string_from_str8(Arena *arena, String8 string)
{
Temp scratch = scratch_begin(&arena, 1);
String16 string16 = str16_from_8(scratch.arena, string);
String8 result = coff_resource_string_from_str16(arena, string16);
scratch_end(scratch);
return result;
}
internal String8
coff_resource_number_from_u16(Arena *arena, U16 number)
{
U16 *buffer = push_array_no_zero(arena, U16, 2);
buffer[0] = max_U16;
buffer[1] = number;
return str8_array(buffer, 2);
}
internal B32 internal B32
coff_resource_id_is_equal(COFF_ResourceID a, COFF_ResourceID b) coff_resource_id_is_equal(COFF_ResourceID a, COFF_ResourceID b)
{ {
@@ -437,28 +626,9 @@ coff_resource_id_is_equal(COFF_ResourceID a, COFF_ResourceID b)
} }
internal COFF_ResourceID internal COFF_ResourceID
coff_resource_id_copy(Arena *arena, COFF_ResourceID id) coff_utf8_resource_id_from_utf16(Arena *arena, COFF_ResourceID_16 *id_16)
{ {
COFF_ResourceID result = zero_struct; COFF_ResourceID id = {0};
switch (id.type) {
case COFF_ResourceIDType_NULL: break;
case COFF_ResourceIDType_NUMBER: {
result.type = COFF_ResourceIDType_NUMBER;
result.u.number = id.u.number;
} break;
case COFF_ResourceIDType_STRING: {
result.type = COFF_ResourceIDType_STRING;
result.u.string = id.u.string;
} break;
default: Assert(!"invalid resource id type");
}
return result;
}
internal COFF_ResourceID
coff_convert_resource_id(Arena *arena, COFF_ResourceID_16 *id_16)
{
COFF_ResourceID id;
id.type = id_16->type; id.type = id_16->type;
switch (id_16->type) { switch (id_16->type) {
case COFF_ResourceIDType_NULL: break; case COFF_ResourceIDType_NULL: break;
@@ -468,23 +638,22 @@ coff_convert_resource_id(Arena *arena, COFF_ResourceID_16 *id_16)
case COFF_ResourceIDType_STRING: { case COFF_ResourceIDType_STRING: {
id.u.string = str8_from_16(arena, id_16->u.string); id.u.string = str8_from_16(arena, id_16->u.string);
} break; } break;
default: Assert(!"invalid resource id type"); default: InvalidPath;
} }
return id; return id;
} }
internal U64 internal U64
coff_read_resource_id(String8 data, U64 off, COFF_ResourceID_16 *id_out) coff_read_resource_id_utf16(String8 data, U64 off, COFF_ResourceID_16 *id_out)
{ {
U64 cursor = off; U64 cursor = off;
U16 flag = 0; U16 flag = 0;
str8_deserial_read_struct(data, cursor, &flag); str8_deserial_read_struct(data, cursor, &flag);
B32 is_number = flag == max_U16; if (flag == max_U16) {
if (is_number) {
cursor += sizeof(flag);
id_out->type = COFF_ResourceIDType_NUMBER; id_out->type = COFF_ResourceIDType_NUMBER;
cursor += sizeof(flag);
cursor += str8_deserial_read_struct(data, cursor, &id_out->u.number); cursor += str8_deserial_read_struct(data, cursor, &id_out->u.number);
} else { } else {
id_out->type = COFF_ResourceIDType_STRING; id_out->type = COFF_ResourceIDType_STRING;
@@ -492,72 +661,130 @@ coff_read_resource_id(String8 data, U64 off, COFF_ResourceID_16 *id_out)
} }
U64 read_size = cursor - off; U64 read_size = cursor - off;
read_size = AlignPow2(read_size, COFF_RES_ALIGN);
return read_size; return read_size;
} }
internal U64 internal U64
coff_read_resource(String8 raw_res, U64 off, Arena *arena, COFF_Resource *res_out) coff_read_resource(String8 raw_res, U64 off, Arena *arena, COFF_Resource *res_out)
{ {
// parse header String8 raw_header = str8_skip(raw_res, off);
COFF_ResourceHeaderPrefix prefix; MemoryZeroStruct(&prefix); U64 header_cursor = 0;
U64 cursor = str8_deserial_read_struct(raw_res, off, &prefix);
String8 header_data = str8_substr(raw_res, rng_1u64(off, off + prefix.header_size)); // prefix
COFF_ResourceHeaderPrefix prefix = {0};
header_cursor += str8_deserial_read_struct(raw_header, header_cursor, &prefix);
Assert(prefix.header_size >= sizeof(COFF_ResourceHeaderPrefix));
raw_header = str8_prefix(raw_header, prefix.header_size);
// header
COFF_ResourceID_16 type_16 = {0};
COFF_ResourceID_16 name_16 = {0};
header_cursor += coff_read_resource_id_utf16(raw_header, header_cursor, &type_16);
header_cursor += coff_read_resource_id_utf16(raw_header, header_cursor, &name_16);
header_cursor += str8_deserial_read_struct(raw_header, header_cursor, &res_out->data_version);
header_cursor += str8_deserial_read_struct(raw_header, header_cursor, &res_out->memory_flags);
header_cursor += str8_deserial_read_struct(raw_header, header_cursor, &res_out->language_id);
header_cursor += str8_deserial_read_struct(raw_header, header_cursor, &res_out->version);
header_cursor += str8_deserial_read_struct(raw_header, header_cursor, &res_out->characteristics);
Assert(prefix.header_size == header_cursor);
// convert utf-16 resource ids to utf-8
res_out->type = coff_utf8_resource_id_from_utf16(arena, &type_16);
res_out->name = coff_utf8_resource_id_from_utf16(arena, &name_16);
// read data
U64 data_read_size = str8_deserial_read_block(raw_res, off + prefix.header_size, prefix.data_size, &res_out->data);
Assert(prefix.data_size == data_read_size);
COFF_ResourceID_16 type_16; MemoryZeroStruct(&type_16); // compute read size
cursor += coff_read_resource_id(header_data, cursor, &type_16); U64 read_size = Max(prefix.header_size, sizeof(prefix)) + AlignPow2(prefix.data_size, COFF_RES_ALIGN);
cursor = AlignPow2(cursor, COFF_RES_ALIGN); return read_size;
COFF_ResourceID_16 name_16; MemoryZeroStruct(&name_16);
cursor += coff_read_resource_id(header_data, cursor, &name_16);
cursor = AlignPow2(cursor, COFF_RES_ALIGN);
U32 data_version = 0;
cursor += str8_deserial_read_struct(header_data, cursor, &data_version);
COFF_ResourceMemoryFlags memory_flags = 0;
cursor += str8_deserial_read_struct(header_data, cursor, &memory_flags);
U16 language_id = 0;
cursor += str8_deserial_read_struct(header_data, cursor, &language_id);
U32 version = 0;
cursor += str8_deserial_read_struct(header_data, cursor, &version);
U32 characteristics = 0;
cursor += str8_deserial_read_struct(header_data, cursor, &characteristics);
String8 data;
cursor += str8_deserial_read_block(raw_res, off + prefix.header_size, prefix.data_size, &data);
// was resource parsed?
Assert(cursor >= prefix.data_size + prefix.header_size);
// fill out result
res_out->type = coff_convert_resource_id(arena, &type_16);
res_out->name = coff_convert_resource_id(arena, &name_16);
res_out->language_id = language_id;
res_out->data_version = data_version;
res_out->version = version;
res_out->memory_flags = memory_flags;
res_out->data = data;
U64 resource_size = AlignPow2(prefix.data_size + prefix.header_size, COFF_RES_ALIGN);
return resource_size;
} }
internal COFF_ResourceList internal COFF_ResourceList
coff_resource_list_from_data(Arena *arena, String8 data) coff_resource_list_from_data(Arena *arena, String8 data)
{ {
COFF_ResourceList list; MemoryZeroStruct(&list); COFF_ResourceList list = {0};
for (U64 cursor = 0, stride; cursor < data.size; cursor += stride) { U64 cursor;
for (cursor = 0 ; cursor < data.size; ) {
COFF_ResourceNode *node = push_array(arena, COFF_ResourceNode, 1); COFF_ResourceNode *node = push_array(arena, COFF_ResourceNode, 1);
stride = coff_read_resource(data, cursor, arena, &node->data); cursor += coff_read_resource(data, cursor, arena, &node->data);
list.count += 1;
SLLQueuePush(list.first, list.last, node); SLLQueuePush(list.first, list.last, node);
++list.count;
} }
Assert(cursor == data.size);
return list; return list;
} }
internal String8
coff_write_resource_id(Arena *arena, COFF_ResourceID id)
{
String8 result = str8_zero();
switch (id.type) {
case COFF_ResourceIDType_NULL: break;
case COFF_ResourceIDType_NUMBER: {
result = coff_resource_number_from_u16(arena, id.u.number);
} break;
case COFF_ResourceIDType_STRING: {
result = coff_resource_string_from_str8(arena, id.u.string);
} break;
default: InvalidPath;
}
return result;
}
internal String8
coff_write_resource(Arena *arena,
COFF_ResourceID type,
COFF_ResourceID name,
U32 data_version,
COFF_ResourceMemoryFlags memory_flags,
U16 language_id,
U32 version,
U32 characteristics,
String8 data)
{
Temp scratch = scratch_begin(&arena, 1);
String8List list = {0};
COFF_ResourceHeaderPrefix *prefix = push_array(scratch.arena, COFF_ResourceHeaderPrefix, 1);
String8 packed_type = coff_write_resource_id(scratch.arena, type);
String8 packed_name = coff_write_resource_id(scratch.arena, name);
// prefix + header
str8_list_push(scratch.arena, &list, str8_struct(prefix));
str8_list_push(scratch.arena, &list, packed_type);
str8_list_push(scratch.arena, &list, packed_name);
str8_list_push(scratch.arena, &list, str8_struct(&data_version));
str8_list_push(scratch.arena, &list, str8_struct(&memory_flags));
str8_list_push(scratch.arena, &list, str8_struct(&language_id));
str8_list_push(scratch.arena, &list, str8_struct(&version));
str8_list_push(scratch.arena, &list, str8_struct(&characteristics));
prefix->data_size = safe_cast_u32(data.size);
prefix->header_size = safe_cast_u32(list.total_size);
// data
str8_list_push(scratch.arena, &list, data);
// magic
str8_list_push_front(scratch.arena, &list, str8_array_fixed(g_coff_res_magic));
// align
U64 align_size = AlignPow2(list.total_size, COFF_RES_ALIGN) - list.total_size;
U8 *align = push_array(scratch.arena, U8, align_size);
str8_list_push(scratch.arena, &list, str8(align, align_size));
// join
String8 res = str8_list_join(arena, &list, 0);
scratch_end(scratch);
return res;
}
//////////////////////////////// ////////////////////////////////
internal COFF_DataType internal COFF_DataType
@@ -567,12 +794,10 @@ coff_data_type_from_data(String8 data)
if (is_big_obj) { if (is_big_obj) {
return COFF_DataType_BIG_OBJ; return COFF_DataType_BIG_OBJ;
} }
B32 is_import = coff_is_import(data); B32 is_import = coff_is_import(data);
if (is_import) { if (is_import) {
return COFF_DataType_IMPORT; return COFF_DataType_IMPORT;
} }
return COFF_DataType_OBJ; return COFF_DataType_OBJ;
} }
@@ -591,18 +816,22 @@ coff_is_import(String8 data)
internal B32 internal B32
coff_is_archive(String8 data) coff_is_archive(String8 data)
{ {
U64 sig = 0; B32 is_archive = 0;
str8_deserial_read_struct(data, 0, &sig); U8 sig[sizeof(g_coff_archive_sig)];
B32 is_archive = sig == COFF_ARCHIVE_SIG; if (str8_deserial_read_struct(data, 0, &sig) == sizeof(sig)) {
is_archive = MemoryCompare(&sig[0], &g_coff_archive_sig[0], sizeof(g_coff_archive_sig)) == 0;
}
return is_archive; return is_archive;
} }
internal B32 internal B32
coff_is_thin_archive(String8 data) coff_is_thin_archive(String8 data)
{ {
U64 sig = 0; B32 is_archive = 0;
str8_deserial_read_struct(data, 0, &sig); U8 sig[sizeof(g_coff_thin_archive_sig)];
B32 is_archive = sig == COFF_THIN_ARCHIVE_SIG; if (str8_deserial_read_struct(data, 0, &sig) == sizeof(sig)) {
is_archive = MemoryCompare(&sig[0], &g_coff_thin_archive_sig[0], sizeof(g_coff_thin_archive_sig)) == 0;
}
return is_archive; return is_archive;
} }
@@ -751,11 +980,9 @@ coff_read_archive_long_name(String8 long_names, String8 name)
internal U64 internal U64
coff_archive_member_iter_init(String8 data) coff_archive_member_iter_init(String8 data)
{ {
U64 cursor = 0; U64 cursor = data.size;
U64 sig = 0; if (coff_is_archive(data)) {
cursor += str8_deserial_read_struct(data, cursor, &sig); cursor = sizeof(g_coff_archive_sig);
if (sig != COFF_ARCHIVE_SIG) {
cursor = data.size;
} }
return cursor; return cursor;
} }
@@ -915,11 +1142,9 @@ coff_archive_from_data(Arena *arena, String8 data)
internal U64 internal U64
coff_thin_archive_member_iter_init(String8 data) coff_thin_archive_member_iter_init(String8 data)
{ {
U64 cursor = 0; U64 cursor = data.size;
U64 sig = 0; if (coff_is_thin_archive(data)) {
cursor += str8_deserial_read_struct(data, cursor, &sig); cursor = sizeof(g_coff_thin_archive_sig);
if (sig != COFF_THIN_ARCHIVE_SIG) {
cursor = data.size;
} }
return cursor; return cursor;
} }
@@ -990,18 +1215,59 @@ coff_archive_parse_from_data(Arena *arena, String8 data)
//////////////////////////////// ////////////////////////////////
read_only struct
{
String8 string;
COFF_MachineType machine;
} g_coff_machine_map[] = {
{ str8_lit_comp(""), COFF_MachineType_UNKNOWN },
{ str8_lit_comp("X86"), COFF_MachineType_X86 },
{ str8_lit_comp("AMD64"), COFF_MachineType_X64 },
{ str8_lit_comp("X64"), COFF_MachineType_X64 },
{ str8_lit_comp("AM33"), COFF_MachineType_AM33 },
{ str8_lit_comp("ARM"), COFF_MachineType_ARM },
{ str8_lit_comp("ARM64"), COFF_MachineType_ARM64 },
{ str8_lit_comp("ARMNT"), COFF_MachineType_ARMNT },
{ str8_lit_comp("EBC"), COFF_MachineType_EBC },
{ str8_lit_comp("IA64"), COFF_MachineType_IA64 },
{ str8_lit_comp("M32R"), COFF_MachineType_M32R },
{ str8_lit_comp("MIPS16"), COFF_MachineType_MIPS16 },
{ str8_lit_comp("MIPSFPU"), COFF_MachineType_MIPSFPU },
{ str8_lit_comp("MIPSFPU16"), COFF_MachineType_MIPSFPU16 },
{ str8_lit_comp("POWERPC"), COFF_MachineType_POWERPC },
{ str8_lit_comp("POWERPCFP"), COFF_MachineType_POWERPCFP },
{ str8_lit_comp("R4000"), COFF_MachineType_R4000 },
{ str8_lit_comp("RISCV32"), COFF_MachineType_RISCV32 },
{ str8_lit_comp("RISCV64"), COFF_MachineType_RISCV64 },
{ str8_lit_comp("SH3"), COFF_MachineType_SH3 },
{ str8_lit_comp("SH3DSP"), COFF_MachineType_SH3DSP },
{ str8_lit_comp("SH4"), COFF_MachineType_SH4 },
{ str8_lit_comp("SH5"), COFF_MachineType_SH5 },
{ str8_lit_comp("THUMB"), COFF_MachineType_THUMB },
{ str8_lit_comp("WCEMIPSV2"), COFF_MachineType_WCEMIPSV2 },
};
read_only static struct {
char * name;
COFF_ImportHeaderType type;
} g_coff_import_header_type_map[] = {
{ "CODE", COFF_ImportHeaderType_CODE },
{ "DATA", COFF_ImportHeaderType_DATA },
{ "CONST", COFF_ImportHeaderType_CONST },
};
internal String8 internal String8
coff_string_from_comdat_select_type(COFF_ComdatSelectType select) coff_string_from_comdat_select_type(COFF_ComdatSelectType select)
{ {
String8 result = str8(0,0); String8 result = str8(0,0);
switch (select) { switch (select) {
case COFF_ComdatSelectType_NULL: result = str8_lit("NULL"); break; case COFF_ComdatSelectType_NULL: result = str8_lit("NULL"); break;
case COFF_ComdatSelectType_NODUPLICATES: result = str8_lit("NODUPLICATES"); break; case COFF_ComdatSelectType_NODUPLICATES: result = str8_lit("NODUPLICATES"); break;
case COFF_ComdatSelectType_ANY: result = str8_lit("ANY"); break; case COFF_ComdatSelectType_ANY: result = str8_lit("ANY"); break;
case COFF_ComdatSelectType_SAME_SIZE: result = str8_lit("SAME_SIZE"); break; case COFF_ComdatSelectType_SAME_SIZE: result = str8_lit("SAME_SIZE"); break;
case COFF_ComdatSelectType_EXACT_MATCH: result = str8_lit("EXACT_MATCH"); break; case COFF_ComdatSelectType_EXACT_MATCH: result = str8_lit("EXACT_MATCH"); break;
case COFF_ComdatSelectType_ASSOCIATIVE: result = str8_lit("ASSOCIATIVE"); break; case COFF_ComdatSelectType_ASSOCIATIVE: result = str8_lit("ASSOCIATIVE"); break;
case COFF_ComdatSelectType_LARGEST: result = str8_lit("LARGEST"); break; case COFF_ComdatSelectType_LARGEST: result = str8_lit("LARGEST"); break;
} }
return result; return result;
} }
@@ -1009,35 +1275,12 @@ coff_string_from_comdat_select_type(COFF_ComdatSelectType select)
internal String8 internal String8
coff_string_from_machine_type(COFF_MachineType machine) coff_string_from_machine_type(COFF_MachineType machine)
{ {
String8 result = str8(0,0); for (U64 i = 0; i < ArrayCount(g_coff_machine_map); ++i) {
switch (machine) { if (g_coff_machine_map[i].machine == machine) {
case COFF_MachineType_UNKNOWN: result = str8_lit("UNKNOWN"); break; return g_coff_machine_map[i].string;
case COFF_MachineType_X86: result = str8_lit("X86"); break; }
case COFF_MachineType_X64: result = str8_lit("X64"); break;
case COFF_MachineType_AM33: result = str8_lit("AM33"); break;
case COFF_MachineType_ARM: result = str8_lit("ARM"); break;
case COFF_MachineType_ARM64: result = str8_lit("ARM64"); break;
case COFF_MachineType_ARMNT: result = str8_lit("ARMNT"); break;
case COFF_MachineType_EBC: result = str8_lit("EBC"); break;
case COFF_MachineType_IA64: result = str8_lit("IA64"); break;
case COFF_MachineType_M32R: result = str8_lit("M32R"); break;
case COFF_MachineType_MIPS16: result = str8_lit("MIPS16"); break;
case COFF_MachineType_MIPSFPU: result = str8_lit("MIPSFPU"); break;
case COFF_MachineType_MIPSFPU16: result = str8_lit("MIPSFPU16"); break;
case COFF_MachineType_POWERPC: result = str8_lit("POWERPC"); break;
case COFF_MachineType_POWERPCFP: result = str8_lit("POWERPCFP"); break;
case COFF_MachineType_R4000: result = str8_lit("R4000"); break;
case COFF_MachineType_RISCV32: result = str8_lit("RISCV32"); break;
case COFF_MachineType_RISCV64: result = str8_lit("RISCV64"); break;
case COFF_MachineType_RISCV128: result = str8_lit("RISCV128"); break;
case COFF_MachineType_SH3: result = str8_lit("SH3"); break;
case COFF_MachineType_SH3DSP: result = str8_lit("SH3DSP"); break;
case COFF_MachineType_SH4: result = str8_lit("SH4"); break;
case COFF_MachineType_SH5: result = str8_lit("SH5"); break;
case COFF_MachineType_THUMB: result = str8_lit("THUMB"); break;
case COFF_MachineType_WCEMIPSV2: result = str8_lit("WCEMIPSV2"); break;
} }
return result; return str8_zero();
} }
internal String8 internal String8
@@ -1117,3 +1360,36 @@ coff_string_from_section_flags(Arena *arena, COFF_SectionFlags flags)
return result; return result;
} }
internal String8
coff_string_from_import_header_type(COFF_ImportHeaderType type)
{
for (U64 i = 0; i < ArrayCount(g_coff_import_header_type_map); ++i) {
if (g_coff_import_header_type_map[i].type == type) {
return str8_cstring(g_coff_import_header_type_map[i].name);
}
}
return str8(0,0);
}
internal COFF_MachineType
coff_machine_from_string(String8 string)
{
for (U64 i = 0; i < ArrayCount(g_coff_machine_map); ++i) {
if (str8_match(g_coff_machine_map[i].string, string, StringMatchFlag_CaseInsensitive)) {
return g_coff_machine_map[i].machine;
}
}
return COFF_MachineType_UNKNOWN;
}
internal COFF_ImportHeaderType
coff_import_header_type_from_string(String8 name)
{
for (U64 i = 0; i < ArrayCount(g_coff_import_header_type_map); ++i) {
if (str8_match(str8_cstring(g_coff_import_header_type_map[i].name), name, StringMatchFlag_CaseInsensitive)) {
return g_coff_import_header_type_map[i].type;
}
}
return COFF_ImportHeaderType_COUNT;
}
+308 -286
View File
@@ -77,12 +77,12 @@ typedef struct COFF_Header COFF_Header;
struct COFF_Header struct COFF_Header
{ {
COFF_MachineType machine; COFF_MachineType machine;
U16 section_count; U16 section_count;
COFF_TimeStamp time_stamp; COFF_TimeStamp time_stamp;
U32 symbol_table_foff; U32 symbol_table_foff;
U32 symbol_count; U32 symbol_count;
U16 optional_header_size; U16 optional_header_size;
COFF_Flags flags; COFF_Flags flags;
}; };
typedef U32 COFF_SectionAlign; typedef U32 COFF_SectionAlign;
@@ -108,35 +108,36 @@ enum
typedef U32 COFF_SectionFlags; typedef U32 COFF_SectionFlags;
enum enum
{ {
COFF_SectionFlag_TYPE_NO_PAD = (1 << 3), COFF_SectionFlag_TYPE_NO_PAD = (1 << 3),
COFF_SectionFlag_CNT_CODE = (1 << 5), COFF_SectionFlag_CNT_CODE = (1 << 5),
COFF_SectionFlag_CNT_INITIALIZED_DATA = (1 << 6), COFF_SectionFlag_CNT_INITIALIZED_DATA = (1 << 6),
COFF_SectionFlag_CNT_UNINITIALIZED_DATA = (1 << 7), COFF_SectionFlag_CNT_UNINITIALIZED_DATA = (1 << 7),
COFF_SectionFlag_LNK_OTHER = (1 << 8), COFF_SectionFlag_LNK_OTHER = (1 << 8),
COFF_SectionFlag_LNK_INFO = (1 << 9), COFF_SectionFlag_LNK_INFO = (1 << 9),
COFF_SectionFlag_LNK_REMOVE = (1 << 11), COFF_SectionFlag_LNK_REMOVE = (1 << 11),
COFF_SectionFlag_LNK_COMDAT = (1 << 12), COFF_SectionFlag_LNK_COMDAT = (1 << 12),
COFF_SectionFlag_GPREL = (1 << 15), COFF_SectionFlag_GPREL = (1 << 15),
COFF_SectionFlag_MEM_16BIT = (1 << 17), COFF_SectionFlag_MEM_16BIT = (1 << 17),
COFF_SectionFlag_MEM_LOCKED = (1 << 18), COFF_SectionFlag_MEM_LOCKED = (1 << 18),
COFF_SectionFlag_MEM_PRELOAD = (1 << 19), COFF_SectionFlag_MEM_PRELOAD = (1 << 19),
COFF_SectionFlag_ALIGN_SHIFT = 20, COFF_SectionFlag_ALIGN_MASK = 0xf, COFF_SectionFlag_ALIGN_SHIFT = 20,
COFF_SectionFlag_LNK_NRELOC_OVFL = (1 << 24), COFF_SectionFlag_ALIGN_MASK = 0xf,
COFF_SectionFlag_MEM_DISCARDABLE = (1 << 25), COFF_SectionFlag_LNK_NRELOC_OVFL = (1 << 24),
COFF_SectionFlag_MEM_NOT_CACHED = (1 << 26), COFF_SectionFlag_MEM_DISCARDABLE = (1 << 25),
COFF_SectionFlag_MEM_NOT_PAGED = (1 << 27), COFF_SectionFlag_MEM_NOT_CACHED = (1 << 26),
COFF_SectionFlag_MEM_SHARED = (1 << 28), COFF_SectionFlag_MEM_NOT_PAGED = (1 << 27),
COFF_SectionFlag_MEM_EXECUTE = (1 << 29), COFF_SectionFlag_MEM_SHARED = (1 << 28),
COFF_SectionFlag_MEM_READ = (1 << 30), COFF_SectionFlag_MEM_EXECUTE = (1 << 29),
COFF_SectionFlag_MEM_WRITE = (1 << 31), COFF_SectionFlag_MEM_READ = (1 << 30),
COFF_SectionFlag_MEM_WRITE = (1 << 31),
}; };
#define COFF_SectionFlags_Extract_ALIGN(f) (COFF_SectionAlign)(((f) >> COFF_SectionFlag_ALIGN_SHIFT) & COFF_SectionFlag_ALIGN_MASK) #define COFF_SectionFlags_Extract_ALIGN(f) (COFF_SectionAlign)(((f) >> COFF_SectionFlag_ALIGN_SHIFT) & COFF_SectionFlag_ALIGN_MASK)
#define COFF_SectionFlags_LNK_FLAGS ((COFF_SectionFlag_ALIGN_MASK << COFF_SectionFlag_ALIGN_SHIFT) | COFF_SectionFlag_LNK_COMDAT | COFF_SectionFlag_LNK_INFO | COFF_SectionFlag_LNK_OTHER | COFF_SectionFlag_LNK_REMOVE | COFF_SectionFlag_LNK_NRELOC_OVFL) #define COFF_SectionFlags_LNK_FLAGS ((COFF_SectionFlag_ALIGN_MASK << COFF_SectionFlag_ALIGN_SHIFT) | COFF_SectionFlag_LNK_COMDAT | COFF_SectionFlag_LNK_INFO | COFF_SectionFlag_LNK_OTHER | COFF_SectionFlag_LNK_REMOVE | COFF_SectionFlag_LNK_NRELOC_OVFL)
typedef struct COFF_SectionHeader COFF_SectionHeader; typedef struct COFF_SectionHeader COFF_SectionHeader;
struct COFF_SectionHeader struct COFF_SectionHeader
{ {
U8 name[8]; U8 name[8];
U32 vsize; U32 vsize;
U32 voff; U32 voff;
U32 fsize; U32 fsize;
@@ -151,112 +152,99 @@ struct COFF_SectionHeader
typedef U16 COFF_RelocTypeX64; typedef U16 COFF_RelocTypeX64;
enum enum
{ {
COFF_RelocTypeX64_ABS = 0x0, COFF_RelocTypeX64_ABS = 0x0,
COFF_RelocTypeX64_ADDR64 = 0x1, COFF_RelocTypeX64_ADDR64 = 0x1,
COFF_RelocTypeX64_ADDR32 = 0x2, COFF_RelocTypeX64_ADDR32 = 0x2,
COFF_RelocTypeX64_ADDR32NB = 0x3, COFF_RelocTypeX64_ADDR32NB = 0x3, // NB => No Base
// NB => No Base COFF_RelocTypeX64_REL32 = 0x4,
COFF_RelocTypeX64_REL32 = 0x4, COFF_RelocTypeX64_REL32_1 = 0x5,
COFF_RelocTypeX64_REL32_1 = 0x5, COFF_RelocTypeX64_REL32_2 = 0x6,
COFF_RelocTypeX64_REL32_2 = 0x6, COFF_RelocTypeX64_REL32_3 = 0x7,
COFF_RelocTypeX64_REL32_3 = 0x7, COFF_RelocTypeX64_REL32_4 = 0x8,
COFF_RelocTypeX64_REL32_4 = 0x8, COFF_RelocTypeX64_REL32_5 = 0x9,
COFF_RelocTypeX64_REL32_5 = 0x9, COFF_RelocTypeX64_SECTION = 0xA,
COFF_RelocTypeX64_SECTION = 0xA, COFF_RelocTypeX64_SECREL = 0xB,
COFF_RelocTypeX64_SECREL = 0xB, COFF_RelocTypeX64_SECREL7 = 0xC, // TODO(nick): MSDN doesn't specify size for CLR token
COFF_RelocTypeX64_SECREL7 = 0xC, COFF_RelocTypeX64_TOKEN = 0xD,
// TODO(nick): MSDN doesn't specify size for CLR token COFF_RelocTypeX64_SREL32 = 0xE, // TODO(nick): MSDN doesn't specify size for PAIR
COFF_RelocTypeX64_TOKEN = 0xD, COFF_RelocTypeX64_PAIR = 0xF,
COFF_RelocTypeX64_SREL32 = 0xE, COFF_RelocTypeX64_SSPAN32 = 0x10,
// TODO(nick): MSDN doesn't specify size for PAIR COFF_RelocTypeX64_COUNT = 17
COFF_RelocTypeX64_PAIR = 0xF,
COFF_RelocTypeX64_SSPAN32 = 0x10,
COFF_RelocTypeX64_COUNT = 17
}; };
typedef U16 COFF_RelocTypeX86; typedef U16 COFF_RelocTypeX86;
enum enum
{ {
COFF_RelocTypeX86_ABS = 0x0, COFF_RelocTypeX86_ABS = 0x0, // relocation is ignored
// relocation is ignored COFF_RelocTypeX86_DIR16 = 0x1, // no support
COFF_RelocTypeX86_DIR16 = 0x1, COFF_RelocTypeX86_REL16 = 0x2, // no support
// no support COFF_RelocTypeX86_UNKNOWN0 = 0x3,
COFF_RelocTypeX86_REL16 = 0x2, COFF_RelocTypeX86_UNKNOWN2 = 0x4,
// no support COFF_RelocTypeX86_UNKNOWN3 = 0x5,
COFF_RelocTypeX86_UNKNOWN0 = 0x3, COFF_RelocTypeX86_DIR32 = 0x6, // 32-bit virtual address
COFF_RelocTypeX86_UNKNOWN2 = 0x4, COFF_RelocTypeX86_DIR32NB = 0x7, // 32-bit virtual offset
COFF_RelocTypeX86_UNKNOWN3 = 0x5, COFF_RelocTypeX86_SEG12 = 0x9, // no support
COFF_RelocTypeX86_DIR32 = 0x6, COFF_RelocTypeX86_SECTION = 0xA, // 16-bit section index, used for debug info purposes
// 32-bit virtual address COFF_RelocTypeX86_SECREL = 0xB, // 32-bit offset from start of a section
COFF_RelocTypeX86_DIR32NB = 0x7, COFF_RelocTypeX86_TOKEN = 0xC, // CLR token? (for managed languages)
// 32-bit virtual offset COFF_RelocTypeX86_SECREL7 = 0xD, // 7-bit offset from the base of the section that contains the target.
COFF_RelocTypeX86_SEG12 = 0x9, COFF_RelocTypeX86_UNKNOWN4 = 0xE,
// no support COFF_RelocTypeX86_UNKNOWN5 = 0xF,
COFF_RelocTypeX86_SECTION = 0xA, COFF_RelocTypeX86_UNKNOWN6 = 0x10,
// 16-bit section index, used for debug info purposes COFF_RelocTypeX86_UNKNOWN7 = 0x11,
COFF_RelocTypeX86_SECREL = 0xB, COFF_RelocTypeX86_UNKNOWN8 = 0x12,
// 32-bit offset from start of a section COFF_RelocTypeX86_UNKNOWN9 = 0x13,
COFF_RelocTypeX86_TOKEN = 0xC, COFF_RelocTypeX86_REL32 = 0x14,
// CLR token? (for managed languages) COFF_RelocTypeX86_COUNT = 20
COFF_RelocTypeX86_SECREL7 = 0xD,
// 7-bit offset from the base of the section that contains the target.
COFF_RelocTypeX86_UNKNOWN4 = 0xE,
COFF_RelocTypeX86_UNKNOWN5 = 0xF,
COFF_RelocTypeX86_UNKNOWN6 = 0x10,
COFF_RelocTypeX86_UNKNOWN7 = 0x11,
COFF_RelocTypeX86_UNKNOWN8 = 0x12,
COFF_RelocTypeX86_UNKNOWN9 = 0x13,
COFF_RelocTypeX86_REL32 = 0x14,
COFF_RelocTypeX86_COUNT = 20
}; };
typedef U16 COFF_RelocTypeARM; typedef U16 COFF_RelocTypeARM;
enum enum
{ {
COFF_RelocTypeARM_ABS = 0x0, COFF_RelocTypeARM_ABS = 0x0,
COFF_RelocTypeARM_ADDR32 = 0x1, COFF_RelocTypeARM_ADDR32 = 0x1,
COFF_RelocTypeARM_ADDR32NB = 0x2, COFF_RelocTypeARM_ADDR32NB = 0x2,
COFF_RelocTypeARM_BRANCH24 = 0x3, COFF_RelocTypeARM_BRANCH24 = 0x3,
COFF_RelocTypeARM_BRANCH11 = 0x4, COFF_RelocTypeARM_BRANCH11 = 0x4,
COFF_RelocTypeARM_UNKNOWN1 = 0x5, COFF_RelocTypeARM_UNKNOWN1 = 0x5,
COFF_RelocTypeARM_UNKNOWN2 = 0x6, COFF_RelocTypeARM_UNKNOWN2 = 0x6,
COFF_RelocTypeARM_UNKNOWN3 = 0x7, COFF_RelocTypeARM_UNKNOWN3 = 0x7,
COFF_RelocTypeARM_UNKNOWN4 = 0x8, COFF_RelocTypeARM_UNKNOWN4 = 0x8,
COFF_RelocTypeARM_UNKNOWN5 = 0x9, COFF_RelocTypeARM_UNKNOWN5 = 0x9,
COFF_RelocTypeARM_REL32 = 0xA, COFF_RelocTypeARM_REL32 = 0xA,
COFF_RelocTypeARM_SECTION = 0xE, COFF_RelocTypeARM_SECTION = 0xE,
COFF_RelocTypeARM_SECREL = 0xF, COFF_RelocTypeARM_SECREL = 0xF,
COFF_RelocTypeARM_MOV32 = 0x10, COFF_RelocTypeARM_MOV32 = 0x10,
COFF_RelocTypeARM_THUMB_MOV32 = 0x11, COFF_RelocTypeARM_THUMB_MOV32 = 0x11,
COFF_RelocTypeARM_THUMB_BRANCH20 = 0x12, COFF_RelocTypeARM_THUMB_BRANCH20 = 0x12,
COFF_RelocTypeARM_UNUSED = 0x13, COFF_RelocTypeARM_UNUSED = 0x13,
COFF_RelocTypeARM_THUMB_BRANCH24 = 0x14, COFF_RelocTypeARM_THUMB_BRANCH24 = 0x14,
COFF_RelocTypeARM_THUMB_BLX23 = 0x15, COFF_RelocTypeARM_THUMB_BLX23 = 0x15,
COFF_RelocTypeARM_PAIR = 0x16, COFF_RelocTypeARM_PAIR = 0x16,
COFF_RelocTypeARM_COUNT = 20 COFF_RelocTypeARM_COUNT = 20
}; };
typedef U16 COFF_RelocTypeARM64; typedef U16 COFF_RelocTypeARM64;
enum enum
{ {
COFF_RelocTypeARM64_ABS = 0x0, COFF_RelocTypeARM64_ABS = 0x0,
COFF_RelocTypeARM64_ADDR32 = 0x1, COFF_RelocTypeARM64_ADDR32 = 0x1,
COFF_RelocTypeARM64_ADDR32NB = 0x2, COFF_RelocTypeARM64_ADDR32NB = 0x2,
COFF_RelocTypeARM64_BRANCH26 = 0x3, COFF_RelocTypeARM64_BRANCH26 = 0x3,
COFF_RelocTypeARM64_PAGEBASE_REL21 = 0x4, COFF_RelocTypeARM64_PAGEBASE_REL21 = 0x4,
COFF_RelocTypeARM64_REL21 = 0x5, COFF_RelocTypeARM64_REL21 = 0x5,
COFF_RelocTypeARM64_PAGEOFFSET_12A = 0x6, COFF_RelocTypeARM64_PAGEOFFSET_12A = 0x6,
COFF_RelocTypeARM64_SECREL = 0x8, COFF_RelocTypeARM64_SECREL = 0x8,
COFF_RelocTypeARM64_SECREL_LOW12A = 0x9, COFF_RelocTypeARM64_SECREL_LOW12A = 0x9,
COFF_RelocTypeARM64_SECREL_HIGH12A = 0xA, COFF_RelocTypeARM64_SECREL_HIGH12A = 0xA,
COFF_RelocTypeARM64_SECREL_LOW12L = 0xB, COFF_RelocTypeARM64_SECREL_LOW12L = 0xB,
COFF_RelocTypeARM64_TOKEN = 0xC, COFF_RelocTypeARM64_TOKEN = 0xC,
COFF_RelocTypeARM64_SECTION = 0xD, COFF_RelocTypeARM64_SECTION = 0xD,
COFF_RelocTypeARM64_ADDR64 = 0xE, COFF_RelocTypeARM64_ADDR64 = 0xE,
COFF_RelocTypeARM64_BRANCH19 = 0xF, COFF_RelocTypeARM64_BRANCH19 = 0xF,
COFF_RelocTypeARM64_BRANCH14 = 0x10, COFF_RelocTypeARM64_BRANCH14 = 0x10,
COFF_RelocTypeARM64_REL32 = 0x11, COFF_RelocTypeARM64_REL32 = 0x11,
COFF_RelocTypeARM64_COUNT = 17 COFF_RelocTypeARM64_COUNT = 17
}; };
typedef U8 COFF_SymType; typedef U8 COFF_SymType;
@@ -273,8 +261,7 @@ enum
COFF_SymType_STRUCT, COFF_SymType_STRUCT,
COFF_SymType_UNION, COFF_SymType_UNION,
COFF_SymType_ENUM, COFF_SymType_ENUM,
COFF_SymType_MOE, COFF_SymType_MOE, // member of enumeration
// member of enumeration
COFF_SymType_BYTE, COFF_SymType_BYTE,
COFF_SymType_WORD, COFF_SymType_WORD,
COFF_SymType_UINT, COFF_SymType_UINT,
@@ -285,100 +272,100 @@ enum
typedef U8 COFF_SymStorageClass; typedef U8 COFF_SymStorageClass;
enum enum
{ {
COFF_SymStorageClass_END_OF_FUNCTION = 0xff, COFF_SymStorageClass_END_OF_FUNCTION = 0xff,
COFF_SymStorageClass_NULL = 0, COFF_SymStorageClass_NULL = 0,
COFF_SymStorageClass_AUTOMATIC = 1, COFF_SymStorageClass_AUTOMATIC = 1,
COFF_SymStorageClass_EXTERNAL = 2, COFF_SymStorageClass_EXTERNAL = 2,
COFF_SymStorageClass_STATIC = 3, COFF_SymStorageClass_STATIC = 3,
COFF_SymStorageClass_REGISTER = 4, COFF_SymStorageClass_REGISTER = 4,
COFF_SymStorageClass_EXTERNAL_DEF = 5, COFF_SymStorageClass_EXTERNAL_DEF = 5,
COFF_SymStorageClass_LABEL = 6, COFF_SymStorageClass_LABEL = 6,
COFF_SymStorageClass_UNDEFINED_LABEL = 7, COFF_SymStorageClass_UNDEFINED_LABEL = 7,
COFF_SymStorageClass_MEMBER_OF_STRUCT = 8, COFF_SymStorageClass_MEMBER_OF_STRUCT = 8,
COFF_SymStorageClass_ARGUMENT = 9, COFF_SymStorageClass_ARGUMENT = 9,
COFF_SymStorageClass_STRUCT_TAG = 10, COFF_SymStorageClass_STRUCT_TAG = 10,
COFF_SymStorageClass_MEMBER_OF_UNION = 11, COFF_SymStorageClass_MEMBER_OF_UNION = 11,
COFF_SymStorageClass_UNION_TAG = 12, COFF_SymStorageClass_UNION_TAG = 12,
COFF_SymStorageClass_TYPE_DEFINITION = 13, COFF_SymStorageClass_TYPE_DEFINITION = 13,
COFF_SymStorageClass_UNDEFINED_STATIC = 14, COFF_SymStorageClass_UNDEFINED_STATIC = 14,
COFF_SymStorageClass_ENUM_TAG = 15, COFF_SymStorageClass_ENUM_TAG = 15,
COFF_SymStorageClass_MEMBER_OF_ENUM = 16, COFF_SymStorageClass_MEMBER_OF_ENUM = 16,
COFF_SymStorageClass_REGISTER_PARAM = 17, COFF_SymStorageClass_REGISTER_PARAM = 17,
COFF_SymStorageClass_BIT_FIELD = 18, COFF_SymStorageClass_BIT_FIELD = 18,
COFF_SymStorageClass_BLOCK = 100, COFF_SymStorageClass_BLOCK = 100,
COFF_SymStorageClass_FUNCTION = 101, COFF_SymStorageClass_FUNCTION = 101,
COFF_SymStorageClass_END_OF_STRUCT = 102, COFF_SymStorageClass_END_OF_STRUCT = 102,
COFF_SymStorageClass_FILE = 103, COFF_SymStorageClass_FILE = 103,
COFF_SymStorageClass_SECTION = 104, COFF_SymStorageClass_SECTION = 104,
COFF_SymStorageClass_WEAK_EXTERNAL = 105, COFF_SymStorageClass_WEAK_EXTERNAL = 105,
COFF_SymStorageClass_CLR_TOKEN = 107, COFF_SymStorageClass_CLR_TOKEN = 107,
COFF_SymStorageClass_COUNT = 27 COFF_SymStorageClass_COUNT = 27
}; };
typedef U16 COFF_SymSecNumber; typedef U16 COFF_SymSecNumber;
enum enum
{ {
COFF_SymSecNumber_NUMBER_UNDEFINED = 0, COFF_SymSecNumber_NUMBER_UNDEFINED = 0,
COFF_SymSecNumber_ABSOLUTE = 0xffff, COFF_SymSecNumber_ABSOLUTE = 0xffff,
COFF_SymSecNumber_DEBUG = 0xfffe, COFF_SymSecNumber_DEBUG = 0xfffe,
COFF_SymSecNumber_COUNT = 3 COFF_SymSecNumber_COUNT = 3
}; };
typedef U8 COFF_SymDType; typedef U8 COFF_SymDType;
enum enum
{ {
COFF_SymDType_NULL = 0, COFF_SymDType_NULL = 0,
COFF_SymDType_PTR = 16, COFF_SymDType_PTR = 16,
COFF_SymDType_FUNC = 32, COFF_SymDType_FUNC = 32,
COFF_SymDType_ARRAY = 48, COFF_SymDType_ARRAY = 48,
COFF_SymDType_COUNT = 4 COFF_SymDType_COUNT = 4
}; };
typedef U32 COFF_WeakExtType; typedef U32 COFF_WeakExtType;
enum enum
{ {
COFF_WeakExtType_NOLIBRARY = 1, COFF_WeakExtType_NOLIBRARY = 1,
COFF_WeakExtType_SEARCH_LIBRARY = 2, COFF_WeakExtType_SEARCH_LIBRARY = 2,
COFF_WeakExtType_SEARCH_ALIAS = 3, COFF_WeakExtType_SEARCH_ALIAS = 3,
COFF_WeakExtType_COUNT = 3 COFF_WeakExtType_COUNT = 3
}; };
typedef U32 COFF_ImportHeaderType; typedef U32 COFF_ImportHeaderType;
enum enum
{ {
COFF_ImportHeaderType_CODE = 0, COFF_ImportHeaderType_CODE = 0,
COFF_ImportHeaderType_DATA = 1, COFF_ImportHeaderType_DATA = 1,
COFF_ImportHeaderType_CONST = 2, COFF_ImportHeaderType_CONST = 2,
COFF_ImportHeaderType_COUNT = 3 COFF_ImportHeaderType_COUNT = 3
}; };
typedef U32 COFF_ImportHeaderNameType; typedef U32 COFF_ImportHeaderNameType;
enum enum
{ {
COFF_ImportHeaderNameType_ORDINAL = 0, COFF_ImportHeaderNameType_ORDINAL = 0,
COFF_ImportHeaderNameType_NAME = 1, COFF_ImportHeaderNameType_NAME = 1,
COFF_ImportHeaderNameType_NAME_NOPREFIX = 2, COFF_ImportHeaderNameType_NAME_NOPREFIX = 2,
COFF_ImportHeaderNameType_UNDECORATE = 3, COFF_ImportHeaderNameType_UNDECORATE = 3,
COFF_ImportHeaderNameType_COUNT = 4 COFF_ImportHeaderNameType_COUNT = 4
}; };
#define COFF_IMPORT_HEADER_TYPE_MASK 0x03 #define COFF_IMPORT_HEADER_TYPE_MASK 0x03
#define COFF_IMPORT_HEADER_TYPE_SHIFT 0 #define COFF_IMPORT_HEADER_TYPE_SHIFT 0
#define COFF_IMPORT_HEADER_NAME_TYPE_MASK 0x1c #define COFF_IMPORT_HEADER_NAME_TYPE_MASK 0x1c
#define COFF_IMPORT_HEADER_NAME_TYPE_SHIFT 2 #define COFF_IMPORT_HEADER_NAME_TYPE_SHIFT 2
#define COFF_IMPORT_HEADER_GET_TYPE(x) (((x) & COFF_IMPORT_HEADER_TYPE_MASK) >> COFF_IMPORT_HEADER_TYPE_SHIFT) #define COFF_IMPORT_HEADER_GET_TYPE(x) (((x) & COFF_IMPORT_HEADER_TYPE_MASK) >> COFF_IMPORT_HEADER_TYPE_SHIFT)
#define COFF_IMPORT_HEADER_GET_NAME_TYPE(x) (((x) & COFF_IMPORT_HEADER_NAME_TYPE_MASK) >> COFF_IMPORT_HEADER_NAME_TYPE_SHIFT) #define COFF_IMPORT_HEADER_GET_NAME_TYPE(x) (((x) & COFF_IMPORT_HEADER_NAME_TYPE_MASK) >> COFF_IMPORT_HEADER_NAME_TYPE_SHIFT)
typedef struct COFF_ImportHeader typedef struct COFF_ImportHeader
{ {
U16 sig1; U16 sig1;
U16 sig2; U16 sig2;
U16 version; U16 version;
U16 machine; U16 machine;
COFF_TimeStamp time_stamp; COFF_TimeStamp time_stamp;
U32 data_size; U32 data_size;
U16 hint; U16 hint;
U16 type; U16 type;
U16 name_type; U16 name_type;
// type : 2 // type : 2
// name type : 3 // name type : 3
// reserved : 11 // reserved : 11
@@ -390,30 +377,18 @@ typedef struct COFF_ImportHeader
typedef U8 COFF_ComdatSelectType; typedef U8 COFF_ComdatSelectType;
enum enum
{ {
COFF_ComdatSelectType_NULL = 0, COFF_ComdatSelectType_NULL = 0, // Only one symbol is allowed to be in global symbol table, otherwise multiply defintion error is thrown.
// Only one symbol is allowed to be in global symbol table, otherwise multiply defintion error is thrown. COFF_ComdatSelectType_NODUPLICATES = 1, // Select any symbol, even if there are multiple definitions. (we default to first declaration)
COFF_ComdatSelectType_NODUPLICATES = 1, COFF_ComdatSelectType_ANY = 2, // Sections that symbols reference must match in size, otherwise multiply definition error is thrown.
// Select any symbol, even if there are multiple definitions. (we default to first declaration) COFF_ComdatSelectType_SAME_SIZE = 3, // Sections that symbols reference must have identical checksums, otherwise multiply defintion error is thrown.
COFF_ComdatSelectType_ANY = 2, COFF_ComdatSelectType_EXACT_MATCH = 4, // Symbols with associative type form a chain of sections are related to each other. (next link is indicated in COFF_SecDef in 'number')
// Sections that symbols reference must match in size, otherwise multiply definition error is thrown. COFF_ComdatSelectType_ASSOCIATIVE = 5, // Linker selects section with largest size.
COFF_ComdatSelectType_SAME_SIZE = 3, COFF_ComdatSelectType_LARGEST = 6,
// Sections that symbols reference must have identical checksums, otherwise multiply defintion error is thrown. COFF_ComdatSelectType_COUNT = 7
COFF_ComdatSelectType_EXACT_MATCH = 4,
// Symbols with associative type form a chain of sections are related to each other. (next link is indicated in COFF_SecDef in 'number')
COFF_ComdatSelectType_ASSOCIATIVE = 5,
// Linker selects section with largest size.
COFF_ComdatSelectType_LARGEST = 6,
COFF_ComdatSelectType_COUNT = 7
}; };
#define COFF_MIN_BIG_OBJ_VERSION 2 #define COFF_MIN_BIG_OBJ_VERSION 2
global U8 coff_big_obj_magic[] =
{
0xC7,0xA1,0xBA,0xD1,0xEE,0xBA,0xA9,0x4B,
0xAF,0x20,0xFA,0xF6,0x6A,0xA4,0xDC,0xB8,
};
typedef struct COFF_HeaderBigObj COFF_HeaderBigObj; typedef struct COFF_HeaderBigObj COFF_HeaderBigObj;
struct COFF_HeaderBigObj struct COFF_HeaderBigObj
{ {
@@ -422,7 +397,7 @@ struct COFF_HeaderBigObj
U16 version; U16 version;
U16 machine; U16 machine;
U32 time_stamp; U32 time_stamp;
U8 magic[16]; U8 magic[16];
U32 unused[4]; U32 unused[4];
U32 section_count; U32 section_count;
U32 pointer_to_symbol_table; U32 pointer_to_symbol_table;
@@ -454,8 +429,8 @@ typedef struct COFF_Symbol16 COFF_Symbol16;
struct COFF_Symbol16 struct COFF_Symbol16
{ {
COFF_SymbolName name; COFF_SymbolName name;
U32 value; U32 value;
U16 section_number; U16 section_number;
union union
{ {
struct struct
@@ -473,8 +448,8 @@ typedef struct COFF_Symbol32 COFF_Symbol32;
struct COFF_Symbol32 struct COFF_Symbol32
{ {
COFF_SymbolName name; COFF_SymbolName name;
U32 value; U32 value;
U32 section_number; U32 section_number;
union union
{ {
struct struct
@@ -494,11 +469,11 @@ struct COFF_Symbol32
// storage class: FUNCTION // storage class: FUNCTION
typedef struct COFF_SymbolFunc typedef struct COFF_SymbolFunc
{ {
U8 unused[4]; U8 unused[4];
U16 ln; U16 ln;
U8 unused2[2]; U8 unused2[2];
U32 ptr_to_next_func; U32 ptr_to_next_func;
U8 unused3[2]; U8 unused3[2];
} COFF_SymbolFunc; } COFF_SymbolFunc;
// storage class: WEAK_EXTERNAL // storage class: WEAK_EXTERNAL
@@ -506,7 +481,7 @@ typedef struct COFF_SymbolWeakExt
{ {
U32 tag_index; U32 tag_index;
U32 characteristics; U32 characteristics;
U8 unused[10]; U8 unused[10];
} COFF_SymbolWeakExt; } COFF_SymbolWeakExt;
typedef struct COFF_SymbolFile typedef struct COFF_SymbolFile
@@ -522,9 +497,10 @@ typedef struct COFF_SymbolSecDef
U16 number_of_relocations; U16 number_of_relocations;
U16 number_of_ln; U16 number_of_ln;
U32 check_sum; U32 check_sum;
U16 number; // one-based section index U16 number_lo; // one-based section index
U8 selection; U8 selection;
U8 unused[3]; U8 unused;
U16 number_hi;
} COFF_SymbolSecDef; } COFF_SymbolSecDef;
// specifies how section data should be modified when placed in the image file. // specifies how section data should be modified when placed in the image file.
@@ -584,7 +560,7 @@ typedef struct COFF_ResourceID_16
COFF_ResourceIDType type; COFF_ResourceIDType type;
union union
{ {
U16 number; U16 number;
String16 string; String16 string;
} u; } u;
} COFF_ResourceID_16; } COFF_ResourceID_16;
@@ -594,20 +570,21 @@ typedef struct COFF_ResourceID
COFF_ResourceIDType type; COFF_ResourceIDType type;
union union
{ {
U16 number; U16 number;
String8 string; String8 string;
} u; } u;
} COFF_ResourceID; } COFF_ResourceID;
typedef struct COFF_Resource typedef struct COFF_Resource
{ {
COFF_ResourceID type; COFF_ResourceID type;
COFF_ResourceID name; COFF_ResourceID name;
U16 language_id; U32 data_version;
U32 data_version;
U32 version;
COFF_ResourceMemoryFlags memory_flags; COFF_ResourceMemoryFlags memory_flags;
String8 data; U16 language_id;
U32 version;
U32 characteristics;
String8 data;
} COFF_Resource; } COFF_Resource;
typedef struct COFF_ResourceDataEntry typedef struct COFF_ResourceDataEntry
@@ -620,12 +597,12 @@ typedef struct COFF_ResourceDataEntry
typedef struct COFF_ResourceDirTable typedef struct COFF_ResourceDirTable
{ {
U32 characteristics; U32 characteristics;
COFF_TimeStamp time_stamp; COFF_TimeStamp time_stamp;
U16 major_version; U16 major_version;
U16 minor_version; U16 minor_version;
U16 name_entry_count; U16 name_entry_count;
U16 id_entry_count; U16 id_entry_count;
} COFF_ResourceDirTable; } COFF_ResourceDirTable;
#define COFF_RESOURCE_SUB_DIR_FLAG (1u << 31u) #define COFF_RESOURCE_SUB_DIR_FLAG (1u << 31u)
@@ -643,24 +620,19 @@ typedef struct COFF_ResourceDirEntry
//////////////////////////////// ////////////////////////////////
// !<arch>\n #define COFF_ARCHIVE_ALIGN 2
#define COFF_ARCHIVE_SIG 0x0A3E686372613C21ULL
// !<thin>\n
#define COFF_THIN_ARCHIVE_SIG 0xA3E6E6968743C21ULL
#define COFF_ARCHIVE_MAX_SHORT_NAME_SIZE 15 #define COFF_ARCHIVE_MAX_SHORT_NAME_SIZE 15
#define COFF_ARCHIVE_MEMBER_HEADER_SIZE 60
#define COFF_ARCHIVE_ALIGN 2
typedef struct COFF_ArchiveMemberHeader typedef struct COFF_ArchiveMemberHeader
{ {
String8 name; // padded to 16 bytes with spaces String8 name; // padded to 16 bytes with spaces
U32 date; // unix time U32 date; // unix time
U32 user_id; // unix artifact that does not have meaning on windows U32 user_id; // unix artifact that does not have meaning on windows
U32 group_id; // unix artifact that does not have meaning on windows U32 group_id; // unix artifact that does not have meaning on windows
String8 mode; // octal representation the members file mode String8 mode; // octal representation the members file mode
U32 size; // size of the member data, not including header U32 size; // size of the member data, not including header
B32 is_end_correct; // set to true if found correct signature after header B32 is_end_correct; // set to true if found correct signature after header
} COFF_ArchiveMemberHeader; } COFF_ArchiveMemberHeader;
//////////////////////////////// ////////////////////////////////
@@ -678,71 +650,61 @@ typedef U32 COFF_DataType;
typedef struct COFF_HeaderInfo typedef struct COFF_HeaderInfo
{ {
COFF_MachineType machine; COFF_MachineType machine;
U64 section_array_off; COFF_DataType type;
U64 section_count_no_null; U64 section_array_off;
U64 string_table_off; U64 section_count_no_null;
U64 symbol_size; U64 string_table_off;
U64 symbol_off; U64 symbol_size;
U64 symbol_count; U64 symbol_off;
U64 symbol_count;
} COFF_HeaderInfo; } COFF_HeaderInfo;
enum enum
{ {
// symbol has section and offset. COFF_SymbolValueInterp_REGULAR, // symbol has section and offset.
COFF_SymbolValueInterp_REGULAR, COFF_SymbolValueInterp_WEAK, // symbol is overridable
COFF_SymbolValueInterp_UNDEFINED, // symbol doesn't have a reference section.
// symbol is overridable COFF_SymbolValueInterp_COMMON, // symbol has no section but still has size.
COFF_SymbolValueInterp_WEAK, COFF_SymbolValueInterp_ABS, // symbol has an absolute (non-relocatable) value and is not an address.
COFF_SymbolValueInterp_DEBUG // symbol is used to provide general type of debugging information.
// symbol doesn't have a reference section.
COFF_SymbolValueInterp_UNDEFINED,
// symbol has no section but still has size.
COFF_SymbolValueInterp_COMMON,
// symbol has an absolute (non-relocatable) value and is not an address.
COFF_SymbolValueInterp_ABS,
// symbol is used to provide general type of debugging information.
COFF_SymbolValueInterp_DEBUG
}; };
typedef U32 COFF_SymbolValueInterpType; typedef U32 COFF_SymbolValueInterpType;
typedef struct COFF_Symbol16Node typedef struct COFF_Symbol16Node
{ {
struct COFF_Symbol16Node *next; struct COFF_Symbol16Node *next;
COFF_Symbol16 data; COFF_Symbol16 data;
} COFF_Symbol16Node; } COFF_Symbol16Node;
typedef struct COFF_Symbol16List typedef struct COFF_Symbol16List
{ {
U64 count; U64 count;
COFF_Symbol16Node *first; COFF_Symbol16Node *first;
COFF_Symbol16Node *last; COFF_Symbol16Node *last;
} COFF_Symbol16List; } COFF_Symbol16List;
typedef struct COFF_Symbol32Array typedef struct COFF_Symbol32Array
{ {
U64 count; U64 count;
COFF_Symbol32 *v; COFF_Symbol32 *v;
} COFF_Symbol32Array; } COFF_Symbol32Array;
typedef struct COFF_RelocNode typedef struct COFF_RelocNode
{ {
struct COFF_RelocNode *next; struct COFF_RelocNode *next;
COFF_Reloc data; COFF_Reloc data;
} COFF_RelocNode; } COFF_RelocNode;
typedef struct COFF_RelocList typedef struct COFF_RelocList
{ {
U64 count; U64 count;
COFF_RelocNode *first; COFF_RelocNode *first;
COFF_RelocNode *last; COFF_RelocNode *last;
} COFF_RelocList; } COFF_RelocList;
typedef struct COFF_RelocArray typedef struct COFF_RelocArray
{ {
U64 count; U64 count;
COFF_Reloc *v; COFF_Reloc *v;
} COFF_RelocArray; } COFF_RelocArray;
@@ -755,12 +717,12 @@ typedef struct COFF_RelocInfo
typedef struct COFF_ResourceNode typedef struct COFF_ResourceNode
{ {
struct COFF_ResourceNode *next; struct COFF_ResourceNode *next;
COFF_Resource data; COFF_Resource data;
} COFF_ResourceNode; } COFF_ResourceNode;
typedef struct COFF_ResourceList typedef struct COFF_ResourceList
{ {
U64 count; U64 count;
COFF_ResourceNode *first; COFF_ResourceNode *first;
COFF_ResourceNode *last; COFF_ResourceNode *last;
} COFF_ResourceList; } COFF_ResourceList;
@@ -770,21 +732,21 @@ typedef struct COFF_ResourceList
typedef struct COFF_ArchiveMember typedef struct COFF_ArchiveMember
{ {
COFF_ArchiveMemberHeader header; COFF_ArchiveMemberHeader header;
U64 offset; U64 offset;
String8 data; String8 data;
} COFF_ArchiveMember; } COFF_ArchiveMember;
typedef struct COFF_ArchiveFirstMember typedef struct COFF_ArchiveFirstMember
{ {
U32 symbol_count; U32 symbol_count;
String8 member_offsets; String8 member_offsets;
String8 string_table; String8 string_table;
} COFF_ArchiveFirstMember; } COFF_ArchiveFirstMember;
typedef struct COFF_ArchiveSecondMember typedef struct COFF_ArchiveSecondMember
{ {
U32 member_count; U32 member_count;
U32 symbol_count; U32 symbol_count;
String8 member_offsets; String8 member_offsets;
String8 symbol_indices; String8 symbol_indices;
String8 string_table; String8 string_table;
@@ -793,12 +755,12 @@ typedef struct COFF_ArchiveSecondMember
typedef struct COFF_ArchiveMemberNode typedef struct COFF_ArchiveMemberNode
{ {
struct COFF_ArchiveMemberNode *next; struct COFF_ArchiveMemberNode *next;
COFF_ArchiveMember data; COFF_ArchiveMember data;
} COFF_ArchiveMemberNode; } COFF_ArchiveMemberNode;
typedef struct COFF_ArchiveMemberList typedef struct COFF_ArchiveMemberList
{ {
U64 count; U64 count;
COFF_ArchiveMemberNode *first; COFF_ArchiveMemberNode *first;
COFF_ArchiveMemberNode *last; COFF_ArchiveMemberNode *last;
} COFF_ArchiveMemberList; } COFF_ArchiveMemberList;
@@ -812,14 +774,37 @@ typedef enum
typedef struct COFF_ArchiveParse typedef struct COFF_ArchiveParse
{ {
COFF_ArchiveFirstMember first_member; COFF_ArchiveFirstMember first_member;
COFF_ArchiveSecondMember second_member; COFF_ArchiveSecondMember second_member;
String8 long_names; String8 long_names;
} COFF_ArchiveParse; } COFF_ArchiveParse;
////////////////////////////////
typedef struct COFF_SectionHeaderArray
{
U64 count;
COFF_SectionHeader *v;
} COFF_SectionHeaderArray;
//////////////////////////////// ////////////////////////////////
//~ rjf: Globals //~ rjf: Globals
read_only global U8 coff_big_obj_magic[] =
{
0xC7,0xA1,0xBA,0xD1,0xEE,0xBA,0xA9,0x4B,
0xAF,0x20,0xFA,0xF6,0x6A,0xA4,0xDC,0xB8,
};
read_only global U8 g_coff_archive_sig[8] = "!<arch>\n";
read_only global U8 g_coff_thin_archive_sig[8] = "!<thin>\n";
read_only global U8 g_coff_res_magic[] =
{
0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
read_only global COFF_SectionHeader coff_section_header_nil = {0}; read_only global COFF_SectionHeader coff_section_header_nil = {0};
//////////////////////////////// ////////////////////////////////
@@ -829,6 +814,7 @@ internal B32 coff_is_big_obj(String8 data);
internal B32 coff_is_obj(String8 data); internal B32 coff_is_obj(String8 data);
internal COFF_HeaderInfo coff_header_info_from_data(String8 data); internal COFF_HeaderInfo coff_header_info_from_data(String8 data);
internal U64 coff_align_size_from_section_flags(COFF_SectionFlags flags); internal U64 coff_align_size_from_section_flags(COFF_SectionFlags flags);
internal COFF_SectionFlags coff_section_flag_from_align_size(U64 align);
internal COFF_SymbolValueInterpType coff_interp_symbol(COFF_Symbol32 *symbol); internal COFF_SymbolValueInterpType coff_interp_symbol(COFF_Symbol32 *symbol);
internal U64 coff_foff_from_voff(COFF_SectionHeader *sections, U64 section_count, U64 voff); internal U64 coff_foff_from_voff(COFF_SectionHeader *sections, U64 section_count, U64 voff);
@@ -844,18 +830,47 @@ internal COFF_Symbol32Array coff_symbol_array_from_data(Arena *arena, String8 d
internal COFF_Symbol16Node * coff_symbol16_list_push(Arena *arena, COFF_Symbol16List *list, COFF_Symbol16 symbol); internal COFF_Symbol16Node * coff_symbol16_list_push(Arena *arena, COFF_Symbol16List *list, COFF_Symbol16 symbol);
internal COFF_RelocInfo coff_reloc_info_from_section_header(String8 data, COFF_SectionHeader *header); internal COFF_RelocInfo coff_reloc_info_from_section_header(String8 data, COFF_SectionHeader *header);
internal U64 coff_word_size_from_machine(COFF_MachineType machine); internal U64 coff_word_size_from_machine(COFF_MachineType machine);
internal U64 coff_default_exe_base_from_machine(COFF_MachineType machine);
internal U64 coff_default_dll_base_from_machine(COFF_MachineType machine);
internal String8 coff_make_import_lookup(Arena *arena, U16 hint, String8 name); internal String8 coff_make_import_lookup(Arena *arena, U16 hint, String8 name);
internal U32 coff_make_ordinal_32(U16 hint); internal U32 coff_make_ordinal_32(U16 hint);
internal U64 coff_make_ordinal_64(U16 hint); internal U64 coff_make_ordinal_64(U16 hint);
internal B32 coff_resource_id_is_equal(COFF_ResourceID a, COFF_ResourceID b); internal String8 coff_make_import_header_by_name(Arena *arena,
internal COFF_ResourceID coff_resource_id_copy(Arena *arena, COFF_ResourceID id); String8 dll_name,
internal COFF_ResourceID coff_convert_resource_id(Arena *arena, COFF_ResourceID_16 *id_16); COFF_MachineType machine,
internal U64 coff_read_resource_id(String8 res, U64 off, COFF_ResourceID_16 *id_out); COFF_TimeStamp time_stamp,
String8 name,
U16 hint,
COFF_ImportHeaderType type);
internal String8 coff_make_import_header_by_ordinal(Arena *arena,
String8 dll_name,
COFF_MachineType machine,
COFF_TimeStamp time_stamp,
U16 ordinal,
COFF_ImportHeaderType type);
////////////////////////////////
//~ Resources
internal String8 coff_resource_string_from_str16(Arena *arena, String16 string);
internal String8 coff_resource_string_from_str8(Arena *arena, String8 string);
internal String8 coff_resource_number_from_u16(Arena *arena, U16 number);
internal B32 coff_resource_id_is_equal(COFF_ResourceID a, COFF_ResourceID b);
internal COFF_ResourceID coff_utf8_resource_id_from_utf16(Arena *arena, COFF_ResourceID_16 *id_16);
internal U64 coff_read_resource_id_utf16(String8 res, U64 off, COFF_ResourceID_16 *id_out);
internal U64 coff_read_resource(String8 data, U64 off, Arena *arena, COFF_Resource *res_out); internal U64 coff_read_resource(String8 data, U64 off, Arena *arena, COFF_Resource *res_out);
internal COFF_ResourceList coff_resource_list_from_data(Arena *arena, String8 data); internal COFF_ResourceList coff_resource_list_from_data(Arena *arena, String8 data);
internal String8 coff_write_resource_id(Arena *arena, COFF_ResourceID id);
internal String8 coff_write_resource(Arena *arena, COFF_ResourceID type, COFF_ResourceID name, U32 data_version, COFF_ResourceMemoryFlags memory_flags, U16 language_id, U32 version, U32 characteristics, String8 data);
////////////////////////////////
internal COFF_DataType coff_data_type_from_data(String8 data); internal COFF_DataType coff_data_type_from_data(String8 data);
internal B32 coff_is_import(String8 data); internal B32 coff_is_import(String8 data);
internal B32 coff_is_archive(String8 data); internal B32 coff_is_archive(String8 data);
@@ -875,8 +890,15 @@ internal COFF_ArchiveParse coff_thin_archive_from_data(Arena *arena, String8 da
internal COFF_ArchiveType coff_archive_type_from_data(String8 data); internal COFF_ArchiveType coff_archive_type_from_data(String8 data);
internal COFF_ArchiveParse coff_archive_parse_from_data(Arena *arena, String8 data); internal COFF_ArchiveParse coff_archive_parse_from_data(Arena *arena, String8 data);
////////////////////////////////
// String <-> Enum
internal String8 coff_string_from_comdat_select_type(COFF_ComdatSelectType select); internal String8 coff_string_from_comdat_select_type(COFF_ComdatSelectType select);
internal String8 coff_string_from_machine_type(COFF_MachineType machine); internal String8 coff_string_from_machine_type(COFF_MachineType machine);
internal String8 coff_string_from_section_flags(Arena *arena, COFF_SectionFlags flags); internal String8 coff_string_from_section_flags(Arena *arena, COFF_SectionFlags flags);
internal String8 coff_string_from_import_header_type(COFF_ImportHeaderType type);
internal COFF_MachineType coff_machine_from_string(String8 string);
internal COFF_ImportHeaderType coff_import_header_type_from_string(String8 name);
#endif //COFF_H #endif //COFF_H
+589 -284
View File
File diff suppressed because it is too large Load Diff
+54 -10
View File
@@ -15,6 +15,20 @@ typedef U64 CTRL_MachineID;
//////////////////////////////// ////////////////////////////////
//~ rjf: Meta Evaluation Types //~ rjf: Meta Evaluation Types
//- rjf: auto-checkbox b32s
typedef struct CTRL_CheckB32 CTRL_CheckB32;
struct CTRL_CheckB32
{
B32 b32;
};
struct_members(CTRL_CheckB32)
{
member_lit_comp(CTRL_CheckB32, type(B32), b32),
};
struct_type(CTRL_CheckB32);
//- rjf: styled string types //- rjf: styled string types
ptr_type(CTRL_PlainString8__str_ptr_type, type(U8), .flags = TypeFlag_IsPlainText,.count_delimiter_name = str8_lit_comp("size")); ptr_type(CTRL_PlainString8__str_ptr_type, type(U8), .flags = TypeFlag_IsPlainText,.count_delimiter_name = str8_lit_comp("size"));
@@ -74,18 +88,22 @@ typedef struct CTRL_MetaEval CTRL_MetaEval;
struct CTRL_MetaEval struct CTRL_MetaEval
{ {
#define CTRL_MetaEval_MemberXList \ #define CTRL_MetaEval_MemberXList \
X(B32, enabled, "Enabled")\ X(B32, enabled, "Enabled")\
X(B32, frozen, "Frozen")\ X(B32, frozen, "Frozen")\
X(U64, hit_count, "Hit Count")\ X(U64, hit_count, "Hit Count")\
X(U64, id, "ID")\ X(U64, id, "ID")\
X(Rng1U64, vaddr_range, "Address Range")\ X(Rng1U64, vaddr_range, "Address Range")\
X(U32, color, "Color")\ X(U32, color, "Color")\
X(CTRL_CheckB32, debug_subprocesses,"Debug Subprocesses")\
Y(String8, type(CTRL_CodeString8), label, "Label")\ Y(String8, type(CTRL_CodeString8), label, "Label")\
Y(String8, type(CTRL_PathString8), exe, "Executable Path")\ Y(String8, type(CTRL_PathString8), exe, "Executable Path")\
Y(String8, type(CTRL_PathString8), dbg, "Debug Info Path")\ Y(String8, type(CTRL_PathString8), dbg, "Debug Info Path")\
Y(String8, type(CTRL_PlainString8), args, "Arguments")\ Y(String8, type(CTRL_PlainString8), args, "Arguments")\
Y(String8, type(CTRL_PathString8), working_directory, "Working Directory")\ Y(String8, type(CTRL_PathString8), working_directory, "Working Directory")\
Y(String8, type(CTRL_CodeString8), entry_point, "Custom Entry Point")\ Y(String8, type(CTRL_CodeString8), entry_point, "Custom Entry Point")\
Y(String8, type(CTRL_PathString8), stdout_path, "Standard Output Path")\
Y(String8, type(CTRL_PathString8), stderr_path, "Standard Error Path")\
Y(String8, type(CTRL_PathString8), stdin_path, "Standard Input Path")\
Y(String8, type(CTRL_PathString8), source_location, "Source Location")\ Y(String8, type(CTRL_PathString8), source_location, "Source Location")\
Y(String8, type(CTRL_CodeString8), function_location, "Function Location")\ Y(String8, type(CTRL_CodeString8), function_location, "Function Location")\
Y(String8, type(CTRL_CodeString8), address_location, "Address Location")\ Y(String8, type(CTRL_CodeString8), address_location, "Address Location")\
@@ -132,6 +150,10 @@ struct_members(CTRL_TargetMetaEval)
member_lit_comp(CTRL_MetaEval, type(CTRL_PlainString8),args, .pretty_name = str8_lit_comp("Arguments")), member_lit_comp(CTRL_MetaEval, type(CTRL_PlainString8),args, .pretty_name = str8_lit_comp("Arguments")),
member_lit_comp(CTRL_MetaEval, type(CTRL_PathString8), working_directory, .pretty_name = str8_lit_comp("Working Directory")), member_lit_comp(CTRL_MetaEval, type(CTRL_PathString8), working_directory, .pretty_name = str8_lit_comp("Working Directory")),
member_lit_comp(CTRL_MetaEval, type(CTRL_CodeString8), entry_point, .pretty_name = str8_lit_comp("Custom Entry Point")), member_lit_comp(CTRL_MetaEval, type(CTRL_CodeString8), entry_point, .pretty_name = str8_lit_comp("Custom Entry Point")),
member_lit_comp(CTRL_MetaEval, type(CTRL_PathString8), stdout_path, .pretty_name = str8_lit_comp("Standard Output Path")),
member_lit_comp(CTRL_MetaEval, type(CTRL_PathString8), stderr_path, .pretty_name = str8_lit_comp("Standard Error Path")),
member_lit_comp(CTRL_MetaEval, type(CTRL_PathString8), stdin_path, .pretty_name = str8_lit_comp("Standard Input Path")),
member_lit_comp(CTRL_MetaEval, type(CTRL_CheckB32), debug_subprocesses, .pretty_name = str8_lit_comp("Debug Subprocesses")),
}; };
struct_members(CTRL_PinMetaEval) struct_members(CTRL_PinMetaEval)
@@ -511,6 +533,7 @@ typedef enum CTRL_MsgKind
CTRL_MsgKind_Launch, CTRL_MsgKind_Launch,
CTRL_MsgKind_Attach, CTRL_MsgKind_Attach,
CTRL_MsgKind_Kill, CTRL_MsgKind_Kill,
CTRL_MsgKind_KillAll,
CTRL_MsgKind_Detach, CTRL_MsgKind_Detach,
CTRL_MsgKind_Run, CTRL_MsgKind_Run,
CTRL_MsgKind_SingleStep, CTRL_MsgKind_SingleStep,
@@ -539,11 +562,15 @@ struct CTRL_Msg
U32 entity_id; U32 entity_id;
U32 exit_code; U32 exit_code;
B32 env_inherit; B32 env_inherit;
B32 debug_subprocesses;
U64 exception_code_filters[(CTRL_ExceptionCodeKind_COUNT+63)/64]; U64 exception_code_filters[(CTRL_ExceptionCodeKind_COUNT+63)/64];
String8 path; String8 path;
String8List entry_points; String8List entry_points;
String8List cmd_line_string_list; String8List cmd_line_string_list;
String8List env_string_list; String8List env_string_list;
String8 stdout_path;
String8 stderr_path;
String8 stdin_path;
CTRL_TrapList traps; CTRL_TrapList traps;
CTRL_UserBreakpointList user_bps; CTRL_UserBreakpointList user_bps;
CTRL_MetaEvalArray meta_evals; CTRL_MetaEvalArray meta_evals;
@@ -813,6 +840,23 @@ struct CTRL_ModuleImageInfoCache
CTRL_ModuleImageInfoCacheStripe *stripes; CTRL_ModuleImageInfoCacheStripe *stripes;
}; };
////////////////////////////////
//~ rjf: Touched Debug Info Directory Cache
typedef struct CTRL_DbgDirNode CTRL_DbgDirNode;
struct CTRL_DbgDirNode
{
CTRL_DbgDirNode *first;
CTRL_DbgDirNode *last;
CTRL_DbgDirNode *next;
CTRL_DbgDirNode *prev;
CTRL_DbgDirNode *parent;
String8 name;
U64 search_count;
U64 child_count;
U64 module_direct_count;
};
//////////////////////////////// ////////////////////////////////
//~ rjf: Wakeup Hook Function Types //~ rjf: Wakeup Hook Function Types
@@ -869,6 +913,8 @@ struct CTRL_State
CTRL_MetaEvalArray user_meta_evals; CTRL_MetaEvalArray user_meta_evals;
U64 exception_code_filters[(CTRL_ExceptionCodeKind_COUNT+63)/64]; U64 exception_code_filters[(CTRL_ExceptionCodeKind_COUNT+63)/64];
U64 process_counter; U64 process_counter;
Arena *dbg_dir_arena;
CTRL_DbgDirNode *dbg_dir_root;
// rjf: user -> memstream ring buffer // rjf: user -> memstream ring buffer
U64 u2ms_ring_size; U64 u2ms_ring_size;
@@ -877,10 +923,6 @@ struct CTRL_State
U64 u2ms_ring_read_pos; U64 u2ms_ring_read_pos;
OS_Handle u2ms_ring_mutex; OS_Handle u2ms_ring_mutex;
OS_Handle u2ms_ring_cv; OS_Handle u2ms_ring_cv;
// rjf: memory stream threads
U64 ms_thread_count;
OS_Handle *ms_threads;
}; };
//////////////////////////////// ////////////////////////////////
@@ -1132,6 +1174,7 @@ internal void ctrl_thread__end_and_flush_info_log(void);
internal void ctrl_thread__launch(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg); internal void ctrl_thread__launch(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg);
internal void ctrl_thread__attach(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg); internal void ctrl_thread__attach(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg);
internal void ctrl_thread__kill(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg); internal void ctrl_thread__kill(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg);
internal void ctrl_thread__kill_all(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg);
internal void ctrl_thread__detach(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg); internal void ctrl_thread__detach(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg);
internal void ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg); internal void ctrl_thread__run(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg);
internal void ctrl_thread__single_step(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg); internal void ctrl_thread__single_step(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg);
@@ -1144,6 +1187,7 @@ internal B32 ctrl_u2ms_enqueue_req(CTRL_Handle process, Rng1U64 vaddr_range, B32
internal void ctrl_u2ms_dequeue_req(CTRL_Handle *out_process, Rng1U64 *out_vaddr_range, B32 *out_zero_terminated); internal void ctrl_u2ms_dequeue_req(CTRL_Handle *out_process, Rng1U64 *out_vaddr_range, B32 *out_zero_terminated);
//- rjf: entry point //- rjf: entry point
ASYNC_WORK_DEF(ctrl_mem_stream_work);
internal void ctrl_mem_stream_thread__entry_point(void *p); internal void ctrl_mem_stream_thread__entry_point(void *p);
#endif // CTRL_CORE_H #endif // CTRL_CORE_H
+281 -300
View File
@@ -41,7 +41,14 @@ dasm_inst_from_code(Arena *arena, Arch arch, U64 vaddr, String8 code, DASM_Synta
ZydisDecodedOperand *first_visible_op = (zinst.info.operand_count_visible > 0 ? &zinst.operands[0] : 0); ZydisDecodedOperand *first_visible_op = (zinst.info.operand_count_visible > 0 ? &zinst.operands[0] : 0);
ZydisDecodedOperand *first_op = (zinst.info.operand_count > 0 ? &zinst.operands[0] : 0); ZydisDecodedOperand *first_op = (zinst.info.operand_count > 0 ? &zinst.operands[0] : 0);
ZydisDecodedOperand *second_op = (zinst.info.operand_count > 1 ? &zinst.operands[1] : 0); ZydisDecodedOperand *second_op = (zinst.info.operand_count > 1 ? &zinst.operands[1] : 0);
if(first_visible_op != 0) if(first_visible_op != 0 &&
(first_visible_op->encoding == ZYDIS_OPERAND_ENCODING_JIMM8 ||
first_visible_op->encoding == ZYDIS_OPERAND_ENCODING_JIMM16 ||
first_visible_op->encoding == ZYDIS_OPERAND_ENCODING_JIMM32 ||
first_visible_op->encoding == ZYDIS_OPERAND_ENCODING_JIMM64 ||
first_visible_op->encoding == ZYDIS_OPERAND_ENCODING_JIMM16_32_64 ||
first_visible_op->encoding == ZYDIS_OPERAND_ENCODING_JIMM32_32_64 ||
first_visible_op->encoding == ZYDIS_OPERAND_ENCODING_JIMM16_32_32))
{ {
ZydisCalcAbsoluteAddress(&zinst.info, first_visible_op, vaddr, &jump_dest_vaddr); ZydisCalcAbsoluteAddress(&zinst.info, first_visible_op, vaddr, &jump_dest_vaddr);
} }
@@ -267,31 +274,9 @@ dasm_init(void)
dasm_shared->u2p_ring_base = push_array_no_zero(arena, U8, dasm_shared->u2p_ring_size); dasm_shared->u2p_ring_base = push_array_no_zero(arena, U8, dasm_shared->u2p_ring_size);
dasm_shared->u2p_ring_cv = os_condition_variable_alloc(); dasm_shared->u2p_ring_cv = os_condition_variable_alloc();
dasm_shared->u2p_ring_mutex = os_mutex_alloc(); dasm_shared->u2p_ring_mutex = os_mutex_alloc();
dasm_shared->parse_thread_count = 1;
dasm_shared->parse_threads = push_array(arena, OS_Handle, dasm_shared->parse_thread_count);
for(U64 idx = 0; idx < dasm_shared->parse_thread_count; idx += 1)
{
dasm_shared->parse_threads[idx] = os_thread_launch(dasm_parse_thread__entry_point, (void *)idx, 0);
}
dasm_shared->evictor_detector_thread = os_thread_launch(dasm_evictor_detector_thread__entry_point, 0, 0); dasm_shared->evictor_detector_thread = os_thread_launch(dasm_evictor_detector_thread__entry_point, 0, 0);
} }
////////////////////////////////
//~ rjf: User Clock
internal void
dasm_user_clock_tick(void)
{
ins_atomic_u64_inc_eval(&dasm_shared->user_clock_idx);
}
internal U64
dasm_user_clock_idx(void)
{
U64 idx = ins_atomic_u64_eval(&dasm_shared->user_clock_idx);
return idx;
}
//////////////////////////////// ////////////////////////////////
//~ rjf: Scoped Access //~ rjf: Scoped Access
@@ -341,7 +326,7 @@ dasm_scope_touch_node__stripe_r_guarded(DASM_Scope *scope, DASM_Node *node)
DASM_Touch *touch = push_array(dasm_tctx->arena, DASM_Touch, 1); DASM_Touch *touch = push_array(dasm_tctx->arena, DASM_Touch, 1);
ins_atomic_u64_inc_eval(&node->scope_ref_count); ins_atomic_u64_inc_eval(&node->scope_ref_count);
ins_atomic_u64_eval_assign(&node->last_time_touched_us, os_now_microseconds()); ins_atomic_u64_eval_assign(&node->last_time_touched_us, os_now_microseconds());
ins_atomic_u64_eval_assign(&node->last_user_clock_idx_touched, dasm_user_clock_idx()); ins_atomic_u64_eval_assign(&node->last_user_clock_idx_touched, update_tick_idx());
touch->hash = node->hash; touch->hash = node->hash;
MemoryCopyStruct(&touch->params, &node->params); MemoryCopyStruct(&touch->params, &node->params);
touch->params.dbgi_key = di_key_copy(dasm_tctx->arena, &touch->params.dbgi_key); touch->params.dbgi_key = di_key_copy(dasm_tctx->arena, &touch->params.dbgi_key);
@@ -423,6 +408,7 @@ dasm_info_from_hash_params(DASM_Scope *scope, U128 hash, DASM_Params *params)
if(node_is_new) if(node_is_new)
{ {
dasm_u2p_enqueue_req(hash, params, max_U64); dasm_u2p_enqueue_req(hash, params, max_U64);
async_push_work(dasm_parse_work);
} }
} }
return info; return info;
@@ -471,8 +457,6 @@ dasm_u2p_enqueue_req(U128 hash, DASM_Params *params, U64 endt_us)
dasm_shared->u2p_ring_write_pos += ring_write_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, &params->dbgi_key.path.size); dasm_shared->u2p_ring_write_pos += ring_write_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, &params->dbgi_key.path.size);
dasm_shared->u2p_ring_write_pos += ring_write(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, params->dbgi_key.path.str, params->dbgi_key.path.size); dasm_shared->u2p_ring_write_pos += ring_write(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, params->dbgi_key.path.str, params->dbgi_key.path.size);
dasm_shared->u2p_ring_write_pos += ring_write_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, &params->dbgi_key.min_timestamp); dasm_shared->u2p_ring_write_pos += ring_write_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, &params->dbgi_key.min_timestamp);
dasm_shared->u2p_ring_write_pos += 7;
dasm_shared->u2p_ring_write_pos -= dasm_shared->u2p_ring_write_pos%8;
break; break;
} }
if(os_now_microseconds() >= endt_us) if(os_now_microseconds() >= endt_us)
@@ -506,8 +490,6 @@ dasm_u2p_dequeue_req(Arena *arena, U128 *hash_out, DASM_Params *params_out)
params_out->dbgi_key.path.str = push_array(arena, U8, params_out->dbgi_key.path.size); params_out->dbgi_key.path.str = push_array(arena, U8, params_out->dbgi_key.path.size);
dasm_shared->u2p_ring_read_pos += ring_read(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_read_pos, params_out->dbgi_key.path.str, params_out->dbgi_key.path.size); dasm_shared->u2p_ring_read_pos += ring_read(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_read_pos, params_out->dbgi_key.path.str, params_out->dbgi_key.path.size);
dasm_shared->u2p_ring_read_pos += ring_read_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_read_pos, &params_out->dbgi_key.min_timestamp); dasm_shared->u2p_ring_read_pos += ring_read_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_read_pos, &params_out->dbgi_key.min_timestamp);
dasm_shared->u2p_ring_read_pos += 7;
dasm_shared->u2p_ring_read_pos -= dasm_shared->u2p_ring_read_pos%8;
break; break;
} }
os_condition_variable_wait(dasm_shared->u2p_ring_cv, dasm_shared->u2p_ring_mutex, max_U64); os_condition_variable_wait(dasm_shared->u2p_ring_cv, dasm_shared->u2p_ring_mutex, max_U64);
@@ -515,284 +497,282 @@ dasm_u2p_dequeue_req(Arena *arena, U128 *hash_out, DASM_Params *params_out)
os_condition_variable_broadcast(dasm_shared->u2p_ring_cv); os_condition_variable_broadcast(dasm_shared->u2p_ring_cv);
} }
internal void ASYNC_WORK_DEF(dasm_parse_work)
dasm_parse_thread__entry_point(void *p)
{ {
ThreadNameF("[dasm] parse thread #%I64u", (U64)p); ProfBeginFunction();
for(;;) Temp scratch = scratch_begin(0, 0);
HS_Scope *hs_scope = hs_scope_open();
DI_Scope *di_scope = di_scope_open();
TXT_Scope *txt_scope = txt_scope_open();
//- rjf: get next request
U128 hash = {0};
DASM_Params params = {0};
dasm_u2p_dequeue_req(scratch.arena, &hash, &params);
U64 change_gen = fs_change_gen();
//- rjf: unpack hash
U64 slot_idx = hash.u64[1]%dasm_shared->slots_count;
U64 stripe_idx = slot_idx%dasm_shared->stripes_count;
DASM_Slot *slot = &dasm_shared->slots[slot_idx];
DASM_Stripe *stripe = &dasm_shared->stripes[stripe_idx];
//- rjf: take task
B32 got_task = 0;
OS_MutexScopeR(stripe->rw_mutex)
{ {
Temp scratch = scratch_begin(0, 0); for(DASM_Node *n = slot->first; n != 0; n = n->next)
HS_Scope *hs_scope = hs_scope_open();
DI_Scope *di_scope = di_scope_open();
TXT_Scope *txt_scope = txt_scope_open();
//- rjf: get next request
U128 hash = {0};
DASM_Params params = {0};
dasm_u2p_dequeue_req(scratch.arena, &hash, &params);
U64 change_gen = fs_change_gen();
//- rjf: unpack hash
U64 slot_idx = hash.u64[1]%dasm_shared->slots_count;
U64 stripe_idx = slot_idx%dasm_shared->stripes_count;
DASM_Slot *slot = &dasm_shared->slots[slot_idx];
DASM_Stripe *stripe = &dasm_shared->stripes[stripe_idx];
//- rjf: take task
B32 got_task = 0;
OS_MutexScopeR(stripe->rw_mutex)
{ {
for(DASM_Node *n = slot->first; n != 0; n = n->next) if(u128_match(n->hash, hash) && dasm_params_match(&n->params, &params))
{ {
if(u128_match(n->hash, hash) && dasm_params_match(&n->params, &params)) got_task = !ins_atomic_u32_eval_cond_assign(&n->is_working, 1, 0);
{ break;
got_task = !ins_atomic_u32_eval_cond_assign(&n->is_working, 1, 0);
break;
}
} }
} }
//- rjf: get dbg info
RDI_Parsed *rdi = &di_rdi_parsed_nil;
if(got_task && params.dbgi_key.path.size != 0)
{
rdi = di_rdi_from_key(di_scope, &params.dbgi_key, max_U64);
}
//- rjf: hash -> data
String8 data = {0};
if(got_task)
{
data = hs_data_from_hash(hs_scope, hash);
}
//- rjf: data * arch * addr * dbg -> decode artifacts
DASM_LineChunkList line_list = {0};
String8List inst_strings = {0};
if(got_task)
{
switch(params.arch)
{
default:{}break;
//- rjf: x86/x64 decoding
case Arch_x64:
case Arch_x86:
{
// rjf: disassemble
RDI_SourceFile *last_file = &rdi_nil_element_union.source_file;
RDI_Line *last_line = 0;
for(U64 off = 0; off < data.size;)
{
// rjf: disassemble one instruction
DASM_Inst inst = dasm_inst_from_code(scratch.arena, params.arch, params.vaddr+off, str8_skip(data, off), params.syntax);
if(inst.size == 0)
{
break;
}
// rjf: push strings derived from voff -> line info
if(params.style_flags & (DASM_StyleFlag_SourceFilesNames|DASM_StyleFlag_SourceLines))
{
if(rdi != &di_rdi_parsed_nil)
{
U64 voff = (params.vaddr+off) - params.base_vaddr;
U32 unit_idx = rdi_vmap_idx_from_section_kind_voff(rdi, RDI_SectionKind_UnitVMap, voff);
RDI_Unit *unit = rdi_element_from_name_idx(rdi, Units, unit_idx);
RDI_LineTable *line_table = rdi_element_from_name_idx(rdi, LineTables, unit->line_table_idx);
RDI_ParsedLineTable unit_line_info = {0};
rdi_parsed_from_line_table(rdi, line_table, &unit_line_info);
U64 line_info_idx = rdi_line_info_idx_from_voff(&unit_line_info, voff);
if(line_info_idx < unit_line_info.count)
{
RDI_Line *line = &unit_line_info.lines[line_info_idx];
RDI_SourceFile *file = rdi_element_from_name_idx(rdi, SourceFiles, line->file_idx);
String8 file_normalized_full_path = {0};
file_normalized_full_path.str = rdi_string_from_idx(rdi, file->normal_full_path_string_idx, &file_normalized_full_path.size);
if(file != last_file)
{
if(params.style_flags & DASM_StyleFlag_SourceFilesNames &&
file->normal_full_path_string_idx != 0 && file_normalized_full_path.size != 0)
{
String8 inst_string = push_str8f(scratch.arena, "> %S", file_normalized_full_path);
DASM_Line inst = {u32_from_u64_saturate(off), DASM_LineFlag_Decorative, 0, r1u64(inst_strings.total_size + inst_strings.node_count,
inst_strings.total_size + inst_strings.node_count + inst_string.size)};
dasm_line_chunk_list_push(scratch.arena, &line_list, 1024, &inst);
str8_list_push(scratch.arena, &inst_strings, inst_string);
}
if(params.style_flags & DASM_StyleFlag_SourceFilesNames && file->normal_full_path_string_idx == 0)
{
String8 inst_string = str8_lit(">");
DASM_Line inst = {u32_from_u64_saturate(off), DASM_LineFlag_Decorative, 0, r1u64(inst_strings.total_size + inst_strings.node_count,
inst_strings.total_size + inst_strings.node_count + inst_string.size)};
dasm_line_chunk_list_push(scratch.arena, &line_list, 1024, &inst);
str8_list_push(scratch.arena, &inst_strings, inst_string);
}
last_file = file;
}
if(line && line != last_line && file->normal_full_path_string_idx != 0 &&
params.style_flags & DASM_StyleFlag_SourceLines &&
file_normalized_full_path.size != 0)
{
FileProperties props = os_properties_from_file_path(file_normalized_full_path);
if(props.modified != 0)
{
// TODO(rjf): need redirection path - this may map to a different path on the local machine,
// need frontend to communicate path remapping info to this layer
U128 key = fs_key_from_path_range(file_normalized_full_path, r1u64(0, max_U64));
TXT_LangKind lang_kind = txt_lang_kind_from_extension(file_normalized_full_path);
U64 endt_us = max_U64;
U128 hash = {0};
TXT_TextInfo text_info = {0};
for(;os_now_microseconds() <= endt_us;)
{
text_info = txt_text_info_from_key_lang(txt_scope, key, lang_kind, &hash);
if(!u128_match(hash, u128_zero()))
{
break;
}
}
if(0 < line->line_num && line->line_num < text_info.lines_count)
{
String8 data = hs_data_from_hash(hs_scope, hash);
String8 line_text = str8_skip_chop_whitespace(str8_substr(data, text_info.lines_ranges[line->line_num-1]));
if(line_text.size != 0)
{
String8 inst_string = push_str8f(scratch.arena, "> %S", line_text);
DASM_Line inst = {u32_from_u64_saturate(off), DASM_LineFlag_Decorative, 0, r1u64(inst_strings.total_size + inst_strings.node_count,
inst_strings.total_size + inst_strings.node_count + inst_string.size)};
dasm_line_chunk_list_push(scratch.arena, &line_list, 1024, &inst);
str8_list_push(scratch.arena, &inst_strings, inst_string);
}
}
}
last_line = line;
}
}
}
}
// rjf: push line
String8 addr_part = {0};
if(params.style_flags & DASM_StyleFlag_Addresses)
{
addr_part = push_str8f(scratch.arena, "%s0x%016I64x ", rdi != &di_rdi_parsed_nil ? " " : "", params.vaddr+off);
}
String8 code_bytes_part = {0};
if(params.style_flags & DASM_StyleFlag_CodeBytes)
{
String8List code_bytes_strings = {0};
str8_list_push(scratch.arena, &code_bytes_strings, str8_lit("{"));
for(U64 byte_idx = 0; byte_idx < inst.size || byte_idx < 16; byte_idx += 1)
{
if(byte_idx < inst.size)
{
str8_list_pushf(scratch.arena, &code_bytes_strings, "%02x%s ", (U32)data.str[off+byte_idx], byte_idx == inst.size-1 ? "}" : "");
}
else if(byte_idx < 8)
{
str8_list_push(scratch.arena, &code_bytes_strings, str8_lit(" "));
}
}
str8_list_push(scratch.arena, &code_bytes_strings, str8_lit(" "));
code_bytes_part = str8_list_join(scratch.arena, &code_bytes_strings, 0);
}
String8 symbol_part = {0};
if(inst.jump_dest_vaddr != 0 && rdi != &di_rdi_parsed_nil && params.style_flags & DASM_StyleFlag_SymbolNames)
{
RDI_U32 scope_idx = rdi_vmap_idx_from_section_kind_voff(rdi, RDI_SectionKind_ScopeVMap, inst.jump_dest_vaddr-params.base_vaddr);
if(scope_idx != 0)
{
RDI_Scope *scope = rdi_element_from_name_idx(rdi, Scopes, scope_idx);
RDI_U32 procedure_idx = scope->proc_idx;
RDI_Procedure *procedure = rdi_element_from_name_idx(rdi, Procedures, procedure_idx);
String8 procedure_name = {0};
procedure_name.str = rdi_string_from_idx(rdi, procedure->name_string_idx, &procedure_name.size);
if(procedure_name.size != 0)
{
symbol_part = push_str8f(scratch.arena, " (%S)", procedure_name);
}
}
}
String8 inst_string = push_str8f(scratch.arena, "%S%S%S%S", addr_part, code_bytes_part, inst.string, symbol_part);
DASM_Line line = {u32_from_u64_saturate(off), 0, inst.jump_dest_vaddr, r1u64(inst_strings.total_size + inst_strings.node_count,
inst_strings.total_size + inst_strings.node_count + inst_string.size)};
dasm_line_chunk_list_push(scratch.arena, &line_list, 1024, &line);
str8_list_push(scratch.arena, &inst_strings, inst_string);
// rjf: increment
off += inst.size;
}
}break;
}
}
//- rjf: artifacts -> value bundle
Arena *info_arena = 0;
DASM_Info info = {0};
if(got_task)
{
//- rjf: produce joined text
Arena *text_arena = arena_alloc();
StringJoin text_join = {0};
text_join.sep = str8_lit("\n");
String8 text = str8_list_join(text_arena, &inst_strings, &text_join);
//- rjf: produce unique key for this disassembly's text
U128 text_key = {0};
{
U64 hash_data[] =
{
hash.u64[0],
hash.u64[1],
params.vaddr,
(U64)params.arch,
(U64)params.style_flags,
(U64)params.syntax,
(U64)rdi,
0x4d534144,
};
text_key = hs_hash_from_data(str8((U8 *)hash_data, sizeof(hash_data)));
}
//- rjf: submit text data to hash store
U128 text_hash = hs_submit_data(text_key, &text_arena, text);
//- rjf: produce value bundle
info_arena = arena_alloc();
info.text_key = text_key;
info.lines = dasm_line_array_from_chunk_list(info_arena, &line_list);
}
//- rjf: commit results to cache
if(got_task) OS_MutexScopeW(stripe->rw_mutex)
{
for(DASM_Node *n = slot->first; n != 0; n = n->next)
{
if(u128_match(n->hash, hash) && dasm_params_match(&n->params, &params))
{
n->info_arena = info_arena;
MemoryCopyStruct(&n->info, &info);
if(rdi != &di_rdi_parsed_nil && params.style_flags & (DASM_StyleFlag_SourceLines|DASM_StyleFlag_SourceFilesNames))
{
n->change_gen = change_gen;
}
else
{
n->change_gen = 0;
}
ins_atomic_u32_eval_assign(&n->is_working, 0);
ins_atomic_u64_inc_eval(&n->load_count);
break;
}
}
}
txt_scope_close(txt_scope);
di_scope_close(di_scope);
hs_scope_close(hs_scope);
scratch_end(scratch);
} }
//- rjf: get dbg info
RDI_Parsed *rdi = &di_rdi_parsed_nil;
if(got_task && params.dbgi_key.path.size != 0)
{
rdi = di_rdi_from_key(di_scope, &params.dbgi_key, max_U64);
}
//- rjf: hash -> data
String8 data = {0};
if(got_task)
{
data = hs_data_from_hash(hs_scope, hash);
}
//- rjf: data * arch * addr * dbg -> decode artifacts
DASM_LineChunkList line_list = {0};
String8List inst_strings = {0};
if(got_task)
{
switch(params.arch)
{
default:{}break;
//- rjf: x86/x64 decoding
case Arch_x64:
case Arch_x86:
{
// rjf: disassemble
RDI_SourceFile *last_file = &rdi_nil_element_union.source_file;
RDI_Line *last_line = 0;
for(U64 off = 0; off < data.size;)
{
// rjf: disassemble one instruction
DASM_Inst inst = dasm_inst_from_code(scratch.arena, params.arch, params.vaddr+off, str8_skip(data, off), params.syntax);
if(inst.size == 0)
{
break;
}
// rjf: push strings derived from voff -> line info
if(params.style_flags & (DASM_StyleFlag_SourceFilesNames|DASM_StyleFlag_SourceLines))
{
if(rdi != &di_rdi_parsed_nil)
{
U64 voff = (params.vaddr+off) - params.base_vaddr;
U32 unit_idx = rdi_vmap_idx_from_section_kind_voff(rdi, RDI_SectionKind_UnitVMap, voff);
RDI_Unit *unit = rdi_element_from_name_idx(rdi, Units, unit_idx);
RDI_LineTable *line_table = rdi_element_from_name_idx(rdi, LineTables, unit->line_table_idx);
RDI_ParsedLineTable unit_line_info = {0};
rdi_parsed_from_line_table(rdi, line_table, &unit_line_info);
U64 line_info_idx = rdi_line_info_idx_from_voff(&unit_line_info, voff);
if(line_info_idx < unit_line_info.count)
{
RDI_Line *line = &unit_line_info.lines[line_info_idx];
RDI_SourceFile *file = rdi_element_from_name_idx(rdi, SourceFiles, line->file_idx);
String8 file_normalized_full_path = {0};
file_normalized_full_path.str = rdi_string_from_idx(rdi, file->normal_full_path_string_idx, &file_normalized_full_path.size);
if(file != last_file)
{
if(params.style_flags & DASM_StyleFlag_SourceFilesNames &&
file->normal_full_path_string_idx != 0 && file_normalized_full_path.size != 0)
{
String8 inst_string = push_str8f(scratch.arena, "> %S", file_normalized_full_path);
DASM_Line inst = {u32_from_u64_saturate(off), DASM_LineFlag_Decorative, 0, r1u64(inst_strings.total_size + inst_strings.node_count,
inst_strings.total_size + inst_strings.node_count + inst_string.size)};
dasm_line_chunk_list_push(scratch.arena, &line_list, 1024, &inst);
str8_list_push(scratch.arena, &inst_strings, inst_string);
}
if(params.style_flags & DASM_StyleFlag_SourceFilesNames && file->normal_full_path_string_idx == 0)
{
String8 inst_string = str8_lit(">");
DASM_Line inst = {u32_from_u64_saturate(off), DASM_LineFlag_Decorative, 0, r1u64(inst_strings.total_size + inst_strings.node_count,
inst_strings.total_size + inst_strings.node_count + inst_string.size)};
dasm_line_chunk_list_push(scratch.arena, &line_list, 1024, &inst);
str8_list_push(scratch.arena, &inst_strings, inst_string);
}
last_file = file;
}
if(line && line != last_line && file->normal_full_path_string_idx != 0 &&
params.style_flags & DASM_StyleFlag_SourceLines &&
file_normalized_full_path.size != 0)
{
FileProperties props = os_properties_from_file_path(file_normalized_full_path);
if(props.modified != 0)
{
// TODO(rjf): need redirection path - this may map to a different path on the local machine,
// need frontend to communicate path remapping info to this layer
U128 key = fs_key_from_path_range(file_normalized_full_path, r1u64(0, max_U64));
TXT_LangKind lang_kind = txt_lang_kind_from_extension(file_normalized_full_path);
U64 endt_us = max_U64;
U128 hash = {0};
TXT_TextInfo text_info = {0};
for(;os_now_microseconds() <= endt_us;)
{
text_info = txt_text_info_from_key_lang(txt_scope, key, lang_kind, &hash);
if(!u128_match(hash, u128_zero()))
{
break;
}
}
if(0 < line->line_num && line->line_num < text_info.lines_count)
{
String8 data = hs_data_from_hash(hs_scope, hash);
String8 line_text = str8_skip_chop_whitespace(str8_substr(data, text_info.lines_ranges[line->line_num-1]));
if(line_text.size != 0)
{
String8 inst_string = push_str8f(scratch.arena, "> %S", line_text);
DASM_Line inst = {u32_from_u64_saturate(off), DASM_LineFlag_Decorative, 0, r1u64(inst_strings.total_size + inst_strings.node_count,
inst_strings.total_size + inst_strings.node_count + inst_string.size)};
dasm_line_chunk_list_push(scratch.arena, &line_list, 1024, &inst);
str8_list_push(scratch.arena, &inst_strings, inst_string);
}
}
}
last_line = line;
}
}
}
}
// rjf: push line
String8 addr_part = {0};
if(params.style_flags & DASM_StyleFlag_Addresses)
{
addr_part = push_str8f(scratch.arena, "%s0x%016I64x ", rdi != &di_rdi_parsed_nil ? " " : "", params.vaddr+off);
}
String8 code_bytes_part = {0};
if(params.style_flags & DASM_StyleFlag_CodeBytes)
{
String8List code_bytes_strings = {0};
str8_list_push(scratch.arena, &code_bytes_strings, str8_lit("{"));
for(U64 byte_idx = 0; byte_idx < inst.size || byte_idx < 16; byte_idx += 1)
{
if(byte_idx < inst.size)
{
str8_list_pushf(scratch.arena, &code_bytes_strings, "%02x%s ", (U32)data.str[off+byte_idx], byte_idx == inst.size-1 ? "}" : "");
}
else if(byte_idx < 8)
{
str8_list_push(scratch.arena, &code_bytes_strings, str8_lit(" "));
}
}
str8_list_push(scratch.arena, &code_bytes_strings, str8_lit(" "));
code_bytes_part = str8_list_join(scratch.arena, &code_bytes_strings, 0);
}
String8 symbol_part = {0};
if(inst.jump_dest_vaddr != 0 && rdi != &di_rdi_parsed_nil && params.style_flags & DASM_StyleFlag_SymbolNames)
{
RDI_U32 scope_idx = rdi_vmap_idx_from_section_kind_voff(rdi, RDI_SectionKind_ScopeVMap, inst.jump_dest_vaddr-params.base_vaddr);
if(scope_idx != 0)
{
RDI_Scope *scope = rdi_element_from_name_idx(rdi, Scopes, scope_idx);
RDI_U32 procedure_idx = scope->proc_idx;
RDI_Procedure *procedure = rdi_element_from_name_idx(rdi, Procedures, procedure_idx);
String8 procedure_name = {0};
procedure_name.str = rdi_string_from_idx(rdi, procedure->name_string_idx, &procedure_name.size);
if(procedure_name.size != 0)
{
symbol_part = push_str8f(scratch.arena, " (%S)", procedure_name);
}
}
}
String8 inst_string = push_str8f(scratch.arena, "%S%S%S%S", addr_part, code_bytes_part, inst.string, symbol_part);
DASM_Line line = {u32_from_u64_saturate(off), 0, inst.jump_dest_vaddr, r1u64(inst_strings.total_size + inst_strings.node_count,
inst_strings.total_size + inst_strings.node_count + inst_string.size)};
dasm_line_chunk_list_push(scratch.arena, &line_list, 1024, &line);
str8_list_push(scratch.arena, &inst_strings, inst_string);
// rjf: increment
off += inst.size;
}
}break;
}
}
//- rjf: artifacts -> value bundle
Arena *info_arena = 0;
DASM_Info info = {0};
if(got_task)
{
//- rjf: produce joined text
Arena *text_arena = arena_alloc();
StringJoin text_join = {0};
text_join.sep = str8_lit("\n");
String8 text = str8_list_join(text_arena, &inst_strings, &text_join);
//- rjf: produce unique key for this disassembly's text
U128 text_key = {0};
{
U64 hash_data[] =
{
hash.u64[0],
hash.u64[1],
params.vaddr,
(U64)params.arch,
(U64)params.style_flags,
(U64)params.syntax,
(U64)rdi,
0x4d534144,
};
text_key = hs_hash_from_data(str8((U8 *)hash_data, sizeof(hash_data)));
}
//- rjf: submit text data to hash store
U128 text_hash = hs_submit_data(text_key, &text_arena, text);
//- rjf: produce value bundle
info_arena = arena_alloc();
info.text_key = text_key;
info.lines = dasm_line_array_from_chunk_list(info_arena, &line_list);
}
//- rjf: commit results to cache
if(got_task) OS_MutexScopeW(stripe->rw_mutex)
{
for(DASM_Node *n = slot->first; n != 0; n = n->next)
{
if(u128_match(n->hash, hash) && dasm_params_match(&n->params, &params))
{
n->info_arena = info_arena;
MemoryCopyStruct(&n->info, &info);
if(rdi != &di_rdi_parsed_nil && params.style_flags & (DASM_StyleFlag_SourceLines|DASM_StyleFlag_SourceFilesNames))
{
n->change_gen = change_gen;
}
else
{
n->change_gen = 0;
}
ins_atomic_u32_eval_assign(&n->is_working, 0);
ins_atomic_u64_inc_eval(&n->load_count);
break;
}
}
}
txt_scope_close(txt_scope);
di_scope_close(di_scope);
hs_scope_close(hs_scope);
scratch_end(scratch);
ProfEnd();
return 0;
} }
//////////////////////////////// ////////////////////////////////
@@ -806,7 +786,7 @@ dasm_evictor_detector_thread__entry_point(void *p)
{ {
U64 change_gen = fs_change_gen(); U64 change_gen = fs_change_gen();
U64 check_time_us = os_now_microseconds(); U64 check_time_us = os_now_microseconds();
U64 check_time_user_clocks = dasm_user_clock_idx(); U64 check_time_user_clocks = update_tick_idx();
U64 evict_threshold_us = 10*1000000; U64 evict_threshold_us = 10*1000000;
U64 retry_threshold_us = 1*1000000; U64 retry_threshold_us = 1*1000000;
U64 evict_threshold_user_clocks = 10; U64 evict_threshold_user_clocks = 10;
@@ -863,6 +843,7 @@ dasm_evictor_detector_thread__entry_point(void *p)
{ {
if(dasm_u2p_enqueue_req(n->hash, &n->params, max_U64)) if(dasm_u2p_enqueue_req(n->hash, &n->params, max_U64))
{ {
async_push_work(dasm_parse_work);
n->last_time_requested_us = os_now_microseconds(); n->last_time_requested_us = os_now_microseconds();
n->last_user_clock_idx_requested = check_time_user_clocks; n->last_user_clock_idx_requested = check_time_user_clocks;
} }
+1 -14
View File
@@ -246,9 +246,6 @@ struct DASM_Shared
{ {
Arena *arena; Arena *arena;
// rjf: user clock
U64 user_clock_idx;
// rjf: cache // rjf: cache
U64 slots_count; U64 slots_count;
U64 stripes_count; U64 stripes_count;
@@ -263,10 +260,6 @@ struct DASM_Shared
OS_Handle u2p_ring_cv; OS_Handle u2p_ring_cv;
OS_Handle u2p_ring_mutex; OS_Handle u2p_ring_mutex;
// rjf: parse threads
U64 parse_thread_count;
OS_Handle *parse_threads;
// rjf: evictor/detector thread // rjf: evictor/detector thread
OS_Handle evictor_detector_thread; OS_Handle evictor_detector_thread;
}; };
@@ -305,12 +298,6 @@ internal U64 dasm_line_array_code_off_from_idx(DASM_LineArray *array, U64 idx);
internal void dasm_init(void); internal void dasm_init(void);
////////////////////////////////
//~ rjf: User Clock
internal void dasm_user_clock_tick(void);
internal U64 dasm_user_clock_idx(void);
//////////////////////////////// ////////////////////////////////
//~ rjf: Scoped Access //~ rjf: Scoped Access
@@ -329,7 +316,7 @@ internal DASM_Info dasm_info_from_key_params(DASM_Scope *scope, U128 key, DASM_P
internal B32 dasm_u2p_enqueue_req(U128 hash, DASM_Params *params, U64 endt_us); internal B32 dasm_u2p_enqueue_req(U128 hash, DASM_Params *params, U64 endt_us);
internal void dasm_u2p_dequeue_req(Arena *arena, U128 *hash_out, DASM_Params *params_out); internal void dasm_u2p_dequeue_req(Arena *arena, U128 *hash_out, DASM_Params *params_out);
internal void dasm_parse_thread__entry_point(void *p); ASYNC_WORK_DEF(dasm_parse_work);
//////////////////////////////// ////////////////////////////////
//~ rjf: Evictor/Detector Thread //~ rjf: Evictor/Detector Thread
+3 -4
View File
@@ -29,9 +29,9 @@ D_CmdTable: // | | | |
{RunToLine 0 1 Null null Nil Null 0 0 0 0 0 0 Play "run_to_line" "Run To Line" "Runs until a particular source line is hit." "" } {RunToLine 0 1 Null null Nil Null 0 0 0 0 0 0 Play "run_to_line" "Run To Line" "Runs until a particular source line is hit." "" }
{RunToAddress 1 1 Vaddr null Nil Null 0 0 0 0 1 1 PlayStepForward "run_to_address" "Run To Address" "Runs until a particular address is hit." "" } {RunToAddress 1 1 Vaddr null Nil Null 0 0 0 0 1 1 PlayStepForward "run_to_address" "Run To Address" "Runs until a particular address is hit." "" }
{Run 1 1 Null null Nil Null 0 0 0 0 0 0 Play "run" "Run" "Runs all targets after starting them if they have not been started yet." "play" } {Run 1 1 Null null Nil Null 0 0 0 0 0 0 Play "run" "Run" "Runs all targets after starting them if they have not been started yet." "play" }
{Restart 1 1 Null null Nil Null 0 0 0 0 0 0 Redo "restart" "Restart" "Kills all attached processes, then restarts the targets which were used to launch all current processes (if any).""restart,retry" } {Restart 1 1 Null null Nil Null 0 0 0 0 0 0 Redo "restart" "Restart" "Kills all attached processes, then launches all active targets." "restart,retry" }
{StepInto 1 1 Null null Nil Null 0 0 0 0 0 0 StepInto "step_into" "Step Into" "Steps once, possibly into function calls, for either source lines or instructions (whichever is selected)." "" } {StepInto 1 1 Null null Nil Null 0 0 0 0 0 0 StepInto "step_into" "Step Into" "Steps once, possibly into function calls, for either source lines or instructions (whichever is selected)." "" }
{StepOver 1 1 Null null Nil Null 0 0 0 0 0 0 StepOver "step_over" "Step Over" "Steps once, always over function calls, for either source lines or instructions." "" } {StepOver 1 1 Null null Nil Null 0 0 0 0 0 0 StepOver "step_over" "Step Over" "Steps once, always over function calls, for either source lines or instructions." "" }
//- rjf: debug control context management operations //- rjf: debug control context management operations
{FreezeThread 1 1 Thread null Nil Thread 0 0 0 0 0 1 Locked "freeze_thread" "Freeze Thread" "Freezes the passed thread." "callstack,unwind" } {FreezeThread 1 1 Thread null Nil Thread 0 0 0 0 0 1 Locked "freeze_thread" "Freeze Thread" "Freezes the passed thread." "callstack,unwind" }
@@ -107,7 +107,6 @@ D_ViewRuleTable:
@table(name) @table(name)
D_DevToggleTable: D_DevToggleTable:
{ {
{telemetry_capture}
{simulate_lag} {simulate_lag}
{draw_ui_text_pos} {draw_ui_text_pos}
{draw_ui_focus_debug} {draw_ui_focus_debug}
+142 -31
View File
@@ -942,6 +942,100 @@ d_lines_from_dbgi_key_voff(Arena *arena, DI_Key *dbgi_key, U64 voff)
// TODO(rjf): this depends on file path maps, needs to move // TODO(rjf): this depends on file path maps, needs to move
internal D_LineListArray
d_lines_array_from_dbgi_key_file_path_line_range(Arena *arena, DI_Key dbgi_key, String8 file_path, Rng1S64 line_num_range)
{
D_LineListArray array = {0};
{
array.count = dim_1s64(line_num_range)+1;
array.v = push_array(arena, D_LineList, array.count);
di_key_list_push(arena, &array.dbgi_keys, &dbgi_key);
}
Temp scratch = scratch_begin(&arena, 1);
U64 *lines_num_voffs = push_array(scratch.arena, U64, array.count);
DI_Scope *scope = di_scope_open();
String8List overrides = rd_possible_overrides_from_file_path(scratch.arena, file_path);
for(String8Node *override_n = overrides.first;
override_n != 0;
override_n = override_n->next)
{
String8 file_path = override_n->string;
String8 file_path_normalized = lower_from_str8(scratch.arena, file_path);
// rjf: binary -> rdi
RDI_Parsed *rdi = di_rdi_from_key(scope, &dbgi_key, 0);
// rjf: file_path_normalized * rdi -> src_id
B32 good_src_id = 0;
U32 src_id = 0;
if(rdi != &di_rdi_parsed_nil) ProfScope("file_path_normalized * rdi -> src_id")
{
RDI_NameMap *mapptr = rdi_element_from_name_idx(rdi, NameMaps, RDI_NameMapKind_NormalSourcePaths);
RDI_ParsedNameMap map = {0};
rdi_parsed_from_name_map(rdi, mapptr, &map);
RDI_NameMapNode *node = rdi_name_map_lookup(rdi, &map, file_path_normalized.str, file_path_normalized.size);
if(node != 0)
{
U32 id_count = 0;
U32 *ids = rdi_matches_from_map_node(rdi, node, &id_count);
if(id_count > 0)
{
good_src_id = 1;
src_id = ids[0];
}
}
}
// rjf: good src-id -> look up line info for visible range
if(good_src_id) ProfScope("good src-id -> look up line info for visible range")
{
RDI_SourceFile *src = rdi_element_from_name_idx(rdi, SourceFiles, src_id);
RDI_SourceLineMap *src_line_map = rdi_element_from_name_idx(rdi, SourceLineMaps, src->source_line_map_idx);
RDI_ParsedSourceLineMap line_map = {0};
rdi_parsed_from_source_line_map(rdi, src_line_map, &line_map);
U64 line_idx = 0;
for(S64 line_num = line_num_range.min;
line_num <= line_num_range.max;
line_num += 1, line_idx += 1)
{
D_LineList *list = &array.v[line_idx];
U32 voff_count = 0;
U64 *voffs = rdi_line_voffs_from_num(&line_map, u32_from_u64_saturate((U64)line_num), &voff_count);
if(lines_num_voffs[line_idx] < 8) ProfScope("iterate voffs (%i)", voff_count) for(U64 idx = 0; idx < voff_count; idx += 1)
{
U64 base_voff = voffs[idx];
U64 unit_idx = rdi_vmap_idx_from_section_kind_voff(rdi, RDI_SectionKind_UnitVMap, base_voff);
RDI_Unit *unit = rdi_element_from_name_idx(rdi, Units, unit_idx);
RDI_LineTable *line_table = rdi_element_from_name_idx(rdi, LineTables, unit->line_table_idx);
RDI_ParsedLineTable unit_line_info = {0};
rdi_parsed_from_line_table(rdi, line_table, &unit_line_info);
U64 line_info_idx = rdi_line_info_idx_from_voff(&unit_line_info, base_voff);
if(unit_line_info.voffs != 0)
{
Rng1U64 range = r1u64(base_voff, unit_line_info.voffs[line_info_idx+1]);
S64 actual_line = (S64)unit_line_info.lines[line_info_idx].line_num;
D_LineNode *n = push_array(arena, D_LineNode, 1);
n->v.voff_range = range;
n->v.pt.line = (S64)actual_line;
n->v.pt.column = 1;
n->v.dbgi_key = dbgi_key;
SLLQueuePush(list->first, list->last, n);
list->count += 1;
lines_num_voffs[line_idx] += 1;
if(lines_num_voffs[line_idx] >= 8)
{
break;
}
}
}
}
}
}
di_scope_close(scope);
scratch_end(scratch);
return array;
}
internal D_LineListArray internal D_LineListArray
d_lines_array_from_file_path_line_range(Arena *arena, String8 file_path, Rng1S64 line_num_range) d_lines_array_from_file_path_line_range(Arena *arena, String8 file_path, Rng1S64 line_num_range)
{ {
@@ -951,6 +1045,7 @@ d_lines_array_from_file_path_line_range(Arena *arena, String8 file_path, Rng1S64
array.v = push_array(arena, D_LineList, array.count); array.v = push_array(arena, D_LineList, array.count);
} }
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
U64 *lines_num_voffs = push_array(scratch.arena, U64, array.count);
DI_Scope *scope = di_scope_open(); DI_Scope *scope = di_scope_open();
DI_KeyList dbgi_keys = d_push_active_dbgi_key_list(scratch.arena); DI_KeyList dbgi_keys = d_push_active_dbgi_key_list(scratch.arena);
String8List overrides = rd_possible_overrides_from_file_path(scratch.arena, file_path); String8List overrides = rd_possible_overrides_from_file_path(scratch.arena, file_path);
@@ -971,7 +1066,7 @@ d_lines_array_from_file_path_line_range(Arena *arena, String8 file_path, Rng1S64
// rjf: file_path_normalized * rdi -> src_id // rjf: file_path_normalized * rdi -> src_id
B32 good_src_id = 0; B32 good_src_id = 0;
U32 src_id = 0; U32 src_id = 0;
if(rdi != &di_rdi_parsed_nil) if(rdi != &di_rdi_parsed_nil) ProfScope("file_path_normalized * rdi -> src_id")
{ {
RDI_NameMap *mapptr = rdi_element_from_name_idx(rdi, NameMaps, RDI_NameMapKind_NormalSourcePaths); RDI_NameMap *mapptr = rdi_element_from_name_idx(rdi, NameMaps, RDI_NameMapKind_NormalSourcePaths);
RDI_ParsedNameMap map = {0}; RDI_ParsedNameMap map = {0};
@@ -990,7 +1085,7 @@ d_lines_array_from_file_path_line_range(Arena *arena, String8 file_path, Rng1S64
} }
// rjf: good src-id -> look up line info for visible range // rjf: good src-id -> look up line info for visible range
if(good_src_id) if(good_src_id) ProfScope("good src-id -> look up line info for visible range")
{ {
RDI_SourceFile *src = rdi_element_from_name_idx(rdi, SourceFiles, src_id); RDI_SourceFile *src = rdi_element_from_name_idx(rdi, SourceFiles, src_id);
RDI_SourceLineMap *src_line_map = rdi_element_from_name_idx(rdi, SourceLineMaps, src->source_line_map_idx); RDI_SourceLineMap *src_line_map = rdi_element_from_name_idx(rdi, SourceLineMaps, src->source_line_map_idx);
@@ -1004,7 +1099,7 @@ d_lines_array_from_file_path_line_range(Arena *arena, String8 file_path, Rng1S64
D_LineList *list = &array.v[line_idx]; D_LineList *list = &array.v[line_idx];
U32 voff_count = 0; U32 voff_count = 0;
U64 *voffs = rdi_line_voffs_from_num(&line_map, u32_from_u64_saturate((U64)line_num), &voff_count); U64 *voffs = rdi_line_voffs_from_num(&line_map, u32_from_u64_saturate((U64)line_num), &voff_count);
for(U64 idx = 0; idx < voff_count; idx += 1) if(lines_num_voffs[line_idx] < 8) ProfScope("iterate voffs (%i)", voff_count) for(U64 idx = 0; idx < voff_count; idx += 1)
{ {
U64 base_voff = voffs[idx]; U64 base_voff = voffs[idx];
U64 unit_idx = rdi_vmap_idx_from_section_kind_voff(rdi, RDI_SectionKind_UnitVMap, base_voff); U64 unit_idx = rdi_vmap_idx_from_section_kind_voff(rdi, RDI_SectionKind_UnitVMap, base_voff);
@@ -1024,6 +1119,11 @@ d_lines_array_from_file_path_line_range(Arena *arena, String8 file_path, Rng1S64
n->v.dbgi_key = key; n->v.dbgi_key = key;
SLLQueuePush(list->first, list->last, n); SLLQueuePush(list->first, list->last, n);
list->count += 1; list->count += 1;
lines_num_voffs[line_idx] += 1;
if(lines_num_voffs[line_idx] >= 8)
{
break;
}
} }
} }
} }
@@ -1041,6 +1141,18 @@ d_lines_array_from_file_path_line_range(Arena *arena, String8 file_path, Rng1S64
return array; return array;
} }
internal D_LineList
d_lines_from_dbgi_key_file_path_line_num(Arena *arena, DI_Key dbgi_key, String8 file_path, S64 line_num)
{
D_LineListArray array = d_lines_array_from_dbgi_key_file_path_line_range(arena, dbgi_key, file_path, r1s64(line_num, line_num+1));
D_LineList list = {0};
if(array.count != 0)
{
list = array.v[0];
}
return list;
}
internal D_LineList internal D_LineList
d_lines_from_file_path_line_num(Arena *arena, String8 file_path, S64 line_num) d_lines_from_file_path_line_num(Arena *arena, String8 file_path, S64 line_num)
{ {
@@ -1968,21 +2080,6 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
} }
} }
//////////////////////////////
//- rjf: start/stop telemetry captures
//
ProfScope("start/stop telemetry captures")
{
if(!ProfIsCapturing() && DEV_telemetry_capture)
{
ProfBeginCapture("raddbg");
}
if(ProfIsCapturing() && !DEV_telemetry_capture)
{
ProfEndCapture();
}
}
////////////////////////////// //////////////////////////////
//- rjf: process top-level commands //- rjf: process top-level commands
// //
@@ -2031,6 +2128,9 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
String8 args = str8_skip_chop_whitespace(target->args); String8 args = str8_skip_chop_whitespace(target->args);
String8 working_directory = str8_skip_chop_whitespace(target->working_directory); String8 working_directory = str8_skip_chop_whitespace(target->working_directory);
String8 custom_entry_point_name = str8_skip_chop_whitespace(target->custom_entry_point_name); String8 custom_entry_point_name = str8_skip_chop_whitespace(target->custom_entry_point_name);
String8 stdout_path = str8_skip_chop_whitespace(target->stdout_path);
String8 stderr_path = str8_skip_chop_whitespace(target->stderr_path);
String8 stdin_path = str8_skip_chop_whitespace(target->stdin_path);
String8List env = target->env; String8List env = target->env;
if(working_directory.size == 0) if(working_directory.size == 0)
{ {
@@ -2071,6 +2171,10 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
msg->kind = CTRL_MsgKind_Launch; msg->kind = CTRL_MsgKind_Launch;
msg->path = working_directory; msg->path = working_directory;
msg->cmd_line_string_list = cmdln_strings; msg->cmd_line_string_list = cmdln_strings;
msg->stdout_path = stdout_path;
msg->stderr_path = stderr_path;
msg->stdin_path = stdin_path;
msg->debug_subprocesses = target->debug_subprocesses;
msg->env_inherit = 1; msg->env_inherit = 1;
MemoryCopyArray(msg->exception_code_filters, exception_code_filters); MemoryCopyArray(msg->exception_code_filters, exception_code_filters);
MemoryCopyStruct(&msg->meta_evals, meta_evals); MemoryCopyStruct(&msg->meta_evals, meta_evals);
@@ -2089,7 +2193,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
// rjf: no targets -> error // rjf: no targets -> error
if(targets_to_launch->count == 0) if(targets_to_launch->count == 0)
{ {
log_user_error(str8_lit("No active targets exist; cannot launch. You must select target first.")); log_user_error(str8_lit("No active targets exist; cannot launch. You must select a target first."));
} }
}break; }break;
case D_CmdKind_Kill: case D_CmdKind_Kill:
@@ -2111,16 +2215,11 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
}break; }break;
case D_CmdKind_KillAll: case D_CmdKind_KillAll:
{ {
CTRL_EntityList processes = ctrl_entity_list_from_kind(d_state->ctrl_entity_store, CTRL_EntityKind_Process); CTRL_Msg *msg = ctrl_msg_list_push(scratch.arena, &ctrl_msgs);
for(CTRL_EntityNode *n = processes.first; n != 0; n = n->next) msg->kind = CTRL_MsgKind_KillAll;
{ msg->exit_code = 1;
CTRL_Msg *msg = ctrl_msg_list_push(scratch.arena, &ctrl_msgs); MemoryCopyArray(msg->exception_code_filters, exception_code_filters);
msg->kind = CTRL_MsgKind_Kill; MemoryCopyStruct(&msg->meta_evals, meta_evals);
msg->exit_code = 1;
msg->entity = n->v->handle;
MemoryCopyArray(msg->exception_code_filters, exception_code_filters);
MemoryCopyStruct(&msg->meta_evals, meta_evals);
}
}break; }break;
case D_CmdKind_Detach: case D_CmdKind_Detach:
{ {
@@ -2308,8 +2407,12 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
}break; }break;
case D_CmdKind_Restart: case D_CmdKind_Restart:
{ {
d_cmd(D_CmdKind_KillAll); CTRL_EntityList processes = ctrl_entity_list_from_kind(d_state->ctrl_entity_store, CTRL_EntityKind_Process);
d_cmd(D_CmdKind_LaunchAndRun); if(processes.count != 0)
{
d_cmd(D_CmdKind_KillAll);
d_cmd(D_CmdKind_LaunchAndRun);
}
}break; }break;
case D_CmdKind_StepInto: case D_CmdKind_StepInto:
case D_CmdKind_StepOver: case D_CmdKind_StepOver:
@@ -2375,6 +2478,14 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P
msg->entity = e->handle; msg->entity = e->handle;
} }
} }
if(d_ctrl_targets_running())
{
need_run = 1;
run_kind = d_state->ctrl_last_run_kind;
run_thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, d_state->ctrl_last_run_thread_handle);
run_flags = d_state->ctrl_last_run_flags;
run_traps = d_state->ctrl_last_run_traps;
}
}break; }break;
//- rjf: entity decoration //- rjf: entity decoration
+7
View File
@@ -14,6 +14,10 @@ struct D_Target
String8 args; String8 args;
String8 working_directory; String8 working_directory;
String8 custom_entry_point_name; String8 custom_entry_point_name;
String8 stdout_path;
String8 stderr_path;
String8 stdin_path;
B32 debug_subprocesses;
String8List env; String8List env;
}; };
@@ -440,7 +444,10 @@ internal D_LineList d_lines_from_dbgi_key_voff(Arena *arena, DI_Key *dbgi_key, U
//- rjf: file:line -> line info //- rjf: file:line -> line info
// TODO(rjf): this depends on file path maps, needs to move // TODO(rjf): this depends on file path maps, needs to move
// TODO(rjf): need to clean this up & dedup
internal D_LineListArray d_lines_array_from_dbgi_key_file_path_line_range(Arena *arena, DI_Key dbgi_key, String8 file_path, Rng1S64 line_num_range);
internal D_LineListArray d_lines_array_from_file_path_line_range(Arena *arena, String8 file_path, Rng1S64 line_num_range); internal D_LineListArray d_lines_array_from_file_path_line_range(Arena *arena, String8 file_path, Rng1S64 line_num_range);
internal D_LineList d_lines_from_dbgi_key_file_path_line_num(Arena *arena, DI_Key dbgi_key, String8 file_path, S64 line_num);
internal D_LineList d_lines_from_file_path_line_num(Arena *arena, String8 file_path, S64 line_num); internal D_LineList d_lines_from_file_path_line_num(Arena *arena, String8 file_path, S64 line_num);
//////////////////////////////// ////////////////////////////////
@@ -71,7 +71,6 @@ D_ViewRuleKind_Geo3D,
D_ViewRuleKind_COUNT, D_ViewRuleKind_COUNT,
} D_ViewRuleKind; } D_ViewRuleKind;
global B32 DEV_telemetry_capture = 0;
global B32 DEV_simulate_lag = 0; global B32 DEV_simulate_lag = 0;
global B32 DEV_draw_ui_text_pos = 0; global B32 DEV_draw_ui_text_pos = 0;
global B32 DEV_draw_ui_focus_debug = 0; global B32 DEV_draw_ui_focus_debug = 0;
@@ -83,7 +82,6 @@ global B32 DEV_scratch_mouse_draw = 0;
global B32 DEV_updating_indicator = 0; global B32 DEV_updating_indicator = 0;
struct {B32 *value_ptr; String8 name;} DEV_toggle_table[] = struct {B32 *value_ptr; String8 name;} DEV_toggle_table[] =
{ {
{&DEV_telemetry_capture, str8_lit_comp("telemetry_capture")},
{&DEV_simulate_lag, str8_lit_comp("simulate_lag")}, {&DEV_simulate_lag, str8_lit_comp("simulate_lag")},
{&DEV_draw_ui_text_pos, str8_lit_comp("draw_ui_text_pos")}, {&DEV_draw_ui_text_pos, str8_lit_comp("draw_ui_text_pos")},
{&DEV_draw_ui_focus_debug, str8_lit_comp("draw_ui_focus_debug")}, {&DEV_draw_ui_focus_debug, str8_lit_comp("draw_ui_focus_debug")},
+1199 -290
View File
File diff suppressed because it is too large Load Diff
+226 -9
View File
@@ -72,7 +72,7 @@ struct DI_EventList
}; };
//////////////////////////////// ////////////////////////////////
//~ rjf: Cache Types //~ rjf: Debug Info Cache Types
typedef struct DI_StringChunkNode DI_StringChunkNode; typedef struct DI_StringChunkNode DI_StringChunkNode;
struct DI_StringChunkNode struct DI_StringChunkNode
@@ -92,7 +92,6 @@ struct DI_Node
U64 ref_count; U64 ref_count;
U64 touch_count; U64 touch_count;
U64 is_working; U64 is_working;
U64 last_time_requested_us;
// rjf: key // rjf: key
DI_Key key; DI_Key key;
@@ -126,6 +125,91 @@ struct DI_Stripe
OS_Handle cv; OS_Handle cv;
}; };
////////////////////////////////
//~ rjf: Search Cache Types
typedef struct DI_SearchItem DI_SearchItem;
struct DI_SearchItem
{
U64 idx;
U64 dbgi_idx;
U64 missed_size;
FuzzyMatchRangeList match_ranges;
};
typedef struct DI_SearchItemChunk DI_SearchItemChunk;
struct DI_SearchItemChunk
{
DI_SearchItemChunk *next;
DI_SearchItem *v;
U64 count;
U64 cap;
};
typedef struct DI_SearchItemChunkList DI_SearchItemChunkList;
struct DI_SearchItemChunkList
{
DI_SearchItemChunk *first;
DI_SearchItemChunk *last;
U64 chunk_count;
U64 total_count;
};
typedef struct DI_SearchItemArray DI_SearchItemArray;
struct DI_SearchItemArray
{
DI_SearchItem *v;
U64 count;
};
typedef struct DI_SearchParams DI_SearchParams;
struct DI_SearchParams
{
RDI_SectionKind target;
DI_KeyArray dbgi_keys;
};
typedef struct DI_SearchBucket DI_SearchBucket;
struct DI_SearchBucket
{
Arena *arena;
String8 query;
U64 params_hash;
DI_SearchParams params;
};
typedef struct DI_SearchNode DI_SearchNode;
struct DI_SearchNode
{
DI_SearchNode *next;
DI_SearchNode *prev;
U128 key;
U64 scope_refcount;
U64 work_refcount;
U64 last_update_tick_idx;
U64 bucket_read_gen;
U64 bucket_write_gen;
U64 bucket_items_gen;
DI_SearchBucket buckets[6];
DI_SearchItemArray items;
};
typedef struct DI_SearchSlot DI_SearchSlot;
struct DI_SearchSlot
{
DI_SearchNode *first;
DI_SearchNode *last;
};
typedef struct DI_SearchStripe DI_SearchStripe;
struct DI_SearchStripe
{
Arena *arena;
DI_SearchNode *free_node;
OS_Handle rw_mutex;
OS_Handle cv;
};
//////////////////////////////// ////////////////////////////////
//~ rjf: Scoped Access Types //~ rjf: Scoped Access Types
@@ -134,6 +218,7 @@ struct DI_Touch
{ {
DI_Touch *next; DI_Touch *next;
DI_Node *node; DI_Node *node;
DI_SearchNode *search_node;
}; };
typedef struct DI_Scope DI_Scope; typedef struct DI_Scope DI_Scope;
@@ -152,6 +237,98 @@ struct DI_TCTX
DI_Touch *free_touch; DI_Touch *free_touch;
}; };
////////////////////////////////
//~ rjf: Search Thread State Types
typedef struct DI_SearchThread DI_SearchThread;
struct DI_SearchThread
{
OS_Handle thread;
OS_Handle ring_mutex;
OS_Handle ring_cv;
U64 ring_size;
U8 *ring_base;
U64 ring_write_pos;
U64 ring_read_pos;
};
////////////////////////////////
//~ rjf: Match Cache State Types
typedef struct DI_Match DI_Match;
struct DI_Match
{
DI_Match *next;
DI_Match *prev;
U64 dbgi_idx;
RDI_SectionKind section;
U32 idx;
};
typedef struct DI_MatchNameNode DI_MatchNameNode;
struct DI_MatchNameNode
{
// rjf: synchronously written by usage code
DI_MatchNameNode *next;
DI_MatchNameNode *prev;
DI_MatchNameNode *lru_next;
DI_MatchNameNode *lru_prev;
U64 alloc_gen;
U64 first_gen_touched;
U64 last_gen_touched;
U64 req_params_hash;
U64 req_count;
String8 name;
U64 hash;
// rjf: atomically written by match work
U64 cmp_count;
U64 cmp_params_hash;
RDI_SectionKind section_kind;
// DI_Match *first_match;
// DI_Match *last_match;
};
typedef struct DI_MatchNameSlot DI_MatchNameSlot;
struct DI_MatchNameSlot
{
DI_MatchNameNode *first;
DI_MatchNameNode *last;
};
typedef struct DI_MatchStore DI_MatchStore;
struct DI_MatchStore
{
Arena *arena;
U64 gen;
Arena *gen_arenas[2];
// rjf: parameters
Arena *params_arena;
OS_Handle params_rw_mutex;
U64 params_hash;
DI_KeyArray params_keys;
// rjf: match cache
U64 match_name_slots_count;
DI_MatchNameSlot *match_name_slots;
DI_MatchNameNode *first_free_match_name;
DI_Match *first_free_match;
DI_MatchNameNode *first_lru_match_name;
DI_MatchNameNode *last_lru_match_name;
U64 active_match_name_nodes_count;
OS_Handle match_rw_mutex;
OS_Handle match_cv;
// rjf: user -> match work ring buffer
OS_Handle u2m_ring_cv;
OS_Handle u2m_ring_mutex;
U64 u2m_ring_size;
U8 *u2m_ring_base;
U64 u2m_ring_write_pos;
U64 u2m_ring_read_pos;
};
//////////////////////////////// ////////////////////////////////
//~ rjf: Shared State Types //~ rjf: Shared State Types
@@ -160,12 +337,18 @@ struct DI_Shared
{ {
Arena *arena; Arena *arena;
// rjf: node cache // rjf: debug info cache
U64 slots_count; U64 slots_count;
DI_Slot *slots; DI_Slot *slots;
U64 stripes_count; U64 stripes_count;
DI_Stripe *stripes; DI_Stripe *stripes;
// rjf: search cache
U64 search_slots_count;
DI_SearchSlot *search_slots;
U64 search_stripes_count;
DI_SearchStripe *search_stripes;
// rjf: user -> parse ring // rjf: user -> parse ring
OS_Handle u2p_ring_mutex; OS_Handle u2p_ring_mutex;
OS_Handle u2p_ring_cv; OS_Handle u2p_ring_cv;
@@ -182,9 +365,10 @@ struct DI_Shared
U64 p2u_ring_write_pos; U64 p2u_ring_write_pos;
U64 p2u_ring_read_pos; U64 p2u_ring_read_pos;
// rjf: threads // rjf: search threads
U64 parse_thread_count; U64 search_threads_count;
OS_Handle *parse_threads; DI_SearchThread *search_threads;
OS_Handle search_evictor_thread;
}; };
//////////////////////////////// ////////////////////////////////
@@ -197,6 +381,7 @@ global RDI_Parsed di_rdi_parsed_nil = {0};
//////////////////////////////// ////////////////////////////////
//~ rjf: Basic Helpers //~ rjf: Basic Helpers
internal U64 di_hash_from_seed_string(U64 seed, String8 string, StringMatchFlags match_flags);
internal U64 di_hash_from_string(String8 string, StringMatchFlags match_flags); internal U64 di_hash_from_string(String8 string, StringMatchFlags match_flags);
internal U64 di_hash_from_key(DI_Key *k); internal U64 di_hash_from_key(DI_Key *k);
internal DI_Key di_key_zero(void); internal DI_Key di_key_zero(void);
@@ -205,6 +390,12 @@ internal DI_Key di_key_copy(Arena *arena, DI_Key *src);
internal DI_Key di_normalized_key_from_key(Arena *arena, DI_Key *src); internal DI_Key di_normalized_key_from_key(Arena *arena, DI_Key *src);
internal void di_key_list_push(Arena *arena, DI_KeyList *list, DI_Key *key); internal void di_key_list_push(Arena *arena, DI_KeyList *list, DI_Key *key);
internal DI_KeyArray di_key_array_from_list(Arena *arena, DI_KeyList *list); internal DI_KeyArray di_key_array_from_list(Arena *arena, DI_KeyList *list);
internal DI_KeyArray di_key_array_copy(Arena *arena, DI_KeyArray *src);
internal DI_SearchParams di_search_params_copy(Arena *arena, DI_SearchParams *src);
internal U64 di_hash_from_search_params(DI_SearchParams *params);
internal void di_search_item_chunk_list_concat_in_place(DI_SearchItemChunkList *dst, DI_SearchItemChunkList *to_push);
internal U64 di_search_item_num_from_array_element_idx__linear_search(DI_SearchItemArray *array, U64 element_idx);
internal String8 di_search_item_string_from_rdi_target_element_idx(RDI_Parsed *rdi, RDI_SectionKind target, U64 element_idx);
//////////////////////////////// ////////////////////////////////
//~ rjf: Main Layer Initialization //~ rjf: Main Layer Initialization
@@ -217,6 +408,7 @@ internal void di_init(void);
internal DI_Scope *di_scope_open(void); internal DI_Scope *di_scope_open(void);
internal void di_scope_close(DI_Scope *scope); internal void di_scope_close(DI_Scope *scope);
internal void di_scope_touch_node__stripe_mutex_r_guarded(DI_Scope *scope, DI_Node *node); internal void di_scope_touch_node__stripe_mutex_r_guarded(DI_Scope *scope, DI_Node *node);
internal void di_scope_touch_search_node__stripe_mutex_r_guarded(DI_Scope *scope, DI_SearchNode *node);
//////////////////////////////// ////////////////////////////////
//~ rjf: Per-Slot Functions //~ rjf: Per-Slot Functions
@@ -237,12 +429,17 @@ internal void di_open(DI_Key *key);
internal void di_close(DI_Key *key); internal void di_close(DI_Key *key);
//////////////////////////////// ////////////////////////////////
//~ rjf: Cache Lookups //~ rjf: Debug Info Cache Lookups
internal RDI_Parsed *di_rdi_from_key(DI_Scope *scope, DI_Key *key, U64 endt_us); internal RDI_Parsed *di_rdi_from_key(DI_Scope *scope, DI_Key *key, U64 endt_us);
//////////////////////////////// ////////////////////////////////
//~ rjf: Parse Threads //~ rjf: Search Cache Lookups
internal DI_SearchItemArray di_search_items_from_key_params_query(DI_Scope *scope, U128 key, DI_SearchParams *params, String8 query, U64 endt_us, B32 *stale_out);
////////////////////////////////
//~ rjf: Asynchronous Parse Work
internal B32 di_u2p_enqueue_key(DI_Key *key, U64 endt_us); internal B32 di_u2p_enqueue_key(DI_Key *key, U64 endt_us);
internal void di_u2p_dequeue_key(Arena *arena, DI_Key *out_key); internal void di_u2p_dequeue_key(Arena *arena, DI_Key *out_key);
@@ -250,6 +447,26 @@ internal void di_u2p_dequeue_key(Arena *arena, DI_Key *out_key);
internal void di_p2u_push_event(DI_Event *event); internal void di_p2u_push_event(DI_Event *event);
internal DI_EventList di_p2u_pop_events(Arena *arena, U64 endt_us); internal DI_EventList di_p2u_pop_events(Arena *arena, U64 endt_us);
internal void di_parse_thread__entry_point(void *p); ASYNC_WORK_DEF(di_parse_work);
////////////////////////////////
//~ rjf: Search Threads
internal B32 di_u2s_enqueue_req(U128 key, U64 endt_us);
internal U128 di_u2s_dequeue_req(U64 thread_idx);
ASYNC_WORK_DEF(di_search_work);
internal int di_qsort_compare_search_items(DI_SearchItem *a, DI_SearchItem *b);
internal void di_search_thread__entry_point(void *p);
internal void di_search_evictor_thread__entry_point(void *p);
////////////////////////////////
//~ rjf: Match Store
internal DI_MatchStore *di_match_store_alloc(void);
internal void di_match_store_begin(DI_MatchStore *store, DI_KeyArray keys);
internal RDI_SectionKind di_match_store_section_kind_from_name(DI_MatchStore *store, String8 name, U64 endt_us);
ASYNC_WORK_DEF(di_match_work);
#endif // DBGI_H #endif // DBGI_H
+30
View File
@@ -156,3 +156,33 @@ dmn_rsp_from_thread(DMN_Handle thread)
scratch_end(scratch); scratch_end(scratch);
return result; return result;
} }
////////////////////////////////
//~ Memory Helpers
internal String8
dmn_process_read_cstring(Arena *arena, DMN_Handle process, U64 addr)
{
Temp scratch = scratch_begin(&arena, 1);
String8List block_list = {0};
for(U64 cursor = addr, stride = 256; ; cursor += stride)
{
U8 *raw_block = push_array_no_zero(scratch.arena, U8, stride);
U64 read_size = dmn_process_read(process, r1u64(cursor, cursor + stride), raw_block);
String8 block = str8_cstring_capped(raw_block, raw_block + read_size);
str8_list_push(scratch.arena, &block_list, block);
if(read_size != stride || (block.size+1 <= read_size && block.str[block.size] == 0))
{
break;
}
}
String8 result = str8_list_join(arena, &block_list, 0);
scratch_end(scratch);
return result;
}
+1
View File
@@ -226,6 +226,7 @@ internal U64 dmn_process_read(DMN_Handle process, Rng1U64 range, void *dst);
internal B32 dmn_process_write(DMN_Handle process, Rng1U64 range, void *src); internal B32 dmn_process_write(DMN_Handle process, Rng1U64 range, void *src);
#define dmn_process_read_struct(process, vaddr, ptr) dmn_process_read((process), r1u64((vaddr), (vaddr)+(sizeof(*ptr))), ptr) #define dmn_process_read_struct(process, vaddr, ptr) dmn_process_read((process), r1u64((vaddr), (vaddr)+(sizeof(*ptr))), ptr)
#define dmn_process_write_struct(process, vaddr, ptr) dmn_process_write((process), r1u64((vaddr), (vaddr)+(sizeof(*ptr))), ptr) #define dmn_process_write_struct(process, vaddr, ptr) dmn_process_write((process), r1u64((vaddr), (vaddr)+(sizeof(*ptr))), ptr)
internal String8 dmn_process_read_cstring(Arena *arena, DMN_Handle process, U64 addr);
//- rjf: threads //- rjf: threads
internal Arch dmn_arch_from_thread(DMN_Handle handle); internal Arch dmn_arch_from_thread(DMN_Handle handle);
+34 -2
View File
@@ -1217,6 +1217,8 @@ dmn_ctrl_launch(DMN_CtrlCtx *ctx, OS_ProcessLaunchParams *params)
{ {
String8List args = {0}; String8List args = {0};
String8 exe_path = params->cmd_line.first->string; String8 exe_path = params->cmd_line.first->string;
String8List exe_path_parts = str8_split_path(scratch.arena, exe_path);
exe_path = str8_list_join(scratch.arena, &exe_path_parts, &(StringJoin){.sep = str8_lit("\\")});
str8_list_pushf(scratch.arena, &args, "\"%S\"", exe_path); str8_list_pushf(scratch.arena, &args, "\"%S\"", exe_path);
for(String8Node *n = params->cmd_line.first->next; n != 0; n = n->next) for(String8Node *n = params->cmd_line.first->next; n != 0; n = n->next)
{ {
@@ -1256,11 +1258,41 @@ dmn_ctrl_launch(DMN_CtrlCtx *ctx, OS_ProcessLaunchParams *params)
String16 env16 = str16_from_8(scratch.arena, env); String16 env16 = str16_from_8(scratch.arena, env);
//- rjf: launch //- rjf: launch
DWORD access_flags = CREATE_UNICODE_ENVIRONMENT|DEBUG_PROCESS; DWORD creation_flags = CREATE_UNICODE_ENVIRONMENT;
if(params->debug_subprocesses)
{
creation_flags |= DEBUG_PROCESS;
}
else
{
creation_flags |= DEBUG_ONLY_THIS_PROCESS;
}
BOOL inherit_handles = 0;
STARTUPINFOW startup_info = {sizeof(startup_info)}; STARTUPINFOW startup_info = {sizeof(startup_info)};
if(!os_handle_match(params->stdout_file, os_handle_zero()))
{
HANDLE stdout_handle = (HANDLE)params->stdout_file.u64[0];
startup_info.hStdOutput = stdout_handle;
startup_info.dwFlags |= STARTF_USESTDHANDLES;
inherit_handles = 1;
}
if(!os_handle_match(params->stderr_file, os_handle_zero()))
{
HANDLE stderr_handle = (HANDLE)params->stderr_file.u64[0];
startup_info.hStdError = stderr_handle;
startup_info.dwFlags |= STARTF_USESTDHANDLES;
inherit_handles = 1;
}
if(!os_handle_match(params->stdin_file, os_handle_zero()))
{
HANDLE stdin_handle = (HANDLE)params->stdin_file.u64[0];
startup_info.hStdInput = stdin_handle;
startup_info.dwFlags |= STARTF_USESTDHANDLES;
inherit_handles = 1;
}
PROCESS_INFORMATION process_info = {0}; PROCESS_INFORMATION process_info = {0};
AllocConsole(); AllocConsole();
if(CreateProcessW(0, (WCHAR*)cmd16.str, 0, 0, 1, access_flags, (WCHAR*)env16.str, (WCHAR*)dir16.str, &startup_info, &process_info)) if(CreateProcessW(0, (WCHAR*)cmd16.str, 0, 0, 1, creation_flags, (WCHAR*)env16.str, (WCHAR*)dir16.str, &startup_info, &process_info))
{ {
// check if we are 32-bit app, and just close it immediately // check if we are 32-bit app, and just close it immediately
BOOL is_wow = 0; BOOL is_wow = 0;
+2
View File
@@ -609,6 +609,7 @@ dr_truncated_fancy_run_fuzzy_matches(Vec2F32 p, DR_FancyRunList *list, F32 max_x
internal void internal void
dr_text_run(Vec2F32 p, Vec4F32 color, FNT_Run run) dr_text_run(Vec2F32 p, Vec4F32 color, FNT_Run run)
{ {
ProfBeginFunction();
F32 advance = 0; F32 advance = 0;
FNT_Piece *piece_first = run.pieces.v; FNT_Piece *piece_first = run.pieces.v;
FNT_Piece *piece_opl = piece_first + run.pieces.count; FNT_Piece *piece_opl = piece_first + run.pieces.count;
@@ -629,6 +630,7 @@ dr_text_run(Vec2F32 p, Vec4F32 color, FNT_Run run)
} }
advance += piece->advance; advance += piece->advance;
} }
ProfEnd();
} }
internal void internal void
+1 -1
View File
@@ -132,7 +132,7 @@ internal DR_Bucket *dr_bucket_make(void);
internal void dr_push_bucket(DR_Bucket *bucket); internal void dr_push_bucket(DR_Bucket *bucket);
internal void dr_pop_bucket(void); internal void dr_pop_bucket(void);
internal DR_Bucket *dr_top_bucket(void); internal DR_Bucket *dr_top_bucket(void);
#define D_BucketScope(b) DeferLoop(dr_push_bucket(b), dr_pop_bucket()) #define DR_BucketScope(b) DeferLoop(dr_push_bucket(b), dr_pop_bucket())
//////////////////////////////// ////////////////////////////////
//~ rjf: Bucket Stacks //~ rjf: Bucket Stacks
+1
View File
@@ -90,6 +90,7 @@ E_ExprKindTable:
{ Typeof UnaryPrefix 1 "typeof" "typeof" "(" ")"} { Typeof UnaryPrefix 1 "typeof" "typeof" "(" ")"}
{ ByteSwap UnaryPrefix 1 "bswap" "bswap" "(" ")"} { ByteSwap UnaryPrefix 1 "bswap" "bswap" "(" ")"}
{ Pos UnaryPrefix 2 "+" "+" "" "" }
{ Neg UnaryPrefix 2 "-" "-" "" "" } { Neg UnaryPrefix 2 "-" "-" "" "" }
{ LogNot UnaryPrefix 2 "!" "!" "" "" } { LogNot UnaryPrefix 2 "!" "!" "" "" }
{ BitNot UnaryPrefix 2 "~" "~" "" "" } { BitNot UnaryPrefix 2 "~" "~" "" "" }
+1 -1
View File
@@ -170,7 +170,7 @@ e_value_eval_from_eval(E_Eval eval)
U64 valid_bits_mask = 0; U64 valid_bits_mask = 0;
for(U64 idx = 0; idx < type->count; idx += 1) for(U64 idx = 0; idx < type->count; idx += 1)
{ {
valid_bits_mask |= (1<<idx); valid_bits_mask |= (1ull<<idx);
} }
eval.value.u64 = eval.value.u64 >> type->off; eval.value.u64 = eval.value.u64 >> type->off;
eval.value.u64 = eval.value.u64 & valid_bits_mask; eval.value.u64 = eval.value.u64 & valid_bits_mask;
+5
View File
@@ -846,6 +846,10 @@ e_irtree_and_type_from_expr(Arena *arena, E_Expr *expr)
}break; }break;
//- rjf: unary operations //- rjf: unary operations
case E_ExprKind_Pos:
{
result = e_irtree_and_type_from_expr(arena, expr->first);
}break;
case E_ExprKind_Neg: case E_ExprKind_Neg:
case E_ExprKind_LogNot: case E_ExprKind_LogNot:
case E_ExprKind_BitNot: case E_ExprKind_BitNot:
@@ -1050,6 +1054,7 @@ e_irtree_and_type_from_expr(Arena *arena, E_Expr *expr)
ptr_root = e_irtree_resolve_to_value(arena, ptr_tree->space, ptr_tree->mode, ptr_root, ptr_tree->type_key); ptr_root = e_irtree_resolve_to_value(arena, ptr_tree->space, ptr_tree->mode, ptr_root, ptr_tree->type_key);
} }
E_IRNode *int_root = int_tree->root; E_IRNode *int_root = int_tree->root;
int_root = e_irtree_resolve_to_value(arena, int_tree->space, int_tree->mode, int_root, int_tree->type_key);
if(direct_type_size > 1) if(direct_type_size > 1)
{ {
E_IRNode *const_root = e_irtree_const_u(arena, direct_type_size); E_IRNode *const_root = e_irtree_const_u(arena, direct_type_size);
+25 -10
View File
@@ -389,6 +389,7 @@ e_token_array_from_text(Arena *arena, String8 text)
E_TokenKind active_token_kind = E_TokenKind_Null; E_TokenKind active_token_kind = E_TokenKind_Null;
B32 active_token_kind_started_with_tick = 0; B32 active_token_kind_started_with_tick = 0;
B32 escaped = 0; B32 escaped = 0;
B32 exp = 0;
for(U64 idx = 0, advance = 0; idx <= text.size; idx += advance) for(U64 idx = 0, advance = 0; idx <= text.size; idx += advance)
{ {
U8 byte = (idx+0 < text.size) ? text.str[idx+0] : 0; U8 byte = (idx+0 < text.size) ? text.str[idx+0] : 0;
@@ -486,11 +487,17 @@ e_token_array_from_text(Arena *arena, String8 text)
}break; }break;
case E_TokenKind_Numeric: case E_TokenKind_Numeric:
{ {
if(!char_is_alpha(byte) && !char_is_digit(byte, 10) && byte != '.' && byte != ':') if(exp && (byte == '+' || byte == '-')){}
else if(!char_is_alpha(byte) && !char_is_digit(byte, 10) && byte != '.' && byte != ':')
{ {
advance = 0; advance = 0;
token_formed = 1; token_formed = 1;
} }
else
{
exp = 0;
exp = (byte == 'e');
}
}break; }break;
case E_TokenKind_StringLiteral: case E_TokenKind_StringLiteral:
{ {
@@ -1018,6 +1025,12 @@ e_parse_type_from_text_tokens(Arena *arena, String8 text, E_TokenArray *tokens)
if(token.kind == E_TokenKind_Identifier) if(token.kind == E_TokenKind_Identifier)
{ {
String8 token_string = str8_substr(text, token.range); String8 token_string = str8_substr(text, token.range);
if(token_string.size >= 2 &&
token_string.str[0] == '`' &&
token_string.str[token_string.size-1] == '`')
{
token_string = str8_substr(token_string, r1u64(1, token_string.size-1));
}
E_TypeKey type_key = e_leaf_type_from_name(token_string); E_TypeKey type_key = e_leaf_type_from_name(token_string);
if(!e_type_key_match(e_type_key_zero(), type_key)) if(!e_type_key_match(e_type_key_zero(), type_key))
{ {
@@ -1351,7 +1364,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
} }
//- rjf: try members //- rjf: try members
if(mapped_identifier == 0 && (resolution_qualifier.size == 0 || str8_match(resolution_qualifier, str8_lit("member"), 0))) if(mapped_identifier == 0 && (resolution_qualifier.size == 0 || str8_match(resolution_qualifier, str8_lit("member"), 0))) ProfScope("try to map name as member")
{ {
U64 data_member_num = e_num_from_string(e_parse_ctx->member_map, token_string); U64 data_member_num = e_num_from_string(e_parse_ctx->member_map, token_string);
if(data_member_num != 0) if(data_member_num != 0)
@@ -1362,7 +1375,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
} }
//- rjf: try locals //- rjf: try locals
if(mapped_identifier == 0 && (resolution_qualifier.size == 0 || str8_match(resolution_qualifier, str8_lit("local"), 0))) if(mapped_identifier == 0 && (resolution_qualifier.size == 0 || str8_match(resolution_qualifier, str8_lit("local"), 0))) ProfScope("try to map name as local")
{ {
E_Module *module = e_parse_ctx->primary_module; E_Module *module = e_parse_ctx->primary_module;
RDI_Parsed *rdi = module->rdi; RDI_Parsed *rdi = module->rdi;
@@ -1426,7 +1439,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
} }
//- rjf: try registers //- rjf: try registers
if(mapped_identifier == 0 && (resolution_qualifier.size == 0 || str8_match(resolution_qualifier, str8_lit("reg"), 0))) if(mapped_identifier == 0 && (resolution_qualifier.size == 0 || str8_match(resolution_qualifier, str8_lit("reg"), 0))) ProfScope("try to map name as register")
{ {
U64 reg_num = e_num_from_string(e_parse_ctx->regs_map, token_string); U64 reg_num = e_num_from_string(e_parse_ctx->regs_map, token_string);
if(reg_num != 0) if(reg_num != 0)
@@ -1440,7 +1453,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
} }
//- rjf: try register aliases //- rjf: try register aliases
if(mapped_identifier == 0 && (resolution_qualifier.size == 0 || str8_match(resolution_qualifier, str8_lit("reg"), 0))) if(mapped_identifier == 0 && (resolution_qualifier.size == 0 || str8_match(resolution_qualifier, str8_lit("reg"), 0))) ProfScope("try to map name as register alias")
{ {
U64 alias_num = e_num_from_string(e_parse_ctx->reg_alias_map, token_string); U64 alias_num = e_num_from_string(e_parse_ctx->reg_alias_map, token_string);
if(alias_num != 0) if(alias_num != 0)
@@ -1454,7 +1467,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
} }
//- rjf: try global variables //- rjf: try global variables
if(mapped_identifier == 0 && (resolution_qualifier.size == 0 || str8_match(resolution_qualifier, str8_lit("global"), 0))) if(mapped_identifier == 0 && (resolution_qualifier.size == 0 || str8_match(resolution_qualifier, str8_lit("global"), 0))) ProfScope("try to map name as global variable")
{ {
for(U64 module_idx = 0; module_idx < e_parse_ctx->modules_count; module_idx += 1) for(U64 module_idx = 0; module_idx < e_parse_ctx->modules_count; module_idx += 1)
{ {
@@ -1498,7 +1511,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
} }
//- rjf: try thread variables //- rjf: try thread variables
if(mapped_identifier == 0 && (resolution_qualifier.size == 0 || str8_match(resolution_qualifier, str8_lit("thread_variable"), 0))) if(mapped_identifier == 0 && (resolution_qualifier.size == 0 || str8_match(resolution_qualifier, str8_lit("thread_variable"), 0))) ProfScope("try to map name as thread variable")
{ {
for(U64 module_idx = 0; module_idx < e_parse_ctx->modules_count; module_idx += 1) for(U64 module_idx = 0; module_idx < e_parse_ctx->modules_count; module_idx += 1)
{ {
@@ -1538,7 +1551,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
} }
//- rjf: try procedures //- rjf: try procedures
if(mapped_identifier == 0 && (resolution_qualifier.size == 0 || str8_match(resolution_qualifier, str8_lit("procedure"), 0))) if(mapped_identifier == 0 && (resolution_qualifier.size == 0 || str8_match(resolution_qualifier, str8_lit("procedure"), 0))) ProfScope("try to map name as procedure")
{ {
for(U64 module_idx = 0; module_idx < e_parse_ctx->modules_count; module_idx += 1) for(U64 module_idx = 0; module_idx < e_parse_ctx->modules_count; module_idx += 1)
{ {
@@ -1580,7 +1593,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
} }
//- rjf: try types //- rjf: try types
if(mapped_identifier == 0 && (resolution_qualifier.size == 0 || str8_match(resolution_qualifier, str8_lit("type"), 0))) if(mapped_identifier == 0 && (resolution_qualifier.size == 0 || str8_match(resolution_qualifier, str8_lit("type"), 0))) ProfScope("try to map name as type")
{ {
type_key = e_leaf_type_from_name(token_string); type_key = e_leaf_type_from_name(token_string);
if(!e_type_key_match(e_type_key_zero(), type_key)) if(!e_type_key_match(e_type_key_zero(), type_key))
@@ -1609,7 +1622,7 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
} }
//- rjf: attach on map //- rjf: attach on map
if(mapped_identifier != 0) if(mapped_identifier != 0) ProfScope("attach on map")
{ {
it += 1; it += 1;
@@ -2100,7 +2113,9 @@ e_parse_expr_from_text_tokens__prec(Arena *arena, String8 text, E_TokenArray *to
internal E_Parse internal E_Parse
e_parse_expr_from_text_tokens(Arena *arena, String8 text, E_TokenArray *tokens) e_parse_expr_from_text_tokens(Arena *arena, String8 text, E_TokenArray *tokens)
{ {
ProfBegin("parse '%.*s'", str8_varg(text));
E_Parse parse = e_parse_expr_from_text_tokens__prec(arena, text, tokens, e_max_precedence); E_Parse parse = e_parse_expr_from_text_tokens__prec(arena, text, tokens, e_max_precedence);
ProfEnd();
return parse; return parse;
} }
+44 -17
View File
@@ -403,6 +403,8 @@ e_type_key_cons_(E_ConsTypeParams *params)
{ {
node->params.members[idx].name = push_str8_copy(e_type_state->arena, node->params.members[idx].name); node->params.members[idx].name = push_str8_copy(e_type_state->arena, node->params.members[idx].name);
node->params.members[idx].inheritance_key_chain = e_type_key_list_copy(e_type_state->arena, &node->params.members[idx].inheritance_key_chain); node->params.members[idx].inheritance_key_chain = e_type_key_list_copy(e_type_state->arena, &node->params.members[idx].inheritance_key_chain);
U64 opl_off = (node->params.members[idx].off + e_type_byte_size_from_key(node->params.members[idx].type_key));
node->byte_size = Max(node->byte_size, opl_off);
} }
} }
else if(params->enum_vals != 0) else if(params->enum_vals != 0)
@@ -413,6 +415,23 @@ e_type_key_cons_(E_ConsTypeParams *params)
{ {
node->params.enum_vals[idx].name = push_str8_copy(e_type_state->arena, node->params.enum_vals[idx].name); node->params.enum_vals[idx].name = push_str8_copy(e_type_state->arena, node->params.enum_vals[idx].name);
} }
node->byte_size = e_type_byte_size_from_key(node->params.direct_key);
}
else switch(params->kind)
{
default:
{
node->byte_size = e_type_byte_size_from_key(node->params.direct_key);
}break;
case E_TypeKind_Ptr:
{
node->byte_size = bit_size_from_arch(node->params.arch)/8;
}break;
case E_TypeKind_Array:
{
U64 ptee_size = e_type_byte_size_from_key(node->params.direct_key);
node->byte_size = ptee_size * node->params.count;
}break;
} }
result = key; result = key;
} }
@@ -565,6 +584,7 @@ e_type_kind_from_key(E_TypeKey key)
internal E_Type * internal E_Type *
e_type_from_key(Arena *arena, E_TypeKey key) e_type_from_key(Arena *arena, E_TypeKey key)
{ {
ProfBeginFunction();
E_Type *type = &e_type_nil; E_Type *type = &e_type_nil;
U64 reg_byte_count = 0; U64 reg_byte_count = 0;
{ {
@@ -603,21 +623,9 @@ e_type_from_key(Arena *arena, E_TypeKey key)
type->name = push_str8_copy(arena, node->params.name); type->name = push_str8_copy(arena, node->params.name);
type->direct_type_key = node->params.direct_key; type->direct_type_key = node->params.direct_key;
type->count = node->params.count; type->count = node->params.count;
type->byte_size = node->byte_size;
switch(type->kind) switch(type->kind)
{ {
default:
{
type->byte_size = e_type_byte_size_from_key(type->direct_type_key);
}break;
case E_TypeKind_Ptr:
{
type->byte_size = bit_size_from_arch(node->params.arch)/8;
}break;
case E_TypeKind_Array:
{
U64 ptee_size = e_type_byte_size_from_key(node->params.direct_key);
type->byte_size = ptee_size * type->count;
}break;
case E_TypeKind_Struct: case E_TypeKind_Struct:
case E_TypeKind_Union: case E_TypeKind_Union:
case E_TypeKind_Class: case E_TypeKind_Class:
@@ -1115,12 +1123,14 @@ e_type_from_key(Arena *arena, E_TypeKey key)
}break; }break;
} }
} }
ProfEnd();
return type; return type;
} }
internal U64 internal U64
e_type_byte_size_from_key(E_TypeKey key) e_type_byte_size_from_key(E_TypeKey key)
{ {
ProfBeginFunction();
U64 result = 0; U64 result = 0;
switch(key.kind) switch(key.kind)
{ {
@@ -1131,14 +1141,31 @@ e_type_byte_size_from_key(E_TypeKey key)
result = e_kind_basic_byte_size_table[kind]; result = e_kind_basic_byte_size_table[kind];
}break; }break;
case E_TypeKeyKind_Ext: case E_TypeKeyKind_Ext:
{
U64 type_node_idx = key.u32[1];
U32 rdi_idx = key.u32[2];
RDI_Parsed *rdi = e_type_state->ctx->modules[rdi_idx].rdi;
RDI_TypeNode *rdi_type = rdi_element_from_name_idx(rdi, TypeNodes, type_node_idx);
result = rdi_type->byte_size;
}break;
case E_TypeKeyKind_Cons: case E_TypeKeyKind_Cons:
{ {
Temp scratch = scratch_begin(0, 0); U64 key_hash = e_hash_from_string(5381, str8_struct(&key));
E_Type *type = e_type_from_key(scratch.arena, key); U64 key_slot_idx = key_hash%e_type_state->cons_key_slots_count;
result = type->byte_size; E_ConsTypeSlot *key_slot = &e_type_state->cons_key_slots[key_slot_idx];
scratch_end(scratch); for(E_ConsTypeNode *node = key_slot->first;
node != 0;
node = node->key_next)
{
if(e_type_key_match(node->key, key))
{
result = node->byte_size;
break;
}
}
}break; }break;
} }
ProfEnd();
return result; return result;
} }
+1
View File
@@ -162,6 +162,7 @@ struct E_ConsTypeNode
E_ConsTypeNode *content_next; E_ConsTypeNode *content_next;
E_TypeKey key; E_TypeKey key;
E_ConsTypeParams params; E_ConsTypeParams params;
U64 byte_size;
}; };
typedef struct E_ConsTypeSlot E_ConsTypeSlot; typedef struct E_ConsTypeSlot E_ConsTypeSlot;
+4 -2
View File
@@ -14,7 +14,7 @@ str8_lit_comp("CharLiteral"),
str8_lit_comp("Symbol"), str8_lit_comp("Symbol"),
}; };
String8 e_expr_kind_strings[47] = String8 e_expr_kind_strings[48] =
{ {
str8_lit_comp("Nil"), str8_lit_comp("Nil"),
str8_lit_comp("Ref"), str8_lit_comp("Ref"),
@@ -26,6 +26,7 @@ str8_lit_comp("Cast"),
str8_lit_comp("Sizeof"), str8_lit_comp("Sizeof"),
str8_lit_comp("Typeof"), str8_lit_comp("Typeof"),
str8_lit_comp("ByteSwap"), str8_lit_comp("ByteSwap"),
str8_lit_comp("Pos"),
str8_lit_comp("Neg"), str8_lit_comp("Neg"),
str8_lit_comp("LogNot"), str8_lit_comp("LogNot"),
str8_lit_comp("BitNot"), str8_lit_comp("BitNot"),
@@ -80,7 +81,7 @@ str8_lit_comp("Insufficient evaluation machine stack space."),
str8_lit_comp("Malformed bytecode."), str8_lit_comp("Malformed bytecode."),
}; };
E_OpInfo e_expr_kind_op_info_table[47] = E_OpInfo e_expr_kind_op_info_table[48] =
{ {
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("") }, { E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("") },
{ E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("") }, { E_OpKind_Null, 0, str8_lit_comp(""), str8_lit_comp(""), str8_lit_comp("") },
@@ -92,6 +93,7 @@ E_OpInfo e_expr_kind_op_info_table[47] =
{ E_OpKind_UnaryPrefix, 1, str8_lit_comp("sizeof"), str8_lit_comp("("), str8_lit_comp(")") }, { E_OpKind_UnaryPrefix, 1, str8_lit_comp("sizeof"), str8_lit_comp("("), str8_lit_comp(")") },
{ E_OpKind_UnaryPrefix, 1, str8_lit_comp("typeof"), str8_lit_comp("("), str8_lit_comp(")") }, { E_OpKind_UnaryPrefix, 1, str8_lit_comp("typeof"), str8_lit_comp("("), str8_lit_comp(")") },
{ E_OpKind_UnaryPrefix, 1, str8_lit_comp("bswap"), str8_lit_comp("("), str8_lit_comp(")") }, { E_OpKind_UnaryPrefix, 1, str8_lit_comp("bswap"), str8_lit_comp("("), str8_lit_comp(")") },
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("+"), str8_lit_comp(""), str8_lit_comp("") },
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("-"), str8_lit_comp(""), str8_lit_comp("") }, { E_OpKind_UnaryPrefix, 2, str8_lit_comp("-"), str8_lit_comp(""), str8_lit_comp("") },
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("!"), str8_lit_comp(""), str8_lit_comp("") }, { E_OpKind_UnaryPrefix, 2, str8_lit_comp("!"), str8_lit_comp(""), str8_lit_comp("") },
{ E_OpKind_UnaryPrefix, 2, str8_lit_comp("~"), str8_lit_comp(""), str8_lit_comp("") }, { E_OpKind_UnaryPrefix, 2, str8_lit_comp("~"), str8_lit_comp(""), str8_lit_comp("") },
+3 -2
View File
@@ -101,6 +101,7 @@ E_ExprKind_Cast,
E_ExprKind_Sizeof, E_ExprKind_Sizeof,
E_ExprKind_Typeof, E_ExprKind_Typeof,
E_ExprKind_ByteSwap, E_ExprKind_ByteSwap,
E_ExprKind_Pos,
E_ExprKind_Neg, E_ExprKind_Neg,
E_ExprKind_LogNot, E_ExprKind_LogNot,
E_ExprKind_BitNot, E_ExprKind_BitNot,
@@ -159,9 +160,9 @@ E_InterpretationCode_COUNT,
C_LINKAGE_BEGIN C_LINKAGE_BEGIN
extern String8 e_token_kind_strings[6]; extern String8 e_token_kind_strings[6];
extern String8 e_expr_kind_strings[47]; extern String8 e_expr_kind_strings[48];
extern String8 e_interpretation_code_display_strings[11]; extern String8 e_interpretation_code_display_strings[11];
extern E_OpInfo e_expr_kind_op_info_table[47]; extern E_OpInfo e_expr_kind_op_info_table[48];
extern U8 e_kind_basic_byte_size_table[56]; extern U8 e_kind_basic_byte_size_table[56];
extern String8 e_kind_basic_string_table[56]; extern String8 e_kind_basic_string_table[56];
@@ -104,6 +104,7 @@ EV_ViewRuleTable:
{x Oct oct "oct" x - - - "Display In Octal" x "" "Specifies that all numeric values should be shown in base 8 (octal)." } {x Oct oct "oct" x - - - "Display In Octal" x "" "Specifies that all numeric values should be shown in base 8 (octal)." }
{x Dec dec "dec" x - - - "Display In Decimal" x "" "Specifies that all numeric values should be shown in base 10 (decimal)." } {x Dec dec "dec" x - - - "Display In Decimal" x "" "Specifies that all numeric values should be shown in base 10 (decimal)." }
{x Hex hex "hex" x - - - "Display In Hexadecimal" x "" "Specifies that all numeric values should be shown in base 16 (hexadecimal)." } {x Hex hex "hex" x - - - "Display In Hexadecimal" x "" "Specifies that all numeric values should be shown in base 16 (hexadecimal)." }
{x NoAddress no_addr "no_addr" x - - - "Omit Addresses" x "" "Specifies that addresses should be omitted from visualizations, if possible." }
} }
@enum EV_ViewRuleKind: @enum EV_ViewRuleKind:
@@ -39,6 +39,12 @@ EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_DEF(identity)
//////////////////////////////// ////////////////////////////////
//~ rjf: Key Functions //~ rjf: Key Functions
#if !defined(XXH_IMPLEMENTATION)
# define XXH_IMPLEMENTATION
# define XXH_STATIC_LINKING_ONLY
# include "linker/third_party_ext/xxHash/xxhash.h"
#endif
internal EV_Key internal EV_Key
ev_key_make(U64 parent_hash, U64 child_id) ev_key_make(U64 parent_hash, U64 child_id)
{ {
@@ -74,11 +80,7 @@ ev_key_match(EV_Key a, EV_Key b)
internal U64 internal U64
ev_hash_from_seed_string(U64 seed, String8 string) ev_hash_from_seed_string(U64 seed, String8 string)
{ {
U64 result = seed; U64 result = XXH3_64bits_withSeed(string.str, string.size, seed);
for(U64 i = 0; i < string.size; i += 1)
{
result = ((result << 5) + result) + string.str[i];
}
return result; return result;
} }
@@ -671,6 +673,7 @@ ev_resolved_from_expr(Arena *arena, E_Expr *expr, EV_ViewRuleList *view_rules)
internal EV_BlockTree internal EV_BlockTree
ev_block_tree_from_expr(Arena *arena, EV_View *view, String8 filter, String8 string, E_Expr *expr, EV_ViewRuleList *view_rules) ev_block_tree_from_expr(Arena *arena, EV_View *view, String8 filter, String8 string, E_Expr *expr, EV_ViewRuleList *view_rules)
{ {
ProfBeginFunction();
EV_BlockTree tree = {&ev_nil_block}; EV_BlockTree tree = {&ev_nil_block};
{ {
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
@@ -818,7 +821,7 @@ ev_block_tree_from_expr(Arena *arena, EV_View *view, String8 filter, String8 str
} }
// rjf: gather children expansions from inverse of expansion state // rjf: gather children expansions from inverse of expansion state
if(!child_count && (expand_info.rows_default_expanded || expand_node == 0 && !expand_info.rows_default_expanded)) if(!child_count && (expand_info.rows_default_expanded || (expand_node == 0 && !expand_info.rows_default_expanded)))
{ {
child_count = expand_info.row_count; child_count = expand_info.row_count;
child_keys = push_array(scratch.arena, EV_Key, child_count); child_keys = push_array(scratch.arena, EV_Key, child_count);
@@ -840,46 +843,51 @@ ev_block_tree_from_expr(Arena *arena, EV_View *view, String8 filter, String8 str
{ {
continue; continue;
} }
EV_ExpandRangeInfo child_expand = expand_view_rule_info->expr_expand_range_info(arena, view, filter, t->expr, expand_params, r1u64(split_relative_idx, split_relative_idx+1), expand_info.user_data); if(expand_info.rows_default_expanded || ev_expansion_from_key(view, child_keys[idx]))
if(child_expand.row_exprs_count > 0)
{ {
EV_Key child_key = child_keys[idx]; EV_ExpandRangeInfo child_expand = expand_view_rule_info->expr_expand_range_info(arena, view, filter, t->expr, expand_params, r1u64(split_relative_idx, split_relative_idx+1), expand_info.user_data);
E_Expr *child_expr = child_expand.row_exprs[0]; if(child_expand.row_exprs_count > 0)
EV_ViewRuleList *child_view_rules = ev_view_rule_list_from_inheritance(arena, t->view_rules);
String8 child_view_rule_string = ev_view_rule_from_key(view, child_key);
ev_view_rule_list_push_string(arena, child_view_rules, child_view_rule_string);
if(child_expand.row_strings[0].size != 0)
{ {
EV_ViewRuleList *fastpath_view_rules = ev_view_rule_list_from_expr_fastpaths(arena, child_expand.row_strings[0]); EV_Key child_key = child_keys[idx];
ev_view_rule_list_concat_in_place(child_view_rules, &fastpath_view_rules); E_Expr *child_expr = child_expand.row_exprs[0];
EV_ViewRuleList *child_view_rules = ev_view_rule_list_from_inheritance(arena, t->view_rules);
String8 child_view_rule_string = ev_view_rule_from_key(view, child_key);
ev_view_rule_list_push_string(arena, child_view_rules, child_view_rule_string);
if(child_expand.row_strings[0].size != 0)
{
EV_ViewRuleList *fastpath_view_rules = ev_view_rule_list_from_expr_fastpaths(arena, child_expand.row_strings[0]);
ev_view_rule_list_concat_in_place(child_view_rules, &fastpath_view_rules);
}
{
Temp scratch = scratch_begin(&arena, 1);
E_IRTreeAndType child_irtree = e_irtree_and_type_from_expr(scratch.arena, child_expr);
EV_ViewRuleList *child_auto_view_rules = ev_auto_view_rules_from_type_key(arena, child_irtree.type_key, 1, child_view_rule_string.size == 0);
ev_view_rule_list_concat_in_place(child_view_rules, &child_auto_view_rules);
scratch_end(scratch);
}
E_Expr *child_expr__resolved = ev_resolved_from_expr(arena, child_expr, child_view_rules);
Task *task = push_array(scratch.arena, Task, 1);
SLLQueuePush(first_task, last_task, task);
task->parent_block = expansion_block;
task->expr = child_expr__resolved;
task->child_id = child_key.child_id;
task->view_rules = child_view_rules;
task->split_relative_idx = split_relative_idx;
task->default_expanded = expand_info.rows_default_expanded;
} }
{
Temp scratch = scratch_begin(&arena, 1);
E_IRTreeAndType child_irtree = e_irtree_and_type_from_expr(scratch.arena, child_expr);
EV_ViewRuleList *child_auto_view_rules = ev_auto_view_rules_from_type_key(arena, child_irtree.type_key, 1, child_view_rule_string.size == 0);
ev_view_rule_list_concat_in_place(child_view_rules, &child_auto_view_rules);
scratch_end(scratch);
}
E_Expr *child_expr__resolved = ev_resolved_from_expr(arena, child_expr, child_view_rules);
Task *task = push_array(scratch.arena, Task, 1);
SLLQueuePush(first_task, last_task, task);
task->parent_block = expansion_block;
task->expr = child_expr__resolved;
task->child_id = child_key.child_id;
task->view_rules = child_view_rules;
task->split_relative_idx = split_relative_idx;
task->default_expanded = expand_info.rows_default_expanded;
} }
} }
} }
scratch_end(scratch); scratch_end(scratch);
} }
ProfEnd();
return tree; return tree;
} }
internal EV_BlockTree internal EV_BlockTree
ev_block_tree_from_string(Arena *arena, EV_View *view, String8 filter, String8 string, EV_ViewRuleList *view_rules) ev_block_tree_from_string(Arena *arena, EV_View *view, String8 filter, String8 string, EV_ViewRuleList *view_rules)
{ {
ProfBeginFunction();
EV_BlockTree tree = {0}; EV_BlockTree tree = {0};
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
{ {
@@ -891,6 +899,7 @@ ev_block_tree_from_string(Arena *arena, EV_View *view, String8 filter, String8 s
tree = ev_block_tree_from_expr(arena, view, filter, string, parse.expr, all_view_rules); tree = ev_block_tree_from_expr(arena, view, filter, string, parse.expr, all_view_rules);
} }
scratch_end(scratch); scratch_end(scratch);
ProfEnd();
return tree; return tree;
} }
@@ -1526,12 +1535,15 @@ ev_string_from_simple_typed_eval(Arena *arena, EV_StringFlags flags, U32 radix,
case E_TypeKind_UChar16: case E_TypeKind_UChar16:
case E_TypeKind_UChar32: case E_TypeKind_UChar32:
{ {
B32 type_is_unsigned = (E_TypeKind_UChar8 <= type_kind && type_kind <= E_TypeKind_UChar32);
String8 char_str = ev_string_from_ascii_value(arena, eval.value.s64); String8 char_str = ev_string_from_ascii_value(arena, eval.value.s64);
if(char_str.size != 0) if(char_str.size != 0)
{ {
if(flags & EV_StringFlag_ReadOnlyDisplayRules) if(flags & EV_StringFlag_ReadOnlyDisplayRules)
{ {
String8 imm_string = str8_from_s64(arena, eval.value.s64, radix, min_digits, digit_group_separator); String8 imm_string = (type_is_unsigned
? str8_from_u64(arena, eval.value.u64, radix, min_digits, digit_group_separator)
: str8_from_s64(arena, eval.value.s64, radix, min_digits, digit_group_separator));
result = push_str8f(arena, "'%S' (%S)", char_str, imm_string); result = push_str8f(arena, "'%S' (%S)", char_str, imm_string);
} }
else else
@@ -1541,7 +1553,9 @@ ev_string_from_simple_typed_eval(Arena *arena, EV_StringFlags flags, U32 radix,
} }
else else
{ {
result = str8_from_s64(arena, eval.value.s64, radix, min_digits, digit_group_separator); result = (type_is_unsigned
? str8_from_u64(arena, eval.value.u64, radix, min_digits, digit_group_separator)
: str8_from_s64(arena, eval.value.s64, radix, min_digits, digit_group_separator));
} }
}break; }break;
@@ -1591,15 +1605,16 @@ ev_string_from_simple_typed_eval(Arena *arena, EV_StringFlags flags, U32 radix,
break; break;
} }
} }
String8 numeric_value_string = str8_from_u64(scratch.arena, eval.value.u64, radix, min_digits, digit_group_separator);
if(flags & EV_StringFlag_ReadOnlyDisplayRules) if(flags & EV_StringFlag_ReadOnlyDisplayRules)
{ {
if(constant_name.size != 0) if(constant_name.size != 0)
{ {
result = push_str8f(arena, "0x%I64x (%S)", eval.value.u64, constant_name); result = push_str8f(arena, "%S (%S)", numeric_value_string, constant_name);
} }
else else
{ {
result = push_str8f(arena, "0x%I64x (%I64u)", eval.value.u64, eval.value.u64); result = push_str8_copy(arena, numeric_value_string);
} }
} }
else if(constant_name.size != 0) else if(constant_name.size != 0)
@@ -1608,7 +1623,7 @@ ev_string_from_simple_typed_eval(Arena *arena, EV_StringFlags flags, U32 radix,
} }
else else
{ {
result = push_str8f(arena, "0x%I64x (%I64u)", eval.value.u64, eval.value.u64); result = push_str8_copy(arena, numeric_value_string);
} }
scratch_end(scratch); scratch_end(scratch);
}break; }break;
@@ -4,7 +4,7 @@
//- GENERATED CODE //- GENERATED CODE
C_LINKAGE_BEGIN C_LINKAGE_BEGIN
EV_ViewRuleInfo ev_builtin_view_rule_info_table[13] = EV_ViewRuleInfo ev_builtin_view_rule_info_table[14] =
{ {
{str8_lit_comp("default"), (EV_ViewRuleInfoFlag_Inherited*0)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_INFO_FUNCTION_NAME(default) , EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_NAME(default) , EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity) }, {str8_lit_comp("default"), (EV_ViewRuleInfoFlag_Inherited*0)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_INFO_FUNCTION_NAME(default) , EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_NAME(default) , EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity) },
{str8_lit_comp("array"), (EV_ViewRuleInfoFlag_Inherited*0)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(array) , EV_VIEW_RULE_EXPR_EXPAND_INFO_FUNCTION_NAME(nil), EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_NAME(nil), EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity) }, {str8_lit_comp("array"), (EV_ViewRuleInfoFlag_Inherited*0)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(array) , EV_VIEW_RULE_EXPR_EXPAND_INFO_FUNCTION_NAME(nil), EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_NAME(nil), EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity) },
@@ -19,6 +19,7 @@ EV_ViewRuleInfo ev_builtin_view_rule_info_table[13] =
{str8_lit_comp("oct"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_INFO_FUNCTION_NAME(nil), EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_NAME(nil), EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity) }, {str8_lit_comp("oct"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_INFO_FUNCTION_NAME(nil), EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_NAME(nil), EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity) },
{str8_lit_comp("dec"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_INFO_FUNCTION_NAME(nil), EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_NAME(nil), EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity) }, {str8_lit_comp("dec"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_INFO_FUNCTION_NAME(nil), EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_NAME(nil), EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity) },
{str8_lit_comp("hex"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_INFO_FUNCTION_NAME(nil), EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_NAME(nil), EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity) }, {str8_lit_comp("hex"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_INFO_FUNCTION_NAME(nil), EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_NAME(nil), EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity) },
{str8_lit_comp("no_addr"), (EV_ViewRuleInfoFlag_Inherited*1)|(EV_ViewRuleInfoFlag_Expandable*0), EV_VIEW_RULE_EXPR_RESOLUTION_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_INFO_FUNCTION_NAME(nil), EV_VIEW_RULE_EXPR_EXPAND_RANGE_INFO_FUNCTION_NAME(nil), EV_VIEW_RULE_EXPR_EXPAND_ID_FROM_NUM_FUNCTION_NAME(identity), EV_VIEW_RULE_EXPR_EXPAND_NUM_FROM_ID_FUNCTION_NAME(identity) },
}; };
C_LINKAGE_END C_LINKAGE_END
@@ -21,6 +21,7 @@ EV_ViewRuleKind_Bin,
EV_ViewRuleKind_Oct, EV_ViewRuleKind_Oct,
EV_ViewRuleKind_Dec, EV_ViewRuleKind_Dec,
EV_ViewRuleKind_Hex, EV_ViewRuleKind_Hex,
EV_ViewRuleKind_NoAddress,
EV_ViewRuleKind_COUNT, EV_ViewRuleKind_COUNT,
} EV_ViewRuleKind; } EV_ViewRuleKind;
+114 -140
View File
@@ -53,12 +53,6 @@ fs_init(void)
fs_shared->u2s_ring_base = push_array_no_zero(arena, U8, fs_shared->u2s_ring_size); fs_shared->u2s_ring_base = push_array_no_zero(arena, U8, fs_shared->u2s_ring_size);
fs_shared->u2s_ring_cv = os_condition_variable_alloc(); fs_shared->u2s_ring_cv = os_condition_variable_alloc();
fs_shared->u2s_ring_mutex = os_mutex_alloc(); fs_shared->u2s_ring_mutex = os_mutex_alloc();
fs_shared->streamer_count = Clamp(1, os_get_system_info()->logical_processor_count-1, 4);
fs_shared->streamers = push_array(arena, OS_Handle, 1);
for(U64 idx = 0; idx < fs_shared->streamer_count; idx += 1)
{
fs_shared->streamers[idx] = os_thread_launch(fs_streamer_thread__entry_point, (void *)idx, 0);
}
fs_shared->detector_thread = os_thread_launch(fs_detector_thread__entry_point, 0, 0); fs_shared->detector_thread = os_thread_launch(fs_detector_thread__entry_point, 0, 0);
} }
@@ -106,7 +100,7 @@ fs_hash_from_path_range(String8 path, Rng1U64 range, U64 endt_us)
FS_Stripe *path_stripe = &fs_shared->stripes[path_stripe_idx]; FS_Stripe *path_stripe = &fs_shared->stripes[path_stripe_idx];
// rjf: loop: request, check for results, return until we can't // rjf: loop: request, check for results, return until we can't
OS_MutexScopeR(path_stripe->rw_mutex) for(;;) OS_MutexScopeW(path_stripe->rw_mutex) for(;;)
{ {
// rjf: path -> node // rjf: path -> node
FS_Node *node = 0; FS_Node *node = 0;
@@ -119,25 +113,14 @@ fs_hash_from_path_range(String8 path, Rng1U64 range, U64 endt_us)
} }
} }
// rjf: node does not exist? -> create & store (we must re-search after promoting r -> w) // rjf: node does not exist? -> create & store
if(node == 0) OS_MutexScopeRWPromote(path_stripe->rw_mutex) if(node == 0)
{ {
for(FS_Node *n = path_slot->first; n != 0; n = n->next) node = push_array(path_stripe->arena, FS_Node, 1);
{ SLLQueuePush(path_slot->first, path_slot->last, node);
if(str8_match(path, n->path, 0)) node->path = push_str8_copy(path_stripe->arena, path);
{ node->slots_count = 64;
node = n; node->slots = push_array(path_stripe->arena, FS_RangeSlot, node->slots_count);
break;
}
}
if(node == 0)
{
node = push_array(path_stripe->arena, FS_Node, 1);
SLLQueuePush(path_slot->first, path_slot->last, node);
node->path = push_str8_copy(path_stripe->arena, path);
node->slots_count = 64;
node->slots = push_array(path_stripe->arena, FS_RangeSlot, node->slots_count);
}
} }
// rjf: range -> node // rjf: range -> node
@@ -154,30 +137,25 @@ fs_hash_from_path_range(String8 path, Rng1U64 range, U64 endt_us)
} }
} }
// rjf: range node does not exist? create & store (we must re-search after promoting r -> w) // rjf: range node does not exist? create & store
if(range_node == 0) OS_MutexScopeRWPromote(path_stripe->rw_mutex) if(range_node == 0)
{ {
for(FS_RangeNode *n = range_slot->first; n != 0; n = n->next) range_node = push_array(path_stripe->arena, FS_RangeNode, 1);
{ SLLQueuePush(range_slot->first, range_slot->last, range_node);
if(MemoryMatchStruct(&n->range, &range)) range_node->range = range;
{
range_node = n;
break;
}
}
if(range_node == 0)
{
range_node = push_array(path_stripe->arena, FS_RangeNode, 1);
SLLQueuePush(range_slot->first, range_slot->last, range_node);
range_node->range = range;
}
} }
// rjf: try to send stream request // rjf: try to send stream request
if(!ins_atomic_u32_eval_cond_assign(&range_node->is_working, 1, 0) && if((ins_atomic_u64_eval(&range_node->request_count) == ins_atomic_u64_eval(&range_node->completion_count) ||
!fs_u2s_enqueue_req(range, path, endt_us)) ins_atomic_u64_eval(&range_node->last_time_requested_us)+100000 < os_now_microseconds()) &&
fs_u2s_enqueue_req(range, path, endt_us))
{ {
ins_atomic_u32_eval_assign(&range_node->is_working, 0); ins_atomic_u64_eval_assign(&range_node->last_time_requested_us, os_now_microseconds());
ins_atomic_u64_inc_eval(&range_node->request_count);
DeferLoop(os_rw_mutex_drop_w(path_stripe->rw_mutex), os_rw_mutex_take_w(path_stripe->rw_mutex))
{
async_push_work(fs_stream_work, .completion_counter = &range_node->completion_count);
}
} }
// rjf: try to reobtain results // rjf: try to reobtain results
@@ -186,7 +164,7 @@ fs_hash_from_path_range(String8 path, Rng1U64 range, U64 endt_us)
// rjf: have time to wait? -> wait on this stripe; otherwise exit // rjf: have time to wait? -> wait on this stripe; otherwise exit
if(u128_match(result, u128_zero()) && os_now_microseconds() <= endt_us) if(u128_match(result, u128_zero()) && os_now_microseconds() <= endt_us)
{ {
os_condition_variable_wait_rw_r(path_stripe->cv, path_stripe->rw_mutex, endt_us); os_condition_variable_wait_rw_w(path_stripe->cv, path_stripe->rw_mutex, endt_us);
} }
else else
{ {
@@ -275,15 +253,14 @@ fs_u2s_enqueue_req(Rng1U64 range, String8 path, U64 endt_us)
{ {
U64 unconsumed_size = fs_shared->u2s_ring_write_pos - fs_shared->u2s_ring_read_pos; U64 unconsumed_size = fs_shared->u2s_ring_write_pos - fs_shared->u2s_ring_read_pos;
U64 available_size = fs_shared->u2s_ring_size - unconsumed_size; U64 available_size = fs_shared->u2s_ring_size - unconsumed_size;
if(available_size >= sizeof(U64) + path.size) U64 needed_size = sizeof(range.min) + sizeof(range.max) + sizeof(path.size) + path.size;
if(available_size >= needed_size)
{ {
result = 1; result = 1;
fs_shared->u2s_ring_write_pos += ring_write_struct(fs_shared->u2s_ring_base, fs_shared->u2s_ring_size, fs_shared->u2s_ring_write_pos, &range.min); fs_shared->u2s_ring_write_pos += ring_write_struct(fs_shared->u2s_ring_base, fs_shared->u2s_ring_size, fs_shared->u2s_ring_write_pos, &range.min);
fs_shared->u2s_ring_write_pos += ring_write_struct(fs_shared->u2s_ring_base, fs_shared->u2s_ring_size, fs_shared->u2s_ring_write_pos, &range.max); fs_shared->u2s_ring_write_pos += ring_write_struct(fs_shared->u2s_ring_base, fs_shared->u2s_ring_size, fs_shared->u2s_ring_write_pos, &range.max);
fs_shared->u2s_ring_write_pos += ring_write_struct(fs_shared->u2s_ring_base, fs_shared->u2s_ring_size, fs_shared->u2s_ring_write_pos, &path.size); fs_shared->u2s_ring_write_pos += ring_write_struct(fs_shared->u2s_ring_base, fs_shared->u2s_ring_size, fs_shared->u2s_ring_write_pos, &path.size);
fs_shared->u2s_ring_write_pos += ring_write(fs_shared->u2s_ring_base, fs_shared->u2s_ring_size, fs_shared->u2s_ring_write_pos, path.str, path.size); fs_shared->u2s_ring_write_pos += ring_write(fs_shared->u2s_ring_base, fs_shared->u2s_ring_size, fs_shared->u2s_ring_write_pos, path.str, path.size);
fs_shared->u2s_ring_write_pos += 7;
fs_shared->u2s_ring_write_pos -= fs_shared->u2s_ring_write_pos%8;
break; break;
} }
os_condition_variable_wait(fs_shared->u2s_ring_cv, fs_shared->u2s_ring_mutex, endt_us); os_condition_variable_wait(fs_shared->u2s_ring_cv, fs_shared->u2s_ring_mutex, endt_us);
@@ -308,8 +285,6 @@ fs_u2s_dequeue_req(Arena *arena, Rng1U64 *range_out, String8 *path_out)
fs_shared->u2s_ring_read_pos += ring_read_struct(fs_shared->u2s_ring_base, fs_shared->u2s_ring_size, fs_shared->u2s_ring_read_pos, &path_out->size); fs_shared->u2s_ring_read_pos += ring_read_struct(fs_shared->u2s_ring_base, fs_shared->u2s_ring_size, fs_shared->u2s_ring_read_pos, &path_out->size);
path_out->str = push_array(arena, U8, path_out->size); path_out->str = push_array(arena, U8, path_out->size);
fs_shared->u2s_ring_read_pos += ring_read(fs_shared->u2s_ring_base, fs_shared->u2s_ring_size, fs_shared->u2s_ring_read_pos, path_out->str, path_out->size); fs_shared->u2s_ring_read_pos += ring_read(fs_shared->u2s_ring_base, fs_shared->u2s_ring_size, fs_shared->u2s_ring_read_pos, path_out->str, path_out->size);
fs_shared->u2s_ring_read_pos += 7;
fs_shared->u2s_ring_read_pos -= fs_shared->u2s_ring_read_pos%8;
break; break;
} }
os_condition_variable_wait(fs_shared->u2s_ring_cv, fs_shared->u2s_ring_mutex, max_U64); os_condition_variable_wait(fs_shared->u2s_ring_cv, fs_shared->u2s_ring_mutex, max_U64);
@@ -317,108 +292,105 @@ fs_u2s_dequeue_req(Arena *arena, Rng1U64 *range_out, String8 *path_out)
os_condition_variable_broadcast(fs_shared->u2s_ring_cv); os_condition_variable_broadcast(fs_shared->u2s_ring_cv);
} }
internal void ASYNC_WORK_DEF(fs_stream_work)
fs_streamer_thread__entry_point(void *p)
{ {
ThreadNameF("[fs] streamer #%I64u", (U64)p); ProfBeginFunction();
for(;;) Temp scratch = scratch_begin(0, 0);
//- rjf: get next request
Rng1U64 range = {0};
String8 path = {0};
fs_u2s_dequeue_req(scratch.arena, &range, &path);
//- rjf: unpack request
U128 key = fs_big_hash_from_string_range(path, range);
U64 path_hash = fs_little_hash_from_string(path);
U64 path_slot_idx = path_hash%fs_shared->slots_count;
U64 path_stripe_idx = path_slot_idx%fs_shared->stripes_count;
FS_Slot *path_slot = &fs_shared->slots[path_slot_idx];
FS_Stripe *path_stripe = &fs_shared->stripes[path_stripe_idx];
//- rjf: load
ProfBegin("load \"%.*s\"", str8_varg(path));
FileProperties pre_props = os_properties_from_file_path(path);
U64 range_size = dim_1u64(range);
U64 read_size = Min(pre_props.size, range_size);
OS_Handle file = os_file_open(OS_AccessFlag_Read|OS_AccessFlag_ShareRead|OS_AccessFlag_ShareWrite, path);
U64 data_arena_size = read_size+ARENA_HEADER_SIZE;
data_arena_size += KB(4)-1;
data_arena_size -= data_arena_size%KB(4);
ProfBegin("allocate");
Arena *data_arena = arena_alloc(.reserve_size = data_arena_size, .commit_size = data_arena_size);
ProfEnd();
ProfBegin("read");
String8 data = os_string_from_file_range(data_arena, file, r1u64(range.min, range.min+read_size));
ProfEnd();
os_file_close(file);
FileProperties post_props = os_properties_from_file_path(path);
//- rjf: abort if modification timestamps differ - we did not successfully read the file
if(pre_props.modified != post_props.modified)
{ {
Temp scratch = scratch_begin(0, 0); ProfScope("abort")
//- rjf: get next request
Rng1U64 range = {0};
String8 path = {0};
fs_u2s_dequeue_req(scratch.arena, &range, &path);
//- rjf: unpack request
U128 key = fs_big_hash_from_string_range(path, range);
U64 path_hash = fs_little_hash_from_string(path);
U64 path_slot_idx = path_hash%fs_shared->slots_count;
U64 path_stripe_idx = path_slot_idx%fs_shared->stripes_count;
FS_Slot *path_slot = &fs_shared->slots[path_slot_idx];
FS_Stripe *path_stripe = &fs_shared->stripes[path_stripe_idx];
//- rjf: load
ProfBegin("load \"%.*s\"", str8_varg(path));
FileProperties pre_props = os_properties_from_file_path(path);
U64 range_size = dim_1u64(range);
U64 read_size = Min(pre_props.size, range_size);
OS_Handle file = os_file_open(OS_AccessFlag_Read|OS_AccessFlag_ShareRead|OS_AccessFlag_ShareWrite, path);
U64 data_arena_size = read_size+ARENA_HEADER_SIZE;
data_arena_size += KB(4)-1;
data_arena_size -= data_arena_size%KB(4);
ProfBegin("allocate");
Arena *data_arena = arena_alloc(.reserve_size = data_arena_size, .commit_size = data_arena_size);
ProfEnd();
ProfBegin("read");
String8 data = os_string_from_file_range(data_arena, file, r1u64(range.min, range.min+read_size));
ProfEnd();
os_file_close(file);
FileProperties post_props = os_properties_from_file_path(path);
//- rjf: abort if modification timestamps differ - we did not successfully read the file
if(pre_props.modified != post_props.modified)
{ {
ProfScope("abort") arena_release(data_arena);
MemoryZeroStruct(&data);
data_arena = 0;
}
}
//- rjf: submit
else
{
ProfScope("submit")
{
hs_submit_data(key, &data_arena, data);
}
}
//- rjf: commit info to cache
ProfScope("commit to cache") OS_MutexScopeW(path_stripe->rw_mutex)
{
FS_Node *node = 0;
for(FS_Node *n = path_slot->first; n != 0; n = n->next)
{
if(str8_match(n->path, path, 0))
{ {
arena_release(data_arena); node = n;
MemoryZeroStruct(&data); break;
data_arena = 0;
} }
} }
if(node != 0)
//- rjf: submit
else
{ {
ProfScope("submit") if(node->timestamp != 0)
{ {
hs_submit_data(key, &data_arena, data); ins_atomic_u64_inc_eval(&fs_shared->change_gen);
} }
} if(post_props.modified == pre_props.modified)
//- rjf: commit info to cache
ProfScope("commit to cache") OS_MutexScopeW(path_stripe->rw_mutex)
{
FS_Node *node = 0;
for(FS_Node *n = path_slot->first; n != 0; n = n->next)
{ {
if(str8_match(n->path, path, 0)) node->timestamp = post_props.modified;
node->size = post_props.size;
}
U64 range_hash = fs_little_hash_from_string(str8_struct(&range));
U64 range_slot_idx = range_hash%node->slots_count;
FS_RangeSlot *range_slot = &node->slots[range_slot_idx];
FS_RangeNode *range_node = 0;
for(FS_RangeNode *n = range_slot->first; n != 0; n = n->next)
{
if(MemoryMatchStruct(&n->range, &range))
{ {
node = n; range_node = n;
break; break;
} }
} }
if(node != 0)
{
if(node->timestamp != 0)
{
ins_atomic_u64_inc_eval(&fs_shared->change_gen);
}
if(post_props.modified == pre_props.modified)
{
node->timestamp = post_props.modified;
node->size = post_props.size;
}
U64 range_hash = fs_little_hash_from_string(str8_struct(&range));
U64 range_slot_idx = range_hash%node->slots_count;
FS_RangeSlot *range_slot = &node->slots[range_slot_idx];
FS_RangeNode *range_node = 0;
for(FS_RangeNode *n = range_slot->first; n != 0; n = n->next)
{
if(MemoryMatchStruct(&n->range, &range))
{
range_node = n;
break;
}
}
ins_atomic_u32_eval_assign(&range_node->is_working, 0);
}
} }
os_condition_variable_broadcast(path_stripe->cv);
ProfEnd();
scratch_end(scratch);
} }
os_condition_variable_broadcast(path_stripe->cv);
ProfEnd();
scratch_end(scratch);
ProfEnd();
return 0;
} }
//////////////////////////////// ////////////////////////////////
@@ -427,7 +399,7 @@ fs_streamer_thread__entry_point(void *p)
internal void internal void
fs_detector_thread__entry_point(void *p) fs_detector_thread__entry_point(void *p)
{ {
ThreadNameF("[fs] detector"); ThreadNameF("[fs] detector thread");
for(;;) for(;;)
{ {
U64 slots_per_stripe = fs_shared->slots_count/fs_shared->stripes_count; U64 slots_per_stripe = fs_shared->slots_count/fs_shared->stripes_count;
@@ -449,10 +421,12 @@ fs_detector_thread__entry_point(void *p)
range_n != 0; range_n != 0;
range_n = range_n->next) range_n = range_n->next)
{ {
if(!ins_atomic_u32_eval_cond_assign(&range_n->is_working, 1, 0) && if(ins_atomic_u64_eval(&range_n->request_count) == ins_atomic_u64_eval(&range_n->completion_count) &&
!fs_u2s_enqueue_req(range_n->range, n->path, os_now_microseconds()+100000)) fs_u2s_enqueue_req(range_n->range, n->path, os_now_microseconds()+100000))
{ {
ins_atomic_u32_eval_assign(&range_n->is_working, 0); ins_atomic_u64_eval_assign(&range_n->last_time_requested_us, os_now_microseconds());
ins_atomic_u64_inc_eval(&range_n->request_count);
async_push_work(fs_stream_work, .completion_counter = &range_n->completion_count);
} }
} }
} }
+5 -8
View File
@@ -12,7 +12,9 @@ struct FS_RangeNode
{ {
FS_RangeNode *next; FS_RangeNode *next;
Rng1U64 range; Rng1U64 range;
B32 is_working; U64 request_count;
U64 completion_count;
U64 last_time_requested_us;
}; };
typedef struct FS_RangeSlot FS_RangeSlot; typedef struct FS_RangeSlot FS_RangeSlot;
@@ -75,10 +77,6 @@ struct FS_Shared
OS_Handle u2s_ring_cv; OS_Handle u2s_ring_cv;
OS_Handle u2s_ring_mutex; OS_Handle u2s_ring_mutex;
// rjf: streamer threads
U64 streamer_count;
OS_Handle *streamers;
// rjf: change detector threads // rjf: change detector threads
OS_Handle detector_thread; OS_Handle detector_thread;
}; };
@@ -114,12 +112,11 @@ internal U64 fs_timestamp_from_path(String8 path);
internal U64 fs_size_from_path(String8 path); internal U64 fs_size_from_path(String8 path);
//////////////////////////////// ////////////////////////////////
//~ rjf: Streamer Threads //~ rjf: Streaming Work
internal B32 fs_u2s_enqueue_req(Rng1U64 range, String8 path, U64 endt_us); internal B32 fs_u2s_enqueue_req(Rng1U64 range, String8 path, U64 endt_us);
internal void fs_u2s_dequeue_req(Arena *arena, Rng1U64 *range_out, String8 *path_out); internal void fs_u2s_dequeue_req(Arena *arena, Rng1U64 *range_out, String8 *path_out);
ASYNC_WORK_DEF(fs_stream_work);
internal void fs_streamer_thread__entry_point(void *p);
//////////////////////////////// ////////////////////////////////
//~ rjf: Change Detector Thread //~ rjf: Change Detector Thread
+1066 -1063
View File
File diff suppressed because it is too large Load Diff
-547
View File
@@ -1,547 +0,0 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: Helpers
internal U64
fzy_hash_from_string(U64 seed, String8 string)
{
U64 result = seed;
for(U64 i = 0; i < string.size; i += 1)
{
result = ((result << 5) + result) + string.str[i];
}
return result;
}
internal U64
fzy_hash_from_params(FZY_Params *params)
{
U64 hash = 5381;
hash = fzy_hash_from_string(hash, str8_struct(&params->target));
for(U64 idx = 0; idx < params->dbgi_keys.count; idx += 1)
{
hash = fzy_hash_from_string(hash, str8_struct(&params->dbgi_keys.v[idx].min_timestamp));
hash = fzy_hash_from_string(hash, params->dbgi_keys.v[idx].path);
}
return hash;
}
internal U64
fzy_item_num_from_array_element_idx__linear_search(FZY_ItemArray *array, U64 element_idx)
{
U64 fuzzy_item_num = 0;
for(U64 idx = 0; idx < array->count; idx += 1)
{
if(array->v[idx].idx == element_idx)
{
fuzzy_item_num = idx+1;
break;
}
}
return fuzzy_item_num;
}
internal String8
fzy_item_string_from_rdi_target_element_idx(RDI_Parsed *rdi, RDI_SectionKind target, U64 element_idx)
{
String8 result = {0};
switch(target)
{
default:{}break;
case RDI_SectionKind_Procedures:
{
RDI_Procedure *proc = rdi_element_from_name_idx(rdi, Procedures, element_idx);
U64 name_size = 0;
U8 *name_base = rdi_string_from_idx(rdi, proc->name_string_idx, &name_size);
result = str8(name_base, name_size);
}break;
case RDI_SectionKind_GlobalVariables:
{
RDI_GlobalVariable *gvar = rdi_element_from_name_idx(rdi, GlobalVariables, element_idx);
U64 name_size = 0;
U8 *name_base = rdi_string_from_idx(rdi, gvar->name_string_idx, &name_size);
result = str8(name_base, name_size);
}break;
case RDI_SectionKind_ThreadVariables:
{
RDI_ThreadVariable *tvar = rdi_element_from_name_idx(rdi, ThreadVariables, element_idx);
U64 name_size = 0;
U8 *name_base = rdi_string_from_idx(rdi, tvar->name_string_idx, &name_size);
result = str8(name_base, name_size);
}break;
case RDI_SectionKind_UDTs:
{
RDI_UDT *udt = rdi_element_from_name_idx(rdi, UDTs, element_idx);
RDI_TypeNode *type_node = rdi_element_from_name_idx(rdi, TypeNodes, udt->self_type_idx);
U64 name_size = 0;
U8 *name_base = rdi_string_from_idx(rdi, type_node->user_defined.name_string_idx, &name_size);
result = str8(name_base, name_size);
}break;
}
return result;
}
internal FZY_Params
fzy_params_copy(Arena *arena, FZY_Params *src)
{
FZY_Params dst = zero_struct;
MemoryCopyStruct(&dst, src);
dst.dbgi_keys.v = push_array(arena, DI_Key, dst.dbgi_keys.count);
MemoryCopy(dst.dbgi_keys.v, src->dbgi_keys.v, sizeof(DI_Key)*src->dbgi_keys.count);
for(U64 idx = 0; idx < dst.dbgi_keys.count; idx += 1)
{
dst.dbgi_keys.v[idx].path = push_str8_copy(arena, dst.dbgi_keys.v[idx].path);
}
return dst;
}
////////////////////////////////
//~ rjf: Main Layer Initialization
internal void
fzy_init(void)
{
Arena *arena = arena_alloc();
fzy_shared = push_array(arena, FZY_Shared, 1);
fzy_shared->arena = arena;
fzy_shared->slots_count = 256;
fzy_shared->stripes_count = os_get_system_info()->logical_processor_count;
fzy_shared->slots = push_array(arena, FZY_Slot, fzy_shared->slots_count);
fzy_shared->stripes = push_array(arena, FZY_Stripe, fzy_shared->stripes_count);
for(U64 idx = 0; idx < fzy_shared->stripes_count; idx += 1)
{
fzy_shared->stripes[idx].arena = arena_alloc();
fzy_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
fzy_shared->stripes[idx].cv = os_condition_variable_alloc();
}
fzy_shared->thread_count = Min(os_get_system_info()->logical_processor_count, 2);
fzy_shared->threads = push_array(arena, FZY_Thread, fzy_shared->thread_count);
for(U64 idx = 0; idx < fzy_shared->thread_count; idx += 1)
{
fzy_shared->threads[idx].u2f_ring_mutex = os_mutex_alloc();
fzy_shared->threads[idx].u2f_ring_cv = os_condition_variable_alloc();
fzy_shared->threads[idx].u2f_ring_size = KB(64);
fzy_shared->threads[idx].u2f_ring_base = push_array_no_zero(arena, U8, fzy_shared->threads[idx].u2f_ring_size);
fzy_shared->threads[idx].thread = os_thread_launch(fzy_search_thread__entry_point, (void *)idx, 0);
}
}
////////////////////////////////
//~ rjf: Scope Functions
internal FZY_Scope *
fzy_scope_open(void)
{
if(fzy_tctx == 0)
{
Arena *arena = arena_alloc();
fzy_tctx = push_array(arena, FZY_TCTX, 1);
fzy_tctx->arena = arena;
}
FZY_Scope *scope = fzy_tctx->free_scope;
if(scope != 0)
{
SLLStackPop(fzy_tctx->free_scope);
}
else
{
scope = push_array_no_zero(fzy_tctx->arena, FZY_Scope, 1);
}
MemoryZeroStruct(scope);
return scope;
}
internal void
fzy_scope_close(FZY_Scope *scope)
{
for(FZY_Touch *t = scope->first_touch, *next = 0; t != 0; t = next)
{
next = t->next;
SLLStackPush(fzy_tctx->free_touch, t);
if(t->node != 0)
{
ins_atomic_u64_dec_eval(&t->node->touch_count);
}
}
SLLStackPush(fzy_tctx->free_scope, scope);
}
internal void
fzy_scope_touch_node__stripe_mutex_r_guarded(FZY_Scope *scope, FZY_Node *node)
{
if(node != 0)
{
ins_atomic_u64_inc_eval(&node->touch_count);
}
FZY_Touch *touch = fzy_tctx->free_touch;
if(touch != 0)
{
SLLStackPop(fzy_tctx->free_touch);
}
else
{
touch = push_array_no_zero(fzy_tctx->arena, FZY_Touch, 1);
}
MemoryZeroStruct(touch);
SLLQueuePush(scope->first_touch, scope->last_touch, touch);
touch->node = node;
}
////////////////////////////////
//~ rjf: Cache Lookup Functions
internal FZY_ItemArray
fzy_items_from_key_params_query(FZY_Scope *scope, U128 key, FZY_Params *params, String8 query, U64 endt_us, B32 *stale_out)
{
Temp scratch = scratch_begin(0, 0);
FZY_ItemArray items = {0};
//- rjf: hash parameters
U64 params_hash = fzy_hash_from_params(params);
//- rjf: unpack key
U64 slot_idx = key.u64[1]%fzy_shared->slots_count;
U64 stripe_idx = slot_idx%fzy_shared->stripes_count;
FZY_Slot *slot = &fzy_shared->slots[slot_idx];
FZY_Stripe *stripe = &fzy_shared->stripes[stripe_idx];
//- rjf: query and/or request
OS_MutexScopeR(stripe->rw_mutex) for(;;)
{
// rjf: map key -> node
FZY_Node *node = 0;
for(FZY_Node *n = slot->first; n != 0; n = n->next)
{
if(u128_match(n->key, key))
{
node = n;
break;
}
}
// rjf: no node? -> allocate
if(node == 0) OS_MutexScopeRWPromote(stripe->rw_mutex)
{
node = push_array(stripe->arena, FZY_Node, 1);
SLLQueuePush(slot->first, slot->last, node);
node->key = key;
for(U64 idx = 0; idx < ArrayCount(node->buckets); idx += 1)
{
node->buckets[idx].arena = arena_alloc();
}
}
// rjf: try to grab last valid results for this key/query; determine if stale
B32 stale = 1;
if(params_hash == node->buckets[node->gen%ArrayCount(node->buckets)].params_hash &&
node->gen != 0)
{
fzy_scope_touch_node__stripe_mutex_r_guarded(scope, node);
items = node->gen_items;
stale = !str8_match(query, node->buckets[node->gen%ArrayCount(node->buckets)].query, 0);
if(stale_out != 0)
{
*stale_out = stale;
}
}
// rjf: if stale -> request again
if(stale) OS_MutexScopeRWPromote(stripe->rw_mutex)
{
if(node->gen <= node->submit_gen && node->submit_gen < node->gen + ArrayCount(node->buckets)-1)
{
node->submit_gen += 1;
arena_clear(node->buckets[node->submit_gen%ArrayCount(node->buckets)].arena);
node->buckets[node->submit_gen%ArrayCount(node->buckets)].query = push_str8_copy(node->buckets[node->submit_gen%ArrayCount(node->buckets)].arena, query);
node->buckets[node->submit_gen%ArrayCount(node->buckets)].params = fzy_params_copy(node->buckets[node->submit_gen%ArrayCount(node->buckets)].arena, params);
node->buckets[node->submit_gen%ArrayCount(node->buckets)].params_hash = params_hash;
}
if((node->submit_gen > node->gen+1 || os_now_microseconds() >= node->last_time_submitted_us+100000) &&
fzy_u2s_enqueue_req(key, endt_us))
{
node->last_time_submitted_us = os_now_microseconds();
}
}
// rjf: not stale, or timeout -> break
if(!stale || os_now_microseconds() >= endt_us)
{
break;
}
// rjf: no results, but have time to wait -> wait
os_condition_variable_wait_rw_r(stripe->cv, stripe->rw_mutex, endt_us);
}
scratch_end(scratch);
return items;
}
////////////////////////////////
//~ rjf: Searcher Threads
internal B32
fzy_u2s_enqueue_req(U128 key, U64 endt_us)
{
B32 sent = 0;
FZY_Thread *thread = &fzy_shared->threads[key.u64[1]%fzy_shared->thread_count];
OS_MutexScope(thread->u2f_ring_mutex) for(;;)
{
U64 unconsumed_size = thread->u2f_ring_write_pos - thread->u2f_ring_read_pos;
U64 available_size = thread->u2f_ring_size - unconsumed_size;
if(available_size >= sizeof(U128))
{
sent = 1;
thread->u2f_ring_write_pos += ring_write_struct(thread->u2f_ring_base, thread->u2f_ring_size, thread->u2f_ring_write_pos, &key);
break;
}
os_condition_variable_wait(thread->u2f_ring_cv, thread->u2f_ring_mutex, endt_us);
}
if(sent)
{
os_condition_variable_broadcast(thread->u2f_ring_cv);
}
return sent;
}
internal void
fzy_u2s_dequeue_req(Arena *arena, FZY_Thread *thread, U128 *key_out)
{
OS_MutexScope(thread->u2f_ring_mutex) for(;;)
{
U64 unconsumed_size = thread->u2f_ring_write_pos - thread->u2f_ring_read_pos;
if(unconsumed_size >= sizeof(U128))
{
thread->u2f_ring_read_pos += ring_read_struct(thread->u2f_ring_base, thread->u2f_ring_size, thread->u2f_ring_read_pos, key_out);
break;
}
os_condition_variable_wait(thread->u2f_ring_cv, thread->u2f_ring_mutex, max_U64);
}
os_condition_variable_broadcast(thread->u2f_ring_cv);
}
internal int
fzy_qsort_compare_items(FZY_Item *a, FZY_Item *b)
{
int result = 0;
if(a->match_ranges.count > b->match_ranges.count)
{
result = -1;
}
else if(a->match_ranges.count < b->match_ranges.count)
{
result = +1;
}
else if(a->missed_size < b->missed_size)
{
result = -1;
}
else if(a->missed_size > b->missed_size)
{
result = +1;
}
return result;
}
internal void
fzy_search_thread__entry_point(void *p)
{
ThreadNameF("[fzy] searcher #%I64u", (U64)p);
FZY_Thread *thread = &fzy_shared->threads[(U64)p];
for(;;)
{
Temp scratch = scratch_begin(0, 0);
DI_Scope *di_scope = di_scope_open();
////////////////////////////
//- rjf: dequeue next request
//
U128 key = {0};
fzy_u2s_dequeue_req(scratch.arena, thread, &key);
U64 slot_idx = key.u64[1]%fzy_shared->slots_count;
U64 stripe_idx = slot_idx%fzy_shared->stripes_count;
FZY_Slot *slot = &fzy_shared->slots[slot_idx];
FZY_Stripe *stripe = &fzy_shared->stripes[stripe_idx];
////////////////////////////
//- rjf: grab next exe_path/query for this key
//
B32 task_is_good = 0;
Arena *task_arena = 0;
String8 query = {0};
FZY_Params params = {RDI_SectionKind_Procedures};
U64 initial_submit_gen = 0;
OS_MutexScopeW(stripe->rw_mutex)
{
for(FZY_Node *n = slot->first; n != 0; n = n->next)
{
if(u128_match(n->key, key))
{
FZY_Bucket *bucket = &n->buckets[n->submit_gen%ArrayCount(n->buckets)];
task_is_good = 1;
initial_submit_gen = n->submit_gen;
task_arena = bucket->arena;
query = bucket->query;
params = bucket->params;
break;
}
}
}
////////////////////////////
//- rjf: params -> look up all rdis
//
U64 rdis_count = params.dbgi_keys.count;
RDI_Parsed **rdis = push_array(scratch.arena, RDI_Parsed *, rdis_count);
if(task_is_good)
{
for(U64 idx = 0; idx < rdis_count; idx += 1)
{
rdis[idx] = di_rdi_from_key(di_scope, &params.dbgi_keys.v[idx], max_U64);
}
}
////////////////////////////
//- rjf: search target -> info about search space
//
U64 element_name_idx_off = 0;
if(task_is_good)
{
switch(params.target)
{
default:{}break;
case RDI_SectionKind_Procedures:
{
element_name_idx_off = OffsetOf(RDI_Procedure, name_string_idx);
}break;
case RDI_SectionKind_GlobalVariables:
{
element_name_idx_off = OffsetOf(RDI_GlobalVariable, name_string_idx);
}break;
case RDI_SectionKind_ThreadVariables:
{
element_name_idx_off = OffsetOf(RDI_ThreadVariable, name_string_idx);
}break;
case RDI_SectionKind_UDTs:
{
// NOTE(rjf): name must be determined from self_type_idx
}break;
}
}
////////////////////////////
//- rjf: rdis * query * params -> item list
//
FZY_ItemChunkList items_list = {0};
if(task_is_good)
{
U64 base_idx = 0;
for(U64 rdi_idx = 0; rdi_idx < rdis_count; rdi_idx += 1)
{
RDI_Parsed *rdi = rdis[rdi_idx];
U64 element_count = 0;
void *table_base = rdi_section_raw_table_from_kind(rdi, params.target, &element_count);
U64 element_size = rdi_section_element_size_table[params.target];
for(U64 idx = 1; task_is_good && idx < element_count; idx += 1)
{
void *element = (U8 *)table_base + element_size*idx;
U32 *name_idx_ptr = (U32 *)((U8 *)element + element_name_idx_off);
if(params.target == RDI_SectionKind_UDTs)
{
RDI_UDT *udt = (RDI_UDT *)element;
RDI_TypeNode *type_node = rdi_element_from_name_idx(rdi, TypeNodes, udt->self_type_idx);
name_idx_ptr = &type_node->user_defined.name_string_idx;
}
U32 name_idx = *name_idx_ptr;
U64 name_size = 0;
U8 *name_base = rdi_string_from_idx(rdi, name_idx, &name_size);
String8 name = str8(name_base, name_size);
if(name.size == 0) { continue; }
FuzzyMatchRangeList matches = fuzzy_match_find(task_arena, query, name);
if(matches.count == matches.needle_part_count)
{
FZY_ItemChunk *chunk = items_list.last;
if(chunk == 0 || chunk->count >= chunk->cap)
{
chunk = push_array(scratch.arena, FZY_ItemChunk, 1);
chunk->cap = 1024;
chunk->count = 0;
chunk->v = push_array_no_zero(scratch.arena, FZY_Item, chunk->cap);
SLLQueuePush(items_list.first, items_list.last, chunk);
items_list.chunk_count += 1;
}
chunk->v[chunk->count].idx = base_idx + idx;
chunk->v[chunk->count].match_ranges = matches;
chunk->v[chunk->count].missed_size = (name_size > matches.total_dim) ? (name_size-matches.total_dim) : 0;
chunk->count += 1;
items_list.total_count += 1;
}
if(idx%100 == 99) OS_MutexScopeR(stripe->rw_mutex)
{
for(FZY_Node *n = slot->first; n != 0; n = n->next)
{
if(u128_match(n->key, key) && n->submit_gen > initial_submit_gen)
{
task_is_good = 0;
break;
}
}
}
}
base_idx += element_count;
}
}
//- rjf: item list -> item array
FZY_ItemArray items = {0};
if(task_is_good)
{
items.count = items_list.total_count;
items.v = push_array_no_zero(task_arena, FZY_Item, items.count);
U64 idx = 0;
for(FZY_ItemChunk *chunk = items_list.first; chunk != 0; chunk = chunk->next)
{
MemoryCopy(items.v+idx, chunk->v, sizeof(FZY_Item)*chunk->count);
idx += chunk->count;
}
}
//- rjf: sort item array
if(items.count != 0 && query.size != 0)
{
quick_sort(items.v, items.count, sizeof(FZY_Item), fzy_qsort_compare_items);
}
//- rjf: commit to cache - busyloop on scope touches
if(task_is_good)
{
for(B32 done = 0; !done;)
{
B32 found = 0;
OS_MutexScopeW(stripe->rw_mutex) for(FZY_Node *n = slot->first; n != 0; n = n->next)
{
if(u128_match(n->key, key))
{
if(n->touch_count == 0)
{
n->gen = initial_submit_gen;
n->gen_items = items;
done = 1;
}
found = 1;
break;
}
}
if(!found)
{
break;
}
}
}
di_scope_close(di_scope);
scratch_end(scratch);
}
}
-192
View File
@@ -1,192 +0,0 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef FUZZY_SEARCH_H
#define FUZZY_SEARCH_H
////////////////////////////////
//~ rjf: Result Types
typedef struct FZY_Item FZY_Item;
struct FZY_Item
{
U64 idx; // indexes into whole space of parameter tables. [rdis[0] element count) [rdis[1] element count) ... [rdis[n] element count)
U64 missed_size;
FuzzyMatchRangeList match_ranges;
};
typedef struct FZY_ItemChunk FZY_ItemChunk;
struct FZY_ItemChunk
{
FZY_ItemChunk *next;
FZY_Item *v;
U64 count;
U64 cap;
};
typedef struct FZY_ItemChunkList FZY_ItemChunkList;
struct FZY_ItemChunkList
{
FZY_ItemChunk *first;
FZY_ItemChunk *last;
U64 chunk_count;
U64 total_count;
};
typedef struct FZY_ItemArray FZY_ItemArray;
struct FZY_ItemArray
{
FZY_Item *v;
U64 count;
};
////////////////////////////////
//~ rjf: Search Parameter Types
typedef struct FZY_Params FZY_Params;
struct FZY_Params
{
RDI_SectionKind target;
DI_KeyArray dbgi_keys;
};
////////////////////////////////
//~ rjf: Cache Types
typedef struct FZY_Bucket FZY_Bucket;
struct FZY_Bucket
{
Arena *arena;
String8 query;
FZY_Params params;
U64 params_hash;
};
typedef struct FZY_Node FZY_Node;
struct FZY_Node
{
FZY_Node *next;
U128 key;
U64 touch_count;
U64 last_time_submitted_us;
FZY_Bucket buckets[3];
U64 gen;
U64 submit_gen;
FZY_ItemArray gen_items;
};
typedef struct FZY_Slot FZY_Slot;
struct FZY_Slot
{
FZY_Node *first;
FZY_Node *last;
};
typedef struct FZY_Stripe FZY_Stripe;
struct FZY_Stripe
{
Arena *arena;
OS_Handle rw_mutex;
OS_Handle cv;
};
////////////////////////////////
//~ rjf: Scoped Access Types
typedef struct FZY_Touch FZY_Touch;
struct FZY_Touch
{
FZY_Touch *next;
FZY_Node *node;
};
typedef struct FZY_Scope FZY_Scope;
struct FZY_Scope
{
FZY_Scope *next;
FZY_Touch *first_touch;
FZY_Touch *last_touch;
};
typedef struct FZY_TCTX FZY_TCTX;
struct FZY_TCTX
{
Arena *arena;
FZY_Scope *free_scope;
FZY_Touch *free_touch;
};
////////////////////////////////
//~ rjf: Shared State Types
typedef struct FZY_Thread FZY_Thread;
struct FZY_Thread
{
OS_Handle thread;
OS_Handle u2f_ring_mutex;
OS_Handle u2f_ring_cv;
U64 u2f_ring_size;
U8 *u2f_ring_base;
U64 u2f_ring_write_pos;
U64 u2f_ring_read_pos;
};
typedef struct FZY_Shared FZY_Shared;
struct FZY_Shared
{
Arena *arena;
// rjf: search artifact cache table
U64 slots_count;
U64 stripes_count;
FZY_Slot *slots;
FZY_Stripe *stripes;
// rjf: threads
U64 thread_count;
FZY_Thread *threads;
};
////////////////////////////////
//~ rjf: Globals
global FZY_Shared *fzy_shared = 0;
thread_static FZY_TCTX *fzy_tctx = 0;
////////////////////////////////
//~ rjf: Helpers
internal U64 fzy_hash_from_string(U64 seed, String8 string);
internal U64 fzy_hash_from_params(FZY_Params *params);
internal U64 fzy_item_num_from_array_element_idx__linear_search(FZY_ItemArray *array, U64 element_idx);
internal String8 fzy_item_string_from_rdi_target_element_idx(RDI_Parsed *rdi, RDI_SectionKind target, U64 element_idx);
internal FZY_Params fzy_params_copy(Arena *arena, FZY_Params *src);
////////////////////////////////
//~ rjf: Main Layer Initialization
internal void fzy_init(void);
////////////////////////////////
//~ rjf: Scope Functions
internal FZY_Scope *fzy_scope_open(void);
internal void fzy_scope_close(FZY_Scope *scope);
internal void fzy_scope_touch_node__stripe_mutex_r_guarded(FZY_Scope *scope, FZY_Node *node);
////////////////////////////////
//~ rjf: Cache Lookup Functions
internal FZY_ItemArray fzy_items_from_key_params_query(FZY_Scope *scope, U128 key, FZY_Params *params, String8 query, U64 endt_us, B32 *stale_out);
////////////////////////////////
//~ rjf: Searcher Threads
internal B32 fzy_u2s_enqueue_req(U128 key, U64 endt_us);
internal void fzy_u2s_dequeue_req(Arena *arena, FZY_Thread *thread, U128 *key_out);
internal int fzy_qsort_compare_items(FZY_Item *a, FZY_Item *b);
internal void fzy_search_thread__entry_point(void *p);
#endif // FUZZY_SEARCH_H
+58 -78
View File
@@ -25,12 +25,6 @@ geo_init(void)
geo_shared->u2x_ring_base = push_array_no_zero(arena, U8, geo_shared->u2x_ring_size); geo_shared->u2x_ring_base = push_array_no_zero(arena, U8, geo_shared->u2x_ring_size);
geo_shared->u2x_ring_cv = os_condition_variable_alloc(); geo_shared->u2x_ring_cv = os_condition_variable_alloc();
geo_shared->u2x_ring_mutex = os_mutex_alloc(); geo_shared->u2x_ring_mutex = os_mutex_alloc();
geo_shared->xfer_thread_count = Clamp(1, os_get_system_info()->logical_processor_count-1, 4);
geo_shared->xfer_threads = push_array(arena, OS_Handle, geo_shared->xfer_thread_count);
for(U64 idx = 0; idx < geo_shared->xfer_thread_count; idx += 1)
{
geo_shared->xfer_threads[idx] = os_thread_launch(geo_xfer_thread__entry_point, (void *)idx, 0);
}
geo_shared->evictor_thread = os_thread_launch(geo_evictor_thread__entry_point, 0, 0); geo_shared->evictor_thread = os_thread_launch(geo_evictor_thread__entry_point, 0, 0);
} }
@@ -48,21 +42,6 @@ geo_tctx_ensure_inited(void)
} }
} }
////////////////////////////////
//~ rjf: User Clock
internal void
geo_user_clock_tick(void)
{
ins_atomic_u64_inc_eval(&geo_shared->user_clock_idx);
}
internal U64
geo_user_clock_idx(void)
{
return ins_atomic_u64_eval(&geo_shared->user_clock_idx);
}
//////////////////////////////// ////////////////////////////////
//~ rjf: Scoped Access //~ rjf: Scoped Access
@@ -116,7 +95,7 @@ geo_scope_touch_node__stripe_r_guarded(GEO_Scope *scope, GEO_Node *node)
GEO_Touch *touch = geo_tctx->free_touch; GEO_Touch *touch = geo_tctx->free_touch;
ins_atomic_u64_inc_eval(&node->scope_ref_count); ins_atomic_u64_inc_eval(&node->scope_ref_count);
ins_atomic_u64_eval_assign(&node->last_time_touched_us, os_now_microseconds()); ins_atomic_u64_eval_assign(&node->last_time_touched_us, os_now_microseconds());
ins_atomic_u64_eval_assign(&node->last_user_clock_idx_touched, geo_user_clock_idx()); ins_atomic_u64_eval_assign(&node->last_user_clock_idx_touched, update_tick_idx());
if(touch != 0) if(touch != 0)
{ {
SLLStackPop(geo_tctx->free_touch); SLLStackPop(geo_tctx->free_touch);
@@ -192,6 +171,7 @@ geo_buffer_from_hash(GEO_Scope *scope, U128 hash)
if(node_is_new) if(node_is_new)
{ {
geo_u2x_enqueue_req(hash, max_U64); geo_u2x_enqueue_req(hash, max_U64);
async_push_work(geo_xfer_work);
} }
} }
return handle; return handle;
@@ -259,68 +239,67 @@ geo_u2x_dequeue_req(U128 *hash_out)
os_condition_variable_broadcast(geo_shared->u2x_ring_cv); os_condition_variable_broadcast(geo_shared->u2x_ring_cv);
} }
internal void ASYNC_WORK_DEF(geo_xfer_work)
geo_xfer_thread__entry_point(void *p)
{ {
for(;;) ProfBeginFunction();
HS_Scope *scope = hs_scope_open();
//- rjf: decode
U128 hash = {0};
geo_u2x_dequeue_req(&hash);
//- rjf: unpack hash
U64 slot_idx = hash.u64[1]%geo_shared->slots_count;
U64 stripe_idx = slot_idx%geo_shared->stripes_count;
GEO_Slot *slot = &geo_shared->slots[slot_idx];
GEO_Stripe *stripe = &geo_shared->stripes[stripe_idx];
//- rjf: take task
B32 got_task = 0;
OS_MutexScopeR(stripe->rw_mutex)
{ {
HS_Scope *scope = hs_scope_open(); for(GEO_Node *n = slot->first; n != 0; n = n->next)
//- rjf: decode
U128 hash = {0};
geo_u2x_dequeue_req(&hash);
//- rjf: unpack hash
U64 slot_idx = hash.u64[1]%geo_shared->slots_count;
U64 stripe_idx = slot_idx%geo_shared->stripes_count;
GEO_Slot *slot = &geo_shared->slots[slot_idx];
GEO_Stripe *stripe = &geo_shared->stripes[stripe_idx];
//- rjf: take task
B32 got_task = 0;
OS_MutexScopeR(stripe->rw_mutex)
{ {
for(GEO_Node *n = slot->first; n != 0; n = n->next) if(u128_match(n->hash, hash))
{ {
if(u128_match(n->hash, hash)) got_task = !ins_atomic_u32_eval_cond_assign(&n->is_working, 1, 0);
{ break;
got_task = !ins_atomic_u32_eval_cond_assign(&n->is_working, 1, 0);
break;
}
} }
} }
//- rjf: hash -> data
String8 data = {0};
if(got_task)
{
data = hs_data_from_hash(scope, hash);
}
//- rjf: data -> buffer
R_Handle buffer = {0};
if(got_task && data.size != 0)
{
buffer = r_buffer_alloc(R_ResourceKind_Static, data.size, data.str);
}
//- rjf: commit results to cache
if(got_task) OS_MutexScopeW(stripe->rw_mutex)
{
for(GEO_Node *n = slot->first; n != 0; n = n->next)
{
if(u128_match(n->hash, hash))
{
n->buffer = buffer;
ins_atomic_u32_eval_assign(&n->is_working, 0);
ins_atomic_u64_inc_eval(&n->load_count);
break;
}
}
}
hs_scope_close(scope);
} }
//- rjf: hash -> data
String8 data = {0};
if(got_task)
{
data = hs_data_from_hash(scope, hash);
}
//- rjf: data -> buffer
R_Handle buffer = {0};
if(got_task && data.size != 0)
{
buffer = r_buffer_alloc(R_ResourceKind_Static, data.size, data.str);
}
//- rjf: commit results to cache
if(got_task) OS_MutexScopeW(stripe->rw_mutex)
{
for(GEO_Node *n = slot->first; n != 0; n = n->next)
{
if(u128_match(n->hash, hash))
{
n->buffer = buffer;
ins_atomic_u32_eval_assign(&n->is_working, 0);
ins_atomic_u64_inc_eval(&n->load_count);
break;
}
}
}
hs_scope_close(scope);
ProfEnd();
return 0;
} }
//////////////////////////////// ////////////////////////////////
@@ -329,10 +308,11 @@ geo_xfer_thread__entry_point(void *p)
internal void internal void
geo_evictor_thread__entry_point(void *p) geo_evictor_thread__entry_point(void *p)
{ {
ThreadNameF("[geo] evictor thread");
for(;;) for(;;)
{ {
U64 check_time_us = os_now_microseconds(); U64 check_time_us = os_now_microseconds();
U64 check_time_user_clocks = geo_user_clock_idx(); U64 check_time_user_clocks = update_tick_idx();
U64 evict_threshold_us = 10*1000000; U64 evict_threshold_us = 10*1000000;
U64 evict_threshold_user_clocks = 10; U64 evict_threshold_user_clocks = 10;
for(U64 slot_idx = 0; slot_idx < geo_shared->slots_count; slot_idx += 1) for(U64 slot_idx = 0; slot_idx < geo_shared->slots_count; slot_idx += 1)
+1 -14
View File
@@ -72,9 +72,6 @@ struct GEO_Shared
{ {
Arena *arena; Arena *arena;
// rjf: user clock
U64 user_clock_idx;
// rjf: cache // rjf: cache
U64 slots_count; U64 slots_count;
U64 stripes_count; U64 stripes_count;
@@ -90,10 +87,6 @@ struct GEO_Shared
OS_Handle u2x_ring_cv; OS_Handle u2x_ring_cv;
OS_Handle u2x_ring_mutex; OS_Handle u2x_ring_mutex;
// rjf: transfer threads
U64 xfer_thread_count;
OS_Handle *xfer_threads;
// rjf: evictor thread // rjf: evictor thread
OS_Handle evictor_thread; OS_Handle evictor_thread;
}; };
@@ -114,12 +107,6 @@ internal void geo_init(void);
internal void geo_tctx_ensure_inited(void); internal void geo_tctx_ensure_inited(void);
////////////////////////////////
//~ rjf: User Clock
internal void geo_user_clock_tick(void);
internal U64 geo_user_clock_idx(void);
//////////////////////////////// ////////////////////////////////
//~ rjf: Scoped Access //~ rjf: Scoped Access
@@ -138,7 +125,7 @@ internal R_Handle geo_buffer_from_key(GEO_Scope *scope, U128 key);
internal B32 geo_u2x_enqueue_req(U128 hash, U64 endt_us); internal B32 geo_u2x_enqueue_req(U128 hash, U64 endt_us);
internal void geo_u2x_dequeue_req(U128 *hash_out); internal void geo_u2x_dequeue_req(U128 *hash_out);
internal void geo_xfer_thread__entry_point(void *p); ASYNC_WORK_DEF(geo_xfer_work);
//////////////////////////////// ////////////////////////////////
//~ rjf: Evictor Threads //~ rjf: Evictor Threads
+2 -4
View File
@@ -14,10 +14,7 @@ internal U128
hs_hash_from_data(String8 data) hs_hash_from_data(String8 data)
{ {
U128 u128 = {0}; U128 u128 = {0};
if(data.size != 0) blake2b((U8 *)&u128.u64[0], sizeof(u128), data.str, data.size, 0, 0);
{
blake2b((U8 *)&u128.u64[0], sizeof(u128), data.str, data.size, 0, 0);
}
return u128; return u128;
} }
@@ -299,6 +296,7 @@ hs_data_from_hash(HS_Scope *scope, U128 hash)
internal void internal void
hs_evictor_thread__entry_point(void *p) hs_evictor_thread__entry_point(void *p)
{ {
ThreadNameF("[hs] evictor thread");
for(;;) for(;;)
{ {
for(U64 slot_idx = 0; slot_idx < hs_shared->slots_count; slot_idx += 1) for(U64 slot_idx = 0; slot_idx < hs_shared->slots_count; slot_idx += 1)
+171 -1
View File
@@ -306,7 +306,8 @@ typedef enum RDI_LanguageEnum
RDI_Language_NULL = 0, RDI_Language_NULL = 0,
RDI_Language_C = 1, RDI_Language_C = 1,
RDI_Language_CPlusPlus = 2, RDI_Language_CPlusPlus = 2,
RDI_Language_COUNT = 3, RDI_Language_Masm = 3,
RDI_Language_COUNT = 4,
} RDI_LanguageEnum; } RDI_LanguageEnum;
typedef RDI_U16 RDI_TypeKind; typedef RDI_U16 RDI_TypeKind;
@@ -367,6 +368,7 @@ RDI_TypeKind_IncompleteClass = 0x2007,
RDI_TypeKind_IncompleteEnum = 0x2008, RDI_TypeKind_IncompleteEnum = 0x2008,
RDI_TypeKind_Bitfield = 0xF000, RDI_TypeKind_Bitfield = 0xF000,
RDI_TypeKind_Variadic = 0xF001, RDI_TypeKind_Variadic = 0xF001,
RDI_TypeKind_Count = 0xF002,
RDI_TypeKind_FirstBuiltIn = RDI_TypeKind_Void, RDI_TypeKind_FirstBuiltIn = RDI_TypeKind_Void,
RDI_TypeKind_LastBuiltIn = RDI_TypeKind_ComplexF128, RDI_TypeKind_LastBuiltIn = RDI_TypeKind_ComplexF128,
RDI_TypeKind_FirstConstructed = RDI_TypeKind_Modifier, RDI_TypeKind_FirstConstructed = RDI_TypeKind_Modifier,
@@ -587,6 +589,172 @@ X(NULL)\
X(X86)\ X(X86)\
X(X64)\ X(X64)\
#define RDI_RegCodeX86_XList \
X(nil, 0)\
X(eax, 1)\
X(ecx, 2)\
X(edx, 3)\
X(ebx, 4)\
X(esp, 5)\
X(ebp, 6)\
X(esi, 7)\
X(edi, 8)\
X(fsbase, 9)\
X(gsbase, 10)\
X(eflags, 11)\
X(eip, 12)\
X(dr0, 13)\
X(dr1, 14)\
X(dr2, 15)\
X(dr3, 16)\
X(dr4, 17)\
X(dr5, 18)\
X(dr6, 19)\
X(dr7, 20)\
X(fpr0, 21)\
X(fpr1, 22)\
X(fpr2, 23)\
X(fpr3, 24)\
X(fpr4, 25)\
X(fpr5, 26)\
X(fpr6, 27)\
X(fpr7, 28)\
X(st0, 29)\
X(st1, 30)\
X(st2, 31)\
X(st3, 32)\
X(st4, 33)\
X(st5, 34)\
X(st6, 35)\
X(st7, 36)\
X(fcw, 37)\
X(fsw, 38)\
X(ftw, 39)\
X(fop, 40)\
X(fcs, 41)\
X(fds, 42)\
X(fip, 43)\
X(fdp, 44)\
X(mxcsr, 45)\
X(mxcsr_mask, 46)\
X(ss, 47)\
X(cs, 48)\
X(ds, 49)\
X(es, 50)\
X(fs, 51)\
X(gs, 52)\
X(ymm0, 53)\
X(ymm1, 54)\
X(ymm2, 55)\
X(ymm3, 56)\
X(ymm4, 57)\
X(ymm5, 58)\
X(ymm6, 59)\
X(ymm7, 60)\
#define RDI_RegCodeX64_XList \
X(nil, 0)\
X(rax, 1)\
X(rcx, 2)\
X(rdx, 3)\
X(rbx, 4)\
X(rsp, 5)\
X(rbp, 6)\
X(rsi, 7)\
X(rdi, 8)\
X(r8, 9)\
X(r9, 10)\
X(r10, 11)\
X(r11, 12)\
X(r12, 13)\
X(r13, 14)\
X(r14, 15)\
X(r15, 16)\
X(es, 17)\
X(cs, 18)\
X(ss, 19)\
X(ds, 20)\
X(fs, 21)\
X(gs, 22)\
X(rip, 23)\
X(rflags, 24)\
X(dr0, 25)\
X(dr1, 26)\
X(dr2, 27)\
X(dr3, 28)\
X(dr4, 29)\
X(dr5, 30)\
X(dr6, 31)\
X(dr7, 32)\
X(st0, 33)\
X(st1, 34)\
X(st2, 35)\
X(st3, 36)\
X(st4, 37)\
X(st5, 38)\
X(st6, 39)\
X(st7, 40)\
X(fpr0, 41)\
X(fpr1, 42)\
X(fpr2, 43)\
X(fpr3, 44)\
X(fpr4, 45)\
X(fpr5, 46)\
X(fpr6, 47)\
X(fpr7, 48)\
X(zmm0, 49)\
X(zmm1, 50)\
X(zmm2, 51)\
X(zmm3, 52)\
X(zmm4, 53)\
X(zmm5, 54)\
X(zmm6, 55)\
X(zmm7, 56)\
X(zmm8, 57)\
X(zmm9, 58)\
X(zmm10, 59)\
X(zmm11, 60)\
X(zmm12, 61)\
X(zmm13, 62)\
X(zmm14, 63)\
X(zmm15, 64)\
X(zmm16, 65)\
X(zmm17, 66)\
X(zmm18, 67)\
X(zmm19, 68)\
X(zmm20, 69)\
X(zmm21, 70)\
X(zmm22, 71)\
X(zmm23, 72)\
X(zmm24, 73)\
X(zmm25, 74)\
X(zmm26, 75)\
X(zmm27, 76)\
X(zmm28, 77)\
X(zmm29, 78)\
X(zmm30, 79)\
X(zmm31, 80)\
X(k0, 81)\
X(k1, 82)\
X(k2, 83)\
X(k3, 84)\
X(k4, 85)\
X(k5, 86)\
X(k6, 87)\
X(k7, 88)\
X(mxcsr, 89)\
X(fsbase, 90)\
X(gsbase, 91)\
X(fcw, 92)\
X(fsw, 93)\
X(ftw, 94)\
X(fop, 95)\
X(fcs, 96)\
X(fds, 97)\
X(fip, 98)\
X(fdp, 99)\
X(mxcsr_mask, 100)\
#define RDI_TopLevelInfo_XList \ #define RDI_TopLevelInfo_XList \
X(RDI_Arch, arch)\ X(RDI_Arch, arch)\
X(RDI_U32, exe_name_string_idx)\ X(RDI_U32, exe_name_string_idx)\
@@ -655,6 +823,7 @@ X(RDI_U32, line_map_voff_base_idx)\
X(NULL)\ X(NULL)\
X(C)\ X(C)\
X(CPlusPlus)\ X(CPlusPlus)\
X(Masm)\
X(COUNT)\ X(COUNT)\
#define RDI_TypeKind_XList \ #define RDI_TypeKind_XList \
@@ -713,6 +882,7 @@ X(IncompleteClass)\
X(IncompleteEnum)\ X(IncompleteEnum)\
X(Bitfield)\ X(Bitfield)\
X(Variadic)\ X(Variadic)\
X(Count)\
#define RDI_TypeModifierFlags_XList \ #define RDI_TypeModifierFlags_XList \
X(Const)\ X(Const)\
+2 -2
View File
@@ -303,9 +303,9 @@ rdi_line_info_idx_from_voff(RDI_ParsedLineTable *line_info, RDI_U64 voff)
{ {
RDI_U64 count = 0; RDI_U64 count = 0;
RDI_U64 result = rdi_line_info_idx_range_from_voff(line_info, voff, &count); RDI_U64 result = rdi_line_info_idx_range_from_voff(line_info, voff, &count);
for(RDI_U64 idx = 0; idx < count && result+idx < line_info->count; idx += 1) for(RDI_S64 idx = count-1; idx >= 0; idx -= 1)
{ {
if(line_info->lines[result+idx].file_idx != 0) if(result + idx < line_info->count && line_info->lines[result+idx].file_idx != 0)
{ {
result += idx; result += idx;
break; break;
+82 -29
View File
@@ -1129,7 +1129,7 @@ rdim_bake_vmap_from_markers(RDIM_Arena *arena, RDIM_VMapMarker *markers, RDIM_So
//- rjf: fill output vmap entries //- rjf: fill output vmap entries
RDI_U32 vmap_count_raw = marker_count - 1 + extra_vmap_entry; RDI_U32 vmap_count_raw = marker_count - 1 + extra_vmap_entry;
RDI_VMapEntry *vmap = rdim_push_array_no_zero(arena, RDI_VMapEntry, vmap_count_raw + 1); RDI_VMapEntry *vmap = rdim_push_array(arena, RDI_VMapEntry, vmap_count_raw + 1);
RDI_U32 vmap_entry_count_pass_1 = 0; RDI_U32 vmap_entry_count_pass_1 = 0;
{ {
typedef struct RDIM_VMapRangeTracker RDIM_VMapRangeTracker; typedef struct RDIM_VMapRangeTracker RDIM_VMapRangeTracker;
@@ -1345,11 +1345,11 @@ rdim_bake_string_chunk_list_sorted_from_unsorted(RDIM_Arena *arena, RDIM_BakeStr
// build new sort tasks for buckets with many elements // build new sort tasks for buckets with many elements
{ {
RDI_U64 write_idx = 0; RDI_U64 write_idx = 0;
for(U64 bucket_idx = 0; bucket_idx < 256; bucket_idx += 1) for(RDI_U64 bucket_idx = 0; bucket_idx < 256; bucket_idx += 1)
{ {
// rjf: write each chunk node's array into original array, detect if there is size left to sort // rjf: write each chunk node's array into original array, detect if there is size left to sort
RDI_U64 bucket_base_idx = write_idx; RDI_U64 bucket_base_idx = write_idx;
RDI_U64 max_size_left_to_sort = 0; RDI_U64 need_next_char_sort = 0;
for(RDIM_BakeStringChunkNode *n = buckets[bucket_idx].first; n != 0; n = n->next) for(RDIM_BakeStringChunkNode *n = buckets[bucket_idx].first; n != 0; n = n->next)
{ {
rdim_memcpy(t->v+write_idx, n->v, sizeof(n->v[0])*n->count); rdim_memcpy(t->v+write_idx, n->v, sizeof(n->v[0])*n->count);
@@ -1358,14 +1358,14 @@ rdim_bake_string_chunk_list_sorted_from_unsorted(RDIM_Arena *arena, RDIM_BakeStr
{ {
if(n->v[idx].string.size > t->string_off+1) if(n->v[idx].string.size > t->string_off+1)
{ {
max_size_left_to_sort = Max(max_size_left_to_sort, (n->v[idx].string.size - t->string_off+1)); need_next_char_sort = 1;
} }
} }
} }
// rjf: if any bucket has >1 element & has some amount of size left to sort, push new task for this // rjf: if any bucket has >1 element & has some amount of size left to sort, push new task for this
// bucket's region in the array, and for remainder of keys // bucket's region in the array, and for remainder of keys
if(buckets[bucket_idx].total_count > 1 && max_size_left_to_sort > 0) if(buckets[bucket_idx].total_count > 1 && need_next_char_sort)
{ {
SortTask *new_task = rdim_push_array(scratch.arena, SortTask, 1); SortTask *new_task = rdim_push_array(scratch.arena, SortTask, 1);
RDIM_SLLQueuePush(first_task, last_task, new_task); RDIM_SLLQueuePush(first_task, last_task, new_task);
@@ -1376,9 +1376,60 @@ rdim_bake_string_chunk_list_sorted_from_unsorted(RDIM_Arena *arena, RDIM_BakeStr
} }
} }
} }
scratch_end(scratch); rdim_scratch_end(scratch);
} }
//- rjf: iterate sorted chunk node, remove duplicates, count # of duplicates
RDI_U64 num_duplicates = 0;
if(dst.first != 0)
{
RDI_U64 last_idx = 0;
for(RDI_U64 idx = 1; idx < dst.first->count; idx += 1)
{
if(rdim_str8_match(dst.first->v[last_idx].string, dst.first->v[idx].string, 0))
{
rdim_memzero_struct(&dst.first->v[idx]);
num_duplicates += 1;
}
else
{
last_idx = idx;
}
}
}
//- rjf: iterate sorted chunk node, make non-empty elements contiguous
if(num_duplicates != 0)
{
RDI_U64 last_idx = 0;
for(RDI_U64 idx = 1; idx < dst.first->count; idx += 1)
{
if(last_idx == 0 &&
dst.first->v[idx].string.RDIM_String8_SizeMember == 0 &&
dst.first->v[idx].hash == 0)
{
last_idx = idx;
}
if(last_idx != 0 && dst.first->v[idx].string.RDIM_String8_SizeMember != 0)
{
rdim_memcpy_struct(&dst.first->v[last_idx], &dst.first->v[idx]);
rdim_memzero_struct(&dst.first->v[idx]);
last_idx += 1;
}
}
//- rjf: pop extras
if(num_duplicates != 0)
{
RDI_U64 arena_pos_pre_pop = rdim_arena_pos(arena);
rdim_arena_pop_to(arena, arena_pos_pre_pop - num_duplicates*sizeof(dst.first->v[0]));
dst.first->count -= num_duplicates;
dst.first->cap -= num_duplicates;
dst.total_count -= num_duplicates;
}
}
return dst; return dst;
} }
@@ -1395,31 +1446,34 @@ rdim_bake_string_map_loose_make(RDIM_Arena *arena, RDIM_BakeStringMapTopology *t
RDI_PROC void RDI_PROC void
rdim_bake_string_map_loose_insert(RDIM_Arena *arena, RDIM_BakeStringMapTopology *map_topology, RDIM_BakeStringMapLoose *map, RDI_U64 chunk_cap, RDIM_String8 string) rdim_bake_string_map_loose_insert(RDIM_Arena *arena, RDIM_BakeStringMapTopology *map_topology, RDIM_BakeStringMapLoose *map, RDI_U64 chunk_cap, RDIM_String8 string)
{ {
RDI_U64 hash = rdi_hash(string.RDIM_String8_BaseMember, string.RDIM_String8_SizeMember); if(string.RDIM_String8_SizeMember != 0)
RDI_U64 slot_idx = hash%map_topology->slots_count;
RDIM_BakeStringChunkList *slot = map->slots[slot_idx];
if(slot == 0)
{ {
slot = map->slots[slot_idx] = rdim_push_array(arena, RDIM_BakeStringChunkList, 1); RDI_U64 hash = rdi_hash(string.RDIM_String8_BaseMember, string.RDIM_String8_SizeMember);
} RDI_U64 slot_idx = hash%map_topology->slots_count;
RDI_S32 is_duplicate = 0; RDIM_BakeStringChunkList *slot = map->slots[slot_idx];
for(RDIM_BakeStringChunkNode *n = slot->first; n != 0; n = n->next) if(slot == 0)
{
for(RDI_U64 idx = 0; idx < n->count; idx += 1)
{ {
if(rdim_str8_match(n->v[idx].string, string, 0)) slot = map->slots[slot_idx] = rdim_push_array(arena, RDIM_BakeStringChunkList, 1);
}
RDI_S32 is_duplicate = 0;
for(RDIM_BakeStringChunkNode *n = slot->first; n != 0; n = n->next)
{
for(RDI_U64 idx = 0; idx < n->count; idx += 1)
{ {
is_duplicate = 1; if(rdim_str8_match(n->v[idx].string, string, 0))
goto break_all; {
is_duplicate = 1;
goto break_all;
}
} }
} }
} break_all:;
break_all:; if(!is_duplicate)
if(!is_duplicate) {
{ RDIM_BakeString *bstr = rdim_bake_string_chunk_list_push(arena, slot, chunk_cap);
RDIM_BakeString *bstr = rdim_bake_string_chunk_list_push(arena, slot, chunk_cap); bstr->string = string;
bstr->string = string; bstr->hash = hash;
bstr->hash = hash; }
} }
} }
@@ -3057,7 +3111,7 @@ rdim_bake_global_vmap(RDIM_Arena *arena, RDIM_SymbolChunkList *src)
RDIM_Temp scratch = rdim_scratch_begin(&arena, 1); RDIM_Temp scratch = rdim_scratch_begin(&arena, 1);
//- rjf: allocate keys/markers //- rjf: allocate keys/markers
RDI_U64 marker_count = src->total_count*2; RDI_U64 marker_count = src->total_count*2 + 2;
RDIM_SortKey *keys = rdim_push_array_no_zero(scratch.arena, RDIM_SortKey, marker_count); RDIM_SortKey *keys = rdim_push_array_no_zero(scratch.arena, RDIM_SortKey, marker_count);
RDIM_VMapMarker *markers = rdim_push_array_no_zero(scratch.arena, RDIM_VMapMarker, marker_count); RDIM_VMapMarker *markers = rdim_push_array_no_zero(scratch.arena, RDIM_VMapMarker, marker_count);
@@ -3427,7 +3481,7 @@ rdim_bake_inline_sites(RDIM_Arena *arena, RDIM_BakeStringMapTight *strings, RDIM
{ {
RDIM_InlineSiteBakeResult result = {0}; RDIM_InlineSiteBakeResult result = {0};
{ {
result.inline_sites_count = src->total_count; result.inline_sites_count = src->total_count+1;
result.inline_sites = rdim_push_array(arena, RDI_InlineSite, result.inline_sites_count+1); result.inline_sites = rdim_push_array(arena, RDI_InlineSite, result.inline_sites_count+1);
RDI_U64 dst_idx = 1; RDI_U64 dst_idx = 1;
for(RDIM_InlineSiteChunkNode *n = src->first; n != 0; n = n->next) for(RDIM_InlineSiteChunkNode *n = src->first; n != 0; n = n->next)
@@ -3510,7 +3564,6 @@ rdim_bake_file_paths(RDIM_Arena *arena, RDIM_BakeStringMapTight *strings, RDIM_B
RDI_PROC RDIM_StringBakeResult RDI_PROC RDIM_StringBakeResult
rdim_bake_strings(RDIM_Arena *arena, RDIM_BakeStringMapTight *strings) rdim_bake_strings(RDIM_Arena *arena, RDIM_BakeStringMapTight *strings)
{ {
RDIM_BakeSectionList sections = {0};
RDI_U32 *str_offs = rdim_push_array_no_zero(arena, RDI_U32, strings->total_count + 1); RDI_U32 *str_offs = rdim_push_array_no_zero(arena, RDI_U32, strings->total_count + 1);
RDI_U32 off_cursor = 0; RDI_U32 off_cursor = 0;
{ {
+88
View File
@@ -0,0 +1,88 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal String8
push_cstr(Arena *arena, String8 str)
{
U64 buffer_size = str.size + 1;
U8 *buffer = push_array_no_zero(arena, U8, buffer_size);
MemoryCopy(buffer, str.str, str.size);
buffer[str.size] = 0;
String8 result = str8(buffer, buffer_size);
return result;
}
internal U32 *
push_u32(Arena *arena, U32 value)
{
U32 *result = push_array_no_zero(arena, U32, 1);
*result = value;
return result;
}
internal U64 *
push_u64(Arena *arena, U64 value)
{
U64 *result = push_array_no_zero(arena, U64, 1);
*result = value;
return result;
}
internal U32 *
push_array_copy_u32(Arena *arena, U32 *v, U64 count)
{
U32 *result = push_array_no_zero(arena, U32, count);
MemoryCopyTyped(result, v, count);
return result;
}
internal U64 *
push_array_copy_u64(Arena *arena, U64 *v, U64 count)
{
U64 *result = push_array_no_zero(arena, U64, count);
MemoryCopyTyped(result, v, count);
return result;
}
internal U64 **
push_matrix_u64(Arena *arena, U64 rows, U64 columns)
{
U64 **result = push_array_no_zero(arena, U64 *, rows);
for (U64 row_idx = 0; row_idx < rows; row_idx += 1) {
result[row_idx] = push_array(arena, U64, columns);
}
return result;
}
internal Arena **
alloc_fixed_size_arena_array(Arena *arena, U64 count, U64 res, U64 cmt)
{
U64 data_size = sizeof(count) + sizeof(Arena *) * count;
U8 *data = push_array_no_zero(arena, U8, data_size);
U64 *count_ptr = (U64 *)data;
Arena **arr = (Arena **)(count_ptr + 1);
*count_ptr = count;
ArenaParams params = {0};
params.reserve_size = res;
params.commit_size = cmt;
for (U64 i = 0; i < count; i += 1) {
Arena *fixed_arena = arena_alloc_(&params);
arr[i] = fixed_arena;
}
return arr;
}
internal void
release_arena_array(Arena **arr)
{
U64 *count_ptr = (U64 *)arr - 1;
U64 count = *count_ptr;
for (U64 i = 0; i < count; i += 1) {
arena_release(arr[i]);
arr[i] = 0;
}
}
+15
View File
@@ -0,0 +1,15 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#pragma once
internal U32 * push_u32(Arena *arena, U32 value);
internal U64 * push_u64(Arena *arena, U64 value);
internal U32 * push_array_copy_u32(Arena *arena, U32 *v, U64 count);
internal U64 * push_array_copy_u64(Arena *arena, U64 *v, U64 count);
internal U64 ** push_matrix_u64(Arena *arena, U64 rows, U64 columns);
internal String8 push_cstr(Arena *arena, String8 str);
internal Arena ** alloc_fixed_size_arena_array(Arena *arena, U64 count, U64 res, U64 cmt);
internal void release_arena_array(Arena **arr);
+230
View File
@@ -0,0 +1,230 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal U64
void_list_count_nodes(VoidNode *head)
{
U64 node_count = 0;
for (VoidNode *curr = head; curr != 0; curr = curr->next) {
++node_count;
}
return node_count;
}
internal void
void_node_concat(VoidNode **head, VoidNode *node)
{
Assert(*head != node);
node->next = *head;
*head = node;
}
internal void
void_node_concat_atomic(VoidNode **head, VoidNode *node)
{
Assert(*head != node);
node->next = ins_atomic_ptr_eval_assign(head, node);
}
internal U64Node *
u64_list_push(Arena *arena, U64List *list, U64 data)
{
U64Node *n = push_array(arena, U64Node, 1);
n->next = 0;
n->data = data;
SLLQueuePush(list->first, list->last, n);
++list->count;
return n;
}
internal void
u64_list_concat_in_place(U64List *list, U64List *to_concat)
{
SLLConcatInPlace(list, to_concat);
}
internal U64Array
u64_array_from_list(Arena *arena, U64List *list)
{
U64Array result;
result.count = 0;
result.v = push_array(arena, U64, list->count);
for (U64Node *n = list->first; n != NULL; n = n->next) {
result.v[result.count++] = n->data;
}
return result;
}
internal void
u32_array_sort(U64 count, U32 *v)
{
radsort(v, count, u32_is_before);
}
internal void
u32_pair_radix_sort(U64 count, PairU32 *arr)
{
Temp scratch = scratch_begin(0,0);
PairU32 *temp = push_array(scratch.arena, PairU32, count);
const U64 bit_count0 = 11;
const U64 bit_count1 = 11;
const U64 bit_count2 = 10;
U32 *count0 = push_array(scratch.arena, U32, (1 << bit_count0));
U32 *count1 = push_array(scratch.arena, U32, (1 << bit_count1));
U32 *count2 = push_array(scratch.arena, U32, (1 << bit_count2));
for (U64 i = 0; i < count; ++i) {
U32 digit0 = (arr[i].v0 >> 0 ) % (1 << bit_count0);
U32 digit1 = (arr[i].v0 >> bit_count0) % (1 << bit_count1);
U32 digit2 = (arr[i].v0 >> bit_count1) % (1 << bit_count2);
++count0[digit0];
++count1[digit1];
++count2[digit2];
}
counts_to_offsets_array_u32((1 << bit_count0), count0);
counts_to_offsets_array_u32((1 << bit_count1), count1);
counts_to_offsets_array_u32((1 << bit_count2), count2);
for (U64 i = 0; i < count; ++i) {
U32 digit0 = (arr[i].v0 >> 0) % (1 << bit_count0);
temp[count0[digit0]++] = arr[i];
}
for (U64 i = 0; i < count; ++i) {
U32 digit1 = (temp[i].v0 >> bit_count0) % (1 << bit_count1);
arr[count1[digit1]++] = temp[i];
}
for (U64 i = 0; i < count; ++i) {
U32 digit2 = (arr[i].v0 >> bit_count1) % (1 << bit_count2);
temp[count2[digit2]++] = arr[i];
}
MemoryCopyTyped(arr, temp, count);
scratch_end(scratch);
}
internal B32
u32_array_compare(U32Array a, U32Array b)
{
B32 are_equal = 0;
if (a.count == b.count) {
int cmp = MemoryCompare(a.v, b.v, sizeof(a.v[0]) * a.count);
are_equal = (cmp == 0);
}
return are_equal;
}
internal U64Array
u64_array_remove_duplicates(Arena *arena, U64Array in)
{
U64Array result;
result.count = 0;
result.v = push_array(arena, U64, in.count);
for (U64 i = 1; i < in.count; ++i) {
B32 is_unique = in.v[i - 1] != in.v[i];
if (is_unique) {
result.v[result.count++] = in.v[i - 1];
}
}
if (in.count > 0 && result.count > 0) {
B32 is_unique = result.v[result.count - 1] != in.v[in.count - 1];
if (is_unique) {
result.v[result.count++] = in.v[in.count - 1];
}
}
U64 slack_size = (in.count - result.count) * sizeof(result.v[0]);
arena_pop(arena, slack_size);
return result;
}
internal U64
sum_array_u64(U64 count, U64 *v)
{
U64 result = 0;
for (U64 i = 0; i < count; i += 1) {
result += v[i];
}
return result;
}
internal U64
sum_matrix_u64(U64 rows, U64 cols, U64 **v)
{
U64 result = 0;
for (U64 i = 0; i < rows; ++i) {
result += sum_array_u64(cols, v[i]);
}
return result;
}
internal U64
max_array_u64(U64 count, U64 *v)
{
U64 result = 0;
for (U64 i = 0; i < count; i += 1) {
result = Max(v[i], result);
}
return result;
}
internal U64
min_array_u64(U64 count, U64 *v)
{
U64 result = max_U64;
for (U64 i = 0; i < count; i += 1) {
result = Min(v[i], result);
}
return result;
}
internal void
counts_to_offsets_array_u32(U64 count, U32 *arr)
{
U32 next_offset = 0;
for (U64 i = 0; i < count; i += 1) {
U32 current_offset = next_offset;
next_offset += arr[i];
arr[i] = current_offset;
}
}
internal void
counts_to_offsets_array_u64(U64 count, U64 *arr)
{
U64 next_offset = 0;
for (U64 i = 0; i < count; i += 1) {
U64 current_offset = next_offset;
next_offset += arr[i];
arr[i] = current_offset;
}
}
internal U32 *
offsets_from_counts_array_u32(Arena *arena, U32 *v, U64 count)
{
U32 *result = push_array_copy_u32(arena, v, count);
counts_to_offsets_array_u32(count, result);
return result;
}
internal U64 *
offsets_from_counts_array_u64(Arena *arena, U64 *v, U64 count)
{
U64 *result = push_array_copy_u64(arena, v, count);
counts_to_offsets_array_u64(count, result);
return result;
}
+63
View File
@@ -0,0 +1,63 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#pragma once
typedef struct U32Array
{
U64 count;
U32 *v;
} U32Array;
typedef struct U64Array
{
U64 count;
U64 *v;
} U64Array;
typedef struct
{
U64 count;
U128 *v;
} U128Array;
typedef struct U64Node
{
struct U64Node *next;
U64 data;
} U64Node;
typedef struct U64List
{
U64 count;
U64Node *first;
U64Node *last;
} U64List;
typedef struct VoidNode
{
struct VoidNode *next;
void *v;
} VoidNode;
////////////////////////////////
internal U64Node * u64_list_push(Arena *arena, U64List *list, U64 data);
internal void u64_list_concat_in_place(U64List *list, U64List *to_concat);
internal U64Array u64_array_from_list(Arena *arena, U64List *list);
internal U64Array u64_array_remove_duplicates(Arena *arena, U64Array in);
internal void u32_array_sort(U64 count, U32 *v);
internal B32 u32_array_compare(U32Array a, U32Array b);
internal U64 sum_array_u64(U64 count, U64 *v);
internal U64 max_array_u64(U64 count, U64 *v);
internal U64 min_array_u64(U64 count, U64 *v);
internal void counts_to_offsets_array_u32(U64 count, U32 *arr);
internal void counts_to_offsets_array_u64(U64 count, U64 *arr);
internal U32 * offsets_from_counts_array_u32(Arena *arena, U32 *v, U64 count);
internal U64 * offsets_from_counts_array_u64(Arena *arena, U64 *v, U64 count);
+276
View File
@@ -0,0 +1,276 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal U32Array
bit_array_init32(Arena *arena, U64 word_count)
{
U32Array result;
result.count = CeilIntegerDiv(word_count, 32);
result.v = push_array(arena, U32, word_count);
return result;
}
internal U64
bit_array_scan_left_to_right32(U32Array bit_array, U64 lo, U64 hi, B32 state)
{
Assert(lo < bit_array.count*32);
Assert(hi <= bit_array.count*32);
Assert(lo <= hi);
Assert(state == 0 || state == 1);
U64 word_lo = lo / 32;
U64 word_hi = CeilIntegerDiv(hi, 32) - 1;
U64 word_idx = word_lo;
U64 bit_idx = 0;
U64 scan_count = hi - lo;
if (scan_count < 32) {
U64 bit_lo = lo % 32;
U64 bit_hi = hi % 32;
U64 word = bit_array.v[word_idx];
word ^= state - 1;
word &= (1U << bit_hi) - (1U << bit_lo);
if (word) {
bit_idx = ctz32(word);
goto exit;
}
} else {
U32 first_word = bit_array.v[word_idx];
first_word ^= state - 1;
first_word &= ~0u << (lo % 32);
if (first_word) {
bit_idx = ctz32(first_word);
goto exit;
}
for (word_idx += 1; word_idx < word_hi; word_idx += 1) {
U32 word = bit_array.v[word_idx];
word ^= state - 1;
if (word != 0) {
bit_idx = ctz32(word);
goto exit;
}
}
U64 bit_hi = hi - (word_idx * 32);
U32 last_word = bit_array.v[word_idx];
last_word ^= state - 1;
last_word &= (1 << bit_hi) - 1;
if (last_word) {
bit_idx = ctz32(last_word);
goto exit;
}
}
word_idx = 0;
bit_idx = max_U32;
exit:;
U64 result = word_idx * 32 + bit_idx;
return result;
}
internal U64
bit_array_scan_right_to_left32(U32Array bit_array, U64 lo, U64 hi, B32 state)
{
Assert(lo <= hi);
Assert(state == 0 || state == 1);
S64 word_lo = lo / 32;
S64 word_hi = CeilIntegerDiv(hi, 32) - 1;
S64 word_idx = word_hi;
S64 bit_idx = -1;
U64 scan_count = hi - lo;
if (scan_count < 32) {
S64 bit_lo = lo % 32;
S64 bit_hi = bit_lo + scan_count;
U32 word = bit_array.v[word_idx];
for (bit_idx = bit_hi; bit_idx >= bit_lo; bit_idx -= 1) {
U32 bit = ExtractBit(word, bit_idx);
if (bit == state) {
goto exit;
}
}
} else {
U32 last_word = bit_array.v[word_idx];
S64 bit_hi = hi % 32;
for (bit_idx = bit_hi; bit_idx >= 0; bit_idx -= 1) {
U32 bit = ExtractBit(last_word, bit_idx);
if (bit == state) {
goto exit;
}
}
for (word_idx -= 1; word_idx > word_lo; word_idx -= 1) {
U32 word = bit_array.v[word_idx];
for (bit_idx = 32 - 1; bit_idx >= 0; bit_idx -= 1) {
U32 bit = ExtractBit(word, bit_idx);
if (bit == state) {
goto exit;
}
}
}
U32 first_word = bit_array.v[word_idx];
S64 bit_lo = lo % 32;
for (bit_idx = 32 - 1; bit_idx >= bit_lo; bit_idx -= 1) {
U32 bit = ExtractBit(first_word, bit_idx);
if (bit == state) {
goto exit;
}
}
}
word_idx = 0;
bit_idx = max_U32;
exit:;
S64 result_s64 = word_idx * 32 + bit_idx;
U64 result_u64 = (U64)result_s64;
return result_u64;
}
internal Rng1U64
bit_array_scan_left_to_right32_contiguous(U32Array bit_array, U64 lo, U64 hi, B32 state, U64 in_row_count)
{
Rng1U64 result = rng_1u64(max_U64, max_U64);
U64 curr_count = 0, rover = lo;
while (curr_count < in_row_count) {
rover = bit_array_scan_left_to_right32(bit_array, rover, hi, state);
// no more bits in range
if (rover >= hi) {
break;
}
// set first match
if (result.v[0] == max_U64) {
result = rng_1u64(rover, rover);
continue;
}
// reset on non-contiguous range
B32 is_bit_index_not_adjoined = (result.v[0] + 1 < rover);
if (is_bit_index_not_adjoined) {
curr_count = 0;
result = rng_1u64(max_U64, max_U64);
continue;
}
// advance
result.v[1] = rover;
curr_count -= 1;
}
// did we allocate enough bits?
if (curr_count != in_row_count) {
result = rng_1u64(max_U64, max_U64);
}
return result;
}
internal Rng1U64
bit_array_scan_right_to_left32_contiguous(U32Array bit_array, U64 lo, U64 hi, B32 state, U64 in_row_count)
{
Rng1U64 result = rng_1u64(max_U64, max_U64);
U64 curr_count = 0, rover = lo;
while (curr_count < in_row_count) {
rover = bit_array_scan_right_to_left32(bit_array, lo, rover, state);
// no more bits in range
if (rover >= hi) {
break;
}
// set first match
if (result.v[0] == max_U64) {
result = rng_1u64(rover, rover);
continue;
}
// reset on non-contiguous range
B32 is_bit_index_not_adjoined = (result.v[0] + 1 < rover);
if (is_bit_index_not_adjoined) {
curr_count = 0;
result = rng_1u64(max_U64, max_U64);
continue;
}
// advance
result.v[0] = rover;
curr_count -= 1;
}
// did we allocate enough bits?
if (curr_count != in_row_count) {
result = rng_1u64(max_U64, max_U64);
}
return result;
}
internal U64
bit_array_find_next_unset_bit32(U32Array bit_array)
{
U64 result = bit_array_scan_left_to_right32(bit_array, 0, bit_array.count*32, 0);
return result;
}
internal U64
bit_array_find_next_set_bit32(U32Array bit_array)
{
U64 result = bit_array_scan_left_to_right32(bit_array, 0, bit_array.count*32, 1);
return result;
}
internal void
bit_array_set_bit32(U32Array bit_array, U64 idx, B32 state)
{
Assert(idx < bit_array.count*32);
U64 word_idx = idx / 32;
U64 bit_idx = idx % 32;
if (state) {
bit_array.v[word_idx] |= (1 << bit_idx);
} else {
bit_array.v[word_idx] &= ~(1 << bit_idx);
}
}
internal void
bit_array_set_bit_range32(U32Array bit_array, Rng1U64 range, B32 state)
{
for (U64 idx = range.min ; idx < range.max; idx += 1) {
bit_array_set_bit32(bit_array, idx, state);
}
}
internal U32
bit_array_get_bit32(U32Array bit_array, U64 idx)
{
Assert(idx < bit_array.count*32);
U64 word_idx = idx / 32;
U64 bit_idx = idx % 32;
U32 bit = (bit_array.v[word_idx] & (1 << bit_idx)) >> bit_idx;
return bit;
}
internal B32
bit_array_is_bit_set(U32Array bit_arr, U64 bit_pos)
{
U64 word_idx = bit_pos / 32;
Assert(word_idx < bit_arr.count);
U32 word = bit_arr.v[word_idx];
U64 bit_idx = bit_pos % 32;
B32 is_set = !!(word & (1 << bit_idx));
return is_set;
}
+18
View File
@@ -0,0 +1,18 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#pragma once
internal U32Array bit_array_init32(Arena *arena, U64 word_count);
internal U64 bit_array_scan_left_to_right32(U32Array bit_array, U64 lo, U64 hi, B32 state);
internal U64 bit_array_scan_right_to_left32(U32Array bit_array, U64 lo, U64 hi, B32 state);
internal Rng1U64 bit_array_scan_left_to_right32_contiguous(U32Array bit_array, U64 lo, U64 hi, B32 state, U64 in_row_count);
internal Rng1U64 bit_array_scan_right_to_left32_contiguous(U32Array bit_array, U64 lo, U64 hi, B32 state, U64 in_row_count);
internal B32 byte_scan_right_to_left(U8 *start, U8 *opl, U8 byte, U64 *offset_out);
internal U64 bit_array_find_next_unset_bit32(U32Array bit_array);
internal U64 bit_array_find_next_set_bit32(U32Array bit_array);
internal void bit_array_set_bit32(U32Array bit_array, U64 idx, B32 state);
internal void bit_array_set_bit_range32(U32Array bit_array, Rng1U64 range, B32 state);
internal U32 bit_array_get_bit32(U32Array bit_array, U64 idx);
+102
View File
@@ -0,0 +1,102 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmacro-redefined"
#elif defined(_MSC_VER)
#pragma warning (push, 0)
#endif
#include "../third_party_ext/blake3/c/blake3_portable.c"
#if defined(_M_AMD64) || defined(__x86_64__)
#define round_fn sse2_round_fn
#define compress_pre sse2_compress_pre
#include "../third_party_ext/blake3/c/blake3_sse2.c"
#define loadu sse41_loadu
#define storeu sse41_storeu
#define addv sse41_addv
#define xorv sse41_xorv
#define set1 sse41_set1
#define set4 sse41_set4
#define rot16 sse41_rot16
#define rot12 sse41_rot12
#define rot8 sse41_rot8
#define rot7 sse41_rot7
#define g1 sse41_g1
#define g2 sse41_g2
#define diagonalize sse41_diagonalize
#define undiagonalize sse41_undiagonalize
#define compress_pre sse41_compress_pre
#define round_fn sse41_round_fn
#define transpose_vecs sse41_transpose_vecs
#define transpose_msg_vecs sse41_transpose_msg_vecs
#define load_counters sse41_load_counters
#if defined(__clang__)
#pragma clang attribute push(__attribute__((target("sse4.1"))), apply_to=function)
#endif
#include "../third_party_ext/blake3/c/blake3_sse41.c"
#if defined(__clang__)
#pragma clang attribute pop
#endif
#define loadu avx2_loadu
#define storeu avx2_storeu
#define addv avx2_addv
#define xorv avx2_xorv
#define set1 avx2_set1
#define rot7 avx2_rot7
#define rot8 avx2_rot8
#define rot12 avx2_rot12
#define rot16 avx2_rot16
#define round_fn avx2_round_fn
#define transpose_vecs avx2_transpose_vecs
#define transpose_msg_vecs avx2_transpose_msg_vecs
#define load_counters avx2_load_counters
#if defined(__clang__)
#pragma clang attribute push(__attribute__((target("avx2"))), apply_to=function)
#endif
#include "../third_party_ext/blake3/c/blake3_avx2.c"
#if defined(__clang__)
#pragma clang attribute pop
#endif
#define set4 avx512_set4
#define g1 avx512_g1
#define g2 avx512_g2
#define diagonalize avx512_diagonalize
#define undiagonalize avx512_undiagonalize
#define compress_pre avx512_compress_pre
#define transpose_vecs avx512_transpose_vecs
#define transpose_msg_vecs avx512_transpose_msg_vecs
#define load_counters avx512_load_counters
#if defined(__clang__)
#pragma clang attribute push(__attribute__((target("avx512f,avx512vl"))), apply_to=function)
#endif
#include "../third_party_ext/blake3/c/blake3_avx512.c"
#if defined(__clang__)
#pragma clang attribute pop
#endif
#endif
#if defined(__aarch64__) || defined(_M_ARM64)
#include "../third_party_ext/blake3/c/blake3_neon.c"
#endif
#include "../third_party_ext/blake3/c/blake3_dispatch.c"
#include "../third_party_ext/blake3/c/blake3.c"
#if defined(__clang__)
#pragma clang diagnostic pop
#elif defined(_MSC_VER)
#pragma warning (pop, 0)
#endif
+41
View File
@@ -0,0 +1,41 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#pragma once
#if defined(__clang__) && defined(__x86_64__)
# if defined(__IMMINTRIN_H)
# error "include this header before immintrin.h / x86intrin.h / intrin.h"
# endif
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wreserved-macro-identifier"
# pragma push_macro("__AVX__")
# pragma push_macro("__AVX2__")
# pragma push_macro("__SSE4_1__")
# pragma push_macro("__AVX512F__")
# pragma push_macro("__AVX512VL__")
# define __AVX__ 1
# define __AVX2__ 1
# define __SSE4_1__ 1
# define __AVX512F__ 1
# define __AVX512VL__ 1
# include <immintrin.h>
# pragma pop_macro("__AVX512VL__")
# pragma pop_macro("__AVX512F__")
# pragma pop_macro("__SSE4_1__")
# pragma pop_macro("__AVX2__")
# pragma pop_macro("__AVX__")
# pragma clang diagnostic pop
#endif
#include "../third_party_ext/blake3/c/blake3.h"
static void
blake3(void* out, size_t outlen, void* in, size_t inlen)
{
blake3_hasher hasher;
blake3_hasher_init(&hasher);
blake3_hasher_update(&hasher, in, inlen);
blake3_hasher_finalize(&hasher, (uint8_t*)out, outlen);
}
+13
View File
@@ -0,0 +1,13 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#include "../third_party_ext/blake3/blake3_portable.c"
#if defined(__aarch64__) || defined(_M_ARM64)
#include "../third_party_ext/blake3/blake3_neon.c"
#endif
#include "../third_party_ext/blake3/blake3_dispatch.c"
#include "../third_party_ext/blake3/blake3.c"
#pragma comment (lib, "blake3")
+18
View File
@@ -0,0 +1,18 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_BLAKE3_H
#define BASE_BLAKE3_H
#include "../third_party_ext/blake3/blake3.h"
static void
blake3(void* out, size_t outlen, void* in, size_t inlen)
{
blake3_hasher hasher;
blake3_hasher_init(&hasher);
blake3_hasher_update(&hasher, in, inlen);
blake3_hasher_finalize(&hasher, (uint8_t*)out, outlen);
}
#endif // BASE_BLAKE3_H
+227
View File
@@ -0,0 +1,227 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal U16
safe_cast_u16x(U64 x)
{
AssertAlways(x <= max_U16);
return (U16)x;
}
////////////////////////////////
internal U64
u128_mod64(U128 a, U64 b)
{
return a.u64[1] % b;
}
////////////////////////////////
internal Version
make_version(U64 major, U64 minor)
{
Version version;
version.major = major;
version.minor = minor;
return version;
}
internal int
version_compar(Version a, Version b)
{
int cmp = 0;
if (a.major < b.major) {
cmp = -1;
} else if (a.major > b.major) {
cmp = +1;
} else if (a.major == b.major) {
if (a.minor < b.minor) {
cmp = -1;
} else if (a.minor > b.minor) {
cmp = +1;
}
}
return cmp;
}
////////////////////////////////
internal ISectOff
isect_off(U32 isect, U32 off)
{
ISectOff result = { isect, off };
return result;
}
////////////////////////////////
internal int
u16_compar(const void *raw_a, const void *raw_b)
{
U16 a = *(U16*)raw_a;
U16 b = *(U16*)raw_b;
int result = a < b ? -1 :
a > b ? +1 :
0;
return result;
}
internal int
u32_compar(const void *raw_a, const void *raw_b)
{
U32 a = *(U32*)raw_a;
U32 b = *(U32*)raw_b;
int result = a < b ? -1 :
a > b ? +1 :
0;
return result;
}
internal int
u64_compar(const void *raw_a, const void *raw_b)
{
U64 a = *(const U64*)raw_a;
U64 b = *(const U64*)raw_b;
int result = a < b ? -1 : a > b ? +1 : 0;
return result;
}
internal int
u64_compar_inv(const void *raw_a, const void *raw_b)
{
U64 a = *(const U64*)raw_a;
U64 b = *(const U64*)raw_b;
int result = a < b ? +1 : a > b ? -1 : 0;
return result;
}
internal int
u16_compar_is_before(void *raw_a, void *raw_b)
{
U16 *a = (U16 *)raw_a;
U16 *b = (U16 *)raw_b;
int is_before = *a < *b;
return is_before;
}
internal int
u32_compar_is_before(void *raw_a, void *raw_b)
{
U32 *a = (U32 *)raw_a;
U32 *b = (U32 *)raw_b;
int is_before = *a < *b;
return is_before;
}
internal int
u64_compar_is_before(void *raw_a, void *raw_b)
{
U64 *a = (U64 *)raw_a;
U64 *b = (U64 *)raw_b;
int is_before = *a < *b;
return is_before;
}
internal int
u8_is_before(void *raw_a, void *raw_b)
{
U8 *a = (U8 *) raw_a;
U8 *b = (U8 *) raw_b;
return *a < *b;
}
internal int
u16_is_before(void *raw_a, void *raw_b)
{
U16 *a = (U16 *) raw_a;
U16 *b = (U16 *) raw_b;
return *a < *b;
}
internal int
u32_is_before(void *raw_a, void *raw_b)
{
U32 *a = (U32 *) raw_a;
U32 *b = (U32 *) raw_b;
return *a < *b;
}
internal int
u64_is_before(void *raw_a, void *raw_b)
{
U64 *a = (U64 *) raw_a;
U64 *b = (U64 *) raw_b;
return *a < *b;
}
internal int
pair_u32_is_before_v0(void *raw_a, void *raw_b)
{
PairU32 *a = raw_a;
PairU32 *b = raw_b;
return a->v0 < b->v0;
}
internal int
pair_u32_is_before(void *raw_a, void *raw_b)
{
PairU32 *a = raw_a;
PairU32 *b = raw_b;
return a->v1 < b->v1;
}
internal int
pair_u64_is_before_v0(void *raw_a, void *raw_b)
{
PairU64 *a = raw_a;
PairU64 *b = raw_b;
return a->v0 < b->v0;
}
internal int
pair_u64_is_before_v1(void *raw_a, void *raw_b)
{
PairU64 *a = raw_a;
PairU64 *b = raw_b;
return a->v1 < b->v1;
}
internal int
pair_u32_compar_v0(const void *raw_a, const void *raw_b)
{
const PairU32 *a = raw_a;
const PairU32 *b = raw_b;
return u32_compar(&a->v0, &b->v0);
}
internal int
pair_u64_compar_v0(const void *raw_a, const void *raw_b)
{
const PairU64 *a = raw_a;
const PairU64 *b = raw_b;
return u64_compar(&a->v0, &b->v0);
}
internal int
pair_u64_compar_v1(const void *raw_a, const void *raw_b)
{
const PairU64 *a = raw_a;
const PairU64 *b = raw_b;
return u64_compar(&a->v1, &b->v1);
}
////////////////////////////////
internal void
str8_list_concat_in_place_array(String8List *list, String8List *arr, U64 count)
{
for (U64 i = 0; i < count; ++i) {
str8_list_concat_in_place(list, &arr[i]);
}
}
+189
View File
@@ -0,0 +1,189 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#pragma once
#if COMPILER_MSVC
# define COMPILER_STRING "MSVC"
#elif COMPILER_CLANG
# define COMPILER_STRING "Clang"
#elif COMPILER_GCC
# define COMPILER_STRING "GCC"
#else
# error "undefined compiler string"
#endif
#if BUILD_DEBUG
# define BUILD_MODE_STRING "Debug"
#else
# define BUILD_MODE_STRING "Release"
#endif
////////////////////////////////
#define BitExtract(x, count, shift) (((x) >> (shift)) & ((1 << (count)) - 1))
////////////////////////////////
// Linked List Helpers
#define DLLConcatInPlace(list, to_concat) do { \
if ((to_concat)->count) { \
if ((list)->count) { \
(list)->last->next = (to_concat)->first; \
(to_concat)->first->prev = (list)->last; \
(list)->last = (to_concat)->last; \
} else { \
(list)->first = (to_concat)->first; \
(list)->last = (to_concat)->last; \
} \
(list)->count += (to_concat)->count; \
MemoryZeroStruct(to_concat); \
} \
} while (0)
#define DLLConcatInPlaceArray(list, to_concat_arr, count) for (U64 i = 0; i < (count); i += 1) { DLLConcatInPlace(list, &(to_concat_arr)[i]); }
#define SLLQueuePushCount(list, node) do { \
SLLQueuePush((list)->first, (list)->last, node); \
++(list)->count; \
} while (0)
#define SLLConcatInPlaceNoCount(list, to_concat) do { \
if ((to_concat)->first) { \
if ((list)->first) { \
(list)->last->next = (to_concat)->first; \
(list)->last = (to_concat)->last; \
} else { \
(list)->first = (to_concat)->first; \
(list)->last = (to_concat)->last; \
} \
MemoryZeroStruct(to_concat); \
} \
} while (0)
#define SLLConcatInPlace(list, to_concat) do { \
if ((to_concat)->count) { \
if ((list)->count) { \
(list)->last->next = (to_concat)->first; \
(list)->last = (to_concat)->last; \
} else { \
(list)->first = (to_concat)->first; \
(list)->last = (to_concat)->last; \
} \
(list)->count += (to_concat)->count; \
MemoryZeroStruct(to_concat); \
} \
} while (0)
#define SLLConcatInPlaceArray(list, to_concat_arr, count) for (U64 i = 0; i < (count); ++i) { SLLConcatInPlace(list, &(to_concat_arr)[i]); }
#define SLLConcatInPlaceChunkList(list, to_concat, chunk_type) do { \
if ((list)->last != 0) { \
U64 base_cursor = (list)->last->base + (list)->last->count; \
for (chunk_type *c = (to_concat)->first; c != 0; c = c->next) { \
c->base = base_cursor; \
base_cursor += c->count; \
} \
} \
SLLConcatInPlace(list, to_concat); \
} while (0)
#define SLLConcatInPlaceChunkListArray(list, to_concat_arr, type, count) for (U64 i = 0; i < (count); ++i) { SLLConcatInPlaceChunkList(list, &(to_concat_arr)[i], type); }
#define SLLChunkListPush(_arena, _list, _cap, _value_type) do { \
if ((_list)->last == 0 || (_list)->last->count >= (_list)->last->cap) { \
_value_type##Chunk *new_chunk = push_array(_arena, _value_type##Chunk, 1); \
new_chunk->v = push_array(_arena, _value_type, _cap); \
new_chunk->cap = _cap; \
new_chunk->base = (_list)->last ? (_list)->last->base + (_list)->last->cap : 0; \
SLLQueuePushCount(_list, new_chunk); \
} \
_value_type *v = &(_list)->last->v[(_list)->last->count++]; \
v->chunk = (_list)->last; \
} while (0)
#define SLLChunkListPushZero(_arena, _list, _cap, _value_type) do { \
SLLChunkListPush(_arena, _list, _cap, _value_type); \
MemoryZeroStruct(SLLChunkListLastItem(_list)); \
SLLChunkListLastItem(_list)->chunk = (_list)->last; \
} while(0)
#define SLLChunkListLastItem(_list) (&(_list)->last->v[(_list)->last->count - 1])
////////////////////////////////
#define MemoryIsZeroStruct(p) memory_is_zero(p, sizeof(*p))
////////////////////////////////
#if ARCH_LITTLE_ENDIAN
# define BE_U32(x) bswap_u32(x)
#else
# define BE_U32(x) (x)
#endif
////////////////////////////////
typedef struct
{
U64 major;
U64 minor;
} Version;
////////////////////////////////
typedef struct ISectOff
{
U32 isect;
U32 off;
} ISectOff;
////////////////////////////////
typedef struct PairU32
{
U32 v0;
U32 v1;
} PairU32;
typedef struct PairU64
{
U64 v0;
U64 v1;
} PairU64;
////////////////////////////////
internal U16 safe_cast_u16x(U64 x);
////////////////////////////////
internal U64 u128_mod64(U128 a, U64 b);
////////////////////////////////
internal Version make_version(U64 major, U64 minor);
internal int version_compar(Version a, Version b);
////////////////////////////////
internal ISectOff isect_off(U32 isect, U32 off);
////////////////////////////////
internal int u16_compar(const void *raw_a, const void *raw_b);
internal int u32_compar(const void *raw_a, const void *raw_b);
internal int u64_compar(const void *raw_a, const void *raw_b);
internal int u8_is_before(void *raw_a, void *raw_b);
internal int u16_is_before(void *raw_a, void *raw_b);
internal int u32_is_before(void *raw_a, void *raw_b);
internal int u64_is_before(void *raw_a, void *raw_b);
internal int pair_u32_is_before_v0(void *raw_a, void *raw_b);
internal int pair_u32_is_before_v1(void *raw_a, void *raw_b);
internal int pair_u64_is_before_v0(void *raw_a, void *raw_b);
internal int pair_u64_is_before_v1(void *raw_a, void *raw_b);
////////////////////////////////
internal void str8_list_concat_in_place_array(String8List *list, String8List *arr, U64 count);
+72
View File
@@ -0,0 +1,72 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal U32
update_crc32(U32 crc, U8 *ptr, U64 size)
{
// CRC-32 algo borrowed from stb.h
local_persist U32 crc_table[256] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535,
0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd,
0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d,
0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec,
0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac,
0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab,
0xb6662d3d, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb,
0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea,
0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce,
0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409,
0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739,
0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2, 0x1e01f268,
0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0,
0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8,
0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703,
0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7,
0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a,
0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae,
0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 0x88085ae6,
0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d,
0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5,
0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
#if 0
for (U32 i = 0; i < 256; ++i) {
U32 s = i;
for (U32 j = 0; j < 8; ++j) {
s = (s >> 1) ^ (s & 1 ? 0xedb88320 : 0);
}
crc_table[i] = s;
}
#endif
crc = ~crc;
for (U32 i = 0; i < size; ++i) {
crc = (crc >> 8) ^ crc_table[(ptr[i] ^ crc) & 0xff];
}
return ~crc;
}
internal U32
crc32_from_string(String8 string)
{
return update_crc32(0, string.str, string.size);
}
+8
View File
@@ -0,0 +1,8 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#pragma once
internal U32 update_crc32(U32 crc, U8 *ptr, U64 size);
internal U32 crc32_from_string(String8 string);
+12
View File
@@ -0,0 +1,12 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#include "base_core.c"
#include "base_strings.c"
#include "base_arena.c"
#include "base_math.c"
#include "base_arrays.c"
#include "base_bit_array.c"
#include "base_crc32.c"
#include "base_md5.c"
+15
View File
@@ -0,0 +1,15 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#pragma once
#include "base_core.h"
#include "base_strings.h"
#include "base_arena.h"
#include "base_math.h"
#include "base_arrays.h"
#include "base_blake3.h"
#include "base_bit_array.h"
#include "base_crc32.h"
#include "base_md5.h"
+19
View File
@@ -0,0 +1,19 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal void
rng_1u64_list_push_node(Rng1U64List *list, Rng1U64Node *node)
{
SLLQueuePush(list->first, list->last, node);
++list->count;
}
internal Rng1U64Node *
rng_1u64_list_push(Arena *arena, Rng1U64List *list, Rng1U64 range)
{
Rng1U64Node *node = push_array(arena, Rng1U64Node, 1);
node->v = range;
rng_1u64_list_push_node(list, node);
return node;
}
+23
View File
@@ -0,0 +1,23 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#pragma once
typedef struct Rng1U64Node
{
struct Rng1U64Node *next;
Rng1U64 v;
} Rng1U64Node;
typedef struct Rng1U64List
{
U64 count;
Rng1U64Node *first;
Rng1U64Node *last;
} Rng1U64List;
////////////////////////////////
internal void rng_1u64_list_push_node(Rng1U64List *list, Rng1U64Node *node);
internal Rng1U64Node * rng_1u64_list_push(Arena *arena, Rng1U64List *list, Rng1U64 range);
+12
View File
@@ -0,0 +1,12 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal MD5Hash
md5_hash_from_string(String8 data)
{
MD5_CTX ctx; MD5_Init(&ctx);
MD5_Update(&ctx, (void*)data.str, safe_cast_u32(data.size));
MD5Hash hash; MD5_Final((unsigned char*)&hash, &ctx);
return hash;
}
+12
View File
@@ -0,0 +1,12 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#pragma once
typedef struct MD5Hash
{
U8 value[16];
} MD5Hash;
internal MD5Hash md5_hash_from_string(String8 data);
+132
View File
@@ -0,0 +1,132 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal int
str8_compar(String8 a, String8 b, B32 ignore_case)
{
int cmp = 0;
U64 size = Min(a.size, b.size);
if (ignore_case) {
for (U64 i = 0; i < size; ++i) {
U8 la = char_to_lower(a.str[i]);
U8 lb = char_to_lower(b.str[i]);
if (la < lb) {
cmp = -1;
break;
} else if (la > lb) {
cmp = +1;
break;
}
}
} else {
for (U64 i = 0; i < size; ++i) {
if (a.str[i] < b.str[i]) {
cmp = -1;
break;
} else if (a.str[i] > b.str[i]) {
cmp = +1;
break;
}
}
}
if (cmp == 0) {
// shorter prefix must precede longer prefixes
if (a.size > b.size) {
cmp = +1;
} else if (b.size > a.size) {
cmp = -1;
}
}
return cmp;
}
internal int
str8_compar_ignore_case(const void *a, const void *b)
{
return str8_compar(*(String8*)a, *(String8*)b, 1);
}
internal int
str8_compar_case_sensitive(const void *a, const void *b)
{
return str8_compar(*(String8*)a, *(String8*)b, 0);
}
internal int
str8_is_before_case_sensitive(const void *a, const void *b)
{
int cmp = str8_compar_case_sensitive(a, b);
return cmp < 0;
}
internal String8Node *
str8_list_push_raw(Arena *arena, String8List *list, void *data_ptr, U64 data_size)
{
String8 data = str8((U8 *)data_ptr, data_size);
String8Node *node = str8_list_push(arena, list, data);
return node;
}
internal U64
str8_list_push_pad(Arena *arena, String8List *list, U64 offset, U64 align)
{
U64 pad_size = AlignPow2(offset, align) - offset;
U8 *pad = push_array(arena, U8, pad_size);
MemorySet(pad, 0, pad_size);
str8_list_push(arena, list, str8(pad, pad_size));
return pad_size;
}
internal U64
str8_list_push_pad_front(Arena *arena, String8List *list, U64 offset, U64 align)
{
U64 pad_size = AlignPow2(offset, align) - offset;
U8 *pad = push_array(arena, U8, pad_size);
MemorySet(pad, 0, pad_size);
str8_list_push_front(arena, list, str8(pad, pad_size));
return pad_size;
}
internal String8List
str8_list_arr_concat(String8List *v, U64 count)
{
String8List result = {0};
for (U64 i = 0; i < count; i += 1) {
str8_list_concat_in_place(&result, &v[i]);
}
return result;
}
internal String8Node *
str8_list_push_many(Arena *arena, String8List *list, U64 count)
{
String8Node *arr = push_array(arena, String8Node, count);
for (U64 i = 0; i < count; ++i) {
str8_list_push_node(list, arr + i);
}
return arr;
}
internal String8Node *
str8_list_pop_front(String8List *list)
{
String8Node *node = 0;
if (list->node_count) {
node = list->first;
Assert(list->total_size >= list->first->string.size);
list->node_count -= 1;
list->total_size -= list->first->string.size;
SLLQueuePop(list->first, list->last);
}
return node;
}
internal U64
hash_from_str8(String8 string)
{
XXH64_hash_t hash64 = XXH3_64bits(string.str, string.size);
return hash64;
}
+23
View File
@@ -0,0 +1,23 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#pragma once
#define MemoryCopyStr8(dst, s) MemoryCopy(dst, (s).str, (s).size)
internal int str8_compar(String8 a, String8 b, B32 ignore_case);
internal int str8_compar_ignore_case(const void *a, const void *b);
internal int str8_compar_case_sensitive(const void *a, const void *b);
#define str8_list_push_struct(a,l,d) str8_list_push_raw(a, l, d, sizeof(*d))
internal String8Node * str8_list_push_raw(Arena *arena, String8List *list, void *data_ptr, U64 data_size);
internal U64 str8_list_push_pad(Arena *arena, String8List *list, U64 offset, U64 align);
internal U64 str8_list_push_pad_front(Arena *arena, String8List *list, U64 offset, U64 align);
internal String8List str8_list_arr_concat(String8List *v, U64 count);
internal String8Node * str8_list_push_many(Arena *arena, String8List *list, U64 count);
// TODO: remove
internal String8Node * str8_list_pop_front(String8List *list);
internal U64 hash_from_str8(String8 string);
File diff suppressed because it is too large Load Diff
+584
View File
@@ -0,0 +1,584 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#pragma once
#define CV_MinComplexTypeIndex 0x1000
////////////////////////////////
// Aligns
#define CV_LeafAlign 4
#define CV_SymbolAlign 1
#define CV_C13SubSectionAlign 4
#define CV_FileCheckSumsAlign 4
////////////////////////////////
//- Symbol and Leaf Headers
#define CV_LeafSize_Max max_U16
typedef U16 CV_LeafSize;
#define CV_SymSize_Max max_U16
typedef U16 CV_SymSize;
typedef struct CV_LeafHeader
{
CV_LeafSize size;
CV_LeafKind kind;
} CV_LeafHeader;
typedef struct CV_SymbolHeader
{
CV_SymSize size;
CV_SymKind kind;
} CV_SymbolHeader;
////////////////////////////////
// Type Index Helpers
typedef enum CV_TypeIndexSource
{
CV_TypeIndexSource_NULL,
CV_TypeIndexSource_TPI,
CV_TypeIndexSource_IPI,
CV_TypeIndexSource_COUNT
} CV_TypeIndexSource;
typedef struct CV_TypeIndexInfo
{
struct CV_TypeIndexInfo *next;
U64 offset;
CV_TypeIndexSource source;
} CV_TypeIndexInfo;
typedef struct CV_TypeIndexInfoList
{
U64 count;
CV_TypeIndexInfo *first;
CV_TypeIndexInfo *last;
} CV_TypeIndexInfoList;
typedef struct CV_TypeIndexArray
{
U32 count;
CV_TypeIndex *v;
} CV_TypeIndexArray;
//- $$Symbols
typedef struct CV_Symbol
{
CV_SymKind kind;
U64 offset;
String8 data;
} CV_Symbol;
typedef struct CV_SymbolNode
{
struct CV_SymbolNode *next;
struct CV_SymbolNode *prev;
CV_Symbol data;
} CV_SymbolNode;
typedef struct CV_SymbolPtrNode
{
struct CV_SymbolPtrNode *next;
CV_Symbol *data;
} CV_SymbolPtrNode;
typedef struct CV_SymbolList
{
U64 count;
CV_Signature signature;
CV_SymbolNode *first;
CV_SymbolNode *last;
} CV_SymbolList;
typedef struct CV_SymbolListArray
{
U64 count;
CV_SymbolList *v;
} CV_SymbolListArray;
typedef struct CV_SymbolPtrArray
{
U64 count;
CV_SymbolNode **v;
} CV_SymbolPtrArray;
typedef struct CV_Scope
{
struct CV_ScopeList *children;
struct CV_Scope *next;
struct CV_Scope *prev;
CV_Symbol symbol;
} CV_Scope;
typedef struct CV_ScopeList
{
CV_Scope *first;
CV_Scope *last;
} CV_ScopeList;
typedef struct CV_ScopeFrame
{
struct CV_ScopeFrame *next;
CV_ScopeList *list;
CV_Scope *curr;
U64 symbol_off;
U32 *parent_off_ptr;
U32 *end_off_ptr;
} CV_ScopeFrame;
//- $$FileChksms
typedef struct CV_Checksum
{
CV_C13Checksum *header;
String8 value;
} CV_Checksum;
typedef struct CV_ChecksumNode
{
struct CV_ChecksumNode *next;
CV_Checksum data;
} CV_ChecksumNode;
typedef struct CV_ChecksumList
{
U64 count;
CV_ChecksumNode *first;
CV_ChecksumNode *last;
} CV_ChecksumList;
//- $$Lines
typedef struct CV_LineArray
{
U32 file_off;
U64 line_count;
U64 col_count;
U64 *voffs; // [line_count + 1]
U32 *line_nums; // [line_count]
U16 *col_nums; // [line_count * 2]
} CV_LineArray;
typedef struct CV_File
{
U32 file_off;
CV_LineArray lines;
} CV_File;
typedef struct CV_C13LinesHeader
{
U64 sec_idx;
U64 sec_off_lo;
U64 sec_off_hi;
U64 file_off;
U64 line_count;
U64 col_count;
U64 line_array_off;
U64 col_array_off;
} CV_C13LinesHeader;
typedef struct CV_C13LinesHeaderNode
{
struct CV_C13LinesHeaderNode *next;
CV_C13LinesHeader v;
} CV_C13LinesHeaderNode;
typedef struct CV_C13LinesHeaderList
{
CV_C13LinesHeaderNode *first;
CV_C13LinesHeaderNode *last;
U64 count;
} CV_C13LinesHeaderList;
////////////////////////////////
typedef struct CV_UDTInfo
{
String8 name;
String8 unique_name;
CV_TypeProps props;
} CV_UDTInfo;
typedef struct CV_TypeServerInfo
{
String8 name;
Guid sig;
U32 age;
} CV_TypeServerInfo;
typedef struct CV_TypeServerInfoNode
{
struct CV_TypeServerInfoNode *next;
CV_TypeServerInfo data;
} CV_TypeServerInfoNode;
typedef struct CV_TypeServerInfoList
{
CV_TypeServerInfoNode *first;
CV_TypeServerInfoNode *last;
U64 count;
} CV_TypeServerInfoList;
typedef struct CV_PrecompInfo
{
CV_TypeIndex start_index;
U32 sig;
U32 leaf_count;
String8 obj_name;
} CV_PrecompInfo;
typedef struct CV_ObjInfo
{
U32 sig;
String8 name;
} CV_ObjInfo;
////////////////////////////////
// Accels
typedef struct CV_Line
{
U64 voff;
U32 file_off;
U32 line_num;
U16 col_num;
} CV_Line;
typedef struct CV_LinesAccel
{
U64 map_count;
CV_Line *map;
} CV_LinesAccel;
typedef struct CV_InlineeLinesAccel
{
U64 bucket_count;
U64 bucket_max;
CV_C13InlineeLinesParsed **buckets;
} CV_InlineeLinesAccel;
typedef struct CV_InlineBinaryAnnotsParsed
{
U64 lines_count;
CV_LineArray *lines;
Rng1U64List code_ranges;
} CV_InlineBinaryAnnotsParsed;
typedef struct CV_C13InlineeLinesParsedList
{
CV_C13InlineeLinesParsedNode *first;
CV_C13InlineeLinesParsedNode *last;
U64 count;
} CV_C13InlineeLinesParsedList;
////////////////////////////////
typedef U32 CV_C13SubSectionIdxKind;
enum
{
CV_C13SubSectionIdxKind_NULL,
#define X(N,c) CV_C13SubSectionIdxKind_##N,
CV_C13SubSectionKindXList(X)
#undef X
CV_C13SubSectionIdxKind_COUNT
};
typedef struct CV_C13SubSectionList
{
CV_C13SubSectionNode *first;
CV_C13SubSectionNode *last;
U64 count;
} CV_C13SubSectionList;
////////////////////////////////
typedef struct CV_DebugS
{
String8List data_list[CV_C13SubSectionIdxKind_COUNT];
} CV_DebugS;
typedef struct CV_DebugT
{
U64 size;
U64 count;
U8 **v;
} CV_DebugT;
////////////////////////////////
//~ Leaf Helpers
typedef struct CV_Leaf
{
CV_LeafKind kind;
String8 data;
} CV_Leaf;
typedef struct CV_LeafNode
{
struct CV_LeafNode *next;
CV_Leaf data;
} CV_LeafNode;
typedef struct CV_LeafList
{
U64 count;
CV_LeafNode *first;
CV_LeafNode *last;
} CV_LeafList;
////////////////////////////////
//~ String Hash Table
typedef struct CV_StringTableRange
{
struct CV_StringTableRange *next;
Rng1U64 range;
U64 debug_s_idx;
} CV_StringTableRange;
typedef struct CV_StringBucket
{
String8 string;
union {
struct {
U32 idx0;
U32 idx1;
};
U64 offset;
} u;
} CV_StringBucket;
typedef struct CV_StringHashTable
{
U64 total_string_size;
U64 total_insert_count;
U64 bucket_cap;
CV_StringBucket **buckets;
} CV_StringHashTable;
typedef struct CV_StringHashTableResult
{
U64 string_count;
CV_StringBucket **buckets;
} CV_StringHashTableResult;
////////////////////////////////
//~ Task Contexts
typedef struct
{
U64 cap;
union {
CV_SymbolNode ***buckets;
CV_SymbolNode **deref_buckets;
} u;
Rng1U64 *ranges;
CV_SymbolNode **symbols;
} CV_SymbolDeduperTask;
typedef struct
{
CV_SymbolList *list_arr;
Rng1U64 *list_range_arr;
U64 *symbol_base_arr;
CV_SymbolNode **symbol_arr;
} CV_SymbolListSyncer;
typedef struct
{
CV_DebugS *arr;
CV_StringTableRange **range_lists;
U64 *string_counts;
U64 bucket_cap;
CV_StringBucket **buckets;
U64 total_string_size;
U64 total_insert_count;
} CV_DedupStringTablesTask;
typedef struct
{
U8 *buffer;
Rng1U64 *ranges;
CV_StringBucket **buckets;
} CV_PackStringHashTableTask;
typedef struct
{
CV_DebugT debug_t;
Rng1U64 *ranges;
String8List *lists;
String8Node *nodes;
} CV_Str8ListFromDebugT;
////////////////////////////////
// Type Index Helpers
internal CV_TypeIndexInfo * cv_symbol_type_index_info_push(Arena *arena, CV_TypeIndexInfoList *list, CV_TypeIndexSource source, U64 offset);
internal CV_TypeIndexInfoList cv_get_symbol_type_index_offsets(Arena *arena, CV_SymKind kind, String8 data);
internal CV_TypeIndexInfoList cv_get_leaf_type_index_offsets(Arena *arena, CV_LeafKind leaf_kind, String8 data);
internal CV_TypeIndexInfoList cv_get_inlinee_type_index_offsets(Arena *arena, String8 raw_data);
internal String8Array cv_get_data_around_type_indices(Arena *arena, CV_TypeIndexInfoList ti_list, String8 data);
internal CV_TypeIndexSource cv_type_index_source_from_leaf_kind(CV_LeafKind leaf_kind);
////////////////////////////////
internal U64 cv_name_offset_from_symbol(CV_SymKind kind, String8 data);
internal String8 cv_name_from_symbol (CV_SymKind kind, String8 data);
internal String8 cv_name_from_udt_info (CV_UDTInfo udt_info);
internal B32 cv_is_udt_name_anon (String8 name);
internal B32 cv_is_udt (CV_LeafKind kind);
internal B32 cv_is_global_symbol (CV_SymKind kind);
internal B32 cv_is_typedef (CV_SymKind kind);
internal B32 cv_is_scope_symbol (CV_SymKind kind);
internal B32 cv_is_end_symbol (CV_SymKind kind);
internal B32 cv_is_leaf_type_server(CV_LeafKind kind);
internal B32 cv_is_leaf_pch (CV_LeafKind kind);
internal CV_ObjInfo cv_obj_info_from_symbol(CV_Symbol symbol);
internal CV_TypeServerInfo cv_type_server_info_from_leaf(CV_Leaf leaf);
internal CV_PrecompInfo cv_precomp_info_from_leaf(CV_Leaf leaf);
internal B32 cv_is_reg_sp(CV_Arch arch, CV_Reg reg);
////////////////////////////////
//~ Leaf Helpers
internal U64 cv_compute_leaf_record_size(String8 data, U64 align);
internal U64 cv_serialize_leaf_to_buffer(U8 *buffer, U64 buffer_cursor, U64 buffer_size, CV_LeafKind kind, String8 data, U64 align);
internal String8 cv_serialize_leaf_ex(Arena *arena, CV_LeafKind kind, String8 data, U64 align);
internal String8 cv_serialize_leaf(Arena *arena, CV_Leaf *leaf, U64 align);
internal CV_Leaf cv_make_leaf(Arena *arena, CV_LeafKind kind, String8 data);
internal U64 cv_deserial_leaf(String8 raw_data, U64 off, U64 align, CV_Leaf *leaf_out);
internal CV_Leaf cv_leaf_from_string(String8 raw_data);
////////////////////////////////
//~ Symbol Helpers
internal U64 cv_compute_symbol_record_size(CV_Symbol *symbol, U64 align);
internal U64 cv_serialize_symbol_to_buffer(U8 *buffer, U64 buffer_cursor, U64 buffer_size, CV_Symbol *symbol, U64 align);
internal String8 cv_serialize_symbol(Arena *arena, CV_Symbol *symbol, U64 align);
internal String8 cv_make_symbol(Arena *arena, CV_SymKind kind, String8 data);
internal String8 cv_make_obj_name(Arena *arena, String8 obj_path, U32 sig);
internal String8 cv_make_comp3(Arena *arena,
CV_Compile3Flags flags, CV_Language lang, CV_Arch arch,
U16 ver_fe_major, U16 ver_fe_minor, U16 ver_fe_build, U16 ver_feqfe,
U16 ver_major, U16 ver_minor, U16 ver_build, U16 ver_qfe,
String8 version_string);
internal String8 cv_make_envblock(Arena *arena, String8List string_list);
internal CV_Symbol cv_make_proc_ref(Arena *arena, CV_ModIndex imod, U32 stream_offset, String8 name, B32 is_local);
internal CV_Symbol cv_make_pub32(Arena *arena, CV_Pub32Flags flags, U32 off, U16 isect, String8 name);
internal CV_SymbolList cv_make_proc_refs(Arena *arena, CV_ModIndex imod, CV_SymbolList symbol_list);
////////////////////////////////
// .debug$S Helpers
internal CV_DebugS cv_parse_debug_s_c13(Arena *arena, String8 raw_debug_s);
internal CV_DebugS cv_parse_debug_s_c13_list(Arena *arena, String8List raw_debug_s);
internal CV_DebugS cv_parse_debug_s(Arena *arena, String8 raw_debug_s);
internal void cv_debug_s_concat_in_place(CV_DebugS *dst, CV_DebugS *src);
internal String8List cv_data_c13_from_debug_s(Arena *arena, CV_DebugS *debug_s, B32 write_sig);
internal CV_C13SubSectionIdxKind cv_c13_sub_section_idx_from_kind(CV_C13SubSectionKind kind);
internal String8List * cv_sub_section_ptr_from_debug_s(CV_DebugS *debug_s, CV_C13SubSectionKind kind);
internal String8List cv_sub_section_from_debug_s(CV_DebugS debug_s, CV_C13SubSectionKind kind);
internal String8 cv_string_table_from_debug_s(CV_DebugS debug_s);
internal String8 cv_file_chksms_from_debug_s(CV_DebugS debug_s);
////////////////////////////////
//~ .debug$T helpers
internal CV_DebugT cv_debug_t_from_data_arr(Arena *arena, String8Array data_arr, U64 align);
internal CV_DebugT cv_debug_t_from_data(Arena *arena, String8 data, U64 align);
internal CV_Leaf cv_debug_t_get_leaf(CV_DebugT debug_t, U64 leaf_idx);
internal String8 cv_debug_t_get_raw_leaf(CV_DebugT debug_t, U64 leaf_idx);
internal CV_LeafHeader * cv_debug_t_get_leaf_header(CV_DebugT debug_t, U64 leaf_idx);
internal B32 cv_debug_t_is_pch(CV_DebugT debug_t);
internal B32 cv_debug_t_is_type_server(CV_DebugT debug_t);
internal U64 cv_debug_t_array_count_leaves(U64 count, CV_DebugT *arr);
internal String8List cv_str8_list_from_debug_t_parallel(TP_Context *tp, Arena *arena, CV_DebugT types);
// $$Symbols
internal void cv_parse_symbol_sub_section(Arena *arena, CV_SymbolList *list, U64 offset_base, String8 data, U64 align);
internal void cv_symbol_list_push_node(CV_SymbolList *list, CV_SymbolNode *node);
internal CV_SymbolNode * cv_symbol_list_push(Arena *arena, CV_SymbolList *list);
internal CV_SymbolNode * cv_symbol_list_push_data(Arena *arena, CV_SymbolList *list, CV_SymKind kind, String8 data);
internal CV_SymbolNode * cv_symbol_list_push_many(Arena *arena, CV_SymbolList *list, U64 count);
internal void cv_symbol_list_remove_node(CV_SymbolList *list, CV_SymbolNode *node);
internal void cv_symbol_list_concat_in_place(CV_SymbolList *list, CV_SymbolList *to_concat);
internal void cv_symbol_list_concat_in_place_arr(CV_SymbolList *list, U64 count, CV_SymbolList *to_concat);
internal U64 cv_symbol_list_arr_get_count(U64 count, CV_SymbolList *list_arr);
internal String8List cv_data_from_symbol_list(Arena *arena, CV_SymbolList symbol_list, U64 align);
internal CV_SymbolList cv_global_scope_symbols_from_list(Arena *arena, CV_SymbolList list);
internal CV_ScopeList cv_symbol_tree_from_symbol_list(Arena *arena, CV_SymbolList list);
internal CV_SymbolList cv_build_symbol_tree(Arena *arena, CV_ScopeList symbol_tree, U64 symbol_base, U64 align);
internal CV_SymbolPtrArray cv_symbol_ptr_array_from_list(Arena *arena, TP_Context *tp, U64 count, CV_SymbolList *symbol_list_arr);
// $$FileChksms
#define CV_MAP_STRING_TO_OFFSET_FUNC(name) U64 name(void *ud, String8 string)
typedef CV_MAP_STRING_TO_OFFSET_FUNC(CV_MapStringToOffsetFunc);
//internal String8 cv_c13_file_chksms_from_sub_sections(String8 c13_data, CV_C13Parsed *ss);
internal void cv_c13_patch_string_offsets_in_checksum_list(CV_ChecksumList checksum_list, String8 string_data, U64 string_data_base_offset, CV_StringHashTable string_ht);
internal String8List cv_c13_collect_source_file_names(Arena *arena, CV_ChecksumList checksum_list, String8 string_data);
// $$Lines
internal CV_C13LinesHeaderList cv_c13_lines_from_sub_sections(Arena *arena, String8 c13_data, Rng1U64 ss_range);
internal CV_LineArray cv_c13_line_array_from_data(Arena *arena, String8 c13_data, U64 sec_base, CV_C13LinesHeader parsed_lines);
// $$InlineeLines
internal CV_C13InlineeLinesParsedList cv_c13_inlinee_lines_from_sub_sections(Arena *arena, String8List raw_inlinee_lines);
internal CV_InlineBinaryAnnotsParsed cv_c13_parse_inline_binary_annots(Arena *arena, U64 parent_voff, CV_C13InlineeLinesParsed *inlinee_parsed, String8 binary_annots);
// $$FrameData
internal void cv_c13_patch_checksum_offsets_in_frame_data_list(String8List frame_data, U32 checksum_rebase);
////////////////////////////////
// $$Lines Accel
internal void cv_make_c13_files(Arena *arena, String8 c13_data, CV_C13SubSectionList lines, U64 *file_count_out, CV_C13File **files_out);
internal CV_LinesAccel * cv_make_lines_accel(Arena *arena, U64 lines_count, CV_LineArray *lines);
internal CV_Line * cv_line_from_voff(CV_LinesAccel *accel, U64 voff, U64 *out_line_count);
////////////////////////////////
// $$InlineeLines Accel
internal U64 cv_c13_inlinee_lines_accel_hash(void *buffer, U64 size);
internal B32 cv_c13_inlinee_lines_accel_push(CV_InlineeLinesAccel *accel, CV_C13InlineeLinesParsed *parsed);
internal CV_C13InlineeLinesParsed * cv_c13_inlinee_lines_accel_find(CV_InlineeLinesAccel *accel, CV_ItemId inlinee);
internal CV_InlineeLinesAccel * cv_c13_make_inlinee_lines_accel(Arena *arena, CV_C13InlineeLinesParsedList sub_sects);
////////////////////////////////
// String Hash Table
internal U64 cv_string_hash_table_hash(String8 string);
internal CV_StringHashTable cv_dedup_string_tables(TP_Arena *arena, TP_Context *tp, U64 count, CV_DebugS *arr);
internal CV_StringHashTableResult cv_serialize_string_hash_table(Arena *arena, TP_Context *tp, CV_StringHashTable string_ht);
internal String8 cv_pack_string_hash_table(Arena *arena, TP_Context *tp, CV_StringHashTable string_ht);
////////////////////////////////
internal CV_EncodedFramePtrReg cv_pick_fp_encoding(CV_SymFrameproc *frameproc, B32 is_local_param);
internal CV_Reg cv_decode_fp_reg(CV_Arch arch, CV_EncodedFramePtrReg encoded_reg);
internal Rng1U64List cv_make_defined_range_list_from_gaps(Arena *arena, Rng1U64 defrange, CV_LvarAddrGap *gaps, U64 gap_count);
////////////////////////////////
internal U64 cv_size_from_reg_x86(CV_Reg reg);
internal U64 cv_size_from_reg_x64(CV_Reg reg);
internal U64 cv_size_from_reg(CV_Arch arch, CV_Reg reg);
////////////////////////////////
internal CV_Arch cv_arch_from_coff_machine(COFF_MachineType machine);
internal String8 cv_string_from_type_index_source(CV_TypeIndexSource ti_source);
+270
View File
@@ -0,0 +1,270 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal void
bucket_list_concat_in_place(BucketList *list, BucketList *to_concat)
{
SLLConcatInPlaceNoCount(list, to_concat);
}
internal BucketNode *
bucket_list_pop(BucketList *list)
{
BucketNode *result = list->first;
SLLQueuePop(list->first, list->last);
return result;
}
////////////////////////////////
internal U64
hash_table_hasher(String8 string)
{
XXH64_hash_t hash64 = XXH3_64bits(string.str, string.size);
return hash64;
}
internal HashTable *
hash_table_init(Arena *arena, U64 cap)
{
HashTable *ht = push_array(arena, HashTable, 1);
ht->cap = cap;
ht->buckets = push_array(arena, BucketList, cap);
return ht;
}
internal void
hash_table_purge(HashTable *ht)
{
// reset key count
ht->count = 0;
// concat buckets
for (U64 ibucket = 0; ibucket < ht->cap; ++ibucket) {
bucket_list_concat_in_place(&ht->free_buckets, &ht->buckets[ibucket]);
}
}
internal BucketNode *
hash_table_push(Arena *arena, HashTable *ht, U64 hash, KeyValuePair v)
{
BucketNode *node;
if (ht->free_buckets.first != 0) {
node = bucket_list_pop(&ht->free_buckets);
} else {
node = push_array(arena, BucketNode, 1);
}
node->next = 0;
node->v = v;
U64 ibucket = hash % ht->cap;
SLLQueuePush(ht->buckets[ibucket].first, ht->buckets[ibucket].last, node);
++ht->count;
return node;
}
internal BucketNode *
hash_table_push_string_string(Arena *arena, HashTable *ht, String8 key, String8 value)
{
U64 hash = hash_table_hasher(key);
return hash_table_push(arena, ht, hash, (KeyValuePair){ .key_string = key, .value_string = value });
}
internal BucketNode *
hash_table_push_string_raw(Arena *arena, HashTable *ht, String8 key, void *value)
{
U64 hash = hash_table_hasher(key);
return hash_table_push(arena, ht, hash, (KeyValuePair){ .key_string = key, .value_raw = value });
}
internal BucketNode *
hash_table_push_string_u64(Arena *arena, HashTable *ht, String8 key, U64 value)
{
U64 hash = hash_table_hasher(key);
return hash_table_push(arena, ht, hash, (KeyValuePair){.key_string = key, .value_u64 = value });
}
internal BucketNode *
hash_table_push_u32_raw(Arena *arena, HashTable *ht, U32 key, void *value)
{
U64 hash = hash_table_hasher(str8_struct(&key));
return hash_table_push(arena, ht, hash, (KeyValuePair){ .key_u32 = key, .value_raw = value });
}
internal BucketNode *
hash_table_push_u32_string(Arena *arena, HashTable *ht, U32 key, String8 value)
{
U64 hash = hash_table_hasher(str8_struct(&key));
return hash_table_push(arena, ht, hash, (KeyValuePair){ .key_u32 = key, .value_string = value });
}
internal BucketNode *
hash_table_push_u64_raw(Arena *arena, HashTable *ht, U64 key, void *value)
{
U64 hash = hash_table_hasher(str8_struct(&key));
return hash_table_push(arena, ht, hash, (KeyValuePair){ .key_u64 = key, .value_raw = value });
}
internal BucketNode *
hash_table_push_u64_string(Arena *arena, HashTable *ht, U64 key, String8 value)
{
U64 hash = hash_table_hasher(str8_struct(&key));
return hash_table_push(arena, ht, hash, (KeyValuePair){ .key_u64 = key, .value_string = value });
}
internal BucketNode *
hash_table_push_u64_u64(Arena *arena, HashTable *ht, U64 key, U64 value)
{
U64 hash = hash_table_hasher(str8_struct(&key));
return hash_table_push(arena, ht, hash, (KeyValuePair){ .key_u64 = key, .value_u64 = value });
}
internal BucketNode *
hash_table_push_path_string(Arena *arena, HashTable *ht, String8 path, String8 value)
{
String8 path_canon = path_canon_from_regular_path(arena, path);
return hash_table_push_string_string(arena, ht, path_canon, value);
}
internal BucketNode *
hash_table_push_path_u64(Arena *arena, HashTable *ht, String8 path, U64 value)
{
String8 path_canon = path_canon_from_regular_path(arena, path);
U64 hash = hash_table_hasher(path_canon);
return hash_table_push(arena, ht, hash, (KeyValuePair){ .key_string = path_canon, .value_u64 = value });
}
internal BucketNode *
hash_table_push_path_raw(Arena *arena, HashTable *ht, String8 path, void *value)
{
String8 path_canon = path_canon_from_regular_path(arena, path);
U64 hash = hash_table_hasher(path_canon);
return hash_table_push(arena, ht, hash, (KeyValuePair){ .key_string = path_canon, .value_raw = value });
}
////////////////////////////////
internal KeyValuePair *
hash_table_search_string(HashTable *ht, String8 key_string)
{
U64 hash = hash_table_hasher(key_string);
U64 ibucket = hash % ht->cap;
BucketList *bucket = ht->buckets + ibucket;
for (BucketNode *n = bucket->first; n != 0; n = n->next) {
if (str8_match(n->v.key_string, key_string, 0)) {
return &n->v;
}
}
return 0;
}
internal KeyValuePair *
hash_table_search_u32(HashTable *ht, U32 key_u32)
{
U64 hash = hash_table_hasher(str8_struct(&key_u32));
U64 ibucket = hash % ht->cap;
BucketList *bucket = ht->buckets + ibucket;
for (BucketNode *n = bucket->first; n != 0; n = n->next) {
if (n->v.key_u32 == key_u32) {
return &n->v;
}
}
return 0;
}
internal KeyValuePair *
hash_table_search_u64(HashTable *ht, U64 key_u64)
{
U64 hash = hash_table_hasher(str8_struct(&key_u64));
U64 ibucket = hash % ht->cap;
BucketList *bucket = ht->buckets + ibucket;
for (BucketNode *n = bucket->first; n != 0; n = n->next) {
if (n->v.key_u64 == key_u64) {
return &n->v;
}
}
return 0;
}
internal KeyValuePair *
hash_table_search_path(HashTable *ht, String8 path)
{
Temp scratch = scratch_begin(0,0);
String8 path_canon = path;
path_canon = lower_from_str8(scratch.arena, path_canon);
path_canon = path_convert_slashes(scratch.arena, path_canon, PathStyle_UnixAbsolute);
KeyValuePair *result = hash_table_search_string(ht, path_canon);
scratch_end(scratch);
return result;
}
internal B32
hash_table_search_path_u64(HashTable *ht, String8 key, U64 *value_out)
{
KeyValuePair *result = hash_table_search_path(ht, key);
if (result != 0) {
if (value_out != 0) {
*value_out = result->value_u64;
}
return 1;
}
return 0;
}
internal B32
hash_table_search_string_u64(HashTable *ht, String8 key, U64 *value_out)
{
KeyValuePair *result = hash_table_search_string(ht, key);
if (result != 0) {
if (value_out != 0) {
*value_out = result->value_u64;
}
return 1;
}
return 0;
}
////////////////////////////////
internal int
key_value_pair_is_before_u32(void *raw_a, void *raw_b)
{
KeyValuePair *a = raw_a;
KeyValuePair *b = raw_b;
return a->key_u32 < b->key_u32;
}
internal int
key_value_pair_is_before_u64(void *raw_a, void *raw_b)
{
KeyValuePair *a = raw_a;
KeyValuePair *b = raw_b;
return a->key_u64 < b->key_u64;
}
internal KeyValuePair *
key_value_pairs_from_hash_table(Arena *arena, HashTable *ht)
{
KeyValuePair *pairs = push_array_no_zero(arena, KeyValuePair, ht->count);
for (U64 bucket_idx = 0, cursor = 0; bucket_idx < ht->cap; ++bucket_idx) {
for (BucketNode *n = ht->buckets[bucket_idx].first; n != 0; n = n->next) {
Assert(cursor < ht->count);
pairs[cursor++] = n->v;
}
}
return pairs;
}
internal void
sort_key_value_pairs_as_u32(KeyValuePair *pairs, U64 count)
{
radsort(pairs, count, key_value_pair_is_before_u32);
}
internal void
sort_key_value_pairs_as_u64(KeyValuePair *pairs, U64 count)
{
radsort(pairs, count, key_value_pair_is_before_u64);
}
+81
View File
@@ -0,0 +1,81 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#pragma once
typedef struct KeyValuePair
{
union {
String8 key_string;
U32 key_u32;
U64 key_u64;
};
union {
String8 value_string;
void *value_raw;
U32 value_u32;
U64 value_u64;
};
} KeyValuePair;
typedef struct BucketNode
{
struct BucketNode *next;
KeyValuePair v;
} BucketNode;
typedef struct BucketList
{
BucketNode *first;
BucketNode *last;
} BucketList;
typedef struct HashTable
{
U64 count;
U64 cap;
BucketList *buckets;
BucketList free_buckets;
} HashTable;
////////////////////////////////
//- bucket list helpers
internal void bucket_list_concat_in_place(BucketList *list, BucketList *to_concat);
internal BucketNode * bucket_list_pop(BucketList *list);
//- main
internal U64 hash_table_hasher(String8 string);
internal HashTable * hash_table_init(Arena *arena, U64 cap);
internal void hash_table_purge(HashTable *ht);
//- push
internal BucketNode * hash_table_push (Arena *arena, HashTable *ht, U64 hash, KeyValuePair v);
internal BucketNode * hash_table_push_u32_string (Arena *arena, HashTable *ht, U32 key, String8 value);
internal BucketNode * hash_table_push_u64_string (Arena *arena, HashTable *ht, U64 key, String8 value);
internal BucketNode * hash_table_push_string_string(Arena *arena, HashTable *ht, String8 key, String8 value);
internal BucketNode * hash_table_push_path_string (Arena *arena, HashTable *ht, String8 key, String8 value);
internal BucketNode * hash_table_push_u32_raw (Arena *arena, HashTable *ht, U32 key, void *value);
internal BucketNode * hash_table_push_u64_raw (Arena *arena, HashTable *ht, U64 key, void *value);
internal BucketNode * hash_table_push_path_raw (Arena *arena, HashTable *ht, String8 path, void *value);
internal BucketNode * hash_table_push_path_u64 (Arena *arena, HashTable *ht, String8 path, U64 value);
internal BucketNode * hash_table_push_u64_u64 (Arena *arena, HashTable *ht, U64 key, U64 value);
//- search
internal KeyValuePair * hash_table_search_string (HashTable *ht, String8 string);
internal KeyValuePair * hash_table_search_u32 (HashTable *ht, U32 key);
internal KeyValuePair * hash_table_search_u64 (HashTable *ht, U64 key);
internal KeyValuePair * hash_table_search_path (HashTable *ht, String8 path);
internal B32 hash_table_search_path_u64(HashTable *ht, String8 key, U64 *value_out);
//- key-value helpers
internal KeyValuePair * key_value_pairs_from_hash_table(Arena *arena, HashTable *ht);
internal void sort_key_value_pairs_as_u32(KeyValuePair *pairs, U64 count);
internal void sort_key_value_pairs_as_u64(KeyValuePair *pairs, U64 count);
+107
View File
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="LNK_Section">
<DisplayString>{{ name={name} flags={flags} id={id} sort_index={sort_index} }}</DisplayString>
</Type>
<Type Name="U32Array">
<AlternativeType Name="U64Array"/>
<Expand>
<Item Name="[count]">count</Item>
<ArrayItems>
<Size>count</Size>
<ValuePointer>v</ValuePointer>
</ArrayItems>
</Expand>
</Type>
<Type Name="LNK_SymbolList">
<AlternativeType Name="LNK_SectionList"/>
<AlternativeType Name="LNK_ChunkList"/>
<AlternativeType Name="CV_SymbolList"/>
<DisplayString>{{count={count} first={first} last={last} }}</DisplayString>
<Expand>
<LinkedListItems>
<Size>count</Size>
<HeadPointer>first</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>data</ValueNode>
</LinkedListItems>
</Expand>
</Type>
<Type Name="Rng1U64List">
<DisplayString>{{count={count} first={first} last={last} }}</DisplayString>
<Expand>
<LinkedListItems>
<Size>count</Size>
<HeadPointer>first</HeadPointer>
<NextPointer>next</NextPointer>
<ValueNode>v</ValueNode>
</LinkedListItems>
</Expand>
</Type>
<Type Name="RDIB_LineTable">
<DisplayString>{{count={count} first={first} last={last} }}</DisplayString>
<Expand>
<Item Name="[count]">count</Item>
<LinkedListItems>
<Size>count</Size>
<HeadPointer>first</HeadPointer>
<NextPointer>next_line_table</NextPointer>
<ValueNode>this</ValueNode>
</LinkedListItems>
</Expand>
</Type>
<Type Name="RDIB_VariableChunkList">
<AlternativeType Name="RDIB_UnitChunkList"/>
<AlternativeType Name="RDIB_LineTableChunkList"/>
<AlternativeType Name="RDIB_SourceFileChunkList"/>
<AlternativeType Name="RDIB_ProcedureChunkList"/>
<AlternativeType Name="RDIB_ScopeChunkList"/>
<AlternativeType Name="RDIB_InlineSiteChunkList"/>
<AlternativeType Name="RDIB_UDTMemberChunkList"/>
<AlternativeType Name="RDIB_TypeChunkList"/>
<Expand>
<Item Name="[chunk count]">count</Item>
<CustomListItems MaxItemsPerView="5000">
<Variable Name="node" InitialValue="first"/>
<Variable Name="idx" InitialValue="0"/>
<Loop>
<Break Condition="node == 0"/>
<Exec>idx = 0</Exec>
<Loop>
<Break Condition="idx >= node->count"/>
<Item>node->v[idx]</Item>
<Exec>idx += 1</Exec>
</Loop>
<Exec>node = node->next</Exec>
</Loop>
</CustomListItems>
</Expand>
</Type>
<Type Name="RDIB_VariableChunk">
<AlternativeType Name="RDIB_UnitChunk"/>
<AlternativeType Name="RDIB_LineTableChunk"/>
<AlternativeType Name="RDIB_SourceFileChunk"/>
<AlternativeType Name="RDIB_ProcedureChunk"/>
<AlternativeType Name="RDIB_ScopeChunk"/>
<AlternativeType Name="RDIB_InlineSiteChunk"/>
<AlternativeType Name="RDIB_UDTMemberChunk"/>
<AlternativeType Name="RDIB_TypeChunk"/>
<DisplayString>{count,cap,v}</DisplayString>
<Expand>
<Item Name="[base]">base</Item>
<Item Name="[count]">count</Item>
<Item Name="[cap]">cap</Item>
<ArrayItems>
<Size>count</Size>
<ValuePointer>v</ValuePointer>
</ArrayItems>
</Expand>
</Type>
</AutoVisualizer>
+4321
View File
File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More