#include "mc_object_info.h"
#include "mc_private.h"
-#include "mc_location.h"
+#include "mc/LocationList.hpp"
#include "mc/AddressSpace.hpp"
#include "mc/Frame.hpp"
#include "mc/ObjectInformation.hpp"
#include "mc/DwarfExpression.hpp"
+#include "mc_dwarf.hpp"
using simgrid::mc::remote;
}
}
-extern "C" {
-
-/** Convert a DWARF register into a libunwind register
- *
- * DWARF and libunwind does not use the same convention for numbering the
- * registers on some architectures. The function makes the necessary
- * convertion.
- */
-static int mc_dwarf_register_to_libunwind(int dwarf_register)
-{
-#if defined(__x86_64__)
- // It seems for this arch, DWARF and libunwind agree in the numbering:
- return dwarf_register;
-#elif defined(__i386__)
- // Could't find the authoritative source of information for this.
- // This is inspired from http://source.winehq.org/source/dlls/dbghelp/cpu_i386.c#L517.
- switch (dwarf_register) {
- case 0:
- return UNW_X86_EAX;
- case 1:
- return UNW_X86_ECX;
- case 2:
- return UNW_X86_EDX;
- case 3:
- return UNW_X86_EBX;
- case 4:
- return UNW_X86_ESP;
- case 5:
- return UNW_X86_EBP;
- case 6:
- return UNW_X86_ESI;
- case 7:
- return UNW_X86_EDI;
- case 8:
- return UNW_X86_EIP;
- case 9:
- return UNW_X86_EFLAGS;
- case 10:
- return UNW_X86_CS;
- case 11:
- return UNW_X86_SS;
- case 12:
- return UNW_X86_DS;
- case 13:
- return UNW_X86_ES;
- case 14:
- return UNW_X86_FS;
- case 15:
- return UNW_X86_GS;
- case 16:
- return UNW_X86_ST0;
- case 17:
- return UNW_X86_ST1;
- case 18:
- return UNW_X86_ST2;
- case 19:
- return UNW_X86_ST3;
- case 20:
- return UNW_X86_ST4;
- case 21:
- return UNW_X86_ST5;
- case 22:
- return UNW_X86_ST6;
- case 23:
- return UNW_X86_ST7;
- default:
- xbt_die("Bad/unknown register number.");
- }
-#else
-#error This architecture is not supported yet for DWARF expression evaluation.
-#endif
-}
-
-}
-
namespace simgrid {
namespace dwarf {
case DW_OP_breg29:
case DW_OP_breg30:
case DW_OP_breg31:{
- int register_id =
- mc_dwarf_register_to_libunwind(op->atom - DW_OP_breg0);
+ int register_id = simgrid::dwarf::dwarf_register_to_libunwind(
+ op->atom - DW_OP_breg0);
unw_word_t res;
if (!context.cursor)
throw evaluation_error("Missin stack context");
}
}
-// ***** Location
-
-/** \brief Resolve a location expression
- * \deprecated Use mc_dwarf_resolve_expression
- */
-void resolve_location(mc_location_t location,
- simgrid::dwarf::DwarfExpression const& expression,
- simgrid::mc::ObjectInformation* object_info,
- unw_cursor_t * c,
- void *frame_pointer_address,
- simgrid::mc::AddressSpace* address_space, int process_index)
-{
- simgrid::dwarf::ExpressionContext context;
- context.frame_base = frame_pointer_address;
- context.cursor = c;
- context.address_space = address_space;
- context.object_info = object_info;
- context.process_index = process_index;
-
- if (!expression.empty()
- && expression[0].atom >= DW_OP_reg0
- && expression[0].atom <= DW_OP_reg31) {
- int dwarf_register = expression[0].atom - DW_OP_reg0;
- xbt_assert(c,
- "Missing frame context for register operation DW_OP_reg%i",
- dwarf_register);
- location->memory_location = NULL;
- location->cursor = c;
- location->register_id = mc_dwarf_register_to_libunwind(dwarf_register);
- return;
- }
-
- simgrid::dwarf::ExpressionStack stack;
- simgrid::dwarf::execute(expression, context, stack);
-
- location->memory_location = (void*) stack.top();
- location->cursor = NULL;
- location->register_id = 0;
}
-
-}
-}
-
-// TODO, move this in a method of LocationList
-static simgrid::dwarf::DwarfExpression* mc_find_expression(
- simgrid::mc::LocationList* locations, unw_word_t ip)
-{
- for (simgrid::mc::LocationListEntry& entry : *locations)
- if (entry.valid_for_ip(ip))
- return &entry.expression;
- return nullptr;
}
extern "C" {
-void mc_dwarf_resolve_locations(mc_location_t location,
- simgrid::mc::LocationList* locations,
- simgrid::mc::ObjectInformation* object_info,
- unw_cursor_t * c,
- void *frame_pointer_address,
- simgrid::mc::AddressSpace* address_space,
- int process_index)
-{
-
- unw_word_t ip = 0;
- if (c) {
- if (unw_get_reg(c, UNW_REG_IP, &ip))
- xbt_die("Could not resolve IP");
- }
-
- simgrid::dwarf::DwarfExpression* expression =
- mc_find_expression(locations, ip);
- if (expression) {
- simgrid::dwarf::resolve_location(location,
- *expression, object_info, c,
- frame_pointer_address, address_space, process_index);
- } else {
- xbt_die("Could not resolve location");
- }
-}
-
/** \brief Find the frame base of a given frame
*
* \param frame
void *mc_find_frame_base(simgrid::mc::Frame* frame, simgrid::mc::ObjectInformation* object_info,
unw_cursor_t * unw_cursor)
{
- s_mc_location_t location;
- mc_dwarf_resolve_locations(&location,
- &frame->frame_base, object_info,
+ simgrid::dwarf::Location location = simgrid::dwarf::resolve(
+ frame->frame_base, object_info,
unw_cursor, NULL, NULL, -1);
- switch(mc_get_location_type(&location)) {
- case MC_LOCATION_TYPE_ADDRESS:
- return location.memory_location;
-
- case MC_LOCATION_TYPE_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(location.cursor, location.register_id, &word);
- return (void*) word;
- }
-
- default:
- xbt_die("Cannot handle non-address frame base");
- return NULL; // Unreachable
+ 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::mc::LocationList* list, simgrid::mc::ObjectInformation* info,
+ simgrid::dwarf::LocationList* list, simgrid::mc::ObjectInformation* info,
Dwarf_Die * die, Dwarf_Attribute * attr)
{
list->clear();
else if (offset == -1)
xbt_die("Error while loading location list");
- simgrid::mc::LocationListEntry entry;
+ simgrid::dwarf::LocationListEntry entry;
entry.expression = simgrid::dwarf::DwarfExpression(ops, ops + len);
void *base = info->base_address();
#include <xbt/base.h>
#include "mc_forward.h"
-#include "mc_location.h"
+#include "mc/LocationList.hpp"
#include "mc/Variable.hpp"
#include "mc/Frame.hpp"
std::string name;
void *low_pc;
void *high_pc;
- simgrid::mc::LocationList frame_base;
+ simgrid::dwarf::LocationList frame_base;
std::vector<Variable> variables;
unsigned long int id; /* DWARF offset of the subprogram */
std::vector<Frame> scopes;
--- /dev/null
+/* Copyright (c) 2004-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 "mc_dwarf.hpp"
+#include <mc/ObjectInformation.hpp>
+#include <mc/LocationList.hpp>
+
+namespace simgrid {
+namespace dwarf {
+
+/** Resolve a location expression */
+Location resolve(
+ simgrid::dwarf::DwarfExpression const& expression,
+ simgrid::mc::ObjectInformation* object_info,
+ unw_cursor_t * c,
+ void *frame_pointer_address,
+ simgrid::mc::AddressSpace* address_space, int process_index)
+{
+ simgrid::dwarf::ExpressionContext context;
+ context.frame_base = frame_pointer_address;
+ context.cursor = c;
+ context.address_space = address_space;
+ context.object_info = object_info;
+ context.process_index = process_index;
+
+ if (!expression.empty()
+ && expression[0].atom >= DW_OP_reg0
+ && expression[0].atom <= DW_OP_reg31) {
+ int dwarf_register = expression[0].atom - DW_OP_reg0;
+ xbt_assert(c,
+ "Missing frame context for register operation DW_OP_reg%i",
+ dwarf_register);
+ return Location(dwarf_register_to_libunwind(dwarf_register));
+ }
+
+ simgrid::dwarf::ExpressionStack stack;
+ simgrid::dwarf::execute(expression, context, stack);
+ return Location((void*) stack.top());
+}
+
+// TODO, move this in a method of LocationList
+static simgrid::dwarf::DwarfExpression const* find_expression(
+ simgrid::dwarf::LocationList const& locations, unw_word_t ip)
+{
+ for (simgrid::dwarf::LocationListEntry const& entry : locations)
+ if (entry.valid_for_ip(ip))
+ return &entry.expression;
+ return nullptr;
+}
+
+Location resolve(
+ simgrid::dwarf::LocationList const& locations,
+ simgrid::mc::ObjectInformation* object_info,
+ unw_cursor_t * c,
+ void *frame_pointer_address,
+ simgrid::mc::AddressSpace* address_space,
+ int process_index)
+{
+ unw_word_t ip = 0;
+ if (c && unw_get_reg(c, UNW_REG_IP, &ip))
+ xbt_die("Could not resolve IP");
+ simgrid::dwarf::DwarfExpression const* expression =
+ find_expression(locations, ip);
+ if (!expression)
+ xbt_die("Could not resolve location");
+ return simgrid::dwarf::resolve(
+ *expression, object_info, c,
+ frame_pointer_address, address_space, process_index);
+}
+
+}
+}
\ No newline at end of file
--- /dev/null
+/* Copyright (c) 2004-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. */
+
+#ifndef SIMGRID_MC_OBJECT_LOCATION_H
+#define SIMGRID_MC_OBJECT_LOCATION_H
+
+#include <stdint.h>
+
+#include <vector>
+
+#include <libunwind.h>
+#include <dwarf.h>
+#include <elfutils/libdw.h>
+
+#include <simgrid_config.h>
+#include "mc_base.h"
+#include "mc_forward.hpp"
+#include "mc/AddressSpace.hpp"
+#include "mc/DwarfExpression.hpp"
+
+namespace simgrid {
+namespace dwarf {
+
+/** \brief A DWARF expression with optional validity contraints */
+class LocationListEntry {
+public:
+ simgrid::dwarf::DwarfExpression expression;
+ void* lowpc, *highpc;
+
+ LocationListEntry() : lowpc(nullptr), highpc(nullptr) {}
+
+ bool always_valid() const
+ {
+ return this->lowpc == nullptr && this->highpc == nullptr;
+ }
+ bool valid_for_ip(unw_word_t ip) const
+ {
+ return always_valid() || (
+ ip >= (unw_word_t) this->lowpc &&
+ ip < (unw_word_t) this->highpc);
+ }
+};
+
+typedef std::vector<LocationListEntry> LocationList;
+
+/** Location of some variable in memory
+ *
+ * The variable is located either in memory of a register.
+ */
+class Location {
+private:
+ void* memory_;
+ int register_id_;
+public:
+ Location(void* x) :memory_(x) {}
+ Location(int register_id) :
+ memory_(nullptr), register_id_(register_id) {}
+ // Type of location:
+ bool in_register() const { return memory_ == nullptr; }
+ bool in_memory() const { return memory_ != nullptr; }
+
+ // Get the location:
+ void* address() const { return memory_; }
+ int register_id() const { return register_id_; }
+};
+
+XBT_PRIVATE
+Location resolve(
+ simgrid::dwarf::DwarfExpression const& expression,
+ simgrid::mc::ObjectInformation* object_info, unw_cursor_t* c,
+ void* frame_pointer_address, simgrid::mc::AddressSpace* address_space,
+ int process_index);
+
+Location resolve(
+ simgrid::dwarf::LocationList const& locations,
+ simgrid::mc::ObjectInformation* object_info,
+ unw_cursor_t * c,
+ void *frame_pointer_address,
+ simgrid::mc::AddressSpace* address_space,
+ int process_index);
+
+}
+}
+
+SG_BEGIN_DECL()
+
+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
#include <xbt/base.h>
#include "mc_forward.h"
-#include "mc_location.h"
+#include "mc/LocationList.hpp"
namespace simgrid {
namespace mc {
#include <xbt/base.h>
#include "mc_forward.h"
-#include "mc_location.h"
+#include "mc/LocationList.hpp"
namespace simgrid {
namespace mc {
simgrid::mc::Type* type;
// Use either of:
- simgrid::mc::LocationList location_list;
+ simgrid::dwarf::LocationList location_list;
void* address;
size_t start_scope;
if (current_variable.address != NULL) {
new_var.address = current_variable.address;
} else if (!current_variable.location_list.empty()) {
- s_mc_location_t location;
- mc_dwarf_resolve_locations(
- &location, ¤t_variable.location_list,
- current_variable.object_info,
- &(stack_frame->unw_cursor),
- (void *) stack_frame->frame_base,
- &mc_model_checker->process(), process_index);
-
- switch(mc_get_location_type(&location)) {
- case MC_LOCATION_TYPE_ADDRESS:
- new_var.address = location.memory_location;
- break;
- case MC_LOCATION_TYPE_REGISTER:
- default:
+ 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(), process_index);
+
+ if (!location.in_memory())
xbt_die("Cannot handle non-address variable");
- }
+ new_var.address = location.address();
} else {
xbt_die("No address");
uintptr_t base = (uintptr_t) info->base_address();
variable->address = (void *) (base + offset);
} else {
- simgrid::mc::LocationListEntry entry;
+ simgrid::dwarf::LocationListEntry entry;
entry.expression = {expr, expr + len};
variable->location_list = { std::move(entry) };
}
}
}
+
+namespace simgrid {
+namespace dwarf {
+
+/** Convert a DWARF register into a libunwind register
+ *
+ * DWARF and libunwind does not use the same convention for numbering the
+ * registers on some architectures. The function makes the necessary
+ * convertion.
+ */
+int dwarf_register_to_libunwind(int dwarf_register)
+{
+#if defined(__x86_64__)
+ // It seems for this arch, DWARF and libunwind agree in the numbering:
+ return dwarf_register;
+#elif defined(__i386__)
+ // Could't find the authoritative source of information for this.
+ // This is inspired from http://source.winehq.org/source/dlls/dbghelp/cpu_i386.c#L517.
+ switch (dwarf_register) {
+ case 0:
+ return UNW_X86_EAX;
+ case 1:
+ return UNW_X86_ECX;
+ case 2:
+ return UNW_X86_EDX;
+ case 3:
+ return UNW_X86_EBX;
+ case 4:
+ return UNW_X86_ESP;
+ case 5:
+ return UNW_X86_EBP;
+ case 6:
+ return UNW_X86_ESI;
+ case 7:
+ return UNW_X86_EDI;
+ case 8:
+ return UNW_X86_EIP;
+ case 9:
+ return UNW_X86_EFLAGS;
+ case 10:
+ return UNW_X86_CS;
+ case 11:
+ return UNW_X86_SS;
+ case 12:
+ return UNW_X86_DS;
+ case 13:
+ return UNW_X86_ES;
+ case 14:
+ return UNW_X86_FS;
+ case 15:
+ return UNW_X86_GS;
+ case 16:
+ return UNW_X86_ST0;
+ case 17:
+ return UNW_X86_ST1;
+ case 18:
+ return UNW_X86_ST2;
+ case 19:
+ return UNW_X86_ST3;
+ case 20:
+ return UNW_X86_ST4;
+ case 21:
+ return UNW_X86_ST5;
+ case 22:
+ return UNW_X86_ST6;
+ case 23:
+ return UNW_X86_ST7;
+ default:
+ xbt_die("Bad/unknown register number.");
+ }
+#else
+#error This architecture is not supported yet for DWARF expression evaluation.
+#endif
+}
+
+}
+}
\ No newline at end of file
const void* base, simgrid::mc::Type* type, simgrid::mc::Member* member,
simgrid::mc::AddressSpace* snapshot, int process_index);
+XBT_PRIVATE
+int dwarf_register_to_libunwind(int dwarf_register);
+
}
}
+++ /dev/null
-/* Copyright (c) 2004-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. */
-
-#ifndef SIMGRID_MC_OBJECT_LOCATION_H
-#define SIMGRID_MC_OBJECT_LOCATION_H
-
-#include <stdint.h>
-
-#include <vector>
-
-#include <libunwind.h>
-#include <dwarf.h>
-#include <elfutils/libdw.h>
-
-#include <simgrid_config.h>
-#include "mc_base.h"
-#include "mc_forward.hpp"
-#include "mc/AddressSpace.hpp"
-#include "mc/DwarfExpression.hpp"
-
-namespace simgrid {
-namespace mc {
-
-
-/** \brief A DWARF expression with optional validity contraints */
-class LocationListEntry {
-public:
- simgrid::dwarf::DwarfExpression expression;
- void* lowpc, *highpc;
-
- LocationListEntry() : lowpc(nullptr), highpc(nullptr) {}
-
- bool valid_for_ip(unw_word_t ip)
- {
- return (this->lowpc == nullptr && this->highpc == nullptr)
- || (ip >= (unw_word_t) this->lowpc
- && ip < (unw_word_t) this->highpc);
- }
-};
-
-typedef std::vector<LocationListEntry> LocationList;
-
-}
-}
-
-SG_BEGIN_DECL()
-
-/** A location is either a location in memory of a register location
- *
- * Usage:
- *
- * * mc_dwarf_resolve_locations or mc_dwarf_resolve_location is used
- * to find the location of a given location expression or location list;
- *
- * * mc_get_location_type MUST be used to find the location type;
- *
- * * for MC_LOCATION_TYPE_ADDRESS, memory_address is the resulting address
- *
- * * for MC_LOCATION_TYPE_REGISTER, unw_get_reg(l.cursor, l.register_id, value)
- * and unw_get_reg(l.cursor, l.register_id, value) can be used to read/write
- * the value.
- * </ul>
- */
-typedef struct s_mc_location {
- void* memory_location;
- unw_cursor_t* cursor;
- int register_id;
-} s_mc_location_t, *mc_location_t;
-
-/** Type of a given location
- *
- * Use `mc_get_location_type(location)` to find the type.
- * */
-typedef enum mc_location_type {
- MC_LOCATION_TYPE_ADDRESS,
- MC_LOCATION_TYPE_REGISTER
-} mc_location_type;
-
-/** Find the type of a location */
-static inline __attribute__ ((always_inline))
-enum mc_location_type mc_get_location_type(mc_location_t location) {
- if (location->cursor) {
- return MC_LOCATION_TYPE_REGISTER;
- } else {
- return MC_LOCATION_TYPE_ADDRESS;
- }
-}
-
-SG_END_DECL()
-
-namespace simgrid {
-namespace dwarf {
-
-XBT_PRIVATE void resolve_location(
- mc_location_t location, simgrid::dwarf::DwarfExpression const& expression,
- simgrid::mc::ObjectInformation* object_info, unw_cursor_t* c,
- void* frame_pointer_address, simgrid::mc::AddressSpace* address_space,
- int process_index);
-
-}
-}
-
-SG_BEGIN_DECL()
-
-void mc_dwarf_resolve_locations(
- mc_location_t location, simgrid::mc::LocationList* locations,
- simgrid::mc::ObjectInformation* object_info, unw_cursor_t* c,
- void* frame_pointer_address, simgrid::mc::AddressSpace* address_space,
- int process_index);
-
-XBT_PRIVATE void mc_dwarf_location_list_init(
- simgrid::mc::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
assert(var);
void* frame_base = mc_find_frame_base(subprogram, info, cursor);
- s_mc_location_t location;
+ simgrid::dwarf::Location location = simgrid::dwarf::resolve(
+ var->location_list, info, cursor, frame_base, NULL, -1);
- mc_dwarf_resolve_locations(&location,
- &var->location_list, info, cursor, frame_base, NULL, -1);
-
- xbt_assert(mc_get_location_type(&location)==MC_LOCATION_TYPE_ADDRESS,
- "Unexpected location type for variable %s of %s", variable, function);
-
- xbt_assert(location.memory_location == address,
+ xbt_assert(location.in_memory(),
+ "Expected the variable %s of function %s to be in memory",
+ variable, function);
+ xbt_assert(location.address() == address,
"Bad resolution of local variable %s of %s", variable, function);
}
src/mc/mcer_ignore.h
src/mc/mc_ignore.h
src/mc/mc_liveness.h
- src/mc/mc_location.h
+ src/mc/LocationList.hpp
+ src/mc/LocationList.cpp
src/mc/mc_liveness.cpp
src/mc/mc_record.cpp
src/mc/mc_member.cpp