Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] C++ify RegionType, StorageType enums
[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 extern "C" {
13
14 /** Resolve snapshot in the process address space
15  *
16  * @param object   Process address of the struct/class
17  * @param type     Type of the struct/class
18  * @param member   Member description
19  * @param snapshot Snapshot (or NULL)
20  * @return Process address of the given member of the 'object' struct/class
21  */
22 void *mc_member_resolve(const void *base, dw_type_t type, dw_type_t member,
23                         mc_address_space_t address_space, int process_index)
24 {
25   if (!member->location.size) {
26     return ((char *) base) + member->offset;
27   }
28
29   s_mc_expression_state_t state;
30   memset(&state, 0, sizeof(s_mc_expression_state_t));
31   state.frame_base = NULL;
32   state.cursor = NULL;
33   state.address_space = address_space;
34   state.stack_size = 1;
35   state.stack[0] = (uintptr_t) base;
36   state.process_index = process_index;
37
38   if (mc_dwarf_execute_expression
39       (member->location.size, member->location.ops, &state))
40     xbt_die("Error evaluating DWARF expression");
41   if (state.stack_size == 0)
42     xbt_die("No value on the stack");
43   else
44     return (void *) state.stack[state.stack_size - 1];
45 }
46
47 }