-void mc_dwarf_expression_clear(mc_expression_t expression)
-{
- free(expression->ops);
- expression->ops = NULL;
- expression->size = 0;
- expression->lowpc = NULL;
- expression->highpc = NULL;
-}
-
-void mc_dwarf_location_list_clear(mc_location_list_t list)
-{
- for (size_t i = 0; i != list->size; ++i) {
- mc_dwarf_expression_clear(list->locations + i);
- }
- free(list->locations);
- list->locations = NULL;
- list->size = 0;
-}
-
-void mc_dwarf_expression_init(mc_expression_t expression, size_t len,
- Dwarf_Op * ops)
-{
- expression->lowpc = NULL;
- expression->highpc = NULL;
- expression->size = len;
- expression->ops = (Dwarf_Op*) xbt_malloc(len * sizeof(Dwarf_Op));
- memcpy(expression->ops, ops, len * sizeof(Dwarf_Op));
-}
-
-void mc_dwarf_location_list_init_from_expression(mc_location_list_t target,
- size_t len, Dwarf_Op * ops)
-{
- target->size = 1;
- target->locations = (mc_expression_t) xbt_malloc(sizeof(s_mc_expression_t));
- mc_dwarf_expression_init(target->locations, len, ops);
-}
-
-void mc_dwarf_location_list_init(mc_location_list_t list, mc_object_info_t info,
- Dwarf_Die * die, Dwarf_Attribute * attr)
-{
- if (list->locations) {
- mc_dwarf_location_list_clear(list);
- }
- list->size = 0;
-
- ptrdiff_t offset = 0;
- Dwarf_Addr base, start, end;
- Dwarf_Op *ops;
- size_t len;
-
- while (1) {
-
- offset = dwarf_getlocations(attr, offset, &base, &start, &end, &ops, &len);
- if (offset == 0)
- return;
- else if (offset == -1)
- xbt_die("Error while loading location list");
-
- int i = list->size;
- list->size++;
- list->locations =
- (mc_expression_t) realloc(list->locations,
- list->size * sizeof(s_mc_expression_t));
- mc_expression_t expression = list->locations + i;
- expression->ops = NULL;
- mc_dwarf_expression_init(expression, len, ops);
-
- void *base =
- info->
- flags & MC_OBJECT_INFO_EXECUTABLE ? 0 : MC_object_base_address(info);
- // If start == 0, this is not a location list:
- expression->lowpc = start == 0 ? NULL : (char *) base + start;
- expression->highpc = start == 0 ? NULL : (char *) base + end;
- }
-
-}
-