1*6881a400Schristos #include <ctf-api.h> 2*6881a400Schristos #include <stdio.h> 3*6881a400Schristos #include <stdlib.h> 4*6881a400Schristos #include <string.h> 5*6881a400Schristos 6*6881a400Schristos int 7*6881a400Schristos main (int argc, char *argv[]) 8*6881a400Schristos { 9*6881a400Schristos ctf_dict_t *fp; 10*6881a400Schristos ctf_archive_t *ctf; 11*6881a400Schristos ctf_id_t foo_type, bar_type, sym_type; 12*6881a400Schristos int found_foo = 0, found_bar = 0; 13*6881a400Schristos ctf_next_t *i = NULL; 14*6881a400Schristos const char *name; 15*6881a400Schristos int err; 16*6881a400Schristos 17*6881a400Schristos if (argc != 2) 18*6881a400Schristos { 19*6881a400Schristos fprintf (stderr, "Syntax: %s PROGRAM\n", argv[0]); 20*6881a400Schristos exit(1); 21*6881a400Schristos } 22*6881a400Schristos 23*6881a400Schristos if ((ctf = ctf_open (argv[1], NULL, &err)) == NULL) 24*6881a400Schristos goto open_err; 25*6881a400Schristos 26*6881a400Schristos if ((fp = ctf_dict_open (ctf, NULL, &err)) == NULL) 27*6881a400Schristos goto open_err; 28*6881a400Schristos 29*6881a400Schristos /* Make sure we can look up only 'foo' as a variable: bar, being nonstatic, 30*6881a400Schristos should have been erased. */ 31*6881a400Schristos 32*6881a400Schristos if ((foo_type = ctf_lookup_variable (fp, "foo")) == CTF_ERR) 33*6881a400Schristos printf ("Cannot look up foo: %s\n", ctf_errmsg (ctf_errno (fp))); 34*6881a400Schristos else 35*6881a400Schristos printf ("foo is of type %lx\n", foo_type); 36*6881a400Schristos 37*6881a400Schristos if ((bar_type = ctf_lookup_variable (fp, "bar")) == CTF_ERR) 38*6881a400Schristos printf ("Cannot look up bar: %s\n", ctf_errmsg (ctf_errno (fp))); 39*6881a400Schristos else 40*6881a400Schristos printf ("bar is of type %lx\n", bar_type); 41*6881a400Schristos 42*6881a400Schristos /* Traverse the entire data object section and make sure it contains an entry 43*6881a400Schristos for bar alone. (This is pure laziness: the section is small and 44*6881a400Schristos ctf_lookup_by_symbol_name does not yet exist.) */ 45*6881a400Schristos while ((sym_type = ctf_symbol_next (fp, &i, &name, 0)) != CTF_ERR) 46*6881a400Schristos { 47*6881a400Schristos if (!name) 48*6881a400Schristos continue; 49*6881a400Schristos 50*6881a400Schristos if (strcmp (name, "foo") == 0) 51*6881a400Schristos { 52*6881a400Schristos found_foo = 1; 53*6881a400Schristos printf ("Found foo in data object section with type %lx, " 54*6881a400Schristos "but it is static\n", sym_type); 55*6881a400Schristos } 56*6881a400Schristos if (strcmp (name, "bar") == 0) 57*6881a400Schristos found_bar = 1; 58*6881a400Schristos } 59*6881a400Schristos if (ctf_errno (fp) != ECTF_NEXT_END) 60*6881a400Schristos fprintf (stderr, "Unexpected error iterating over symbols: %s\n", 61*6881a400Schristos ctf_errmsg (ctf_errno (fp))); 62*6881a400Schristos 63*6881a400Schristos if (!found_foo) 64*6881a400Schristos printf ("foo missing from the data object section\n"); 65*6881a400Schristos if (!found_bar) 66*6881a400Schristos printf ("bar missing from the data object section\n"); 67*6881a400Schristos 68*6881a400Schristos ctf_dict_close (fp); 69*6881a400Schristos ctf_close (ctf); 70*6881a400Schristos 71*6881a400Schristos return 0; 72*6881a400Schristos 73*6881a400Schristos open_err: 74*6881a400Schristos fprintf (stderr, "%s: cannot open: %s\n", argv[0], ctf_errmsg (err)); 75*6881a400Schristos return 1; 76*6881a400Schristos } 77