* \param ip Instruction pointer
* \return true if the variable is valid
* */
-static bool mc_valid_variable(mc_variable_t var, dw_frame_t scope,
+static bool mc_valid_variable(mc_variable_t var, mc_frame_t scope,
const void *ip)
{
// The variable is not yet valid:
}
static void mc_fill_local_variables_values(mc_stack_frame_t stack_frame,
- dw_frame_t scope, int process_index,
+ mc_frame_t scope, int process_index,
std::vector<s_local_variable>& result)
{
mc_process_t process = &mc_model_checker->process();
}
// Recursive processing of nested scopes:
- dw_frame_t nested_scope = NULL;
+ mc_frame_t nested_scope = nullptr;
xbt_dynar_foreach(scope->scopes, cursor, nested_scope) {
mc_fill_local_variables_values(stack_frame, nested_scope, process_index, result);
}
// TODO, use real addresses in frame_t instead of fixing it here
- dw_frame_t frame = process->find_function(remote(ip));
+ mc_frame_t frame = process->find_function(remote(ip));
stack_frame.frame = frame;
if (frame) {
result.push_back(std::move(stack_frame));
/* Stop before context switch with maestro */
- if (frame != NULL && frame->name != NULL
- && !strcmp(frame->name, "smx_ctx_sysv_wrapper"))
+ if (frame != nullptr &&
+ frame->name == "smx_ctx_sysv_wrapper")
break;
int ret = unw_step(&c);
|| current_var1->ip != current_var2->ip) {
// TODO, fix current_varX->subprogram->name to include name if DW_TAG_inlined_subprogram
XBT_VERB
- ("Different name of variable (%s - %s) or frame (%s - %s) or ip (%lu - %lu)",
- current_var1->name.c_str(), current_var2->name.c_str(),
- current_var1->subprogram->name, current_var2->subprogram->name,
+ ("Different name of variable (%s - %s) "
+ "or frame (%s - %s) or ip (%lu - %lu)",
+ current_var1->name.c_str(),
+ current_var2->name.c_str(),
+ current_var1->subprogram->name.c_str(),
+ current_var2->subprogram->name.c_str(),
current_var1->ip, current_var2->ip);
return 1;
}
// TODO, fix current_varX->subprogram->name to include name if DW_TAG_inlined_subprogram
XBT_TRACE3(mc, local_diff, -1, -1, current_var1->name);
XBT_VERB
- ("Local variable %s (%p - %p) in frame %s is different between snapshots",
- current_var1->name.c_str(), current_var1->address, current_var2->address,
- current_var1->subprogram->name);
+ ("Local variable %s (%p - %p) in frame %s "
+ "is different between snapshots",
+ current_var1->name.c_str(),
+ current_var1->address,
+ current_var2->address,
+ current_var1->subprogram->name.c_str());
return res;
}
cursor++;
#include "mc_object_info.h"
#include "mc_private.h"
-static void mc_variable_free(mc_variable_t v);
-static void mc_variable_free_voidp(void *t);
+static void mc_variable_free_voidp(void *t)
+{
+ delete *(simgrid::mc::Variable**)t;
+}
+
+static void mc_frame_free(void* frame)
+{
+ delete (simgrid::mc::Frame*)frame;
+}
static void MC_dwarf_register_global_variable(mc_object_info_t info, mc_variable_t variable);
-static void MC_register_variable(mc_object_info_t info, dw_frame_t frame, mc_variable_t variable);
-static void MC_dwarf_register_non_global_variable(mc_object_info_t info, dw_frame_t frame, mc_variable_t variable);
-static void MC_dwarf_register_variable(mc_object_info_t info, dw_frame_t frame, mc_variable_t variable);
+static void MC_register_variable(mc_object_info_t info, mc_frame_t frame, mc_variable_t variable);
+static void MC_dwarf_register_non_global_variable(mc_object_info_t info, mc_frame_t frame, mc_variable_t variable);
+static void MC_dwarf_register_variable(mc_object_info_t info, mc_frame_t frame, mc_variable_t variable);
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_dwarf, mc, "DWARF processing");
* \param frame containg frame if any
*/
static void MC_dwarf_handle_die(mc_object_info_t info, Dwarf_Die * die,
- Dwarf_Die * unit, dw_frame_t frame,
+ Dwarf_Die * unit, mc_frame_t frame,
const char *ns);
/** \brief Process a type DIE
*/
static void MC_dwarf_handle_type_die(mc_object_info_t info, Dwarf_Die * die,
- Dwarf_Die * unit, dw_frame_t frame,
+ Dwarf_Die * unit, mc_frame_t frame,
const char *ns);
/** \brief Calls MC_dwarf_handle_die on all childrend of the given die
* \param frame containg frame if any
*/
static void MC_dwarf_handle_children(mc_object_info_t info, Dwarf_Die * die,
- Dwarf_Die * unit, dw_frame_t frame,
+ Dwarf_Die * unit, mc_frame_t frame,
const char *ns);
/** \brief Handle a variable (DW_TAG_variable or other)
* \param frame containg frame if any
*/
static void MC_dwarf_handle_variable_die(mc_object_info_t info, Dwarf_Die * die,
- Dwarf_Die * unit, dw_frame_t frame,
+ Dwarf_Die * unit, mc_frame_t frame,
const char *ns);
/** \brief Get the DW_TAG_type of the DIE
* \return MC representation of the type
*/
static mc_type_t MC_dwarf_die_to_type(mc_object_info_t info, Dwarf_Die * die,
- Dwarf_Die * unit, dw_frame_t frame,
+ Dwarf_Die * unit, mc_frame_t frame,
const char *ns)
{
}
static void MC_dwarf_handle_type_die(mc_object_info_t info, Dwarf_Die * die,
- Dwarf_Die * unit, dw_frame_t frame,
+ Dwarf_Die * unit, mc_frame_t frame,
const char *ns)
{
mc_type_t type = MC_dwarf_die_to_type(info, die, unit, frame, ns);
static int mc_anonymous_variable_index = 0;
static mc_variable_t MC_die_to_variable(mc_object_info_t info, Dwarf_Die * die,
- Dwarf_Die * unit, dw_frame_t frame,
+ Dwarf_Die * unit, mc_frame_t frame,
const char *ns)
{
// Skip declarations:
}
static void MC_dwarf_handle_variable_die(mc_object_info_t info, Dwarf_Die * die,
- Dwarf_Die * unit, dw_frame_t frame,
+ Dwarf_Die * unit, mc_frame_t frame,
const char *ns)
{
mc_variable_t variable =
MC_dwarf_register_variable(info, frame, variable);
}
-static void mc_frame_free_voipd(dw_frame_t * p)
-{
- mc_frame_free(*p);
- *p = NULL;
-}
-
static void MC_dwarf_handle_scope_die(mc_object_info_t info, Dwarf_Die * die,
- Dwarf_Die * unit, dw_frame_t parent_frame,
+ Dwarf_Die * unit, mc_frame_t parent_frame,
const char *ns)
{
// TODO, handle DW_TAG_type/DW_TAG_location for DW_TAG_with_stmt
if (klass == mc_tag_scope)
xbt_assert(parent_frame, "No parent scope for this scope");
- dw_frame_t frame = xbt_new0(s_dw_frame_t, 1);
+ mc_frame_t frame = new simgrid::mc::Frame();
frame->tag = tag;
frame->id = dwarf_dieoffset(die);
if (klass == mc_tag_subprogram) {
const char *name = MC_dwarf_attr_integrate_string(die, DW_AT_name);
- frame->name =
- ns ? bprintf("%s::%s", ns, name) : xbt_strdup(name);
+ if(ns)
+ frame->name = std::string(ns) + "::" + name;
+ else
+ frame->name = name;
}
frame->abstract_origin_id =
// See DWARF4 spec 7.5
void *base = info->base_address();
- // Variables are filled in the (recursive) call of MC_dwarf_handle_children:
- frame->variables =
- xbt_dynar_new(sizeof(mc_variable_t), mc_variable_free_voidp);
-
// TODO, support DW_AT_ranges
uint64_t low_pc = MC_dwarf_attr_integrate_addr(die, DW_AT_low_pc);
frame->low_pc = low_pc ? ((char *) base) + low_pc : 0;
&attr_frame_base);
}
- frame->scopes =
- xbt_dynar_new(sizeof(dw_frame_t), (void_f_pvoid_t) mc_frame_free_voipd);
-
// Register it:
if (klass == mc_tag_subprogram) {
char *key = bprintf("%" PRIx64, (uint64_t) frame->id);
static void mc_dwarf_handle_namespace_die(mc_object_info_t info,
Dwarf_Die * die, Dwarf_Die * unit,
- dw_frame_t frame,
+ mc_frame_t frame,
const char *ns)
{
const char *name = MC_dwarf_attr_integrate_string(die, DW_AT_name);
}
static void MC_dwarf_handle_children(mc_object_info_t info, Dwarf_Die * die,
- Dwarf_Die * unit, dw_frame_t frame,
+ Dwarf_Die * unit, mc_frame_t frame,
const char *ns)
{
// For each child DIE:
}
static void MC_dwarf_handle_die(mc_object_info_t info, Dwarf_Die * die,
- Dwarf_Die * unit, dw_frame_t frame,
+ Dwarf_Die * unit, mc_frame_t frame,
const char *ns)
{
int tag = dwarf_tag(die);
/************************** Free functions *************************/
-void mc_frame_free(dw_frame_t frame)
-{
- xbt_free(frame->name);
- mc_dwarf_location_list_clear(&(frame->frame_base));
- xbt_dynar_free(&(frame->variables));
- xbt_dynar_free(&(frame->scopes));
- xbt_free(frame);
-}
-
static void dw_type_free(mc_type_t t)
{
delete t;
}
-void mc_variable_free_voidp(void *t)
-{
- delete *(simgrid::mc::Variable**)t;
-}
-
// ***** object_info
namespace simgrid {
this->end_rw = nullptr;
this->start_ro = nullptr;
this->end_ro = nullptr;
- this->subprograms = xbt_dict_new_homogeneous((void (*)(void *)) mc_frame_free);
+ this->subprograms = xbt_dict_new_homogeneous(mc_frame_free);
this->global_variables =
xbt_dynar_new(sizeof(mc_variable_t), mc_variable_free_voidp);
this->types = xbt_dict_new_homogeneous((void (*)(void *)) dw_type_free);
xbt_dynar_t index = xbt_dynar_new(sizeof(s_mc_function_index_item_t), NULL);
// Populate the array:
- dw_frame_t frame = NULL;
+ mc_frame_t frame = NULL;
xbt_dict_cursor_t cursor;
char *key;
xbt_dict_foreach(info->subprograms, cursor, key, frame) {
info->types, variable->type_id.c_str());
}
-static void mc_post_process_scope(mc_object_info_t info, dw_frame_t scope)
+static void mc_post_process_scope(mc_object_info_t info, mc_frame_t scope)
{
if (scope->tag == DW_TAG_inlined_subroutine) {
// Attach correct namespaced name in inlined subroutine:
char *key = bprintf("%" PRIx64, (uint64_t) scope->abstract_origin_id);
- dw_frame_t abstract_origin = (dw_frame_t) xbt_dict_get_or_null(info->subprograms, key);
+ mc_frame_t abstract_origin = (mc_frame_t) xbt_dict_get_or_null(info->subprograms, key);
xbt_assert(abstract_origin, "Could not lookup abstract origin %s", key);
xbt_free(key);
- scope->name = xbt_strdup(abstract_origin->name);
-
+ scope->name = abstract_origin->name;
}
// Direct:
info->types, variable->type_id.c_str());
// Recursive post-processing of nested-scopes:
- dw_frame_t nested_scope = nullptr;
+ mc_frame_t nested_scope = nullptr;
xbt_dynar_foreach(scope->scopes, cursor, nested_scope)
mc_post_process_scope(info, nested_scope);
{
xbt_dict_cursor_t cursor;
char *key;
- dw_frame_t subprogram = NULL;
+ mc_frame_t subprogram = NULL;
xbt_dict_foreach(info->subprograms, cursor, key, subprogram) {
mc_post_process_scope(info, subprogram);
}
}
void MC_dwarf_register_non_global_variable(mc_object_info_t info,
- dw_frame_t frame,
+ mc_frame_t frame,
mc_variable_t variable)
{
xbt_assert(frame, "Frame is NULL");
// TODO, else ?
}
-void MC_dwarf_register_variable(mc_object_info_t info, dw_frame_t frame,
+void MC_dwarf_register_variable(mc_object_info_t info, mc_frame_t frame,
mc_variable_t variable)
{
if (variable->global)
* \param frame
* \param unw_cursor
*/
-void *mc_find_frame_base(dw_frame_t frame, mc_object_info_t object_info,
+void *mc_find_frame_base(mc_frame_t frame, mc_object_info_t object_info,
unw_cursor_t * unw_cursor)
{
s_mc_location_t location;
class ObjectInformation;
class Type;
class Variable;
+class Frame;
}
}
typedef ::simgrid::mc::ObjectInformation s_mc_object_info_t;
typedef ::simgrid::mc::Type s_mc_type_t;
typedef ::simgrid::mc::Variable s_mc_variable_t;
+typedef ::simgrid::mc::Frame s_mc_frame_t;
#else
typedef struct _s_mc_object_info_t s_mc_object_info_t;
typedef struct _s_mc_type_t s_mc_type_t;
typedef struct _s_mc_variable_t s_mc_variable_t;
+typedef struct _s_mc_frame_t s_mc_frame_t;
#endif
-typedef struct s_memory_map s_memory_map_t, *memory_map_t;
-typedef struct s_dw_frame s_dw_frame_t, *dw_frame_t;
-
typedef s_mc_pages_store_t *mc_pages_store_t;
typedef s_mc_model_checker_t *mc_model_checker_t;
typedef s_mc_address_space_t *mc_address_space_t;
typedef s_mc_object_info_t *mc_object_info_t;
typedef s_mc_type_t *mc_type_t;
typedef s_mc_variable_t *mc_variable_t;
+typedef s_mc_frame_t *mc_frame_t;
+
+typedef struct s_memory_map s_memory_map_t, *memory_map_t;
SG_BEGIN_DECL()
extern mc_model_checker_t mc_model_checker;
static void mc_hash_stack_frame(mc_hash_t * hash,
mc_object_info_t info,
- unw_cursor_t * unw_cursor, dw_frame_t frame,
+ unw_cursor_t * unw_cursor, mc_frame_t frame,
char *frame_pointer, mc_hashing_state * state)
{
size_t n, const Dwarf_Op* ops, mc_expression_state_t state);
MC_SHOULD_BE_INTERNAL void* mc_find_frame_base(
- dw_frame_t frame, mc_object_info_t object_info, unw_cursor_t* unw_cursor);
+ mc_frame_t frame, mc_object_info_t object_info, unw_cursor_t* unw_cursor);
SG_END_DECL()
namespace simgrid {
namespace mc {
+// Free functions
+
+static void mc_variable_free_voidp(void *t)
+{
+ delete *(simgrid::mc::Variable**)t;
+}
+
+static void mc_frame_free_voipd(void** p)
+{
+ delete *(mc_frame_t**)p;
+ *p = nullptr;
+}
+
// Type
Type::Type()
mc_dwarf_location_list_clear(&this->location_list);
}
+// Frame
+
+Frame::Frame()
+{
+ this->tag = 0;
+ this->low_pc = nullptr;
+ this->high_pc = nullptr;
+ this->frame_base = {0, nullptr};
+ this->variables = xbt_dynar_new(
+ sizeof(mc_variable_t), mc_variable_free_voidp);
+ this->id = 0;
+ this->scopes = xbt_dynar_new(
+ sizeof(mc_frame_t), (void_f_pvoid_t) mc_frame_free_voipd);
+ this->abstract_origin_id = 0;
+ this->object_info = nullptr;
+}
+
+Frame::~Frame()
+{
+ mc_dwarf_location_list_clear(&(this->frame_base));
+ xbt_dynar_free(&(this->variables));
+ xbt_dynar_free(&(this->scopes));
+}
+
// ObjectInformations
-dw_frame_t ObjectInformation::find_function(const void *ip) const
+mc_frame_t ObjectInformation::find_function(const void *ip) const
{
xbt_dynar_t dynar = this->functions_index;
mc_function_index_item_t base =
char *end_rw; // Read-write segment
char *start_ro;
char *end_ro; // read-only segment
- xbt_dict_t subprograms; // xbt_dict_t<origin as hexadecimal string, dw_frame_t>
+ xbt_dict_t subprograms; // xbt_dict_t<origin as hexadecimal string, mc_frame_t>
xbt_dynar_t global_variables; // xbt_dynar_t<mc_variable_t>
xbt_dict_t types; // xbt_dict_t<origin as hexadecimal string, mc_type_t>
xbt_dict_t full_types_by_name; // xbt_dict_t<name, mc_type_t> (full defined type only)
void* base_address() const;
- dw_frame_t find_function(const void *ip) const;
+ mc_frame_t find_function(const void *ip) const;
mc_variable_t find_variable(const char* name) const;
};
};
-}
-}
+class Frame {
+public:
+ Frame();
+ ~Frame();
+ Frame(Frame const&) = delete;
+ Frame& operator=(Frame&) = delete;
-struct s_dw_frame{
int tag;
- char *name;
+ std::string name;
void *low_pc;
void *high_pc;
s_mc_location_list_t frame_base;
xbt_dynar_t /* <mc_variable_t> */ variables; /* Cannot use dict, there may be several variables with the same name (in different lexical blocks)*/
unsigned long int id; /* DWARF offset of the subprogram */
- xbt_dynar_t /* <dw_frame_t> */ scopes;
+ xbt_dynar_t /* <mc_frame_t> */ scopes;
Dwarf_Off abstract_origin_id;
mc_object_info_t object_info;
};
+}
+}
+
+
+
struct s_mc_function_index_item {
void* low_pc, *high_pc;
- dw_frame_t function;
+ mc_frame_t function;
};
-XBT_INTERNAL void mc_frame_free(dw_frame_t freme);
-
#endif
return nullptr;
}
-dw_frame_t Process::find_function(remote_ptr<void> ip) const
+mc_frame_t Process::find_function(remote_ptr<void> ip) const
{
std::shared_ptr<s_mc_object_info_t> info = this->find_object_info_exec(ip);
return info ? info->find_function((void*) ip.address()) : nullptr;
std::shared_ptr<s_mc_object_info_t> find_object_info(remote_ptr<void> addr) const;
std::shared_ptr<s_mc_object_info_t> find_object_info_exec(remote_ptr<void> addr) const;
std::shared_ptr<s_mc_object_info_t> find_object_info_rw(remote_ptr<void> addr) const;
- dw_frame_t find_function(remote_ptr<void> ip) const;
+ mc_frame_t find_function(remote_ptr<void> ip) const;
mc_variable_t find_variable(const char* name) const;
// Heap access:
/** Stack pointer */
unw_word_t sp;
unw_word_t frame_base;
- dw_frame_t frame;
+ mc_frame_t frame;
std::string frame_name;
unw_cursor_t unw_cursor;
} s_mc_stack_frame_t, *mc_stack_frame_t;
typedef struct s_local_variable{
- dw_frame_t subprogram;
+ mc_frame_t subprogram;
unsigned long ip;
std::string name;
mc_type_t type;
void* arg)
{
mc_unw_context_t context = (mc_unw_context_t) arg;
- dw_frame_t frame = context->process->find_function(remote(addr));
+ mc_frame_t frame = context->process->find_function(remote(addr));
if (!frame)
return - UNW_ENOINFO;
*offp = (unw_word_t) frame->low_pc - addr;
- strncpy(bufp, frame->name, buf_len);
+ strncpy(bufp, frame->name.c_str(), buf_len);
if (bufp[buf_len - 1]) {
bufp[buf_len - 1] = 0;
return -UNW_ENOMEM;
static void mc_ignore_local_variable_in_scope(const char *var_name,
const char *subprogram_name,
- dw_frame_t subprogram,
- dw_frame_t scope);
+ mc_frame_t subprogram,
+ mc_frame_t scope);
static void MC_ignore_local_variable_in_object(const char *var_name,
const char *subprogram_name,
mc_object_info_t info);
mc_object_info_t info)
{
xbt_dict_cursor_t cursor2;
- dw_frame_t frame;
+ mc_frame_t frame;
char *key;
xbt_dict_foreach(info->subprograms, cursor2, key, frame) {
mc_ignore_local_variable_in_scope(var_name, subprogram_name, frame, frame);
*/
static void mc_ignore_local_variable_in_scope(const char *var_name,
const char *subprogram_name,
- dw_frame_t subprogram,
- dw_frame_t scope)
+ mc_frame_t subprogram,
+ mc_frame_t scope)
{
// Processing of direct variables:
// If the current subprogram matches the given name:
- if (!subprogram_name ||
- (subprogram->name && strcmp(subprogram_name, subprogram->name) == 0)) {
+ if (subprogram_name == nullptr ||
+ (!subprogram->name.empty()
+ && subprogram->name == subprogram_name)) {
// Try to find the variable and remove it:
int start = 0;
}
// And recursive processing in nested scopes:
unsigned cursor = 0;
- dw_frame_t nested_scope = NULL;
+ mc_frame_t nested_scope = NULL;
xbt_dynar_foreach(scope->scopes, cursor, nested_scope) {
// The new scope may be an inlined subroutine, in this case we want to use its
// namespaced name in recursive calls:
- dw_frame_t nested_subprogram =
+ mc_frame_t nested_subprogram =
nested_scope->tag ==
DW_TAG_inlined_subroutine ? nested_scope : subprogram;
return NULL;
}
-static dw_frame_t find_function_by_name(mc_object_info_t info, const char* name) {
+static mc_frame_t find_function_by_name(
+ mc_object_info_t info, const char* name)
+{
xbt_dict_cursor_t cursor = 0;
- dw_frame_t subprogram;
+ mc_frame_t subprogram;
char* key;
- xbt_dict_foreach(info->subprograms, cursor, key, subprogram){
- if(!strcmp(name, subprogram->name))
+ xbt_dict_foreach(info->subprograms, cursor, key, subprogram)
+ if(subprogram->name == name)
return subprogram;
- }
-
- return NULL;
+ return nullptr;
}
static mc_variable_t find_local_variable(
- dw_frame_t frame, const char* argument_name) {
+ mc_frame_t frame, const char* argument_name) {
unsigned int cursor = 0;
mc_variable_t variable;
xbt_dynar_foreach(frame->variables, cursor, variable)
if(argument_name == variable->name)
return variable;
- dw_frame_t scope = nullptr;
+ mc_frame_t scope = nullptr;
xbt_dynar_foreach(frame->scopes, cursor, scope) {
variable = find_local_variable(scope, argument_name);
if(variable)
}
static void test_local_variable(mc_object_info_t info, const char* function, const char* variable, void* address, unw_cursor_t* cursor) {
- dw_frame_t subprogram = find_function_by_name(info, function);
+ mc_frame_t subprogram = find_function_by_name(info, function);
assert(subprogram);
// TODO, Lookup frame by IP and test against name instead