1 /* Make sure we can look up a pointer-to-type where the type is more than a page
2    into the parent and the child has never had a lookup before.  */
3 
4 #include <ctf-api.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 
9 int
main(void)10 main (void)
11 {
12   ctf_dict_t *pfp, *cfp;
13   ctf_encoding_t e = { CTF_INT_SIGNED, 0, sizeof (long) };
14   ctf_id_t ptype, ptrtype, type, foo;
15   size_t i;
16   int err;
17 
18   if ((pfp = ctf_create (&err)) == NULL)
19     goto create_err;
20 
21   if ((ptype = ctf_add_integer (pfp, CTF_ADD_NONROOT, "blah", &e)) == CTF_ERR)
22     goto create_parent;
23 
24   for (i = 0; i < 4096; i++)
25     if ((foo = ctf_add_pointer (pfp, CTF_ADD_NONROOT, ptype)) == CTF_ERR)
26       goto create_parent;
27 
28   if ((cfp = ctf_create (&err)) == NULL)
29     goto create_err;
30 
31   if (ctf_import (cfp, pfp) < 0)
32     goto create_child;
33 
34   if ((ptype = ctf_add_integer (pfp, CTF_ADD_ROOT, "foo", &e)) == CTF_ERR)
35     goto create_parent;
36 
37   if ((ptrtype = ctf_add_pointer (pfp, CTF_ADD_ROOT, ptype)) == CTF_ERR)
38     goto create_parent;
39 
40   if ((type = ctf_lookup_by_name (cfp, "*foo")) != CTF_ERR)
41     {
42       fprintf (stderr, "Type lookup unexpectedly succeeded: %s\n", ctf_errmsg (ctf_errno (cfp)));
43       exit (1);
44     }
45 
46   if ((type = ctf_lookup_by_name (cfp, "foo *")) == CTF_ERR)
47     {
48       fprintf (stderr, "Type lookup error: %s\n", ctf_errmsg (ctf_errno (cfp)));
49       exit (1);
50     }
51 
52   ctf_dict_close (cfp);
53   ctf_dict_close (pfp);
54 
55   printf ("Type lookup succeeded.\n");
56 
57   return 0;
58 
59  create_err:
60   fprintf (stderr, "Creation failed: %s\n", ctf_errmsg (err));
61   exit (1);
62  create_parent:
63   fprintf (stderr, "Cannot create parent type: %s\n", ctf_errmsg (ctf_errno (pfp)));
64   exit (1);
65  create_child:
66   fprintf (stderr, "Cannot create child type: %s\n", ctf_errmsg (ctf_errno (cfp)));
67   exit (1);
68 }
69