Logo AND Algorithmique Numérique Distribuée

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