From 5f32263569ffe21e013c081a922778e4cb785d7f Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Tue, 13 Oct 2015 00:16:03 +0200 Subject: [PATCH] [mc] OOify mc_find_frame_base() --- src/mc/DwarfExpression.cpp | 27 -------------------------- src/mc/Frame.cpp | 33 ++++++++++++++++++++++++++++++++ src/mc/Frame.hpp | 4 +++- src/mc/LocationList.hpp | 3 --- src/mc/mc_checkpoint.cpp | 2 +- src/mc/mc_dwarf.cpp | 2 +- teshsuite/mc/dwarf/dwarf.cpp | 2 +- tools/cmake/DefinePackages.cmake | 1 + 8 files changed, 40 insertions(+), 34 deletions(-) create mode 100644 src/mc/Frame.cpp diff --git a/src/mc/DwarfExpression.cpp b/src/mc/DwarfExpression.cpp index 5e89864124..ddb3799488 100644 --- a/src/mc/DwarfExpression.cpp +++ b/src/mc/DwarfExpression.cpp @@ -270,33 +270,6 @@ void execute( extern "C" { -/** \brief Find the frame base of a given frame - * - * \param frame - * \param unw_cursor - */ -void *mc_find_frame_base(simgrid::mc::Frame* frame, simgrid::mc::ObjectInformation* object_info, - unw_cursor_t * unw_cursor) -{ - simgrid::dwarf::Location location = simgrid::dwarf::resolve( - frame->frame_base, object_info, - unw_cursor, NULL, NULL, -1); - if (location.in_memory()) - return location.address(); - else if (location.in_register()) { - // This is a special case. - // The register if not the location of the frame base - // (a frame base cannot be located in a register) - // Instead, DWARF defines this to mean that the register - // contains the address of the frame base. - unw_word_t word; - unw_get_reg(unw_cursor, location.register_id(), &word); - return (void*) word; - } - else xbt_die("Unexpected location type"); - -} - void mc_dwarf_location_list_init( simgrid::dwarf::LocationList* list, simgrid::mc::ObjectInformation* info, Dwarf_Die * die, Dwarf_Attribute * attr) diff --git a/src/mc/Frame.cpp b/src/mc/Frame.cpp new file mode 100644 index 0000000000..448cfa1114 --- /dev/null +++ b/src/mc/Frame.cpp @@ -0,0 +1,33 @@ +/* Copyright (c) 2007-2015. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include + +namespace simgrid { +namespace mc { + +void* Frame::frame_base(unw_cursor_t& unw_cursor) const +{ + simgrid::dwarf::Location location = simgrid::dwarf::resolve( + frame_base_location, object_info, + &unw_cursor, NULL, NULL, -1); + if (location.in_memory()) + return location.address(); + else if (location.in_register()) { + // This is a special case. + // The register if not the location of the frame base + // (a frame base cannot be located in a register) + // Instead, DWARF defines this to mean that the register + // contains the address of the frame base. + unw_word_t word; + unw_get_reg(&unw_cursor, location.register_id(), &word); + return (void*) word; + } + else xbt_die("Unexpected location type"); +} + +} +} \ No newline at end of file diff --git a/src/mc/Frame.hpp b/src/mc/Frame.hpp index 589a11d3b3..67d638ef5e 100644 --- a/src/mc/Frame.hpp +++ b/src/mc/Frame.hpp @@ -27,12 +27,14 @@ public: std::string name; void *low_pc; void *high_pc; - simgrid::dwarf::LocationList frame_base; + simgrid::dwarf::LocationList frame_base_location; std::vector variables; unsigned long int id; /* DWARF offset of the subprogram */ std::vector scopes; unsigned long int abstract_origin_id; simgrid::mc::ObjectInformation* object_info; + + void* frame_base(unw_cursor_t& unw_cursor) const; }; inline diff --git a/src/mc/LocationList.hpp b/src/mc/LocationList.hpp index 2e04e01439..978232aa66 100644 --- a/src/mc/LocationList.hpp +++ b/src/mc/LocationList.hpp @@ -91,9 +91,6 @@ XBT_PRIVATE void mc_dwarf_location_list_init( simgrid::dwarf::LocationList*, simgrid::mc::ObjectInformation* info, Dwarf_Die* die, Dwarf_Attribute* attr); -void* mc_find_frame_base( - simgrid::mc::Frame* frame, simgrid::mc::ObjectInformation* object_info, unw_cursor_t* unw_cursor); - SG_END_DECL() #endif diff --git a/src/mc/mc_checkpoint.cpp b/src/mc/mc_checkpoint.cpp index 1ea719cb45..746d20b115 100644 --- a/src/mc/mc_checkpoint.cpp +++ b/src/mc/mc_checkpoint.cpp @@ -380,7 +380,7 @@ static std::vector MC_unwind_stack_frames(mc_unw_context_t s if (frame) { stack_frame.frame_name = frame->name; stack_frame.frame_base = - (unw_word_t) mc_find_frame_base(frame, frame->object_info, &c); + (unw_word_t) frame->frame_base(c); } else { stack_frame.frame_base = 0; stack_frame.frame_name = std::string(); diff --git a/src/mc/mc_dwarf.cpp b/src/mc/mc_dwarf.cpp index 5151a7ac07..4b88e2f829 100644 --- a/src/mc/mc_dwarf.cpp +++ b/src/mc/mc_dwarf.cpp @@ -909,7 +909,7 @@ static void MC_dwarf_handle_scope_die(simgrid::mc::ObjectInformation* info, Dwar if (klass == simgrid::dwarf::TagClass::Subprogram) { Dwarf_Attribute attr_frame_base; if (dwarf_attr_integrate(die, DW_AT_frame_base, &attr_frame_base)) - mc_dwarf_location_list_init(&frame.frame_base, info, die, + mc_dwarf_location_list_init(&frame.frame_base_location, info, die, &attr_frame_base); } diff --git a/teshsuite/mc/dwarf/dwarf.cpp b/teshsuite/mc/dwarf/dwarf.cpp index 9af2e2ff48..383fbf562d 100644 --- a/teshsuite/mc/dwarf/dwarf.cpp +++ b/teshsuite/mc/dwarf/dwarf.cpp @@ -68,7 +68,7 @@ static void test_local_variable(simgrid::mc::ObjectInformation* info, const char simgrid::mc::Variable* var = find_local_variable(subprogram, variable); assert(var); - void* frame_base = mc_find_frame_base(subprogram, info, cursor); + void* frame_base = subprogram->frame_base(*cursor); simgrid::dwarf::Location location = simgrid::dwarf::resolve( var->location_list, info, cursor, frame_base, NULL, -1); diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index a244369b02..cc7e45373e 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -613,6 +613,7 @@ set(MC_SRC src/mc/AddressSpace.hpp src/mc/AddressSpace.cpp src/mc/Frame.hpp + src/mc/Frame.cpp src/mc/ModelChecker.hpp src/mc/ModelChecker.cpp src/mc/ObjectInformation.hpp -- 2.20.1