From 729a5a939219205edf497befb3e53eb863ac2d8b Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Sun, 26 May 2024 14:56:13 -0700 Subject: [PATCH] clean up & merge inline binary annotation decoders --- src/codeview/codeview.c | 77 ++++++++++++++++++++++------------------- src/codeview/codeview.h | 13 +++---- 2 files changed, 49 insertions(+), 41 deletions(-) diff --git a/src/codeview/codeview.c b/src/codeview/codeview.c index 06b2d2c8..f7a88fd0 100644 --- a/src/codeview/codeview.c +++ b/src/codeview/codeview.c @@ -171,44 +171,51 @@ cv_f64_from_numeric(CV_NumericParsed *num){ internal U64 cv_decode_inline_annot_u32(String8 data, U64 offset, U32 *out_value) { - U32 value; - U64 cursor = offset; - + + // rjf: read header U8 header = 0; cursor += str8_deserial_read_struct(data, cursor, &header); - - // 1 byte - if((header & 0x80) == 0) + + // rjf: decode value + U32 value = 0; { - value = header; + // 1 byte + if((header & 0x80) == 0) + { + value = header; + } + + // 2 bytes + else if((header & 0xC0) == 0x80 && cursor+2 <= data.size) + { + U8 second_byte; + cursor += str8_deserial_read_struct(data, cursor, &second_byte); + value = ((header & 0x3F) << 8) | second_byte; + } + + // 4 bytes + else if((header & 0xE0) == 0xC0 && cursor+3 <= data.size) + { + U8 second_byte, third_byte, fourth_byte; + cursor += str8_deserial_read_struct(data, cursor, &second_byte); + cursor += str8_deserial_read_struct(data, cursor, &third_byte); + cursor += str8_deserial_read_struct(data, cursor, &fourth_byte); + value = (((U32)header & 0x1F) << 24) | ((U32)second_byte << 16) | ((U32)third_byte << 8) | (U32)fourth_byte; + } + + // bad encode + else if((header & 0xE0) == 0xE0) + { + value = max_U32; + } } - // 2 bytes - else if((header & 0xC0) == 0x80) + + // rjf: output results + if(out_value) { - Assert(cursor + sizeof(U8) * 2 <= data.size); - U8 second_byte; - cursor += str8_deserial_read_struct(data, cursor, &second_byte); - value = ((header & 0x3F) << 8) | second_byte; + *out_value = value; } - // 4 bytes - else if((header & 0xE0) == 0xC0) - { - Assert(cursor + sizeof(U8) * 3 <= data.size); - U8 second_byte, third_byte, fourth_byte; - cursor += str8_deserial_read_struct(data, cursor, &second_byte); - cursor += str8_deserial_read_struct(data, cursor, &third_byte); - cursor += str8_deserial_read_struct(data, cursor, &fourth_byte); - value = (((U32)header & 0x1F) << 24) | ((U32)second_byte << 16) | ((U32)third_byte << 8) | (U32)fourth_byte; - } - // bad encode - else if((header & 0xE0) == 0xE0) - { - value = max_U32; - } - - *out_value = value; - U64 read_size = cursor - offset; return read_size; } @@ -217,9 +224,9 @@ internal U64 cv_decode_inline_annot_s32(String8 data, U64 offset, S32 *out_value) { U32 value; - + U64 read_size = cv_decode_inline_annot_u32(data, offset, &value); - + if(value & 1) { value = -(value >> 1); @@ -228,9 +235,9 @@ cv_decode_inline_annot_s32(String8 data, U64 offset, S32 *out_value) { value = value >> 1; } - + *out_value = (S32)value; - + return read_size; } diff --git a/src/codeview/codeview.h b/src/codeview/codeview.h index ff9f348e..5c3fe546 100644 --- a/src/codeview/codeview.h +++ b/src/codeview/codeview.h @@ -1761,8 +1761,8 @@ struct CV_SymBuildInfo //- (SymKind: INLINESITE) -typedef U32 CV_InlineBinaryAnnotaiton; -typedef enum CV_InlineBinaryAnnotationenum +typedef U32 CV_InlineBinaryAnnotation; +typedef enum CV_InlineBinaryAnnotationEnum { CV_InlineBinaryAnnotation_Null, CV_InlineBinaryAnnotation_CodeOffset, @@ -1778,14 +1778,16 @@ typedef enum CV_InlineBinaryAnnotationenum CV_InlineBinaryAnnotation_ChangeCodeOffsetAndLineOffset, CV_InlineBinaryAnnotation_ChangeCodeLengthAndCodeOffset, CV_InlineBinaryAnnotaiton_ChangeColumnEnd -}; +} +CV_InlineBinaryAnnotationEnum; typedef U32 CV_InlineRangeKind; -typedef enum CV_InlnineRangeKindEnum +typedef enum CV_InlineRangeKindEnum { CV_InlineRangeKind_Expr, CV_InlineRangeKind_Stmt -}; +} +CV_InlineRangeKindEnum; typedef struct CV_SymInlineSite CV_SymInlineSite; struct CV_SymInlineSite @@ -2917,7 +2919,6 @@ struct CV_TypeIdArray U64 count; }; - //////////////////////////////// //~ CodeView Common Functions