Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
59e7e7d06cd79beae5ddccbf7ec7211a98297668
[simgrid.git] / src / mc / mc_member.cpp
1 /* Copyright (c) 2014. 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
12 /** Resolve snapshot in the process address space
13  *
14  * @param object   Process address of the struct/class
15  * @param type     Type of the struct/class
16  * @param member   Member description
17  * @param snapshot Snapshot (or NULL)
18  * @return Process address of the given member of the 'object' struct/class
19  */
20 void *mc_member_resolve(const void *base, simgrid::mc::Type* type, simgrid::mc::Type* member,
21                         simgrid::mc::AddressSpace* address_space, int process_index)
22 {
23   // TODO, get rid of this?
24   if (!member->has_offset_location())
25     return ((char *) base) + member->offset();
26
27   s_mc_expression_state_t state;
28   memset(&state, 0, sizeof(s_mc_expression_state_t));
29   state.frame_base = NULL;
30   state.cursor = NULL;
31   state.address_space = address_space;
32   state.stack_size = 1;
33   state.stack[0] = (uintptr_t) base;
34   state.process_index = process_index;
35
36   if (simgrid::mc::execute(
37       member->location_expression, &state))
38     xbt_die("Error evaluating DWARF expression");
39   if (state.stack_size == 0)
40     xbt_die("No value on the stack");
41   else
42     return (void *) state.stack[state.stack_size - 1];
43 }