📄 dwarfread.c
字号:
case DW_ATE_signed_char: switch( bytesize ) { case 1: sym->type[sym->nextt++] = tChar; break; case 2: sym->type[sym->nextt++] = tShort; break; case 4: sym->type[sym->nextt++] = tInt; break; case 8: sym->type[sym->nextt++] = tLong; break; default: ASSERT(0); break; } break; case DW_ATE_boolean: /* we treat as a general unsigned value */ case DW_ATE_unsigned: case DW_ATE_unsigned_char: switch( bytesize ) { case 1: sym->type[sym->nextt++] = tUChar; break; case 2: sym->type[sym->nextt++] = tUShort; break; case 4: sym->type[sym->nextt++] = tUInt; break; case 8: sym->type[sym->nextt++] = tULong; break; default: ASSERT(0); break; } break; case DW_ATE_complex_float: case DW_ATE_address: /* not sure what this is */ default: ASSERT(0); break; } break; case DW_TAG_array_type: sym->type[sym->nextt++] = tArray; FillInBasicType(sym, di.ddie, bitsize, exec); *bitsize = 0; break; case DW_TAG_entry_point: ASSERT(0); break; case DW_TAG_enumeration_type: sym->type[sym->nextt++] = tEnum; if( dwarf_bytesize( ddie, &bytesize, &rc ) != DW_DLV_OK) { CPUWarning("dwarf_bytesize failed: %s\n", dwarf_errmsg( rc ) ); ASSERT(0); } *bitsize = 8*bytesize; break; case DW_TAG_imported_declaration: case DW_TAG_lexical_block: case DW_TAG_member: case DW_TAG_variable: ASSERT(0); break; case DW_TAG_label: sym->type[sym->nextt++] = tLabel; *bitsize = 0; break; case DW_TAG_pointer_type: sym->type[sym->nextt++] = tPtr; if( dwarf_bytesize( ddie, &bytesize, &rc ) != DW_DLV_OK) { CPUWarning("dwarf_bytesize failed: %s\n", dwarf_errmsg( rc ) ); ASSERT(0); } *bitsize = 8*bytesize; break; case DW_TAG_reference_type: case DW_TAG_compile_unit: case DW_TAG_string_type: case DW_TAG_formal_parameter: ASSERT(0); break; case DW_TAG_class_type: case DW_TAG_structure_type: sym->type[sym->nextt++] = tStruct; if( dwarf_bytesize( ddie, &bytesize, &rc ) != DW_DLV_OK) { CPUWarning("dwarf_bytesize failed: %s\n", dwarf_errmsg( rc ) ); ASSERT(0); } *bitsize = 8*bytesize; break; case DW_TAG_subroutine_type: case DW_TAG_inlined_subroutine: case DW_TAG_subprogram: sym->type[sym->nextt++] = tPtr; *bitsize = 0; break; case DW_TAG_typedef:#ifdef notdef sym->type[sym->nextt++] = tTypedef; *bitsize = 0;#endif FillInBasicType(sym, di.ddie, bitsize, exec); break; case DW_TAG_union_type: sym->type[sym->nextt++] = tUnion; /* we possibly should recurse to get the bitsize */ *bitsize = 0; break; case DW_TAG_unspecified_parameters: case DW_TAG_variant: case DW_TAG_common_block: case DW_TAG_common_inclusion: case DW_TAG_inheritance: case DW_TAG_module: case DW_TAG_ptr_to_member_type: case DW_TAG_set_type: case DW_TAG_subrange_type: case DW_TAG_with_stmt: case DW_TAG_access_declaration: case DW_TAG_catch_block: case DW_TAG_const_type: case DW_TAG_constant: case DW_TAG_enumerator: case DW_TAG_file_type: case DW_TAG_friend: case DW_TAG_namelist: case DW_TAG_namelist_item: case DW_TAG_packed_type: case DW_TAG_template_type_param: case DW_TAG_template_value_param: case DW_TAG_thrown_type: case DW_TAG_try_block: case DW_TAG_variant_part: case DW_TAG_volatile_type: case DW_TAG_lo_user: case DW_TAG_MIPS_loop: case DW_TAG_hi_user: ASSERT(0); break; default: ASSERT(0); break; } freedieinfo(&di,exec);}static intFillInSym( Symb *sym, DIE_REF dieref, Execfile *exec ){ Dwarf_Error rc; struct dieinfo di; int err; Dwarf_Addr atmp; Dwarf_Locdesc *loclist; Dwarf_Signed signedtmp; Dwarf_Unsigned bitsize; Dwarf_Off type; basicdieinfo (&di, NULL, dieref, exec); /* we use the isym field for the dieref field, even though it's not * strictly speaking big enough. */ sym->global = 0; sym->isym = (int)dieref; sym->exec = exec; sym->nextt = 1; sym->value = 0xbeeebaaabeeebaaaLL; /* to help catch errors */ sym->index = DWARF_INDEX; /* special tornado marker */ switch (di.die_tag) { case DW_TAG_entry_point: ASSERT(0); break; case DW_TAG_array_type: type = GetTypeAbsOffset(di.ddie, exec); ASSERT(type != 0); freedieinfo(&di,exec); return FillInSym(sym, type, exec); case DW_TAG_enumeration_type: sym->type[sym->nextt++] = tEnumDef; break; case DW_TAG_imported_declaration: ASSERT(0); break; case DW_TAG_lexical_block: sym->type[sym->nextt++] = tBlock; break; case DW_TAG_variable: FillInBasicType(sym, di.ddie, &bitsize, exec); sym->value = GetLocation(di.ddie,exec); break; case DW_TAG_member: FillInBasicType(sym, di.ddie, &bitsize, exec); sym->value = 8*GetLocation(di.ddie,exec); /* offset in structure */ break; case DW_TAG_pointer_type: { Dwarf_Unsigned dummy; sym->type[sym->nextt++] = tPtr; FillInBasicType( sym, di.ddie, &dummy, exec ); break; } case DW_TAG_reference_type: case DW_TAG_compile_unit: case DW_TAG_string_type: case DW_TAG_formal_parameter: ASSERT(0); break; case DW_TAG_class_type: case DW_TAG_structure_type: sym->type[sym->nextt++] = tStructDef; if( dwarf_bytesize( di.ddie, &bitsize, &rc ) != DW_DLV_OK) { CPUWarning("dwarf_bytesize failed: %s\n", dwarf_errmsg( rc ) ); ASSERT(0); } sym->value = bitsize; /* ok, really bytesize here */ break; case DW_TAG_label: sym->type[sym->nextt++] = tLabel; if( dwarf_lowpc( di.ddie, &atmp, &rc ) != DW_DLV_OK) { CPUWarning("dwarf_lowpc failed: %s\n", dwarf_errmsg( rc ) ); ASSERT(0); } sym->value = atmp; break; case DW_TAG_subroutine_type: case DW_TAG_inlined_subroutine: case DW_TAG_subprogram: sym->type[sym->nextt++] = tProc; if( dwarf_lowpc( di.ddie, &atmp, &rc ) != DW_DLV_OK) { CPUWarning("dwarf_lowpc failed: %s\n", dwarf_errmsg( rc ) ); ASSERT(0); } sym->value = atmp;#ifdef TORNADO /* problems with constructor return values (refs) so just ignore * for now, as I don't think we really care */#else FillInBasicType(sym, di.ddie, &bitsize, exec);#endif break; case DW_TAG_typedef:#ifdef notdef sym->type[sym->nextt++] = tTypedefDef; FillInBasicType(sym, di.ddie, &bitsize, exec);#endif type = GetTypeAbsOffset(di.ddie, exec); ASSERT(type != 0); freedieinfo(&di,exec); return FillInSym(sym, type, exec); case DW_TAG_union_type: sym->type[sym->nextt++] = tUnionDef; break; case DW_TAG_unspecified_parameters: case DW_TAG_variant: case DW_TAG_common_block: case DW_TAG_common_inclusion: case DW_TAG_inheritance: case DW_TAG_module: case DW_TAG_ptr_to_member_type: case DW_TAG_set_type: case DW_TAG_subrange_type: case DW_TAG_with_stmt: case DW_TAG_access_declaration: case DW_TAG_base_type: case DW_TAG_catch_block: case DW_TAG_const_type: case DW_TAG_constant: case DW_TAG_enumerator: case DW_TAG_file_type: case DW_TAG_friend: case DW_TAG_namelist: case DW_TAG_namelist_item: case DW_TAG_packed_type: case DW_TAG_template_type_param: case DW_TAG_template_value_param: case DW_TAG_thrown_type: case DW_TAG_try_block: case DW_TAG_variant_part: case DW_TAG_volatile_type: case DW_TAG_lo_user: case DW_TAG_MIPS_loop: case DW_TAG_hi_user: ASSERT(0); break; default: ASSERT(0); break; } ASSERT(sym->nextt<MAX_TYPES); sym->type[sym->nextt] = tNil; sym->nextt = 1; freedieinfo(&di,exec); return SYM_OK;}static voidscan_partial_symbols ( Dwarf_Die ddie, Execfile *exec, Srcfile *src ){ char *nextdie; char *temp; struct dieinfo di; Dwarf_Die nextddie; Dwarf_Bool btmp1, btmp2; Dwarf_Error rc; while (ddie) { basicdieinfo (&di, ddie, 0, exec); nextddie = di.sibdie; di.sibdie = NULL; /* ensure not freed */ switch (di.die_tag) { case DW_TAG_subprogram: case DW_TAG_variable: dwarf_hasattr(ddie,DW_AT_low_pc,&btmp1,&rc); dwarf_hasattr(ddie,DW_AT_location,&btmp2,&rc); if ( di.at_name && (btmp1 || btmp2) ) { (void)add_global(&di, exec->globals); (void)add_global(&di, src->globals); } break; case DW_TAG_typedef: if (di.at_name) { (void)add_global(&di, exec->globals); (void)add_global(&di, src->globals); } break; case DW_TAG_class_type: case DW_TAG_structure_type: case DW_TAG_union_type: case DW_TAG_enumeration_type: if (di.at_name) { (void)add_global(&di, exec->gStructs); (void)add_global(&di, src->globals); } break; } freedieinfo(&di,exec); ddie = nextddie; }}static voidscan_compilation_units (Execfile *exec){ struct dieinfo di; int culength; int curoff; Dwarf_Error rc; Dwarf_Unsigned length; Dwarf_Half version; Dwarf_Off offset; Dwarf_Half addrsize; Dwarf_Unsigned next; Dwarf_Die ddie; Dwarf_Die nextddie; Dwarf_Half tagval; int err; int fd; Srcfile *src; VA low_pc; VA high_pc; while (1) { err = dwarf_next_cu_header( exec->dwarf, &length, &version, &offset, &addrsize, &next, &rc ); if( err == DW_DLV_NO_ENTRY ) { break; } else if( err != DW_DLV_OK) { CPUWarning("dwarf_next_cu_header failed: %s\n", dwarf_errmsg(rc) ); ASSERT(0); } if( version != 2 ) { CPUWarning("Wrong dwarf version: %u != 2\n", version); ASSERT(0); } if( dwarf_siblingof( exec->dwarf, NULL, &ddie, &rc ) != DW_DLV_OK) { CPUWarning("dwarf_siblingof failed: %s\n", dwarf_errmsg( rc ) ); ASSERT(0); } basicdieinfo (&di, ddie, 0, exec); if (di.die_tag != DW_TAG_compile_unit) { CPUWarning("Not a compilation unit! (%x)\n", di.die_tag); ASSERT(0); } else { /*CPUWarning("Found cu '%s'\n", di.at_name);*/ decode_line_numbers (di.ddie, &low_pc, &high_pc, exec); /* fill in source structure information and add to table */ if (AssocTabLookup(exec->srcs, StripPath(di.at_name), NULL) == AT_OK) { /* nothing */ CPUWarning("'%s' is a duplicate cu\n", di.at_name); } else { src = (Srcfile*)malloc(sizeof(Srcfile)); src->head.label = SaveString(StripPath(di.at_name)); src->globals = AssocTabCreate(); src->lopc = low_pc;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -