Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into mc-process
[simgrid.git] / src / mc / mc_member.c
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 "mc_object_info.h"
8 #include "mc_private.h"
9
10 /** Resolve snapshot in the process address space
11  *
12  * @param object   Process address of the struct/class
13  * @param type     Type of the struct/class
14  * @param member   Member description
15  * @param snapshot Snapshot (or NULL)
16  * @return Process address of the given member of the 'object' struct/class
17  */
18 void *mc_member_resolve(const void *base, dw_type_t type, dw_type_t member,
19                         mc_address_space_t address_space, int process_index)
20 {
21   if (!member->location.size) {
22     return ((char *) base) + member->offset;
23   }
24
25   s_mc_expression_state_t state;
26   memset(&state, 0, sizeof(s_mc_expression_state_t));
27   state.frame_base = NULL;
28   state.cursor = NULL;
29   state.address_space = address_space;
30   state.stack_size = 1;
31   state.stack[0] = (uintptr_t) base;
32   state.process_index = process_index;
33
34   if (mc_dwarf_execute_expression
35       (member->location.size, member->location.ops, &state))
36     xbt_die("Error evaluating DWARF expression");
37   if (state.stack_size == 0)
38     xbt_die("No value on the stack");
39   else
40     return (void *) state.stack[state.stack_size - 1];
41 }