From: Frederic Suter Date: Tue, 17 Dec 2019 09:25:36 +0000 (+0100) Subject: another bunch of cleanups X-Git-Tag: v3.25~270 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/433d1f5fdc698c0511174016ee6be327da2d4821 another bunch of cleanups --- diff --git a/src/mc/ModelChecker.cpp b/src/mc/ModelChecker.cpp index eb12028b75..52c7796954 100644 --- a/src/mc/ModelChecker.cpp +++ b/src/mc/ModelChecker.cpp @@ -39,10 +39,10 @@ ModelChecker::ModelChecker(std::unique_ptr process) , page_store_(500) , process_(std::move(process)) { - } -ModelChecker::~ModelChecker() { +ModelChecker::~ModelChecker() +{ if (socket_event_ != nullptr) event_free(socket_event_); if (signal_event_ != nullptr) @@ -116,7 +116,7 @@ void ModelChecker::shutdown() { XBT_DEBUG("Shuting down model-checker"); - simgrid::mc::RemoteClient* process = &this->process(); + RemoteClient* process = &this->process(); if (process->running()) { XBT_DEBUG("Killing process"); kill(process->pid(), SIGKILL); @@ -124,11 +124,11 @@ void ModelChecker::shutdown() } } -void ModelChecker::resume(simgrid::mc::RemoteClient& process) +void ModelChecker::resume(RemoteClient& process) { int res = process.get_channel().send(MC_MESSAGE_CONTINUE); if (res) - throw simgrid::xbt::errno_error(); + throw xbt::errno_error(); process.clear_cache(); } @@ -146,8 +146,8 @@ static void MC_report_crash(int status) XBT_INFO("Counter-example execution trace:"); for (auto const& s : mc_model_checker->getChecker()->get_textual_trace()) XBT_INFO(" %s", s.c_str()); - simgrid::mc::dumpRecordPath(); - simgrid::mc::session->log_state(); + dumpRecordPath(); + session->log_state(); if (xbt_log_no_loc) { XBT_INFO("Stack trace not displayed because you passed --log=no_loc"); } else { @@ -164,8 +164,8 @@ static void MC_report_assertion_error() XBT_INFO("Counter-example execution trace:"); for (auto const& s : mc_model_checker->getChecker()->get_textual_trace()) XBT_INFO(" %s", s.c_str()); - simgrid::mc::dumpRecordPath(); - simgrid::mc::session->log_state(); + dumpRecordPath(); + session->log_state(); } bool ModelChecker::handle_message(char* buffer, ssize_t size) @@ -175,7 +175,6 @@ bool ModelChecker::handle_message(char* buffer, ssize_t size) memcpy(&base_message, buffer, sizeof(base_message)); switch(base_message.type) { - case MC_MESSAGE_IGNORE_HEAP: { s_mc_message_ignore_heap_t message; @@ -226,13 +225,12 @@ bool ModelChecker::handle_message(char* buffer, ssize_t size) xbt_assert(not message.callback, "Support for client-side function proposition is not implemented."); XBT_DEBUG("Received symbol: %s", message.name); - if (simgrid::mc::property_automaton == nullptr) - simgrid::mc::property_automaton = xbt_automaton_new(); + if (property_automaton == nullptr) + property_automaton = xbt_automaton_new(); - simgrid::mc::RemoteClient* process = &this->process(); - simgrid::mc::RemotePtr address = simgrid::mc::remote((int*)message.data); - simgrid::xbt::add_proposition(simgrid::mc::property_automaton, message.name, - [process, address]() { return process->read(address); }); + RemoteClient* process = &this->process(); + RemotePtr address = remote((int*)message.data); + xbt::add_proposition(property_automaton, message.name, [process, address]() { return process->read(address); }); break; } @@ -246,7 +244,6 @@ bool ModelChecker::handle_message(char* buffer, ssize_t size) default: xbt_die("Unexpected message from model-checked application"); - } return true; } @@ -303,7 +300,6 @@ void ModelChecker::handle_waitpid() } if (pid == this->process().pid()) { - // From PTRACE_O_TRACEEXIT: #ifdef __linux__ if (status>>8 == (SIGTRAP | (PTRACE_EVENT_EXIT<<8))) { @@ -379,5 +375,5 @@ bool ModelChecker::checkDeadlock() return message.value != 0; } -} -} +} // namespace mc +} // namespace simgrid diff --git a/src/mc/checker/Checker.cpp b/src/mc/checker/Checker.cpp index b34fbce66c..42b0b26820 100644 --- a/src/mc/checker/Checker.cpp +++ b/src/mc/checker/Checker.cpp @@ -18,5 +18,5 @@ Checker::Checker(Session& s) : session_(&s) mc_model_checker->setChecker(this); } -} -} +} // namespace mc +} // namespace simgrid diff --git a/src/mc/checker/SafetyChecker.cpp b/src/mc/checker/SafetyChecker.cpp index 22a868cb8b..d926af5959 100644 --- a/src/mc/checker/SafetyChecker.cpp +++ b/src/mc/checker/SafetyChecker.cpp @@ -146,7 +146,6 @@ void SafetyChecker::run() /* If this is a new state (or if we don't care about state-equality reduction) */ if (visited_state_ == nullptr) { - /* Get an enabled process and insert it in the interleave set of the next state */ for (auto& remoteActor : mc_model_checker->process().actors()) { auto actor = remoteActor.copy.get_buffer(); diff --git a/src/mc/inspect/DwarfExpression.cpp b/src/mc/inspect/DwarfExpression.cpp index c0c6a3eb9c..4c15f5b04b 100644 --- a/src/mc/inspect/DwarfExpression.cpp +++ b/src/mc/inspect/DwarfExpression.cpp @@ -28,9 +28,7 @@ void execute(const Dwarf_Op* ops, std::size_t n, const ExpressionContext& contex intptr_t second; switch (atom) { - // Registers: - case DW_OP_breg0: case DW_OP_breg1: case DW_OP_breg2: diff --git a/src/mc/inspect/ObjectInformation.cpp b/src/mc/inspect/ObjectInformation.cpp index ed52d5a055..d456364492 100644 --- a/src/mc/inspect/ObjectInformation.cpp +++ b/src/mc/inspect/ObjectInformation.cpp @@ -16,13 +16,11 @@ namespace simgrid { namespace mc { -/* For an executable object, addresses are virtual address - * (there is no offset) i.e. - * \f$\text{virtual address} = \{dwarf address}\f$ +/* For an executable object, addresses are virtual address (there is no offset) i.e. + * \f$\text{virtual address} = \{dwarf address}\f$ * - * For a shared object, the addresses are offset from the beginning - * of the shared object (the base address of the mapped shared - * object must be used as offset + * For a shared object, the addresses are offset from the beginning of the shared object (the base address of the + * mapped shared object must be used as offset * i.e. \f$\text{virtual address} = \text{shared object base address} * + \text{dwarf address}\f$. */ @@ -32,8 +30,7 @@ void* ObjectInformation::base_address() const if (this->executable()) return nullptr; - // For an a shared-object (ET_DYN, including position-independent executables) - // the base address is its lowest address: + // For an a shared-object (ET_DYN, including position-independent executables) the base address is its lowest address: void* result = this->start_exec; if (this->start_rw != nullptr && result > (void*)this->start_rw) result = this->start_rw; @@ -42,7 +39,7 @@ void* ObjectInformation::base_address() const return result; } -simgrid::mc::Frame* ObjectInformation::find_function(const void* ip) const +Frame* ObjectInformation::find_function(const void* ip) const { /* This is implemented by binary search on a sorted array. * @@ -56,9 +53,9 @@ simgrid::mc::Frame* ObjectInformation::find_function(const void* ip) const * We could use std::binary_search by including the high_pc inside * the FunctionIndexEntry. */ - const simgrid::mc::FunctionIndexEntry* base = this->functions_index.data(); - int i = 0; - int j = this->functions_index.size() - 1; + const FunctionIndexEntry* base = this->functions_index.data(); + int i = 0; + int j = this->functions_index.size() - 1; while (j >= i) { int k = i + ((j - i) / 2); @@ -81,9 +78,9 @@ simgrid::mc::Frame* ObjectInformation::find_function(const void* ip) const return nullptr; } -const simgrid::mc::Variable* ObjectInformation::find_variable(const char* name) const +const Variable* ObjectInformation::find_variable(const char* name) const { - for (simgrid::mc::Variable const& variable : this->global_variables) { + for (Variable const& variable : this->global_variables) { if (variable.name == name) return &variable; } @@ -103,11 +100,10 @@ void ObjectInformation::remove_global_variable(const char* name) while (first <= last) { size_type cursor = first + (last - first) / 2; - simgrid::mc::Variable& current_var = this->global_variables[cursor]; + Variable& current_var = this->global_variables[cursor]; int cmp = current_var.name.compare(name); if (cmp == 0) { - // Find the whole range: first = cursor; while (first != 0 && this->global_variables[first - 1].name == name) @@ -132,8 +128,7 @@ void ObjectInformation::remove_global_variable(const char* name) /** Ignore a local variable in a scope * - * Ignore all instances of variables with a given name in - * any (possibly inlined) subprogram with a given namespaced + * Ignore all instances of variables with a given name in any (possibly inlined) subprogram with a given namespaced * name. * * @param var_name Name of the local variable to ignore @@ -141,15 +136,14 @@ void ObjectInformation::remove_global_variable(const char* name) * @param subprogram (possibly inlined) Subprogram of the scope current scope * @param scope Current scope */ -static void remove_local_variable(simgrid::mc::Frame& scope, const char* var_name, const char* subprogram_name, - simgrid::mc::Frame const& subprogram) +static void remove_local_variable(Frame& scope, const char* var_name, const char* subprogram_name, + Frame const& subprogram) { typedef std::vector::size_type size_type; // If the current subprogram matches the given name: if ((subprogram_name == nullptr || (not subprogram.name.empty() && subprogram.name == subprogram_name)) && not scope.variables.empty()) { - // Try to find the variable and remove it: size_type start = 0; size_type end = scope.variables.size() - 1; @@ -157,7 +151,7 @@ static void remove_local_variable(simgrid::mc::Frame& scope, const char* var_nam // Binary search: while (start <= end) { size_type cursor = start + (end - start) / 2; - simgrid::mc::Variable& current_var = scope.variables[cursor]; + Variable& current_var = scope.variables[cursor]; int compare = current_var.name.compare(var_name); if (compare == 0) { // Variable found, remove it: @@ -173,11 +167,10 @@ static void remove_local_variable(simgrid::mc::Frame& scope, const char* var_nam } // And recursive processing in nested scopes: - for (simgrid::mc::Frame& nested_scope : scope.scopes) { + for (Frame& nested_scope : scope.scopes) { // The new scope may be an inlined subroutine, in this case we want to use its // namespaced name in recursive calls: - simgrid::mc::Frame const& nested_subprogram = - nested_scope.tag == DW_TAG_inlined_subroutine ? nested_scope : subprogram; + Frame const& nested_subprogram = nested_scope.tag == DW_TAG_inlined_subroutine ? nested_scope : subprogram; remove_local_variable(nested_scope, var_name, subprogram_name, nested_subprogram); } } @@ -185,17 +178,17 @@ static void remove_local_variable(simgrid::mc::Frame& scope, const char* var_nam void ObjectInformation::remove_local_variable(const char* var_name, const char* subprogram_name) { for (auto& entry : this->subprograms) - simgrid::mc::remove_local_variable(entry.second, var_name, subprogram_name, entry.second); + mc::remove_local_variable(entry.second, var_name, subprogram_name, entry.second); } /** @brief Fills the position of the segments (executable, read-only, read/write) */ // TODO, use the ELF segment information for more robustness -void find_object_address(std::vector const& maps, simgrid::mc::ObjectInformation* result) +void find_object_address(std::vector const& maps, ObjectInformation* result) { const int PROT_RW = PROT_READ | PROT_WRITE; const int PROT_RX = PROT_READ | PROT_EXEC; - std::string name = simgrid::xbt::Path(result->file_name).get_base_name(); + std::string name = xbt::Path(result->file_name).get_base_name(); for (size_t i = 0; i < maps.size(); ++i) { simgrid::xbt::VmMap const& reg = maps[i]; @@ -236,7 +229,7 @@ void find_object_address(std::vector const& maps, simgrid:: else if (reg.prot == PROT_READ) { xbt_assert(not result->start_ro, "Multiple read-only segments for %s, not supported. Compiling with the following may help: " - "-Wl,-znorelro -Wl,-znoseparate-code", + "-Wl,-znorelro -Wl,-znoseparate-code", maps[i].pathname.c_str()); result->start_ro = (char*)reg.start_addr; result->end_ro = (char*)reg.end_addr; diff --git a/src/mc/remote/Client.cpp b/src/mc/remote/Client.cpp index 06916a44e0..585ed0cb80 100644 --- a/src/mc/remote/Client.cpp +++ b/src/mc/remote/Client.cpp @@ -122,7 +122,6 @@ void Client::handle_messages() s_mc_message_t* message = (s_mc_message_t*)message_buffer; switch (message->type) { - case MC_MESSAGE_DEADLOCK_CHECK: xbt_assert(received_size == sizeof(s_mc_message_t), "Unexpected size for DEADLOCK_CHECK (%zd != %zu)", received_size, sizeof(s_mc_message_t)); @@ -243,5 +242,5 @@ void Client::declare_stack(void* stack, size_t size, ucontext_t* context) if (channel_.send(message)) xbt_die("Could not send STACK_REGION to model-checker"); } -} -} +} // namespace mc +} // namespace simgrid diff --git a/src/mc/sosp/PageStore.cpp b/src/mc/sosp/PageStore.cpp index e11d6532b4..5126851e57 100644 --- a/src/mc/sosp/PageStore.cpp +++ b/src/mc/sosp/PageStore.cpp @@ -26,8 +26,8 @@ namespace mc { /** @brief Compute a hash for the given memory page * - * The page is used before inserting the page in the page store - * in order to find duplicate of this page in the page store. + * The page is used before inserting the page in the page store in order to find duplicate of this page in the page + * store. * * @param data Memory page * @return hash off the page @@ -118,7 +118,6 @@ void PageStore::resize(std::size_t size) std::size_t PageStore::alloc_page() { if (this->free_pages_.empty()) { - // Expand the region: if (this->top_index_ == this->capacity_) // All the pages are allocated, we need add more pages: @@ -126,9 +125,7 @@ std::size_t PageStore::alloc_page() // Use a page from the top: return this->top_index_++; - } else { - // Use a page from free_pages_ (inside of the region): size_t res = this->free_pages_[this->free_pages_.size() - 1]; this->free_pages_.pop_back(); @@ -160,7 +157,6 @@ std::size_t PageStore::store_page(void* page) for (size_t const& pageno : page_set) { const void* snapshot_page = this->get_page(pageno); if (memcmp(page, snapshot_page, xbt_pagesize) == 0) { - // If a page with the same content is already in the page store it's reused and its refcount is incremented. page_counts_[pageno]++; return pageno; diff --git a/src/mc/sosp/Snapshot.cpp b/src/mc/sosp/Snapshot.cpp index 2f50339173..e42e3d3f65 100644 --- a/src/mc/sosp/Snapshot.cpp +++ b/src/mc/sosp/Snapshot.cpp @@ -16,19 +16,18 @@ namespace mc { /************************************* Take Snapshot ************************************/ /****************************************************************************************/ -void simgrid::mc::Snapshot::snapshot_regions(simgrid::mc::RemoteClient* process) +void Snapshot::snapshot_regions(RemoteClient* process) { snapshot_regions_.clear(); for (auto const& object_info : process->object_infos) - add_region(simgrid::mc::RegionType::Data, object_info.get(), object_info->start_rw, - object_info->end_rw - object_info->start_rw); + add_region(RegionType::Data, object_info.get(), object_info->start_rw, object_info->end_rw - object_info->start_rw); xbt_mheap_t heap = process->get_heap(); void* start_heap = heap->base; void* end_heap = heap->breakval; - add_region(simgrid::mc::RegionType::Heap, nullptr, start_heap, (char*)end_heap - (char*)start_heap); + add_region(RegionType::Heap, nullptr, start_heap, (char*)end_heap - (char*)start_heap); heap_bytes_used_ = mmalloc_get_bytes_used_remote(heap->heaplimit, process->get_malloc_info()); } @@ -50,14 +49,13 @@ static bool valid_variable(simgrid::mc::Variable* var, simgrid::mc::Frame* scope return true; } -static void fill_local_variables_values(mc_stack_frame_t stack_frame, simgrid::mc::Frame* scope, +static void fill_local_variables_values(mc_stack_frame_t stack_frame, Frame* scope, std::vector& result) { if (not scope || not scope->range.contain(stack_frame->ip)) return; - for (simgrid::mc::Variable& current_variable : scope->variables) { - + for (Variable& current_variable : scope->variables) { if (not valid_variable(¤t_variable, scope, (void*)stack_frame->ip)) continue; @@ -71,14 +69,13 @@ static void fill_local_variables_values(mc_stack_frame_t stack_frame, simgrid::m if (current_variable.address != nullptr) new_var.address = current_variable.address; else if (not current_variable.location_list.empty()) { - simgrid::dwarf::Location location = simgrid::dwarf::resolve( - current_variable.location_list, current_variable.object_info, &(stack_frame->unw_cursor), - (void*)stack_frame->frame_base, &mc_model_checker->process()); + dwarf::Location location = simgrid::dwarf::resolve(current_variable.location_list, current_variable.object_info, + &(stack_frame->unw_cursor), (void*)stack_frame->frame_base, + &mc_model_checker->process()); if (not location.in_memory()) xbt_die("Cannot handle non-address variable"); new_var.address = location.address(); - } else xbt_die("No address"); @@ -86,7 +83,7 @@ static void fill_local_variables_values(mc_stack_frame_t stack_frame, simgrid::m } // Recursive processing of nested scopes: - for (simgrid::mc::Frame& nested_scope : scope->scopes) + for (Frame& nested_scope : scope->scopes) fill_local_variables_values(stack_frame, &nested_scope, result); } @@ -98,9 +95,9 @@ static std::vector get_local_variables_values(std::vector unwind_stack_frames(simgrid::mc::UnwindContext* stack_context) +static std::vector unwind_stack_frames(UnwindContext* stack_context) { - simgrid::mc::RemoteClient* process = &mc_model_checker->process(); + RemoteClient* process = &mc_model_checker->process(); std::vector result; unw_cursor_t c = stack_context->cursor(); @@ -108,7 +105,6 @@ static std::vector unwind_stack_frames(simgrid::mc::UnwindCo // TODO, check condition check (unw_init_local==0 means end of frame) while (1) { - s_mc_stack_frame_t stack_frame; stack_frame.unw_cursor = c; @@ -124,7 +120,7 @@ static std::vector unwind_stack_frames(simgrid::mc::UnwindCo // TODO, use real addresses in frame_t instead of fixing it here - simgrid::mc::Frame* frame = process->find_function(remote(ip)); + Frame* frame = process->find_function(remote(ip)); stack_frame.frame = frame; if (frame) { @@ -153,7 +149,7 @@ static std::vector unwind_stack_frames(simgrid::mc::UnwindCo return result; } -void simgrid::mc::Snapshot::snapshot_stacks(simgrid::mc::RemoteClient* process) +void Snapshot::snapshot_stacks(RemoteClient* process) { for (auto const& stack : process->stack_areas()) { s_mc_snapshot_stack_t st; @@ -176,7 +172,7 @@ void simgrid::mc::Snapshot::snapshot_stacks(simgrid::mc::RemoteClient* process) } } -static void snapshot_handle_ignore(simgrid::mc::Snapshot* snapshot) +static void snapshot_handle_ignore(Snapshot* snapshot) { xbt_assert(snapshot->process()); @@ -194,6 +190,7 @@ static void snapshot_handle_ignore(simgrid::mc::Snapshot* snapshot) for (auto const& region : snapshot->process()->ignored_regions()) snapshot->process()->clear_bytes(remote(region.addr), region.size); } + static void snapshot_ignore_restore(simgrid::mc::Snapshot* snapshot) { for (auto const& ignored_data : snapshot->ignored_data_) @@ -225,14 +222,14 @@ Snapshot::Snapshot(int num_state, RemoteClient* process) void Snapshot::add_region(RegionType type, ObjectInformation* object_info, void* start_addr, std::size_t size) { - if (type == simgrid::mc::RegionType::Data) + if (type == RegionType::Data) xbt_assert(object_info, "Missing object info for object."); - else if (type == simgrid::mc::RegionType::Heap) + else if (type == RegionType::Heap) xbt_assert(not object_info, "Unexpected object info for heap region."); - simgrid::mc::Region* region = new Region(type, start_addr, size); + Region* region = new Region(type, start_addr, size); region->object_info(object_info); - snapshot_regions_.push_back(std::unique_ptr(std::move(region))); + snapshot_regions_.push_back(std::unique_ptr(std::move(region))); } void* Snapshot::read_bytes(void* buffer, std::size_t size, RemotePtr address, ReadOptions options) const @@ -281,7 +278,7 @@ void Snapshot::restore(RemoteClient* process) XBT_DEBUG("Restore snapshot %i", num_state_); // Restore regions - for (std::unique_ptr const& region : snapshot_regions_) { + for (std::unique_ptr const& region : snapshot_regions_) { if (region) // privatized variables are not snapshotted region.get()->restore(); }