From patchwork Wed Oct 1 00:44:31 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: 3041 Received: (qmail 8267 invoked by alias); 1 Oct 2014 00:44:38 -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 8243 invoked by uid 89); 1 Oct 2014 00:44:35 -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-oi0-f48.google.com Received: from mail-oi0-f48.google.com (HELO mail-oi0-f48.google.com) (209.85.218.48) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 01 Oct 2014 00:44:33 +0000 Received: by mail-oi0-f48.google.com with SMTP id g201so69110oib.7 for ; Tue, 30 Sep 2014 17:44:32 -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=kgTwI1EPfQaWEYWGcVGis/4sB5PA5j1aUko6QqBiKEs=; b=NDlhIHk20g4DHhMdPyo1Xh7J1csxiO+mpByehCy5e+x6kuVwscAVF8qf2KQP0cy+MT gm1P6Vwfd6i0kps1RPQ8B0oYgy41zG6dGD5OfdQfll8dnZqzEHThb7Q1Z7t5F4Ax23KL JurC/hyDJE94L6KH+aUEJQjuC1NFx6oJHfMhGFiwlt4SLtD4GP7L+g2KgrR0NOzI5zTJ Hl72pUICermUcRUdG8uiv+mDxrY4Ro80aVlPHq2J3d8n3MZ+gpdr8haD1a/3hKXVObnk e9d44sPj1+hPGCw+Yj9zi1sM6zts87/sAvFNXlipHZmNqpbLFRSyM2WtMAmbin1YOxI1 DcLA== X-Gm-Message-State: ALoCoQmRb+bOfQnq2Zf4Z5kSYvTNEV2aRDvQ7Nxkl+M/eXX4dwHYbbyIOyMmPiK0XeeMHRFvbCca MIME-Version: 1.0 X-Received: by 10.182.18.101 with SMTP id v5mr15904249obd.64.1412124271971; Tue, 30 Sep 2014 17:44:31 -0700 (PDT) Received: by 10.202.197.13 with HTTP; Tue, 30 Sep 2014 17:44:31 -0700 (PDT) Date: Tue, 30 Sep 2014 17:44:31 -0700 Message-ID: Subject: [PATCH 1/2 v2] 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. Link to description: https://sourceware.org/ml/gdb-patches/2014-09/msg00788.html gdb/ChangeLog: 2014-09-30 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..cace2aa 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,43 @@ 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 mirror of V at MIRROR_ADDR and return it. It is implicitly + assumed that V does not have a dynamic type different from its static + type. */ + +struct value * +setup_stack_mirror (struct value *v, CORE_ADDR mirror_addr) +{ + struct value *mirror; + + write_memory (mirror_addr, value_contents_raw (v), + TYPE_LENGTH (value_type (v))); + mirror = value_from_contents_and_address (value_type (v), NULL, mirror_addr); + + VALUE_LVAL (v) = lval_mirrored_on_inferior_stack; + v->location.stack_mirror = mirror; + + return mirror; +} + /* Allocate NOT_LVAL value for type TYPE being OPTIMIZED_OUT. */ struct value * @@ -1446,6 +1485,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..0ce3aa0 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 struct value *setup_stack_mirror (struct value *v, CORE_ADDR addr); + extern void value_contents_copy (struct value *dst, int dst_offset, struct value *src, int src_offset, int length);