value.h revision 429b1845ef6bee24d8ab5851e90018666c83c481
15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* 2926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * This file is part of ltrace. 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2011,2012 Petr Machata, Red Hat Inc. 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This program is free software; you can redistribute it and/or 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modify it under the terms of the GNU General Public License as 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * published by the Free Software Foundation; either version 2 of the 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * License, or (at your option) any later version. 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This program is distributed in the hope that it will be useful, but 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * WITHOUT ANY WARRANTY; without even the implied warranty of 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * General Public License for more details. 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * You should have received a copy of the GNU General Public License 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * along with this program; if not, write to the Free Software 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 02110-1301 USA 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */ 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef VALUE_H 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define VALUE_H 235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "forward.h" 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "sysdep.h" 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* Values are objects that capture data fetched from an inferior. 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Typically a value is attached to a single inferior where it was 295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * extracted from, but it is possible to create a detached value. 305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Each value is typed. Values support a number of routines, such as 3153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * dereferencing if the value is of pointer type, array or structure 3253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * access, etc. 335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 34d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) * A value can be uninitialized, abstract or reified. Abstract values 3553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * are just references into inferior, no transfer has taken place yet. 365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Reified values have been copied out of the corresponding inferior, 3753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * or otherwise set to some value. */ 38926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 398abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)enum value_location_t { 405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) VAL_LOC_NODATA = 0, /* Uninitialized. */ 4109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) VAL_LOC_INFERIOR, /* Value is in the inferior process. */ 4253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) VAL_LOC_COPY, /* Value was copied out of the inferior. */ 43d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) VAL_LOC_SHARED, /* Like VAL_LOC_COPY, but don't free. */ 4453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) VAL_LOC_WORD, /* Like VAL_LOC_COPY, but small enough. */ 4553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)}; 4653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)struct value { 4853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) struct arg_type_info *type; 491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) struct Process *inferior; 505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) struct value *parent; 51e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch size_t size; 52591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch union { 53591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch void *address; /* VAL_LOC_COPY, VAL_LOC_SHARED */ 54d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) arch_addr_t inf_address; /* VAL_LOC_INFERIOR */ 55d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) long value; /* VAL_LOC_WORD */ 5653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) unsigned char buf[0]; 5709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) } u; 5853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) enum value_location_t where; 595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) int own_type; 60d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)}; 615267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* Initialize VALUE. INFERIOR must not be NULL. PARENT is parental 635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * value, in case of compound types. It may be NULL. TYPE is a type 6453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) * of the value. It may be NULL if the type is not yet known. If 65 * OWN_TYPE, the passed-in type is owned and released by value. */ 66void value_init(struct value *value, struct Process *inferior, 67 struct value *parent, struct arg_type_info *type, 68 int own_type); 69 70/* Initialize VALUE. This is like value_init, except that inferior is 71 * NULL. VALP is initialized as a detached value, without assigned 72 * process. You have to be careful not to use VAL_LOC_INFERIOR 73 * values if the value is detached. */ 74void value_init_detached(struct value *value, struct value *parent, 75 struct arg_type_info *type, int own_type); 76 77/* Set TYPE. This releases old type if it was owned. TYPE is owned 78 * and released if OWN_TYPE. */ 79void value_set_type(struct value *value, 80 struct arg_type_info *type, int own_type); 81 82/* Transfers the ownership of VALUE's type, if any, to the caller. 83 * This doesn't reset the VALUE's type, but gives up ownership if 84 * there was one. Previous ownership is passed in OWN_TYPE. */ 85void value_take_type(struct value *value, 86 struct arg_type_info **type, int *own_type); 87 88/* Release the data held by VALP, if any, but not the type. */ 89void value_release(struct value *valp); 90 91/* Value resides in inferior, on given ADDRESS. */ 92void value_in_inferior(struct value *valp, arch_addr_t address); 93 94/* Destroy the value. This is like value_release, but it additionally 95 * frees the value type, if it's own_type. It doesn't free the VAL 96 * pointer itself. */ 97void value_destroy(struct value *val); 98 99/* Set the data held by VALP to VALUE. This also sets the value's 100 * where to VAL_LOC_WORD. */ 101void value_set_word(struct value *valp, long value); 102 103/* Set the data held by VALP to a buffer of size SIZE. This buffer 104 * may be allocated by malloc. Returns NULL on failure. */ 105unsigned char *value_reserve(struct value *valp, size_t size); 106 107/* Access ELEMENT-th field of the compound value VALP, and store the 108 * result into the value RET_VAL. Returns 0 on success, or negative 109 * value on failure. */ 110int value_init_element(struct value *ret_val, struct value *valp, size_t element); 111 112/* De-reference pointer value, and store the result into the value 113 * RET_VAL. Returns 0 on success, or negative value on failure. */ 114int value_init_deref(struct value *ret_val, struct value *valp); 115 116/* If value is in inferior, copy it over to ltrace. Return 0 for 117 * success or negative value for failure. */ 118int value_reify(struct value *val, struct value_dict *arguments); 119 120/* Return a pointer to the data of the value. This copies the data 121 * from the inferior to the tracer. Returns NULL on failure. */ 122unsigned char *value_get_data(struct value *val, struct value_dict *arguments); 123 124/* Return a pointer to the raw data of the value. This shall not be 125 * called on a VAL_LOC_INFERIOR value. */ 126unsigned char *value_get_raw_data(struct value *val); 127 128/* Copy value VAL into the area pointed-to by RETP. Return 0 on 129 * success or a negative value on failure. */ 130int value_clone(struct value *retp, struct value *val); 131 132/* Give a size of given value. Return (size_t)-1 for error. This is 133 * a full size of the value. In particular for arrays, it returns 134 * actual length of the array, as computed by the length 135 * expression. */ 136size_t value_size(struct value *val, struct value_dict *arguments); 137 138/* Extract at most word-sized datum from the value. Return 0 on 139 * success or negative value on failure. */ 140int value_extract_word(struct value *val, long *retp, 141 struct value_dict *arguments); 142 143/* Copy contents of VAL to DATA. The buffer must be large enough to 144 * hold all the data inside. */ 145int value_extract_buf(struct value *val, unsigned char *data, 146 struct value_dict *arguments); 147 148/* Find the most enclosing parental value that is a struct. Return 149 * NULL when there is no such parental value. */ 150struct value *value_get_parental_struct(struct value *val); 151 152/* Determine whether this is all-zero value. Returns >0 if it is, ==0 153 * if it isn't, <0 on error. */ 154int value_is_zero(struct value *val, struct value_dict *arguments); 155 156/* Convert a structure type to pointer to that structure type. */ 157int value_pass_by_reference(struct value *value); 158 159#endif /* VALUE_H */ 160