1 /* Copyright (c) 2008-2013. The SimGrid Team.
2 * All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include <elfutils/libdw.h>
11 #include <simgrid_config.h>
13 #include <xbt/sysdep.h>
15 #include "mc_private.h"
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_dwarf, mc, "DWARF processing");
19 /** \brief The default DW_TAG_lower_bound for a given DW_AT_language.
21 * The default for a given language is defined in the DWARF spec.
23 * \param language consant as defined by the DWARf spec
25 static uint64_t MC_dwarf_default_lower_bound(int lang);
27 /** \brief Computes the the element_count of a DW_TAG_enumeration_type DIE
29 * This is the number of elements in a given array dimension.
31 * A reference of the compilation unit (DW_TAG_compile_unit) is
32 * needed because the default lower bound (when there is no DW_AT_lower_bound)
33 * depends of the language of the compilation unit (DW_AT_language).
35 * \param die DIE for the DW_TAG_enumeration_type or DW_TAG_subrange_type
36 * \param unit DIE of the DW_TAG_compile_unit
38 static uint64_t MC_dwarf_subrange_element_count(Dwarf_Die* die, Dwarf_Die* unit);
40 /** \brief Computes the number of elements of a given DW_TAG_array_type.
42 * \param die DIE for the DW_TAG_array_type
44 static uint64_t MC_dwarf_array_element_count(Dwarf_Die* die, Dwarf_Die* unit);
46 /** \brief Process a DIE
48 * \param info the resulting object fot the library/binary file (output)
49 * \param die the current DIE
50 * \param unit the DIE of the compile unit of the current DIE
51 * \param frame containg frame if any
53 static void MC_dwarf_handle_die(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit, dw_frame_t frame, const char* namespace);
55 /** \brief Process a type DIE
57 static void MC_dwarf_handle_type_die(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit, dw_frame_t frame, const char* namespace);
59 /** \brief Calls MC_dwarf_handle_die on all childrend of the given die
61 * \param info the resulting object fot the library/binary file (output)
62 * \param die the current DIE
63 * \param unit the DIE of the compile unit of the current DIE
64 * \param frame containg frame if any
66 static void MC_dwarf_handle_children(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit, dw_frame_t frame, const char* namespace);
68 /** \brief Handle a variable (DW_TAG_variable or other)
70 * \param info the resulting object fot the library/binary file (output)
71 * \param die the current DIE
72 * \param unit the DIE of the compile unit of the current DIE
73 * \param frame containg frame if any
75 static void MC_dwarf_handle_variable_die(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit, dw_frame_t frame, const char* namespace);
77 /** \brief Get the DW_TAG_type of the DIE
80 * \return DW_TAG_type attribute as a new string (NULL if none)
82 static char* MC_dwarf_at_type(Dwarf_Die* die);
84 /** \brief Get the name of an attribute (DW_AT_*) from its code
86 * \param attr attribute code (see the DWARF specification)
87 * \return name of the attribute
89 const char* MC_dwarf_attrname(int attr) {
91 #include "mc_dwarf_attrnames.h"
93 return "DW_AT_unknown";
97 /** \brief Get the name of a dwarf tag (DW_TAG_*) from its code
99 * \param tag tag code (see the DWARF specification)
100 * \return name of the tag
102 const char* MC_dwarf_tagname(int tag) {
104 #include "mc_dwarf_tagnames.h"
106 return "DW_TAG_invalid";
108 return "DW_TAG_unknown";
112 /** \brief A class of DWARF tags (DW_TAG_*)
114 typedef enum mc_tag_class {
123 static mc_tag_class MC_dwarf_tag_classify(int tag) {
126 case DW_TAG_array_type:
127 case DW_TAG_class_type:
128 case DW_TAG_enumeration_type:
130 case DW_TAG_pointer_type:
131 case DW_TAG_reference_type:
132 case DW_TAG_rvalue_reference_type:
133 case DW_TAG_string_type:
134 case DW_TAG_structure_type:
135 case DW_TAG_subroutine_type:
136 case DW_TAG_union_type:
137 case DW_TAG_ptr_to_member_type:
138 case DW_TAG_set_type:
139 case DW_TAG_subrange_type:
140 case DW_TAG_base_type:
141 case DW_TAG_const_type:
142 case DW_TAG_file_type:
143 case DW_TAG_packed_type:
144 case DW_TAG_volatile_type:
145 case DW_TAG_restrict_type:
146 case DW_TAG_interface_type:
147 case DW_TAG_unspecified_type:
148 case DW_TAG_mutable_type:
149 case DW_TAG_shared_type:
152 case DW_TAG_subprogram:
153 return mc_tag_subprogram;
155 case DW_TAG_variable:
156 case DW_TAG_formal_parameter:
157 return mc_tag_variable;
159 case DW_TAG_lexical_block:
160 case DW_TAG_try_block:
161 case DW_TAG_inlined_subroutine:
164 case DW_TAG_namespace:
165 return mc_tag_namespace;
168 return mc_tag_unknown;
173 #define MC_DW_CLASS_UNKNOWN 0
174 #define MC_DW_CLASS_ADDRESS 1 // Location in the address space of the program
175 #define MC_DW_CLASS_BLOCK 2 // Arbitrary block of bytes
176 #define MC_DW_CLASS_CONSTANT 3
177 #define MC_DW_CLASS_STRING 3 // String
178 #define MC_DW_CLASS_FLAG 4 // Boolean
179 #define MC_DW_CLASS_REFERENCE 5 // Reference to another DIE
180 #define MC_DW_CLASS_EXPRLOC 6 // DWARF expression/location description
181 #define MC_DW_CLASS_LINEPTR 7
182 #define MC_DW_CLASS_LOCLISTPTR 8
183 #define MC_DW_CLASS_MACPTR 9
184 #define MC_DW_CLASS_RANGELISTPTR 10
186 static int MC_dwarf_form_get_class(int form) {
189 return MC_DW_CLASS_ADDRESS;
194 return MC_DW_CLASS_BLOCK;
201 return MC_DW_CLASS_CONSTANT;
204 return MC_DW_CLASS_STRING;
205 case DW_FORM_ref_addr:
210 case DW_FORM_ref_udata:
211 return MC_DW_CLASS_REFERENCE;
213 case DW_FORM_flag_present:
214 return MC_DW_CLASS_FLAG;
215 case DW_FORM_exprloc:
216 return MC_DW_CLASS_EXPRLOC;
220 return MC_DW_CLASS_UNKNOWN;
224 /** \brief Get the name of the tag of a given DIE
227 * \return name of the tag of this DIE
229 static inline const char* MC_dwarf_die_tagname(Dwarf_Die* die) {
230 return MC_dwarf_tagname(dwarf_tag(die));
235 /** \brief Get an attribute of a given DIE as a string
238 * \param attribute attribute
239 * \return value of the given attribute of the given DIE
241 static const char* MC_dwarf_attr_string(Dwarf_Die* die, int attribute) {
242 Dwarf_Attribute attr;
243 if (!dwarf_attr_integrate(die, attribute, &attr)) {
246 return dwarf_formstring(&attr);
250 /** \brief Get the linkage name of a DIE.
252 * Use either DW_AT_linkage_name or DW_AR_MIPS_linkage_name.
255 * \return linkage name of the given DIE (or NULL)
257 static const char* MC_dwarf_at_linkage_name(Dwarf_Die* die) {
258 const char* name = MC_dwarf_attr_string(die, DW_AT_linkage_name);
260 name = MC_dwarf_attr_string(die, DW_AT_MIPS_linkage_name);
264 static char* MC_dwarf_at_type(Dwarf_Die* die) {
265 Dwarf_Attribute attr;
266 if (dwarf_hasattr_integrate(die, DW_AT_type)) {
267 dwarf_attr_integrate(die, DW_AT_type, &attr);
268 Dwarf_Die subtype_die;
269 if (dwarf_formref_die(&attr, &subtype_die)==NULL) {
270 xbt_die("Could not find DIE for type");
272 Dwarf_Off subtype_global_offset = dwarf_dieoffset(&subtype_die);
273 return bprintf("%" PRIx64 , subtype_global_offset);
278 static uint64_t MC_dwarf_attr_addr(Dwarf_Die* die, int attribute) {
279 Dwarf_Attribute attr;
280 if(dwarf_attr_integrate(die, attribute, &attr)==NULL)
283 if (dwarf_formaddr(&attr, &value) == 0)
284 return (uint64_t) value;
289 static uint64_t MC_dwarf_attr_uint(Dwarf_Die* die, int attribute, uint64_t default_value) {
290 Dwarf_Attribute attr;
291 if (dwarf_attr_integrate(die, attribute, &attr)==NULL)
292 return default_value;
294 return dwarf_formudata(dwarf_attr_integrate(die, attribute, &attr), &value) == 0 ? (uint64_t) value : default_value;
297 static bool MC_dwarf_attr_flag(Dwarf_Die* die, int attribute, int integrate) {
298 Dwarf_Attribute attr;
299 if ((integrate ? dwarf_attr_integrate(die, attribute, &attr)
300 : dwarf_attr(die, attribute, &attr))==0)
304 if (dwarf_formflag(&attr, &result))
305 xbt_die("Unexpected form for attribute %s",
306 MC_dwarf_attrname(attribute));
310 static uint64_t MC_dwarf_default_lower_bound(int lang) {
315 case DW_LANG_C_plus_plus:
319 case DW_LANG_ObjC_plus_plus:
325 case DW_LANG_Fortran77:
326 case DW_LANG_Fortran90:
327 case DW_LANG_Fortran95:
328 case DW_LANG_Modula2:
329 case DW_LANG_Pascal83:
331 case DW_LANG_Cobol74:
332 case DW_LANG_Cobol85:
335 xbt_die("No default MT_TAG_lower_bound for language %i and none given", lang);
340 static uint64_t MC_dwarf_subrange_element_count(Dwarf_Die* die, Dwarf_Die* unit) {
341 xbt_assert(dwarf_tag(die)==DW_TAG_enumeration_type ||dwarf_tag(die)==DW_TAG_subrange_type,
342 "MC_dwarf_subrange_element_count called with DIE of type %s", MC_dwarf_die_tagname(die));
344 // Use DW_TAG_count if present:
345 if (dwarf_hasattr_integrate(die, DW_AT_count)) {
346 return MC_dwarf_attr_uint(die, DW_AT_count, 0);
349 // Otherwise compute DW_TAG_upper_bound-DW_TAG_lower_bound + 1:
351 if (!dwarf_hasattr_integrate(die, DW_AT_upper_bound)) {
352 // This is not really 0, but the code expects this (we do not know):
355 uint64_t upper_bound = MC_dwarf_attr_uint(die, DW_AT_upper_bound, -1);
357 uint64_t lower_bound = 0;
358 if (dwarf_hasattr_integrate(die, DW_AT_lower_bound)) {
359 lower_bound = MC_dwarf_attr_uint(die, DW_AT_lower_bound, -1);
361 lower_bound = MC_dwarf_default_lower_bound(dwarf_srclang(unit));
363 return upper_bound - lower_bound + 1;
366 static uint64_t MC_dwarf_array_element_count(Dwarf_Die* die, Dwarf_Die* unit) {
367 xbt_assert(dwarf_tag(die)==DW_TAG_array_type,
368 "MC_dwarf_array_element_count called with DIE of type %s", MC_dwarf_die_tagname(die));
373 for (res=dwarf_child(die, &child); res==0; res=dwarf_siblingof(&child,&child)) {
374 int child_tag = dwarf_tag(&child);
375 if (child_tag==DW_TAG_subrange_type ||child_tag==DW_TAG_enumeration_type) {
376 result *= MC_dwarf_subrange_element_count(&child, unit);
384 static void MC_dwarf_fill_member_location(dw_type_t type, dw_type_t member, Dwarf_Die* child) {
385 if (dwarf_hasattr(child, DW_AT_data_bit_offset)) {
386 xbt_die("Can't groke DW_AT_data_bit_offset.");
389 if (!dwarf_hasattr_integrate(child, DW_AT_data_member_location)) {
390 if (type->type != DW_TAG_union_type) {
392 "Missing DW_AT_data_member_location field in DW_TAG_member %s of type <%p>%s",
393 member->name, type->id, type->name);
399 Dwarf_Attribute attr;
400 dwarf_attr_integrate(child, DW_AT_data_member_location, &attr);
401 int form = dwarf_whatform(&attr);
402 int klass = MC_dwarf_form_get_class(form);
404 case MC_DW_CLASS_EXPRLOC:
405 case MC_DW_CLASS_BLOCK:
406 // Location expression:
410 if (dwarf_getlocation(&attr, &expr, &len)) {
412 "Could not read location expression DW_AT_data_member_location in DW_TAG_member %s of type <%p>%s",
413 MC_dwarf_attr_string(child, DW_AT_name),
414 type->id, type->name);
416 if (len==1 && expr[0].atom == DW_OP_plus_uconst) {
417 member->offset = expr[0].number;
419 mc_dwarf_expression_init(&member->location, len, expr);
423 case MC_DW_CLASS_CONSTANT:
424 // Offset from the base address of the object:
427 if (!dwarf_formudata(&attr, &offset))
428 member->offset = offset;
430 xbt_die("Cannot get %s location <%p>%s",
431 MC_dwarf_attr_string(child, DW_AT_name),
432 type->id, type->name);
435 case MC_DW_CLASS_LOCLISTPTR:
436 // Reference to a location list:
438 case MC_DW_CLASS_REFERENCE:
439 // It's supposed to be possible in DWARF2 but I couldn't find its semantic
443 "Can't handle form class (%i) / form 0x%x as DW_AT_member_location",
449 static void dw_type_free_voidp(void *t){
450 dw_type_free((dw_type_t) * (void **) t);
453 static void MC_dwarf_add_members(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit, dw_type_t type) {
456 xbt_assert(!type->members);
457 type->members = xbt_dynar_new(sizeof(dw_type_t), (void(*)(void*))dw_type_free_voidp);
458 for (res=dwarf_child(die, &child); res==0; res=dwarf_siblingof(&child,&child)) {
459 int tag = dwarf_tag(&child);
460 if (tag==DW_TAG_member || tag==DW_TAG_inheritance) {
462 // Skip declarations:
463 if (MC_dwarf_attr_flag(&child, DW_AT_declaration, false))
466 // Skip compile time constants:
467 if(dwarf_hasattr(&child, DW_AT_const_value))
470 // TODO, we should use another type (because is is not a type but a member)
471 dw_type_t member = xbt_new0(s_dw_type_t, 1);
475 member->id = (void *) dwarf_dieoffset(&child);
477 const char* name = MC_dwarf_attr_string(&child, DW_AT_name);
479 member->name = xbt_strdup(name);
483 member->byte_size = MC_dwarf_attr_uint(&child, DW_AT_byte_size, 0);
484 member->element_count = -1;
485 member->dw_type_id = MC_dwarf_at_type(&child);
486 member->members = NULL;
487 member->is_pointer_type = 0;
490 if(dwarf_hasattr(&child, DW_AT_data_bit_offset)) {
491 xbt_die("Can't groke DW_AT_data_bit_offset.");
494 MC_dwarf_fill_member_location(type, member, &child);
496 if (!member->dw_type_id) {
497 xbt_die("Missing type for member %s of <%p>%s", member->name, type->id, type->name);
500 xbt_dynar_push(type->members, &member);
505 /** \brief Create a MC type object from a DIE
507 * \param info current object info object
508 * \param DIE (for a given type);
509 * \param unit compilation unit of the current DIE
510 * \return MC representation of the type
512 static dw_type_t MC_dwarf_die_to_type(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit, dw_frame_t frame, const char* namespace) {
514 dw_type_t type = xbt_new0(s_dw_type_t, 1);
519 type->element_count = -1;
520 type->dw_type_id = NULL;
521 type->members = NULL;
522 type->is_pointer_type = 0;
525 type->type = dwarf_tag(die);
528 type->id = (void *) dwarf_dieoffset(die);
530 const char* prefix = "";
531 switch (type->type) {
532 case DW_TAG_structure_type:
535 case DW_TAG_union_type:
538 case DW_TAG_class_type:
545 const char* name = MC_dwarf_attr_string(die, DW_AT_name);
547 type->name = namespace ? bprintf("%s%s::%s", prefix, namespace, name) : bprintf("%s%s", prefix, name);
550 XBT_DEBUG("Processing type <%p>%s", type->id, type->name);
552 type->dw_type_id = MC_dwarf_at_type(die);
554 // Computation of the byte_size;
555 if (dwarf_hasattr_integrate(die, DW_AT_byte_size))
556 type->byte_size = MC_dwarf_attr_uint(die, DW_AT_byte_size, 0);
557 else if (type->type == DW_TAG_array_type || type->type==DW_TAG_structure_type || type->type==DW_TAG_class_type) {
559 if (dwarf_aggregate_size(die, &size)==0) {
560 type->byte_size = size;
564 switch (type->type) {
565 case DW_TAG_array_type:
566 type->element_count = MC_dwarf_array_element_count(die, unit);
567 // TODO, handle DW_byte_stride and (not) DW_bit_stride
570 case DW_TAG_pointer_type:
571 case DW_TAG_reference_type:
572 case DW_TAG_rvalue_reference_type:
573 type->is_pointer_type = 1;
576 case DW_TAG_structure_type:
577 case DW_TAG_union_type:
578 case DW_TAG_class_type:
579 MC_dwarf_add_members(info, die, unit, type);
580 char* new_namespace = namespace == NULL ? xbt_strdup(type->name)
581 : bprintf("%s::%s", namespace, name);
582 MC_dwarf_handle_children(info, die, unit, frame, new_namespace);
590 static void MC_dwarf_handle_type_die(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit, dw_frame_t frame, const char* namespace) {
591 dw_type_t type = MC_dwarf_die_to_type(info, die, unit, frame, namespace);
593 char* key = bprintf("%" PRIx64, (uint64_t) type->id);
594 xbt_dict_set(info->types, key, type, NULL);
596 if(type->name && type->byte_size!=0) {
597 xbt_dict_set(info->full_types_by_name, type->name, type, NULL);
601 static int mc_anonymous_variable_index = 0;
603 static dw_variable_t MC_die_to_variable(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit, dw_frame_t frame, const char* namespace) {
604 // Skip declarations:
605 if (MC_dwarf_attr_flag(die, DW_AT_declaration, false))
608 // Skip compile time constants:
609 if(dwarf_hasattr(die, DW_AT_const_value))
612 Dwarf_Attribute attr_location;
613 if (dwarf_attr(die, DW_AT_location, &attr_location)==NULL) {
614 // No location: do not add it ?
618 dw_variable_t variable = xbt_new0(s_dw_variable_t, 1);
619 variable->dwarf_offset = dwarf_dieoffset(die);
620 variable->global = frame == NULL; // Can be override base on DW_AT_location
622 const char* name = MC_dwarf_attr_string(die, DW_AT_name);
623 variable->name = xbt_strdup(name);
625 variable->type_origin = MC_dwarf_at_type(die);
627 int form = dwarf_whatform(&attr_location);
628 int klass = form == DW_FORM_sec_offset ? MC_DW_CLASS_CONSTANT : MC_dwarf_form_get_class(form);
630 case MC_DW_CLASS_EXPRLOC:
631 case MC_DW_CLASS_BLOCK:
632 // Location expression:
636 if (dwarf_getlocation(&attr_location, &expr, &len)) {
638 "Could not read location expression in DW_AT_location of variable <%p>%s",
639 (void*) variable->dwarf_offset, variable->name);
642 if (len==1 && expr[0].atom == DW_OP_addr) {
643 variable->global = 1;
644 Dwarf_Off offset = expr[0].number;
645 // TODO, Why is this different base on the object?
646 Dwarf_Off base = strcmp(info->file_name, xbt_binary_name) !=0 ? (Dwarf_Off) info->start_exec : 0;
647 variable->address = (void*) (base + offset);
649 mc_dwarf_location_list_init_from_expression(&variable->locations, len, expr);
654 case MC_DW_CLASS_LOCLISTPTR:
655 case MC_DW_CLASS_CONSTANT:
656 // Reference to location list:
657 mc_dwarf_location_list_init(&variable->locations, info, die, &attr_location);
660 xbt_die("Unexpected form 0x%x (%i), class 0x%x (%i) list for location in <%p>%s",
661 form, form, klass, klass, (void*) variable->dwarf_offset, variable->name);
664 // Handle start_scope:
665 if (dwarf_hasattr(die, DW_AT_start_scope)) {
666 Dwarf_Attribute attr;
667 dwarf_attr(die, DW_AT_start_scope, &attr);
668 int form = dwarf_whatform(&attr);
669 int klass = MC_dwarf_form_get_class(form);
671 case MC_DW_CLASS_CONSTANT:
674 variable->start_scope = dwarf_formudata(&attr, &value) == 0 ? (size_t) value : 0;
678 xbt_die("Unhandled form 0x%x, class 0x%X for DW_AT_start_scope of variable %s",
679 form, klass, name==NULL ? "?" : name);
683 if(namespace && variable->global) {
684 char* old_name = variable->name;
685 variable->name = bprintf("%s::%s", namespace, old_name);
689 // The current code needs a variable name,
690 // generate a fake one:
691 if(!variable->name) {
692 variable->name = bprintf("@anonymous#%i", mc_anonymous_variable_index++);
698 static void MC_dwarf_handle_variable_die(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit, dw_frame_t frame, const char* namespace) {
699 dw_variable_t variable = MC_die_to_variable(info, die, unit, frame, namespace);
702 MC_dwarf_register_variable(info, frame, variable);
705 static void MC_dwarf_handle_subprogram_die(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit, dw_frame_t parent_frame, const char* namespace) {
707 // (Template) Subprogram declaration:
708 if (MC_dwarf_attr_flag(die, DW_AT_declaration, false))
711 dw_frame_t frame = xbt_new0(s_dw_frame_t, 1);
713 frame->start = dwarf_dieoffset(die);
715 const char* name = MC_dwarf_attr_string(die, DW_AT_name);
716 frame->name = namespace ? bprintf("%s::%s", namespace, name) : xbt_strdup(name);
718 // This is the base address for DWARF addresses.
719 // Relocated addresses are offset from this base address.
720 // See DWARF4 spec 7.5
721 void* base = info->flags & MC_OBJECT_INFO_EXECUTABLE ? 0 : MC_object_base_address(info);
723 // Variables are filled in the (recursive) call of MC_dwarf_handle_children:
724 frame->variables = xbt_dynar_new(sizeof(dw_variable_t), dw_variable_free_voidp);
725 frame->high_pc = ((char*) base) + MC_dwarf_attr_addr(die, DW_AT_high_pc);
726 frame->low_pc = ((char*) base) + MC_dwarf_attr_addr(die, DW_AT_low_pc);
728 Dwarf_Attribute attr_frame_base;
729 if (dwarf_attr_integrate(die, DW_AT_frame_base, &attr_frame_base))
730 mc_dwarf_location_list_init(&frame->frame_base, info, die, &attr_frame_base);
732 frame->end = -1; // This one is now useless:
735 const char* key = bprintf("%" PRIx64, (uint64_t) frame->start);
736 xbt_dict_set(info->subprograms, key, frame, NULL);
739 MC_dwarf_handle_children(info, die, unit, frame, namespace);
742 static void mc_dwarf_handle_namespace_die(
743 mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit, dw_frame_t frame, const char* namespace) {
744 const char* name = MC_dwarf_attr_string(die, DW_AT_name);
746 xbt_die("Unexpected namespace in a subprogram");
747 char* new_namespace = namespace == NULL ? xbt_strdup(name)
748 : bprintf("%s::%s", namespace, name);
749 MC_dwarf_handle_children(info, die, unit, frame, new_namespace);
752 static void MC_dwarf_handle_children(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit, dw_frame_t frame, const char* namespace) {
755 for (res=dwarf_child(die, &child); res==0; res=dwarf_siblingof(&child,&child)) {
756 MC_dwarf_handle_die(info, &child, unit, frame, namespace);
760 static void MC_dwarf_handle_die(mc_object_info_t info, Dwarf_Die* die, Dwarf_Die* unit, dw_frame_t frame, const char* namespace) {
761 int tag = dwarf_tag(die);
762 mc_tag_class klass = MC_dwarf_tag_classify(tag);
767 MC_dwarf_handle_type_die(info, die, unit, frame, namespace);
771 case mc_tag_subprogram:
772 MC_dwarf_handle_subprogram_die(info, die, unit, frame, namespace);
776 case mc_tag_variable:
777 MC_dwarf_handle_variable_die(info, die, unit, frame, namespace);
785 case mc_tag_namespace:
786 mc_dwarf_handle_namespace_die(info, die, unit, frame, namespace);
795 void MC_dwarf_get_variables(mc_object_info_t info) {
796 int fd = open(info->file_name, O_RDONLY);
798 xbt_die("Could not open file %s", info->file_name);
800 Dwarf *dwarf = dwarf_begin(fd, DWARF_C_READ);
802 xbt_die("Your program must be compiled with -g");
805 Dwarf_Off offset = 0;
806 Dwarf_Off next_offset = 0;
808 while (dwarf_nextcu (dwarf, offset, &next_offset, &length, NULL, NULL, NULL) == 0) {
811 if(dwarf_offdie(dwarf, offset+length, &unit_die)!=NULL) {
814 for (res=dwarf_child(&unit_die, &child); res==0; res=dwarf_siblingof(&child,&child)) {
815 MC_dwarf_handle_die(info, &child, &unit_die, NULL, NULL);
818 offset = next_offset;