From: "Andrew Burgess" <aburgess@broadcom.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 11/12] Add test mechanism for value unavailable vector.
Date: Mon, 12 Aug 2013 12:32:00 -0000 [thread overview]
Message-ID: <5208D5E3.8080608@broadcom.com> (raw)
In-Reply-To: <5208D1DF.1090201@broadcom.com>
This patch it optional, and is really just an idea. More work
might be required.
This adds a unit test like command for the value unavailable vector.
This let me build vectors and see how they were merged and ordered to
help get the code right.
Given that the amount of extra code is pretty small it might be nice to
keep this in.... what do you think?
Some possible changes would be, adding a new "unit-test" sub-command
under which this could be placed, currently the test command lives
under maintenance, but we could have "maintenance unit-test <blah>".
We could also guard the unit tests with a build flag so compiling
them in was optional.
What do folk think?
Cheers,
Andrew
gdb/ChangeLog
2013-08-09 Andrew Burgess <aburgess@broadcom.com>
* value.c (vector_test_show): New function.
(vector_test_parse_range): New function.
(vector_test_command): New function.
(_initialize_values): Add value-vector-test command.
gdb/testsuite/ChangeLog
2013-08-09 Andrew Burgess <aburgess@broadcom.com>
* gdb.base/value-unavailable-vector.exp: New file.
diff --git a/gdb/testsuite/gdb.base/value-unavailable-vector.exp
b/gdb/testsuite/gdb.base/value-unavailable-vector.exp
new file mode 100644
index 0000000..2a602eb
--- /dev/null
+++ b/gdb/testsuite/gdb.base/value-unavailable-vector.exp
@@ -0,0 +1,32 @@
+# Copyright 2013 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Test the behaviour of the gdb value unavailable bits vector.
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+
+gdb_test "maintenance value-vector-test (2,2,unavailable)
(4,2,unavailable) (2,6,optimized-out)" \
+ "VECTOR: \\(2, 6, optimized-out\\)"
+
+gdb_test "maintenance value-vector-test ( 4, 2,unavailable) ( 8,
2,unavailable) (12, 2,unavailable) ( 2,11,optimized-out)" \
+ "VECTOR: \\(2, 11, optimized-out\\) \\(13, 1, unavailable\\)"
+
+gdb_test "maintenance value-vector-test ( 4, 2,unavailable) ( 8,
2,unavailable) (12, 2,optimized-out) ( 2,13,unavailable)" \
+ "VECTOR: \\(2, 10, unavailable\\) \\(12, 2, optimized-out\\) \\(14,
1, unavailable\\)"
+
+gdb_test "maintenance value-vector-test ( 4, 2,optimized-out) ( 8,
2,optimized-out) (12, 2,optimized-out) ( 2,13,unavailable)" \
+ "VECTOR: \\(2, 2, unavailable\\) \\(4, 2, optimized-out\\) \\(6, 2,
unavailable\\) \\(8, 2, optimized-out\\) \\(10, 2, unavailable\\) \\(12,
2, optimized-out\\) \\(14, 1, unavailable\\)"
diff --git a/gdb/value.c b/gdb/value.c
index ec46863..7151b61 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -43,6 +43,7 @@
#include "tracepoint.h"
#include "cp-abi.h"
#include "user-regs.h"
+#include "cli/cli-utils.h"
/* Prototypes for exported functions. */
@@ -3736,6 +3737,122 @@ value_fetch_lazy (struct value *val)
return 0;
}
+/* Internal debugging function. Used to display a vector containing the
+ unavailable and optimized out information. This is currently only used
+ by the maintenance command value-vector-test. */
+
+static void
+vector_test_show (VEC(range_s) *vector)
+{
+ if (VEC_empty (range_s, vector))
+ printf_filtered ("VECTOR is empty.\n");
+ else
+ {
+ range_s *r;
+ int i;
+
+ printf_filtered ("VECTOR:");
+ for (i = 0; VEC_iterate (range_s, vector, i, r); i++)
+ {
+ printf_filtered (" (%d, %d, %s)",
+ r->offset, r->length,
+ (r->reason == bit_range_optimized_out
+ ? "optimized-out"
+ : (r->reason == bit_range_unavailable
+ ? "unavailable"
+ : "unknown")));
+
+ if (i > 0)
+ {
+ range_s *prev = VEC_index (range_s, vector, (i - 1));
+
+ if (prev->offset + prev->length > r->offset)
+ internal_error (__FILE__, __LINE__,
+ "Inconsistent vector configuration: overlap");
+
+ if (prev->offset + prev->length == r->offset
+ && prev->reason == r->reason)
+ internal_error (__FILE__, __LINE__,
+ "Inconsistent vector configuration: unmerged");
+ }
+ }
+ printf_filtered ("\n");
+ }
+}
+
+/* Parse vector entries of the form "(START, LENGTH, TYPE)", where START
+ and LENGTH are numbers, START >= 0 && LENGTH > 0. The TYPE is a string
+ either "optimized-out", or "unavailable". */
+
+static char *
+vector_test_parse_range (char *exp, range_s *rng)
+{
+ char *tmp;
+
+ gdb_assert (exp);
+ exp = skip_spaces (exp);
+
+ memset (rng, 0, sizeof (*rng));
+
+ if (*exp != '(')
+ error ("Invalid range specification in `%s'", exp);
+ exp++;
+ /* Find the next "," character (error if non found). */
+ tmp = strchr (exp, ',');
+ if (!tmp)
+ error ("Missing `,' in `%s'", exp);
+ *tmp = '\0';
+ rng->offset = parse_and_eval_long (exp);
+ *tmp = ',';
+ exp = skip_spaces (tmp + 1);
+
+ tmp = strchr (exp, ',');
+ if (!tmp)
+ error ("Missing `,' in `%s'", exp);
+ *tmp = '\0';
+ rng->length = parse_and_eval_long (exp);
+ *tmp = ',';
+ exp = skip_spaces (tmp + 1);
+
+ tmp = strchr (exp, ')');
+ if (!tmp)
+ error ("Missing `)' in `%s'", exp);
+ *tmp = '\0';
+ if (strcasecmp (exp, "unavailable") == 0)
+ rng->reason = bit_range_unavailable;
+ else if (strcasecmp (exp, "optimized-out") == 0)
+ rng->reason = bit_range_optimized_out;
+ else
+ error ("unknown reason field in `%s'", exp);
+ *tmp = ')';
+ exp = skip_spaces (tmp + 1);
+
+ return exp;
+}
+
+/* Parse sequence of range descriptions from EXP into a vector then display
+ the resulting vector. This allows us to test the vector construction
+ algorithm. */
+
+static void
+vector_test_command (char *exp, int from_tty)
+{
+ VEC(range_s) *vector = NULL;
+
+ (void) from_tty;
+
+ while (exp && *exp != '\0')
+ {
+ range_s r;
+
+ exp = vector_test_parse_range (exp, &r);
+ insert_into_bit_range_vector (&vector, r.offset, r.length, r.reason);
+ }
+
+ vector_test_show (vector);
+ VEC_free (range_s, vector);
+}
+
void
_initialize_values (void)
{
@@ -3768,4 +3885,8 @@ VARIABLE is already initialized."));
add_prefix_cmd ("function", no_class, function_command, _("\
Placeholder command for showing help on convenience functions."),
&functionlist, "function ", 0, &cmdlist);
+
+ add_cmd ("value-vector-test", class_maintenance, vector_test_command,
+ _("Allows for testing of internal gdb unavailability vector."),
+ &maintenancelist);
}
next prev parent reply other threads:[~2013-08-12 12:32 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-12 12:15 [RFC 00/12] Merge value optimized_out and unavailable Andrew Burgess
2013-08-12 12:16 ` [PATCH 01/12] Introduce is_unavailable_error Andrew Burgess
2013-08-12 12:18 ` [PATCH 02/12]: Remove set_value_optimized_out Andrew Burgess
2013-08-12 12:20 ` [PATCH 03/12] Mark optimized out values as non-lazy Andrew Burgess
2013-11-26 16:38 ` Pedro Alves
2013-11-26 19:19 ` Andrew Burgess
2013-08-12 12:22 ` [PATCH 04/12] Introduce OPTIMIZED_OUT_ERROR Andrew Burgess
2013-08-12 12:24 ` [PATCH 05/12] Convert the unavailable to be bit based Andrew Burgess
2013-08-12 12:27 ` [PATCH 06/12] Delete value_bits_valid Andrew Burgess
2013-11-25 21:41 ` [PATCH] Print entirely unavailable struct/union values as a single <unavailable>. (Re: [PATCH 06/12] Delete value_bits_valid.) Pedro Alves
2013-11-26 10:13 ` Andrew Burgess
2013-11-28 20:14 ` Pedro Alves
2013-08-12 12:28 ` [PATCH 07/12] Generic print unavailable or optimized out function Andrew Burgess
2013-08-12 12:29 ` [PATCH 08/12] Replace some value_optimized_out with value_entirely_available Andrew Burgess
2013-11-27 17:52 ` [COMMITTED PATCH 0/2] "set debug frame 1" and not saved registers (was: Re: [PATCH 08/12] Replace some value_optimized_out with value_entirely_available) Pedro Alves
2013-11-27 18:14 ` [PATCH 1/2] Make "set debug frame 1" use the standard print routine for optimized out values Pedro Alves
2013-11-27 18:35 ` [PATCH 2/2] Make "set debug frame 1" output print <not saved> instead of <optimized out> Pedro Alves
2013-11-27 18:41 ` Pedro Alves
2013-11-27 18:53 ` [pushed] Fix type of not saved registers. (was: Re: [PATCH 2/2] Make "set debug frame 1" output print <not saved> instead of <optimized out>.) Pedro Alves
2013-08-12 12:30 ` [PATCH 09/12] DWARF value, mark unavailable in bits not bytes Andrew Burgess
2013-08-12 12:31 ` [PATCH 10/12] Merge optimized_out into unavailable vector Andrew Burgess
2013-08-12 12:32 ` Andrew Burgess [this message]
2013-08-12 12:33 ` [PATCH 12/12] Remove old lval check valid functions Andrew Burgess
2013-08-29 17:21 ` PING: Re: [RFC 00/12] Merge value optimized_out and unavailable Andrew Burgess
2013-11-12 9:37 ` Andrew Burgess
2013-11-29 22:31 ` Pedro Alves
2013-12-04 14:54 ` Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5208D5E3.8080608@broadcom.com \
--to=aburgess@broadcom.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox