+ return state.stack[state.stack_size-1];
+}
+
+uintptr_t mc_dwarf_resolve_locations(mc_location_list_t locations, mc_object_info_t object_info, unw_cursor_t* c, void* frame_pointer_address, mc_snapshot_t snapshot) {
+
+ unw_word_t ip;
+ if(c) {
+ if(unw_get_reg(c, UNW_REG_IP, &ip))
+ xbt_die("Could not resolve IP");
+ }
+
+ for(size_t i=0; i!=locations->size; ++i) {
+ mc_expression_t expression = locations->locations + i;
+ if( (expression->lowpc==NULL && expression->highpc==NULL)
+ || (c && ip >= (unw_word_t) expression->lowpc && ip < (unw_word_t) expression->highpc)) {
+ return mc_dwarf_resolve_location(expression, object_info, c, frame_pointer_address, snapshot);
+ }
+ }
+ xbt_die("Could not resolve location");
+}
+
+/** \brief Find the frame base of a given frame
+ *
+ * \param frame
+ * \param unw_cursor
+ */
+void* mc_find_frame_base(dw_frame_t frame, mc_object_info_t object_info, unw_cursor_t* unw_cursor) {
+ return (void*) mc_dwarf_resolve_locations(&frame->frame_base, object_info, unw_cursor, NULL, NULL);
+}
+
+void mc_dwarf_expression_clear(mc_expression_t expression) {
+ free(expression->ops);
+ expression->ops = NULL;
+ expression->size = 0;
+ expression->lowpc = NULL;
+ expression->highpc = NULL;
+}
+
+void mc_dwarf_location_list_clear(mc_location_list_t list) {
+ for(size_t i=0; i!=list->size; ++i) {
+ mc_dwarf_expression_clear(list->locations + i);
+ }
+ free(list->locations);
+ list->locations = NULL;
+ list->size = 0;
+}
+
+void mc_dwarf_expression_init(mc_expression_t expression, size_t len, Dwarf_Op* ops) {
+ if(expression->ops) {
+ free(expression->ops);
+ }
+ expression->lowpc = NULL;
+ expression->highpc = NULL;
+ expression->size = len;
+ expression->ops = xbt_malloc(len*sizeof(Dwarf_Op));
+ memcpy(expression->ops, ops, len*sizeof(Dwarf_Op));
+}
+
+void mc_dwarf_location_list_init_from_expression(mc_location_list_t target, size_t len, Dwarf_Op* ops) {
+ if(target->locations) {
+ mc_dwarf_location_list_clear(target);
+ }
+ target->size = 1;
+ target->locations = (mc_expression_t) xbt_malloc(sizeof(s_mc_expression_t));
+ mc_dwarf_expression_init(target->locations, len, ops);