@@ -1060,12 +1060,71 @@ SmxV1Image::GetFileName(size_t index) const
1060
1060
return debug_names_ + debug_files_[index ].name ;
1061
1061
}
1062
1062
1063
+ template <typename SymbolType, typename DimType>
1064
+ uint32_t
1065
+ SmxV1Image::getFunctionCount (const SymbolType* syms) const {
1066
+ const uint8_t * cursor = reinterpret_cast <const uint8_t *>(syms);
1067
+ const uint8_t * cursor_end = cursor + debug_symbols_section_->size ;
1068
+ uint32_t func_count = 0 ;
1069
+ for (uint32_t i = 0 ; i < debug_info_->num_syms ; i++) {
1070
+ if (cursor + sizeof (SymbolType) > cursor_end)
1071
+ break ;
1072
+
1073
+ const SymbolType* sym = reinterpret_cast <const SymbolType*>(cursor);
1074
+ if (sym->ident == sp::IDENT_FUNCTION)
1075
+ func_count++;
1076
+
1077
+ if (sym->dimcount > 0 )
1078
+ cursor += sizeof (DimType) * sym->dimcount ;
1079
+ cursor += sizeof (SymbolType);
1080
+ }
1081
+ return func_count;
1082
+ }
1083
+
1063
1084
size_t
1064
1085
SmxV1Image::NumFunctions () const {
1065
1086
if (rtti_methods_) {
1066
1087
return rtti_methods_->row_count ;
1067
1088
}
1068
- return 0 ;
1089
+
1090
+ // Count function symbols once.
1091
+ static uint32_t num_debug_functions = 0 ;
1092
+ if (num_debug_functions == 0 ) {
1093
+ if (debug_syms_)
1094
+ num_debug_functions = getFunctionCount<sp_fdbg_symbol_t , sp_fdbg_arraydim_t >(debug_syms_);
1095
+ else
1096
+ num_debug_functions = getFunctionCount<sp_u_fdbg_symbol_t , sp_u_fdbg_arraydim_t >(debug_syms_unpacked_);
1097
+ }
1098
+ return num_debug_functions;
1099
+ }
1100
+
1101
+ template <typename SymbolType, typename DimType>
1102
+ const char *
1103
+ SmxV1Image::getFunctionName (const SymbolType* syms, const char ** filename, uint32_t index) const {
1104
+ const uint8_t * cursor = reinterpret_cast <const uint8_t *>(syms);
1105
+ const uint8_t * cursor_end = cursor + debug_symbols_section_->size ;
1106
+ uint32_t func_count = 0 ;
1107
+ for (uint32_t i = 0 ; i < debug_info_->num_syms ; i++) {
1108
+ if (cursor + sizeof (SymbolType) > cursor_end)
1109
+ break ;
1110
+
1111
+ const SymbolType* sym = reinterpret_cast <const SymbolType*>(cursor);
1112
+ if (sym->ident == sp::IDENT_FUNCTION) {
1113
+ if (func_count == index ) {
1114
+ if (filename)
1115
+ *filename = LookupFile (sym->addr );
1116
+ if (sym->name < debug_names_section_->size )
1117
+ return debug_names_ + sym->name ;
1118
+ return nullptr ;
1119
+ }
1120
+ func_count++;
1121
+ }
1122
+
1123
+ if (sym->dimcount > 0 )
1124
+ cursor += sizeof (DimType) * sym->dimcount ;
1125
+ cursor += sizeof (SymbolType);
1126
+ }
1127
+ return nullptr ;
1069
1128
}
1070
1129
1071
1130
const char *
@@ -1079,7 +1138,12 @@ SmxV1Image::GetFunctionName(size_t index, const char** filename) const {
1079
1138
*filename = LookupFile (method->pcode_start );
1080
1139
return names_ + method->name ;
1081
1140
}
1082
- return nullptr ;
1141
+
1142
+ if (debug_syms_) {
1143
+ return getFunctionName<sp_fdbg_symbol_t , sp_fdbg_arraydim_t >(debug_syms_, filename, index );
1144
+ } else {
1145
+ return getFunctionName<sp_u_fdbg_symbol_t , sp_u_fdbg_arraydim_t >(debug_syms_unpacked_, filename, index );
1146
+ }
1083
1147
}
1084
1148
1085
1149
template <typename SymbolType, typename DimType>
0 commit comments