dbghelp: Attempt to cache some basic symbol types for easier and faster code.

This commit is contained in:
Eric Pouech 2008-02-06 21:56:06 +01:00 committed by Alexandre Julliard
parent 75803e9448
commit 43afc9178b
1 changed files with 42 additions and 5 deletions

View File

@ -167,6 +167,13 @@ typedef struct dwarf2_traverse_context_s
unsigned char word_size; unsigned char word_size;
} dwarf2_traverse_context_t; } dwarf2_traverse_context_t;
/* symt_cache indexes */
#define sc_void 0
#define sc_int1 1
#define sc_int2 2
#define sc_int4 3
#define sc_num 4
typedef struct dwarf2_parse_context_s typedef struct dwarf2_parse_context_s
{ {
const dwarf2_section_t* sections; const dwarf2_section_t* sections;
@ -179,6 +186,7 @@ typedef struct dwarf2_parse_context_s
unsigned long load_offset; unsigned long load_offset;
unsigned long ref_offset; unsigned long ref_offset;
unsigned char word_size; unsigned char word_size;
struct symt* symt_cache[sc_num]; /* void, int1, int2, int4 */
} dwarf2_parse_context_t; } dwarf2_parse_context_t;
/* stored in the dbghelp's module internal structure for later reuse */ /* stored in the dbghelp's module internal structure for later reuse */
@ -932,7 +940,7 @@ static struct symt* dwarf2_parse_base_type(dwarf2_parse_context_t* ctx,
struct attribute size; struct attribute size;
struct attribute encoding; struct attribute encoding;
enum BasicType bt; enum BasicType bt;
int cache_idx = -1;
if (di->symt) return di->symt; if (di->symt) return di->symt;
TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di)); TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
@ -956,6 +964,25 @@ static struct symt* dwarf2_parse_base_type(dwarf2_parse_context_t* ctx,
default: bt = btNoType; break; default: bt = btNoType; break;
} }
di->symt = &symt_new_basic(ctx->module, bt, name.u.string, size.u.uvalue)->symt; di->symt = &symt_new_basic(ctx->module, bt, name.u.string, size.u.uvalue)->symt;
switch (bt)
{
case btVoid:
assert(size.u.uvalue == 0);
cache_idx = sc_void;
break;
case btInt:
switch (size.u.uvalue)
{
case 1: cache_idx = sc_int1; break;
case 2: cache_idx = sc_int2; break;
case 4: cache_idx = sc_int4; break;
}
break;
default: break;
}
if (!ctx->symt_cache[cache_idx])
ctx->symt_cache[cache_idx] = di->symt;
if (di->abbrev->have_child) FIXME("Unsupported children\n"); if (di->abbrev->have_child) FIXME("Unsupported children\n");
return di->symt; return di->symt;
} }
@ -991,8 +1018,10 @@ static struct symt* dwarf2_parse_pointer_type(dwarf2_parse_context_t* ctx,
if (!dwarf2_find_attribute(ctx, di, DW_AT_byte_size, &size)) size.u.uvalue = 0; if (!dwarf2_find_attribute(ctx, di, DW_AT_byte_size, &size)) size.u.uvalue = 0;
if (!(ref_type = dwarf2_lookup_type(ctx, di))) if (!(ref_type = dwarf2_lookup_type(ctx, di)))
ref_type = &symt_new_basic(ctx->module, btVoid, "void", 0)->symt; {
ref_type = ctx->symt_cache[sc_void];
assert(ref_type);
}
di->symt = &symt_new_pointer(ctx->module, ref_type)->symt; di->symt = &symt_new_pointer(ctx->module, ref_type)->symt;
if (di->abbrev->have_child) FIXME("Unsupported children\n"); if (di->abbrev->have_child) FIXME("Unsupported children\n");
return di->symt; return di->symt;
@ -1564,7 +1593,10 @@ static struct symt* dwarf2_parse_subprogram(dwarf2_parse_context_t* ctx,
is_decl.u.uvalue = 0; is_decl.u.uvalue = 0;
if (!(ret_type = dwarf2_lookup_type(ctx, di))) if (!(ret_type = dwarf2_lookup_type(ctx, di)))
ret_type = &symt_new_basic(ctx->module, btVoid, "void", 0)->symt; {
ret_type = ctx->symt_cache[sc_void];
assert(ret_type);
}
/* FIXME: assuming C source code */ /* FIXME: assuming C source code */
sig_type = symt_new_function_signature(ctx->module, ret_type, CV_CALL_FAR_C); sig_type = symt_new_function_signature(ctx->module, ret_type, CV_CALL_FAR_C);
@ -1657,7 +1689,10 @@ static struct symt* dwarf2_parse_subroutine_type(dwarf2_parse_context_t* ctx,
TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di)); TRACE("%s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_di(di));
if (!(ret_type = dwarf2_lookup_type(ctx, di))) if (!(ret_type = dwarf2_lookup_type(ctx, di)))
ret_type = &symt_new_basic(ctx->module, btVoid, "void", 0)->symt; {
ret_type = ctx->symt_cache[sc_void];
assert(ret_type);
}
/* FIXME: assuming C source code */ /* FIXME: assuming C source code */
sig_type = symt_new_function_signature(ctx->module, ret_type, CV_CALL_FAR_C); sig_type = symt_new_function_signature(ctx->module, ret_type, CV_CALL_FAR_C);
@ -1979,6 +2014,8 @@ static BOOL dwarf2_parse_compilation_unit(const dwarf2_section_t* sections,
ctx.thunks = thunks; ctx.thunks = thunks;
ctx.load_offset = load_offset; ctx.load_offset = load_offset;
ctx.ref_offset = comp_unit_cursor - sections[section_debug].address; ctx.ref_offset = comp_unit_cursor - sections[section_debug].address;
memset(ctx.symt_cache, 0, sizeof(ctx.symt_cache));
ctx.symt_cache[sc_void] = &symt_new_basic(module, btVoid, "void", 0)->symt;
traverse.start_data = comp_unit_cursor + sizeof(dwarf2_comp_unit_stream_t); traverse.start_data = comp_unit_cursor + sizeof(dwarf2_comp_unit_stream_t);
traverse.data = traverse.start_data; traverse.data = traverse.start_data;