1 /* Copyright (c) 2004-2014. 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 MC_OBJECT_LOCATION_H
8 #define MC_OBJECT_LOCATION_H
12 #include <libunwind.h>
14 #include <elfutils/libdw.h>
16 #include <simgrid_config.h>
18 #include "mc_forward.h"
19 #include "mc_object_info.h"
20 #include "mc_forward.h"
21 #include "mc_address_space.h"
25 /** \brief a DWARF expression with optional validity contraints */
26 typedef struct s_mc_expression {
31 } s_mc_expression_t, *mc_expression_t;
33 /** A location list (list of location expressions) */
34 typedef struct s_mc_location_list {
36 mc_expression_t locations;
37 } s_mc_location_list_t, *mc_location_list_t;
39 /** A location is either a location in memory of a register location
43 * * mc_dwarf_resolve_locations or mc_dwarf_resolve_location is used
44 * to find the location of a given location expression or location list;
46 * * mc_get_location_type MUST be used to find the location type;
48 * * for MC_LOCATION_TYPE_ADDRESS, memory_address is the resulting address
50 * * for MC_LOCATION_TYPE_REGISTER, unw_get_reg(l.cursor, l.register_id, value)
51 * and unw_get_reg(l.cursor, l.register_id, value) can be used to read/write
55 typedef struct s_mc_location {
56 void* memory_location;
59 } s_mc_location_t, *mc_location_t;
61 /** Type of a given location
63 * Use `mc_get_location_type(location)` to find the type.
65 typedef enum mc_location_type {
66 MC_LOCATION_TYPE_ADDRESS,
67 MC_LOCATION_TYPE_REGISTER
70 /** Find the type of a location */
71 static inline __attribute__ ((always_inline))
72 enum mc_location_type mc_get_location_type(mc_location_t location) {
73 if (location->cursor) {
74 return MC_LOCATION_TYPE_REGISTER;
76 return MC_LOCATION_TYPE_ADDRESS;
80 XBT_INTERNAL void mc_dwarf_resolve_location(mc_location_t location, mc_expression_t expression, mc_object_info_t object_info, unw_cursor_t* c, void* frame_pointer_address, mc_address_space_t address_space, int process_index);
81 MC_SHOULD_BE_INTERNAL void mc_dwarf_resolve_locations(mc_location_t location, mc_location_list_t locations, mc_object_info_t object_info, unw_cursor_t* c, void* frame_pointer_address, mc_address_space_t address_space, int process_index);
83 XBT_INTERNAL void mc_dwarf_expression_clear(mc_expression_t expression);
84 XBT_INTERNAL void mc_dwarf_expression_init(mc_expression_t expression, size_t len, Dwarf_Op* ops);
86 XBT_INTERNAL void mc_dwarf_location_list_clear(mc_location_list_t list);
88 XBT_INTERNAL void mc_dwarf_location_list_init_from_expression(mc_location_list_t target, size_t len, Dwarf_Op* ops);
89 XBT_INTERNAL void mc_dwarf_location_list_init(mc_location_list_t target, mc_object_info_t info, Dwarf_Die* die, Dwarf_Attribute* attr);
91 #define MC_EXPRESSION_STACK_SIZE 64
93 #define MC_EXPRESSION_OK 0
94 #define MC_EXPRESSION_E_UNSUPPORTED_OPERATION 1
95 #define MC_EXPRESSION_E_STACK_OVERFLOW 2
96 #define MC_EXPRESSION_E_STACK_UNDERFLOW 3
97 #define MC_EXPRESSION_E_MISSING_STACK_CONTEXT 4
98 #define MC_EXPRESSION_E_MISSING_FRAME_BASE 5
99 #define MC_EXPRESSION_E_NO_BASE_ADDRESS 6
101 typedef struct s_mc_expression_state {
102 uintptr_t stack[MC_EXPRESSION_STACK_SIZE];
105 unw_cursor_t* cursor;
107 mc_address_space_t address_space;
108 mc_object_info_t object_info;
110 } s_mc_expression_state_t, *mc_expression_state_t;
112 MC_SHOULD_BE_INTERNAL int mc_dwarf_execute_expression(
113 size_t n, const Dwarf_Op* ops, mc_expression_state_t state);
115 MC_SHOULD_BE_INTERNAL void* mc_find_frame_base(
116 dw_frame_t frame, mc_object_info_t object_info, unw_cursor_t* unw_cursor);