1 /* Copyright (c) 2014. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "mc_private.h"
9 /** Resolve snapshot in the process address space
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
17 void* mc_member_resolve(const void* base, dw_type_t type, dw_type_t member, mc_snapshot_t snapshot) {
18 if(!member->location.size) {
19 return ((char*) base) + member->offset;
22 s_mc_expression_state_t state;
23 memset(&state, 0, sizeof(s_mc_expression_state_t));
24 state.frame_base = NULL;
26 state.snapshot = snapshot;
28 state.stack[0] = (uintptr_t) base;
30 if(mc_dwarf_execute_expression(member->location.size, member->location.ops, &state))
31 xbt_die("Error evaluating DWARF expression");
32 if(state.stack_size==0)
33 xbt_die("No value on the stack");
35 return (void*) state.stack[state.stack_size-1];
38 /** Resolve snapshot in the snapshot address space
40 * @param object Snapshot address of the struct/class
41 * @param type Type of the struct/class
42 * @param member Member description
43 * @param snapshot Snapshot (or NULL)
44 * @return Snapshot address of the given member of the 'object' struct/class
46 void* mc_member_snapshot_resolve(const void* object, dw_type_t type, dw_type_t member, mc_snapshot_t snapshot) {
47 if(!member->location.size) {
48 return (char*) object + member->offset;
50 // Translate the problem in the process address space:
51 void* real_area = (void*) mc_untranslate_address((void *)object, snapshot);
52 // Resolve the member in the process address space:
53 void* real_member = mc_member_resolve(real_area, type, member, snapshot);
54 // Translate back in the snapshot address space:
55 return mc_translate_address((uintptr_t)real_member, snapshot);