Skip to content

Commit a574a9e

Browse files
committed
Moved dwarf5_consumeSome to a more general dwarf_consumeSome
1 parent 24b1b08 commit a574a9e

File tree

4 files changed

+71
-70
lines changed

4 files changed

+71
-70
lines changed

src/parser/file/dwarf/dwarf_parser.c

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,62 @@ uint64_t dwarf_parseInitialSize(void* buffer, size_t* counter, bool* bit64) {
334334
return toReturn;
335335
}
336336

337+
bool dwarf_consumeSome(struct dwarf_parser* self, void* buffer, size_t* counter, uint64_t type) {
338+
switch (type) {
339+
case DW_FORM_block: {
340+
const uint64_t length = getULEB128(buffer, counter);
341+
*counter += length;
342+
break;
343+
}
344+
345+
case DW_FORM_block1: {
346+
uint8_t length = *((uint8_t*) (buffer + (*counter)++));
347+
*counter += length;
348+
break;
349+
}
350+
351+
case DW_FORM_block2: {
352+
uint16_t length = *((uint16_t*) (buffer + *counter));
353+
*counter += 2 + length;
354+
break;
355+
}
356+
357+
case DW_FORM_block4: {
358+
uint32_t length = *((uint32_t*) (buffer + *counter));
359+
*counter += 4 + length;
360+
break;
361+
}
362+
363+
case DW_FORM_flag:
364+
case DW_FORM_strx1:
365+
case DW_FORM_data1: ++(*counter); break;
366+
case DW_FORM_strx2:
367+
case DW_FORM_data2: *counter += 2; break;
368+
case DW_FORM_strx3: *counter += 3; break;
369+
case DW_FORM_strx4:
370+
case DW_FORM_data4: *counter += 4; break;
371+
case DW_FORM_data8: *counter += 8; break;
372+
case DW_FORM_data16: *counter += 16; break;
373+
374+
case DW_FORM_strp:
375+
case DW_FORM_string:
376+
case DW_FORM_line_strp:
377+
(void) dwarf5_readString(self, buffer, counter, type);
378+
break;
379+
380+
case DW_FORM_sdata: getLEB128(buffer, counter); break;
381+
382+
case DW_FORM_strx:
383+
case DW_FORM_udata: getULEB128(buffer, counter); break;
384+
385+
case DW_FORM_sec_offset: *counter += self->bit64 ? 8 : 4; break;
386+
387+
default: return false;
388+
}
389+
return true;
390+
}
391+
392+
337393
/**
338394
* Parses the compilation directory.
339395
*
@@ -403,10 +459,10 @@ static inline bool dwarf_parseCompDir(struct dwarf_parser* self) {
403459
continue;
404460
} else if (element->second == DW_FORM_indirect) {
405461
const uint64_t actualForm = getULEB128(self->debugInfo.content, &counter);
406-
if (!dwarf5_consumeSome(self, self->debugInfo.content, &counter, actualForm)) {
462+
if (!dwarf_consumeSome(self, self->debugInfo.content, &counter, actualForm)) {
407463
break;
408464
}
409-
} else if (!dwarf5_consumeSome(self, self->debugInfo.content, &counter, element->second)) {
465+
} else if (!dwarf_consumeSome(self, self->debugInfo.content, &counter, element->second)) {
410466
break;
411467
}
412468
})

src/parser/file/dwarf/dwarf_parser.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,16 @@ char* dwarf_pathConcatenate(const char* string1, const char* string2);
167167
*/
168168
uint64_t dwarf_parseInitialSize(void* buffer, size_t* counter, bool* bit64);
169169

170+
/**
171+
* Consumes the following data block of different possible types, according to the
172+
* formats available for additional vendor specific data.
173+
*
174+
* @param self the dwarf parser structure
175+
* @param buffer the data buffer
176+
* @param counter the reading index
177+
* @param type the expected data type
178+
* @return whether the data was allowed and skipped successfully
179+
*/
180+
bool dwarf_consumeSome(struct dwarf_parser* self, void* buffer, size_t* counter, uint64_t type);
181+
170182
#endif /* dwarf_parser_h */

src/parser/file/dwarf/v5/parser.c

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -256,61 +256,6 @@ static inline uint8_t* dwarf5_readMD5(void* buffer, size_t* counter) {
256256
return toReturn;
257257
}
258258

259-
bool dwarf5_consumeSome(struct dwarf_parser* self, void* buffer, size_t* counter, uint64_t type) {
260-
switch (type) {
261-
case DW_FORM_block: {
262-
const uint64_t length = getULEB128(buffer, counter);
263-
*counter += length;
264-
break;
265-
}
266-
267-
case DW_FORM_block1: {
268-
uint8_t length = *((uint8_t*) (buffer + (*counter)++));
269-
*counter += length;
270-
break;
271-
}
272-
273-
case DW_FORM_block2: {
274-
uint16_t length = *((uint16_t*) (buffer + *counter));
275-
*counter += 2 + length;
276-
break;
277-
}
278-
279-
case DW_FORM_block4: {
280-
uint32_t length = *((uint32_t*) (buffer + *counter));
281-
*counter += 4 + length;
282-
break;
283-
}
284-
285-
case DW_FORM_flag:
286-
case DW_FORM_strx1:
287-
case DW_FORM_data1: ++(*counter); break;
288-
case DW_FORM_strx2:
289-
case DW_FORM_data2: *counter += 2; break;
290-
case DW_FORM_strx3: *counter += 3; break;
291-
case DW_FORM_strx4:
292-
case DW_FORM_data4: *counter += 4; break;
293-
case DW_FORM_data8: *counter += 8; break;
294-
case DW_FORM_data16: *counter += 16; break;
295-
296-
case DW_FORM_strp:
297-
case DW_FORM_string:
298-
case DW_FORM_line_strp:
299-
(void) dwarf5_readString(self, buffer, counter, type);
300-
break;
301-
302-
case DW_FORM_sdata: getLEB128(buffer, counter); break;
303-
304-
case DW_FORM_strx:
305-
case DW_FORM_udata: getULEB128(buffer, counter); break;
306-
307-
case DW_FORM_sec_offset: *counter += self->bit64 ? 8 : 4; break;
308-
309-
default: return false;
310-
}
311-
return true;
312-
}
313-
314259
/**
315260
* Parses the following file attributes in the line program header.
316261
*
@@ -372,7 +317,7 @@ static inline optional_vector_fileAttribute_t dwarf5_parseFileAttributes(struct
372317
break;
373318

374319
default:
375-
if (!dwarf5_consumeSome(self, self->debugLine.content, counter, element->second)) goto fail;
320+
if (!dwarf_consumeSome(self, self->debugLine.content, counter, element->second)) goto fail;
376321
break;
377322
}
378323
})

src/parser/file/dwarf/v5/parser.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,6 @@ struct dwarf5_parser {
4848
*/
4949
void dwarf5_parser_create(struct dwarf_parser* self);
5050

51-
/**
52-
* Consumes the following data block of different possible types, according to the
53-
* formats available for additional vendor specific data.
54-
*
55-
* @param self the dwarf parser structure
56-
* @param buffer the data buffer
57-
* @param counter the reading index
58-
* @param type the expected data type
59-
* @return whether the data was allowed and skipped successfully
60-
*/
61-
bool dwarf5_consumeSome(struct dwarf_parser* self, void* buffer, size_t* counter, uint64_t type);
62-
6351
/**
6452
* @brief Reads a string.
6553
*

0 commit comments

Comments
 (0)