Logo AND Algorithmique Numérique Distribuée

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