static void MC_get_memory_regions(mc_process_t process, mc_snapshot_t snapshot)
{
- const size_t n = process->object_infos_size;
+ const size_t n = process->object_infos.size();
snapshot->snapshot_regions.resize(n + 1);
- for (size_t i = 0; i != n; ++i) {
- mc_object_info_t object_info = process->object_infos[i];
- MC_snapshot_add_region(i, snapshot, simgrid::mc::RegionType::Data, object_info,
+ int i = 0;
+ for (auto const& object_info : process->object_infos) {
+ MC_snapshot_add_region(i, snapshot, simgrid::mc::RegionType::Data,
+ object_info.get(),
object_info->start_rw, object_info->start_rw,
object_info->end_rw - object_info->start_rw);
+ ++i;
}
xbt_mheap_t heap = process->get_heap();
}
/** \brief Finds informations about a given shared object/executable */
-mc_object_info_t MC_find_object_info(
+std::shared_ptr<s_mc_object_info_t> MC_find_object_info(
std::vector<simgrid::mc::VmMap> const& maps, const char *name, int executable)
{
- mc_object_info_t result = new s_mc_object_info_t();
+ std::shared_ptr<s_mc_object_info_t> result =
+ std::make_shared<s_mc_object_info_t>();
if (executable)
result->flags |= MC_OBJECT_INFO_EXECUTABLE;
result->file_name = xbt_strdup(name);
- MC_find_object_address(maps, result);
- MC_dwarf_get_variables(result);
- MC_post_process_types(result);
- MC_post_process_variables(result);
- MC_post_process_functions(result);
- MC_make_functions_index(result);
- return result;
+ MC_find_object_address(maps, result.get());
+ MC_dwarf_get_variables(result.get());
+ MC_post_process_types(result.get());
+ MC_post_process_variables(result.get());
+ MC_post_process_functions(result.get());
+ MC_make_functions_index(result.get());
+ return std::move(result);
}
/*************************************************************************/
// Resolve full_type:
if (subtype->name && subtype->byte_size == 0) {
- for (size_t i = 0; i != process->object_infos_size; ++i) {
+ for (auto const& object_info : process->object_infos) {
dw_type_t same_type = (dw_type_t)
- xbt_dict_get_or_null(process->object_infos[i]->full_types_by_name,
+ xbt_dict_get_or_null(object_info->full_types_by_name,
subtype->name);
if (same_type && same_type->name && same_type->byte_size) {
type->full_type = same_type;
*/
XBT_INTERNAL void* MC_object_base_address(mc_object_info_t info);
-XBT_INTERNAL mc_object_info_t MC_find_object_info(
+XBT_INTERNAL std::shared_ptr<s_mc_object_info_t> MC_find_object_info(
std::vector<simgrid::mc::VmMap> const& maps, const char* name, int executable);
XBT_INTERNAL void MC_free_object_info(mc_object_info_t* p);
xbt_dynar_free(&process->smx_process_infos);
xbt_dynar_free(&process->smx_old_process_infos);
- size_t i;
- for (i=0; i!=process->object_infos_size; ++i) {
- delete process->object_infos[i];
- process->object_infos[i] = nullptr;
- }
- free(process->object_infos);
- process->object_infos = NULL;
- process->object_infos_size = 0;
if (process->memory_file >= 0) {
close(process->memory_file);
}
XBT_DEBUG("Get debug information ...");
this->maestro_stack_start_ = nullptr;
this->maestro_stack_end_ = nullptr;
- this->object_infos = NULL;
- this->object_infos_size = 0;
+ this->object_infos.resize(0);
this->binary_info = NULL;
this->libsimgrid_info = NULL;
const char* current_name = NULL;
+ this->object_infos.resize(0);
+
for (size_t i=0; i < maps.size(); i++) {
simgrid::mc::VmMap const& reg = maps[i];
const char* pathname = maps[i].pathname.c_str();
}
}
- mc_object_info_t info =
+ std::shared_ptr<s_mc_object_info_t> info =
MC_find_object_info(this->memory_map_, pathname, is_executable);
- this->object_infos = (mc_object_info_t*) realloc(this->object_infos,
- (this->object_infos_size+1) * sizeof(mc_object_info_t));
- this->object_infos[this->object_infos_size] = info;
- this->object_infos_size++;
+ this->object_infos.push_back(info);
if (is_executable)
this->binary_info = info;
else if (libname && MC_is_simgrid_lib(libname))
regfree(&res.version_re);
// Resolve time (including accross differents objects):
- for (size_t i=0; i!=this->object_infos_size; ++i)
- MC_post_process_object_info(this, this->object_infos[i]);
+ for (auto const& object_info : this->object_infos)
+ MC_post_process_object_info(this, object_info.get());
xbt_assert(this->maestro_stack_start_, "Did not find maestro_stack_start");
xbt_assert(this->maestro_stack_end_, "Did not find maestro_stack_end");
XBT_DEBUG("Get debug information done !");
}
-mc_object_info_t Process::find_object_info(remote_ptr<void> addr) const
+std::shared_ptr<s_mc_object_info_t> Process::find_object_info(remote_ptr<void> addr) const
{
- size_t i;
- for (i = 0; i != this->object_infos_size; ++i) {
- if (addr.address() >= (std::uint64_t)this->object_infos[i]->start
- && addr.address() <= (std::uint64_t)this->object_infos[i]->end) {
- return this->object_infos[i];
+ for (auto const& object_info : this->object_infos) {
+ if (addr.address() >= (std::uint64_t)object_info->start
+ && addr.address() <= (std::uint64_t)object_info->end) {
+ return object_info;
}
}
return NULL;
}
-mc_object_info_t Process::find_object_info_exec(remote_ptr<void> addr) const
+std::shared_ptr<s_mc_object_info_t> Process::find_object_info_exec(remote_ptr<void> addr) const
{
- size_t i;
- for (i = 0; i != this->object_infos_size; ++i) {
- if (addr.address() >= (std::uint64_t)this->object_infos[i]->start_exec
- && addr.address() <= (std::uint64_t)this->object_infos[i]->end_exec) {
- return this->object_infos[i];
+ for (std::shared_ptr<s_mc_object_info> const& info : this->object_infos) {
+ if (addr.address() >= (std::uint64_t) info->start_exec
+ && addr.address() <= (std::uint64_t) info->end_exec) {
+ return info;
}
}
- return NULL;
+ return nullptr;
}
-mc_object_info_t Process::find_object_info_rw(remote_ptr<void> addr) const
+std::shared_ptr<s_mc_object_info_t> Process::find_object_info_rw(remote_ptr<void> addr) const
{
- size_t i;
- for (i = 0; i != this->object_infos_size; ++i) {
- if (addr.address() >= (std::uint64_t)this->object_infos[i]->start_rw
- && addr.address() <= (std::uint64_t)this->object_infos[i]->end_rw) {
- return this->object_infos[i];
+ for (std::shared_ptr<s_mc_object_info> const& info : this->object_infos) {
+ if (addr.address() >= (std::uint64_t)info->start_rw
+ && addr.address() <= (std::uint64_t)info->end_rw) {
+ return info;
}
}
- return NULL;
+ return nullptr;
}
dw_frame_t Process::find_function(remote_ptr<void> ip) const
{
- mc_object_info_t info = this->find_object_info_exec(ip);
- if (info == NULL)
- return NULL;
+ std::shared_ptr<s_mc_object_info_t> info = this->find_object_info_exec(ip);
+ if (!info)
+ return nullptr;
else
- return MC_file_object_info_find_function(info, (void*) ip.address());
+ return MC_file_object_info_find_function(info.get(), (void*) ip.address());
}
/** Find (one occurence of) the named variable definition
*/
dw_variable_t Process::find_variable(const char* name) const
{
- const size_t n = this->object_infos_size;
- size_t i;
-
// First lookup the variable in the executable shared object.
// A global variable used directly by the executable code from a library
// is reinstanciated in the executable memory .data/.bss.
// We need to look up the variable in the execvutable first.
if (this->binary_info) {
- mc_object_info_t info = this->binary_info;
- dw_variable_t var = MC_file_object_info_find_variable_by_name(info, name);
+ std::shared_ptr<s_mc_object_info_t> const& info = this->binary_info;
+ dw_variable_t var = MC_file_object_info_find_variable_by_name(info.get(), name);
if (var)
return var;
}
- for (i=0; i!=n; ++i) {
- mc_object_info_t info = this->object_infos[i];
- dw_variable_t var = MC_file_object_info_find_variable_by_name(info, name);
+ for (std::shared_ptr<s_mc_object_info_t> const& info : this->object_infos) {
+ dw_variable_t var = MC_file_object_info_find_variable_by_name(info.get(), name);
if (var)
return var;
}
AddressSpace::ReadMode mode) const
{
if (process_index != simgrid::mc::ProcessIndexDisabled) {
- mc_object_info_t info = this->find_object_info_rw((void*)address.address());
+ std::shared_ptr<s_mc_object_info_t> const& info =
+ this->find_object_info_rw((void*)address.address());
// Segment overlap is not handled.
- if (MC_object_info_is_privatized(info)) {
+ if (MC_object_info_is_privatized(info.get())) {
if (process_index < 0)
xbt_die("Missing process index");
if (process_index >= (int) MC_smpi_process_count())
#include <sys/types.h>
#include <vector>
+#include <memory>
#include "simgrid_config.h"
#include <sys/types.h>
void clear_bytes(remote_ptr<void> address, size_t len);
// Debug information:
- mc_object_info_t find_object_info(remote_ptr<void> addr) const;
- mc_object_info_t find_object_info_exec(remote_ptr<void> addr) const;
- mc_object_info_t find_object_info_rw(remote_ptr<void> addr) const;
+ 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;
dw_variable_t find_variable(const char* name) const;
public: // object info
// TODO, make private (first, objectify mc_object_info_t)
- mc_object_info_t libsimgrid_info;
- mc_object_info_t binary_info;
- mc_object_info_t* object_infos;
- size_t object_infos_size;
+ std::vector<std::shared_ptr<s_mc_object_info_t>> object_infos;
+ std::shared_ptr<s_mc_object_info_t> libsimgrid_info;
+ std::shared_ptr<s_mc_object_info_t> binary_info;
public: // Copies of MCed SMX data structures
/** Copy of `simix_global->process_list`
void MCer_ignore_global_variable(const char *name)
{
mc_process_t process = &mc_model_checker->process();
- xbt_assert(process->object_infos, "MC subsystem not initialized");
+ xbt_assert(!process->object_infos.empty(), "MC subsystem not initialized");
- size_t n = process->object_infos_size;
- for (size_t i=0; i!=n; ++i) {
- mc_object_info_t info = process->object_infos[i];
+ for (std::shared_ptr<s_mc_object_info_t> const& info : process->object_infos) {
// Binary search:
int start = 0;
if (strcmp(frame_name, "*") == 0)
frame_name = NULL;
- size_t n = process->object_infos_size;
- size_t i;
- for (i=0; i!=n; ++i) {
- MC_ignore_local_variable_in_object(var_name, frame_name, process->object_infos[i]);
- }
+ for (std::shared_ptr<s_mc_object_info_t> const& info : process->object_infos)
+ MC_ignore_local_variable_in_object(var_name, frame_name, info.get());
}
static void MC_ignore_local_variable_in_object(const char *var_name,
s_mc_process_t p(getpid(), -1);
mc_process_t process = &p;
- test_global_variable(process, process->binary_info, "some_local_variable", &some_local_variable, sizeof(int));
+ test_global_variable(process, process->binary_info.get(),
+ "some_local_variable", &some_local_variable, sizeof(int));
- var = test_global_variable(process, process->binary_info, "test_some_array", &test_some_array, sizeof(test_some_array));
+ var = test_global_variable(process, process->binary_info.get(),
+ "test_some_array", &test_some_array, sizeof(test_some_array));
type = (dw_type_t) xbt_dict_get_or_null(process->binary_info->types, var->type_origin);
xbt_assert(type->element_count == 6*5*4, "element_count mismatch in test_some_array : %i / %i", type->element_count, 6*5*4);
- var = test_global_variable(process, process->binary_info, "test_some_struct", &test_some_struct, sizeof(test_some_struct));
+ var = test_global_variable(process, process->binary_info.get(),
+ "test_some_struct", &test_some_struct, sizeof(test_some_struct));
type = (dw_type_t) xbt_dict_get_or_null(process->binary_info->types, var->type_origin);
- assert(find_member(process->binary_info, "first", type)->offset == 0);
- assert(find_member(process->binary_info, "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;
unw_getcontext(&context);
unw_init_local(&cursor, &context);
- test_local_variable(process->binary_info, "main", "argc", &argc, &cursor);
+ test_local_variable(process->binary_info.get(), "main", "argc", &argc, &cursor);
{
int lexical_block_variable = 50;
- test_local_variable(process->binary_info, "main", "lexical_block_variable", &lexical_block_variable, &cursor);
+ test_local_variable(process->binary_info.get(), "main",
+ "lexical_block_variable", &lexical_block_variable, &cursor);
}
s_foo my_foo;