1 #include <ctf-api.h> 2 #include <stdio.h> 3 #include <stdlib.h> 4 5 int 6 main (int argc, char *argv[]) 7 { 8 ctf_dict_t *fp; 9 ctf_archive_t *ctf; 10 ctf_id_t type; 11 char *type_name; 12 ctf_membinfo_t mi; 13 int err; 14 15 if (argc != 2) 16 { 17 fprintf (stderr, "Syntax: %s PROGRAM\n", argv[0]); 18 exit(1); 19 } 20 21 if ((ctf = ctf_open (argv[1], NULL, &err)) == NULL) 22 goto open_err; 23 if ((fp = ctf_dict_open (ctf, NULL, &err)) == NULL) 24 goto open_err; 25 26 /* Dig out some strucutre members by name. */ 27 28 if ((type = ctf_lookup_by_name (fp, "struct foo_t") ) == CTF_ERR) 29 goto err; 30 31 if (ctf_member_info (fp, type, "baz", &mi) < 0) 32 goto err; 33 34 type_name = ctf_type_aname (fp, mi.ctm_type); 35 printf ("baz is of type %s, at offset %lx\n", type_name, mi.ctm_offset); 36 free (type_name); 37 38 if (ctf_member_info (fp, type, "one_more_level", &mi) < 0) 39 goto err; 40 41 type_name = ctf_type_aname (fp, mi.ctm_type); 42 printf ("one_more_level is of type %s, at offset %lx\n", type_name, mi.ctm_offset); 43 free (type_name); 44 45 if (ctf_member_info (fp, type, "should_not_appear", &mi) >= 0 46 || ctf_errno (fp) != ECTF_NOMEMBNAM) 47 fprintf (stderr, "should_not_appear appeared.\n"); 48 49 ctf_dict_close (fp); 50 ctf_close (ctf); 51 52 return 0; 53 54 open_err: 55 fprintf (stderr, "%s: cannot open: %s\n", argv[0], ctf_errmsg (err)); 56 return 1; 57 err: 58 fprintf (stderr, "Lookup failed: %s\n", ctf_errmsg (ctf_errno (fp))); 59 return 1; 60 } 61