From patchwork Fri Sep 26 13:29:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siva Chandra Reddy X-Patchwork-Id: 2999 Received: (qmail 29693 invoked by alias); 26 Sep 2014 13:29:59 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 29681 invoked by uid 89); 26 Sep 2014 13:29:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wi0-f175.google.com Received: from mail-wi0-f175.google.com (HELO mail-wi0-f175.google.com) (209.85.212.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 26 Sep 2014 13:29:57 +0000 Received: by mail-wi0-f175.google.com with SMTP id r20so10932081wiv.8 for ; Fri, 26 Sep 2014 06:29:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=tnJcK/Hyb7YrUYsgjY+PbMQtqbFZoQ/37ogZac1I830=; b=LlSiiBjikI6PREIqbv7OsqKMcCPs4BvOTW5kvMCi0YBHUrh8xFjgDkqNIzTON2fjDa 5plntQA482Juwunu7rTiCOmVVmt1sX5jfycgevwqXvdPjkwsElAeH8XItpTM3ZEKxn1o VSAi88HA1j4ssOdzP8p8iVzKmE/qve+NU6TC3DdNL+r/CxIrLPYL71fXw7YA6N8Znt7i iA1AMnzbFxoID3xj7LFXiAu6F+twIwhIdPudZJYp1vgYZGisg6bmPkD75Vapx3McHB6N zOlrmfnlh0agy171J9IqSZN0CilDp2lZyAAiBqWMUHyUF5pstRFHsHwXLYZbqRxEA0O+ ApWQ== X-Gm-Message-State: ALoCoQnEbJ73KcvJxc6K/LUucxvu4AwVVuMxmlEiqFhAoiVD/9zbCsBH011Vo6HOH9KXrGpZ5xfu MIME-Version: 1.0 X-Received: by 10.180.99.67 with SMTP id eo3mr27287321wib.8.1411738194498; Fri, 26 Sep 2014 06:29:54 -0700 (PDT) Received: by 10.27.53.136 with HTTP; Fri, 26 Sep 2014 06:29:54 -0700 (PDT) Date: Fri, 26 Sep 2014 06:29:54 -0700 Message-ID: Subject: [PATCH 1/2] Introduce a new lval_type lval_mirrored_on_inferior_stack From: Siva Chandra To: gdb-patches X-IsSubscribed: yes Introduce a new lval_type lval_mirrored_on_inferior_stack. Add support for values with the new lval_type. gdb/ChangeLog: 2014-09-26 Siva Chandra Reddy * defs.h (enum lval_type): Add new lval_type lval_mirrored_on_inferior_stack. * valops.c (value_coerce_array, value_from_pointer) (value_addr): Do not error on values with lval_type lval_mirrored_on_inferior_stack. * value.c (struct value): Add field stack_mirror to the location field. (allocate_value_mirrored_on_stack, setup_stack_mirror): New functions. (value_address): Handle values with lval_type lval_mirrored_on_inferior_stack. * value.h (allocate_value_mirrored_on_stack) (setup_stack_mirror): Declare. diff --git a/gdb/defs.h b/gdb/defs.h index 8914512..4e64b75 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -342,7 +342,10 @@ enum lval_type lval_internalvar_component, /* * Value's bits are fetched and stored using functions provided by its creator. */ - lval_computed + lval_computed, + /* * Value mirrored on inferior stack. The value on stack is an + lval_memory value. */ + lval_mirrored_on_inferior_stack }; /* * Control types for commands. */ diff --git a/gdb/valops.c b/gdb/valops.c index e1decf0..564d282 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -1440,7 +1440,8 @@ value_coerce_array (struct value *arg1) be a good time to do so. */ arg1 = value_coerce_to_target (arg1); - if (VALUE_LVAL (arg1) != lval_memory) + if (VALUE_LVAL (arg1) != lval_memory + && VALUE_LVAL (arg1) != lval_mirrored_on_inferior_stack) error (_("Attempt to take address of value not located in memory.")); return value_from_pointer (lookup_pointer_type (TYPE_TARGET_TYPE (type)), @@ -1455,7 +1456,8 @@ value_coerce_function (struct value *arg1) { struct value *retval; - if (VALUE_LVAL (arg1) != lval_memory) + if (VALUE_LVAL (arg1) != lval_memory + && VALUE_LVAL (arg1) != lval_mirrored_on_inferior_stack) error (_("Attempt to take address of value not located in memory.")); retval = value_from_pointer (lookup_pointer_type (value_type (arg1)), @@ -1489,7 +1491,8 @@ value_addr (struct value *arg1) then this would be a good time to force it to memory. */ arg1 = value_coerce_to_target (arg1); - if (VALUE_LVAL (arg1) != lval_memory) + if (VALUE_LVAL (arg1) != lval_memory + && VALUE_LVAL (arg1) != lval_mirrored_on_inferior_stack) error (_("Attempt to take address of value not located in memory.")); /* Get target memory address. */ diff --git a/gdb/value.c b/gdb/value.c index fdc8858d..ec99828 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -233,6 +233,8 @@ struct value /* Closure for those functions to use. */ void *closure; } computed; + + struct value *stack_mirror; } location; /* Describes offset of a value within lval of a structure in bytes. @@ -998,6 +1000,39 @@ allocate_computed_value (struct type *type, return v; } +/* Allocate a value which is mirrored on inferior stack. + MIRROR is a value whose lval is lval_memory. It is an error if MIRROR has + an lval of any other type. */ + +struct value * +allocate_value_mirrored_on_stack (struct value *mirror) +{ + struct value *v; + + gdb_assert (VALUE_LVAL (mirror) == lval_memory); + + v = allocate_value (value_type (mirror)); + VALUE_LVAL (v) = lval_mirrored_on_inferior_stack; + v->location.stack_mirror = mirror; + + return v; +} + +/* Sets up a mirro of V at MIRROR_ADDR. It is implicitly assumed that V does + not have a dynamic type different from its static type. */ + +void +setup_stack_mirror (struct value *v, CORE_ADDR mirror_addr) +{ + write_memory (mirror_addr, value_contents_raw (v), + TYPE_LENGTH (value_type (v))); + + VALUE_LVAL (v) = lval_mirrored_on_inferior_stack; + v->location.stack_mirror = value_from_contents_and_address (value_type (v), + NULL, + mirror_addr); +} + /* Allocate NOT_LVAL value for type TYPE being OPTIMIZED_OUT. */ struct value * @@ -1446,6 +1481,8 @@ value_address (const struct value *value) return 0; if (value->parent != NULL) return value_address (value->parent) + value->offset; + else if (value->lval == lval_mirrored_on_inferior_stack) + return value_address (value->location.stack_mirror); else return value->location.address + value->offset; } diff --git a/gdb/value.h b/gdb/value.h index e3603c3..555a980 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -677,6 +677,10 @@ extern struct value *default_read_var_value (struct symbol *var, extern struct value *allocate_value (struct type *type); extern struct value *allocate_value_lazy (struct type *type); + +extern struct value *allocate_value_mirrored_on_stack (struct value *mirror); +extern void setup_stack_mirror (struct value *v, CORE_ADDR mirror_addr); + extern void value_contents_copy (struct value *dst, int dst_offset, struct value *src, int src_offset, int length);