@@ -246,8 +246,9 @@ internal U64
246246dw2_read_form_val (DW2_ParseCtx * ctx , String8 data , U64 off , DW_FormKind form_kind , U64 implicit_const , DW2_FormVal * out )
247247{
248248 U64 start_off = off ;
249- DW2_FormVal val = {0 };
249+ DW2_FormVal val = {form_kind };
250250 {
251+ //- rjf: read value bytes
251252 U64 bytes_to_read = 0 ;
252253 switch (form_kind )
253254 {
@@ -351,8 +352,7 @@ dw2_read_form_val(DW2_ParseCtx *ctx, String8 data, U64 off, DW_FormKind form_kin
351352 U64 size = 0 ;
352353 U64 og_read_off = off ;
353354 off += str8_deserial_read_uleb128 (data , off , & size );
354- val .u128 .u64 [0 ] = size ;
355- val .u128 .u64 [1 ] = og_read_off ;
355+ val .string = str8_substr (data , r1u64 (off , off + size ));
356356 off += size ;
357357 }break ;
358358
@@ -362,8 +362,7 @@ dw2_read_form_val(DW2_ParseCtx *ctx, String8 data, U64 off, DW_FormKind form_kin
362362 String8 string = {0 };
363363 U64 og_read_off = off ;
364364 off += str8_deserial_read_cstr (data , off , & string );
365- val .u128 .u64 [0 ] = og_read_off ;
366- val .u128 .u64 [1 ] = og_read_off + string .size - 1 ;
365+ val .string = string ;
367366 }break ;
368367
369368 //- rjf: implicit constants (no reading in .debug_info; value comes from .debug_abbrev)
@@ -389,21 +388,41 @@ dw2_read_form_val(DW2_ParseCtx *ctx, String8 data, U64 off, DW_FormKind form_kin
389388 val .u128 .u64 [0 ] = 1 ;
390389 }break ;
391390 }
391+
392+ //- rjf: in some cases, resolve numeric values -> strings
393+ {
394+ switch (form_kind )
395+ {
396+ default :{}break ;
397+ case DW_Form_Strx1 :
398+ case DW_Form_Strx2 :
399+ case DW_Form_Strx3 :
400+ case DW_Form_Strx4 :
401+ case DW_Form_Strx :
402+ {
403+ // TODO(rjf)
404+ }break ;
405+ case DW_Form_LineStrp :
406+ {
407+ String8 string_section_data = ctx -> raw -> sec [DW_Section_LineStr ].data ;
408+ val .string = str8_cstring_capped (string_section_data .str + val .u128 .u64 [0 ],
409+ string_section_data .str + string_section_data .size );
410+ }break ;
411+ case DW_Form_Strp :
412+ case DW_Form_StrpSup :
413+ {
414+ String8 string_section_data = ctx -> raw -> sec [DW_Section_Str ].data ;
415+ val .string = str8_cstring_capped (string_section_data .str + val .u128 .u64 [0 ],
416+ string_section_data .str + string_section_data .size );
417+ }break ;
418+ }
419+ }
392420 }
393421 * out = val ;
394422 U64 bytes_read = (off - start_off );
395423 return bytes_read ;
396424}
397425
398- internal String8
399- dw2_string_from_form_val (DW2_ParseCtx * ctx , DW2_FormVal val )
400- {
401- String8 section_data = ctx -> raw -> sec [val .section_kind ].data ;
402- Rng1U64 range = r1u64 (val .u128 .u64 [0 ], val .u128 .u64 [1 ]);
403- String8 string = str8_substr (section_data , range );
404- return string ;
405- }
406-
407426////////////////////////////////
408427//~ rjf: Tag Parsing
409428
@@ -490,7 +509,7 @@ dw2_read_tag(Arena *arena, DW2_ParseCtx *ctx, String8 data, U64 off, DW2_Tag *ta
490509 SLLQueuePush (attribs .first , attribs .last , n );
491510 attribs .count += 1 ;
492511 n -> v .attrib_kind = attrib_kind ;
493- n -> v .form_kind = attrib_form_kind ;
512+ n -> v .val = val ;
494513 }
495514
496515 // rjf: no movement, or no attrib kind -> done
@@ -511,6 +530,21 @@ dw2_read_tag(Arena *arena, DW2_ParseCtx *ctx, String8 data, U64 off, DW2_Tag *ta
511530 return bytes_read ;
512531}
513532
533+ internal DW2_Attrib *
534+ dw2_attrib_from_kind (DW2_Tag * tag , DW_AttribKind kind )
535+ {
536+ DW2_Attrib * result = & dw2_attrib_nil ;
537+ for EachNode (n , DW2_AttribNode , tag -> attribs .first )
538+ {
539+ if (n -> v .attrib_kind == kind )
540+ {
541+ result = & n -> v ;
542+ break ;
543+ }
544+ }
545+ return result ;
546+ }
547+
514548////////////////////////////////
515549//~ rjf: Line Table Parsing
516550
@@ -695,15 +729,16 @@ dw2_read_line_table_header(Arena *arena, DW2_ParseCtx *ctx, String8 data, U64 of
695729 case DW_Version_5 :
696730 {
697731 //- rjf: read directory & file tables
698- for (B32 files = 0 , dirs = 1 ; files <= 1 ; files = 1 , dirs = 0 )
732+ for (B32 do_files = 0 , do_dirs = 1 ; do_files <= 1 ; do_files + = 1 , do_dirs = 0 )
699733 {
700734 // rjf: read header
701735 U8 entry_formats_count = 0 ;
702736 off += str8_deserial_read_struct (data , off , & entry_formats_count );
703737 U64 * entry_formats = push_array (scratch .arena , U64 , entry_formats_count * 2 );
704738 for EachIndex (idx , entry_formats_count )
705739 {
706- off += str8_deserial_read_uleb128 (data , off , & entry_formats [idx ]);
740+ off += str8_deserial_read_uleb128 (data , off , & entry_formats [idx * 2 + 0 ]);
741+ off += str8_deserial_read_uleb128 (data , off , & entry_formats [idx * 2 + 1 ]);
707742 }
708743 U64 table_count = 0 ;
709744 off += str8_deserial_read_uleb128 (data , off , & table_count );
@@ -731,7 +766,7 @@ dw2_read_line_table_header(Arena *arena, DW2_ParseCtx *ctx, String8 data, U64 of
731766 }break ;
732767 case DW_LNCT_Path :
733768 {
734- entry_out -> file_name = dw2_string_from_form_val ( ctx , form_val ) ;
769+ entry_out -> file_name = form_val . string ;
735770 }break ;
736771 case DW_LNCT_DirectoryIndex :
737772 {
@@ -751,12 +786,17 @@ dw2_read_line_table_header(Arena *arena, DW2_ParseCtx *ctx, String8 data, U64 of
751786 }break ;
752787 case DW_LNCT_LLVM_Source :
753788 {
754- entry_out -> source = dw2_string_from_form_val ( ctx , form_val ) ;
789+ entry_out -> source = form_val . string ;
755790 }break ;
756791 }
757792 }
758793 }
759794 }
795+
796+ // rjf: store
797+ if (0 ){}
798+ else if (do_files ) { files = table ; }
799+ else if (do_dirs ) { dirs = table ; }
760800 }
761801
762802 }break ;
0 commit comments