Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[tesh] cosmetics on outputs when an error is detected
[simgrid.git] / src / mc / mc_member.cpp
1 /* Copyright (c) 2014-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <xbt/misc.h>
8
9 #include "mc_object_info.h"
10 #include "mc_private.h"
11 #include "mc/Type.hpp"
12
13 /** Resolve snapshot in the process address space
14  *
15  * @param object   Process address of the struct/class
16  * @param type     Type of the struct/class
17  * @param member   Member description
18  * @param snapshot Snapshot (or NULL)
19  * @return Process address of the given member of the 'object' struct/class
20  */
21 void *mc_member_resolve(const void *base, simgrid::mc::Type* type, simgrid::mc::Type* member,
22                         simgrid::mc::AddressSpace* address_space, int process_index)
23 {
24   // TODO, get rid of this?
25   if (!member->has_offset_location())
26     return ((char *) base) + member->offset();
27
28   s_mc_expression_state_t state;
29   memset(&state, 0, sizeof(s_mc_expression_state_t));
30   state.frame_base = NULL;
31   state.cursor = NULL;
32   state.address_space = address_space;
33   state.stack_size = 1;
34   state.stack[0] = (uintptr_t) base;
35   state.process_index = process_index;
36
37   if (simgrid::mc::execute(
38       member->location_expression, &state))
39     xbt_die("Error evaluating DWARF expression");
40   if (state.stack_size == 0)
41     xbt_die("No value on the stack");
42   else
43     return (void *) state.stack[state.stack_size - 1];
44 }