00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef __cplusplus
00042 #error This header must be compiled as C++
00043 #endif
00044
00045
00046
00047
00048
00049
00050
00051 #ifndef IPC_DST_UTILS_included
00052 #define IPC_DST_UTILS_included
00053
00054 #define USE_STANDARD_TYPES
00055 #define USE_DST_INTERNALS
00056 #include "dwarf_DST_mem.h"
00057 #include "dwarf_DST.h"
00058 #include "mempool.h"
00059 #include "errors.h"
00060
00061 #include <iterator>
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 inline void* DST_IDX_to_ptr(DST_TYPE dst_vptr, DST_IDX idx) {
00074 DST_Type* dst = static_cast<DST_Type*>(dst_vptr);
00075
00076 Is_True(dst != 0, ("DST pointer is null"));
00077 Is_True(idx.block_idx != DST_INVALID_BLOCK_IDX &&
00078 idx.block_idx >= 0 &&
00079 idx.block_idx <= dst->last_block_header,
00080 ("Invalid DST index %d:%d", idx.byte_idx, idx.block_idx));
00081 block_header& block = dst->dst_blocks[idx.block_idx];
00082 Is_True(idx.byte_idx != DST_INVALID_BYTE_IDX &&
00083 idx.byte_idx >= 0 &&
00084 idx.byte_idx < block.size,
00085 ("Invalid DST index %d:%d", idx.byte_idx, idx.block_idx));
00086 return block.offset + idx.byte_idx;
00087 }
00088
00089 inline char* DST_IDX_to_string(DST_TYPE dst, DST_IDX idx) {
00090 return static_cast<char*>(DST_IDX_to_ptr(dst, idx));
00091 }
00092
00093
00094 inline block_header& DST_get_block(DST_TYPE dst_vptr, DST_BLOCK_IDX block_idx)
00095 {
00096 DST_Type* dst = static_cast<DST_Type*>(dst_vptr);
00097
00098 Is_True(dst != 0, ("DST pointer is null"));
00099 Is_True(block_idx >= 0 && block_idx <= dst->last_block_header,
00100 ("Invalid block idx %d, should be in range 0 <= idx <= %d",
00101 block_idx, dst->last_block_header));
00102 return dst->dst_blocks[block_idx];
00103 }
00104
00105
00106 inline bool DST_block_is_empty(const block_header& block) {
00107 Is_True(block.size >= 0,
00108 ("Block size is %d, should be nonnegative", block.size));
00109 return block.size == 0;
00110 }
00111
00112
00113 inline bool DST_has_block_of_kind(DST_TYPE dst_vptr, DST_BLOCK_KIND kind) {
00114 Is_True(dst_vptr != 0, ("DST pointer is null"));
00115 Is_True(kind >= DST_include_dirs_block && kind < DST_noblock,
00116 ("Invalid block kind"));
00117 DST_Type* dst = static_cast<DST_Type*>(dst_vptr);
00118 Is_True(dst->block_list[kind] == DST_INVALID_BLOCK_IDX ||
00119 DST_get_block(dst_vptr, dst->block_list[kind]).kind == kind,
00120 ("Inconsistent block list: kind is %d, should be %d",
00121 DST_get_block(dst_vptr, dst->block_list[kind]).kind, kind));
00122 return dst->block_list[kind] != DST_INVALID_BLOCK_IDX;
00123 }
00124
00125
00126
00127 inline block_header&
00128 DST_first_block_of_kind(DST_TYPE dst_vptr, DST_BLOCK_KIND kind) {
00129 Is_True(dst_vptr != 0, ("DST pointer is null"));
00130 Is_True(kind >= DST_include_dirs_block && kind < DST_noblock,
00131 ("Invalid block kind"));
00132 Is_True(DST_has_block_of_kind(dst_vptr, kind),
00133 ("No block of kind %d", kind));
00134
00135 DST_Type* dst = static_cast<DST_Type*>(dst_vptr);
00136 return DST_get_block(dst, dst->block_list[kind]);
00137 }
00138
00139
00140 inline bool DST_has_compile_unit(DST_TYPE dst_vptr) {
00141 return DST_has_block_of_kind(dst_vptr, DST_file_scope_block) &&
00142 !DST_block_is_empty(DST_first_block_of_kind(dst_vptr,
00143 DST_file_scope_block));
00144 }
00145
00146
00147
00148 DST_IDX DST_get_compile_unit(DST_TYPE dst);
00149
00150
00151
00152 DST_IDX DST_get_include_dirs(DST_TYPE);
00153
00154
00155
00156 DST_IDX DST_get_file_names(DST_TYPE);
00157
00158
00159 inline DST_INFO* DST_get_info(DST_TYPE dst, DST_IDX info_idx) {
00160 Is_True(dst != 0, ("DST pointer is null"));
00161 return static_cast<DST_INFO*>(DST_IDX_to_ptr(dst, info_idx));
00162 }
00163
00164
00165
00166 inline DST_COMPILE_UNIT*
00167 DST_get_compile_unit_attr(DST_TYPE dst, DST_INFO* info) {
00168 DST_IDX attr_idx = DST_INFO_attributes(info);
00169 Is_True(DST_INFO_tag(info) == DW_TAG_compile_unit, ("Not a compile unit"));
00170 Is_True( !DST_ARE_EQUAL(attr_idx, DST_INVALID_IDX), ("Compile unit attr idx is null"));
00171 return static_cast<DST_COMPILE_UNIT*>(DST_IDX_to_ptr(dst, attr_idx));
00172 }
00173
00174
00175
00176 inline DST_SUBPROGRAM*
00177 DST_get_subprogram_attr(DST_TYPE dst, DST_INFO* info) {
00178 DST_IDX attr_idx = DST_INFO_attributes(info);
00179 Is_True(DST_INFO_tag(info) == DW_TAG_subprogram, ("Not a subprogram"));
00180 Is_True( !DST_ARE_EQUAL(attr_idx, DST_INVALID_IDX), ("Subprogram unit attr idx is null"));
00181 return static_cast<DST_SUBPROGRAM*>(DST_IDX_to_ptr(dst, attr_idx));
00182 }
00183
00184
00185 inline DST_INCLUDE_DIR* DST_get_include_dir(DST_TYPE dst, DST_IDX idx) {
00186 Is_True(dst != 0, ("DST_get_include_dir: null dst pointer"));
00187 Is_True( !DST_ARE_EQUAL(idx, DST_INVALID_IDX), ("DST_get_include_dir: bad dst index"));
00188 return static_cast<DST_INCLUDE_DIR*>(DST_IDX_to_ptr(dst, idx));
00189 }
00190
00191
00192 inline DST_FILE_NAME* DST_get_file_name(DST_TYPE dst, DST_IDX idx) {
00193 Is_True(dst != 0, ("DST_get_file_name: null dst pointer"));
00194 Is_True( !DST_ARE_EQUAL(idx, DST_INVALID_IDX), ("DST_get_file_name: bad dst index"));
00195 return static_cast<DST_FILE_NAME*>(DST_IDX_to_ptr(dst, idx));
00196 }
00197
00198 inline bool DST_SUBPROGRAM_has_spec(DST_INFO* info) {
00199 Is_True(info != 0, ("DST_INFO pointer must not be null"));
00200 Is_True(DST_INFO_tag(info) == DW_TAG_subprogram, ("Not a subprogram node"));
00201 return DST_IS_memdef(DST_INFO_flag(info)) ||
00202 !DST_IS_declaration(DST_INFO_flag(info));
00203 }
00204
00205 inline bool DST_SUBPROGRAM_has_origin(DST_INFO* info) {
00206 Is_True(info != 0, ("DST_INFO pointer must not be null"));
00207 Is_True(DST_INFO_tag(info) == DW_TAG_subprogram, ("Not a subprogram node"));
00208 return DST_IS_declaration(DST_INFO_flag(info)) ||
00209 DST_IS_memdef(DST_INFO_flag(info));
00210 }
00211
00212 inline DST_IDX& DST_SUBPROGRAM_spec(DST_INFO* info, DST_SUBPROGRAM* attr) {
00213 Is_True(info != 0, ("DST_INFO pointer must not be null"));
00214 Is_True(DST_INFO_tag(info) == DW_TAG_subprogram, ("Not a subprogram node"));
00215 Is_True(DST_SUBPROGRAM_has_spec(info),
00216 ("Not a memdef or subprogram definition node"));
00217 if (DST_IS_memdef(DST_INFO_flag(info)))
00218 return DST_SUBPROGRAM_memdef_spec(attr);
00219 else
00220 return DST_SUBPROGRAM_def_specification(attr);
00221 }
00222
00223 inline DST_IDX& DST_SUBPROGRAM_origin(DST_INFO* info, DST_SUBPROGRAM* attr) {
00224 Is_True(info != 0, ("DST_INFO pointer must not be null"));
00225 Is_True(DST_INFO_tag(info) == DW_TAG_subprogram, ("Not a subprogram node"));
00226 Is_True(DST_SUBPROGRAM_has_origin(info),
00227 ("Not a subprogram declaration or subprogram definition node"));
00228 if (DST_IS_declaration(DST_INFO_flag(info)))
00229 return DST_SUBPROGRAM_decl_origin(attr);
00230 else
00231 return DST_SUBPROGRAM_def_clone_origin(attr);
00232 }
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 DST_TYPE DST_create(MEM_POOL*, UINT32 num_block_headers = 1024);
00249
00250
00251 block_header* DST_set_current_block(DST_TYPE, DST_BLOCK_IDX);
00252
00253
00254 DST_BLOCK_IDX
00255 DST_new_block(DST_TYPE, MEM_POOL*, DST_BLOCK_KIND, INT32 blocksize);
00256
00257
00258
00259
00260
00261 DST_IDX DST_allocate(DST_TYPE dst, MEM_POOL* p,
00262 INT32 size, INT32 align, DST_BLOCK_KIND kind);
00263
00264
00265
00266 DST_IDX DST_mk_string(DST_TYPE dst, MEM_POOL* p, const char* s);
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278 DST_IDX DST_mk_include_dir(DST_TYPE dst, MEM_POOL* p, const char* path,
00279 DST_IDX prev);
00280
00281
00282
00283
00284
00285 DST_IDX DST_mk_filename(DST_TYPE dst, MEM_POOL* p, const char* name,
00286 UINT16 dir, UINT64 size, UINT64 modt,
00287 DST_IDX prev);
00288
00289
00290 DST_IDX DST_copy_include_dir(DST_TYPE src, DST_TYPE dest,
00291 MEM_POOL* p,
00292 DST_IDX prev,
00293 DST_IDX old_index);
00294
00295
00296
00297
00298
00299 DST_IDX DST_copy_filename(DST_TYPE src, DST_TYPE dest,
00300 MEM_POOL* p,
00301 DST_IDX prev,
00302 DST_IDX old_index,
00303 UINT16 offset);
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 void DST_init_info(DST_TYPE dst, DST_IDX info_idx,
00315 DST_DW_tag tag, DST_flag flag,
00316 DST_ATTR_IDX attr,
00317 DST_INFO_IDX prev_info);
00318
00319
00320
00321
00322
00323 DST_IDX DST_mk_compile_unit(DST_TYPE dst,
00324 MEM_POOL* p,
00325 DST_IDX prev,
00326 const char* name,
00327 const char* comp_dir,
00328 const char* comp_info,
00329 DST_language language,
00330 DST_identifier_case id_case);
00331
00332
00333
00334
00335
00336 DST_IDX DST_copy_compile_unit(DST_TYPE src, DST_TYPE dest,
00337 MEM_POOL* p,
00338 DST_IDX prev,
00339 DST_IDX old_index);
00340
00341
00342
00343
00344
00345
00346
00347 DST_IDX DST_mk_subpr_decl(DST_TYPE dst,
00348 MEM_POOL* p,
00349 DST_IDX cu_idx,
00350 DST_IDX prev,
00351 USRCPOS decl,
00352 const char* name,
00353 const char* mangled_name,
00354 DST_inline inlin,
00355 DST_virtuality virtuality,
00356 DST_vtable_elem_location loc,
00357 DST_flag flag);
00358
00359 DST_IDX DST_mk_subpr_def(DST_TYPE dst,
00360 MEM_POOL* p,
00361 DST_IDX cu_idx,
00362 DST_IDX prev,
00363 USRCPOS decl,
00364 const char* name,
00365 const char* mangled_name,
00366 const char* pubname,
00367 DST_ASSOC_INFO st,
00368 DST_inline inlin,
00369 DST_virtuality virtuality,
00370 DST_vtable_elem_location loc,
00371 DST_flag flag);
00372
00373 DST_IDX DST_mk_memdef(DST_TYPE dst,
00374 MEM_POOL* p,
00375 DST_IDX cu_idx,
00376 DST_IDX prev,
00377 USRCPOS decl,
00378 DST_ASSOC_INFO st,
00379 DST_flag flag);
00380
00381
00382
00383
00384
00385 DST_IDX DST_copy_subprogram(DST_TYPE src, DST_TYPE dest,
00386 MEM_POOL* p,
00387 DST_IDX cu, DST_IDX prev,
00388 DST_IDX old_idx);
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398 struct DST_file_scope_iter {
00399
00400 typedef std::forward_iterator_tag iterator_category;
00401 typedef DST_IDX value_type;
00402 typedef UINT32 difference_type;
00403 typedef const DST_IDX* pointer;
00404 typedef const DST_IDX& reference;
00405
00406
00407 DST_file_scope_iter() : dst(0), idx(DST_INVALID_IDX) {}
00408 DST_file_scope_iter(DST_TYPE dst_vptr, DST_IDX cu_index, DST_IDX index) {
00409 dst = static_cast<DST_Type*>(dst_vptr);
00410 cu_idx = cu_index;
00411 idx = index;
00412 Is_True( DST_ARE_EQUAL(cu_idx, DST_INVALID_IDX) ||
00413 DST_INFO_tag(DST_get_info(dst, cu_idx)) == DW_TAG_compile_unit,
00414 ("Not a compile unit"));
00415 }
00416
00417 static DST_file_scope_iter begin(DST_TYPE dst) {
00418 DST_IDX cu_info_idx = DST_get_compile_unit(dst);
00419 DST_INFO* cu_info = DST_get_info(dst, cu_info_idx);
00420 DST_COMPILE_UNIT* cu = DST_get_compile_unit_attr(dst, cu_info);
00421 DST_IDX idx = DST_COMPILE_UNIT_first_child(cu);
00422 return DST_file_scope_iter(dst, cu_info_idx, idx);
00423 }
00424
00425 static DST_file_scope_iter end(DST_TYPE dst) {
00426 Is_True(dst != 0, ("Can't construct iterator with null DST"));
00427 return DST_file_scope_iter(dst, DST_INVALID_IDX, DST_INVALID_IDX);
00428 }
00429
00430
00431 const DST_IDX& operator*() const {
00432 Is_True(dst != 0, ("Iterator is singular"));
00433 Is_True( DST_ARE_EQUAL(idx, DST_INVALID_IDX), ("Iterator is past-the-end"));
00434 return idx;
00435 }
00436
00437 const DST_IDX* operator->() const {
00438 return &(operator*());
00439 }
00440
00441 DST_INFO* to_info_ptr() const {
00442 DST_IDX info_idx = *(*this);
00443 return static_cast<DST_INFO*>(DST_IDX_to_ptr(dst, info_idx));
00444 }
00445
00446 DST_file_scope_iter& operator++() {
00447 idx = DST_INFO_sibling(this->to_info_ptr());
00448 if( DST_ARE_EQUAL(idx,DST_INVALID_IDX) ){
00449 DST_INFO* old_cu_info = DST_get_info(dst, cu_idx);
00450 cu_idx = DST_INFO_sibling(old_cu_info);
00451 if( !DST_ARE_EQUAL(cu_idx, DST_INVALID_IDX)) {
00452 DST_INFO* cu_info = DST_get_info(dst, cu_idx);
00453 DST_COMPILE_UNIT* cu = DST_get_compile_unit_attr(dst, cu_info);
00454 idx = DST_COMPILE_UNIT_first_child(cu);
00455 }
00456 }
00457 return *this;
00458 }
00459
00460 DST_file_scope_iter operator++(int) {
00461 DST_file_scope_iter tmp(*this);
00462 ++*this;
00463 return tmp;
00464 }
00465
00466 bool operator== (const DST_file_scope_iter& x) const {
00467 return dst == x.dst && DST_ARE_EQUAL(cu_idx, x.cu_idx) && DST_ARE_EQUAL(idx, x.idx);
00468 }
00469 bool operator!= (const DST_file_scope_iter& x) const {
00470 return dst != x.dst || !DST_ARE_EQUAL(cu_idx, x.cu_idx) || !DST_ARE_EQUAL(idx, x.idx);
00471 }
00472
00473 private:
00474 DST_Type* dst;
00475 DST_IDX cu_idx;
00476 DST_IDX idx;
00477 };
00478
00479 #endif