VirtualBox

source: vbox/trunk/src/VBox/ExtPacks/VBoxDTrace/onnv/common/ctf/ctf_labels.c@ 53657

Last change on this file since 53657 was 53657, checked in by vboxsync, 10 years ago

VBoxDTrace: CTF compiles and links. (r33)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 2002-2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#ifndef VBOX
28#pragma ident "%Z%%M% %I% %E% SMI"
29#endif
30
31#include <ctf_impl.h>
32
33static int
34extract_label_info(ctf_file_t *fp, const ctf_lblent_t **ctl, uint_t *num_labels)
35{
36 const ctf_header_t *h;
37
38 /*
39 * Labels are only supported in V2 or later
40 */
41 if (fp->ctf_version < CTF_VERSION_2)
42 return (ctf_set_errno(fp, ECTF_NOTSUP));
43
44 h = (const ctf_header_t *)fp->ctf_data.cts_data;
45
46 /* LINTED - pointer alignment */
47 *ctl = (const ctf_lblent_t *)(fp->ctf_buf + h->cth_lbloff);
48 *num_labels = (h->cth_objtoff - h->cth_lbloff) / sizeof (ctf_lblent_t);
49
50 return (0);
51}
52
53/*
54 * Returns the topmost label, or NULL if any errors are encountered
55 */
56const char *
57ctf_label_topmost(ctf_file_t *fp)
58{
59 const ctf_lblent_t *ctlp;
60 const char *s;
61 uint_t num_labels;
62
63 if (extract_label_info(fp, &ctlp, &num_labels) == CTF_ERR)
64 return (NULL); /* errno is set */
65
66 if (num_labels == 0) {
67 (void) ctf_set_errno(fp, ECTF_NOLABELDATA);
68 return (NULL);
69 }
70
71 if ((s = ctf_strraw(fp, (ctlp + num_labels - 1)->ctl_label)) == NULL)
72 (void) ctf_set_errno(fp, ECTF_CORRUPT);
73
74 return (s);
75}
76
77/*
78 * Iterate over all labels. We pass the label string and the lblinfo_t struct
79 * to the specified callback function.
80 */
81int
82ctf_label_iter(ctf_file_t *fp, ctf_label_f *func, void *arg)
83{
84 const ctf_lblent_t *ctlp;
85 uint_t i, num_labels;
86 ctf_lblinfo_t linfo;
87 const char *lname;
88 int rc;
89
90 if (extract_label_info(fp, &ctlp, &num_labels) == CTF_ERR)
91 return (CTF_ERR); /* errno is set */
92
93 if (num_labels == 0)
94 return (ctf_set_errno(fp, ECTF_NOLABELDATA));
95
96 for (i = 0; i < num_labels; i++, ctlp++) {
97 if ((lname = ctf_strraw(fp, ctlp->ctl_label)) == NULL) {
98 ctf_dprintf("failed to decode label %u with "
99 "typeidx %u\n", ctlp->ctl_label, ctlp->ctl_typeidx);
100 return (ctf_set_errno(fp, ECTF_CORRUPT));
101 }
102
103 linfo.ctb_typeidx = ctlp->ctl_typeidx;
104 if ((rc = func(lname, &linfo, arg)) != 0)
105 return (rc);
106 }
107
108 return (0);
109}
110
111typedef struct linfo_cb_arg {
112 const char *lca_name; /* Label we want to retrieve info for */
113 ctf_lblinfo_t *lca_info; /* Where to store the info about the label */
114} linfo_cb_arg_t;
115
116static int
117label_info_cb(const char *lname, const ctf_lblinfo_t *linfo, void *arg)
118{
119 /*
120 * If lname matches the label we are looking for, copy the
121 * lblinfo_t struct for the caller.
122 */
123 if (strcmp(lname, ((linfo_cb_arg_t *)arg)->lca_name) == 0) {
124 /*
125 * Allow caller not to allocate storage to test if label exists
126 */
127 if (((linfo_cb_arg_t *)arg)->lca_info != NULL)
128 bcopy(linfo, ((linfo_cb_arg_t *)arg)->lca_info,
129 sizeof (ctf_lblinfo_t));
130 return (1); /* Indicate we found a match */
131 }
132
133 return (0);
134}
135
136/*
137 * Retrieve information about the label with name "lname"
138 */
139int
140ctf_label_info(ctf_file_t *fp, const char *lname, ctf_lblinfo_t *linfo)
141{
142 linfo_cb_arg_t cb_arg;
143 int rc;
144
145 cb_arg.lca_name = lname;
146 cb_arg.lca_info = linfo;
147
148 if ((rc = ctf_label_iter(fp, label_info_cb, &cb_arg)) == CTF_ERR)
149 return (rc);
150
151 if (rc != 1)
152 return (ctf_set_errno(fp, ECTF_NOLABEL));
153
154 return (0);
155}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette