1 /* Copyright (c) 2004-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "mc_dwarf.hpp"
8 #include <mc/ObjectInformation.hpp>
9 #include <mc/LocationList.hpp>
14 /** Resolve a location expression */
16 simgrid::dwarf::DwarfExpression const& expression,
17 simgrid::mc::ObjectInformation* object_info,
19 void *frame_pointer_address,
20 simgrid::mc::AddressSpace* address_space, int process_index)
22 simgrid::dwarf::ExpressionContext context;
23 context.frame_base = frame_pointer_address;
25 context.address_space = address_space;
26 context.object_info = object_info;
27 context.process_index = process_index;
29 if (!expression.empty()
30 && expression[0].atom >= DW_OP_reg0
31 && expression[0].atom <= DW_OP_reg31) {
32 int dwarf_register = expression[0].atom - DW_OP_reg0;
34 "Missing frame context for register operation DW_OP_reg%i",
36 return Location(dwarf_register_to_libunwind(dwarf_register));
39 simgrid::dwarf::ExpressionStack stack;
40 simgrid::dwarf::execute(expression, context, stack);
41 return Location((void*) stack.top());
44 // TODO, move this in a method of LocationList
45 static simgrid::dwarf::DwarfExpression const* find_expression(
46 simgrid::dwarf::LocationList const& locations, unw_word_t ip)
48 for (simgrid::dwarf::LocationListEntry const& entry : locations)
49 if (entry.valid_for_ip(ip))
50 return &entry.expression;
55 simgrid::dwarf::LocationList const& locations,
56 simgrid::mc::ObjectInformation* object_info,
58 void *frame_pointer_address,
59 simgrid::mc::AddressSpace* address_space,
63 if (c && unw_get_reg(c, UNW_REG_IP, &ip))
64 xbt_die("Could not resolve IP");
65 simgrid::dwarf::DwarfExpression const* expression =
66 find_expression(locations, ip);
68 xbt_die("Could not resolve location");
69 return simgrid::dwarf::resolve(
70 *expression, object_info, c,
71 frame_pointer_address, address_space, process_index);