1825 Commits
Author SHA1 Message Date
ed 57252a8e29 Merge tag 'v0.9.24-alpha' 2025-10-23 23:36:21 -04:00
Ryan Fleury c0d28e0ced only retry call stacks on stale / gen tears, *not* on errored frames. 2025-10-23 17:41:49 -07:00
Ryan Fleury e6c3942ed3 artifact_cache: keep access points that we're waiting for up-to-date, even if we don't get the result, so that they are not prematurely cancelled. 2025-10-23 17:16:13 -07:00
Ryan Fleury 980c5a4c21 notes 2025-10-23 16:58:10 -07:00
Ryan Fleury b1a91b8247 adjust expiration timeouts for searches; fix unnecessary lowercasing when generating paths from pdbs 2025-10-23 16:41:08 -07:00
Ryan Fleury 7a5784b5f0 notes 2025-10-23 16:21:12 -07:00
Ryan Fleury 766d7176c4 cycle linked list test in mule 2025-10-23 16:13:07 -07:00
Ryan Fleury 4053329d65 fix incorrect list link read 2025-10-23 16:09:44 -07:00
Ryan Fleury e88a59a57e mask off bad conversion task launches 2025-10-23 15:58:00 -07:00
Ryan Fleury 5a93f5d4cb clean up drop completion, provide paths for debug info drop completion 2025-10-23 15:37:34 -07:00
Ryan Fleury ae17084b44 better artifact cache cancellation thread work organization - only do more frequent cancellation scans when in a tick, otherwise sleep 2025-10-23 14:39:44 -07:00
Ryan Fleury 721649b7ea tweak process working set size placement 2025-10-23 14:14:48 -07:00
Ryan Fleury 1d8abb1906 switch to tighter cache for loaded debug infos 2025-10-23 13:55:51 -07:00
Ryan Fleury c318c10486 pipe through guids in rdi conversion; sketch out 'query' meta cfg evaluation members, which are not stored but computed, but are not sets; plug in debug info guid evaluation that way 2025-10-23 12:10:23 -07:00
Ryan Fleury e83a95f370 relax background timeout 2025-10-23 11:11:34 -07:00
Ryan Fleury b33a257bc4 switch eval viz stringification, and lister completions, over to working correctly with process-less (but not debug-info-less) evaluations 2025-10-22 16:59:24 -07:00
Ryan Fleury c8c25c0f98 processless debug info loading/unloading; separate modules from dbg infos in eval; keep dbg infos around after debugging via config, correllate to new modules, evict when necessary, when generating new versions 2025-10-22 16:39:29 -07:00
Ryan Fleury f9d1ffa5fc look up lowercased file paths in pdb disqualification path as well as normally cased paths 2025-10-21 11:54:34 -07:00
Ryan Fleury cf856524c1 reflect dpi change events appropriately in font size / window pos & size 2025-10-20 17:42:34 -07:00
Ryan Fleury f2d28045fa fix incorrect clip in ui hover 2025-10-20 17:07:36 -07:00
Ryan Fleury 08698d739d do not use full escaping path for cli args - does not correctly match command line behavior 2025-10-20 16:35:04 -07:00
Ryan Fleury 09418f1b08 pipe member finding errors through correctly 2025-10-20 16:30:59 -07:00
Ryan Fleury 2ad3e5b1cf allow . and -> for array types 2025-10-20 16:28:07 -07:00
Ryan Fleury c921645043 fix signed shifts in raddbg_markup utf8 decoding; fix quoting of argument strings with spaces in command line target builds 2025-10-20 16:19:22 -07:00
Ryan Fleury b371bff6f2 do not skip basic itypes when building type building dependency chains! 2025-10-20 14:52:10 -07:00
Mārtiņš Možeiko 6589cbe374 update third_party/martins_hash with latest code 2025-10-20 14:45:09 -07:00
Ryan Fleury 4bc6240ac0 actually record hit offsets in linked list gathering artifact creation! 2025-10-20 13:45:14 -07:00
Ryan Fleury 36fadc3b95 need null check, if match is cancelled 2025-10-17 14:24:24 -07:00
Ryan Fleury 2eba506897 cancellation on match tasks - keep wide matches longer 2025-10-17 14:13:20 -07:00
Ryan Fleury 6bf2d2abb1 artifact cache cancellation mechanism - use in dbgi searching, since this gets huge (& is often not needed quickly after querying) 2025-10-17 14:10:51 -07:00
ed beeba835d6 Merge tag 'v0.9.23-alpha' 2025-10-17 11:42:36 -04:00
Ryan Fleury 0d8590a2f2 bump to 24 2025-10-17 08:01:19 -07:00
Ryan Fleury f5b9443636 notes 2025-10-17 07:44:49 -07:00
Ryan Fleury a96c822440 use process handles in list evaluations rather than spaces - we will need to upgrade this once eval has been upgraded 2025-10-17 07:37:36 -07:00
Ryan Fleury 52680a81fe require data field members when looking for links w/ list lens; config node ptr lists need dll 2025-10-16 15:57:43 -07:00
Ryan Fleury 0f277d6e6e float panels into config layer 2025-10-16 15:26:07 -07:00
Ryan Fleury 7844761748 float keymaps into config 2025-10-16 15:19:18 -07:00
Ryan Fleury 2f315911a5 switch off rd_cfg to cfg layer 2025-10-16 15:00:13 -07:00
Ryan Fleury 46634f547f remove old frame call stack tree cache - supplanted by artifact cache 2025-10-16 14:08:50 -07:00
Ryan Fleury edb1863020 rd_cfgid -> cfg_id 2025-10-16 14:06:12 -07:00
Ryan Fleury 05e096d8b7 further port of rd cfg 2025-10-16 13:56:26 -07:00
Ryan Fleury 78c8aeaf4c config layer schemas 2025-10-16 12:18:29 -07:00
Ryan Fleury 02c7aaec85 progress on config layer untangled from debugger frontend, to do eval on config on ctrl or async threads; turn off metaprogram by default 2025-10-16 12:02:06 -07:00
Ryan Fleury 8dbfa97c71 adjust list lens member picking rules - use default argument, then fall back to next, prev, or the first pointer to an identical type 2025-10-16 11:10:00 -07:00
Ryan Fleury a2522c00fa tweak debug info conversion balancing - we want to give a bit more to debuggees... 2025-10-16 10:33:53 -07:00
Ryan Fleury 891eaec5cb bucket active conversion tasks by priority; adjust thread cap for bg conversion processes, don't flood cores with work while target is doing things 2025-10-15 17:56:10 -07:00
Ryan Fleury 410837d26d key list gather artifact lookups by space gen 2025-10-15 16:44:30 -07:00
Ryan Fleury ac9d6e861c first pass at list view, w/ asynchronous offset chain gathering 2025-10-15 16:33:59 -07:00
Ryan Fleury 25beda50ca mask off more work based on subset flags from baker 2025-10-15 15:44:04 -07:00
Ryan Fleury d9d321c074 mask off name map builds 2025-10-15 15:34:08 -07:00
Ryan Fleury d6a7c8bd00 adjust chunk sizes for per-sym-stream symbol chunk lists 2025-10-15 15:21:42 -07:00
Ryan Fleury 9377efbe13 eliminate rest of p2r_shared usage, just use lane syncs 2025-10-15 14:21:32 -07:00
Ryan Fleury d347e2473b eliminate most reliance on p2r_shared for shared data - isolate scratch allocations, pull into scratch arenas, pop when possible 2025-10-15 14:07:42 -07:00
Ryan Fleury 80b6744673 move more scratch artifacts to scratch lifetimes 2025-10-15 12:01:40 -07:00
Ryan Fleury 1d9870c1f9 rdi string baking, name map baking, idx run baking: put temporary per-lane artifacts/maps onto scratch & pop - reduce permanent memory usage 2025-10-15 11:55:45 -07:00
Ryan Fleury 5cc9d9ae89 remove new marker 2025-10-14 16:37:47 -07:00
Ryan Fleury c7d0a3431b eliminate old vmap baking 2025-10-14 16:35:24 -07:00
Ryan Fleury b757762908 plug in new vmap baking 2025-10-14 16:34:51 -07:00
Ryan Fleury feb5249f47 first pass at faster & simplified vmap baking: sort ranges by both base voff *and* size, generate vmap directly from sorted ranges w/ stack machine; avoid quadratic pop 2025-10-14 16:02:47 -07:00
Ryan Fleury 0d06b7d2d2 regrel32: interpret rbp-relative offsets as potential parameters as well (this only shows up with /ZI - usually everything is rsp-relative) 2025-10-14 10:13:44 -07:00
Ryan Fleury 92517ef2d7 re-enable single-step on empty trap net, if no line info is present 2025-10-14 10:00:31 -07:00
Ryan Fleury 010825a0bb checkpoint on attempt at wide vmap baking 2025-10-13 17:32:53 -07:00
Ryan Fleury 89be41fda9 checkpoint: first pass at wide vmap baking 2025-10-13 17:00:01 -07:00
Ryan Fleury b688c69f13 radbin: compress sections wide, deduplicate work 2025-10-13 13:07:37 -07:00
Ryan Fleury ec39cefc9e correctly decompress rdis in radbin dumping path; do not compress zero-sized sections in rdi make 2025-10-13 12:47:46 -07:00
Ryan Fleury 87edc583bf define ctrl entity eval spaces once, in ctrl layer - nest in rd layer 2025-10-13 12:40:28 -07:00
Ryan Fleury 6bcbf5909d correctly handle bitfield type operators in eval viz string iterator 2025-10-13 11:23:49 -07:00
ed 84cb0f0a44 Merge remote-tracking branch 'EpicGamesExt/master' 2025-10-10 21:50:09 -04:00
ed 5c1c44d46e ignore vscode settings 2025-10-10 21:50:02 -04:00
Ryan Fleury b41bf5b39e update readme 2025-10-10 16:20:34 -07:00
Ryan Fleury b9be24a17d fix releasing of nil gpu buffer handles 2025-10-10 15:53:56 -07:00
Ryan Fleury c934892006 bump version to v0.9.23 2025-10-10 14:55:07 -07:00
Ryan Fleury b09e539534 fix build script for pgo 2025-10-10 14:35:13 -07:00
Ryan Fleury 8e452f10ac v0.9.22-alpha changelog 2025-10-10 13:50:47 -07:00
Ryan Fleury ac378b0ac2 switch in file menu 2025-10-10 13:10:02 -07:00
Ryan Fleury 7fcba83282 use debug info to infer language for files from including-unit language, if we cannot deduce it from extensions / settings (e.g. C++ .inl files) 2025-10-10 13:08:43 -07:00
Ryan Fleury bd9372f07c use current working directory as working directory for command line targets 2025-10-10 12:56:24 -07:00
Nikita Smith 43fcc21490 clang build fixes 2025-10-10 10:19:47 -07:00
Nikita Smith 3bd89b1fad switch over to new MD5 hash lib 2025-10-10 10:15:22 -07:00
Nikita Smith 061b5c5955 added CFA instruction parser, interpreter, and a dumper 2025-10-10 10:09:46 -07:00
Ryan Fleury c738768e41 demon/win32: do not assume actual_read is valid after a failed process memory read 2025-10-09 16:05:13 -07:00
Ryan Fleury da44e89a92 fix clang build 2025-10-09 13:57:41 -07:00
Ryan Fleury 9022efd3ab new strategy - allow artifact creation to report a completed generation which differs from the requested generation, thus preventing duplicate gen requests (in the case of ctrl process memory) 2025-10-09 11:24:48 -07:00
Ryan Fleury 28bb158c61 revert last change - that will forever-retry those reads! need a slightly different retry mechanism 2025-10-09 11:10:14 -07:00
Ryan Fleury fe6eff9d3b pass requested gen to artifact creation hooks, use to retry ctrl memory reads on many successive mem gen bumps - prevents spurious duplicate hashes in content store history 2025-10-09 10:40:31 -07:00
Ryan Fleury 4268c1de76 bump load gen on dbgi close also 2025-10-08 15:59:56 -07:00
Ryan Fleury 96477c65dd switch to martins hash 2025-10-08 12:58:59 -07:00
Nikita Smith 7eb64dbd13 metagen does not have this macro... 2025-10-07 20:42:52 -07:00
Nikita Smith e1986c9594 clang fixes 2025-10-07 20:37:00 -07:00
Nikita Smith 401d7b47df factor out C++ ABI exception handling 2025-10-07 20:28:06 -07:00
Nikita Smith 3560c7d3e7 dump CIE and FDE 2025-10-07 18:16:32 -07:00
Nikita Smith e4f6c0fc8e helper for querying arch bittness in byte size 2025-10-07 18:16:31 -07:00
Nikita Smith 7cf3eaf73f parsers for CIE and FDE 2025-10-07 18:16:31 -07:00
Nikita Smith 62ae5ca3f5 stringify format and cfa opcodes enums 2025-10-07 18:16:31 -07:00
Nikita Smith fb0d42e6d8 extend stb_sprintf.h with formatter for Rng1U64 via %r 2025-10-07 18:16:31 -07:00
Ryan Fleury 9e110bbe6d resolve register space -> primary module space in all visualizers which work on, broadly speaking, ranges of memory 2025-10-07 17:23:58 -07:00
Ryan Fleury fb825247ed resolve register-space evaluations to primary-module space evaluations in the visualizers 2025-10-07 17:20:44 -07:00
Ryan Fleury 7ff5764696 store successful queries keyed by target section as well, to avoid different table evals having different success states - fixes autocomplete flicker 2025-10-07 16:57:05 -07:00
Ryan Fleury d2feaa5f56 oops, fix dbgi search arenas leak! 2025-10-07 16:45:02 -07:00
Ryan Fleury 166b84cf30 eliminate content-layer-specific u128 hash 2025-10-07 16:24:54 -07:00
Ryan Fleury cd26bf1bcc only submit empty ctrl process memory artifacts if we have no other history; only retry on mem gen tears & valid ranges 2025-10-07 16:06:59 -07:00
Ryan Fleury ec69ebff35 fix tick-deferred command mechanism in debug engine 2025-10-07 15:50:52 -07:00
Ryan Fleury 783988c0ac expand ctrl process memory cache access to allow waiting for fresh results, rather than any results; use when doing a ctrl process memory write, to prefer viewing less stale data on exact frame. also expand trap net generation with success bit, use to retry stepping commands across frames if process memory reads are hindered. abort after N retries. 2025-10-07 15:44:35 -07:00
Ryan Fleury 2cc7f45ec1 promote register values to primary module space values for memory view specifically 2025-10-07 15:06:46 -07:00
Ryan Fleury f67cf8b59d remove incorrect space promotion rule 2025-10-07 14:51:34 -07:00
Ryan Fleury ec978d8d46 do not use complex register union types for common registers; just use primitive integer types instead 2025-10-07 14:41:51 -07:00
Ryan Fleury ab841035c0 preserve operand size info for shift operations, use along with typegroup to do correct sign preservation on shifts 2025-10-07 14:20:36 -07:00
Ryan Fleury f60ccb60f1 do not attach last successful filter to view state, since does not apply in all cases - fix artifact staleness default marker (if we do not get an artifact at all, then it is stale) 2025-10-07 12:09:14 -07:00
Ryan Fleury 0f0e36d40b disambiguate rip identifier in disasm base address calculation 2025-10-07 11:45:09 -07:00
Ryan Fleury 2acf77ad9e fix impossible disasm loading condition; do not go wide on dbgi matching unless we have significant-enough dbgis 2025-10-07 11:34:30 -07:00
Ryan Fleury fadef8a886 log source of dwarf info more specifically 2025-10-07 11:03:18 -07:00
Ryan Fleury fe8608ee1c more verbose logging in radbin 2025-10-07 10:37:15 -07:00
Ryan Fleury d20cce536a rdim bake parameter joining, source rdi bake parameters from *all* inputs, and not mutually-exclusive dwarf vs. pdb cases 2025-10-07 10:20:19 -07:00
Ryan Fleury b02a815a27 flush dwm on resize; use WS_EX_NOREDIRECTIONBITMAP window flag to avoid dwm bug 2025-10-06 17:34:19 -07:00
Ryan Fleury 2a7177861b remove extra watch row column cases - simplify most cases down to expr / eval. use extra 'note' for watch window cells to annotate type info - this sacrifices the full type evaluation cell, and instead uses a small extra bit of text to denote the type for quick reading. but this full type cell is not needed in most cases, and it can always be reobtained with an explicit typeof evaluation. 2025-10-06 17:06:00 -07:00
Ryan Fleury 6f4e78d06c do not try to release failed-creation textures 2025-10-06 14:55:51 -07:00
Ryan Fleury 284524e0c4 fix incorrect ctx check in win32 demon 2025-10-06 14:35:41 -07:00
Ryan Fleury 835a57f918 extend dbgi matching system with preferred dbgi key, to disambiguate results - fill with primary module dbgi in eval, to always prefer selected thread context when applicable 2025-10-06 14:31:57 -07:00
Ryan Fleury d2216019b9 prefer primary module, or modules with space matching the primary module's, when doing top-level debug info name matching in eval 2025-10-06 14:23:34 -07:00
Ryan Fleury af4f18ed98 sketch out more flexible texture 2d format codes 2025-10-06 13:52:59 -07:00
Ryan Fleury 213dc6a6a7 fix busted ctrl memory stream, when bad memory & null terminated (#647); do not refresh repeatedly due to loading, if any raddbg window is not focused 2025-10-06 11:38:58 -07:00
Ryan Fleury 811f316ca2 fix clang warnings in dwarf -> rdi 2025-10-06 11:20:12 -07:00
Nikita Smith da0028033d changed dumper to print .debug_info in more compact form 2025-10-03 20:10:09 -07:00
Nikita Smith b1b83c4e3d bugfix const64 interp 2025-10-03 17:16:45 -07:00
Ryan Fleury 32e344c806 remove dbgi name from ood warning 2025-10-02 18:34:04 -07:00
Ryan Fleury 073a0fcf3a add checksum checking for timestamps; fix incorrect sha256 async checksum calculation; plug file-ood back in 2025-10-02 18:34:04 -07:00
Nikita Smith f8229a390d merge conf fix 2025-10-02 18:19:42 -07:00
Nikita Smith 9acff9ecd2 use check sum defn from rdi.h 2025-10-02 18:19:42 -07:00
Nikita Smith 555f8ec6ff grab ranges in compile unit tag for the unit vmap 2025-10-02 18:19:42 -07:00
Nikita Smith 4ba1ee6e06 follow C type conversion rules in the expression transpiler 2025-10-02 18:19:42 -07:00
Nikita Smith 1f9ce6e6ba eval opcode stubs 2025-10-02 18:19:42 -07:00
Nikita Smith c7774c7582 helper for convert opcode 2025-10-02 18:19:42 -07:00
Nikita Smith 1264115d13 define push and pop counts for expression opcodes 2025-10-02 18:19:42 -07:00
Nikita Smith 954633bba2 add opcode for swapping top two values on the stack 2025-10-02 18:19:42 -07:00
Nikita Smith 48c7e45535 helper for determining if bytecode has dependency on TLS 2025-10-02 18:19:42 -07:00
Nikita Smith 0f9df9bc40 change opcode type to U8 2025-10-02 18:19:42 -07:00
Nikita Smith 0e9739f964 expression parser 2025-10-02 18:19:42 -07:00
Nikita Smith da74b8595c add operand count for expression opcodes 2025-10-02 18:19:42 -07:00
Ryan Fleury 569481c779 plug in debugger-side checksum computation & comparison 2025-10-02 17:29:59 -07:00
Ryan Fleury ee759dbac7 sha1/sha256 2025-10-02 17:07:16 -07:00
Ryan Fleury 104e72999c base layer hashing algorithms, fill out md5 2025-10-02 16:20:34 -07:00
Ryan Fleury 2d672d232f checksum baking & rdi changes; checksum dumping 2025-10-02 16:12:53 -07:00
Ryan Fleury c1e32b93a7 switch from variable size checksum data sections to just making well-defined fixed size ones for all of the concrete cases 2025-10-02 15:43:01 -07:00
Ryan Fleury 403d05cc8b first pass at checksum baking 2025-10-02 14:17:44 -07:00
Ryan Fleury 56b5792546 rdi checksum kinds, rdim checksums, pull parsed checksum kinds/values from cv, fill out rdim checksums (still haven't put into rdi itself yet) 2025-10-02 13:40:45 -07:00
Ryan Fleury b88c45d737 dbg info conversion events 2025-10-02 12:44:42 -07:00
Ryan Fleury 871daf3f22 only push unique hashes to key history in content layer; fix staleness detection in search 2025-10-02 12:08:31 -07:00
Ryan Fleury 32c4da878f fix radbin build 2025-10-02 11:53:53 -07:00
Ryan Fleury a58c23754a di2 -> di; delete old dbg info layer, delete async layer 2025-10-01 17:30:08 -07:00
Ryan Fleury 544fea0929 actually - keep (path * stamp -> key) and (key -> path * stamp) history - we do not need to evict these. also fix incorrect file map view closure on debug info close 2025-10-01 17:19:15 -07:00
Ryan Fleury 2cb94c422a update key -> path and path -> key records on debug info closing 2025-10-01 16:36:45 -07:00
Ryan Fleury 47e2014250 reset high priority bit 2025-10-01 15:53:58 -07:00
Ryan Fleury 24670e3095 fix di2 successful search continuity 2025-10-01 15:46:42 -07:00
Ryan Fleury 7707ba1d60 dwarf debug info option in builds, fix heuristic to try to load debug info from exe itself 2025-10-01 15:36:36 -07:00
Ryan Fleury db66beaf22 correctly interpret conversion completions; single high priority re-loop bit for async threads 2025-10-01 14:32:44 -07:00
Ryan Fleury b92821b503 convert less aggressively, fix incorrect di2 request batch clearing 2025-10-01 11:44:47 -07:00
Ryan Fleury 24406d1e4e use lack of user bps as hint that no rdis are necessary to wait on 2025-10-01 11:24:37 -07:00
Ryan Fleury cd048a878b fix module req cache bug; fall back on exe path as debug info 2025-09-30 17:54:31 -07:00
Ryan Fleury 628eaf84ee fix release order in dbg_info2 2025-09-30 16:47:26 -07:00
Ryan Fleury 89a026e2a6 fix content cache submission - theory is that non-zeroed keys were causing double-decs of history! 2025-09-30 15:55:22 -07:00
Ryan Fleury d5ea64a72d merge blob & key storage locking scopes in content layer - keep both blob & key cache updates 'atomic' 2025-09-30 15:25:15 -07:00
Ryan Fleury 5b00aaadaf debugging / fixes 2025-09-30 14:18:11 -07:00
Ryan Fleury 4964a94cd3 transition to dbg_info2 2025-09-30 12:52:32 -07:00
Ryan Fleury 4b122dec51 testing / debugging 2025-09-30 11:21:35 -07:00
Ryan Fleury ea99cb22e7 dbg_info2: async match artifact cache hooks / lookup 2025-09-30 11:16:15 -07:00
Ryan Fleury bf27344a9b replace extra gen parameters in artifact creation hook; replace with explicit cancellation signal, passed by caller 2025-09-30 11:01:04 -07:00
Ryan Fleury 45a2137d08 linux: fix incorrect gethostname usage, fix build, fix clang warnings 2025-09-30 10:02:40 -07:00
Nikita Smith 81d747b8d7 fix process join 2025-09-29 18:05:11 -07:00
Ryan Fleury d842da0b2e checkpoint on wide all-debug-info fuzzy searching cache 2025-09-29 17:21:37 -07:00
Ryan Fleury 4d30933c44 debug info load gen, to easily key anything based on entire set of loaded debug info 2025-09-29 17:15:03 -07:00
Ryan Fleury d2678db25f first pass at new wide async all-debug-info fuzzy searching 2025-09-29 17:09:44 -07:00
Ryan Fleury 768755b0a4 equip conversion subprocesses with info to signal parent on completion, + plug into a wakeup thread, which can re-trigger the async wavefront. also fix duplicate line counts in text parsing 2025-09-29 16:38:57 -07:00
Ryan Fleury 3a409f5ab3 throttle new conversion process launches based on available system-wide threads, with heuristic threshold of oversubscription; tweak size -> thread count heuristic 2025-09-29 16:07:16 -07:00
Ryan Fleury 92809ee6b6 new debug info loading layer debugging & fixes 2025-09-29 15:07:08 -07:00
Ryan Fleury 08904c9e2d another checkpoint on new dbg info loading 2025-09-29 14:51:28 -07:00
Ryan Fleury 46527c8465 checkpoint in new debug info layer: 16-byte key (set up to use GUIDs or otherwise unique keys at the base), better control over oversubscribing cores for conversion, better prioritization of conversions 2025-09-29 14:12:33 -07:00
Nikita Smith 8bf0a3de5b split conversion pass into three (types, udts, and symbols) and use
new locations chunk list
2025-09-29 00:11:27 -07:00
Nikita Smith 07d77a0e79 report unsuccessful writes 2025-09-26 16:28:46 -07:00
Nikita Smith c5fe329c05 fix return status for file writes 2025-09-26 16:28:46 -07:00
Nikita Smith 5709fb54dd simplify debug info conversion loop 2025-09-26 16:28:46 -07:00
Nikita Smith 7084320a83 helper for finding parent type 2025-09-26 16:28:46 -07:00
Nikita Smith eb4e6d2883 alloc slots for null 2025-09-26 16:28:46 -07:00
Ryan Fleury d7fc7d1fa9 handle aliases gracefully in eval expansion & string iterator 2025-09-26 16:23:17 -07:00
Ryan Fleury eda4f6bafa preserve & visualize restrict type modifiers in eval 2025-09-26 15:32:13 -07:00
Ryan Fleury 5fa3efe76a bugfix evictions, correctly maintain downstream content hash counts 2025-09-26 15:09:47 -07:00
Ryan Fleury ad9c67ae43 eliminate old caches from ctrl layer 2025-09-26 13:44:19 -07:00
Ryan Fleury b2acc13fb8 eliminate old async call stack computation / call stack cache code 2025-09-26 12:00:25 -07:00
Ryan Fleury 99195282f1 async call stack tree computation -> artifact cache 2025-09-26 11:57:08 -07:00
Ryan Fleury 9033ad8a2e no dashes in guid formatting in breakpad output; also include age 2025-09-26 11:44:42 -07:00
Ryan Fleury cd7e2d3f89 breakpad dumping: include pdb name if missing exe name, include pdb guid if no exe hash 2025-09-26 11:37:07 -07:00
Ryan Fleury 9ad7361cb9 thin out needed entities for call stack build; fix unnecessary re-loops on async threads 2025-09-25 17:07:02 -07:00
Ryan Fleury 88eddce324 same for clang 2025-09-25 16:42:26 -07:00
Ryan Fleury b1b03ebd56 turn on opt:ref and opt:icf for all builds 2025-09-25 16:38:42 -07:00
Ryan Fleury d1845bf51f no_inline on entry_point 2025-09-25 15:52:58 -07:00
Ryan Fleury 366c63e3ce extend artifact cache loop with an early-out cancellation path, when new high priority requests have been pushed, while low priority ones are still being worked on 2025-09-25 15:35:22 -07:00
Ryan Fleury c4bf855af9 extend artifact cache nodes with last requested vs. last completed gen; pass last requested gen to artifact creation to support cancellation 2025-09-25 14:59:29 -07:00
Nikita Smith d3d91c64cc get DWARF converter up and running 2025-09-25 12:38:21 -07:00
Ryan Fleury 05fbd06f82 delete dead code, dbgi -> dbg_info 2025-09-25 11:57:23 -07:00
Ryan Fleury 6d39a66672 eliminate ptr graph cache experiment 2025-09-25 11:52:33 -07:00
Ryan Fleury f61cd2b673 fix use of unused layers 2025-09-25 11:47:56 -07:00
Ryan Fleury 7990b043a0 eliminate geo cache, replace with trivial use of artifact cache defined by geo visualizer 2025-09-25 11:47:31 -07:00
Ryan Fleury d8fcbcd868 eliminate texture_cache; replace with trivial usage of artifact cache, in raddbg layer defining the bitmap visualizer, which was the only usage 2025-09-25 11:40:35 -07:00
Ryan Fleury b4d672efba flag ctrl memory reads as high priority 2025-09-25 11:20:14 -07:00
Ryan Fleury a338b3413e artifact cache fixes, move ctrl process memory streaming to artifact cache 2025-09-25 10:35:47 -07:00
Ryan Fleury ca7bfab7ea bucket artifact cache requests by wideness/priority; do high/wide, high/thin, low/wide, low/thin 2025-09-24 17:08:08 -07:00
Ryan Fleury 10e8a10d9b adjust new call stack artifact cache hooks to work gracefully with terminated threads/processes 2025-09-24 16:06:46 -07:00
Ryan Fleury 3dc3707b22 maintain fs change gen alsog 2025-09-24 15:41:00 -07:00
Ryan Fleury bdfd4c14ae eliminate old file stream cache, just use simplified cache for linting filesystem changes; otherwise switch everything to artifact cache 2025-09-24 15:40:11 -07:00
Ryan Fleury 684f6344c5 switch to old call stack cache for now 2025-09-24 15:08:07 -07:00
Ryan Fleury 4b335103bc begin moving call stack computation / cache to artifact cache; fix incorrect broadcast val location 2025-09-24 15:04:45 -07:00
Ryan Fleury 0679b4b04c #if 0 out old evictor thread for ptr graph 2025-09-24 13:43:51 -07:00
Nikita Smith 18b5e27015 change log 2025-09-24 12:42:17 -07:00
Nikita Smith 647bc4206f minor typo 2025-09-24 12:42:17 -07:00
Nikita Smith 06e895be7c organize task structs 2025-09-24 12:42:17 -07:00
Nikita Smith 20c92e0baf speed up base reloc gather step and serialize pages in parallel 2025-09-24 12:42:17 -07:00
Nikita Smith 3c0c531c53 reloc helper 2025-09-24 12:42:17 -07:00
Nikita Smith 0a930be613 use radsort for sorting base reloc pages 2025-09-24 12:42:17 -07:00
Ryan Fleury fa0b2440ec subset flag for constants conversion; fix empty-tpi-hash case 2025-09-24 12:42:04 -07:00
Ryan Fleury 7f2a066e8f tear out old file stream tick; switch disasm to using new file stream for interleaved text lines 2025-09-24 12:09:59 -07:00
Ryan Fleury 8e68187107 fix incorrect file artifact reading offsets; switch file eval reads to new artifact cache 2025-09-24 11:53:52 -07:00
Ryan Fleury 5f883860e0 move part of file evaluations onto new async file reads 2025-09-24 11:50:53 -07:00
Ryan Fleury e7368af35c artifact cache waitable cache access; debugging / fixes; start plugging in file stream to artifact cache 2025-09-24 11:25:18 -07:00
Ryan Fleury 7e05a60ffe checkpoint on more artifact cache port of ctrl process memory streaming 2025-09-23 17:05:45 -07:00
Ryan Fleury 141b6c1396 sketch out artifact cache hooks for file streaming layer 2025-09-23 11:58:00 -07:00
Ryan Fleury 6cdce22284 expand artifacts a bit more, to be more useful with larger-than-ptr but not huge allocations 2025-09-23 11:27:56 -07:00
Ryan Fleury 9787c698e6 sketch out new async path for ctrl memory streaming 2025-09-23 10:58:17 -07:00
Ryan Fleury 2ce581fa19 more subset flag respecting 2025-09-22 17:39:26 -07:00
Ryan Fleury 5c1cf77fda respect subset flags in pdb -> rdi converter 2025-09-22 17:32:05 -07:00
Ryan Fleury 8078b90f51 text_cache / dasm_cache -> text / disasm 2025-09-22 16:52:55 -07:00
Ryan Fleury 408c57639a eliminate dasm cache hook calls 2025-09-22 16:23:11 -07:00
Ryan Fleury 6ac8c588f7 eliminate old disasm cache code 2025-09-22 16:22:33 -07:00
Ryan Fleury 4b1939bd6d provide u64 broadcasting mechanism in base layer wavefront lane context, allows more flexible data sharing mechanism which does not depend on statics; reshape dasm building codepath for clicking into artifact cache 2025-09-22 16:21:30 -07:00
Ryan Fleury 8a1e6ab2e6 extend artifact cache with non-key-included generations, to allow gracefully decaying certain computations 2025-09-22 15:25:01 -07:00
Ryan Fleury 811e58c249 progress on single async-filled computation artifact cache; hook up to text cache layer, eliminate bespoke cache for text only 2025-09-22 15:13:31 -07:00
Ryan Fleury 9459327687 pull out table stripe arrays as base layer primitive; unified 'artifact cache' experiment 2025-09-22 14:07:21 -07:00
Nikita Smith 6b278e1ccc parallelize image fill 2025-09-22 10:06:21 -07:00
Nikita Smith a75a33e6d3 minor fix for UBA detour 2025-09-22 10:06:21 -07:00
Nikita Smith e72512f638 switch over to 64-bit pointer tagging 2025-09-22 10:06:21 -07:00
Nikita Smith d1dd8e654c add 128-bit compare exchange 2025-09-22 10:06:21 -07:00
Nikita Smith 861c2cf893 macro for aligning types 2025-09-22 10:06:21 -07:00
Nikita Smith 4717701540 update threading API 2025-09-22 10:06:21 -07:00
Nikita Smith 362557e503 renormalize line endings 2025-09-22 10:06:21 -07:00
Nikita Smith 872c387bad let errors from MT to bubble up to linker's stdout and stderr 2025-09-22 10:06:21 -07:00
Nikita Smith 3d7afb58fa speed up symbol patching 2025-09-22 10:06:21 -07:00
Nikita Smith 42999bea63 profile markup obj relocation patching 2025-09-22 10:06:21 -07:00
Nikita Smith 553154eb39 layer color fix 2025-09-22 10:06:21 -07:00
Nikita Smith ac985bb5da add a real pgo PGO target 2025-09-22 10:06:21 -07:00
Nikita Smith 371e52ad42 add /rad_alt_pch_dir for remapping objs in the local folder for pgo builds 2025-09-22 10:06:21 -07:00
Nikita Smith ee75ada087 mark function override meta-data sections with link info flag so
they do not get a section definition
2025-09-22 10:06:20 -07:00
Nikita Smith ce044e7e83 detect removed fixup symbol and propagate correct section number 2025-09-22 10:06:20 -07:00
Nikita Smith a060f581d9 stub /d2 2025-09-22 10:06:20 -07:00
Nikita Smith 17058e71bf remove empty nodes 2025-09-22 10:06:20 -07:00
Nikita Smith e864674fbd add pgo support to build.cmd 2025-09-22 10:06:20 -07:00
Ryan Fleury aa0eec5763 prevent focusing null window, which was causing weird input event stealing on run... 2025-09-19 16:58:41 -07:00
Ryan Fleury 1745ad4758 eliminate old profiling markup 2025-09-19 16:55:07 -07:00
Ryan Fleury 53054e5add fix incorrect loop-again logic on async threads 2025-09-19 16:41:49 -07:00
Ryan Fleury 8fa01d3e30 expand access scope touches to automatically record update clock idx touch time, + timestamp; move texture cache to new async wavefront 2025-09-19 15:31:30 -07:00
Ryan Fleury 8e2ceeee9e provide mechanism to not wait at top of async loop 2025-09-18 16:20:17 -07:00
Ryan Fleury 30ae9620f9 eliminate ptr graph scope; simplify dasm cache eviction loop 2025-09-18 15:59:21 -07:00
Ryan Fleury 4e99312b75 eliminate tex_scope; fold into access 2025-09-18 15:53:00 -07:00
Ryan Fleury c5bcdbf232 eliminate geo_scope, fold into base layer's 'access' construct 2025-09-18 15:40:13 -07:00
Ryan Fleury 2131e792a1 eliminate text cache scope; fold into base layer's 'access' construct 2025-09-18 15:25:11 -07:00
Ryan Fleury 1b93dbd4bd promote content scope to base layer, rename as 'access'; generalize based just on list of scope refcounts, + optional cvs; eliminate c_scope; replace dasm_scope with access as well 2025-09-18 15:21:22 -07:00
Ryan Fleury 5381307e90 hash_store -> content 2025-09-18 14:42:25 -07:00
Ryan Fleury 364e15491c switch from static lane distribution in file/dasm to dynamic counter 2025-09-18 14:19:00 -07:00
Ryan Fleury 7c08d6846b dasm cache in new async wavefront 2025-09-18 11:18:36 -07:00
Ryan Fleury 0c1010b72d move hash store eviction to base layer async wavefront; start dasm transition 2025-09-17 16:38:14 -07:00
Nikita Smith e33a95bfe2 do not embed time stamp with /brepro 2025-09-17 15:21:37 -07:00
Nikita Smith 0b154cef46 stub /brepro 2025-09-17 15:21:37 -07:00
Nikita Smith c653410af5 stub /errorreportlevel 2025-09-17 15:21:37 -07:00
Nikita Smith 28aec349fd update readme 2025-09-17 15:21:37 -07:00
Nikita Smith b646e1cd43 fix compiler errors 2025-09-17 15:21:37 -07:00
Nikita Smith fe63983d4a u32 decrement intrinsic 2025-09-17 15:21:37 -07:00
Nikita Smith 5a12513306 parallelize section garbage collection
currently we tag pointers to solve ABA problem however if the list
has more than max_U16 items, the tag will overflow and cause serious issues.
To fix this, we need to use 64-bit tags together with 128-bit interlocked
compare-exchange intrinsic
2025-09-17 15:21:37 -07:00
Nikita Smith cc8fdc6c6f order check for COMDATs with any property 2025-09-17 15:21:37 -07:00
Nikita Smith 630c3b42a7 do lightweight import gathering while resolving links 2025-09-17 15:21:37 -07:00
Nikita Smith d4ac5ede77 assign correct removed section type 2025-09-17 15:21:37 -07:00
Nikita Smith 8a46ee0ad2 return full path to the first matched file 2025-09-17 15:21:37 -07:00
Nikita Smith 0b5dd92a87 minor tweaks 2025-09-17 15:21:37 -07:00
Nikita Smith ded932e3ba skip library searches for import stubs 2025-09-17 15:21:37 -07:00
Nikita Smith 98eaf67dd8 while symbol table is being built sort weak and undefined symbols to
separate chunk lists to speed up library search
2025-09-17 15:21:37 -07:00
Nikita Smith 4e1ebe5a6b change import stub symbol characteristic to search alias to skip them
on subsequent searches
2025-09-17 15:21:37 -07:00
Ryan Fleury 7d7edd7cf7 renormalize line endings 2025-09-17 15:21:24 -07:00
Ryan Fleury 6abdadcccb garbage collect window states on quit as well 2025-09-17 14:50:06 -07:00
Ryan Fleury 0d15b8670b eliminate bifurcated rw lock path based on exclusive mode; promote thread operations to base layer, use os layer as impl; first pass on moving file streaming layer to base layer's async wavefront 2025-09-17 14:47:55 -07:00
Ryan Fleury 99c989a3c3 first pass at setting up base layer async thread path 2025-09-17 10:06:21 -07:00
Ryan Fleury 443646b356 rdi make: fix incorrect base encoding offset initialization when pushing into new location chunk 2025-09-16 12:28:33 -07:00
Ryan Fleury 49bcb252d9 remove year from license 2025-09-16 11:51:10 -07:00
Ryan Fleury c5a1da5c80 bump to 22 2025-09-16 11:48:00 -07:00
Ryan Fleury 3ab9f72c76 readme pass 2025-09-16 11:47:04 -07:00
Nikita Smith 80967fac12 pre-parse section names and flag debug info sections 2025-09-16 10:31:02 -07:00
Nikita Smith 3224c5e0aa skip linker info sections during relocation patching, also log a message
when encountering an unsupported machine type
2025-09-16 10:31:01 -07:00
Nikita Smith 488849792c change file search to return on first match 2025-09-16 10:31:01 -07:00
Nikita Smith 7095a8cd6e fix bug where new object tracking failed, causing certain objs to be
skipped during the symbol table input step
2025-09-16 10:31:01 -07:00
Nikita Smith 5aff575feb discard empty symbol nodes 2025-09-16 10:31:01 -07:00
Nikita Smith b5a2bbaf54 early-out of default library searches 2025-09-16 10:31:01 -07:00
Nikita Smith d6596efac8 allow weak symbols to resolve to other weak symbols 2025-09-16 10:31:01 -07:00
Nikita Smith c47b35f635 update link symbol set logic to replace import address symbols with jump
thunk symbols
2025-09-16 10:31:01 -07:00
Nikita Smith c7c86cd360 do not report unresolved symbols in debug info sections 2025-09-16 10:31:01 -07:00
Ryan Fleury 937c6c8bce eliminate radcon, eliminate unused string helpers 2025-09-16 10:17:02 -07:00
Ryan Fleury 1b82c52803 only enable priority thread running on initial run loop; do not pay the cost every run loop iteration 2025-09-15 17:18:59 -07:00
Ryan Fleury 2a8ca37cb3 record & restore target window on runs 2025-09-15 14:10:30 -07:00
Ryan Fleury c7bb49092f radbin dump: isolate output bundling on lane 0 2025-09-15 13:28:43 -07:00
Ryan Fleury cf94b3757e wide rdi dumping 2025-09-15 13:02:32 -07:00
Ryan Fleury 26606d7895 do not strip enums/aliases on array index ops 2025-09-15 11:32:22 -07:00
Ryan Fleury e021079d05 bump rdi encoding version 2025-09-09 08:28:08 -07:00
Nikita Smith b1609017c5 inline xxhash functions 2025-09-08 16:07:31 -07:00
Nikita Smith 763bb57459 revert hasher 2025-09-08 16:07:31 -07:00
Nikita Smith 98a05728b3 add check for whether weak symbol is resolved 2025-09-08 16:07:31 -07:00
Nikita Smith fc0a7d51d3 warning fixes 2025-09-08 16:07:31 -07:00
Nikita Smith 58e3af5b3c test for linking using first and second lib headers 2025-09-08 16:07:31 -07:00
Nikita Smith bbe430cc2f write first linker member header with symbol names grouped by member 2025-09-08 16:07:31 -07:00
Nikita Smith 24b427fe72 delete unused blake3 headers 2025-09-08 16:07:31 -07:00
Nikita Smith ee3832ea3b parallel for lib symbol search 2025-09-08 16:07:31 -07:00
Nikita Smith fb46d0bba4 sort symbol names in first member header 2025-09-08 16:07:31 -07:00
Nikita Smith 7193986305 binary search for strings 2025-09-08 16:07:31 -07:00
Nikita Smith 00536f7ea8 rewrite set linked symbol logic to respect declaration order in obj symbol table 2025-09-08 16:07:31 -07:00
Nikita Smith 8a22910d9b add "Links" log type for diagnosing linked lib members 2025-09-08 16:07:31 -07:00
Nikita Smith 082f6cf6fd fix free block check and remove unused free_size field 2025-09-08 16:07:31 -07:00
Nikita Smith 8f749f4239 use global symbol table to detect duplicate imports 2025-09-08 16:07:31 -07:00
Nikita Smith 7cea036bc1 clean up pass over symbol table
- rename functions for consistency
- remove unused code
2025-09-08 16:07:31 -07:00
Nikita Smith 222c220d99 make xxhash API funcs static and hash string size too 2025-09-08 16:07:31 -07:00
Ryan Fleury 80b65bc0fb fix treatment of unitless pdbs 2025-09-08 16:06:45 -07:00
Nikita Smith 069d683690 fix crash when obj does not have debug info 2025-09-06 09:54:23 -07:00
Nikita Smith 3459070f71 remove windows.h from blake3 2025-09-06 09:54:23 -07:00
Nikita Smith a6432cce8e improve unresolved symbol errors
- collect symbol references and print out objs that reference
  unresolved symbol
- print source file location of the references
2025-09-06 09:54:23 -07:00
Nikita Smith d92f45784d rename defined symbol to obj ref, as the symbol table no longer has
scopes and it makes no sense to refer to them that way
2025-09-06 09:54:22 -07:00
Nikita Smith 21163264d4 redirect entry point to CRT version if name is inferred 2025-09-06 09:54:22 -07:00
Nikita Smith a11406ac51 declare thunk symobls as functions 2025-09-06 09:54:22 -07:00
Ryan Fleury 40d6ce2f59 do not return zeroes for top-level structures in pdb parser; ensure you have a top-level readable pointer, always 2025-09-06 09:53:04 -07:00
Ryan Fleury 0c161f83c7 fix clang 2025-09-05 17:09:01 -07:00
Ryan Fleury 23a68faadd rdim2 -> rdim; p2r2 -> p2r 2025-09-05 17:06:19 -07:00
Ryan Fleury 51ef166e60 eliminate all old conversion/baking code 2025-09-05 17:02:56 -07:00
Ryan Fleury 78530fb10d merge p2r2 into original p2r, delete old conversion path; replace pdb -> breakpad converter & dependency on old converter 2025-09-05 16:35:35 -07:00
Ryan Fleury a2b4e7bdc5 fix missing null voff in scope voff data section 2025-09-05 16:02:38 -07:00
Nikita Smith 11373f4432 disable COFF group info generation 2025-09-05 15:19:31 -07:00
Nikita Smith f2ee135439 fix up symbols visibility 2025-09-05 15:19:31 -07:00
Nikita Smith 56c43ad614 clean up HashTable, removed unused command line switches, added
list wrapper for alt names, added natvis for HashTable, AltNameList,
MergeDirectiveList, and IncludeSymbolList
2025-09-05 15:19:31 -07:00
Nikita Smith 6a3d7e65f3 remove year from the copyright 2025-09-05 15:19:31 -07:00
Nikita Smith e88dc44f31 clean up debug leftovers 2025-09-05 15:19:31 -07:00
Nikita Smith 580303b0dd emit jump thunks for imports only when needed 2025-09-05 15:19:30 -07:00
Nikita Smith 43e81b934b move weak symbol replacer to the symbol table layer 2025-09-05 15:19:30 -07:00
Nikita Smith 8d75497bba do not set function pad min switch by default 2025-09-05 15:19:30 -07:00
Nikita Smith 0b0a2664d1 merge .idata with .rdata 2025-09-05 15:19:30 -07:00
Nikita Smith a64f8f4196 clean up over base strings in the linker layer 2025-09-05 15:19:30 -07:00
Nikita Smith 9f6da0ec63 simplify section removal and purging 2025-09-05 15:19:30 -07:00
Nikita Smith 43b35d43dc change lib sort to preserve input order 2025-09-05 15:19:30 -07:00
Nikita Smith 845e225e81 push alt name strings after they are copied to the config arena 2025-09-05 15:19:30 -07:00
Nikita Smith fdad3f4f58 natvis for lib member ref 2025-09-05 15:19:30 -07:00
Nikita Smith 78b1f7e701 optionally emit import thunks 2025-09-05 15:19:30 -07:00
Nikita Smith 1aac27095e WIP: reorder input and library search order to match MSVC behavior 2025-09-05 15:19:30 -07:00
Nikita Smith 240935f0cc WIP: use MSVC rule for COMDAT symbol replacement 2025-09-05 15:19:30 -07:00
Nikita Smith d9eb26a830 infer subsystem when only entry point is specified 2025-09-05 15:19:30 -07:00
Nikita Smith b0db2b19f8 move entry point name redirection helper to MSCRT layer 2025-09-05 15:19:30 -07:00
Nikita Smith e1b7168605 update weak vs undefined replacement rule 2025-09-05 15:19:30 -07:00
Nikita Smith d7cdaa98b5 oops forgot to set enum type 2025-09-05 15:19:30 -07:00
Nikita Smith c397b1dfb1 handle common section case 2025-09-05 15:19:30 -07:00
Nikita Smith 843de72f64 add U8 atomic exchange for clang and gcc 2025-09-05 15:19:30 -07:00
Nikita Smith 0dac1a91db fix u128 make 2025-09-05 15:19:30 -07:00
Nikita Smith fc4e269211 ignore sign conversions in stb_sprintf.h 2025-09-05 15:19:30 -07:00
Nikita Smith daf69ff1c7 fix sign conversion in radsort.h 2025-09-05 15:19:30 -07:00
Nikita Smith 971f1b9a2f ignore sign conversions in blake3 2025-09-05 15:19:30 -07:00
Nikita Smith 1a9e17ee37 remove invalid normalize helpers for integer vectors (they always produce zero) 2025-09-05 15:19:30 -07:00
Nikita Smith e0c409e3f4 move prototype decl to base_core.h to fix implicit function usage 2025-09-05 15:19:30 -07:00
Nikita Smith 3bd8f0e1d5 fix argument expansion in github actions and build.bat 2025-09-05 15:19:30 -07:00
Nikita Smith 41fe8a7410 merge undefined and weak search passes 2025-09-05 15:19:30 -07:00
Nikita Smith b64e1dca9a WIP fix lib push order and sort new inputs 2025-09-05 15:19:30 -07:00
Nikita Smith 67e66dc26e WIP switching to serial library search-style, removed lib scope from
the symbol table
2025-09-05 15:19:30 -07:00
Nikita Smith 330c8ead38 move member queue-attempt flag from symbol to lib struct 2025-09-05 15:19:30 -07:00
Nikita Smith f1b22dbe27 change library to use compressed member offsets 2025-09-05 15:19:30 -07:00
Nikita Smith 89d496c855 fix replacement rule for weak search library vs undefined 2025-09-05 15:19:30 -07:00
Nikita Smith 0ceadff525 maintain input order of objs in PDB 2025-09-05 15:19:30 -07:00
Ryan Fleury 4eca7f7fea source file / source line map baking 2025-09-05 15:19:30 -07:00
Ryan Fleury efb24fb0fa checkpoint on src file / src line map baking 2025-09-05 15:19:30 -07:00
Ryan Fleury d2e6e5de5a oops - fix non-allocation in previous part 2025-09-05 15:19:30 -07:00
Ryan Fleury 15e9cda7d2 new location info baking, new constants baking 2025-09-05 15:19:30 -07:00
Ryan Fleury ee8dc27428 location data / location block baking 2025-09-05 15:19:30 -07:00
Ryan Fleury cd77ddb1b7 pdb converter - new location info building for all cases 2025-09-05 15:19:30 -07:00
Ryan Fleury 6f9b22b258 plug in new location building code to pdb conversion 2025-09-05 15:19:30 -07:00
Ryan Fleury cc9f45299a eliminate separate chunk list for location cases 2025-09-05 15:19:30 -07:00
Ryan Fleury fa05bbf2a5 udt member/enum-val layout & nested baking; use rio to pre-fault all commits 2025-09-05 15:19:30 -07:00
Ryan Fleury a84142ed77 re-nest enum vals & members into udts; we want to keep the building API flexible with order of member building, and we can assume ~statistically-uniform distribution across all udts, so it makes more sense to just parallelize on udts, and pay the small cost of an upfront per-lane layout. 2025-09-05 15:19:30 -07:00
Ryan Fleury 8b83e5ef48 more non-determinism & bug fixes in name map & idx run map building 2025-09-05 15:19:29 -07:00
Ryan Fleury 4c3bb98c64 more determinism fixes 2025-09-05 15:19:29 -07:00
Ryan Fleury 096b631e8a remove debugging code 2025-09-05 15:19:29 -07:00
Ryan Fleury 27f2acd45d further progress/fixes on pdb -> rdi determinism 2025-09-05 15:19:29 -07:00
Ryan Fleury 27d4793900 fix line table building non-determinism 2025-09-05 15:19:29 -07:00
Ryan Fleury f093ba9d35 fix src file path gathering determinism - was caused by interleaving each lane's non-inline and inline file paths - with different thread counts, these subdivisions will be different, so the order will change 2025-09-05 15:19:29 -07:00
Ryan Fleury 6234fb0c49 fix incorrect scope voff serialization offsets 2025-09-05 15:19:29 -07:00
Ryan Fleury 955f033043 fix incorrect idx run baking; slots need to be laid out based on *idx counts*, rather than *value counts*! 2025-09-05 15:19:29 -07:00
Ryan Fleury e276ce4fb3 stub out src file baking 2025-09-05 15:19:29 -07:00
Ryan Fleury 57125fee1b eliminate helpers from string map baking; no point in extra entry points for partial bakes 2025-09-05 15:19:29 -07:00
Ryan Fleury 2f9006bb8a bugfix name map baking 2025-09-05 15:19:29 -07:00
Ryan Fleury 46ac437e86 name map baking / serialization 2025-09-05 15:19:29 -07:00
Ryan Fleury 92f24a043d idx runs baking 2025-09-05 15:19:29 -07:00
Ryan Fleury 55b05301a4 expand scope vmap sorting -> all vmaps; do final vmap bakes; do first pass of scope (1 scope -> many locals, many voffs) layout / baking 2025-09-05 15:19:29 -07:00
Ryan Fleury cc0d707eb2 eliminate 'lane groups', since we can go wide on the sorts now 2025-09-05 15:19:29 -07:00
Ryan Fleury 1d7cd4f4d2 cleanup / radix sort experimentation 2025-09-05 15:19:29 -07:00
Ryan Fleury a44fbb0909 parallel radix sort for scope vmap baking 2025-09-05 15:19:29 -07:00
Ryan Fleury 8fe4b3524f with sufficient threads, split baking threads into two groups: small # of threads to do expensive 'background' baking tasks, use the rest to do wide predictable baking stuff 2025-09-05 15:19:29 -07:00
Ryan Fleury f065ca33a2 location block baking 2025-09-05 15:19:29 -07:00
Ryan Fleury 3b1aae44d0 location info baking 2025-09-05 15:19:29 -07:00
Ryan Fleury 71cbdba76e remove old section requirement part of rdi, since all sections are now fixed; unit/scope/global vmap baking; collapse chunk list impls 2025-09-05 15:19:29 -07:00
Ryan Fleury e4ac3febd0 finish new udt baking; pull members & enum vals out of sub-udt lists, makes it much harder to layout & parallelize - instead pull them aside into their own chunk lists, require that UDTs just point to their first member; that way we can go wide when baking UDT members/enum-vals 2025-09-05 15:19:29 -07:00
Ryan Fleury b8414c4bfd type, first part of udt baking, string baking 2025-09-05 15:19:29 -07:00
Ryan Fleury ad4e57ec5a idx run baking 2025-09-05 15:19:29 -07:00
Ryan Fleury b22f6d3544 fully wide name map baking, joining, & sorting 2025-09-05 15:19:29 -07:00
Ryan Fleury 95e88e92e7 top-level info string baking 2025-09-05 15:19:29 -07:00
Ryan Fleury 618233eba1 checkpoint on new baker; globals, threads, inline sites 2025-09-05 15:19:29 -07:00
Ryan Fleury 595270bdab path tree baking 2025-09-05 15:19:29 -07:00
Ryan Fleury b169090dc6 checkpoint on new rdi baking; line table baking, string map building, plug in radsort over bad radix sort; arena tweak to aovoid unnecessary zeroes 2025-09-05 15:19:29 -07:00
Ryan Fleury 66ec3e834b rdi baking: wide line table gathering/joining & sorting 2025-09-05 15:19:29 -07:00
Ryan Fleury 69d0da9586 checkpoint on moving all of radbin to wavefront-style, first step to going wide on rdi baking as well 2025-09-05 15:19:28 -07:00
Mārtiņš Možeiko d8bb8c76c6 add shadow stack register and read it in win32 thread context 2025-09-03 09:36:20 -07:00
Ryan Fleury c35c14dadb prefer last match to first in debug info, to gracefully avoid stale debug info in pdbs 2025-08-30 12:04:39 -07:00
Ryan Fleury be5634c448 p2r2 - final conversion output bundling 2025-08-19 17:02:05 -07:00
Ryan Fleury cdec8d5980 ctrl/demon: fastfail exception codes / notes; p2r2: finish symbol conversion etc. in new wavefront-style version 2025-08-19 16:47:12 -07:00
Nikita Smith 0656020ab3 sync primitive fixes 2025-08-18 19:26:35 -07:00
Nikita Smith 429ba8b080 helper for writing 32-bit address relocation 2025-08-18 19:09:32 -07:00
Nikita Smith eee6a9c08a natvis for obj list 2025-08-18 19:09:32 -07:00
Nikita Smith b56ce72b7f test cases for weak vs weak 2025-08-18 19:09:32 -07:00
Nikita Smith 257914da2f handle alternate name directive after obj input 2025-08-18 19:09:32 -07:00
Nikita Smith b19f73b93a change unresolved weak symbol type to undefined 2025-08-18 19:09:32 -07:00
Nikita Smith cdf515793f stop walking on reaching an undefined symbol 2025-08-18 19:09:32 -07:00
Nikita Smith 0983915f40 oops forgot to init the delay load dll hash table and the established name string 2025-08-18 19:09:32 -07:00
Nikita Smith b05237ceec handle anti-dependency weak symbol 2025-08-18 19:09:32 -07:00
Nikita Smith 31b2b1c0f7 add replacement cases for weak vs. undefined and vice versa 2025-08-18 19:09:32 -07:00
Nikita Smith 873aa475e8 update tests to conform to new linking rules 2025-08-18 19:09:32 -07:00
Nikita Smith 1bca83610f changed symbol search logic to run in three steps: undefined, weak,
and anti-dependency weak, allowing linking to proceed only after
symbols from previous step are added to the symbol table

this solves the problem of anti-dependency symbols because they are
searched in libraries if the dependency is unresolved weak symbol
2025-08-18 19:09:32 -07:00
Nikita Smith e1786d0a11 discard delay loads in the config before they get to link context builder 2025-08-18 19:09:32 -07:00
Nikita Smith 1ce2fbfd1a helper for setting default symbol 2025-08-18 19:09:32 -07:00
Nikita Smith a3582332ee push a null symbol as a terminator for /alternatename weak symbol chain 2025-08-18 19:09:31 -07:00
Nikita Smith 04d2877b40 strip leading white space 2025-08-18 19:09:31 -07:00
Nikita Smith 81381f9a6d minor cleanups 2025-08-18 19:09:31 -07:00
Nikita Smith 81c68cfdd3 register common and absolute symbols in library's symbol table 2025-08-18 19:09:31 -07:00
Nikita Smith e27831902e note 2025-08-18 19:09:31 -07:00
Nikita Smith c53b8d43d0 assign symbol indices before serializing symbols so forward-references
are possible
2025-08-18 19:09:31 -07:00
Ryan Fleury cff69f287a p2r2 more progress; src file line sequence equipping, sketch out symbol conversion - we unfortunately cannot currently easily subdivide units! we need to pull out the few 'record-range' concepts and make them flat first, e.g. proc base address for inline sites, frameproc info, etc. 2025-08-18 16:58:05 -07:00
Ryan Fleury 83d4afabd5 p2r2: types building 2025-08-18 16:28:22 -07:00
Ryan Fleury 0fa45fe71b p2r2: reslice per-lane work; bucket subsets of units by record count, rather than assigning units to lanes 2025-08-18 15:24:25 -07:00
Ryan Fleury 55f21018df unit conversion, line info conversion 2025-08-18 14:19:48 -07:00
Ryan Fleury 34cb8ded2c better uniform lane range distribution when count / lanes is not cleanly divisible; plug in source file path gathering 2025-08-18 12:01:55 -07:00
Ryan Fleury d52b6d7bca go wide on msf stream extraction 2025-08-18 11:36:33 -07:00
Ryan Fleury d0ece7bc57 hook up p2r2 to radbin 2025-08-18 11:26:05 -07:00
Ryan Fleury c33dd2869a define synchronization primitive interface in base layer, implement using os layer; convert all usage -> base layer; use base sync primitives in lane tctx info 2025-08-18 10:46:43 -07:00
Ryan Fleury a48651471d share-read in header analysis in radbin 2025-08-15 16:54:06 -07:00
Ryan Fleury e566b2ed30 checkpoint on wavefront-style pdb -> rdi converter 2025-08-15 16:50:28 -07:00
Ryan Fleury f1a1863d5c set up base-layer tctx info for thread wavefront metadata 2025-08-15 12:16:58 -07:00
Ryan Fleury f754b4c2db fix pointer/array comparison paths not being enabled for not-equal; fix value arithmetic paths applying in type comparisons 2025-08-15 11:31:50 -07:00
Ryan Fleury 83650a5fe0 support unsigned -> unsigned int; support as-style casts in expressions; pack int alias in pdb-produced rdis 2025-08-15 10:56:42 -07:00
Ryan Fleury 36c626e375 Merge branch 'master' of https://github.com/EpicGames/raddebugger into dev 2025-08-14 11:31:43 -07:00
Ryan Fleury 7be1faaa9b fix callstack cache lookup early out case 2025-08-13 14:13:10 -07:00
Ryan Fleury 5144ced282 turn off call stack tree macro for now 2025-08-13 13:46:02 -07:00
Ryan Fleury 6a8277536f fix one-sided bounds check in text containing-scope binary search 2025-08-13 13:21:34 -07:00
Nikita Smith 1d6eae2b18 minor fixes for gathering library members 2025-08-12 19:03:51 -07:00
Nikita Smith 086d774b8b fix ELF compressed header and skip duplicate sections 2025-08-12 14:10:13 -07:00
Ryan Fleury 788df5f556 os: barrier 2025-08-12 10:12:05 -07:00
Nikita Smith b50f309422 modified member queue logic to prioritize libs where pull-in reference
symbol is declared
2025-08-11 23:28:03 -07:00
Ryan Fleury a8f6142e63 eval/ir: do not strip enum types off when doing address operations 2025-08-11 16:18:39 -07:00
Ryan Fleury 36dcd65a83 first pass at call stack tree evaluation 2025-08-11 16:08:04 -07:00
Ryan Fleury 056604fb94 sketch out tline -> vline text wrapping cache types; first pass of async call stack tree builder 2025-08-11 13:46:06 -07:00
Nikita Smith 829a35430c add flag to exclude objs from debug info input 2025-08-11 02:49:26 -07:00
Nikita Smith 702fd74b23 minor cleanup in obj initer 2025-08-10 21:41:39 -07:00
Nikita Smith 2b02f5cec6 lifetime fixes
- fully serialize the lib because we cannot guarantee that its members
  will have the same lifetime as the serialized lib
- put import stub symbols on the symbol table arena
2025-08-10 21:35:33 -07:00
Nikita Smith 7466da1479 mark referenced symbols as live for unresolved-symbol detection 2025-08-08 15:54:21 -07:00
Nikita Smith 9893a8135d fix crash when linking undefined weak symbol 2025-08-08 13:35:47 -07:00
Nikita Smith 137eb6403a fix crash when relocation points to an undefined section symbol 2025-08-07 22:40:20 -07:00
Nikita Smith 4f6f9d61ed inline function for replacing weak symbols with default symbol 2025-08-07 17:41:45 -07:00
Nikita Smith 9a1f96bda2 progress on /opt:ref
Link the debugger and strip unreferenced sections
TODO: Mark referenced undefined symbols for unresolved symbol reporting
2025-08-07 17:36:11 -07:00
Ryan Fleury e1d6b9f319 tweaks 2025-08-06 17:21:44 -07:00
ed 0c32946cd6 Merge remote-tracking branch 'EpicGamesExt/master' 2025-08-06 18:45:17 -04:00
Ryan Fleury af5dcffdac tie scope rendering to settings 2025-08-06 14:33:17 -07:00
Ryan Fleury a227aff8f6 finish containing-scope visualization 2025-08-06 14:24:12 -07:00
Ryan Fleury cd8c3a2172 enable read/write bits on just read data breakpoint on x64 - there is no way to do a read-only (without write) data breakpoint 2025-08-06 11:50:01 -07:00
Ryan Fleury 4c10e84e5f fix txt cache scope lookup binary search 2025-08-05 21:17:50 -07:00
Ryan Fleury 01f60834e9 plug in text scope tree to code slice visualization 2025-08-05 16:36:59 -07:00
Ryan Fleury 230f452edb text cache scope tree lookup paths 2025-08-05 16:11:49 -07:00
Ryan Fleury 5a5fd53bfa scope tree / sorted scope endpoints parsing in text cache parsing 2025-08-05 14:28:49 -07:00
Ryan Fleury c4374810cb fix wrong void type in pdb -> rdi 2025-08-05 13:41:10 -07:00
Ryan Fleury 9cff2bc7dd symbolof operation in eval 2025-08-05 10:21:42 -07:00
Ryan Fleury 1856c52e58 xxhash for ctrl layer 2025-08-05 09:27:38 -07:00
Nikita Smith cff6426741 null check for obj 2025-08-05 08:39:12 -07:00
Nikita Smith d3dedd8bef simplifying symbol table scopes
Linker cannot register extern import symbols initially because
the import object files are not available until all other object files are
resolved. To work around this, we create a stub weak symbol and assign
it to each import symbol. This allows linker to proceed. Once the import
object files are generated, linker replaces the stub symbol with
the actual ones from the import objects.
2025-08-05 08:39:12 -07:00
Nikita Smith dd715dacf7 assign COMDAT symlinks as soon as the symbol table is processed 2025-08-05 08:39:11 -07:00
Nikita Smith 1fe85acff8 refactor include symbols to go through same code path as alternate name symbols 2025-08-05 08:39:11 -07:00
Nikita Smith c1958809eb make use of undocumented anti-dependency search property on weak symbols
to implement alternate name using weak symbols
2025-08-05 08:39:11 -07:00
Nikita Smith 8d246d0c6a pass down to config obj; preparing to refactor alternate name out of the symbol table 2025-08-05 08:39:11 -07:00
Ryan Fleury 31973ac2ac eliminate extra type stuff in rdim, organize / reslice dwarf conversion code, start reading through dwarf conversion 2025-08-04 14:19:17 -07:00
Ryan Fleury b31b4612e9 pre-emptive thread register cache updating on ctrl thread - cache reading/updating on ui thread should always be allowed to gracefully fail, since it is literally impossible on linux, but we can always rely on the ctrl thread to pipe the right thing through eventually. 2025-08-04 13:13:18 -07:00
Ryan Fleury 9c2bdf492f ptrace register reading debugging 2025-08-04 12:36:04 -07:00
Ryan Fleury 209c5e96b8 bitmap view -> rich hover 2025-08-01 11:45:28 -07:00
Ryan Fleury 25963dc9b4 demon/linux: correct main module address range formation; further progress on event processing 2025-07-31 17:33:58 -07:00
Ryan Fleury a323aec6d0 demon/linux: x64 trap writing 2025-07-31 15:10:25 -07:00
Ryan Fleury 7c99e79981 demon/linux: first pass port at x64 register writing 2025-07-31 14:54:28 -07:00
Ryan Fleury 1a19bf9663 render/d3d11: adjust allowed frame 'latency' (frames-in-queue) based on number of active windows, to not unnecessarily block if we have two windows to build frames for; demon/linux: sketch out register writing path, ensure reg read/write paths have slots for other architectures 2025-07-31 14:09:42 -07:00
Ryan Fleury ad735dab5e pull raddbg byte attachment aside into standalone section - this guarantees byte placement, does not rely on ordering, and does not require symbols 2025-07-31 13:15:37 -07:00
Ryan Fleury 9ef87e9d56 fix to match 32 -> 64 change in demon/win32 2025-07-29 14:22:23 -07:00
Ryan Fleury 7403a8ea3b demon/linux: x64 register reading 2025-07-29 14:19:54 -07:00
Nikita Smith 92e6069104 collapse obj directive directive code paths 2025-07-28 20:07:56 -07:00
Nikita Smith 18f83521e4 clean up pass over directives handler; preparing to collapse code paths 2025-07-28 20:07:56 -07:00
Nikita Smith 0b904f4e24 extract function size infer logic into its own block 2025-07-28 20:07:56 -07:00
Nikita Smith 7be9df0e90 move directive section gather logic to obj layer 2025-07-28 20:07:56 -07:00
Nikita Smith 72e073e4e6 fix typo that broke /NODEFAULTLIB usage 2025-07-28 20:07:56 -07:00
Nikita Smith b3efce4b9a better place for this helper function 2025-07-28 20:07:56 -07:00
Nikita Smith 1e1d903878 store library pointer in the obj instead of path; required for prioritized symbol lookup implementation 2025-07-28 20:07:56 -07:00
Nikita Smith 4cb09e73c2 remove warning pragma 2025-07-28 20:07:56 -07:00
Nikita Smith 0b37fac81c move delay load helper to mscrt layer 2025-07-28 20:07:55 -07:00
Ryan Fleury 0e9f2ee03c demon/linux: halting, sigstop cases 2025-07-28 17:47:50 -07:00
Ryan Fleury 64c2d98ede demon/linux: sketch out signal interpretation, more ptrace study 2025-07-28 17:25:24 -07:00
Ryan Fleury 122c27eabe do not funnel non-dwarf sections in dwarf input prep pass 2025-07-28 16:22:23 -07:00
Ryan Fleury 48f5df2523 cleanup pass over elf parsing; base addr calculation? 2025-07-28 16:13:45 -07:00
Ryan Fleury 09f9cc25df os/linux: move-file-path impl 2025-07-28 14:54:48 -07:00
Ryan Fleury 2e8c0875c8 only use type-derived sizes in eval ranges when the evaluation is an offset, not a value 2025-07-28 14:34:46 -07:00
Ryan Fleury 5134d1ce4c adjust eval -> space range mapping to fix a few edge cases 2025-07-28 14:32:47 -07:00
Ryan Fleury c22ecf8e71 output clearing path 2025-07-28 12:05:37 -07:00
Ryan Fleury 97b4abd6de measure os file write helper success by bytes written - do not assume the write completes if the file handle is valid 2025-07-28 11:36:43 -07:00
Ryan Fleury 9b28ab68f2 adjust open user/project path to be more robust in cases of loading corrupted data on startup 2025-07-28 11:26:55 -07:00
Ryan Fleury e3a79dae86 apply slash insensitivity to fuzzy matches 2025-07-27 21:02:34 -07:00
Ryan Fleury 7dca3fd954 os/gfx/win32: fix bad alloc size in new utf16 clipboard path 2025-07-27 20:02:18 -07:00
Ryan Fleury 2e14f34cc8 derefence pointer/reference evaluations when generating block tree, to match expected behavior, & what the string iterator does 2025-07-25 16:11:17 -07:00
Ryan Fleury cb68abe844 packed bits test in mule 2025-07-25 15:31:22 -07:00
Ryan Fleury 163b79e4c0 decay bitfield types in casting path, allow casting to integer types 2025-07-25 15:29:34 -07:00
Ryan Fleury 393c291f63 reflect casting changes to call-cast style 2025-07-25 15:19:35 -07:00
Ryan Fleury 1c2855a314 unwrap decorative type operators on casts when building ops for casting, to allow for graceful enum casting; gracefully skip struct/enum symbol name prefixes 2025-07-25 15:17:39 -07:00
Ryan Fleury 1d67eb42a2 os win32 -> upgrade clipboard paths for unicode 2025-07-25 14:27:38 -07:00
Ryan Fleury 4d7088d321 do not pre-emptively exit the debug event loop on timeout unless we actually have debug strings 2025-07-25 14:21:31 -07:00
Ryan Fleury b5accc9105 apply floating flag to tooltip correctly 2025-07-25 14:00:23 -07:00
Ryan Fleury c43697fb18 fix type debug info table evaluations; fix preference for auto-hook-applied lhs evaluation when doing member/array accesses 2025-07-25 13:29:08 -07:00
Ryan Fleury 81b51446a4 cap maximum frame latency 2025-07-25 11:26:08 -07:00
Nikita Smith 6fda20ec9c helper script for extracting obj paths out of pdb 2025-07-24 17:44:13 -07:00
Nikita Smith 54fad8a89c validate strong symbol interp type 2025-07-24 17:32:05 -07:00
Nikita Smith 6cc5be0065 opt ref test 2025-07-24 17:32:05 -07:00
Nikita Smith 2d52e274ce remove debug code 2025-07-24 17:32:05 -07:00
Nikita Smith cc6e56eee1 do full path check for thin objs only 2025-07-24 17:32:05 -07:00
Ryan Fleury 955a5f01ca fix normalized path allocation 2025-07-23 17:28:14 -07:00
Ryan Fleury 66d5d93fc9 build path tree via non-case-mutated (non-normalized) src file paths in rdi build; still sanitize paths, but do not normalize them until we actually have to build the normalized file path map build 2025-07-23 17:18:54 -07:00
Ryan Fleury 45d1f8e58b clear overwritten path on cfg writes 2025-07-23 16:24:34 -07:00
Nikita Smith 9b91a0f907 github actions fun 2025-07-23 16:09:48 -07:00
Nikita Smith 9fab69002c fix buffer over-read in sinfl.h 2025-07-23 16:09:48 -07:00
Nikita 295a822889 put quotes around arguments to prevent command injection 2025-07-23 16:09:48 -07:00
Nikita Smith 07c7178770 filter out removed COMDATs from the PDB public symbols 2025-07-23 16:09:48 -07:00
Nikita Smith ffc9317067 add a relocation to "a" to prevent linker from removing .test 2025-07-23 16:09:48 -07:00
Nikita Smith 17d35cd327 add garbage collector for COMDAT sections 2025-07-23 16:09:48 -07:00
Nikita Smith a6b2cf64ba WIP collect sections associations 2025-07-23 16:09:48 -07:00
Nikita Smith a4ac07162e test abs vs abs 2025-07-23 16:09:48 -07:00
Nikita Smith d32667546d factor out weak symbol resolution logic and apply it to the symbol table
when building link context
2025-07-23 16:09:48 -07:00
Nikita Smith 7cd5a670e3 WIP factoring out symbol table fixups 2025-07-23 16:09:48 -07:00
Ryan Fleury 051bacf124 reflect cast changes in cast-calls 2025-07-23 16:05:30 -07:00
Ryan Fleury 3ae3f94db0 split unsigned => signed casting case from shrinking conversion truncation cast path 2025-07-23 16:04:59 -07:00
Ryan Fleury a776f53379 skip block group row unpack paths when we're doing the special case of a root block row generation 2025-07-23 15:20:41 -07:00
Ryan Fleury cf9d736ff5 promote register space -> primary space, on space reads 2025-07-23 15:00:05 -07:00
Ryan Fleury 38f769c00d only apply truncation to integer types, oops 2025-07-23 14:36:20 -07:00
Ryan Fleury cd64d959ef apply integer truncation operations on both sign/size changes, rather than just size 2025-07-23 14:31:51 -07:00
Ryan Fleury 8d1de1b24c report user errors from ctrl thread more vigorously 2025-07-23 14:06:17 -07:00
Ryan Fleury a85284793b be more robust to user/project paths passed via command line to raddbg; do not interpret them as targets 2025-07-23 14:03:39 -07:00
Ryan Fleury 87fa6b9239 fix <64-bit integer eval stringification path, to not interpret too many bits 2025-07-23 13:26:23 -07:00
Ryan Fleury 6026ac16d4 fix call stack flickering; do not timeout early if we need to fall back to stale results after requesting new call stack compute 2025-07-23 10:38:59 -07:00
Ryan Fleury 64a0682611 fix processing of select-alls in watch tabnles 2025-07-23 10:34:27 -07:00
Ryan Fleury fcf3e73f5f demon/linux: thread resuming in dmn_ctrl_run 2025-07-17 18:51:40 -07:00
Ryan Fleury 6fb406d6c5 demon/linux: launch event info coverage, module path strings, pipe deferred debug info events first on dmn_ctrl_run 2025-07-17 18:05:00 -07:00
Ryan Fleury d5380998a7 os/linux: fix rwlock cv waits 2025-07-17 16:32:12 -07:00
Ryan Fleury 145ad87967 fix incorrect font metrics in freetype font provider 2025-07-17 15:18:02 -07:00
Ryan Fleury eba2aff0f0 demon/linux: process read/write 2025-07-17 14:46:31 -07:00
Ryan Fleury 3466779d41 demon/linux: kill, detach, process iteration 2025-07-17 14:45:08 -07:00
Ryan Fleury 2db6b826a1 demon/linux: launching events/entity builds; access synchronization 2025-07-17 14:31:57 -07:00
Ryan Fleury 0610d5ae13 demon/linux: pid extraction, module extraction, most of launching path 2025-07-17 14:08:44 -07:00
Ryan Fleury 190b3384f9 preserve selected thread info on continues 2025-07-16 15:52:41 -07:00
Ryan Fleury 6e6a2df0cb implement 'priority thread' in demon, to prefer debug events from selected thread - greatly improves multithreaded stepping 2025-07-16 15:38:27 -07:00
Nikita Smith db52ba32e6 helper for profiling parallel fors 2025-07-16 13:54:58 -07:00
Nikita Smith 093e43d2ff change output folder name 2025-07-16 13:54:58 -07:00
Ryan Fleury 5e04734444 source_files collection evaluation; expand switch to allow file evaluations 2025-07-16 13:52:49 -07:00
Ryan Fleury f6931ef0b7 apply string size limitations from explicit array types in eval string iterator 2025-07-16 13:10:35 -07:00
Ryan Fleury fc8b521b2c adjust demon to correctly produce, & ctrl to correctly process, breakpoint events which cannot be correlated to a high-level UI-defined breakpoint state. this catches, for example, data breakpoints which are programmatically set by the user program. 2025-07-16 11:54:02 -07:00
Ryan Fleury 26f9e09483 eliminate cases where typekind_function was being assumed when building keys for function & inline site types - this cannot be assumed, and will lead to bad type info interpretation 2025-07-16 10:35:14 -07:00
Ryan Fleury 0902d9fafb detach in control menu 2025-07-01 20:08:44 -07:00
Ryan Fleury a4d0fbcb46 always show null pointer address values with string visualization 2025-07-01 09:46:12 -07:00
Ryan Fleury dc79c06031 adjust implicit accessing rules with nested auto hooks (slice-of-slices case); prefer to not show address value with string prefix content in single-line eval stringification 2025-06-30 09:33:23 -07:00
Ryan Fleury 15a7efab43 slice-of-slice ambiguity debugging note 2025-06-29 18:22:03 -07:00
Ryan Fleury 74e1ccd147 invalidate mem/reg/run generations on every dmn run 2025-06-28 11:18:02 -07:00
Ryan Fleury 124c71c19a notes & bump version 2025-06-28 11:15:02 -07:00
Ryan Fleury 89cfd65f9c fix incorrect programmatic bp generation on vaddr range notes... 2025-06-28 11:07:43 -07:00
Ryan Fleury 709bc2cfab float run/mem/reg generations out of demon, into core; fix issue of demon access synchronization w/ mem gens, causing failure-to-update-stale-parts-of-process-memory-cache 2025-06-28 10:02:51 -07:00
Ryan Fleury e34e8adbaa do not disqualify flagged expr breakpoints if 0 2025-06-27 23:15:02 -07:00
Ryan Fleury ac8c402868 note 2025-06-27 23:03:16 -07:00
Ryan Fleury b67d7f729b do not require eval cache for breakpoint touched-symbols parse/check; reintroduce memory read retry loop - necessary in some cases 2025-06-27 22:59:10 -07:00
Ryan Fleury 5ba9b6abd8 regression debugging & notes 2025-06-27 22:54:34 -07:00
Ryan Fleury 0018147b95 bounds-check di matches 2025-06-27 14:40:13 -07:00
Ryan Fleury d4c15d9089 pull out type-only identifier resolution and switch to match store; eliminate synchronous matching work 2025-06-27 13:55:18 -07:00
Ryan Fleury d723a00979 zero precise match info before doing matches in dbgi async match path, so we don't keep stale ones around too long, once they've been invalidated 2025-06-27 12:52:13 -07:00
Ryan Fleury 09a047feee zero match store dbgi/idx selection info if params hash has changed; we can still return the section kind (e.g. for syntax highlighting), but we no longer want to try to refer to any specific debug info slot, since it may have been evicted. 2025-06-27 12:36:27 -07:00
Ryan Fleury 5750c17c80 eliminate old slow identifier resolution path 2025-06-27 12:34:46 -07:00
Ryan Fleury 29886171b3 fix missing strtbl stream case in msf parser 2025-06-27 12:24:58 -07:00
Ryan Fleury 460dbe52fe fix invalid strtbl validity check in pdb_has_file_ref path 2025-06-27 12:19:07 -07:00
Ryan Fleury b315bf6811 switch eval debug info symbol name resolution to using async match store 2025-06-27 11:58:04 -07:00
Ryan Fleury a702e187ef expand match store cache to include all match info 2025-06-27 11:24:59 -07:00
Ryan Fleury 0d75e8e5e0 fix raddbg_is_attached data marker - static won't work, will be stripped... 2025-06-25 17:36:03 -07:00
Nikita Smith 4322c9ccfc change torture to assume default liker to be radlink, typo fix, and
added progress report
2025-06-25 10:53:25 -07:00
Nikita Smith 17ca83697b draft symbol table fixups to prepare for refactoring symbol table patching step 2025-06-25 10:53:25 -07:00
Nikita Smith 08f2b749e8 omit file offset, file size, and hash on bss sections 2025-06-25 10:53:25 -07:00
Nikita Smith 7769a485ba more merge fixes 2025-06-25 10:53:25 -07:00
Nikita Smith 91ddd214b3 fix string to U64 conversion
- handle zero on input string
- handle upper and lower case prefixes
2025-06-25 10:53:25 -07:00
Nikita Smith a954c2125c merge fixups 2025-06-25 10:53:25 -07:00
Nikita Smith fcb06579a4 collapse symbol scope and symbol type enums 2025-06-25 10:53:25 -07:00
Nikita Smith b1723ce066 gracefully handle invalid libs 2025-06-25 10:53:25 -07:00
Nikita Smith 2ba9f2a61b fix uinited var warning 2025-06-25 10:53:24 -07:00
Nikita Smith 153d78ec6a unpoison memory-mapped files 2025-06-25 10:53:24 -07:00
Nikita Smith 790c95fc80 organization pass over symbol table files 2025-06-25 10:53:24 -07:00
Nikita Smith 7120d0c1a4 share memory mapped files 2025-06-25 10:53:24 -07:00
Nikita Smith 2fbaafa32c parallel compute common block 2025-06-25 10:53:24 -07:00
Nikita Smith a395398bdf remove global variable for null section contrib 2025-06-25 10:53:24 -07:00
Nikita Smith f5b19675cb merge conflict 2025-06-25 10:53:24 -07:00
Nikita Smith 0aadf60359 update code block dividers 2025-06-25 10:53:24 -07:00
Nikita Smith 46663688e2 on read memory map files 2025-06-25 10:53:24 -07:00
Nikita Smith 16e72fd573 remove unused switch 2025-06-25 10:53:24 -07:00
Nikita Smith 6b3a63f474 correct task name for weak symbol patch 2025-06-25 10:53:24 -07:00
Nikita Smith 65095437b7 allow forward reference tag symbols 2025-06-25 10:53:24 -07:00
Nikita Smith e487fbc494 minor torture fixes 2025-06-25 10:53:24 -07:00
Nikita Smith ba326924ee test for relocation against removed COMDAT 2025-06-25 10:53:24 -07:00
Nikita Smith ad3e6e0b79 pipe obj reads through IO layer 2025-06-25 10:53:24 -07:00
Nikita Smith 4c972c0fba handle COMDAT symbols with non-zero section offset 2025-06-25 10:53:24 -07:00
Nikita Smith 422829b196 print align and debug sections 2025-06-25 10:53:24 -07:00
Nikita Smith bddf088df1 collect type indices in L_THREAD32 2025-06-25 10:53:24 -07:00
Nikita Smith c7d6145ec9 print section contributions in RAD_MAP 2025-06-25 10:53:24 -07:00
Nikita Smith 1fde5a5120 linker natvis 2025-06-25 10:53:24 -07:00
Nikita Smith 06e844abaa remove default delay bind table 2025-06-25 10:53:24 -07:00
Nikita Smith 048600260c special case fill for bss contribs 2025-06-25 10:53:24 -07:00
Nikita Smith a4b4d5799a fixes for delay import by ordinal and null terminate ILT, IAT, BIAT, and UIAT 2025-06-25 10:53:24 -07:00
Nikita Smith 8ba64238a2 delay load test 2025-06-25 10:53:24 -07:00
Nikita Smith 3c4edba465 validate section flags on merge 2025-06-25 10:53:24 -07:00
Nikita Smith cccbbfc74c do not patch debug section symbols and patch replaced COMDATs in separate
pass
2025-06-25 10:53:24 -07:00
Nikita Smith b19be0574c function pad min - final pass over 2025-06-25 10:53:24 -07:00
Nikita Smith bbb825adf4 extract hotpatch flag from compile symbol 2025-06-25 10:53:24 -07:00
Nikita Smith a5119e3b51 WIP function pad min 2025-06-25 10:53:24 -07:00
Nikita Smith d7b8de5998 test empty section and section with removed flag 2025-06-25 10:53:24 -07:00
Nikita Smith 5fb0d978b9 WIP function pad min 2025-06-25 10:53:24 -07:00
Nikita Smith 9d93eda3ed simplify section table 2025-06-25 10:53:24 -07:00
Nikita Smith ecdee57c60 move helpers to COFF layer 2025-06-25 10:53:24 -07:00
Nikita Smith a484906cf9 create section contribution for common block 2025-06-25 10:53:24 -07:00
Nikita Smith 95bea877ab merge .bss with custom section to simplify linker output verification 2025-06-25 10:53:24 -07:00
Nikita Smith 15836572f4 factor out section sort index into contribution chunk and simplify
contribution sorting
2025-06-25 10:53:24 -07:00
Nikita Smith f64265aafe typo in contrib sort 2025-06-25 10:53:24 -07:00
Nikita Smith 246bbf1e23 fix common block patch 2025-06-25 10:53:24 -07:00
Nikita Smith 490b22f6f9 put common blocks in .bss 2025-06-25 10:53:24 -07:00
Nikita Smith 626d94104d atomic contrib push 2025-06-25 10:53:24 -07:00
Nikita Smith b3aadbd49a store first data node in section contrib 2025-06-25 10:53:24 -07:00
Nikita Smith 3fb5e21d73 profiler markup 2025-06-25 10:53:24 -07:00
Nikita Smith 439fd0324d typos 2025-06-25 10:53:24 -07:00
Nikita Smith 75d02f1c1e check symbol presence using stable name pointer 2025-06-25 10:53:24 -07:00
Nikita Smith 5fd06f4466 do not push section contribs for sections without bytes 2025-06-25 10:53:24 -07:00
Nikita Smith af00acd0f5 add missing symbol replacement logic 2025-06-25 10:53:24 -07:00
Nikita Smith 205723f8d6 parallelize symbol tables patching 2025-06-25 10:53:24 -07:00
Nikita Smith d604456def align sizeofs 2025-06-25 10:53:24 -07:00
Nikita Smith 32a22779da fix run 2025-06-25 10:53:24 -07:00
Nikita Smith 7d77210a5f run test after build 2025-06-25 10:53:24 -07:00
Nikita Smith 25710d39b7 test optional header fields 2025-06-25 10:53:24 -07:00
Nikita Smith fe967a3d36 more validity checks in simple_link_test 2025-06-25 10:53:24 -07:00
Nikita Smith c4a36f73dc redirect stdout and stderr to a file 2025-06-25 10:53:24 -07:00
Nikita Smith 1c08db2705 move image, import lib, and debug info builders outside of the state machine 2025-06-25 10:53:24 -07:00
Nikita Smith e971db7fdd remove unused layout flag in section struct 2025-06-25 10:53:24 -07:00
Nikita Smith 47ef37ed8e fix section order 2025-06-25 10:53:24 -07:00
Nikita Smith 881050addf add default merges and section removes 2025-06-25 10:53:23 -07:00
Nikita Smith a4b2d40d15 fix sizeof section headers 2025-06-25 10:53:23 -07:00
Nikita Smith 578a7ebdee factor out pdata code to PE layer 2025-06-25 10:53:23 -07:00
Nikita Smith f055267e59 remove double init and equip of thread contexts 2025-06-25 10:53:23 -07:00
Nikita Smith aae3874521 disable TLS merge for now 2025-06-25 10:53:23 -07:00
Nikita Smith c82b98cd49 assign section index to .reloc 2025-06-25 10:53:23 -07:00
Nikita Smith e1278a6545 null terminate static imports 2025-06-25 10:53:23 -07:00
Nikita Smith e65d1536b6 dynamic loader crashes if the import data is not in a stand-alone section 2025-06-25 10:53:23 -07:00
Nikita Smith 54e7f9aafc appease ASAN 2025-06-25 10:53:23 -07:00
Nikita Smith 1c656979d2 move MSVC lib symbols to CRT layer 2025-06-25 10:53:23 -07:00
Nikita Smith 47e123221a minor fixes 2025-06-25 10:53:23 -07:00
Nikita Smith 86556c68ed point TLS directory to TLS header 2025-06-25 10:53:23 -07:00
Nikita Smith 3d2b1e19e3 handle communal var vs regular non-comdat symbol 2025-06-25 10:53:23 -07:00
Nikita Smith 42bed0e5c6 merge delayed data section with .data 2025-06-25 10:53:23 -07:00
Nikita Smith f2394b6cf7 off-by-one 2025-06-25 10:53:23 -07:00
Nikita Smith e911bf5368 move obj writer for PE debug directory to stand-alone file 2025-06-25 10:53:23 -07:00
Nikita Smith 7f6d8004a9 fix import dll debug symbols 2025-06-25 10:53:23 -07:00
Nikita Smith 89e2ea15ad add /RAD_REMOVE_SECTION switch and special case debug sections 2025-06-25 10:53:23 -07:00
Nikita Smith 9c59cfd4e7 pointless check, in .debug relocations point to __ImageBase 2025-06-25 10:53:23 -07:00
Nikita Smith d51fe49bab delay import fix 2025-06-25 10:53:23 -07:00
Nikita Smith dcc4f38709 clean up pass over obj file 2025-06-25 10:53:23 -07:00
Nikita Smith 64415e21f0 special case bss section contribs and fix off by one in range array bsearch 2025-06-25 10:53:23 -07:00
Nikita Smith 37689b2e4a section collector 2025-06-25 10:53:23 -07:00
Nikita Smith 382204a4ea WIP test delay user32 import 2025-06-25 10:53:23 -07:00
Nikita Smith 8fb0aaf2b3 test kernel32 import 2025-06-25 10:53:23 -07:00
Nikita Smith fb0e8d7579 fix crash on COMDAT folding communal variable 2025-06-25 10:53:23 -07:00
Nikita Smith 9060004827 test for communal variable 2025-06-25 10:53:23 -07:00
Nikita Smith 40efbeb512 test for /INCLUDE 2025-06-25 10:53:23 -07:00
Nikita Smith 8d7bd6f9fe minor fixes
- copy alt name to config arena
- promote alternate name conflict error to stop run
- remove unused error code
2025-06-25 10:53:23 -07:00
Nikita Smith da0e7e5f69 test for /ALTERNATENAME 2025-06-25 10:53:23 -07:00
Nikita Smith ea81d18223 test for out of bounds section number on external symbol 2025-06-25 10:53:23 -07:00
Nikita Smith ef476bf1f0 tests for COMDAT Associative selection 2025-06-25 10:53:23 -07:00
Nikita Smith bf25b5b249 handle COMDAT Associative selection 2025-06-25 10:53:23 -07:00
Nikita Smith 69d4e31b15 helper for parsing COFF symbols 2025-06-25 10:53:23 -07:00
Nikita Smith 8fad6da751 add support for associative COMDAT symbols 2025-06-25 10:53:23 -07:00
Nikita Smith 889b1807f2 test for COMDAT Largest selection 2025-06-25 10:53:23 -07:00
Nikita Smith e97d476c7c test for COMDAT ExactMatch selection 2025-06-25 10:53:23 -07:00
Nikita Smith bde11caf11 improve exact match selection 2025-06-25 10:53:23 -07:00
Nikita Smith 4b8c9db8f5 add dependency to COMDAT symbol so we do not need to link with /OPT:NOREF 2025-06-25 10:53:23 -07:00
Nikita Smith 9bea163d10 test COMDAT SameSize selection 2025-06-25 10:53:23 -07:00
Nikita Smith aafb980c6b prevent dropping of newly inserted symbol while selecting slot leader 2025-06-25 10:53:23 -07:00
Nikita Smith 3eb7debad5 check COMDAT symlink points to a defined symbol 2025-06-25 10:53:23 -07:00
Nikita Smith 8d324775a2 test COMDAT NoDuplicates selection 2025-06-25 10:53:23 -07:00
Nikita Smith 3978181d02 check symbol type before patching section header 2025-06-25 10:53:23 -07:00
Nikita Smith a6924a22cf by default stop on undefined section symbol 2025-06-25 10:53:23 -07:00
Nikita Smith c907a10365 fixup test for COMDAT Any 2025-06-25 10:53:23 -07:00
Nikita Smith f5504c79e9 test COMDAT any selection 2025-06-25 10:53:23 -07:00
Nikita Smith 4aa6e6d132 store symbol links for COMDAT 2025-06-25 10:53:23 -07:00
Nikita Smith 9b6a15ce66 headers for delay import table columns 2025-06-25 10:53:23 -07:00
Nikita Smith f0a967a15d don't create BIAT and UIAT sections when not requested 2025-06-25 10:53:23 -07:00
Nikita Smith 9c93ee1579 compute correct IAT size 2025-06-25 10:53:23 -07:00
Nikita Smith b1cd2146ac patch export table directory using section contribs 2025-06-25 10:53:23 -07:00
Nikita Smith 0f9321e92a move default linker options to main file 2025-06-25 10:53:23 -07:00
Nikita Smith dcc8bfcf39 test section merges 2025-06-25 10:53:23 -07:00
Nikita Smith c2b3634e7a guard against circular section merges 2025-06-25 10:53:23 -07:00
Nikita Smith 2e531cd70a refactored special case for image base 2025-06-25 10:53:22 -07:00
Nikita Smith d22962af8d warn about exporting entry point symbol 2025-06-25 10:53:22 -07:00
Nikita Smith 90797f363f fix for machine compatibility check 2025-06-25 10:53:22 -07:00
Nikita Smith b709640ddc test for machine compatibility 2025-06-25 10:53:22 -07:00
Nikita Smith b7a06f3f7f sort on section index too 2025-06-25 10:53:22 -07:00
Nikita Smith 422e9449c8 natvis for section contrib types 2025-06-25 10:53:22 -07:00
Nikita Smith b8f45e97c9 test section alignment flags 2025-06-25 10:53:22 -07:00
Nikita Smith 87acc95016 set section align in common block test 2025-06-25 10:53:22 -07:00
Nikita Smith c0613c2a7e section align fixes 2025-06-25 10:53:22 -07:00
Nikita Smith 681c1619fb finish undefined section test 2025-06-25 10:53:22 -07:00
Nikita Smith a3bcfe01e1 fix signedness issue 2025-06-25 10:53:22 -07:00
Nikita Smith 671431cfbd remove unused define 2025-06-25 10:53:22 -07:00
Nikita Smith d5297e01ac workaround for image base address 2025-06-25 10:53:22 -07:00
Nikita Smith 971f6ec368 test virtual offset relocation with __ImageBase 2025-06-25 10:53:22 -07:00
Nikita Smith c98ae0925f error check relocations 2025-06-25 10:53:22 -07:00
Nikita Smith ad069cb854 unknown relocation 2025-06-25 10:53:22 -07:00
Nikita Smith 73fe9d223a handle /ALTERNATENAME directive 2025-06-25 10:53:22 -07:00
Nikita Smith 60d3f25057 test for __ImageBase with relative and address relocations 2025-06-25 10:53:22 -07:00
Nikita Smith 03e4958190 assign layout offsets and sizes to merged sections 2025-06-25 10:53:22 -07:00
Nikita Smith f75cdd23d7 collapse linker input states into one state 2025-06-25 10:53:22 -07:00
Nikita Smith d3c3b672ea image name helper 2025-06-25 10:53:22 -07:00
Nikita Smith 6fd9ab7388 strip postfix when searching for section 2025-06-25 10:53:22 -07:00
Nikita Smith a2bef106a1 handle case where symbol doesn't have obj 2025-06-25 10:53:22 -07:00
Nikita Smith 1cc23e42ff delay import objs 2025-06-25 10:53:22 -07:00
Nikita Smith c209dd730a set ordinal low in export finalize path 2025-06-25 10:53:22 -07:00
Nikita Smith ac261b3eed trim obj paths pulled in from libs 2025-06-25 10:53:22 -07:00
Nikita Smith f2c7e69844 natvis for hash table 2025-06-25 10:53:22 -07:00
Nikita Smith 71596b2f3e collapse make API for imports 2025-06-25 10:53:22 -07:00
Nikita Smith 65944f0444 clean up pass over COFF writer 2025-06-25 10:53:22 -07:00
Nikita Smith 34a87e7828 create member symbol only for imports with name 2025-06-25 10:53:22 -07:00
Nikita Smith 89239fc744 test reloc for section symbol with merged section 2025-06-25 10:53:22 -07:00
Nikita Smith f467ff8822 WIP move export and import table make code to appropriate layers 2025-06-25 10:53:22 -07:00
Nikita Smith 69d5010245 WIP switching to creating import table objs 2025-06-25 10:53:22 -07:00
Nikita Smith 1b21d0709f return symbol for pushed lib member 2025-06-25 10:53:22 -07:00
Nikita Smith 2c5fb7e7ef guard against merges with resource and base reloc sections 2025-06-25 10:53:22 -07:00
Nikita Smith 86fe2ddd38 remove arena per section 2025-06-25 10:53:22 -07:00
Nikita Smith 8da56025b3 patch section symbol and test for relocations to discarded memory 2025-06-25 10:53:22 -07:00
Nikita Smith 40fda5335c move default section flags to separate file to use them in torture 2025-06-25 10:53:22 -07:00
Nikita Smith bd830a6023 test case for relocation to undefined section with base relocations 2025-06-25 10:53:22 -07:00
Nikita Smith f25dc5cc8d pack export table into obj and input back to the linker 2025-06-25 10:53:22 -07:00
Nikita Smith c5164bd490 discard null data nodes 2025-06-25 10:53:22 -07:00
Nikita Smith 3ffd8c19ea helper for querying machine specific relocation for virtual offset relocation 2025-06-25 10:53:22 -07:00
Nikita Smith c55c60549e export virtual ranges for data directories 2025-06-25 10:53:22 -07:00
Nikita Smith f37f94a2b9 minor fixes 2025-06-25 10:53:22 -07:00
Nikita Smith 4161dd0440 check export table entries 2025-06-25 10:53:22 -07:00
Nikita Smith 9bcb227ed9 test imports and exports 2025-06-25 10:53:22 -07:00
Nikita Smith 35e6b4a9f9 linker directive header fix 2025-06-25 10:53:22 -07:00
Nikita Smith e7c808ee69 test simple lib link 2025-06-25 10:53:22 -07:00
Nikita Smith 3a7afcd80c replace linker lib writer with one from COFF 2025-06-25 10:53:22 -07:00
Nikita Smith 120829095b COFF lib writer 2025-06-25 10:53:22 -07:00
Nikita Smith ccf204d2f1 build target for torture 2025-06-25 10:53:22 -07:00
Nikita Smith 7c071e7238 linker checkpoint 2025-06-25 10:53:22 -07:00
Nikita Smith a60216fa9f minor fixes in hash table 2025-06-25 10:53:22 -07:00
Nikita Smith 0f81aae985 extend COFF obj writer with ability to produce linker directive section 2025-06-25 10:53:22 -07:00
Nikita Smith 45ca147579 report test stats, and check the exit code 2025-06-25 10:53:22 -07:00
Nikita Smith b0a652b10b helpers for parsing aux COFF symbols 2025-06-25 10:53:22 -07:00
Nikita Smith f81bab5a4c remove special sort postfix case 2025-06-25 10:53:22 -07:00
Nikita Smith 63a374cf54 simplify COFF reloc apply helper 2025-06-25 10:53:22 -07:00
Nikita Smith a5b3df7d1b check flags on custom bss section 2025-06-25 10:53:22 -07:00
Nikita Smith 5cb682bcb3 check common block relocs and sort 2025-06-25 10:53:22 -07:00
Nikita Smith cede94f8d9 test for conflicting section header flags and common bss and common block
basic tests
2025-06-25 10:53:21 -07:00
Nikita Smith e9d5022a55 test section sorter 2025-06-25 10:53:21 -07:00
Nikita Smith 0772617486 add relocation for shared symbol in abs_vs_regular test
test linker on base relocations to abs symbols
2025-06-25 10:53:21 -07:00
Nikita Smith 2a0929014b test weak tag 2025-06-25 10:53:21 -07:00
Nikita Smith f39397fa78 test cycles made from weak symbols 2025-06-25 10:53:21 -07:00
Nikita Smith 2c6db1b566 update COFF type enum strings 2025-06-25 10:53:21 -07:00
Nikita Smith 174c6ebb7d bugfix data directory range export 2025-06-25 10:53:21 -07:00
Nikita Smith f17ed8485d add tests for symbols with absolute address 2025-06-25 10:53:21 -07:00
Nikita Smith 01c905dbbd reuse import table flags, and parameterize data directory count 2025-06-25 10:53:21 -07:00
Nikita Smith c56cfefe09 move rsp unwrapper to config 2025-06-25 10:53:21 -07:00
Nikita Smith 3875b057d7 delete string compars form linker layer 2025-06-25 10:53:21 -07:00
Nikita Smith c2a0a6f1e1 factored out format specific relocation code to COFF layer 2025-06-25 10:53:21 -07:00
Nikita Smith ada037cb88 export range for data directories, subsystem, and check sum 2025-06-25 10:53:21 -07:00
Nikita Smith f001f08e04 string compar funcs 2025-06-25 10:53:21 -07:00
Nikita Smith 88d34eff54 simple link test 2025-06-25 10:53:21 -07:00
Nikita Smith 19694dac2a test case for merged pdata 2025-06-25 10:53:21 -07:00
Nikita Smith b9768be4ed tester for linkers 2025-06-25 10:53:21 -07:00
Nikita Smith 19a7ada1dc make export table with COFF obj writer,
partially converted import table to COFF obj writer
2025-06-25 10:53:21 -07:00
Nikita Smith 3a2bb318c7 make import lib objs with COFF obj writer 2025-06-25 10:53:21 -07:00
Nikita Smith e580b69180 make linker obj with COFF obj writer 2025-06-25 10:53:21 -07:00
Nikita Smith c45088b546 replaced dependency on linker's chunking for resource serialization
with COFF obj writer
2025-06-25 10:53:21 -07:00
Nikita Smith 55c76db902 handle linker directives in a separate step after obj is initialized,
this way we don't need to store directives in obj struct
2025-06-25 10:53:21 -07:00
Nikita Smith 307d3a7f4b check obj compatibility before initializing them 2025-06-25 10:53:21 -07:00
Nikita Smith 1eca5818a6 removed dependency on relocation list when error checking .drectve 2025-06-25 10:53:21 -07:00
Ryan Fleury 36f5597d8e eliminate unneeded path-renormalization in debug info cache lookup 2025-06-25 10:52:29 -07:00
Ryan Fleury e2eb1cd6d6 do not unnecessarily block on parses when closing modules 2025-06-25 09:41:48 -07:00
Ryan Fleury 10a49ca331 actually, rely on entry point trap calculation to do exe-rdi waiting; adjust default fonts to be more consistent with windows 2025-06-25 08:32:48 -07:00
Ryan Fleury a2608261d1 always wait for initial module debug info 2025-06-25 07:56:51 -07:00
Ryan Fleury 5f1a0e27a8 sketch out event buffer opening/closing 2025-06-21 12:30:00 -07:00
Ryan Fleury 185056a5cd breakpoint list command 2025-06-21 12:10:07 -07:00
Ryan Fleury 6dbc275129 command coverage for target/bp modifications; allow full path matches when fuzzy searching through cfgs 2025-06-21 11:22:05 -07:00
Ryan Fleury 2595427189 request frames on all ipc receives 2025-06-21 09:57:25 -07:00
Ryan Fleury b6eca01e2a upgrade textual command -> cmd-regs-filling path, to use expression evaluation when possible, and to use fuzzy filtering over associated query lists when possible 2025-06-21 09:24:08 -07:00
Ryan Fleury 65f00f3b17 do not scale swapchain framebuffer contents 2025-06-20 13:52:51 -07:00
Ryan Fleury 7960a0546a fix rd cfg debug stringification for new hs apis 2025-06-20 13:45:42 -07:00
Ryan Fleury 7e08b58cd8 render/d3d11: switch to flip_discard model 2025-06-20 12:34:13 -07:00
Ryan Fleury ce9f7f691a always-refresh dev option 2025-06-20 10:55:45 -07:00
Ryan Fleury 995f65ee1a rdi dump parseability pass 2025-06-20 09:08:25 -07:00
Ryan Fleury ad995374bb cache module requirement disqualifications; reuse within scope of same run (& thus same user bps) 2025-06-20 07:57:16 -07:00
Ryan Fleury 327f0f128a more parseability coverage on rdi dumping 2025-06-19 21:15:16 -07:00
Ryan Fleury 248a155579 checkpoint on dump parseability pass 2025-06-19 16:48:07 -07:00
Ryan Fleury fa242b3d80 #if 0 broken code; fix clang build 2025-06-19 15:26:56 -07:00
Ryan Fleury d532f62aaa plug in expression-based breakpoints to RDI-necessary-checking path 2025-06-19 14:53:13 -07:00
Ryan Fleury bfe90f5906 plug in thin pdb analysis to determine if waiting on a full RDI conversion is necessary - do not wait if RDI is determined to be unnecessary given breakpoints! 2025-06-19 14:48:13 -07:00
Ryan Fleury b28b730788 plug in dwarf dumping to radbin 2025-06-19 13:37:28 -07:00
Ryan Fleury 052d32d534 sketch out dwarf in radbin 2025-06-19 11:12:10 -07:00
Ryan Fleury 056942a792 remaining dwarf dumping coverage 2025-06-19 11:00:24 -07:00
Ryan Fleury 8eab0e16b8 pass over .debug_abbrev dump 2025-06-19 10:41:42 -07:00
Ryan Fleury 7c35028a6b .debug_info dumping pass 2025-06-19 10:33:44 -07:00
Ryan Fleury a2ab822eb5 attrib -> attrib_kind; attrib_ptr -> attrib 2025-06-19 09:49:01 -07:00
Ryan Fleury 8dac256a12 consistency pass over dwarf layer 2025-06-19 09:44:41 -07:00
Ryan Fleury e37ee72feb ditto 2025-06-19 08:28:36 -07:00
Ryan Fleury db4831fafb include rad lzb codec directly in rdi parse library 2025-06-19 08:25:35 -07:00
Ryan Fleury 88867ac758 lib_rdi_format -> lib_rdi 2025-06-19 08:21:58 -07:00
Ryan Fleury 66c2d51a7d pass over dwarf dump, get it building, eliminate reliance on one-off helpers from raddump 2025-06-19 08:02:36 -07:00
Ryan Fleury f590e9b6d5 eliminate separate path layer, merge into base strings layer 2025-06-19 07:38:34 -07:00
Ryan Fleury f2dc9a7d4a fix codeview format/parse interleave 2025-06-19 07:29:24 -07:00
Ryan Fleury 058c1454e2 eliminate all extra enums files for formats 2025-06-19 07:25:35 -07:00
Ryan Fleury 699cb5134e dwarf dump => dwarf layer; eliminate separate dwarf enum file 2025-06-19 07:19:38 -07:00
Ryan Fleury a812dc95ce notes 2025-06-18 14:08:16 -07:00
Ryan Fleury 9f0da8d1b8 notes 2025-06-18 13:31:22 -07:00
Ryan Fleury 0ff246d13f fixes to ctrl call stack lookup path 2025-06-18 13:26:45 -07:00
Ryan Fleury df901b2497 pass over ctrl call stack lookup path, eliminate races between multiple retry loops 2025-06-18 12:42:34 -07:00
Ryan Fleury a1f71379f4 adjust thread extra string rendering to account for missing modules/rdi frames 2025-06-18 10:40:50 -07:00
Ryan Fleury bee2570d39 fix double-load in radbin conversion path; fix incorrect mutation of potentially-nil trees when snapping to a file without a specific line; fix di_close path when work is occurring 2025-06-18 09:56:47 -07:00
Ryan Fleury 401f117653 adjust step trap net build in case of memory read failure - ensure we get correct memory read, otherwise we can generate bad trap nets during heavy load. allow high vs. low priority in async rdi loading; use low-priority in pre-emptive case 2025-06-18 08:36:41 -07:00
Ryan Fleury 5de7c06d3b always zero param type keys 2025-06-17 07:26:17 -07:00
Ryan Fleury 53e6050ee0 outer loop timeout exit condition in ctrl process memory cache lookup 2025-06-16 09:10:25 -07:00
ed bd5ec34b38 Merge tag 'v0.9.20-alpha' 2025-06-13 23:07:02 -04:00
Ryan Fleury 6543dad458 use .rdi fallback only when generating rdi, use .psym for breakpad 2025-06-10 15:30:41 -07:00
Ryan Fleury 0ad3bb1550 fix radsort multi-inclusion 2025-06-10 15:15:54 -07:00
Ryan Fleury b8c0a6c4f0 adjust file format preamble for unsupported formats 2025-06-10 14:41:50 -07:00
Ryan Fleury 399915e14d fix default subsets in radbin dump 2025-06-10 14:40:23 -07:00
Ryan Fleury 0e414a3dfb fix clang build; adjust raddbg --convert option to --bin 2025-06-10 14:39:09 -07:00
Ryan Fleury f604ced174 bump version 2025-06-10 14:35:38 -07:00
Ryan Fleury 87fac3a42c adjust help to match rdi support only for now 2025-06-10 14:34:15 -07:00
Ryan Fleury 834f38f73b pass over rdi dumping code; relocate to rdi_format_local; eliminate redundant helpers; plug into radbin 2025-06-10 14:14:39 -07:00
Ryan Fleury 6096869004 pass over radbin help 2025-06-10 09:57:01 -07:00
Ryan Fleury 7205b7d1ab pass over base layer command line parsing. do not assume debugger-style 'treat all after first non-option input as passthrough options'. most things do not want that - the debugger can still get it by doing a quick secondary parse 2025-06-10 09:46:46 -07:00
Ryan Fleury 49de09883e plug in dwarf converter to radbin; hook up to both rdi generation & breakpad generation; radbin exe -> pdb / elf -> dwarf inferences; cleanup / unification passes 2025-06-10 08:53:57 -07:00
Ryan Fleury 638adad93b implement raddbg markup lib functions only once, allow inclusion of header across many TUs, linking with the implementation in only one 2025-06-10 06:42:28 -07:00
Ryan Fleury 79bf3d8639 eliminate standalone programs for pdb -> rdi; dwarf -> rdi; pdb -> breakpad; sketch out 'radbin', unified cli frontend for dumping/converting/etc., plug in pdb -> rdi, pdb -> breakpad, & stub out dumper/dwarf 2025-06-09 15:40:48 -07:00
Ryan Fleury 4926f6cfc8 programmatic address range annotations; pipe -> ctrl entities; render in memory view 2025-06-08 17:37:55 -07:00
Ryan Fleury bb2900c2b7 memory view: globals & procedures annotations, changed & bad visualization 2025-06-08 16:26:57 -07:00
Ryan Fleury c3f4c758b4 notes 2025-06-06 15:43:09 -07:00
Ryan Fleury 4057e00fa1 further memory view fixes / tweaks; rich hover coverage for virtual address ranges in memory views / watch views 2025-06-06 14:57:46 -07:00
Ryan Fleury 2d9929452c memory view go-to-address / cursor/mark tracking fixes 2025-06-06 12:09:07 -07:00
Ryan Fleury 60d88ac446 fix missing increment in eval token chunk list -> token array 2025-06-06 09:53:44 -07:00
Ryan Fleury c282e7d4be command outputs; ipc command output reception & writing to stdout 2025-06-05 16:08:53 -07:00
Ryan Fleury 3d7bfb41b8 pull aside project registration in user, pull aside last-opened-user setting, trigger on save user/project, as well as open. 2025-06-05 13:16:35 -07:00
Ryan Fleury a73cda80e7 adjust find-code-location path to account for many windows; always snap in obviously-correct cases (e.g. window has the source code focused), fall back to other rules, mask off extra snaps when snap destination is found by earlier passes. 2025-06-05 12:55:48 -07:00
Ryan Fleury 3e1bc21f95 p2r: hoist comp unit contributions bucketing out from per-unit path 2025-06-04 13:23:56 -07:00
Ryan Fleury 0512b61d95 p2r: wide/async per-unit src file gather/dedup; wide/async line (& inline) table conversion 2025-06-03 17:10:36 -07:00
Ryan Fleury ad0ead92c3 fix bad parent eval inheritance in raddbg_pin ui build 2025-06-03 14:28:17 -07:00
Ryan Fleury 00fd597658 fix ptr/ref coverage in expansions 2025-06-03 13:55:37 -07:00
Ryan Fleury b57deebd03 another pass over ctrl process memory cache lookup, prevent another deadlock case 2025-06-03 12:06:02 -07:00
Ryan Fleury 594594ec72 adjust ctrl memory cache committing condition to be more robust to bad regions. otherwise we were flooding new request to repeatedly recopy from the client, when we effectively already knew it would never be valid. 2025-06-02 15:28:26 -07:00
Ryan Fleury 44280f3dd0 fix bad wait condition in ctrl memory cache accessing 2025-06-02 14:45:52 -07:00
Ryan Fleury 94b969f203 copyright year 2025-06-02 14:13:57 -07:00
Ryan Fleury cff99f5431 oops, fix very bad mistake, using part of HS roots that don't exist! 2025-06-02 14:00:47 -07:00
Ryan Fleury becb61f00d many-thread-stepping test in mule, adjust call stack thread name decoration limit, now that call stack computation is async; tweak ctrl process memory cache lookup exit condition to be more robust to failed-read cases 2025-06-02 11:59:49 -07:00
Ryan Fleury e83c74db29 more ue type view coverage 2025-05-29 18:20:43 -07:00
Ryan Fleury af4972a333 all constants evaluation; constant autocompletion; constant name string baking fix 2025-05-29 17:50:35 -07:00
Ryan Fleury 6322427171 qualify constant names by containing type, if applicable; otherwise we get tons of duplicate constant names... 2025-05-29 17:36:41 -07:00
Ryan Fleury a111c21972 fix constant evaluation 2025-05-29 17:12:44 -07:00
Ryan Fleury 858f3866d4 fix name map kind name lookup build 2025-05-29 17:05:51 -07:00
Ryan Fleury 770fbe9459 constant evaluation 2025-05-29 17:04:01 -07:00
Ryan Fleury 89cc73eca6 constant name map 2025-05-29 16:57:08 -07:00
Ryan Fleury ae139fea05 raddump constants 2025-05-29 16:51:40 -07:00
Ryan Fleury bf5ac0d3e8 fill out constants in symbol stream conversion 2025-05-29 16:43:22 -07:00
Ryan Fleury 3513d6cfb9 first pass at rdi format constant value support 2025-05-29 16:37:36 -07:00
Ryan Fleury a53ccee46d more ue type view coverage 2025-05-29 13:55:52 -07:00
Ryan Fleury 477e2b19da fix preservation of ir tree chain w/ multiple composing type views 2025-05-29 13:40:46 -07:00
Ryan Fleury 14cfd87f68 start sketching out basic unreal type views 2025-05-28 18:00:16 -07:00
Ryan Fleury 7350c2d576 fix trailing wildcard matches 2025-05-28 15:51:15 -07:00
Ryan Fleury f116d88b08 wildcard instance identifier resolution in type views; ?{arg1, arg2, arg3} in type view pattern -> use arg1, arg2, or arg3 in expression 2025-05-28 15:41:48 -07:00
Ryan Fleury 1d72de8c4a pattern parts as strings -> pattern part type, which can include wildcard inst names 2025-05-28 14:52:21 -07:00
Ryan Fleury de3782c974 do not advance wildcard scan position if wildcard match done 2025-05-28 14:42:20 -07:00
Ryan Fleury d0a2c0f22c auto hook list(expr) -> auto hook list(match), where match includes both an expression and a list of comma-delimited wildcard instances 2025-05-28 14:37:44 -07:00
Ryan Fleury 1609c8f948 clean up & fixup pass over type pattern matching, allow closed {}s, ()s, []s, <>s in wildcards 2025-05-28 14:08:53 -07:00
Ryan Fleury 70ccfd2d86 do greedy ? matching in type pattern matching by default 2025-05-28 13:07:18 -07:00
Ryan Fleury 8bf07f8a52 bump to 19 2025-05-22 22:37:03 -07:00
Ryan Fleury 58df68b9be adjust good-machine-code check to factor in memory read failure mask 2025-05-22 17:15:51 -07:00
Ryan Fleury 914273d5af hack in quick fix for overambitious type pattern matching - will do a better pass shortly... 2025-05-22 12:29:56 -07:00
Ryan Fleury 4aeadc12b7 adjust memory reading fail conditions in trap net generation; fix early-aborting of retry loop in process memory cache lookup 2025-05-22 12:15:31 -07:00
Ryan Fleury 02611de6af broadcast wakeup event on ctrl cache commits 2025-05-22 11:39:08 -07:00
Ryan Fleury c41d67120f fix incorrect bounds check in new per-line fstrs building path 2025-05-22 11:13:18 -07:00
Ryan Fleury 25813e62ea adjust spall usage code - still not generating multi-thread events correctly... 2025-05-22 09:58:09 -07:00
Ryan Fleury 3fcdb85ebf use tid/pid-specifying spall functions 2025-05-22 09:34:47 -07:00
Ryan Fleury d254d8edb4 switch singular frame scopes to stack of frame scopes; always ensure scopes are closed before breaks in frames. 2025-05-22 09:28:13 -07:00
Ryan Fleury 895a965f70 defer call stack scope touches until retry loop exit 2025-05-21 17:33:30 -07:00
Ryan Fleury b0fb102813 sketch out spall integration 2025-05-21 12:01:43 -07:00
ed 46ef06e4db Merge remote-tracking branch 'EpicGamesExt/dev' 2025-05-20 22:08:31 -04:00
Ryan Fleury 8bed56adde step-into-line trap nets: omit stopping at non-final call destinations with no line info 2025-05-20 16:15:03 -07:00
Ryan Fleury 25dda717ad setting to prefer os native file dialog uis (off by default because they are slow and bad) 2025-05-20 15:59:49 -07:00
Ryan Fleury 2d5bf9efc2 last-hit-breakpoint visualization 2025-05-20 15:41:16 -07:00
Ryan Fleury 16fd72ef4f more granular watch window fresh/bad visualization, since each cell can be an arbitrary evaluation now; also reintroduce failed-memory-read visualization 2025-05-20 15:31:37 -07:00
Ryan Fleury e6f53a39bb old windows dpi awareness paths 2025-05-20 15:13:23 -07:00
Ryan Fleury 0eb37c527c fix incorrect abort-on-0-rip condition in unwinder path; we can still have nonzero rsps and find valid frames. 2025-05-20 15:09:35 -07:00
Ryan Fleury f7df65678f fix incorrect bounds check in regrel32 frameproc grab 2025-05-20 15:05:05 -07:00
Ryan Fleury 206ec346cf fix 2-byte utf decoding issues, fix utf8 lexing issues 2025-05-20 14:46:46 -07:00
Ryan Fleury 2f5082fb61 fix treatment of octal strings in try_u64/s64_from_str8_c_rules 2025-05-20 14:10:34 -07:00
Ryan Fleury 95dbba1144 debugging notes of programmatic data breakpoints 2025-05-20 13:18:15 -07:00
Ryan Fleury a55c5b49aa similarly adjust call stack cache timeout periods 2025-05-20 13:06:16 -07:00
Ryan Fleury 15459edc75 adjust wait timeout properties of ctrl process memory cache grab; don't wait forever to submit, don't wait if work was completed even if results bad, etc. 2025-05-20 13:03:58 -07:00
Ryan Fleury d709724128 fix ctrl scope mal-usage 2025-05-20 11:15:55 -07:00
Ryan Fleury 7fc39a3d97 eliminate old debug engine unwind cache 2025-05-20 11:13:04 -07:00
Ryan Fleury 41ee0c83d4 notes; skip relativization path for stdout/stderr/stdin paths 2025-05-20 11:00:18 -07:00
Ryan Fleury 34df269c58 eliminate extra root id list placement in key nodes 2025-05-20 10:53:02 -07:00
Ryan Fleury 56b975a6b1 adjust async call stack querying API to guard against waiting in clearly-invalid cases (trying to wait for call stacks when running, for example); also eliminate logs 2025-05-20 10:36:44 -07:00
Ryan Fleury b94535b20b fix array-indexing in type evaluation mode 2025-05-19 22:22:47 -07:00
Ryan Fleury 7d274dd2f6 fix incorrect lens application condition in eval viz string iter 2025-05-19 22:09:52 -07:00
Ryan Fleury 7dc4399300 dead ctrl process memory cache elimination 2025-05-19 19:38:27 -07:00
Ryan Fleury 9ae0ee9a46 correctly use tab width px in new code slice fstrs measuring path 2025-05-19 19:21:06 -07:00
Ryan Fleury 54325828b2 absolutify target stdout/stderr/stdin paths based on working directory 2025-05-19 18:56:13 -07:00
Ryan Fleury 862e0ef882 fix lens expansions being treated like set expansions in eval viz string iter 2025-05-19 18:47:52 -07:00
Ryan Fleury 47d658daed ensure rd frame depth is always computed correctly; eliminate incorrect frame scope (ctrl/di) usage - fix weird deadlocks! 2025-05-19 16:21:38 -07:00
Ryan Fleury b9e3df4cae pass over hash store layer / all users, to switch to explicit 64-bit root alloc/dealloc, and 128-bit ids, for a full 192-bit hs key 2025-05-19 14:52:28 -07:00
Ryan Fleury 8b4e2a099f hash store root allocation/deallocation 2025-05-18 16:00:18 -07:00
Ryan Fleury cb2f8aa766 sketch out 'root cache' in hash store 2025-05-18 15:46:50 -07:00
Ryan Fleury 90955ac2a8 fix incorrect lock type in hs key closing path 2025-05-18 15:24:56 -07:00
Ryan Fleury 342627ae3b dead code deletion 2025-05-18 13:16:51 -07:00
Ryan Fleury 0a51de094d switch to stripe-cv-based waiting mechanism on nonzero scope touches 2025-05-18 12:58:44 -07:00
Ryan Fleury f99dd2a477 clean up search data commit on scope-hold mechanism 2025-05-17 13:33:43 -07:00
Ryan Fleury 5cb2a7bbde fix usage of [] operator on pointer values; fix incorrect interpretation of []s as assembly style derefs in chained cases 2025-05-17 13:05:07 -07:00
Ryan Fleury 5712c2ac07 fix ternary expr tree stringification 2025-05-17 12:56:49 -07:00
Ryan Fleury ea5dcafd1e hash store key closing path 2025-05-17 12:41:47 -07:00
Ryan Fleury 66fdfc84fc further pass over call stack cache lookup path 2025-05-17 10:16:49 -07:00
Ryan Fleury 7a44cbbd0d adjust high priority call stack timeout threshold 2025-05-17 08:41:51 -07:00
Ryan Fleury a379134ed8 demon tweaks / debugging; adjust call stack cache reading API to account for high-priority path, where we want to try computing the thread's call stack immediately 2025-05-16 21:12:58 -07:00
Ryan Fleury 86eabe0d6d offer priority selection in call stack retrieval; prioritize selected thread & operations which require a result; adjust call stack builder path to be a bit more generous while waiting for memory reads 2025-05-15 21:57:50 -07:00
Ryan Fleury 965f5f4896 0.9.18 notes 2025-05-15 14:37:37 -07:00
Ryan Fleury ed9866e9e2 retry call stack commits a bit more aggressively 2025-05-15 14:17:17 -07:00
Ryan Fleury 6ff66b0fef adjust static breakpoint disqualification to not assume invalid eval -> statically disqualfiied 2025-05-15 14:05:14 -07:00
Ryan Fleury 95032147e8 lock ctrl thread entity ctx for much less long when doing unwinds; only copy the minimal entity tree needed into a mini entity ctx, then use that to do the unwind 2025-05-15 13:47:55 -07:00
Ryan Fleury 9a805b8bb5 adjust call stack cachc committing mechanism, to guarantee commits in face of scope touches, and to ensure waiting for new commits in face of cache lookup 2025-05-15 13:27:11 -07:00
Ryan Fleury e5d6a49055 first pass at call stack cache, need a lot of clean up before this is working... 2025-05-14 21:44:09 -07:00
Ryan Fleury a84739e1c4 set up async cached call stack building 2025-05-14 20:15:10 -07:00
Ryan Fleury 981dd2e02c tighten up usage of ctrl entity ctx vs. r/w ctx store vs. accel 2025-05-14 19:16:06 -07:00
Ryan Fleury 1b26c3f180 entity_ctx * entity_store -> entity_ctx, entity_ctx_rw_store, thread-local entity_ctx_lookup_accel 2025-05-14 19:11:02 -07:00
Ryan Fleury 1e6b3ee2e6 split read-only ctrl entity operations from read-write ctrl entity operations, represent in type system via EntityCtx vs. EntityStore 2025-05-14 18:35:25 -07:00
Ryan Fleury e513af5361 ditto 2025-05-14 15:30:49 -07:00
Ryan Fleury 60e47fb821 unwind cache -> callstack cache 2025-05-14 15:28:57 -07:00
Ryan Fleury 81483f5100 eliminate per-callstack-frame 'parent num' - redundant info 2025-05-14 14:41:13 -07:00
Ryan Fleury 1e53ac29ef still protect against infinite unwinds, but require that both rsp/rip remain unchanged, rather than just rip 2025-05-14 13:55:16 -07:00
Ryan Fleury 99a8108b2a eliminate now-unnecessary debug info references in call stack data structure 2025-05-14 13:53:24 -07:00
Ryan Fleury a7b6e6f02a eliminate usage of old overcomplicated call stack data structure, which required actively holding debug info references... we want to eliminate this so that we can trivially cache call stacks / unwinds 2025-05-14 13:51:59 -07:00
Ryan Fleury b49f4559ce get main unwinding path off of requiring entire ctrl entity store 2025-05-14 13:32:32 -07:00
Ryan Fleury f12b66c1ee sketch out asynchronous unwinding stuff 2025-05-14 13:27:10 -07:00
Ryan Fleury e60e0c8555 sketch out unwind cache 2025-05-14 11:43:54 -07:00
Ryan Fleury a67f326f78 eliminate redundant recomputation of ir extensions 2025-05-14 10:27:01 -07:00
Ryan Fleury 10c4dcecd1 do not prohibit same-rips from stopping unwinds 2025-05-14 10:15:42 -07:00
Ryan Fleury 2e2eb4a6f2 bump to 18 2025-05-14 09:53:50 -07:00
Ryan Fleury 70ae35cbd7 do not use worker thread arenas from main thread in rdi baker... 2025-05-14 09:51:46 -07:00
Ryan Fleury 141b96c17e do not skip 0 with texture formats 2025-05-14 08:21:54 -07:00
Ryan Fleury a371374d6c require file existence before calling into dwrite 2025-05-14 08:19:30 -07:00
Ryan Fleury ad714e9baa dwrite: do not try to create font face if font file creation fails 2025-05-14 08:11:13 -07:00
Ryan Fleury 271e8e4523 deduplicate new file path maps on-add 2025-05-13 16:29:23 -07:00
Ryan Fleury 5532aa6903 rdi_from_pdb: when relative paths are supplied by line info, build them as being relative to OBJ; this is not necessarily correct but it is the best thing we can do given the available information. the user needs to remap this once in the debugger, but then it will work. 2025-05-13 16:23:31 -07:00
Ryan Fleury 258b45a837 eliminate a bit of duplicate font cache lookups in code view build, + eliminate unnecessary per-box color lookups 2025-05-13 15:11:41 -07:00
Ryan Fleury e10f0489da record which irtree-and-type generations were produced via auto-hooks; skip those when doing typeofs 2025-05-13 14:19:30 -07:00
Ryan Fleury 89e93459d7 fix ufcs-style 'raw' lens application 2025-05-13 13:51:56 -07:00
Ryan Fleury 8b8c88f310 preserve whole chain of parent irtrees, do not simply apply only to autohook overrides; straighten out some event consumption weirdness in interaction between autocompletion floating view & query floating view; ensure we mark the cfg space as dirty when modifying strings 2025-05-13 13:44:14 -07:00
Ryan Fleury 97c58e3747 start sketching out pieces for flattened expansions in rows(...) 2025-05-13 11:55:06 -07:00
Ryan Fleury 34304280c9 fix old usage of table in mule_main; resolve to value in (sequence) 2025-05-13 10:55:39 -07:00
Ryan Fleury 11c1b5277e only -> rows; table -> columns 2025-05-13 10:44:06 -07:00
Ryan Fleury 73c91ae2bc eval: adjust array expansion, use parent key of pointer argument, rather than key of pointer argument, to scope count expression evaluation; fix up a few edge cases with $. and implicit $ member accesses; make omit much more powerful, by allowing list of arguments to control all expansion expressions, rather than assuming only member names 2025-05-13 10:19:47 -07:00
Ryan Fleury 86dcec4334 Merge branch 'dev' of https://github.com/EpicGames/raddebugger 2025-05-12 21:39:46 -07:00
Ryan Fleury bc75635a65 os/gfx/linux: window focus querying 2025-05-12 21:22:03 -07:00
Ryan Fleury 4c1585444c be less ambitious about occupying basic type names in debugger; can conflict with common purposes in codebases, and really we should defer to debug info when possible 2025-05-12 17:33:57 -07:00
Ryan Fleury 533136875e eliminate dummy window egl setup 2025-05-12 17:20:46 -07:00
Ryan Fleury d564184d31 chip away more unneeded path processing, impeding proper support for relative paths; we want to mostly preserve paths as we see them, and then we should find a different story for mapping the paths in very few places 2025-05-12 17:09:13 -07:00
Ryan Fleury a5b227a1c6 egl/glx work; eliminate unneeded path normalization paths; do not assume os current path when normalizing paths; gl synchronous debug strings 2025-05-12 16:03:36 -07:00
Ryan Fleury fe3cac7ac3 parameterize irtree generation path with identifier resolution rules; in most cases, we want the usual order: implicit accesses -> locals -> registers -> globals/tlocals/types/procedures -> macros; but if we are specifically evaluating a call expression tree, we want to prefer callables - in this case, macros should be prioritized. 2025-05-12 11:56:57 -07:00
Ryan Fleury 8688322a43 more of the same 2025-05-11 21:47:24 -07:00
Ryan Fleury 2307d44506 forward declare XLookupString ourselves, since it is apparently missing in libx11-dev 2025-05-11 21:26:39 -07:00
Ryan Fleury cc319190c6 render/opengl: flushed instance buffers 2025-05-11 15:26:05 -07:00
Ryan Fleury 1896ec2a85 more os/gfx linux coverage 2025-05-11 15:19:40 -07:00
Ryan Fleury 684402efac x11 event coverage 2025-05-11 14:14:12 -07:00
Ryan Fleury 9de203e2cd adjust smooth-unhinted dwrite raster params 2025-05-11 13:48:05 -07:00
Ryan Fleury 8b3f07c7b5 eliminate font fudge factors; fix size units in freetype backend; fix directory iteration lack-of-robustness-to-failed-dir-open 2025-05-11 13:27:59 -07:00
Ryan Fleury 6df96b7eef preserve mouse coordinates from xlib button events 2025-05-10 17:08:40 -07:00
Ryan Fleury 0a3869981f correctly calculate shortened hash w/ dirty marker in build.sh 2025-05-10 16:01:56 -07:00
Ryan Fleury 219e5bd211 first pass at standing up freetype font provider backend 2025-05-10 15:59:44 -07:00
Ryan Fleury 868f2d0660 be a bit more robust to failures in window creation, IPC thread launching, & semaphore non-implemented parts 2025-05-10 14:39:32 -07:00
Ryan Fleury 3fd1f9d255 stub out demon/fontprovider so we can build debugger 2025-05-10 14:28:14 -07:00
Ryan Fleury b52e3be5ae fill out more linux os layer coverage 2025-05-10 11:38:43 -07:00
Ryan Fleury b9350c867c egl backend for linux backend of opengl backend of render 2025-05-10 11:04:59 -07:00
Ryan Fleury ab5c47a0fd fix opengl win32 build 2025-05-10 08:36:13 -07:00
Ryan Fleury a1318e6117 sketch out first bit of linux-backend of opengl-backend 2025-05-09 21:51:48 -07:00
Ryan Fleury 5939c3f010 switch 4coder back to defaultly building with d3d11 backend 2025-05-09 19:51:24 -07:00
Ryan Fleury 48b8c41713 opengl render backend 2025-05-09 19:48:41 -07:00
Ryan Fleury 1b7a57914e get linux building again 2025-05-09 13:44:17 -07:00
Ryan Fleury f38da420e9 force hover eval in window on X axis only; store expr strings rather than expr trees in auto hook map 2025-05-09 12:51:02 -07:00
Ryan Fleury 345d5579d2 do not show switch in IPC docs 2025-05-09 12:27:35 -07:00
Ryan Fleury 2c58b81dde parameterize find-code-location by forcing-focus to destination panel; use that in 'switch' command 2025-05-09 12:22:27 -07:00
Ryan Fleury 719e8ce179 crash dump generation from crash dialog, or via --gen_crash_dump for CLI 2025-05-09 12:08:08 -07:00
Jan Hebbel 7939bcbc95 Fixed signed minimum values. 2025-05-09 11:35:42 -07:00
Ryan Fleury a3e471897c scroll-to-bottom-on-change setting for text (inc. output) visualizers 2025-05-09 11:31:54 -07:00
Ryan Fleury f2bf8ccb2e layer color coverage / usage in thread colors 2025-05-09 11:15:00 -07:00
Ryan Fleury 1c4ad499dc prohibit DefWindowProc from running on syschars, for everything except alt+space 2025-05-09 10:51:03 -07:00
Ryan Fleury 5fce46baaf adjust toggle-switch-dragging path so that keyboard presses still register 2025-05-09 10:43:17 -07:00
Ryan Fleury 3b0064d8cd multi-toggle-switch-toggle-in-single-press 2025-05-09 10:34:00 -07:00
Ryan Fleury 417202c0a0 press in view content -> steal focus from query bar 2025-05-09 10:16:49 -07:00
Ryan Fleury e491a76861 prevent mutating nil trees in irtree generation 2025-05-09 09:58:39 -07:00
Ryan Fleury cb2e9fe27c record last opened user in program data, recall on startup 2025-05-09 09:56:16 -07:00
Ryan Fleury dd3f3366a8 fix bad 0.9.16 version check in config loading; helpers for building version codes, so they can be compared 2025-05-09 09:48:54 -07:00
Ryan Fleury bbdbcead16 correctly allow space keybindings; bind by default to 'accept', along with return; -> allow space for hitting buttons, expansions, etc. 2025-05-09 09:05:51 -07:00
Ryan Fleury f237f6cb24 hack in fix for not automatically escaping user inputs - was preventing backslashes from being used correctly in query inputs 2025-05-08 16:16:53 -07:00
Ryan Fleury 5bfef50915 bump to 0.9.17 2025-05-08 15:24:35 -07:00
Ryan Fleury 802da729b2 further work on view callee helper ui 2025-05-08 15:18:09 -07:00
Ryan Fleury 2a3c5527e0 only decorate debug-info-table-generated expressions with `s when we can detect it is necessary (.s are now allowed); only generate simplified expression extension strings for expressions in watch windows if parent keys are present, otherwise just do the full expression 2025-05-08 14:14:30 -07:00
Ryan Fleury b30e928501 fall back on creating a synthetic symbol name when a chain of leaf-identifier member accesses fail, and produce synthetic leaf-identifier expression to try to resolve it that way. 2025-05-08 14:00:54 -07:00
Ryan Fleury e13de08637 fix process choice in lister-completion-evaluation; do not rely on selected process! fixes 'enter' in listers not functioning when initially launching a process. 2025-05-08 13:34:38 -07:00
Ryan Fleury 4c49daa5a4 reintroduce add function breakpoint fast-path 2025-05-08 13:22:16 -07:00
Ryan Fleury 13324d9073 more progress on view caller helper 2025-05-08 12:25:31 -07:00
Ryan Fleury ef974b8dc0 begin sketching out the callee info helper, as an additional mechanism within the autocompletion system - find the call we're in, evaluate the callee, look up schema, show args/docs 2025-05-08 12:03:12 -07:00
Ryan Fleury a95780f2be provide path for explicit cast operator in eval parser; abort trying c-style casts in non-trivial cases (the parse becomes ambiguous, and it is better for us to prefer the usual non-casting path 2025-05-08 11:04:11 -07:00
Ryan Fleury e0202c5c18 path_pt schema type, which bundles a file path & textual location; use to do path relativization on serialize with breakpoints/watch pins 2025-05-08 10:23:46 -07:00
Ryan Fleury b59e8e5024 absolutify initial user/project paths; need absolute path information in order to relativize/absolutify paths in config 2025-05-08 09:57:17 -07:00
Ryan Fleury a31840fd8c eliminate reload-active command binding - it is no longer a command 2025-05-08 09:20:09 -07:00
Ryan Fleury ead193ee3b move enum value by-name lookup onto cached fastpath 2025-05-07 17:08:28 -07:00
Ryan Fleury 54a0560cef make window-level font size changing more strict wrt modifiers; do not accept ctrl+shift 2025-05-07 17:05:25 -07:00
Ryan Fleury 64e12d0591 fix binary tool builds after usage of path in rdi_from_pdb layer 2025-05-07 16:10:22 -07:00
Ryan Fleury 43c1a5d68b oops, fix bad reset of autocompletion arena! 2025-05-07 16:00:06 -07:00
Ryan Fleury 80f1a8b7ba enum value filtering / lookup cache 2025-05-07 15:46:59 -07:00
Ryan Fleury e7a4f407bb use 'sufficient suffixes' when generating enum expansions 2025-05-07 15:24:23 -07:00
Ryan Fleury 1929bcac0a defer to simple numeric evaluation if we cannot visualize an enum value by name 2025-05-07 15:20:49 -07:00
Ryan Fleury 7ded00af72 pdb -> rdi: correctly convert negative enumerate numerics; move enum value visualization into complex string-iterator visualization path, rather than hacking it into the simply-typed eval path (we want to generate a new task for the numeric value itself); handle negative enums correctly 2025-05-07 15:20:12 -07:00
Ryan Fleury a4367e02f2 pdb -> rdi: more gracefully handle ..s in file paths when building source line maps, normalized file paths, and path tree 2025-05-07 14:58:23 -07:00
Ryan Fleury 4f980c4820 correctly flag deletion editing commands as zeroing delta on selection 2025-05-07 14:36:39 -07:00
Ryan Fleury 9c296cb9b2 fixes for arithmetic with bitfields; bitfield -> numeric value path in irtree generation; fix bad stomping / mutation when generating a synthetic UFCS tree 2025-05-07 14:19:39 -07:00
Ryan Fleury 1cc5561f1f evaluate settings in raw mode, always 2025-05-07 10:50:27 -07:00
Ryan Fleury db2c8607fb clear breakpoints command 2025-05-07 09:23:42 -07:00
Ryan Fleury cbc0ec1254 commit root-level split axis data on panel tree edits 2025-05-07 09:13:59 -07:00
Ryan Fleury 1284c25b9e sketch out better usage of expansion info in text visualizer; notes; naming pass 2025-05-07 08:58:12 -07:00
Ryan Fleury 4d6d4429e1 fix incorrect rad <-> turn conversion path 2025-05-07 06:31:19 -07:00
Ryan Fleury 73d30759a1 fix incorrect command usage in auto-run path 2025-05-07 06:27:34 -07:00
Ryan Fleury 2919ecb135 more robustness to malformed expressions 2025-05-07 06:25:47 -07:00
Ryan Fleury 84e299e081 readme adjustments 2025-05-07 05:56:41 -07:00
Ryan Fleury afd1f0c713 do not reset to default bindings if not needed... 2025-05-07 05:50:47 -07:00
Ryan Fleury 7048a8748c bindings resetting function 2025-05-06 17:34:49 -07:00
Ryan Fleury df8c29d7b1 clamp font size settings 2025-05-06 17:22:59 -07:00
Ryan Fleury 1447e6ca24 revert-to-default ui for meta setting editors 2025-05-06 17:09:01 -07:00
Ryan Fleury 6b4c1997e1 eliminate defaults for overridden properties, e.g. per-tab font size; just pull value from hierarchy 2025-05-06 16:25:04 -07:00
Ryan Fleury de5ae9746d when generating debug info table evaluations, check for non-simple symbol identifiers, and generate slightly-better-though-not-comprehensive-escape-hatch for that symbol expression 2025-05-06 15:48:57 -07:00
Ryan Fleury 8d8e9b3cc5 be more judicious about edit buttons in fancy rows; allow escape-hatch identifier evaluation via grave accents 2025-05-06 15:42:36 -07:00
Ryan Fleury 53fea4a17e hack to fix corner case in watch window controls 2025-05-06 15:29:38 -07:00
Ryan Fleury b902b0a5b3 animation setting coverage 2025-05-06 15:21:01 -07:00
Ryan Fleury 848f144ab9 distinguish between expr strings and code strings in schemas; use normal autocompletion in meta-evaluation spaces only when editing expr strings, whereas code strings you want to look like code but do not generally refer to things that expressions can, e.g. it is a label 2025-05-06 14:42:27 -07:00
Ryan Fleury 686c666058 final theme presets pass 2025-05-06 14:03:22 -07:00
Ryan Fleury e1bdae4144 adjust focuses on project-load, if project-filtered tabs are focused 2025-05-06 13:20:52 -07:00
Ryan Fleury fe8d7e86fe fix expression editability condition in watch tables; notes 2025-05-06 13:09:47 -07:00
Ryan Fleury a6eda7db04 fix incorrect parsing / expr-building order of casts vs. other prefix unaries in new parser path 2025-05-06 13:02:48 -07:00
Ryan Fleury 08402a57b4 notes 2025-05-06 09:41:54 -07:00
Ryan Fleury 2b1e286aad preserve dbgi fuzzy searching results based on key alone, rather than throwing away all results if params change (although still re-querying if params change); also fix not clearing the autocompletion string gathered for a UI build across frames 2025-05-06 09:31:16 -07:00
Ryan Fleury e5a2f6da11 do not apply filters past one block layer (fixes broken expansions in debug info table tabs) 2025-05-06 09:24:34 -07:00
Ryan Fleury b8eace001a working on visualizer tab pull-outs in all cases, cleaning up some rough edges of watch window controls 2025-05-06 08:56:11 -07:00
Ryan Fleury f218ac6628 release notes 2025-05-05 23:06:23 -07:00
Ryan Fleury ac0a242f73 sketch out simple old-config-loader to just preserve targets/file_path_maps/etc. from 0.9.15 and before 2025-05-05 22:04:40 -07:00
Ryan Fleury 0594d99c8d clean up status bar rendering, collapse ui for rebinding/run-status/errors/conversions 2025-05-05 20:45:17 -07:00
Ryan Fleury 0e1599c554 constrain queries to window 2025-05-05 20:14:31 -07:00
Ryan Fleury 241d2454be stop funnelling autocompletion through via events - it is not an event-like thing, and making it one led to weirdness... 2025-05-05 20:01:44 -07:00
Ryan Fleury 64010486fe theme preset coverage 2025-05-05 17:19:29 -07:00
Ryan Fleury e52ab7ad6b garbage collect window states based on frame touch, and on cfg elimination 2025-05-05 16:30:31 -07:00
Ryan Fleury afae94b49c opaque backgrounds setting coverage 2025-05-05 16:00:57 -07:00
Ryan Fleury b2e24fe760 do not synthesize simpler expression strings on unsuccessful evaluation 2025-05-05 15:56:28 -07:00
Ryan Fleury 5f3c2d6932 new/save user/project commands 2025-05-05 15:51:42 -07:00
Ryan Fleury d17502fac4 fix missing byte sizes on alises 2025-05-05 15:29:07 -07:00
Ryan Fleury 27072e1148 save to project 2025-05-05 15:23:16 -07:00
Ryan Fleury 9c969d7c2b readme pass 2025-05-05 15:23:16 -07:00
Nikita Smith 08515428fb convert typedefs from PDB 2025-05-05 15:11:48 -07:00
Nikita Smith d3f8c1864d simplify aliases table and build basic types for unknown records 2025-05-05 15:03:53 -07:00
Nikita Smith cbe2783e0d always create RDI builtins 2025-05-05 15:03:53 -07:00
Ryan Fleury ced9c7a3f5 fix more secondary-flag coverage, fix error rows being generated as type rows, fix improper piping of autocompletion cursor info into autocompletion lister build 2025-05-05 11:26:14 -07:00
Ryan Fleury 4ad3748d1e commit panel/tab/view to rd_regs earlier in window_frame, this allows correct calculation of per-window settings in theme calc etc. 2025-05-05 10:53:25 -07:00
Ryan Fleury cf33470cb1 fix incorrect usage of type byte size for eval memory range sizes 2025-05-05 10:49:52 -07:00
Ryan Fleury 573a6b0bb2 further work on autocompletion system; more carefully preserve information about cursor / what is being replaced, do not apply autocompletion lister enabling setting to required listers (e.g. for settings/themes), and adjust navigation controls such that arrowkeys are consumed by the autocompletion lister (in principle this is 'stealing' functionality from the source ui, e.g. the watch window using up/down to go to different rows, but in practice when an autocompletion lister pops up, it feels way more natural to use arrowkeys) 2025-05-05 10:45:40 -07:00
Nikita Smith e1ca449ccb revert type indices change 2025-05-05 10:19:13 -07:00
Nikita Smith e2266322d0 Revert "pass over PDB converter"
This reverts commit f1e88b5667.
2025-05-05 10:19:13 -07:00
Ryan Fleury c840071bf8 clean up visualizer default sizes, clean up rough edges of various combos of theme setting / config state 2025-05-05 09:54:29 -07:00
Nikita Smith f7a3239294 utility for stripping debug info out of libs 2025-05-05 09:22:59 -07:00
Ryan Fleury d13bf27ab7 shift theme pattern cache from a per-frame cache to a permanent cache; use to animate (ui_key -> color) 2025-05-05 06:00:45 -07:00
Ryan Fleury da8e583f93 hook up fancy-cell edit button to double-click action, ensure double-click starts edits in listers for editable cells 2025-05-05 05:32:26 -07:00
Ryan Fleury 19acf2cdee checkpoint on final pre-release pass over 'fancy rows' (combined line edit, toggler, slider, etc. widget), plug autocompletion in for theme selection lister 2025-05-04 16:57:50 -07:00
Ryan Fleury 9b3a2c2428 pull out decision of autocompletion list expression, so that we can begin basing it on destination evaluations; adjust top-level theme editing controls to be less annoying 2025-05-04 15:28:47 -07:00
Ryan Fleury 24148dd672 set up settings for enabling/disabling pre-packaged stl/ue type view rules; fill out basic stl ones 2025-05-03 21:01:26 -07:00
Ryan Fleury 6c7568f946 fix out-of-date file rendering 2025-05-03 16:56:54 -07:00
Ryan Fleury 8fddc7b712 markup: omit static in global raddbg-section data, since clang will strip it 2025-05-03 16:53:57 -07:00
Ryan Fleury 8b7e7471f5 markup: thread id based APIs for names/colors; handle names/colors-before-thread, or id-based application, in ctrl layer 2025-05-03 16:45:45 -07:00
Ryan Fleury 5086d1b3db notes 2025-05-03 16:18:58 -07:00
Ryan Fleury 473f84cbda flip priority of (handle, id) thread name events; prefer id if it is there, to correctly work with the set-suspended-thread-name-by-ID case 2025-05-03 16:17:10 -07:00
Ryan Fleury ad8ae313f4 windows: clear unneeded working set pages shortly after startup/initialization 2025-05-03 09:43:02 -07:00
Ryan Fleury edafc4d5c2 batteries-included std::string_view 2025-05-03 09:19:48 -07:00
Ryan Fleury dfd0fe3fcb raddbg_markup: stl batteries-included basics 2025-05-03 06:18:26 -07:00
Ryan Fleury fe7bd82bda handmade hero theme 2025-05-03 05:52:56 -07:00
Ryan Fleury d3a60e1808 solarized dark theme 2025-05-03 05:30:16 -07:00
Ryan Fleury 2835706d3d 4coder theme 2025-05-02 20:44:50 -07:00
Ryan Fleury 293738e084 parameterize open-theme path correctly by parent bucket, rather than assuming user 2025-05-02 16:25:01 -07:00
Ryan Fleury a140197fcd crazier union test 2025-05-02 16:20:17 -07:00
Ryan Fleury f7ae0a1b47 collapse theme-file vs. theme-preset, plug all theme selection paths into picking that single string, plug theme lister in 2025-05-02 16:13:39 -07:00
Ryan Fleury 6c2cf98ea6 themes collection evaluation, begin moving theme preset/file setting to just being based on the themes folder, rather than completely path-based 2025-05-02 15:52:21 -07:00
Ryan Fleury 644ba8d02e theme presets work 2025-05-02 15:28:56 -07:00
Ryan Fleury d98335ef76 per-window theme-usage setting - by default, prioritize project theme settings, but allow using only user themes per-window as well. 2025-05-02 13:24:01 -07:00
Ryan Fleury dddc79e852 adjust tags in accordance with theme design pass 2025-05-02 13:17:17 -07:00
Ryan Fleury adf2eabba7 eliminate remaining usage code of old theme system; to not pay the cost of slower-path color lookups for every single syntax highlighted thing in the UI, just introduce 'code color slots', which are computed once per window per frame 2025-05-02 11:34:24 -07:00
Ryan Fleury 2b12239300 preserve query regs in floating views, so that we can chain info from many query commands together; more progress on theme editing, simplify command surface 2025-05-02 11:10:14 -07:00
Ryan Fleury 137855c217 improve row-building for type evaluations (eliminate redunant cells, show offsets/sizes) 2025-05-02 10:46:04 -07:00
Ryan Fleury bbeeb3dde5 ditto 2025-05-02 10:35:37 -07:00
Ryan Fleury 58b1aa41f6 drag/drop work & cleanup; memory view work; pull initial project path (if not specified on command line) from user recent projects before forming a default path 2025-05-02 10:29:22 -07:00
Ryan Fleury a96546c5f5 view rules / auto view rules -> views / type views 2025-05-02 09:50:41 -07:00
Ryan Fleury 2dbe8d42eb eliminate more old view settings code, simplify new, also clean up the targetless launch flow even more - if we only have one target, but it's inactive, and the user is trying to launch, then it doesn't hurt to just act as if that target was selected, then select it for them... 2025-05-01 17:04:29 -07:00
Ryan Fleury afc3a1a818 begin memory view pass 2025-05-01 16:43:20 -07:00
Ryan Fleury 23601f38a2 more run-in-invalid-state case tweaks 2025-05-01 14:17:57 -07:00
Ryan Fleury b20f003e7f tooltip coverage for all command evaluations, major top-bar simplification, anchored tooltips 2025-05-01 14:09:05 -07:00
Ryan Fleury e3f68622f7 window titles 2025-05-01 13:06:16 -07:00
Ryan Fleury 3be17c7157 merge local todo notes, pre/post 0.9.16 notes pass 2025-05-01 12:52:33 -07:00
Ryan Fleury f7757cd163 update memory range parameter extraction in visualizers, to be based on cfg tree 2025-05-01 11:56:27 -07:00
Ryan Fleury 630394750e add all visualizers to fixed tab list, derive language from view tree correctly rather than just the evaluation 2025-05-01 11:39:08 -07:00
Ryan Fleury 36e77e9691 clean up flow of active-targetless launch path; instead of just erroring, prompt user with selection, select if none selected, etc. 2025-05-01 11:04:14 -07:00
Ryan Fleury 306ad2d382 allow multiple leaf-identifier completions per input, using the cursor_off -> cursor_expr_node autocompletion querying path 2025-05-01 10:38:36 -07:00
Ryan Fleury 80268dd770 correctly evaluate array lens size arguments in the context of the parent expression 2025-05-01 10:16:41 -07:00
Ryan Fleury aa9a00f754 sketch out first pass of autocompletion list-expr/replace-range/filter based on cursor-offset -> expression-node path 2025-05-01 09:47:20 -07:00
Ryan Fleury 3a46e66efa expand eval expression tree location info to being based on textual range, rather than just offset 2025-05-01 09:05:42 -07:00
Ryan Fleury 2a1e19ad23 fix view-embedded query pushing - needs to apply to view, not simply tabs; fix schema-expansion command filtering 2025-05-01 08:34:43 -07:00
Ryan Fleury ed4fe5e3d1 fix auto-downcasting to work in all cases 2025-05-01 08:27:03 -07:00
Ryan Fleury 791187b152 blank cell rendering fixes, autocompletion work, fix to value-string visualization, more fixes/tweaks 2025-05-01 08:18:14 -07:00
Ryan Fleury 91be06dea9 fix single-line string value stringification; expand commands for tabs 2025-05-01 07:50:46 -07:00
Ryan Fleury f73ef86a54 fix row command query spawning rules 2025-05-01 07:36:34 -07:00
Ryan Fleury b0dd7700d7 apply autocasting below the ir-tree generation level of lens calls, so that we don't accidentally strip away lenses 2025-04-30 17:04:10 -07:00
Ryan Fleury 58a3a364cf sketch out autocompletion lister usage in query bars 2025-04-30 16:55:56 -07:00
Ryan Fleury c199ea6158 fix empty case in autocompletion lister building 2025-04-30 16:48:23 -07:00
Ryan Fleury fd6637b87b more dead code elimination 2025-04-30 16:41:01 -07:00
Ryan Fleury 78928974cb implicit member access path 2025-04-30 16:38:25 -07:00
Ryan Fleury c473cdf3b8 eliminate old autocompletion code 2025-04-30 16:24:38 -07:00
Ryan Fleury 1d4aa92779 fix autocomplete hint rendering on non-active line edits 2025-04-30 15:38:46 -07:00
Ryan Fleury 6ea0a237ce feed autocompletion rows forward from autocompletion lister 2025-04-30 15:33:15 -07:00
Ryan Fleury 9c53215daf fix expression updating with query views 2025-04-30 15:17:46 -07:00
Ryan Fleury 24f4ef2d2d begin sketching out new autocompletion lister path 2025-04-30 15:06:43 -07:00
Ryan Fleury 9ed65c2997 fix sizeof/typeof/bswap expr stringization 2025-04-30 13:42:43 -07:00
Ryan Fleury b1d63cd130 unattached process evaluation / lister 2025-04-30 13:34:05 -07:00
Ryan Fleury 9f468c44d9 ditto 2025-04-30 11:57:35 -07:00
Ryan Fleury e16f64f4e2 tighten up expr drag/drop 2025-04-30 11:54:10 -07:00
Ryan Fleury ee9017d5db cfg schema-based path relativization on save, derelativization on load; omit for file path maps 2025-04-30 10:50:36 -07:00
Ryan Fleury 005ff83d67 eliminate now-0redundant raw usage in watch row build 2025-04-30 10:19:44 -07:00
Ryan Fleury 10ff98faa8 fix type pattern matching for auto hooks, improve slice array indexing operations to rely less on the full irtree path (it composes poorly when using combining type views 2025-04-30 10:15:32 -07:00
Ryan Fleury 60b2195500 file path map, replacement file picking 2025-04-30 08:46:03 -07:00
Ryan Fleury 6f939bf9fc first pass at expr drag/drop in watch windows 2025-04-29 17:06:22 -07:00
Ryan Fleury fc308c0609 command correctness/cleanup pass 2025-04-29 16:00:06 -07:00
Ryan Fleury 7b5f55c3c8 convert mule_main to crlf, apparently..? 2025-04-29 15:34:39 -07:00
Ryan Fleury f521e01d6e dynamic ternaries in ir tree evaluation, fixes to over-ambitious parsing of identifier qualifiers 2025-04-29 15:26:40 -07:00
Ryan Fleury 0a214fda3c dynamic type resolution in ir tree / type generation pass 2025-04-29 15:06:06 -07:00
Ryan Fleury 4cccc9cb42 proper cast parsing, elimninate chained casts entirely 2025-04-29 14:53:35 -07:00
Ryan Fleury d41b414f2a eliminate very-poorly-thought-through idea of 'chained casts' - we need to recognize cast operators in the parser somehow, otherwise we are using the expr chain for way too many things in many cases... 2025-04-29 14:29:42 -07:00
Ryan Fleury 195883cbcb stub single line expansion flag 2025-04-29 13:50:20 -07:00
Ryan Fleury 3e6efb8935 fix lister row flags 2025-04-29 13:21:52 -07:00
Ryan Fleury 09372bd7c1 color visualizer / theme editing work 2025-04-29 12:15:41 -07:00
Ryan Fleury ddbb2148a4 distinguish tabs vs. views in rd_regs 2025-04-29 09:55:02 -07:00
Ryan Fleury c9be93485f build full evaluation expr string when building a view from an eval 2025-04-29 09:27:49 -07:00
Ryan Fleury f4e2728e9c full evaluation expression string computation, use for expression drag/drop - resolve parent expression chain in order 2025-04-29 09:16:26 -07:00
Ryan Fleury bc67abe4ca fix block type extraction in row build; the block tree build resolves evals to whatever types it is using for expansion, but sometimes we need to see types which have been stripped for row building (e.g. tables) 2025-04-29 09:01:09 -07:00
Ryan Fleury 71bdeb8f92 release notes work 2025-04-28 21:20:08 -07:00
Ryan Fleury 0c535b3e60 pre-emptively accumulate label edits in evaluation macro map, to prevent mid-frame ui tearing on edited cfg state 2025-04-28 17:51:45 -07:00
Ryan Fleury e7acf145cf clear cfgs on release 2025-04-28 17:29:13 -07:00
Ryan Fleury eb3b2572f1 more fixes to name -> color matching; more meta-type-tag usage fixes in reordering path 2025-04-28 17:13:22 -07:00
Ryan Fleury 1f1c4f161b cfg query eval filtering 2025-04-28 16:53:53 -07:00
Ryan Fleury a2ba3933cf fix ui tags-key/name -> color mapping; if a pattern is too specific, it should never match more general queries. but more specific queries can match less general patterns 2025-04-28 16:43:39 -07:00
Ryan Fleury 33479ec732 fix thread-in-code-view right-clicks, after moving to more stable ctrl entity evaluation 2025-04-28 16:20:41 -07:00
Ryan Fleury 57c331537b release notes 2025-04-28 16:19:05 -07:00
Ryan Fleury dc15a4fdc5 fix busted chained dot-access-style views 2025-04-28 16:02:48 -07:00
Ryan Fleury f72c956c9f fix implicit parent/override member accesses 2025-04-28 15:41:32 -07:00
Ryan Fleury 9fdfc7fab9 eval: distinguish irtree 'parents' from 'overrides' - parents are any irtree which some other expression is extending, and overrides are a subset of those, being just the irtrees overridden by auto-hooks. doing this because when we unwind the parent chain, sometimes we do not want to do that for basic expression extensions - we just want to undo the overrides. 2025-04-28 15:37:30 -07:00
Ryan Fleury 5a5e24a4a9 ditto 2025-04-28 14:06:02 -07:00
Ryan Fleury fff259e113 cache font setting calculations per-frame rather than recomputing all the time, fix some expandability calculations in eval visualization w/ multiple composing views 2025-04-28 14:04:02 -07:00
Ryan Fleury 0cdcb06db8 fix some edge cases in new casting compilation, fix some old usage of cast expr trees 2025-04-28 12:11:38 -07:00
Ryan Fleury c62ad20a9a switch cast expressions from being formally represented in the expression tree - instead use cast-like tree shapes to perform casts in the ir/typechecking phase. this is odd, given C's casting syntax, but it is much more natural given that the parser is not any longer doing identifier resolution, and as such it fixes a bunch of nasty edge cases. 2025-04-28 11:50:23 -07:00
Ryan Fleury 81425e8b90 use more stable IDs for ctrl entity evaluations 2025-04-28 10:25:37 -07:00
Ryan Fleury 93b1e3988d notes 2025-04-27 20:32:36 -07:00
Ryan Fleury 66187931aa accept font names, as well as font paths 2025-04-26 21:41:27 -07:00
Ryan Fleury 693ba7d077 fix 'cut' event being missed in standalone cell 2025-04-26 20:49:03 -07:00
Ryan Fleury 1e82d31eba first rough pass on theme editing 2025-04-26 19:01:35 -07:00
Ryan Fleury 282f6022e1 begin color editing, fix some bugs with meta-type-info disrupting type chain scans 2025-04-26 17:30:34 -07:00
Ryan Fleury 6a7420b7aa exception code filter project settings / ui 2025-04-26 14:50:49 -07:00
Ryan Fleury 2092f5ca69 eval space generation, to gracefully mark cached evaluations as dirty when desired 2025-04-26 12:33:48 -07:00
Ryan Fleury ea18e58903 fix & simplify path/pt meta editing 2025-04-26 11:38:22 -07:00
Ryan Fleury 6a9d212e70 adjust escape-to-close-query view rules, to account for non-lister query views, but with a command 2025-04-26 11:17:47 -07:00
Ryan Fleury db4f390fd0 fix input-expression-evaluation fallback in query views, to not be listerified; automatically open breakpoint editor when adding an address breakpoint manually 2025-04-26 11:13:36 -07:00
Ryan Fleury 05b52cfaca add extra bit that views can use to disable query bar - use in the case of watch window (and thus lister) editing 2025-04-26 11:04:54 -07:00
Ryan Fleury 6749f30b6b release notes 2025-04-26 10:57:11 -07:00
Ryan Fleury 19784ba476 improve labeled view titles, convert old watch-expression-gathering paths to using the per-watch-tab watches structure 2025-04-26 10:48:49 -07:00
Ryan Fleury 5103252a1b eliminate watches as a top-level entity, nest watch expressions under tabs - allow many watch windows, each with their own set of expressions. 2025-04-26 10:27:21 -07:00
Ryan Fleury 09f248de59 cfg evaluation improvements, tab expression editing, window size serialization fix, other small fixes 2025-04-26 10:02:56 -07:00
Ryan Fleury 970f40e516 notes 2025-04-25 11:08:46 -07:00
Ryan Fleury 33362d91a0 add dedicated open tab command as a fast path for all tab commands, simplify/streamline new tab menu 2025-04-25 10:04:42 -07:00
Ryan Fleury 0ed951e537 simplify font cache run building api, since it is now cahced 2025-04-25 09:46:58 -07:00
Ryan Fleury 7dc920c14f font cache: add additional layer of caching for runs 2025-04-25 09:45:43 -07:00
Ryan Fleury e0ba1155e8 eliminate recursive version of final ui layout position pass 2025-04-25 08:29:44 -07:00
Ryan Fleury fe46e61acb eliminate recursion from ui size calculation pass, replace with iterative equivalents 2025-04-25 08:25:00 -07:00
Ryan Fleury 0fbcd72a3e fix query offsets 2025-04-24 20:09:18 -07:00
Ryan Fleury b59528edea tab/text-pt/text-range filtered commands, hook up to right-click menus 2025-04-24 16:55:52 -07:00
Ryan Fleury 0470b646cd more tab-opening-fastpath coverage, fix described-code-string meta-cfg evaluation value rendering, tab settings cmd coverage 2025-04-24 16:27:24 -07:00
Ryan Fleury 23c7fcf099 plug tab opening back in 2025-04-24 15:57:57 -07:00
Ryan Fleury f4b364b668 autogenerate fixed tab list, autogenerate command metadata for opening fixed tabs 2025-04-24 15:21:51 -07:00
Ryan Fleury d0cbaee344 prep watch windows for floating query stacks; fix member/array-index generated-expression visualization 2025-04-24 13:39:26 -07:00
Ryan Fleury a9685e6b9d pass through eval msgs appropriately in eval cache evaluations; fix rules for reverting to overridden IR trees on usage of 'raw'; more fixes/improvements 2025-04-24 13:04:32 -07:00
Ryan Fleury a6c9a1bd2a fix editable expression strings, fix command evaluation, etc. 2025-04-24 09:52:29 -07:00
Ryan Fleury a35e483629 switch type expansion hooks to being eval-based, not expr/irtree-based 2025-04-24 09:36:00 -07:00
Ryan Fleury 9bb592786a eliminate all old evaluation bundled helpers, eliminate old fragmented eval caches; move all to unified evaluation cache 2025-04-24 09:07:29 -07:00
Ryan Fleury c341fb6c00 work on next release notes 2025-04-23 21:26:32 -07:00
Ryan Fleury 2f7e48e5cf first pass at unified evaluation cache 2025-04-23 17:29:31 -07:00
Ryan Fleury 23125dd312 cache font raster flag settings, add additional acceleration to very common repeated cfg lookups - e.g. same window/view -> state structure N times, or same ID -> cfg N times 2025-04-23 16:21:10 -07:00
Ryan Fleury ba29350939 parse cache, ir-tree cache 2025-04-23 16:00:23 -07:00
Ryan Fleury c9a05bc76f adjust block tree building from being on expr -> being on eval 2025-04-23 14:45:15 -07:00
Ryan Fleury a27b90a3f9 eliminate separate expr -> type path (this is just done via ir tree generation now), eliminate helper for locating defines & pushing to macro maps 2025-04-23 12:04:50 -07:00
Ryan Fleury c766ffe0a3 kill old code 2025-04-23 11:55:58 -07:00
Ryan Fleury 264dbc8199 deduplication from evaluation ctxs - just have base ctx with deduplicated info, then separate type-state, ir-ctx, and interpretation-ctx 2025-04-23 11:49:44 -07:00
Ryan Fleury 0ce85082ec include font in user settings schema 2025-04-22 17:16:29 -07:00
Ryan Fleury a9dcc7a08e more tweaks 2025-04-22 17:05:28 -07:00
Ryan Fleury afed771adb adjust cmd binding editor buttons style 2025-04-22 16:43:17 -07:00
Ryan Fleury 4cbb03fbfe ctrl + scroll -> adjust global font size by default, ctrl + shift + scroll -> adjust text view font size 2025-04-22 16:40:45 -07:00
Ryan Fleury fc728ea4e9 description coverage, char visualization disabling 2025-04-22 16:13:29 -07:00
Ryan Fleury 5bfb5b578a do not do mixed eval/expr booleans in watch groups 2025-04-22 15:47:37 -07:00
Ryan Fleury 42ee4b9776 lister -> palette 2025-04-22 15:36:45 -07:00
Ryan Fleury 5aae5cc4bb more work on combined cell path, debugging, fixes 2025-04-22 15:29:58 -07:00
Ryan Fleury d9d102cb56 expand cell capabilities to have meta data (expr name/description/etc.), as well as value editor, as well as fancy value editing widgets, all in one cell 2025-04-22 13:53:52 -07:00
Ryan Fleury 78b5582e95 dead code elimination, do cleanup pass over cell text rendering story, prep for expr/eval in same cell 2025-04-22 11:24:41 -07:00
Ryan Fleury c7a9e174fa eliminate mutual exclusion of expression/evaluation cells; allow both paths to be turned on in a single cell 2025-04-22 10:17:16 -07:00
Ryan Fleury 3d1f764741 control to disable windows style menu bar alt behavior 2025-04-21 17:23:38 -07:00
Ryan Fleury c9227b71e2 corner radii editing 2025-04-21 17:17:52 -07:00
Ryan Fleury 83e59bb0c0 fix incorrect resolution to type-mode evaluation with dereference ops 2025-04-21 16:57:27 -07:00
Ryan Fleury 1c71b89387 eval irgen: allow ,length fastpath for array types as well 2025-04-21 16:55:46 -07:00
Ryan Fleury 4fe602521a fix pointer dereference path in type-mode evaluation; carve out exception for lens visualization with string-pointers - in that case, we just want to apply a string size limitation & go to the regular string path; begin getting off old color slots 2025-04-21 16:49:02 -07:00
Ryan Fleury 93b8aef49c fix target environment string list evaluation cell building; extend lister completion with further push-queries for catchall; extend f1 lister to include targets, types, globals, thread-locals 2025-04-21 15:45:39 -07:00
Ryan Fleury a5c68412fc further work/convergence on cell rendering / listers 2025-04-21 15:23:49 -07:00
Ryan Fleury 20ba4a6af9 dead code elimination, user/project setting evaluation, work on color view ui 2025-04-21 14:57:31 -07:00
Ryan Fleury 0ce9925ba6 pipe through parent expression string info through expr -> string generation path, so we can correctly generate standalone expression strings in the presence of $ (parent shortcuts) 2025-04-21 11:54:55 -07:00
Ryan Fleury 7946e938c0 raw -> walk chain of overridden irtrees, since we want to strip 100% of all overrides/hooks/etc. 2025-04-21 11:46:03 -07:00
Ryan Fleury 8dd334d754 fix row key uniqueness of chained expansions, fix initial edit strings for value editing 2025-04-21 11:37:10 -07:00
Ryan Fleury 21a7126a57 kill old row/cell building code, fix incorrect use of view ui rule hooks in all cells 2025-04-21 11:12:42 -07:00
Ryan Fleury c4a18f7bff list select thread command in ui again 2025-04-21 11:05:14 -07:00
Ryan Fleury 02dc501547 transient tab editing, more work on descriptions/schemas for settings/etc 2025-04-21 11:02:27 -07:00
Nikita Smith d98ea1cf6f parallel build targets 2025-04-21 10:19:56 -07:00
Ryan Fleury cbe1365244 cell description rendering 2025-04-20 20:21:54 -07:00
Ryan Fleury 9453f62cf4 cmd filter -> filter on display names, descriptions, and search tags 2025-04-20 19:35:37 -07:00
Ryan Fleury ffb81cd814 f1 lister completion; improve command listing 2025-04-20 19:30:22 -07:00
Ryan Fleury 19a56b88a0 correct cell expression edit string formation 2025-04-20 19:09:11 -07:00
Ryan Fleury c45bd364eb use meta-display-names in cell rendering, fix small command buttons 2025-04-19 21:23:48 -07:00
Ryan Fleury 657f5edb31 compute cell editability 2025-04-19 19:12:55 -07:00
Ryan Fleury 92f3ea922d fix row command evaluations in row building 2025-04-19 09:44:43 -07:00
Ryan Fleury dc151609ad fix files/cmds fancy string list build 2025-04-18 21:21:46 -07:00
Ryan Fleury e30df5122a first half of cell rendering pass 2025-04-18 17:15:57 -07:00
Ryan Fleury 225ac267f0 pass over row info building 2025-04-18 15:51:27 -07:00
Ryan Fleury f99d560b40 more tweaks of the previous 2025-04-18 15:02:24 -07:00
Ryan Fleury c5402faa25 work on floating view state machines / characteristics - lister, query views, what happens on escape, is there a filter by default or not, etc. 2025-04-18 14:49:59 -07:00
Ryan Fleury d053edab3f correctly register types for cfg/ctrl-entity queries 2025-04-18 13:58:38 -07:00
Ryan Fleury ff35db0e16 more eval type operators for metadata decorations; fix target environment string list evaluation / edits 2025-04-18 13:48:31 -07:00
Ryan Fleury ddf0703b02 fix scroll bar size in watch views with changed font size, fix type evaluations 2025-04-18 11:03:40 -07:00
Ryan Fleury 2fd5e743b9 eliminate old font size code 2025-04-17 16:35:01 -07:00
Ryan Fleury 2925161c3a sequence/table visualization test in mule 2025-04-17 16:29:38 -07:00
Ryan Fleury 79b6ee4959 fix permanent growth of transient cfg trees, ensure correct recycling as old cfg trees for module-defined auto view rules etc. 2025-04-17 16:26:13 -07:00
Ryan Fleury 559f1baae1 begin fitting settings into window evaluation 2025-04-17 16:05:31 -07:00
Ryan Fleury f3974b2af7 only/omit; disallow chained fastpaths (vs-style ,x ; ,b; ,count) in nested irtree generations 2025-04-17 15:36:43 -07:00
Ryan Fleury 751f3708e7 interval lens, to generate an expansion of N things, to use w/ tables 2025-04-17 13:46:06 -07:00
Ryan Fleury a2047619c4 window evaluation, provide path to get to per-window settings 2025-04-17 13:14:08 -07:00
Ryan Fleury 9bc8641db1 distinguish row commands vs. expansion commands in cfg evals 2025-04-17 12:52:47 -07:00
Ryan Fleury b20ff61e50 fix inc/dec font size commands for new font size cfg setup 2025-04-17 11:22:51 -07:00
Ryan Fleury f1549f6b53 correctly use all schemas (including inherited ones) when doing lookups/evaluations; shift enabled to using evaluation path rather than just checking the value string; fix visualization of inherited schema values (e.g. font sizes in tabs) 2025-04-17 10:53:11 -07:00
Ryan Fleury f29c017268 adjust text/disasm views to apply top-level font size to scroll bars / metadata, but use the per-view font size for main contents 2025-04-16 12:16:36 -07:00
Ryan Fleury 950199026b begin folding font size parameters into main cfg tree settings path; allow per-tab font sizes, eliminate all redundant font size lookups/applications 2025-04-16 12:10:56 -07:00
Ryan Fleury 51f46cb5b8 eliminate extra view rule channel in rd_regs/hover-eval/watch-pins/etc. 2025-04-16 11:13:30 -07:00
Ryan Fleury 2a45696294 matrix table visualization test 2025-04-16 11:02:04 -07:00
Ryan Fleury b9ef453a14 eval visualization - allow chained expressions to cause multiple child expansion blocks; begin work on unified lister watch window 2025-04-15 16:27:44 -07:00
Ryan Fleury 923f55fb2b correctly treat chains of lenses when looking up type hooks; allow type-evaluations when producing per-cell evaluations 2025-04-15 14:18:21 -07:00
Ryan Fleury 82ec25ad19 table lens 2025-04-15 13:31:11 -07:00
Ryan Fleury 85f715f2ba revert to single expression from parse, but keep chains as implicit extension to expressions; use chained expressions to look up shorthands for hex, dec, bin, array counts, etc. 2025-04-15 13:07:59 -07:00
Ryan Fleury 1679aa6f64 fix up / simplify decision path to wrap cfg evaluations with meta-expr type 2025-04-15 11:50:36 -07:00
Ryan Fleury e27f31cfa4 adjust meta-expr type visualization; unify 'type unwrapping' paths, instead of nest of various 'scanners', we just have one path which we parameterize via bits to skip what each path needs 2025-04-15 11:35:49 -07:00
Ryan Fleury db381db85d meta-expr type operators, for meta-evaluations, to annotate source expression strings of evaluations 2025-04-14 15:21:46 -07:00
Ryan Fleury 8e13f8162a adjust memory reads from cfg spaces to evaluating the cfg strings, rather than directly interpreting them as leaves 2025-04-14 14:52:46 -07:00
Ryan Fleury cbc44cd9e4 fix hover eval view cfg build; fix editability-from-type-key path to respect lenses 2025-04-14 14:31:38 -07:00
Ryan Fleury a34e39751f eliminate type-determined cfg tree eval writes - just always use textual data, and only use type info if committing to an actual ctrl entity space 2025-04-14 14:12:23 -07:00
Ryan Fleury a021e6f68f extend rangification of meta evaluations to all child evaluations; further mark up schema expansion types 2025-04-14 13:51:43 -07:00
Ryan Fleury 5162301316 f32 path for meta evaluations 2025-04-14 13:18:01 -07:00
Ryan Fleury 7d48e9915d adjust lens'd eval -> view cfg to being based on type info, not expression tree 2025-04-14 12:58:26 -07:00
Ryan Fleury b34c70a247 begin merging view state / view parameterizations - unify code for introspecting on each, thus allowing explicit parameterizations of view state via a lens call. also build out the path from an eval -> cfg tree 2025-04-14 12:49:47 -07:00
Ryan Fleury ee0c1b25c3 eval ir generation: adjust autohook-allowance to be a stack, and correctly disable it for all sub-evaluations when using a raw lens, such that autohooks do not apply for evaluation of the parameter (e.g. raw(foo) -> foo, without allowing mapping of foo to something else) 2025-04-14 11:07:18 -07:00
Ryan Fleury 70c003607d further fixes to slider viz 2025-04-14 10:55:33 -07:00
Ryan Fleury 550950ed46 ui min sizes, fixes to slider viz 2025-04-14 10:49:36 -07:00
Ryan Fleury b98f2b153e fix call expr stringification 2025-04-13 16:45:27 -07:00
Ryan Fleury 7c668388eb hook up programmatic breakpoint state to trap list 2025-04-12 19:38:07 -07:00
Ryan Fleury 8a857b2154 use set/unset breakpoint events to build bp entities in ctrl entity tree 2025-04-12 15:32:27 -07:00
Ryan Fleury 7ba027e841 sketch out new markup API for programmatic address/data breakpoints 2025-04-12 15:21:48 -07:00
Ryan Fleury 6a5fa58d8a dedup flagged traps, so we don't write the same data breakpoint into the registers multiple times 2025-04-12 14:47:29 -07:00
Ryan Fleury 97e3c73086 fix flagged-trap-search 2025-04-12 14:39:38 -07:00
Ryan Fleury 0f380e9228 transmit user breakpoints hit from demon -> ctrl using ctrl-defined IDs, correllate those IDs to rd-defined IDs, use rd-defined IDs in stop events to count bp hits, rather than re-resolving breakpoints. further fixes & work on first pass of data breakpoints 2025-04-12 14:28:38 -07:00
Ryan Fleury d894f7112f array view rule 2025-04-12 07:55:19 -07:00
Ryan Fleury 3f69b028e4 fix ptr-to-ptr expansions 2025-04-12 07:34:27 -07:00
Ryan Fleury ecad70ca19 pass through data breakpoint length, more progress on fixes/correctness in first pass 2025-04-11 18:07:00 -07:00
Ryan Fleury 929e68d074 first pass at setting up x64 debug registers for data breakpoints 2025-04-11 17:49:16 -07:00
Ryan Fleury e621d13669 frontend ui/editor & data funnelling for hardware data breakpoints 2025-04-11 17:03:36 -07:00
Ryan Fleury 64187e75eb slider extension to built-in cell controls (similar to toggle-switch) 2025-04-11 16:21:47 -07:00
Ryan Fleury 72aa479724 eliminate unnecessary usage of $. in mule auto view rules 2025-04-11 15:04:32 -07:00
Ryan Fleury e754380caa eval identifier resolution: allow implicitly mapping leaf identifiers to member accesses of overridden irtree 2025-04-11 15:02:54 -07:00
Ryan Fleury 2e8bca21f6 strip out only/omit - i think they are insufficient for long-term filtering stuff... 2025-04-11 14:41:15 -07:00
Ryan Fleury 3e49e92e98 only and omit; notes & dead code deletion 2025-04-11 14:16:48 -07:00
Ryan Fleury 83a31a5229 take out view rules from pins, since that is just in the expr itself now 2025-04-11 13:21:25 -07:00
Ryan Fleury abd33f7160 new (and successful :) ) story for 'parent/overridden irtrees'. basically, if we have a rule which maps some eval X's type from A -> B, we preserve the original ir-tree compilation of A in the 'history' when we inevitably produce the ir-tree compilation of B. this can be used for accesses on overridden evaluations, and it allows us to implement $ in auto view rules. 2025-04-11 11:58:43 -07:00
Ryan Fleury 9622bc8808 fix calls to parent tree experiment 2025-04-11 11:26:01 -07:00
Ryan Fleury b60329c817 eliminate view rule column; eliminate 'parent irtree' experiment, need to do something else 2025-04-11 11:25:16 -07:00
Ryan Fleury 59df09b39b re-enable auto view rules in mule 2025-04-10 16:53:36 -07:00
Ryan Fleury 297c576623 irtree parent experiment (failed) 2025-04-10 16:20:52 -07:00
Ryan Fleury b7e12f900c eliminate dead code 2025-04-10 15:19:58 -07:00
Ryan Fleury 0dd0f1b8bc rephrase type irgen hook -> irext, to eliminate cases where it'd be very easy to accidentally cause infinite recursion of ir generation (e.g. slice(x) requiring evaluation of 'lhs.count', where lhs == slice(x)). also bring back slice hooks 2025-04-10 15:19:29 -07:00
Ryan Fleury 4a69b8e57a type decoration to explicitly disable string visualization; use in registers & padding members; eliminate dead code 2025-04-10 14:29:58 -07:00
Ryan Fleury c05c21cfa4 lens inheritance-on-expansion, composability with lens types & accesses (dot operator, array index operator), plugging in visualizers, killing dead code, etc. 2025-04-10 14:29:58 -07:00
Ryan Fleury d15f9af4b7 fix incorrect signal of error on meta-ctrl-entity eval space write 2025-04-10 14:29:58 -07:00
Ryan Fleury 8dd8eaa507 more work on lens-wrapped expressions composability w/ default expansions, operators, etc. 2025-04-10 14:29:58 -07:00
Ryan Fleury c9e55cacf5 fix root-level block -> row expansion 2025-04-10 14:29:57 -07:00
Ryan Fleury c7a3a73b63 fix incorrect story for chained lens calls; fix possibly-overridden usage of lens calls in ui build 2025-04-10 14:29:57 -07:00
Ryan Fleury fbe747a8b4 further work on convergence, dead code elimination, and lens (view rule) calls 2025-04-10 14:29:57 -07:00
Ryan Fleury cde079a14d checkpoint in moving to new type-based view rule / synthetic structure hooks 2025-04-10 14:29:57 -07:00
Ryan Fleury ac65d7fc34 fix incorrect type info generation of schema'd evaluations 2025-04-10 14:29:57 -07:00
Ryan Fleury c938a6fcfa next checkpoint; eval/type-hooks for registers, locals, files/folders, cfgs 2025-04-10 14:29:57 -07:00
Ryan Fleury d3f0a9a672 checkpoint in moving from old lookup hooks -> new type hooks; elimination of unnecessary recomputation of ir-trees/evals, just use information in already-computed evals 2025-04-10 14:29:56 -07:00
Ryan Fleury fbd78525d2 sketch out new eval type-system-defined hooks for all eval-layer view rules; accesses (., [] operators), expansion ranges, id <-> num mapping 2025-04-10 14:29:56 -07:00
Ryan Fleury 7c0a37fef3 boil down expr/irtree/type -> lookup_rule mapping more - since lens arguments are now stored in type info, we no longer need other ways of smuggling through expression trees. also fill out new path of pointer eval single-line string generation. 2025-04-10 14:29:56 -07:00
Ryan Fleury 9bfa4f87e3 work on new eval-viz layer stringification which factors out measurement/limiting/etc., but just walks an eval tree and stringifies each part; start working on new types <-> lookup-rule stuff 2025-04-10 14:29:56 -07:00
Ryan Fleury b1f17b217c checkpoint - extend constructed types w/ expression arguments, new 'lens' type operator, which can wrap evaluations of other types, + provide a name/args. e.g., bitmap(256, 256) <- (uint8 *), as a well-formed type. this also is the first step to collapsing all 'expression introspection' paths, and making sure they all compose properly. 2025-04-10 14:29:56 -07:00
Ryan Fleury 97a1003d85 eliminate old incorrect auto-hook of ctrl entity type keys; was busting visualization of ctrl entities 2025-04-10 14:29:56 -07:00
Ryan Fleury 84e16b81ff automatically mark up entry_point as exe entry points, for codebase builds 2025-04-10 14:29:55 -07:00
Ryan Fleury da69d9e91c more progress on new eval/view-rule integration; raddbg_entry_point markup feature 2025-04-10 14:29:55 -07:00
Ryan Fleury ecb3992b93 eval stability tests in tester; tear out last pass' view rule extensions 2025-04-10 14:29:55 -07:00
Ryan Fleury 710828c67d checkpoint in switching to new call-style of view rules for everything 2025-04-10 14:29:55 -07:00
Martins Mozeiko 0c999d70dc better error message if CreateProcess fails 2025-04-07 10:42:54 -07:00
Ryan Fleury 0705ba0a96 begin plugging in view rules as formal call part of expression language 2025-04-07 08:01:33 -07:00
Nikita Smith d060cb58b7 disable import library for radlink build 2025-04-05 11:59:10 -07:00
Nikita Smith ea5aab3f7e remove assert for empty switch 2025-04-04 15:50:23 -07:00
Nikita Smith ab05133f8a picked better name convention for the section table 2025-04-04 15:47:56 -07:00
Nikita Smith 8beb168905 went over COFF string table and changed the parser code accept to String8 2025-04-04 15:45:51 -07:00
Nikita Smith c090bee2f3 added missing debug comments for chunks 2025-04-04 15:45:51 -07:00
Nikita Smith bb3d01ffe6 output lib index and chunk debug comments 2025-04-04 15:45:51 -07:00
Nikita Smith c6ba475427 produce image layout map 2025-04-04 15:45:51 -07:00
Nikita Smith 02885b0b86 dedup manifest inputs 2025-04-02 22:48:56 -07:00
Ryan Fleury ca7f20e394 detect window resizes as a layout-reset correctly 2025-04-02 15:55:50 -07:00
Ryan Fleury 95df14bc20 eliminate old short-circuit from leaf-numeric expr tree generation path 2025-04-02 15:25:14 -07:00
Ryan Fleury c6add5f8f0 fix incorrect type name short-circuit check 2025-04-02 15:12:32 -07:00
Ryan Fleury 9bf69afd0b eval: procedure, type, thread-variable name mapping; sketch out implicit member access path 2025-04-02 15:07:35 -07:00
Ryan Fleury 33de625373 eval: register, register alias name mapping in new name resolution pass 2025-04-02 14:56:53 -07:00
Ryan Fleury 9146594ff9 eval: global name resolution in new ir-stage name resolution path 2025-04-02 14:39:38 -07:00
Ryan Fleury 6113a2e3db eval: do simplification pass over identifier resolution, shift from parsing stage -> ir generation / typechecking stage; do simplifications over expr tree, eliminate redundant kinds 2025-04-02 14:30:12 -07:00
Ryan Fleury b2ae4d89d7 eval: re-slice helper map data structures -> core 2025-04-02 11:08:27 -07:00
Ryan Fleury 190b74f411 shift first-class basic type names to more widely-used names (int32 instead of S32, etc.); force match of any debugger-known basic type name -> key, do not settle for bogus aliases from debug info 2025-04-01 16:04:57 -07:00
Nikita Smith 1c518bfa07 prefix COFF machine enums with "Type" 2025-03-31 22:53:10 -07:00
Nikita Smith 1c1a8b84ec pass over raddump
- made inline sites section more compact
- consistent indentation for PE/COFF printers
2025-03-31 22:49:17 -07:00
Nikita Smith 03a87fd4ee cleaned up a bit symbol replacement logic 2025-03-31 22:47:57 -07:00
Ryan Fleury bca5169447 eliminate manual console creation & needs-console detection; use user-error mechanism for process creation failure 2025-03-31 16:38:18 -07:00
Ryan Fleury 999eca5e29 more old eval trimming 2025-03-31 15:41:10 -07:00
Ryan Fleury a5d6e8a335 make eval ctxs more robust to missing info, e.g. in the test harness case 2025-03-31 13:48:19 -07:00
Ryan Fleury 17ff4da9bf more eval scratch work 2025-03-31 13:09:30 -07:00
Ryan Fleury fbe0d3bc2e set up eval scratch; promote raddbg_markup to base layer, plug in custom codebase vsnprintf 2025-03-31 11:41:14 -07:00
Ryan Fleury 1adf280354 delete dead code in eval 2025-03-31 11:02:17 -07:00
Ryan Fleury 833bee35e3 sketch out new auto view rules for new expression language idea 2025-03-28 15:50:19 -07:00
Ryan Fleury 5eb9f2f886 big notes/todos/release-notes pass 2025-03-28 12:21:18 -07:00
Ryan Fleury 160083835a add std::vector / auto-view-rule test to mule 2025-03-28 11:38:56 -07:00
Ryan Fleury 269efba455 fix treatment of floats in thread color rgba macro in raddbg_markup 2025-03-28 11:04:37 -07:00
Ryan Fleury 3911a66b30 fill out first pass implementations of raddbg_markup features; thread names, thread colors, format-string output-debug-string helper, attachment-checking 2025-03-28 10:56:41 -07:00
Nikita Smith 4cc883a353 update includes in rdi_breakpad_from_pdb 2025-03-27 15:49:15 -07:00
Ryan Fleury da3c15c7ed short-circuit rule lookups if explicit default is found 2025-03-27 15:41:47 -07:00
Nikita Smith c57b5fcd6d appease clang 2025-03-27 15:37:27 -07:00
Nikita Smith dab65d6523 deleted rdi_dump, all features of this dumper are now part of raddump 2025-03-27 15:18:43 -07:00
Nikita 350c17a606 Update builds.yml
replaced rdi_dump with raddump
2025-03-27 15:17:50 -07:00
Nikita 12628c679c Update builds.yml
remove rdi_from_dwarf
2025-03-27 15:10:57 -07:00
Nikita Smith 5ba981357d fix string cast warning 2025-03-27 15:01:16 -07:00
Nikita Smith 3c7c2918f6 replace pointers to incomplete types in UDT members 2025-03-27 13:47:47 -07:00
Nikita Smith 49ba163077 export CodeView types as aliases to its builtin counter-parts, 2025-03-27 13:47:47 -07:00
Nikita Smith 53c889e5d3 switched to using base Arch enum for converting DWARF registers,
simplified top level building path
2025-03-27 13:47:46 -07:00
Ryan Fleury dc967f5274 fix treatment of 0-terminator in raddbg data section, fix encoding of auto view rules in raddbg data section 2025-03-26 16:28:13 -07:00
Ryan Fleury b154c5a120 use slightly looser mapping for auto-view-rules, to not generate false negatives when looking up 2025-03-26 14:57:58 -07:00
Nikita Smith 14966d932e don't bake discarded type 2025-03-26 14:52:35 -07:00
Ryan Fleury 03cbbac6d7 source-markup-defined auto-view-rules 2025-03-26 13:45:26 -07:00
Nikita Smith 8f7ca178c2 bugfix incomplete type resolution hash table lookup 2025-03-26 12:21:55 -07:00
Nikita Smith c80661449c added rest of XMM registers, more progress on converting expressions front 2025-03-26 12:19:16 -07:00
Nikita Smith e7cee3b83c helper for extract bits 2025-03-26 12:19:16 -07:00
Nikita Smith ff61ad4cf8 improved formatting of bytecode locations, and added inline site name display
next to inline site index
2025-03-26 12:19:16 -07:00
Nikita Smith 63086b802c opcodes for encoding partial values 2025-03-26 12:19:16 -07:00
Nikita Smith 64b8f762cb fix bytecode list concat 2025-03-26 12:19:16 -07:00
Nikita Smith d137d928c9 added call site value opcode to RDI format 2025-03-26 12:19:16 -07:00
Nikita Smith 8551e8c3ec remove unused funcs 2025-03-26 12:19:16 -07:00
Nikita Smith 801b18a82d bugfix machine conversion in PDB and improved inference of conversion drivers 2025-03-26 12:19:16 -07:00
Nikita Smith a63254b70d merged rdim_help.c into rdim_local.c 2025-03-26 12:19:16 -07:00
Nikita Smith 7d5110e752 take into account null type slot 2025-03-26 12:18:47 -07:00
Nikita Smith b10b08783a WIP RAD debug info converter 2025-03-26 12:18:47 -07:00
Nikita Smith a84028d67a helper for checking if ELF has DWARF debug sections 2025-03-26 12:18:47 -07:00
Nikita Smith b9c4774786 minor fixes 2025-03-26 12:18:46 -07:00
Nikita Smith 2e6ffbd0c4 fixed typo in attrib class for DW_Form_RngListx 2025-03-26 12:18:46 -07:00
Nikita Smith 0c61415f72 merged path helper code from linker layer into main path layer 2025-03-26 12:18:46 -07:00
Nikita Smith 1ec1deedee moved MSF magic checkers to msf.c 2025-03-26 12:18:46 -07:00
Nikita Smith 0c3a37af44 helper for extracting GNU debug link info 2025-03-26 12:18:46 -07:00
Ryan Fleury 48f0702e05 fix source markup parsing, release notes for source-defined watch annotations 2025-03-26 11:49:15 -07:00
Ryan Fleury bd35ea83fc support for raddbg_pin markup on-the-fly watch pin annotations 2025-03-26 11:38:32 -07:00
Ryan Fleury 29d430ca6c dial back use of hand hover cursor 2025-03-26 10:00:49 -07:00
Ryan Fleury 42e888d41e fix breakpad converter build 2025-03-25 16:57:33 -07:00
Ryan Fleury ab9885bc7d fix clang build 2025-03-25 16:54:12 -07:00
Ryan Fleury 213091cf75 add safeguard to not overwrite old config data, for anyone using dev currently... 2025-03-25 16:40:52 -07:00
Ryan Fleury a826afd4d6 merge part 2 2025-03-25 16:30:05 -07:00
Ryan Fleury c4f4b5ff01 merge 2025-03-25 16:21:51 -07:00
Ryan Fleury 4787a183e3 fix consistency issues 2025-03-25 16:06:13 -07:00
Ryan Fleury 8ba44295c6 more aggressively gc hover eval view state; do not use hotkey intermediate if a command triggered by a watch window is already parameterized 2025-03-25 15:17:56 -07:00
Ryan Fleury af9ddf0a48 eliminate old entity -> eval blob paths / cache 2025-03-25 14:57:06 -07:00
Ryan Fleury aff63db8eb ctrl entity meta evaluation, hook up reads/writes, get off eval blobs; switch freeze/thaw ui to working on 'active' child, plugs into usual toggle path 2025-03-25 14:56:21 -07:00
Ryan Fleury 974ce5fa59 eliminate rule to associate set names with expand rules / visualizers; this is really only a rule we want for the core eval lookup hooks 2025-03-25 14:13:59 -07:00
Ryan Fleury ef1685adc9 pass over cfg meta evaluations; instead of forming artificial 'eval blob', just use sets/queries/hooks to do the lookups. eliminate cfg -> eval blob cache. switch to 'enabled' rather than 'disabled' as the cfg default. more convergences/fixes/tweaks. 2025-03-25 13:49:59 -07:00
Ryan Fleury 87e4b8b3f8 adjust toggle_switch 2025-03-24 15:48:44 -07:00
Ryan Fleury 2d7a8740bf adjust toggle switch rules 2025-03-24 15:04:54 -07:00
Ryan Fleury 4f2eb2ebe2 pass over cell line edit; toggle-switches for editable boolean types 2025-03-24 14:56:41 -07:00
Ryan Fleury 93584ba2ba convergence, enum member name evaluation fixes, visual fixes/tweaks 2025-03-24 13:17:10 -07:00
Ryan Fleury 02322191fe fix drag/drop of immediate views, fix disallowance of [ or { in mdesk tags, other various convergences/fixes 2025-03-21 17:18:16 -07:00
Ryan Fleury c2bebf2a53 snap to thread on stop on all windows, not just focused 2025-03-21 14:30:29 -07:00
Ryan Fleury c70132cd37 never mind --- this conflicts badly with stable version! 2025-03-21 11:51:52 -07:00
Ryan Fleury 1cef39d0a3 bump encoding version to match dev 2025-03-21 11:42:02 -07:00
Ryan Fleury cc4c889a99 bump format encoding version; add breakpad converter to ci; remove unused code 2025-03-21 11:39:53 -07:00
Ryan Fleury 6f3c14c423 fix misusage of disabled schema 2025-03-20 16:17:12 -07:00
Ryan Fleury 5596f1c8a3 more convergence, fixes, use new tab options mechanism to allow disabling line numbers in text/disasm 2025-03-20 16:00:23 -07:00
Ryan Fleury e2bfecc384 further work on rich hover vs. hover eval vs. ctx menu arrangements; it's a bit too noisy/annoying when hover eval for breakpoints/threads/etc. is just turned on all the time, and now that we have the ability to hover-eval-style query views, because of tabs, we can just do that with breakpoints etc. too. the old rich hover tooltips / highlights / etc. can then just be used normally. also put in some mechanisms to block rich hover tooltips when it is strictly redundant information. 2025-03-20 15:01:40 -07:00
Ryan Fleury 43d8fd4886 query watch windows progress; hook up visualizer schemas to cfg evaluator, use in tab query watch 2025-03-20 14:26:09 -07:00
Ryan Fleury f5683b0f3d convergence - source view switching commands 2025-03-20 10:09:06 -07:00
Ryan Fleury 1ffb8a082e sketch out first several 0.9.16 release notes 2025-03-20 09:19:27 -07:00
Ryan Fleury 8df16b8508 fix ctx menu closing escape consumption rules; fix top bar prioritization rules 2025-03-19 16:42:14 -07:00
Ryan Fleury b9ed7b3f0f fix menu bar focus rules breaking when hover eval focused 2025-03-19 16:22:42 -07:00
Ryan Fleury 4316325b33 demon win32: only alloc console when launching target if the exe is not a windows gui pe subsystem 2025-03-19 16:08:29 -07:00
Ryan Fleury d3e25567ac convergence on listers / visual fixes 2025-03-19 15:30:47 -07:00
Ryan Fleury 7d4d8762b7 collapse query/hover-eval building paths into single floating-view-build path 2025-03-19 10:30:50 -07:00
Ryan Fleury eaa3711405 dead code elimination / small fixes in collection query eval 2025-03-19 06:31:18 -07:00
Ryan Fleury 6a44f6485d eliminate old and now unused parts of hover eval state 2025-03-18 16:30:14 -07:00
ed 26c488b93a Merge tag 'v0.9.15-alpha' 2025-03-17 20:06:46 -04:00
Nikita Smith 1dc0192322 fix clang warning and errors 2025-03-17 15:25:49 -07:00
Nikita Smith 344cd8ffbf use djb2 hash for now 2025-03-17 14:20:40 -07:00
Nikita Smith 4298f3d5f6 typo 2025-03-17 13:29:52 -07:00
Nikita Smith 13352751ec moved DWARF parser to use str8_deserial-style API, added to the parser
layer functionality for interpreting different types of attributes,
added support for location lists, and API to enable parsing tags with
abstract origin.
2025-03-17 10:40:59 -07:00
Nikita Smith 57208909f1 updated DWARF expression printer, added ELF preamble,
transitioned debug info and debug line printers to new parser
2025-03-17 10:28:56 -07:00
Ryan Fleury 9c763c4554 fix open-recent-project according to recent_project schema 2025-03-17 07:13:52 -07:00
Ryan Fleury 41a252e563 notes on low-priority odd edge-case behavior 2025-03-15 11:42:20 -07:00
Ryan Fleury a4888055e2 better disabled/conditional rendering of breakpoints 2025-03-14 21:16:19 -07:00
Ryan Fleury cb6a66b98d member filtering, better visualization for selection state in targets/bps/threads/etc. 2025-03-14 13:27:26 -07:00
Ryan Fleury 24ddab0db2 fix slice view rule to apply correctly to pointers/refs->structs too 2025-03-14 12:41:48 -07:00
Ryan Fleury 41aa23b71b work on hover eval visualizers; skip watch window level if all we're doing is spawning a visualizer at the top-level; more convergence / cleanup / fixes 2025-03-14 09:54:48 -07:00
Nikita Smith f1e88b5667 pass over PDB converter
- moved incomplete type resolution from the converter to RDI make helper
  layer so we don't need to duplicate code in DWARF converter
- changed code for building basic types to handle various data models
2025-03-13 23:04:40 -07:00
Ryan Fleury c331133388 adjust hash store - first, don't keep strong refcounts for key history past the 2nd hash - this is prohibitively expensive. but, keep 'downstream' refcounts - this is a mechanism which downstream caches (e.g. text visualization info parsing etc.) can use to ensure a hash stays held in the hash store, given some other data's dependence on it - this stops the storing of unnecessary OutputDebugString log copies 2025-03-13 14:02:06 -07:00
Ryan Fleury d10547d2c0 don't assume offset evaluation mode in array dereferences; could apply to type info too, thus null mode; fix visualizer drag/drop causing close of hover eval, invalidating the dragged view too early; fix close-window not exiting if last window 2025-03-13 08:30:16 -07:00
Nikita Smith 631106b0a8 natvis for RDI Make types 2025-03-12 14:52:09 -07:00
Nikita Smith 3eedcb1912 initialize frame base in interp context 2025-03-12 14:49:14 -07:00
Nikita Smith 44249f35fc pass over the make RDI library
- Handle type layout in the library so converts simply
  define type graph and let the library handle DAG layout.
- Changed location baking. For now the library waits for scope, procs,
  global vars, and thread vars steps to serially finish because
  of common dependency on location sections, we need to parallel for each step.
- Changed encoded offset size for RDI_EvalOp_FrameOff to 8 bytes
  (1 byte is not enough to cover all cases)
- Added frame base location to RDI_Procedure (WASM encodes frame base
  as an index into a global array and so we have to resolve the base
  at runtime).
2025-03-10 16:49:54 -07:00
Nikita Smith 5717d6c54c export restrict modifier 2025-03-04 13:26:24 -08:00
Nikita Smith 4e775d5b6c hash table helper 2025-03-04 11:39:26 -08:00
Nikita Smith dfd6950ff3 deleted obsolete DWARF parser files 2025-03-03 17:20:22 -08:00
Nikita Smith 2ba1a0d502 pass over DWARF header
- added new types
- renamed mode -> format
- fixed section naming
- added helper for picking array lower bound
2025-03-03 17:14:22 -08:00
Nikita Smith ed897979ca added fields for user defined ELF types 2025-03-03 17:11:52 -08:00
Nikita Smith 6c425aa9dc misc NATVIS types 2025-03-03 17:10:44 -08:00
Nikita Smith 35ed8d6a1e bugfixed zero-length block decomp and fixed 64-bit casts 2025-03-03 17:10:06 -08:00
Nikita Smith 8b4f97223e moved async bakers from PDB converter to a stand-alone file to reuse
them in DWARF converter
2025-03-03 17:09:01 -08:00
Nikita Smith 53bff614e6 moved LEB helpers to DWARF layer 2025-03-03 17:06:58 -08:00
Nikita Smith d5811b7748 binary search for U64 and Rng1U64 arrays 2025-03-03 17:04:07 -08:00
Nikita Smith a06f576161 detect and error out on PDB linked with /DEBUG:FASTLINK 2025-02-25 14:42:10 -08:00
Nikita Smith 6c5d2a05cb moved platform depended code from OS layer to linkers IO 2025-02-25 14:41:34 -08:00
Nikita Smith d5ab121183 pre-allocate file size before write 2025-02-25 14:41:34 -08:00
Nikita Smith bbce89eada added /RAD_WRITE_TEMP_FILES
When enabled linker writes image and debug info to temporary files
and renames them after all writes are done.
2025-02-25 14:41:34 -08:00
Nikita Smith 8a8a8bcc8d resource id compar typo 2025-02-25 14:41:34 -08:00
Nikita Smith 1d441bac30 minor fixes and renames in DWARF enums 2025-02-25 14:41:16 -08:00
Nikita Smith 90c05d56b5 added zlib decompressor for DWARF extraction 2025-02-25 14:41:16 -08:00
Nikita Smith b74c304f39 added ELF header and parser 2025-02-25 14:41:15 -08:00
Nikita Smith 87ae363292 print file path in DW_Attrib_DeclFile 2025-02-25 14:41:15 -08:00
Nikita Smith ea6a84ca57 helper for extracting DWARF sections in COFF files 2025-02-25 14:41:15 -08:00
Nikita Smith 8d9f85bfcc move magic check to PE layer 2025-02-25 14:41:15 -08:00
Ryan Fleury 33326a8fa6 fix breakpad converter build 2025-02-23 14:18:12 -08:00
Ryan Fleury 9e6e65d3c6 eliminate cfg testing from this build; fix bad recursion artifacts, causing bad state when types tab visible; put in temporary fix for memory view truncation 2025-02-23 14:06:11 -08:00
Ryan Fleury 225445a204 bump version 2025-02-23 13:21:06 -08:00
Ryan Fleury 74ce085adc start on new 'pull/pop out' button for visualizers 2025-02-21 19:59:26 -08:00
Ryan Fleury f753e9bd18 small fix 2025-02-21 19:20:09 -08:00
Ryan Fleury a3062dfeb1 watch-window-defined/driven query lister completion 2025-02-21 19:15:26 -08:00
Ryan Fleury 8bca57ef7f improved stability w.r.t. cfgs and ctrl entities expansion across changes 2025-02-21 18:14:02 -08:00
Ryan Fleury 1b4a5e529f more convergence / fixes relating to searching/queries/filters 2025-02-21 16:33:57 -08:00
Ryan Fleury 9b636568fd more convergence 2025-02-21 15:29:54 -08:00
Ryan Fleury e76da7892a fix bad debug info scope search usage 2025-02-21 13:57:54 -08:00
Ryan Fleury 3c8f58cb38 add tracking to dbgi scopes 2025-02-21 13:23:12 -08:00
Ryan Fleury 03337a7280 more convergence on lister/queries 2025-02-21 13:01:28 -08:00
Ryan Fleury b0486d942e correctly pipe through exception info, visualize exceptions better 2025-02-21 11:46:28 -08:00
Ryan Fleury 96fbcc848e double clicking cfgs with location info -> snap 2025-02-21 11:30:45 -08:00
Ryan Fleury 4f99a76ace commit window placement/etc. to cfg tree, pass through all monitor/pos/size/fullscreen/maximize info to initialization 2025-02-21 10:57:32 -08:00
Ryan Fleury 9e0fe942e6 allow base/opl style slices in slice view rule 2025-02-21 10:20:11 -08:00
Ryan Fleury 4f1e0dedb2 start plugging tab-opening back in 2025-02-21 09:52:50 -08:00
Ryan Fleury 2f2bb0d797 plug rebindings back in 2025-02-21 09:25:26 -08:00
Ryan Fleury c7da3e8a13 distinguish cfg (breakpoints, watch pins) source-locations from address locations; expand breakpoint addresses to being full expressions, & use this to implement symbol breakpoints (we now support fancier address resolution breakpoints too) 2025-02-21 08:42:33 -08:00
Ryan Fleury f3c6ee6f1f fix statically-disqualifiable breakpoint evaluations from being sent to the control thread as actual control thread conditions 2025-02-20 19:52:17 -08:00
Ryan Fleury 0a588d4058 fix keyboard input delegation between meta-interfaces (query lister line edit) and watch window controls; always accept single-visible-button presses, if multiline logic does not consume an event 2025-02-20 19:46:41 -08:00
Ryan Fleury 04c40e8359 expand eval to collecting irtree/type/lookup-rule, base all value string generation on entire root_eval rather than just root_expr; fixes wrong inheritance of tags in single-line visualization 2025-02-20 19:16:27 -08:00
Ryan Fleury 92df402ad1 member filtering 2025-02-20 18:46:22 -08:00
Ryan Fleury 2373af25ce watch expr drag/drop -> watch pin creation 2025-02-20 18:11:25 -08:00
Ryan Fleury e4de4dd52f hook up project cfg saving 2025-02-20 17:28:56 -08:00
Ryan Fleury cc966deb7c eliminate 'watch' as a view ui rule, move formally into just being a regular view ui build. hook up user file saving. fix metadesk parser - newlines must terminate *all* active implicit set parsing work. 2025-02-20 17:25:38 -08:00
Ryan Fleury 428a3f2536 always prefer explicitly attached tags (view rules); give all tags a chance in sequence; allow 'default' to be explicitly attached, to disable auto-view-rules etc. 2025-02-20 16:38:27 -08:00
Ryan Fleury ec782fa39c correct tag poisoning in lookup-rule tag usage within ir generation, allow lookup-rules to call dependent irgens 2025-02-20 16:26:40 -08:00
Ryan Fleury 13bfa42acf more work on watch-window-driven file lister 2025-02-20 14:49:25 -08:00
Ryan Fleury eae15a3d41 work on command queries, distinguish floating vs. embedded 2025-02-20 13:30:28 -08:00
Ryan Fleury 6653a0e437 auto tabs 2025-02-20 10:04:48 -08:00
Ryan Fleury 1a84f1cedd macroify 'search_path', use in file system queries 2025-02-19 17:22:49 -08:00
Ryan Fleury f61d87e0ce extend command info with query expressions for lister 2025-02-19 17:09:48 -08:00
Ryan Fleury b0cff76501 eliminate old palette system entirely 2025-02-19 12:09:28 -08:00
Ryan Fleury 26514ddc6a dead code elimination 2025-02-19 11:35:30 -08:00
Ryan Fleury a8f72dd5f1 progress on per-view searching operation - will be specialized & used for replacements for finding text, for going to line/address, and filtering in query views 2025-02-19 11:33:16 -08:00
Ryan Fleury f87dd1be82 per-box tags -> per-box tags key; cache (key -> tags_list), and (key * string -> theme_pattern) separately; accelerate all theme lookups 2025-02-19 09:35:45 -08:00
Ryan Fleury 9805f8cd20 begin work on lister-flavored watch windows; begin on using that for the query ui 2025-02-19 08:37:34 -08:00
Ryan Fleury 73351b7550 fix zero-sized content rect busting panel rectangles 2025-02-19 07:21:53 -08:00
Ryan Fleury eb4fe472f9 tweaks 2025-02-18 19:33:47 -08:00
Ryan Fleury 8706e7c56d dead code elimination, eliminating old theme usage 2025-02-18 19:27:27 -08:00
Ryan Fleury 1b8e39c635 work on tag-based styling 2025-02-18 18:08:18 -08:00
Ryan Fleury 6c9f7018f1 sketch out tag-based theme, per-window computation 2025-02-18 15:13:59 -08:00
Ryan Fleury e45bdfd90d linearize theme from srgba on load, use linear colors everywhere; begin simplifying ui colors 2025-02-18 10:39:43 -08:00
Ryan Fleury 42e3c406cd oklab <-> linear, linear <-> srgb 2025-02-17 18:33:56 -08:00
Ryan Fleury 2b54f48aab test with srgba buffer, hack in srgb -> linear conversion in shader for
testing
2025-02-17 18:02:47 -08:00
Ryan Fleury 21a41e9105 sketch out unattached process evaluation 2025-02-17 16:47:44 -08:00
Ryan Fleury 877e0126c9 file path drag/drops; a few fixes with tab drag/drop 2025-02-17 16:24:17 -08:00
Ryan Fleury 36798def1b convergence & cleanup & simplification & fixes of tab drag/drop, panel rearranging 2025-02-17 16:03:05 -08:00
Ryan Fleury 40d762756b more convergence on panel creation/removal paths 2025-02-17 13:25:06 -08:00
Ryan Fleury 72869bc73b simplify name alloctors in rd/ctrl layers; port panel-closure path 2025-02-17 12:05:56 -08:00
Ryan Fleury dc79b82991 watch pin view rules 2025-02-17 10:13:34 -08:00
Ryan Fleury 2636f296cc simplify stylized watch row building rules; allow buttons to be editable, maintain expr key stability even in different watch row styles 2025-02-17 09:48:26 -08:00
Ryan Fleury 5d8e6dac91 begin working on watch window stylization for file system evaluations 2025-02-16 22:16:59 -08:00
Ryan Fleury c77f2de156 more work on file evaluation; move eval_string <-> eval <-> file_path to formal filesystem/file spaces, rather than inferring from the expression tree; imply '.data' when generating file contents visualizer tabs 2025-02-16 18:36:45 -08:00
Ryan Fleury 5e98e40af7 file/folder evaluation work 2025-02-16 17:57:00 -08:00
Ryan Fleury 95493b6c30 do not lex/highlight non-code strings in watch cell 2025-02-16 14:22:01 -08:00
Ryan Fleury 7d84ec79c5 formalize file/folder evaluations; use set-types for files/folders so that we can evaluate both file metadata & contents, rather than just assuming the contents; adjust slice view rule to just expand to the contents, rather than achieving the slice with a changed type 2025-02-16 14:13:48 -08:00
Ryan Fleury c603457460 dead code deletion, begin extending eval/eval-viz to work on expr-chains rather than single expressions; fixes / convergence for watch window 2025-02-15 18:11:22 -08:00
Ryan Fleury 176c2590a0 ghosted 'view rule' hint 2025-02-15 15:10:04 -08:00
Ryan Fleury 5ce74bd66b readjust cfg lookup rule to apply to not just top-level queries but scoped queries too; eliminate old scheduler code 2025-02-15 15:02:58 -08:00
Ryan Fleury b7f6b301ec eliminate unnecessary complication for debugger query evaluations; formalize them in the schemas, use set-hook rule to automatically plug in querying functions for them 2025-02-15 14:52:40 -08:00
Ryan Fleury 404ad620ef more convergence; split scheduler into machines, process, and threads tabs. most people just care about threads, and so that should be the default/common case 2025-02-15 13:32:46 -08:00
Ryan Fleury 81be64dac6 more covergence, freeze controls on applicable ctrl entities when evalled 2025-02-14 13:41:02 -08:00
Ryan Fleury ecb4e0d282 rich hover for thread-hover editors 2025-02-14 09:43:19 -08:00
Ryan Fleury c5de847fa5 ctrl entity rich hovering 2025-02-14 09:19:25 -08:00
Ryan Fleury 35ba41f712 correctly hook up watch window commands to their associated cfg; plug in ctrl entity detection / fancy rows 2025-02-14 09:04:46 -08:00
Ryan Fleury 87ee37d19e if cell activates on single-click, disable double-click path 2025-02-13 21:55:04 -08:00
Ryan Fleury af8f1ff162 frontend cleanups, cmd running from watch 2025-02-13 21:33:40 -08:00
Ryan Fleury f58c13b3a0 plug full data member calculation path & padding member visualization back in 2025-02-13 15:26:21 -08:00
Ryan Fleury 141dd69eba correct rich hovering for rich watch window rows; distinguish between single/double-click watch cells; more convergence 2025-02-13 15:12:34 -08:00
Ryan Fleury c39cc5d642 call stack rows -> module evaluation column 2025-02-13 11:36:57 -08:00
Ryan Fleury 18010db753 per-row command cells in watch windows when evaluating cfgs; table-drive per-collection commands 2025-02-13 11:20:10 -08:00
Ryan Fleury 6498666619 begin moving per-row style info to per-cell style info 2025-02-13 09:26:05 -08:00
Ryan Fleury fba0053e9b preserve ambiguous path rendering 2025-02-13 08:21:48 -08:00
Ryan Fleury 863d98c43e do the same reuse of the computed irtree for array-index expr extensions 2025-02-13 08:13:53 -08:00
Ryan Fleury 50b195deb3 eliminate member-expr-extension irtree/oplist/etc. recomputations; just convert lhs irtree to bytecode and attach that to new expr as a leaf bytecode 2025-02-13 06:51:50 -08:00
Ryan Fleury c31b15524a ensure threads match before visualizing call stack frame selection 2025-02-12 17:53:41 -08:00
Ryan Fleury 4dfa4a120f re-add special-case watch cell style for call stack frame selection 2025-02-12 17:50:18 -08:00
Ryan Fleury 374317abd7 call stack info extraction in watch row building; special style for call stack frames 2025-02-12 17:39:17 -08:00
Ryan Fleury f165eb7b8e recompute row infos on watch column drag 2025-02-12 16:58:24 -08:00
Ryan Fleury 96afe943c2 multi-row-topology watch window column dragging & saving to cfg tree 2025-02-12 16:54:48 -08:00
Ryan Fleury e84f8e66f5 precompute watch row infos before build 2025-02-12 16:05:37 -08:00
Ryan Fleury c8fb9a0ec9 clean up panel drop site jank 2025-02-12 14:27:14 -08:00
Ryan Fleury 204ac60999 extend fancy string lists to include per-node rasterization flags, to correctly mix flags from various fonts; pull command tables into the vocabulary map & accelerate lookups; drive icons/display-strings for commands with vocabulary map; plug in commands/fstrs to command evaluations in watch windows 2025-02-12 14:01:21 -08:00
Ryan Fleury 295cfa8698 fix new window creation 2025-02-11 17:21:24 -08:00
Ryan Fleury c555166af6 visualize *.N ptrs in single-line eval visualization; eliminate old hover eval code 2025-02-11 16:58:17 -08:00
Ryan Fleury 5f88db68ec preserve fancy string list on a per-ui_box basis - do not rely on fancy *run* list for truncated-string-hover, as this will invalidly hold onto stale render handles (fixes crash on font resizes) 2025-02-11 16:48:12 -08:00
Ryan Fleury 6c37db2105 more inline visualization; do not require qualifier if view rule names collide with locals 2025-02-11 16:36:20 -08:00
Ryan Fleury 98ec6ee3bb extend constructed type info with 'pointer depth', to distinguish between inline-depths; use in symbolizing & call stack expression formation 2025-02-11 16:16:44 -08:00
Ryan Fleury 312ddd5899 fix array-index ir tree generation - was incorrectly applying array value rules to address value evaluations; plug in ir-generation hooks for slices, arrays, etc.; eliminate old view rule code 2025-02-11 15:25:42 -08:00
Ryan Fleury 50e4f6a22a move watch window to using exclusively view ui rule input eval, rather than looking at the expression string itself 2025-02-11 14:14:55 -08:00
Ryan Fleury fa7143a3e4 never build hover evals if we cannot evaluate the root expression successfully 2025-02-11 14:07:43 -08:00
Ryan Fleury 82803e710e plug in fancy member names to watch views 2025-02-11 14:03:28 -08:00
Ryan Fleury ee984877b0 work on multi-topology watch tables; fancy evaluation for cfgs, regardless of where they are spawned 2025-02-11 13:30:07 -08:00
Ryan Fleury 1162841b6e begin sketching out watch row button cells, for intermixing fancy buttons for cfgs/entities/etc. with regular watch rows 2025-02-11 11:14:38 -08:00
Ryan Fleury 045aad8578 request reanimation on view loading-persist 2025-02-10 16:54:29 -08:00
Ryan Fleury 2a543ee7d7 fix environment string piping to control thread 2025-02-10 16:36:53 -08:00
Ryan Fleury 80b0138ea3 fix expansion rules being applied to traditionally non-expandable type info; plug memory view back in 2025-02-10 16:32:07 -08:00
Ryan Fleury 29033fe6cc fix incorrect type usage in default lookup-range eval path; fixes broken pointer/reference expansions to structs/unions/classes 2025-02-10 16:14:11 -08:00
Ryan Fleury 052efc7f64 meta command evaluation in frontend eval/eval-viz 2025-02-10 16:11:34 -08:00
Ryan Fleury 428617de91 re-add id stability to top-level-cfg evaluation expansions 2025-02-10 15:51:36 -08:00
Ryan Fleury f3c17a4e2c target environment string editing 2025-02-10 15:32:48 -08:00
Ryan Fleury 300231ad75 require file handle validity for file stream cache submits; simply retry on missing files 2025-02-10 14:22:42 -08:00
Ryan Fleury 3b19334075 tear out old meta evaluation code; robustify filesystem streaming async reads 2025-02-10 14:12:44 -08:00
Ryan Fleury d48cd460d1 begin prepping watch window ui for reintroduction of fancy rows; extend target/thread evaluations with .environment & .call_stack sketch; more convergence progress 2025-02-10 12:15:03 -08:00
Ryan Fleury 2da83dd732 bump to 0.9.15 - hook disasm back up 2025-02-10 09:47:37 -08:00
Ryan Fleury 4b85df0725 fix expr chain parsing; fix panel tree building 2025-02-10 09:44:32 -08:00
Ryan Fleury 3de43b8c74 view params, pulled either from cfg trees or view rule params (tag calls); expr chain parsing; correctly use tags in nested single-line eval visualization 2025-02-07 15:20:19 -08:00
Ryan Fleury 3582ab10e2 eliminate old watch view column state; plug in on-the-fly computed per-row cells; eliminate old table helper usage in watch window; plug in visualizers to watch window 2025-02-07 12:45:30 -08:00
Ryan Fleury 412c55a474 plug in visualizer view ui rules in new eval viz code; cfg-tree/vocab-driven tab titles 2025-02-07 11:40:49 -08:00
Ryan Fleury 31b0772137 eval viz: view rule -> expansion rule; rd: view rule -> view ui rule 2025-02-07 09:21:06 -08:00
Ryan Fleury e88f2e2e82 eliminate old entity tables 2025-02-06 12:51:59 -08:00
Ryan Fleury 712162af4a correctly apply root view rules; apply inherited view rule tags first, since we apply all view rules in order, and we want explicitly-stored tags (nearest to the expression) to be strongest 2025-02-06 12:32:09 -08:00
Ryan Fleury 7bc1dd7362 eliminate old eval vis view rule paths; sketch out view-rule-lookup & expr-tag-equipping, & expr tag (view rule) inheritance 2025-02-06 12:14:12 -08:00
Ryan Fleury d1541d3989 fix handling of root-expr editing in watch views; eliminate dead code 2025-02-06 11:36:56 -08:00
Ryan Fleury eaa65a6b3d raddbg: cast basic type value commits to destination type; ensures numeric things are casted appropriately (fixes f32/f64 value writes) 2025-02-06 11:26:02 -08:00
Ryan Fleury 295778f1ca eval: prohibit identifier overrides in macro maps; raddbg: correctly mark dirty state & recompute given watch window mutations; do not escape unquoted value eval strings 2025-02-06 11:17:42 -08:00
Ryan Fleury 43222e8511 tweak cfg tree mutations a bit to recycle old nodes/identities where possible 2025-02-06 09:35:19 -08:00
Ryan Fleury be039496c7 rd: watch window editability progress, implicit root vis rules; eval: fix call args parser 2025-02-06 09:15:13 -08:00
Ryan Fleury 66ab9c0ba3 rd: watch cell string edit commits 2025-02-05 16:21:51 -08:00
Ryan Fleury f2a958e5b6 rd: progress on reintroducing watch window editability 2025-02-05 16:09:20 -08:00
Ryan Fleury ffe8a01699 uid <-> num mapping for top-level cfg collection expansions; fix incorrect expansion for watches 2025-02-05 14:15:50 -08:00
Ryan Fleury 836b671491 move from ptr*gen handles -> id; eliminate all handle code in frontend and convert to using 64-bit ids 2025-02-05 13:37:58 -08:00
Ryan Fleury edbce2713f eliminate RD_Entity code entirely 2025-02-05 13:11:06 -08:00
Ryan Fleury 92d4f3ebb1 eliminate old config code 2025-02-05 13:02:12 -08:00
Ryan Fleury a80bd6664d collapse all watch-table watch window view rules into specializations of singular watch view path 2025-02-05 12:44:33 -08:00
Ryan Fleury ad4e6cbce5 size hover eval watch window by predicted block tree 2025-02-05 11:38:55 -08:00
Ryan Fleury 8a8f1e4fc2 work on new hover eval ui, built using the new cfg data structure, immediate-mode view states, etc.; all watch window features -> hover eval 2025-02-05 10:34:47 -08:00
Ryan Fleury 50f8732e63 fix num/idx/vidx/vnum coordinates to correctly apply to root row in watch windows 2025-02-04 19:38:57 -08:00
Ryan Fleury a003a11425 progress on mixing control (command, insertion) rows in cfg-list evaluation, for watch windows; e.g. empty row in watch window, add-new buttons in targets/breakpoints/watchpins/etc. 2025-02-04 16:44:04 -08:00
Ryan Fleury de16c9cdef keep active tab view states hot, even if their ui is not built on any given frame (because they are not selected) 2025-02-04 14:13:01 -08:00
Ryan Fleury 90c86dc812 eval/eval-viz: pull out rules for mapping exprs/irtrees -> lookup/expansion rules; use this path in the single-line value string generator; eliminate old non-view-rulified string generation paths 2025-02-04 13:20:25 -08:00
Ryan Fleury afd113adcc rd: derive schema tree parse on startup rather than recomputing every time 2025-02-04 12:16:28 -08:00
Ryan Fleury b9756d222a eval: sketch out parse/ir cache 2025-02-04 10:29:52 -08:00
Ryan Fleury 657b78c4ef eval: separate ir_ctx -> ir_state & ir_ctx; ir_state for implicit thread-local caching mechanisms for eval, ir_ctx for explicitly supplied user info 2025-02-04 09:57:13 -08:00
Ryan Fleury 9a405bee20 eval: lookup info hook -> just pass irtree, do not recompute; cache for type-key -> auto hook tag exprs; use tags/auto-tags in lookup rule for . operator; fix tag poisoning in ir generation pass; cache for type-key -> unpacked type info; replace all unpacked type info paths with cache usage 2025-02-03 13:21:08 -08:00
Ryan Fleury 59fe6c79cb distinguish root block from non-root blocks; in root case, we do not want to do a lookup-range to generate the block's expression (but in all other cases we do) 2025-02-03 10:07:20 -08:00
Ryan Fleury 6f4533d8f5 rd: new ctrl entity meta evaluation path; ctrl entity meta evaluation cache; eval: auto-view-rules (via 'auto hook map'), + support for 'type patterns', e.g. for templates; ir generation / typechecking hook application + source-tag coloring (to avoid infinite recursion of repeatedly-applied auto view rules 2025-02-02 17:08:14 -08:00
Ryan Fleury eab5c7c971 eval_visualization: eliminate expansion-range hook; move expansions & block tree building completely to new eval hooks for lookups 2025-02-02 14:39:43 -08:00
Ryan Fleury 5bbd9f1c7e eliminate expr resolution hook in eval visualization layer; now succeeded by irgen hook 2025-02-02 12:46:59 -08:00
Nikita Smith d9874e8f2f bugfix resource compar 2025-02-02 00:06:07 -08:00
Nikita Smith 76b83794b2 added printer for .res files 2025-02-01 23:50:30 -08:00
Ryan Fleury 07c9268941 eval: specify formal way in which tags (view rules) can fit into expression language, both in parsing & in structure; introduce ir-generation hook step in eval pipeline, transfer most of the default non-vbisualization view rule features to that layer 2025-02-01 20:50:31 -08:00
Ryan Fleury aac93b5952 move over all expansion view rules to new eval-system lookup hooks; eliminate most of old hooks 2025-02-01 17:37:24 -08:00
Ryan Fleury b1829af8c6 eliminate old per-frame cfg group cache 2025-01-30 16:52:15 -08:00
Ryan Fleury 5b82fc2339 eliminate member-filtering hack for cfg views; eliminate deref-space-ptr hack 2025-01-30 15:52:26 -08:00
Ryan Fleury 68966ba55f eval: more progress on 'sets', plug primary watch group into it; rd: more progress on watch ui based on new sets/lookups 2025-01-30 15:43:41 -08:00
Ryan Fleury 12784d9ae9 partial transition to new flexible watch table structure; more work on 'set' types; checkpoint before replacement of old view-rule-hacks with proper-eval-system support for sets/collections/etc. 2025-01-30 14:11:01 -08:00
ed 92df592f82 Merge remote-tracking branch 'EpicGamesExt/dev' 2025-01-30 14:44:58 -05:00
Ryan Fleury 92e68701d0 eval: lookup rule map building; eval: use general 'set' type-kind to specify custom lookup rule; watch: new table <-> stable-point mappings 2025-01-30 10:57:29 -08:00
Ryan Fleury 394d35287a fix default lookup rule 2025-01-29 17:00:50 -08:00
Ryan Fleury baa19f3de4 begin introducing 'lookup' hook path in eval ir-tree generation, to collapse/universalize all 'access' operations, such that ., ->, and [] operations can be overridden via view rules, for cfg evaluations, and so on 2025-01-29 16:41:14 -08:00
Nikita Smith 0a0742aa0e remove unused enum fields 2025-01-29 16:28:02 -08:00
Nikita Smith e114ea7fdb hook RDI printers to the dumper 2025-01-29 16:27:15 -08:00
Nikita Smith 5c1e219901 minor prof fix 2025-01-29 16:26:02 -08:00
Nikita Smith 497f0e45d6 WIP merging RDI dump into RAD Dumper 2025-01-29 10:47:18 -08:00
Ryan Fleury 136a6a6d80 eval visualization: vidx <-> num mappings; helpers to move from logical nums -> rows, feed through windowed row production path 2025-01-29 10:38:04 -08:00
Ryan Fleury 84d55c8939 make some progress on watch window refinement for various row topologies 2025-01-28 18:31:34 -08:00
Nikita Smith bd5d38ef0c handle null write 2025-01-28 16:56:12 -08:00
Nikita Smith 5e3b500119 put ranges on arena 2025-01-28 16:46:50 -08:00
Ryan Fleury 2a1ab9b3be fix incorrect bytecode writing for deref-space-ptr 2025-01-28 10:42:41 -08:00
Ryan Fleury 4cc5f636fe cfg tree collection evaluation 2025-01-27 15:33:35 -08:00
Ryan Fleury b085acbc32 strip out collection type - instead we will implement collections via arrays of exprs which map to meta evals 2025-01-27 11:02:49 -08:00
Ryan Fleury c0f23c3807 further tweaks to support meta cfg eval 2025-01-27 09:22:34 -08:00
Nikita Smith 409905c983 yank out shared mutex impl
Initially shared mutex was needed to lock cores so thread pool
executes one parallel for at a time but on machine with high core count
we cant saturate processor all the time so we switched to shared semaphore
and block thread when all cores are busy.
2025-01-25 11:46:25 -08:00
Ryan Fleury 730e8a4720 commit cfg changes to eval blob cache immediately 2025-01-24 15:55:08 -08:00
Nikita Smith 0ca9d97750 error out on /LIB and /DUMP switches 2025-01-24 14:40:27 -08:00
Ryan Fleury aa03955a45 first pass at meta-cfg-space writes, for cfg editing 2025-01-24 13:22:14 -08:00
Nikita Smith f2f18b9798 replaced /RAD_IDLE_WORKERS with /RAD_SHARED_THREAD_POOL_MAX_WORKERS 2025-01-24 12:49:30 -08:00
Ryan Fleury 04e6eae49d progress on meta-evaluation of cfg trees & plugging into watch/eval system 2025-01-24 12:28:52 -08:00
Nikita Smith 8196ef0a6e tweaks and fixed in thread pool
- created a separate entry point for shared workers
- fixed race condition in tp_run_tasks where worker would read
  modified task count and cause unpredictable behavior
2025-01-24 10:33:42 -08:00
Nikita Smith b18060ef0d on crash CRT randomly wont flush stdout 2025-01-23 20:45:25 -08:00
Nikita Smith b463c8087d copy alternate name strings 2025-01-23 20:44:14 -08:00
Nikita Smith 71b0dfa150 bugfix for uninited memory 2025-01-23 20:39:06 -08:00
Nikita Smith b007e4c0e5 printer for S_LABEL 2025-01-23 20:38:43 -08:00
Ryan Fleury 50000c0d6b adjust metagen to support correctly-escaped multiline string generations; sketch out setting schemas; eliminate old settings hack, move to using cfg tree & settings schema 2025-01-23 11:39:55 -08:00
Ryan Fleury 45f02b7a41 sketch out top-level schema for cfg tree 2025-01-22 15:42:21 -08:00
Ryan Fleury 9a54ae50c1 old config code elimination 2025-01-22 14:23:39 -08:00
Ryan Fleury 443fee10ec more entity code deletion 2025-01-22 09:57:40 -08:00
Ryan Fleury 7443f33069 sketch out schemas for configuration trees 2025-01-22 09:40:57 -08:00
Ryan Fleury 16a717d684 further elimination of entity-based code; more simplification/moving to cfg; begin sketching out expanded eval-viz block tree, such that each block can have its own table topology (will be useful to collapse/simplify/expand the capabilities of watch views) 2025-01-22 09:22:06 -08:00
Ryan Fleury 84fd1e9d3f big batch of work in moving from entity -> cfg; work on new universal lister system for cfg right-click menus, system processes, file system, autocompletion, procedures, etc. 2025-01-21 16:41:59 -08:00
Nikita Smith 53db7ee712 fix symbol table printer for big objs 2025-01-21 11:29:28 -08:00
Nikita Smith aa4ec903a6 update LF_STRUCT2 printer 2025-01-21 11:29:12 -08:00
Nikita Smith c6d28b97b7 more details for LF_STRUCT2 2025-01-21 11:14:12 -08:00
Nikita Smith 61307aefbc reworked thread pool to share workers via semaphore 2025-01-21 01:55:13 -08:00
Nikita Smith 85ea141b83 minor fixes 2025-01-20 21:53:45 -08:00
Nikita Smith d3fbc858b8 impl shared thread pool mode 2025-01-20 21:41:24 -08:00
Nikita Smith e1e7fb745e win32 shared mutex impl and linux stubs 2025-01-20 21:36:43 -08:00
Nikita Smith 153bbc7b1d pass over COFF layer
- updated naming convention on structs, enums, and macros to conform with code base style
- moved related structs closer to each other
- moved parser code to separate file
2025-01-20 19:31:52 -08:00
Nikita Smith 269dc33985 set COMDAT selection on chunks created by import table 2025-01-18 23:21:06 -08:00
Nikita Smith a1d5837ff3 helpers for matching string literals 2025-01-18 17:39:11 -08:00
Nikita Smith 89ff4d0de2 on lambda types we have to replace unique name with hash,
otherwise visual studio wont show local variables in lambdas
2025-01-17 15:31:34 -08:00
Ryan Fleury 5cbef8f10d more entity -> cfg work 2025-01-17 15:16:23 -08:00
Ryan Fleury 4371d727fb line expressions in eval lang; begin getting off of entities for breakpoints/watch-pins/etc., move -> cfg 2025-01-17 13:34:18 -08:00
Ryan Fleury 069084c108 fix view parameter storage hook to not repeatedly duplicate key values 2025-01-17 10:35:04 -08:00
Ryan Fleury e6d0afb026 stateful query lister stack & immediate-mode autocompletion lister, via same codepath; begin hooking up views 2025-01-17 08:11:01 -08:00
Nikita Smith de2ea38f50 build file paths relative to image path 2025-01-16 14:03:14 -08:00
Nikita Smith b405ed4873 factored out logic for splitting function chunks into separate pass
over symbol table; associations are now assigned to sub chunks too;
inherit function chunk align from parent chunk
2025-01-16 13:47:13 -08:00
Nikita Smith c000817b9a pass over COFF symbol parser 2025-01-16 13:43:19 -08:00
Ryan Fleury 4ae032efff begin sketching out stuff for stateful listers being collapsed with immediate-mode autocomplete lister 2025-01-15 17:18:58 -08:00
Ryan Fleury 62894c098a further progress on unified lister interface 2025-01-15 15:25:49 -08:00
Nikita Smith 190eb03ff3 removed default lib directive parser, moved directive code to obj file,
getting ready to deprecate LNK_Directive struct
2025-01-15 14:03:40 -08:00
Nikita Smith 1d6ee73409 handle zero sized array 2025-01-15 10:37:47 -08:00
Nikita Smith 1f8433096a COFF parser fixes 2025-01-15 10:25:16 -08:00
Ryan Fleury 6fe9a14778 eliminate stateful keybindings data structure - move to on-the-fly cfg tree usage 2025-01-14 17:30:07 -08:00
Nikita Smith 25f924b075 generate markers from RDI 2025-01-14 16:49:23 -08:00
Nikita Smith b889765c15 updated PE bin info to handle RDI entry, changed raddump to
convert and load RDI from memory, added helper for parsing debug directory
2025-01-14 16:49:05 -08:00
Ryan Fleury b98ebc8da4 lister applicability work - applies to commands, icons, descriptions, etc. 2025-01-14 15:16:55 -08:00
Ryan Fleury ace7db492b fix nil-cases of cfg insertion; fix incorrect root setting in cfg deep copy 2025-01-14 13:06:26 -08:00
Nikita Smith b1c5b308c0 collect inline site name string 2025-01-14 10:42:22 -08:00
Nikita Smith 24efb574f1 factored out inline site decoder into stand alone helper so it can be
reused in the converter
2025-01-13 18:00:18 -08:00
Nikita Smith 3cec629a8c pipe obj directives through config path 2025-01-13 15:22:37 -08:00
Ryan Fleury 1b52100361 part 5: begin shifting autocompletion lister box to being unified lister/ctx-menu replacement 2025-01-13 14:18:34 -08:00
Ryan Fleury e9a10bbbd2 part 4: fix panel/tab ui key stability for new cfg-based panels/tabs; eliminate query views & begin pluggin in autocompletion lister to query input 2025-01-13 11:12:59 -08:00
Nikita Smith 076aa0a8cb build fixes for parse_inline_sites 2025-01-13 10:12:15 -08:00
Ryan Fleury 8bb3e6c191 rdi_from_pdb: fix line emitting rules in inline site symbol parsing; also fix non-application of code lengths to code offsets in inline lines 2025-01-13 10:07:59 -08:00
Ryan Fleury a1e7ec5a0e rdi_from_pdb: fix line emitting rules in inline site symbol parsing; also fix non-application of code lengths to code offsets in inline lines 2025-01-13 10:06:47 -08:00
ed d42aa42ab1 Merge remote-tracking branch 'EpicGamesExt/master' 2025-01-12 17:29:22 -05:00
Ryan Fleury 6ff2693823 part 3: more progress on entity -> cfg frontend pass 2025-01-10 15:53:40 -08:00
Ryan Fleury d9ca51b36f part 2: furthered progress on cfg switch 2025-01-10 12:56:53 -08:00
Ryan Fleury 6ce8046029 part 1: new cfg data structure & caches to replace rd_entity, rd_window, rd_panel, rd_view, etc. 2025-01-09 17:31:02 -08:00
Ryan Fleury 5b7c366234 cfg data structure first pass, serialization/deserialization, & building, to prep for all rd_entity code deletion 2025-01-08 14:54:11 -08:00
Nikita Smith 30dc0340a4 print sizes in telemetry mark up in GSI build step 2025-01-08 03:26:04 -08:00
Nikita Smith 2b33978037 updated name convention for flag extract macro in CodeView layer 2025-01-08 03:26:04 -08:00
Nikita Smith 42e441541d fixes for LEB decode 2025-01-08 03:26:04 -08:00
Nikita Smith d0d1786cec define enum for image type 2025-01-08 03:26:04 -08:00
Nikita Smith 0d0a6d3980 fixed compile error in Linux entry point 2025-01-08 03:26:04 -08:00
Nikita Smith 98b9427446 dumper for Dwarf 2025-01-08 03:26:04 -08:00
Nikita Smith 543ee72f95 u64 array helper 2025-01-08 03:26:04 -08:00
Nikita Smith a5c9a1c978 u64 array sort 2025-01-08 03:26:04 -08:00
Nikita Smith b27b783e6f Dwarf parser WIP
Copied the parser from internal repo and integrated with the base layer
(not tested)

Parser uses based/range pattern for which we have an alternative in
string layer (str8_deserial_*)
2025-01-08 03:26:04 -08:00
Nikita Smith 76b742ceb8 coffdump -> raddump 2025-01-08 03:26:04 -08:00
Nikita Smith b6b64be867 moved enum handling code to separate files 2025-01-08 03:24:35 -08:00
Nikita Smith 3961f93d1a moved CodeView parser code into separate file 2025-01-08 03:24:35 -08:00
Nikita Smith be81533f63 removed coff guid and added missing defrange symbol 2025-01-08 03:24:35 -08:00
Ryan Fleury 41d4bcfe11 notes 2025-01-07 16:10:28 -08:00
Ryan Fleury 1bf66afef9 more entity code deletion 2025-01-07 15:53:22 -08:00
Ryan Fleury ee181c685b more old entity code deletion 2025-01-07 14:05:58 -08:00
Ryan Fleury 7fea55348f fix hack to stop busted animation when minimized - just bounds check the content rectangle 2025-01-07 13:30:53 -08:00
Ryan Fleury 6682613a1a entity, d -> rd convergence 2025-01-07 13:21:23 -08:00
Ryan Fleury ee9961cce4 rd: eliminate old entity code pertaining to mirroring ctrl entities - we just use ctrl entities directly now, and rd entities are just used for frontend debugger state 2025-01-07 11:49:13 -08:00
Ryan Fleury 64aa06895e eliminate code view dependence on txt/hs 2025-01-07 11:42:18 -08:00
Ryan Fleury e82041e5df 'ghost exceptions' fix - spoof hit detection needs to occur based on the demon event's reported exception address, rather than wherever the instruction pointer happens to be at the time of the exception 2025-01-07 11:04:34 -08:00
Ryan Fleury c1a2023b15 move remaining parts of frontend to xxhash, eliminate blake2; sketch out test program for debug string performance testing 2025-01-07 10:40:55 -08:00
ed 4cdff84bb0 scripts 2025-01-06 11:59:08 -05:00
Ryan Fleury 812cea7e73 actually, bad idea - turn that off for now... 2025-01-05 22:47:06 -08:00
Ryan Fleury fb1fb6b014 fix incorrect restriction of value committing in watch views; only commit value if initial value of edited text was unchanged 2025-01-05 22:46:08 -08:00
Ryan Fleury bc44f58a80 fix off-by-one size restriction in string chunk allocation; apply same fixes to ctrl entity string allocator 2025-01-05 22:39:10 -08:00
Ryan Fleury d70ce6465a fix incorrect initialization of catchall chunks in name allocator free list 2025-01-05 22:39:10 -08:00
Ryan Fleury fbc1f871cf add comment about previously introduced path heuristic - will need to be careful on linux 2025-01-04 17:07:34 -08:00
Ryan Fleury 47373fbb58 prioritize exe-relative debug paths - treat embedded pdb/rdi paths as relative to the exe first - if they are relative, then relative to the exe is the correct choice, but if they are absolute, then it will simply be an invalid path, and so it will just pick up the full absolute embedded pdb path on the next candidate. 2025-01-04 17:02:46 -08:00
Ryan Fleury 4cb6e889ef hack to avoid minimization causing bad panel animation state - will investigate this more fully later... 2024-12-30 10:09:29 -08:00
Ryan Fleury 94f0ae660f fix bytecode size calculation bug 2024-12-29 16:02:54 -08:00
Ryan Fleury be45100964 if regrel32 is marked as being outside the procedure frame, and if it has no type info, it seems that compilers generate that case to encode return variables which exist outside a procedure's frame, in which case we can make up the difference by grabbing the return type from the containing procedure type. this does not break existing valid cases, but may not be the fully correct rule. 2024-12-29 13:46:44 -08:00
Ryan Fleury aa42d12d0f zerofiy range dim, if max > min; fixes incorrect range intersection & read, in eval path 2024-12-20 09:00:17 -08:00
Ryan Fleury 49d11ea35b plug min-digits view rule into f32/f64 value string visualization path; also expand default precision of f32/f64 string visualization, but truncate redundant zeroes 2024-12-17 16:04:09 -08:00
Ryan Fleury e9ac6ccf7e remove heuristic of array view rule implicitly disabling string visualization; prefer explicit no_string view rule 2024-12-17 09:45:54 -08:00
Ryan Fleury 3023269a9c correctly use array sizes in value string string literal visualization; slices / array lengths now correctly apply to string visualization 2024-12-17 09:39:57 -08:00
Ryan Fleury 78309209ae clear completed task log 2024-12-16 13:02:37 -08:00
Ryan Fleury 5f1d0b4d1c adjust compact vs. default panel layout pick heuristic 2024-12-16 12:52:46 -08:00
Ryan Fleury 090c555d68 fix default space assumption in full eval path, if not inferred from the expression itself 2024-12-16 12:09:50 -08:00
Ryan Fleury 8f91ec4f88 fix __va_args__ nonsense in rdi_from_dwarf; fix incorrect mask check in linux os_file_open 2024-12-16 11:41:23 -08:00
Ryan Fleury c66d705791 toggle-press for theme colors in settings view, not click-to-open 2024-12-16 11:33:26 -08:00
Ryan Fleury 97241e73f9 more aggressively commit changes to meta-entity edits in watch windows; undo if cancelling 2024-12-16 11:26:08 -08:00
Ryan Fleury ac54281062 fix nccalcsize in fullscreen mode 2024-12-16 10:59:35 -08:00
Nikita Smith 2a72f525fb added support for dumping disassembly and raw data out of sections 2024-12-11 12:07:42 -08:00
Nikita Smith c91253a19e move feature flags to appropriate layer 2024-12-10 14:07:51 -08:00
Nikita Smith 48cb999c3d format VC Features and COFF Group in debug directory 2024-12-10 13:47:47 -08:00
Nikita Smith 9ff49c33cc validate export table fields 2024-12-10 13:44:09 -08:00
Nikita Smith cd3fd4df16 format file preamble and warn about unknown argument 2024-12-09 17:16:44 -08:00
Nikita Smith dd3b4a025d advance offset 2024-12-09 15:49:34 -08:00
Nikita Smith aaa82af9b3 format base relocations 2024-12-09 15:25:12 -08:00
Nikita Smith db82b2ea63 remove dependency on bin info from base reloc parser 2024-12-09 15:24:18 -08:00
Nikita Smith 723c950c01 add default params for /FUNCTIONPADMIN 2024-12-09 14:27:03 -08:00
Ryan Fleury 274b710329 notes 2024-12-09 08:35:01 -08:00
Ryan Fleury edfbcb9c85 fix incorrect line textual coordinates when triple-dragging code slices 2024-12-06 16:32:43 -08:00
Nikita Smith 08a368dd66 handle ADDR32 base relocation 2024-12-06 15:35:33 -08:00
Nikita Smith f56bc209e0 minor fix 2024-12-06 14:39:00 -08:00
Nikita Smith b5273d6a00 keep parsing on encountering epilog opcode 2024-12-06 14:00:12 -08:00
Ryan Fleury bca1325d9a eliminate machine/file entities in frontend layer 2024-12-06 13:53:25 -08:00
Ryan Fleury 87a1dd84ec delete raddbg layer duplicative ctrl entity kinds / related code; we are now fully moved onto the ctrl system for ctrl entities 2024-12-06 12:31:37 -08:00
Ryan Fleury 751626446a pending thread names in ctrl entity system, for cases where a thread name is established before the thread is reported as being created, and the id is used to correllate 2024-12-06 12:31:37 -08:00
Ryan Fleury 59e2d7de61 eliminate old universal entity ui; eliminate old stop explanation string generation path 2024-12-06 12:31:37 -08:00
Nikita Smith 6cf42338ba clang build fixes 2024-12-06 12:05:44 -08:00
Nikita Smith e73ce59945 WIP coffdump 2024-12-06 11:53:16 -08:00
Nikita Smith c3831e4350 WIP parser for MSVC C++ exceptions unwind info 2024-12-06 11:53:16 -08:00
Nikita Smith 0ea0820d19 minor fixes and cleanups 2024-12-06 11:53:16 -08:00
Nikita Smith 86db833a83 pass over PE
* upgraded PE with parsers for imports, exports, and tls
* added struct definitions for image load config and debug dir structs
2024-12-06 11:53:16 -08:00
Nikita Smith 80fa226432 pass over COFF archive parser 2024-12-06 11:53:16 -08:00
Nikita Smith 29de0c5a9e moved unsigned range list to base math 2024-12-06 11:53:16 -08:00
Nikita Smith d73e53a5b5 integer array structs 2024-12-06 11:53:16 -08:00
Nikita Smith 3851604705 32bit integer from ascii helpers 2024-12-06 11:53:16 -08:00
Nikita Smith 2bf3194cff disable .exp for radlink 2024-12-06 11:53:16 -08:00
Nikita Smith 669c03cff1 rename time -> time_stamp 2024-12-06 11:53:16 -08:00
Nikita Smith e22bd33275 pass over COFF, added symbol for function definitions, updated names
and types in structs, added enum to and from string helpers
2024-12-06 11:53:16 -08:00
Nikita Smith 53a5f6ab06 big-endian conversion helpers 2024-12-06 11:53:16 -08:00
Nikita Smith 746a2728b3 date time from unix time stamp 2024-12-06 11:53:16 -08:00
Nikita Smith 9ad63e45e6 u32 from string version 2024-12-06 11:53:16 -08:00
Nikita Smith 47ac1796a9 use build string literal from base context 2024-12-06 11:53:16 -08:00
Nikita Smith fc429449cf fix out of bounds check 2024-12-06 11:53:16 -08:00
Ryan Fleury cd64657746 adjust disasm snapping rules, to not open disasm in cases where we can infer user doesn't have/want it open, and also to snap correctly if we can infer that the user is actively viewing/using disasm 2024-12-06 10:27:37 -08:00
Ryan Fleury 347ce2281d clear breakpoint hit counts on restart command 2024-12-04 13:40:20 -08:00
Ryan Fleury 09cf0fb348 introduce manual clearing path in font cache layer; use to prevent permanent accumulation of font glyphs even after font resizes etc. 2024-12-04 13:34:00 -08:00
Ryan Fleury 94c4000603 adjust failure cases in conversion; adjust waiting time period in pre-emptive heuristic conversion rule; avoid bp resolution path & waiting on debug info when unnecessary 2024-12-03 11:32:57 -08:00
Ryan Fleury aee2d510d4 fix blur 2024-12-02 15:19:29 -08:00
Ryan Fleury 74004321aa adjust auto-focus-on-stop rules; only do it given stops caused by threads 2024-12-02 10:01:58 -08:00
Ryan Fleury a827c74501 adjust thread-selection-on-stop & thread-snapping rules, to prevent useless disasm snaps & incorrect thread selections in some edge cases 2024-12-02 09:44:50 -08:00
alektron 0c86580e1e Further simplify WM_NCCALCSIZE handling; 2024-12-01 08:21:58 -08:00
alektron b4cbaa0171 Simplify borderless window code and improve resizing behavior and style (e.g. dropshadow); 2024-12-01 08:21:58 -08:00
Nikita Smith 19fac9b1aa changed symbol table parser to convert symbols as they are being read 2024-11-21 19:42:39 -08:00
Nikita Smith a0dbe72820 moved common codeview code to the main layer 2024-11-21 15:58:32 -08:00
Nikita Smith 7ac7bea420 minor fixes 2024-11-21 15:58:32 -08:00
Nikita Smith fbf180df2f assert when merging associative chunks 2024-11-21 13:30:13 -08:00
Nikita Smith 8e8924fcc6 minor fixes 2024-11-21 13:29:23 -08:00
Nikita Smith d9d0618e97 helpers for quickly checking presence of symbols and file paths in PDB 2024-11-21 01:05:33 -08:00
Nikita Smith a87e2745a4 GSI and String Table helpers 2024-11-21 01:05:33 -08:00
Nikita Smith bdb41aa040 fix off by one in GSI parser 2024-11-21 01:05:33 -08:00
Nikita Smith 714316aebf factor out stream table out of MSF parser 2024-11-21 01:05:33 -08:00
Nikita Smith c037d6ad75 WIP function padding 2024-11-21 01:05:33 -08:00
Ryan Fleury d8279c1ff3 clean up per-build natvis integration into build.bat 2024-11-20 19:41:27 -08:00
Ryan Fleury f15a4f17d1 worker thread parameterization; sketch out wide-conversion scratch program; fix one common crash case in some pdb conversions 2024-11-20 15:36:13 -08:00
Ryan Fleury adbd7fbc97 fix is-zoomed behavior in nccalcsize 2024-11-20 10:44:54 -08:00
Ryan Fleury cb4232469e adjust nccalcsize window message; we just need to coax windows into doing the copy in order to avoid resize artifacts. still not perfect, can get into a weird state, and we may need to do more full size calculation in some cases 2024-11-19 16:59:20 -08:00
Ryan Fleury a40c26a0eb fix incorrect singly-linked-list/doubly-linked-list mismatch in dbgi search cache 2024-11-19 10:41:22 -08:00
Nikita Smith 816d8e88bf remove warning pragma around radsort 2024-11-18 16:26:42 -08:00
Ryan Fleury 9eb482b17b fix old include sites of xxhash 2024-11-18 16:19:04 -08:00
Nikita Smith 31f536334e third party include fixups 2024-11-18 16:17:26 -08:00
Nikita Smith f0a1deec62 merge third party folders 2024-11-18 16:16:15 -08:00
Nikita Smith af57e321de show full lib path for better debuggability 2024-11-18 15:38:00 -08:00
Nikita Smith e44dd3aa07 instead of searching for manifest tool manually punt the job to CreateProcess 2024-11-18 15:38:00 -08:00
Nikita Smith 938be0aa84 changed string conversion routines to return null on null input
In os_process_launch on windows, linker relies on directory string conversion
to return null so CreateProcessW can set work directory itself.
2024-11-18 15:38:00 -08:00
Ryan Fleury 33c4c7c883 fix false positive file ood rule 2024-11-18 13:54:57 -08:00
Ryan Fleury cb5f9a2e06 robustify search item usage code to changed sets of dbgis 2024-11-18 11:42:43 -08:00
Ryan Fleury 846cfd259c fix incorrect search joining logic, in cases where a key has been evicted 2024-11-18 10:24:02 -08:00
Ryan Fleury 32cfe28094 exclusively lock search stripe when taking task & bumping work refcount 2024-11-18 09:58:34 -08:00
546 changed files with 149917 additions and 98077 deletions

No files matched your search

+30 -10
View File
@@ -13,6 +13,17 @@ jobs:
runs-on: windows-2022 runs-on: windows-2022
strategy: strategy:
fail-fast: false fail-fast: false
matrix:
target:
- raddbg
- radlink
- radbin
compiler:
- msvc
- clang
mode:
- debug
- release
steps: steps:
- name: checkout - name: checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
@@ -20,13 +31,22 @@ jobs:
shell: cmd shell: cmd
run: | run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64 call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
call build raddbg msvc debug || exit /b 1 call build "${{ matrix.target }}" "${{ matrix.compiler }}" "${{ matrix.mode }}" || exit /b 1
call build rdi_from_pdb msvc debug || exit /b 1
call build rdi_from_dwarf msvc debug || exit /b 1 run-torture:
call build rdi_dump msvc debug || exit /b 1 runs-on: windows-2022
call build raddbg clang debug || exit /b 1 steps:
call build rdi_from_pdb clang debug || exit /b 1 # - name: Install ASAN
call build rdi_from_dwarf clang debug || exit /b 1 # shell: cmd
call build rdi_dump clang debug || exit /b 1 # run: |
call build radlink msvc debug || exit /b 1 # "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe" modify --installPath "C:\Program Files\Microsoft Visual Studio\2022\Enterprise" --quiet --force --norestart --add Microsoft.VisualStudio.Component.VC.ASAN
call build radlink clang debug || exit /b 1 - name: checkout
uses: actions/checkout@v2
- name: run-torture
shell: cmd
run: |
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
call build radlink asan debug no_meta || exit /b 1
call build torture debug no_meta || exit /b 1
cd build
torture -l:radlink || exit /b 1
+1
View File
@@ -1,3 +1,4 @@
/build/ /build/
/local/ /local/
*~ *~
.vscode/settings.json
+137
View File
@@ -0,0 +1,137 @@
# v0.9.24-alpha
## Debugger Changes
- Added the ability for the debugger to load, use, and evaluate using debug
info, even when not actively debugging. The debugger will now keep a process'
debug info loaded, even after the process ends. It stores the set of loaded
debug info files in the project configuration file, meaning it will also
automatically load the same debug info across many runs. Debug info can also
be loaded manually (without ever launching a process) with the
`Load Debug Info` command. There is also a new tab, `Debug Info`, which allows
viewing and managing the set of loaded debug info files.
- Improved the debugger's behavior when used as a drag & drop target, to allow
for debug info loading as an option (when relevant), and to better handle the
case where many files (potentially of different types) are dropped together.
- Improved debug info searching performance and reponsiveness in large projects.
- Fixed some crashes and incorrect results with the new `list` view.
- Fixed some cases where RDIs did not contain some basic types from their
originating PDBs.
- Allowed `.` and `->` operators to be used with array types.
- Fixed the debugger's treatment of quoted command line arguments when building
targets. In previous versions, calling `raddbg main.exe "foo bar baz"` would
create a target `main.exe` with arguments `foo bar baz` (dropping the quotes).
This is now fixed, such that the target's arguments string will also contain
the quotes, and pass them to the target when launched.
- Fixed the debugger not correctly responding (through font and UI scale) to DPI
changes.
- Fixed the debugger incorrectly generating conflicting source line info records
in PDB -> RDI conversion, which in some scenarios was preventing source line
maps from working (leading to breakpoint resolution failing).
- Other small fixes, improvements, and tweaks.
# v0.9.23-alpha
## Debugger Changes
- Further improved PDB -> RDI conversion performance & memory usage.
- Adjusted limits for the amount of PDB -> RDI conversion work that the
debugger will kick off, to prevent PDB -> RDI conversion interfering with
debuggee performance.
- Reintroduced the `list` lens, which gathers all nodes in a linked list, and
visualizes them as a flat list of pointers (the same as how an array of
pointers is visualized).
- Fixed a crash when closing empty Geometry 3D views. (#652, #657)
- Fixed the debugger not visualizing `enum` types when evaluated through a
bitfield type. (#655)
- Fixed the PDB -> RDI conversion not correctly generating location information
for function parameters, when the EXE/PDB were built to include support for
Edit and Continue (`-ZI` switch). (#656)
## Binary Utility Changes
- Fixed a crash when using the `--compress` option, when generating RDI files.
# v0.9.22-alpha
## Debugger Changes
- Further improved PDB -> RDI conversion performance.
- Capped the number of additional threads / processes spawned for PDB -> RDI
conversion.
- Prioritize PDB -> RDI conversion based on what is actually found to be
necessary by the debugger, rather than converting all PDBs in the order in
which they're discovered.
- Added preliminary support for DWARF -> RDI conversion on Windows.
- The debugger now relies on source file checksums to determine whether or not
a source file is out-of-date with respect to what was compiled when debug info
was produced, rather than just the modification timestamp.
- The debugger now will rely on debug info to detect the language of source code
files, if it cannot infer from the source file's extension, or view settings.
This will enable features like syntax highlighting and hover evaluation in
cases like `.inl` files being included in C++ projects.
- The debugger now will restore the last focused window when continuing
automatically. (#245, #596)
- Watch tables have been simplified in that they no longer have a separate
column for evaluation types, since this was usually taking a lot more space
than it deserved. The type of evaluations is still displayed in watch table
cells, and it can always be evaluated directly via `typeof`.
- Type evaluations have been simplified in watch tables as well; they no longer
have untitled columns for sizes and offsets, this is instead displayed as
an extra note by default. Similar behavior to the original behavior can still
be obtained using the `columns` view, if needed.
- The debugger no longer uses complex `union` types for most registers, and
instead just displays the register value plainly.
- The hover evaluation UI has been made larger when needed.
- The debugger now prefers matching global, function, and type identifiers to
the most relevant debug info and module in context; this fixes evaluation in
some multi-process debugging contexts. (#581)
- Fixed the debugger unnecessarily stripping `enum` type information when
accessed through array operators. (#634)
- The debugger now understands a standalone `unsigned` keyword as an
`unsigned int` type, to match C rules.
- The debugger now uses the current working directory to form the working
directory for targets specified on the command line, to match behavior when
running a command from the command line without the debugger.
- Improved call stack computation performance.
- Improved debugger memory usage over long periods of time.
- Fixed string-pointer comparison not working with not-equal (`!=`) operations.
- Fixed a bug which was causing bad debuggee performance on some threads after
some interactions with the debugger controller.
- Fixed incorrect results when adding two register values. (#642)
- Fixed the interpretation of register expressions in visualizers. (#649)
- Fixed "forever loading" states in disassembly views in some cases. (#643)
- Fixed jittering on window resizing. (#636)
- Fixed the bitmap visualizer crashing in some circumstances relating to
unsupported bitmap sizes. (#444, #563)
- Fixed a crash when an empty `cast()` expression would be evaluated. (#625)
- Fixed a crash when an invalid expression would be visualized using the `text`
view. (#647)
## Linker Changes
- Changed symbol resolution in libaries to match MSVC behavior.
- Optimized image building step to reduce memory usage.
- Linker memory maps all input files by default to lower memory usage.
(`/RAD_MEMORY_MAP_FILES`)
- If debug info is available, linker uses it to show file and line number for
unresolved relocations.
- Improved base relocation build performance for large images, cutting build
time by 70%.
- Added stubs for `/Brepro`, `/D2`, and /ErrorReport to improve compatability
with existing response files
- Implemented section garbage collection (`/OPT:REF`)
- Fixed bug where thread local variables pointed to incorrect types.
- Changed rules for weak and undefined symbols, now weak symbol is not allowed
to replace an undefined symbol.
- Linker no longer creates thunks for imports that don't require them.
## Binary Utility Changes
- The binary utility, like the debugger, now can convert DWARF debug info to
RDI files. When both DWARF and PDB info is present, it can now convert both,
and produce a single final RDI file with all information.
- Textual dumping of RDI files is now done in parallel, massively improving
dumping performance.
- PDB -> Breakpad conversion performance has now been parallelized to a greater
degree, improving performance.
+1 -1
View File
@@ -1,4 +1,4 @@
Copyright (c) 2024 Epic Games Tools Copyright (c) Epic Games Tools
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in this software and associated documentation files (the “Software”), to deal in
+189 -153
View File
@@ -1,45 +1,93 @@
# The RAD Debugger Project # The RAD Debugger Project
_**Note:** This README does not document usage instructions and tips for the _**NOTE:** This README does not document usage instructions and tips for the
debugger itself, and is intended as a technical overview of the project. The debugger itself, and is intended as a technical overview of the project. The
debugger's README, which includes usage instructions and tips, can be found debugger's README, which includes usage instructions and tips, can be found
packaged along with debugger releases, or within the `build` folder after a packaged along with debugger releases, or within the `build` folder after a
local copy has been built._ local copy has been built. You can find pre-built release binaries
[here](https://github.com/EpicGamesExt/raddebugger/releases)._
The RAD Debugger is a native, user-mode, multi-process, graphical debugger. It The RAD Debugger is a native, user-mode, multi-process, graphical debugger. It
currently only supports local-machine Windows x64 debugging with PDBs, with currently only supports local-machine Windows x64 debugging with PDBs, with
plans to expand and port in the future. In the future we'll expand to also plans to expand and port in the future. In the future we'll expand to also
support native Linux debugging and DWARF debug info. support native Linux debugging and DWARF debug info.
The RAD Debugger is currently in *ALPHA*. In order to get the debugger bullet- The debugger is currently in *ALPHA*. In order to get the debugger
proof, it'd greatly help out if you submitted the issues you find here, along bullet-proof, it'd greatly help out if you submitted the issues you find
with any information you can gather, like dump files (along with the build you [here](https://github.com/EpicGamesExt/raddebugger/issues), along with any
used), instructions to reproduce, test executables, and so on. information you can gather, like dump files (along with the build you used),
instructions to reproduce, test executables, and so on.
You can download pre-built binaries for the debugger In addition to the debugger, we aim to further improve the toolchain with two
[here](https://github.com/EpicGamesExt/raddebugger/releases). additional related technologies: **(1)** the RAD Debug Info (RDI) format, and
**(2)** the RAD Linker.
The RAD Debugger project aims to simplify the debugger by simplifying and ## The RAD Debug Info (RDI) Format
unifying the underlying debug info format. In that pursuit we've built the RAD
Debug Info (RDI) format, which is what the debugger parses and uses. To work The RAD Debug Info (RDI) format is our custom debug information format, which
with existing toolchains, we convert PDB (and eventually PE/ELF files with the debugger parses and uses, rather than the debug information natively
embedded DWARF) into the RDI format on-demand. produced by toolchains, like PDB or DWARF. To work with these existing
toolchains, we convert PDB (and eventually PE/ELF files with embedded DWARF)
into the RDI format on-demand.
The RDI format is currently specified in code, in the files within the The RDI format is currently specified in code, in the files within the
`src/lib_rdi_format` folder. The other relevant folders for working with the `src/lib_rdi` folder. In [`rdi.h`](src/lib_rdi/rdi.h) and
format are: [`rdi.c`](src/lib_rdi/rdi.c), the types and functions which define the format
itself are specified. In [`rdi_parse.h`](src/lib_rdi/rdi_parse.h) and
[`rdi_parse.c`](src/lib_rdi/rdi_parse.c), helpers for parsing the format are
included.
- `lib_rdi_make`: The "RAD Debug Info Make" library, for making RDI debug info. We also have an in-progress library for constructing and serializing RDI data,
- `rdi_from_pdb`: Our PDB-to-RDI converter. Can be used as a helper codebase located within the `src/lib_rdi_make` folder.
layer, or built as an executable with a command line interface frontend.
- `rdi_from_dwarf`: Our in-progress DWARF-to-RDI converter.
- `rdi_dump`: Our RDI textual dumping utility.
## Development Setup Instructions Our `radbin` utility (accessible through the debugger too, via the `--bin`
command line argument) is capable of converting native debug information formats
to RDI, and of producing textual dumps of contents stored within RDI files.
**Note: Currently, only x64 Windows development is supported.** ## The RAD Linker
### 1. Installing the Required Tools (MSVC & Windows SDK) 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) natively create
RAD Debug Info too, which is useful both to eliminate on-demand conversion time
when debugging, but also 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; 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
link-time-optimizations, but this feature is on the road map.
By default, the 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.
A benchmark of the linker's performance is below:
![AMD Ryzen Threadripper PRO 3995WX 64-Cores, 256 GiB RAM (Windows x64)](https://github.com/user-attachments/assets/a95b382a-76b4-4a4c-b809-b61fe25e667a)
---
# Project Development Setup Instructions
**NOTE: Currently, only x64 Windows development is supported for the project.**
## 1. Installing the Required Tools (MSVC & Windows SDK)
In order to work with the codebase, you'll need the [Microsoft C/C++ Build Tools In order to work with the codebase, you'll need the [Microsoft C/C++ Build Tools
v15 (2017) or later](https://aka.ms/vs/17/release/vs_BuildTools.exe), for both v15 (2017) or later](https://aka.ms/vs/17/release/vs_BuildTools.exe), for both
@@ -48,7 +96,7 @@ the Windows SDK and the MSVC compiler and linker.
If the Windows SDK is installed (e.g. via installation of the Microsoft C/C++ If the Windows SDK is installed (e.g. via installation of the Microsoft C/C++
Build Tools), you may also build with [Clang](https://releases.llvm.org/). Build Tools), you may also build with [Clang](https://releases.llvm.org/).
### 2. Build Environment Setup ## 2. Build Environment Setup
Building the codebase can be done in a terminal which is equipped with the Building the codebase can be done in a terminal which is equipped with the
ability to call either MSVC or Clang from command line. ability to call either MSVC or Clang from command line.
@@ -90,10 +138,11 @@ You should see the following output:
``` ```
[debug mode] [debug mode]
[msvc compile] [msvc compile]
[default mode, assuming `raddbg` build]
metagen_main.c metagen_main.c
searching C:\devel\raddebugger/src... 309 files found searching C:\devel\raddebugger/src... 458 files found
parsing metadesk... 15 metadesk files parsed parsing metadesk... 16 metadesk files parsed
gathering tables... 96 tables found gathering tables... 97 tables found
generating layer code... generating layer code...
raddbg_main.c raddbg_main.c
``` ```
@@ -101,23 +150,53 @@ raddbg_main.c
If everything worked correctly, there will be a `build` folder in the root If everything worked correctly, there will be a `build` folder in the root
level of the codebase, and it will contain a freshly-built `raddbg.exe`. level of the codebase, and it will contain a freshly-built `raddbg.exe`.
## Short-To-Medium-Term Roadmap This `raddbg.exe` will have been built in **debug mode**, which is not built
with optimizations, and may perform worse. To produce a
**release mode executable**, run `build.bat` with a `release` argument:
```
build release
```
This build will take significantly longer.
By default, `build.bat` only builds the debugger if no arguments (or just
`release`) are passed, but additional arguments can be passed to build the RAD
Linker, or the `radbin` CLI binary file utility:
```
build radlink release
build radbin release
```
---
# Project Roadmap
### The Initial Alpha Battle-Testing Phase ### The Initial Alpha Battle-Testing Phase
The first priority for the project is to ensure that the most crucial debugger The first priority for the project is to ensure that the most crucial components
components are functioning extremely reliably for local, x64, Windows are functioning extremely reliably for local, x64, Windows development.
debugging. This would include parts like debug info conversion, debug info For the debugger, this would include parts like debug info conversion, debug
loading, process control, stepping, evaluation (correct usage of both location info loading, process control, stepping, evaluation (correct usage of both
info and type info), and a robust frontend which ensures the lower level parts location info and type info), and a robust frontend which ensures the lower
are usable. level parts are usable. For the linker, this is a matter of reliability and
convergence with existing linker behavior.
We feel that the debugger has already come a long way in all of these respects, We feel that we've already come a long way in all of these respects, but given
but given the massive set of possible combinations of languages, build the massive set of possible combinations of languages, build settings,
settings, toolchains, used language features, and patterns of generated code, toolchains, used language features, and patterns of generated code, we still
there are still cases where the debugger has not been tested, and so there are expect some issues, and are prioritizing these issues being resolved first.
still issues. So, we feel that the top priority is eliminating these issues,
such that the debugging experience is rock solid. We also hope to continue to improve performance in this phase. For the debugger,
this primarily includes frontend performance, introducing caches when economical
to do so, and tightening existing systems up. For the linker, it has been mostly
tuned thus far for giant projects, and so we'd like to improve linking speed for
small-to-mid sized projects as well.
For the linker, there are also a number of features to come, like
dead-code-elimination (`/opt:ref`), and link-time-optimizations with the help
of `clang` (we won't support LTCG from MSVC, since it is undocumented).
### Local x64 Linux Debugging Phase ### Local x64 Linux Debugging Phase
@@ -160,42 +239,7 @@ But for now, we're mostly focused on those first two phases.
--- ---
# The RAD Linker # Codebase Introduction
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
@@ -210,7 +254,7 @@ also exist:
- `local`: Local files, used for local build configuration input files. Not - `local`: Local files, used for local build configuration input files. Not
checked in to version control. checked in to version control.
## Codebase Introduction ## Layer Descriptions
The codebase is organized into *layers*. Layers are separated either to isolate The codebase is organized into *layers*. Layers are separated either to isolate
certain problems, and to allow inclusion into various builds without needing to certain problems, and to allow inclusion into various builds without needing to
@@ -238,86 +282,85 @@ so in other words, layers are arranged into a directed acyclic graph.
A few layers are built to be used completely independently from the rest of the A few layers are built to be used completely independently from the rest of the
codebase, as libraries in other codebases and projects. As such, these layers do codebase, as libraries in other codebases and projects. As such, these layers do
not depend on any other layers in the codebase. The folders which contain these 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`.
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 - `artifact_cache` (`AC_`): Implements an asynchronously-filled cache of
and executed on a thread pool. computation artifacts, which are automatically evicted when not accessed. Used
for asynchronously streaming and caching process memory and file system
contents, as well as asynchronously preparing visualizer data.
- `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. Requires
on no other codebase layers. no other codebase layers.
- `codeview` (`CV_`): Code for parsing and/or writing the CodeView format. - `codeview` (`CV_`): Code for parsing and writing the CodeView format.
- `coff` (`COFF_`): Code for parsing and/or writing the COFF (Common Object File - `coff` (`COFF_`): Code for parsing and writing the COFF (Common Object File
Format) file format. Format) file format.
- `content` (`C_`): Implements a cache for general data blobs, keyed by a
128-bit hash of the data. Also implements a keying system on top, where keys
refer to a unique identity which corresponds to a history of 128-bit hashes.
Used as a general data store by other layers.
- `ctrl` (`CTRL_`): The debugger's "control system" layer. Implements - `ctrl` (`CTRL_`): The debugger's "control system" layer. Implements
asynchronous process control, stepping, and breakpoints for all attached asynchronous process control, stepping, and breakpoints for all attached
processes. Runs in lockstep with attached processes. When it runs, attached processes. Runs in lockstep with attached processes. When it runs, attached
processes are halted. When attached processes are running, it is halted. processes are halted. When attached processes are running, it is halted.
Driven by a debugger frontend on another thread. Driven by a debugger frontend on another thread.
- `dasm_cache` (`DASM_`): An asynchronous disassembly decoder and cache. Users
ask for disassembly for some data, with a particular architecture, and other
various parameters, and threads implemented in this layer decode and cache the
disassembly for that data with those parameters.
- `dbgi` (`DI_`): An asynchronous debug info loader and cache. Loads debug info
stored in the RDI format. Users ask for debug info for a particular path, and
on separate threads, this layer loads the associated debug info file. If
necessary, it will launch a separate conversion process to convert original
debug info into the RDI format.
- `dbg_engine` (`D_`): Implements the core debugger system, without any - `dbg_engine` (`D_`): Implements the core debugger system, without any
graphical components. This contains top-level logic for things like stepping, graphical components. This contains top-level logic for things like stepping,
launching, freezing threads, mid-run breakpoint addition, some caching layers, launching, freezing threads, mid-run breakpoint addition, some caches, and so
and so on. on.
- `dbg_info` (`DI_`): Implements asynchronous debug info conversion and loading.
Maintains a cache for loaded debug info. Loads RAD Debug Info (RDI) files.
Launches separate processes for on-demand conversion to the RDI format if
necessary. Also provides various asynchronous operations for using debug info,
like fuzzy searching across all records in loaded debug info.
- `demon` (`DMN_`): An abstraction layer for local-machine, low-level process - `demon` (`DMN_`): An abstraction layer for local-machine, low-level process
control. The abstraction is used to provide a common interface for process control. The abstraction is used to provide a common interface for process
control on target platforms. Used to implement part of `ctrl`. control on target platforms. Used to implement part of `ctrl`.
- `disasm` (`DASM_`): Implements disassembly generation, including exposing the
ability to compute and cache disassembly asynchronously.
- `draw` (`DR_`): Implements a high-level graphics drawing API for the - `draw` (`DR_`): Implements a high-level graphics drawing API for the
debugger's purposes, using the underlying `render` abstraction layer. Provides debugger's purposes, using the underlying `render` abstraction layer. Provides
high-level APIs for various draw commands, but takes care of batching them, high-level APIs for various draw commands, but takes care of batching them,
and so on. and so on.
- `eval` (`E_`): Implements a compiler for an expression language built for - `dwarf` (`DW_`): Code for parsing the DWARF format.
evaluation of variables, registers, types, and more, from debugger-attached - `eh` (`EH_`): Code for parsing the EH frame format.
processes, debug info, debugger state, and files. Broken into several phases - `elf` (`ELF_`): Code for parsing the ELF format.
mostly corresponding to traditional compiler phases - lexer, parser, - `eval` (`E_`): A compiler for an expression language, built for evaluation of
type-checker, IR generation, and IR evaluation. variables, registers, types, and more, from debugger-attached processes,
debug info, debugger state, and files. Broken into several phases mostly
corresponding to traditional compiler phases: lexer, parser, type-checker, IR
generation, and IR evaluation.
- `eval_visualization` (`EV_`): Implements the core non-graphical evaluation - `eval_visualization` (`EV_`): Implements the core non-graphical evaluation
visualization engine, which can be used to visualize evaluations (provided by visualization engine, which can be used to visualize evaluations (provided by
the `eval` layer) in a number of ways. Implements core data structures and the `eval` layer) in a number of ways. Implements core data structures and
transforms for the `Watch` view. transforms for watch tables.
- `file_stream` (`FS_`): Provides asynchronous file loading, storing the - `file_stream` (`FS_`): Implements asynchronous file streaming, storing the
artifacts inside of the cache implemented by the `hash_store` layer, and artifacts inside of the cache implemented by the `content` and
hot-reloading the contents of files when they change. Allows callers to map `artifact_cache` layers, hot-reloading the contents of files when they change.
file paths to data hashes, which can then be used to obtain the file's data. Allows callers to map file paths to data hashes, which can then be used to
obtain the file's data.
- `font_cache` (`FNT_`): Implements a cache of rasterized font data, both in - `font_cache` (`FNT_`): Implements a cache of rasterized font data, both in
CPU-side data for text shaping, and in GPU texture atlases for rasterized CPU-side data for text shaping, and in GPU texture atlases for rasterized
glyphs. All cache information is sourced from the `font_provider` abstraction glyphs. All cache information is sourced from the `font_provider` abstraction
layer. layer.
- `font_provider` (`FP_`): An abstraction layer for various font file decoding - `font_provider` (`FP_`): An abstraction layer for various font file decoding
and font rasterization backends. and font rasterization backends.
- `fuzzy_search` (`FZY_`): Provides a fuzzy searching engine for doing
large, asynchronous fuzzy searches. Used by the debugger for implementing
things like the symbol lister or the `Procedures` view, which search across
all loaded debug info records, using fuzzy matching rules.
- `geo_cache` (`GEO_`): Implements an asynchronously-filled cache for GPU
geometry data, filled by data sourced in the `hash_store` layer's cache. Used
for asynchronously preparing data for visualization.
- `hash_store` (`HS_`): Implements a cache for general data blobs, keyed by a
128-bit hash of the data. Also implements a 128-bit key cache on top, where
the keys refer to a unique identity, associated with a 128-bit hash, where the
hash may change across time. Used as a general data store by other layers.
- `lib_raddbg_markup` (`RADDBG_`): Standalone library for marking up user - `lib_raddbg_markup` (`RADDBG_`): Standalone library for marking up user
programs to work with various features in the debugger. Does not depend on programs to work with various features in the debugger. Does not depend on
`base`, and can be independently relocated to other codebases. `base`, and can be independently relocated to other codebases.
- `lib_rdi_format` (`RDI_`): Standalone library which defines the core RDI types - `lib_rdi` (`RDI_`): Standalone library which defines the core RDI types
and helper functions for reading and writing the RDI debug info file format. and helper functions for reading and writing the RDI debug info file format.
Does not depend on `base`, and can be independently relocated to other Does not depend on `base`, and can be independently relocated to other
codebases. codebases.
- `lib_rdi_make` (`RDIM_`): Standalone library for constructing RDI debug info - `lib_rdi_make` (`RDIM_`): Standalone library for constructing RDI debug info
data. Does not depend on `base`, and can be independently relocated data. Does not depend on `base`, and can be independently relocated
to other codebases. to other codebases.
- `linker` (`LNK_`): The layer which implements the RAD Linker executable
itself.
- `mdesk` (`MD_`): Code for parsing Metadesk files (stored as `.mdesk`), which - `mdesk` (`MD_`): Code for parsing Metadesk files (stored as `.mdesk`), which
is the JSON-like (technically a JSON superset) text format used for the is the JSON-like (technically a JSON superset) text format used for the
debugger's user and project configuration files, view rules, and metacode, debugger's user and project configuration files and metacode, which is parsed
which is parsed and used to generate code with the `metagen` layer. and used to generate code with the `metagen` layer.
- `metagen` (`MG_`): A metaprogram which is used to generate primarily code and - `metagen` (`MG_`): A metaprogram which is used to generate primarily code and
data tables. Consumes Metadesk files, stored with the extension `.mdesk`, and data tables. Consumes Metadesk files, stored with the extension `.mdesk`, and
generates C code which is then included by hand-written C code. Currently, it generates C code which is then included by hand-written C code. Currently, it
@@ -326,18 +369,13 @@ A list of the layers in the codebase and their associated namespaces is below:
tables, which are then used to produce e.g. C `enum`s and a number of tables, which are then used to produce e.g. C `enum`s and a number of
associated data tables. There are also a number of other generation features, associated data tables. There are also a number of other generation features,
like embedding binary files or complex multi-line strings into source code. like embedding binary files or complex multi-line strings into source code.
This layer cannot depend on any other layer in the codebase directly, - `msf` (`MSF_`): Code for parsing and writing the MSF file format.
including `base`, because it may be used to generate code for those layers. To - `msvc_crt` (`MSCRT_`): Code for parsing that's specific to the MSVC CRT.
still use `base` and `os` layer features in the `metagen` program, a separate,
duplicate version of `base` and `os` are included in this layer. They are
updated manually, as needed. This is to ensure the stability of the
metaprogram.
- `msf` (`MSF_`): Code for parsing and/or writing the MSF file format.
- `mule` (no namespace): Test executables for battle testing debugger - `mule` (no namespace): Test executables for battle testing debugger
functionality. functionality.
- `mutable_text` (`MTX_`): Implements an asynchronously-filled-and-mutated - `mutable_text` (`MTX_`): Implements an asynchronously-filled-and-mutated
cache for text buffers which are mutated across time. In the debugger, this is cache for text buffers which are mutated across time. In the debugger, this is
used to implement the `Output` view. used to implement the `Output` log.
- `natvis` (no namespace): NatVis files for type visualization of the codebase's - `natvis` (no namespace): NatVis files for type visualization of the codebase's
types in other debuggers. types in other debuggers.
- `os/core` (`OS_`): An abstraction layer providing core, non-graphical - `os/core` (`OS_`): An abstraction layer providing core, non-graphical
@@ -346,26 +384,27 @@ A list of the layers in the codebase and their associated namespaces is below:
- `os/gfx` (`OS_`): An abstraction layer, building on `os/core`, providing - `os/gfx` (`OS_`): An abstraction layer, building on `os/core`, providing
graphical operating system features under an abstract API, which is graphical operating system features under an abstract API, which is
implemented per-target-operating-system. implemented per-target-operating-system.
- `path` (`PATH_`): Small helpers for manipulating file path strings. - `pdb` (`PDB_`): Code for parsing and writing the PDB file format.
- `pdb` (`PDB_`): Code for parsing and/or writing the PDB file format. - `pe` (`PE_`): Code for parsing and writing the PE (Portable Executable) file
- `pe` (`PE_`): Code for parsing and/or writing the PE (Portable Executable) format.
file format. - `radbin` (`RB_`): The layer implementing the `radbin` binary utility
executable.
- `raddbg` (`RD_`): The layer which ties everything together for the main - `raddbg` (`RD_`): The layer which ties everything together for the main
graphical debugger. Implements the debugger's graphical frontend, all of the graphical debugger executable. Implements the debugger's graphical frontend,
debugger-specific UI, the debugger executable's command line interface, and all of the debugger-specific UI, the debugger executable's command line
all of the built-in visualizers. interface, and all of the built-in visualizers.
- `rdi_breakpad_from_pdb` (`P2B_`): Our implementation, using the codebase's RDI - `rdi` (`RDI_`): A layer which includes the `lib_rdi` layer and bundles it with
technology, for extracting information from PDBs and generating Breakpad text codebase-specific helpers, to easily include the library in codebase programs,
dumps. and have it be integrated with codebase constructs.
- `rdi_dump` (no namespace): A dumper utility program for dumping - `rdi_from_coff` (`C2R_`): Code for converting information in COFF files to the
textualizations of RDI debug info files. equivalent RDI data.
- `rdi_format` (no namespace): A layer which includes the `lib_rdi_format` layer - `rdi_from_dwarf` (`D2R_`): In-progress code for converting DWARF to the
and bundles it with codebase-specific helpers, to easily include the library equivalent RDI data.
in codebase programs, and have it be integrated with codebase constructs. - `rdi_from_elf` (`E2R_`)): Code for converting ELF data to the equivalent RDI
- `rdi_from_dwarf` (`D2R_`): Our in-progress implementation of DWARF-to-RDI data.
conversion. - `rdi_from_pdb` (`P2R_`): Code for converting PDB data to the equivalent RDI
- `rdi_from_pdb` (`P2R_`): Our implementation of PDB-to-RDI conversion. data.
- `rdi_make` (no namespace): A layer which includes the `lib_rdi_make` layer and - `rdi_make` (`RDIM_`): A layer which includes the `lib_rdi_make` layer and
bundles it with codebase-specific helpers, to easily include the library in bundles it with codebase-specific helpers, to easily include the library in
codebase programs, and have it be integrated with codebase constructs. codebase programs, and have it be integrated with codebase constructs.
- `regs` (`REGS_`): Types, helper functions, and metadata for registers on - `regs` (`REGS_`): Types, helper functions, and metadata for registers on
@@ -377,13 +416,10 @@ 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.
- `texture_cache` (`TEX_`): Implements an asynchronously-filled cache for GPU - `tester` (no namespace): A program used for automated testing.
texture data, filled by data sourced in the `hash_store` layer's cache. Used - `text` (`TXT_`): Implements text processing functions, like parsing line
for asynchronously preparing data for visualization. breaks, and lexing and parsing source code. Also offers an API to do this
- `text_cache` (`TXT_`): Implements an asynchronously-filled cache for textual asynchronously.
analysis data (tokens, line ranges, and so on), filled by data sourced in the
`hash_store` layer's cache. Used for asynchronously preparing data for
visualization (like for the source code viewer).
- `third_party` (no namespace): External code from other projects, which some - `third_party` (no namespace): External code from other projects, which some
layers in the codebase depend on. All external code is included and built layers in the codebase depend on. All external code is included and built
directly within the codebase. directly within the codebase.
+55 -27
View File
@@ -1,6 +1,7 @@
@echo off @echo off
setlocal enabledelayedexpansion setlocal enabledelayedexpansion
cd /D "%~dp0" cd /D "%~dp0"
:restart
:: --- Usage Notes (2024/1/10) ------------------------------------------------ :: --- Usage Notes (2024/1/10) ------------------------------------------------
:: ::
@@ -24,9 +25,10 @@ cd /D "%~dp0"
:: ::
:: - `asan`: enable address sanitizer :: - `asan`: enable address sanitizer
:: - `telemetry`: enable RAD telemetry profiling support :: - `telemetry`: enable RAD telemetry profiling support
:: - `spall`: enable spall profiling support
:: --- Unpack Arguments ------------------------------------------------------- :: --- Unpack Arguments -------------------------------------------------------
for %%a in (%*) do set "%%a=1" for %%a in (%*) do set "%%~a=1"
if not "%msvc%"=="1" if not "%clang%"=="1" set msvc=1 if not "%msvc%"=="1" if not "%clang%"=="1" set msvc=1
if not "%release%"=="1" set debug=1 if not "%release%"=="1" set debug=1
if "%debug%"=="1" set release=0 && echo [debug mode] if "%debug%"=="1" set release=0 && echo [debug mode]
@@ -38,34 +40,50 @@ if "%~1"=="release" if "%~2"=="" echo [default mode, assuming `raddbg` build] &&
:: --- Unpack Command Line Build Arguments ------------------------------------ :: --- Unpack Command Line Build Arguments ------------------------------------
set auto_compile_flags= set auto_compile_flags=
if "%telemetry%"=="1" set auto_compile_flags=%auto_compile_flags% -DPROFILE_TELEMETRY=1 && echo [telemetry profiling enabled] if "%telemetry%"=="1" set auto_compile_flags=%auto_compile_flags% -DPROFILE_TELEMETRY=1 && echo [telemetry profiling enabled]
if "%asan%"=="1" set auto_compile_flags=%auto_compile_flags% -fsanitize=address && echo [asan enabled] if "%spall%"=="1" set auto_compile_flags=%auto_compile_flags% -DPROFILE_SPALL=1 && echo [spall profiling enabled]
if "%asan%"=="1" set auto_compile_flags=%auto_compile_flags% -fsanitize=address && echo [asan enabled]
if "%opengl%"=="1" set auto_compile_flags=%auto_compile_flags% -DR_BACKEND=R_BACKEND_OPENGL && echo [opengl render backend]
if "%dwarf%"=="1" if "%clang%"=="1" set auto_compile_flags=%auto_compile_flags% -gdwarf && echo [dwarf debug info]
if "%dwarf%"=="" if "%clang%"=="1" set auto_compile_flags=%auto_compile_flags% -gcodeview
if "%pgo%"=="1" (
where llvm-profdata /q || echo llvm-profdata is not in the PATH || exit /b 1
if "%clang%"=="1" (
if "%pgo_run%" == "1" (
call llvm-profdata merge %LLVM_PROFILE_FILE% -output=%~dp0build\build.profdata || exit /b 1
set auto_compile_flags=%auto_compile_flags% -fprofile-use=%~dp0build\build.profdata
set pgo_run=0
) else (
echo [pgo enabled]
set auto_compile_flags=%auto_compile_flags% -fprofile-generate -mllvm -vp-counters-per-site=5
set LLVM_PROFILE_FILE=%~dp0build\build.profraw
set pgo_run=1
)
) else (
echo ERROR: PGO build is not supported with current compiler
exit /b 1
)
)
:: --- Compile/Link Line Definitions ------------------------------------------ :: --- Compile/Link Line Definitions ------------------------------------------
set cl_common= /I..\src\ /I..\local\ /nologo /FC /Z7 set cl_common= /I..\src\ /I..\local\ /nologo /FC /Z7
set clang_common= -I..\src\ -I..\local\ -gcodeview -fdiagnostics-absolute-paths -Wall -Wno-unknown-warning-option -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 -Xclang -flto-visibility-public-std -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf -ferror-limit=10000
set cl_debug= call cl /Od /Ob1 /DBUILD_DEBUG=1 %cl_common% %auto_compile_flags% set cl_debug= call cl /Od /Ob1 /DBUILD_DEBUG=1 %cl_common% %auto_compile_flags%
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 cl_link= /link /MANIFEST:EMBED /INCREMENTAL:NO /pdbaltpath:%%%%_PDB%%%% /NATVIS:"%~dp0\src\natvis\base.natvis" /noexp /nocoffgrpinfo /opt:ref /opt:icf
set cl_out= /out:
set cl_linker=
set clang_common= -I..\src\ -I..\local\ -fdiagnostics-absolute-paths -Wall -Wno-unknown-warning-option -Wno-missing-braces -Wno-unused-function -Wno-unused-parameter -Wno-writable-strings -Wno-missing-field-initializers -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 -Xclang -flto-visibility-public-std -D_USE_MATH_DEFINES -Dstrdup=_strdup -Dgnu_printf=printf -ferror-limit=10000 -mcx16 -msha
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 /pdbaltpath:%%%%_PDB%%%% set clang_link= -fuse-ld=lld -Xlinker /MANIFEST:EMBED -Xlinker /pdbaltpath:%%%%_PDB%%%% -Xlinker /NATVIS:"%~dp0\src\natvis\base.natvis" -Xlinker /opt:ref -Xlinker /opt:icf
set clang_link= -fuse-ld=lld -Xlinker /MANIFEST:EMBED -Xlinker /pdbaltpath:%%%%_PDB%%%%
set cl_out= /out:
set clang_out= -o set clang_out= -o
set clang_linker= -Xlinker
:: --- 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 set link_icon=logo.res
if "%msvc%"=="1" set linker=%cl_linker%
if "%clang%"=="1" set linker=%clang_linker%
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
@@ -87,9 +105,6 @@ 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
@@ -104,8 +119,8 @@ for /f %%i in ('call git describe --always --dirty') do set compile=%compile%
for /f %%i in ('call git rev-parse HEAD') do set compile=%compile% -DBUILD_GIT_HASH_FULL=\"%%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 "%meta%"=="1" (
if not "%no_meta%"=="1" ( echo [doing metagen]
pushd build pushd build
%compile_debug% ..\src\metagen\metagen_main.c %compile_link% %out%metagen.exe || exit /b 1 %compile_debug% ..\src\metagen\metagen_main.c %compile_link% %out%metagen.exe || exit /b 1
metagen.exe || exit /b 1 metagen.exe || exit /b 1
@@ -115,18 +130,21 @@ 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% %link_icon% %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 "%radlink%"=="1" set didbuild=1 && %compile% ..\src\linker\lnk.c %compile_link% %linker% /NOIMPLIB %linker% /NATVIS:"%~dp0\src\linker\linker.natvis" %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 "%radbin%"=="1" set didbuild=1 && %compile% ..\src\radbin\radbin_main.c %compile_link% %out%radbin.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 "%raddump%"=="1" set didbuild=1 && %compile% ..\src\raddump\raddump_main.c %compile_link% %out%raddump.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 "%tester%"=="1" set didbuild=1 && %compile% ..\src\tester\tester_main.c %compile_link% %out%tester.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 "%eval_scratch%"=="1" set didbuild=1 && %compile% ..\src\scratch\eval_scratch.c %compile_link% %out%eval_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 "%textperf%"=="1" set didbuild=1 && %compile% ..\src\scratch\textperf.c %compile_link% %out%textperf.exe || exit /b 1
if "%convertperf%"=="1" set didbuild=1 && %compile% ..\src\scratch\convertperf.c %compile_link% %out%convertperf.exe || exit /b 1
if "%debugstringperf%"=="1" set didbuild=1 && %compile% ..\src\scratch\debugstringperf.c %compile_link% %out%debugstringperf.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 "%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 "%strip_lib_debug%"=="1" set didbuild=1 && %compile% ..\src\strip_lib_debug\strip_lib_debug.c %compile_link% %out%strip_lib_debug.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
if "%torture%"=="1" set didbuild=1 && %compile% ..\src\torture\torture.c %compile_link% %out%torture.exe || exit /b1
if "%mule_peb_trample%"=="1" ( if "%mule_peb_trample%"=="1" (
set didbuild=1 set didbuild=1
if exist mule_peb_trample.exe move mule_peb_trample.exe mule_peb_trample_old_%random%.exe if exist mule_peb_trample.exe move mule_peb_trample.exe mule_peb_trample_old_%random%.exe
@@ -142,3 +160,13 @@ 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`.
exit /b 1 exit /b 1
) )
:: --- PGO Run ----------------------------------------------------------------
if "%pgo_run%"=="1" (
if "%radlink%"=="1" (
pushd local\lyra_pgo
call %~dp0build\radlink @lyra.rsp /rad_alt_pch_dir:%~dp0local\lyra_pgo || exit /b 1
popd
)
goto restart
)
+6 -4
View File
@@ -15,11 +15,11 @@ if [ -v gcc ]; then compiler="${CC:-gcc}"; echo "[gcc compile]"; fi
auto_compile_flags='' auto_compile_flags=''
# --- Get Current Git Commit Id ----------------------------------------------- # --- Get Current Git Commit Id -----------------------------------------------
git_hash=$(git rev-parse HEAD) git_hash=$(git describe --always --dirty)
git_hash_full=$(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 -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_common="-I../src/ -I/usr/include/freetype2/ -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"
@@ -33,6 +33,8 @@ gcc_out="-o"
# --- Per-Build Settings ------------------------------------------------------ # --- Per-Build Settings ------------------------------------------------------
link_dll="-fPIC" link_dll="-fPIC"
link_os_gfx="-lX11 -lXext" link_os_gfx="-lX11 -lXext"
link_render="-lGL -lEGL"
link_font_provider="-lfreetype"
# --- Choose Compile/Link Lines ----------------------------------------------- # --- Choose Compile/Link Lines -----------------------------------------------
if [ -v gcc ]; then compile_debug="$gcc_debug"; fi if [ -v gcc ]; then compile_debug="$gcc_debug"; fi
@@ -62,13 +64,13 @@ 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 $link_render $link_font_provider $out raddbg; fi
if [ -v radlink ]; then didbuild=1 && $compile ../src/linker/lnk.c $compile_link $out radlink; 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
if [ -v rdi_breakpad_from_pdb ]; then didbuild=1 && $compile ../src/rdi_breakpad_from_pdb/rdi_breakpad_from_pdb_main.c $compile_link $out rdi_breakpad_from_pdb; fi if [ -v rdi_breakpad_from_pdb ]; then didbuild=1 && $compile ../src/rdi_breakpad_from_pdb/rdi_breakpad_from_pdb_main.c $compile_link $out rdi_breakpad_from_pdb; fi
if [ -v ryan_scratch ]; then didbuild=1 && $compile ../src/scratch/ryan_scratch.c $compile_link $link_os_gfx $out ryan_scratch; fi if [ -v ryan_scratch ]; then didbuild=1 && $compile ../src/scratch/ryan_scratch.c $compile_link $link_os_gfx $link_render $link_font_provider $out ryan_scratch; fi
cd .. cd ..
# --- Warn On No Builds ------------------------------------------------------- # --- Warn On No Builds -------------------------------------------------------
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+25 -6
View File
@@ -45,12 +45,31 @@ load_paths =
commands = commands =
{ {
//- rjf: fkey command slots (change locally but do not commit) //- rjf: [raddbg]
.f1 = { .win = "build raddbg telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, .f1 = { .win = "raddbg_stable --ipc kill_all && build raddbg meta 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, }, // .f1 = { .win = "raddbg_stable --ipc kill_all && build radbin debug telemetry", .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, }, //- rjf: [raddbg wsl]
// .f3 = { .win = "pushd build && textperf.exe --capture && popd",.linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, // .f1 = { .win = "wsl ./build.sh raddbg", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
//- rjf: [scratch]
.f2 = { .win = "build radbin debug telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
//- rjf: [textperf]
// .f1 = { .win = "raddbg_stable --ipc kill_all && build no_meta telemetry textperf && raddbg_stable --ipc bring_to_front && raddbg_stable --ipc run", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
//- rjf: [tester]
// .f1 = { .win = "raddbg_stable --ipc kill_all && build no_meta tester", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
//- rjf: [radbin]
// .f1 = { .win = "raddbg_stable --ipc kill_all && build radbin", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
//- rjf: running target
.f3 = { .win = "raddbg_stable --ipc run", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
// .f3 = { .win = "wsl ./build/raddbg", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
// .f3 = { .win = "pushd build && raddbg --user:dev.raddbg_user && popd", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
// .f3 = { .win = "C:/devel/raddebugger/build/raddbg.exe --capture --user:C:/devel/raddebugger/build/local_dev.raddbg_user --project:C:/devel/raddebugger/build/local_dev.raddbg_project", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
// .f3 = { .win = "wsl_launch /mnt/c/devel/raddebugger/build/raddbg", .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, },
+654
View File
@@ -0,0 +1,654 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: Layer Initialization
internal void
ac_init(void)
{
Arena *arena = arena_alloc();
ac_shared = push_array(arena, AC_Shared, 1);
ac_shared->arena = arena;
ac_shared->cache_slots_count = 256;
ac_shared->cache_slots = push_array(arena, AC_Cache *, ac_shared->cache_slots_count);
ac_shared->cache_stripes = stripe_array_alloc(arena);
for EachElement(idx, ac_shared->req_batches)
{
ac_shared->req_batches[idx].mutex = mutex_alloc();
ac_shared->req_batches[idx].arena = arena_alloc();
}
ac_shared->cancel_thread = thread_launch(ac_cancel_thread_entry_point, 0);
ac_shared->cancel_thread_mutex = mutex_alloc();
mutex_take(ac_shared->cancel_thread_mutex);
}
////////////////////////////////
//~ rjf: Cache Lookups
internal AC_Artifact
ac_artifact_from_key_(Access *access, String8 key, AC_ArtifactParams *params, U64 endt_us)
{
ProfBeginFunction();
AC_RequestBatch *req_batch = &ac_shared->req_batches[params->flags & AC_Flag_HighPriority ? 0 : 1];
//- rjf: create function -> cache
AC_Cache *cache = 0;
{
U64 cache_hash = u64_hash_from_str8(str8_struct(&params->create));
U64 cache_slot_idx = cache_hash%ac_shared->cache_slots_count;
Stripe *cache_stripe = stripe_from_slot_idx(&ac_shared->cache_stripes, cache_slot_idx);
for(B32 write_mode = 0; write_mode <= 1; write_mode += 1)
{
RWMutexScope(cache_stripe->rw_mutex, write_mode)
{
for(AC_Cache *c = ac_shared->cache_slots[cache_slot_idx]; c != 0; c = c->next)
{
if(c->create == params->create)
{
cache = c;
break;
}
}
if(write_mode && cache == 0)
{
cache = push_array(cache_stripe->arena, AC_Cache, 1);
SLLStackPush(ac_shared->cache_slots[cache_slot_idx], cache);
cache->create = params->create;
cache->destroy = params->destroy;
cache->slots_count = Max(256, params->slots_count);
cache->slots = push_array(cache_stripe->arena, AC_Slot, cache->slots_count);
cache->stripes = stripe_array_alloc(cache_stripe->arena);
}
}
if(cache != 0)
{
break;
}
}
}
//- rjf: unpack key
U64 hash = u64_hash_from_str8(key);
U64 slot_idx = hash%cache->slots_count;
AC_Slot *slot = &cache->slots[slot_idx];
Stripe *stripe = stripe_from_slot_idx(&cache->stripes, slot_idx);
//- rjf: cache * key -> existing artifact
B32 artifact_is_stale = 1;
B32 got_artifact = 0;
B32 need_request = 0;
AC_Artifact artifact = {0};
RWMutexScope(stripe->rw_mutex, 0)
{
for(AC_Node *n = slot->first; n != 0; n = n->next)
{
if(str8_match(n->key, key, 0))
{
ins_atomic_u64_eval_assign(&n->last_requested_gen, params->gen);
B32 is_stale = (n->last_completed_gen != params->gen);
if(ins_atomic_u64_eval(&n->completion_count) != 0 && (!is_stale || !(params->flags & AC_Flag_WaitForFresh)))
{
got_artifact = 1;
artifact_is_stale = is_stale;
artifact = n->val;
access_touch(access, &n->access_pt, stripe->cv);
}
if(is_stale)
{
B32 got_task = (ins_atomic_u64_eval_cond_assign(&n->working_count, 1, 0) == 0);
need_request = got_task;
}
break;
}
}
}
//- rjf: didn't get artifact we want? -> fall back to slow path
if(!got_artifact || need_request)
{
RWMutexScope(stripe->rw_mutex, 1) for(;;)
{
B32 out_of_time = (os_now_microseconds() >= endt_us);
// rjf: find node in cache
AC_Node *node = 0;
for(AC_Node *n = slot->first; n != 0; n = n->next)
{
if(str8_match(n->key, key, 0))
{
node = n;
break;
}
}
// rjf: no node? -> create
if(node == 0)
{
need_request = 1;
node = stripe->free;
if(node)
{
stripe->free = node->next;
}
else
{
node = push_array_no_zero(stripe->arena, AC_Node, 1);
}
MemoryZeroStruct(node);
DLLPushBack(slot->first, slot->last, node);
// TODO(rjf): string allocator for keys
node->key = str8_copy(stripe->arena, key);
node->working_count = 1;
node->evict_threshold_us = params->evict_threshold_us;
}
node->access_pt.last_time_touched_us = os_now_microseconds();
node->access_pt.last_update_idx_touched = update_tick_idx();
// rjf: request
if(need_request)
{
need_request = 0;
MutexScope(req_batch->mutex)
{
AC_RequestNode *n = push_array(req_batch->arena, AC_RequestNode, 1);
if(params->flags & AC_Flag_Wide)
{
SLLQueuePush(req_batch->first_wide, req_batch->last_wide, n);
req_batch->wide_count += 1;
}
else
{
SLLQueuePush(req_batch->first_thin, req_batch->last_thin, n);
req_batch->thin_count += 1;
}
n->v.key = str8_copy(req_batch->arena, key);
n->v.gen = params->gen;
n->v.cancel_signal = &node->cancelled;
n->v.create = params->create;
}
cond_var_broadcast(async_tick_start_cond_var);
ins_atomic_u32_eval_assign(&async_loop_again, 1);
if(params->flags & AC_Flag_HighPriority)
{
ins_atomic_u32_eval_assign(&async_loop_again_high_priority, 1);
}
}
// rjf: get value from node, if possible
if(!got_artifact && ins_atomic_u64_eval(&node->completion_count) != 0 && ((node->last_completed_gen == params->gen) || !(params->flags & AC_Flag_WaitForFresh) || out_of_time))
{
got_artifact = 1;
artifact_is_stale = (node->last_completed_gen == params->gen);
artifact = node->val;
access_touch(access, &node->access_pt, stripe->cv);
}
// rjf: abort if needed
if(out_of_time || got_artifact || is_async_thread)
{
break;
}
// rjf: wait for results
cond_var_wait_rw(stripe->cv, stripe->rw_mutex, 1, endt_us);
}
}
//- rjf: report staleness
if(params->stale_out)
{
params->stale_out[0] = artifact_is_stale;
}
ProfEnd();
return artifact;
}
////////////////////////////////
//~ rjf: Asynchronous Tick
internal void
ac_async_tick(void)
{
Temp scratch = scratch_begin(0, 0);
//////////////////////////////
//- rjf: enable cancellation scanning
//
if(lane_idx() == 0)
{
mutex_drop(ac_shared->cancel_thread_mutex);
}
//////////////////////////////
//- rjf: do eviction pass across all caches
//
for EachIndex(cache_slot_idx, ac_shared->cache_slots_count)
{
Stripe *cache_stripe = stripe_from_slot_idx(&ac_shared->cache_stripes, cache_slot_idx);
RWMutexScope(cache_stripe->rw_mutex, 0)
{
for EachNode(cache, AC_Cache, ac_shared->cache_slots[cache_slot_idx])
{
Rng1U64 slot_range = lane_range(cache->slots_count);
for EachInRange(slot_idx, slot_range)
{
AC_Slot *slot = &cache->slots[slot_idx];
Stripe *stripe = stripe_from_slot_idx(&cache->stripes, slot_idx);
for(B32 write_mode = 0; write_mode <= 1; write_mode += 1)
{
B32 slot_has_work = 0;
RWMutexScope(stripe->rw_mutex, write_mode)
{
for(AC_Node *n = slot->first, *next = 0; n != 0; n = next)
{
next = n->next;
if(access_pt_is_expired(&n->access_pt, .time = n->evict_threshold_us) && ins_atomic_u64_eval(&n->working_count) == 0)
{
slot_has_work = 1;
if(!write_mode)
{
break;
}
else
{
DLLRemove(slot->first, slot->last, n);
n->next = (AC_Node *)stripe->free;
stripe->free = n;
if(cache->destroy)
{
cache->destroy(n->val);
}
}
}
}
}
if(!slot_has_work)
{
break;
}
}
}
}
}
}
//////////////////////////////
//- rjf: gather requests
//
typedef struct RequestBatchTask RequestBatchTask;
struct RequestBatchTask
{
AC_Request *wide;
U64 wide_count;
AC_Request *thin;
U64 thin_count;
};
RequestBatchTask *tasks = 0;
U64 tasks_count = 0;
if(lane_idx() == 0)
{
tasks_count = 2;
tasks = push_array(scratch.arena, RequestBatchTask, tasks_count);
for EachElement(task_idx, ac_shared->req_batches)
{
AC_RequestBatch *batch = &ac_shared->req_batches[task_idx];
MutexScope(batch->mutex)
{
tasks[task_idx].wide_count = batch->wide_count;
tasks[task_idx].thin_count = batch->thin_count;
tasks[task_idx].wide = push_array(scratch.arena, AC_Request, tasks[task_idx].wide_count);
tasks[task_idx].thin = push_array(scratch.arena, AC_Request, tasks[task_idx].thin_count);
{
U64 idx = 0;
for EachNode(n, AC_RequestNode, batch->first_wide)
{
MemoryCopyStruct(&tasks[task_idx].wide[idx], &n->v);
tasks[task_idx].wide[idx].key = str8_copy(scratch.arena, tasks[task_idx].wide[idx].key);
idx += 1;
}
}
{
U64 idx = 0;
for EachNode(n, AC_RequestNode, batch->first_thin)
{
MemoryCopyStruct(&tasks[task_idx].thin[idx], &n->v);
tasks[task_idx].thin[idx].key = str8_copy(scratch.arena, tasks[task_idx].thin[idx].key);
idx += 1;
}
}
arena_clear(batch->arena);
batch->first_wide = batch->last_wide = batch->first_thin = batch->last_thin = 0;
batch->wide_count = batch->thin_count = 0;
}
}
}
lane_sync_u64(&tasks, 0);
lane_sync_u64(&tasks_count, 0);
lane_sync();
//////////////////////////////
//- rjf: do all requests
//
for EachIndex(task_idx, tasks_count)
{
lane_sync();
RequestBatchTask *task = &tasks[task_idx];
//- rjf: set up cancellation signal
U64 cancelled = 0;
U64 *cancelled_ptr = 0;
if(lane_idx() == 0)
{
cancelled_ptr = &cancelled;
}
lane_sync_u64(&cancelled_ptr, 0);
//- rjf: do all wide requests for this priority
U64 done_wide_count = 0;
ProfScope("wide requests (p%I64u)", task_idx)
{
for EachIndex(idx, task->wide_count)
{
lane_sync();
AC_Request *r = &task->wide[idx];
// rjf: any new higher priority tasks? -> cancel
if(lane_idx() == 0)
{
if(task_idx == 1 && idx != 0 && ins_atomic_u32_eval(&async_loop_again_high_priority))
{
ins_atomic_u64_eval_assign(cancelled_ptr, 1);
}
}
lane_sync();
// rjf: cancelled? -> exit
if(ins_atomic_u32_eval(cancelled_ptr))
{
break;
}
// rjf: compute val
B32 retry = 0;
U64 gen = r->gen;
AC_Artifact val = r->create(r->key, r->cancel_signal, &retry, &gen);
// rjf: retry? -> resubmit request
if(retry && lane_idx() == 0)
{
AC_RequestBatch *batch = &ac_shared->req_batches[task_idx];
MutexScope(batch->mutex)
{
AC_RequestNode *n = push_array(batch->arena, AC_RequestNode, 1);
SLLQueuePush(batch->first_wide, batch->last_wide, n);
batch->wide_count += 1;
MemoryCopyStruct(&n->v, r);
n->v.key = str8_copy(batch->arena, n->v.key);
}
ins_atomic_u32_eval_assign(&async_loop_again, 1);
}
// rjf: create function -> cache
AC_Cache *cache = 0;
if(!retry && lane_idx() == 0)
{
U64 cache_hash = u64_hash_from_str8(str8_struct(&r->create));
U64 cache_slot_idx = cache_hash%ac_shared->cache_slots_count;
Stripe *cache_stripe = stripe_from_slot_idx(&ac_shared->cache_stripes, cache_slot_idx);
RWMutexScope(cache_stripe->rw_mutex, 0)
{
for(AC_Cache *c = ac_shared->cache_slots[cache_slot_idx]; c != 0; c = c->next)
{
if(c->create == r->create)
{
cache = c;
break;
}
}
}
}
// rjf: write value into cache
if(!retry && lane_idx() == 0)
{
U64 hash = u64_hash_from_str8(r->key);
U64 slot_idx = hash%cache->slots_count;
AC_Slot *slot = &cache->slots[slot_idx];
Stripe *stripe = stripe_from_slot_idx(&cache->stripes, slot_idx);
RWMutexScope(stripe->rw_mutex, 1)
{
for(AC_Node *n = slot->first; n != 0; n = n->next)
{
if(str8_match(n->key, r->key, 0))
{
n->last_completed_gen = gen;
n->val = val;
ins_atomic_u64_dec_eval(&n->working_count);
ins_atomic_u64_inc_eval(&n->completion_count);
}
}
}
cond_var_broadcast(stripe->cv);
}
// rjf: increment count
lane_sync();
done_wide_count += 1;
}
}
lane_sync();
//- rjf: do all thin requests for this priority
U64 done_thin_count = 0;
ProfScope("thin requests (p%I64u)", task_idx)
{
U64 req_take_counter = 0;
U64 *req_take_counter_ptr = 0;
if(lane_idx() == 0)
{
req_take_counter_ptr = &req_take_counter;
}
lane_sync_u64(&req_take_counter_ptr, 0);
for(;;)
{
// rjf: any new higher priority tasks? -> cancel
if(task_idx == 1 && ins_atomic_u64_eval(req_take_counter_ptr) >= task->thin_count/2 &&
ins_atomic_u32_eval(&async_loop_again_high_priority))
{
ins_atomic_u64_eval_assign(cancelled_ptr, 1);
}
// rjf: cancelled? -> exit
if(ins_atomic_u64_eval(cancelled_ptr))
{
break;
}
// rjf: take next task
U64 req_idx = ins_atomic_u64_inc_eval(req_take_counter_ptr) - 1;
if(req_idx >= task->thin_count) { break; }
AC_Request *r = &task->thin[req_idx];
// rjf: push thin lane ctx
U64 thin_lane_ctx_broadcast_memory = 0;
LaneCtx thin_lane_ctx = {0, 1, {0}, &thin_lane_ctx_broadcast_memory};
LaneCtx lane_ctx_restore = lane_ctx(thin_lane_ctx);
// rjf: compute val
B32 retry = 0;
U64 gen = r->gen;
AC_Artifact val = r->create(r->key, r->cancel_signal, &retry, &gen);
// rjf: restore wide lane ctx
lane_ctx(lane_ctx_restore);
// rjf: retry? -> resubmit request
if(retry)
{
AC_RequestBatch *batch = &ac_shared->req_batches[task_idx];
MutexScope(batch->mutex)
{
AC_RequestNode *n = push_array(batch->arena, AC_RequestNode, 1);
SLLQueuePush(batch->first_thin, batch->last_thin, n);
batch->thin_count += 1;
MemoryCopyStruct(&n->v, r);
n->v.key = str8_copy(batch->arena, n->v.key);
}
ins_atomic_u32_eval_assign(&async_loop_again, 1);
}
// rjf: create function -> cache
AC_Cache *cache = 0;
if(!retry)
{
U64 cache_hash = u64_hash_from_str8(str8_struct(&r->create));
U64 cache_slot_idx = cache_hash%ac_shared->cache_slots_count;
Stripe *cache_stripe = stripe_from_slot_idx(&ac_shared->cache_stripes, cache_slot_idx);
RWMutexScope(cache_stripe->rw_mutex, 0)
{
for(AC_Cache *c = ac_shared->cache_slots[cache_slot_idx]; c != 0; c = c->next)
{
if(c->create == r->create)
{
cache = c;
break;
}
}
}
}
// rjf: write value into cache
if(!retry)
{
U64 hash = u64_hash_from_str8(r->key);
U64 slot_idx = hash%cache->slots_count;
AC_Slot *slot = &cache->slots[slot_idx];
Stripe *stripe = stripe_from_slot_idx(&cache->stripes, slot_idx);
RWMutexScope(stripe->rw_mutex, 1)
{
for(AC_Node *n = slot->first; n != 0; n = n->next)
{
if(str8_match(n->key, r->key, 0))
{
n->last_completed_gen = gen;
n->val = val;
ins_atomic_u64_dec_eval(&n->working_count);
ins_atomic_u64_inc_eval(&n->completion_count);
}
}
}
cond_var_broadcast(stripe->cv);
}
}
lane_sync();
done_thin_count = ins_atomic_u64_eval(req_take_counter_ptr);
lane_sync();
}
//- rjf: cancelled early, unfinished tasks? -> defer to next tick
if(lane_idx() == 0 && task_idx > 0)
{
B32 need_another_try = (done_wide_count < task->wide_count || done_thin_count < task->thin_count);
AC_RequestBatch *batch = &ac_shared->req_batches[task_idx];
MutexScope(batch->mutex)
{
// rjf: push leftover wide tasks
for(U64 idx = done_wide_count; idx < task->wide_count; idx += 1)
{
AC_Request *r = &task->wide[idx];
AC_RequestNode *n = push_array(batch->arena, AC_RequestNode, 1);
SLLQueuePush(batch->first_wide, batch->last_wide, n);
batch->wide_count += 1;
MemoryCopyStruct(&n->v, r);
n->v.key = str8_copy(batch->arena, n->v.key);
}
// rjf: push leftover thin tasks
for(U64 idx = done_thin_count; idx < task->thin_count; idx += 1)
{
AC_Request *r = &task->thin[idx];
AC_RequestNode *n = push_array(batch->arena, AC_RequestNode, 1);
SLLQueuePush(batch->first_thin, batch->last_thin, n);
batch->thin_count += 1;
MemoryCopyStruct(&n->v, r);
n->v.key = str8_copy(batch->arena, n->v.key);
}
}
if(need_another_try)
{
ins_atomic_u32_eval_assign(&async_loop_again, 1);
}
}
lane_sync();
}
lane_sync();
//////////////////////////////
//- rjf: disable cancellation scanning
//
if(lane_idx() == 0)
{
mutex_take(ac_shared->cancel_thread_mutex);
}
scratch_end(scratch);
}
////////////////////////////////
//~ rjf: Cancel Thread
internal void
ac_cancel_thread_entry_point(void *p)
{
for(;;)
{
os_sleep_milliseconds(50);
MutexScope(ac_shared->cancel_thread_mutex)
{
for EachIndex(cache_slot_idx, ac_shared->cache_slots_count)
{
Stripe *cache_stripe = stripe_from_slot_idx(&ac_shared->cache_stripes, cache_slot_idx);
RWMutexScope(cache_stripe->rw_mutex, 0)
{
for EachNode(cache, AC_Cache, ac_shared->cache_slots[cache_slot_idx])
{
Rng1U64 slot_range = lane_range(cache->slots_count);
for EachInRange(slot_idx, slot_range)
{
AC_Slot *slot = &cache->slots[slot_idx];
Stripe *stripe = stripe_from_slot_idx(&cache->stripes, slot_idx);
for(B32 write_mode = 0; write_mode <= 1; write_mode += 1)
{
B32 slot_has_work = 0;
RWMutexScope(stripe->rw_mutex, write_mode)
{
for(AC_Node *n = slot->first, *next = 0; n != 0; n = next)
{
next = n->next;
if(access_pt_is_expired(&n->access_pt, .time = n->evict_threshold_us) && ins_atomic_u64_eval(&n->working_count) > 0)
{
slot_has_work = 1;
if(!write_mode)
{
break;
}
else
{
n->cancelled = 1;
}
}
}
}
if(!slot_has_work)
{
break;
}
}
}
}
}
}
}
}
}
+161
View File
@@ -0,0 +1,161 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef ARTIFACT_CACHE_H
#define ARTIFACT_CACHE_H
////////////////////////////////
//~ rjf: Artifact Handle Type
typedef struct AC_Artifact AC_Artifact;
struct AC_Artifact
{
U64 u64[4];
};
////////////////////////////////
//~ rjf: Artifact Computation Function Types
typedef AC_Artifact AC_CreateFunctionType(String8 key, B32 *cancel_signal, B32 *retry_out, U64 *gen_out);
typedef void AC_DestroyFunctionType(AC_Artifact artifact);
typedef U32 AC_Flags;
typedef enum AC_FlagsEnum
{
AC_Flag_WaitForFresh = (1<<0),
AC_Flag_HighPriority = (1<<1),
AC_Flag_Wide = (1<<2),
}
AC_FlagsEnum;
typedef struct AC_ArtifactParams AC_ArtifactParams;
struct AC_ArtifactParams
{
AC_CreateFunctionType *create;
AC_DestroyFunctionType *destroy;
U64 slots_count;
U64 gen;
U64 evict_threshold_us;
B32 *stale_out;
AC_Flags flags;
};
////////////////////////////////
//~ rjf: Cache Types
typedef struct AC_Request AC_Request;
struct AC_Request
{
String8 key;
U64 gen;
B32 *cancel_signal;
AC_CreateFunctionType *create;
};
typedef struct AC_RequestNode AC_RequestNode;
struct AC_RequestNode
{
AC_RequestNode *next;
AC_Request v;
};
typedef struct AC_Node AC_Node;
struct AC_Node
{
AC_Node *next;
AC_Node *prev;
// rjf: key/gen/value
String8 key;
U64 last_requested_gen;
U64 last_completed_gen;
AC_Artifact val;
// rjf: metadata
AccessPt access_pt;
U64 working_count;
U64 completion_count;
U64 evict_threshold_us;
B32 cancelled;
U64 _unused_;
};
typedef struct AC_Slot AC_Slot;
struct AC_Slot
{
AC_Node *first;
AC_Node *last;
};
typedef struct AC_Cache AC_Cache;
struct AC_Cache
{
// rjf: link / key for cache-cache
AC_Cache *next;
AC_CreateFunctionType *create;
AC_DestroyFunctionType *destroy;
// rjf: artifact cache
U64 slots_count;
AC_Slot *slots;
StripeArray stripes;
};
typedef struct AC_RequestBatch AC_RequestBatch;
struct AC_RequestBatch
{
Mutex mutex;
Arena *arena;
AC_RequestNode *first_wide;
AC_RequestNode *last_wide;
AC_RequestNode *first_thin;
AC_RequestNode *last_thin;
U64 wide_count;
U64 thin_count;
};
typedef struct AC_Shared AC_Shared;
struct AC_Shared
{
Arena *arena;
// rjf: cache cache
U64 cache_slots_count;
AC_Cache **cache_slots;
StripeArray cache_stripes;
// rjf: requests
AC_RequestBatch req_batches[2]; // 0: high priority, 1: low priority
// rjf: cancel thread
Thread cancel_thread;
Mutex cancel_thread_mutex;
};
////////////////////////////////
//~ rjf: Globals
global AC_Shared *ac_shared = 0;
////////////////////////////////
//~ rjf: Layer Initialization
internal void ac_init(void);
////////////////////////////////
//~ rjf: Cache Lookups
internal AC_Artifact ac_artifact_from_key_(Access *access, String8 key, AC_ArtifactParams *params, U64 endt_us);
#define ac_artifact_from_key(access, key, create_fn, destroy_fn, endt_us, ...) ac_artifact_from_key_((access), (key), &(AC_ArtifactParams){.create = (create_fn), .destroy = (destroy_fn), .evict_threshold_us = (2000000), __VA_ARGS__}, (endt_us))
////////////////////////////////
//~ rjf: Asynchronous Tick
internal void ac_async_tick(void);
////////////////////////////////
//~ rjf: Cancel Thread
internal void ac_cancel_thread_entry_point(void *p);
#endif // ARTIFACT_CACHE_H
-240
View File
@@ -1,240 +0,0 @@
// 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
@@ -1,144 +0,0 @@
// 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
+32 -18
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
//////////////////////////////// ////////////////////////////////
@@ -37,6 +37,7 @@ arena_alloc_(ArenaParams *params)
base = os_reserve(reserve_size); base = os_reserve(reserve_size);
os_commit(base, commit_size); os_commit(base, commit_size);
} }
raddbg_annotate_vaddr_range(base, reserve_size, "arena %s:%i", params->allocation_site_file, params->allocation_site_line);
} }
// rjf: panic on arena creation failure // rjf: panic on arena creation failure
@@ -58,8 +59,9 @@ arena_alloc_(ArenaParams *params)
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;
arena->allocation_site_file = params->allocation_site_file;
arena->allocation_site_line = params->allocation_site_line;
#if ARENA_FREE_LIST #if ARENA_FREE_LIST
arena->free_size = 0;
arena->free_last = 0; arena->free_last = 0;
#endif #endif
AsanPoisonMemoryRegion(base, commit_size); AsanPoisonMemoryRegion(base, commit_size);
@@ -80,7 +82,7 @@ arena_release(Arena *arena)
//- rjf: arena push/pop core functions //- rjf: arena push/pop core functions
internal void * internal void *
arena_push(Arena *arena, U64 size, U64 align) arena_push(Arena *arena, U64 size, U64 align, B32 zero)
{ {
Arena *current = arena->current; Arena *current = arena->current;
U64 pos_pre = AlignPow2(current->pos, align); U64 pos_pre = AlignPow2(current->pos, align);
@@ -92,22 +94,22 @@ arena_push(Arena *arena, U64 size, U64 align)
Arena *new_block = 0; Arena *new_block = 0;
#if ARENA_FREE_LIST #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)
{ {
if(new_block->res >= AlignPow2(size, align)) Arena *prev_block;
for(new_block = arena->free_last, prev_block = 0; new_block != 0; prev_block = new_block, new_block = new_block->prev)
{ {
if(prev_block) if(new_block->res >= AlignPow2(new_block->pos, align) + size)
{ {
prev_block->prev = new_block->prev; if(prev_block)
{
prev_block->prev = new_block->prev;
}
else
{
arena->free_last = new_block->prev;
}
break;
} }
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;
} }
} }
#endif #endif
@@ -123,7 +125,9 @@ arena_push(Arena *arena, U64 size, U64 align)
} }
new_block = arena_alloc(.reserve_size = res_size, new_block = arena_alloc(.reserve_size = res_size,
.commit_size = cmt_size, .commit_size = cmt_size,
.flags = current->flags); .flags = current->flags,
.allocation_site_file = current->allocation_site_file,
.allocation_site_line = current->allocation_site_line);
} }
new_block->base_pos = current->base_pos + current->res; new_block->base_pos = current->base_pos + current->res;
@@ -134,6 +138,13 @@ arena_push(Arena *arena, U64 size, U64 align)
pos_pst = pos_pre + size; pos_pst = pos_pre + size;
} }
// rjf: compute the size we need to zero
U64 size_to_zero = 0;
if(zero)
{
size_to_zero = Min(current->cmt, pos_pst) - pos_pre;
}
// rjf: commit new pages, if needed // rjf: commit new pages, if needed
if(current->cmt < pos_pst) if(current->cmt < pos_pst)
{ {
@@ -160,6 +171,10 @@ arena_push(Arena *arena, U64 size, U64 align)
result = (U8 *)current+pos_pre; result = (U8 *)current+pos_pre;
current->pos = pos_pst; current->pos = pos_pst;
AsanUnpoisonMemoryRegion(result, size); AsanUnpoisonMemoryRegion(result, size);
if(size_to_zero != 0)
{
MemoryZero(result, size_to_zero);
}
} }
// rjf: panic on failure // rjf: panic on failure
@@ -193,9 +208,8 @@ arena_pop_to(Arena *arena, U64 pos)
{ {
prev = current->prev; prev = current->prev;
current->pos = ARENA_HEADER_SIZE; current->pos = ARENA_HEADER_SIZE;
arena->free_size += current->res_size;
SLLStackPush_N(arena->free_last, current, prev); SLLStackPush_N(arena->free_last, current, prev);
AsanPoisonMemoryRegion((U8*)current + ARENA_HEADER_SIZE, current->res_size - ARENA_HEADER_SIZE); AsanPoisonMemoryRegion((U8*)current + ARENA_HEADER_SIZE, current->res - ARENA_HEADER_SIZE);
} }
#else #else
for(Arena *prev = 0; current->base_pos >= big_pos; current = prev) for(Arena *prev = 0; current->base_pos >= big_pos; current = prev)
+11 -14
View File
@@ -1,17 +1,14 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_ARENA_H #ifndef BASE_ARENA_H
#define BASE_ARENA_H #define BASE_ARENA_H
//////////////////////////////// ////////////////////////////////
//~ rjf: Constants //~ rjf: Arena Types
#define ARENA_HEADER_SIZE 128 #define ARENA_HEADER_SIZE 128
////////////////////////////////
//~ rjf: Types
typedef U64 ArenaFlags; typedef U64 ArenaFlags;
enum enum
{ {
@@ -26,6 +23,8 @@ struct ArenaParams
U64 reserve_size; U64 reserve_size;
U64 commit_size; U64 commit_size;
void *optional_backing_buffer; void *optional_backing_buffer;
char *allocation_site_file;
int allocation_site_line;
}; };
typedef struct Arena Arena; typedef struct Arena Arena;
@@ -40,8 +39,9 @@ struct Arena
U64 pos; U64 pos;
U64 cmt; U64 cmt;
U64 res; U64 res;
char *allocation_site_file;
int allocation_site_line;
#if ARENA_FREE_LIST #if ARENA_FREE_LIST
U64 free_size;
Arena *free_last; Arena *free_last;
#endif #endif
}; };
@@ -55,22 +55,19 @@ struct Temp
}; };
//////////////////////////////// ////////////////////////////////
//~ rjf: Global Defaults //~ rjf: Arena Functions
global U64 arena_default_reserve_size = MB(64); global U64 arena_default_reserve_size = MB(64);
global U64 arena_default_commit_size = KB(64); global U64 arena_default_commit_size = KB(64);
global ArenaFlags arena_default_flags = 0; global ArenaFlags arena_default_flags = 0;
////////////////////////////////
//~ rjf: Arena Functions
//- rjf: arena creation/destruction //- rjf: arena creation/destruction
internal Arena *arena_alloc_(ArenaParams *params); internal Arena *arena_alloc_(ArenaParams *params);
#define arena_alloc(...) arena_alloc_(&(ArenaParams){.reserve_size = arena_default_reserve_size, .commit_size = arena_default_commit_size, .flags = arena_default_flags, __VA_ARGS__}) #define arena_alloc(...) arena_alloc_(&(ArenaParams){.reserve_size = arena_default_reserve_size, .commit_size = arena_default_commit_size, .flags = arena_default_flags, .allocation_site_file = __FILE__, .allocation_site_line = __LINE__, __VA_ARGS__})
internal void arena_release(Arena *arena); internal void arena_release(Arena *arena);
//- rjf: arena push/pop/pos core functions //- rjf: arena push/pop/pos core functions
internal void *arena_push(Arena *arena, U64 size, U64 align); internal void *arena_push(Arena *arena, U64 size, U64 align, B32 zero);
internal U64 arena_pos(Arena *arena); internal U64 arena_pos(Arena *arena);
internal void arena_pop_to(Arena *arena, U64 pos); internal void arena_pop_to(Arena *arena, U64 pos);
@@ -83,8 +80,8 @@ internal Temp temp_begin(Arena *arena);
internal void temp_end(Temp temp); internal void temp_end(Temp temp);
//- rjf: push helper macros //- rjf: push helper macros
#define push_array_no_zero_aligned(a, T, c, align) (T *)arena_push((a), sizeof(T)*(c), (align)) #define push_array_no_zero_aligned(a, T, c, align) (T *)arena_push((a), sizeof(T)*(c), (align), (0))
#define push_array_aligned(a, T, c, align) (T *)MemoryZero(push_array_no_zero_aligned(a, T, c, align), sizeof(T)*(c)) #define push_array_aligned(a, T, c, align) (T *)arena_push((a), sizeof(T)*(c), (align), (1))
#define push_array_no_zero(a, T, c) push_array_no_zero_aligned(a, T, c, Max(8, AlignOf(T))) #define push_array_no_zero(a, T, c) push_array_no_zero_aligned(a, T, c, Max(8, AlignOf(T)))
#define push_array(a, T, c) push_array_aligned(a, T, c, Max(8, AlignOf(T))) #define push_array(a, T, c) push_array_aligned(a, T, c, Max(8, AlignOf(T)))
+39 -61
View File
@@ -1,19 +1,8 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
//////////////////////////////// ////////////////////////////////
//~ NOTE(rjf): Command Line Option Parsing //~ rjf: Command Line Parsing Functions
internal U64
cmd_line_hash_from_string(String8 string)
{
U64 result = 5381;
for(U64 i = 0; i < string.size; i += 1)
{
result = ((result << 5) + result) + string.str[i];
}
return result;
}
internal CmdLineOpt ** internal CmdLineOpt **
cmd_line_slot_from_string(CmdLine *cmd_line, String8 string) cmd_line_slot_from_string(CmdLine *cmd_line, String8 string)
@@ -21,7 +10,7 @@ cmd_line_slot_from_string(CmdLine *cmd_line, String8 string)
CmdLineOpt **slot = 0; CmdLineOpt **slot = 0;
if(cmd_line->option_table_size != 0) if(cmd_line->option_table_size != 0)
{ {
U64 hash = cmd_line_hash_from_string(string); U64 hash = u64_hash_from_str8(string);
U64 bucket = hash % cmd_line->option_table_size; U64 bucket = hash % cmd_line->option_table_size;
slot = &cmd_line->option_table[bucket]; slot = &cmd_line->option_table[bucket];
} }
@@ -64,7 +53,7 @@ cmd_line_insert_opt(Arena *arena, CmdLine *cmd_line, String8 string, String8List
{ {
var = push_array(arena, CmdLineOpt, 1); var = push_array(arena, CmdLineOpt, 1);
var->hash_next = *slot; var->hash_next = *slot;
var->hash = cmd_line_hash_from_string(string); var->hash = u64_hash_from_str8(string);
var->string = push_str8_copy(arena, string); var->string = push_str8_copy(arena, string);
var->value_strings = values; var->value_strings = values;
StringJoin join = {0}; StringJoin join = {0};
@@ -83,28 +72,25 @@ cmd_line_from_string_list(Arena *arena, String8List command_line)
{ {
CmdLine parsed = {0}; CmdLine parsed = {0};
parsed.exe_name = command_line.first->string; parsed.exe_name = command_line.first->string;
parsed.option_table_size = 64;
parsed.option_table = push_array(arena, CmdLineOpt *, parsed.option_table_size);
// NOTE(rjf): Set up config option table. //- rjf: parse options / inputs
{
parsed.option_table_size = 4096;
parsed.option_table = push_array(arena, CmdLineOpt *, parsed.option_table_size);
}
// NOTE(rjf): Parse command line.
B32 after_passthrough_option = 0; B32 after_passthrough_option = 0;
B32 first_passthrough = 1; B32 first_passthrough = 1;
for(String8Node *node = command_line.first->next, *next = 0; node != 0; node = next) for(String8Node *node = command_line.first->next, *next = 0; node != 0; node = next)
{ {
next = node->next; next = node->next;
String8 option_name = node->string;
// NOTE(rjf): Look at --, -, or / (only on Windows) at the start of an //- rjf: look at --, -, or / (only on Windows) at the start of an
// argument to determine if it's a flag option. All arguments after a // argument to determine if it's a flag option. all arguments after a
// single "--" (with no trailing string on the command line will be // single "--" (with no trailing string on the command line will be
// considered as input files. // considered as passthrough input strings.
B32 is_option = 1; B32 is_option = 0;
if(after_passthrough_option == 0) String8 option_name = node->string;
if(!after_passthrough_option)
{ {
is_option = 1;
if(str8_match(node->string, str8_lit("--"), 0)) if(str8_match(node->string, str8_lit("--"), 0))
{ {
after_passthrough_option = 1; after_passthrough_option = 1;
@@ -118,7 +104,7 @@ 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 && else if(OperatingSystem_CURRENT == OperatingSystem_Windows &&
str8_match(str8_prefix(node->string, 1), str8_lit("/"), 0)) str8_match(str8_prefix(node->string, 1), str8_lit("/"), 0))
{ {
option_name = str8_skip(option_name, 1); option_name = str8_skip(option_name, 1);
@@ -128,69 +114,61 @@ cmd_line_from_string_list(Arena *arena, String8List command_line)
is_option = 0; is_option = 0;
} }
} }
else
{
is_option = 0;
}
// NOTE(rjf): This string is an option. //- rjf: string is an option
if(is_option) if(is_option)
{ {
B32 has_arguments = 0; // rjf: unpack option prefix
U64 arg_signifier_position1 = str8_find_needle(option_name, 0, str8_lit(":"), 0); B32 has_values = 0;
U64 arg_signifier_position2 = str8_find_needle(option_name, 0, str8_lit("="), 0); U64 value_signifier_position1 = str8_find_needle(option_name, 0, str8_lit(":"), 0);
U64 arg_signifier_position = Min(arg_signifier_position1, arg_signifier_position2); U64 value_signifier_position2 = str8_find_needle(option_name, 0, str8_lit("="), 0);
String8 arg_portion_this_string = str8_skip(option_name, arg_signifier_position+1); U64 value_signifier_position = Min(value_signifier_position1, value_signifier_position2);
if(arg_signifier_position < option_name.size) String8 value_portion_this_string = str8_skip(option_name, value_signifier_position+1);
if(value_signifier_position < option_name.size)
{ {
has_arguments = 1; has_values = 1;
} }
option_name = str8_prefix(option_name, arg_signifier_position); option_name = str8_prefix(option_name, value_signifier_position);
String8List arguments = {0}; // rjf: parse option's values
String8List values = {0};
// NOTE(rjf): Parse arguments. if(has_values)
if(has_arguments)
{ {
for(String8Node *n = node; n; n = n->next) for(String8Node *n = node; n; n = n->next)
{ {
next = n->next; next = n->next;
String8 string = n->string; String8 string = n->string;
if(n == node) if(n == node)
{ {
string = arg_portion_this_string; string = value_portion_this_string;
} }
U8 splits[] = { ',' }; U8 splits[] = { ',' };
String8List args_in_this_string = str8_split(arena, string, splits, ArrayCount(splits), 0); String8List values_in_this_string = str8_split(arena, string, splits, ArrayCount(splits), 0);
for(String8Node *sub_arg = args_in_this_string.first; sub_arg; sub_arg = sub_arg->next) for(String8Node *sub_val = values_in_this_string.first; sub_val; sub_val = sub_val->next)
{ {
str8_list_push(arena, &arguments, sub_arg->string); str8_list_push(arena, &values, sub_val->string);
} }
if(!str8_match(str8_postfix(n->string, 1), str8_lit(","), 0) && if(!str8_match(str8_postfix(n->string, 1), str8_lit(","), 0) &&
(n != node || arg_portion_this_string.size != 0)) (n != node || value_portion_this_string.size != 0))
{ {
break; break;
} }
} }
} }
// NOTE(rjf): Register config variable. // rjf: store
cmd_line_insert_opt(arena, &parsed, option_name, arguments); cmd_line_insert_opt(arena, &parsed, option_name, values);
} }
// NOTE(rjf): Default path, treat as a passthrough config option to be //- rjf: default path - treat as a passthrough input
// handled by tool-specific code.
else if(!str8_match(node->string, str8_lit("--"), 0) || !first_passthrough) else if(!str8_match(node->string, str8_lit("--"), 0) || !first_passthrough)
{ {
str8_list_push(arena, &parsed.inputs, node->string); str8_list_push(arena, &parsed.inputs, node->string);
after_passthrough_option = 1;
first_passthrough = 0; first_passthrough = 0;
} }
} }
// rjf: fill argc/argv //- rjf: fill argc/argv
parsed.argc = command_line.node_count; parsed.argc = command_line.node_count;
parsed.argv = push_array(arena, char *, parsed.argc); parsed.argv = push_array(arena, char *, parsed.argc);
{ {
@@ -239,12 +217,12 @@ internal B32
cmd_line_has_flag(CmdLine *cmd_line, String8 name) cmd_line_has_flag(CmdLine *cmd_line, String8 name)
{ {
CmdLineOpt *var = cmd_line_opt_from_string(cmd_line, name); CmdLineOpt *var = cmd_line_opt_from_string(cmd_line, name);
return(var != 0); return (var != 0);
} }
internal B32 internal B32
cmd_line_has_argument(CmdLine *cmd_line, String8 name) cmd_line_has_argument(CmdLine *cmd_line, String8 name)
{ {
CmdLineOpt *var = cmd_line_opt_from_string(cmd_line, name); CmdLineOpt *var = cmd_line_opt_from_string(cmd_line, name);
return(var != 0 && var->value_strings.node_count > 0); return (var != 0 && var->value_strings.node_count > 0);
} }
+2 -3
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_COMMAND_LINE_H #ifndef BASE_COMMAND_LINE_H
@@ -39,9 +39,8 @@ struct CmdLine
}; };
//////////////////////////////// ////////////////////////////////
//~ NOTE(rjf): Command Line Option Parsing //~ rjf: Command Line Parsing Functions
internal U64 cmd_line_hash_from_string(String8 string);
internal CmdLineOpt** cmd_line_slot_from_string(CmdLine *cmd_line, String8 string); internal CmdLineOpt** cmd_line_slot_from_string(CmdLine *cmd_line, String8 string);
internal CmdLineOpt* cmd_line_opt_from_slot(CmdLineOpt **slot, String8 string); internal CmdLineOpt* cmd_line_opt_from_slot(CmdLineOpt **slot, String8 string);
internal void cmd_line_push_opt(CmdLineOptList *list, CmdLineOpt *var); internal void cmd_line_push_opt(CmdLineOptList *list, CmdLineOpt *var);
+2 -2
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_CONTEXT_CRACKING_H #ifndef BASE_CONTEXT_CRACKING_H
@@ -159,7 +159,7 @@
#endif #endif
#if !defined(BUILD_VERSION_PATCH) #if !defined(BUILD_VERSION_PATCH)
# define BUILD_VERSION_PATCH 14 # define BUILD_VERSION_PATCH 24
#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)
+195 -49
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
//////////////////////////////// ////////////////////////////////
@@ -41,7 +41,7 @@ u128_zero(void)
internal U128 internal U128
u128_make(U64 v0, U64 v1) u128_make(U64 v0, U64 v1)
{ {
U128 v = {v0, v1}; U128 v = { .u64 = { v0, v1 }};
return v; return v;
} }
@@ -246,7 +246,8 @@ sign_from_side_F32(Side side){
//~ rjf: Memory Functions //~ rjf: Memory Functions
internal B32 internal B32
memory_is_zero(void *ptr, U64 size){ memory_is_zero(void *ptr, U64 size)
{
B32 result = 1; B32 result = 1;
// break down size // break down size
@@ -257,8 +258,10 @@ memory_is_zero(void *ptr, U64 size){
U64 *p64 = (U64*)ptr; U64 *p64 = (U64*)ptr;
if(result) if(result)
{ {
for (U64 i = 0; i < count8; i += 1, p64 += 1){ for(U64 i = 0; i < count8; i += 1, p64 += 1)
if (*p64 != 0){ {
if(*p64 != 0)
{
result = 0; result = 0;
goto done; goto done;
} }
@@ -269,8 +272,10 @@ memory_is_zero(void *ptr, U64 size){
if(result) if(result)
{ {
U8 *p8 = (U8*)p64; U8 *p8 = (U8*)p64;
for (U64 i = 0; i < extra; i += 1, p8 += 1){ for(U64 i = 0; i < extra; i += 1, p8 += 1)
if (*p8 != 0){ {
if(*p8 != 0)
{
result = 0; result = 0;
goto done; goto done;
} }
@@ -278,7 +283,7 @@ memory_is_zero(void *ptr, U64 size){
} }
done:; done:;
return(result); return result;
} }
//////////////////////////////// ////////////////////////////////
@@ -402,6 +407,12 @@ bit_size_from_arch(Arch arch)
return arch_bitsize; return arch_bitsize;
} }
internal U64
byte_size_from_arch(Arch arch)
{
return bit_size_from_arch(arch) / 8;
}
internal U64 internal U64
max_instruction_size_from_arch(Arch arch) max_instruction_size_from_arch(Arch arch)
{ {
@@ -409,47 +420,6 @@ max_instruction_size_from_arch(Arch arch)
return 64; return 64;
} }
internal OperatingSystem
operating_system_from_context(void){
OperatingSystem os = OperatingSystem_Null;
#if OS_WINDOWS
os = OperatingSystem_Windows;
#elif OS_LINUX
os = OperatingSystem_Linux;
#elif OS_MAC
os = OperatingSystem_Mac;
#endif
return os;
}
internal Arch
arch_from_context(void){
Arch arch = Arch_Null;
#if ARCH_X64
arch = Arch_x64;
#elif ARCH_X86
arch = Arch_x86;
#elif ARCH_ARM64
arch = Arch_arm64;
#elif ARCH_ARM32
arch = Arch_arm32;
#endif
return arch;
}
internal Compiler
compiler_from_context(void){
Compiler compiler = Compiler_Null;
#if COMPILER_MSVC
compiler = Compiler_msvc;
#elif COMPILER_GCC
compiler = Compiler_gcc;
#elif COMPILER_CLANG
compiler = Compiler_clang;
#endif
return compiler;
}
//////////////////////////////// ////////////////////////////////
//~ rjf: Time Functions //~ rjf: Time Functions
@@ -514,6 +484,60 @@ date_time_from_micro_seconds(U64 time){
return(result); return(result);
} }
internal DateTime
date_time_from_unix_time(U64 unix_time)
{
DateTime date = {0};
date.year = 1970;
date.day = 1 + (unix_time / 86400);
date.sec = (U32)unix_time % 60;
date.min = (U32)(unix_time / 60) % 60;
date.hour = (U32)(unix_time / 3600) % 24;
for(;;)
{
for(date.month = 0; date.month < 12; ++date.month)
{
U64 c = 0;
switch(date.month)
{
case Month_Jan: c = 31; break;
case Month_Feb:
{
if((date.year % 4 == 0) && ((date.year % 100) != 0 || (date.year % 400) == 0))
{
c = 29;
}
else
{
c = 28;
}
} break;
case Month_Mar: c = 31; break;
case Month_Apr: c = 30; break;
case Month_May: c = 31; break;
case Month_Jun: c = 30; break;
case Month_Jul: c = 31; break;
case Month_Aug: c = 31; break;
case Month_Sep: c = 30; break;
case Month_Oct: c = 31; break;
case Month_Nov: c = 30; break;
case Month_Dec: c = 31; break;
default: InvalidPath;
}
if(date.day <= c)
{
goto exit;
}
date.day -= c;
}
++date.year;
}
exit:;
return date;
}
//////////////////////////////// ////////////////////////////////
//~ rjf: Non-Fancy Ring Buffer Reads/Writes //~ rjf: Non-Fancy Ring Buffer Reads/Writes
@@ -548,3 +572,125 @@ ring_read(U8 *ring_base, U64 ring_size, U64 ring_pos, void *dst_data, U64 read_s
} }
return read_size; return read_size;
} }
////////////////////////////////
internal U64
u64_array_bsearch(U64 *arr, U64 count, U64 value)
{
if(count > 1 && arr[0] <= value && value < arr[count-1])
{
U64 l = 0;
U64 r = count - 1;
for(; l <= r; )
{
U64 m = l + (r - l) / 2;
if(arr[m] == value)
{
return m;
}
else if(arr[m] < value)
{
l = m + 1;
}
else
{
r = m - 1;
}
}
}
else if (count == 1 && arr[0] == value)
{
return 0;
}
return max_U64;
}
////////////////////////////////
internal U64
index_of_zero_u32(U32 *ptr, U64 count)
{
for (U64 i = 0; i < count; i += 1) {
if (ptr[i] == 0) {
return i;
}
}
return max_U64;
}
internal U64
index_of_zero_u64(U64 *ptr, U64 count)
{
for (U64 i = 0; i < count; i += 1) {
if (ptr[i] == 0) {
return i;
}
}
return max_U64;
}
////////////////////////////////
//~ rjf: Third Party Includes
#if !BUILD_SUPPLEMENTARY_UNIT
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wsign-conversion"
#elif defined(_MSC_VER)
#pragma warning (push, 0)
#endif
# define STB_SPRINTF_IMPLEMENTATION
# define STB_SPRINTF_STATIC
# include "third_party/stb/stb_sprintf.h"
#endif
#if defined(__clang__)
#pragma clang diagnostic pop
#elif defined(_MSC_VER)
#pragma warning (pop, 0)
#endif
////////////////////////////////
//~ rjf: String <-> Integer Tables
read_only global U8 integer_symbols[16] =
{
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F',
};
// NOTE(rjf): Includes reverses for uppercase and lowercase hex.
read_only global U8 integer_symbol_reverse[128] =
{
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
};
read_only global U8 base64[64] =
{
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'_', '$',
};
read_only global U8 base64_reverse[128] =
{
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0x3F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,
0xFF,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,
0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0xFF,0xFF,0xFF,0xFF,0x3E,
0xFF,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,
0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0xFF,0xFF,0xFF,0xFF,0xFF,
};
+236 -50
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_CORE_H #ifndef BASE_CORE_H
@@ -13,6 +13,13 @@
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
////////////////////////////////
//~ rjf: Third Party Includes
#define STB_SPRINTF_DECORATE(name) raddbg_##name
#define STB_SPRINTF_STATIC
#include "third_party/stb/stb_sprintf.h"
//////////////////////////////// ////////////////////////////////
//~ rjf: Codebase Keywords //~ rjf: Codebase Keywords
@@ -38,12 +45,24 @@
# define thread_static __declspec(thread) # define thread_static __declspec(thread)
#elif COMPILER_CLANG || COMPILER_GCC #elif COMPILER_CLANG || COMPILER_GCC
# define thread_static __thread # define thread_static __thread
#else
# error thread_static not defined for this compiler.
#endif #endif
#if COMPILER_MSVC #if COMPILER_MSVC
# define force_inline __forceinline # define force_inline __forceinline
#elif COMPILER_CLANG || COMPILER_GCC #elif COMPILER_CLANG || COMPILER_GCC
# define force_inline __attribute__((always_inline)) # define force_inline __attribute__((always_inline))
#else
# error force_inline not defined for this compiler.
#endif
#if COMPILER_MSVC
# define no_inline __declspec(noinline)
#elif COMPILER_CLANG || COMPILER_GCC
# define no_inline __attribute__((noinline))
#else
# error no_inline not defined for this compiler.
#endif #endif
//////////////////////////////// ////////////////////////////////
@@ -65,6 +84,45 @@
# define C_LINKAGE # define C_LINKAGE
#endif #endif
////////////////////////////////
//~ rjf: Optimization Settings
#if COMPILER_MSVC
# define OPTIMIZE_BEGIN _Pragma("optimize(\"\", on)")
# define OPTIMIZE_END _Pragma("optimize(\"\", off)")
#elif COMPILER_CLANG
# define OPTIMIZE_BEGIN _Pragma("clang optimize on")
# define OPTIMIZE_END _Pragma("clang optimize off")
#elif COMPILER_GCC
# define OPTIMIZE_BEGIN _Pragma("GCC push_options") _Pragma("GCC optimize(\"O2\")")
# define OPTIMIZE_END _Pragma("GCC pop_options")
#else
# define OPTIMIZE_BEGIN
# define OPTIMIZE_END
#endif
#if COMPILER_MSVC && !BUILD_DEBUG
# define NO_OPTIMIZE_BEGIN _Pragma("optimize(\"\", off)")
# define NO_OPTIMIZE_END _Pragma("optimize(\"\", on)")
#elif COMPILER_CLANG && !BUILD_DEBUG
# define NO_OPTIMIZE_BEGIN _Pragma("clang optimize off")
# define NO_OPTIMIZE_END _Pragma("clang optimize on")
#elif COMPILER_GCC && !BUILD_DEBUG
# define NO_OPTIMIZE_BEGIN _Pragma("GCC push_options") _Pragma("GCC optimize(\"O0\")")
# define NO_OPTIMIZE_END _Pragma("GCC pop_options")
#else
# define NO_OPTIMIZE_BEGIN
# define NO_OPTIMIZE_END
#endif
////////////////////////////////
//~ rjf: Versions
#define Version(major, minor, patch) (U64)((((U64)(major) & 0xffff) << 32) | ((((U64)(minor) & 0xffff) << 16)) | ((((U64)(patch) & 0xffff) << 0)))
#define MajorFromVersion(version) (((version) & 0xffff00000000ull) >> 32)
#define MinorFromVersion(version) (((version) & 0x0000ffff0000ull) >> 16)
#define PatchFromVersion(version) (((version) & 0x00000000ffffull) >> 0)
//////////////////////////////// ////////////////////////////////
//~ rjf: Units //~ rjf: Units
@@ -110,6 +168,14 @@
# error AlignOf not defined for this compiler. # error AlignOf not defined for this compiler.
#endif #endif
#if COMPILER_MSVC
# define AlignType(x) __declspec(align(x))
#elif COMPILER_CLANG || COMPILER_GCC
# define AlignType(x) __attribute__((aligned(x)))
#else
# error AlignType not defined for this compiler.
#endif
//////////////////////////////// ////////////////////////////////
//~ rjf: Member Offsets //~ rjf: Member Offsets
@@ -128,6 +194,8 @@
#define EachElement(it, array) (U64 it = 0; it < ArrayCount(array); it += 1) #define EachElement(it, array) (U64 it = 0; it < ArrayCount(array); it += 1)
#define EachEnumVal(type, it) (type it = (type)0; it < type##_COUNT; it = (type)(it+1)) #define EachEnumVal(type, it) (type it = (type)0; it < type##_COUNT; it = (type)(it+1))
#define EachNonZeroEnumVal(type, it) (type it = (type)1; it < type##_COUNT; it = (type)(it+1)) #define EachNonZeroEnumVal(type, it) (type it = (type)1; it < type##_COUNT; it = (type)(it+1))
#define EachInRange(it, range) (U64 it = (range).min; it < (range).max; it += 1)
#define EachNode(it, T, first) (T *it = first; it != 0; it = it->next)
//////////////////////////////// ////////////////////////////////
//~ rjf: Memory Operation Macros //~ rjf: Memory Operation Macros
@@ -140,6 +208,7 @@
#define MemoryCopyStruct(d,s) MemoryCopy((d),(s),sizeof(*(d))) #define MemoryCopyStruct(d,s) MemoryCopy((d),(s),sizeof(*(d)))
#define MemoryCopyArray(d,s) MemoryCopy((d),(s),sizeof(d)) #define MemoryCopyArray(d,s) MemoryCopy((d),(s),sizeof(d))
#define MemoryCopyTyped(d,s,c) MemoryCopy((d),(s),sizeof(*(d))*(c)) #define MemoryCopyTyped(d,s,c) MemoryCopy((d),(s),sizeof(*(d))*(c))
#define MemoryCopyStr8(dst, s) MemoryCopy(dst, (s).str, (s).size)
#define MemoryZero(s,z) memset((s),0,(z)) #define MemoryZero(s,z) memset((s),0,(z))
#define MemoryZeroStruct(s) MemoryZero((s),sizeof(*(s))) #define MemoryZeroStruct(s) MemoryZero((s),sizeof(*(s)))
@@ -150,6 +219,8 @@
#define MemoryMatchStruct(a,b) MemoryMatch((a),(b),sizeof(*(a))) #define MemoryMatchStruct(a,b) MemoryMatch((a),(b),sizeof(*(a)))
#define MemoryMatchArray(a,b) MemoryMatch((a),(b),sizeof(a)) #define MemoryMatchArray(a,b) MemoryMatch((a),(b),sizeof(a))
#define MemoryIsZeroStruct(ptr) memory_is_zero((ptr), sizeof(*(ptr)))
#define MemoryRead(T,p,e) ( ((p)+sizeof(T)<=(e))?(*(T*)(p)):(0) ) #define MemoryRead(T,p,e) ( ((p)+sizeof(T)<=(e))?(*(T*)(p)):(0) )
#define MemoryConsume(T,p,e) ( ((p)+sizeof(T)<=(e))?((p)+=sizeof(T),*(T*)((p)-sizeof(T))):((p)=(e),0) ) #define MemoryConsume(T,p,e) ( ((p)+sizeof(T)<=(e))?((p)+=sizeof(T),*(T*)((p)-sizeof(T))):((p)=(e),0) )
@@ -181,44 +252,46 @@
#if COMPILER_MSVC #if COMPILER_MSVC
# include <intrin.h> # include <intrin.h>
# if ARCH_X64 # if ARCH_X64
# define ins_atomic_u64_eval(x) *((volatile U64 *)(x)) # define ins_atomic_u128_eval_cond_assign(x,k,c) (B32)InterlockedCompareExchange128((__int64 *)(x), ((__int64 *)&(k))[1], ((__int64 *)&(k))[0], (__int64 *)c)
# define ins_atomic_u64_inc_eval(x) InterlockedIncrement64((volatile __int64 *)(x)) # define ins_atomic_u64_eval(x) *((volatile U64 *)(x))
# define ins_atomic_u64_dec_eval(x) InterlockedDecrement64((volatile __int64 *)(x)) # define ins_atomic_u64_inc_eval(x) InterlockedIncrement64((__int64 *)(x))
# define ins_atomic_u64_eval_assign(x,c) InterlockedExchange64((volatile __int64 *)(x),(c)) # define ins_atomic_u64_dec_eval(x) InterlockedDecrement64((__int64 *)(x))
# define ins_atomic_u64_add_eval(x,c) InterlockedAdd64((volatile __int64 *)(x), c) # define ins_atomic_u64_eval_assign(x,c) InterlockedExchange64((__int64 *)(x),(c))
# define ins_atomic_u64_eval_cond_assign(x,k,c) InterlockedCompareExchange64((volatile __int64 *)(x),(k),(c)) # define ins_atomic_u64_add_eval(x,c) InterlockedAdd64((__int64 *)(x), c)
# define ins_atomic_u32_eval(x) *((volatile U32 *)(x)) # define ins_atomic_u64_eval_cond_assign(x,k,c) InterlockedCompareExchange64((__int64 *)(x),(k),(c))
# define ins_atomic_u32_inc_eval(x) InterlockedIncrement((volatile LONG *)x) # 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((LONG *)(x))
# define ins_atomic_u32_eval_cond_assign(x,k,c) InterlockedCompareExchange((volatile LONG *)(x),(k),(c)) # define ins_atomic_u32_dec_eval(x) InterlockedDecrement((LONG *)(x))
# define ins_atomic_u32_add_eval(x,c) InterlockedAdd((volatile LONG *)(x), c) # define ins_atomic_u32_eval_assign(x,c) InterlockedExchange((LONG *)(x),(c))
# define ins_atomic_u32_eval_cond_assign(x,k,c) InterlockedCompareExchange((LONG *)(x),(k),(c))
# define ins_atomic_u32_add_eval(x,c) InterlockedAdd((LONG *)(x), (c))
# define ins_atomic_u8_eval_assign(x,c) InterlockedExchange8((CHAR *)(x), (c))
# else # else
# error Atomic intrinsics not defined for this compiler / architecture combination. # error Atomic intrinsics not defined for this compiler / architecture combination.
# endif # endif
#elif COMPILER_CLANG || COMPILER_GCC #elif COMPILER_CLANG || COMPILER_GCC
# define ins_atomic_u64_eval(x) __atomic_load_n(x, __ATOMIC_SEQ_CST) # define ins_atomic_u128_eval_cond_assign(x,k,c) (B32)__atomic_compare_exchange_n((__int128 *)(x),(__int128 *)(c),*(__int128 *)(k),0,__ATOMIC_SEQ_CST,__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_eval(x) __atomic_load_n(x, __ATOMIC_SEQ_CST)
# define ins_atomic_u64_dec_eval(x) (__atomic_fetch_sub((volatile U64 *)(x), 1, __ATOMIC_SEQ_CST) - 1) # define ins_atomic_u64_inc_eval(x) (__atomic_fetch_add((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_dec_eval(x) (__atomic_fetch_sub((U64 *)(x), 1, __ATOMIC_SEQ_CST) - 1)
# define ins_atomic_u64_add_eval(x,c) (__atomic_fetch_add((volatile U64 *)(x), c, __ATOMIC_SEQ_CST) + (c)) # define ins_atomic_u64_eval_assign(x,c) __atomic_exchange_n(x, c, __ATOMIC_SEQ_CST)
# 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_u64_add_eval(x,c) (__atomic_fetch_add((U64 *)(x), c, __ATOMIC_SEQ_CST) + (c))
# define ins_atomic_u32_eval(x) __atomic_load_n(x, __ATOMIC_SEQ_CST) # define ins_atomic_u64_eval_cond_assign(x,k,c) ({ U64 _new = (c); __atomic_compare_exchange_n((U64 *)(x),&_new,(k),0,__ATOMIC_SEQ_CST,__ATOMIC_SEQ_CST); _new; })
# define ins_atomic_u32_inc_eval(x) (__atomic_fetch_add((volatile U32 *)(x), 1, __ATOMIC_SEQ_CST) + 1) # define ins_atomic_u32_eval(x) __atomic_load_n(x, __ATOMIC_SEQ_CST)
# define ins_atomic_u32_add_eval(x,c) (__atomic_fetch_add((volatile U32 *)(x), c, __ATOMIC_SEQ_CST) + (c)) # define ins_atomic_u32_inc_eval(x) (__atomic_fetch_add((U32 *)(x), 1, __ATOMIC_SEQ_CST) + 1)
# define ins_atomic_u32_eval_assign(x,c) __atomic_exchange_n(x, c, __ATOMIC_SEQ_CST) # define ins_atomic_u32_dec_eval(x) (__atomic_fetch_sub((U32 *)(x), 1, __ATOMIC_SEQ_CST) - 1)
# 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; }) # define ins_atomic_u32_add_eval(x,c) (__atomic_fetch_add((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((U32 *)(x),&_new,(k),0,__ATOMIC_SEQ_CST,__ATOMIC_SEQ_CST); _new; })
# define ins_atomic_u8_eval_assign(x,c) __atomic_exchange_n((x), (c), __ATOMIC_SEQ_CST)
#else #else
# error Atomic intrinsics not defined for this compiler / architecture. # error Atomic intrinsics not defined for this compiler / architecture.
#endif #endif
#if ARCH_64BIT #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_cond_assign(x,k,c) (void *)ins_atomic_u64_eval_cond_assign((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_assign(x,c) (void *)ins_atomic_u64_eval_assign((U64 *)(x), (U64)(c))
# define ins_atomic_ptr_eval(x) (void*)ins_atomic_u64_eval((volatile U64 *)x) # define ins_atomic_ptr_eval(x) (void *)ins_atomic_u64_eval((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 #else
# error Atomic intrinsics for pointers not defined for this architecture. # error Atomic intrinsics for pointers not defined for this architecture.
#endif #endif
@@ -306,7 +379,6 @@ CheckNil(nil,p) ? \
#endif #endif
#if ASAN_ENABLED #if ASAN_ENABLED
#pragma comment(lib, "clang_rt.asan-x86_64.lib")
C_LINKAGE void __asan_poison_memory_region(void const volatile *addr, size_t size); C_LINKAGE void __asan_poison_memory_region(void const volatile *addr, size_t size);
C_LINKAGE void __asan_unpoison_memory_region(void const volatile *addr, size_t size); C_LINKAGE void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
# define AsanPoisonMemoryRegion(addr, size) __asan_poison_memory_region((addr), (size)) # define AsanPoisonMemoryRegion(addr, size) __asan_poison_memory_region((addr), (size))
@@ -338,9 +410,10 @@ C_LINKAGE void __asan_unpoison_memory_region(void const volatile *addr, size_t s
#else #else
# error Missing pointer-to-integer cast for this architecture. # error Missing pointer-to-integer cast for this architecture.
#endif #endif
#define PtrFromInt(i) (void*)((U8*)0 + (i)) #define PtrFromInt(i) (void*)(i)
#define Compose64Bit(a,b) ((((U64)a) << 32) | ((U64)b)); #define Compose64Bit(a,b) ((((U64)a) << 32) | ((U64)b))
#define Compose32Bit(a,b) ((((U32)a) << 16) | ((U32)b))
#define AlignPow2(x,b) (((x) + (b) - 1)&(~((b) - 1))) #define AlignPow2(x,b) (((x) + (b) - 1)&(~((b) - 1)))
#define AlignDownPow2(x,b) ((x)&(~((b) - 1))) #define AlignDownPow2(x,b) ((x)&(~((b) - 1)))
#define AlignPadPow2(x,b) ((0-(x)) & ((b) - 1)) #define AlignPadPow2(x,b) ((0-(x)) & ((b) - 1))
@@ -348,6 +421,9 @@ C_LINKAGE void __asan_unpoison_memory_region(void const volatile *addr, size_t s
#define IsPow2OrZero(x) ((((x) - 1)&(x)) == 0) #define IsPow2OrZero(x) ((((x) - 1)&(x)) == 0)
#define ExtractBit(word, idx) (((word) >> (idx)) & 1) #define ExtractBit(word, idx) (((word) >> (idx)) & 1)
#define Extract8(word, pos) (((word) >> ((pos)*8)) & max_U8)
#define Extract16(word, pos) (((word) >> ((pos)*16)) & max_U16)
#define Extract32(word, pos) (((word) >> ((pos)*32)) & max_U32)
#if LANG_CPP #if LANG_CPP
# define zero_struct {} # define zero_struct {}
@@ -379,11 +455,64 @@ typedef S64 B64;
typedef float F32; typedef float F32;
typedef double F64; typedef double F64;
typedef void VoidProc(void); typedef void VoidProc(void);
typedef struct U128 U128; typedef union U128 U128;
struct U128 union U128
{ {
U8 u8[16];
U16 u16[8];
U32 u32[4];
U64 u64[2]; U64 u64[2];
}; };
typedef union U256 U256;
union U256
{
U8 u8[32];
U16 u16[16];
U32 u32[8];
U64 u64[4];
U128 u128[2];
};
typedef union U512 U512;
union U512
{
U8 u8[64];
U16 u16[32];
U32 u32[16];
U64 u64[8];
U128 u128[4];
U256 u256[2];
};
////////////////////////////////
//~ rjf: Basic Type Structures
typedef struct U16Array U16Array;
struct U16Array
{
U64 count;
U16 *v;
};
typedef struct U32Array U32Array;
struct U32Array
{
U64 count;
U32 *v;
};
typedef struct U64Array U64Array;
struct U64Array
{
U64 count;
U64 *v;
};
typedef struct U128Array U128Array;
struct U128Array
{
U64 count;
U128 *v;
};
//////////////////////////////// ////////////////////////////////
//~ rjf: Basic Types & Spaces //~ rjf: Basic Types & Spaces
@@ -451,9 +580,29 @@ typedef enum OperatingSystem
OperatingSystem_Linux, OperatingSystem_Linux,
OperatingSystem_Mac, OperatingSystem_Mac,
OperatingSystem_COUNT, OperatingSystem_COUNT,
#if OS_WINDOWS
OperatingSystem_CURRENT = OperatingSystem_Windows,
#elif OS_LINUX
OperatingSystem_CURRENT = OperatingSystem_Linux,
#elif OS_MAC
OperatingSystem_CURRENT = OperatingSystem_Mac,
#else
OperatingSystem_CURRENT = OperatingSystem_Null,
#endif
} }
OperatingSystem; OperatingSystem;
typedef enum ExecutableImageKind
{
ExecutableImageKind_Null,
ExecutableImageKind_CoffPe,
ExecutableImageKind_Elf32,
ExecutableImageKind_Elf64,
ExecutableImageKind_Macho,
ExecutableImageKind_COUNT
}
ExecutableImageKind;
typedef enum Arch typedef enum Arch
{ {
Arch_Null, Arch_Null,
@@ -462,6 +611,17 @@ typedef enum Arch
Arch_arm64, Arch_arm64,
Arch_arm32, Arch_arm32,
Arch_COUNT, Arch_COUNT,
#if ARCH_X64
Arch_CURRENT = Arch_x64,
#elif ARCH_X86
Arch_CURRENT = Arch_x86,
#elif ARCH_ARM64
Arch_CURRENT = Arch_arm64,
#elif ARCH_ARM32
Arch_CURRENT = Arch_arm32,
#else
Arch_CURRENT = Arch_Null,
#endif
} }
Arch; Arch;
@@ -472,6 +632,15 @@ typedef enum Compiler
Compiler_gcc, Compiler_gcc,
Compiler_clang, Compiler_clang,
Compiler_COUNT, Compiler_COUNT,
#if COMPILER_MSVC
Compiler_CURRENT = Compiler_msvc,
#elif COMPILER_GCC
Compiler_CURRENT = Compiler_gcc,
#elif COMPILER_CLANG
Compiler_CURRENT = Compiler_clang,
#else
Compiler_CURRENT = Compiler_Null,
#endif
} }
Compiler; Compiler;
@@ -493,7 +662,7 @@ struct TxtRng
}; };
//////////////////////////////// ////////////////////////////////
//~ Globally Unique Ids //~ rjf: Globally Unique Ids
typedef union Guid Guid; typedef union Guid Guid;
union Guid union Guid
@@ -510,7 +679,7 @@ union Guid
StaticAssert(sizeof(Guid) == 16, g_guid_size_check); StaticAssert(sizeof(Guid) == 16, g_guid_size_check);
//////////////////////////////// ////////////////////////////////
//~ NOTE(allen): Constants //~ rjf: Basic Constants
global U32 sign32 = 0x80000000; global U32 sign32 = 0x80000000;
global U32 exponent32 = 0x7F800000; global U32 exponent32 = 0x7F800000;
@@ -528,15 +697,15 @@ global U32 max_U32 = 0xffffffff;
global U16 max_U16 = 0xffff; global U16 max_U16 = 0xffff;
global U8 max_U8 = 0xff; global U8 max_U8 = 0xff;
global S64 max_S64 = (S64)0x7fffffffffffffffull; global S64 max_S64 = (S64)0x7fffffffffffffffll;
global S32 max_S32 = (S32)0x7fffffff; global S32 max_S32 = (S32)0x7fffffff;
global S16 max_S16 = (S16)0x7fff; global S16 max_S16 = (S16)0x7fff;
global S8 max_S8 = (S8)0x7f; global S8 max_S8 = (S8)0x7f;
global S64 min_S64 = (S64)0xffffffffffffffffull; global S64 min_S64 = (S64)0x8000000000000000ll;
global S32 min_S32 = (S32)0xffffffff; global S32 min_S32 = (S32)0x80000000;
global S16 min_S16 = (S16)0xffff; global S16 min_S16 = (S16)0x8000;
global S8 min_S8 = (S8)0xff; global S8 min_S8 = (S8)0x80;
global const U32 bitmask1 = 0x00000001; global const U32 bitmask1 = 0x00000001;
global const U32 bitmask2 = 0x00000003; global const U32 bitmask2 = 0x00000003;
@@ -671,7 +840,7 @@ global const U64 bit63 = (1ull<<62);
global const U64 bit64 = (1ull<<63); global const U64 bit64 = (1ull<<63);
//////////////////////////////// ////////////////////////////////
//~ allen: Time //~ rjf: Time Types
typedef enum WeekDay typedef enum WeekDay
{ {
@@ -729,7 +898,7 @@ struct DateTime
typedef U64 DenseTime; typedef U64 DenseTime;
//////////////////////////////// ////////////////////////////////
//~ allen: Files //~ rjf: File Types
typedef U32 FilePropertyFlags; typedef U32 FilePropertyFlags;
enum enum
@@ -775,6 +944,16 @@ 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);
#if ARCH_LITTLE_ENDIAN
# define from_be_u16(x) bswap_u16(x)
# define from_be_u32(x) bswap_u32(x)
# define from_be_u64(x) bswap_u64(x)
#else
# define from_be_u16(x) (x)
# define from_be_u32(x) (x)
# define from_be_u64(x) (x)
#endif
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);
@@ -811,18 +990,16 @@ internal B32 txt_rng_contains(TxtRng r, TxtPt pt);
//~ rjf: Toolchain/Environment Enum Functions //~ rjf: Toolchain/Environment Enum Functions
internal U64 bit_size_from_arch(Arch arch); internal U64 bit_size_from_arch(Arch arch);
internal U64 byte_size_from_arch(Arch arch);
internal U64 max_instruction_size_from_arch(Arch arch); internal U64 max_instruction_size_from_arch(Arch arch);
internal OperatingSystem operating_system_from_context(void);
internal Arch arch_from_context(void);
internal Compiler compiler_from_context(void);
//////////////////////////////// ////////////////////////////////
//~ rjf: Time Functions //~ rjf: Time Functions
internal DenseTime dense_time_from_date_time(DateTime date_time); internal DenseTime dense_time_from_date_time(DateTime date_time);
internal DateTime date_time_from_dense_time(DenseTime time); internal DateTime date_time_from_dense_time(DenseTime time);
internal DateTime date_time_from_micro_seconds(U64 time); internal DateTime date_time_from_micro_seconds(U64 time);
internal DateTime date_time_from_unix_time(U64 unix_time);
//////////////////////////////// ////////////////////////////////
//~ rjf: Non-Fancy Ring Buffer Reads/Writes //~ rjf: Non-Fancy Ring Buffer Reads/Writes
@@ -837,4 +1014,13 @@ internal U64 ring_read(U8 *ring_base, U64 ring_size, U64 ring_pos, void *dst_dat
#define quick_sort(ptr, count, element_size, cmp_function) qsort((ptr), (count), (element_size), (int (*)(const void *, const void *))(cmp_function)) #define quick_sort(ptr, count, element_size, cmp_function) qsort((ptr), (count), (element_size), (int (*)(const void *, const void *))(cmp_function))
////////////////////////////////
internal U64 u64_array_bsearch(U64 *arr, U64 count, U64 value);
////////////////////////////////
internal U64 index_of_zero_u32(U32 *ptr, U64 count);
internal U64 index_of_zero_u64(U64 *ptr, U64 count);
#endif // BASE_CORE_H #endif // BASE_CORE_H
+134 -30
View File
@@ -1,13 +1,26 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) 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; global U64 global_update_tick_idx = 0;
global U64 async_threads_count = 0;
global CondVar async_tick_start_cond_var = {0};
global Mutex async_tick_start_mutex = {0};
global Mutex async_tick_stop_mutex = {0};
global B32 async_loop_again = 0;
global B32 async_loop_again_high_priority = 0;
global B32 global_async_exit = 0;
thread_static B32 is_async_thread = 0;
internal void internal void
main_thread_base_entry_point(int arguments_count, char **arguments) main_thread_base_entry_point(int arguments_count, char **arguments)
{ {
ThreadNameF("main_thread");
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
ThreadNameF("[main thread]");
//- rjf: set up async thread group info
async_tick_start_cond_var = cond_var_alloc();
async_tick_start_mutex = mutex_alloc();
async_tick_stop_mutex = mutex_alloc();
//- rjf: set up telemetry //- rjf: set up telemetry
#if PROFILE_TELEMETRY #if PROFILE_TELEMETRY
@@ -17,8 +30,19 @@ main_thread_base_entry_point(int arguments_count, char **arguments)
tmInitialize(sizeof(tm_data), tm_data); tmInitialize(sizeof(tm_data), tm_data);
#endif #endif
//- rjf: set up spall
#if PROFILE_SPALL
spall_profile = spall_init_file_ex("spall_capture", 1, 0);
#endif
//- rjf: parse command line //- rjf: parse command line
String8List command_line_argument_strings = os_string_list_from_argcv(scratch.arena, arguments_count, arguments); String8List command_line_argument_strings = {0};
{
for EachIndex(idx, arguments_count)
{
str8_list_push(scratch.arena, &command_line_argument_strings, str8_cstring(arguments[idx]));
}
}
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,36 +50,27 @@ main_thread_base_entry_point(int arguments_count, char **arguments)
if(capture) if(capture)
{ {
ProfBeginCapture(arguments[0]); ProfBeginCapture(arguments[0]);
ProfMsg(BUILD_TITLE);
} }
#if PROFILE_TELEMETRY
tmMessage(0, TMMF_ICON_NOTE, BUILD_TITLE);
#endif
//- rjf: initialize all included layers //- rjf: initialize all included layers
#if defined(ARTIFACT_CACHE_H) && !defined(AC_INIT_MANUAL)
ac_init();
#endif
#if defined(ASYNC_H) && !defined(ASYNC_INIT_MANUAL) #if defined(ASYNC_H) && !defined(ASYNC_INIT_MANUAL)
async_init(); async_init(&cmdline);
#endif #endif
#if defined(RDI_FROM_PDB_H) && !defined(P2R_INIT_MANUAL) #if defined(CONTENT_H) && !defined(C_INIT_MANUAL)
p2r_init(); c_init();
#endif
#if defined(HASH_STORE_H) && !defined(HS_INIT_MANUAL)
hs_init();
#endif #endif
#if defined(FILE_STREAM_H) && !defined(FS_INIT_MANUAL) #if defined(FILE_STREAM_H) && !defined(FS_INIT_MANUAL)
fs_init(); fs_init();
#endif #endif
#if defined(TEXT_CACHE_H) && !defined(TXT_INIT_MANUAL)
txt_init();
#endif
#if defined(MUTABLE_TEXT_H) && !defined(MTX_INIT_MANUAL) #if defined(MUTABLE_TEXT_H) && !defined(MTX_INIT_MANUAL)
mtx_init(); mtx_init();
#endif #endif
#if defined(DASM_CACHE_H) && !defined(DASM_INIT_MANUAL) #if defined(DBG_INFO_H) && !defined(DI_INIT_MANUAL)
dasm_init(); di_init(&cmdline);
#endif
#if defined(DBGI_H) && !defined(DI_INIT_MANUAL)
di_init();
#endif #endif
#if defined(DEMON_CORE_H) && !defined(DMN_INIT_MANUAL) #if defined(DEMON_CORE_H) && !defined(DMN_INIT_MANUAL)
dmn_init(); dmn_init();
@@ -72,12 +87,6 @@ main_thread_base_entry_point(int arguments_count, char **arguments)
#if defined(RENDER_CORE_H) && !defined(R_INIT_MANUAL) #if defined(RENDER_CORE_H) && !defined(R_INIT_MANUAL)
r_init(&cmdline); r_init(&cmdline);
#endif #endif
#if defined(TEXTURE_CACHE_H) && !defined(TEX_INIT_MANUAL)
tex_init();
#endif
#if defined(GEO_CACHE_H) && !defined(GEO_INIT_MANUAL)
geo_init();
#endif
#if defined(FONT_CACHE_H) && !defined(FNT_INIT_MANUAL) #if defined(FONT_CACHE_H) && !defined(FNT_INIT_MANUAL)
fnt_init(); fnt_init();
#endif #endif
@@ -88,9 +97,48 @@ main_thread_base_entry_point(int arguments_count, char **arguments)
rd_init(&cmdline); rd_init(&cmdline);
#endif #endif
//- rjf: launch async threads
Thread *async_threads = 0;
U64 lane_broadcast_val = 0;
{
U64 num_main_threads = 1;
#if defined(CTRL_CORE_H)
num_main_threads += 1;
#endif
U64 num_async_threads = os_get_system_info()->logical_processor_count;
U64 num_main_threads_clamped = Min(num_async_threads, num_main_threads);
num_async_threads -= num_main_threads_clamped;
String8 num_async_threads_string = cmd_line_string(&cmdline, str8_lit("async_thread_count"));
if(num_async_threads_string.size != 0)
{
try_u64_from_str8_c_rules(num_async_threads_string, &num_async_threads);
}
num_async_threads = Max(1, num_async_threads);
Barrier barrier = barrier_alloc(num_async_threads);
LaneCtx *lane_ctxs = push_array(scratch.arena, LaneCtx, num_async_threads);
async_threads_count = num_async_threads;
async_threads = push_array(scratch.arena, Thread, async_threads_count);
for EachIndex(idx, num_async_threads)
{
lane_ctxs[idx].lane_idx = idx;
lane_ctxs[idx].lane_count = async_threads_count;
lane_ctxs[idx].barrier = barrier;
lane_ctxs[idx].broadcast_memory = &lane_broadcast_val;
async_threads[idx] = thread_launch(async_thread_entry_point, &lane_ctxs[idx]);
}
}
//- rjf: call into entry point //- rjf: call into entry point
entry_point(&cmdline); entry_point(&cmdline);
//- rjf: join async threads
ins_atomic_u32_inc_eval(&global_async_exit);
cond_var_broadcast(async_tick_start_cond_var);
for EachIndex(idx, async_threads_count)
{
thread_join(async_threads[idx], max_U64);
}
//- rjf: end captures //- rjf: end captures
if(capture) if(capture)
{ {
@@ -103,10 +151,10 @@ main_thread_base_entry_point(int arguments_count, char **arguments)
internal void internal void
supplement_thread_base_entry_point(void (*entry_point)(void *params), void *params) supplement_thread_base_entry_point(void (*entry_point)(void *params), void *params)
{ {
TCTX tctx; TCTX *tctx = tctx_alloc();
tctx_init_and_equip(&tctx); tctx_select(tctx);
entry_point(params); entry_point(params);
tctx_release(); tctx_release(tctx);
} }
internal U64 internal U64
@@ -121,6 +169,9 @@ update(void)
{ {
ProfTick(0); ProfTick(0);
ins_atomic_u64_inc_eval(&global_update_tick_idx); ins_atomic_u64_inc_eval(&global_update_tick_idx);
#if defined(FONT_CACHE_H)
fnt_frame();
#endif
#if OS_FEATURE_GRAPHICAL #if OS_FEATURE_GRAPHICAL
B32 result = frame(); B32 result = frame();
#else #else
@@ -128,3 +179,56 @@ update(void)
#endif #endif
return result; return result;
} }
internal void
async_thread_entry_point(void *params)
{
LaneCtx lctx = *(LaneCtx *)params;
lane_ctx(lctx);
is_async_thread = 1;
ThreadNameF("async_thread_%I64u", lane_idx());
for(;;)
{
// rjf: wait for signal if we need, otherwise reset loop signal & continue
if(lane_idx() == 0)
{
if(!ins_atomic_u32_eval(&async_loop_again))
{
MutexScope(async_tick_start_mutex) cond_var_wait(async_tick_start_cond_var, async_tick_start_mutex, os_now_microseconds()+1000000);
}
ins_atomic_u32_eval_assign(&async_loop_again, 0);
ins_atomic_u32_eval_assign(&async_loop_again_high_priority, 0);
}
lane_sync();
// rjf: do all ticks for all layers
ProfScope("async tick")
{
#if defined(ARTIFACT_CACHE_H)
ac_async_tick();
#endif
#if defined(CONTENT_H)
c_async_tick();
#endif
#if defined(FILE_STREAM_H)
fs_async_tick();
#endif
#if defined(DBG_INFO_H)
di_async_tick();
#endif
}
// rjf: take exit signal; break if set
lane_sync();
B32 need_exit = 0;
if(lane_idx() == 0)
{
need_exit = ins_atomic_u32_eval(&global_async_exit);
}
lane_sync_u64(&need_exit, 0);
if(need_exit)
{
break;
}
}
}
+2 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_ENTRY_POINT_H #ifndef BASE_ENTRY_POINT_H
@@ -8,5 +8,6 @@ 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 U64 update_tick_idx(void);
internal B32 update(void); internal B32 update(void);
internal void async_thread_entry_point(void *params);
#endif // BASE_ENTRY_POINT_H #endif // BASE_ENTRY_POINT_H
+50
View File
@@ -0,0 +1,50 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: MD5
#include "third_party/martins_hash/md5.h"
internal MD5
md5_from_data(String8 data)
{
md5_ctx ctx = {0};
md5_init(&ctx);
md5_update(&ctx, (void*)data.str, data.size);
MD5 result = {0};
md5_finish(&ctx, result.u8);
return result;
}
////////////////////////////////
//~ rjf: SHA
#include "third_party/martins_hash/sha1.h"
#include "third_party/martins_hash/sha256.h"
internal SHA1
sha1_from_data(String8 data)
{
SHA1 result = {0};
{
sha1_ctx ctx = {0};
sha1_init(&ctx);
sha1_update(&ctx, data.str, data.size);
sha1_finish(&ctx, result.u8);
}
return result;
}
internal SHA256
sha256_from_data(String8 data)
{
SHA256 result = {0};
{
sha256_ctx ctx = {0};
sha256_init(&ctx);
sha256_update(&ctx, data.str, data.size);
sha256_finish(&ctx, result.u8);
}
return result;
}
+48
View File
@@ -0,0 +1,48 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_HASH_H
#define BASE_HASH_H
////////////////////////////////
//~ rjf: Hash Result Types
typedef union MD5 MD5;
union MD5
{
U8 u8[16];
U16 u16[8];
U32 u32[4];
U64 u64[2];
U128 u128;
};
typedef union SHA1 SHA1;
union SHA1
{
U8 u8[20];
};
typedef union SHA256 SHA256;
union SHA256
{
U8 u8[32];
U16 u16[16];
U32 u32[8];
U64 u64[4];
U128 u128[2];
U256 u256;
};
////////////////////////////////
//~ rjf: MD5
internal MD5 md5_from_data(String8 data);
////////////////////////////////
//~ rjf: SHA
internal SHA1 sha1_from_data(String8 data);
internal SHA256 sha256_from_data(String8 data);
#endif // BASE_HASH_H
+5 -3
View File
@@ -1,17 +1,19 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
//////////////////////////////// ////////////////////////////////
//~ rjf: Base Includes //~ rjf: Base Includes
#undef MARKUP_LAYER_COLOR #undef LAYER_COLOR
#define MARKUP_LAYER_COLOR 0.20f, 0.60f, 0.80f #define LAYER_COLOR 0x3399ccff
#include "base_core.c" #include "base_core.c"
#include "base_profile.c" #include "base_profile.c"
#include "base_arena.c" #include "base_arena.c"
#include "base_math.c" #include "base_math.c"
#include "base_strings.c" #include "base_strings.c"
#include "base_hash.c"
#include "base_threads.c"
#include "base_thread_context.c" #include "base_thread_context.c"
#include "base_command_line.c" #include "base_command_line.c"
#include "base_markup.c" #include "base_markup.c"
+3 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_INC_H #ifndef BASE_INC_H
@@ -14,6 +14,8 @@
#include "base_arena.h" #include "base_arena.h"
#include "base_math.h" #include "base_math.h"
#include "base_strings.h" #include "base_strings.h"
#include "base_hash.h"
#include "base_threads.h"
#include "base_thread_context.h" #include "base_thread_context.h"
#include "base_command_line.h" #include "base_command_line.h"
#include "base_markup.h" #include "base_markup.h"
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
//////////////////////////////// ////////////////////////////////
+6 -6
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_LOG_H #ifndef BASE_LOG_H
@@ -48,13 +48,13 @@ internal void log_select(Log *log);
internal void log_msg(LogMsgKind kind, String8 string); internal void log_msg(LogMsgKind kind, String8 string);
internal void log_msgf(LogMsgKind kind, char *fmt, ...); internal void log_msgf(LogMsgKind kind, char *fmt, ...);
#define log_info(s) log_msg(LogMsgKind_Info, (s)) #define log_info(s) log_msg(LogMsgKind_Info, (s))
#define log_infof(fmt, ...) log_msgf(LogMsgKind_Info, (fmt), __VA_ARGS__) #define log_infof(...) log_msgf(LogMsgKind_Info, __VA_ARGS__)
#define log_user_error(s) log_msg(LogMsgKind_UserError, (s)) #define log_user_error(s) log_msg(LogMsgKind_UserError, (s))
#define log_user_errorf(fmt, ...) log_msgf(LogMsgKind_UserError, (fmt), __VA_ARGS__) #define log_user_errorf(...) log_msgf(LogMsgKind_UserError, __VA_ARGS__)
#define LogInfoNamedBlock(s) DeferLoop(log_infof("%S:\n{\n", (s)), log_infof("}\n")) #define LogInfoNamedBlock(s) DeferLoop(log_infof("%S:\n{\n", (s)), log_infof("}\n"))
#define LogInfoNamedBlockF(fmt, ...) DeferLoop((log_infof(fmt, __VA_ARGS__), log_infof(":\n{\n")), log_infof("}\n")) #define LogInfoNamedBlockF(...) DeferLoop((log_infof(__VA_ARGS__), log_infof(":\n{\n")), log_infof("}\n"))
//////////////////////////////// ////////////////////////////////
//~ rjf: Log Scopes //~ rjf: Log Scopes
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
internal void internal void
+13 -3
View File
@@ -1,12 +1,22 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_MARKUP_H #ifndef BASE_MARKUP_H
#define BASE_MARKUP_H #define BASE_MARKUP_H
#define RADDBG_MARKUP_IMPLEMENTATION
#define RADDBG_MARKUP_VSNPRINTF raddbg_vsnprintf
#if OS_LINUX
# define RADDBG_MARKUP_STUBS
#endif
#include "lib_raddbg_markup/raddbg_markup.h"
#if !defined(LAYER_COLOR)
# define LAYER_COLOR 0x404040ff
#endif
internal void set_thread_name(String8 string); internal void set_thread_name(String8 string);
internal void set_thread_namef(char *fmt, ...); internal void set_thread_namef(char *fmt, ...);
#define ThreadNameF(...) (set_thread_namef(__VA_ARGS__)) #define ThreadNameF(...) (set_thread_namef(__VA_ARGS__), raddbg_thread_color_u32(LAYER_COLOR))
#define ThreadName(str) (set_thread_name(str))
#endif // BASE_MARKUP_H #endif // BASE_MARKUP_H
+237 -23
View File
@@ -1,8 +1,8 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
//////////////////////////////// ////////////////////////////////
//~ rjf: Scalar Ops //~ rjf: Scalar Math Ops
internal F32 internal F32
mix_1f32(F32 a, F32 b, F32 t) mix_1f32(F32 a, F32 b, F32 t)
@@ -42,7 +42,6 @@ internal Vec2S64 scale_2s64(Vec2S64 v, S64 s) {Vec2S64 c = {v.
internal S64 dot_2s64(Vec2S64 a, Vec2S64 b) {S64 c = a.x*b.x + a.y*b.y; return c;} internal S64 dot_2s64(Vec2S64 a, Vec2S64 b) {S64 c = a.x*b.x + a.y*b.y; return c;}
internal S64 length_squared_2s64(Vec2S64 v) {S64 c = v.x*v.x + v.y*v.y; return c;} internal S64 length_squared_2s64(Vec2S64 v) {S64 c = v.x*v.x + v.y*v.y; return c;}
internal S64 length_2s64(Vec2S64 v) {S64 c = (S64)sqrt_f64((F64)(v.x*v.x + v.y*v.y)); return c;} internal S64 length_2s64(Vec2S64 v) {S64 c = (S64)sqrt_f64((F64)(v.x*v.x + v.y*v.y)); return c;}
internal Vec2S64 normalize_2s64(Vec2S64 v) {v = scale_2s64(v, (S64)(1.f/length_2s64(v))); return v;}
internal Vec2S64 mix_2s64(Vec2S64 a, Vec2S64 b, F32 t) {Vec2S64 c = {(S64)mix_1f32((F32)a.x, (F32)b.x, t), (S64)mix_1f32((F32)a.y, (F32)b.y, t)}; return c;} internal Vec2S64 mix_2s64(Vec2S64 a, Vec2S64 b, F32 t) {Vec2S64 c = {(S64)mix_1f32((F32)a.x, (F32)b.x, t), (S64)mix_1f32((F32)a.y, (F32)b.y, t)}; return c;}
internal Vec2S32 vec_2s32(S32 x, S32 y) {Vec2S32 v = {x, y}; return v;} internal Vec2S32 vec_2s32(S32 x, S32 y) {Vec2S32 v = {x, y}; return v;}
@@ -54,7 +53,6 @@ internal Vec2S32 scale_2s32(Vec2S32 v, S32 s) {Vec2S32 c = {v.
internal S32 dot_2s32(Vec2S32 a, Vec2S32 b) {S32 c = a.x*b.x + a.y*b.y; return c;} internal S32 dot_2s32(Vec2S32 a, Vec2S32 b) {S32 c = a.x*b.x + a.y*b.y; return c;}
internal S32 length_squared_2s32(Vec2S32 v) {S32 c = v.x*v.x + v.y*v.y; return c;} internal S32 length_squared_2s32(Vec2S32 v) {S32 c = v.x*v.x + v.y*v.y; return c;}
internal S32 length_2s32(Vec2S32 v) {S32 c = (S32)sqrt_f32((F32)v.x*(F32)v.x + (F32)v.y*(F32)v.y); return c;} internal S32 length_2s32(Vec2S32 v) {S32 c = (S32)sqrt_f32((F32)v.x*(F32)v.x + (F32)v.y*(F32)v.y); return c;}
internal Vec2S32 normalize_2s32(Vec2S32 v) {v = scale_2s32(v, (S32)(1.f/length_2s32(v))); return v;}
internal Vec2S32 mix_2s32(Vec2S32 a, Vec2S32 b, F32 t) {Vec2S32 c = {(S32)mix_1f32((F32)a.x, (F32)b.x, t), (S32)mix_1f32((F32)a.y, (F32)b.y, t)}; return c;} internal Vec2S32 mix_2s32(Vec2S32 a, Vec2S32 b, F32 t) {Vec2S32 c = {(S32)mix_1f32((F32)a.x, (F32)b.x, t), (S32)mix_1f32((F32)a.y, (F32)b.y, t)}; return c;}
internal Vec2S16 vec_2s16(S16 x, S16 y) {Vec2S16 v = {x, y}; return v;} internal Vec2S16 vec_2s16(S16 x, S16 y) {Vec2S16 v = {x, y}; return v;}
@@ -66,7 +64,6 @@ internal Vec2S16 scale_2s16(Vec2S16 v, S16 s) {Vec2S16 c = {(S
internal S16 dot_2s16(Vec2S16 a, Vec2S16 b) {S16 c = a.x*b.x + a.y*b.y; return c;} internal S16 dot_2s16(Vec2S16 a, Vec2S16 b) {S16 c = a.x*b.x + a.y*b.y; return c;}
internal S16 length_squared_2s16(Vec2S16 v) {S16 c = v.x*v.x + v.y*v.y; return c;} internal S16 length_squared_2s16(Vec2S16 v) {S16 c = v.x*v.x + v.y*v.y; return c;}
internal S16 length_2s16(Vec2S16 v) {S16 c = (S16)sqrt_f32((F32)(v.x*v.x + v.y*v.y)); return c;} internal S16 length_2s16(Vec2S16 v) {S16 c = (S16)sqrt_f32((F32)(v.x*v.x + v.y*v.y)); return c;}
internal Vec2S16 normalize_2s16(Vec2S16 v) {v = scale_2s16(v, (S16)(1.f/length_2s16(v))); return v;}
internal Vec2S16 mix_2s16(Vec2S16 a, Vec2S16 b, F32 t) {Vec2S16 c = {(S16)mix_1f32((F32)a.x, (F32)b.x, t), (S16)mix_1f32((F32)a.y, (F32)b.y, t)}; return c;} internal Vec2S16 mix_2s16(Vec2S16 a, Vec2S16 b, F32 t) {Vec2S16 c = {(S16)mix_1f32((F32)a.x, (F32)b.x, t), (S16)mix_1f32((F32)a.y, (F32)b.y, t)}; return c;}
internal Vec3F32 vec_3f32(F32 x, F32 y, F32 z) {Vec3F32 v = {x, y, z}; return v;} internal Vec3F32 vec_3f32(F32 x, F32 y, F32 z) {Vec3F32 v = {x, y, z}; return v;}
@@ -81,6 +78,14 @@ internal F32 length_3f32(Vec3F32 v) {F32 c = sqrt_f3
internal Vec3F32 normalize_3f32(Vec3F32 v) {v = scale_3f32(v, 1.f/length_3f32(v)); return v;} internal Vec3F32 normalize_3f32(Vec3F32 v) {v = scale_3f32(v, 1.f/length_3f32(v)); return v;}
internal Vec3F32 mix_3f32(Vec3F32 a, Vec3F32 b, F32 t) {Vec3F32 c = {mix_1f32(a.x, b.x, t), mix_1f32(a.y, b.y, t), mix_1f32(a.z, b.z, t)}; return c;} internal Vec3F32 mix_3f32(Vec3F32 a, Vec3F32 b, F32 t) {Vec3F32 c = {mix_1f32(a.x, b.x, t), mix_1f32(a.y, b.y, t), mix_1f32(a.z, b.z, t)}; return c;}
internal Vec3F32 cross_3f32(Vec3F32 a, Vec3F32 b) {Vec3F32 c = {a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x}; return c;} internal Vec3F32 cross_3f32(Vec3F32 a, Vec3F32 b) {Vec3F32 c = {a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x}; return c;}
internal Vec3F32 xform_3f32(Vec3F32 v, Mat3x3F32 m)
{
Vec3F32 result;
result.x = v.x*m.v[0][0] + v.y*m.v[1][0] + v.z*m.v[2][0];
result.y = v.x*m.v[0][1] + v.y*m.v[1][1] + v.z*m.v[2][1];
result.z = v.x*m.v[0][2] + v.y*m.v[1][2] + v.z*m.v[2][2];
return result;
}
internal Vec3S32 vec_3s32(S32 x, S32 y, S32 z) {Vec3S32 v = {x, y, z}; return v;} internal Vec3S32 vec_3s32(S32 x, S32 y, S32 z) {Vec3S32 v = {x, y, z}; return v;}
internal Vec3S32 add_3s32(Vec3S32 a, Vec3S32 b) {Vec3S32 c = {a.x+b.x, a.y+b.y, a.z+b.z}; return c;} internal Vec3S32 add_3s32(Vec3S32 a, Vec3S32 b) {Vec3S32 c = {a.x+b.x, a.y+b.y, a.z+b.z}; return c;}
@@ -91,7 +96,6 @@ internal Vec3S32 scale_3s32(Vec3S32 v, S32 s) {Vec3S32 c = {v.
internal S32 dot_3s32(Vec3S32 a, Vec3S32 b) {S32 c = a.x*b.x + a.y*b.y + a.z*b.z; return c;} internal S32 dot_3s32(Vec3S32 a, Vec3S32 b) {S32 c = a.x*b.x + a.y*b.y + a.z*b.z; return c;}
internal S32 length_squared_3s32(Vec3S32 v) {S32 c = v.x*v.x + v.y*v.y + v.z*v.z; return c;} internal S32 length_squared_3s32(Vec3S32 v) {S32 c = v.x*v.x + v.y*v.y + v.z*v.z; return c;}
internal S32 length_3s32(Vec3S32 v) {S32 c = (S32)sqrt_f32((F32)(v.x*v.x + v.y*v.y + v.z*v.z)); return c;} internal S32 length_3s32(Vec3S32 v) {S32 c = (S32)sqrt_f32((F32)(v.x*v.x + v.y*v.y + v.z*v.z)); return c;}
internal Vec3S32 normalize_3s32(Vec3S32 v) {v = scale_3s32(v, (S32)(1.f/length_3s32(v))); return v;}
internal Vec3S32 mix_3s32(Vec3S32 a, Vec3S32 b, F32 t) {Vec3S32 c = {(S32)mix_1f32((F32)a.x, (F32)b.x, t), (S32)mix_1f32((F32)a.y, (F32)b.y, t), (S32)mix_1f32((F32)a.z, (F32)b.z, t)}; return c;} internal Vec3S32 mix_3s32(Vec3S32 a, Vec3S32 b, F32 t) {Vec3S32 c = {(S32)mix_1f32((F32)a.x, (F32)b.x, t), (S32)mix_1f32((F32)a.y, (F32)b.y, t), (S32)mix_1f32((F32)a.z, (F32)b.z, t)}; return c;}
internal Vec3S32 cross_3s32(Vec3S32 a, Vec3S32 b) {Vec3S32 c = {a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x}; return c;} internal Vec3S32 cross_3s32(Vec3S32 a, Vec3S32 b) {Vec3S32 c = {a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x}; return c;}
@@ -116,7 +120,6 @@ internal Vec4S32 scale_4s32(Vec4S32 v, S32 s) {Vec4S32 c = {v.
internal S32 dot_4s32(Vec4S32 a, Vec4S32 b) {S32 c = a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w; return c;} internal S32 dot_4s32(Vec4S32 a, Vec4S32 b) {S32 c = a.x*b.x + a.y*b.y + a.z*b.z + a.w*b.w; return c;}
internal S32 length_squared_4s32(Vec4S32 v) {S32 c = v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w; return c;} internal S32 length_squared_4s32(Vec4S32 v) {S32 c = v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w; return c;}
internal S32 length_4s32(Vec4S32 v) {S32 c = (S32)sqrt_f32((F32)(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w)); return c;} internal S32 length_4s32(Vec4S32 v) {S32 c = (S32)sqrt_f32((F32)(v.x*v.x + v.y*v.y + v.z*v.z + v.w*v.w)); return c;}
internal Vec4S32 normalize_4s32(Vec4S32 v) {v = scale_4s32(v, (S32)(1.f/length_4s32(v))); return v;}
internal Vec4S32 mix_4s32(Vec4S32 a, Vec4S32 b, F32 t) {Vec4S32 c = {(S32)mix_1f32((F32)a.x, (F32)b.x, t), (S32)mix_1f32((F32)a.y, (F32)b.y, t), (S32)mix_1f32((F32)a.z, (F32)b.z, t), (S32)mix_1f32((F32)a.w, (F32)b.w, t)}; return c;} internal Vec4S32 mix_4s32(Vec4S32 a, Vec4S32 b, F32 t) {Vec4S32 c = {(S32)mix_1f32((F32)a.x, (F32)b.x, t), (S32)mix_1f32((F32)a.y, (F32)b.y, t), (S32)mix_1f32((F32)a.z, (F32)b.z, t), (S32)mix_1f32((F32)a.w, (F32)b.w, t)}; return c;}
//////////////////////////////// ////////////////////////////////
@@ -386,6 +389,21 @@ derotate_4x4f32(Mat4x4F32 mat)
return mat; return mat;
} }
internal Mat4x4F32
transpose_4x4f32(Mat4x4F32 mat)
{
Mat4x4F32 result =
{
{
mat.v[0][0], mat.v[1][0], mat.v[2][0], mat.v[3][0],
mat.v[0][1], mat.v[1][1], mat.v[2][1], mat.v[3][1],
mat.v[0][2], mat.v[1][2], mat.v[2][2], mat.v[3][2],
mat.v[0][3], mat.v[1][3], mat.v[2][3], mat.v[3][3],
}
};
return result;
}
//////////////////////////////// ////////////////////////////////
//~ rjf: Range Ops //~ rjf: Range Ops
@@ -394,7 +412,7 @@ internal Rng1U32 shift_1u32(Rng1U32 r, U32 x) {r.min += x; r.m
internal Rng1U32 pad_1u32(Rng1U32 r, U32 x) {r.min -= x; r.max += x; return r;} internal Rng1U32 pad_1u32(Rng1U32 r, U32 x) {r.min -= x; r.max += x; return r;}
internal U32 center_1u32(Rng1U32 r) {U32 c = (r.min+r.max)/2; return c;} internal U32 center_1u32(Rng1U32 r) {U32 c = (r.min+r.max)/2; return c;}
internal B32 contains_1u32(Rng1U32 r, U32 x) {B32 c = (r.min <= x && x < r.max); return c;} internal B32 contains_1u32(Rng1U32 r, U32 x) {B32 c = (r.min <= x && x < r.max); return c;}
internal U32 dim_1u32(Rng1U32 r) {U32 c = r.max-r.min; return c;} internal U32 dim_1u32(Rng1U32 r) {U32 c = ((r.max > r.min) ? (r.max - r.min) : 0); return c;}
internal Rng1U32 union_1u32(Rng1U32 a, Rng1U32 b) {Rng1U32 c = {Min(a.min, b.min), Max(a.max, b.max)}; return c;} internal Rng1U32 union_1u32(Rng1U32 a, Rng1U32 b) {Rng1U32 c = {Min(a.min, b.min), Max(a.max, b.max)}; return c;}
internal Rng1U32 intersect_1u32(Rng1U32 a, Rng1U32 b) {Rng1U32 c = {Max(a.min, b.min), Min(a.max, b.max)}; return c;} internal Rng1U32 intersect_1u32(Rng1U32 a, Rng1U32 b) {Rng1U32 c = {Max(a.min, b.min), Min(a.max, b.max)}; return c;}
internal U32 clamp_1u32(Rng1U32 r, U32 v) {v = Clamp(r.min, v, r.max); return v;} internal U32 clamp_1u32(Rng1U32 r, U32 v) {v = Clamp(r.min, v, r.max); return v;}
@@ -404,7 +422,7 @@ internal Rng1S32 shift_1s32(Rng1S32 r, S32 x) {r.min += x; r.m
internal Rng1S32 pad_1s32(Rng1S32 r, S32 x) {r.min -= x; r.max += x; return r;} internal Rng1S32 pad_1s32(Rng1S32 r, S32 x) {r.min -= x; r.max += x; return r;}
internal S32 center_1s32(Rng1S32 r) {S32 c = (r.min+r.max)/2; return c;} internal S32 center_1s32(Rng1S32 r) {S32 c = (r.min+r.max)/2; return c;}
internal B32 contains_1s32(Rng1S32 r, S32 x) {B32 c = (r.min <= x && x < r.max); return c;} internal B32 contains_1s32(Rng1S32 r, S32 x) {B32 c = (r.min <= x && x < r.max); return c;}
internal S32 dim_1s32(Rng1S32 r) {S32 c = r.max-r.min; return c;} internal S32 dim_1s32(Rng1S32 r) {S32 c = ((r.max > r.min) ? (r.max - r.min) : 0); return c;}
internal Rng1S32 union_1s32(Rng1S32 a, Rng1S32 b) {Rng1S32 c = {Min(a.min, b.min), Max(a.max, b.max)}; return c;} internal Rng1S32 union_1s32(Rng1S32 a, Rng1S32 b) {Rng1S32 c = {Min(a.min, b.min), Max(a.max, b.max)}; return c;}
internal Rng1S32 intersect_1s32(Rng1S32 a, Rng1S32 b) {Rng1S32 c = {Max(a.min, b.min), Min(a.max, b.max)}; return c;} internal Rng1S32 intersect_1s32(Rng1S32 a, Rng1S32 b) {Rng1S32 c = {Max(a.min, b.min), Min(a.max, b.max)}; return c;}
internal S32 clamp_1s32(Rng1S32 r, S32 v) {v = Clamp(r.min, v, r.max); return v;} internal S32 clamp_1s32(Rng1S32 r, S32 v) {v = Clamp(r.min, v, r.max); return v;}
@@ -414,7 +432,7 @@ internal Rng1U64 shift_1u64(Rng1U64 r, U64 x) {r.min += x; r.m
internal Rng1U64 pad_1u64(Rng1U64 r, U64 x) {r.min -= x; r.max += x; return r;} internal Rng1U64 pad_1u64(Rng1U64 r, U64 x) {r.min -= x; r.max += x; return r;}
internal U64 center_1u64(Rng1U64 r) {U64 c = (r.min+r.max)/2; return c;} internal U64 center_1u64(Rng1U64 r) {U64 c = (r.min+r.max)/2; return c;}
internal B32 contains_1u64(Rng1U64 r, U64 x) {B32 c = (r.min <= x && x < r.max); return c;} internal B32 contains_1u64(Rng1U64 r, U64 x) {B32 c = (r.min <= x && x < r.max); return c;}
internal U64 dim_1u64(Rng1U64 r) {U64 c = r.max-r.min; return c;} internal U64 dim_1u64(Rng1U64 r) {U64 c = ((r.max > r.min) ? (r.max - r.min) : 0); return c;}
internal Rng1U64 union_1u64(Rng1U64 a, Rng1U64 b) {Rng1U64 c = {Min(a.min, b.min), Max(a.max, b.max)}; return c;} internal Rng1U64 union_1u64(Rng1U64 a, Rng1U64 b) {Rng1U64 c = {Min(a.min, b.min), Max(a.max, b.max)}; return c;}
internal Rng1U64 intersect_1u64(Rng1U64 a, Rng1U64 b) {Rng1U64 c = {Max(a.min, b.min), Min(a.max, b.max)}; return c;} internal Rng1U64 intersect_1u64(Rng1U64 a, Rng1U64 b) {Rng1U64 c = {Max(a.min, b.min), Min(a.max, b.max)}; return c;}
internal U64 clamp_1u64(Rng1U64 r, U64 v) {v = Clamp(r.min, v, r.max); return v;} internal U64 clamp_1u64(Rng1U64 r, U64 v) {v = Clamp(r.min, v, r.max); return v;}
@@ -424,7 +442,7 @@ internal Rng1S64 shift_1s64(Rng1S64 r, S64 x) {r.min += x; r.m
internal Rng1S64 pad_1s64(Rng1S64 r, S64 x) {r.min -= x; r.max += x; return r;} internal Rng1S64 pad_1s64(Rng1S64 r, S64 x) {r.min -= x; r.max += x; return r;}
internal S64 center_1s64(Rng1S64 r) {S64 c = (r.min+r.max)/2; return c;} internal S64 center_1s64(Rng1S64 r) {S64 c = (r.min+r.max)/2; return c;}
internal B32 contains_1s64(Rng1S64 r, S64 x) {B32 c = (r.min <= x && x < r.max); return c;} internal B32 contains_1s64(Rng1S64 r, S64 x) {B32 c = (r.min <= x && x < r.max); return c;}
internal S64 dim_1s64(Rng1S64 r) {S64 c = r.max-r.min; return c;} internal S64 dim_1s64(Rng1S64 r) {S64 c = ((r.max > r.min) ? (r.max - r.min) : 0); return c;}
internal Rng1S64 union_1s64(Rng1S64 a, Rng1S64 b) {Rng1S64 c = {Min(a.min, b.min), Max(a.max, b.max)}; return c;} internal Rng1S64 union_1s64(Rng1S64 a, Rng1S64 b) {Rng1S64 c = {Min(a.min, b.min), Max(a.max, b.max)}; return c;}
internal Rng1S64 intersect_1s64(Rng1S64 a, Rng1S64 b) {Rng1S64 c = {Max(a.min, b.min), Min(a.max, b.max)}; return c;} internal Rng1S64 intersect_1s64(Rng1S64 a, Rng1S64 b) {Rng1S64 c = {Max(a.min, b.min), Min(a.max, b.max)}; return c;}
internal S64 clamp_1s64(Rng1S64 r, S64 v) {v = Clamp(r.min, v, r.max); return v;} internal S64 clamp_1s64(Rng1S64 r, S64 v) {v = Clamp(r.min, v, r.max); return v;}
@@ -434,7 +452,7 @@ internal Rng1F32 shift_1f32(Rng1F32 r, F32 x) {r.min += x; r.m
internal Rng1F32 pad_1f32(Rng1F32 r, F32 x) {r.min -= x; r.max += x; return r;} internal Rng1F32 pad_1f32(Rng1F32 r, F32 x) {r.min -= x; r.max += x; return r;}
internal F32 center_1f32(Rng1F32 r) {F32 c = (r.min+r.max)/2; return c;} internal F32 center_1f32(Rng1F32 r) {F32 c = (r.min+r.max)/2; return c;}
internal B32 contains_1f32(Rng1F32 r, F32 x) {B32 c = (r.min <= x && x < r.max); return c;} internal B32 contains_1f32(Rng1F32 r, F32 x) {B32 c = (r.min <= x && x < r.max); return c;}
internal F32 dim_1f32(Rng1F32 r) {F32 c = r.max-r.min; return c;} internal F32 dim_1f32(Rng1F32 r) {F32 c = ((r.max > r.min) ? (r.max - r.min) : 0); return c;}
internal Rng1F32 union_1f32(Rng1F32 a, Rng1F32 b) {Rng1F32 c = {Min(a.min, b.min), Max(a.max, b.max)}; return c;} internal Rng1F32 union_1f32(Rng1F32 a, Rng1F32 b) {Rng1F32 c = {Min(a.min, b.min), Max(a.max, b.max)}; return c;}
internal Rng1F32 intersect_1f32(Rng1F32 a, Rng1F32 b) {Rng1F32 c = {Max(a.min, b.min), Min(a.max, b.max)}; return c;} internal Rng1F32 intersect_1f32(Rng1F32 a, Rng1F32 b) {Rng1F32 c = {Max(a.min, b.min), Min(a.max, b.max)}; return c;}
internal F32 clamp_1f32(Rng1F32 r, F32 v) {v = Clamp(r.min, v, r.max); return v;} internal F32 clamp_1f32(Rng1F32 r, F32 v) {v = Clamp(r.min, v, r.max); return v;}
@@ -444,7 +462,7 @@ internal Rng2S16 shift_2s16(Rng2S16 r, Vec2S16 x) {r.min = add_2s1
internal Rng2S16 pad_2s16(Rng2S16 r, S16 x) {Vec2S16 xv = {x, x}; r.min = sub_2s16(r.min, xv); r.max = add_2s16(r.max, xv); return r;} internal Rng2S16 pad_2s16(Rng2S16 r, S16 x) {Vec2S16 xv = {x, x}; r.min = sub_2s16(r.min, xv); r.max = add_2s16(r.max, xv); return r;}
internal Vec2S16 center_2s16(Rng2S16 r) {Vec2S16 c = {(S16)((r.min.x+r.max.x)/2), (S16)((r.min.y+r.max.y)/2)}; return c;} internal Vec2S16 center_2s16(Rng2S16 r) {Vec2S16 c = {(S16)((r.min.x+r.max.x)/2), (S16)((r.min.y+r.max.y)/2)}; return c;}
internal B32 contains_2s16(Rng2S16 r, Vec2S16 x) {B32 c = (r.min.x <= x.x && x.x < r.max.x && r.min.y <= x.y && x.y < r.max.y); return c;} internal B32 contains_2s16(Rng2S16 r, Vec2S16 x) {B32 c = (r.min.x <= x.x && x.x < r.max.x && r.min.y <= x.y && x.y < r.max.y); return c;}
internal Vec2S16 dim_2s16(Rng2S16 r) {Vec2S16 dim = {(S16)(r.max.x-r.min.x), (S16)(r.max.y-r.min.y)}; return dim;} internal Vec2S16 dim_2s16(Rng2S16 r) {Vec2S16 dim = {(S16)(((r.max.x > r.min.x) ? (r.max.x - r.min.x) : 0)), (S16)(((r.max.y > r.min.y) ? (r.max.y - r.min.y) : 0))}; return dim;}
internal Rng2S16 union_2s16(Rng2S16 a, Rng2S16 b) {Rng2S16 c; c.p0.x = Min(a.min.x, b.min.x); c.p0.y = Min(a.min.y, b.min.y); c.p1.x = Max(a.max.x, b.max.x); c.p1.y = Max(a.max.y, b.max.y); return c;} internal Rng2S16 union_2s16(Rng2S16 a, Rng2S16 b) {Rng2S16 c; c.p0.x = Min(a.min.x, b.min.x); c.p0.y = Min(a.min.y, b.min.y); c.p1.x = Max(a.max.x, b.max.x); c.p1.y = Max(a.max.y, b.max.y); return c;}
internal Rng2S16 intersect_2s16(Rng2S16 a, Rng2S16 b) {Rng2S16 c; c.p0.x = Max(a.min.x, b.min.x); c.p0.y = Max(a.min.y, b.min.y); c.p1.x = Min(a.max.x, b.max.x); c.p1.y = Min(a.max.y, b.max.y); return c;} internal Rng2S16 intersect_2s16(Rng2S16 a, Rng2S16 b) {Rng2S16 c; c.p0.x = Max(a.min.x, b.min.x); c.p0.y = Max(a.min.y, b.min.y); c.p1.x = Min(a.max.x, b.max.x); c.p1.y = Min(a.max.y, b.max.y); return c;}
internal Vec2S16 clamp_2s16(Rng2S16 r, Vec2S16 v) {v.x = Clamp(r.min.x, v.x, r.max.x); v.y = Clamp(r.min.y, v.y, r.max.y); return v;} internal Vec2S16 clamp_2s16(Rng2S16 r, Vec2S16 v) {v.x = Clamp(r.min.x, v.x, r.max.x); v.y = Clamp(r.min.y, v.y, r.max.y); return v;}
@@ -454,7 +472,7 @@ internal Rng2S32 shift_2s32(Rng2S32 r, Vec2S32 x) {r.min = add_2s3
internal Rng2S32 pad_2s32(Rng2S32 r, S32 x) {Vec2S32 xv = {x, x}; r.min = sub_2s32(r.min, xv); r.max = add_2s32(r.max, xv); return r;} internal Rng2S32 pad_2s32(Rng2S32 r, S32 x) {Vec2S32 xv = {x, x}; r.min = sub_2s32(r.min, xv); r.max = add_2s32(r.max, xv); return r;}
internal Vec2S32 center_2s32(Rng2S32 r) {Vec2S32 c = {(r.min.x+r.max.x)/2, (r.min.y+r.max.y)/2}; return c;} internal Vec2S32 center_2s32(Rng2S32 r) {Vec2S32 c = {(r.min.x+r.max.x)/2, (r.min.y+r.max.y)/2}; return c;}
internal B32 contains_2s32(Rng2S32 r, Vec2S32 x) {B32 c = (r.min.x <= x.x && x.x < r.max.x && r.min.y <= x.y && x.y < r.max.y); return c;} internal B32 contains_2s32(Rng2S32 r, Vec2S32 x) {B32 c = (r.min.x <= x.x && x.x < r.max.x && r.min.y <= x.y && x.y < r.max.y); return c;}
internal Vec2S32 dim_2s32(Rng2S32 r) {Vec2S32 dim = {r.max.x-r.min.x, r.max.y-r.min.y}; return dim;} internal Vec2S32 dim_2s32(Rng2S32 r) {Vec2S32 dim = {((r.max.x > r.min.x) ? (r.max.x - r.min.x) : 0), ((r.max.y > r.min.y) ? (r.max.y - r.min.y) : 0)}; return dim;}
internal Rng2S32 union_2s32(Rng2S32 a, Rng2S32 b) {Rng2S32 c; c.p0.x = Min(a.min.x, b.min.x); c.p0.y = Min(a.min.y, b.min.y); c.p1.x = Max(a.max.x, b.max.x); c.p1.y = Max(a.max.y, b.max.y); return c;} internal Rng2S32 union_2s32(Rng2S32 a, Rng2S32 b) {Rng2S32 c; c.p0.x = Min(a.min.x, b.min.x); c.p0.y = Min(a.min.y, b.min.y); c.p1.x = Max(a.max.x, b.max.x); c.p1.y = Max(a.max.y, b.max.y); return c;}
internal Rng2S32 intersect_2s32(Rng2S32 a, Rng2S32 b) {Rng2S32 c; c.p0.x = Max(a.min.x, b.min.x); c.p0.y = Max(a.min.y, b.min.y); c.p1.x = Min(a.max.x, b.max.x); c.p1.y = Min(a.max.y, b.max.y); return c;} internal Rng2S32 intersect_2s32(Rng2S32 a, Rng2S32 b) {Rng2S32 c; c.p0.x = Max(a.min.x, b.min.x); c.p0.y = Max(a.min.y, b.min.y); c.p1.x = Min(a.max.x, b.max.x); c.p1.y = Min(a.max.y, b.max.y); return c;}
internal Vec2S32 clamp_2s32(Rng2S32 r, Vec2S32 v) {v.x = Clamp(r.min.x, v.x, r.max.x); v.y = Clamp(r.min.y, v.y, r.max.y); return v;} internal Vec2S32 clamp_2s32(Rng2S32 r, Vec2S32 v) {v.x = Clamp(r.min.x, v.x, r.max.x); v.y = Clamp(r.min.y, v.y, r.max.y); return v;}
@@ -464,7 +482,7 @@ internal Rng2S64 shift_2s64(Rng2S64 r, Vec2S64 x) {r.min = add_2s6
internal Rng2S64 pad_2s64(Rng2S64 r, S64 x) {Vec2S64 xv = {x, x}; r.min = sub_2s64(r.min, xv); r.max = add_2s64(r.max, xv); return r;} internal Rng2S64 pad_2s64(Rng2S64 r, S64 x) {Vec2S64 xv = {x, x}; r.min = sub_2s64(r.min, xv); r.max = add_2s64(r.max, xv); return r;}
internal Vec2S64 center_2s64(Rng2S64 r) {Vec2S64 c = {(r.min.x+r.max.x)/2, (r.min.y+r.max.y)/2}; return c;} internal Vec2S64 center_2s64(Rng2S64 r) {Vec2S64 c = {(r.min.x+r.max.x)/2, (r.min.y+r.max.y)/2}; return c;}
internal B32 contains_2s64(Rng2S64 r, Vec2S64 x) {B32 c = (r.min.x <= x.x && x.x < r.max.x && r.min.y <= x.y && x.y < r.max.y); return c;} internal B32 contains_2s64(Rng2S64 r, Vec2S64 x) {B32 c = (r.min.x <= x.x && x.x < r.max.x && r.min.y <= x.y && x.y < r.max.y); return c;}
internal Vec2S64 dim_2s64(Rng2S64 r) {Vec2S64 dim = {r.max.x-r.min.x, r.max.y-r.min.y}; return dim;} internal Vec2S64 dim_2s64(Rng2S64 r) {Vec2S64 dim = {((r.max.x > r.min.x) ? (r.max.x - r.min.x) : 0), ((r.max.y > r.min.y) ? (r.max.y - r.min.y) : 0)}; return dim;}
internal Rng2S64 union_2s64(Rng2S64 a, Rng2S64 b) {Rng2S64 c; c.p0.x = Min(a.min.x, b.min.x); c.p0.y = Min(a.min.y, b.min.y); c.p1.x = Max(a.max.x, b.max.x); c.p1.y = Max(a.max.y, b.max.y); return c;} internal Rng2S64 union_2s64(Rng2S64 a, Rng2S64 b) {Rng2S64 c; c.p0.x = Min(a.min.x, b.min.x); c.p0.y = Min(a.min.y, b.min.y); c.p1.x = Max(a.max.x, b.max.x); c.p1.y = Max(a.max.y, b.max.y); return c;}
internal Rng2S64 intersect_2s64(Rng2S64 a, Rng2S64 b) {Rng2S64 c; c.p0.x = Max(a.min.x, b.min.x); c.p0.y = Max(a.min.y, b.min.y); c.p1.x = Min(a.max.x, b.max.x); c.p1.y = Min(a.max.y, b.max.y); return c;} internal Rng2S64 intersect_2s64(Rng2S64 a, Rng2S64 b) {Rng2S64 c; c.p0.x = Max(a.min.x, b.min.x); c.p0.y = Max(a.min.y, b.min.y); c.p1.x = Min(a.max.x, b.max.x); c.p1.y = Min(a.max.y, b.max.y); return c;}
internal Vec2S64 clamp_2s64(Rng2S64 r, Vec2S64 v) {v.x = Clamp(r.min.x, v.x, r.max.x); v.y = Clamp(r.min.y, v.y, r.max.y); return v;} internal Vec2S64 clamp_2s64(Rng2S64 r, Vec2S64 v) {v.x = Clamp(r.min.x, v.x, r.max.x); v.y = Clamp(r.min.y, v.y, r.max.y); return v;}
@@ -474,13 +492,15 @@ internal Rng2F32 shift_2f32(Rng2F32 r, Vec2F32 x) {r.min = add_2f3
internal Rng2F32 pad_2f32(Rng2F32 r, F32 x) {Vec2F32 xv = {x, x}; r.min = sub_2f32(r.min, xv); r.max = add_2f32(r.max, xv); return r;} internal Rng2F32 pad_2f32(Rng2F32 r, F32 x) {Vec2F32 xv = {x, x}; r.min = sub_2f32(r.min, xv); r.max = add_2f32(r.max, xv); return r;}
internal Vec2F32 center_2f32(Rng2F32 r) {Vec2F32 c = {(r.min.x+r.max.x)/2, (r.min.y+r.max.y)/2}; return c;} internal Vec2F32 center_2f32(Rng2F32 r) {Vec2F32 c = {(r.min.x+r.max.x)/2, (r.min.y+r.max.y)/2}; return c;}
internal B32 contains_2f32(Rng2F32 r, Vec2F32 x) {B32 c = (r.min.x <= x.x && x.x < r.max.x && r.min.y <= x.y && x.y < r.max.y); return c;} internal B32 contains_2f32(Rng2F32 r, Vec2F32 x) {B32 c = (r.min.x <= x.x && x.x < r.max.x && r.min.y <= x.y && x.y < r.max.y); return c;}
internal Vec2F32 dim_2f32(Rng2F32 r) {Vec2F32 dim = {r.max.x-r.min.x, r.max.y-r.min.y}; return dim;} internal Vec2F32 dim_2f32(Rng2F32 r) {Vec2F32 dim = {((r.max.x > r.min.x) ? (r.max.x - r.min.x) : 0), ((r.max.y > r.min.y) ? (r.max.y - r.min.y) : 0)}; return dim;}
internal Rng2F32 union_2f32(Rng2F32 a, Rng2F32 b) {Rng2F32 c; c.p0.x = Min(a.min.x, b.min.x); c.p0.y = Min(a.min.y, b.min.y); c.p1.x = Max(a.max.x, b.max.x); c.p1.y = Max(a.max.y, b.max.y); return c;} internal Rng2F32 union_2f32(Rng2F32 a, Rng2F32 b) {Rng2F32 c; c.p0.x = Min(a.min.x, b.min.x); c.p0.y = Min(a.min.y, b.min.y); c.p1.x = Max(a.max.x, b.max.x); c.p1.y = Max(a.max.y, b.max.y); return c;}
internal Rng2F32 intersect_2f32(Rng2F32 a, Rng2F32 b) {Rng2F32 c; c.p0.x = Max(a.min.x, b.min.x); c.p0.y = Max(a.min.y, b.min.y); c.p1.x = Min(a.max.x, b.max.x); c.p1.y = Min(a.max.y, b.max.y); return c;} internal Rng2F32 intersect_2f32(Rng2F32 a, Rng2F32 b) {Rng2F32 c; c.p0.x = Max(a.min.x, b.min.x); c.p0.y = Max(a.min.y, b.min.y); c.p1.x = Min(a.max.x, b.max.x); c.p1.y = Min(a.max.y, b.max.y); return c;}
internal Vec2F32 clamp_2f32(Rng2F32 r, Vec2F32 v) {v.x = Clamp(r.min.x, v.x, r.max.x); v.y = Clamp(r.min.y, v.y, r.max.y); return v;} internal Vec2F32 clamp_2f32(Rng2F32 r, Vec2F32 v) {v.x = Clamp(r.min.x, v.x, r.max.x); v.y = Clamp(r.min.y, v.y, r.max.y); return v;}
//////////////////////////////// ////////////////////////////////
//~ rjf: Miscellaneous Ops //~ rjf: Color Operations
//- rjf: hsv <-> rgb
internal Vec3F32 internal Vec3F32
hsv_from_rgb(Vec3F32 rgb) hsv_from_rgb(Vec3F32 rgb)
@@ -567,16 +587,102 @@ rgba_from_hsva(Vec4F32 hsva)
return rgba; return rgba;
} }
internal Vec4F32 //- rjf: srgb <-> linear
rgba_from_u32(U32 hex)
internal Vec3F32
linear_from_srgb(Vec3F32 srgb)
{ {
Vec4F32 result = v4f32(((hex&0xff000000)>>24)/255.f, Vec3F32 result;
((hex&0x00ff0000)>>16)/255.f, for EachElement(idx, srgb.v)
((hex&0x0000ff00)>> 8)/255.f, {
((hex&0x000000ff)>> 0)/255.f); result.v[idx] = (srgb.v[idx] < 0.0404482362771082f ? srgb.v[idx] / 12.92f : pow_f32((srgb.v[idx] + 0.055f) / 1.055f, 2.4f));
}
return result; return result;
} }
internal Vec3F32
srgb_from_linear(Vec3F32 linear)
{
Vec3F32 result;
for EachElement(idx, linear.v)
{
result.v[idx] = (0 <= linear.v[idx] && linear.v[idx] < 0.00313066844250063) ? linear.v[idx]*12.92f : 1.05f * pow_f32(linear.v[idx], 1.f/2.4f) - 0.055f;
}
return result;
}
internal Vec4F32
linear_from_srgba(Vec4F32 srgba)
{
Vec4F32 result;
result.xyz = linear_from_srgb(srgba.xyz);
result.w = srgba.w;
return result;
}
internal Vec4F32
srgba_from_linear(Vec4F32 linear)
{
Vec4F32 result;
result.xyz = srgb_from_linear(linear.xyz);
result.w = linear.w;
return result;
}
//- rjf: oklab <-> linear
internal Vec3F32
oklab_from_linear(Vec3F32 linear)
{
F32 l = (0.4122214708f * linear.x + 0.5363325363f * linear.y + 0.0514459929f * linear.z);
F32 m = (0.2119034982f * linear.x + 0.6806995451f * linear.y + 0.1073969566f * linear.z);
F32 s = (0.0883024619f * linear.x + 0.2817188376f * linear.y + 0.6299787005f * linear.z);
F32 l_ = cbrt_f32(l);
F32 m_ = cbrt_f32(m);
F32 s_ = cbrt_f32(s);
Vec3F32 result;
result.x = 0.2104542553f*l_ + 0.7936177850f*m_ - 0.0040720468f*s_;
result.y = 1.9779984951f*l_ - 2.4285922050f*m_ + 0.4505937099f*s_;
result.z = 0.0259040371f*l_ + 0.7827717662f*m_ - 0.8086757660f*s_;
return result;
}
internal Vec3F32
linear_from_oklab(Vec3F32 oklab)
{
F32 l_ = oklab.x + 0.3963377774f * oklab.y + 0.2158037573f * oklab.z;
F32 m_ = oklab.x - 0.1055613458f * oklab.y - 0.0638541728f * oklab.z;
F32 s_ = oklab.x - 0.0894841775f * oklab.y - 1.2914855480f * oklab.z;
F32 l = l_*l_*l_;
F32 m = m_*m_*m_;
F32 s = s_*s_*s_;
Vec3F32 result;
result.x = +4.0767416621f * l - 3.3077115913f * m + 0.2309699292f * s;
result.y = -1.2684380046f * l + 2.6097574011f * m - 0.3413193965f * s;
result.z = -0.0041960863f * l - 0.7034186147f * m + 1.7076147010f * s;
return result;
}
internal Vec4F32
oklab_from_lineara(Vec4F32 lineara)
{
Vec4F32 result;
result.xyz = oklab_from_linear(lineara.xyz);
result.w = lineara.w;
return result;
}
internal Vec4F32
lineara_from_oklab(Vec4F32 oklab)
{
Vec4F32 result;
result.xyz = linear_from_oklab(oklab.xyz);
result.w = oklab.w;
return result;
}
//- rjf: rgba <-> u32
internal U32 internal U32
u32_from_rgba(Vec4F32 rgba) u32_from_rgba(Vec4F32 rgba)
{ {
@@ -588,9 +694,100 @@ u32_from_rgba(Vec4F32 rgba)
return result; return result;
} }
internal Vec4F32
rgba_from_u32(U32 hex)
{
Vec4F32 result = v4f32(((hex&0xff000000)>>24)/255.f,
((hex&0x00ff0000)>>16)/255.f,
((hex&0x0000ff00)>> 8)/255.f,
((hex&0x000000ff)>> 0)/255.f);
return result;
}
//////////////////////////////// ////////////////////////////////
//~ rjf: List Type Functions //~ rjf: List Type Functions
internal void
rng1u64_list_push_node(Rng1U64List *list, Rng1U64Node *n)
{
SLLQueuePush(list->first, list->last, n);
list->count += 1;
}
internal Rng1U64Node *
rng1u64_list_push(Arena *arena, Rng1U64List *list, Rng1U64 rng)
{
Rng1U64Node *n = push_array(arena, Rng1U64Node, 1);
MemoryCopyStruct(&n->v, &rng);
rng1u64_list_push_node(list, n);
return n;
}
internal void
rng1u64_list_concat(Rng1U64List *list, Rng1U64List *to_concat)
{
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);
}
}
internal Rng1U64Array
rng1u64_array_from_list(Arena *arena, Rng1U64List *list)
{
Rng1U64Array arr = {0};
arr.count = list->count;
arr.v = push_array_no_zero(arena, Rng1U64, arr.count);
U64 idx = 0;
for(Rng1U64Node *n = list->first; n != 0; n = n->next)
{
arr.v[idx] = n->v;
idx += 1;
}
return arr;
}
internal U64
rng_1u64_array_bsearch(Rng1U64Array arr, U64 value)
{
if(arr.count > 0 && arr.v[0].min < value && value < arr.v[arr.count-1].max)
{
U64 l = 0;
U64 r = arr.count - 1;
for(; l <= r; )
{
U64 m = l + (r - l) / 2;
if(contains_1u64(arr.v[m], value))
{
return m;
}
else if(arr.v[m].min < value)
{
l = m + 1;
}
else
{
r = m - 1;
}
}
}
else if(arr.count == 1 && contains_1u64(arr.v[0], value))
{
return 0;
}
return max_U64;
}
internal void internal void
rng1s64_list_push(Arena *arena, Rng1S64List *list, Rng1S64 rng) rng1s64_list_push(Arena *arena, Rng1S64List *list, Rng1S64 rng)
{ {
@@ -614,3 +811,20 @@ rng1s64_array_from_list(Arena *arena, Rng1S64List *list)
} }
return arr; return arr;
} }
////////////////////////////////
//~ rjf: N -> M Element Subdivision
internal Rng1U64
m_range_from_n_idx_m_count(U64 n_idx, U64 n_count, U64 m_count)
{
U64 main_idxes_per_lane = m_count/n_count;
U64 leftover_idxes_count = m_count - main_idxes_per_lane*n_count;
U64 leftover_idxes_before_this_lane_count = Min(n_idx, leftover_idxes_count);
U64 lane_base_idx = n_idx*main_idxes_per_lane + leftover_idxes_before_this_lane_count;
U64 lane_base_idx__clamped = Min(lane_base_idx, m_count);
U64 lane_opl_idx = lane_base_idx__clamped + main_idxes_per_lane + ((n_idx < leftover_idxes_count) ? 1 : 0);
U64 lane_opl_idx__clamped = Min(lane_opl_idx, m_count);
Rng1U64 result = r1u64(lane_base_idx__clamped, lane_opl_idx__clamped);
return result;
}
+695 -649
View File
File diff suppressed because it is too large. Load diff
+16 -17
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
//////////////////////////////// ////////////////////////////////
@@ -44,8 +44,7 @@ typed_data_rebase_ptrs(Type *type, String8 data, void *base_ptr)
switch(t->type->kind) switch(t->type->kind)
{ {
default:{}break; default:{}break;
case TypeKind_Ptr: case TypeKind_Ptr:
if(!(t->type->flags & TypeFlag_IsExternal))
{ {
*(U64 *)t->ptr = ((U64)(*(U8 **)t->ptr - (U8 *)base_ptr)); *(U64 *)t->ptr = ((U64)(*(U8 **)t->ptr - (U8 *)base_ptr));
}break; }break;
@@ -173,13 +172,13 @@ serialized_from_typed_data(Arena *arena, Type *type, String8 data, TypeSerialize
task->containing_type = t->containing_type; task->containing_type = t->containing_type;
task->containing_ptr = t->containing_ptr; task->containing_ptr = t->containing_ptr;
SLLQueuePush(first_task, last_task, task); SLLQueuePush(first_task, last_task, task);
} }
// rjf: catch-all: write pointer value // rjf: catch-all: write pointer value
else else
{ {
str8_serial_push_string(scratch.arena, &strings, str8(t->src, t->type->size*t->count)); str8_serial_push_string(scratch.arena, &strings, str8(t->src, t->type->size*t->count));
} }
}break; }break;
//- rjf: arrays -> descend to underlying type, + count //- rjf: arrays -> descend to underlying type, + count
@@ -345,14 +344,14 @@ deserialized_from_typed_data(Arena *arena, Type *type, String8 data, TypeSeriali
task->containing_type = t->containing_type; task->containing_type = t->containing_type;
task->containing_ptr = t->containing_ptr; task->containing_ptr = t->containing_ptr;
SLLQueuePush(first_task, last_task, task); SLLQueuePush(first_task, last_task, task);
} }
// rjf: catch-all: read pointer value // rjf: catch-all: read pointer value
else else
{ {
MemoryCopy(t->dst, t_src, t->type->size*t->count); MemoryCopy(t->dst, t_src, t->type->size*t->count);
read_off += t->type->size*t->count; read_off += t->type->size*t->count;
} }
}break; }break;
//- rjf: arrays -> descend to underlying type, + count //- rjf: arrays -> descend to underlying type, + count
+4 -5
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_META_H #ifndef BASE_META_H
@@ -100,10 +100,9 @@ TypeKind;
typedef U32 TypeFlags; typedef U32 TypeFlags;
enum enum
{ {
TypeFlag_IsExternal = (1<<0), TypeFlag_IsPlainText = (1<<0),
TypeFlag_IsPlainText = (1<<1), TypeFlag_IsCodeText = (1<<1),
TypeFlag_IsCodeText = (1<<2), TypeFlag_IsPathText = (1<<2),
TypeFlag_IsPathText = (1<<3),
}; };
typedef U32 MemberFlags; typedef U32 MemberFlags;
+30 -1
View File
@@ -1,2 +1,31 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#if PROFILE_SPALL
internal inline void
spall_begin(char *fmt, ...)
{
if(spall_buffer.data == 0)
{
spall_buffer.length = MB(1);
spall_buffer.data = os_reserve(spall_buffer.length);
os_commit(spall_buffer.data, spall_buffer.length);
spall_buffer_init(&spall_profile, &spall_buffer);
}
if(spall_pid == 0)
{
spall_pid = os_get_process_info()->pid;
}
if(spall_tid == 0)
{
spall_tid = os_tid();
}
Temp scratch = scratch_begin(0, 0);
va_list args;
va_start(args, fmt);
String8 string = push_str8fv(scratch.arena, fmt, args);
spall_buffer_begin_ex(&spall_profile, &spall_buffer, string.str, string.size, os_now_microseconds(), spall_tid, spall_pid);
va_end(args);
scratch_end(scratch);
}
#endif
+55 -25
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_PROFILE_H #ifndef BASE_PROFILE_H
@@ -10,9 +10,8 @@
#if !defined(PROFILE_TELEMETRY) #if !defined(PROFILE_TELEMETRY)
# define PROFILE_TELEMETRY 0 # define PROFILE_TELEMETRY 0
#endif #endif
#if !defined(PROFILE_SPALL)
#if !defined(MARKUP_LAYER_COLOR) # define PROFILE_SPALL 0
# define MARKUP_LAYER_COLOR 1.00f, 0.00f, 1.00f
#endif #endif
//////////////////////////////// ////////////////////////////////
@@ -21,8 +20,11 @@
#if PROFILE_TELEMETRY #if PROFILE_TELEMETRY
# include "rad_tm.h" # include "rad_tm.h"
# if OS_WINDOWS # if OS_WINDOWS
# pragma comment(lib, "ws2_32.lib")
# pragma comment(lib, "rad_tm_win64.lib") # pragma comment(lib, "rad_tm_win64.lib")
# endif # endif
#elif PROFILE_SPALL
# include "spall.h"
#endif #endif
//////////////////////////////// ////////////////////////////////
@@ -42,27 +44,55 @@
# define ProfEndLockWait(...) tmEndWaitForLock(0) # define ProfEndLockWait(...) tmEndWaitForLock(0)
# 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) tmZoneColor((((color) & 0xff000000) >> 24) / 255.f, (((color) & 0x00ff0000) >> 16) / 255.f, (((color) & 0x0000ff00) >> 8) / 255.f)
# define ProfBeginV(...) \ # define ProfBeginV(...) \
if (TM_API_PTR) { \ if (TM_API_PTR) { \
static tm_uint64 file_id = 0; TM_API_PTR->_tmStaticString(&file_id, __FILE__); \ static tm_uint64 file_id = 0; TM_API_PTR->_tmStaticString(&file_id, __FILE__); \
Temp scratch = scratch_begin(0,0); \ Temp scratch = scratch_begin(0,0); \
String8 string = push_str8f(scratch.arena, __VA_ARGS__); \ String8 string = push_str8f(scratch.arena, __VA_ARGS__); \
tm_uint64 hash = TM_API_PTR->_tmHash((char*)string.str, string.size); \ tm_uint64 hash = TM_API_PTR->_tmHash((char*)string.str, string.size); \
hash = TM_API_PTR->_tmSendDynamicString(hash, (char*)string.str); \ hash = TM_API_PTR->_tmSendDynamicString(hash, (char*)string.str); \
TM_API_PTR->_tmEnterZoneFast_Core(0, 0, file_id, __LINE__, hash); \ TM_API_PTR->_tmEnterZoneFast_Core(0, 0, file_id, __LINE__, hash); \
scratch_end(scratch); \ scratch_end(scratch); \
} }
# define ProfNoteV(...) \ # define ProfNoteV(...) \
if (TM_API_PTR) { \ if (TM_API_PTR) { \
static tm_uint64 file_id = 0; TM_API_PTR->_tmStaticString(&file_id, __FILE__); \ static tm_uint64 file_id = 0; TM_API_PTR->_tmStaticString(&file_id, __FILE__); \
Temp scratch = scratch_begin(0,0); \ Temp scratch = scratch_begin(0,0); \
String8 string = push_str8f(scratch.arena, __VA_ARGS__); \ String8 string = push_str8f(scratch.arena, __VA_ARGS__); \
tm_uint64 hash = TM_API_PTR->_tmHash((char*)string.str, string.size); \ tm_uint64 hash = TM_API_PTR->_tmHash((char*)string.str, string.size); \
hash = TM_API_PTR->_tmSendDynamicString(hash, (char*)string.str); \ hash = TM_API_PTR->_tmSendDynamicString(hash, (char*)string.str); \
TM_API_PTR->_tmMessageFast_Core(0, TMMF_ICON_NOTE, file_id, __LINE__, hash); \ TM_API_PTR->_tmMessageFast_Core(0, TMMF_ICON_NOTE, file_id, __LINE__, hash); \
scratch_end(scratch); \ scratch_end(scratch); \
} }
#endif
////////////////////////////////
//~ rjf: Spall Profile Defines
#if PROFILE_SPALL
global U64 spall_capturing = 0;
global SpallProfile spall_profile = {0};
thread_static SpallBuffer spall_buffer = {0};
thread_static U32 spall_tid = 0;
thread_static U32 spall_pid = 0;
internal inline void spall_begin(char *fmt, ...);
# define ProfBegin(...) (spall_capturing ? (spall_begin(__VA_ARGS__), 0) : 0)
# define ProfBeginDynamic(...) (spall_capturing ? (spall_begin(__VA_ARGS__), 0) : 0)
# define ProfEnd(...) (spall_capturing ? (spall_buffer_end_ex(&spall_profile, &spall_buffer, os_now_microseconds(), spall_tid, spall_pid)), 0 : 0)
# define ProfTick(...)
# define ProfIsCapturing(...) (!!spall_capturing)
# define ProfBeginCapture(...) (spall_capturing = 1)
# define ProfEndCapture(...) (spall_capturing = 0, spall_flush(&spall_profile))
# define ProfThreadName(...)
# define ProfMsg(...)
# define ProfBeginLockWait(...)
# define ProfEndLockWait(...)
# define ProfLockTake(...)
# define ProfLockDrop(...)
# define ProfColor(color)
# define ProfBeginV(...)
# define ProfNoteV(...)
#endif #endif
//////////////////////////////// ////////////////////////////////
+1137 -541
View File
File diff suppressed because it is too large. Load diff
+95 -46
View File
@@ -1,15 +1,9 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_STRINGS_H #ifndef BASE_STRINGS_H
#define BASE_STRINGS_H #define BASE_STRINGS_H
////////////////////////////////
//~ rjf: Third Party Includes
#define STB_SPRINTF_DECORATE(name) raddbg_##name
#include "third_party/stb/stb_sprintf.h"
//////////////////////////////// ////////////////////////////////
//~ rjf: String Types //~ rjf: String Types
@@ -44,13 +38,6 @@ struct String8Node
String8 string; String8 string;
}; };
typedef struct String8MetaNode String8MetaNode;
struct String8MetaNode
{
String8MetaNode *next;
String8Node *node;
};
typedef struct String8List String8List; typedef struct String8List String8List;
struct String8List struct String8List
{ {
@@ -65,6 +52,7 @@ struct String8Array
{ {
String8 *v; String8 *v;
U64 count; U64 count;
U64 total_size;
}; };
//////////////////////////////// ////////////////////////////////
@@ -96,7 +84,7 @@ typedef enum PathStyle
#elif OS_LINUX #elif OS_LINUX
PathStyle_SystemAbsolute = PathStyle_UnixAbsolute PathStyle_SystemAbsolute = PathStyle_UnixAbsolute
#else #else
# error "absolute path style is undefined for this OS" # error Absolute path style is undefined for this OS.
#endif #endif
} }
PathStyle; PathStyle;
@@ -158,9 +146,9 @@ internal B32 char_is_lower(U8 c);
internal B32 char_is_alpha(U8 c); internal B32 char_is_alpha(U8 c);
internal B32 char_is_slash(U8 c); internal B32 char_is_slash(U8 c);
internal B32 char_is_digit(U8 c, U32 base); internal B32 char_is_digit(U8 c, U32 base);
internal U8 char_to_lower(U8 c); internal U8 lower_from_char(U8 c);
internal U8 char_to_upper(U8 c); internal U8 upper_from_char(U8 c);
internal U8 char_to_correct_slash(U8 c); internal U8 correct_slash_from_char(U8 c);
//////////////////////////////// ////////////////////////////////
//~ rjf: C-String Measurement //~ rjf: C-String Measurement
@@ -206,10 +194,13 @@ internal String8 backslashed_from_str8(Arena *arena, String8 string);
//////////////////////////////// ////////////////////////////////
//~ rjf: String Matching //~ rjf: String Matching
#define str8_match_lit(a_lit, b, flags) str8_match(str8_lit(a_lit), (b), (flags))
#define str8_match_cstr(a_cstr, b, flags) str8_match(str8_cstring(a_cstr), (b), (flags))
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 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_is_before(String8 a, String8 b);
#define str8_ends_with(string, end, flags) str8_match(str8_postfix((string), (end).size), (end), (flags))
//////////////////////////////// ////////////////////////////////
//~ rjf: String Slicing //~ rjf: String Slicing
@@ -220,14 +211,21 @@ internal String8 str8_skip(String8 str, U64 amt);
internal String8 str8_postfix(String8 str, U64 size); internal String8 str8_postfix(String8 str, U64 size);
internal String8 str8_chop(String8 str, U64 amt); internal String8 str8_chop(String8 str, U64 amt);
internal String8 str8_skip_chop_whitespace(String8 string); internal String8 str8_skip_chop_whitespace(String8 string);
internal String8 str8_skip_chop_slashes(String8 string);
//////////////////////////////// ////////////////////////////////
//~ rjf: String Formatting & Copying //~ rjf: String Formatting & Copying
internal String8 push_str8_cat(Arena *arena, String8 s1, String8 s2); internal String8 str8_cat(Arena *arena, String8 s1, String8 s2);
internal String8 push_str8_copy(Arena *arena, String8 s); internal String8 str8_copy(Arena *arena, String8 s);
internal String8 push_str8fv(Arena *arena, char *fmt, va_list args); internal String8 str8fv(Arena *arena, char *fmt, va_list args);
internal String8 push_str8f(Arena *arena, char *fmt, ...); internal String8 str8f(Arena *arena, char *fmt, ...);
// TODO(rjf): remove these once we're ready to convert all usages:
#define push_str8_cat(arena, s1, s2) str8_cat((arena), (s1), (s2))
#define push_str8_copy(arena, s) str8_copy((arena), (s))
#define push_str8fv(arena, fmt, args) str8fv((arena), (fmt), (args))
#define push_str8f(arena, ...) str8f((arena), __VA_ARGS__)
internal String8 push_cstr(Arena *arena, String8 str); // TODO(rjf): this is unnecessary - this is implied by `push_str8_copy`. need to remove.
//////////////////////////////// ////////////////////////////////
//~ rjf: String <=> Integer Conversions //~ rjf: String <=> Integer Conversions
@@ -237,6 +235,8 @@ internal S64 sign_from_str8(String8 string, String8 *string_tail);
internal B32 str8_is_integer(String8 string, U32 radix); internal B32 str8_is_integer(String8 string, U32 radix);
internal U64 u64_from_str8(String8 string, U32 radix); internal U64 u64_from_str8(String8 string, U32 radix);
internal S64 s64_from_str8(String8 string, U32 radix); internal S64 s64_from_str8(String8 string, U32 radix);
internal U32 u32_from_str8(String8 string, U32 radix);
internal S32 s32_from_str8(String8 string, U32 radix);
internal B32 try_u64_from_str8_c_rules(String8 string, U64 *x); 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);
@@ -256,12 +256,12 @@ internal F64 f64_from_str8(String8 string);
//////////////////////////////// ////////////////////////////////
//~ rjf: String List Construction Functions //~ rjf: String List Construction Functions
internal String8Node* str8_list_push_node(String8List *list, String8Node *node); internal String8Node *str8_list_push_node(String8List *list, String8Node *node);
internal String8Node* str8_list_push_node_set_string(String8List *list, String8Node *node, String8 string); internal String8Node *str8_list_push_node_set_string(String8List *list, String8Node *node, String8 string);
internal String8Node* str8_list_push_node_front(String8List *list, String8Node *node); internal String8Node *str8_list_push_node_front(String8List *list, String8Node *node);
internal String8Node* str8_list_push_node_front_set_string(String8List *list, String8Node *node, String8 string); internal String8Node *str8_list_push_node_front_set_string(String8List *list, String8Node *node, String8 string);
internal String8Node* str8_list_push(Arena *arena, String8List *list, String8 string); internal String8Node *str8_list_push(Arena *arena, String8List *list, String8 string);
internal String8Node* str8_list_push_front(Arena *arena, String8List *list, String8 string); internal String8Node *str8_list_push_front(Arena *arena, String8List *list, String8 string);
internal void str8_list_concat_in_place(String8List *list, String8List *to_push); internal void str8_list_concat_in_place(String8List *list, String8List *to_push);
internal String8Node* str8_list_push_aligner(Arena *arena, String8List *list, U64 min, U64 align); internal String8Node* str8_list_push_aligner(Arena *arena, String8List *list, U64 min, U64 align);
internal String8Node* str8_list_pushf(Arena *arena, String8List *list, char *fmt, ...); internal String8Node* str8_list_pushf(Arena *arena, String8List *list, char *fmt, ...);
@@ -274,19 +274,44 @@ internal String8List str8_list_copy(Arena *arena, String8List *list);
internal String8List str8_split(Arena *arena, String8 string, U8 *split_chars, U64 split_char_count, StringSplitFlags flags); internal String8List str8_split(Arena *arena, String8 string, U8 *split_chars, U64 split_char_count, StringSplitFlags flags);
internal String8List str8_split_by_string_chars(Arena *arena, String8 string, String8 split_chars, StringSplitFlags flags); internal String8List str8_split_by_string_chars(Arena *arena, String8 string, String8 split_chars, StringSplitFlags flags);
internal String8List str8_list_split_by_string_chars(Arena *arena, String8List list, String8 split_chars, StringSplitFlags flags);
internal String8 str8_list_join(Arena *arena, String8List *list, StringJoin *optional_params); internal String8 str8_list_join(Arena *arena, String8List *list, StringJoin *optional_params);
internal void str8_list_from_flags(Arena *arena, String8List *list, U32 flags, String8 *flag_string_table, U32 flag_string_count);
////////////////////////////////
//~ rjf: Basic Data Stringification Helpers
internal String8List numeric_str8_list_from_data(Arena *arena, U32 radix, String8 data, U64 stride);
//////////////////////////////// ////////////////////////////////
//~ rjf; String Arrays //~ rjf; String Arrays
internal String8Array str8_array_zero(void);
internal String8Array str8_array_from_list(Arena *arena, String8List *list); internal String8Array str8_array_from_list(Arena *arena, String8List *list);
internal String8Array str8_array_reserve(Arena *arena, U64 count); internal String8Array str8_array_reserve(Arena *arena, U64 count);
internal String8Array str8_array_copy(Arena *arena, String8Array array);
////////////////////////////////
//~ rjf: String <-> Version Helpers
internal U64 version_from_str8(String8 string);
internal String8 str8_from_version(Arena *arena, U64 version);
//////////////////////////////// ////////////////////////////////
//~ rjf: String Path Helpers //~ rjf: String Path Helpers
global read_only struct
{
String8 string;
PathStyle path_style;
}
g_path_style_map[] =
{
{ str8_lit_comp(""), PathStyle_Null },
{ str8_lit_comp("relative"), PathStyle_Relative },
{ str8_lit_comp("windows"), PathStyle_WindowsAbsolute },
{ str8_lit_comp("unix"), PathStyle_UnixAbsolute },
{ str8_lit_comp("system"), PathStyle_SystemAbsolute },
};
internal String8 str8_chop_last_slash(String8 string); internal String8 str8_chop_last_slash(String8 string);
internal String8 str8_skip_last_slash(String8 string); internal String8 str8_skip_last_slash(String8 string);
internal String8 str8_chop_last_dot(String8 string); internal String8 str8_chop_last_dot(String8 string);
@@ -299,6 +324,29 @@ internal String8 str8_path_list_join_by_style(Arena *arena, String8List *pat
internal String8TxtPtPair str8_txt_pt_pair_from_string(String8 string); internal String8TxtPtPair str8_txt_pt_pair_from_string(String8 string);
////////////////////////////////
//~ rjf: Relative <-> Absolute Path
internal String8 path_relative_dst_from_absolute_dst_src(Arena *arena, String8 dst, String8 src);
internal String8 path_absolute_dst_from_relative_dst_src(Arena *arena, String8 dst, String8 src);
////////////////////////////////
//~ rjf: Path Normalization
internal String8List path_normalized_list_from_string(Arena *arena, String8 path, PathStyle *style_out);
internal String8 path_normalized_from_string(Arena *arena, String8 path);
internal B32 path_match_normalized(String8 left, String8 right);
////////////////////////////////
//~ rjf: Misc. Path Helpers
internal PathStyle path_style_from_string(String8 string);
internal String8 string_from_path_style(PathStyle style);
internal String8 path_separator_string_from_style(PathStyle style);
internal StringMatchFlags path_match_flags_from_os(OperatingSystem os);
internal String8 path_convert_slashes(Arena *arena, String8 path, PathStyle path_style);
internal String8 path_replace_file_extension(Arena *arena, String8 file_name, String8 ext);
//////////////////////////////// ////////////////////////////////
//~ rjf: UTF-8 & UTF-16 Decoding/Encoding //~ rjf: UTF-8 & UTF-16 Decoding/Encoding
@@ -306,7 +354,6 @@ internal UnicodeDecode utf8_decode(U8 *str, U64 max);
internal UnicodeDecode utf16_decode(U16 *str, U64 max); internal UnicodeDecode utf16_decode(U16 *str, U64 max);
internal U32 utf8_encode(U8 *str, U32 codepoint); internal U32 utf8_encode(U8 *str, U32 codepoint);
internal U32 utf16_encode(U16 *str, U32 codepoint); internal U32 utf16_encode(U16 *str, U32 codepoint);
internal U32 utf8_from_utf32_single(U8 *buffer, U32 character);
//////////////////////////////// ////////////////////////////////
//~ rjf: Unicode String Conversions //~ rjf: Unicode String Conversions
@@ -317,29 +364,21 @@ 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 //~ rjf: Basic Types & Space Enum <-> String Conversions
internal OperatingSystem operating_system_from_string(String8 string); internal OperatingSystem operating_system_from_string(String8 string);
////////////////////////////////
//~ rjf: Basic Types & Space Enum -> String Conversions
internal String8 string_from_dimension(Dimension dimension); internal String8 string_from_dimension(Dimension dimension);
internal String8 string_from_side(Side side); internal String8 string_from_side(Side side);
internal String8 string_from_operating_system(OperatingSystem os); internal String8 string_from_operating_system(OperatingSystem os);
internal String8 string_from_arch(Arch arch); internal String8 string_from_arch(Arch arch);
////////////////////////////////
//~ rjf: Time Types -> String
internal String8 string_from_week_day(WeekDay week_day); internal String8 string_from_week_day(WeekDay week_day);
internal String8 string_from_month(Month month); internal String8 string_from_month(Month month);
internal String8 push_date_time_string(Arena *arena, DateTime *date_time); internal String8 string_from_date_time(Arena *arena, DateTime *date_time);
internal String8 push_file_name_date_time_string(Arena *arena, DateTime *date_time); internal String8 string_from_date_time__file_name(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 //~ rjf: String <-> Globally Unique IDs
internal String8 string_from_guid(Arena *arena, Guid guid); internal String8 string_from_guid(Arena *arena, Guid guid);
internal B32 try_guid_from_string(String8 string, Guid *guid_out); internal B32 try_guid_from_string(String8 string, Guid *guid_out);
@@ -389,6 +428,7 @@ internal void str8_serial_push_u16(Arena *arena, String8List *srl, U16 x);
internal void str8_serial_push_u8(Arena *arena, String8List *srl, U8 x); internal void str8_serial_push_u8(Arena *arena, String8List *srl, U8 x);
internal void str8_serial_push_cstr(Arena *arena, String8List *srl, String8 str); internal void str8_serial_push_cstr(Arena *arena, String8List *srl, String8 str);
internal void str8_serial_push_string(Arena *arena, String8List *srl, String8 str); internal void str8_serial_push_string(Arena *arena, String8List *srl, String8 str);
internal void str8_serial_push_cstr(Arena *arena, String8List *srl, String8 str);
#define str8_serial_push_array(arena, srl, ptr, count) str8_serial_push_data(arena, srl, ptr, sizeof(*(ptr)) * (count)) #define str8_serial_push_array(arena, srl, ptr, count) str8_serial_push_data(arena, srl, ptr, sizeof(*(ptr)) * (count))
#define str8_serial_push_struct(arena, srl, ptr) str8_serial_push_array(arena, srl, ptr, 1) #define str8_serial_push_struct(arena, srl, ptr) str8_serial_push_array(arena, srl, ptr, 1)
@@ -397,10 +437,19 @@ internal void str8_serial_push_string(Arena *arena, String8List *srl, String8
internal U64 str8_deserial_read(String8 string, U64 off, void *read_dst, U64 read_size, U64 granularity); internal U64 str8_deserial_read(String8 string, U64 off, void *read_dst, U64 read_size, U64 granularity);
internal U64 str8_deserial_find_first_match(String8 string, U64 off, U16 scan_val); internal U64 str8_deserial_find_first_match(String8 string, U64 off, U16 scan_val);
internal void * str8_deserial_get_raw_ptr(String8 string, U64 off, U64 size);internal U64 str8_deserial_read_cstr(String8 string, U64 off, String8 *cstr_out); internal void * str8_deserial_get_raw_ptr(String8 string, U64 off, U64 size);
internal U64 str8_deserial_read_cstr(String8 string, U64 off, String8 *cstr_out);
internal U64 str8_deserial_read_windows_utf16_string16(String8 string, U64 off, String16 *str_out); internal U64 str8_deserial_read_windows_utf16_string16(String8 string, U64 off, String16 *str_out);
internal U64 str8_deserial_read_block(String8 string, U64 off, U64 size, String8 *block_out); internal U64 str8_deserial_read_block(String8 string, U64 off, U64 size, String8 *block_out);
#define str8_deserial_read_array(string, off, ptr, count) str8_deserial_read((string), (off), (ptr), sizeof(*(ptr))*(count), sizeof(*(ptr))) #define str8_deserial_read_array(string, off, ptr, count) str8_deserial_read((string), (off), (ptr), sizeof(*(ptr))*(count), sizeof(*(ptr)))
#define str8_deserial_read_struct(string, off, ptr) str8_deserial_read((string), (off), (ptr), sizeof(*(ptr)), sizeof(*(ptr))) #define str8_deserial_read_struct(string, off, ptr) str8_deserial_read_array(string, off, ptr, 1)
////////////////////////////////
//~ rjf: Basic String Hashes
internal U64 u64_hash_from_seed_str8(U64 seed, String8 string);
internal U64 u64_hash_from_str8(String8 string);
internal U128 u128_hash_from_seed_str8(U64 seed, String8 string);
internal U128 u128_hash_from_str8(String8 string);
#endif // BASE_STRINGS_H #endif // BASE_STRINGS_H
+177 -39
View File
@@ -1,87 +1,225 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
//////////////////////////////// ////////////////////////////////
// NOTE(allen): Thread Context Functions //~ rjf: Globals
C_LINKAGE thread_static TCTX* tctx_thread_local; C_LINKAGE thread_static TCTX *tctx_thread_local;
#if !BUILD_SUPPLEMENTARY_UNIT #if !BUILD_SUPPLEMENTARY_UNIT
C_LINKAGE thread_static TCTX* tctx_thread_local = 0; C_LINKAGE thread_static TCTX *tctx_thread_local = 0;
#endif #endif
////////////////////////////////
//~ rjf: Thread Context Functions
//- rjf: thread-context allocation & selection
internal TCTX *
tctx_alloc(void)
{
Arena *arena = arena_alloc();
TCTX *tctx = push_array(arena, TCTX, 1);
tctx->arenas[0] = arena;
tctx->arenas[1] = arena_alloc();
tctx->lane_ctx.lane_count = 1;
return tctx;
}
internal void internal void
tctx_init_and_equip(TCTX *tctx){ tctx_release(TCTX *tctx)
MemoryZeroStruct(tctx); {
Arena **arena_ptr = tctx->arenas; arena_release(tctx->arenas[1]);
for (U64 i = 0; i < ArrayCount(tctx->arenas); i += 1, arena_ptr += 1){ arena_release(tctx->arenas[0]);
*arena_ptr = arena_alloc(); }
}
internal void
tctx_select(TCTX *tctx)
{
tctx_thread_local = tctx; tctx_thread_local = tctx;
} }
internal void internal TCTX *
tctx_release(void) tctx_selected(void)
{ {
for(U64 i = 0; i < ArrayCount(tctx_thread_local->arenas); i += 1) return tctx_thread_local;
{
arena_release(tctx_thread_local->arenas[i]);
}
} }
internal TCTX* //- rjf: scratch arenas
tctx_get_equipped(void){
return(tctx_thread_local);
}
internal Arena* internal Arena *
tctx_get_scratch(Arena **conflicts, U64 count){ tctx_get_scratch(Arena **conflicts, U64 count)
TCTX *tctx = tctx_get_equipped(); {
TCTX *tctx = tctx_selected();
Arena *result = 0; Arena *result = 0;
Arena **arena_ptr = tctx->arenas; Arena **arena_ptr = tctx->arenas;
for (U64 i = 0; i < ArrayCount(tctx->arenas); i += 1, arena_ptr += 1){ for(U64 i = 0; i < ArrayCount(tctx->arenas); i += 1, arena_ptr += 1)
{
Arena **conflict_ptr = conflicts; Arena **conflict_ptr = conflicts;
B32 has_conflict = 0; B32 has_conflict = 0;
for (U64 j = 0; j < count; j += 1, conflict_ptr += 1){ for(U64 j = 0; j < count; j += 1, conflict_ptr += 1)
if (*arena_ptr == *conflict_ptr){ {
if(*arena_ptr == *conflict_ptr)
{
has_conflict = 1; has_conflict = 1;
break; break;
} }
} }
if (!has_conflict){ if(!has_conflict)
{
result = *arena_ptr; result = *arena_ptr;
break; break;
} }
} }
return result;
return(result); }
//- rjf: lane metadata
internal LaneCtx
tctx_set_lane_ctx(LaneCtx lane_ctx)
{
TCTX *tctx = tctx_selected();
LaneCtx restore = tctx->lane_ctx;
tctx->lane_ctx = lane_ctx;
return restore;
} }
internal void internal void
tctx_set_thread_name(String8 string){ tctx_lane_barrier_wait(void *broadcast_ptr, U64 broadcast_size, U64 broadcast_src_lane_idx)
TCTX *tctx = tctx_get_equipped(); {
ProfBeginFunction();
ProfColor(0x00000ff);
TCTX *tctx = tctx_selected();
// rjf: doing broadcast -> copy to broadcast memory on source lane
U64 broadcast_size_clamped = ClampTop(broadcast_size, sizeof(tctx->lane_ctx.broadcast_memory[0]));
if(broadcast_ptr != 0 && lane_idx() == broadcast_src_lane_idx)
{
MemoryCopy(tctx->lane_ctx.broadcast_memory, broadcast_ptr, broadcast_size_clamped);
}
// rjf: all cases: barrier
os_barrier_wait(tctx->lane_ctx.barrier);
// rjf: doing broadcast -> copy from broadcast memory on destination lanes
if(broadcast_ptr != 0 && lane_idx() != broadcast_src_lane_idx)
{
MemoryCopy(broadcast_ptr, tctx->lane_ctx.broadcast_memory, broadcast_size_clamped);
}
// rjf: doing broadcast -> barrier on all lanes
if(broadcast_ptr != 0)
{
os_barrier_wait(tctx->lane_ctx.barrier);
}
ProfEnd();
}
//- rjf: thread names
internal void
tctx_set_thread_name(String8 string)
{
TCTX *tctx = tctx_selected();
U64 size = ClampTop(string.size, sizeof(tctx->thread_name)); U64 size = ClampTop(string.size, sizeof(tctx->thread_name));
MemoryCopy(tctx->thread_name, string.str, size); MemoryCopy(tctx->thread_name, string.str, size);
tctx->thread_name_size = size; tctx->thread_name_size = size;
} }
internal String8 internal String8
tctx_get_thread_name(void){ tctx_get_thread_name(void)
TCTX *tctx = tctx_get_equipped(); {
TCTX *tctx = tctx_selected();
String8 result = str8(tctx->thread_name, tctx->thread_name_size); String8 result = str8(tctx->thread_name, tctx->thread_name_size);
return(result); return result;
} }
//- rjf: thread source-locations
internal void internal void
tctx_write_srcloc(char *file_name, U64 line_number){ tctx_write_srcloc(char *file_name, U64 line_number)
TCTX *tctx = tctx_get_equipped(); {
TCTX *tctx = tctx_selected();
tctx->file_name = file_name; tctx->file_name = file_name;
tctx->line_number = line_number; tctx->line_number = line_number;
} }
internal void internal void
tctx_read_srcloc(char **file_name, U64 *line_number){ tctx_read_srcloc(char **file_name, U64 *line_number)
TCTX *tctx = tctx_get_equipped(); {
TCTX *tctx = tctx_selected();
*file_name = tctx->file_name; *file_name = tctx->file_name;
*line_number = tctx->line_number; *line_number = tctx->line_number;
} }
////////////////////////////////
//~ rjf: Touch Scope Functions
internal Access *
access_open(void)
{
if(tctx_thread_local->access_arena == 0)
{
tctx_thread_local->access_arena = arena_alloc();
}
Access *access = tctx_thread_local->free_access;
if(access != 0)
{
SLLStackPop(tctx_thread_local->free_access);
}
else
{
access = push_array_no_zero(tctx_thread_local->access_arena, Access, 1);
}
MemoryZeroStruct(access);
return access;
}
internal void
access_close(Access *access)
{
for(Touch *touch = access->top_touch, *next = 0; touch != 0; touch = next)
{
next = touch->next;
ins_atomic_u64_dec_eval(&touch->pt->access_refcount);
if(touch->cv.u64[0] != 0) { cond_var_broadcast(touch->cv); }
SLLStackPush(tctx_thread_local->free_touch, touch);
}
SLLStackPush(tctx_thread_local->free_access, access);
}
internal void
access_touch(Access *access, AccessPt *pt, CondVar cv)
{
ins_atomic_u64_inc_eval(&pt->access_refcount);
ins_atomic_u64_eval_assign(&pt->last_time_touched_us, os_now_microseconds());
ins_atomic_u64_eval_assign(&pt->last_update_idx_touched, update_tick_idx());
Touch *touch = tctx_thread_local->free_touch;
if(touch != 0)
{
SLLStackPop(tctx_thread_local->free_touch);
}
else
{
touch = push_array_no_zero(tctx_thread_local->access_arena, Touch, 1);
}
MemoryZeroStruct(touch);
SLLStackPush(access->top_touch, touch);
touch->cv = cv;
touch->pt = pt;
}
//- rjf: access points
internal B32
access_pt_is_expired_(AccessPt *pt, AccessPtExpireParams *params)
{
U64 access_refcount = ins_atomic_u64_eval(&pt->access_refcount);
U64 last_time_touched_us = ins_atomic_u64_eval(&pt->last_time_touched_us);
U64 last_update_idx_touched = ins_atomic_u64_eval(&pt->last_update_idx_touched);
B32 result = (access_refcount == 0 &&
last_time_touched_us + params->time <= os_now_microseconds() &&
last_update_idx_touched + params->update_idxs <= update_tick_idx());
return result;
}
+106 -15
View File
@@ -1,41 +1,132 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_THREAD_CONTEXT_H #ifndef BASE_THREAD_CONTEXT_H
#define BASE_THREAD_CONTEXT_H #define BASE_THREAD_CONTEXT_H
//////////////////////////////// ////////////////////////////////
// NOTE(allen): Thread Context //~ rjf: Lane Context
typedef struct LaneCtx LaneCtx;
struct LaneCtx
{
U64 lane_idx;
U64 lane_count;
Barrier barrier;
U64 *broadcast_memory;
};
////////////////////////////////
//~ rjf: Access Scopes
typedef struct AccessPt AccessPt;
struct AccessPt
{
U64 access_refcount;
U64 last_time_touched_us;
U64 last_update_idx_touched;
};
typedef struct AccessPtExpireParams AccessPtExpireParams;
struct AccessPtExpireParams
{
U64 time;
U64 update_idxs;
};
typedef struct Touch Touch;
struct Touch
{
Touch *next;
AccessPt *pt;
CondVar cv;
};
typedef struct Access Access;
struct Access
{
Access *next;
Touch *top_touch;
};
////////////////////////////////
//~ rjf: Base Per-Thread State Bundle
typedef struct TCTX TCTX; typedef struct TCTX TCTX;
struct TCTX struct TCTX
{ {
// rjf: scratch arenas
Arena *arenas[2]; Arena *arenas[2];
// rjf: thread name
U8 thread_name[32]; U8 thread_name[32];
U64 thread_name_size; U64 thread_name_size;
// rjf: lane context
LaneCtx lane_ctx;
// rjf: source location info
char *file_name; char *file_name;
U64 line_number; U64 line_number;
// rjf: accesses
Arena *access_arena;
Access *free_access;
Touch *free_touch;
// rjf: progress
U64 *progress_counter_ptr;
U64 *progress_target_ptr;
}; };
//////////////////////////////// ////////////////////////////////
// NOTE(allen): Thread Context Functions //~ rjf: Thread Context Functions
internal void tctx_init_and_equip(TCTX *tctx); //- rjf: thread-context allocation & selection
internal void tctx_release(void); internal TCTX *tctx_alloc(void);
internal TCTX* tctx_get_equipped(void); internal void tctx_release(TCTX *tctx);
internal void tctx_select(TCTX *tctx);
internal Arena* tctx_get_scratch(Arena **conflicts, U64 countt); internal TCTX *tctx_selected(void);
internal void tctx_set_thread_name(String8 name);
internal String8 tctx_get_thread_name(void);
internal void tctx_write_srcloc(char *file_name, U64 line_number);
internal void tctx_read_srcloc(char **file_name, U64 *line_number);
#define tctx_write_this_srcloc() tctx_write_srcloc(__FILE__, __LINE__)
//- rjf: scratch arenas
internal Arena *tctx_get_scratch(Arena **conflicts, U64 count);
#define scratch_begin(conflicts, count) temp_begin(tctx_get_scratch((conflicts), (count))) #define scratch_begin(conflicts, count) temp_begin(tctx_get_scratch((conflicts), (count)))
#define scratch_end(scratch) temp_end(scratch) #define scratch_end(scratch) temp_end(scratch)
//- rjf: lane metadata
internal LaneCtx tctx_set_lane_ctx(LaneCtx lane_ctx);
internal void tctx_lane_barrier_wait(void *broadcast_ptr, U64 broadcast_size, U64 broadcast_src_lane_idx);
#define lane_idx() (tctx_selected()->lane_ctx.lane_idx)
#define lane_count() (tctx_selected()->lane_ctx.lane_count)
#define lane_from_task_idx(idx) ((idx)%lane_count())
#define lane_ctx(ctx) tctx_set_lane_ctx((ctx))
#define lane_sync() tctx_lane_barrier_wait(0, 0, 0)
#define lane_sync_u64(ptr, src_lane_idx) tctx_lane_barrier_wait((ptr), sizeof(*(ptr)), (src_lane_idx))
#define lane_range(count) m_range_from_n_idx_m_count(lane_idx(), lane_count(), (count))
//- rjf: thread names
internal void tctx_set_thread_name(String8 name);
internal String8 tctx_get_thread_name(void);
//- rjf: thread source-locations
internal void tctx_write_srcloc(char *file_name, U64 line_number);
internal void tctx_read_srcloc(char **file_name, U64 *line_number);
#define tctx_write_this_srcloc() tctx_write_srcloc(__FILE__, __LINE__)
//- rjf: access scopes
internal Access *access_open(void);
internal void access_close(Access *access);
internal void access_touch(Access *access, AccessPt *pt, CondVar cv);
//- rjf: access points
internal B32 access_pt_is_expired_(AccessPt *pt, AccessPtExpireParams *params);
#define access_pt_is_expired(pt, ...) access_pt_is_expired_((pt), &(AccessPtExpireParams){.time = 2000000, .update_idxs = 2, __VA_ARGS__})
//- rjf: progress counters
#define set_progress_ptr(ptr) (tctx_selected()->progress_counter_ptr = (ptr))
#define set_progress_target_ptr(ptr) (tctx_selected()->progress_target_ptr = (ptr))
#define set_progress(val) (tctx_selected()->progress_counter_ptr ? ins_atomic_u64_eval_assign(tctx_selected()->progress_counter_ptr, (val)) : (void)0)
#define add_progress(val) (tctx_selected()->progress_counter_ptr ? ins_atomic_u64_add_eval(tctx_selected()->progress_counter_ptr, (val)) : (void)0)
#define set_progress_target(val) (tctx_selected()->progress_target_ptr ? ins_atomic_u64_eval_assign(tctx_selected()->progress_target_ptr, (val)) : (void)0)
#endif // BASE_THREAD_CONTEXT_H #endif // BASE_THREAD_CONTEXT_H
+102
View File
@@ -0,0 +1,102 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: Thread Functions
internal Thread
thread_launch(ThreadEntryPointFunctionType *f, void *p)
{
Thread thread = os_thread_launch(f, p);
return thread;
}
internal B32
thread_join(Thread thread, U64 endt_us)
{
B32 result = os_thread_join(thread, endt_us);
return result;
}
internal void
thread_detach(Thread thread)
{
os_thread_detach(thread);
}
////////////////////////////////
//~ rjf: Synchronization Primitive Functions
//- rjf: recursive mutexes
internal Mutex mutex_alloc(void) {return os_mutex_alloc();}
internal void mutex_release(Mutex mutex) {os_mutex_release(mutex);}
internal void mutex_take(Mutex mutex) {os_mutex_take(mutex);}
internal void mutex_drop(Mutex mutex) {os_mutex_drop(mutex);}
//- rjf: reader/writer mutexes
internal RWMutex rw_mutex_alloc(void) {return os_rw_mutex_alloc();}
internal void rw_mutex_release(RWMutex mutex) {os_rw_mutex_release(mutex);}
internal void rw_mutex_take(RWMutex mutex, B32 write_mode) {os_rw_mutex_take(mutex, write_mode);}
internal void rw_mutex_drop(RWMutex mutex, B32 write_mode) {os_rw_mutex_drop(mutex, write_mode);}
//- rjf: condition variables
internal CondVar cond_var_alloc(void) {return os_cond_var_alloc();}
internal void cond_var_release(CondVar cv) {os_cond_var_release(cv);}
internal B32 cond_var_wait(CondVar cv, Mutex mutex, U64 endt_us) {return os_cond_var_wait(cv, mutex, endt_us);}
internal B32 cond_var_wait_rw(CondVar cv, RWMutex mutex_rw, B32 write_mode, U64 endt_us) {return os_cond_var_wait_rw(cv, mutex_rw, write_mode, endt_us);}
internal void cond_var_signal(CondVar cv) {os_cond_var_signal(cv);}
internal void cond_var_broadcast(CondVar cv) {os_cond_var_broadcast(cv);}
//- rjf: cross-process semaphores
internal Semaphore semaphore_alloc(U32 initial_count, U32 max_count, String8 name) {return os_semaphore_alloc(initial_count, max_count, name);}
internal void semaphore_release(Semaphore semaphore) {os_semaphore_release(semaphore);}
internal Semaphore semaphore_open(String8 name) {return os_semaphore_open(name);}
internal void semaphore_close(Semaphore semaphore) {os_semaphore_close(semaphore);}
internal B32 semaphore_take(Semaphore semaphore, U64 endt_us) {return os_semaphore_take(semaphore, endt_us);}
internal void semaphore_drop(Semaphore semaphore) {os_semaphore_drop(semaphore);}
//- rjf: barriers
internal Barrier barrier_alloc(U64 count) {return os_barrier_alloc(count);}
internal void barrier_release(Barrier barrier) {os_barrier_release(barrier);}
internal void barrier_wait(Barrier barrier) {os_barrier_wait(barrier);}
////////////////////////////////
//~ rjf: Table Stripe Functions
internal StripeArray
stripe_array_alloc(Arena *arena)
{
StripeArray array = {0};
array.count = os_get_system_info()->logical_processor_count;
array.v = push_array(arena, Stripe, array.count);
for EachIndex(idx, array.count)
{
array.v[idx].arena = arena_alloc();
array.v[idx].rw_mutex = rw_mutex_alloc();
array.v[idx].cv = cond_var_alloc();
}
return array;
}
internal void
stripe_array_release(StripeArray *stripes)
{
for EachIndex(idx, stripes->count)
{
arena_release(stripes->v[idx].arena);
rw_mutex_release(stripes->v[idx].rw_mutex);
cond_var_release(stripes->v[idx].cv);
}
}
internal Stripe *
stripe_from_slot_idx(StripeArray *stripes, U64 slot_idx)
{
Stripe *stripe = &stripes->v[slot_idx%stripes->count];
return stripe;
}
+133
View File
@@ -0,0 +1,133 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef BASE_THREADS_H
#define BASE_THREADS_H
////////////////////////////////
//~ rjf: Thread Types
typedef struct Thread Thread;
struct Thread
{
U64 u64[1];
};
typedef void ThreadEntryPointFunctionType(void *p);
////////////////////////////////
//~ rjf: Synchronization Primitive Types
typedef struct Mutex Mutex;
struct Mutex
{
U64 u64[1];
};
typedef struct RWMutex RWMutex;
struct RWMutex
{
U64 u64[1];
};
typedef struct CondVar CondVar;
struct CondVar
{
U64 u64[1];
};
typedef struct Semaphore Semaphore;
struct Semaphore
{
U64 u64[1];
};
typedef struct Barrier Barrier;
struct Barrier
{
U64 u64[1];
};
////////////////////////////////
//~ rjf: Table Stripes
typedef struct Stripe Stripe;
struct Stripe
{
Arena *arena;
RWMutex rw_mutex;
CondVar cv;
void *free;
};
typedef struct StripeArray StripeArray;
struct StripeArray
{
Stripe *v;
U64 count;
};
////////////////////////////////
//~ rjf: Thread Functions
internal Thread thread_launch(ThreadEntryPointFunctionType *f, void *p);
internal B32 thread_join(Thread thread, U64 endt_us);
internal void thread_detach(Thread thread);
////////////////////////////////
//~ rjf: Synchronization Primitive Functions
//- rjf: recursive mutexes
internal Mutex mutex_alloc(void);
internal void mutex_release(Mutex mutex);
internal void mutex_take(Mutex mutex);
internal void mutex_drop(Mutex mutex);
//- rjf: reader/writer mutexes
internal RWMutex rw_mutex_alloc(void);
internal void rw_mutex_release(RWMutex mutex);
internal void rw_mutex_take(RWMutex mutex, B32 write_mode);
internal void rw_mutex_drop(RWMutex mutex, B32 write_mode);
#define rw_mutex_take_r(m) rw_mutex_take((m), (0))
#define rw_mutex_take_w(m) rw_mutex_take((m), (1))
#define rw_mutex_drop_r(m) rw_mutex_drop((m), (0))
#define rw_mutex_drop_w(m) rw_mutex_drop((m), (1))
//- rjf: condition variables
internal CondVar cond_var_alloc(void);
internal void cond_var_release(CondVar cv);
// returns false on timeout, true on signal, (max_wait_ms = max_U64) -> no timeout
internal B32 cond_var_wait(CondVar cv, Mutex mutex, U64 endt_us);
internal B32 cond_var_wait_rw(CondVar cv, RWMutex mutex_rw, B32 write_mode, U64 endt_us);
#define cond_var_wait_rw_r(cv, m, endt) cond_var_wait_rw((cv), (m), (0), (endt))
#define cond_var_wait_rw_w(cv, m, endt) cond_var_wait_rw((cv), (m), (1), (endt))
internal void cond_var_signal(CondVar cv);
internal void cond_var_broadcast(CondVar cv);
//- rjf: cross-process semaphores
internal Semaphore semaphore_alloc(U32 initial_count, U32 max_count, String8 name);
internal void semaphore_release(Semaphore semaphore);
internal Semaphore semaphore_open(String8 name);
internal void semaphore_close(Semaphore semaphore);
internal B32 semaphore_take(Semaphore semaphore, U64 endt_us);
internal void semaphore_drop(Semaphore semaphore);
//- rjf: barriers
internal Barrier barrier_alloc(U64 count);
internal void barrier_release(Barrier barrier);
internal void barrier_wait(Barrier barrier);
//- rjf: scope macros
#define MutexScope(mutex) DeferLoop(mutex_take(mutex), mutex_drop(mutex))
#define RWMutexScope(mutex, write_mode) DeferLoop(rw_mutex_take((mutex), (write_mode)), rw_mutex_drop((mutex), (write_mode)))
#define MutexScopeR(mutex) DeferLoop(rw_mutex_take_r(mutex), rw_mutex_drop_r(mutex))
#define MutexScopeW(mutex) DeferLoop(rw_mutex_take_w(mutex), rw_mutex_drop_w(mutex))
#define MutexScopeRWPromote(mutex) DeferLoop((rw_mutex_drop_r(mutex), rw_mutex_take_w(mutex)), (rw_mutex_drop_w(mutex), rw_mutex_take_r(mutex)))
////////////////////////////////
//~ rjf: Table Stripe Functions
internal StripeArray stripe_array_alloc(Arena *arena);
internal void stripe_array_release(StripeArray *stripes);
internal Stripe *stripe_from_slot_idx(StripeArray *stripes, U64 slot_idx);
#endif // BASE_THREADS_H
+1019 -556
View File
File diff suppressed because it is too large. Load diff
+1384 -1484
View File
File diff suppressed because it is too large. Load diff
+34 -34
View File
@@ -395,48 +395,48 @@ CV_BasicTypeTable:
{FBASICSTR 0x06 "" } {FBASICSTR 0x06 "" }
{NOTTRANS 0x07 "" } {NOTTRANS 0x07 "" }
{HRESULT 0x08 "HRESULT" } {HRESULT 0x08 "HRESULT" }
{CHAR 0x10 "char" } {CHAR 0x10 "CHAR" }
{SHORT 0x11 "S16" } {SHORT 0x11 "SHORT" }
{LONG 0x12 "S32" } {LONG 0x12 "LONG" }
{QUAD 0x13 "S64" } {QUAD 0x13 "QUAD" }
{OCT 0x14 "S128" } {OCT 0x14 "OCT" }
{UCHAR 0x20 "UCHAR" } {UCHAR 0x20 "UCHAR" }
{USHORT 0x21 "U16" } {USHORT 0x21 "USHORT" }
{ULONG 0x22 "U32" } {ULONG 0x22 "ULONG" }
{UQUAD 0x23 "U64" } {UQUAD 0x23 "UQUAD" }
{UOCT 0x24 "U128" } {UOCT 0x24 "UOCT" }
{BOOL8 0x30 "B8" } {BOOL8 0x30 "BOOL8" }
{BOOL16 0x31 "B16" } {BOOL16 0x31 "BOOL16" }
{BOOL32 0x32 "B32" } {BOOL32 0x32 "BOOL32" }
{BOOL64 0x33 "B64" } {BOOL64 0x33 "BOOL64" }
{FLOAT32 0x40 "F32" } {FLOAT32 0x40 "FLOAT32" }
{FLOAT64 0x41 "F64" } {FLOAT64 0x41 "FLOAT64" }
{FLOAT80 0x42 "F80" } {FLOAT80 0x42 "FLOAT80" }
{FLOAT128 0x43 "F128" } {FLOAT128 0x43 "FLOAT128" }
{FLOAT48 0x44 "F48" } {FLOAT48 0x44 "FLOAT48" }
{FLOAT32PP 0x45 "F32PP" } {FLOAT32PP 0x45 "FLOAT32PP" }
{FLOAT16 0x46 "F16" } {FLOAT16 0x46 "FLOAT16" }
{COMPLEX32 0x50 "ComplexF32" } {COMPLEX32 0x50 "ComplexF32" }
{COMPLEX64 0x51 "ComplexF64" } {COMPLEX64 0x51 "ComplexF64" }
{COMPLEX80 0x52 "ComplexF80" } {COMPLEX80 0x52 "ComplexF80" }
{COMPLEX128 0x53 "ComplexF128" } {COMPLEX128 0x53 "ComplexF128" }
{BIT 0x60 "" } {BIT 0x60 "" }
{PASCHAR 0x61 "" } {PASCHAR 0x61 "" }
{BOOL32FF 0x62 "B32FF" } {BOOL32FF 0x62 "BOOL32FF" }
{INT8 0x68 "S8" } {INT8 0x68 "int8" }
{UINT8 0x69 "U8" } {UINT8 0x69 "uint8" }
{RCHAR 0x70 "char" } {RCHAR 0x70 "char" }
{WCHAR 0x71 "WCHAR" } {WCHAR 0x71 "WCHAR" }
{INT16 0x72 "S16" } {INT16 0x72 "int16" }
{UINT16 0x73 "U16" } {UINT16 0x73 "uint16" }
{INT32 0x74 "S32" } {INT32 0x74 "int32" }
{UINT32 0x75 "U32" } {UINT32 0x75 "uint32" }
{INT64 0x76 "S64" } {INT64 0x76 "int64" }
{UINT64 0x77 "U64" } {UINT64 0x77 "uint64" }
{INT128 0x78 "S128" } {INT128 0x78 "int128" }
{UINT128 0x79 "U128" } {UINT128 0x79 "uint128" }
{CHAR16 0x7a "CHAR16" } {CHAR16 0x7a "char16" }
{CHAR32 0x7b "CHAR32" } {CHAR32 0x7b "char32" }
{CHAR8 0x7c "char" } {CHAR8 0x7c "char" }
{PTR 0xf0 "PTR" } {PTR 0xf0 "PTR" }
} }
@@ -588,7 +588,7 @@ CV_LeafKindTable:
{MATRIX - 0x151c} {MATRIX - 0x151c}
{VFTABLE - 0x151d} {VFTABLE - 0x151d}
{FUNC_ID FuncId 0x1601} {FUNC_ID FuncId 0x1601}
{MFUNC_ID MFuncId 0x1602} {MFUNC_ID MFuncId 0x1602}
{BUILDINFO BuildInfo 0x1603} {BUILDINFO BuildInfo 0x1603}
{SUBSTR_LIST SubstrList 0x1604} {SUBSTR_LIST SubstrList 0x1604}
{STRING_ID StringId 0x1605} {STRING_ID StringId 0x1605}
+24
View File
@@ -0,0 +1,24 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal String8
cv_string_from_numeric(Arena *arena, CV_NumericParsed num)
{
String8 result = str8_zero();
switch (num.kind) {
case CV_NumericKind_FLOAT16: NotImplemented; break; // TODO: format float16
case CV_NumericKind_FLOAT32: result = push_str8f(arena, "%f", (F64)(*(F32*)num.val)); break;
case CV_NumericKind_FLOAT48: NotImplemented; break; // TODO: format float48
case CV_NumericKind_FLOAT64: result = push_str8f(arena, "%f", *(F64*)num.val); break;
case CV_NumericKind_FLOAT80: NotImplemented; break; // TODO: format float80
case CV_NumericKind_FLOAT128: NotImplemented; break; // TODO: format float128
case CV_NumericKind_CHAR: result = push_str8f(arena, "%d", *(S8 *)num.val); break;
case CV_NumericKind_SHORT: result = push_str8f(arena, "%d", *(S16*)num.val); break;
case CV_NumericKind_LONG: result = push_str8f(arena, "%d", *(S32*)num.val); break;
case CV_NumericKind_QUADWORD: result = push_str8f(arena, "%lld", *(S64*)num.val); break;
case CV_NumericKind_USHORT: result = push_str8f(arena, "%u", *(U16*)num.val); break;
case CV_NumericKind_ULONG: result = push_str8f(arena, "%u", *(U32*)num.val); break;
case CV_NumericKind_UQUADWORD: result = push_str8f(arena, "%llu", *(U64*)num.val); break;
}
return result;
}
+9
View File
@@ -0,0 +1,9 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef CODEVIEW_DUMP_H
#define CODEVIEW_DUMP_H
internal String8 cv_string_from_numeric(Arena *arena, CV_NumericParsed num);
#endif // CODEVIEW_DUMP_H
File diff suppressed because it is too large. Load diff
+305
View File
@@ -0,0 +1,305 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef CODEVIEW_PARSE_H
#define CODEVIEW_PARSE_H
////////////////////////////////
//~ CodeView Common Parser Types
// CV_Numeric layout
// x: U16
// buf: U8[]
// case (x < 0x8000): kind=U16 val=x
// case (x >= 0x8000): kind=x val=buf
typedef struct CV_NumericParsed CV_NumericParsed;
struct CV_NumericParsed
{
CV_NumericKind kind;
U8 *val;
U64 encoded_size;
};
typedef struct CV_RecRange CV_RecRange;
struct CV_RecRange
{
U32 off;
CV_RecHeader hdr;
};
#define CV_REC_RANGE_CHUNK_SIZE 511
typedef struct CV_RecRangeChunk CV_RecRangeChunk;
struct CV_RecRangeChunk
{
struct CV_RecRangeChunk *next;
CV_RecRange ranges[CV_REC_RANGE_CHUNK_SIZE];
};
typedef struct CV_RecRangeStream CV_RecRangeStream;
struct CV_RecRangeStream
{
CV_RecRangeChunk *first_chunk;
CV_RecRangeChunk *last_chunk;
U64 total_count;
};
typedef struct CV_RecRangeArray CV_RecRangeArray;
struct CV_RecRangeArray
{
CV_RecRange *ranges;
U64 count;
};
////////////////////////////////
//~ CodeView Sym Parser Types
typedef struct CV_SymTopLevelInfo CV_SymTopLevelInfo;
struct CV_SymTopLevelInfo
{
CV_Arch arch;
CV_Language language;
String8 compiler_name;
};
typedef struct CV_SymParsed CV_SymParsed;
struct CV_SymParsed
{
// source information
String8 data;
U64 sym_align;
// sym index derived from source
CV_RecRangeArray sym_ranges;
// top-level info derived from the syms
CV_SymTopLevelInfo info;
};
////////////////////////////////
//~ CodeView Leaf Parser Types
typedef struct CV_LeafParsed CV_LeafParsed;
struct CV_LeafParsed
{
// source information
String8 data;
CV_TypeId itype_first;
CV_TypeId itype_opl;
// leaf index derived from source
CV_RecRangeArray leaf_ranges;
};
////////////////////////////////
//~ CodeView C13 Info Parser Types
typedef struct CV_C13InlineSiteDecoder CV_C13InlineSiteDecoder;
struct CV_C13InlineSiteDecoder
{
U64 cursor;
U64 parent_voff;
CV_InlineRangeKind range_kind;
U32 code_length;
U32 code_offset;
U32 file_off;
S32 ln;
S32 cn;
U64 code_offset_lo;
B32 code_offset_changed;
B32 code_offset_lo_changed;
B32 code_length_changed;
B32 ln_changed;
B32 file_off_changed;
Rng1U64 last_range;
U32 file_count;
Rng1U64 file_last_range;
U64 file_line_count;
U64 file_last_ln;
};
typedef U32 CV_C13InlineSiteDecoderStepFlags;
enum
{
CV_C13InlineSiteDecoderStepFlag_EmitRange = (1 << 0),
CV_C13InlineSiteDecoderStepFlag_ExtendLastRange = (1 << 1),
CV_C13InlineSiteDecoderStepFlag_EmitFile = (1 << 2),
CV_C13InlineSiteDecoderStepFlag_EmitLine = (1 << 3),
};
typedef struct CV_C13InlineSiteDecoderStep CV_C13InlineSiteDecoderStep;
struct CV_C13InlineSiteDecoderStep
{
CV_C13InlineSiteDecoderStepFlags flags;
Rng1U64 range;
U64 line_voff;
U64 line_voff_end;
U64 ln;
U64 cn;
U32 file_off;
};
typedef struct CV_C13LinesParsed CV_C13LinesParsed;
struct CV_C13LinesParsed
{
// raw info
U32 sec_idx;
U32 file_off;
U64 secrel_base_off;
// parsed info
String8 file_name;
CV_C13ChecksumKind checksum_kind;
String8 checksum;
U64 *voffs; // [line_count + 1]
U32 *line_nums; // [line_count]
U16 *col_nums; // [2*line_count]
U32 line_count;
};
typedef struct CV_C13LinesParsedNode CV_C13LinesParsedNode;
struct CV_C13LinesParsedNode
{
CV_C13LinesParsedNode *next;
CV_C13LinesParsed v;
};
typedef struct CV_C13InlineeLinesParsed CV_C13InlineeLinesParsed;
struct CV_C13InlineeLinesParsed
{
CV_ItemId inlinee;
U32 file_off;
String8 file_name;
CV_C13ChecksumKind checksum_kind;
String8 checksum;
U32 first_source_ln;
U32 extra_file_count;
U32 *extra_files;
};
typedef struct CV_C13InlineeLinesParsedNode CV_C13InlineeLinesParsedNode;
struct CV_C13InlineeLinesParsedNode
{
CV_C13InlineeLinesParsedNode *next;
CV_C13InlineeLinesParsedNode *hash_next;
CV_C13InlineeLinesParsed v;
};
typedef struct CV_C13SubSectionNode CV_C13SubSectionNode;
struct CV_C13SubSectionNode
{
struct CV_C13SubSectionNode *next;
CV_C13SubSectionKind kind;
U32 off;
U32 size;
CV_C13LinesParsedNode *lines_first;
CV_C13LinesParsedNode *lines_last;
CV_C13InlineeLinesParsedNode *inlinee_lines_first;
CV_C13InlineeLinesParsedNode *inlinee_lines_last;
};
typedef struct CV_C13Parsed CV_C13Parsed;
struct CV_C13Parsed
{
// rjf: source data
String8 data;
// rjf: full sub-section list
CV_C13SubSectionNode *first_sub_section;
CV_C13SubSectionNode *last_sub_section;
U64 sub_section_count;
// rjf: fastpath to file checksums section
CV_C13SubSectionNode *file_chksms_sub_section;
// rjf: fastpath to map inlinee CV_ItemId -> CV_InlineeLinesParsed quickly
CV_C13InlineeLinesParsedNode **inlinee_lines_parsed_slots;
U64 inlinee_lines_parsed_slots_count;
};
typedef struct CV_UDTInfo CV_UDTInfo;
struct CV_UDTInfo
{
String8 name;
String8 unique_name;
CV_TypeProps props;
};
////////////////////////////////
//~ CodeView Compound Types
typedef struct CV_TypeIdArray CV_TypeIdArray;
struct CV_TypeIdArray
{
CV_TypeId *itypes;
U64 count;
};
////////////////////////////////
//- Hasher
internal U64 cv_hash_from_string(String8 string);
internal U64 cv_hash_from_item_id(CV_ItemId item_id);
//- Numeric Decoder
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_s64(CV_NumericParsed *num);
internal B32 cv_numeric_fits_in_f64(CV_NumericParsed *num);
internal U64 cv_u64_from_numeric(CV_NumericParsed *num);
internal S64 cv_s64_from_numeric(CV_NumericParsed *num);
internal F64 cv_f64_from_numeric(CV_NumericParsed *num);
//- Inlinee Lines Binary Annot Decoder
internal U64 cv_decode_inline_annot_u32(String8 data, U64 offset, U32 *out_value);
internal U64 cv_decode_inline_annot_s32(String8 data, U64 offset, S32 *out_value);
internal S32 cv_inline_annot_signed_from_unsigned_operand(U32 value);
internal CV_C13InlineSiteDecoder cv_c13_inline_site_decoder_init(U32 file_off, U32 first_source_ln, U32 parent_voff);
internal CV_C13InlineSiteDecoderStep cv_c13_inline_site_decoder_step(CV_C13InlineSiteDecoder *decoder, String8 binary_annots);
//- Symbol/Leaf Helpers
internal B32 cv_is_udt_name_anon(String8 name);
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_udt(CV_LeafKind kind);
internal B32 cv_is_leaf_type_server(CV_LeafKind kind);
internal B32 cv_is_leaf_pch(CV_LeafKind kind);
internal CV_TypeIndexSource cv_type_index_source_from_leaf_kind(CV_LeafKind leaf_kind);
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 U64 cv_name_offset_from_symbol(CV_SymKind kind, String8 data);
internal String8 cv_name_from_symbol(CV_SymKind kind, String8 data);
internal CV_UDTInfo cv_get_udt_info(CV_LeafKind kind, String8 data);
internal String8 cv_name_from_udt_info(CV_UDTInfo udt_info);
//- rjf: record range stream parsing
internal CV_RecRangeStream * cv_rec_range_stream_from_data(Arena *arena, String8 data, U64 align);
internal CV_RecRangeArray cv_rec_range_array_from_stream(Arena *arena, CV_RecRangeStream *stream);
//- rjf: sym stream parsing
internal CV_SymParsed * cv_sym_from_data(Arena *arena, String8 sym_data, U64 sym_align);
//- rjf: leaf stream parsing
internal CV_LeafParsed * cv_leaf_from_data(Arena *arena, String8 leaf_data, CV_TypeId first);
internal CV_C13Parsed * cv_c13_parsed_from_data(Arena *arena, String8 c13_data, String8 strtbl, COFF_SectionHeaderArray sections);
#endif // CODEVIEW_PARSE_H
File diff suppressed because it is too large. Load diff
-84
View File
@@ -1,84 +0,0 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef CODEVIEW_STRINGIZE_H
#define CODEVIEW_STRINGIZE_H
////////////////////////////////
//~ CodeView Stringize Helper Types
typedef struct CV_StringizeSymParams{
CV_Arch arch;
} CV_StringizeSymParams;
typedef struct CV_StringizeLeafParams{
U32 dummy;
} CV_StringizeLeafParams;
////////////////////////////////
//~ CodeView Common Stringize Functions
internal void cv_stringize_numeric(Arena *arena, String8List *out, CV_NumericParsed *num);
internal void cv_stringize_lvar_addr_range(Arena *arena, String8List *out,
CV_LvarAddrRange *range);
internal void cv_stringize_lvar_addr_gap(Arena *arena, String8List *out, CV_LvarAddrGap *gap);
internal void cv_stringize_lvar_addr_gap_list(Arena *arena, String8List *out,
void *first, void *opl);
internal String8 cv_string_from_basic_type(CV_BasicType basic_type);
internal String8 cv_string_from_c13_sub_section_kind(CV_C13SubSectionKind kind);
internal String8 cv_string_from_reg(CV_Arch arch, CV_Reg reg);
internal String8 cv_string_from_pointer_kind(CV_PointerKind ptr_kind);
internal String8 cv_string_from_pointer_mode(CV_PointerMode ptr_mode);
internal String8 cv_string_from_hfa_kind(CV_HFAKind hfa_kind);
internal String8 cv_string_from_mo_com_udt_kind(CV_MoComUDTKind mo_com_udt_kind);
////////////////////////////////
//~ CodeView Flags Stringize Functions
internal void cv_stringize_modifier_flags(Arena *arena, String8List *out,
U32 indent, CV_ModifierFlags flags);
internal void cv_stringize_type_props(Arena *arena, String8List *out,
U32 indent, CV_TypeProps props);
internal void cv_stringize_pointer_attribs(Arena *arena, String8List *out,
U32 indent, CV_PointerAttribs attribs);
internal void cv_stringize_local_flags(Arena *arena, String8List *out,
U32 indent, CV_LocalFlags flags);
////////////////////////////////
//~ CodeView Sym Stringize Functions
internal void cv_stringize_sym_parsed(Arena *arena, String8List *out, CV_SymParsed *sym);
internal void cv_stringize_sym_range(Arena *arena, String8List *out,
CV_RecRange *range, String8 data,
CV_StringizeSymParams *p);
internal void cv_stringize_sym_array(Arena *arena, String8List *out,
CV_RecRangeArray *ranges, String8 data,
CV_StringizeSymParams *p);
////////////////////////////////
//~ CodeView Leaf Stringize Functions
internal void cv_stringize_leaf_parsed(Arena *arena, String8List *out, CV_LeafParsed *leaf);
internal void cv_stringize_leaf_range(Arena *arena, String8List *out,
CV_RecRange *range, CV_TypeId itype, String8 data,
CV_StringizeLeafParams *p);
internal void cv_stringize_leaf_array(Arena *arena, String8List *out,
CV_RecRangeArray *ranges, CV_TypeId itype_first,
String8 data,
CV_StringizeLeafParams *p);
////////////////////////////////
//~ CodeView C13 Stringize Functions
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
+34 -34
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE //- GENERATED CODE
@@ -392,48 +392,48 @@ case CV_BasicType_NBASICSTR:{result = str8_lit("");}break;
case CV_BasicType_FBASICSTR:{result = str8_lit("");}break; case CV_BasicType_FBASICSTR:{result = str8_lit("");}break;
case CV_BasicType_NOTTRANS:{result = str8_lit("");}break; case CV_BasicType_NOTTRANS:{result = str8_lit("");}break;
case CV_BasicType_HRESULT:{result = str8_lit("HRESULT");}break; case CV_BasicType_HRESULT:{result = str8_lit("HRESULT");}break;
case CV_BasicType_CHAR:{result = str8_lit("char");}break; case CV_BasicType_CHAR:{result = str8_lit("CHAR");}break;
case CV_BasicType_SHORT:{result = str8_lit("S16");}break; case CV_BasicType_SHORT:{result = str8_lit("SHORT");}break;
case CV_BasicType_LONG:{result = str8_lit("S32");}break; case CV_BasicType_LONG:{result = str8_lit("LONG");}break;
case CV_BasicType_QUAD:{result = str8_lit("S64");}break; case CV_BasicType_QUAD:{result = str8_lit("QUAD");}break;
case CV_BasicType_OCT:{result = str8_lit("S128");}break; case CV_BasicType_OCT:{result = str8_lit("OCT");}break;
case CV_BasicType_UCHAR:{result = str8_lit("UCHAR");}break; case CV_BasicType_UCHAR:{result = str8_lit("UCHAR");}break;
case CV_BasicType_USHORT:{result = str8_lit("U16");}break; case CV_BasicType_USHORT:{result = str8_lit("USHORT");}break;
case CV_BasicType_ULONG:{result = str8_lit("U32");}break; case CV_BasicType_ULONG:{result = str8_lit("ULONG");}break;
case CV_BasicType_UQUAD:{result = str8_lit("U64");}break; case CV_BasicType_UQUAD:{result = str8_lit("UQUAD");}break;
case CV_BasicType_UOCT:{result = str8_lit("U128");}break; case CV_BasicType_UOCT:{result = str8_lit("UOCT");}break;
case CV_BasicType_BOOL8:{result = str8_lit("B8");}break; case CV_BasicType_BOOL8:{result = str8_lit("BOOL8");}break;
case CV_BasicType_BOOL16:{result = str8_lit("B16");}break; case CV_BasicType_BOOL16:{result = str8_lit("BOOL16");}break;
case CV_BasicType_BOOL32:{result = str8_lit("B32");}break; case CV_BasicType_BOOL32:{result = str8_lit("BOOL32");}break;
case CV_BasicType_BOOL64:{result = str8_lit("B64");}break; case CV_BasicType_BOOL64:{result = str8_lit("BOOL64");}break;
case CV_BasicType_FLOAT32:{result = str8_lit("F32");}break; case CV_BasicType_FLOAT32:{result = str8_lit("FLOAT32");}break;
case CV_BasicType_FLOAT64:{result = str8_lit("F64");}break; case CV_BasicType_FLOAT64:{result = str8_lit("FLOAT64");}break;
case CV_BasicType_FLOAT80:{result = str8_lit("F80");}break; case CV_BasicType_FLOAT80:{result = str8_lit("FLOAT80");}break;
case CV_BasicType_FLOAT128:{result = str8_lit("F128");}break; case CV_BasicType_FLOAT128:{result = str8_lit("FLOAT128");}break;
case CV_BasicType_FLOAT48:{result = str8_lit("F48");}break; case CV_BasicType_FLOAT48:{result = str8_lit("FLOAT48");}break;
case CV_BasicType_FLOAT32PP:{result = str8_lit("F32PP");}break; case CV_BasicType_FLOAT32PP:{result = str8_lit("FLOAT32PP");}break;
case CV_BasicType_FLOAT16:{result = str8_lit("F16");}break; case CV_BasicType_FLOAT16:{result = str8_lit("FLOAT16");}break;
case CV_BasicType_COMPLEX32:{result = str8_lit("ComplexF32");}break; case CV_BasicType_COMPLEX32:{result = str8_lit("ComplexF32");}break;
case CV_BasicType_COMPLEX64:{result = str8_lit("ComplexF64");}break; case CV_BasicType_COMPLEX64:{result = str8_lit("ComplexF64");}break;
case CV_BasicType_COMPLEX80:{result = str8_lit("ComplexF80");}break; case CV_BasicType_COMPLEX80:{result = str8_lit("ComplexF80");}break;
case CV_BasicType_COMPLEX128:{result = str8_lit("ComplexF128");}break; case CV_BasicType_COMPLEX128:{result = str8_lit("ComplexF128");}break;
case CV_BasicType_BIT:{result = str8_lit("");}break; case CV_BasicType_BIT:{result = str8_lit("");}break;
case CV_BasicType_PASCHAR:{result = str8_lit("");}break; case CV_BasicType_PASCHAR:{result = str8_lit("");}break;
case CV_BasicType_BOOL32FF:{result = str8_lit("B32FF");}break; case CV_BasicType_BOOL32FF:{result = str8_lit("BOOL32FF");}break;
case CV_BasicType_INT8:{result = str8_lit("S8");}break; case CV_BasicType_INT8:{result = str8_lit("int8");}break;
case CV_BasicType_UINT8:{result = str8_lit("U8");}break; case CV_BasicType_UINT8:{result = str8_lit("uint8");}break;
case CV_BasicType_RCHAR:{result = str8_lit("char");}break; case CV_BasicType_RCHAR:{result = str8_lit("char");}break;
case CV_BasicType_WCHAR:{result = str8_lit("WCHAR");}break; case CV_BasicType_WCHAR:{result = str8_lit("WCHAR");}break;
case CV_BasicType_INT16:{result = str8_lit("S16");}break; case CV_BasicType_INT16:{result = str8_lit("int16");}break;
case CV_BasicType_UINT16:{result = str8_lit("U16");}break; case CV_BasicType_UINT16:{result = str8_lit("uint16");}break;
case CV_BasicType_INT32:{result = str8_lit("S32");}break; case CV_BasicType_INT32:{result = str8_lit("int32");}break;
case CV_BasicType_UINT32:{result = str8_lit("U32");}break; case CV_BasicType_UINT32:{result = str8_lit("uint32");}break;
case CV_BasicType_INT64:{result = str8_lit("S64");}break; case CV_BasicType_INT64:{result = str8_lit("int64");}break;
case CV_BasicType_UINT64:{result = str8_lit("U64");}break; case CV_BasicType_UINT64:{result = str8_lit("uint64");}break;
case CV_BasicType_INT128:{result = str8_lit("S128");}break; case CV_BasicType_INT128:{result = str8_lit("int128");}break;
case CV_BasicType_UINT128:{result = str8_lit("U128");}break; case CV_BasicType_UINT128:{result = str8_lit("uint128");}break;
case CV_BasicType_CHAR16:{result = str8_lit("CHAR16");}break; case CV_BasicType_CHAR16:{result = str8_lit("char16");}break;
case CV_BasicType_CHAR32:{result = str8_lit("CHAR32");}break; case CV_BasicType_CHAR32:{result = str8_lit("char32");}break;
case CV_BasicType_CHAR8:{result = str8_lit("char");}break; case CV_BasicType_CHAR8:{result = str8_lit("char");}break;
case CV_BasicType_PTR:{result = str8_lit("PTR");}break; case CV_BasicType_PTR:{result = str8_lit("PTR");}break;
} }
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE //- GENERATED CODE
+713 -1154
View File
File diff suppressed because it is too large. Load diff
+500 -747
View File
File diff suppressed because it is too large. Load diff
+819
View File
@@ -0,0 +1,819 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#if 0
internal void
coff_print_archive_member_header(Arena *arena, String8List *out, String8 indent, COFF_ParsedArchiveMemberHeader header, String8 long_names)
{
Temp scratch = scratch_begin(&arena, 1);
String8 time_stamp = coff_string_from_time_stamp(scratch.arena, header.time_stamp);
rd_printf("Name : %S" , header.name );
rd_printf("Time Stamp: (%#x) %S" , header.time_stamp, time_stamp );
rd_printf("User ID : %u" , header.user_id );
rd_printf("Group ID : %u" , header.group_id);
rd_printf("Mode : %S" , header.mode );
rd_printf("Data : [%#llx-%#llx)", header.data_range.min, header.data_range.max);
scratch_end(scratch);
}
internal void
coff_print_section_table(Arena *arena,
String8List *out,
String8 indent,
String8 string_table,
COFF_Symbol32Array symbol_table,
U64 section_count,
COFF_SectionHeader *section_table)
{
Temp scratch = scratch_begin(&arena, 1);
String8 *symlinks = push_array(scratch.arena, String8, section_count);
for (U64 i = 0; i < symbol_table.count; ++i) {
COFF_Symbol32 *symbol = symbol_table.v+i;
COFF_SymbolValueInterpType interp = coff_interp_symbol(symbol->section_number, symbol->value, symbol->storage_class);
if (interp == COFF_SymbolValueInterp_Regular &&
symbol->aux_symbol_count == 0 &&
(symbol->storage_class == COFF_SymStorageClass_External || symbol->storage_class == COFF_SymStorageClass_Static)) {
if (symbol->section_number > 0 && symbol->section_number <= symbol_table.count) {
COFF_SectionHeader *header = section_table+(symbol->section_number-1);
if (header->flags & COFF_SectionFlag_LnkCOMDAT) {
symlinks[symbol->section_number-1] = coff_read_symbol_name(string_table, &symbol->name);
}
}
}
i += symbol->aux_symbol_count;
}
if (section_count) {
rd_printf("# Section Table");
rd_indent();
rd_printf("%-4s %-8s %-8s %-8s %-8s %-8s %-8s %-8s %-8s %-8s %-5s %-10s %s",
"No.",
"Name",
"VirtSize",
"VirtOff",
"FileSize",
"FileOff",
"RelocOff",
"LinesOff",
"RelocCnt",
"LineCnt",
"Align",
"Flags",
"Symlink");
for (U64 i = 0; i < section_count; ++i) {
COFF_SectionHeader *header = section_table+i;
String8 name = str8_cstring_capped(header->name, header->name+sizeof(header->name));
String8 full_name = coff_name_from_section_header(string_table, header);
String8 align;
{
U64 align_size = coff_align_size_from_section_flags(header->flags);
align = push_str8f(scratch.arena, "%u", align_size);
}
String8 flags;
{
String8List mem_flags = {0};
if (header->flags & COFF_SectionFlag_MemRead) {
str8_list_pushf(scratch.arena, &mem_flags, "r");
}
if (header->flags & COFF_SectionFlag_MemWrite) {
str8_list_pushf(scratch.arena, &mem_flags, "w");
}
if (header->flags & COFF_SectionFlag_MemExecute) {
str8_list_pushf(scratch.arena, &mem_flags, "x");
}
String8List cnt_flags = {0};
if (header->flags & COFF_SectionFlag_CntCode) {
str8_list_pushf(scratch.arena, &cnt_flags, "c");
}
if (header->flags & COFF_SectionFlag_CntInitializedData) {
str8_list_pushf(scratch.arena, &cnt_flags, "d");
}
if (header->flags & COFF_SectionFlag_CntUninitializedData) {
str8_list_pushf(scratch.arena, &cnt_flags, "u");
}
String8List mem_extra_flags = {0};
if (header->flags & COFF_SectionFlag_MemShared) {
str8_list_pushf(scratch.arena, &mem_flags, "s");
}
if (header->flags & COFF_SectionFlag_Mem16Bit) {
str8_list_pushf(scratch.arena, &mem_extra_flags, "h");
}
if (header->flags & COFF_SectionFlag_MemLocked) {
str8_list_pushf(scratch.arena, &mem_extra_flags, "l");
}
if (header->flags & COFF_SectionFlag_MemDiscardable) {
str8_list_pushf(scratch.arena, &mem_extra_flags, "d");
}
if (header->flags & COFF_SectionFlag_MemNotCached) {
str8_list_pushf(scratch.arena, &mem_extra_flags, "c");
}
if (header->flags & COFF_SectionFlag_MemNotPaged) {
str8_list_pushf(scratch.arena, &mem_extra_flags, "p");
}
String8List lnk_flags = {0};
if (header->flags & COFF_SectionFlag_LnkRemove) {
str8_list_pushf(scratch.arena, &lnk_flags, "r");
}
if (header->flags & COFF_SectionFlag_LnkCOMDAT) {
str8_list_pushf(scratch.arena, &lnk_flags, "c");
}
if (header->flags & COFF_SectionFlag_LnkOther) {
str8_list_pushf(scratch.arena, &lnk_flags, "o");
}
if (header->flags & COFF_SectionFlag_LnkInfo) {
str8_list_pushf(scratch.arena, &lnk_flags, "i");
}
if (header->flags & COFF_SectionFlag_LnkNRelocOvfl) {
str8_list_pushf(scratch.arena, &lnk_flags, "f");
}
String8List other_flags = {0};
if (header->flags & COFF_SectionFlag_TypeNoPad) {
str8_list_pushf(scratch.arena, &other_flags, "n");
}
if (header->flags & COFF_SectionFlag_GpRel) {
str8_list_pushf(scratch.arena, &other_flags, "g");
}
String8 mem = str8_list_join(scratch.arena, &mem_flags, 0);
String8 cnt = str8_list_join(scratch.arena, &cnt_flags, 0);
String8 lnk = str8_list_join(scratch.arena, &lnk_flags, 0);
String8 ext = str8_list_join(scratch.arena, &mem_extra_flags, 0);
String8 oth = str8_list_join(scratch.arena, &other_flags, 0);
String8List f = {0};
str8_list_push(scratch.arena, &f, mem);
str8_list_push(scratch.arena, &f, cnt);
str8_list_push(scratch.arena, &f, ext);
str8_list_push(scratch.arena, &f, lnk);
str8_list_push(scratch.arena, &f, oth);
flags = str8_list_join(scratch.arena, &f, &(StringJoin){ .sep = str8_lit("-") });
if (!flags.size) {
flags = str8_lit("none");
}
}
String8List l = {0};
str8_list_pushf(scratch.arena, &l, "%-4x", i+1 );
str8_list_pushf(scratch.arena, &l, "%-8S", name );
str8_list_pushf(scratch.arena, &l, "%08x", header->vsize );
str8_list_pushf(scratch.arena, &l, "%08x", header->voff );
str8_list_pushf(scratch.arena, &l, "%08x", header->fsize );
str8_list_pushf(scratch.arena, &l, "%08x", header->foff );
str8_list_pushf(scratch.arena, &l, "%08x", header->relocs_foff);
str8_list_pushf(scratch.arena, &l, "%08x", header->lines_foff );
str8_list_pushf(scratch.arena, &l, "%08x", header->reloc_count);
str8_list_pushf(scratch.arena, &l, "%08x", header->line_count );
str8_list_pushf(scratch.arena, &l, "%-5S", align );
str8_list_pushf(scratch.arena, &l, "%-10S", flags );
if (symlinks[i].size > 0) {
str8_list_pushf(scratch.arena, &l, "%S", symlinks[i]);
} else {
str8_list_pushf(scratch.arena, &l, "[no symlink]");
}
String8 line = str8_list_join(scratch.arena, &l, &(StringJoin){ .sep = str8_lit(" "), });
rd_printf("%S", line);
if (full_name.size != name.size) {
rd_indent();
rd_printf("Full Name: %S", full_name);
rd_unindent();
}
}
rd_newline();
rd_printf("Flags:");
rd_indent();
rd_printf("r = MemRead w = MemWrite x = MemExecute");
rd_printf("c = CntCode d = InitializedData u = UninitializedData");
rd_printf("s = MemShared h = Mem16bit l = MemLocked d = MemDiscardable c = MemNotCached p = MemNotPaged");
rd_printf("r = LnkRemove c = LnkComdat o = LnkOther i = LnkInfo f = LnkNRelocOvfl");
rd_printf("g = GpRel n = TypeNoPad");
rd_unindent();
rd_unindent();
rd_newline();
}
scratch_end(scratch);
}
internal void
coff_disasm_sections(Arena *arena,
String8List *out,
String8 indent,
String8 raw_data,
COFF_MachineType machine,
U64 image_base,
B32 is_obj,
RD_MarkerArray *section_markers,
U64 section_count,
COFF_SectionHeader *sections)
{
if (section_count) {
for (U64 sect_idx = 0; sect_idx < section_count; ++sect_idx) {
COFF_SectionHeader *sect = sections+sect_idx;
if (sect->flags & COFF_SectionFlag_CntCode) {
U64 sect_off = is_obj ? sect->foff : sect->voff;
U64 sect_size = is_obj ? sect->fsize : sect->vsize;
String8 raw_code = str8_substr(raw_data, rng_1u64(sect->foff, sect->foff+sect_size));
U64 sect_number = sect_idx+1;
RD_MarkerArray markers = section_markers[sect_number];
rd_printf("# Disassembly [Section No. %#llx]", sect_number);
rd_indent();
rd_print_disasm(arena, out, indent, arch_from_coff_machine(machine), image_base, sect_off, markers.count, markers.v, raw_code);
rd_unindent();
}
}
}
}
internal void
coff_raw_data_sections(Arena *arena,
String8List *out,
String8 indent,
String8 raw_data,
B32 is_obj,
RD_MarkerArray *section_markers,
U64 section_count,
COFF_SectionHeader *section_table)
{
if (section_count) {
for (U64 sect_idx = 0; sect_idx < section_count; ++sect_idx) {
COFF_SectionHeader *sect = section_table+sect_idx;
if (sect->fsize > 0) {
U64 sect_size = is_obj ? sect->fsize : sect->vsize;
String8 raw_sect = str8_substr(raw_data, rng_1u64(sect->foff, sect->foff+sect_size));
RD_MarkerArray markers = section_markers[sect_idx];
rd_printf("# Raw Data [Section No. %#llx]", (sect_idx+1));
rd_indent();
rd_print_raw_data(arena, out, indent, 32, markers.count, markers.v, raw_sect);
rd_unindent();
rd_newline();
}
}
}
}
internal void
coff_print_relocs(Arena *arena,
String8List *out,
String8 indent,
String8 raw_data,
String8 string_table,
COFF_MachineType machine,
U64 sect_count,
COFF_SectionHeader *sect_headers,
COFF_Symbol32Array symbols)
{
Temp scratch = scratch_begin(&arena, 1);
B32 print_header = 1;
for (U64 sect_idx = 0; sect_idx < sect_count; ++sect_idx) {
COFF_SectionHeader *sect_header = sect_headers+sect_idx;
COFF_RelocInfo reloc_info = coff_reloc_info_from_section_header(raw_data, sect_header);
if (reloc_info.count) {
if (print_header) {
print_header = 0;
rd_printf("# Relocations");
rd_indent();
}
rd_printf("## Section %llx", sect_idx);
rd_indent();
rd_printf("%-4s %-8s %-16s %-16s %-8s %-7s", "No.", "Offset", "Type", "ApplyTo", "SymIdx", "SymName");
for (U64 reloc_idx = 0; reloc_idx < reloc_info.count; ++reloc_idx) {
COFF_Reloc *reloc = (COFF_Reloc*)(raw_data.str + reloc_info.array_off) + reloc_idx;
String8 type = coff_string_from_reloc(machine, reloc->type);
U64 apply_size = coff_apply_size_from_reloc(machine, reloc->type);
U64 apply_foff = sect_header->foff + reloc->apply_off;
if (apply_foff + apply_size > raw_data.size) {
rd_errorf("out of bounds apply file offset %#llx in relocation %#llx", apply_foff, reloc_idx);
break;
}
U64 raw_apply;
AssertAlways(apply_size <= sizeof(raw_apply));
MemoryCopy(&raw_apply, raw_data.str + apply_foff, apply_size);
S64 apply = extend_sign64(raw_apply, apply_size);
if (reloc->isymbol > symbols.count) {
rd_errorf("out of bounds symbol index %u in relocation %#llx", reloc->isymbol, reloc_idx);
break;
}
COFF_Symbol32 *symbol = symbols.v+reloc->isymbol;
String8 symbol_name = coff_read_symbol_name(string_table, &symbol->name);
String8List line = {0};
str8_list_pushf(scratch.arena, &line, "%-4x", reloc_idx );
str8_list_pushf(scratch.arena, &line, "%08x", reloc->apply_off);
str8_list_pushf(scratch.arena, &line, "%-16S", type );
str8_list_pushf(scratch.arena, &line, "%016x", apply );
str8_list_pushf(scratch.arena, &line, "%S", symbol_name );
String8 l = str8_list_join(scratch.arena, &line, &(StringJoin){.sep=str8_lit(" ")});
rd_printf("%S", l);
}
rd_unindent();
}
}
if (!print_header) {
rd_unindent();
}
rd_newline();
scratch_end(scratch);
}
internal void
coff_print_symbol_table(Arena *arena,
String8List *out,
String8 indent,
String8 raw_data,
B32 is_big_obj,
String8 string_table,
COFF_Symbol32Array symbols)
{
Temp scratch = scratch_begin(&arena, 1);
if (symbols.count) {
rd_printf("# Symbol Table");
rd_indent();
rd_printf("%-4s %-8s %-10s %-4s %-4s %-4s %-16s %-20s",
"No.", "Value", "SectNum", "Aux", "Msb", "Lsb", "Storage", "Name");
for (U64 i = 0; i < symbols.count; ++i) {
COFF_Symbol32 *symbol = &symbols.v[i];
String8 name = coff_read_symbol_name(string_table, &symbol->name);
String8 msb = coff_string_from_sym_dtype(symbol->type.u.msb);
String8 lsb = coff_string_from_sym_type(symbol->type.u.lsb);
String8 storage_class = coff_string_from_sym_storage_class(symbol->storage_class);
String8 section_number;
switch (symbol->section_number) {
case COFF_Symbol_UndefinedSection: section_number = str8_lit("Undef"); break;
case COFF_Symbol_AbsSection32: section_number = str8_lit("Abs"); break;
case COFF_Symbol_DebugSection32: section_number = str8_lit("Debug"); break;
default: section_number = push_str8f(scratch.arena, "%010x", symbol->section_number); break;
}
String8List line = {0};
str8_list_pushf(scratch.arena, &line, "%-4x", i );
str8_list_pushf(scratch.arena, &line, "%08x", symbol->value );
str8_list_pushf(scratch.arena, &line, "%-10S", section_number );
str8_list_pushf(scratch.arena, &line, "%-4u", symbol->aux_symbol_count);
str8_list_pushf(scratch.arena, &line, "%-4S", msb );
str8_list_pushf(scratch.arena, &line, "%-4S", lsb );
str8_list_pushf(scratch.arena, &line, "%-16S", storage_class );
str8_list_pushf(scratch.arena, &line, "%S", name );
String8 l = str8_list_join(scratch.arena, &line, &(StringJoin){.sep = str8_lit(" ")});
rd_printf("%S", l);
rd_indent();
for (U64 k=i+1, c = i+symbol->aux_symbol_count; k <= c; ++k) {
void *raw_aux = &symbols.v[k];
switch (symbol->storage_class) {
case COFF_SymStorageClass_External: {
COFF_SymbolFuncDef *func_def = (COFF_SymbolFuncDef*)&symbols.v[k];
rd_printf("Tag Index %#x, Total Size %#x, Line Numbers %#x, Next Function %#x",
func_def->tag_index, func_def->total_size, func_def->ptr_to_ln, func_def->ptr_to_next_func);
} break;
case COFF_SymStorageClass_Function: {
COFF_SymbolFunc *func = raw_aux;
rd_printf("Ordinal Line Number %#x, Next Function %#x", func->ln, func->ptr_to_next_func);
} break;
case COFF_SymStorageClass_WeakExternal: {
COFF_SymbolWeakExt *weak = raw_aux;
String8 type = coff_string_from_weak_ext_type(weak->characteristics);
rd_printf("Tag Index %#x, Characteristics %S", weak->tag_index, type);
} break;
case COFF_SymStorageClass_File: {
COFF_SymbolFile *file = raw_aux;
String8 name = str8_cstring_capped(file->name, file->name+sizeof(file->name));
rd_printf("Name %S", name);
} break;
case COFF_SymStorageClass_Static: {
COFF_SymbolSecDef *sd = raw_aux;
String8 selection = coff_string_from_comdat_select_type(sd->selection);
U32 number = sd->number_lo;
if (is_big_obj) {
number |= (U32)sd->number_hi << 16;
}
if (number) {
rd_printf("Length %x, Reloc Count %u, Line Count %u, Checksum %x, Section %x, Selection %S",
sd->length, sd->number_of_relocations, sd->number_of_ln, sd->check_sum, number, selection);
} else {
rd_printf("Length %x, Reloc Count %u, Line Count %u, Checksum %x",
sd->length, sd->number_of_relocations, sd->number_of_ln, sd->check_sum);
}
} break;
default: {
rd_printf("???");
} break;
}
}
i += symbol->aux_symbol_count;
rd_unindent();
}
rd_unindent();
rd_newline();
}
scratch_end(scratch);
}
internal void
coff_print_big_obj_header(Arena *arena, String8List *out, String8 indent, COFF_BigObjHeader *header)
{
Temp scratch = scratch_begin(&arena, 1);
String8 time_stamp = coff_string_from_time_stamp(scratch.arena, header->time_stamp);
String8 machine = coff_string_from_machine_type(header->machine);
rd_printf("# Big Obj");
rd_indent();
rd_printf("Time Stamp : %#x (%S)", header->time_stamp, time_stamp);
rd_printf("Machine : %#x (%S)", header->machine, machine );
rd_printf("Section Count: %u", header->section_count );
rd_printf("Symbol Table : %#x", header->symbol_table_foff);
rd_printf("Symbol Count : %u", header->symbol_count );
rd_unindent();
scratch_end(scratch);
}
internal void
coff_print_file_header(Arena *arena, String8List *out, String8 indent, COFF_FileHeader *header)
{
Temp scratch = scratch_begin(&arena, 1);
String8 time_stamp = coff_string_from_time_stamp(scratch.arena, header->time_stamp);
String8 machine = coff_string_from_machine_type(header->machine);
String8 flags = coff_string_from_flags(scratch.arena, header->flags);
rd_printf("# COFF File Header");
rd_indent();
rd_printf("Time Stamp : %#x (%S)", header->time_stamp, time_stamp );
rd_printf("Machine : %#x %S", header->machine, machine );
rd_printf("Section Count : %u", header->section_count );
rd_printf("Symbol Table : %#x", header->symbol_table_foff );
rd_printf("Symbol Count : %u", header->symbol_count );
rd_printf("Optional Header Size: %#x (%m)", header->optional_header_size, header->optional_header_size);
rd_printf("Flags : %#x (%S)", header->flags, flags );
rd_unindent();
scratch_end(scratch);
}
internal void
coff_print_import(Arena *arena, String8List *out, String8 indent, COFF_ParsedArchiveImportHeader *header)
{
Temp scratch = scratch_begin(&arena, 1);
String8 machine = coff_string_from_machine_type(header->machine);
String8 time_stamp = coff_string_from_time_stamp(scratch.arena, header->time_stamp);
rd_printf("# Import");
rd_indent();
rd_printf("Version : %u", header->version );
rd_printf("Machine : %S", machine );
rd_printf("Time Stamp: %#x (%S)", header->time_stamp, time_stamp );
rd_printf("Data Size : %#x (%m)", header->data_size, header->data_size);
rd_printf("Hint : %u", header->hint_or_ordinal);
rd_printf("Type : %u", header->type );
rd_printf("Import By : %u", header->import_by );
rd_printf("Function : %S", header->func_name );
rd_printf("DLL : %S", header->dll_name );
rd_unindent();
scratch_end(scratch);
}
internal void
coff_print_big_obj(Arena *arena, String8List *out, String8 indent, String8 raw_data, RD_Option opts)
{
Temp scratch = scratch_begin(&arena, 1);
COFF_FileHeaderInfo header_info = coff_file_header_info_from_data(raw_data);
String8 raw_header = str8_substr(raw_data, header_info.header_range);
String8 raw_section_table = str8_substr(raw_data, header_info.section_table_range);
String8 raw_string_table = str8_substr(raw_data, header_info.string_table_range);
COFF_BigObjHeader *big_obj = (COFF_BigObjHeader *)raw_header.str;
COFF_SectionHeader *section_table = (COFF_SectionHeader *)raw_section_table.str;
COFF_Symbol32Array symbol_table = coff_symbol_array_from_data_32(scratch.arena, raw_data, header_info.symbol_table_range.min, big_obj->symbol_count);
if (opts & RD_Option_Headers) {
coff_print_big_obj_header(arena, out, indent, big_obj);
rd_newline();
}
if (opts & RD_Option_Sections) {
Rng1U64 sect_headers_range = rng_1u64(sizeof(*big_obj), sizeof(*big_obj) + sizeof(COFF_SectionHeader)*big_obj->section_count);
Rng1U64 symbols_range = rng_1u64(big_obj->symbol_table_foff, big_obj->symbol_table_foff + sizeof(COFF_Symbol32)*big_obj->symbol_count);
if (sect_headers_range.max > raw_data.size) {
rd_errorf("not enough bytes to read big obj section headers");
goto exit;
}
if (big_obj->symbol_count) {
if (symbols_range.max > raw_data.size) {
rd_errorf("not enough bytes to read big obj symbol table");
goto exit;
}
if (contains_1u64(symbols_range, sect_headers_range.min) ||
contains_1u64(symbols_range, sect_headers_range.max)) {
rd_errorf("section headers and symbol table ranges overlap");
goto exit;
}
}
coff_print_section_table(arena, out, indent, raw_string_table, symbol_table, big_obj->section_count, section_table);
rd_newline();
}
if (opts & RD_Option_Relocs) {
coff_print_relocs(arena, out, indent, raw_data, raw_string_table, big_obj->machine, big_obj->section_count, section_table, symbol_table);
rd_newline();
}
if (opts & RD_Option_Symbols) {
coff_print_symbol_table(arena, out, indent, raw_data, 1, raw_string_table, symbol_table);
rd_newline();
}
exit:;
scratch_end(scratch);
}
internal void
coff_print_obj(Arena *arena, String8List *out, String8 indent, String8 raw_data, RD_Option opts)
{
Temp scratch = scratch_begin(&arena, 1);
COFF_FileHeaderInfo header_info = coff_file_header_info_from_data(raw_data);
String8 raw_header = str8_substr(raw_data, header_info.header_range);
String8 raw_section_table = str8_substr(raw_data, header_info.section_table_range);
String8 raw_string_table = str8_substr(raw_data, header_info.string_table_range);
COFF_FileHeader *header = (COFF_FileHeader *)raw_header.str;
COFF_SectionHeader *section_table = (COFF_SectionHeader *)raw_section_table.str;
COFF_Symbol32Array symbol_table = coff_symbol_array_from_data_16(scratch.arena, raw_data, header_info.symbol_table_range.min, header->symbol_count);
Arch arch = arch_from_coff_machine(header->machine);
if (opts & RD_Option_Headers) {
coff_print_file_header(arena, out, indent, header);
rd_newline();
}
if (opts & RD_Option_Sections) {
Rng1U64 sect_headers_range = rng_1u64(sizeof(*header), sizeof(*header) + sizeof(COFF_SectionHeader)*header->section_count);
Rng1U64 symbols_range = rng_1u64(header->symbol_table_foff, header->symbol_table_foff + sizeof(COFF_Symbol16)*header->symbol_count);
if (sect_headers_range.max > raw_data.size) {
rd_errorf("not enough bytes to read obj section headers");
goto exit;
}
if (header->symbol_count) {
if (symbols_range.max > raw_data.size) {
rd_errorf("not enough bytes to read obj symbol table");
goto exit;
}
if (contains_1u64(symbols_range, sect_headers_range.min) ||
contains_1u64(symbols_range, sect_headers_range.max)) {
rd_errorf("section headers and symbol table ranges overlap");
goto exit;
}
}
coff_print_section_table(arena, out, indent, raw_string_table, symbol_table, header->section_count, section_table);
rd_newline();
}
if (opts & RD_Option_Relocs) {
coff_print_relocs(arena, out, indent, raw_data, raw_string_table, header->machine, header->section_count, section_table, symbol_table);
rd_newline();
}
if (opts & RD_Option_Symbols) {
coff_print_symbol_table(arena, out, indent, raw_data, 0, raw_string_table, symbol_table);
rd_newline();
}
RD_MarkerArray *section_markers = 0;
if (opts & (RD_Option_Disasm|RD_Option_Rawdata)) {
section_markers = rd_section_markers_from_coff_symbol_table(scratch.arena, raw_string_table, header->section_count, symbol_table);
}
if (opts & RD_Option_Rawdata) {
coff_raw_data_sections(arena, out, indent, raw_data, 1, section_markers, header->section_count, section_table);
}
if (opts & RD_Option_Disasm) {
coff_disasm_sections(arena, out, indent, raw_data, header->machine, 0, 1, section_markers, header->section_count, section_table);
rd_newline();
}
if (opts & RD_Option_Codeview) {
cv_format_debug_sections(arena, out, indent, raw_data, raw_string_table, header->section_count, section_table);
}
if (opts & RD_Option_Dwarf) {
DW_Input dwarf_input = dw_input_from_coff_section_table(scratch.arena, raw_data, raw_string_table, header->section_count, section_table);
dw_format(arena, out, indent, opts, &dwarf_input, arch, ExecutableImageKind_CoffPe);
}
exit:;
scratch_end(scratch);
}
internal void
coff_print_archive(Arena *arena, String8List *out, String8 indent, String8 raw_archive, RD_Option opts)
{
Temp scratch = scratch_begin(&arena, 1);
COFF_ArchiveParse archive_parse = coff_archive_parse_from_data(raw_archive);
if (archive_parse.error.size) {
rd_errorf("%S", archive_parse.error);
return;
}
COFF_ArchiveFirstMember first_member = archive_parse.first_member;
{
rd_printf("# First Header");
rd_indent();
rd_printf("Symbol Count : %u", first_member.symbol_count);
rd_printf("String Table Size: %#llx (%M)", first_member.string_table.size, first_member.string_table.size);
rd_printf("Members:");
rd_indent();
String8List string_table = str8_split_by_string_chars(scratch.arena, first_member.string_table, str8_lit("\0"), 0);
if (string_table.node_count == first_member.member_offset_count) {
String8Node *string_n = string_table.first;
for (U64 i = 0; i < string_table.node_count; ++i, string_n = string_n->next) {
U32 offset = from_be_u32(first_member.member_offsets[i]);
rd_printf("[%4u] %#08x %S", i, offset, string_n->string);
}
} else {
rd_errorf("Member offset count (%llu) doesn't match string table count (%llu)", first_member.member_offset_count);
}
rd_unindent();
rd_unindent();
rd_newline();
}
if (archive_parse.has_second_header) {
COFF_ArchiveSecondMember second_member = archive_parse.second_member;
rd_printf("# Second Header");
rd_indent();
rd_printf("Member Count : %u", second_member.member_count);
rd_printf("Symbol Count : %u", second_member.symbol_count);
rd_printf("String Table Size: %#llx (%M)", second_member.string_table.size, second_member.string_table.size);
String8List string_table = str8_split_by_string_chars(scratch.arena, second_member.string_table, str8_lit("\0"), 0);
rd_printf("Members:");
rd_indent();
if (second_member.symbol_index_count == second_member.symbol_count) {
String8Node *string_n = string_table.first;
for (U64 i = 0; i < second_member.symbol_count; ++i, string_n = string_n->next) {
U16 symbol_number = second_member.symbol_indices[i];
if (symbol_number > 0 && symbol_number <= second_member.member_offset_count) {
U16 symbol_idx = symbol_number - 1;
U32 member_offset = second_member.member_offsets[i];
rd_printf("[%4u] %#08x %S", i, member_offset, string_n->string);
} else {
rd_errorf("[%4u] Out of bounds symbol number %u", i, symbol_number);
break;
}
}
} else {
rd_errorf("Symbol index count %u doesn't match symbol count %u",
second_member.symbol_index_count, second_member.symbol_count);
}
rd_unindent();
rd_unindent();
rd_newline();
}
if (archive_parse.has_long_names && opts & RD_Option_LongNames) {
rd_printf("# Long Names");
rd_indent();
String8List long_names = str8_split_by_string_chars(scratch.arena, archive_parse.long_names, str8_lit("\0"), 0);
U64 name_idx = 0;
for (String8Node *name_n = long_names.first; name_n != 0; name_n = name_n->next, ++name_idx) {
U64 offset = (U64)(name_n->string.str - archive_parse.long_names.str);
rd_printf("[%-4u] %#08x %S", name_idx, offset, name_n->string);
}
rd_unindent();
rd_newline();
}
U64 member_offset_count = 0;
U32 *member_offsets = 0;
if (archive_parse.has_second_header) {
member_offset_count = archive_parse.second_member.member_offset_count;
member_offsets = archive_parse.second_member.member_offsets;
} else {
HashTable *ht = hash_table_init(scratch.arena, 0x1000);
for (U64 i = 0; i < archive_parse.first_member.member_offset_count; ++i) {
U32 member_offset = from_be_u32(archive_parse.first_member.member_offsets[i]);
if (!hash_table_search_u32(ht, member_offset)) {
hash_table_push_u32_raw(scratch.arena, ht, member_offset, 0);
}
}
member_offset_count = ht->count;
member_offsets = keys_from_hash_table_u32(scratch.arena, ht);
radsort(member_offsets, member_offset_count, u32_is_before);
}
rd_printf("# Members");
rd_indent();
for (U64 i = 0; i < member_offset_count; ++i) {
U64 next_member_offset = i+1 < member_offset_count ? member_offsets[i+1] : raw_archive.size;
U64 member_offset = member_offsets[i];
String8 raw_member = str8_substr(raw_archive, rng_1u64(member_offset, next_member_offset));
COFF_ArchiveMember member = coff_archive_member_from_data(raw_member);
COFF_DataType member_type = coff_data_type_from_data(member.data);
rd_printf("Member @ %#llx", member_offset);
rd_indent();
if (opts & RD_Option_Headers) {
coff_print_archive_member_header(arena, out, indent, member.header, archive_parse.long_names);
rd_newline();
}
switch (member_type) {
case COFF_DataType_Obj: {
coff_print_obj(arena, out, indent, member.data, opts);
} break;
case COFF_DataType_BigObj: {
coff_print_big_obj(arena, out, indent, member.data, opts);
} break;
case COFF_DataType_Import: {
if (opts & RD_Option_Headers) {
COFF_ParsedArchiveImportHeader header = {0};
U64 parse_size = coff_parse_import(member.data, 0, &header);
if (parse_size) {
coff_print_import(arena, out, indent, &header);
} else {
rd_errorf("not enough bytes to parse import header");
}
}
} break;
case COFF_DataType_Null: {
rd_errorf("unknown member format", member_offset);
} break;
}
rd_unindent();
rd_newline();
}
rd_unindent();
scratch_end(scratch);
}
#endif
+22
View File
@@ -0,0 +1,22 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef COFF_DUMP_H
#define COFF_DUMP_H
#if 0
internal void coff_print_archive_member_header(Arena *arena, String8List *out, String8 indent, COFF_ParsedArchiveMemberHeader header, String8 long_names);
internal void coff_print_section_table (Arena *arena, String8List *out, String8 indent, String8 string_table, COFF_Symbol32Array symbols, U64 sect_count, COFF_SectionHeader *sect_headers);
internal void coff_disasm_sections (Arena *arena, String8List *out, String8 indent, String8 raw_data, COFF_MachineType machine, U64 image_base, B32 is_obj, RD_MarkerArray *section_markers, U64 section_count, COFF_SectionHeader *sections);
internal void coff_raw_data_sections (Arena *arena, String8List *out, String8 indent, String8 raw_data, B32 is_obj, RD_MarkerArray *section_markers, U64 section_count, COFF_SectionHeader *sections);
internal void coff_print_relocs (Arena *arena, String8List *out, String8 indent, String8 raw_data, String8 string_table, COFF_MachineType machine, U64 sect_count, COFF_SectionHeader *sect_headers, COFF_Symbol32Array symbols);
internal void coff_print_symbol_table (Arena *arena, String8List *out, String8 indent, String8 raw_data, B32 is_big_obj, String8 string_table, COFF_Symbol32Array symbols);
internal void coff_print_big_obj_header (Arena *arena, String8List *out, String8 indent, COFF_BigObjHeader *header);
internal void coff_print_file_header (Arena *arena, String8List *out, String8 indent, COFF_FileHeader *header);
internal void coff_print_import (Arena *arena, String8List *out, String8 indent, COFF_ParsedArchiveImportHeader *header);
internal void coff_print_big_obj (Arena *arena, String8List *out, String8 indent, String8 raw_data, RD_Option opts);
internal void coff_print_obj (Arena *arena, String8List *out, String8 indent, String8 raw_data, RD_Option opts);
internal void coff_print_archive (Arena *arena, String8List *out, String8 indent, String8 raw_archive, RD_Option opts);
#endif
#endif // COFF_DUMP_H
+1
View File
@@ -0,0 +1 @@
+6
View File
@@ -0,0 +1,6 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#include "coff/coff.c"
#include "coff/coff_parse.c"
#include "coff/coff_dump.c"
+11
View File
@@ -0,0 +1,11 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef COFF_INC_H
#define COFF_INC_H
#include "coff/coff.h"
#include "coff/coff_parse.h"
#include "coff/coff_dump.h"
#endif // COFF_INC_H
+387
View File
@@ -0,0 +1,387 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal COFF_LibWriterSymbolNode *
coff_lib_writer_symbol_list_push(Arena *arena, COFF_LibWriterSymbolList *list, COFF_LibWriterSymbol symbol)
{
COFF_LibWriterSymbolNode *node = push_array_no_zero(arena, COFF_LibWriterSymbolNode, 1);
node->next = 0;
node->data = symbol;
SLLQueuePush(list->first, list->last, node);
list->count += 1;
return node;
}
internal COFF_LibWriterMemberNode *
coff_lib_writer_member_list_push(Arena *arena, COFF_LibWriterMemberList *list, COFF_LibWriterMember member)
{
COFF_LibWriterMemberNode *node = push_array_no_zero(arena, COFF_LibWriterMemberNode, 1);
node->next = 0;
node->data = member;
SLLQueuePush(list->first, list->last, node);
list->count += 1;
return node;
}
internal COFF_LibWriterSymbol *
coff_lib_writer_symbol_array_from_list(Arena *arena, COFF_LibWriterSymbolList list)
{
COFF_LibWriterSymbol *arr = push_array_no_zero(arena, COFF_LibWriterSymbol, list.count + 2);
COFF_LibWriterSymbol *ptr = arr + 1;
for (COFF_LibWriterSymbolNode *i = list.first; i != 0; i = i->next, ptr += 1) {
*ptr = i->data;
}
MemoryZeroStruct(&arr[0]);
MemoryZeroStruct(&arr[list.count+1]);
return arr;
}
internal COFF_LibWriterMember *
coff_lib_writer_member_array_from_list(Arena *arena, COFF_LibWriterMemberList list)
{
COFF_LibWriterMember *arr = push_array_no_zero(arena, COFF_LibWriterMember, list.count);
COFF_LibWriterMember *ptr = arr;
for (COFF_LibWriterMemberNode *i = list.first; i != 0; i = i->next, ptr += 1) {
ptr->name = push_str8_copy(arena, i->data.name);
ptr->data = push_str8_copy(arena, i->data.data);
}
return arr;
}
internal int
coff_lib_writer_symbol_name_compar(const void *raw_a, const void *raw_b)
{
const COFF_LibWriterSymbol *sa = raw_a;
const COFF_LibWriterSymbol *sb = raw_b;
return str8_compar_case_sensitive(&sa->name, &sb->name);
}
internal int
coff_lib_writer_symbol_is_before_name(void *raw_a, void *raw_b)
{
return coff_lib_writer_symbol_name_compar(raw_a, raw_b) < 0;
}
internal int
coff_lib_writer_symbol_is_before_member_idx(void *raw_a, void *raw_b)
{
COFF_LibWriterSymbol *a = raw_a, *b = raw_b;
return a->member_idx < b->member_idx;
}
internal void
coff_lib_writer_symbol_array_sort_on_name(COFF_LibWriterSymbol *arr, U64 count)
{
Assert(count >= 2);
radsort(arr + 1, count - 2, coff_lib_writer_symbol_is_before_name);
}
internal void
coff_lib_writer_symbol_array_sort_on_member_idx(COFF_LibWriterSymbol *arr, U64 count)
{
Assert(count >= 2);
radsort(arr + 1, count - 2, coff_lib_writer_symbol_is_before_member_idx);
}
internal COFF_LibWriter *
coff_lib_writer_alloc(void)
{
Arena *arena = arena_alloc();
COFF_LibWriter *writer = push_array(arena, COFF_LibWriter, 1);
writer->arena = arena;
return writer;
}
internal void
coff_lib_writer_release(COFF_LibWriter **writer_ptr)
{
arena_release((*writer_ptr)->arena);
*writer_ptr = 0;
}
internal U64
coff_lib_writer_push_obj(COFF_LibWriter *writer, String8 obj_path, String8 obj_data)
{
U64 member_idx = writer->member_list.count;
// push obj member
COFF_LibWriterMember member = { .name = obj_path, .data = obj_data };
COFF_LibWriterMemberNode *member_node = coff_lib_writer_member_list_push(writer->arena, &writer->member_list, member);
// push external symbols
COFF_FileHeaderInfo obj_header = coff_file_header_info_from_data(obj_data);
String8 string_table = str8_substr(obj_data, obj_header.string_table_range);
String8 symbol_table = str8_substr(obj_data, obj_header.symbol_table_range);
COFF_ParsedSymbol symbol;
for (U64 symbol_idx = 0; symbol_idx < obj_header.symbol_count; symbol_idx += (1 + symbol.aux_symbol_count)) {
symbol = coff_parse_symbol(obj_header, string_table, symbol_table, symbol_idx);
COFF_SymbolValueInterpType interp = coff_interp_from_parsed_symbol(symbol);
if (interp == COFF_SymbolValueInterp_Regular || interp == COFF_SymbolValueInterp_Common || interp == COFF_SymbolValueInterp_Abs) {
if (symbol.storage_class == COFF_SymStorageClass_External) {
COFF_LibWriterSymbol lib_symbol = { .name = symbol.name, .member_idx = member_idx };
coff_lib_writer_symbol_list_push(writer->arena, &writer->symbol_list, lib_symbol);
}
}
}
return member_idx;
}
internal void
coff_lib_writer_push_import(COFF_LibWriter *lib_writer, COFF_MachineType machine, COFF_TimeStamp time_stamp, String8 dll_name, COFF_ImportByType import_by, String8 name, U16 hint_or_ordinal, COFF_ImportType import_type)
{
U64 member_idx = lib_writer->member_list.count;
String8 member_data = coff_make_import_header(lib_writer->arena, machine, time_stamp, dll_name, import_by, name, hint_or_ordinal, import_type);
COFF_LibWriterMember member = { .name = dll_name, .data = member_data };
COFF_LibWriterMemberNode *member_node = coff_lib_writer_member_list_push(lib_writer->arena, &lib_writer->member_list, member);
if (name.size) {
switch (import_type) {
case COFF_ImportHeader_Code: {
COFF_LibWriterSymbol thunk_symbol = {0};
thunk_symbol.name = push_str8_copy(lib_writer->arena, name);
thunk_symbol.member_idx = member_idx;
coff_lib_writer_symbol_list_push(lib_writer->arena, &lib_writer->symbol_list, thunk_symbol);
COFF_LibWriterSymbol imp_symbol = {0};
imp_symbol.name = push_str8f(lib_writer->arena, "__imp_%S", name);
imp_symbol.member_idx = member_idx;
coff_lib_writer_symbol_list_push(lib_writer->arena, &lib_writer->symbol_list, imp_symbol);
} break;
case COFF_ImportHeader_Data: {
COFF_LibWriterSymbol imp_symbol = {0};
imp_symbol.name = push_str8f(lib_writer->arena, "__imp_%S", name);
imp_symbol.member_idx = member_idx;
coff_lib_writer_symbol_list_push(lib_writer->arena, &lib_writer->symbol_list, imp_symbol);
} break;
case COFF_ImportHeader_Const: { NotImplemented; } break;
default: { InvalidPath; } break;
}
}
}
internal String8
coff_lib_writer_serialize(Arena *arena, COFF_LibWriter *lib_writer, COFF_TimeStamp time_stamp, U16 mode, B32 emit_second_member)
{
Temp scratch = scratch_begin(&arena, 1);
// member lists -> arrays
U64 member_count = lib_writer->member_list.count;
COFF_LibWriterMember *member_array = coff_lib_writer_member_array_from_list(scratch.arena, lib_writer->member_list);
// serialize members
U64 *member_offsets = push_array_no_zero(scratch.arena, U64, member_count);
String8List long_names_list = {0};
String8List member_data_list = {0};
{
HashTable *name_ht = hash_table_init(scratch.arena, 1024);
for EachIndex(member_idx, member_count) {
COFF_LibWriterMember *member = &member_array[member_idx];
// make member name
String8 name;
U64 name_with_slash_size = member->name.size + 1;
if (name_with_slash_size > COFF_Archive_MaxShortNameSize) {
// have we seen this member name before?
KeyValuePair *is_present = hash_table_search_string(name_ht, member->name);
if (is_present) {
name = is_present->value_string;
} else {
name = push_str8f(scratch.arena, "/%u", long_names_list.total_size);
str8_list_pushf(scratch.arena, &long_names_list, "%S/\n", member->name);
hash_table_push_string_string(scratch.arena, name_ht, member->name, name);
}
} else {
name = push_str8f(scratch.arena, "%S/", member->name);
}
member_offsets[member_idx] = member_data_list.total_size;
String8 member_data = member->data;
String8 member_header = coff_make_lib_member_header(scratch.arena, name, time_stamp, 0, 0, mode, member_data.size);
str8_list_push(scratch.arena, &member_data_list, member_header);
str8_list_push(scratch.arena, &member_data_list, member_data);
{
U64 pad_size = AlignPadPow2(member_data_list.total_size, COFF_Archive_MemberAlign);
U8 *pad = push_array(scratch.arena, U8, pad_size);
str8_list_push(scratch.arena, &member_data_list, str8(pad, pad_size));
}
}
}
// write long names member
if (long_names_list.total_size) {
String8 header = coff_make_lib_member_header(scratch.arena, str8_lit("//"), time_stamp, 0, 0, mode, long_names_list.total_size);
String8 data = str8_list_join(scratch.arena, &long_names_list, 0);
U64 member_offset = member_data_list.total_size + data.size + header.size;
{
U64 pad_size = AlignPadPow2(member_offset, COFF_Archive_MemberAlign);
U8 *pad = push_array(scratch.arena, U8, pad_size);
str8_list_push_front(scratch.arena, &member_data_list, str8(pad, pad_size));
}
str8_list_push_front(scratch.arena, &member_data_list, data);
str8_list_push_front(scratch.arena, &member_data_list, header);
}
// compute size for symbol string table
U32 name_buffer_size = 0;
for (COFF_LibWriterSymbolNode *node = lib_writer->symbol_list.first; node != 0; node = node->next) {
name_buffer_size += node->data.name.size;
name_buffer_size += 1; // null
}
// compute members base offset
U64 members_base_offset;
{
U64 sizeof_first_header = sizeof(COFF_ArchiveMemberHeader) + sizeof(U32) + sizeof(U32) * lib_writer->symbol_list.count + name_buffer_size;
U64 sizeof_second_header = sizeof(COFF_ArchiveMemberHeader) + sizeof(U32) + sizeof(U32) * member_count + sizeof(U32) + sizeof(U16) * lib_writer->symbol_list.count + name_buffer_size;
U64 sizeof_long_names = sizeof(COFF_ArchiveMemberHeader) + long_names_list.total_size;
sizeof_first_header = AlignPow2(sizeof_first_header, COFF_Archive_MemberAlign);
sizeof_second_header = AlignPow2(sizeof_second_header, COFF_Archive_MemberAlign);
sizeof_long_names = AlignPow2(sizeof_long_names, COFF_Archive_MemberAlign);
members_base_offset = sizeof(g_coff_archive_sig);
members_base_offset += sizeof_first_header;
if (emit_second_member) {
members_base_offset += sizeof_second_header;
}
if (long_names_list.total_size) {
members_base_offset += sizeof_long_names;
}
}
// write second linker member
if (emit_second_member) {
U64 symbols_count;
COFF_LibWriterSymbol *symbols;
{
U64 symbols_count_with_null = lib_writer->symbol_list.count + 2;
COFF_LibWriterSymbol *symbols_with_null = coff_lib_writer_symbol_array_from_list(scratch.arena, lib_writer->symbol_list);
coff_lib_writer_symbol_array_sort_on_name(symbols_with_null, symbols_count_with_null);
symbols_count = symbols_count_with_null - 2;
symbols = symbols_with_null + 1;
}
// write symbol name buffer
U8 *name_buffer = push_array_no_zero(scratch.arena, U8, name_buffer_size);
{
U64 name_cursor = 0;
for EachIndex(symbol_idx, symbols_count) {
COFF_LibWriterSymbol *symbol = &symbols[symbol_idx];
MemoryCopy(name_buffer + name_cursor, symbol->name.str, symbol->name.size);
name_buffer[name_cursor + symbol->name.size] = '\0';
name_cursor += symbol->name.size + 1;
}
}
U32 member_count32 = safe_cast_u32(member_count);
U32 symbol_count32 = safe_cast_u32(symbols_count);
U32 *member_off32_arr = push_array_no_zero(scratch.arena, U32, member_count);
U16 *member_idx16_arr = push_array_no_zero(scratch.arena, U16, symbols_count);
// write member offset array
for EachIndex(member_idx, member_count) {
U64 member_offset = members_base_offset + member_offsets[member_idx];
U32 member_off32 = safe_cast_u32(member_offset);
member_off32_arr[member_idx] = member_off32;
}
// write member offset indices for each symbol
for EachIndex(symbol_idx, symbols_count) {
// member offset indices are 1-based
U64 member_idx = symbols[symbol_idx].member_idx + 1;
U16 member_idx16 = safe_cast_u16(member_idx);
member_idx16_arr[symbol_idx] = member_idx16;
}
// layout second member data
String8List second_member_data_list = {0};
str8_list_push(scratch.arena, &second_member_data_list, str8_struct(&member_count32));
str8_list_push(scratch.arena, &second_member_data_list, str8_array(member_off32_arr, member_count));
str8_list_push(scratch.arena, &second_member_data_list, str8_struct(&symbol_count32));
str8_list_push(scratch.arena, &second_member_data_list, str8_array(member_idx16_arr, symbols_count));
str8_list_push(scratch.arena, &second_member_data_list, str8(name_buffer, name_buffer_size));
String8 member_data = str8_list_join(scratch.arena, &second_member_data_list, 0);
String8 member_header = coff_make_lib_member_header(scratch.arena, str8_lit("/"), time_stamp, 0, 0, mode, member_data.size);
U64 member_offset = member_data_list.total_size + member_data.size + member_header.size;
{
U64 pad_size = AlignPadPow2(member_offset, COFF_Archive_MemberAlign);
U8 *pad = push_array(scratch.arena, U8, pad_size);
str8_list_push_front(scratch.arena, &member_data_list, str8(pad, pad_size));
}
str8_list_push_front(scratch.arena, &member_data_list, member_data);
str8_list_push_front(scratch.arena, &member_data_list, member_header);
}
// write first linker member (obsolete, but kept for compatability reasons)
{
U64 symbols_count;
COFF_LibWriterSymbol *symbols;
{
U64 symbols_count_with_null = lib_writer->symbol_list.count + 2;
COFF_LibWriterSymbol *symbols_with_null = coff_lib_writer_symbol_array_from_list(scratch.arena, lib_writer->symbol_list);
coff_lib_writer_symbol_array_sort_on_member_idx(symbols_with_null, symbols_count_with_null);
symbols_count = symbols_count_with_null - 2;
symbols = symbols_with_null + 1;
}
// write symbol name buffer
U8 *name_buffer = push_array_no_zero(scratch.arena, U8, name_buffer_size);
{
U64 name_cursor = 0;
for EachIndex(symbol_idx, symbols_count) {
COFF_LibWriterSymbol *symbol = &symbols[symbol_idx];
MemoryCopy(name_buffer + name_cursor, symbol->name.str, symbol->name.size);
name_buffer[name_cursor + symbol->name.size] = '\0';
name_cursor += symbol->name.size + 1;
}
}
U32 symbol_count_be = from_be_u32(symbols_count);
U32 *member_off32_arr = push_array_no_zero(scratch.arena, U32, symbols_count);
for EachIndex(symbol_idx, symbols_count) {
COFF_LibWriterSymbol *symbol = &symbols[symbol_idx];
// write big endian member offset
U64 member_offset = members_base_offset + member_offsets[symbol->member_idx];
U32 member_off32 = from_be_u32(safe_cast_u32(member_offset));
member_off32_arr[symbol_idx] = member_off32;
}
// layout first member data
String8List first_member_data_list = {0};
str8_list_push(scratch.arena, &first_member_data_list, str8_struct(&symbol_count_be));
str8_list_push(scratch.arena, &first_member_data_list, str8_array(member_off32_arr, symbols_count));
str8_list_push(scratch.arena, &first_member_data_list, str8(name_buffer, name_buffer_size));
String8 member_data = str8_list_join(scratch.arena, &first_member_data_list, 0);
String8 member_header = coff_make_lib_member_header(scratch.arena, str8_lit("/"), time_stamp, 0, 0, mode, member_data.size);
U64 member_offset = sizeof(g_coff_archive_sig) + member_header.size + member_data.size;
{
U64 pad_size = AlignPadPow2(member_offset, COFF_Archive_MemberAlign);
U8 *pad = push_array(scratch.arena, U8, pad_size);
str8_list_push_front(scratch.arena, &member_data_list, str8(pad, pad_size));
}
str8_list_push_front(scratch.arena, &member_data_list, member_data);
str8_list_push_front(scratch.arena, &member_data_list, member_header);
}
// archive signature
str8_list_push_front(scratch.arena, &member_data_list, str8_struct(&g_coff_archive_sig));
String8 raw_lib = str8_list_join(arena, &member_data_list, 0);
scratch_end(scratch);
return raw_lib;
}
+70
View File
@@ -0,0 +1,70 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef COFF_LIB_WRITER_H
#define COFF_LIB_WRITER_H
typedef struct COFF_LibWriterMember
{
String8 name;
String8 data;
} COFF_LibWriterMember;
typedef struct COFF_LibWriterMemberNode
{
COFF_LibWriterMember data;
struct COFF_LibWriterMemberNode *next;
} COFF_LibWriterMemberNode;
typedef struct COFF_LibWriterMemberList
{
U64 count;
COFF_LibWriterMemberNode *first;
COFF_LibWriterMemberNode *last;
} COFF_LibWriterMemberList;
typedef struct COFF_LibWriterSymbol
{
String8 name;
U64 member_idx;
} COFF_LibWriterSymbol;
typedef struct COFF_LibWriterSymbolNode
{
COFF_LibWriterSymbol data;
struct COFF_LibWriterSymbolNode *next;
} COFF_LibWriterSymbolNode;
typedef struct COFF_LibWriterSymbolList
{
U64 count;
COFF_LibWriterSymbolNode *first;
COFF_LibWriterSymbolNode *last;
} COFF_LibWriterSymbolList;
typedef struct COFF_LibWriter
{
Arena *arena;
COFF_LibWriterMemberList member_list;
COFF_LibWriterSymbolList symbol_list;
} COFF_LibWriter;
////////////////////////////////
internal COFF_LibWriterSymbolNode * coff_lib_writer_symbol_list_push(Arena *arena, COFF_LibWriterSymbolList *list, COFF_LibWriterSymbol symbol);
internal COFF_LibWriterMemberNode * coff_lib_writer_member_list_push(Arena *arena, COFF_LibWriterMemberList *list, COFF_LibWriterMember member);
internal COFF_LibWriterSymbol * coff_lib_writer_symbol_array_from_list(Arena *arena, COFF_LibWriterSymbolList list);
internal COFF_LibWriterMember * coff_lib_writer_member_array_from_list(Arena *arena, COFF_LibWriterMemberList list);
internal void coff_lib_writer_symbol_array_sort_on_name(COFF_LibWriterSymbol *arr, U64 count);
internal void coff_lib_writer_symbol_array_sort_on_member_idx(COFF_LibWriterSymbol *arr, U64 count);
internal COFF_LibWriter * coff_lib_writer_alloc(void);
internal void coff_lib_writer_release(COFF_LibWriter **writer_ptr);
internal U64 coff_lib_writer_push_obj(COFF_LibWriter *writer, String8 obj_path, String8 obj_data);
internal void coff_lib_writer_push_import(COFF_LibWriter *lib_writer, COFF_MachineType machine, COFF_TimeStamp time_stamp, String8 dll_name, COFF_ImportByType import_by, String8 name, U16 hint_or_ordinal, COFF_ImportType import_type);
internal String8 coff_lib_writer_serialize(Arena *arena, COFF_LibWriter *lib_writer, COFF_TimeStamp time_stamp, U16 mode, B32 emit_second_member);
#endif // COFF_LIB_WRITER_H
+500
View File
@@ -0,0 +1,500 @@
internal COFF_ObjWriter*
coff_obj_writer_alloc(COFF_TimeStamp time_stamp, COFF_MachineType machine)
{
Arena *arena = arena_alloc();
COFF_ObjWriter *obj_writer = push_array(arena, COFF_ObjWriter, 1);
obj_writer->arena = arena;
obj_writer->time_stamp = time_stamp;
obj_writer->machine = machine;
return obj_writer;
}
internal void
coff_obj_writer_release(COFF_ObjWriter **obj_writer)
{
arena_release((*obj_writer)->arena);
*obj_writer = 0;
}
internal String8
coff_obj_writer_serialize(Arena *arena, COFF_ObjWriter *obj_writer)
{
Temp scratch = scratch_begin(&arena, 1);
String8List srl = {0};
String8List string_table = {0};
U32 *string_table_size = push_array(scratch.arena, U32, 1);
*string_table_size = sizeof(*string_table_size);
str8_list_push(scratch.arena, &string_table, str8_struct(string_table_size));
//
// assing section numbers
//
U64 obj_sections_count;
COFF_ObjSection **obj_sections;
{
obj_sections_count = obj_writer->sect_count;
obj_sections = push_array(scratch.arena, COFF_ObjSection *, obj_writer->sect_count);
U64 sect_idx = 0;
for (COFF_ObjSectionNode *sect_n = obj_writer->sect_first; sect_n != 0; sect_n = sect_n->next, sect_idx += 1) {
COFF_ObjSection *sect = &sect_n->v;
sect->section_number = sect_idx+1;
obj_sections[sect_idx] = sect;
}
}
AssertAlways(obj_sections_count <= max_U16);
//
// serialize symbol table
//
String8List symbol_table = {0};
{
{
U64 symbol_idx = 0;
for (COFF_ObjSymbolNode *symbol_n = obj_writer->symbol_first; symbol_n != 0; symbol_n = symbol_n->next) {
COFF_ObjSymbol *s = &symbol_n->v;
// assign symbol index
s->idx = symbol_idx++;
symbol_idx += s->aux_symbols.node_count;
}
}
U64 symbol_idx = 0;
for (COFF_ObjSymbolNode *symbol_n = obj_writer->symbol_first; symbol_n != 0; symbol_n = symbol_n->next) {
COFF_ObjSymbol *s = &symbol_n->v;
COFF_Symbol16 *d = push_array(scratch.arena, COFF_Symbol16, 1);
str8_list_push(scratch.arena, &symbol_table, str8_struct(d));
COFF_SymbolName name = {0};
// long name
if (s->name.size > sizeof(name.short_name)) {
U64 string_table_offset = string_table.total_size;
str8_list_push(scratch.arena, &string_table, s->name);
str8_list_push(scratch.arena, &string_table, str8_lit("\0"));
name.long_name.zeroes = 0;
name.long_name.string_table_offset = safe_cast_u32(string_table_offset);
}
// short name
else {
MemoryCopyStr8(name.short_name, s->name);
MemoryZeroTyped(name.short_name + s->name.size, sizeof(name.short_name) - s->name.size);
}
// symbol header
AssertAlways(s->aux_symbols.node_count <= max_U8);
d->name = name;
d->value = s->value;
switch (s->loc.type) {
case COFF_SymbolLocation_Null: break;
case COFF_SymbolLocation_Section: d->section_number = safe_cast_u16(s->loc.u.section->section_number); break;
case COFF_SymbolLocation_Abs: d->section_number = COFF_Symbol_AbsSection16; break;
case COFF_SymbolLocation_Undef: d->section_number = COFF_Symbol_UndefinedSection; break;
case COFF_SymbolLocation_Common: d->section_number = COFF_Symbol_UndefinedSection; break;
}
d->type = s->type;
d->storage_class = s->storage_class;
d->aux_symbol_count = 0;
U64 start_symbol_idx = symbol_idx;
if (s->storage_class == COFF_SymStorageClass_WeakExternal) {
if (s->aux_symbols.node_count > 0) {
COFF_ObjSymbolWeak *s_weak = (COFF_ObjSymbolWeak *)s->aux_symbols.first->string.str;
COFF_SymbolWeakExt *d_weak = push_array(scratch.arena, COFF_SymbolWeakExt, 1);
d_weak->tag_index = s_weak->tag ? s_weak->tag->idx : max_U32;
d_weak->characteristics = s_weak->characteristics;
str8_list_push(scratch.arena, &symbol_table, str8_struct(d_weak));
symbol_idx += 1;
}
} else if (s->storage_class == COFF_SymStorageClass_Static) {
if (s->aux_symbols.node_count > 0) {
Assert(s->loc.type == COFF_SymbolLocation_Section);
COFF_ObjSection *sect = s->loc.u.section;
COFF_ObjSymbolSecDef *s_sd = (COFF_ObjSymbolSecDef *)s->aux_symbols.first->string.str;
COFF_SymbolSecDef *d_sd = push_array(scratch.arena, COFF_SymbolSecDef, 1);
d_sd->length = safe_cast_u32(sect->data.total_size);
d_sd->number_of_relocations = (U16)sect->reloc_count;
d_sd->check_sum = 0;
d_sd->number_lo = s_sd->selection == COFF_ComdatSelect_Associative ? safe_cast_u16(s_sd->associate->section_number) : 0;
d_sd->selection = s_sd->selection;
str8_list_push(scratch.arena, &symbol_table, str8_struct(d_sd));
symbol_idx += 1;
}
}
U8 processed_aux_symbol_count = (U8)(symbol_idx - start_symbol_idx);
for (U64 aux_idx = processed_aux_symbol_count; aux_idx < s->aux_symbols.node_count; aux_idx += 1) {
COFF_Symbol16 *a = push_array(scratch.arena, COFF_Symbol16, 1);
str8_list_push(scratch.arena, &symbol_table, str8_struct(a));
}
d->aux_symbol_count = (U8)s->aux_symbols.node_count;
}
}
//
// file header
//
COFF_FileHeader *file_header = push_array(scratch.arena, COFF_FileHeader, 1);
file_header->machine = obj_writer->machine;
file_header->section_count = obj_sections_count;
file_header->time_stamp = obj_writer->time_stamp;
file_header->symbol_table_foff = 0;
file_header->symbol_count = safe_cast_u32(symbol_table.node_count);
file_header->optional_header_size = 0;
file_header->flags = 0;
str8_list_push(scratch.arena, &srl, str8_struct(file_header));
//
// section table
//
COFF_SectionHeader *sectab = push_array(scratch.arena, COFF_SectionHeader, obj_sections_count);
str8_list_push(scratch.arena, &srl, str8_array(sectab, obj_sections_count));
{
for (U64 sect_idx = 0; sect_idx < obj_sections_count; sect_idx += 1) {
COFF_ObjSection *s = obj_sections[sect_idx];
COFF_SectionHeader *d = &sectab[sect_idx];
// section name
String8 sect_name = s->name;
if (sect_name.size > sizeof(d->name)) {
U64 sect_name_off = string_table.total_size;
str8_list_push(scratch.arena, &string_table, push_cstr(scratch.arena, sect_name));
sect_name = push_str8f(scratch.arena, "/%u", sect_name_off);
AssertAlways(sect_name.size <= sizeof(d->name));
}
// alloc zero nodes
for (String8Node *data_n = s->data.first; data_n != 0; data_n = data_n->next) {
if (data_n->string.str == 0 && data_n->string.size > 0) {
data_n->string = str8(push_array(scratch.arena, U8, data_n->string.size), data_n->string.size);
}
}
// section data
U64 data_foff = 0;
U64 data_size = 0;
if (s->data.total_size > 0) {
data_foff = srl.total_size;
data_size = s->data.total_size;
str8_list_concat_in_place(&srl, &s->data);
}
// section relocs
U64 relocs_foff = 0;
if (s->reloc_count) {
AssertAlways(s->reloc_count <= max_U16);
COFF_Reloc *relocs = push_array(scratch.arena, COFF_Reloc, s->reloc_count);
U64 reloc_idx = 0;
for (COFF_ObjRelocNode *reloc_n = s->reloc_first; reloc_n != 0; reloc_n = reloc_n->next, reloc_idx += 1) {
COFF_ObjReloc *rs = &reloc_n->v;
COFF_Reloc *rd = &relocs[reloc_idx];
rd->apply_off = rs->apply_off;
rd->isymbol = rs->symbol->idx;
rd->type = rs->type;
}
relocs_foff = srl.total_size;
str8_list_push(scratch.arena, &srl, str8_array(relocs, s->reloc_count));
}
// section header
MemoryCopyStr8(d->name, sect_name);
MemoryZeroTyped(d->name + sect_name.size, sizeof(d->name) - sect_name.size);
d->vsize = 0;
d->voff = 0;
d->fsize = data_size;
d->foff = data_foff;
d->relocs_foff = relocs_foff;
d->lines_foff = 0;
d->reloc_count = safe_cast_u32(s->reloc_count);
d->line_count = 0;
d->flags = s->flags;
}
}
//
// symbol table
//
if (symbol_table.total_size || string_table.total_size > sizeof(*string_table_size)) {
file_header->symbol_table_foff = srl.total_size;
str8_list_concat_in_place(&srl, &symbol_table);
}
//
// string table
//
if (string_table.total_size) {
*string_table_size = safe_cast_u32(string_table.total_size);
str8_list_concat_in_place(&srl, &string_table);
}
//
// join
//
String8 obj = str8_list_join(arena, &srl, 0);
scratch_end(scratch);
return obj;
}
internal COFF_ObjSection *
coff_obj_writer_push_section(COFF_ObjWriter *obj_writer, String8 name, COFF_SectionFlags flags, String8 data)
{
COFF_ObjSectionNode *sect_n = push_array(obj_writer->arena, COFF_ObjSectionNode, 1);
SLLQueuePush(obj_writer->sect_first, obj_writer->sect_last, sect_n);
obj_writer->sect_count += 1;
COFF_ObjSection *sect = &sect_n->v;
sect->name = name;
sect->flags = flags;
if (data.size) {
str8_list_push(obj_writer->arena, &sect->data, data);
}
return sect;
}
internal COFF_ObjSymbol *
coff_obj_writer_push_symbol(COFF_ObjWriter *obj_writer, String8 name, U32 value, COFF_SymbolLocation loc, COFF_SymbolType type, COFF_SymStorageClass storage_class)
{
COFF_ObjSymbolNode *n = push_array(obj_writer->arena, COFF_ObjSymbolNode, 1);
SLLQueuePush(obj_writer->symbol_first, obj_writer->symbol_last, n);
obj_writer->symbol_count += 1;
COFF_ObjSymbol *s = &n->v;
s->name = name;
s->value = value;
s->loc = loc;
s->type = type;
s->storage_class = storage_class;
return s;
}
internal COFF_ObjSymbol *
coff_obj_writer_push_symbol_extern(COFF_ObjWriter *obj_writer, String8 name, U32 value, COFF_ObjSection *section)
{
COFF_SymbolLocation loc = {0};
loc.type = COFF_SymbolLocation_Section;
loc.u.section = section;
COFF_ObjSymbol *s = coff_obj_writer_push_symbol(obj_writer, name, value, loc, (COFF_SymbolType){0}, COFF_SymStorageClass_External);
return s;
}
internal COFF_ObjSymbol *
coff_obj_writer_push_symbol_extern_func(COFF_ObjWriter *obj_writer, String8 name, U32 value, COFF_ObjSection *section)
{
COFF_SymbolType type = { .u.msb = COFF_SymDType_Func };
COFF_SymbolLocation loc = { .type = COFF_SymbolLocation_Section, .u.section = section };
COFF_ObjSymbol *s = coff_obj_writer_push_symbol(obj_writer, name, value, loc, type, COFF_SymStorageClass_External);
return s;
}
internal COFF_ObjSymbol *
coff_obj_writer_push_symbol_static(COFF_ObjWriter *obj_writer, String8 name, U32 off, COFF_ObjSection *section)
{
COFF_SymbolLocation loc = {0};
loc.type = COFF_SymbolLocation_Section;
loc.u.section = section;
COFF_SymbolType symtype = {0};
COFF_ObjSymbol *s = coff_obj_writer_push_symbol(obj_writer, name, off, loc, symtype, COFF_SymStorageClass_Static);
return s;
}
internal COFF_ObjSymbol *
coff_obj_writer_push_symbol_secdef(COFF_ObjWriter *obj_writer, COFF_ObjSection *section, COFF_ComdatSelectType selection)
{
COFF_ObjSymbol *s = coff_obj_writer_push_symbol_static(obj_writer, section->name, 0, section);
COFF_ObjSymbolSecDef *sd = push_array(obj_writer->arena, COFF_ObjSymbolSecDef, 1);
sd->selection = selection;
str8_list_push(obj_writer->arena, &s->aux_symbols, str8_struct(sd));
return s;
}
internal COFF_ObjSymbol *
coff_obj_writer_push_symbol_associative(COFF_ObjWriter *obj_writer, COFF_ObjSection *head, COFF_ObjSection *associate)
{
COFF_ObjSymbol *s = coff_obj_writer_push_symbol_static(obj_writer, head->name, 0, head);
COFF_ObjSymbolSecDef *sd = push_array(obj_writer->arena, COFF_ObjSymbolSecDef, 1);
sd->selection = COFF_ComdatSelect_Associative;
sd->associate = associate;
str8_list_push(obj_writer->arena, &s->aux_symbols, str8_struct(sd));
return s;
}
internal COFF_ObjSymbol *
coff_obj_writer_push_symbol_weak(COFF_ObjWriter *obj_writer, String8 name, COFF_WeakExtType characteristics, COFF_ObjSymbol *tag)
{
COFF_SymbolLocation loc = {0};
COFF_SymbolType symtype = {0};
COFF_ObjSymbol *s = coff_obj_writer_push_symbol(obj_writer, name, COFF_Symbol_UndefinedSection, loc, symtype, COFF_SymStorageClass_WeakExternal);
COFF_ObjSymbolWeak *weak_ext = push_array(obj_writer->arena, COFF_ObjSymbolWeak, 1);
weak_ext->tag = tag;
weak_ext->characteristics = characteristics;
str8_list_push(obj_writer->arena, &s->aux_symbols, str8_struct(weak_ext));
return s;
}
internal COFF_ObjSymbol *
coff_obj_writer_push_symbol_abs(COFF_ObjWriter *obj_writer, String8 name, U32 value, COFF_SymStorageClass storage_class)
{
COFF_SymbolLocation loc = {0};
loc.type = COFF_SymbolLocation_Abs;
COFF_ObjSymbol *s = coff_obj_writer_push_symbol(obj_writer, name, value, loc, (COFF_SymbolType){0}, storage_class);
return s;
}
internal COFF_ObjSymbol *
coff_obj_writer_push_symbol_undef(COFF_ObjWriter *obj_writer, String8 name)
{
COFF_SymbolType type = {0};
COFF_SymbolLocation loc = {0};
loc.type = COFF_SymbolLocation_Undef;
COFF_ObjSymbol *s = coff_obj_writer_push_symbol(obj_writer, name, 0, loc, type, COFF_SymStorageClass_External);
return s;
}
internal COFF_ObjSymbol *
coff_obj_writer_push_symbol_undef_func(COFF_ObjWriter *obj_writer, String8 name)
{
COFF_SymbolType type = {0};
type.u.msb = COFF_SymDType_Func;
COFF_SymbolLocation loc = {0};
loc.type = COFF_SymbolLocation_Undef;
COFF_ObjSymbol *s = coff_obj_writer_push_symbol(obj_writer, name, 0, loc, type, COFF_SymStorageClass_External);
return s;
}
internal COFF_ObjSymbol *
coff_obj_writer_push_symbol_undef_sect(COFF_ObjWriter *obj_writer, String8 name, U32 value)
{
COFF_SymbolType type = {0};
COFF_SymbolLocation loc = {0};
loc.type = COFF_SymbolLocation_Undef;
COFF_ObjSymbol *s = coff_obj_writer_push_symbol(obj_writer, name, value, loc, type, COFF_SymStorageClass_Section);
return s;
}
internal COFF_ObjSymbol *
coff_obj_writer_push_symbol_sect(COFF_ObjWriter *obj_writer, String8 name, COFF_ObjSection *sect)
{
COFF_SymbolType type = {0};
COFF_SymbolLocation loc = {0};
loc.type = COFF_SymbolLocation_Section;
loc.u.section = sect;
// strip align flags
COFF_SectionFlags expected_flags = sect->flags & ~(COFF_SectionFlag_AlignMask << COFF_SectionFlag_AlignShift);
COFF_ObjSymbol *s = coff_obj_writer_push_symbol(obj_writer, name, expected_flags, loc, type, COFF_SymStorageClass_Section);
return s;
}
internal COFF_ObjSymbol *
coff_obj_writer_push_symbol_common(COFF_ObjWriter *obj_writer, String8 name, U32 size)
{
COFF_SymbolType type = {0};
COFF_SymbolLocation loc = {0};
loc.type = COFF_SymbolLocation_Common;
COFF_ObjSymbol *s = coff_obj_writer_push_symbol(obj_writer, name, size, loc, type, COFF_SymStorageClass_External);
return s;
}
internal void
coff_obj_writer_set_default_symbol(COFF_ObjSymbol *weak_symbol, COFF_ObjSymbol *default_symbol)
{
AssertAlways(weak_symbol->storage_class == COFF_SymStorageClass_WeakExternal);
COFF_ObjSymbolWeak *w = (COFF_ObjSymbolWeak *)weak_symbol->aux_symbols.first->string.str;
w->tag = default_symbol;
}
internal COFF_ObjReloc*
coff_obj_writer_section_push_reloc(COFF_ObjWriter *obj_writer, COFF_ObjSection *sect, U32 apply_off, COFF_ObjSymbol *symbol, COFF_RelocType type)
{
COFF_ObjRelocNode *reloc_n = push_array(obj_writer->arena, COFF_ObjRelocNode, 1);
SLLQueuePush(sect->reloc_first, sect->reloc_last, reloc_n);
sect->reloc_count += 1;
COFF_ObjReloc *reloc = &reloc_n->v;
reloc->apply_off = apply_off;
reloc->symbol = symbol;
reloc->type = type;
return reloc;
}
internal COFF_ObjReloc *
coff_obj_writer_section_push_reloc_addr32(COFF_ObjWriter *obj_writer, COFF_ObjSection *sect, U32 apply_off, COFF_ObjSymbol *symbol)
{
COFF_RelocType reloc_type = 0;
switch (obj_writer->machine) {
case COFF_MachineType_Unknown: break;
case COFF_MachineType_X64: reloc_type = COFF_Reloc_X64_Addr32; break;
default: { NotImplemented; } break;
}
return coff_obj_writer_section_push_reloc(obj_writer, sect, apply_off, symbol, reloc_type);
}
internal COFF_ObjReloc *
coff_obj_writer_section_push_reloc_addr(COFF_ObjWriter *obj_writer, COFF_ObjSection *sect, U32 apply_off, COFF_ObjSymbol *symbol)
{
COFF_RelocType reloc_type = 0;
switch (obj_writer->machine) {
case COFF_MachineType_Unknown: break;
case COFF_MachineType_X64: reloc_type = COFF_Reloc_X64_Addr64; break;
default: { NotImplemented; } break;
}
return coff_obj_writer_section_push_reloc(obj_writer, sect, apply_off, symbol, reloc_type);
}
internal COFF_ObjReloc *
coff_obj_writer_section_push_reloc_voff(COFF_ObjWriter *obj_writer, COFF_ObjSection *sect, U32 apply_off, COFF_ObjSymbol *symbol)
{
COFF_RelocType reloc_type = 0;
switch (obj_writer->machine) {
case COFF_MachineType_Unknown: break;
case COFF_MachineType_X64: reloc_type = COFF_Reloc_X64_Addr32Nb; break;
default: { NotImplemented; } break;
}
return coff_obj_writer_section_push_reloc(obj_writer, sect, apply_off, symbol, reloc_type);
}
internal void
coff_obj_writer_push_directive(COFF_ObjWriter *obj_writer, String8 directive)
{
if (obj_writer->drectve_sect == 0) {
local_persist const U8 bom_sig[] = { ' ', ' ', ' ' };
obj_writer->drectve_sect = coff_obj_writer_push_section(obj_writer, str8_lit(".drectve"), COFF_SectionFlag_LnkInfo|COFF_SectionFlag_LnkRemove|COFF_SectionFlag_Align1Bytes, str8_array_fixed(bom_sig));
}
String8List *data = &obj_writer->drectve_sect->data;
str8_list_push(obj_writer->arena, data, directive);
str8_list_pushf(obj_writer->arena, data, " ");
}
internal int
coff_obj_section_is_before(void *raw_a, void *raw_b)
{
COFF_ObjSection **a = raw_a;
COFF_ObjSection **b = raw_b;
return (*a)->section_number < (*b)->section_number;
}
+128
View File
@@ -0,0 +1,128 @@
#ifndef COFF_OBJ_WRITER_H
#define COFF_OBJ_WRITER_H
typedef enum
{
COFF_SymbolLocation_Null,
COFF_SymbolLocation_Section,
COFF_SymbolLocation_Abs,
COFF_SymbolLocation_Undef,
COFF_SymbolLocation_Common,
} COFF_SymbolLocationType;
typedef struct COFF_SymbolLocation
{
COFF_SymbolLocationType type;
union {
struct COFF_ObjSection *section;
} u;
} COFF_SymbolLocation;
typedef struct COFF_ObjSymbolWeak
{
struct COFF_ObjSymbol *tag;
COFF_WeakExtType characteristics;
} COFF_ObjSymbolWeak;
typedef struct COFF_ObjSymbolSecDef
{
COFF_ComdatSelectType selection;
struct COFF_ObjSection *associate;
} COFF_ObjSymbolSecDef;
typedef struct COFF_ObjSymbol
{
String8 name;
U32 value;
COFF_SymbolLocation loc;
COFF_SymbolType type;
COFF_SymStorageClass storage_class;
String8List aux_symbols;
U32 idx;
} COFF_ObjSymbol;
typedef struct COFF_ObjSymbolNode
{
struct COFF_ObjSymbolNode *next;
COFF_ObjSymbol v;
} COFF_ObjSymbolNode;
typedef struct COFF_ObjReloc
{
U32 apply_off;
COFF_ObjSymbol *symbol;
COFF_RelocType type;
} COFF_ObjReloc;
typedef struct COFF_ObjRelocNode
{
struct COFF_ObjRelocNode *next;
COFF_ObjReloc v;
} COFF_ObjRelocNode;
typedef struct COFF_ObjSection
{
String8 name;
String8List data;
COFF_SectionFlags flags;
U64 reloc_count;
COFF_ObjRelocNode *reloc_first;
COFF_ObjRelocNode *reloc_last;
U32 section_number;
} COFF_ObjSection;
typedef struct COFF_ObjSectionNode
{
struct COFF_ObjSectionNode *next;
COFF_ObjSection v;
} COFF_ObjSectionNode;
typedef struct COFF_ObjWriter
{
Arena *arena;
COFF_TimeStamp time_stamp;
COFF_MachineType machine;
U64 symbol_count;
COFF_ObjSymbolNode *symbol_first;
COFF_ObjSymbolNode *symbol_last;
U64 sect_count;
COFF_ObjSectionNode *sect_first;
COFF_ObjSectionNode *sect_last;
COFF_ObjSection *drectve_sect;
} COFF_ObjWriter;
////////////////////////////////
internal COFF_ObjWriter * coff_obj_writer_alloc(COFF_TimeStamp time_stamp, COFF_MachineType machine);
internal void coff_obj_writer_release(COFF_ObjWriter **obj_writer);
internal String8 coff_obj_writer_serialize(Arena *arena, COFF_ObjWriter *obj_writer);
internal COFF_ObjSection * coff_obj_writer_push_section(COFF_ObjWriter *obj_writer, String8 name, COFF_SectionFlags flags, String8 data);
internal COFF_ObjSymbol* coff_obj_writer_push_symbol(COFF_ObjWriter *obj_writer, String8 name, U32 value, COFF_SymbolLocation loc, COFF_SymbolType type, COFF_SymStorageClass storage_class);
internal COFF_ObjSymbol * coff_obj_writer_push_symbol_extern_func(COFF_ObjWriter *obj_writer, String8 name, U32 value, COFF_ObjSection *section);
internal COFF_ObjSymbol * coff_obj_writer_push_symbol_extern(COFF_ObjWriter *obj_writer, String8 name, U32 value, COFF_ObjSection *section);
internal COFF_ObjSymbol * coff_obj_writer_push_symbol_static(COFF_ObjWriter *obj_writer, String8 name, U32 off, COFF_ObjSection *section);
internal COFF_ObjSymbol * coff_obj_writer_push_symbol_secdef(COFF_ObjWriter *obj_writer, COFF_ObjSection *section, COFF_ComdatSelectType selection);
internal COFF_ObjSymbol * coff_obj_writer_push_symbol_associative(COFF_ObjWriter *obj_writer, COFF_ObjSection *head, COFF_ObjSection *associate);
internal COFF_ObjSymbol * coff_obj_writer_push_symbol_weak(COFF_ObjWriter *obj_writer, String8 name, COFF_WeakExtType characteristics, COFF_ObjSymbol *tag);
internal COFF_ObjSymbol * coff_obj_writer_push_symbol_abs(COFF_ObjWriter *obj_writer, String8 name, U32 value, COFF_SymStorageClass storage_class);
internal COFF_ObjSymbol * coff_obj_writer_push_symbol_undef(COFF_ObjWriter *obj_writer, String8 name);
internal COFF_ObjSymbol * coff_obj_writer_push_symbol_undef_func(COFF_ObjWriter *obj_writer, String8 name);
internal COFF_ObjSymbol * coff_obj_writer_push_symbol_undef_sect(COFF_ObjWriter *obj_writer, String8 name, U32 value);
internal COFF_ObjSymbol * coff_obj_writer_push_symbol_sect(COFF_ObjWriter *obj_writer, String8 name, COFF_ObjSection *sect);
internal COFF_ObjSymbol * coff_obj_writer_push_symbol_common(COFF_ObjWriter *obj_writer, String8 name, U32 size);
internal void coff_obj_writer_set_default_symbol(COFF_ObjSymbol *weak_symbol, COFF_ObjSymbol *default_symbol);
internal COFF_ObjReloc * coff_obj_writer_section_push_reloc(COFF_ObjWriter *obj_writer, COFF_ObjSection *sect, U32 apply_off, COFF_ObjSymbol *symbol, COFF_RelocType reloc_type);
internal COFF_ObjReloc * coff_obj_writer_section_push_reloc_addr32(COFF_ObjWriter *obj_writer, COFF_ObjSection *sect, U32 apply_off, COFF_ObjSymbol *symbol);
internal COFF_ObjReloc * coff_obj_writer_section_push_reloc_addr(COFF_ObjWriter *obj_writer, COFF_ObjSection *sect, U32 apply_off, COFF_ObjSymbol *symbol);
internal COFF_ObjReloc * coff_obj_writer_section_push_reloc_voff(COFF_ObjWriter *obj_writer, COFF_ObjSection *sect, U32 apply_off, COFF_ObjSymbol *symbol);
internal void coff_obj_writer_push_directive(COFF_ObjWriter *obj_writer, String8 directive);
#endif // COFF_OBJ_WRITER_H
+991
View File
@@ -0,0 +1,991 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal B32
coff_is_big_obj(String8 raw_coff)
{
B32 is_big_obj = 0;
if (raw_coff.size >= sizeof(COFF_BigObjHeader)) {
COFF_BigObjHeader *file_header32 = (COFF_BigObjHeader*)(raw_coff.str);
is_big_obj = file_header32->sig1 == COFF_MachineType_Unknown &&
file_header32->sig2 == max_U16 &&
file_header32->version >= 2 &&
MemoryCompare(file_header32->magic, g_coff_big_header_magic, sizeof(file_header32->magic)) == 0;
}
return is_big_obj;
}
internal B32
coff_is_obj(String8 raw_coff)
{
B32 is_obj = 0;
if (raw_coff.size >= sizeof(COFF_FileHeader)) {
COFF_FileHeader *header = (COFF_FileHeader*)(raw_coff.str);
// validate machine
B32 is_machine_type_valid = 0;
switch (header->machine) {
case COFF_MachineType_Unknown:
case COFF_MachineType_X86: case COFF_MachineType_X64:
case COFF_MachineType_Am33: case COFF_MachineType_Arm:
case COFF_MachineType_Arm64: case COFF_MachineType_ArmNt:
case COFF_MachineType_Ebc: case COFF_MachineType_Ia64:
case COFF_MachineType_M32R: case COFF_MachineType_Mips16:
case COFF_MachineType_MipsFpu:case COFF_MachineType_MipsFpu16:
case COFF_MachineType_PowerPc:case COFF_MachineType_PowerPcFp:
case COFF_MachineType_R4000: case COFF_MachineType_RiscV32:
case COFF_MachineType_RiscV64:case COFF_MachineType_RiscV128:
case COFF_MachineType_Sh3: case COFF_MachineType_Sh3Dsp:
case COFF_MachineType_Sh4: case COFF_MachineType_Sh5:
case COFF_MachineType_Thumb: case COFF_MachineType_WceMipsV2:
{
is_machine_type_valid = 1;
}break;
}
if (is_machine_type_valid) {
// validate section count
U64 section_count = header->section_count;
U64 section_hdr_opl_off = sizeof(*header) + section_count*sizeof(COFF_SectionHeader);
if (raw_coff.size >= section_hdr_opl_off) {
COFF_SectionHeader *section_hdrs = (COFF_SectionHeader*)(raw_coff.str + sizeof(*header));
COFF_SectionHeader *section_hdr_opl = section_hdrs + section_count;
// validate section ranges
B32 is_sect_range_valid = 1;
for (COFF_SectionHeader *sec_hdr = section_hdrs;
sec_hdr < section_hdr_opl;
sec_hdr += 1) {
if (!(sec_hdr->flags & COFF_SectionFlag_CntUninitializedData)) {
U64 min = sec_hdr->foff;
U64 max = min + sec_hdr->fsize;
if (sec_hdr->fsize > 0 && !(section_hdr_opl_off <= min && min <= max && max <= raw_coff.size)) {
is_sect_range_valid = 0;
break;
}
}
}
if (is_sect_range_valid) {
// validate symbol table
U64 symbol_table_off = header->symbol_table_foff;
U64 symbol_table_size = sizeof(COFF_Symbol16)*header->symbol_count;
U64 symbol_table_opl_off = symbol_table_off + symbol_table_size;
// don't validate symbol table when there is none
if (symbol_table_off == 0 && symbol_table_size == 0) {
symbol_table_off = section_hdr_opl_off;
symbol_table_opl_off = section_hdr_opl_off;
}
is_obj = (section_hdr_opl_off <= symbol_table_off &&
symbol_table_off <= symbol_table_opl_off &&
symbol_table_opl_off <= raw_coff.size);
}
}
}
}
return is_obj;
}
internal COFF_FileHeaderInfo
coff_file_header_info_from_data(String8 raw_coff)
{
COFF_FileHeaderInfo info = {0};
if (coff_is_big_obj(raw_coff)) {
COFF_BigObjHeader *header32 = (COFF_BigObjHeader*)raw_coff.str;
info.is_big_obj = 1;
info.machine = header32->machine;
info.section_count_no_null = header32->section_count;
info.symbol_count = header32->symbol_count;
info.symbol_size = sizeof(COFF_Symbol32);
info.header_range = rng_1u64(0, sizeof(COFF_BigObjHeader));
info.section_table_range = rng_1u64(info.header_range.max, info.header_range.max + sizeof(COFF_SectionHeader) * header32->section_count);
info.symbol_table_range = rng_1u64(header32->symbol_table_foff, header32->symbol_table_foff + sizeof(COFF_Symbol32) * header32->symbol_count);
info.string_table_range = rng_1u64(info.symbol_table_range.max, raw_coff.size);
} else if (coff_is_obj(raw_coff)) {
COFF_FileHeader *header16 = (COFF_FileHeader*)raw_coff.str;
info.is_big_obj = 0;
info.machine = header16->machine;
info.section_count_no_null = header16->section_count;
info.symbol_count = header16->symbol_count;
info.symbol_size = sizeof(COFF_Symbol16);
info.header_range = rng_1u64(0, sizeof(COFF_FileHeader));
info.section_table_range = rng_1u64(info.header_range.max, info.header_range.max + sizeof(COFF_SectionHeader) * header16->section_count);
info.symbol_table_range = rng_1u64(header16->symbol_table_foff, header16->symbol_table_foff + sizeof(COFF_Symbol16) * header16->symbol_count);
info.string_table_range = rng_1u64(info.symbol_table_range.max, raw_coff.size);
}
return info;
}
internal COFF_SectionHeader **
coff_section_table_from_data(Arena *arena, String8 data, Rng1U64 section_table_range)
{
U64 section_count = dim_1u64(section_table_range) / sizeof(COFF_SectionHeader);
COFF_SectionHeader **section_table = push_array_no_zero(arena, COFF_SectionHeader *, section_count+1);
section_table[0] = push_array(arena, COFF_SectionHeader, 1);
for (U64 i = 0; i < section_count; ++i) {
section_table[i+1] = str8_deserial_get_raw_ptr(data, section_table_range.min + i*sizeof(COFF_SectionHeader), sizeof(COFF_SectionHeader));
}
return section_table;
}
internal COFF_ParsedSymbol
coff_parse_symbol32(String8 string_table, COFF_Symbol32 *sym32)
{
COFF_ParsedSymbol result = {0};
result.name = coff_read_symbol_name(string_table, &sym32->name);
result.value = sym32->value;
result.section_number = sym32->section_number;
result.type = sym32->type;
result.storage_class = sym32->storage_class;
result.aux_symbol_count = sym32->aux_symbol_count;
result.raw_symbol = sym32;
return result;
}
internal COFF_ParsedSymbol
coff_parse_symbol16(String8 string_table, COFF_Symbol16 *sym16)
{
COFF_ParsedSymbol result = {0};
result.name = coff_read_symbol_name(string_table, &sym16->name);
result.value = sym16->value;
if (sym16->section_number == COFF_Symbol_DebugSection16) {
result.section_number = COFF_Symbol_DebugSection32;
} else if (sym16->section_number == COFF_Symbol_AbsSection16) {
result.section_number = COFF_Symbol_AbsSection32;
} else {
result.section_number = (U32)sym16->section_number;
}
result.type = sym16->type;
result.storage_class = sym16->storage_class;
result.aux_symbol_count = sym16->aux_symbol_count;
result.raw_symbol = sym16;
return result;
}
internal COFF_ParsedSymbol
coff_parse_symbol(COFF_FileHeaderInfo header, String8 string_table, String8 symbol_table, U32 symbol_idx)
{
COFF_ParsedSymbol symbol;
if (header.is_big_obj) {
symbol = coff_parse_symbol32(string_table, (COFF_Symbol32 *)symbol_table.str + symbol_idx);
} else {
symbol = coff_parse_symbol16(string_table, (COFF_Symbol16 *)symbol_table.str + symbol_idx);
}
return symbol;
}
internal COFF_Symbol32Array
coff_symbol_array_from_data_16(Arena *arena, String8 raw_coff, U64 symbol_array_off, U64 symbol_count)
{
COFF_Symbol32Array result = {0};
result.count = symbol_count;
result.v = push_array_no_zero_aligned(arena, COFF_Symbol32, result.count, 8);
Rng1U64 sym16_arr_range = rng_1u64(symbol_array_off, symbol_array_off + sizeof(COFF_Symbol16) * symbol_count);
String8 raw_sym16_arr = str8_substr(raw_coff, sym16_arr_range);
COFF_Symbol16 *sym16_arr = (COFF_Symbol16 *)raw_sym16_arr.str;
for (U64 isymbol = 0, count = raw_sym16_arr.size / sizeof(COFF_Symbol16); isymbol < count; isymbol += 1) {
COFF_Symbol16 *sym16 = &sym16_arr[isymbol];
COFF_Symbol32 *sym32 = &result.v[isymbol];
sym32->name = sym16->name;
sym32->value = sym16->value;
if (sym16->section_number == COFF_Symbol_DebugSection16) {
sym32->section_number = COFF_Symbol_DebugSection32;
} else if (sym16->section_number == COFF_Symbol_AbsSection16) {
sym32->section_number = COFF_Symbol_AbsSection32;
} else {
sym32->section_number = (U32)sym16->section_number;
}
sym32->type.v = sym16->type.v;
sym32->storage_class = sym16->storage_class;
sym32->aux_symbol_count = sym16->aux_symbol_count;
// copy aux symbols
for (U64 iaux = isymbol+1, iaux_hi = Min(count, iaux+sym16->aux_symbol_count); iaux < iaux_hi; iaux += 1) {
COFF_Symbol16 *aux16 = sym16_arr + iaux;
COFF_Symbol32 *aux32 = result.v + iaux;
// 32bit COFF uses 16bit aux symbols
MemoryCopy(aux32, aux16, sizeof(COFF_Symbol16));
MemoryZero((U8 *)aux32 + sizeof(COFF_Symbol16), sizeof(COFF_Symbol32)-sizeof(COFF_Symbol16));
}
// take into account aux symbols
isymbol += sym32->aux_symbol_count;
}
return result;
}
internal COFF_Symbol32Array
coff_symbol_array_from_data_32(Arena *arena, String8 data, U64 symbol_array_off, U64 symbol_count)
{
COFF_Symbol32Array result;
result.count = symbol_count;
result.v = (COFF_Symbol32 *)(data.str + symbol_array_off);
return result;
}
internal COFF_Symbol32Array
coff_symbol_array_from_data(Arena *arena, String8 data, U64 symbol_array_off, U64 symbol_count, U64 symbol_size)
{
COFF_Symbol32Array result = {0};
switch (symbol_size) {
case sizeof(COFF_Symbol16): result = coff_symbol_array_from_data_16(arena, data, symbol_array_off, symbol_count); break;
case sizeof(COFF_Symbol32): result = coff_symbol_array_from_data_32(arena, data, symbol_array_off, symbol_count); break;
}
return result;
}
internal COFF_Symbol16Node *
coff_symbol16_list_push(Arena *arena, COFF_Symbol16List *list, COFF_Symbol16 symbol)
{
COFF_Symbol16Node *node = push_array(arena, COFF_Symbol16Node, 1);
node->next = 0;
node->data = symbol;
SLLQueuePush(list->first, list->last, node);
list->count += 1;
return node;
}
internal COFF_SymbolValueInterpType
coff_interp_symbol(U32 section_number, U32 value, COFF_SymStorageClass storage_class)
{
if (storage_class == COFF_SymStorageClass_Section && section_number == COFF_Symbol_UndefinedSection) {
return COFF_SymbolValueInterp_Undefined;
}
if (storage_class == COFF_SymStorageClass_External && value == 0 && section_number == COFF_Symbol_UndefinedSection) {
return COFF_SymbolValueInterp_Undefined;
}
if (storage_class == COFF_SymStorageClass_External && value != 0 && section_number == COFF_Symbol_UndefinedSection) {
return COFF_SymbolValueInterp_Common;
}
if (section_number == COFF_Symbol_AbsSection32) {
return COFF_SymbolValueInterp_Abs;
}
if (section_number == COFF_Symbol_DebugSection32) {
return COFF_SymbolValueInterp_Debug;
}
if (storage_class == COFF_SymStorageClass_WeakExternal) {
return COFF_SymbolValueInterp_Weak;
}
return COFF_SymbolValueInterp_Regular;
}
internal COFF_SymbolValueInterpType
coff_interp_from_parsed_symbol(COFF_ParsedSymbol symbol)
{
return coff_interp_symbol(symbol.section_number, symbol.value, symbol.storage_class);
}
internal B32
coff_is_undefined_data_symbol(COFF_ParsedSymbol symbol)
{
COFF_SymbolValueInterpType interp = coff_interp_from_parsed_symbol(symbol);
return interp == COFF_SymbolValueInterp_Undefined && symbol.storage_class == COFF_SymStorageClass_External;
}
internal void
coff_parse_secdef(COFF_ParsedSymbol symbol, B32 is_big_obj, COFF_ComdatSelectType *selection_out, U32 *number_out, U32 *length_out, U32 *check_sum_out)
{
Assert(coff_interp_symbol(symbol.section_number, symbol.value, symbol.storage_class) == COFF_SymbolValueInterp_Regular);
Assert(symbol.aux_symbol_count > 0);
if (is_big_obj) {
COFF_SymbolSecDef *sd = (COFF_SymbolSecDef *)((COFF_Symbol32 *)symbol.raw_symbol + 1);
if (selection_out) *selection_out = sd->selection;
if (length_out) *length_out = sd->length;
if (check_sum_out) *check_sum_out = sd->check_sum;
if (number_out) *number_out = Compose32Bit(sd->number_hi, sd->number_lo);
} else {
COFF_SymbolSecDef *sd = (COFF_SymbolSecDef *)((COFF_Symbol16 *)symbol.raw_symbol + 1);
if (selection_out) *selection_out = sd->selection;
if (length_out) *length_out = sd->length;
if (check_sum_out) *check_sum_out = sd->check_sum;
if (number_out) *number_out = sd->number_lo;
}
}
internal COFF_SymbolWeakExt *
coff_parse_weak_tag(COFF_ParsedSymbol symbol, B32 is_big_obj)
{
Assert(coff_interp_symbol(symbol.section_number, symbol.value, symbol.storage_class) == COFF_SymbolValueInterp_Weak);
Assert(symbol.aux_symbol_count > 0);
void *tag;
if (is_big_obj) {
tag = (COFF_SymbolWeakExt *)((COFF_Symbol32 *)symbol.raw_symbol + 1);
} else {
tag = (COFF_SymbolWeakExt *)((COFF_Symbol16 *)symbol.raw_symbol + 1);
}
return tag;
}
internal COFF_RelocNode *
coff_reloc_list_push(Arena *arena, COFF_RelocList *list, COFF_Reloc reloc)
{
COFF_RelocNode *node = push_array(arena, COFF_RelocNode, 1);
node->data = reloc;
SLLQueuePush(list->first, list->last, node);
++list->count;
return node;
}
internal COFF_RelocInfo
coff_reloc_info_from_section_header(String8 data, COFF_SectionHeader *header)
{
COFF_RelocInfo result = {0};
if (header->flags & COFF_SectionFlag_LnkNRelocOvfl && header->reloc_count == max_U16) {
COFF_Reloc counter;
U64 read_size = str8_deserial_read_struct(data, header->relocs_foff, &counter);
if (read_size == sizeof(counter) && counter.apply_off > 0) {
result.array_off = header->relocs_foff + sizeof(COFF_Reloc);
result.count = counter.apply_off - 1; // exclude counter entry
}
} else {
result.array_off = header->relocs_foff;
result.count = header->reloc_count;
}
return result;
}
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 COFF_ResourceID
coff_utf8_resource_id_from_utf16(Arena *arena, COFF_ResourceID16 *id_16)
{
COFF_ResourceID id = {0};
id.type = id_16->type;
switch (id_16->type) {
case COFF_ResourceIDType_Null: break;
case COFF_ResourceIDType_Number: {
id.u.number = id_16->u.number;
} break;
case COFF_ResourceIDType_String: {
id.u.string = str8_from_16(arena, id_16->u.string);
} break;
default: InvalidPath;
}
return id;
}
internal U64
coff_read_resource_id_utf16(String8 raw_res, U64 off, COFF_ResourceID16 *id_out)
{
U64 cursor = off;
U16 flag = 0;
str8_deserial_read_struct(raw_res, cursor, &flag);
if (flag == max_U16) {
id_out->type = COFF_ResourceIDType_Number;
cursor += sizeof(flag);
cursor += str8_deserial_read_struct(raw_res, cursor, &id_out->u.number);
} else {
id_out->type = COFF_ResourceIDType_String;
cursor += str8_deserial_read_windows_utf16_string16(raw_res, cursor, &id_out->u.string);
}
U64 read_size = cursor - off;
read_size = AlignPow2(read_size, COFF_ResourceAlign);
return read_size;
}
internal U64
coff_read_resource(Arena *arena, String8 raw_res, U64 off, COFF_ParsedResource *res_out)
{
String8 raw_header = str8_skip(raw_res, off);
U64 header_cursor = 0;
// 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_ResourceID16 type_16 = {0};
COFF_ResourceID16 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);
// compute read size
U64 read_size = Max(prefix.header_size, sizeof(prefix)) + AlignPow2(prefix.data_size, COFF_ResourceAlign);
return read_size;
}
internal COFF_ParsedResourceList
coff_resource_list_from_data(Arena *arena, String8 data)
{
COFF_ParsedResourceList list = {0};
U64 cursor;
for (cursor = 0 ; cursor < data.size; ) {
COFF_ParsedResourceNode *node = push_array(arena, COFF_ParsedResourceNode, 1);
cursor += coff_read_resource(arena, data, cursor, &node->data);
SLLQueuePush(list.first, list.last, node);
++list.count;
}
Assert(cursor == data.size);
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_ResourceAlign) - 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 int
coff_resource_id_compar(void *raw_a, void *raw_b)
{
int cmp;
COFF_ResourceID *a = raw_a;
COFF_ResourceID *b = raw_b;
if (a->type == b->type) {
switch (a->type) {
default:
case COFF_ResourceIDType_Null: cmp = 0; break;
case COFF_ResourceIDType_Number: cmp = MemoryCompare(&a->u.number, &b->u.number, sizeof(a->u.number)); break;
case COFF_ResourceIDType_String: cmp = strncmp((char *)a->u.string.str, (char *)b->u.string.str, Min(a->u.string.size, b->u.string.size)); break;
}
} else {
cmp = a->type < b->type ? -1 : a->type > b->type ? +1 : 0;
}
return cmp;
}
internal B32
coff_is_import(String8 raw_archive_member)
{
B32 is_import = 0;
if (raw_archive_member.size >= sizeof(U16)*2) {
U16 *sig1 = (U16*)raw_archive_member.str;
U16 *sig2 = sig1 + 1;
is_import = *sig1 == COFF_MachineType_Unknown && *sig2 == 0xffff;
}
return is_import;
}
internal COFF_DataType
coff_data_type_from_data(String8 raw_archive_member)
{
B32 is_big_obj = coff_is_big_obj(raw_archive_member);
if (is_big_obj) {
return COFF_DataType_BigObj;
}
B32 is_import = coff_is_import(raw_archive_member);
if (is_import) {
return COFF_DataType_Import;
}
return COFF_DataType_Obj;
}
internal B32
coff_is_regular_archive(String8 raw_archive)
{
B32 is_archive = 0;
U8 sig[sizeof(g_coff_archive_sig)];
if (str8_deserial_read_struct(raw_archive, 0, &sig) == sizeof(sig)) {
is_archive = MemoryCompare(&sig[0], &g_coff_archive_sig[0], sizeof(g_coff_archive_sig)) == 0;
}
return is_archive;
}
internal B32
coff_is_thin_archive(String8 raw_archive)
{
B32 is_archive = 0;
U8 sig[sizeof(g_coff_thin_archive_sig)];
if (str8_deserial_read_struct(raw_archive, 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;
}
internal COFF_ArchiveType
coff_archive_type_from_data(String8 raw_archive)
{
if (coff_is_regular_archive(raw_archive)) {
return COFF_Archive_Regular;
} else if (coff_is_thin_archive(raw_archive)) {
return COFF_Archive_Thin;
}
return COFF_Archive_Null;
}
internal U64
coff_parse_archive_member_header(String8 raw_archive, U64 offset, COFF_ParsedArchiveMemberHeader *header_out)
{
COFF_ArchiveMemberHeader *header = str8_deserial_get_raw_ptr(raw_archive, offset, sizeof(*header));
if (header) {
String8 name = str8_skip_chop_whitespace(str8_cstring_capped(header->name, header->name + sizeof(header->name) ));
String8 date = str8_skip_chop_whitespace(str8_cstring_capped(header->date, header->date + sizeof(header->date) ));
String8 user_id = str8_skip_chop_whitespace(str8_cstring_capped(header->user_id, header->user_id + sizeof(header->user_id) ));
String8 group_id = str8_skip_chop_whitespace(str8_cstring_capped(header->group_id, header->group_id + sizeof(header->group_id)));
String8 mode = str8_skip_chop_whitespace(str8_cstring_capped(header->mode, header->mode + sizeof(header->mode) ));
String8 size = str8_skip_chop_whitespace(str8_cstring_capped(header->size, header->size + sizeof(header->size) ));
String8 end = str8_cstring_capped(header->end, header->end + sizeof(header->end));
U32 data_size = u32_from_str8(size, 10);
U64 data_off = offset + sizeof(COFF_ArchiveMemberHeader);
header_out->name = name;
header_out->time_stamp = u32_from_str8(date, 10);
header_out->user_id = u32_from_str8(user_id, 10);
header_out->group_id = u32_from_str8(group_id, 10);
header_out->mode = mode;
header_out->is_end_correct = str8_match_lit("`\n", end, 0);
header_out->data_range = rng_1u64(data_off, data_off + data_size);
return sizeof(*header);
}
return 0;
}
internal COFF_ArchiveFirstMember
coff_parse_first_archive_member(COFF_ArchiveMember *member)
{
Assert(str8_match_lit("/", member->header.name, 0));
U64 cursor = 0;
U32 symbol_count = 0;
cursor += str8_deserial_read_struct(member->data, cursor, &symbol_count);
symbol_count = from_be_u32(symbol_count);
Rng1U64 member_offsets_range = rng_1u64(cursor, cursor + symbol_count * sizeof(U32));
cursor += dim_1u64(member_offsets_range);
Rng1U64 string_table_range = rng_1u64(cursor, member->data.size);
cursor += dim_1u64(string_table_range);
String8 raw_member_offsets = str8_substr(member->data, member_offsets_range);
U32 *member_offsets = (U32 *)raw_member_offsets.str;
U64 member_offset_count = raw_member_offsets.size / sizeof(member_offsets[0]);
COFF_ArchiveFirstMember result = {0};
result.symbol_count = symbol_count;
result.member_offset_count = member_offset_count;
result.member_offsets = member_offsets;
result.string_table = str8_substr(member->data, string_table_range);
return result;
}
internal COFF_ArchiveSecondMember
coff_parse_second_archive_member(COFF_ArchiveMember *member)
{
COFF_ArchiveSecondMember result = {0};
if (str8_match_lit("/", member->header.name, 0)) {
U64 cursor = 0;
U32 member_count = 0;
cursor += str8_deserial_read_struct(member->data, cursor, &member_count);
Rng1U64 member_offsets_range = rng_1u64(cursor, cursor + member_count * sizeof(U32));
cursor += dim_1u64(member_offsets_range);
U32 symbol_count = 0;
cursor += str8_deserial_read_struct(member->data, cursor, &symbol_count);
Rng1U64 symbol_indices_range = rng_1u64(cursor, cursor + symbol_count * sizeof(U16));
cursor += dim_1u64(symbol_indices_range);
Rng1U64 string_table_range = rng_1u64(cursor, member->data.size);
String8 raw_member_offsets = str8_substr(member->data, member_offsets_range);
String8 raw_indices = str8_substr(member->data, symbol_indices_range);
U32 *member_offsets = (U32 *)raw_member_offsets.str;
U64 member_offset_count = raw_member_offsets.size / sizeof(member_offsets[0]);
U16 *symbol_indices = (U16 *)raw_indices.str;
U64 symbol_index_count = raw_indices.size / sizeof(symbol_indices[0]);
result.member_count = member_count;
result.symbol_count = symbol_count;
result.member_offsets = member_offsets;
result.member_offset_count = member_offset_count;
result.symbol_indices = symbol_indices;
result.symbol_index_count = symbol_index_count;
result.string_table = str8_substr(member->data, string_table_range);
}
return result;
}
internal String8
coff_decode_raw_member_name(String8 long_names, String8 name)
{
String8 result = name;
if (name.size > 0 && name.str[0] == '/') {
String8 offset_str = str8(name.str + 1, name.size - 1);
U64 offset = u64_from_str8(offset_str, 10);
if (offset < long_names.size) {
U8 *ptr = long_names.str + offset;
U8 *opl = long_names.str + long_names.size;
for (; ptr < opl; ++ptr) {
if (*ptr == '\0' || *ptr == '\n') {
break;
}
}
result = str8_range(long_names.str + offset, ptr);
}
}
return result;
}
internal String8
coff_decode_member_name(String8 long_names, String8 name)
{
String8 member_name = coff_decode_raw_member_name(long_names, name);
String8 slash = str8_lit("/");
if (str8_ends_with(member_name, slash, 0)) {
member_name = str8_chop(member_name, slash.size);
}
return member_name;
}
internal U64
coff_parse_import(String8 raw_archive_member, U64 offset, COFF_ParsedArchiveImportHeader *header_out)
{
COFF_ImportHeader *header = str8_deserial_get_raw_ptr(raw_archive_member, offset, sizeof(*header));
if (header) {
Rng1U64 data_range = rng_1u64(offset + sizeof(*header), offset + sizeof(*header) + header->data_size);
String8 raw_data = str8_substr(raw_archive_member, data_range);
U64 data_cursor = 0;
header_out->version = header->version;
header_out->machine = header->machine;
header_out->time_stamp = header->time_stamp;
header_out->data_size = header->data_size;
header_out->hint_or_ordinal = header->hint_or_ordinal;
header_out->type = COFF_ImportHeader_ExtractType(header->flags);
header_out->import_by = COFF_ImportHeader_ExtractImportBy(header->flags);
data_cursor += str8_deserial_read_cstr(raw_data, data_cursor, &header_out->func_name);
data_cursor += str8_deserial_read_cstr(raw_data, data_cursor, &header_out->dll_name);
Assert(header_out->func_name.size + header_out->dll_name.size + /* nulls */ 2 == header_out->data_size);
U64 read_size = sizeof(*header) + header->data_size;
return read_size;
}
return 0;
}
internal COFF_ArchiveMember
coff_archive_member_from_offset(String8 raw_archive, U64 offset)
{
COFF_ArchiveMember member = {0};
coff_regular_archive_member_iter_next(raw_archive, &offset, &member);
return member;
}
internal COFF_ArchiveMember
coff_archive_member_from_data(String8 raw_archive_member)
{
return coff_archive_member_from_offset(raw_archive_member, 0);
}
internal COFF_ParsedArchiveImportHeader
coff_archive_import_from_data(String8 raw_archive_member)
{
COFF_ParsedArchiveImportHeader header = {0};
coff_parse_import(raw_archive_member, 0, &header);
return header;
}
internal U64
coff_regular_archive_member_iter_init(String8 raw_archive)
{
U64 cursor = raw_archive.size;
if (coff_is_regular_archive(raw_archive)) {
cursor = sizeof(g_coff_archive_sig);
}
return cursor;
}
internal B32
coff_regular_archive_member_iter_next(String8 raw_archive, U64 *offset, COFF_ArchiveMember *member_out)
{
B32 is_parsed = 0;
member_out->header.is_end_correct = 0;
U64 header_size = coff_parse_archive_member_header(raw_archive, *offset, &member_out->header);
if (member_out->header.is_end_correct) {
member_out->offset = *offset;
member_out->data = str8_substr(raw_archive, member_out->header.data_range);
U64 read_size = AlignPow2(header_size + dim_1u64(member_out->header.data_range), COFF_Archive_MemberAlign);
*offset += read_size;
is_parsed = 1;
}
return is_parsed;
}
internal U64
coff_thin_archive_member_iter_init(String8 raw_archive)
{
U64 cursor = raw_archive.size;
if (coff_is_thin_archive(raw_archive)) {
cursor = sizeof(g_coff_thin_archive_sig);
}
return cursor;
}
internal B32
coff_thin_archive_member_iter_next(String8 raw_archive, U64 *offset, COFF_ArchiveMember *member_out)
{
B32 is_parsed = 0;
member_out->header.is_end_correct = 0;
U64 header_size = coff_parse_archive_member_header(raw_archive, *offset, &member_out->header);
if (member_out->header.is_end_correct) {
Rng1U64 data_in_archive_range = {0};
if (str8_match_lit("/", member_out->header.name, 0) || str8_match_lit("//", member_out->header.name, 0)) {
data_in_archive_range = member_out->header.data_range;
}
member_out->offset = *offset;
member_out->data = str8_substr(raw_archive, data_in_archive_range);
U64 read_size = AlignPow2(header_size + dim_1u64(data_in_archive_range), COFF_Archive_MemberAlign);
*offset += read_size;
is_parsed = 1;
}
return is_parsed;
}
internal void
coff_archive_member_list_push_node(COFF_ArchiveMemberList *list, COFF_ArchiveMemberNode *node)
{
SLLQueuePush(list->first, list->last, node);
list->count += 1;
}
internal COFF_ArchiveParse
coff_archive_parse_from_member_list(COFF_ArchiveMemberList member_list)
{
String8 error = str8_zero();
B32 has_second_header = 0;
B32 has_long_names = 0;
COFF_ArchiveMember first_header = {0};
COFF_ArchiveMember second_header = {0};
COFF_ArchiveMember long_names_member = {0};
COFF_ArchiveMemberNode *ptr = member_list.first;
if (ptr) {
if (str8_match_lit("/", ptr->data.header.name, 0)) {
if (ptr->data.header.is_end_correct) {
first_header = ptr->data;
ptr = ptr->next;
} else {
error = str8_lit("first header doesn't have correct end");
}
}
} else {
error = str8_lit("missing first header");
}
if (!error.size && ptr) {
if (str8_match_lit("/", ptr->data.header.name, 0)) {
if (ptr->data.header.is_end_correct) {
second_header = ptr->data;
ptr = ptr->next;
has_second_header = 1;
} else {
error = str8_lit("second header doesn't have correct end");
}
}
}
if (!error.size && ptr) {
if (str8_match_lit("//", ptr->data.header.name, 0)) {
if (ptr->data.header.is_end_correct) {
long_names_member = ptr->data;
ptr = ptr->next;
has_long_names;
} else {
error = str8_lit("long names header doesn't have correct end");
}
}
}
COFF_ArchiveParse parse = {0};
parse.has_second_header = has_second_header;
parse.has_long_names = has_long_names;
parse.first_member = coff_parse_first_archive_member(&first_header);
parse.second_member = coff_parse_second_archive_member(&second_header);
parse.long_names = long_names_member.data;
parse.error = error;
return parse;
}
internal COFF_ArchiveParse
coff_regular_archive_parse_from_data(String8 raw_archive)
{
COFF_ArchiveMemberList list = {0};
COFF_ArchiveMemberNode node_arr[3] = {0};
U64 cursor = coff_regular_archive_member_iter_init(raw_archive);
for (U64 i = 0; i < ArrayCount(node_arr); ++i) {
COFF_ArchiveMemberNode *node = &node_arr[i];
if (!coff_regular_archive_member_iter_next(raw_archive, &cursor, &node->data)) {
break;
}
coff_archive_member_list_push_node(&list, node);
}
return coff_archive_parse_from_member_list(list);
}
internal COFF_ArchiveParse
coff_thin_archive_parse_from_data(String8 raw_archive)
{
COFF_ArchiveMemberList list = {0};
COFF_ArchiveMemberNode node_arr[3] = {0};
U64 cursor = coff_thin_archive_member_iter_init(raw_archive);
for (U64 i = 0; i < ArrayCount(node_arr); i += 1) {
COFF_ArchiveMemberNode *node = &node_arr[i];
if (!coff_thin_archive_member_iter_next(raw_archive, &cursor, &node->data)) {
break;
}
coff_archive_member_list_push_node(&list, node);
}
return coff_archive_parse_from_member_list(list);
}
internal COFF_ArchiveParse
coff_archive_parse_from_data(String8 raw_archive)
{
COFF_ArchiveType type = coff_archive_type_from_data(raw_archive);
switch (type) {
case COFF_Archive_Null: break;
case COFF_Archive_Regular: return coff_regular_archive_parse_from_data(raw_archive);
case COFF_Archive_Thin: return coff_thin_archive_parse_from_data(raw_archive);
}
COFF_ArchiveParse null_parse = {0};
return null_parse;
}
+329
View File
@@ -0,0 +1,329 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef COFF_PARSE_H
#define COFF_PARSE_H
typedef struct COFF_FileHeaderInfo
{
B32 is_big_obj;
COFF_MachineType machine;
U64 header_size;
U64 section_count_no_null;
U64 symbol_size;
U64 symbol_count;
Rng1U64 header_range;
Rng1U64 section_table_range;
Rng1U64 symbol_table_range;
Rng1U64 string_table_range;
} COFF_FileHeaderInfo;
////////////////////////////////
typedef struct COFF_SectionHeaderArray
{
U64 count;
COFF_SectionHeader *v;
} COFF_SectionHeaderArray;
////////////////////////////////
typedef struct COFF_Symbol16Node
{
struct COFF_Symbol16Node *next;
COFF_Symbol16 data;
} COFF_Symbol16Node;
typedef struct COFF_Symbol16List
{
U64 count;
COFF_Symbol16Node *first;
COFF_Symbol16Node *last;
} COFF_Symbol16List;
typedef struct COFF_Symbol32Array
{
U64 count;
COFF_Symbol32 *v;
} COFF_Symbol32Array;
typedef struct COFF_ParsedSymbol
{
String8 name;
U64 value;
U32 section_number;
COFF_SymbolType type;
COFF_SymStorageClass storage_class;
U8 aux_symbol_count;
void *raw_symbol;
} COFF_ParsedSymbol;
typedef U32 COFF_SymbolValueInterpType;
enum
{
COFF_SymbolValueInterp_Regular, // symbol has section and offset.
COFF_SymbolValueInterp_Weak, // symbol is overridable.
COFF_SymbolValueInterp_Undefined, // symbol doesn't have a reference section.
COFF_SymbolValueInterp_Common, // symbol has no section but still has size.
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.
};
////////////////////////////////
typedef struct COFF_RelocNode
{
struct COFF_RelocNode *next;
COFF_Reloc data;
} COFF_RelocNode;
typedef struct COFF_RelocList
{
U64 count;
COFF_RelocNode *first;
COFF_RelocNode *last;
} COFF_RelocList;
typedef struct COFF_RelocArray
{
U64 count;
COFF_Reloc *v;
} COFF_RelocArray;
typedef struct COFF_RelocInfo
{
U64 array_off;
U64 count;
} COFF_RelocInfo;
////////////////////////////////
typedef U32 COFF_ResourceIDType;
enum COFF_ResourceIDTypeEnum
{
COFF_ResourceIDType_Null,
COFF_ResourceIDType_Number,
COFF_ResourceIDType_String,
COFF_ResourceIDType_Count
};
typedef struct COFF_ResourceID16
{
COFF_ResourceIDType type;
union {
U16 number;
String16 string;
} u;
} COFF_ResourceID16;
typedef struct COFF_ResourceID
{
COFF_ResourceIDType type;
union {
U16 number;
String8 string;
} u;
} COFF_ResourceID;
typedef struct COFF_ParsedResource
{
COFF_ResourceID type;
COFF_ResourceID name;
U32 data_version;
COFF_ResourceMemoryFlags memory_flags;
U16 language_id;
U32 version;
U32 characteristics;
String8 data;
} COFF_ParsedResource;
typedef struct COFF_ParsedResourceNode
{
struct COFF_ParsedResourceNode *next;
COFF_ParsedResource data;
} COFF_ParsedResourceNode;
typedef struct COFF_ParsedResourceList
{
U64 count;
COFF_ParsedResourceNode *first;
COFF_ParsedResourceNode *last;
} COFF_ParsedResourceList;
////////////////////////////////
typedef enum
{
COFF_DataType_Null,
COFF_DataType_Obj,
COFF_DataType_BigObj,
COFF_DataType_Import
} COFF_DataType;
typedef enum
{
COFF_Archive_Null,
COFF_Archive_Regular,
COFF_Archive_Thin
} COFF_ArchiveType;
typedef struct COFF_ParsedArchiveMemberHeader
{
String8 name; // padded to 16 bytes with spaces
COFF_TimeStamp time_stamp;
U32 user_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
B32 is_end_correct; // set to true if found correct signature after header
Rng1U64 data_range;
} COFF_ParsedArchiveMemberHeader;
typedef struct COFF_ParsedArchiveImportHeader
{
B32 is_sig_correct;
U16 version;
COFF_MachineType machine;
COFF_TimeStamp time_stamp;
U32 data_size;
U16 hint_or_ordinal;
COFF_ImportType type;
COFF_ImportByType import_by;
String8 func_name;
String8 dll_name;
} COFF_ParsedArchiveImportHeader;
typedef struct COFF_ArchiveMember
{
COFF_ParsedArchiveMemberHeader header;
U64 offset;
String8 data;
} COFF_ArchiveMember;
typedef struct COFF_ArchiveFirstMember
{
U32 symbol_count;
U64 member_offset_count;
U32 *member_offsets;
String8 string_table;
} COFF_ArchiveFirstMember;
typedef struct COFF_ArchiveSecondMember
{
U32 member_count;
U32 symbol_count;
U64 member_offset_count;
U32 *member_offsets;
U64 symbol_index_count;
U16 *symbol_indices;
String8 string_table;
} COFF_ArchiveSecondMember;
typedef struct COFF_ArchiveMemberNode
{
struct COFF_ArchiveMemberNode *next;
COFF_ArchiveMember data;
} COFF_ArchiveMemberNode;
typedef struct COFF_ArchiveMemberList
{
U64 count;
COFF_ArchiveMemberNode *first;
COFF_ArchiveMemberNode *last;
} COFF_ArchiveMemberList;
typedef struct COFF_ArchiveParse
{
B32 has_second_header;
B32 has_long_names;
COFF_ArchiveFirstMember first_member;
COFF_ArchiveSecondMember second_member;
String8 long_names;
String8 error;
} COFF_ArchiveParse;
////////////////////////////////
// Obj Header
internal B32 coff_is_big_obj(String8 raw_coff);
internal B32 coff_is_obj (String8 raw_coff);
internal COFF_FileHeaderInfo coff_file_header_info_from_data(String8 raw_coff);
////////////////////////////////
// Section
internal COFF_SectionHeader ** coff_section_table_from_data(Arena *arena, String8 data, Rng1U64 section_table_range);
////////////////////////////////
// Symbol
internal COFF_ParsedSymbol coff_parse_symbol32(String8 string_table, COFF_Symbol32 *sym32);
internal COFF_ParsedSymbol coff_parse_symbol16(String8 string_table, COFF_Symbol16 *sym16);
internal COFF_ParsedSymbol coff_parse_symbol(COFF_FileHeaderInfo header, String8 string_table, String8 symbol_table, U32 symbol_idx);
internal COFF_Symbol32Array coff_symbol_array_from_data_16(Arena *arena, String8 data, U64 symbol_array_off, U64 symbol_count);
internal COFF_Symbol32Array coff_symbol_array_from_data_32(Arena *arena, String8 data, U64 symbol_array_off, U64 symbol_count);
internal COFF_Symbol32Array coff_symbol_array_from_data (Arena *arena, String8 data, U64 symbol_array_off, U64 symbol_count, U64 symbol_size);
internal COFF_Symbol16Node *coff_symbol16_list_push(Arena *arena, COFF_Symbol16List *list, COFF_Symbol16 symbol);
internal COFF_SymbolValueInterpType coff_interp_symbol(U32 section_number, U32 value, COFF_SymStorageClass storage_class);
internal COFF_SymbolValueInterpType coff_interp_from_parsed_symbol(COFF_ParsedSymbol symbol);
internal B32 coff_is_undefined_data_symbol(COFF_ParsedSymbol symbol);
internal void coff_parse_secdef(COFF_ParsedSymbol symbol, B32 is_big_obj, COFF_ComdatSelectType *selection_out, U32 *number_out, U32 *length_out, U32 *check_sum_out);
internal COFF_SymbolWeakExt * coff_parse_weak_tag(COFF_ParsedSymbol symbol, B32 is_big_obj);
////////////////////////////////
// Reloc
internal COFF_RelocInfo coff_reloc_info_from_section_header(String8 data, COFF_SectionHeader *header);
////////////////////////////////
// Resource
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 COFF_ResourceID coff_utf8_resource_id_from_utf16(Arena *arena, COFF_ResourceID16 *id_16);
internal U64 coff_read_resource_id_utf16 (String8 raw_res, U64 off, COFF_ResourceID16 *id_out);
internal U64 coff_read_resource (Arena *arena, String8 raw_res, U64 off, COFF_ParsedResource *res_out);
internal COFF_ParsedResourceList 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 int coff_resource_id_compar(void *raw_a, void *raw_b); // COFF_ResourceID
////////////////////////////////
// Archive
internal B32 coff_is_import (String8 raw_archive_member);
internal COFF_DataType coff_data_type_from_data (String8 raw_archive_member);
internal B32 coff_is_regular_archive (String8 raw_archive);
internal B32 coff_is_thin_archive (String8 raw_archive);
internal COFF_ArchiveType coff_archive_type_from_data(String8 raw_archive);
internal U64 coff_parse_archive_member_header(String8 raw_archive, U64 offset, COFF_ParsedArchiveMemberHeader *header_out);
internal COFF_ArchiveFirstMember coff_parse_first_archive_member (COFF_ArchiveMember *member);
internal COFF_ArchiveSecondMember coff_parse_second_archive_member(COFF_ArchiveMember *member);
internal String8 coff_decode_raw_member_name (String8 long_names, String8 name);
internal String8 coff_decode_member_name (String8 long_names, String8 name);
internal U64 coff_parse_import (String8 raw_archive_member, U64 offset, COFF_ParsedArchiveImportHeader *header_out);
internal COFF_ArchiveMember coff_archive_member_from_offset(String8 raw_archive, U64 offset);
internal COFF_ArchiveMember coff_archive_member_from_data (String8 raw_archive_member);
internal COFF_ParsedArchiveImportHeader coff_archive_import_from_data (String8 raw_archive_member);
internal U64 coff_regular_archive_member_iter_init(String8 raw_archive);
internal B32 coff_regular_archive_member_iter_next(String8 raw_archive, U64 *offset, COFF_ArchiveMember *member_out);
internal U64 coff_thin_archive_member_iter_init(String8 raw_archive);
internal B32 coff_thin_archive_member_iter_next(String8 raw_archive, U64 *offset, COFF_ArchiveMember *member_out);
internal COFF_ArchiveParse coff_regular_archive_parse_from_member_list(COFF_ArchiveMemberList list);
internal COFF_ArchiveParse coff_thin_archive_parse_from_data (String8 raw_archive);
internal COFF_ArchiveParse coff_regular_archive_parse_from_data (String8 raw_archive);
internal COFF_ArchiveParse coff_archive_parse_from_data (String8 raw_archive);
#endif // COFF_PARSE_H
+111
View File
@@ -0,0 +1,111 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal CFG_KeyMap *
cfg_key_map_from_cfg(Arena *arena)
{
Temp scratch = scratch_begin(&arena, 1);
CFG_KeyMap *key_map = push_array(arena, CFG_KeyMap, 1);
{
key_map->name_slots_count = 4096;
key_map->name_slots = push_array(arena, CFG_KeyMapSlot, key_map->name_slots_count);
key_map->binding_slots_count = 4096;
key_map->binding_slots = push_array(arena, CFG_KeyMapSlot, key_map->binding_slots_count);
//- rjf: gather & parse all explicitly stored keybinding sets
CFG_NodePtrList keybindings_cfg_list = cfg_node_top_level_list_from_string(scratch.arena, str8_lit("keybindings"));
for(CFG_NodePtrNode *n = keybindings_cfg_list.first; n != 0; n = n->next)
{
CFG_Node *keybindings_root = n->v;
for(CFG_Node *keybinding = keybindings_root->first; keybinding != &cfg_nil_node; keybinding = keybinding->next)
{
String8 name = {0};
CFG_Binding binding = {0};
for(CFG_Node *child = keybinding->first; child != &cfg_nil_node; child = child->next)
{
if(0){}
else if(str8_match(child->string, str8_lit("ctrl"), 0)) { binding.modifiers |= OS_Modifier_Ctrl; }
else if(str8_match(child->string, str8_lit("alt"), 0)) { binding.modifiers |= OS_Modifier_Alt; }
else if(str8_match(child->string, str8_lit("shift"), 0)) { binding.modifiers |= OS_Modifier_Shift; }
else
{
OS_Key key = OS_Key_Null;
for EachEnumVal(OS_Key, k)
{
if(str8_match(child->string, os_g_key_cfg_string_table[k], StringMatchFlag_CaseInsensitive))
{
key = k;
break;
}
}
if(key != OS_Key_Null)
{
binding.key = key;
}
else
{
name = child->string;
}
}
}
if(name.size != 0)
{
U64 name_hash = d_hash_from_string(name);
U64 binding_hash = d_hash_from_string(str8_struct(&binding));
U64 name_slot_idx = name_hash%key_map->name_slots_count;
U64 binding_slot_idx = binding_hash%key_map->binding_slots_count;
CFG_KeyMapNode *n = push_array(arena, CFG_KeyMapNode, 1);
n->cfg_id = keybinding->id;
n->name = push_str8_copy(arena, name);
n->binding = binding;
SLLQueuePush_N(key_map->name_slots[name_slot_idx].first, key_map->name_slots[name_slot_idx].last, n, name_hash_next);
SLLQueuePush_N(key_map->binding_slots[binding_slot_idx].first, key_map->binding_slots[binding_slot_idx].last, n, binding_hash_next);
}
}
}
}
scratch_end(scratch);
return key_map;
}
internal CFG_KeyMapNodePtrList
cfg_key_map_node_ptr_list_from_name(Arena *arena, CFG_KeyMap *key_map, String8 string)
{
CFG_KeyMapNodePtrList list = {0};
{
U64 hash = d_hash_from_string(string);
U64 slot_idx = hash%key_map->name_slots_count;
for(CFG_KeyMapNode *n = key_map->name_slots[slot_idx].first; n != 0; n = n->name_hash_next)
{
if(str8_match(n->name, string, 0))
{
CFG_KeyMapNodePtr *ptr = push_array(arena, CFG_KeyMapNodePtr, 1);
ptr->v = n;
SLLQueuePush(list.first, list.last, ptr);
list.count += 1;
}
}
}
return list;
}
internal CFG_KeyMapNodePtrList
cfg_key_map_node_ptr_list_from_binding(Arena *arena, CFG_KeyMap *key_map, CFG_Binding binding)
{
CFG_KeyMapNodePtrList list = {0};
{
U64 hash = d_hash_from_string(str8_struct(&binding));
U64 slot_idx = hash%key_map->binding_slots_count;
for(CFG_KeyMapNode *n = key_map->binding_slots[slot_idx].first; n != 0; n = n->binding_hash_next)
{
if(MemoryMatchStruct(&binding, &n->binding))
{
CFG_KeyMapNodePtr *ptr = push_array(arena, CFG_KeyMapNodePtr, 1);
ptr->v = n;
SLLQueuePush(list.first, list.last, ptr);
list.count += 1;
}
}
}
return list;
}
+59
View File
@@ -0,0 +1,59 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef CONFIG_BINDINGS_H
#define CONFIG_BINDINGS_H
typedef struct CFG_Binding CFG_Binding;
struct CFG_Binding
{
OS_Key key;
OS_Modifiers modifiers;
};
typedef struct CFG_KeyMapNode CFG_KeyMapNode;
struct CFG_KeyMapNode
{
CFG_KeyMapNode *name_hash_next;
CFG_KeyMapNode *binding_hash_next;
CFG_ID cfg_id;
String8 name;
CFG_Binding binding;
};
typedef struct CFG_KeyMapNodePtr CFG_KeyMapNodePtr;
struct CFG_KeyMapNodePtr
{
CFG_KeyMapNodePtr *next;
CFG_KeyMapNode *v;
};
typedef struct CFG_KeyMapNodePtrList CFG_KeyMapNodePtrList;
struct CFG_KeyMapNodePtrList
{
CFG_KeyMapNodePtr *first;
CFG_KeyMapNodePtr *last;
U64 count;
};
typedef struct CFG_KeyMapSlot CFG_KeyMapSlot;
struct CFG_KeyMapSlot
{
CFG_KeyMapNode *first;
CFG_KeyMapNode *last;
};
typedef struct CFG_KeyMap CFG_KeyMap;
struct CFG_KeyMap
{
U64 name_slots_count;
CFG_KeyMapSlot *name_slots;
U64 binding_slots_count;
CFG_KeyMapSlot *binding_slots;
};
internal CFG_KeyMap *cfg_key_map_from_cfg(Arena *arena);
internal CFG_KeyMapNodePtrList cfg_key_map_node_ptr_list_from_name(Arena *arena, CFG_KeyMap *key_map, String8 string);
internal CFG_KeyMapNodePtrList cfg_key_map_node_ptr_list_from_binding(Arena *arena, CFG_KeyMap *key_map, CFG_Binding binding);
#endif // CONFIG_BINDINGS_H
+896
View File
@@ -0,0 +1,896 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: ID Functions
internal void
cfg_id_list_push(Arena *arena, CFG_IDList *list, CFG_ID id)
{
CFG_IDNode *n = push_array(arena, CFG_IDNode, 1);
SLLQueuePush(list->first, list->last, n);
list->count += 1;
n->v = id;
}
internal CFG_IDList
cfg_id_list_copy(Arena *arena, CFG_IDList *src)
{
CFG_IDList dst = {0};
for EachNode(n, CFG_IDNode, src->first)
{
cfg_id_list_push(arena, &dst, n->v);
}
return dst;
}
////////////////////////////////
//~ rjf: Node Pointer Data Structure Functions
internal void
cfg_node_ptr_list_push(Arena *arena, CFG_NodePtrList *list, CFG_Node *node)
{
CFG_NodePtrNode *n = push_array(arena, CFG_NodePtrNode, 1);
DLLPushBack(list->first, list->last, n);
list->count += 1;
n->v = node;
}
internal void
cfg_node_ptr_list_push_front(Arena *arena, CFG_NodePtrList *list, CFG_Node *node)
{
CFG_NodePtrNode *n = push_array(arena, CFG_NodePtrNode, 1);
DLLPushFront(list->first, list->last, n);
list->count += 1;
n->v = node;
}
internal CFG_NodePtrArray
cfg_node_ptr_array_from_list(Arena *arena, CFG_NodePtrList *list)
{
CFG_NodePtrArray array = {0};
array.count = list->count;
array.v = push_array_no_zero(arena, CFG_Node *, array.count);
{
U64 idx = 0;
for EachNode(n, CFG_NodePtrNode, list->first)
{
array.v[idx] = n->v;
idx += 1;
}
}
return array;
}
////////////////////////////////
//~ rjf: Schema Data Structure Functions
internal void
cfg_schema_table_insert(Arena *arena, CFG_SchemaTable *table, String8 name, MD_Node *schema)
{
U64 hash = u64_hash_from_str8(name);
U64 slot_idx = hash%table->slots_count;
CFG_SchemaNode *node = 0;
for(CFG_SchemaNode *n = table->slots[slot_idx]; n != 0; n = n->next)
{
if(str8_match(n->name, name, 0))
{
node = n;
break;
}
}
if(node == 0)
{
node = push_array(arena, CFG_SchemaNode, 1);
node->name = str8_copy(arena, name);
node->schema = schema;
SLLStackPush(table->slots[slot_idx], node);
}
}
internal MD_Node *
cfg_schema_from_name(CFG_SchemaTable *table, String8 name)
{
MD_Node *result = &md_nil_node;
{
U64 hash = u64_hash_from_str8(name);
U64 slot_idx = hash%table->slots_count;
CFG_SchemaNode *node = 0;
for(CFG_SchemaNode *n = table->slots[slot_idx]; n != 0; n = n->next)
{
if(str8_match(n->name, name, 0))
{
result = n->schema;
break;
}
}
}
return result;
}
internal MD_NodePtrList
cfg_schemas_from_name(Arena *arena, CFG_SchemaTable *table, String8 name)
{
MD_NodePtrList result = {0};
{
Temp scratch = scratch_begin(&arena, 1);
String8List tasks = {0};
String8Node seed_task = {0, name};
str8_list_push_node(&tasks, &seed_task);
for EachNode(task, String8Node, tasks.first)
{
MD_Node *schema = cfg_schema_from_name(table, task->string);
if(!md_node_is_nil(schema))
{
md_node_ptr_list_push_front(arena, &result, schema);
for MD_EachNode(tag, schema->first_tag)
{
if(str8_match(tag->string, str8_lit("inherit"), 0))
{
str8_list_push(scratch.arena, &tasks, tag->first->string);
}
}
}
}
scratch_end(scratch);
}
return result;
}
////////////////////////////////
//~ rjf: Config Reading Functions
//- rjf: context selection
internal void
cfg_ctx_select(CFG_Ctx *ctx)
{
cfg_ctx = ctx;
}
//- rjf: tree navigations
internal U64
cfg_change_gen(void)
{
U64 result = 0;
if(cfg_ctx != 0)
{
result = cfg_ctx->change_gen;
}
return result;
}
internal CFG_Node *
cfg_node_root(void)
{
CFG_Node *result = &cfg_nil_node;
if(cfg_ctx != 0)
{
result = cfg_ctx->root;
}
return result;
}
internal CFG_Node *
cfg_node_from_id(CFG_ID id)
{
CFG_Node *result = &cfg_nil_node;
if(id != 0 &&
id == cfg_ctx->last_accessed_id &&
id == cfg_ctx->last_accessed->id)
{
result = cfg_ctx->last_accessed;
}
else
{
U64 hash = u64_hash_from_str8(str8_struct(&id));
U64 slot_idx = hash%cfg_ctx->id_slots_count;
for(CFG_NodePtrNode *n = cfg_ctx->id_slots[slot_idx].first; n != 0; n = n->next)
{
if(n->v->id == id)
{
result = n->v;
break;
}
}
}
cfg_ctx->last_accessed_id = id;
cfg_ctx->last_accessed = result;
return result;
}
internal CFG_Node *
cfg_node_child_from_string(CFG_Node *parent, String8 string)
{
CFG_Node *child = &cfg_nil_node;
if(string.size != 0)
{
for(CFG_Node *c = parent->first; c != &cfg_nil_node; c = c->next)
{
if(str8_match(c->string, string, 0))
{
child = c;
break;
}
}
}
return child;
}
internal CFG_Node *
cfg_node_child_from_string_or_parent(CFG_Node *parent, String8 string)
{
CFG_Node *result = cfg_node_child_from_string(parent, string);
if(result == &cfg_nil_node)
{
result = parent;
}
return result;
}
internal CFG_NodePtrList
cfg_node_child_list_from_string(Arena *arena, CFG_Node *parent, String8 string)
{
CFG_NodePtrList result = {0};
for(CFG_Node *child = parent->first; child != &cfg_nil_node; child = child->next)
{
if(str8_match(child->string, string, 0))
{
cfg_node_ptr_list_push(arena, &result, child);
}
}
return result;
}
internal CFG_NodePtrList
cfg_node_top_level_list_from_string(Arena *arena, String8 string)
{
CFG_NodePtrList result = {0};
for(CFG_Node *bucket = cfg_ctx->root->first; bucket != &cfg_nil_node; bucket = bucket->next)
{
for(CFG_Node *tln = bucket->first; tln != &cfg_nil_node; tln = tln->next)
{
if(str8_match(tln->string, string, 0))
{
cfg_node_ptr_list_push(arena, &result, tln);
}
}
}
return result;
}
internal CFG_NodeRec
cfg_node_rec__depth_first(CFG_Node *root, CFG_Node *node)
{
CFG_NodeRec rec = {&cfg_nil_node};
if(node->first != &cfg_nil_node)
{
rec.next = node->first;
rec.push_count = 1;
}
else for(CFG_Node *p = node; p != root; p = p->parent, rec.pop_count += 1)
{
if(p->next != &cfg_nil_node)
{
rec.next = p->next;
break;
}
}
return rec;
}
//- rjf: serialization
internal String8
cfg_string_from_tree(Arena *arena, CFG_SchemaTable *schema_table, String8 root_path, CFG_Node *root)
{
Temp scratch = scratch_begin(&arena, 1);
String8List strings = {0};
{
typedef struct NestTask NestTask;
struct NestTask
{
NestTask *next;
CFG_Node *cfg;
MD_Node *schema;
B32 is_simple;
};
NestTask *top_nest_task = 0;
CFG_NodeRec rec = {0};
for(CFG_Node *c = root; c != &cfg_nil_node; c = rec.next)
{
// rjf: look up parent's schemas
MD_NodePtrList schemas = {0};
if(top_nest_task != 0)
{
CFG_Node *parent = top_nest_task->cfg;
schemas = cfg_schemas_from_name(scratch.arena, schema_table, parent->string);
}
// rjf: look up child schema
MD_Node *c_schema = &md_nil_node;
for(MD_NodePtrNode *n = schemas.first; n != 0 && c_schema == &md_nil_node; n = n->next)
{
c_schema = md_child_from_string(n->v, c->string, 0);
}
// rjf: push name of this node
if(c->string.size != 0 || c->first == &cfg_nil_node)
{
// rjf: extract the textualized form for this string (we may need to escape / relativize)
String8 c_serialized_string = c->string;
{
MD_Node *c_schema = &md_nil_node;
if(top_nest_task != 0)
{
c_schema = top_nest_task->schema;
}
// rjf: paths -> relativize
if(!md_node_has_tag(c_schema->first, str8_lit("no_relativize"), 0))
{
if(str8_match(c_schema->first->string, str8_lit("path"), 0))
{
String8 path_absolute = c->string;
String8 path_relative = path_relative_dst_from_absolute_dst_src(arena, path_absolute, root_path);
c_serialized_string = path_relative;
}
else if(str8_match(c_schema->first->string, str8_lit("path_pt"), 0))
{
String8 value = c->string;
String8TxtPtPair parts = str8_txt_pt_pair_from_string(value);
String8 path_relative = path_relative_dst_from_absolute_dst_src(scratch.arena, parts.string, root_path);
c_serialized_string = push_str8f(arena, "%S:%I64d:%I64d", path_relative, parts.pt.line, parts.pt.column);
}
}
// rjf: all strings -> escape
c_serialized_string = escaped_from_raw_str8(arena, c_serialized_string);
}
// rjf: generate all strings for this node's string
String8List c_name_strings = {0};
{
B32 name_can_be_pushed_standalone = 0;
{
Temp temp = temp_begin(scratch.arena);
MD_TokenizeResult c_name_tokenize = md_tokenize_from_text(temp.arena, c_serialized_string);
name_can_be_pushed_standalone = (c_name_tokenize.tokens.count == 1 && c_name_tokenize.tokens.v[0].flags & (MD_TokenFlag_Identifier|
MD_TokenFlag_Numeric|
MD_TokenFlag_StringLiteral|
MD_TokenFlag_Symbol));
temp_end(temp);
}
if(name_can_be_pushed_standalone)
{
str8_list_push(scratch.arena, &c_name_strings, c_serialized_string);
}
else
{
str8_list_push(scratch.arena, &c_name_strings, str8_lit("\""));
str8_list_push(scratch.arena, &c_name_strings, c_serialized_string);
str8_list_push(scratch.arena, &c_name_strings, str8_lit("\""));
}
}
// rjf: if we're in a simple nesting task, then just break children by space
if(top_nest_task != 0 && top_nest_task->is_simple)
{
str8_list_push(scratch.arena, &strings, str8_lit(" "));
}
// rjf: join c's strings with main string list
str8_list_concat_in_place(&strings, &c_name_strings);
}
// rjf: grab next recursion
rec = cfg_node_rec__depth_first(root, c);
// rjf: push a new nesting task before descending to children
if(c->first != &cfg_nil_node)
{
B32 is_simple_children_list = 1;
for(CFG_Node *child = c->first; child != &cfg_nil_node; child = child->next)
{
if(child->first != &cfg_nil_node && child != c->last)
{
is_simple_children_list = 0;
break;
}
}
NestTask *task = push_array(scratch.arena, NestTask, 1);
task->cfg = c;
task->schema = c_schema;
task->is_simple = is_simple_children_list;
SLLStackPush(top_nest_task, task);
}
// rjf: tree navigations -> encode hierarchy
if(rec.push_count > 0)
{
if(top_nest_task->is_simple && c->string.size != 0)
{
str8_list_push(scratch.arena, &strings, str8_lit(":"));
}
else
{
if(c->string.size != 0)
{
str8_list_push(scratch.arena, &strings, str8_lit(":\n"));
}
str8_list_push(scratch.arena, &strings, str8_lit("{"));
}
}
else
{
for(S32 pop_idx = 0; pop_idx < rec.pop_count; pop_idx += 1, SLLStackPop(top_nest_task))
{
if(top_nest_task->is_simple)
{
if(top_nest_task->cfg->string.size == 0)
{
str8_list_push(scratch.arena, &strings, str8_lit(" }"));
}
}
else
{
str8_list_push(scratch.arena, &strings, str8_lit("\n}"));
}
}
}
if(!top_nest_task || top_nest_task->is_simple == 0)
{
str8_list_push(scratch.arena, &strings, str8_lit("\n"));
}
}
}
String8 result_unindented = str8_list_join(scratch.arena, &strings, 0);
String8 result = indented_from_string(arena, result_unindented);
scratch_end(scratch);
return result;
}
////////////////////////////////
//~ rjf: Config Writing Functions
//- rjf: state creation / destroying
internal CFG_State *
cfg_state_alloc(void)
{
Arena *arena = arena_alloc();
CFG_State *state = push_array(arena, CFG_State, 1);
state->arena = arena;
state->ctx.id_slots_count = 4096;
state->ctx.id_slots = push_array(arena, CFG_NodePtrSlot, state->ctx.id_slots_count);
state->ctx.root = cfg_node_alloc(state);
return state;
}
internal void
cfg_state_release(CFG_State *state)
{
arena_release(state->arena);
}
//- rjf: state -> ctx
internal CFG_Ctx *
cfg_state_ctx(CFG_State *state)
{
CFG_Ctx *ctx = &state->ctx;
return ctx;
}
//- rjf: string allocations
internal U64
cfg_string_bucket_num_from_size(U64 size)
{
U64 bucket_num = 0;
if(size > 0)
{
for EachElement(idx, cfg_string_bucket_chunk_sizes)
{
if(size <= cfg_string_bucket_chunk_sizes[idx])
{
bucket_num = idx+1;
break;
}
}
}
return bucket_num;
}
internal String8
cfg_string_alloc(CFG_State *state, String8 string)
{
//- rjf: allocate node
CFG_StringChunkNode *node = 0;
{
U64 bucket_num = cfg_string_bucket_num_from_size(string.size);
if(bucket_num == ArrayCount(cfg_string_bucket_chunk_sizes))
{
CFG_StringChunkNode *best_node = 0;
CFG_StringChunkNode *best_node_prev = 0;
U64 best_node_size = max_U64;
{
for(CFG_StringChunkNode *n = state->free_string_chunks[bucket_num-1], *prev = 0; n != 0; (prev = n, n = n->next))
{
if(n->size >= string.size && n->size < best_node_size)
{
best_node = n;
best_node_prev = prev;
best_node_size = n->size;
}
}
}
if(best_node != 0)
{
node = best_node;
if(best_node_prev)
{
best_node_prev->next = best_node->next;
}
else
{
state->free_string_chunks[bucket_num-1] = best_node->next;
}
}
else
{
U64 chunk_size = u64_up_to_pow2(string.size);
node = (CFG_StringChunkNode *)push_array(state->arena, U8, chunk_size);
}
}
else if(bucket_num != 0)
{
node = state->free_string_chunks[bucket_num-1];
if(node != 0)
{
SLLStackPop(state->free_string_chunks[bucket_num-1]);
}
else
{
node = (CFG_StringChunkNode *)push_array(state->arena, U8, cfg_string_bucket_chunk_sizes[bucket_num-1]);
}
}
}
//- rjf: fill node
String8 result = {0};
if(node != 0)
{
result.str = (U8 *)node;
result.size = string.size;
MemoryCopy(result.str, string.str, result.size);
}
return result;
}
internal void
cfg_string_release(CFG_State *state, String8 string)
{
U64 bucket_num = cfg_string_bucket_num_from_size(string.size);
if(1 <= bucket_num && bucket_num <= ArrayCount(cfg_string_bucket_chunk_sizes))
{
U64 bucket_idx = bucket_num-1;
CFG_StringChunkNode *node = (CFG_StringChunkNode *)string.str;
SLLStackPush(state->free_string_chunks[bucket_idx], node);
node->size = u64_up_to_pow2(string.size);
}
}
//- rjf: tree building
internal CFG_Node *
cfg_node_alloc(CFG_State *state)
{
state->ctx.change_gen += 1;
// rjf: allocate
CFG_Node *result = state->free;
{
if(result)
{
SLLStackPop(state->free);
}
else
{
result = push_array_no_zero(state->arena, CFG_Node, 1);
}
}
// rjf: generate ID & fill
state->id_gen += 1;
MemoryZeroStruct(result);
result->first = result->last = result->next = result->prev = result->parent = &cfg_nil_node;
result->id = state->id_gen;
// rjf: store to ID -> cfg map
{
CFG_NodePtrNode *cfg_id_node = state->free_id_node;
if(cfg_id_node != 0)
{
SLLStackPop(state->free_id_node);
}
else
{
cfg_id_node = push_array(state->arena, CFG_NodePtrNode, 1);
}
U64 hash = u64_hash_from_str8(str8_struct(&result->id));
U64 slot_idx = hash%state->ctx.id_slots_count;
DLLPushBack(state->ctx.id_slots[slot_idx].first, state->ctx.id_slots[slot_idx].last, cfg_id_node);
cfg_id_node->v = result;
}
return result;
}
internal void
cfg_node_release(CFG_State *state, CFG_Node *node)
{
state->ctx.change_gen += 1;
Temp scratch = scratch_begin(0, 0);
// rjf: unhook from context
cfg_node_unhook(state, node->parent, node);
// rjf: gather root & all descendants
CFG_NodePtrList nodes = {0};
for(CFG_Node *c = node; c != &cfg_nil_node; c = cfg_node_rec__depth_first(node, c).next)
{
cfg_node_ptr_list_push(scratch.arena, &nodes, c);
}
// rjf: release all nodes
for(CFG_NodePtrNode *n = nodes.first; n != 0; n = n->next)
{
CFG_Node *c = n->v;
cfg_string_release(state, c->string);
SLLStackPush(state->free, c);
c->first = c->last = c->prev = c->parent = 0;
c->id = 0;
c->string = str8_zero();
U64 hash = u64_hash_from_str8(str8_struct(&c->id));
U64 slot_idx = hash%state->ctx.id_slots_count;
for(CFG_NodePtrNode *n = state->ctx.id_slots[slot_idx].first; n != 0; n = n->next)
{
if(n->v == c)
{
DLLRemove(state->ctx.id_slots[slot_idx].first, state->ctx.id_slots[slot_idx].last, n);
SLLStackPush(state->free_id_node, n);
break;
}
}
}
scratch_end(scratch);
}
internal void
cfg_node_release_all_children(CFG_State *state, CFG_Node *node)
{
for(CFG_Node *child = node->first, *next = &cfg_nil_node; child != &cfg_nil_node; child = next)
{
next = child->next;
cfg_node_release(state, child);
}
}
internal CFG_Node *
cfg_node_new(CFG_State *state, CFG_Node *parent, String8 string)
{
CFG_Node *node = cfg_node_alloc(state);
cfg_node_insert_child(state, parent, parent->last, node);
cfg_node_equip_string(state, node, string);
return node;
}
internal CFG_Node *
cfg_node_newf(CFG_State *state, CFG_Node *parent, char *fmt, ...)
{
Temp scratch = scratch_begin(0, 0);
va_list args;
va_start(args, fmt);
String8 string = push_str8fv(scratch.arena, fmt, args);
CFG_Node *result = cfg_node_new(state, parent, string);
va_end(args);
scratch_end(scratch);
return result;
}
internal CFG_Node *
cfg_node_new_replace(CFG_State *state, CFG_Node *parent, String8 string)
{
Temp scratch = scratch_begin(0, 0);
string = push_str8_copy(scratch.arena, string);
for(CFG_Node *child = parent->first->next, *next = &cfg_nil_node; child != &cfg_nil_node; child = next)
{
next = child->next;
cfg_node_release(state, child);
}
if(parent->first == &cfg_nil_node)
{
cfg_node_new(state, parent, str8_zero());
}
CFG_Node *child = parent->first;
cfg_node_equip_string(state, child, string);
scratch_end(scratch);
return child;
}
internal CFG_Node *
cfg_node_new_replacef(CFG_State *state, CFG_Node *parent, char *fmt, ...)
{
Temp scratch = scratch_begin(0, 0);
va_list args;
va_start(args, fmt);
String8 string = push_str8fv(scratch.arena, fmt, args);
CFG_Node *result = cfg_node_new_replace(state, parent, string);
va_end(args);
scratch_end(scratch);
return result;
}
internal CFG_Node *
cfg_node_deep_copy(CFG_State *state, CFG_Node *src_root)
{
CFG_NodeRec rec = {0};
CFG_Node *dst_root = &cfg_nil_node;
CFG_Node *dst_parent = &cfg_nil_node;
for(CFG_Node *src = src_root; src != &cfg_nil_node; src = rec.next)
{
CFG_Node *dst = cfg_node_new(state, dst_parent, src->string);
if(dst_root == &cfg_nil_node)
{
dst_root = dst;
}
rec = cfg_node_rec__depth_first(src_root, src);
if(rec.push_count > 0)
{
dst_parent = dst;
}
else for(S32 pop_idx = 0; pop_idx < rec.pop_count; pop_idx += 1)
{
dst_parent = dst_parent->parent;
}
}
return dst_root;
}
internal void
cfg_node_equip_string(CFG_State *state, CFG_Node *node, String8 string)
{
cfg_string_release(state, node->string);
node->string = cfg_string_alloc(state, string);
state->ctx.change_gen += 1;
}
internal void
cfg_node_equip_stringf(CFG_State *state, CFG_Node *node, char *fmt, ...)
{
Temp scratch = scratch_begin(0, 0);
va_list args;
va_start(args, fmt);
String8 string = push_str8fv(scratch.arena, fmt, args);
cfg_node_equip_string(state, node, string);
va_end(args);
scratch_end(scratch);
}
internal void
cfg_node_insert_child(CFG_State *state, CFG_Node *parent, CFG_Node *prev_child, CFG_Node *new_child)
{
if(parent != &cfg_nil_node)
{
if(new_child->parent != &cfg_nil_node)
{
cfg_node_unhook(state, new_child->parent, new_child);
}
DLLInsert_NPZ(&cfg_nil_node, parent->first, parent->last, prev_child, new_child, next, prev);
new_child->parent = parent;
}
}
internal void
cfg_node_unhook(CFG_State *state, CFG_Node *parent, CFG_Node *child)
{
if(child != &cfg_nil_node && parent == child->parent && parent != &cfg_nil_node)
{
DLLRemove_NPZ(&cfg_nil_node, parent->first, parent->last, child, next, prev);
child->parent = &cfg_nil_node;
}
}
internal CFG_Node *
cfg_node_child_from_string_or_alloc(CFG_State *state, CFG_Node *parent, String8 string)
{
CFG_Node *node = cfg_node_child_from_string(parent, string);
if(node == &cfg_nil_node)
{
node = cfg_node_new(state, parent, string);
}
return node;
}
//- rjf: deserialization
internal CFG_NodePtrList
cfg_node_ptr_list_from_string(Arena *arena, CFG_State *state, CFG_SchemaTable *schema_table, String8 root_path, String8 string)
{
CFG_NodePtrList result = {0};
Temp scratch = scratch_begin(&arena, 1);
//- rjf: parse the string as metadesk
MD_Node *root = md_tree_from_string(scratch.arena, string);
//- rjf: iterate the top-level metadesk trees, generate new cfg trees for each
for MD_EachNode(tln, root->first)
{
CFG_Node *dst_root_n = &cfg_nil_node;
CFG_Node *dst_active_parent_n = &cfg_nil_node;
MD_NodeRec rec = {0};
for(MD_Node *src_n = tln; !md_node_is_nil(src_n); src_n = rec.next)
{
// rjf: lookup schema for this string
MD_Node *schema = &md_nil_node;
{
MD_NodePtrList schemas = cfg_schemas_from_name(scratch.arena, schema_table, dst_active_parent_n->parent->string);
for(MD_NodePtrNode *n = schemas.first; n != 0 && schema == &md_nil_node; n = n->next)
{
schema = md_child_from_string(n->v, dst_active_parent_n->string, 0);
}
}
// rjf: extract & transform metadesk node's string (it is raw textual data, so we need to
// go escaped -> raw, and derelativize paths)
String8 dst_n_string = {0};
{
String8 src_n_string = src_n->string;
String8 src_n_string__raw = raw_from_escaped_str8(scratch.arena, src_n_string);
if(!md_node_has_tag(schema->first, str8_lit("no_relativize"), 0))
{
if(str8_match(schema->first->string, str8_lit("path"), 0))
{
src_n_string__raw = path_absolute_dst_from_relative_dst_src(scratch.arena, src_n_string__raw, root_path);
}
else if(str8_match(schema->first->string, str8_lit("path_pt"), 0))
{
String8TxtPtPair parts = str8_txt_pt_pair_from_string(src_n_string__raw);
src_n_string__raw = push_str8f(scratch.arena, "%S:%I64d:%I64d", path_absolute_dst_from_relative_dst_src(scratch.arena, parts.string, root_path), parts.pt.line, parts.pt.column);
}
}
dst_n_string = src_n_string__raw;
}
// rjf: allocate, fill, & insert new cfg for this metadesk node
CFG_Node *dst_n = cfg_node_alloc(state);
cfg_node_equip_string(state, dst_n, dst_n_string);
if(dst_active_parent_n != &cfg_nil_node)
{
cfg_node_insert_child(state, dst_active_parent_n, dst_active_parent_n->last, dst_n);
}
// rjf: recurse
rec = md_node_rec_depth_first_pre(src_n, tln);
if(dst_active_parent_n == &cfg_nil_node)
{
dst_root_n = dst_n;
}
if(rec.push_count > 0)
{
dst_active_parent_n = dst_n;
}
else for(S32 pop_idx = 0; pop_idx < rec.pop_count; pop_idx += 1)
{
dst_active_parent_n = dst_active_parent_n->parent;
}
}
cfg_node_ptr_list_push(arena, &result, dst_root_n);
}
scratch_end(scratch);
return result;
}
+233
View File
@@ -0,0 +1,233 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef CONFIG_CORE_H
#define CONFIG_CORE_H
////////////////////////////////
//~ rjf: IDs
typedef U64 CFG_ID;
typedef struct CFG_IDNode CFG_IDNode;
struct CFG_IDNode
{
CFG_IDNode *next;
CFG_ID v;
};
typedef struct CFG_IDList CFG_IDList;
struct CFG_IDList
{
CFG_IDNode *first;
CFG_IDNode *last;
U64 count;
};
////////////////////////////////
//~ rjf: Tree Types
typedef struct CFG_Node CFG_Node;
struct CFG_Node
{
CFG_Node *first;
CFG_Node *last;
CFG_Node *next;
CFG_Node *prev;
CFG_Node *parent;
CFG_ID id;
String8 string;
};
typedef struct CFG_NodePtrNode CFG_NodePtrNode;
struct CFG_NodePtrNode
{
CFG_NodePtrNode *next;
CFG_NodePtrNode *prev;
CFG_Node *v;
};
typedef struct CFG_NodePtrSlot CFG_NodePtrSlot;
struct CFG_NodePtrSlot
{
CFG_NodePtrNode *first;
CFG_NodePtrNode *last;
};
typedef struct CFG_NodePtrList CFG_NodePtrList;
struct CFG_NodePtrList
{
CFG_NodePtrNode *first;
CFG_NodePtrNode *last;
U64 count;
};
typedef struct CFG_NodePtrArray CFG_NodePtrArray;
struct CFG_NodePtrArray
{
CFG_Node **v;
U64 count;
};
typedef struct CFG_NodeRec CFG_NodeRec;
struct CFG_NodeRec
{
CFG_Node *next;
S32 push_count;
S32 pop_count;
};
////////////////////////////////
//~ rjf: String Allocator
read_only global U64 cfg_string_bucket_chunk_sizes[] =
{
16,
64,
256,
1024,
4096,
16384,
65536,
0xffffffffffffffffull,
};
typedef struct CFG_StringChunkNode CFG_StringChunkNode;
struct CFG_StringChunkNode
{
CFG_StringChunkNode *next;
U64 size;
};
////////////////////////////////
//~ rjf: Config State Bundles
typedef struct CFG_Ctx CFG_Ctx;
struct CFG_Ctx
{
CFG_Node *root;
U64 id_slots_count;
CFG_NodePtrSlot *id_slots;
U64 change_gen;
CFG_ID last_accessed_id;
CFG_Node *last_accessed;
};
typedef struct CFG_State CFG_State;
struct CFG_State
{
Arena *arena;
CFG_Node *free;
CFG_NodePtrNode *free_id_node;
CFG_StringChunkNode *free_string_chunks[ArrayCount(cfg_string_bucket_chunk_sizes)];
U64 id_gen;
CFG_Ctx ctx;
};
////////////////////////////////
//~ rjf: Schema Table
typedef struct CFG_SchemaNode CFG_SchemaNode;
struct CFG_SchemaNode
{
CFG_SchemaNode *next;
String8 name;
MD_Node *schema;
};
typedef struct CFG_SchemaTable CFG_SchemaTable;
struct CFG_SchemaTable
{
CFG_SchemaNode **slots;
U64 slots_count;
};
////////////////////////////////
//~ rjf: Globals
read_only global CFG_Node cfg_nil_node =
{
&cfg_nil_node,
&cfg_nil_node,
&cfg_nil_node,
&cfg_nil_node,
&cfg_nil_node,
};
thread_static CFG_Ctx *cfg_ctx = 0;
////////////////////////////////
//~ rjf: ID Functions
internal void cfg_id_list_push(Arena *arena, CFG_IDList *list, CFG_ID id);
internal CFG_IDList cfg_id_list_copy(Arena *arena, CFG_IDList *src);
////////////////////////////////
//~ rjf: Node Pointer Data Structure Functions
internal void cfg_node_ptr_list_push(Arena *arena, CFG_NodePtrList *list, CFG_Node *node);
internal void cfg_node_ptr_list_push_front(Arena *arena, CFG_NodePtrList *list, CFG_Node *node);
#define cfg_node_ptr_list_first(list) ((list)->count ? (list)->first->v : &cfg_nil_node)
#define cfg_node_ptr_list_last(list) ((list)->count ? (list)->last->v : &cfg_nil_node)
internal CFG_NodePtrArray cfg_node_ptr_array_from_list(Arena *arena, CFG_NodePtrList *list);
////////////////////////////////
//~ rjf: Schema Data Structure Functions
internal void cfg_schema_table_insert(Arena *arena, CFG_SchemaTable *table, String8 name, MD_Node *schema);
internal MD_Node *cfg_schema_from_name(CFG_SchemaTable *table, String8 name);
internal MD_NodePtrList cfg_schemas_from_name(Arena *arena, CFG_SchemaTable *table, String8 name);
////////////////////////////////
//~ rjf: Config Reading Functions
//- rjf: context selection
internal void cfg_ctx_select(CFG_Ctx *ctx);
//- rjf: tree navigations
internal U64 cfg_change_gen(void);
internal CFG_Node *cfg_node_root(void);
internal CFG_Node *cfg_node_from_id(CFG_ID id);
internal CFG_Node *cfg_node_child_from_string(CFG_Node *parent, String8 string);
internal CFG_Node *cfg_node_child_from_string_or_parent(CFG_Node *parent, String8 string);
internal CFG_NodePtrList cfg_node_child_list_from_string(Arena *arena, CFG_Node *parent, String8 string);
internal CFG_NodePtrList cfg_node_top_level_list_from_string(Arena *arena, String8 string);
internal CFG_NodeRec cfg_node_rec__depth_first(CFG_Node *root, CFG_Node *node);
//- rjf: serialization
internal String8 cfg_string_from_tree(Arena *arena, CFG_SchemaTable *schema_table, String8 root_path, CFG_Node *root);
////////////////////////////////
//~ rjf: Config Writing Functions
//- rjf: state creation / destroying
internal CFG_State *cfg_state_alloc(void);
internal void cfg_state_release(CFG_State *state);
//- rjf: state -> ctx
internal CFG_Ctx *cfg_state_ctx(CFG_State *state);
//- rjf: string allocations
internal U64 cfg_string_bucket_num_from_size(U64 size);
internal String8 cfg_string_alloc(CFG_State *state, String8 string);
internal void cfg_string_release(CFG_State *state, String8 string);
//- rjf: tree building
internal CFG_Node *cfg_node_alloc(CFG_State *state);
internal void cfg_node_release(CFG_State *state, CFG_Node *node);
internal void cfg_node_release_all_children(CFG_State *state, CFG_Node *node);
internal CFG_Node *cfg_node_new(CFG_State *state, CFG_Node *parent, String8 string);
internal CFG_Node *cfg_node_newf(CFG_State *state, CFG_Node *parent, char *fmt, ...);
internal CFG_Node *cfg_node_new_replace(CFG_State *state, CFG_Node *parent, String8 string);
internal CFG_Node *cfg_node_new_replacef(CFG_State *state, CFG_Node *parent, char *fmt, ...);
internal CFG_Node *cfg_node_deep_copy(CFG_State *state, CFG_Node *src_root);
internal void cfg_node_equip_string(CFG_State *state, CFG_Node *node, String8 string);
internal void cfg_node_equip_stringf(CFG_State *state, CFG_Node *node, char *fmt, ...);
internal void cfg_node_insert_child(CFG_State *state, CFG_Node *parent, CFG_Node *prev_child, CFG_Node *new_child);
internal void cfg_node_unhook(CFG_State *state, CFG_Node *parent, CFG_Node *child);
internal CFG_Node *cfg_node_child_from_string_or_alloc(CFG_State *state, CFG_Node *parent, String8 string);
//- rjf: deserialization
internal CFG_NodePtrList cfg_node_ptr_list_from_string(Arena *arena, CFG_State *state, CFG_SchemaTable *schema_table, String8 root_path, String8 string);
#endif // CONFIG_CORE_H
+8
View File
@@ -0,0 +1,8 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#include "config_core.c"
#include "config_panels.c"
#if defined(OS_GFX_H)
# include "config_bindings.c"
#endif
+13
View File
@@ -0,0 +1,13 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef CONFIG_INC_H
#define CONFIG_INC_H
#include "config_core.h"
#include "config_panels.h"
#if defined(OS_GFX_H)
# include "config_bindings.h"
#endif
#endif // CONFIG_INC_H
+217
View File
@@ -0,0 +1,217 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal CFG_Node *
cfg_window_from_cfg(CFG_Node *cfg)
{
CFG_Node *result = &cfg_nil_node;
for(CFG_Node *c = cfg; c != &cfg_nil_node; c = c->parent)
{
if(c->parent->parent == cfg_node_root() && str8_match(c->string, str8_lit("window"), 0))
{
result = c;
break;
}
}
return result;
}
internal CFG_PanelTree
cfg_panel_tree_from_cfg(Arena *arena, CFG_Node *cfg_root)
{
Temp scratch = scratch_begin(&arena, 1);
CFG_Node *wcfg = cfg_window_from_cfg(cfg_root);
CFG_Node *src_root = cfg_node_child_from_string(wcfg, str8_lit("panels"));
CFG_PanelNode *dst_root = &cfg_nil_panel_node;
CFG_PanelNode *dst_focused = &cfg_nil_panel_node;
{
Axis2 active_split_axis = cfg_node_child_from_string(wcfg, str8_lit("split_x")) != &cfg_nil_node ? Axis2_X : Axis2_Y;
CFG_NodeRec rec = {0};
CFG_PanelNode *dst_active_parent = &cfg_nil_panel_node;
for(CFG_Node *src = src_root; src != &cfg_nil_node; src = rec.next)
{
// rjf: build a panel node
CFG_PanelNode *dst = push_array(arena, CFG_PanelNode, 1);
MemoryCopyStruct(dst, &cfg_nil_panel_node);
dst->parent = dst_active_parent;
if(dst_active_parent != &cfg_nil_panel_node)
{
DLLPushBack_NPZ(&cfg_nil_panel_node, dst_active_parent->first, dst_active_parent->last, dst, next, prev);
dst_active_parent->child_count += 1;
}
if(dst_root == &cfg_nil_panel_node)
{
dst_root = dst;
}
// rjf: extract cfg info
B32 panel_has_children = 0;
dst->cfg = src;
dst->pct_of_parent = (src == src_root ? 1.f : (F32)f64_from_str8(src->string));
dst->tab_side = (cfg_node_child_from_string(src, str8_lit("tabs_on_bottom")) != &cfg_nil_node ? Side_Max : Side_Min);
dst->split_axis = active_split_axis;
for(CFG_Node *src_child = src->first; src_child != &cfg_nil_node; src_child = src_child->next)
{
MD_TokenizeResult tokenize = md_tokenize_from_text(scratch.arena, src_child->string);
if(tokenize.tokens.count == 1 && tokenize.tokens.v[0].flags & MD_TokenFlag_Numeric)
{
panel_has_children = 1;
}
else if(str8_match(src_child->string, str8_lit("tabs_on_bottom"), 0))
{
// NOTE(rjf): skip - this is a panel option.
}
else if(str8_match(src_child->string, str8_lit("selected"), 0))
{
dst_focused = dst;
}
else if(tokenize.tokens.count == 1 && tokenize.tokens.v[0].flags & MD_TokenFlag_Identifier)
{
cfg_node_ptr_list_push(arena, &dst->tabs, src_child);
if(cfg_node_child_from_string(src_child, str8_lit("selected")) != &cfg_nil_node)
{
dst->selected_tab = src_child;
}
}
}
// rjf: recurse
rec = cfg_node_rec__depth_first(src_root, src);
if(!panel_has_children)
{
MemoryZeroStruct(&rec);
rec.next = &cfg_nil_node;
for(CFG_Node *p = src; p != src_root && p != &cfg_nil_node; p = p->parent, rec.pop_count += 1)
{
if(p->next != &cfg_nil_node)
{
rec.next = p->next;
break;
}
}
}
if(rec.push_count > 0)
{
dst_active_parent = dst;
active_split_axis = axis2_flip(active_split_axis);
}
else for(S32 pop_idx = 0; pop_idx < rec.pop_count; pop_idx += 1)
{
dst_active_parent = dst_active_parent->parent;
active_split_axis = axis2_flip(active_split_axis);
}
}
}
scratch_end(scratch);
CFG_PanelTree tree = {dst_root, dst_focused};
return tree;
}
internal CFG_PanelNodeRec
cfg_panel_node_rec__depth_first(CFG_PanelNode *root, CFG_PanelNode *panel, U64 sib_off, U64 child_off)
{
CFG_PanelNodeRec rec = {&cfg_nil_panel_node};
if(*MemberFromOffset(CFG_PanelNode **, panel, child_off) != &cfg_nil_panel_node)
{
rec.next = *MemberFromOffset(CFG_PanelNode **, panel, child_off);
rec.push_count += 1;
}
else for(CFG_PanelNode *p = panel; p != &cfg_nil_panel_node && p != root; p = p->parent, rec.pop_count += 1)
{
if(*MemberFromOffset(CFG_PanelNode **, p, sib_off) != &cfg_nil_panel_node)
{
rec.next = *MemberFromOffset(CFG_PanelNode **, p, sib_off);
break;
}
}
return rec;
}
internal CFG_PanelNode *
cfg_panel_node_from_tree_cfg(CFG_PanelNode *root, CFG_Node *cfg)
{
CFG_PanelNode *result = &cfg_nil_panel_node;
for(CFG_PanelNode *p = root;
p != &cfg_nil_panel_node;
p = cfg_panel_node_rec__depth_first_pre(root, p).next)
{
if(p->cfg == cfg)
{
result = p;
break;
}
}
return result;
}
internal Rng2F32
cfg_target_rect_from_panel_node_child(Rng2F32 parent_rect, CFG_PanelNode *parent, CFG_PanelNode *panel)
{
Rng2F32 rect = parent_rect;
if(parent != &cfg_nil_panel_node)
{
Vec2F32 parent_rect_size = dim_2f32(parent_rect);
Axis2 axis = parent->split_axis;
rect.p1.v[axis] = rect.p0.v[axis];
for(CFG_PanelNode *child = parent->first; child != &cfg_nil_panel_node; child = child->next)
{
rect.p1.v[axis] += parent_rect_size.v[axis] * child->pct_of_parent;
if(child == panel)
{
break;
}
rect.p0.v[axis] = rect.p1.v[axis];
}
//rect.p0.v[axis] += parent_rect_size.v[axis] * panel->off_pct_of_parent.v[axis];
//rect.p0.v[axis2_flip(axis)] += parent_rect_size.v[axis2_flip(axis)] * panel->off_pct_of_parent.v[axis2_flip(axis)];
}
rect.x0 = round_f32(rect.x0);
rect.x1 = round_f32(rect.x1);
rect.y0 = round_f32(rect.y0);
rect.y1 = round_f32(rect.y1);
return rect;
}
internal Rng2F32
cfg_target_rect_from_panel_node(Rng2F32 root_rect, CFG_PanelNode *root, CFG_PanelNode *panel)
{
Temp scratch = scratch_begin(0, 0);
// rjf: count ancestors
U64 ancestor_count = 0;
for(CFG_PanelNode *p = panel->parent; p != &cfg_nil_panel_node; p = p->parent)
{
ancestor_count += 1;
}
// rjf: gather ancestors
CFG_PanelNode **ancestors = push_array(scratch.arena, CFG_PanelNode *, ancestor_count);
{
U64 ancestor_idx = 0;
for(CFG_PanelNode *p = panel->parent; p != &cfg_nil_panel_node; p = p->parent)
{
ancestors[ancestor_idx] = p;
ancestor_idx += 1;
}
}
// rjf: go from highest ancestor => panel and calculate rect
Rng2F32 parent_rect = root_rect;
for(S64 ancestor_idx = (S64)ancestor_count-1;
0 <= ancestor_idx && ancestor_idx < ancestor_count;
ancestor_idx -= 1)
{
CFG_PanelNode *ancestor = ancestors[ancestor_idx];
CFG_PanelNode *parent = ancestor->parent;
if(parent != &cfg_nil_panel_node)
{
parent_rect = cfg_target_rect_from_panel_node_child(parent_rect, parent, ancestor);
}
}
// rjf: calculate final rect
Rng2F32 rect = cfg_target_rect_from_panel_node_child(parent_rect, panel->parent, panel);
scratch_end(scratch);
return rect;
}
+67
View File
@@ -0,0 +1,67 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef CONFIG_PANELS_H
#define CONFIG_PANELS_H
typedef struct CFG_PanelNode CFG_PanelNode;
struct CFG_PanelNode
{
// rjf: links data
CFG_PanelNode *first;
CFG_PanelNode *last;
CFG_PanelNode *next;
CFG_PanelNode *prev;
CFG_PanelNode *parent;
U64 child_count;
CFG_Node *cfg;
// rjf: split data
Axis2 split_axis;
F32 pct_of_parent;
// rjf: tab params
Side tab_side;
// rjf: which tabs are attached
CFG_NodePtrList tabs;
CFG_Node *selected_tab;
};
typedef struct CFG_PanelTree CFG_PanelTree;
struct CFG_PanelTree
{
CFG_PanelNode *root;
CFG_PanelNode *focused;
};
typedef struct CFG_PanelNodeRec CFG_PanelNodeRec;
struct CFG_PanelNodeRec
{
CFG_PanelNode *next;
S32 push_count;
S32 pop_count;
};
read_only global CFG_PanelNode cfg_nil_panel_node =
{
&cfg_nil_panel_node,
&cfg_nil_panel_node,
&cfg_nil_panel_node,
&cfg_nil_panel_node,
&cfg_nil_panel_node,
0,
&cfg_nil_node,
.selected_tab = &cfg_nil_node,
};
internal CFG_Node *cfg_window_from_cfg(CFG_Node *cfg);
internal CFG_PanelTree cfg_panel_tree_from_cfg(Arena *arena, CFG_Node *cfg_root);
internal CFG_PanelNodeRec cfg_panel_node_rec__depth_first(CFG_PanelNode *root, CFG_PanelNode *panel, U64 sib_off, U64 child_off);
#define cfg_panel_node_rec__depth_first_pre(root, p) cfg_panel_node_rec__depth_first((root), (p), OffsetOf(CFG_PanelNode, next), OffsetOf(CFG_PanelNode, first))
#define cfg_panel_node_rec__depth_first_pre_rev(root, p) cfg_panel_node_rec__depth_first((root), (p), OffsetOf(CFG_PanelNode, prev), OffsetOf(CFG_PanelNode, last))
internal CFG_PanelNode *cfg_panel_node_from_tree_cfg(CFG_PanelNode *root, CFG_Node *cfg);
internal Rng2F32 cfg_target_rect_from_panel_node_child(Rng2F32 parent_rect, CFG_PanelNode *parent, CFG_PanelNode *panel);
internal Rng2F32 cfg_target_rect_from_panel_node(Rng2F32 root_rect, CFG_PanelNode *root, CFG_PanelNode *panel);
#endif // CONFIG_PANELS_H
+522
View File
@@ -0,0 +1,522 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#undef LAYER_COLOR
#define LAYER_COLOR 0x684123ff
////////////////////////////////
//~ rjf: Basic Helpers
internal C_ID
c_id_make(U64 u64_0, U64 u64_1)
{
C_ID id;
id.u128[0].u64[0] = u64_0;
id.u128[0].u64[1] = u64_1;
return id;
}
internal B32
c_id_match(C_ID a, C_ID b)
{
B32 result = MemoryMatchStruct(&a, &b);
return result;
}
internal C_Key
c_key_make(C_Root root, C_ID id)
{
C_Key key = {root, 0, id};
return key;
}
internal B32
c_key_match(C_Key a, C_Key b)
{
return (MemoryMatchStruct(&a.root, &b.root) && c_id_match(a.id, b.id));
}
////////////////////////////////
//~ rjf: Main Layer Initialization
internal void
c_init(void)
{
Arena *arena = arena_alloc();
c_shared = push_array(arena, C_Shared, 1);
c_shared->arena = arena;
c_shared->blob_slots_count = 16384;
c_shared->blob_stripes_count = Min(c_shared->blob_slots_count, os_get_system_info()->logical_processor_count);
c_shared->blob_slots = push_array(arena, C_BlobSlot, c_shared->blob_slots_count);
c_shared->blob_stripes = push_array(arena, C_Stripe, c_shared->blob_stripes_count);
c_shared->blob_stripes_free_nodes = push_array(arena, C_BlobNode *, c_shared->blob_stripes_count);
for(U64 idx = 0; idx < c_shared->blob_stripes_count; idx += 1)
{
C_Stripe *stripe = &c_shared->blob_stripes[idx];
stripe->arena = arena_alloc();
stripe->rw_mutex = rw_mutex_alloc();
stripe->cv = cond_var_alloc();
}
c_shared->key_slots_count = 4096;
c_shared->key_stripes_count = Min(c_shared->key_slots_count, os_get_system_info()->logical_processor_count);
c_shared->key_slots = push_array(arena, C_KeySlot, c_shared->key_slots_count);
c_shared->key_stripes = push_array(arena, C_Stripe, c_shared->key_stripes_count);
c_shared->key_stripes_free_nodes = push_array(arena, C_KeyNode *, c_shared->key_stripes_count);
for(U64 idx = 0; idx < c_shared->key_stripes_count; idx += 1)
{
C_Stripe *stripe = &c_shared->key_stripes[idx];
stripe->arena = arena_alloc();
stripe->rw_mutex = rw_mutex_alloc();
stripe->cv = cond_var_alloc();
}
c_shared->root_slots_count = 4096;
c_shared->root_stripes_count = Min(c_shared->root_slots_count, os_get_system_info()->logical_processor_count);
c_shared->root_slots = push_array(arena, C_RootSlot, c_shared->root_slots_count);
c_shared->root_stripes = push_array(arena, C_Stripe, c_shared->root_stripes_count);
c_shared->root_stripes_free_nodes = push_array(arena, C_RootNode *, c_shared->root_stripes_count);
for(U64 idx = 0; idx < c_shared->root_stripes_count; idx += 1)
{
C_Stripe *stripe = &c_shared->root_stripes[idx];
stripe->arena = arena_alloc();
stripe->rw_mutex = rw_mutex_alloc();
stripe->cv = cond_var_alloc();
}
}
////////////////////////////////
//~ rjf: Root Allocation/Deallocation
internal C_Root
c_root_alloc(void)
{
C_Root root = {0};
root.u64[0] = ins_atomic_u64_inc_eval(&c_shared->root_id_gen);
U64 slot_idx = root.u64[0]%c_shared->root_slots_count;
U64 stripe_idx = slot_idx%c_shared->root_stripes_count;
C_RootSlot *slot = &c_shared->root_slots[slot_idx];
C_Stripe *stripe = &c_shared->root_stripes[stripe_idx];
MutexScopeW(stripe->rw_mutex)
{
C_RootNode *node = c_shared->root_stripes_free_nodes[stripe_idx];
if(node != 0)
{
SLLStackPop(c_shared->root_stripes_free_nodes[stripe_idx]);
}
else
{
node = push_array(stripe->arena, C_RootNode, 1);
}
DLLPushBack(slot->first, slot->last, node);
node->root = root;
node->arena = arena_alloc();
}
return root;
}
internal void
c_root_release(C_Root root)
{
//- rjf: unpack root
U64 slot_idx = root.u64[0]%c_shared->root_slots_count;
U64 stripe_idx = slot_idx%c_shared->root_stripes_count;
C_RootSlot *slot = &c_shared->root_slots[slot_idx];
C_Stripe *stripe = &c_shared->root_stripes[stripe_idx];
//- rjf: release root node, grab its arena / ID list
Arena *root_arena = 0;
C_RootIDChunkList root_ids = {0};
MutexScopeW(stripe->rw_mutex)
{
for(C_RootNode *n = slot->first; n != 0; n = n->next)
{
if(MemoryMatchStruct(&root, &n->root))
{
DLLRemove(slot->first, slot->last, n);
root_arena = n->arena;
root_ids = n->ids;
SLLStackPush(c_shared->root_stripes_free_nodes[stripe_idx], n);
break;
}
}
}
//- rjf: release all IDs
for(C_RootIDChunkNode *id_chunk_n = root_ids.first; id_chunk_n != 0; id_chunk_n = id_chunk_n->next)
{
for EachIndex(chunk_idx, id_chunk_n->count)
{
C_ID id = id_chunk_n->v[chunk_idx];
C_Key key = c_key_make(root, id);
c_close_key(key);
}
}
}
////////////////////////////////
//~ rjf: Cache Submission
internal U128
c_submit_data(C_Key key, Arena **data_arena, String8 data)
{
//- rjf: unpack key
U64 key_hash = u64_hash_from_str8(str8_struct(&key));
U64 key_slot_idx = key_hash%c_shared->key_slots_count;
U64 key_stripe_idx = key_slot_idx%c_shared->key_stripes_count;
C_KeySlot *key_slot = &c_shared->key_slots[key_slot_idx];
C_Stripe *key_stripe = &c_shared->key_stripes[key_stripe_idx];
//- rjf: hash data, unpack hash
U128 hash = u128_hash_from_str8(data);
U64 slot_idx = hash.u64[1]%c_shared->blob_slots_count;
U64 stripe_idx = slot_idx%c_shared->blob_stripes_count;
C_BlobSlot *slot = &c_shared->blob_slots[slot_idx];
C_Stripe *stripe = &c_shared->blob_stripes[stripe_idx];
//- rjf: commit to (hash -> data) cache
ProfScope("commit to (hash -> data) cache") RWMutexScope(stripe->rw_mutex, 1)
{
// rjf: find existing node
C_BlobNode *node = 0;
for(C_BlobNode *n = slot->first; n != 0; n = n->next)
{
if(u128_match(n->hash, hash))
{
node = n;
break;
}
}
// rjf: release duplicate data if node already exists
if(node != 0 && data_arena != 0 && *data_arena != 0)
{
arena_release(*data_arena);
}
// rjf: allocate node if needed
if(node == 0)
{
node = c_shared->blob_stripes_free_nodes[stripe_idx];
if(node)
{
SLLStackPop(c_shared->blob_stripes_free_nodes[stripe_idx]);
}
else
{
node = push_array_no_zero(stripe->arena, C_BlobNode, 1);
}
MemoryZeroStruct(node);
node->hash = hash;
if(data_arena != 0)
{
node->arena = *data_arena;
}
node->data = data;
DLLPushBack(slot->first, slot->last, node);
}
// rjf: bump key ref count
node->key_ref_count += 1;
// rjf "steal" arena from caller
if(data_arena != 0)
{
*data_arena = 0;
}
}
//- rjf: commit to (key -> list(hash)) cache
U128 key_expired_hash = {0};
ProfScope("commit to (key -> list(hash)) cache") RWMutexScope(key_stripe->rw_mutex, 1)
{
// rjf: find existing key
C_KeyNode *key_node = 0;
for(C_KeyNode *n = key_slot->first; n != 0; n = n->next)
{
if(c_key_match(n->key, key))
{
key_node = n;
break;
}
}
// rjf: create key node if it doesn't exist
B32 key_is_new = 0;
if(!key_node)
{
key_is_new = 1;
key_node = c_shared->key_stripes_free_nodes[key_stripe_idx];
if(key_node)
{
SLLStackPop(c_shared->key_stripes_free_nodes[key_stripe_idx]);
}
else
{
key_node = push_array_no_zero(key_stripe->arena, C_KeyNode, 1);
}
MemoryZeroStruct(key_node);
key_node->key = key;
DLLPushBack(key_slot->first, key_slot->last, key_node);
}
// rjf: push hash into key's history
if(key_node)
{
if(key_node->hash_history_gen >= C_KEY_HASH_HISTORY_STRONG_REF_COUNT)
{
key_expired_hash = key_node->hash_history[(key_node->hash_history_gen-C_KEY_HASH_HISTORY_STRONG_REF_COUNT)%ArrayCount(key_node->hash_history)];
}
key_node->hash_history[key_node->hash_history_gen%ArrayCount(key_node->hash_history)] = hash;
key_node->hash_history_gen += 1;
}
// rjf: key is new -> add this key to the associated root
if(key_is_new)
{
U64 root_hash = u64_hash_from_str8(str8_struct(&key.root));
U64 root_slot_idx = root_hash%c_shared->root_slots_count;
U64 root_stripe_idx = root_slot_idx%c_shared->root_stripes_count;
C_RootSlot *root_slot = &c_shared->root_slots[root_slot_idx];
C_Stripe *root_stripe = &c_shared->root_stripes[root_stripe_idx];
RWMutexScope(root_stripe->rw_mutex, 1)
{
for(C_RootNode *n = root_slot->first; n != 0; n = n->next)
{
if(MemoryMatchStruct(&n->root, &key.root))
{
C_RootIDChunkNode *chunk = n->ids.last;
if(chunk == 0 || chunk->count >= chunk->cap)
{
chunk = push_array(n->arena, C_RootIDChunkNode, 1);
SLLQueuePush(n->ids.first, n->ids.last, chunk);
n->ids.chunk_count += 1;
chunk->cap = 1024;
chunk->v = push_array_no_zero(n->arena, C_ID, chunk->cap);
}
chunk->v[chunk->count] = key.id;
chunk->count += 1;
n->ids.total_count += 1;
break;
}
}
}
}
}
//- rjf: decrement key ref count of expired hash
if(!u128_match(key_expired_hash, u128_zero())) ProfScope("decrement key ref count of expired hash")
{
U64 old_hash_slot_idx = key_expired_hash.u64[1]%c_shared->blob_slots_count;
U64 old_hash_stripe_idx = old_hash_slot_idx%c_shared->blob_stripes_count;
C_BlobSlot *old_hash_slot = &c_shared->blob_slots[old_hash_slot_idx];
C_Stripe *old_hash_stripe = &c_shared->blob_stripes[old_hash_stripe_idx];
RWMutexScope(old_hash_stripe->rw_mutex, 0)
{
for(C_BlobNode *n = old_hash_slot->first; n != 0; n = n->next)
{
if(u128_match(n->hash, key_expired_hash))
{
ins_atomic_u64_dec_eval(&n->key_ref_count);
break;
}
}
}
}
return hash;
}
////////////////////////////////
//~ rjf: Key Closing
internal void
c_close_key(C_Key key)
{
U64 key_hash = u64_hash_from_str8(str8_struct(&key));
U64 key_slot_idx = key_hash%c_shared->key_slots_count;
U64 key_stripe_idx = key_slot_idx%c_shared->key_stripes_count;
C_KeySlot *key_slot = &c_shared->key_slots[key_slot_idx];
C_Stripe *key_stripe = &c_shared->key_stripes[key_stripe_idx];
RWMutexScope(key_stripe->rw_mutex, 1)
{
for(C_KeyNode *n = key_slot->first; n != 0; n = n->next)
{
if(c_key_match(n->key, key))
{
for(U64 history_idx = 0;
history_idx < C_KEY_HASH_HISTORY_STRONG_REF_COUNT && history_idx < n->hash_history_gen;
history_idx += 1)
{
U128 hash = n->hash_history[(n->hash_history_gen-1-history_idx) % ArrayCount(n->hash_history)];
U64 hash_slot_idx = hash.u64[1]%c_shared->blob_slots_count;
U64 hash_stripe_idx = hash_slot_idx%c_shared->blob_stripes_count;
C_BlobSlot *hash_slot = &c_shared->blob_slots[hash_slot_idx];
C_Stripe *hash_stripe = &c_shared->blob_stripes[hash_stripe_idx];
MutexScopeR(hash_stripe->rw_mutex)
{
for(C_BlobNode *n = hash_slot->first; n != 0; n = n->next)
{
if(u128_match(n->hash, hash))
{
ins_atomic_u64_dec_eval(&n->key_ref_count);
break;
}
}
}
}
DLLRemove(key_slot->first, key_slot->last, n);
SLLStackPush(c_shared->key_stripes_free_nodes[key_stripe_idx], n);
break;
}
}
}
}
////////////////////////////////
//~ rjf: Downstream Accesses
internal void
c_hash_downstream_inc(U128 hash)
{
U64 slot_idx = hash.u64[1]%c_shared->blob_slots_count;
U64 stripe_idx = slot_idx%c_shared->blob_stripes_count;
C_BlobSlot *slot = &c_shared->blob_slots[slot_idx];
C_Stripe *stripe = &c_shared->blob_stripes[stripe_idx];
MutexScopeR(stripe->rw_mutex)
{
for(C_BlobNode *n = slot->first; n != 0; n = n->next)
{
if(u128_match(hash, n->hash))
{
ins_atomic_u64_inc_eval(&n->downstream_ref_count);
break;
}
}
}
}
internal void
c_hash_downstream_dec(U128 hash)
{
U64 slot_idx = hash.u64[1]%c_shared->blob_slots_count;
U64 stripe_idx = slot_idx%c_shared->blob_stripes_count;
C_BlobSlot *slot = &c_shared->blob_slots[slot_idx];
C_Stripe *stripe = &c_shared->blob_stripes[stripe_idx];
MutexScopeR(stripe->rw_mutex)
{
for(C_BlobNode *n = slot->first; n != 0; n = n->next)
{
if(u128_match(hash, n->hash))
{
ins_atomic_u64_dec_eval(&n->downstream_ref_count);
break;
}
}
}
}
////////////////////////////////
//~ rjf: Cache Lookup
internal U128
c_hash_from_key(C_Key key, U64 rewind_count)
{
U128 result = {0};
U64 key_hash = u64_hash_from_str8(str8_struct(&key));
U64 key_slot_idx = key_hash%c_shared->key_slots_count;
U64 key_stripe_idx = key_slot_idx%c_shared->key_stripes_count;
C_KeySlot *key_slot = &c_shared->key_slots[key_slot_idx];
C_Stripe *key_stripe = &c_shared->key_stripes[key_stripe_idx];
RWMutexScope(key_stripe->rw_mutex, 0)
{
for(C_KeyNode *n = key_slot->first; n != 0; n = n->next)
{
if(c_key_match(n->key, key) && n->hash_history_gen > 0 && n->hash_history_gen-1 >= rewind_count)
{
result = n->hash_history[(n->hash_history_gen-1-rewind_count)%ArrayCount(n->hash_history)];
break;
}
}
}
return result;
}
internal String8
c_data_from_hash(Access *access, U128 hash)
{
ProfBeginFunction();
String8 result = {0};
U64 slot_idx = hash.u64[1]%c_shared->blob_slots_count;
U64 stripe_idx = slot_idx%c_shared->blob_stripes_count;
C_BlobSlot *slot = &c_shared->blob_slots[slot_idx];
C_Stripe *stripe = &c_shared->blob_stripes[stripe_idx];
MutexScopeR(stripe->rw_mutex)
{
for(C_BlobNode *n = slot->first; n != 0; n = n->next)
{
if(u128_match(n->hash, hash))
{
result = n->data;
access_touch(access, &n->access_pt, stripe->cv);
break;
}
}
}
ProfEnd();
return result;
}
////////////////////////////////
//~ rjf: Asynchronous Tick
internal void
c_async_tick(void)
{
ProfBeginFunction();
//- rjf: garbage collect blobs
{
Rng1U64 range = lane_range(c_shared->blob_slots_count);
for EachInRange(slot_idx, range)
{
U64 stripe_idx = slot_idx%c_shared->blob_stripes_count;
C_BlobSlot *slot = &c_shared->blob_slots[slot_idx];
C_Stripe *stripe = &c_shared->blob_stripes[stripe_idx];
for(B32 write_mode = 0; write_mode <= 1; write_mode += 1)
{
B32 slot_has_work = 0;
RWMutexScope(stripe->rw_mutex, write_mode)
{
for(C_BlobNode *n = slot->first, *next = 0; n != 0; n = next)
{
next = n->next;
U64 key_ref_count = ins_atomic_u64_eval(&n->key_ref_count);
U64 downstream_ref_count = ins_atomic_u64_eval(&n->downstream_ref_count);
if(access_pt_is_expired(&n->access_pt, .time = 5000000) && key_ref_count == 0 && downstream_ref_count == 0)
{
slot_has_work = 1;
if(!write_mode)
{
break;
}
else
{
DLLRemove(slot->first, slot->last, n);
SLLStackPush(c_shared->blob_stripes_free_nodes[stripe_idx], n);
if(n->arena != 0)
{
arena_release(n->arena);
}
}
}
}
}
if(!slot_has_work)
{
break;
}
}
}
}
ProfEnd();
}
+243
View File
@@ -0,0 +1,243 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef CONTENT_H
#define CONTENT_H
////////////////////////////////
//~ NOTE(rjf): Hash Store Notes (2025/05/18)
//
// The hash store is a general-purpose data cache. It offers three layers of
// caching: (a) content (hash of data), (b) key (unique identity correllated
// with history of hashes), and (c) root (bucket for many keys, manually
// allocated / deallocated).
//
// (a) The "content" level of cache access is a simply hash(data) -> data
// mapping. This bypasses all identity/key/root mechanisms and provides a
// way to just talk about unique (and deduplicated) blobs of data.
//
// (b) The "key" level of cache access is used to encode a history of hashes
// for some unique "identity", where the "identity" is a concept managed
// by the user. One example of an identity would be a particular address
// range inside of some process to which the debugger is attached. Another
// might be a range inside of some file.
//
// (c) The "root" level is to provide a top-level allocation/deallocation
// mechanism for a large set of keys. It also provides an extra level of
// key uniqueness. For instance, each process to which the debugger is
// attached might have its own root, and each key might correspond to a
// particular address range within that process. This way, when the
// process ends, all of its keys can be easily destroyed using a single
// deallocation of the root.
//
// The way this might be generally used inside of the debugger would be that
// some evaluation - let's say it's some variable `x` - is mapped (via debug
// info) to some address range. If `x` is a `char[4096]`, then it might map
// to some address range [&x, &x + 4096). This, together with the process
// within which `x` is evaluated, forms both a `root` (for the process) and
// a `key` (for the address range). Some asynchronous memory streaming system
// can then, together with the root and key, read memory for that range, then
// submit that data to the hash store, correllating with the root and key
// combo.
////////////////////////////////
//~ rjf: Key Types
typedef struct C_Root C_Root;
struct C_Root
{
U64 u64[1];
};
typedef struct C_ID C_ID;
struct C_ID
{
U128 u128[1];
};
typedef struct C_Key C_Key;
struct C_Key
{
C_Root root;
U64 _padding_;
C_ID id;
};
////////////////////////////////
//~ rjf: Cache Stripe Type
typedef struct C_Stripe C_Stripe;
struct C_Stripe
{
Arena *arena;
RWMutex rw_mutex;
CondVar cv;
};
////////////////////////////////
//~ rjf: Root Cache Types
typedef struct C_RootIDChunkNode C_RootIDChunkNode;
struct C_RootIDChunkNode
{
C_RootIDChunkNode *next;
C_ID *v;
U64 count;
U64 cap;
};
typedef struct C_RootIDChunkList C_RootIDChunkList;
struct C_RootIDChunkList
{
C_RootIDChunkNode *first;
C_RootIDChunkNode *last;
U64 chunk_count;
U64 total_count;
};
typedef struct C_RootNode C_RootNode;
struct C_RootNode
{
C_RootNode *next;
C_RootNode *prev;
Arena *arena;
C_Root root;
C_RootIDChunkList ids;
};
typedef struct C_RootSlot C_RootSlot;
struct C_RootSlot
{
C_RootNode *first;
C_RootNode *last;
};
////////////////////////////////
//~ rjf: Key Cache Types
#define C_KEY_HASH_HISTORY_COUNT 64
#define C_KEY_HASH_HISTORY_STRONG_REF_COUNT 2
typedef struct C_KeyNode C_KeyNode;
struct C_KeyNode
{
C_KeyNode *next;
C_KeyNode *prev;
C_Key key;
U128 hash_history[C_KEY_HASH_HISTORY_COUNT];
U64 hash_history_gen;
};
typedef struct C_KeySlot C_KeySlot;
struct C_KeySlot
{
C_KeyNode *first;
C_KeyNode *last;
};
////////////////////////////////
//~ rjf: Content Blob Cache Types
typedef struct C_BlobNode C_BlobNode;
struct C_BlobNode
{
C_BlobNode *next;
C_BlobNode *prev;
U128 hash;
Arena *arena;
String8 data;
AccessPt access_pt;
U64 key_ref_count;
U64 downstream_ref_count;
};
typedef struct C_BlobSlot C_BlobSlot;
struct C_BlobSlot
{
C_BlobNode *first;
C_BlobNode *last;
};
////////////////////////////////
//~ rjf: Shared State
typedef struct C_Shared C_Shared;
struct C_Shared
{
Arena *arena;
// rjf: main data blob cache
U64 blob_slots_count;
U64 blob_stripes_count;
C_BlobSlot *blob_slots;
C_Stripe *blob_stripes;
C_BlobNode **blob_stripes_free_nodes;
// rjf: key cache
U64 key_slots_count;
U64 key_stripes_count;
C_KeySlot *key_slots;
C_Stripe *key_stripes;
C_KeyNode **key_stripes_free_nodes;
// rjf: root cache
U64 root_slots_count;
U64 root_stripes_count;
C_RootSlot *root_slots;
C_Stripe *root_stripes;
C_RootNode **root_stripes_free_nodes;
U64 root_id_gen;
};
////////////////////////////////
//~ rjf: Globals
global C_Shared *c_shared = 0;
////////////////////////////////
//~ rjf: Basic Helpers
internal C_ID c_id_make(U64 u64_0, U64 u64_1);
internal B32 c_id_match(C_ID a, C_ID b);
internal C_Key c_key_make(C_Root root, C_ID id);
internal B32 c_key_match(C_Key a, C_Key b);
////////////////////////////////
//~ rjf: Main Layer Initialization
internal void c_init(void);
////////////////////////////////
//~ rjf: Root Allocation/Deallocation
internal C_Root c_root_alloc(void);
internal void c_root_release(C_Root root);
////////////////////////////////
//~ rjf: Cache Submission
internal U128 c_submit_data(C_Key key, Arena **data_arena, String8 data);
////////////////////////////////
//~ rjf: Key Closing
internal void c_close_key(C_Key key);
////////////////////////////////
//~ rjf: Downstream Accesses
internal void c_hash_downstream_inc(U128 hash);
internal void c_hash_downstream_dec(U128 hash);
////////////////////////////////
//~ rjf: Cache Lookups
internal U128 c_hash_from_key(C_Key key, U64 rewind_count);
internal String8 c_data_from_hash(Access *access, U128 hash);
////////////////////////////////
//~ rjf: Asynchronous Tick
internal void c_async_tick(void);
#endif // CONTENT_H
+95 -9
View File
@@ -1,19 +1,23 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
//////////////////////////////// ////////////////////////////////
//~ rjf: Entity Kinds //~ rjf: Entity Kinds
@table(name display_string) @table(name code_name display_string)
CTRL_EntityKindTable: CTRL_EntityKindTable:
{ {
{Root "Root" } {Root root "Root" }
{Machine "Machine" } {Machine machine "Machine" }
{Process "Process" } {Process process "Process" }
{Thread "Thread" } {Thread thread "Thread" }
{Module "Module" } {Module module "Module" }
{EntryPoint "Entry Point" } {EntryPoint entry_point "Entry Point" }
{DebugInfoPath "Debug Info Path" } {DebugInfoPath debug_info_path "Debug Info Path" }
{PendingThreadName pending_thread_name "Pending Thread Name" }
{PendingThreadColor pending_thread_color "Pending Thread Color" }
{Breakpoint breakpoint "Breakpoint" }
{AddressRangeAnnotation address_range_annotation "Address Range Annotation" }
} }
@enum CTRL_EntityKind: @enum CTRL_EntityKind:
@@ -23,6 +27,12 @@ CTRL_EntityKindTable:
COUNT, COUNT,
} }
@data(String8) ctrl_entity_kind_code_name_table:
{
`{0}`,
@expand(CTRL_EntityKindTable a) `str8_lit_comp("$(a.code_name)")`
}
@data(String8) ctrl_entity_kind_display_string_table: @data(String8) ctrl_entity_kind_display_string_table:
{ {
`{0}`, `{0}`,
@@ -104,3 +114,79 @@ CTRL_ExceptionCodeKindTable:
`0`; `0`;
@expand(CTRL_ExceptionCodeKindTable a) `$(a.default)`; @expand(CTRL_ExceptionCodeKindTable a) `$(a.default)`;
} }
////////////////////////////////
//~ rjf: Exception Sub-Codes
@table(name, value)
CTRL_ExceptionSubCodeKindTable:
{
{ W32_FAST_FAIL_LEGACY_GS_VIOLATION 0 }
{ W32_FAST_FAIL_VTGUARD_CHECK_FAILURE 1 }
{ W32_FAST_FAIL_STACK_COOKIE_CHECK_FAILURE 2 }
{ W32_FAST_FAIL_CORRUPT_LIST_ENTRY 3 }
{ W32_FAST_FAIL_INCORRECT_STACK 4 }
{ W32_FAST_FAIL_INVALID_ARG 5 }
{ W32_FAST_FAIL_GS_COOKIE_INIT 6 }
{ W32_FAST_FAIL_FATAL_APP_EXIT 7 }
{ W32_FAST_FAIL_RANGE_CHECK_FAILURE 8 }
{ W32_FAST_FAIL_UNSAFE_REGISTRY_ACCESS 9 }
{ W32_FAST_FAIL_GUARD_ICALL_CHECK_FAILURE 10 }
{ W32_FAST_FAIL_GUARD_WRITE_CHECK_FAILURE 11 }
{ W32_FAST_FAIL_INVALID_FIBER_SWITCH 12 }
{ W32_FAST_FAIL_INVALID_SET_OF_CONTEXT 13 }
{ W32_FAST_FAIL_INVALID_REFERENCE_COUNT 14 }
{ W32_FAST_FAIL_INVALID_JUMP_BUFFER 18 }
{ W32_FAST_FAIL_MRDATA_MODIFIED 19 }
{ W32_FAST_FAIL_CERTIFICATION_FAILURE 20 }
{ W32_FAST_FAIL_INVALID_EXCEPTION_CHAIN 21 }
{ W32_FAST_FAIL_CRYPTO_LIBRARY 22 }
{ W32_FAST_FAIL_INVALID_CALL_IN_DLL_CALLOUT 23 }
{ W32_FAST_FAIL_INVALID_IMAGE_BASE 24 }
{ W32_FAST_FAIL_DLOAD_PROTECTION_FAILURE 25 }
{ W32_FAST_FAIL_UNSAFE_EXTENSION_CALL 26 }
{ W32_FAST_FAIL_DEPRECATED_SERVICE_INVOKED 27 }
{ W32_FAST_FAIL_INVALID_BUFFER_ACCESS 28 }
{ W32_FAST_FAIL_INVALID_BALANCED_TREE 29 }
{ W32_FAST_FAIL_INVALID_NEXT_THREAD 30 }
{ W32_FAST_FAIL_GUARD_ICALL_CHECK_SUPPRESSED 31 }
{ W32_FAST_FAIL_APCS_DISABLED 32 }
{ W32_FAST_FAIL_INVALID_IDLE_STATE 33 }
{ W32_FAST_FAIL_MRDATA_PROTECTION_FAILURE 34 }
{ W32_FAST_FAIL_UNEXPECTED_HEAP_EXCEPTION 35 }
{ W32_FAST_FAIL_INVALID_LOCK_STATE 36 }
{ W32_FAST_FAIL_GUARD_JUMPTABLE 37 }
{ W32_FAST_FAIL_INVALID_LONGJUMP_TARGET 38 }
{ W32_FAST_FAIL_INVALID_DISPATCH_CONTEXT 39 }
{ W32_FAST_FAIL_INVALID_THREAD 40 }
{ W32_FAST_FAIL_INVALID_SYSCALL_NUMBER 41 }
{ W32_FAST_FAIL_INVALID_FILE_OPERATION 42 }
{ W32_FAST_FAIL_LPAC_ACCESS_DENIED 43 }
{ W32_FAST_FAIL_GUARD_SS_FAILURE 44 }
{ W32_FAST_FAIL_LOADER_CONTINUITY_FAILURE 45 }
{ W32_FAST_FAIL_GUARD_EXPORT_SUPPRESSION_FAILURE 46 }
{ W32_FAST_FAIL_INVALID_CONTROL_STACK 47 }
{ W32_FAST_FAIL_SET_CONTEXT_DENIED 48 }
{ W32_FAST_FAIL_INVALID_IAT 49 }
{ W32_FAST_FAIL_HEAP_METADATA_CORRUPTION 50 }
{ W32_FAST_FAIL_PAYLOAD_RESTRICTION_VIOLATION 51 }
{ W32_FAST_FAIL_LOW_LABEL_ACCESS_DENIED 52 }
{ W32_FAST_FAIL_ENCLAVE_CALL_FAILURE 53 }
{ W32_FAST_FAIL_UNHANDLED_LSS_EXCEPTON 54 }
{ W32_FAST_FAIL_ADMINLESS_ACCESS_DENIED 55 }
{ W32_FAST_FAIL_UNEXPECTED_CALL 56 }
{ W32_FAST_FAIL_CONTROL_INVALID_RETURN_ADDRESS 57 }
{ W32_FAST_FAIL_UNEXPECTED_HOST_BEHAVIOR 58 }
{ W32_FAST_FAIL_FLAGS_CORRUPTION 59 }
{ W32_FAST_FAIL_VEH_CORRUPTION 60 }
{ W32_FAST_FAIL_ETW_CORRUPTION 61 }
{ W32_FAST_FAIL_RIO_ABORT 62 }
{ W32_FAST_FAIL_INVALID_PFN 63 }
{ W32_FAST_FAIL_GUARD_ICALL_CHECK_FAILURE_XFG 64 }
{ W32_FAST_FAIL_CAST_GUARD 65 }
{ W32_FAST_FAIL_HOST_VISIBILITY_CHANGE 66 }
{ W32_FAST_FAIL_KERNEL_CET_SHADOW_STACK_ASSIST 67 }
{ W32_FAST_FAIL_PATCH_CALLBACK_FAILED 68 }
{ W32_FAST_FAIL_NTDLL_PATCH_FAILED 69 }
{ W32_FAST_FAIL_INVALID_FLS_DATA 70 }
}
+2297 -1672
View File
File diff suppressed because it is too large. Load diff
+253 -414
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef CTRL_CORE_H #ifndef CTRL_CORE_H
@@ -13,227 +13,51 @@ typedef U64 CTRL_MachineID;
#define CTRL_MachineID_Local (1) #define CTRL_MachineID_Local (1)
//////////////////////////////// ////////////////////////////////
//~ rjf: Meta Evaluation Types //~ rjf: User Breakpoint Types
//- rjf: auto-checkbox b32s typedef U32 CTRL_UserBreakpointFlags;
enum
typedef struct CTRL_CheckB32 CTRL_CheckB32;
struct CTRL_CheckB32
{ {
B32 b32; CTRL_UserBreakpointFlag_BreakOnWrite = (1<<0),
CTRL_UserBreakpointFlag_BreakOnRead = (1<<1),
CTRL_UserBreakpointFlag_BreakOnExecute = (1<<2),
}; };
struct_members(CTRL_CheckB32) typedef enum CTRL_UserBreakpointKind
{ {
member_lit_comp(CTRL_CheckB32, type(B32), b32), CTRL_UserBreakpointKind_Null,
}; CTRL_UserBreakpointKind_FileNameAndLineColNumber,
struct_type(CTRL_CheckB32); CTRL_UserBreakpointKind_Expression,
CTRL_UserBreakpointKind_COUNT
}
CTRL_UserBreakpointKind;
//- rjf: styled string types typedef struct CTRL_UserBreakpoint CTRL_UserBreakpoint;
struct CTRL_UserBreakpoint
ptr_type(CTRL_PlainString8__str_ptr_type, type(U8), .flags = TypeFlag_IsPlainText,.count_delimiter_name = str8_lit_comp("size"));
ptr_type(CTRL_CodeString8__str_ptr_type, type(U8), .flags = TypeFlag_IsCodeText, .count_delimiter_name = str8_lit_comp("size"));
ptr_type(CTRL_PathString8__str_ptr_type, type(U8), .flags = TypeFlag_IsPathText, .count_delimiter_name = str8_lit_comp("size"));
Member CTRL_PlainString8__members[] =
{ {
member_lit_comp(String8, &CTRL_PlainString8__str_ptr_type, str, .pretty_name = str8_lit_comp("Contents")), CTRL_UserBreakpointKind kind;
member_lit_comp(String8, type(U64), size, .pretty_name = str8_lit_comp("Size")), CTRL_UserBreakpointFlags flags;
}; U64 id;
Member CTRL_CodeString8__members[] = String8 string;
{ TxtPt pt;
member_lit_comp(String8, &CTRL_CodeString8__str_ptr_type, str, .pretty_name = str8_lit_comp("Contents")), U64 size;
member_lit_comp(String8, type(U64), size, .pretty_name = str8_lit_comp("Size")), String8 condition;
};
Member CTRL_PathString8__members[] =
{
member_lit_comp(String8, &CTRL_PathString8__str_ptr_type, str, .pretty_name = str8_lit_comp("Contents")),
member_lit_comp(String8, type(U64), size, .pretty_name = str8_lit_comp("Size")),
};
named_struct_type(CTRL_PlainString8, String8, .name = str8_lit_comp("string"));
named_struct_type(CTRL_CodeString8, String8, .name = str8_lit_comp("string"));
named_struct_type(CTRL_PathString8, String8, .name = str8_lit_comp("string"));
//- rjf: meta evaluation callstack types
typedef struct CTRL_MetaEvalFrame CTRL_MetaEvalFrame;
struct CTRL_MetaEvalFrame
{
U64 vaddr;
U64 inline_depth;
};
ptr_type(CTRL_MetaEvalFrame__vaddr_type, type(void), .flags = TypeFlag_IsExternal, .size = sizeof(U64));
struct_members(CTRL_MetaEvalFrame)
{
member_lit_comp(CTRL_MetaEvalFrame, &CTRL_MetaEvalFrame__vaddr_type, vaddr),
member_lit_comp(CTRL_MetaEvalFrame, type(U64), inline_depth),
};
struct_type(CTRL_MetaEvalFrame, .name = str8_lit_comp("callstack_frame"));
typedef struct CTRL_MetaEvalFrameArray CTRL_MetaEvalFrameArray;
struct CTRL_MetaEvalFrameArray
{
U64 count;
CTRL_MetaEvalFrame *v;
};
ptr_type(CTRL_MetaEvalFrameArray__v_ptr_type, type(CTRL_MetaEvalFrame), .count_delimiter_name = str8_lit_comp("count"));
struct_members(CTRL_MetaEvalFrameArray)
{
member_lit_comp(CTRL_MetaEvalFrameArray, type(U64), count, .pretty_name = str8_lit_comp("Frame Count")),
{str8_lit_comp("v"), str8_lit_comp("Frame Addresses"), &CTRL_MetaEvalFrameArray__v_ptr_type, OffsetOf(CTRL_MetaEvalFrameArray, v)},
};
struct_type(CTRL_MetaEvalFrameArray, .name = str8_lit_comp("callstack_frames"));
//- rjf: meta evaluation instance types
typedef struct CTRL_MetaEval CTRL_MetaEval;
struct CTRL_MetaEval
{
#define CTRL_MetaEval_MemberXList \
X(B32, enabled, "Enabled")\
X(B32, frozen, "Frozen")\
X(U64, hit_count, "Hit Count")\
X(U64, id, "ID")\
X(Rng1U64, vaddr_range, "Address Range")\
X(U32, color, "Color")\
X(CTRL_CheckB32, debug_subprocesses,"Debug Subprocesses")\
Y(String8, type(CTRL_CodeString8), label, "Label")\
Y(String8, type(CTRL_PathString8), exe, "Executable Path")\
Y(String8, type(CTRL_PathString8), dbg, "Debug Info Path")\
Y(String8, type(CTRL_PlainString8), args, "Arguments")\
Y(String8, type(CTRL_PathString8), working_directory, "Working Directory")\
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_CodeString8), function_location, "Function Location")\
Y(String8, type(CTRL_CodeString8), address_location, "Address Location")\
Y(String8, type(CTRL_PathString8), source_path, "Source Path")\
Y(String8, type(CTRL_PathString8), destination_path, "Destination Path")\
Y(String8, type(CTRL_CodeString8), type, "Type")\
Y(String8, type(CTRL_CodeString8), view_rule, "View Rule")\
Y(String8, type(CTRL_CodeString8), condition, "Condition")\
X(CTRL_MetaEvalFrameArray, callstack, "Call Stack")
#define X(T, name, pretty_name) T name;
#define Y(T, ti, name, pretty_name) T name;
CTRL_MetaEval_MemberXList
#undef X
#undef Y
};
struct_members(CTRL_MetaEval)
{
#define X(T, name, pretty_name_) member_lit_comp(CTRL_MetaEval, type(T), name, .pretty_name = str8_lit_comp(pretty_name_)),
#define Y(T, ti, name, pretty_name_) member_lit_comp(CTRL_MetaEval, (ti), name, .pretty_name = str8_lit_comp(pretty_name_)),
CTRL_MetaEval_MemberXList
#undef X
#undef Y
};
struct_type(CTRL_MetaEval);
//- rjf: filters on main meta evaluation bundle
struct_members(CTRL_BreakpointMetaEval)
{
member_lit_comp(CTRL_MetaEval, type(B32), enabled, .pretty_name = str8_lit_comp("Enabled")),
member_lit_comp(CTRL_MetaEval, type(U32), color, .pretty_name = str8_lit_comp("Color")),
member_lit_comp(CTRL_MetaEval, type(U64), hit_count, .pretty_name = str8_lit_comp("Hit Count")),
member_lit_comp(CTRL_MetaEval, type(CTRL_CodeString8), label, .pretty_name = str8_lit_comp("Label")),
member_lit_comp(CTRL_MetaEval, type(CTRL_CodeString8), condition, .pretty_name = str8_lit_comp("Condition")),
member_lit_comp(CTRL_MetaEval, type(CTRL_PathString8), source_location, .pretty_name = str8_lit_comp("Source Location")),
member_lit_comp(CTRL_MetaEval, type(CTRL_CodeString8), function_location, .pretty_name = str8_lit_comp("Function Location")),
member_lit_comp(CTRL_MetaEval, type(CTRL_CodeString8), address_location, .pretty_name = str8_lit_comp("Address Location")),
}; };
struct_members(CTRL_TargetMetaEval) typedef struct CTRL_UserBreakpointNode CTRL_UserBreakpointNode;
struct CTRL_UserBreakpointNode
{ {
member_lit_comp(CTRL_MetaEval, type(CTRL_CodeString8), label, .pretty_name = str8_lit_comp("Label")), CTRL_UserBreakpointNode *next;
member_lit_comp(CTRL_MetaEval, type(CTRL_PathString8), exe, .pretty_name = str8_lit_comp("Executable")), CTRL_UserBreakpoint v;
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_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) typedef struct CTRL_UserBreakpointList CTRL_UserBreakpointList;
struct CTRL_UserBreakpointList
{ {
member_lit_comp(CTRL_MetaEval, type(CTRL_CodeString8), label, .pretty_name = str8_lit_comp("Expression")), CTRL_UserBreakpointNode *first;
member_lit_comp(CTRL_MetaEval, type(U32), color, .pretty_name = str8_lit_comp("Color")), CTRL_UserBreakpointNode *last;
member_lit_comp(CTRL_MetaEval, type(CTRL_PathString8), source_location, .pretty_name = str8_lit_comp("Source Location")),
member_lit_comp(CTRL_MetaEval, type(CTRL_CodeString8), address_location, .pretty_name = str8_lit_comp("Address Location")),
};
struct_members(CTRL_FilePathMapMetaEval)
{
member_lit_comp(CTRL_MetaEval, type(CTRL_PathString8), source_path, .pretty_name = str8_lit_comp("Source Path")),
member_lit_comp(CTRL_MetaEval, type(CTRL_PathString8), destination_path, .pretty_name = str8_lit_comp("Destination Path")),
};
struct_members(CTRL_AutoViewRuleMetaEval)
{
member_lit_comp(CTRL_MetaEval, type(CTRL_CodeString8), type, .pretty_name = str8_lit_comp("Type")),
member_lit_comp(CTRL_MetaEval, type(CTRL_CodeString8), view_rule, .pretty_name = str8_lit_comp("View Rule")),
};
struct_members(CTRL_MachineMetaEval)
{
member_lit_comp(CTRL_MetaEval, type(B32), frozen, .pretty_name = str8_lit_comp("Frozen")),
member_lit_comp(CTRL_MetaEval, type(U32), color, .pretty_name = str8_lit_comp("Color")),
member_lit_comp(CTRL_MetaEval, type(CTRL_CodeString8), label, .pretty_name = str8_lit_comp("Name")),
};
struct_members(CTRL_ProcessMetaEval)
{
member_lit_comp(CTRL_MetaEval, type(B32), frozen, .pretty_name = str8_lit_comp("Frozen")),
member_lit_comp(CTRL_MetaEval, type(U32), color, .pretty_name = str8_lit_comp("Color")),
member_lit_comp(CTRL_MetaEval, type(CTRL_CodeString8), label, .pretty_name = str8_lit_comp("Name")),
member_lit_comp(CTRL_MetaEval, type(U64), id, .pretty_name = str8_lit_comp("ID")),
};
struct_members(CTRL_ModuleMetaEval)
{
member_lit_comp(CTRL_MetaEval, type(U32), color, .pretty_name = str8_lit_comp("Color")),
member_lit_comp(CTRL_MetaEval, type(CTRL_CodeString8), label, .pretty_name = str8_lit_comp("Name")),
member_lit_comp(CTRL_MetaEval, type(CTRL_PathString8), exe, .pretty_name = str8_lit_comp("Executable Path")),
member_lit_comp(CTRL_MetaEval, type(CTRL_PathString8), dbg, .pretty_name = str8_lit_comp("Debug Info Path")),
member_lit_comp(CTRL_MetaEval, type(Rng1U64), vaddr_range, .pretty_name = str8_lit_comp("Address Range")),
};
struct_members(CTRL_ThreadMetaEval)
{
member_lit_comp(CTRL_MetaEval, type(B32), frozen, .pretty_name = str8_lit_comp("Frozen")),
member_lit_comp(CTRL_MetaEval, type(U32), color, .pretty_name = str8_lit_comp("Color")),
member_lit_comp(CTRL_MetaEval, type(CTRL_CodeString8), label, .pretty_name = str8_lit_comp("Name")),
member_lit_comp(CTRL_MetaEval, type(U64), id, .pretty_name = str8_lit_comp("ID")),
member_lit_comp(CTRL_MetaEval, type(CTRL_MetaEvalFrameArray), callstack, .pretty_name = str8_lit_comp("Call Stack")),
};
named_struct_type(CTRL_BreakpointMetaEval, CTRL_MetaEval, .name = str8_lit_comp("breakpoint"));
named_struct_type(CTRL_TargetMetaEval, CTRL_MetaEval, .name = str8_lit_comp("target"));
named_struct_type(CTRL_PinMetaEval, CTRL_MetaEval, .name = str8_lit_comp("pin"));
named_struct_type(CTRL_FilePathMapMetaEval, CTRL_MetaEval, .name = str8_lit_comp("file_path_map"));
named_struct_type(CTRL_AutoViewRuleMetaEval,CTRL_MetaEval, .name = str8_lit_comp("auto_view_rule"));
named_struct_type(CTRL_MachineMetaEval, CTRL_MetaEval, .name = str8_lit_comp("machine"));
named_struct_type(CTRL_ProcessMetaEval, CTRL_MetaEval, .name = str8_lit_comp("process"));
named_struct_type(CTRL_ModuleMetaEval, CTRL_MetaEval, .name = str8_lit_comp("module"));
named_struct_type(CTRL_ThreadMetaEval, CTRL_MetaEval, .name = str8_lit_comp("thread"));
//- rjf: meta evaluation array
typedef struct CTRL_MetaEvalArray CTRL_MetaEvalArray;
struct CTRL_MetaEvalArray
{
CTRL_MetaEval *v;
U64 count; U64 count;
}; };
ptr_type(CTRL_MetaEvalArray__v_ptr_type, type(CTRL_BreakpointMetaEval), .count_delimiter_name = str8_lit_comp("count"));
struct_members(CTRL_MetaEvalArray)
{
{str8_lit_comp("v"), {0}, &CTRL_MetaEvalArray__v_ptr_type, OffsetOf(CTRL_MetaEvalArray, v)},
member_lit_comp(CTRL_MetaEvalArray, type(U64), count),
};
struct_type(CTRL_MetaEvalArray);
//////////////////////////////// ////////////////////////////////
//~ rjf: Entity Handle Types //~ rjf: Entity Handle Types
@@ -260,6 +84,13 @@ struct CTRL_HandleList
U64 count; U64 count;
}; };
typedef struct CTRL_HandleArray CTRL_HandleArray;
struct CTRL_HandleArray
{
CTRL_Handle *v;
U64 count;
};
//////////////////////////////// ////////////////////////////////
//~ rjf: Generated Code //~ rjf: Generated Code
@@ -279,12 +110,14 @@ struct CTRL_Entity
CTRL_EntityKind kind; CTRL_EntityKind kind;
Arch arch; Arch arch;
B32 is_frozen; B32 is_frozen;
B32 is_soloed;
U32 rgba; U32 rgba;
CTRL_Handle handle; CTRL_Handle handle;
U64 id; U64 id;
Rng1U64 vaddr_range; Rng1U64 vaddr_range;
U64 stack_base; U64 stack_base;
U64 timestamp; U64 timestamp;
CTRL_UserBreakpointFlags bp_flags;
String8 string; String8 string;
}; };
@@ -340,21 +173,45 @@ struct CTRL_EntityStringChunkNode
U64 size; U64 size;
}; };
typedef struct CTRL_EntityStore CTRL_EntityStore; read_only global U64 ctrl_entity_string_bucket_chunk_sizes[] =
struct CTRL_EntityStore {
16,
64,
256,
1024,
4096,
16384,
65536,
0xffffffffffffffffull,
};
typedef struct CTRL_EntityCtx CTRL_EntityCtx;
struct CTRL_EntityCtx
{
CTRL_Entity *root;
U64 hash_slots_count;
CTRL_EntityHashSlot *hash_slots;
U64 entity_kind_counts[CTRL_EntityKind_COUNT];
U64 entity_kind_alloc_gens[CTRL_EntityKind_COUNT];
};
typedef struct CTRL_EntityCtxRWStore CTRL_EntityCtxRWStore;
struct CTRL_EntityCtxRWStore
{ {
Arena *arena; Arena *arena;
CTRL_Entity *root; CTRL_EntityCtx ctx;
CTRL_Entity *free; CTRL_Entity *free;
CTRL_EntityHashSlot *hash_slots;
CTRL_EntityHashNode *hash_node_free; CTRL_EntityHashNode *hash_node_free;
U64 hash_slots_count; CTRL_EntityStringChunkNode *free_string_chunks[ArrayCount(ctrl_entity_string_bucket_chunk_sizes)];
CTRL_EntityStringChunkNode *free_string_chunks[8]; };
U64 entity_kind_counts[CTRL_EntityKind_COUNT];
Arena *entity_kind_lists_arenas[CTRL_EntityKind_COUNT]; typedef struct CTRL_EntityCtxLookupAccel CTRL_EntityCtxLookupAccel;
U64 entity_kind_lists_gens[CTRL_EntityKind_COUNT]; struct CTRL_EntityCtxLookupAccel
U64 entity_kind_alloc_gens[CTRL_EntityKind_COUNT]; {
CTRL_EntityList entity_kind_lists[CTRL_EntityKind_COUNT]; Arena *arena;
Arena *entity_kind_arrays_arenas[CTRL_EntityKind_COUNT];
CTRL_EntityArray entity_kind_arrays[CTRL_EntityKind_COUNT];
U64 entity_kind_arrays_gens[CTRL_EntityKind_COUNT];
}; };
//////////////////////////////// ////////////////////////////////
@@ -404,32 +261,49 @@ struct CTRL_Unwind
//////////////////////////////// ////////////////////////////////
//~ rjf: Call Stack Types //~ rjf: Call Stack Types
typedef struct CTRL_CallStackInlineFrame CTRL_CallStackInlineFrame;
struct CTRL_CallStackInlineFrame
{
CTRL_CallStackInlineFrame *next;
CTRL_CallStackInlineFrame *prev;
RDI_InlineSite *inline_site;
};
typedef struct CTRL_CallStackFrame CTRL_CallStackFrame; typedef struct CTRL_CallStackFrame CTRL_CallStackFrame;
struct CTRL_CallStackFrame struct CTRL_CallStackFrame
{ {
CTRL_CallStackInlineFrame *first_inline_frame; U64 unwind_count;
CTRL_CallStackInlineFrame *last_inline_frame; U64 inline_depth;
U64 inline_frame_count;
void *regs; void *regs;
RDI_Parsed *rdi;
RDI_Procedure *procedure;
}; };
typedef struct CTRL_CallStack CTRL_CallStack; typedef struct CTRL_CallStack CTRL_CallStack;
struct CTRL_CallStack struct CTRL_CallStack
{ {
CTRL_CallStackFrame *frames; CTRL_CallStackFrame *frames;
U64 concrete_frame_count; U64 frames_count;
U64 inline_frame_count; CTRL_CallStackFrame **concrete_frames;
U64 total_frame_count; U64 concrete_frames_count;
};
////////////////////////////////
//~ rjf: Call Stack Tree Types
typedef struct CTRL_CallStackTreeNode CTRL_CallStackTreeNode;
struct CTRL_CallStackTreeNode
{
CTRL_CallStackTreeNode *hash_next;
CTRL_CallStackTreeNode *first;
CTRL_CallStackTreeNode *last;
CTRL_CallStackTreeNode *next;
CTRL_CallStackTreeNode *parent;
U64 child_count;
U64 id;
CTRL_Handle process;
U64 vaddr;
U64 depth;
CTRL_HandleList threads;
U64 all_descendant_threads_count;
};
typedef struct CTRL_CallStackTree CTRL_CallStackTree;
struct CTRL_CallStackTree
{
CTRL_CallStackTreeNode *root;
U64 slots_count;
CTRL_CallStackTreeNode **slots;
}; };
//////////////////////////////// ////////////////////////////////
@@ -476,44 +350,6 @@ struct CTRL_Spoof
U64 new_ip_value; U64 new_ip_value;
}; };
////////////////////////////////
//~ rjf: User Breakpoint Types
typedef enum CTRL_UserBreakpointKind
{
CTRL_UserBreakpointKind_Null,
CTRL_UserBreakpointKind_FileNameAndLineColNumber,
CTRL_UserBreakpointKind_SymbolNameAndOffset,
CTRL_UserBreakpointKind_VirtualAddress,
CTRL_UserBreakpointKind_COUNT
}
CTRL_UserBreakpointKind;
typedef struct CTRL_UserBreakpoint CTRL_UserBreakpoint;
struct CTRL_UserBreakpoint
{
CTRL_UserBreakpointKind kind;
String8 string;
TxtPt pt;
U64 u64;
String8 condition;
};
typedef struct CTRL_UserBreakpointNode CTRL_UserBreakpointNode;
struct CTRL_UserBreakpointNode
{
CTRL_UserBreakpointNode *next;
CTRL_UserBreakpoint v;
};
typedef struct CTRL_UserBreakpointList CTRL_UserBreakpointList;
struct CTRL_UserBreakpointList
{
CTRL_UserBreakpointNode *first;
CTRL_UserBreakpointNode *last;
U64 count;
};
//////////////////////////////// ////////////////////////////////
//~ rjf: Evaluation Spaces //~ rjf: Evaluation Spaces
@@ -521,7 +357,7 @@ typedef U64 CTRL_EvalSpaceKind;
enum enum
{ {
CTRL_EvalSpaceKind_Entity = E_SpaceKind_FirstUserDefined, CTRL_EvalSpaceKind_Entity = E_SpaceKind_FirstUserDefined,
CTRL_EvalSpaceKind_Meta, CTRL_EvalSpaceKind_FirstUserDefined,
}; };
//////////////////////////////// ////////////////////////////////
@@ -573,7 +409,6 @@ struct CTRL_Msg
String8 stdin_path; String8 stdin_path;
CTRL_TrapList traps; CTRL_TrapList traps;
CTRL_UserBreakpointList user_bps; CTRL_UserBreakpointList user_bps;
CTRL_MetaEvalArray meta_evals;
}; };
typedef struct CTRL_MsgNode CTRL_MsgNode; typedef struct CTRL_MsgNode CTRL_MsgNode;
@@ -618,10 +453,13 @@ typedef enum CTRL_EventKind
//- rjf: debug info changes //- rjf: debug info changes
CTRL_EventKind_ModuleDebugInfoPathChange, CTRL_EventKind_ModuleDebugInfoPathChange,
//- rjf: debug strings / decorations //- rjf: debug strings / decorations / markup
CTRL_EventKind_DebugString, CTRL_EventKind_DebugString,
CTRL_EventKind_ThreadName, CTRL_EventKind_ThreadName,
CTRL_EventKind_ThreadColor, CTRL_EventKind_ThreadColor,
CTRL_EventKind_SetBreakpoint,
CTRL_EventKind_UnsetBreakpoint,
CTRL_EventKind_SetVAddrRangeNote,
//- rjf: memory //- rjf: memory
CTRL_EventKind_MemReserve, CTRL_EventKind_MemReserve,
@@ -677,6 +515,7 @@ struct CTRL_Event
U64 timestamp; U64 timestamp;
U32 exception_code; U32 exception_code;
U32 rgba; U32 rgba;
CTRL_UserBreakpointFlags bp_flags;
String8 string; String8 string;
}; };
@@ -696,61 +535,7 @@ struct CTRL_EventList
}; };
//////////////////////////////// ////////////////////////////////
//~ rjf: Process Memory Cache Types //~ rjf: Process Memory Types
typedef struct CTRL_ProcessMemoryRangeHashNode CTRL_ProcessMemoryRangeHashNode;
struct CTRL_ProcessMemoryRangeHashNode
{
CTRL_ProcessMemoryRangeHashNode *next;
Rng1U64 vaddr_range;
B32 zero_terminated;
Rng1U64 vaddr_range_clamped;
U128 hash;
U64 mem_gen;
U64 last_time_requested_us;
B32 is_taken;
};
typedef struct CTRL_ProcessMemoryRangeHashSlot CTRL_ProcessMemoryRangeHashSlot;
struct CTRL_ProcessMemoryRangeHashSlot
{
CTRL_ProcessMemoryRangeHashNode *first;
CTRL_ProcessMemoryRangeHashNode *last;
};
typedef struct CTRL_ProcessMemoryCacheNode CTRL_ProcessMemoryCacheNode;
struct CTRL_ProcessMemoryCacheNode
{
CTRL_ProcessMemoryCacheNode *next;
CTRL_ProcessMemoryCacheNode *prev;
Arena *arena;
CTRL_Handle handle;
U64 range_hash_slots_count;
CTRL_ProcessMemoryRangeHashSlot *range_hash_slots;
};
typedef struct CTRL_ProcessMemoryCacheSlot CTRL_ProcessMemoryCacheSlot;
struct CTRL_ProcessMemoryCacheSlot
{
CTRL_ProcessMemoryCacheNode *first;
CTRL_ProcessMemoryCacheNode *last;
};
typedef struct CTRL_ProcessMemoryCacheStripe CTRL_ProcessMemoryCacheStripe;
struct CTRL_ProcessMemoryCacheStripe
{
OS_Handle rw_mutex;
OS_Handle cv;
};
typedef struct CTRL_ProcessMemoryCache CTRL_ProcessMemoryCache;
struct CTRL_ProcessMemoryCache
{
U64 slots_count;
CTRL_ProcessMemoryCacheSlot *slots;
U64 stripes_count;
CTRL_ProcessMemoryCacheStripe *stripes;
};
typedef struct CTRL_ProcessMemorySlice CTRL_ProcessMemorySlice; typedef struct CTRL_ProcessMemorySlice CTRL_ProcessMemorySlice;
struct CTRL_ProcessMemorySlice struct CTRL_ProcessMemorySlice
@@ -788,7 +573,7 @@ typedef struct CTRL_ThreadRegCacheStripe CTRL_ThreadRegCacheStripe;
struct CTRL_ThreadRegCacheStripe struct CTRL_ThreadRegCacheStripe
{ {
Arena *arena; Arena *arena;
OS_Handle rw_mutex; RWMutex rw_mutex;
}; };
typedef struct CTRL_ThreadRegCache CTRL_ThreadRegCache; typedef struct CTRL_ThreadRegCache CTRL_ThreadRegCache;
@@ -815,6 +600,8 @@ struct CTRL_ModuleImageInfoCacheNode
U64 entry_point_voff; U64 entry_point_voff;
Rng1U64 tls_vaddr_range; Rng1U64 tls_vaddr_range;
String8 initial_debug_info_path; String8 initial_debug_info_path;
Rng1U64 raddbg_section_voff_range;
String8 raddbg_data;
}; };
typedef struct CTRL_ModuleImageInfoCacheSlot CTRL_ModuleImageInfoCacheSlot; typedef struct CTRL_ModuleImageInfoCacheSlot CTRL_ModuleImageInfoCacheSlot;
@@ -828,7 +615,7 @@ typedef struct CTRL_ModuleImageInfoCacheStripe CTRL_ModuleImageInfoCacheStripe;
struct CTRL_ModuleImageInfoCacheStripe struct CTRL_ModuleImageInfoCacheStripe
{ {
Arena *arena; Arena *arena;
OS_Handle rw_mutex; RWMutex rw_mutex;
}; };
typedef struct CTRL_ModuleImageInfoCache CTRL_ModuleImageInfoCache; typedef struct CTRL_ModuleImageInfoCache CTRL_ModuleImageInfoCache;
@@ -857,6 +644,29 @@ struct CTRL_DbgDirNode
U64 module_direct_count; U64 module_direct_count;
}; };
////////////////////////////////
//~ rjf: Control Thread Evaluation Scopes
typedef struct CTRL_EvalScope CTRL_EvalScope;
struct CTRL_EvalScope
{
Access *access;
E_BaseCtx base_ctx;
E_IRCtx ir_ctx;
E_InterpretCtx interpret_ctx;
};
////////////////////////////////
//~ rjf: Module Requirement Cache Types
typedef struct CTRL_ModuleReqCacheNode CTRL_ModuleReqCacheNode;
struct CTRL_ModuleReqCacheNode
{
CTRL_ModuleReqCacheNode *next;
CTRL_Handle module;
B32 required;
};
//////////////////////////////// ////////////////////////////////
//~ rjf: Wakeup Hook Function Types //~ rjf: Wakeup Hook Function Types
@@ -877,17 +687,21 @@ struct CTRL_State
E_String2NumMap arch_string2alias_tables[Arch_COUNT]; E_String2NumMap arch_string2alias_tables[Arch_COUNT];
// rjf: caches // rjf: caches
CTRL_ProcessMemoryCache process_memory_cache;
CTRL_ThreadRegCache thread_reg_cache; CTRL_ThreadRegCache thread_reg_cache;
CTRL_ModuleImageInfoCache module_image_info_cache; CTRL_ModuleImageInfoCache module_image_info_cache;
// rjf: generations
U64 run_gen;
U64 mem_gen;
U64 reg_gen;
// rjf: user -> ctrl msg ring buffer // rjf: user -> ctrl msg ring buffer
U64 u2c_ring_size; U64 u2c_ring_size;
U8 *u2c_ring_base; U8 *u2c_ring_base;
U64 u2c_ring_write_pos; U64 u2c_ring_write_pos;
U64 u2c_ring_read_pos; U64 u2c_ring_read_pos;
OS_Handle u2c_ring_mutex; Mutex u2c_ring_mutex;
OS_Handle u2c_ring_cv; CondVar u2c_ring_cv;
// rjf: ctrl -> user event ring buffer // rjf: ctrl -> user event ring buffer
U64 c2u_ring_size; U64 c2u_ring_size;
@@ -895,34 +709,32 @@ struct CTRL_State
U8 *c2u_ring_base; U8 *c2u_ring_base;
U64 c2u_ring_write_pos; U64 c2u_ring_write_pos;
U64 c2u_ring_read_pos; U64 c2u_ring_read_pos;
OS_Handle c2u_ring_mutex; Mutex c2u_ring_mutex;
OS_Handle c2u_ring_cv; CondVar c2u_ring_cv;
// rjf: ctrl thread state // rjf: ctrl thread state
U64 ctrl_thread_run_state;
String8 ctrl_thread_log_path; String8 ctrl_thread_log_path;
OS_Handle ctrl_thread; Thread ctrl_thread;
Log *ctrl_thread_log; Log *ctrl_thread_log;
CTRL_EntityStore *ctrl_thread_entity_store; RWMutex ctrl_thread_entity_ctx_rw_mutex;
CTRL_EntityCtxRWStore *ctrl_thread_entity_store;
E_Cache *ctrl_thread_eval_cache;
Arena *ctrl_thread_msg_process_arena;
Arena *dmn_event_arena; Arena *dmn_event_arena;
DMN_EventNode *first_dmn_event_node; DMN_EventNode *first_dmn_event_node;
DMN_EventNode *last_dmn_event_node; DMN_EventNode *last_dmn_event_node;
DMN_EventNode *free_dmn_event_node; DMN_EventNode *free_dmn_event_node;
Arena *user_entry_point_arena; Arena *user_entry_point_arena;
String8List user_entry_points; String8List user_entry_points;
Arena *user_meta_eval_arena;
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; Arena *dbg_dir_arena;
CTRL_DbgDirNode *dbg_dir_root; CTRL_DbgDirNode *dbg_dir_root;
U64 module_req_cache_slots_count;
// rjf: user -> memstream ring buffer CTRL_ModuleReqCacheNode **module_req_cache_slots;
U64 u2ms_ring_size; String8List msg_user_bp_touched_files;
U8 *u2ms_ring_base; String8List msg_user_bp_touched_symbols;
U64 u2ms_ring_write_pos;
U64 u2ms_ring_read_pos;
OS_Handle u2ms_ring_mutex;
OS_Handle u2ms_ring_cv;
}; };
//////////////////////////////// ////////////////////////////////
@@ -937,11 +749,20 @@ read_only global CTRL_Entity ctrl_entity_nil =
&ctrl_entity_nil, &ctrl_entity_nil,
&ctrl_entity_nil, &ctrl_entity_nil,
}; };
read_only global CTRL_CallStackTreeNode ctrl_call_stack_tree_node_nil =
{
0,
&ctrl_call_stack_tree_node_nil,
&ctrl_call_stack_tree_node_nil,
&ctrl_call_stack_tree_node_nil,
&ctrl_call_stack_tree_node_nil,
};
thread_static CTRL_EntityCtxLookupAccel *ctrl_entity_ctx_lookup_accel = 0;
//////////////////////////////// ////////////////////////////////
//~ rjf: Logging Markup //~ rjf: Logging Markup
#define CTRL_CtrlThreadLogScope DeferLoop(log_scope_begin(), ctrl_thread__end_and_flush_info_log()) #define CTRL_CtrlThreadLogScope DeferLoop(log_scope_begin(), ctrl_thread__end_and_flush_log())
//////////////////////////////// ////////////////////////////////
//~ rjf: Basic Type Functions //~ rjf: Basic Type Functions
@@ -949,8 +770,12 @@ read_only global CTRL_Entity ctrl_entity_nil =
internal U64 ctrl_hash_from_string(String8 string); internal U64 ctrl_hash_from_string(String8 string);
internal U64 ctrl_hash_from_handle(CTRL_Handle handle); internal U64 ctrl_hash_from_handle(CTRL_Handle handle);
internal CTRL_EventCause ctrl_event_cause_from_dmn_event_kind(DMN_EventKind event_kind); internal CTRL_EventCause ctrl_event_cause_from_dmn_event_kind(DMN_EventKind event_kind);
internal CTRL_ExceptionKind ctrl_exception_kind_from_dmn(DMN_ExceptionKind kind);
internal String8 ctrl_string_from_event_kind(CTRL_EventKind kind); internal String8 ctrl_string_from_event_kind(CTRL_EventKind kind);
internal String8 ctrl_string_from_msg_kind(CTRL_MsgKind kind); internal String8 ctrl_string_from_msg_kind(CTRL_MsgKind kind);
internal CTRL_EntityKind ctrl_entity_kind_from_string(String8 string);
internal DMN_TrapFlags ctrl_dmn_trap_flags_from_user_breakpoint_flags(CTRL_UserBreakpointFlags flags);
internal CTRL_UserBreakpointFlags ctrl_user_breakpoint_flags_from_dmn_trap_flags(DMN_TrapFlags flags);
//////////////////////////////// ////////////////////////////////
//~ rjf: Handle Type Functions //~ rjf: Handle Type Functions
@@ -960,6 +785,9 @@ internal CTRL_Handle ctrl_handle_make(CTRL_MachineID machine_id, DMN_Handle dmn_
internal B32 ctrl_handle_match(CTRL_Handle a, CTRL_Handle b); internal B32 ctrl_handle_match(CTRL_Handle a, CTRL_Handle b);
internal void ctrl_handle_list_push(Arena *arena, CTRL_HandleList *list, CTRL_Handle *pair); internal void ctrl_handle_list_push(Arena *arena, CTRL_HandleList *list, CTRL_Handle *pair);
internal CTRL_HandleList ctrl_handle_list_copy(Arena *arena, CTRL_HandleList *src); internal CTRL_HandleList ctrl_handle_list_copy(Arena *arena, CTRL_HandleList *src);
internal CTRL_HandleArray ctrl_handle_array_from_list(Arena *arena, CTRL_HandleList *src);
internal String8 ctrl_string_from_handle(Arena *arena, CTRL_Handle handle);
internal CTRL_Handle ctrl_handle_from_string(String8 string);
//////////////////////////////// ////////////////////////////////
//~ rjf: Trap Type Functions //~ rjf: Trap Type Functions
@@ -1004,38 +832,21 @@ internal CTRL_Event ctrl_event_from_serialized_string(Arena *arena, String8 stri
//- rjf: entity list data structures //- rjf: entity list data structures
internal void ctrl_entity_list_push(Arena *arena, CTRL_EntityList *list, CTRL_Entity *entity); internal void ctrl_entity_list_push(Arena *arena, CTRL_EntityList *list, CTRL_Entity *entity);
internal CTRL_EntityList ctrl_entity_list_from_handle_list(Arena *arena, CTRL_EntityStore *store, CTRL_HandleList *list); internal CTRL_EntityList ctrl_entity_list_from_handle_list(Arena *arena, CTRL_EntityCtx *ctx, CTRL_HandleList *list);
#define ctrl_entity_list_first(list) ((list)->first ? (list)->first->v : &ctrl_entity_nil) #define ctrl_entity_list_first(list) ((list)->first ? (list)->first->v : &ctrl_entity_nil)
//- rjf: entity array data structure //- rjf: entity array data structure
internal CTRL_EntityArray ctrl_entity_array_from_list(Arena *arena, CTRL_EntityList *list); internal CTRL_EntityArray ctrl_entity_array_from_list(Arena *arena, CTRL_EntityList *list);
#define ctrl_entity_array_first(array) ((array)->count != 0 ? (array)->v[0] : &ctrl_entity_nil)
//- rjf: cache creation/destruction //- rjf: entity context (entity group read-only) functions
internal CTRL_EntityStore *ctrl_entity_store_alloc(void); internal CTRL_Entity *ctrl_entity_from_handle(CTRL_EntityCtx *ctx, CTRL_Handle handle);
internal void ctrl_entity_store_release(CTRL_EntityStore *store);
//- rjf: string allocation/deletion
internal U64 ctrl_name_bucket_idx_from_string_size(U64 size);
internal String8 ctrl_entity_string_alloc(CTRL_EntityStore *store, String8 string);
internal void ctrl_entity_string_release(CTRL_EntityStore *store, String8 string);
//- rjf: entity construction/deletion
internal CTRL_Entity *ctrl_entity_alloc(CTRL_EntityStore *store, CTRL_Entity *parent, CTRL_EntityKind kind, Arch arch, CTRL_Handle handle, U64 id);
internal void ctrl_entity_release(CTRL_EntityStore *store, CTRL_Entity *entity);
//- rjf: entity equipment
internal void ctrl_entity_equip_string(CTRL_EntityStore *store, CTRL_Entity *entity, String8 string);
//- rjf: entity store lookups
internal CTRL_Entity *ctrl_entity_from_handle(CTRL_EntityStore *store, CTRL_Handle handle);
internal CTRL_Entity *ctrl_entity_child_from_kind(CTRL_Entity *parent, CTRL_EntityKind kind); internal CTRL_Entity *ctrl_entity_child_from_kind(CTRL_Entity *parent, CTRL_EntityKind kind);
internal CTRL_Entity *ctrl_entity_ancestor_from_kind(CTRL_Entity *entity, CTRL_EntityKind kind); internal CTRL_Entity *ctrl_entity_ancestor_from_kind(CTRL_Entity *entity, CTRL_EntityKind kind);
internal CTRL_Entity *ctrl_process_from_entity(CTRL_Entity *entity); internal CTRL_Entity *ctrl_process_from_entity(CTRL_Entity *entity);
internal CTRL_Entity *ctrl_module_from_process_vaddr(CTRL_Entity *process, U64 vaddr); internal CTRL_Entity *ctrl_module_from_process_vaddr(CTRL_Entity *process, U64 vaddr);
internal DI_Key ctrl_dbgi_key_from_module(CTRL_Entity *module); internal DI_Key ctrl_dbgi_key_from_module(CTRL_Entity *module);
internal CTRL_EntityList ctrl_modules_from_dbgi_key(Arena *arena, CTRL_EntityStore *store, DI_Key *dbgi_key); internal CTRL_Entity *ctrl_module_from_thread_candidates(CTRL_EntityCtx *ctx, CTRL_Entity *thread, CTRL_EntityList *candidates);
internal CTRL_Entity *ctrl_module_from_thread_candidates(CTRL_EntityStore *store, CTRL_Entity *thread, CTRL_EntityList *candidates);
internal CTRL_EntityList ctrl_entity_list_from_kind(CTRL_EntityStore *store, CTRL_EntityKind kind);
internal U64 ctrl_vaddr_from_voff(CTRL_Entity *module, U64 voff); internal U64 ctrl_vaddr_from_voff(CTRL_Entity *module, U64 voff);
internal U64 ctrl_voff_from_vaddr(CTRL_Entity *module, U64 vaddr); internal U64 ctrl_voff_from_vaddr(CTRL_Entity *module, U64 vaddr);
internal Rng1U64 ctrl_vaddr_range_from_voff_range(CTRL_Entity *module, Rng1U64 voff_range); internal Rng1U64 ctrl_vaddr_range_from_voff_range(CTRL_Entity *module, Rng1U64 voff_range);
@@ -1047,8 +858,30 @@ internal CTRL_EntityRec ctrl_entity_rec_depth_first(CTRL_Entity *entity, CTRL_En
#define ctrl_entity_rec_depth_first_pre(entity, subtree_root) ctrl_entity_rec_depth_first((entity), (subtree_root), OffsetOf(CTRL_Entity, next), OffsetOf(CTRL_Entity, first)) #define ctrl_entity_rec_depth_first_pre(entity, subtree_root) ctrl_entity_rec_depth_first((entity), (subtree_root), OffsetOf(CTRL_Entity, next), OffsetOf(CTRL_Entity, first))
#define ctrl_entity_rec_depth_first_post(entity, subtree_root) ctrl_entity_rec_depth_first((entity), (subtree_root), OffsetOf(CTRL_Entity, prev), OffsetOf(CTRL_Entity, last)) #define ctrl_entity_rec_depth_first_post(entity, subtree_root) ctrl_entity_rec_depth_first((entity), (subtree_root), OffsetOf(CTRL_Entity, prev), OffsetOf(CTRL_Entity, last))
//- rjf: entity ctx r/w store state functions
internal CTRL_EntityCtxRWStore *ctrl_entity_ctx_rw_store_alloc(void);
internal void ctrl_entity_ctx_rw_store_release(CTRL_EntityCtxRWStore *store);
//- rjf: string allocation/deletion
internal U64 ctrl_name_bucket_num_from_string_size(U64 size);
internal String8 ctrl_entity_string_alloc(CTRL_EntityCtxRWStore *store, String8 string);
internal void ctrl_entity_string_release(CTRL_EntityCtxRWStore *store, String8 string);
//- rjf: entity construction/deletion
internal CTRL_Entity *ctrl_entity_alloc(CTRL_EntityCtxRWStore *store, CTRL_Entity *parent, CTRL_EntityKind kind, Arch arch, CTRL_Handle handle, U64 id);
internal void ctrl_entity_release(CTRL_EntityCtxRWStore *store, CTRL_Entity *entity);
//- rjf: entity equipment
internal void ctrl_entity_equip_string(CTRL_EntityCtxRWStore *store, CTRL_Entity *entity, String8 string);
//- rjf: accelerated entity context lookups
internal CTRL_EntityCtxLookupAccel *ctrl_thread_entity_ctx_lookup_accel(void);
internal CTRL_EntityArray ctrl_entity_array_from_kind(CTRL_EntityCtx *ctx, CTRL_EntityKind kind);
internal CTRL_EntityList ctrl_modules_from_dbgi_key(Arena *arena, CTRL_EntityCtx *ctx, DI_Key dbgi_key);
internal CTRL_Entity *ctrl_thread_from_id(CTRL_EntityCtx *ctx, U64 id);
//- rjf: applying events to entity caches //- rjf: applying events to entity caches
internal void ctrl_entity_store_apply_events(CTRL_EntityStore *store, CTRL_EventList *list); internal void ctrl_entity_store_apply_events(CTRL_EntityCtxRWStore *store, CTRL_EventList *list);
//////////////////////////////// ////////////////////////////////
//~ rjf: Main Layer Initialization //~ rjf: Main Layer Initialization
@@ -1060,33 +893,14 @@ internal void ctrl_init(void);
internal void ctrl_set_wakeup_hook(CTRL_WakeupFunctionType *wakeup_hook); internal void ctrl_set_wakeup_hook(CTRL_WakeupFunctionType *wakeup_hook);
////////////////////////////////
//~ rjf: Process Memory Functions
//- rjf: process memory cache interaction
internal U128 ctrl_calc_hash_store_key_from_process_vaddr_range(CTRL_Handle process, Rng1U64 range, B32 zero_terminated);
internal U128 ctrl_stored_hash_from_process_vaddr_range(CTRL_Handle process, Rng1U64 range, B32 zero_terminated, B32 *out_is_stale, U64 endt_us);
//- rjf: bundled key/stream helper
internal U128 ctrl_hash_store_key_from_process_vaddr_range(CTRL_Handle process, Rng1U64 range, B32 zero_terminated);
//- rjf: process memory cache reading helpers
internal CTRL_ProcessMemorySlice ctrl_query_cached_data_from_process_vaddr_range(Arena *arena, CTRL_Handle process, Rng1U64 range, U64 endt_us);
internal CTRL_ProcessMemorySlice ctrl_query_cached_zero_terminated_data_from_process_vaddr_limit(Arena *arena, CTRL_Handle process, U64 vaddr, U64 limit, U64 element_size, U64 endt_us);
internal B32 ctrl_read_cached_process_memory(CTRL_Handle process, Rng1U64 range, B32 *is_stale_out, void *out, U64 endt_us);
#define ctrl_read_cached_process_memory_struct(process, vaddr, is_stale_out, ptr, endt_us) ctrl_read_cached_process_memory((process), r1u64((vaddr), (vaddr)+(sizeof(*(ptr)))), (is_stale_out), (ptr), (endt_us))
//- rjf: process memory writing
internal B32 ctrl_process_write(CTRL_Handle process, Rng1U64 range, void *src);
//////////////////////////////// ////////////////////////////////
//~ rjf: Thread Register Functions //~ rjf: Thread Register Functions
//- rjf: thread register cache reading //- rjf: thread register cache reading
internal void *ctrl_query_cached_reg_block_from_thread(Arena *arena, CTRL_EntityStore *store, CTRL_Handle handle); internal void *ctrl_reg_block_from_thread(Arena *arena, CTRL_EntityCtx *ctx, CTRL_Handle handle);
internal U64 ctrl_query_cached_tls_root_vaddr_from_thread(CTRL_EntityStore *store, CTRL_Handle handle); internal U64 ctrl_tls_root_vaddr_from_thread(CTRL_EntityCtx *ctx, CTRL_Handle handle);
internal U64 ctrl_query_cached_rip_from_thread(CTRL_EntityStore *store, CTRL_Handle handle); internal U64 ctrl_rip_from_thread(CTRL_EntityCtx *ctx, CTRL_Handle handle);
internal U64 ctrl_query_cached_rsp_from_thread(CTRL_EntityStore *store, CTRL_Handle handle); internal U64 ctrl_rsp_from_thread(CTRL_EntityCtx *ctx, CTRL_Handle handle);
//- rjf: thread register writing //- rjf: thread register writing
internal B32 ctrl_thread_write_reg_block(CTRL_Handle thread, void *block); internal B32 ctrl_thread_write_reg_block(CTRL_Handle thread, void *block);
@@ -1099,6 +913,7 @@ internal PE_IntelPdata *ctrl_intel_pdata_from_module_voff(Arena *arena, CTRL_Han
internal U64 ctrl_entry_point_voff_from_module(CTRL_Handle module_handle); internal U64 ctrl_entry_point_voff_from_module(CTRL_Handle module_handle);
internal Rng1U64 ctrl_tls_vaddr_range_from_module(CTRL_Handle module_handle); internal Rng1U64 ctrl_tls_vaddr_range_from_module(CTRL_Handle module_handle);
internal String8 ctrl_initial_debug_info_path_from_module(Arena *arena, CTRL_Handle module_handle); internal String8 ctrl_initial_debug_info_path_from_module(Arena *arena, CTRL_Handle module_handle);
internal String8 ctrl_raddbg_data_from_module(Arena *arena, CTRL_Handle module_handle);
//////////////////////////////// ////////////////////////////////
//~ rjf: Unwinding Functions //~ rjf: Unwinding Functions
@@ -1108,18 +923,19 @@ internal CTRL_Unwind ctrl_unwind_deep_copy(Arena *arena, Arch arch, CTRL_Unwind
//- rjf: [x64] //- rjf: [x64]
internal REGS_Reg64 *ctrl_unwind_reg_from_pe_gpr_reg__pe_x64(REGS_RegBlockX64 *regs, PE_UnwindGprRegX64 gpr_reg); internal REGS_Reg64 *ctrl_unwind_reg_from_pe_gpr_reg__pe_x64(REGS_RegBlockX64 *regs, PE_UnwindGprRegX64 gpr_reg);
internal CTRL_UnwindStepResult ctrl_unwind_step__pe_x64(CTRL_EntityStore *store, CTRL_Handle process_handle, CTRL_Handle module_handle, REGS_RegBlockX64 *regs, U64 endt_us); internal CTRL_UnwindStepResult ctrl_unwind_step__pe_x64(CTRL_Handle process_handle, CTRL_Handle module_handle, U64 module_base_vaddr, REGS_RegBlockX64 *regs, U64 endt_us);
//- rjf: abstracted unwind step //- rjf: abstracted unwind step
internal CTRL_UnwindStepResult ctrl_unwind_step(CTRL_EntityStore *store, CTRL_Handle process, CTRL_Handle module, Arch arch, void *reg_block, U64 endt_us); internal CTRL_UnwindStepResult ctrl_unwind_step(CTRL_Handle process, CTRL_Handle module, U64 module_base_vaddr, Arch arch, void *reg_block, U64 endt_us);
//- rjf: abstracted full unwind //- rjf: abstracted full unwind
internal CTRL_Unwind ctrl_unwind_from_thread(Arena *arena, CTRL_EntityStore *store, CTRL_Handle thread, U64 endt_us); internal CTRL_Unwind ctrl_unwind_from_thread(Arena *arena, CTRL_EntityCtx *ctx, CTRL_Handle thread, U64 endt_us);
//////////////////////////////// ////////////////////////////////
//~ rjf: Call Stack Building Functions //~ rjf: Call Stack Building Functions
internal CTRL_CallStack ctrl_call_stack_from_unwind(Arena *arena, DI_Scope *di_scope, CTRL_Entity *process, CTRL_Unwind *base_unwind); internal CTRL_CallStack ctrl_call_stack_from_unwind(Arena *arena, CTRL_Entity *process, CTRL_Unwind *base_unwind);
internal CTRL_CallStackFrame *ctrl_call_stack_frame_from_unwind_and_inline_depth(CTRL_CallStack *call_stack, U64 unwind_count, U64 inline_depth);
//////////////////////////////// ////////////////////////////////
//~ rjf: Halting All Attached Processes //~ rjf: Halting All Attached Processes
@@ -1153,22 +969,27 @@ internal CTRL_EventList ctrl_c2u_pop_events(Arena *arena);
internal void ctrl_thread__entry_point(void *p); internal void ctrl_thread__entry_point(void *p);
//- rjf: breakpoint resolution //- rjf: breakpoint resolution
internal void ctrl_thread__append_resolved_module_user_bp_traps(Arena *arena, CTRL_Handle process, CTRL_Handle module, CTRL_UserBreakpointList *user_bps, DMN_TrapChunkList *traps_out); internal void ctrl_thread__append_resolved_module_user_bp_traps(Arena *arena, CTRL_EvalScope *eval_scope, CTRL_Handle process, CTRL_Handle module, CTRL_UserBreakpointList *user_bps, DMN_TrapChunkList *traps_out);
internal void ctrl_thread__append_resolved_process_user_bp_traps(Arena *arena, CTRL_Handle process, CTRL_UserBreakpointList *user_bps, DMN_TrapChunkList *traps_out); internal void ctrl_thread__append_resolved_process_user_bp_traps(Arena *arena, CTRL_EvalScope *eval_scope, CTRL_Handle process, CTRL_UserBreakpointList *user_bps, DMN_TrapChunkList *traps_out);
internal void ctrl_thread__append_program_defined_bp_traps(Arena *arena, CTRL_Entity *bp, DMN_TrapChunkList *traps_out);
//- rjf: module lifetime open/close work //- rjf: module lifetime open/close work
internal void ctrl_thread__module_open(CTRL_Handle process, CTRL_Handle module, Rng1U64 vaddr_range, String8 path); internal void ctrl_thread__module_open(CTRL_Handle process, CTRL_Handle module, Rng1U64 vaddr_range, String8 path);
internal void ctrl_thread__module_close(CTRL_Handle module); internal void ctrl_thread__module_close(CTRL_Handle process, CTRL_Handle module, Rng1U64 vaddr_range);
//- rjf: attached process running/event gathering //- rjf: attached process running/event gathering
internal DMN_Event *ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, DMN_RunCtrls *run_ctrls, CTRL_Spoof *spoof); internal DMN_Event *ctrl_thread__next_dmn_event(Arena *arena, DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg, DMN_RunCtrls *run_ctrls, CTRL_Spoof *spoof);
//- rjf: eval helpers //- rjf: eval helpers
internal B32 ctrl_eval_space_read(void *u, E_Space space, void *out, Rng1U64 vaddr_range); internal U64 ctrl_eval_space_gen(E_Space space);
internal B32 ctrl_eval_space_read(E_Space space, void *out, Rng1U64 vaddr_range);
//- rjf: control thread eval scopes
internal CTRL_EvalScope *ctrl_thread__eval_scope_begin(Arena *arena, CTRL_UserBreakpointList *user_bps, CTRL_Entity *thread);
internal void ctrl_thread__eval_scope_end(CTRL_EvalScope *scope);
//- rjf: log flusher //- rjf: log flusher
internal void ctrl_thread__flush_info_log(String8 string); internal void ctrl_thread__end_and_flush_log(void);
internal void ctrl_thread__end_and_flush_info_log(void);
//- rjf: msg kind implementations //- rjf: msg kind implementations
internal void ctrl_thread__launch(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg); internal void ctrl_thread__launch(DMN_CtrlCtx *ctrl_ctx, CTRL_Msg *msg);
@@ -1180,14 +1001,32 @@ 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);
//////////////////////////////// ////////////////////////////////
//~ rjf: Memory-Stream Thread Functions //~ rjf: Process Memory Artifact Cache Hooks / Lookups
//- rjf: user -> memory stream communication internal AC_Artifact ctrl_memory_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out, U64 *gen_out);
internal B32 ctrl_u2ms_enqueue_req(CTRL_Handle process, Rng1U64 vaddr_range, B32 zero_terminated, U64 endt_us); internal void ctrl_memory_artifact_destroy(AC_Artifact artifact);
internal void ctrl_u2ms_dequeue_req(CTRL_Handle *out_process, Rng1U64 *out_vaddr_range, B32 *out_zero_terminated); internal C_Key ctrl_key_from_process_vaddr_range(CTRL_Handle process, Rng1U64 vaddr_range, B32 zero_terminated, B32 wait_for_fresh, U64 endt_us, B32 *out_is_stale);
//- rjf: entry point //- rjf: process memory reading helpers
ASYNC_WORK_DEF(ctrl_mem_stream_work); internal CTRL_ProcessMemorySlice ctrl_process_memory_slice_from_vaddr_range(Arena *arena, CTRL_Handle process, Rng1U64 range, B32 wait_for_fresh, U64 endt_us);
internal void ctrl_mem_stream_thread__entry_point(void *p); internal B32 ctrl_process_memory_read(CTRL_Handle process, Rng1U64 range, B32 *is_stale_out, void *out, U64 endt_us);
#define ctrl_process_memory_read_struct(process, vaddr, is_stale_out, ptr, endt_us) ctrl_process_memory_read((process), r1u64((vaddr), (vaddr)+(sizeof(*(ptr)))), (is_stale_out), (ptr), (endt_us))
//- rjf: process memory writing
internal B32 ctrl_process_write(CTRL_Handle process, Rng1U64 range, void *src);
////////////////////////////////
//~ rjf: Call Stack Artifact Cache Hooks / Lookups
internal AC_Artifact ctrl_call_stack_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out, U64 *gen_out);
internal void ctrl_call_stack_artifact_destroy(AC_Artifact artifact);
internal CTRL_CallStack ctrl_call_stack_from_thread(Access *access, CTRL_Handle thread_handle, B32 high_priority, U64 endt_us);
////////////////////////////////
//~ rjf: Call Stack Tree Artifact Cache Hooks / Lookups
internal AC_Artifact ctrl_call_stack_tree_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out, U64 *gen_out);
internal void ctrl_call_stack_tree_artifact_destroy(AC_Artifact artifact);
internal CTRL_CallStackTree ctrl_call_stack_tree(Access *access, U64 endt_us);
#endif // CTRL_CORE_H #endif // CTRL_CORE_H
+4 -1
View File
@@ -1,4 +1,7 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#undef LAYER_COLOR
#define LAYER_COLOR 0x969696ff
#include "ctrl_core.c" #include "ctrl_core.c"
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef CTRL_INC_H #ifndef CTRL_INC_H
+22 -2
View File
@@ -1,10 +1,26 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE //- GENERATED CODE
C_LINKAGE_BEGIN C_LINKAGE_BEGIN
String8 ctrl_entity_kind_display_string_table[8] = String8 ctrl_entity_kind_code_name_table[12] =
{
{0},
str8_lit_comp("root"),
str8_lit_comp("machine"),
str8_lit_comp("process"),
str8_lit_comp("thread"),
str8_lit_comp("module"),
str8_lit_comp("entry_point"),
str8_lit_comp("debug_info_path"),
str8_lit_comp("pending_thread_name"),
str8_lit_comp("pending_thread_color"),
str8_lit_comp("breakpoint"),
str8_lit_comp("address_range_annotation"),
};
String8 ctrl_entity_kind_display_string_table[12] =
{ {
{0}, {0},
str8_lit_comp("Root"), str8_lit_comp("Root"),
@@ -14,6 +30,10 @@ str8_lit_comp("Thread"),
str8_lit_comp("Module"), str8_lit_comp("Module"),
str8_lit_comp("EntryPoint"), str8_lit_comp("EntryPoint"),
str8_lit_comp("DebugInfoPath"), str8_lit_comp("DebugInfoPath"),
str8_lit_comp("PendingThreadName"),
str8_lit_comp("PendingThreadColor"),
str8_lit_comp("Breakpoint"),
str8_lit_comp("AddressRangeAnnotation"),
}; };
U32 ctrl_exception_code_kind_code_table[38] = U32 ctrl_exception_code_kind_code_table[38] =
+7 -2
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE //- GENERATED CODE
@@ -16,6 +16,10 @@ CTRL_EntityKind_Thread,
CTRL_EntityKind_Module, CTRL_EntityKind_Module,
CTRL_EntityKind_EntryPoint, CTRL_EntityKind_EntryPoint,
CTRL_EntityKind_DebugInfoPath, CTRL_EntityKind_DebugInfoPath,
CTRL_EntityKind_PendingThreadName,
CTRL_EntityKind_PendingThreadColor,
CTRL_EntityKind_Breakpoint,
CTRL_EntityKind_AddressRangeAnnotation,
CTRL_EntityKind_COUNT, CTRL_EntityKind_COUNT,
} CTRL_EntityKind; } CTRL_EntityKind;
@@ -63,7 +67,8 @@ CTRL_ExceptionCodeKind_COUNT,
} CTRL_ExceptionCodeKind; } CTRL_ExceptionCodeKind;
C_LINKAGE_BEGIN C_LINKAGE_BEGIN
extern String8 ctrl_entity_kind_display_string_table[8]; extern String8 ctrl_entity_kind_code_name_table[12];
extern String8 ctrl_entity_kind_display_string_table[12];
extern U32 ctrl_exception_code_kind_code_table[38]; extern U32 ctrl_exception_code_kind_code_table[38];
extern String8 ctrl_exception_code_kind_display_string_table[38]; extern String8 ctrl_exception_code_kind_display_string_table[38];
extern String8 ctrl_exception_code_kind_lowercase_code_string_table[38]; extern String8 ctrl_exception_code_kind_lowercase_code_string_table[38];
-856
View File
@@ -1,856 +0,0 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
//~ rjf: Instruction Decoding/Disassembling Type Functions
#if !defined(ZYDIS_H)
#include "third_party/zydis/zydis.h"
#include "third_party/zydis/zydis.c"
#endif
internal DASM_Inst
dasm_inst_from_code(Arena *arena, Arch arch, U64 vaddr, String8 code, DASM_Syntax syntax)
{
DASM_Inst inst = {0};
switch(arch)
{
default:{}break;
//- rjf: x86/x64 disassembly
case Arch_x86:
case Arch_x64:
{
// rjf: determine zydis formatter style
ZydisFormatterStyle style = ZYDIS_FORMATTER_STYLE_INTEL;
switch(syntax)
{
default:{}break;
case DASM_Syntax_Intel:{style = ZYDIS_FORMATTER_STYLE_INTEL;}break;
case DASM_Syntax_ATT: {style = ZYDIS_FORMATTER_STYLE_ATT;}break;
}
// rjf: disassemble one instruction
ZydisDisassembledInstruction zinst = {0};
ZyanStatus status = ZydisDisassemble(ZYDIS_MACHINE_MODE_LONG_64, vaddr, code.str, code.size, &zinst, style);
// rjf: analyze
DASM_InstFlags flags = 0;
U64 jump_dest_vaddr = 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 *second_op = (zinst.info.operand_count > 1 ? &zinst.operands[1] : 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);
}
if(first_op != 0 && second_op != 0 && first_op->type == ZYDIS_OPERAND_TYPE_REGISTER &&
(first_op->reg.value == ZYDIS_REGISTER_RSP ||
first_op->reg.value == ZYDIS_REGISTER_ESP ||
first_op->reg.value == ZYDIS_REGISTER_SP))
{
flags |= DASM_InstFlag_ChangesStackPointer;
if(second_op->type != ZYDIS_OPERAND_TYPE_IMMEDIATE)
{
flags |= DASM_InstFlag_ChangesStackPointerVariably;
}
}
if(zinst.info.attributes & (ZYDIS_ATTRIB_HAS_REP|
ZYDIS_ATTRIB_HAS_REPE|
ZYDIS_ATTRIB_HAS_REPZ|
ZYDIS_ATTRIB_HAS_REPNZ|
ZYDIS_ATTRIB_HAS_REPNE))
{
flags |= DASM_InstFlag_Repeats;
}
switch(zinst.info.mnemonic)
{
case ZYDIS_MNEMONIC_CALL:
{
flags |= DASM_InstFlag_Call;
}break;
case ZYDIS_MNEMONIC_JB:
case ZYDIS_MNEMONIC_JBE:
case ZYDIS_MNEMONIC_JCXZ:
case ZYDIS_MNEMONIC_JECXZ:
case ZYDIS_MNEMONIC_JKNZD:
case ZYDIS_MNEMONIC_JKZD:
case ZYDIS_MNEMONIC_JL:
case ZYDIS_MNEMONIC_JLE:
case ZYDIS_MNEMONIC_JNB:
case ZYDIS_MNEMONIC_JNBE:
case ZYDIS_MNEMONIC_JNL:
case ZYDIS_MNEMONIC_JNLE:
case ZYDIS_MNEMONIC_JNO:
case ZYDIS_MNEMONIC_JNP:
case ZYDIS_MNEMONIC_JNS:
case ZYDIS_MNEMONIC_JNZ:
case ZYDIS_MNEMONIC_JO:
case ZYDIS_MNEMONIC_JP:
case ZYDIS_MNEMONIC_JRCXZ:
case ZYDIS_MNEMONIC_JS:
case ZYDIS_MNEMONIC_JZ:
case ZYDIS_MNEMONIC_LOOP:
case ZYDIS_MNEMONIC_LOOPE:
case ZYDIS_MNEMONIC_LOOPNE:
{
flags |= DASM_InstFlag_Branch;
}break;
case ZYDIS_MNEMONIC_JMP:
{
flags |= DASM_InstFlag_UnconditionalJump;
}break;
case ZYDIS_MNEMONIC_RET:
{
flags |= DASM_InstFlag_Return;
}break;
case ZYDIS_MNEMONIC_PUSH:
case ZYDIS_MNEMONIC_POP:
{
flags |= DASM_InstFlag_ChangesStackPointer;
}break;
default:
{
flags |= DASM_InstFlag_NonFlow;
}break;
}
}
// rjf: convert
{
inst.flags = flags;
inst.size = zinst.info.length;
inst.string = push_str8_copy(arena, str8_cstring(zinst.text));
inst.jump_dest_vaddr = jump_dest_vaddr;
}
}break;
}
return inst;
}
////////////////////////////////
//~ rjf: Control Flow Analysis
internal DASM_CtrlFlowInfo
dasm_ctrl_flow_info_from_arch_vaddr_code(Arena *arena, DASM_InstFlags exit_points_mask, Arch arch, U64 vaddr, String8 code)
{
Temp scratch = scratch_begin(&arena, 1);
DASM_CtrlFlowInfo info = {0};
for(U64 offset = 0; offset < code.size;)
{
DASM_Inst inst = dasm_inst_from_code(scratch.arena, arch, vaddr+offset, str8_skip(code, offset), DASM_Syntax_Intel);
U64 inst_vaddr = vaddr+offset;
offset += inst.size;
info.total_size += inst.size;
if(inst.flags & exit_points_mask)
{
DASM_CtrlFlowPoint point = {0};
point.inst_flags = inst.flags;
point.vaddr = inst_vaddr;
point.jump_dest_vaddr = inst.jump_dest_vaddr;
DASM_CtrlFlowPointNode *node = push_array(arena, DASM_CtrlFlowPointNode, 1);
node->v = point;
SLLQueuePush(info.exit_points.first, info.exit_points.last, node);
info.exit_points.count += 1;
}
}
scratch_end(scratch);
return info;
}
////////////////////////////////
//~ rjf: Parameter Type Functions
internal B32
dasm_params_match(DASM_Params *a, DASM_Params *b)
{
B32 result = (a->vaddr == b->vaddr &&
a->arch == b->arch &&
a->style_flags == b->style_flags &&
a->syntax == b->syntax &&
a->base_vaddr == b->base_vaddr &&
di_key_match(&a->dbgi_key, &b->dbgi_key));
return result;
}
////////////////////////////////
//~ rjf: Line Type Functions
internal void
dasm_line_chunk_list_push(Arena *arena, DASM_LineChunkList *list, U64 cap, DASM_Line *inst)
{
DASM_LineChunkNode *node = list->last;
if(node == 0 || node->count >= node->cap)
{
node = push_array(arena, DASM_LineChunkNode, 1);
node->v = push_array_no_zero(arena, DASM_Line, cap);
node->cap = cap;
SLLQueuePush(list->first, list->last, node);
list->node_count += 1;
}
MemoryCopyStruct(&node->v[node->count], inst);
node->count += 1;
list->line_count += 1;
}
internal DASM_LineArray
dasm_line_array_from_chunk_list(Arena *arena, DASM_LineChunkList *list)
{
DASM_LineArray array = {0};
array.count = list->line_count;
array.v = push_array_no_zero(arena, DASM_Line, array.count);
U64 idx = 0;
for(DASM_LineChunkNode *n = list->first; n != 0; n = n->next)
{
MemoryCopy(array.v+idx, n->v, sizeof(DASM_Line)*n->count);
idx += n->count;
}
return array;
}
internal U64
dasm_line_array_idx_from_code_off__linear_scan(DASM_LineArray *array, U64 off)
{
U64 result = 0;
for(U64 idx = 0; idx < array->count; idx += 1)
{
U64 next_off = (idx+1 < array->count ? array->v[idx+1].code_off : max_U64);
if(array->v[idx].code_off <= off && off < next_off)
{
result = idx;
if(!(array->v[idx].flags & DASM_LineFlag_Decorative))
{
break;
}
}
}
return result;
}
internal U64
dasm_line_array_code_off_from_idx(DASM_LineArray *array, U64 idx)
{
U64 off = 0;
if(idx < array->count)
{
off = array->v[idx].code_off;
}
return off;
}
////////////////////////////////
//~ rjf: Main Layer Initialization
internal void
dasm_init(void)
{
Arena *arena = arena_alloc();
dasm_shared = push_array(arena, DASM_Shared, 1);
dasm_shared->arena = arena;
dasm_shared->slots_count = 1024;
dasm_shared->stripes_count = Min(dasm_shared->slots_count, os_get_system_info()->logical_processor_count);
dasm_shared->slots = push_array(arena, DASM_Slot, dasm_shared->slots_count);
dasm_shared->stripes = push_array(arena, DASM_Stripe, dasm_shared->stripes_count);
for(U64 idx = 0; idx < dasm_shared->stripes_count; idx += 1)
{
dasm_shared->stripes[idx].arena = arena_alloc();
dasm_shared->stripes[idx].rw_mutex = os_rw_mutex_alloc();
dasm_shared->stripes[idx].cv = os_condition_variable_alloc();
}
dasm_shared->u2p_ring_size = KB(64);
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_mutex = os_mutex_alloc();
dasm_shared->evictor_detector_thread = os_thread_launch(dasm_evictor_detector_thread__entry_point, 0, 0);
}
////////////////////////////////
//~ rjf: Scoped Access
internal DASM_Scope *
dasm_scope_open(void)
{
if(dasm_tctx == 0)
{
Arena *arena = arena_alloc();
dasm_tctx = push_array(arena, DASM_TCTX, 1);
dasm_tctx->arena = arena;
}
U64 base_pos = arena_pos(dasm_tctx->arena);
DASM_Scope *scope = push_array(dasm_tctx->arena, DASM_Scope, 1);
scope->base_pos = base_pos;
return scope;
}
internal void
dasm_scope_close(DASM_Scope *scope)
{
for(DASM_Touch *t = scope->top_touch, *next = 0; t != 0; t = next)
{
next = t->next;
U64 slot_idx = t->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];
OS_MutexScopeR(stripe->rw_mutex)
{
for(DASM_Node *n = slot->first; n != 0; n = n->next)
{
if(u128_match(t->hash, n->hash) && dasm_params_match(&t->params, &n->params))
{
ins_atomic_u64_dec_eval(&n->scope_ref_count);
break;
}
}
}
}
arena_pop_to(dasm_tctx->arena, scope->base_pos);
}
internal void
dasm_scope_touch_node__stripe_r_guarded(DASM_Scope *scope, DASM_Node *node)
{
DASM_Touch *touch = push_array(dasm_tctx->arena, DASM_Touch, 1);
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_user_clock_idx_touched, update_tick_idx());
touch->hash = node->hash;
MemoryCopyStruct(&touch->params, &node->params);
touch->params.dbgi_key = di_key_copy(dasm_tctx->arena, &touch->params.dbgi_key);
SLLStackPush(scope->top_touch, touch);
}
////////////////////////////////
//~ rjf: Cache Lookups
internal DASM_Info
dasm_info_from_hash_params(DASM_Scope *scope, U128 hash, DASM_Params *params)
{
DASM_Info info = {0};
if(!u128_match(hash, u128_zero()))
{
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];
B32 found = 0;
OS_MutexScopeR(stripe->rw_mutex)
{
for(DASM_Node *n = slot->first; n != 0; n = n->next)
{
if(u128_match(hash, n->hash) && dasm_params_match(params, &n->params))
{
MemoryCopyStruct(&info, &n->info);
found = 1;
dasm_scope_touch_node__stripe_r_guarded(scope, n);
break;
}
}
}
B32 node_is_new = 0;
if(!found)
{
OS_MutexScopeW(stripe->rw_mutex)
{
DASM_Node *node = 0;
for(DASM_Node *n = slot->first; n != 0; n = n->next)
{
if(u128_match(hash, n->hash) && dasm_params_match(params, &n->params))
{
node = n;
break;
}
}
if(node == 0)
{
LogInfoNamedBlockF("dasm_new_node")
{
log_infof("hash: [0x%I64x 0x%I64x]\n", hash.u64[0], hash.u64[1]);
log_infof("vaddr: 0x%I64x\n", params->vaddr);
log_infof("arch: %S\n", string_from_arch(params->arch));
log_infof("style_flags: 0x%x\n", params->style_flags);
log_infof("syntax: %i\n", params->syntax);
log_infof("base_vaddr: 0x%I64x\n", params->base_vaddr);
log_infof("dbgi_key: [%S 0x%I64x]\n", params->dbgi_key.path, params->dbgi_key.min_timestamp);
}
node = stripe->free_node;
if(node)
{
SLLStackPop(stripe->free_node);
}
else
{
node = push_array_no_zero(stripe->arena, DASM_Node, 1);
}
MemoryZeroStruct(node);
DLLPushBack(slot->first, slot->last, node);
node->hash = hash;
MemoryCopyStruct(&node->params, params);
// TODO(rjf): need to make this releasable - currently all exe_paths just leak
node->params.dbgi_key = di_key_copy(stripe->arena, &node->params.dbgi_key);
node_is_new = 1;
}
}
}
if(node_is_new)
{
dasm_u2p_enqueue_req(hash, params, max_U64);
async_push_work(dasm_parse_work);
}
}
return info;
}
internal DASM_Info
dasm_info_from_key_params(DASM_Scope *scope, U128 key, DASM_Params *params, U128 *hash_out)
{
DASM_Info result = {0};
for(U64 rewind_idx = 0; rewind_idx < HS_KEY_HASH_HISTORY_COUNT; rewind_idx += 1)
{
U128 hash = hs_hash_from_key(key, rewind_idx);
result = dasm_info_from_hash_params(scope, hash, params);
if(result.lines.count != 0)
{
if(hash_out)
{
*hash_out = hash;
}
break;
}
}
return result;
}
////////////////////////////////
//~ rjf: Parse Threads
internal B32
dasm_u2p_enqueue_req(U128 hash, DASM_Params *params, U64 endt_us)
{
B32 good = 0;
OS_MutexScope(dasm_shared->u2p_ring_mutex) for(;;)
{
U64 unconsumed_size = dasm_shared->u2p_ring_write_pos - dasm_shared->u2p_ring_read_pos;
U64 available_size = dasm_shared->u2p_ring_size - unconsumed_size;
if(available_size >= sizeof(hash)+sizeof(U64)+sizeof(Arch)+sizeof(DASM_StyleFlags)+sizeof(DASM_Syntax)+sizeof(U64)+sizeof(U64)+params->dbgi_key.path.size+sizeof(U64))
{
good = 1;
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, &hash);
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->vaddr);
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->arch);
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->style_flags);
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->syntax);
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->base_vaddr);
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_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_write_pos, &params->dbgi_key.min_timestamp);
break;
}
if(os_now_microseconds() >= endt_us)
{
break;
}
os_condition_variable_wait(dasm_shared->u2p_ring_cv, dasm_shared->u2p_ring_mutex, endt_us);
}
if(good)
{
os_condition_variable_broadcast(dasm_shared->u2p_ring_cv);
}
return good;
}
internal void
dasm_u2p_dequeue_req(Arena *arena, U128 *hash_out, DASM_Params *params_out)
{
OS_MutexScope(dasm_shared->u2p_ring_mutex) for(;;)
{
U64 unconsumed_size = dasm_shared->u2p_ring_write_pos - dasm_shared->u2p_ring_read_pos;
if(unconsumed_size >= sizeof(*hash_out)+sizeof(U64)+sizeof(Arch)+sizeof(DASM_StyleFlags)+sizeof(DASM_Syntax)+sizeof(U64)+sizeof(U64)+sizeof(U64))
{
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, hash_out);
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->vaddr);
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->arch);
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->style_flags);
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->syntax);
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->base_vaddr);
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.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_struct(dasm_shared->u2p_ring_base, dasm_shared->u2p_ring_size, dasm_shared->u2p_ring_read_pos, &params_out->dbgi_key.min_timestamp);
break;
}
os_condition_variable_wait(dasm_shared->u2p_ring_cv, dasm_shared->u2p_ring_mutex, max_U64);
}
os_condition_variable_broadcast(dasm_shared->u2p_ring_cv);
}
ASYNC_WORK_DEF(dasm_parse_work)
{
ProfBeginFunction();
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)
{
for(DASM_Node *n = slot->first; n != 0; n = n->next)
{
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;
}
}
}
//- 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;
}
////////////////////////////////
//~ rjf: Evictor/Detector Thread
internal void
dasm_evictor_detector_thread__entry_point(void *p)
{
ThreadNameF("[dasm] evictor/detector thread");
for(;;)
{
U64 change_gen = fs_change_gen();
U64 check_time_us = os_now_microseconds();
U64 check_time_user_clocks = update_tick_idx();
U64 evict_threshold_us = 10*1000000;
U64 retry_threshold_us = 1*1000000;
U64 evict_threshold_user_clocks = 10;
U64 retry_threshold_user_clocks = 10;
for(U64 slot_idx = 0; slot_idx < dasm_shared->slots_count; slot_idx += 1)
{
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];
B32 slot_has_work = 0;
OS_MutexScopeR(stripe->rw_mutex)
{
for(DASM_Node *n = slot->first; n != 0; n = n->next)
{
if(n->scope_ref_count == 0 &&
n->last_time_touched_us+evict_threshold_us <= check_time_us &&
n->last_user_clock_idx_touched+evict_threshold_user_clocks <= check_time_user_clocks &&
n->load_count != 0 &&
n->is_working == 0)
{
slot_has_work = 1;
break;
}
if(n->change_gen != 0 && n->change_gen != change_gen &&
n->last_time_requested_us+retry_threshold_us <= check_time_us &&
n->last_user_clock_idx_requested+retry_threshold_user_clocks <= check_time_user_clocks)
{
slot_has_work = 1;
break;
}
}
}
if(slot_has_work) OS_MutexScopeW(stripe->rw_mutex)
{
for(DASM_Node *n = slot->first, *next = 0; n != 0; n = next)
{
next = n->next;
if(n->scope_ref_count == 0 &&
n->last_time_touched_us+evict_threshold_us <= check_time_us &&
n->last_user_clock_idx_touched+evict_threshold_user_clocks <= check_time_user_clocks &&
n->load_count != 0 &&
n->is_working == 0)
{
DLLRemove(slot->first, slot->last, n);
if(n->info_arena != 0)
{
arena_release(n->info_arena);
}
SLLStackPush(stripe->free_node, n);
}
if(n->change_gen != 0 && n->change_gen != change_gen &&
n->last_time_requested_us+retry_threshold_us <= check_time_us &&
n->last_user_clock_idx_requested+retry_threshold_user_clocks <= check_time_user_clocks)
{
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_user_clock_idx_requested = check_time_user_clocks;
}
}
}
}
}
os_sleep_milliseconds(100);
}
}
+38 -80
View File
@@ -1,56 +1,55 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
//////////////////////////////// ////////////////////////////////
//~ rjf: Built-In Command Tables //~ rjf: Built-In Command Tables
@table(name ui_vis ipc_docs_vis q_slot q_view q_ent_kind q_ctrl_ent_kind q_allow_files q_allow_folders q_keep_oi q_select_oi q_is_code q_required canonical_icon string display_name desc search_tags ) @table(name ui_vis ipc_docs_vis text_pt_vis text_rng_vis q_expr q_slot q_view q_ent_kind q_ctrl_ent_kind q_allow_files q_allow_folders q_keep_oi q_select_oi q_is_code q_floating q_required canonical_icon string display_name desc search_tags ctx_filter)
// / | | | \___ _________________________________/ | | | | | // / | | | | | | \___ _________________________________/ | | | | | |
// / | | | \ / | | | | | // / | | | | | | \ / | | | | | |
D_CmdTable: // | | | | | | | | | | D_CmdTable: // | | | | | | | | | | | | | |
{ {
//- rjf: low-level target control operations //- rjf: low-level target control operations
{LaunchAndRun 1 1 Entity null Target Null 0 0 0 0 0 1 Play "launch_and_run" "Launch and Run" "Starts debugging a new instance of a target, then runs." "launch,start,run,target" } {LaunchAndRun 1 1 0 0 "query:targets" Cfg null Target Null 0 0 0 0 0 1 1 Play "launch_and_run" "Launch and Run" "Starts debugging a new instance of a target, then runs." "launch,start,run,target" "" }
{LaunchAndInit 1 1 Entity null Target Null 0 0 0 0 0 1 PlayStepForward "launch_and_init" "Launch and Initialize" "Starts debugging a new instance of a target, then stops at the program's entry point." "launch,start,entry,point" } {LaunchAndStepInto 1 1 0 0 "query:targets" Cfg null Target Null 0 0 0 0 0 1 1 PlayStepForward "launch_and_step_into" "Launch and Step Into" "Starts debugging a new instance of a target, then stops at the program's entry point." "launch,start,entry,point" "" }
{Kill 1 1 Process null Nil Process 0 0 0 0 0 1 X "kill" "Kill" "Kills the specified existing attached process(es)." "stop,kill" } {Kill 1 1 0 0 "query:processes" Process null Nil Process 0 0 0 0 0 1 1 X "kill" "Kill" "Kills the specified existing attached process(es)." "stop,kill" "" }
{KillAll 1 1 Null null Nil Null 0 0 0 0 0 0 Stop "kill_all" "Kill All" "Kills all attached processes." "stop,kill,all" } {KillAll 1 1 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 Stop "kill_all" "Kill All" "Kills all attached processes." "stop,kill,all" "" }
{Detach 1 1 Process null Nil Process 0 0 0 0 0 1 Null "detach" "Detach" "Detaches the specified attached process(es)." "detach" } {Detach 1 1 0 0 "query:processes" Process null Nil Process 0 0 0 0 0 1 1 Null "detach" "Detach" "Detaches the specified attached process(es)." "detach" "" }
{Continue 1 1 Null null Nil Null 0 0 0 0 0 0 Play "continue" "Continue" "Continues executing all attached processes." "" } {Continue 1 1 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 Play "continue" "Continue" "Continues executing all attached processes." "" "" }
{StepIntoInst 1 1 Null null Nil Null 0 0 0 0 0 0 StepInto "step_into_inst" "Step Into (Assembly)" "Performs a step that goes into calls, at the instruction level." "single,step,thread" } {StepIntoInst 1 1 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 StepInto "step_into_inst" "Step Into (Assembly)" "Performs a step that goes into calls, at the instruction level." "single,step,thread" "" }
{StepOverInst 1 1 Null null Nil Null 0 0 0 0 0 0 StepOver "step_over_inst" "Step Over (Assembly)" "Performs a step that skips calls, at the instruction level." "single,step,thread" } {StepOverInst 1 1 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 StepOver "step_over_inst" "Step Over (Assembly)" "Performs a step that skips calls, at the instruction level." "single,step,thread" "" }
{StepIntoLine 1 1 Null null Nil Null 0 0 0 0 0 0 StepInto "step_into_line" "Step Into (Line)" "Performs a step that goes into calls, at the source code line level." "step,thread" } {StepIntoLine 1 1 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 StepInto "step_into_line" "Step Into (Line)" "Performs a step that goes into calls, at the source code line level." "step,thread" "" }
{StepOverLine 1 1 Null null Nil Null 0 0 0 0 0 0 StepOver "step_over_line" "Step Over (Line)" "Performs a step that skips calls, at the source code line level." "step,thread" } {StepOverLine 1 1 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 StepOver "step_over_line" "Step Over (Line)" "Performs a step that skips calls, at the source code line level." "step,thread" "" }
{StepOut 1 1 Null null Nil Null 0 0 0 0 0 0 StepOut "step_out" "Step Out" "Runs to the end of the current function and exits it." "" } {StepOut 1 1 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 StepOut "step_out" "Step Out" "Runs to the end of the current function and exits it." "" "" }
{Halt 1 1 Null null Nil Null 0 0 0 0 0 0 Pause "halt" "Halt" "Halts all attached processes." "pause" } {Halt 1 1 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 Pause "halt" "Halt" "Halts all attached processes." "pause" "" }
{SoftHaltRefresh 1 1 Null null Nil Null 0 0 0 0 0 0 Refresh "soft_halt_refresh" "Soft Halt Refresh" "Interrupts all attached processes to collect data, and then resumes them." "" } {SoftHaltRefresh 0 0 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 Refresh "soft_halt_refresh" "Soft Halt Refresh" "Interrupts all attached processes to collect data, and then resumes them." "" "" }
{SetThreadIP 0 1 Vaddr null Nil Null 0 0 0 0 1 1 Null "set_thread_ip" "Set Thread IP" "Sets the specified thread's instruction pointer at the specified address." "" } {SetThreadIP 0 1 0 0 "" Vaddr null Nil Null 0 0 0 0 1 1 1 Null "set_thread_ip" "Set Thread IP" "Sets the specified thread's instruction pointer at the specified address." "" "" }
//- rjf: high-level composite target control operations //- rjf: high-level composite target control operations
{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 1 1 1 0 "" Null null Nil Null 0 0 0 0 0 0 0 Play "run_to_line" "Run To Line" "Runs until a particular source line is hit." "" "$text_pt," }
{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 0 0 "" Null null Nil Null 0 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 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 Redo "restart" "Restart" "Kills all attached processes, then launches all active targets." "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 0 0 "" Null null Nil Null 0 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 0 0 "" Null null Nil Null 0 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 0 0 "query:threads" Thread null Nil Thread 0 0 0 0 0 1 1 Locked "freeze_thread" "Freeze Thread" "Freezes the passed thread." "callstack,unwind" "" }
{ThawThread 1 1 Thread null Nil Thread 0 0 0 0 0 1 Unlocked "thaw_thread" "Thaw Thread" "Thaws the passed thread." "" } {ThawThread 1 1 0 0 "query:threads" Thread null Nil Thread 0 0 0 0 0 1 1 Unlocked "thaw_thread" "Thaw Thread" "Thaws the passed thread." "" "" }
{FreezeProcess 1 1 Process null Nil Process 0 0 0 0 0 1 Locked "freeze_process" "Freeze Process" "Freezes the passed process." "" } {FreezeProcess 1 1 0 0 "query:processes" Process null Nil Process 0 0 0 0 0 1 1 Locked "freeze_process" "Freeze Process" "Freezes the passed process." "" "" }
{ThawProcess 1 1 Process null Nil Process 0 0 0 0 0 1 Unlocked "thaw_process" "Thaw Process" "Thaws the passed process." "" } {ThawProcess 1 1 0 0 "query:processes" Process null Nil Process 0 0 0 0 0 1 1 Unlocked "thaw_process" "Thaw Process" "Thaws the passed process." "" "" }
{FreezeMachine 0 1 Machine null Nil Machine 0 0 0 0 0 1 Locked "freeze_machine" "Freeze Machine" "Freezes the passed machine." "" } {FreezeMachine 0 1 0 0 "query:machines" Machine null Nil Machine 0 0 0 0 0 1 1 Locked "freeze_machine" "Freeze Machine" "Freezes the passed machine." "" "" }
{ThawMachine 0 1 Machine null Nil Machine 0 0 0 0 0 1 Unlocked "thaw_machine" "Thaw Machine" "Thaws the passed machine." "" } {ThawMachine 0 1 0 0 "query:machines" Machine null Nil Machine 0 0 0 0 0 1 1 Unlocked "thaw_machine" "Thaw Machine" "Thaws the passed machine." "" "" }
{FreezeLocalMachine 1 1 Null null Nil Null 0 0 0 0 0 0 Machine "freeze_local_machine" "Freeze Local Machine" "Freezes the local machine." "" } {FreezeLocalMachine 1 1 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 Machine "freeze_local_machine" "Freeze Local Machine" "Freezes the local machine." "" "" }
{ThawLocalMachine 1 1 Null null Nil Null 0 0 0 0 0 0 Machine "thaw_local_machine" "Thaw Local Machine" "Thaws the local machine." "" } {ThawLocalMachine 1 1 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 Machine "thaw_local_machine" "Thaw Local Machine" "Thaws the local machine." "" "" }
{FreezeEntity 0 0 Null null Nil Null 0 0 0 0 0 0 Null "freeze_entity" "Freeze Entity" "Freezes an entity." "" } {FreezeEntity 0 0 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 Unlocked "freeze_entity" "Freeze Entity" "Freezes an entity." "" "" }
{ThawEntity 0 0 Null null Nil Null 0 0 0 0 0 0 Null "thaw_entity" "Thaw Entity" "Thaws an entity." "" } {ThawEntity 0 0 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 Locked "thaw_entity" "Thaw Entity" "Thaws an entity." "" "" }
//- rjf: entity decoration //- rjf: entity decoration
{SetEntityColor 0 0 Null null Nil Null 0 0 0 0 0 0 Null "set_entity_color" "Set Entity Color" "Sets the passed entity's color." "" } {SetEntityColor 0 0 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 Null "set_entity_color" "Set Entity Color" "Sets the passed entity's color." "" "" }
{SetEntityName 0 0 Null null Nil Null 0 0 0 0 0 0 Null "set_entity_name" "Set Entity Name" "Sets the passed entity's name." "" } {SetEntityName 0 0 0 0 "" Null null Nil Null 0 0 0 0 0 0 0 Null "set_entity_name" "Set Entity Name" "Sets the passed entity's name." "" "" }
//- rjf: attaching //- rjf: attaching
{Attach 1 1 PID null Nil Null 0 0 0 0 0 1 Null "attach" "Attach" "Attaches to a process that is already running on the local machine." "" } {Attach 1 1 0 0 "query:unattached_processes" PID null Nil Null 0 0 0 0 0 1 1 Null "attach" "Attach" "Attaches to a process that is already running on the local machine." "" "" }
} }
@enum D_CmdKind: @enum D_CmdKind:
@@ -60,53 +59,13 @@ D_CmdTable: // | | | |
COUNT, COUNT,
} }
////////////////////////////////
//~ rjf: Built-In VieNull w Rules
@table(coverage_check name name_lower string ih ex xp vb display_name docs schema description)
D_ViewRuleTable:
{
{x Default default "default" - - - x "Default" - "" "" }
{x Array array "array" - - x - "Array" x "x:{expr}" "Specifies that a pointer points to N elements, rather than only 1." }
{x Slice slice "slice" - - x - "Slice" x "" "Specifies that a pointer within a struct, also containing an integer, points to the number of elements encoded by the integer." }
{- List list "list" - - - x "List" - "x:{member}" "Specifies that some struct, union, or class forms the top of a linked list, and the member which points at the following element in the list." }
{x ByteSwap bswap "bswap" x - x - "Byte Swap" x "" "Specifies that all integral evaluations should be byte-swapped, such that their endianness is reversed." }
{x Cast cast "cast" - - x - "Cast" x "x:{type}" "Specifies that the expression to which the view rule is applied should be casted to the provided type." }
{- BaseDec base_dec "dec" x - - - "Decimal Base (Base 10)" x "" "Specifies that all integral evaluations should appear in base-10 form." }
{- BaseBin base_bin "bin" x - - - "Binary Base (Base 2)" x "" "Specifies that all integral evaluations should appear in base-2 form." }
{- BaseOct base_oct "oct" x - - - "Octal Base (Base 8)" x "" "Specifies that all integral evaluations should appear in base-8 form." }
{- BaseHex base_hex "hex" x - - - "Hexadecimal Base (Base 16)" x "" "Specifies that all integral evaluations should appear in base-16 form." }
{- Only only "only" x - - x "Only Specified Members" x "x:{member}" "Specifies that only the specified members should appear in struct, union, or class evaluations." }
{- Omit omit "omit" x - - x "Omit Specified Members" x "x:{member}" "Omits a list of member names from appearing in struct, union, or class evaluations." }
{- NoAddr no_addr "no_addr" x - - - "Disable Address Values" x "" "Displays only what pointers point to, if possible, without the pointer's address value." }
{x Checkbox checkbox "checkbox" - - - - "Checkbox" x "" "Displays simple integer values as checkboxes, encoding zero or nonzero values." }
{- ColorRGBA color_rgba "color_rgba" - x - x "Color (RGBA)" x "" "Displays as a color, interpreting the data as encoding R, G, B, and A values." }
{x Text text "text" - x - x "Text" x "x:{'lang':lang, 'size':expr}" "Displays as text." }
{x Disasm disasm "disasm" - x - x "Disassembly" x "x:{'arch':arch, 'size':expr}" "Displays as disassembled instructions, interpreting the data as raw machine code." }
{x Memory memory "memory" - x - x "Memory" x "x:{'size':expr}" "Displays as a raw memory grid." }
{- Graph graph "graph" - x - x "Graph" x "" "Displays as a pointer graph, visualizing nodes and edges formed by pointers directly." }
{x Bitmap bitmap "bitmap" - x - x "Bitmap" x "x:{'w':expr, 'h':expr, 'fmt':tex2dformat}" "Displays as a bitmap, interpreting the data as raw pixel data." }
{- Geo3D geo3d "geo3d" - x - x "Geometry (3D)" x "x:{'count':expr, 'vtx':expr, 'vtx_size':expr}" "Displays as geometry, interpreting the data as index or vertex data." }
}
@enum D_ViewRuleKind:
{
@expand(D_ViewRuleTable a) `$(a.name)`,
COUNT,
}
@data(D_ViewRuleSpecInfo) @c_file d_core_view_rule_spec_info_table:
{
@expand(D_ViewRuleTable a)
```{str8_lit_comp("$(a.string)"), str8_lit_comp("$(a.display_name)"), str8_lit_comp("$(a.schema)"), str8_lit_comp("$(a.description)"), (D_ViewRuleSpecInfoFlag_Inherited*$(a.ih == "x"))|(D_ViewRuleSpecInfoFlag_Expandable*$(a.ex == "x"))|(D_ViewRuleSpecInfoFlag_ExprResolution*$(a.xp == "x"))|(D_ViewRuleSpecInfoFlag_VizBlockProd*$(a.vb == "x")), }```;
}
//////////////////////////////// ////////////////////////////////
//~ rjf: Developer Toggles //~ rjf: Developer Toggles
@table(name) @table(name)
D_DevToggleTable: D_DevToggleTable:
{ {
{always_refresh}
{simulate_lag} {simulate_lag}
{draw_ui_text_pos} {draw_ui_text_pos}
{draw_ui_focus_debug} {draw_ui_focus_debug}
@@ -114,7 +73,6 @@ D_DevToggleTable:
{eval_compiler_tooltips} {eval_compiler_tooltips}
{eval_watch_key_tooltips} {eval_watch_key_tooltips}
{cmd_context_tooltips} {cmd_context_tooltips}
{scratch_mouse_draw}
{updating_indicator} {updating_indicator}
} }
File diff suppressed because it is too large. Load diff
+38 -99
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DBG_ENGINE_CORE_H #ifndef DBG_ENGINE_CORE_H
@@ -28,14 +28,24 @@ struct D_TargetArray
U64 count; U64 count;
}; };
typedef U32 D_BreakpointFlags;
enum
{
D_BreakpointFlag_BreakOnWrite = (1<<0),
D_BreakpointFlag_BreakOnRead = (1<<1),
D_BreakpointFlag_BreakOnExecute = (1<<2),
};
typedef struct D_Breakpoint D_Breakpoint; typedef struct D_Breakpoint D_Breakpoint;
struct D_Breakpoint struct D_Breakpoint
{ {
D_BreakpointFlags flags;
U64 id;
String8 file_path; String8 file_path;
TxtPt pt; TxtPt pt;
String8 symbol_name; String8 vaddr_expr;
U64 vaddr;
String8 condition; String8 condition;
U64 size;
}; };
typedef struct D_BreakpointArray D_BreakpointArray; typedef struct D_BreakpointArray D_BreakpointArray;
@@ -59,12 +69,24 @@ struct D_PathMapArray
U64 count; U64 count;
}; };
////////////////////////////////
//~ rjf: Trap Nets
typedef struct D_TrapNet D_TrapNet;
struct D_TrapNet
{
CTRL_TrapList traps;
B32 good_line_info;
B32 good_read;
};
//////////////////////////////// ////////////////////////////////
//~ rjf: Tick Output Types //~ rjf: Tick Output Types
typedef enum D_EventKind typedef enum D_EventKind
{ {
D_EventKind_Null, D_EventKind_Null,
D_EventKind_ModuleLoad,
D_EventKind_ProcessEnd, D_EventKind_ProcessEnd,
D_EventKind_Stop, D_EventKind_Stop,
D_EventKind_COUNT D_EventKind_COUNT
@@ -76,6 +98,7 @@ typedef enum D_EventCause
D_EventCause_Null, D_EventCause_Null,
D_EventCause_UserBreakpoint, D_EventCause_UserBreakpoint,
D_EventCause_Halt, D_EventCause_Halt,
D_EventCause_SoftHalt,
D_EventCause_COUNT D_EventCause_COUNT
} }
D_EventCause; D_EventCause;
@@ -85,9 +108,11 @@ struct D_Event
{ {
D_EventKind kind; D_EventKind kind;
D_EventCause cause; D_EventCause cause;
CTRL_Handle module;
CTRL_Handle thread; CTRL_Handle thread;
U64 vaddr; U64 vaddr;
U64 code; U64 code;
U64 id;
}; };
typedef struct D_EventNode D_EventNode; typedef struct D_EventNode D_EventNode;
@@ -157,42 +182,6 @@ D_RunKind;
#include "dbg_engine/generated/dbg_engine.meta.h" #include "dbg_engine/generated/dbg_engine.meta.h"
////////////////////////////////
//~ rjf: View Rules
typedef U32 D_ViewRuleSpecInfoFlags; // NOTE(rjf): see @view_rule_info
enum
{
D_ViewRuleSpecInfoFlag_Inherited = (1<<0),
D_ViewRuleSpecInfoFlag_Expandable = (1<<1),
D_ViewRuleSpecInfoFlag_ExprResolution = (1<<2),
D_ViewRuleSpecInfoFlag_VizBlockProd = (1<<3),
};
typedef struct D_ViewRuleSpecInfo D_ViewRuleSpecInfo;
struct D_ViewRuleSpecInfo
{
String8 string;
String8 display_string;
String8 schema;
String8 description;
D_ViewRuleSpecInfoFlags flags;
};
typedef struct D_ViewRuleSpecInfoArray D_ViewRuleSpecInfoArray;
struct D_ViewRuleSpecInfoArray
{
D_ViewRuleSpecInfo *v;
U64 count;
};
typedef struct D_ViewRuleSpec D_ViewRuleSpec;
struct D_ViewRuleSpec
{
D_ViewRuleSpec *hash_next;
D_ViewRuleSpecInfo info;
};
//////////////////////////////// ////////////////////////////////
//~ rjf: Command Types //~ rjf: Command Types
@@ -211,6 +200,7 @@ struct D_CmdParams
U32 pid; U32 pid;
U32 rgba; U32 rgba;
D_TargetArray targets; D_TargetArray targets;
U64 retry_idx;
}; };
typedef struct D_Cmd D_Cmd; typedef struct D_Cmd D_Cmd;
@@ -239,35 +229,6 @@ struct D_CmdList
//////////////////////////////// ////////////////////////////////
//~ rjf: Main State Caches //~ rjf: Main State Caches
//- rjf: per-thread unwind cache
typedef struct D_UnwindCacheNode D_UnwindCacheNode;
struct D_UnwindCacheNode
{
D_UnwindCacheNode *next;
D_UnwindCacheNode *prev;
U64 reggen;
U64 memgen;
Arena *arena;
CTRL_Handle thread;
CTRL_Unwind unwind;
};
typedef struct D_UnwindCacheSlot D_UnwindCacheSlot;
struct D_UnwindCacheSlot
{
D_UnwindCacheNode *first;
D_UnwindCacheNode *last;
};
typedef struct D_UnwindCache D_UnwindCache;
struct D_UnwindCache
{
U64 slots_count;
D_UnwindCacheSlot *slots;
D_UnwindCacheNode *free_node;
};
//- rjf: per-run tls-base-vaddr cache //- rjf: per-run tls-base-vaddr cache
typedef struct D_RunTLSBaseCacheNode D_RunTLSBaseCacheNode; typedef struct D_RunTLSBaseCacheNode D_RunTLSBaseCacheNode;
@@ -330,17 +291,15 @@ struct D_State
// rjf: top-level state // rjf: top-level state
Arena *arena; Arena *arena;
U64 frame_index; U64 frame_index;
U64 frame_eval_memread_endt_us;
// rjf: commands // rjf: commands
Arena *cmds_arena; Arena *cmds_arena;
D_CmdList cmds; D_CmdList cmds;
// rjf: output log key // rjf: output log key
U128 output_log_key; C_Key output_log_key;
// rjf: per-run caches // rjf: per-run caches
D_UnwindCache unwind_cache;
U64 tls_base_cache_reggen_idx; U64 tls_base_cache_reggen_idx;
U64 tls_base_cache_memgen_idx; U64 tls_base_cache_memgen_idx;
D_RunTLSBaseCache tls_base_caches[2]; D_RunTLSBaseCache tls_base_caches[2];
@@ -352,10 +311,6 @@ struct D_State
D_RunLocalsCache member_caches[2]; D_RunLocalsCache member_caches[2];
U64 member_cache_gen; U64 member_cache_gen;
// rjf: view rule specification table
U64 view_rule_spec_table_size;
D_ViewRuleSpec **view_rule_spec_table;
// rjf: user -> ctrl driving state // rjf: user -> ctrl driving state
Arena *ctrl_last_run_arena; Arena *ctrl_last_run_arena;
D_RunKind ctrl_last_run_kind; D_RunKind ctrl_last_run_kind;
@@ -372,7 +327,7 @@ struct D_State
CTRL_MsgList ctrl_msgs; CTRL_MsgList ctrl_msgs;
// rjf: ctrl -> user reading state // rjf: ctrl -> user reading state
CTRL_EntityStore *ctrl_entity_store; CTRL_EntityCtxRWStore *ctrl_entity_store;
Arena *ctrl_stop_arena; Arena *ctrl_stop_arena;
CTRL_Event ctrl_last_stop_event; CTRL_Event ctrl_last_stop_event;
}; };
@@ -380,7 +335,6 @@ struct D_State
//////////////////////////////// ////////////////////////////////
//~ rjf: Globals //~ rjf: Globals
read_only global D_ViewRuleSpec d_nil_core_view_rule_spec = {0};
global D_State *d_state = 0; global D_State *d_state = 0;
//////////////////////////////// ////////////////////////////////
@@ -415,32 +369,18 @@ internal D_CmdParams d_cmd_params_copy(Arena *arena, D_CmdParams *src);
//- rjf: command lists //- rjf: command lists
internal void d_cmd_list_push_new(Arena *arena, D_CmdList *cmds, D_CmdKind kind, D_CmdParams *params); internal void d_cmd_list_push_new(Arena *arena, D_CmdList *cmds, D_CmdKind kind, D_CmdParams *params);
////////////////////////////////
//~ rjf: View Rule Spec Stateful Functions
internal void d_register_view_rule_specs(D_ViewRuleSpecInfoArray specs);
internal D_ViewRuleSpec *d_view_rule_spec_from_string(String8 string);
//////////////////////////////// ////////////////////////////////
//~ rjf: Stepping "Trap Net" Builders //~ rjf: Stepping "Trap Net" Builders
internal CTRL_TrapList d_trap_net_from_thread__step_over_inst(Arena *arena, CTRL_Entity *thread); internal D_TrapNet d_trap_net_from_thread__step_over_inst(Arena *arena, CTRL_Entity *thread);
internal CTRL_TrapList d_trap_net_from_thread__step_over_line(Arena *arena, CTRL_Entity *thread); internal D_TrapNet d_trap_net_from_thread__step_over_line(Arena *arena, CTRL_Entity *thread);
internal CTRL_TrapList d_trap_net_from_thread__step_into_line(Arena *arena, CTRL_Entity *thread); internal D_TrapNet d_trap_net_from_thread__step_into_line(Arena *arena, CTRL_Entity *thread);
//////////////////////////////// ////////////////////////////////
//~ rjf: Debug Info Lookups //~ rjf: Debug Info Lookups
//- rjf: voff|vaddr -> symbol lookups
internal String8 d_symbol_name_from_dbgi_key_voff(Arena *arena, DI_Key *dbgi_key, U64 voff, B32 decorated);
internal String8 d_symbol_name_from_process_vaddr(Arena *arena, CTRL_Entity *process, U64 vaddr, B32 decorated);
//- rjf: symbol -> voff lookups
internal U64 d_voff_from_dbgi_key_symbol_name(DI_Key *dbgi_key, String8 symbol_name);
internal U64 d_type_num_from_dbgi_key_name(DI_Key *dbgi_key, String8 name);
//- rjf: voff -> line info //- rjf: voff -> line info
internal D_LineList d_lines_from_dbgi_key_voff(Arena *arena, DI_Key *dbgi_key, U64 voff); internal D_LineList d_lines_from_dbgi_key_voff(Arena *arena, DI_Key dbgi_key, U64 voff);
//- 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
@@ -476,12 +416,11 @@ internal B32 d_ctrl_targets_running(void);
internal DI_KeyList d_push_active_dbgi_key_list(Arena *arena); internal DI_KeyList d_push_active_dbgi_key_list(Arena *arena);
//- rjf: per-run caches //- rjf: per-run caches
internal CTRL_Unwind d_query_cached_unwind_from_thread(CTRL_Entity *thread);
internal U64 d_query_cached_rip_from_thread(CTRL_Entity *thread); internal U64 d_query_cached_rip_from_thread(CTRL_Entity *thread);
internal U64 d_query_cached_rip_from_thread_unwind(CTRL_Entity *thread, U64 unwind_count); internal U64 d_query_cached_rip_from_thread_unwind(CTRL_Entity *thread, U64 unwind_count);
internal U64 d_query_cached_tls_base_vaddr_from_process_root_rip(CTRL_Entity *process, U64 root_vaddr, U64 rip_vaddr); internal U64 d_query_cached_tls_base_vaddr_from_process_root_rip(CTRL_Entity *process, U64 root_vaddr, U64 rip_vaddr);
internal E_String2NumMap *d_query_cached_locals_map_from_dbgi_key_voff(DI_Key *dbgi_key, U64 voff); internal E_String2NumMap *d_query_cached_locals_map_from_dbgi_key_voff(DI_Key dbgi_key, U64 voff);
internal E_String2NumMap *d_query_cached_member_map_from_dbgi_key_voff(DI_Key *dbgi_key, U64 voff); internal E_String2NumMap *d_query_cached_member_map_from_dbgi_key_voff(DI_Key dbgi_key, U64 voff);
//- rjf: top-level command dispatch //- rjf: top-level command dispatch
internal void d_push_cmd(D_CmdKind kind, D_CmdParams *params); internal void d_push_cmd(D_CmdKind kind, D_CmdParams *params);
@@ -494,6 +433,6 @@ internal B32 d_next_cmd(D_Cmd **cmd);
//~ rjf: Main Layer Top-Level Calls //~ rjf: Main Layer Top-Level Calls
internal void d_init(void); internal void d_init(void);
internal D_EventList d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_PathMapArray *path_maps, U64 exception_code_filters[(CTRL_ExceptionCodeKind_COUNT+63)/64], CTRL_MetaEvalArray *meta_evals); internal D_EventList d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_PathMapArray *path_maps, U64 exception_code_filters[(CTRL_ExceptionCodeKind_COUNT+63)/64]);
#endif // DBG_ENGINE_CORE_H #endif // DBG_ENGINE_CORE_H
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#include "dbg_engine_core.c" #include "dbg_engine_core.c"
+1 -1
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DBG_ENGINE_INC_H #ifndef DBG_ENGINE_INC_H
+1 -29
View File
@@ -1,33 +1,5 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE //- GENERATED CODE
C_LINKAGE_BEGIN
D_ViewRuleSpecInfo d_core_view_rule_spec_info_table[21] =
{
{str8_lit_comp("default"), str8_lit_comp("Default"), str8_lit_comp(""), str8_lit_comp(""), (D_ViewRuleSpecInfoFlag_Inherited*0)|(D_ViewRuleSpecInfoFlag_Expandable*0)|(D_ViewRuleSpecInfoFlag_ExprResolution*0)|(D_ViewRuleSpecInfoFlag_VizBlockProd*1), },
{str8_lit_comp("array"), str8_lit_comp("Array"), str8_lit_comp("x:{expr}"), str8_lit_comp("Specifies that a pointer points to N elements, rather than only 1."), (D_ViewRuleSpecInfoFlag_Inherited*0)|(D_ViewRuleSpecInfoFlag_Expandable*0)|(D_ViewRuleSpecInfoFlag_ExprResolution*1)|(D_ViewRuleSpecInfoFlag_VizBlockProd*0), },
{str8_lit_comp("slice"), str8_lit_comp("Slice"), str8_lit_comp(""), str8_lit_comp("Specifies that a pointer within a struct, also containing an integer, points to the number of elements encoded by the integer."), (D_ViewRuleSpecInfoFlag_Inherited*0)|(D_ViewRuleSpecInfoFlag_Expandable*0)|(D_ViewRuleSpecInfoFlag_ExprResolution*1)|(D_ViewRuleSpecInfoFlag_VizBlockProd*0), },
{str8_lit_comp("list"), str8_lit_comp("List"), str8_lit_comp("x:{member}"), str8_lit_comp("Specifies that some struct, union, or class forms the top of a linked list, and the member which points at the following element in the list."), (D_ViewRuleSpecInfoFlag_Inherited*0)|(D_ViewRuleSpecInfoFlag_Expandable*0)|(D_ViewRuleSpecInfoFlag_ExprResolution*0)|(D_ViewRuleSpecInfoFlag_VizBlockProd*1), },
{str8_lit_comp("bswap"), str8_lit_comp("Byte Swap"), str8_lit_comp(""), str8_lit_comp("Specifies that all integral evaluations should be byte-swapped, such that their endianness is reversed."), (D_ViewRuleSpecInfoFlag_Inherited*1)|(D_ViewRuleSpecInfoFlag_Expandable*0)|(D_ViewRuleSpecInfoFlag_ExprResolution*1)|(D_ViewRuleSpecInfoFlag_VizBlockProd*0), },
{str8_lit_comp("cast"), str8_lit_comp("Cast"), str8_lit_comp("x:{type}"), str8_lit_comp("Specifies that the expression to which the view rule is applied should be casted to the provided type."), (D_ViewRuleSpecInfoFlag_Inherited*0)|(D_ViewRuleSpecInfoFlag_Expandable*0)|(D_ViewRuleSpecInfoFlag_ExprResolution*1)|(D_ViewRuleSpecInfoFlag_VizBlockProd*0), },
{str8_lit_comp("dec"), str8_lit_comp("Decimal Base (Base 10)"), str8_lit_comp(""), str8_lit_comp("Specifies that all integral evaluations should appear in base-10 form."), (D_ViewRuleSpecInfoFlag_Inherited*1)|(D_ViewRuleSpecInfoFlag_Expandable*0)|(D_ViewRuleSpecInfoFlag_ExprResolution*0)|(D_ViewRuleSpecInfoFlag_VizBlockProd*0), },
{str8_lit_comp("bin"), str8_lit_comp("Binary Base (Base 2)"), str8_lit_comp(""), str8_lit_comp("Specifies that all integral evaluations should appear in base-2 form."), (D_ViewRuleSpecInfoFlag_Inherited*1)|(D_ViewRuleSpecInfoFlag_Expandable*0)|(D_ViewRuleSpecInfoFlag_ExprResolution*0)|(D_ViewRuleSpecInfoFlag_VizBlockProd*0), },
{str8_lit_comp("oct"), str8_lit_comp("Octal Base (Base 8)"), str8_lit_comp(""), str8_lit_comp("Specifies that all integral evaluations should appear in base-8 form."), (D_ViewRuleSpecInfoFlag_Inherited*1)|(D_ViewRuleSpecInfoFlag_Expandable*0)|(D_ViewRuleSpecInfoFlag_ExprResolution*0)|(D_ViewRuleSpecInfoFlag_VizBlockProd*0), },
{str8_lit_comp("hex"), str8_lit_comp("Hexadecimal Base (Base 16)"), str8_lit_comp(""), str8_lit_comp("Specifies that all integral evaluations should appear in base-16 form."), (D_ViewRuleSpecInfoFlag_Inherited*1)|(D_ViewRuleSpecInfoFlag_Expandable*0)|(D_ViewRuleSpecInfoFlag_ExprResolution*0)|(D_ViewRuleSpecInfoFlag_VizBlockProd*0), },
{str8_lit_comp("only"), str8_lit_comp("Only Specified Members"), str8_lit_comp("x:{member}"), str8_lit_comp("Specifies that only the specified members should appear in struct, union, or class evaluations."), (D_ViewRuleSpecInfoFlag_Inherited*1)|(D_ViewRuleSpecInfoFlag_Expandable*0)|(D_ViewRuleSpecInfoFlag_ExprResolution*0)|(D_ViewRuleSpecInfoFlag_VizBlockProd*1), },
{str8_lit_comp("omit"), str8_lit_comp("Omit Specified Members"), str8_lit_comp("x:{member}"), str8_lit_comp("Omits a list of member names from appearing in struct, union, or class evaluations."), (D_ViewRuleSpecInfoFlag_Inherited*1)|(D_ViewRuleSpecInfoFlag_Expandable*0)|(D_ViewRuleSpecInfoFlag_ExprResolution*0)|(D_ViewRuleSpecInfoFlag_VizBlockProd*1), },
{str8_lit_comp("no_addr"), str8_lit_comp("Disable Address Values"), str8_lit_comp(""), str8_lit_comp("Displays only what pointers point to, if possible, without the pointer's address value."), (D_ViewRuleSpecInfoFlag_Inherited*1)|(D_ViewRuleSpecInfoFlag_Expandable*0)|(D_ViewRuleSpecInfoFlag_ExprResolution*0)|(D_ViewRuleSpecInfoFlag_VizBlockProd*0), },
{str8_lit_comp("checkbox"), str8_lit_comp("Checkbox"), str8_lit_comp(""), str8_lit_comp("Displays simple integer values as checkboxes, encoding zero or nonzero values."), (D_ViewRuleSpecInfoFlag_Inherited*0)|(D_ViewRuleSpecInfoFlag_Expandable*0)|(D_ViewRuleSpecInfoFlag_ExprResolution*0)|(D_ViewRuleSpecInfoFlag_VizBlockProd*0), },
{str8_lit_comp("color_rgba"), str8_lit_comp("Color (RGBA)"), str8_lit_comp(""), str8_lit_comp("Displays as a color, interpreting the data as encoding R, G, B, and A values."), (D_ViewRuleSpecInfoFlag_Inherited*0)|(D_ViewRuleSpecInfoFlag_Expandable*1)|(D_ViewRuleSpecInfoFlag_ExprResolution*0)|(D_ViewRuleSpecInfoFlag_VizBlockProd*1), },
{str8_lit_comp("text"), str8_lit_comp("Text"), str8_lit_comp("x:{'lang':lang, 'size':expr}"), str8_lit_comp("Displays as text."), (D_ViewRuleSpecInfoFlag_Inherited*0)|(D_ViewRuleSpecInfoFlag_Expandable*1)|(D_ViewRuleSpecInfoFlag_ExprResolution*0)|(D_ViewRuleSpecInfoFlag_VizBlockProd*1), },
{str8_lit_comp("disasm"), str8_lit_comp("Disassembly"), str8_lit_comp("x:{'arch':arch, 'size':expr}"), str8_lit_comp("Displays as disassembled instructions, interpreting the data as raw machine code."), (D_ViewRuleSpecInfoFlag_Inherited*0)|(D_ViewRuleSpecInfoFlag_Expandable*1)|(D_ViewRuleSpecInfoFlag_ExprResolution*0)|(D_ViewRuleSpecInfoFlag_VizBlockProd*1), },
{str8_lit_comp("memory"), str8_lit_comp("Memory"), str8_lit_comp("x:{'size':expr}"), str8_lit_comp("Displays as a raw memory grid."), (D_ViewRuleSpecInfoFlag_Inherited*0)|(D_ViewRuleSpecInfoFlag_Expandable*1)|(D_ViewRuleSpecInfoFlag_ExprResolution*0)|(D_ViewRuleSpecInfoFlag_VizBlockProd*1), },
{str8_lit_comp("graph"), str8_lit_comp("Graph"), str8_lit_comp(""), str8_lit_comp("Displays as a pointer graph, visualizing nodes and edges formed by pointers directly."), (D_ViewRuleSpecInfoFlag_Inherited*0)|(D_ViewRuleSpecInfoFlag_Expandable*1)|(D_ViewRuleSpecInfoFlag_ExprResolution*0)|(D_ViewRuleSpecInfoFlag_VizBlockProd*1), },
{str8_lit_comp("bitmap"), str8_lit_comp("Bitmap"), str8_lit_comp("x:{'w':expr, 'h':expr, 'fmt':tex2dformat}"), str8_lit_comp("Displays as a bitmap, interpreting the data as raw pixel data."), (D_ViewRuleSpecInfoFlag_Inherited*0)|(D_ViewRuleSpecInfoFlag_Expandable*1)|(D_ViewRuleSpecInfoFlag_ExprResolution*0)|(D_ViewRuleSpecInfoFlag_VizBlockProd*1), },
{str8_lit_comp("geo3d"), str8_lit_comp("Geometry (3D)"), str8_lit_comp("x:{'count':expr, 'vtx':expr, 'vtx_size':expr}"), str8_lit_comp("Displays as geometry, interpreting the data as index or vertex data."), (D_ViewRuleSpecInfoFlag_Inherited*0)|(D_ViewRuleSpecInfoFlag_Expandable*1)|(D_ViewRuleSpecInfoFlag_ExprResolution*0)|(D_ViewRuleSpecInfoFlag_VizBlockProd*1), },
};
C_LINKAGE_END
+4 -31
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
//- GENERATED CODE //- GENERATED CODE
@@ -10,7 +10,7 @@ typedef enum D_CmdKind
{ {
D_CmdKind_Null, D_CmdKind_Null,
D_CmdKind_LaunchAndRun, D_CmdKind_LaunchAndRun,
D_CmdKind_LaunchAndInit, D_CmdKind_LaunchAndStepInto,
D_CmdKind_Kill, D_CmdKind_Kill,
D_CmdKind_KillAll, D_CmdKind_KillAll,
D_CmdKind_Detach, D_CmdKind_Detach,
@@ -24,7 +24,6 @@ D_CmdKind_Halt,
D_CmdKind_SoftHaltRefresh, D_CmdKind_SoftHaltRefresh,
D_CmdKind_SetThreadIP, D_CmdKind_SetThreadIP,
D_CmdKind_RunToLine, D_CmdKind_RunToLine,
D_CmdKind_RunToAddress,
D_CmdKind_Run, D_CmdKind_Run,
D_CmdKind_Restart, D_CmdKind_Restart,
D_CmdKind_StepInto, D_CmdKind_StepInto,
@@ -45,32 +44,7 @@ D_CmdKind_Attach,
D_CmdKind_COUNT, D_CmdKind_COUNT,
} D_CmdKind; } D_CmdKind;
typedef enum D_ViewRuleKind global B32 DEV_always_refresh = 0;
{
D_ViewRuleKind_Default,
D_ViewRuleKind_Array,
D_ViewRuleKind_Slice,
D_ViewRuleKind_List,
D_ViewRuleKind_ByteSwap,
D_ViewRuleKind_Cast,
D_ViewRuleKind_BaseDec,
D_ViewRuleKind_BaseBin,
D_ViewRuleKind_BaseOct,
D_ViewRuleKind_BaseHex,
D_ViewRuleKind_Only,
D_ViewRuleKind_Omit,
D_ViewRuleKind_NoAddr,
D_ViewRuleKind_Checkbox,
D_ViewRuleKind_ColorRGBA,
D_ViewRuleKind_Text,
D_ViewRuleKind_Disasm,
D_ViewRuleKind_Memory,
D_ViewRuleKind_Graph,
D_ViewRuleKind_Bitmap,
D_ViewRuleKind_Geo3D,
D_ViewRuleKind_COUNT,
} D_ViewRuleKind;
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;
@@ -78,10 +52,10 @@ global B32 DEV_draw_ui_box_heatmap = 0;
global B32 DEV_eval_compiler_tooltips = 0; global B32 DEV_eval_compiler_tooltips = 0;
global B32 DEV_eval_watch_key_tooltips = 0; global B32 DEV_eval_watch_key_tooltips = 0;
global B32 DEV_cmd_context_tooltips = 0; global B32 DEV_cmd_context_tooltips = 0;
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_always_refresh, str8_lit_comp("always_refresh")},
{&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")},
@@ -89,7 +63,6 @@ struct {B32 *value_ptr; String8 name;} DEV_toggle_table[] =
{&DEV_eval_compiler_tooltips, str8_lit_comp("eval_compiler_tooltips")}, {&DEV_eval_compiler_tooltips, str8_lit_comp("eval_compiler_tooltips")},
{&DEV_eval_watch_key_tooltips, str8_lit_comp("eval_watch_key_tooltips")}, {&DEV_eval_watch_key_tooltips, str8_lit_comp("eval_watch_key_tooltips")},
{&DEV_cmd_context_tooltips, str8_lit_comp("cmd_context_tooltips")}, {&DEV_cmd_context_tooltips, str8_lit_comp("cmd_context_tooltips")},
{&DEV_scratch_mouse_draw, str8_lit_comp("scratch_mouse_draw")},
{&DEV_updating_indicator, str8_lit_comp("updating_indicator")}, {&DEV_updating_indicator, str8_lit_comp("updating_indicator")},
}; };
#endif // DBG_ENGINE_META_H #endif // DBG_ENGINE_META_H
File diff suppressed because it is too large. Load diff
+365
View File
@@ -0,0 +1,365 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DBG_INFO_H
#define DBG_INFO_H
////////////////////////////////
//~ rjf: Unique Debug Info Key
typedef struct DI_Key DI_Key;
struct DI_Key
{
U64 u64[2];
};
typedef struct DI_KeyNode DI_KeyNode;
struct DI_KeyNode
{
DI_KeyNode *next;
DI_Key v;
};
typedef struct DI_KeyList DI_KeyList;
struct DI_KeyList
{
DI_KeyNode *first;
DI_KeyNode *last;
U64 count;
};
typedef struct DI_KeyArray DI_KeyArray;
struct DI_KeyArray
{
DI_Key *v;
U64 count;
};
////////////////////////////////
//~ rjf: Debug Info Path / Timestamp => Key Cache Types
typedef struct DI_KeyPathNode DI_KeyPathNode;
struct DI_KeyPathNode
{
DI_KeyPathNode *next;
DI_KeyPathNode *prev;
String8 path;
U64 min_timestamp;
DI_Key key;
};
typedef struct DI_KeySlot DI_KeySlot;
struct DI_KeySlot
{
DI_KeyPathNode *first;
DI_KeyPathNode *last;
};
////////////////////////////////
//~ rjf: Debug Info Cache Types
typedef struct DI_Node DI_Node;
struct DI_Node
{
// rjf: links
DI_Node *next;
DI_Node *prev;
// rjf: key
DI_Key key;
// rjf: value
OS_Handle file;
OS_Handle file_map;
void *file_base;
FileProperties file_props;
Arena *arena;
RDI_Parsed rdi;
// rjf: metadata
AccessPt access_pt;
U64 refcount;
U64 batch_request_counts[2];
U64 working_count;
U64 completion_count;
};
typedef struct DI_Slot DI_Slot;
struct DI_Slot
{
DI_Node *first;
DI_Node *last;
};
////////////////////////////////
//~ rjf: Requests
typedef struct DI_Request DI_Request;
struct DI_Request
{
DI_Key key;
};
typedef struct DI_RequestNode DI_RequestNode;
struct DI_RequestNode
{
DI_RequestNode *next;
DI_Request v;
};
typedef struct DI_RequestBatch DI_RequestBatch;
struct DI_RequestBatch
{
Mutex mutex;
Arena *arena;
DI_RequestNode *first;
DI_RequestNode *last;
U64 count;
};
////////////////////////////////
//~ rjf: Load Tasks
typedef enum DI_LoadTaskStatus
{
DI_LoadTaskStatus_Null,
DI_LoadTaskStatus_Active,
DI_LoadTaskStatus_Done,
}
DI_LoadTaskStatus;
typedef struct DI_LoadTask DI_LoadTask;
struct DI_LoadTask
{
DI_LoadTask *next;
DI_LoadTask *prev;
DI_Key key;
DI_LoadTaskStatus status;
B32 og_analyzed;
B32 og_is_rdi;
U64 og_size;
B32 rdi_analyzed;
B32 rdi_is_stale;
U64 thread_count;
OS_Handle process;
};
typedef struct DI_LoadCompletion DI_LoadCompletion;
struct DI_LoadCompletion
{
DI_LoadCompletion *next;
U64 code;
};
////////////////////////////////
//~ rjf: Search Types
typedef struct DI_SearchItem DI_SearchItem;
struct DI_SearchItem
{
U64 idx;
DI_Key key;
U64 missed_size;
FuzzyMatchRangeList match_ranges;
};
typedef struct DI_SearchItemChunk DI_SearchItemChunk;
struct DI_SearchItemChunk
{
DI_SearchItemChunk *next;
U64 base_idx;
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;
};
////////////////////////////////
//~ rjf: Match Types
typedef struct DI_Match DI_Match;
struct DI_Match
{
DI_Key key;
RDI_SectionKind section_kind;
U32 idx;
};
////////////////////////////////
//~ rjf: Events
typedef enum DI_EventKind
{
DI_EventKind_Null,
DI_EventKind_ConversionStarted,
DI_EventKind_ConversionEnded,
DI_EventKind_COUNT
}
DI_EventKind;
typedef struct DI_Event DI_Event;
struct DI_Event
{
DI_EventKind kind;
String8 string;
};
typedef struct DI_EventNode DI_EventNode;
struct DI_EventNode
{
DI_EventNode *next;
DI_Event v;
};
typedef struct DI_EventList DI_EventList;
struct DI_EventList
{
DI_EventNode *first;
DI_EventNode *last;
U64 count;
};
////////////////////////////////
//~ rjf: Shared State
typedef struct DI_Shared DI_Shared;
struct DI_Shared
{
Arena *arena;
U64 load_gen;
U64 load_count;
// rjf: key -> path cache
U64 key2path_slots_count;
DI_KeySlot *key2path_slots;
StripeArray key2path_stripes;
// rjf: path -> key cache
U64 path2key_slots_count;
DI_KeySlot *path2key_slots;
StripeArray path2key_stripes;
// rjf: debug info cache
U64 slots_count;
DI_Slot *slots;
StripeArray stripes;
// rjf: requests
DI_RequestBatch req_batches[2]; // [0] -> high priority, [1] -> low priority
// rjf: conversion tasks
DI_LoadTask *first_load_task[2];
DI_LoadTask *last_load_task[2];
DI_LoadTask *free_load_task;
U64 conversion_process_count;
U64 conversion_thread_count;
// rjf: conversion completion receiving thread
U64 conversion_completion_code;
String8 conversion_completion_lock_semaphore_name;
String8 conversion_completion_signal_semaphore_name;
String8 conversion_completion_shared_memory_name;
Semaphore conversion_completion_lock_semaphore;
Semaphore conversion_completion_signal_semaphore;
OS_Handle conversion_completion_shared_memory;
U64 *conversion_completion_shared_memory_base;
Thread conversion_completion_signal_receiver_thread;
// rjf: completion batch
Mutex completion_mutex;
Arena *completion_arena;
DI_LoadCompletion *first_completion;
DI_LoadCompletion *last_completion;
// rjf: events
Mutex event_mutex;
Arena *event_arena;
DI_EventList events;
};
////////////////////////////////
//~ rjf: Globals
global DI_Shared *di_shared = 0;
////////////////////////////////
//~ rjf: Helpers
internal DI_Key di_key_zero(void);
internal B32 di_key_match(DI_Key a, DI_Key b);
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);
////////////////////////////////
//~ rjf: Main Layer Initialization
internal void di_init(CmdLine *cmdline);
////////////////////////////////
//~ rjf: Path * Timestamp Cache Submission & Lookup
internal DI_Key di_key_from_path_timestamp(String8 path, U64 min_timestamp);
////////////////////////////////
//~ rjf: Debug Info Opening / Closing
internal void di_open(DI_Key key);
internal void di_close(DI_Key key, B32 force_closed);
////////////////////////////////
//~ rjf: Debug Info Lookups
internal U64 di_load_gen(void);
internal U64 di_load_count(void);
internal DI_KeyArray di_push_all_loaded_keys(Arena *arena);
internal RDI_Parsed *di_rdi_from_key(Access *access, DI_Key key, B32 high_priority, U64 endt_us);
////////////////////////////////
//~ rjf: Events
internal DI_EventList di_get_events(Arena *arena);
////////////////////////////////
//~ rjf: Asynchronous Tick
internal void di_async_tick(void);
////////////////////////////////
//~ rjf: Conversion Completion Signal Receiver Thread
internal void di_signal_completion(void);
internal void di_conversion_completion_signal_receiver_thread_entry_point(void *p);
////////////////////////////////
//~ rjf: Search Artifact Cache Hooks / Lookups
internal AC_Artifact di_search_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out, U64 *gen_out);
internal void di_search_artifact_destroy(AC_Artifact artifact);
internal DI_SearchItemArray di_search_item_array_from_target_query(Access *access, RDI_SectionKind target, String8 query, U64 endt_us, B32 *stale_out);
////////////////////////////////
//~ rjf: Match Artifact Cache Hooks / Lookups
internal AC_Artifact di_match_artifact_create(String8 key, B32 *cancel_signal, B32 *retry_out, U64 *gen_out);
internal DI_Match di_match_from_string(String8 string, U64 index, DI_Key preferred_dbgi_key, U64 endt_us);
#endif // DBG_INFO_H
-1800
View File
File diff suppressed because it is too large. Load diff
-472
View File
@@ -1,472 +0,0 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DBGI_H
#define DBGI_H
////////////////////////////////
//~ rjf: Cache Key Type
typedef struct DI_Key DI_Key;
struct DI_Key
{
String8 path;
U64 min_timestamp;
};
typedef struct DI_KeyNode DI_KeyNode;
struct DI_KeyNode
{
DI_KeyNode *next;
DI_Key v;
};
typedef struct DI_KeyList DI_KeyList;
struct DI_KeyList
{
DI_KeyNode *first;
DI_KeyNode *last;
U64 count;
};
typedef struct DI_KeyArray DI_KeyArray;
struct DI_KeyArray
{
DI_Key *v;
U64 count;
};
////////////////////////////////
//~ rjf: Event Types
typedef enum DI_EventKind
{
DI_EventKind_Null,
DI_EventKind_ConversionStarted,
DI_EventKind_ConversionEnded,
DI_EventKind_ConversionFailureUnsupportedFormat,
DI_EventKind_COUNT
}
DI_EventKind;
typedef struct DI_Event DI_Event;
struct DI_Event
{
DI_EventKind kind;
String8 string;
};
typedef struct DI_EventNode DI_EventNode;
struct DI_EventNode
{
DI_EventNode *next;
DI_Event v;
};
typedef struct DI_EventList DI_EventList;
struct DI_EventList
{
DI_EventNode *first;
DI_EventNode *last;
U64 count;
};
////////////////////////////////
//~ rjf: Debug Info Cache Types
typedef struct DI_StringChunkNode DI_StringChunkNode;
struct DI_StringChunkNode
{
DI_StringChunkNode *next;
U64 size;
};
typedef struct DI_Node DI_Node;
struct DI_Node
{
// rjf: links
DI_Node *next;
DI_Node *prev;
// rjf: metadata
U64 ref_count;
U64 touch_count;
U64 is_working;
// rjf: key
DI_Key key;
// rjf: file handles
OS_Handle file;
OS_Handle file_map;
void *file_base;
FileProperties file_props;
// rjf: parse artifacts
Arena *arena;
RDI_Parsed rdi;
B32 parse_done;
};
typedef struct DI_Slot DI_Slot;
struct DI_Slot
{
DI_Node *first;
DI_Node *last;
};
typedef struct DI_Stripe DI_Stripe;
struct DI_Stripe
{
Arena *arena;
DI_Node *free_node;
DI_StringChunkNode *free_string_chunks[8];
OS_Handle rw_mutex;
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
typedef struct DI_Touch DI_Touch;
struct DI_Touch
{
DI_Touch *next;
DI_Node *node;
DI_SearchNode *search_node;
};
typedef struct DI_Scope DI_Scope;
struct DI_Scope
{
DI_Scope *next;
DI_Touch *first_touch;
DI_Touch *last_touch;
};
typedef struct DI_TCTX DI_TCTX;
struct DI_TCTX
{
Arena *arena;
DI_Scope *free_scope;
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
typedef struct DI_Shared DI_Shared;
struct DI_Shared
{
Arena *arena;
// rjf: debug info cache
U64 slots_count;
DI_Slot *slots;
U64 stripes_count;
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
OS_Handle u2p_ring_mutex;
OS_Handle u2p_ring_cv;
U64 u2p_ring_size;
U8 *u2p_ring_base;
U64 u2p_ring_write_pos;
U64 u2p_ring_read_pos;
// rjf: parse -> user event ring
OS_Handle p2u_ring_mutex;
OS_Handle p2u_ring_cv;
U64 p2u_ring_size;
U8 *p2u_ring_base;
U64 p2u_ring_write_pos;
U64 p2u_ring_read_pos;
// rjf: search threads
U64 search_threads_count;
DI_SearchThread *search_threads;
OS_Handle search_evictor_thread;
};
////////////////////////////////
//~ rjf: Globals
global DI_Shared *di_shared = 0;
thread_static DI_TCTX *di_tctx = 0;
global RDI_Parsed di_rdi_parsed_nil = {0};
////////////////////////////////
//~ 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_key(DI_Key *k);
internal DI_Key di_key_zero(void);
internal B32 di_key_match(DI_Key *a, DI_Key *b);
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 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_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
internal void di_init(void);
////////////////////////////////
//~ rjf: Scope Functions
internal DI_Scope *di_scope_open(void);
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_search_node__stripe_mutex_r_guarded(DI_Scope *scope, DI_SearchNode *node);
////////////////////////////////
//~ rjf: Per-Slot Functions
internal DI_Node *di_node_from_key_slot__stripe_mutex_r_guarded(DI_Slot *slot, DI_Key *key);
////////////////////////////////
//~ rjf: Per-Stripe Functions
internal U64 di_string_bucket_idx_from_string_size(U64 size);
internal String8 di_string_alloc__stripe_mutex_w_guarded(DI_Stripe *stripe, String8 string);
internal void di_string_release__stripe_mutex_w_guarded(DI_Stripe *stripe, String8 string);
////////////////////////////////
//~ rjf: Key Opening/Closing
internal void di_open(DI_Key *key);
internal void di_close(DI_Key *key);
////////////////////////////////
//~ rjf: Debug Info Cache Lookups
internal RDI_Parsed *di_rdi_from_key(DI_Scope *scope, DI_Key *key, U64 endt_us);
////////////////////////////////
//~ 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 void di_u2p_dequeue_key(Arena *arena, DI_Key *out_key);
internal void di_p2u_push_event(DI_Event *event);
internal DI_EventList di_p2u_pop_events(Arena *arena, U64 endt_us);
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
+2 -8
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
//////////////////////////////// ////////////////////////////////
@@ -158,31 +158,25 @@ dmn_rsp_from_thread(DMN_Handle thread)
} }
//////////////////////////////// ////////////////////////////////
//~ Memory Helpers //~ rjf: Process Reading Helper Functions (Helpers, Implemented Once)
internal String8 internal String8
dmn_process_read_cstring(Arena *arena, DMN_Handle process, U64 addr) dmn_process_read_cstring(Arena *arena, DMN_Handle process, U64 addr)
{ {
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
String8List block_list = {0}; String8List block_list = {0};
for(U64 cursor = addr, stride = 256; ; cursor += stride) for(U64 cursor = addr, stride = 256; ; cursor += stride)
{ {
U8 *raw_block = push_array_no_zero(scratch.arena, U8, 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); U64 read_size = dmn_process_read(process, r1u64(cursor, cursor + stride), raw_block);
String8 block = str8_cstring_capped(raw_block, raw_block + read_size); String8 block = str8_cstring_capped(raw_block, raw_block + read_size);
str8_list_push(scratch.arena, &block_list, block); str8_list_push(scratch.arena, &block_list, block);
if(read_size != stride || (block.size+1 <= read_size && block.str[block.size] == 0)) if(read_size != stride || (block.size+1 <= read_size && block.str[block.size] == 0))
{ {
break; break;
} }
} }
String8 result = str8_list_join(arena, &block_list, 0); String8 result = str8_list_join(arena, &block_list, 0);
scratch_end(scratch); scratch_end(scratch);
return result; return result;
} }
+18 -8
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2024 Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef DEMON_CORE_H #ifndef DEMON_CORE_H
@@ -73,7 +73,7 @@ struct DMN_Event
U64 size; U64 size;
String8 string; String8 string;
U32 code; // code gives pid & tid on CreateProcess and CreateThread (respectfully) U32 code; // code gives pid & tid on CreateProcess and CreateThread (respectfully)
U32 flags; U32 flags; // DMN_TrapFlags, if `DMN_EventKind_SetBreakpoint`
S32 signo; S32 signo;
S32 sigcode; S32 sigcode;
U64 instruction_pointer; U64 instruction_pointer;
@@ -100,12 +100,22 @@ struct DMN_EventList
//////////////////////////////// ////////////////////////////////
//~ rjf: Run Control Types //~ rjf: Run Control Types
typedef U32 DMN_TrapFlags;
enum
{
DMN_TrapFlag_BreakOnWrite = (1<<0),
DMN_TrapFlag_BreakOnRead = (1<<1),
DMN_TrapFlag_BreakOnExecute = (1<<2),
};
typedef struct DMN_Trap DMN_Trap; typedef struct DMN_Trap DMN_Trap;
struct DMN_Trap struct DMN_Trap
{ {
DMN_Handle process; DMN_Handle process;
U64 vaddr; U64 vaddr;
U64 id; U64 id;
DMN_TrapFlags flags;
U32 size;
}; };
typedef struct DMN_TrapChunkNode DMN_TrapChunkNode; typedef struct DMN_TrapChunkNode DMN_TrapChunkNode;
@@ -129,6 +139,7 @@ struct DMN_TrapChunkList
typedef struct DMN_RunCtrls DMN_RunCtrls; typedef struct DMN_RunCtrls DMN_RunCtrls;
struct DMN_RunCtrls struct DMN_RunCtrls
{ {
DMN_Handle priority_thread;
DMN_Handle single_step_thread; DMN_Handle single_step_thread;
B8 ignore_previous_exception; B8 ignore_previous_exception;
B8 run_entities_are_unfrozen; B8 run_entities_are_unfrozen;
@@ -180,6 +191,11 @@ internal DMN_Event *dmn_event_list_push(Arena *arena, DMN_EventList *list);
internal U64 dmn_rip_from_thread(DMN_Handle thread); internal U64 dmn_rip_from_thread(DMN_Handle thread);
internal U64 dmn_rsp_from_thread(DMN_Handle thread); internal U64 dmn_rsp_from_thread(DMN_Handle thread);
////////////////////////////////
//~ rjf: Process Reading Helper Functions (Helpers, Implemented Once)
internal String8 dmn_process_read_cstring(Arena *arena, DMN_Handle process, U64 addr);
//////////////////////////////// ////////////////////////////////
//~ rjf: @dmn_os_hooks Main Layer Initialization (Implemented Per-OS) //~ rjf: @dmn_os_hooks Main Layer Initialization (Implemented Per-OS)
@@ -206,11 +222,6 @@ internal void dmn_halt(U64 code, U64 user_data);
//////////////////////////////// ////////////////////////////////
//~ rjf: @dmn_os_hooks Introspection Functions (Implemented Per-OS) //~ rjf: @dmn_os_hooks Introspection Functions (Implemented Per-OS)
//- rjf: run/memory/register counters
internal U64 dmn_run_gen(void);
internal U64 dmn_mem_gen(void);
internal U64 dmn_reg_gen(void);
//- rjf: non-blocking-control-thread access barriers //- rjf: non-blocking-control-thread access barriers
internal B32 dmn_access_open(void); internal B32 dmn_access_open(void);
internal void dmn_access_close(void); internal void dmn_access_close(void);
@@ -226,7 +237,6 @@ 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);
+4
View File
@@ -21,6 +21,10 @@ DMN_EventKindTable:
{Memory} {Memory}
{DebugString} {DebugString}
{SetThreadName} {SetThreadName}
{SetThreadColor}
{SetBreakpoint}
{UnsetBreakpoint}
{SetVAddrRangeNote}
} }
@table(name) @table(name)
Loaded 100 of 546 files, more files were not shown because too many files have changed in this diff. Show more