-// ***** Location
-
-/** \brief Resolve a location expression
- * \deprecated Use mc_dwarf_resolve_expression
- */
-void resolve_location(mc_location_t location,
- simgrid::dwarf::DwarfExpression const& expression,
- simgrid::mc::ObjectInformation* object_info,
- unw_cursor_t * c,
- void *frame_pointer_address,
- simgrid::mc::AddressSpace* address_space, int process_index)
-{
- simgrid::dwarf::ExpressionContext context;
- context.frame_base = frame_pointer_address;
- context.cursor = c;
- context.address_space = address_space;
- context.object_info = object_info;
- context.process_index = process_index;
-
- if (!expression.empty()
- && expression[0].atom >= DW_OP_reg0
- && expression[0].atom <= DW_OP_reg31) {
- int dwarf_register = expression[0].atom - DW_OP_reg0;
- xbt_assert(c,
- "Missing frame context for register operation DW_OP_reg%i",
- dwarf_register);
- location->memory_location = NULL;
- location->cursor = c;
- location->register_id = mc_dwarf_register_to_libunwind(dwarf_register);
- return;
- }
-
- simgrid::dwarf::ExpressionStack stack;
- simgrid::dwarf::execute(expression, context, stack);
-
- location->memory_location = (void*) stack.top();
- location->cursor = NULL;
- location->register_id = 0;
-}
-
-}
-}
-
-// TODO, move this in a method of LocationList
-static simgrid::dwarf::DwarfExpression* mc_find_expression(
- simgrid::mc::LocationList* locations, unw_word_t ip)
-{
- for (simgrid::mc::LocationListEntry& entry : *locations)
- if (entry.valid_for_ip(ip))
- return &entry.expression;
- return nullptr;
-}
-
-extern "C" {
-
-void mc_dwarf_resolve_locations(mc_location_t location,
- simgrid::mc::LocationList* locations,
- simgrid::mc::ObjectInformation* object_info,
- unw_cursor_t * c,
- void *frame_pointer_address,
- simgrid::mc::AddressSpace* address_space,
- int process_index)
-{
-
- unw_word_t ip = 0;
- if (c) {
- if (unw_get_reg(c, UNW_REG_IP, &ip))
- xbt_die("Could not resolve IP");
- }
-
- simgrid::dwarf::DwarfExpression* expression =
- mc_find_expression(locations, ip);
- if (expression) {
- simgrid::dwarf::resolve_location(location,
- *expression, object_info, c,
- frame_pointer_address, address_space, process_index);
- } else {
- xbt_die("Could not resolve location");
- }
-}
-
-/** \brief Find the frame base of a given frame
- *
- * \param frame
- * \param unw_cursor
- */
-void *mc_find_frame_base(simgrid::mc::Frame* frame, simgrid::mc::ObjectInformation* object_info,
- unw_cursor_t * unw_cursor)
-{
- s_mc_location_t location;
- mc_dwarf_resolve_locations(&location,
- &frame->frame_base, object_info,
- unw_cursor, NULL, NULL, -1);
- switch(mc_get_location_type(&location)) {
- case MC_LOCATION_TYPE_ADDRESS:
- return location.memory_location;
-
- case MC_LOCATION_TYPE_REGISTER: {
- // This is a special case.
- // The register if not the location of the frame base
- // (a frame base cannot be located in a register)
- // Instead, DWARF defines this to mean that the register
- // contains the address of the frame base.
- unw_word_t word;
- unw_get_reg(location.cursor, location.register_id, &word);
- return (void*) word;
- }
-
- default:
- xbt_die("Cannot handle non-address frame base");
- return NULL; // Unreachable
- }
-}
-
-void mc_dwarf_location_list_init(
- simgrid::mc::LocationList* list, simgrid::mc::ObjectInformation* info,
- Dwarf_Die * die, Dwarf_Attribute * attr)
-{
- list->clear();
-
- std::ptrdiff_t offset = 0;
- Dwarf_Addr base, start, end;
- Dwarf_Op *ops;
- std::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");
-
- simgrid::mc::LocationListEntry entry;
- entry.expression = simgrid::dwarf::DwarfExpression(ops, ops + len);
-
- void *base = info->base_address();
- // If start == 0, this is not a location list:
- entry.lowpc = start == 0 ? NULL : (char *) base + start;
- entry.highpc = start == 0 ? NULL : (char *) base + end;
-
- list->push_back(std::move(entry));
- }
-