Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
03e4161d76000bea8425b6fc17c1349e214e72d2
[simgrid.git] / src / mc / LocationList.cpp
1 /* Copyright (c) 2004-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "mc_dwarf.hpp"
8 #include <mc/ObjectInformation.hpp>
9 #include <mc/LocationList.hpp>
10
11 namespace simgrid {
12 namespace dwarf {
13
14 /** Resolve a location expression */
15 Location resolve(
16                       simgrid::dwarf::DwarfExpression const& expression,
17                       simgrid::mc::ObjectInformation* object_info,
18                       unw_cursor_t * c,
19                       void *frame_pointer_address,
20                       simgrid::mc::AddressSpace* address_space, int process_index)
21 {
22   simgrid::dwarf::ExpressionContext context;
23   context.frame_base = frame_pointer_address;
24   context.cursor = c;
25   context.address_space = address_space;
26   context.object_info = object_info;
27   context.process_index = process_index;
28
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;
33     xbt_assert(c,
34       "Missing frame context for register operation DW_OP_reg%i",
35       dwarf_register);
36     return Location(dwarf_register_to_libunwind(dwarf_register));
37   }
38
39   simgrid::dwarf::ExpressionStack stack;
40   simgrid::dwarf::execute(expression, context, stack);
41   return Location((void*) stack.top());
42 }
43
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)
47 {
48   for (simgrid::dwarf::LocationListEntry const& entry : locations)
49     if (entry.valid_for_ip(ip))
50       return &entry.expression;
51   return nullptr;
52 }
53
54 Location resolve(
55   simgrid::dwarf::LocationList const& locations,
56   simgrid::mc::ObjectInformation* object_info,
57   unw_cursor_t * c,
58   void *frame_pointer_address,
59   simgrid::mc::AddressSpace* address_space,
60   int process_index)
61 {
62   unw_word_t ip = 0;
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);
67   if (!expression)
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);
72 }
73
74 }
75 }