mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-07 14:28:40 +00:00
moved CodeView parser code into separate file
This commit is contained in:
+1
-1397
File diff suppressed because it is too large
Load Diff
+1022
-1256
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,253 @@
|
|||||||
|
// Copyright (c) 2024 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_C13LinesParsed CV_C13LinesParsed;
|
||||||
|
struct CV_C13LinesParsed
|
||||||
|
{
|
||||||
|
// raw info
|
||||||
|
U32 sec_idx;
|
||||||
|
U32 file_off;
|
||||||
|
U64 secrel_base_off;
|
||||||
|
|
||||||
|
// parsed info
|
||||||
|
String8 file_name;
|
||||||
|
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;
|
||||||
|
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);
|
||||||
|
|
||||||
|
//- 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
|
||||||
|
|
||||||
@@ -3,24 +3,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
// Aligns
|
|
||||||
|
|
||||||
#define CV_LeafAlign 4
|
|
||||||
#define CV_SymbolAlign 1
|
|
||||||
#define CV_C13SubSectionAlign 4
|
|
||||||
#define CV_FileCheckSumsAlign 4
|
|
||||||
|
|
||||||
////////////////////////////////
|
|
||||||
|
|
||||||
//- Symbol and Leaf Headers
|
//- Symbol and Leaf Headers
|
||||||
|
|
||||||
#define CV_LeafSize_Max max_U16
|
|
||||||
typedef U16 CV_LeafSize;
|
|
||||||
|
|
||||||
#define CV_SymSize_Max max_U16
|
|
||||||
typedef U16 CV_SymSize;
|
|
||||||
|
|
||||||
typedef struct CV_LeafHeader
|
typedef struct CV_LeafHeader
|
||||||
{
|
{
|
||||||
CV_LeafSize size;
|
CV_LeafSize size;
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
#include "coff/coff.h"
|
#include "coff/coff.h"
|
||||||
#include "pe/pe.h"
|
#include "pe/pe.h"
|
||||||
#include "codeview/codeview.h"
|
#include "codeview/codeview.h"
|
||||||
|
#include "codeview/codeview_parse.h"
|
||||||
#include "msf/msf.h"
|
#include "msf/msf.h"
|
||||||
#include "msf/msf_parse.h"
|
#include "msf/msf_parse.h"
|
||||||
#include "pdb/pdb.h"
|
#include "pdb/pdb.h"
|
||||||
@@ -48,6 +49,8 @@
|
|||||||
#include "coff/coff.c"
|
#include "coff/coff.c"
|
||||||
#include "pe/pe.c"
|
#include "pe/pe.c"
|
||||||
#include "codeview/codeview.c"
|
#include "codeview/codeview.c"
|
||||||
|
#include "codeview/codeview_parse.c"
|
||||||
|
#include "msf/msf.c"
|
||||||
#include "msf/msf_parse.c"
|
#include "msf/msf_parse.c"
|
||||||
#include "pdb/pdb.c"
|
#include "pdb/pdb.c"
|
||||||
#include "msvc_crt/msvc_crt.c"
|
#include "msvc_crt/msvc_crt.c"
|
||||||
|
|||||||
+2
-2
@@ -17,7 +17,7 @@ pdb_info_from_data(Arena *arena, String8 data){
|
|||||||
PDB_Info *result = 0;
|
PDB_Info *result = 0;
|
||||||
if (header != 0){
|
if (header != 0){
|
||||||
// read guid
|
// read guid
|
||||||
COFF_Guid *auth_guid = 0;
|
Guid *auth_guid = 0;
|
||||||
U32 after_auth_guid_off = sizeof(*header);
|
U32 after_auth_guid_off = sizeof(*header);
|
||||||
switch (header->version){
|
switch (header->version){
|
||||||
case PDB_InfoVersion_VC70_DEP:
|
case PDB_InfoVersion_VC70_DEP:
|
||||||
@@ -26,7 +26,7 @@ pdb_info_from_data(Arena *arena, String8 data){
|
|||||||
case PDB_InfoVersion_VC110:
|
case PDB_InfoVersion_VC110:
|
||||||
case PDB_InfoVersion_VC140:
|
case PDB_InfoVersion_VC140:
|
||||||
{
|
{
|
||||||
auth_guid = (COFF_Guid*)(data.str + after_auth_guid_off);
|
auth_guid = (Guid*)(data.str + after_auth_guid_off);
|
||||||
after_auth_guid_off = sizeof(*header) + sizeof(*auth_guid);
|
after_auth_guid_off = sizeof(*header) + sizeof(*auth_guid);
|
||||||
}break;
|
}break;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -44,7 +44,7 @@ typedef struct PDB_Info
|
|||||||
{
|
{
|
||||||
PDB_InfoNode *first;
|
PDB_InfoNode *first;
|
||||||
PDB_InfoNode *last;
|
PDB_InfoNode *last;
|
||||||
COFF_Guid auth_guid;
|
Guid auth_guid;
|
||||||
} PDB_Info;
|
} PDB_Info;
|
||||||
|
|
||||||
typedef struct PDB_InfoHeader
|
typedef struct PDB_InfoHeader
|
||||||
|
|||||||
@@ -342,7 +342,7 @@
|
|||||||
#include "coff/coff.h"
|
#include "coff/coff.h"
|
||||||
#include "pe/pe.h"
|
#include "pe/pe.h"
|
||||||
#include "codeview/codeview.h"
|
#include "codeview/codeview.h"
|
||||||
#include "codeview/codeview_stringize.h"
|
#include "codeview/codeview_parse.h"
|
||||||
#include "msf/msf.h"
|
#include "msf/msf.h"
|
||||||
#include "msf/msf_parse.h"
|
#include "msf/msf_parse.h"
|
||||||
#include "pdb/pdb.h"
|
#include "pdb/pdb.h"
|
||||||
@@ -383,7 +383,7 @@
|
|||||||
#include "coff/coff.c"
|
#include "coff/coff.c"
|
||||||
#include "pe/pe.c"
|
#include "pe/pe.c"
|
||||||
#include "codeview/codeview.c"
|
#include "codeview/codeview.c"
|
||||||
#include "codeview/codeview_stringize.c"
|
#include "codeview/codeview_parse.c"
|
||||||
#include "msf/msf.c"
|
#include "msf/msf.c"
|
||||||
#include "msf/msf_parse.c"
|
#include "msf/msf_parse.c"
|
||||||
#include "pdb/pdb.c"
|
#include "pdb/pdb.c"
|
||||||
|
|||||||
@@ -3127,7 +3127,7 @@ p2r_convert(Arena *arena, P2R_User2Convert *in)
|
|||||||
//- rjf: parse PDB auth_guid & named streams table
|
//- rjf: parse PDB auth_guid & named streams table
|
||||||
//
|
//
|
||||||
PDB_NamedStreamTable *named_streams = 0;
|
PDB_NamedStreamTable *named_streams = 0;
|
||||||
COFF_Guid auth_guid = {0};
|
Guid auth_guid = {0};
|
||||||
if(msf != 0) ProfScope("parse PDB auth_guid & named streams table")
|
if(msf != 0) ProfScope("parse PDB auth_guid & named streams table")
|
||||||
{
|
{
|
||||||
Temp scratch = scratch_begin(&arena, 1);
|
Temp scratch = scratch_begin(&arena, 1);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
#include "rdi_make/rdi_make_local.h"
|
#include "rdi_make/rdi_make_local.h"
|
||||||
#include "coff/coff.h"
|
#include "coff/coff.h"
|
||||||
#include "codeview/codeview.h"
|
#include "codeview/codeview.h"
|
||||||
#include "codeview/codeview_stringize.h"
|
#include "codeview/codeview_parse.h"
|
||||||
#include "msf/msf.h"
|
#include "msf/msf.h"
|
||||||
#include "msf/msf_parse.h"
|
#include "msf/msf_parse.h"
|
||||||
#include "pdb/pdb.h"
|
#include "pdb/pdb.h"
|
||||||
@@ -38,7 +38,7 @@
|
|||||||
#include "rdi_make/rdi_make_local.c"
|
#include "rdi_make/rdi_make_local.c"
|
||||||
#include "coff/coff.c"
|
#include "coff/coff.c"
|
||||||
#include "codeview/codeview.c"
|
#include "codeview/codeview.c"
|
||||||
#include "codeview/codeview_stringize.c"
|
#include "codeview/codeview_parse.c"
|
||||||
#include "msf/msf.c"
|
#include "msf/msf.c"
|
||||||
#include "msf/msf_parse.c"
|
#include "msf/msf_parse.c"
|
||||||
#include "pdb/pdb.c"
|
#include "pdb/pdb.c"
|
||||||
|
|||||||
Reference in New Issue
Block a user