Make location expression a std::vector.
mc_type_t member;
xbt_dynar_foreach(type->members, cursor, member) {
- if (!member->location.size) {
+ if (member->has_offset_location()) {
// We have the offset, use it directly (shortcut):
- if (member->offset == offset)
+ if (member->offset() == offset)
return member->subtype;
} else {
void *real_member =
PRIx64 ">%s", MC_dwarf_attr_integrate_string(child, DW_AT_name),
(uint64_t) type->id, type->name.c_str());
}
- if (len == 1 && expr[0].atom == DW_OP_plus_uconst) {
- member->offset = expr[0].number;
- } else {
- mc_dwarf_expression_init(&member->location, len, expr);
- }
+ simgrid::mc::DwarfExpression(expr, expr+len);
break;
}
case MC_DW_CLASS_CONSTANT:
{
Dwarf_Word offset;
if (!dwarf_formudata(&attr, &offset))
- member->offset = offset;
+ member->offset(offset);
else
xbt_die("Cannot get %s location <%" PRIx64 ">%s",
MC_dwarf_attr_integrate_string(child, DW_AT_name),
#include <stdint.h>
+#include <vector>
+
#include <libunwind.h>
#include <dwarf.h>
#include <elfutils/libdw.h>
#include "mc_forward.h"
#include "AddressSpace.hpp"
+namespace simgrid {
+namespace mc {
+
+typedef std::vector<Dwarf_Op> DwarfExpression;
+
+}
+}
+
SG_BEGIN_DECL()
/** \brief a DWARF expression with optional validity contraints */
SG_END_DECL()
+namespace simgrid {
+namespace mc {
+
+inline
+int execute(DwarfExpression const& expression, mc_expression_state_t state)
+{
+ return mc_dwarf_execute_expression(
+ expression.size(), expression.data(), state);
+}
+
+}
+}
+
#endif
void *mc_member_resolve(const void *base, mc_type_t type, mc_type_t member,
mc_address_space_t address_space, int process_index)
{
- if (!member->location.size) {
- return ((char *) base) + member->offset;
- }
+ // TODO, get rid of this?
+ if (!member->has_offset_location())
+ return ((char *) base) + member->offset();
s_mc_expression_state_t state;
memset(&state, 0, sizeof(s_mc_expression_state_t));
state.stack[0] = (uintptr_t) base;
state.process_index = process_index;
- if (mc_dwarf_execute_expression
- (member->location.size, member->location.ops, &state))
+ if (simgrid::mc::execute(
+ member->location_expression, &state))
xbt_die("Error evaluating DWARF expression");
if (state.stack_size == 0)
xbt_die("No value on the stack");
{
this->type = 0;
this->id = 0;
- this->name = std::string();
this->byte_size = 0;
this->element_count = 0;
this->members = nullptr;
this->is_pointer_type = 0;
- this->location = {0, 0, 0, 0};
- this->offset = 0;
this->subtype = nullptr;
this->full_type = nullptr;
}
Type::~Type()
{
xbt_dynar_free(&this->members);
- mc_dwarf_expression_clear(&this->location);
}
// ObjectInformations
#include <xbt/dict.h>
#include <xbt/dynar.h>
+#include <elfutils/libdw.h>
+
#include "mc_forward.h"
#include "mc_location.h"
#include "mc_process.h"
namespace simgrid {
namespace mc {
+/** Represents a type in the program
+ *
+ * It is currently used to represent members of structs and unions as well.
+ */
class Type {
public:
Type();
int is_pointer_type;
// Location (for members) is either of:
- struct s_mc_expression location;
- int offset;
+ simgrid::mc::DwarfExpression location_expression;
mc_type_t subtype; // DW_AT_type
mc_type_t full_type; // The same (but more complete) type
+
+ bool has_offset_location() const
+ {
+ return location_expression.size() == 1 &&
+ location_expression[0].atom == DW_OP_plus_uconst;
+ }
+
+ // TODO, check if this shortcut is really necessary
+ int offset() const
+ {
+ xbt_assert(this->has_offset_location());
+ return this->location_expression[0].number;
+ }
+
+ void offset(int new_offset)
+ {
+ Dwarf_Op op;
+ op.atom = DW_OP_plus_uconst;
+ op.number = new_offset;
+ this->location_expression = { op };
+ }
};
}
var = test_global_variable(process, process->binary_info.get(),
"test_some_struct", &test_some_struct, sizeof(test_some_struct));
type = (mc_type_t) xbt_dict_get_or_null(process->binary_info->types, var->type_origin);
- assert(find_member(process->binary_info.get(), "first", type)->offset == 0);
- assert(find_member(process->binary_info.get(), "second", type)->offset
+ assert(find_member(process->binary_info.get(), "first", type)->offset() == 0);
+ assert(find_member(process->binary_info.get(), "second", type)->offset()
== ((const char*)&test_some_struct.second) - (const char*)&test_some_struct);
unw_context_t context;