From: Tom Tromey <tromey@redhat.com>
To: Jie Zhang <jie.zhang@analog.com>
Cc: gdb-patches@sourceware.org
Subject: Re: PING: [PATCH] Fix a bug of addrmap
Date: Tue, 25 Nov 2008 23:09:00 -0000 [thread overview]
Message-ID: <m3skpfu466.fsf@fleche.redhat.com> (raw)
In-Reply-To: <490E9540.7000207@analog.com> (Jie Zhang's message of "Mon\, 03 Nov 2008 14\:08\:00 +0800")
>>>>> "Jie" == Jie Zhang <jie.zhang@analog.com> writes:
Jie> Could someone give a review on this patch:
Jie> http://sourceware.org/ml/gdb-patches/2008-10/msg00503.html
I was curious about this patch so I took a look.
Since addrmap is a relatively self-contained data structure, I figured
it was a good candidate for a unit test. So, I wrote a test case
based on your original report.
I think the test case is pretty clear. And sure enough, it fails
before your patch and it passes after your pass. So, on that basis I
would support checking in your patch. However, please note I cannot
approve it.
I think it also worth checking in the appended. If we ever find
another addrmap bug, we could extend the unit test. Please review
this, thanks.
Tom
2008-11-25 Tom Tromey <tromey@redhat.com>
* Makefile.in (test-addrmap.o): New target.
(test-addrmap): Likewise.
(clean mostlyclean): Remove test-addrmap.
* addrmap.c (xfree): New function.
(internal_error): Likewise.
(test_inclusion): Likewise.
(main): Likewise.
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 5432c88..8d947d2 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -968,6 +968,15 @@ test-cp-name-parser$(EXEEXT): test-cp-name-parser.o $(LIBIBERTY)
$(CC_LD) $(INTERNAL_LDFLAGS) -o test-cp-name-parser$(EXEEXT) \
test-cp-name-parser.o $(LIBIBERTY)
+# Addrmap has unit tests which can be run standalone.
+test-addrmap.o: addrmap.c
+ $(COMPILE) -DADDRMAP_UNIT_TEST $(srcdir)/addrmap.c
+ $(POSTCOMPILE)
+
+test-addrmap: test-addrmap.o $(LIBIBERTY)
+ $(CC_LD) $(INTERNAL_LDFLAGS) -o test-addrmap$(EXEEXT) \
+ test-addrmap.o $(LIBIBERTY)
+
# We do this by grepping through sources. If that turns out to be too slow,
# maybe we could just require every .o file to have an initialization routine
# of a given name (top.o -> _initialize_top, etc.).
@@ -1117,7 +1126,7 @@ clean mostlyclean: $(CONFIG_CLEAN)
rm -f init.c version.c
rm -f gdb$(EXEEXT) core make.log
rm -f gdb[0-9]$(EXEEXT)
- rm -f test-cp-name-parser$(EXEEXT)
+ rm -f test-cp-name-parser$(EXEEXT) test-addrmap$(EXEEXT)
rm -f xml-builtin.c stamp-xml
.PHONY: clean-tui
diff --git a/gdb/addrmap.c b/gdb/addrmap.c
index 68832e9..a73a945 100644
--- a/gdb/addrmap.c
+++ b/gdb/addrmap.c
@@ -541,3 +541,67 @@ _initialize_addrmap (void)
gdb_assert (sizeof (splay_tree_key) >= sizeof (CORE_ADDR *));
gdb_assert (sizeof (splay_tree_value) >= sizeof (void *));
}
+
+\f
+/* Unit testing. */
+
+#ifdef ADDRMAP_UNIT_TEST
+
+/* When this file is built as a standalone program, xmalloc comes from
+ libiberty --- in which case we have to provide xfree ourselves. */
+
+void
+xfree (void *ptr)
+{
+ free (ptr);
+}
+
+/* Likewise for internal_error. */
+NORETURN void
+internal_error (const char *file, int line, const char *string, ...)
+{
+ /* The user will have to debug this anyway. */
+ exit (1);
+}
+
+/* A test case reported to the list. Return 1 if ok, 0 on
+ failure. */
+static int
+test_inclusion (void)
+{
+ struct obstack alloc;
+ struct addrmap *map;
+ char *fooc = "foo.c";
+ char *mainc = "main.c";
+ int result;
+
+ obstack_init (&alloc);
+ map = addrmap_create_mutable (&alloc);
+
+ addrmap_set_empty (map, 0x400448, 0x40053e, mainc);
+ addrmap_set_empty (map, 0x400454, 0x40045f, fooc);
+
+ map = addrmap_create_fixed (map, &alloc);
+
+ result = (addrmap_find (map, 0x0) == NULL
+ && addrmap_find (map, 0x400447) == NULL
+ && addrmap_find (map, 0x400448) == mainc
+ && addrmap_find (map, 0x400453) == mainc
+ && addrmap_find (map, 0x400454) == fooc
+ && addrmap_find (map, 0x40045f) == fooc
+ && addrmap_find (map, 0x400460) == mainc
+ && addrmap_find (map, 0x40053e) == mainc
+ && addrmap_find (map, 0x40053f) == NULL);
+
+ obstack_free (&alloc, 0);
+
+ return result;
+}
+
+int
+main (int argc, char **argv)
+{
+ return !test_inclusion ();
+}
+
+#endif /* ADDRMAP_UNIT_TEST */
next prev parent reply other threads:[~2008-11-25 17:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-21 4:44 Jie Zhang
2008-11-03 6:09 ` PING: " Jie Zhang
2008-11-25 23:09 ` Tom Tromey [this message]
2008-11-26 6:34 ` Joel Brobecker
2008-11-26 13:53 ` Tom Tromey
2008-11-26 14:24 ` Daniel Jacobowitz
2008-11-26 15:05 ` Daniel Jacobowitz
2008-11-27 14:45 ` Tom Tromey
2008-12-08 23:12 ` Joel Brobecker
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=m3skpfu466.fsf@fleche.redhat.com \
--to=tromey@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=jie.zhang@analog.com \
/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