aboutsummaryrefslogtreecommitdiff
path: root/libctf/testsuite
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2024-03-26 13:04:20 +0000
committerNick Alcock <nick.alcock@oracle.com>2024-04-19 16:14:47 +0100
commit483546ce4f36a93d3fb711f2261b15b75871f3f9 (patch)
tree7022abc55beff5b441d1c959ae52cbc18bafaf82 /libctf/testsuite
parentcf9da3b0b6a6ae9d71ba36898a5e39710150f85e (diff)
downloadgdb-483546ce4f36a93d3fb711f2261b15b75871f3f9.zip
gdb-483546ce4f36a93d3fb711f2261b15b75871f3f9.tar.gz
gdb-483546ce4f36a93d3fb711f2261b15b75871f3f9.tar.bz2
libctf: make ctf_serialize() actually serialize
ctf_serialize() evolved from the old ctf_update(), which mutated the in-memory CTF dict to make all the dynamic in-memory types into static, unchanging written-to-the-dict types (by deserializing and reserializing it): back in the days when you could only do type lookups on static types, this meant you could see all the types you added recently, at the small, small cost of making it impossible to change those older types ever again and inducing an amortized O(n^2) cost if you actually wanted to add references to types you added at arbitrary times to later types. It also reset things so that ctf_discard() would throw away only types you added after the most recent ctf_update() call. Some time ago this was all changed so that you could look up dynamic types just as easily as static types: ctf_update() changed so that only its visible side-effect of affecting ctf_discard() remained: the old ctf_update() was renamed to ctf_serialize(), made internal to libctf, and called from the various functions that wrote files out. ... but it was still working by serializing and deserializing the entire dict, swapping out its guts with the newly-serialized copy in an invasive and horrible fashion that coupled ctf_serialize() to almost every field in the ctf_dict_t. This is totally useless, and fixing it is easy: just rip all that code out and have ctf_serialize return a serialized representation, and let everything use that directly. This simplifies most of its callers significantly. (It also points up another bug: ctf_gzwrite() failed to call ctf_serialize() at all, so it would only ever work for a dict you just ctf_write_mem()ed yourself, just for its invisible side-effect of serializing the dict!) This lets us simplify away a bunch of internal-only open-side functionality for overriding the syn_ext_strtab and some just-added functionality for forcing in an existing atoms table, without loss of functionality, and lets us lift the restriction on reserializing a dict that was ctf_open()ed rather than being ctf_create()d: it's now perfectly OK to open a dict, modify it (except for adding members to existing structs, unions, or enums, which fails with -ECTF_RDONLY), and write it out again, just as one would expect. libctf/ * ctf-serialize.c (ctf_symtypetab_sect_sizes): Fix typos. (ctf_type_sect_size): Add static type sizes too. (ctf_serialize): Return the new dict rather than updating the existing dict. No longer fail for dicts with static types; copy them onto the start of the new types table. (ctf_gzwrite): Actually serialize before gzwriting. (ctf_write_mem): Improve forced (test-mode) endian-flipping: flip dicts even if they are too small to be compressed. Improve confusing variable naming. * ctf-archive.c (arc_write_one_ctf): Don't bother to call ctf_serialize: both the functions we call do so. * ctf-string.c (ctf_str_create_atoms): Drop serializing case (atoms arg). * ctf-open.c (ctf_simple_open): Call ctf_bufopen directly. (ctf_simple_open_internal): Delete. (ctf_bufopen_internal): Delete/rename to ctf_bufopen: no longer bother with syn_ext_strtab or forced atoms table, serialization no longer needs them. * ctf-create.c (ctf_create): Call ctf_bufopen directly. * ctf-impl.h (ctf_str_create_atoms): Drop atoms arg. (ctf_simple_open_internal): Delete. (ctf_bufopen_internal): Likewise. (ctf_serialize): Adjust. * testsuite/libctf-lookup/add-to-opened.c: Adjust now that this is supposed to work.
Diffstat (limited to 'libctf/testsuite')
-rw-r--r--libctf/testsuite/libctf-lookup/add-to-opened.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/libctf/testsuite/libctf-lookup/add-to-opened.c b/libctf/testsuite/libctf-lookup/add-to-opened.c
index dc2e1f5..96629af 100644
--- a/libctf/testsuite/libctf-lookup/add-to-opened.c
+++ b/libctf/testsuite/libctf-lookup/add-to-opened.c
@@ -118,11 +118,9 @@ main (int argc, char *argv[])
if (ctf_errno (fp) != ECTF_RDONLY)
fprintf (stderr, "unexpected error %s attempting to set array in readonly portion\n", ctf_errmsg (ctf_errno (fp)));
- if ((ctf_written = ctf_write_mem (fp, &size, 4096)) != NULL)
- fprintf (stderr, "Writeout unexpectedly succeeded: %s\n", ctf_errmsg (ctf_errno (fp)));
-
- if (ctf_errno (fp) != ECTF_RDONLY)
- fprintf (stderr, "unexpected error %s trying to write out previously serialized dict\n", ctf_errmsg (ctf_errno (fp)));
+ if ((ctf_written = ctf_write_mem (fp, &size, 4096)) == NULL)
+ fprintf (stderr, "Re-writeout unexpectedly failed: %s\n", ctf_errmsg (ctf_errno (fp)));
+ free (ctf_written);
/* Finally, make sure we can add new types, and look them up again. */
@@ -138,6 +136,9 @@ main (int argc, char *argv[])
if (ctf_type_reference (fp, ptrtype) != type)
fprintf (stderr, "Look up of newly-added type in serialized dict yields ID %lx, expected %lx\n", ctf_type_reference (fp, ptrtype), type);
+ ctf_dict_close (fp);
+ ctf_close (ctf);
+
printf ("All done.\n");
return 0;