* \deprecated Use mc_dwarf_resolve_expression
*/
void mc_dwarf_resolve_location(mc_location_t location,
- mc_expression_t expression,
+ simgrid::mc::DwarfExpression* expression,
mc_object_info_t object_info,
unw_cursor_t * c,
void *frame_pointer_address,
state.object_info = object_info;
state.process_index = process_index;
- if (expression->size >= 1
- && expression->ops[0].atom >=DW_OP_reg0 && expression->ops[0].atom <= DW_OP_reg31) {
- int dwarf_register = expression->ops[0].atom - DW_OP_reg0;
- xbt_assert(c, "Missing frame context for register operation DW_OP_reg%i",
+ if (expression->size() >= 1
+ && (*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;
return;
}
- if (mc_dwarf_execute_expression(expression->size, expression->ops, &state))
+ if (mc_dwarf_execute_expression(
+ expression->size(), expression->data(), &state))
xbt_die("Error evaluating DWARF expression");
if (state.stack_size == 0)
xbt_die("No value on the stack");
}
}
-static mc_expression_t mc_find_expression(mc_location_list_t locations, unw_word_t ip) {
- for (size_t i = 0; i != locations->size; ++i) {
- mc_expression_t expression = locations->locations + i;
- if ((expression->lowpc == NULL && expression->highpc == NULL)
- || (ip && ip >= (unw_word_t) expression->lowpc
- && ip < (unw_word_t) expression->highpc)) {
- return expression;
- }
- }
- return NULL;
+// TODO, move this in a method of LocationList
+static simgrid::mc::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;
}
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)
+ simgrid::mc::LocationList* locations,
+ mc_object_info_t object_info,
+ unw_cursor_t * c,
+ void *frame_pointer_address,
+ mc_address_space_t address_space,
+ int process_index)
{
unw_word_t ip = 0;
xbt_die("Could not resolve IP");
}
- mc_expression_t expression = mc_find_expression(locations, ip);
+ simgrid::mc::DwarfExpression* expression = mc_find_expression(locations, ip);
if (expression) {
mc_dwarf_resolve_location(location,
expression, object_info, c,
}
}
-void mc_dwarf_expression_clear(mc_expression_t expression)
-{
- free(expression->ops);
- expression->ops = NULL;
- expression->size = 0;
- expression->lowpc = NULL;
- expression->highpc = NULL;
-}
-
-void mc_dwarf_location_list_clear(mc_location_list_t list)
-{
- for (size_t i = 0; i != list->size; ++i) {
- mc_dwarf_expression_clear(list->locations + i);
- }
- free(list->locations);
- list->locations = NULL;
- list->size = 0;
-}
-
-void mc_dwarf_expression_init(mc_expression_t expression, size_t len,
- Dwarf_Op * ops)
+void mc_dwarf_location_list_init(
+ simgrid::mc::LocationList* list, mc_object_info_t info,
+ Dwarf_Die * die, Dwarf_Attribute * attr)
{
- expression->lowpc = NULL;
- expression->highpc = NULL;
- expression->size = len;
- expression->ops = (Dwarf_Op*) xbt_malloc(len * sizeof(Dwarf_Op));
- memcpy(expression->ops, ops, len * sizeof(Dwarf_Op));
-}
-
-void mc_dwarf_location_list_init_from_expression(mc_location_list_t target,
- size_t len, Dwarf_Op * ops)
-{
- target->size = 1;
- target->locations = (mc_expression_t) xbt_malloc(sizeof(s_mc_expression_t));
- mc_dwarf_expression_init(target->locations, len, ops);
-}
-
-void mc_dwarf_location_list_init(mc_location_list_t list, mc_object_info_t info,
- Dwarf_Die * die, Dwarf_Attribute * attr)
-{
- if (list->locations) {
- mc_dwarf_location_list_clear(list);
- }
- list->size = 0;
+ list->clear();
ptrdiff_t offset = 0;
Dwarf_Addr base, start, end;
else if (offset == -1)
xbt_die("Error while loading location list");
- int i = list->size;
- list->size++;
- list->locations =
- (mc_expression_t) realloc(list->locations,
- list->size * sizeof(s_mc_expression_t));
- mc_expression_t expression = list->locations + i;
- expression->ops = NULL;
- mc_dwarf_expression_init(expression, len, ops);
+ simgrid::mc::LocationListEntry entry;
+ entry.expression = simgrid::mc::DwarfExpression(ops, ops + len);
void *base = info->base_address();
// If start == 0, this is not a location list:
- expression->lowpc = start == 0 ? NULL : (char *) base + start;
- expression->highpc = start == 0 ? NULL : (char *) base + end;
+ entry.lowpc = start == 0 ? NULL : (char *) base + start;
+ entry.highpc = start == 0 ? NULL : (char *) base + end;
+
+ list->push_back(std::move(entry));
}
}
typedef std::vector<Dwarf_Op> DwarfExpression;
+
+/** \brief A DWARF expression with optional validity contraints */
+class LocationListEntry {
+public:
+ DwarfExpression expression;
+ void* lowpc, *highpc;
+
+ LocationListEntry() : lowpc(nullptr), highpc(nullptr) {}
+
+ bool valid_for_ip(unw_word_t ip)
+ {
+ return (this->lowpc == nullptr && this->highpc == nullptr)
+ || (ip >= (unw_word_t) this->lowpc
+ && ip < (unw_word_t) this->highpc);
+ }
+};
+
+typedef std::vector<LocationListEntry> LocationList;
+
}
}
SG_BEGIN_DECL()
-/** \brief a DWARF expression with optional validity contraints */
-typedef struct s_mc_expression {
- size_t size;
- Dwarf_Op* ops;
- // Optional validity:
- void* lowpc, *highpc;
-} s_mc_expression_t, *mc_expression_t;
-
-/** A location list (list of location expressions) */
-typedef struct s_mc_location_list {
- size_t size;
- mc_expression_t locations;
-} s_mc_location_list_t, *mc_location_list_t;
-
/** A location is either a location in memory of a register location
*
* Usage:
}
}
-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);
-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);
-
-XBT_INTERNAL void mc_dwarf_expression_clear(mc_expression_t expression);
-XBT_INTERNAL void mc_dwarf_expression_init(mc_expression_t expression, size_t len, Dwarf_Op* ops);
-
-XBT_INTERNAL void mc_dwarf_location_list_clear(mc_location_list_t list);
-
-XBT_INTERNAL void mc_dwarf_location_list_init_from_expression(mc_location_list_t target, size_t len, Dwarf_Op* ops);
-XBT_INTERNAL void mc_dwarf_location_list_init(mc_location_list_t target, mc_object_info_t info, Dwarf_Die* die, Dwarf_Attribute* attr);
+XBT_INTERNAL void mc_dwarf_resolve_location(
+ mc_location_t location, simgrid::mc::DwarfExpression* expression,
+ mc_object_info_t object_info, unw_cursor_t* c,
+ void* frame_pointer_address, mc_address_space_t address_space,
+ int process_index);
+MC_SHOULD_BE_INTERNAL void mc_dwarf_resolve_locations(
+ mc_location_t location, simgrid::mc::LocationList* locations,
+ mc_object_info_t object_info, unw_cursor_t* c,
+ void* frame_pointer_address, mc_address_space_t address_space,
+ int process_index);
+
+XBT_INTERNAL void mc_dwarf_location_list_init(
+ simgrid::mc::LocationList*, mc_object_info_t info, Dwarf_Die* die,
+ Dwarf_Attribute* attr);
#define MC_EXPRESSION_STACK_SIZE 64