xref: /dflybsd-src/contrib/gdb-7/libiberty/simple-object.txh (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
1*86d7f5d3SJohn Marino@c -*- mode: texinfo -*-
2*86d7f5d3SJohn Marino@deftypefn Extension {simple_object_read *} simple_object_open_read @
3*86d7f5d3SJohn Marino  (int @var{descriptor}, off_t @var{offset}, const char *{segment_name}, @
4*86d7f5d3SJohn Marino  const char **@var{errmsg}, int *@var{err})
5*86d7f5d3SJohn Marino
6*86d7f5d3SJohn MarinoOpens an object file for reading.  Creates and returns an
7*86d7f5d3SJohn Marino@code{simple_object_read} pointer which may be passed to other
8*86d7f5d3SJohn Marinofunctions to extract data from the object file.
9*86d7f5d3SJohn Marino
10*86d7f5d3SJohn Marino@var{descriptor} holds a file descriptor which permits reading.
11*86d7f5d3SJohn Marino
12*86d7f5d3SJohn Marino@var{offset} is the offset into the file; this will be @code{0} in the
13*86d7f5d3SJohn Marinonormal case, but may be a different value when reading an object file
14*86d7f5d3SJohn Marinoin an archive file.
15*86d7f5d3SJohn Marino
16*86d7f5d3SJohn Marino@var{segment_name} is only used with the Mach-O file format used on
17*86d7f5d3SJohn MarinoDarwin aka Mac OS X.  It is required on that platform, and means to
18*86d7f5d3SJohn Marinoonly look at sections within the segment with that name.  The
19*86d7f5d3SJohn Marinoparameter is ignored on other systems.
20*86d7f5d3SJohn Marino
21*86d7f5d3SJohn MarinoIf an error occurs, this functions returns @code{NULL} and sets
22*86d7f5d3SJohn Marino@code{*@var{errmsg}} to an error string and sets @code{*@var{err}} to
23*86d7f5d3SJohn Marinoan errno value or @code{0} if there is no relevant errno.
24*86d7f5d3SJohn Marino
25*86d7f5d3SJohn Marino@end deftypefn
26*86d7f5d3SJohn Marino
27*86d7f5d3SJohn Marino@deftypefn Extension {const char *} simple_object_find_sections @
28*86d7f5d3SJohn Marino  (simple_object_read *@var{simple_object}, int (*@var{pfn}) (void *@var{data}, @
29*86d7f5d3SJohn Marino  const char *@var{name}, off_t @var{offset}, off_t @var{length}), @
30*86d7f5d3SJohn Marino  void *@var{data}, int *@var{err})
31*86d7f5d3SJohn Marino
32*86d7f5d3SJohn MarinoThis function calls @var{pfn} for each section in @var{simple_object}.
33*86d7f5d3SJohn MarinoIt calls @var{pfn} with the section name, the offset within the file
34*86d7f5d3SJohn Marinoof the section contents, and the length of the section contents.  The
35*86d7f5d3SJohn Marinooffset within the file is relative to the offset passed to
36*86d7f5d3SJohn Marino@code{simple_object_open_read}.  The @var{data} argument to this
37*86d7f5d3SJohn Marinofunction is passed along to @var{pfn}.
38*86d7f5d3SJohn Marino
39*86d7f5d3SJohn MarinoIf @var{pfn} returns @code{0}, the loop over the sections stops and
40*86d7f5d3SJohn Marino@code{simple_object_find_sections} returns.  If @var{pfn} returns some
41*86d7f5d3SJohn Marinoother value, the loop continues.
42*86d7f5d3SJohn Marino
43*86d7f5d3SJohn MarinoOn success @code{simple_object_find_sections} returns.  On error it
44*86d7f5d3SJohn Marinoreturns an error string, and sets @code{*@var{err}} to an errno value
45*86d7f5d3SJohn Marinoor @code{0} if there is no relevant errno.
46*86d7f5d3SJohn Marino
47*86d7f5d3SJohn Marino@end deftypefn
48*86d7f5d3SJohn Marino
49*86d7f5d3SJohn Marino@deftypefn Extension {int} simple_object_find_section @
50*86d7f5d3SJohn Marino  (simple_object_read *@var{simple_object} off_t *@var{offset}, @
51*86d7f5d3SJohn Marino  off_t *@var{length}, const char **@var{errmsg}, int *@var{err})
52*86d7f5d3SJohn Marino
53*86d7f5d3SJohn MarinoLook for the section @var{name} in @var{simple_object}.  This returns
54*86d7f5d3SJohn Marinoinformation for the first section with that name.
55*86d7f5d3SJohn Marino
56*86d7f5d3SJohn MarinoIf found, return 1 and set @code{*@var{offset}} to the offset in the
57*86d7f5d3SJohn Marinofile of the section contents and set @code{*@var{length}} to the
58*86d7f5d3SJohn Marinolength of the section contents.  The value in @code{*@var{offset}}
59*86d7f5d3SJohn Marinowill be relative to the offset passed to
60*86d7f5d3SJohn Marino@code{simple_object_open_read}.
61*86d7f5d3SJohn Marino
62*86d7f5d3SJohn MarinoIf the section is not found, and no error occurs,
63*86d7f5d3SJohn Marino@code{simple_object_find_section} returns @code{0} and set
64*86d7f5d3SJohn Marino@code{*@var{errmsg}} to @code{NULL}.
65*86d7f5d3SJohn Marino
66*86d7f5d3SJohn MarinoIf an error occurs, @code{simple_object_find_section} returns
67*86d7f5d3SJohn Marino@code{0}, sets @code{*@var{errmsg}} to an error message, and sets
68*86d7f5d3SJohn Marino@code{*@var{err}} to an errno value or @code{0} if there is no
69*86d7f5d3SJohn Marinorelevant errno.
70*86d7f5d3SJohn Marino
71*86d7f5d3SJohn Marino@end deftypefn
72*86d7f5d3SJohn Marino
73*86d7f5d3SJohn Marino@deftypefn Extension {void} simple_object_release_read @
74*86d7f5d3SJohn Marino  (simple_object_read *@var{simple_object})
75*86d7f5d3SJohn Marino
76*86d7f5d3SJohn MarinoRelease all resources associated with @var{simple_object}.  This does
77*86d7f5d3SJohn Marinonot close the file descriptor.
78*86d7f5d3SJohn Marino
79*86d7f5d3SJohn Marino@end deftypefn
80*86d7f5d3SJohn Marino
81*86d7f5d3SJohn Marino@deftypefn Extension {simple_object_attributes *} simple_object_fetch_attributes @
82*86d7f5d3SJohn Marino  (simple_object_read *@var{simple_object}, const char **@var{errmsg}, int *@var{err})
83*86d7f5d3SJohn Marino
84*86d7f5d3SJohn MarinoFetch the attributes of @var{simple_object}.  The attributes are
85*86d7f5d3SJohn Marinointernal information such as the format of the object file, or the
86*86d7f5d3SJohn Marinoarchitecture it was compiled for.  This information will persist until
87*86d7f5d3SJohn Marino@code{simple_object_attributes_release} is called, even if
88*86d7f5d3SJohn Marino@var{simple_object} itself is released.
89*86d7f5d3SJohn Marino
90*86d7f5d3SJohn MarinoOn error this returns @code{NULL}, sets @code{*@var{errmsg}} to an
91*86d7f5d3SJohn Marinoerror message, and sets @code{*@var{err}} to an errno value or
92*86d7f5d3SJohn Marino@code{0} if there is no relevant errno.
93*86d7f5d3SJohn Marino
94*86d7f5d3SJohn Marino@end deftypefn
95*86d7f5d3SJohn Marino
96*86d7f5d3SJohn Marino@deftypefn Extension {const char *} simple_object_attributes_compare @
97*86d7f5d3SJohn Marino  (simple_object_attributes *@var{attrs1}, simple_object_attributes *@var{attrs2}, @
98*86d7f5d3SJohn Marino   int *@var{err})
99*86d7f5d3SJohn Marino
100*86d7f5d3SJohn MarinoCompare @var{attrs1} and @var{attrs2}.  If they could be linked
101*86d7f5d3SJohn Marinotogether without error, return @code{NULL}.  Otherwise, return an
102*86d7f5d3SJohn Marinoerror message and set @code{*@var{err}} to an errno value or @code{0}
103*86d7f5d3SJohn Marinoif there is no relevant errno.
104*86d7f5d3SJohn Marino
105*86d7f5d3SJohn Marino@end deftypefn
106*86d7f5d3SJohn Marino
107*86d7f5d3SJohn Marino@deftypefn Extension {void} simple_object_release_attributes @
108*86d7f5d3SJohn Marino  (simple_object_attributes *@var{attrs})
109*86d7f5d3SJohn Marino
110*86d7f5d3SJohn MarinoRelease all resources associated with @var{attrs}.
111*86d7f5d3SJohn Marino
112*86d7f5d3SJohn Marino@end deftypefn
113*86d7f5d3SJohn Marino
114*86d7f5d3SJohn Marino@deftypefn Extension {simple_object_write *} simple_object_start_write @
115*86d7f5d3SJohn Marino  (simple_object_attributes @var{attrs}, const char *@var{segment_name}, @
116*86d7f5d3SJohn Marino  const char **@var{errmsg}, int *@var{err})
117*86d7f5d3SJohn Marino
118*86d7f5d3SJohn MarinoStart creating a new object file using the object file format
119*86d7f5d3SJohn Marinodescribed in @var{attrs}.  You must fetch attribute information from
120*86d7f5d3SJohn Marinoan existing object file before you can create a new one.  There is
121*86d7f5d3SJohn Marinocurrently no support for creating an object file de novo.
122*86d7f5d3SJohn Marino
123*86d7f5d3SJohn Marino@var{segment_name} is only used with Mach-O as found on Darwin aka Mac
124*86d7f5d3SJohn MarinoOS X.  The parameter is required on that target.  It means that all
125*86d7f5d3SJohn Marinosections are created within the named segment.  It is ignored for
126*86d7f5d3SJohn Marinoother object file formats.
127*86d7f5d3SJohn Marino
128*86d7f5d3SJohn MarinoOn error @code{simple_object_start_write} returns @code{NULL}, sets
129*86d7f5d3SJohn Marino@code{*@var{ERRMSG}} to an error message, and sets @code{*@var{err}}
130*86d7f5d3SJohn Marinoto an errno value or @code{0} if there is no relevant errno.
131*86d7f5d3SJohn Marino
132*86d7f5d3SJohn Marino@end deftypefn
133*86d7f5d3SJohn Marino
134*86d7f5d3SJohn Marino@deftypefn Extension {simple_object_write_section *} simple_object_write_create_section @
135*86d7f5d3SJohn Marino  (simple_object_write *@var{simple_object}, const char *@var{name}, @
136*86d7f5d3SJohn Marino  unsigned int @var{align}, const char **@var{errmsg}, int *@var{err})
137*86d7f5d3SJohn Marino
138*86d7f5d3SJohn MarinoAdd a section to @var{simple_object}.  @var{name} is the name of the
139*86d7f5d3SJohn Marinonew section.  @var{align} is the required alignment expressed as the
140*86d7f5d3SJohn Marinonumber of required low-order 0 bits (e.g., 2 for alignment to a 32-bit
141*86d7f5d3SJohn Marinoboundary).
142*86d7f5d3SJohn Marino
143*86d7f5d3SJohn MarinoThe section is created as containing data, readable, not writable, not
144*86d7f5d3SJohn Marinoexecutable, not loaded at runtime.  The section is not written to the
145*86d7f5d3SJohn Marinofile until @code{simple_object_write_to_file} is called.
146*86d7f5d3SJohn Marino
147*86d7f5d3SJohn MarinoOn error this returns @code{NULL}, sets @code{*@var{errmsg}} to an
148*86d7f5d3SJohn Marinoerror message, and sets @code{*@var{err}} to an errno value or
149*86d7f5d3SJohn Marino@code{0} if there is no relevant errno.
150*86d7f5d3SJohn Marino
151*86d7f5d3SJohn Marino@end deftypefn
152*86d7f5d3SJohn Marino
153*86d7f5d3SJohn Marino@deftypefn Extension {const char *} simple_object_write_add_data @
154*86d7f5d3SJohn Marino  (simple_object_write *@var{simple_object}, @
155*86d7f5d3SJohn Marino  simple_object_write_section *@var{section}, const void *@var{buffer}, @
156*86d7f5d3SJohn Marino  size_t @var{size}, int @var{copy}, int *@var{err})
157*86d7f5d3SJohn Marino
158*86d7f5d3SJohn MarinoAdd data @var{buffer}/@var{size} to @var{section} in
159*86d7f5d3SJohn Marino@var{simple_object}.  If @var{copy} is non-zero, the data will be
160*86d7f5d3SJohn Marinocopied into memory if necessary.  If @var{copy} is zero, @var{buffer}
161*86d7f5d3SJohn Marinomust persist until @code{simple_object_write_to_file} is called.  is
162*86d7f5d3SJohn Marinoreleased.
163*86d7f5d3SJohn Marino
164*86d7f5d3SJohn MarinoOn success this returns @code{NULL}.  On error this returns an error
165*86d7f5d3SJohn Marinomessage, and sets @code{*@var{err}} to an errno value or 0 if there is
166*86d7f5d3SJohn Marinono relevant erro.
167*86d7f5d3SJohn Marino
168*86d7f5d3SJohn Marino@end deftypefn
169*86d7f5d3SJohn Marino
170*86d7f5d3SJohn Marino@deftypefn Extension {const char *} simple_object_write_to_file @
171*86d7f5d3SJohn Marino  (simple_object_write *@var{simple_object}, int @var{descriptor}, int *@var{err})
172*86d7f5d3SJohn Marino
173*86d7f5d3SJohn MarinoWrite the complete object file to @var{descriptor}, an open file
174*86d7f5d3SJohn Marinodescriptor.  This writes out all the data accumulated by calls to
175*86d7f5d3SJohn Marino@code{simple_object_write_create_section} and
176*86d7f5d3SJohn Marino@var{simple_object_write_add_data}.
177*86d7f5d3SJohn Marino
178*86d7f5d3SJohn MarinoThis returns @code{NULL} on success.  On error this returns an error
179*86d7f5d3SJohn Marinomessage and sets @code{*@var{err}} to an errno value or @code{0} if
180*86d7f5d3SJohn Marinothere is no relevant errno.
181*86d7f5d3SJohn Marino
182*86d7f5d3SJohn Marino@end deftypefn
183*86d7f5d3SJohn Marino
184*86d7f5d3SJohn Marino@deftypefn Extension {void} simple_object_release_write @
185*86d7f5d3SJohn Marino  (simple_object_write *@var{simple_object})
186*86d7f5d3SJohn Marino
187*86d7f5d3SJohn MarinoRelease all resources associated with @var{simple_object}.
188*86d7f5d3SJohn Marino
189*86d7f5d3SJohn Marino@end deftypefn
190