Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #17 from mpoquet/master
[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, dw_type_t type, dw_type_t member,
21                         mc_address_space_t address_space, int process_index)
22 {
23   if (!member->location.size) {
24     return ((char *) base) + member->offset;
25   }
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 (mc_dwarf_execute_expression
37       (member->location.size, member->location.ops, &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 }