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 #ifndef SIMGRID_MC_OBJECT_LOCATION_H
8 #define SIMGRID_MC_OBJECT_LOCATION_H
14 #include <libunwind.h>
16 #include <elfutils/libdw.h>
18 #include <simgrid_config.h>
20 #include "mc_forward.hpp"
21 #include "mc/AddressSpace.hpp"
22 #include "mc/DwarfExpression.hpp"
28 /** \brief A DWARF expression with optional validity contraints */
29 class LocationListEntry {
31 simgrid::dwarf::DwarfExpression expression;
34 LocationListEntry() : lowpc(nullptr), highpc(nullptr) {}
36 bool valid_for_ip(unw_word_t ip)
38 return (this->lowpc == nullptr && this->highpc == nullptr)
39 || (ip >= (unw_word_t) this->lowpc
40 && ip < (unw_word_t) this->highpc);
44 typedef std::vector<LocationListEntry> LocationList;
51 /** A location is either a location in memory of a register location
55 * * mc_dwarf_resolve_locations or mc_dwarf_resolve_location is used
56 * to find the location of a given location expression or location list;
58 * * mc_get_location_type MUST be used to find the location type;
60 * * for MC_LOCATION_TYPE_ADDRESS, memory_address is the resulting address
62 * * for MC_LOCATION_TYPE_REGISTER, unw_get_reg(l.cursor, l.register_id, value)
63 * and unw_get_reg(l.cursor, l.register_id, value) can be used to read/write
67 typedef struct s_mc_location {
68 void* memory_location;
71 } s_mc_location_t, *mc_location_t;
73 /** Type of a given location
75 * Use `mc_get_location_type(location)` to find the type.
77 typedef enum mc_location_type {
78 MC_LOCATION_TYPE_ADDRESS,
79 MC_LOCATION_TYPE_REGISTER
82 /** Find the type of a location */
83 static inline __attribute__ ((always_inline))
84 enum mc_location_type mc_get_location_type(mc_location_t location) {
85 if (location->cursor) {
86 return MC_LOCATION_TYPE_REGISTER;
88 return MC_LOCATION_TYPE_ADDRESS;
97 XBT_PRIVATE void resolve_location(
98 mc_location_t location, simgrid::dwarf::DwarfExpression const& expression,
99 simgrid::mc::ObjectInformation* object_info, unw_cursor_t* c,
100 void* frame_pointer_address, simgrid::mc::AddressSpace* address_space,
108 void mc_dwarf_resolve_locations(
109 mc_location_t location, simgrid::mc::LocationList* locations,
110 simgrid::mc::ObjectInformation* object_info, unw_cursor_t* c,
111 void* frame_pointer_address, simgrid::mc::AddressSpace* address_space,
114 XBT_PRIVATE void mc_dwarf_location_list_init(
115 simgrid::mc::LocationList*, simgrid::mc::ObjectInformation* info, Dwarf_Die* die,
116 Dwarf_Attribute* attr);
118 void* mc_find_frame_base(
119 simgrid::mc::Frame* frame, simgrid::mc::ObjectInformation* object_info, unw_cursor_t* unw_cursor);