@@ -58,28 +58,28 @@ static inline char* dwarf5_stringFromSection(uint64_t offset,
5858 * @param debugStrOffsets the debug string offsets section
5959 * @return the optionally deducted string table offset
6060 */
61- static inline optional_uint64_t dwarf5_loadStringOffset (uint64_t index , struct lcs_section debugStrOffsets ) {
61+ static inline optional_uint64_t dwarf5_loadStringOffset (uint64_t index , struct lcs_section debugStrOffsets , optional_uint64_t offset ) {
6262 bool bit64 ;
6363 size_t counter = 0 ;
6464 const uint64_t size = dwarf_parseInitialSize (debugStrOffsets .content , & counter , & bit64 );
6565 if (bit64 ) {
6666 if (index >= size / 8 ) {
6767 return (optional_uint64_t ) { .has_value = false };
6868 }
69+ if (offset .has_value ) {
70+ return (optional_uint64_t ) { true, ((uint64_t * ) (debugStrOffsets .content + offset .value ))[index ] };
71+ }
6972 return (optional_uint64_t ) { true, ((uint64_t * ) (debugStrOffsets .content + counter ))[index ] };
7073 } else if (index >= size / 4 ) {
7174 return (optional_uint64_t ) { .has_value = false };
7275 }
76+ if (offset .has_value ) {
77+ return (optional_uint64_t ) { true, ((uint32_t * ) (debugStrOffsets .content + offset .value ))[index ] };
78+ }
7379 return (optional_uint64_t ) { true, ((uint32_t * ) (debugStrOffsets .content + counter ))[index ] };
7480}
7581
76- char * dwarf5_readString (void * buffer ,
77- size_t * counter ,
78- uint64_t type ,
79- bool bit64 ,
80- struct lcs_section debugLineStr ,
81- struct lcs_section debugStr ,
82- struct lcs_section debugStrOffsets ) {
82+ char * dwarf5_readString (struct dwarf_parser * self , void * buffer , size_t * counter , uint64_t type ) {
8383 if (type == DW_FORM_string ) {
8484 char * toReturn = (buffer + * counter );
8585 * counter += strlen (toReturn ) + 1 ;
@@ -92,7 +92,7 @@ char* dwarf5_readString(void* buffer,
9292 }
9393 uint64_t offset ;
9494 if (type == DW_FORM_strp || type == DW_FORM_line_strp || type == DW_FORM_strp_sup ) {
95- if (bit64 ) {
95+ if (self -> bit64 ) {
9696 offset = * ((uint64_t * ) (buffer + * counter ));
9797 * counter += 8 ;
9898 } else {
@@ -128,13 +128,13 @@ char* dwarf5_readString(void* buffer,
128128 default : return NULL ;
129129 }
130130 type = DW_FORM_strp ;
131- optional_uint64_t value = dwarf5_loadStringOffset (index , debugStrOffsets );
131+ optional_uint64_t value = dwarf5_loadStringOffset (index , self -> debugStrOffsets , self -> debugStrOffset );
132132 if (!value .has_value ) {
133133 return NULL ;
134134 }
135135 offset = value .value ;
136136 }
137- return dwarf5_stringFromSection (offset , type , debugLineStr , debugStr );
137+ return dwarf5_stringFromSection (offset , type , self -> debugLineStr , self -> debugStr );
138138}
139139
140140/**
@@ -255,7 +255,7 @@ static inline uint8_t* dwarf5_readMD5(void* buffer, size_t* counter) {
255255 return toReturn ;
256256}
257257
258- bool dwarf5_consumeSome (void * buffer , size_t * counter , uint64_t type , bool bit64 ) {
258+ bool dwarf5_consumeSome (struct dwarf_parser * self , void * buffer , size_t * counter , uint64_t type ) {
259259 switch (type ) {
260260 case DW_FORM_block : {
261261 const uint64_t length = getULEB128 (buffer , counter );
@@ -295,18 +295,15 @@ bool dwarf5_consumeSome(void* buffer, size_t* counter, uint64_t type, bool bit64
295295 case DW_FORM_strp :
296296 case DW_FORM_string :
297297 case DW_FORM_line_strp :
298- (void ) dwarf5_readString (buffer , counter , type , bit64 ,
299- (struct lcs_section ) { .content = NULL , .size = 0 },
300- (struct lcs_section ) { .content = NULL , .size = 0 },
301- (struct lcs_section ) { .content = NULL , .size = 0 });
298+ (void ) dwarf5_readString (self , buffer , counter , type );
302299 break ;
303300
304301 case DW_FORM_sdata : getLEB128 (buffer , counter ); break ;
305302
306303 case DW_FORM_strx :
307304 case DW_FORM_udata : getULEB128 (buffer , counter ); break ;
308305
309- case DW_FORM_sec_offset : * counter += bit64 ? 8 : 4 ; break ;
306+ case DW_FORM_sec_offset : * counter += self -> bit64 ? 8 : 4 ; break ;
310307
311308 default : return false;
312309 }
@@ -344,7 +341,7 @@ static inline optional_vector_fileAttribute_t dwarf5_parseFileAttributes(struct
344341 vector_iterate (pair_uint64_t , & entryFormats , {
345342 switch (element -> first ) {
346343 case DW_LNCT_path :
347- attribute .path = dwarf5_readString (self -> debugLine .content , counter , element -> second , self -> bit64 , self -> debugLineStr , self -> debugStr , self -> debugStrOffsets );
344+ attribute .path = dwarf5_readString (self , self -> debugLine .content , counter , element -> second );
348345 break ;
349346
350347 case DW_LNCT_directory_index : {
@@ -374,7 +371,7 @@ static inline optional_vector_fileAttribute_t dwarf5_parseFileAttributes(struct
374371 break ;
375372
376373 default :
377- if (!dwarf5_consumeSome (self -> debugLine .content , counter , element -> second , self -> bit64 )) goto fail ;
374+ if (!dwarf5_consumeSome (self , self -> debugLine .content , counter , element -> second )) goto fail ;
378375 break ;
379376 }
380377 })
0 commit comments