]>
Commit | Line | Data |
---|---|---|
bccafa26 | 1 | /* Output Dwarf format symbol table information from GCC. |
07576557 | 2 | Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
3 | 2002, 2003 Free Software Foundation, Inc. | |
7bfbda1f | 4 | Contributed by Ron Guilmette (rfg@monkeys.com) of Network Computing Devices. |
2554c338 | 5 | |
f12b58b3 | 6 | This file is part of GCC. |
e8363d4c | 7 | |
f12b58b3 | 8 | GCC is free software; you can redistribute it and/or modify it under |
9 | the terms of the GNU General Public License as published by the Free | |
10 | Software Foundation; either version 2, or (at your option) any later | |
11 | version. | |
e8363d4c | 12 | |
f12b58b3 | 13 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 | for more details. | |
e8363d4c | 17 | |
18 | You should have received a copy of the GNU General Public License | |
f12b58b3 | 19 | along with GCC; see the file COPYING. If not, write to the Free |
20 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
21 | 02111-1307, USA. */ | |
e8363d4c | 22 | |
546d24e9 | 23 | /* |
24 | ||
25 | Notes on the GNU Implementation of DWARF Debugging Information | |
26 | -------------------------------------------------------------- | |
27 | Last Major Update: Sun Jul 17 08:17:42 PDT 1994 by rfg@segfault.us.com | |
28 | ------------------------------------------------------------ | |
29 | ||
30 | This file describes special and unique aspects of the GNU implementation of | |
31 | the DWARF Version 1 debugging information language, as provided in the GNU | |
32 | version 2.x compiler(s). | |
33 | ||
34 | For general information about the DWARF debugging information language, | |
35 | you should obtain the DWARF version 1.1 specification document (and perhaps | |
36 | also the DWARF version 2 draft specification document) developed by the | |
37 | (now defunct) UNIX International Programming Languages Special Interest Group. | |
38 | ||
39 | To obtain a copy of the DWARF Version 1 and/or DWARF Version 2 | |
40 | specification, visit the web page for the DWARF Version 2 committee, at | |
41 | ||
42 | http://www.eagercon.com/dwarf/dwarf2std.htm | |
43 | ||
44 | The generation of DWARF debugging information by the GNU version 2.x C | |
45 | compiler has now been tested rather extensively for m88k, i386, i860, and | |
7800959d | 46 | SPARC targets. The DWARF output of the GNU C compiler appears to inter- |
546d24e9 | 47 | operate well with the standard SVR4 SDB debugger on these kinds of target |
48 | systems (but of course, there are no guarantees). | |
49 | ||
50 | DWARF 1 generation for the GNU g++ compiler is implemented, but limited. | |
51 | C++ users should definitely use DWARF 2 instead. | |
52 | ||
53 | Future plans for the dwarfout.c module of the GNU compiler(s) includes the | |
54 | addition of full support for GNU FORTRAN. (This should, in theory, be a | |
55 | lot simpler to add than adding support for g++... but we'll see.) | |
56 | ||
57 | Many features of the DWARF version 2 specification have been adapted to | |
58 | (and used in) the GNU implementation of DWARF (version 1). In most of | |
59 | these cases, a DWARF version 2 approach is used in place of (or in addition | |
60 | to) DWARF version 1 stuff simply because it is apparent that DWARF version | |
61 | 1 is not sufficiently expressive to provide the kinds of information which | |
62 | may be necessary to support really robust debugging. In all of these cases | |
63 | however, the use of DWARF version 2 features should not interfere in any | |
64 | way with the interoperability (of GNU compilers) with generally available | |
65 | "classic" (pre version 1) DWARF consumer tools (e.g. SVR4 SDB). | |
66 | ||
67 | The DWARF generation enhancement for the GNU compiler(s) was initially | |
68 | donated to the Free Software Foundation by Network Computing Devices. | |
69 | (Thanks NCD!) Additional development and maintenance of dwarfout.c has | |
70 | been largely supported (i.e. funded) by Intel Corporation. (Thanks Intel!) | |
71 | ||
72 | If you have questions or comments about the DWARF generation feature, please | |
73 | send mail to me <rfg@netcom.com>. I will be happy to investigate any bugs | |
74 | reported and I may even provide fixes (but of course, I can make no promises). | |
75 | ||
76 | The DWARF debugging information produced by GCC may deviate in a few minor | |
77 | (but perhaps significant) respects from the DWARF debugging information | |
78 | currently produced by other C compilers. A serious attempt has been made | |
79 | however to conform to the published specifications, to existing practice, | |
80 | and to generally accepted norms in the GNU implementation of DWARF. | |
81 | ||
82 | ** IMPORTANT NOTE ** ** IMPORTANT NOTE ** ** IMPORTANT NOTE ** | |
83 | ||
84 | Under normal circumstances, the DWARF information generated by the GNU | |
85 | compilers (in an assembly language file) is essentially impossible for | |
86 | a human being to read. This fact can make it very difficult to debug | |
87 | certain DWARF-related problems. In order to overcome this difficulty, | |
88 | a feature has been added to dwarfout.c (enabled by the -dA | |
89 | option) which causes additional comments to be placed into the assembly | |
90 | language output file, out to the right-hand side of most bits of DWARF | |
91 | material. The comments indicate (far more clearly that the obscure | |
92 | DWARF hex codes do) what is actually being encoded in DWARF. Thus, the | |
93 | -dA option can be highly useful for those who must study the | |
94 | DWARF output from the GNU compilers in detail. | |
95 | ||
96 | --------- | |
97 | ||
98 | (Footnote: Within this file, the term `Debugging Information Entry' will | |
99 | be abbreviated as `DIE'.) | |
100 | ||
101 | ||
102 | Release Notes (aka known bugs) | |
103 | ------------------------------- | |
104 | ||
105 | In one very obscure case involving dynamically sized arrays, the DWARF | |
106 | "location information" for such an array may make it appear that the | |
107 | array has been totally optimized out of existence, when in fact it | |
108 | *must* actually exist. (This only happens when you are using *both* -g | |
109 | *and* -O.) This is due to aggressive dead store elimination in the | |
110 | compiler, and to the fact that the DECL_RTL expressions associated with | |
111 | variables are not always updated to correctly reflect the effects of | |
112 | GCC's aggressive dead store elimination. | |
113 | ||
114 | ------------------------------- | |
115 | ||
116 | When attempting to set a breakpoint at the "start" of a function compiled | |
117 | with -g1, the debugger currently has no way of knowing exactly where the | |
118 | end of the prologue code for the function is. Thus, for most targets, | |
119 | all the debugger can do is to set the breakpoint at the AT_low_pc address | |
120 | for the function. But if you stop there and then try to look at one or | |
121 | more of the formal parameter values, they may not have been "homed" yet, | |
122 | so you may get inaccurate answers (or perhaps even addressing errors). | |
123 | ||
124 | Some people may consider this simply a non-feature, but I consider it a | |
125 | bug, and I hope to provide some GNU-specific attributes (on function | |
126 | DIEs) which will specify the address of the end of the prologue and the | |
127 | address of the beginning of the epilogue in a future release. | |
128 | ||
129 | ------------------------------- | |
130 | ||
131 | It is believed at this time that old bugs relating to the AT_bit_offset | |
132 | values for bit-fields have been fixed. | |
133 | ||
134 | There may still be some very obscure bugs relating to the DWARF description | |
135 | of type `long long' bit-fields for target machines (e.g. 80x86 machines) | |
136 | where the alignment of type `long long' data objects is different from | |
137 | (and less than) the size of a type `long long' data object. | |
138 | ||
139 | Please report any problems with the DWARF description of bit-fields as you | |
140 | would any other GCC bug. (Procedures for bug reporting are given in the | |
141 | GNU C compiler manual.) | |
142 | ||
143 | -------------------------------- | |
144 | ||
145 | At this time, GCC does not know how to handle the GNU C "nested functions" | |
146 | extension. (See the GCC manual for more info on this extension to ANSI C.) | |
147 | ||
148 | -------------------------------- | |
149 | ||
150 | The GNU compilers now represent inline functions (and inlined instances | |
151 | thereof) in exactly the manner described by the current DWARF version 2 | |
152 | (draft) specification. The version 1 specification for handling inline | |
153 | functions (and inlined instances) was known to be brain-damaged (by the | |
154 | PLSIG) when the version 1 spec was finalized, but it was simply too late | |
155 | in the cycle to get it removed before the version 1 spec was formally | |
156 | released to the public (by UI). | |
157 | ||
158 | -------------------------------- | |
159 | ||
160 | At this time, GCC does not generate the kind of really precise information | |
161 | about the exact declared types of entities with signed integral types which | |
162 | is required by the current DWARF draft specification. | |
163 | ||
164 | Specifically, the current DWARF draft specification seems to require that | |
edc2a478 | 165 | the type of a non-unsigned integral bit-field member of a struct or union |
546d24e9 | 166 | type be represented as either a "signed" type or as a "plain" type, |
167 | depending upon the exact set of keywords that were used in the | |
168 | type specification for the given bit-field member. It was felt (by the | |
169 | UI/PLSIG) that this distinction between "plain" and "signed" integral types | |
170 | could have some significance (in the case of bit-fields) because ANSI C | |
171 | does not constrain the signedness of a plain bit-field, whereas it does | |
172 | constrain the signedness of an explicitly "signed" bit-field. For this | |
173 | reason, the current DWARF specification calls for compilers to produce | |
174 | type information (for *all* integral typed entities... not just bit-fields) | |
175 | which explicitly indicates the signedness of the relevant type to be | |
176 | "signed" or "plain" or "unsigned". | |
177 | ||
178 | Unfortunately, the GNU DWARF implementation is currently incapable of making | |
179 | such distinctions. | |
180 | ||
181 | -------------------------------- | |
182 | ||
183 | ||
184 | Known Interoperability Problems | |
185 | ------------------------------- | |
186 | ||
187 | Although the GNU implementation of DWARF conforms (for the most part) with | |
188 | the current UI/PLSIG DWARF version 1 specification (with many compatible | |
189 | version 2 features added in as "vendor specific extensions" just for good | |
190 | measure) there are a few known cases where GCC's DWARF output can cause | |
191 | some confusion for "classic" (pre version 1) DWARF consumers such as the | |
192 | System V Release 4 SDB debugger. These cases are described in this section. | |
193 | ||
194 | -------------------------------- | |
195 | ||
196 | The DWARF version 1 specification includes the fundamental type codes | |
197 | FT_ext_prec_float, FT_complex, FT_dbl_prec_complex, and FT_ext_prec_complex. | |
198 | Since GNU C is only a C compiler (and since C doesn't provide any "complex" | |
199 | data types) the only one of these fundamental type codes which GCC ever | |
200 | generates is FT_ext_prec_float. This fundamental type code is generated | |
201 | by GCC for the `long double' data type. Unfortunately, due to an apparent | |
202 | bug in the SVR4 SDB debugger, SDB can become very confused wherever any | |
203 | attempt is made to print a variable, parameter, or field whose type was | |
204 | given in terms of FT_ext_prec_float. | |
205 | ||
206 | (Actually, SVR4 SDB fails to understand *any* of the four fundamental type | |
207 | codes mentioned here. This will fact will cause additional problems when | |
208 | there is a GNU FORTRAN front-end.) | |
209 | ||
210 | -------------------------------- | |
211 | ||
212 | In general, it appears that SVR4 SDB is not able to effectively ignore | |
213 | fundamental type codes in the "implementation defined" range. This can | |
214 | cause problems when a program being debugged uses the `long long' data | |
215 | type (or the signed or unsigned varieties thereof) because these types | |
216 | are not defined by ANSI C, and thus, GCC must use its own private fundamental | |
217 | type codes (from the implementation-defined range) to represent these types. | |
218 | ||
219 | -------------------------------- | |
220 | ||
221 | ||
222 | General GNU DWARF extensions | |
223 | ---------------------------- | |
224 | ||
225 | In the current DWARF version 1 specification, no mechanism is specified by | |
226 | which accurate information about executable code from include files can be | |
227 | properly (and fully) described. (The DWARF version 2 specification *does* | |
228 | specify such a mechanism, but it is about 10 times more complicated than | |
229 | it needs to be so I'm not terribly anxious to try to implement it right | |
230 | away.) | |
231 | ||
232 | In the GNU implementation of DWARF version 1, a fully downward-compatible | |
233 | extension has been implemented which permits the GNU compilers to specify | |
234 | which executable lines come from which files. This extension places | |
235 | additional information (about source file names) in GNU-specific sections | |
236 | (which should be totally ignored by all non-GNU DWARF consumers) so that | |
237 | this extended information can be provided (to GNU DWARF consumers) in a way | |
238 | which is totally transparent (and invisible) to non-GNU DWARF consumers | |
239 | (e.g. the SVR4 SDB debugger). The additional information is placed *only* | |
240 | in specialized GNU-specific sections, where it should never even be seen | |
241 | by non-GNU DWARF consumers. | |
242 | ||
243 | To understand this GNU DWARF extension, imagine that the sequence of entries | |
244 | in the .lines section is broken up into several subsections. Each contiguous | |
245 | sequence of .line entries which relates to a sequence of lines (or statements) | |
246 | from one particular file (either a `base' file or an `include' file) could | |
247 | be called a `line entries chunk' (LEC). | |
248 | ||
249 | For each LEC there is one entry in the .debug_srcinfo section. | |
250 | ||
251 | Each normal entry in the .debug_srcinfo section consists of two 4-byte | |
252 | words of data as follows: | |
253 | ||
254 | (1) The starting address (relative to the entire .line section) | |
255 | of the first .line entry in the relevant LEC. | |
256 | ||
257 | (2) The starting address (relative to the entire .debug_sfnames | |
258 | section) of a NUL terminated string representing the | |
259 | relevant filename. (This filename name be either a | |
260 | relative or an absolute filename, depending upon how the | |
261 | given source file was located during compilation.) | |
262 | ||
263 | Obviously, each .debug_srcinfo entry allows you to find the relevant filename, | |
264 | and it also points you to the first .line entry that was generated as a result | |
265 | of having compiled a given source line from the given source file. | |
266 | ||
267 | Each subsequent .line entry should also be assumed to have been produced | |
268 | as a result of compiling yet more lines from the same file. The end of | |
269 | any given LEC is easily found by looking at the first 4-byte pointer in | |
270 | the *next* .debug_srcinfo entry. That next .debug_srcinfo entry points | |
271 | to a new and different LEC, so the preceding LEC (implicitly) must have | |
272 | ended with the last .line section entry which occurs at the 2 1/2 words | |
273 | just before the address given in the first pointer of the new .debug_srcinfo | |
274 | entry. | |
275 | ||
276 | The following picture may help to clarify this feature. Let's assume that | |
277 | `LE' stands for `.line entry'. Also, assume that `* 'stands for a pointer. | |
278 | ||
279 | ||
280 | .line section .debug_srcinfo section .debug_sfnames section | |
281 | ---------------------------------------------------------------- | |
282 | ||
283 | LE <---------------------- * | |
284 | LE * -----------------> "foobar.c" <--- | |
285 | LE | | |
286 | LE | | |
287 | LE <---------------------- * | | |
288 | LE * -----------------> "foobar.h" <| | | |
289 | LE | | | |
290 | LE | | | |
291 | LE <---------------------- * | | | |
292 | LE * -----------------> "inner.h" | | | |
293 | LE | | | |
294 | LE <---------------------- * | | | |
295 | LE * ------------------------------- | | |
296 | LE | | |
297 | LE | | |
298 | LE | | |
299 | LE | | |
300 | LE <---------------------- * | | |
301 | LE * ----------------------------------- | |
302 | LE | |
303 | LE | |
304 | LE | |
305 | ||
306 | In effect, each entry in the .debug_srcinfo section points to *both* a | |
307 | filename (in the .debug_sfnames section) and to the start of a block of | |
308 | consecutive LEs (in the .line section). | |
309 | ||
310 | Note that just like in the .line section, there are specialized first and | |
311 | last entries in the .debug_srcinfo section for each object file. These | |
312 | special first and last entries for the .debug_srcinfo section are very | |
313 | different from the normal .debug_srcinfo section entries. They provide | |
314 | additional information which may be helpful to a debugger when it is | |
315 | interpreting the data in the .debug_srcinfo, .debug_sfnames, and .line | |
316 | sections. | |
317 | ||
318 | The first entry in the .debug_srcinfo section for each compilation unit | |
319 | consists of five 4-byte words of data. The contents of these five words | |
320 | should be interpreted (by debuggers) as follows: | |
321 | ||
322 | (1) The starting address (relative to the entire .line section) | |
323 | of the .line section for this compilation unit. | |
324 | ||
325 | (2) The starting address (relative to the entire .debug_sfnames | |
326 | section) of the .debug_sfnames section for this compilation | |
327 | unit. | |
328 | ||
329 | (3) The starting address (in the execution virtual address space) | |
330 | of the .text section for this compilation unit. | |
331 | ||
332 | (4) The ending address plus one (in the execution virtual address | |
333 | space) of the .text section for this compilation unit. | |
334 | ||
335 | (5) The date/time (in seconds since midnight 1/1/70) at which the | |
336 | compilation of this compilation unit occurred. This value | |
337 | should be interpreted as an unsigned quantity because gcc | |
338 | might be configured to generate a default value of 0xffffffff | |
339 | in this field (in cases where it is desired to have object | |
340 | files created at different times from identical source files | |
341 | be byte-for-byte identical). By default, these timestamps | |
342 | are *not* generated by dwarfout.c (so that object files | |
343 | compiled at different times will be byte-for-byte identical). | |
344 | If you wish to enable this "timestamp" feature however, you | |
345 | can simply place a #define for the symbol `DWARF_TIMESTAMPS' | |
346 | in your target configuration file and then rebuild the GNU | |
347 | compiler(s). | |
348 | ||
349 | Note that the first string placed into the .debug_sfnames section for each | |
350 | compilation unit is the name of the directory in which compilation occurred. | |
351 | This string ends with a `/' (to help indicate that it is the pathname of a | |
352 | directory). Thus, the second word of each specialized initial .debug_srcinfo | |
353 | entry for each compilation unit may be used as a pointer to the (string) | |
354 | name of the compilation directory, and that string may in turn be used to | |
355 | "absolutize" any relative pathnames which may appear later on in the | |
356 | .debug_sfnames section entries for the same compilation unit. | |
357 | ||
358 | The fifth and last word of each specialized starting entry for a compilation | |
359 | unit in the .debug_srcinfo section may (depending upon your configuration) | |
360 | indicate the date/time of compilation, and this may be used (by a debugger) | |
361 | to determine if any of the source files which contributed code to this | |
362 | compilation unit are newer than the object code for the compilation unit | |
363 | itself. If so, the debugger may wish to print an "out-of-date" warning | |
364 | about the compilation unit. | |
365 | ||
366 | The .debug_srcinfo section associated with each compilation will also have | |
367 | a specialized terminating entry. This terminating .debug_srcinfo section | |
368 | entry will consist of the following two 4-byte words of data: | |
369 | ||
370 | (1) The offset, measured from the start of the .line section to | |
371 | the beginning of the terminating entry for the .line section. | |
372 | ||
373 | (2) A word containing the value 0xffffffff. | |
374 | ||
375 | -------------------------------- | |
376 | ||
377 | In the current DWARF version 1 specification, no mechanism is specified by | |
378 | which information about macro definitions and un-definitions may be provided | |
379 | to the DWARF consumer. | |
380 | ||
381 | The DWARF version 2 (draft) specification does specify such a mechanism. | |
382 | That specification was based on the GNU ("vendor specific extension") | |
383 | which provided some support for macro definitions and un-definitions, | |
384 | but the "official" DWARF version 2 (draft) specification mechanism for | |
385 | handling macros and the GNU implementation have diverged somewhat. I | |
386 | plan to update the GNU implementation to conform to the "official" | |
387 | DWARF version 2 (draft) specification as soon as I get time to do that. | |
388 | ||
389 | Note that in the GNU implementation, additional information about macro | |
390 | definitions and un-definitions is *only* provided when the -g3 level of | |
391 | debug-info production is selected. (The default level is -g2 and the | |
392 | plain old -g option is considered to be identical to -g2.) | |
393 | ||
394 | GCC records information about macro definitions and undefinitions primarily | |
395 | in a section called the .debug_macinfo section. Normal entries in the | |
396 | .debug_macinfo section consist of the following three parts: | |
397 | ||
398 | (1) A special "type" byte. | |
399 | ||
400 | (2) A 3-byte line-number/filename-offset field. | |
401 | ||
402 | (3) A NUL terminated string. | |
403 | ||
404 | The interpretation of the second and third parts is dependent upon the | |
405 | value of the leading (type) byte. | |
406 | ||
407 | The type byte may have one of four values depending upon the type of the | |
408 | .debug_macinfo entry which follows. The 1-byte MACINFO type codes presently | |
409 | used, and their meanings are as follows: | |
410 | ||
411 | MACINFO_start A base file or an include file starts here. | |
412 | MACINFO_resume The current base or include file ends here. | |
413 | MACINFO_define A #define directive occurs here. | |
414 | MACINFO_undef A #undef directive occur here. | |
415 | ||
416 | (Note that the MACINFO_... codes mentioned here are simply symbolic names | |
417 | for constants which are defined in the GNU dwarf.h file.) | |
418 | ||
419 | For MACINFO_define and MACINFO_undef entries, the second (3-byte) field | |
420 | contains the number of the source line (relative to the start of the current | |
421 | base source file or the current include files) when the #define or #undef | |
422 | directive appears. For a MACINFO_define entry, the following string field | |
423 | contains the name of the macro which is defined, followed by its definition. | |
424 | Note that the definition is always separated from the name of the macro | |
425 | by at least one whitespace character. For a MACINFO_undef entry, the | |
426 | string which follows the 3-byte line number field contains just the name | |
427 | of the macro which is being undef'ed. | |
428 | ||
429 | For a MACINFO_start entry, the 3-byte field following the type byte contains | |
430 | the offset, relative to the start of the .debug_sfnames section for the | |
431 | current compilation unit, of a string which names the new source file which | |
432 | is beginning its inclusion at this point. Following that 3-byte field, | |
433 | each MACINFO_start entry always contains a zero length NUL terminated | |
434 | string. | |
435 | ||
436 | For a MACINFO_resume entry, the 3-byte field following the type byte contains | |
437 | the line number WITHIN THE INCLUDING FILE at which the inclusion of the | |
438 | current file (whose inclusion ends here) was initiated. Following that | |
439 | 3-byte field, each MACINFO_resume entry always contains a zero length NUL | |
440 | terminated string. | |
441 | ||
442 | Each set of .debug_macinfo entries for each compilation unit is terminated | |
443 | by a special .debug_macinfo entry consisting of a 4-byte zero value followed | |
444 | by a single NUL byte. | |
445 | ||
446 | -------------------------------- | |
447 | ||
448 | In the current DWARF draft specification, no provision is made for providing | |
449 | a separate level of (limited) debugging information necessary to support | |
450 | tracebacks (only) through fully-debugged code (e.g. code in system libraries). | |
451 | ||
452 | A proposal to define such a level was submitted (by me) to the UI/PLSIG. | |
453 | This proposal was rejected by the UI/PLSIG for inclusion into the DWARF | |
454 | version 1 specification for two reasons. First, it was felt (by the PLSIG) | |
455 | that the issues involved in supporting a "traceback only" subset of DWARF | |
456 | were not well understood. Second, and perhaps more importantly, the PLSIG | |
457 | is already having enough trouble agreeing on what it means to be "conforming" | |
458 | to the DWARF specification, and it was felt that trying to specify multiple | |
459 | different *levels* of conformance would only complicate our discussions of | |
460 | this already divisive issue. Nonetheless, the GNU implementation of DWARF | |
461 | provides an abbreviated "traceback only" level of debug-info production for | |
462 | use with fully-debugged "system library" code. This level should only be | |
463 | used for fully debugged system library code, and even then, it should only | |
464 | be used where there is a very strong need to conserve disk space. This | |
465 | abbreviated level of debug-info production can be used by specifying the | |
466 | -g1 option on the compilation command line. | |
467 | ||
468 | -------------------------------- | |
469 | ||
470 | As mentioned above, the GNU implementation of DWARF currently uses the DWARF | |
471 | version 2 (draft) approach for inline functions (and inlined instances | |
472 | thereof). This is used in preference to the version 1 approach because | |
473 | (quite simply) the version 1 approach is highly brain-damaged and probably | |
474 | unworkable. | |
475 | ||
476 | -------------------------------- | |
477 | ||
478 | ||
479 | GNU DWARF Representation of GNU C Extensions to ANSI C | |
480 | ------------------------------------------------------ | |
481 | ||
482 | The file dwarfout.c has been designed and implemented so as to provide | |
483 | some reasonable DWARF representation for each and every declarative | |
484 | construct which is accepted by the GNU C compiler. Since the GNU C | |
485 | compiler accepts a superset of ANSI C, this means that there are some | |
486 | cases in which the DWARF information produced by GCC must take some | |
487 | liberties in improvising DWARF representations for declarations which | |
488 | are only valid in (extended) GNU C. | |
489 | ||
490 | In particular, GNU C provides at least three significant extensions to | |
491 | ANSI C when it comes to declarations. These are (1) inline functions, | |
492 | and (2) dynamic arrays, and (3) incomplete enum types. (See the GCC | |
493 | manual for more information on these GNU extensions to ANSI C.) When | |
494 | used, these GNU C extensions are represented (in the generated DWARF | |
495 | output of GCC) in the most natural and intuitively obvious ways. | |
496 | ||
497 | In the case of inline functions, the DWARF representation is exactly as | |
498 | called for in the DWARF version 2 (draft) specification for an identical | |
499 | function written in C++; i.e. we "reuse" the representation of inline | |
500 | functions which has been defined for C++ to support this GNU C extension. | |
501 | ||
502 | In the case of dynamic arrays, we use the most obvious representational | |
503 | mechanism available; i.e. an array type in which the upper bound of | |
504 | some dimension (usually the first and only dimension) is a variable | |
505 | rather than a constant. (See the DWARF version 1 specification for more | |
506 | details.) | |
507 | ||
508 | In the case of incomplete enum types, such types are represented simply | |
509 | as TAG_enumeration_type DIEs which DO NOT contain either AT_byte_size | |
510 | attributes or AT_element_list attributes. | |
511 | ||
512 | -------------------------------- | |
513 | ||
514 | ||
515 | Future Directions | |
516 | ----------------- | |
517 | ||
518 | The codes, formats, and other paraphernalia necessary to provide proper | |
519 | support for symbolic debugging for the C++ language are still being worked | |
520 | on by the UI/PLSIG. The vast majority of the additions to DWARF which will | |
521 | be needed to completely support C++ have already been hashed out and agreed | |
522 | upon, but a few small issues (e.g. anonymous unions, access declarations) | |
523 | are still being discussed. Also, we in the PLSIG are still discussing | |
524 | whether or not we need to do anything special for C++ templates. (At this | |
525 | time it is not yet clear whether we even need to do anything special for | |
1eefe280 | 526 | these.) |
546d24e9 | 527 | |
528 | With regard to FORTRAN, the UI/PLSIG has defined what is believed to be a | |
529 | complete and sufficient set of codes and rules for adequately representing | |
530 | all of FORTRAN 77, and most of Fortran 90 in DWARF. While some support for | |
531 | this has been implemented in dwarfout.c, further implementation and testing | |
532 | is needed. | |
533 | ||
534 | GNU DWARF support for other languages (i.e. Pascal and Modula) is a moot | |
535 | issue until there are GNU front-ends for these other languages. | |
536 | ||
537 | As currently defined, DWARF only describes a (binary) language which can | |
538 | be used to communicate symbolic debugging information from a compiler | |
539 | through an assembler and a linker, to a debugger. There is no clear | |
540 | specification of what processing should be (or must be) done by the | |
541 | assembler and/or the linker. Fortunately, the role of the assembler | |
542 | is easily inferred (by anyone knowledgeable about assemblers) just by | |
543 | looking at examples of assembly-level DWARF code. Sadly though, the | |
544 | allowable (or required) processing steps performed by a linker are | |
545 | harder to infer and (perhaps) even harder to agree upon. There are | |
546 | several forms of very useful `post-processing' steps which intelligent | |
547 | linkers *could* (in theory) perform on object files containing DWARF, | |
548 | but any and all such link-time transformations are currently both disallowed | |
549 | and unspecified. | |
550 | ||
551 | In particular, possible link-time transformations of DWARF code which could | |
552 | provide significant benefits include (but are not limited to): | |
553 | ||
554 | Commonization of duplicate DIEs obtained from multiple input | |
555 | (object) files. | |
556 | ||
557 | Cross-compilation type checking based upon DWARF type information | |
558 | for objects and functions. | |
559 | ||
560 | Other possible `compacting' transformations designed to save disk | |
561 | space and to reduce linker & debugger I/O activity. | |
562 | ||
1eefe280 | 563 | */ |
546d24e9 | 564 | |
e8363d4c | 565 | #include "config.h" |
805e22b2 | 566 | #include "system.h" |
567 | #include "coretypes.h" | |
568 | #include "tm.h" | |
e8363d4c | 569 | |
be6eb971 | 570 | #ifdef DWARF_DEBUGGING_INFO |
e8363d4c | 571 | #include "dwarf.h" |
572 | #include "tree.h" | |
573 | #include "flags.h" | |
a6ff766a | 574 | #include "function.h" |
e8363d4c | 575 | #include "rtl.h" |
017ffcef | 576 | #include "hard-reg-set.h" |
e8363d4c | 577 | #include "insn-config.h" |
578 | #include "reload.h" | |
579 | #include "output.h" | |
58356836 | 580 | #include "dwarf2asm.h" |
0268b6e3 | 581 | #include "toplev.h" |
c5b89159 | 582 | #include "tm_p.h" |
b896d81b | 583 | #include "debug.h" |
07576557 | 584 | #include "target.h" |
d19bd1f0 | 585 | #include "langhooks.h" |
e8363d4c | 586 | |
e8363d4c | 587 | /* NOTE: In the comments in this file, many references are made to |
588 | so called "Debugging Information Entries". For the sake of brevity, | |
589 | this term is abbreviated to `DIE' throughout the remainder of this | |
590 | file. */ | |
591 | ||
592 | /* Note that the implementation of C++ support herein is (as yet) unfinished. | |
593 | If you want to try to complete it, more power to you. */ | |
594 | ||
e8363d4c | 595 | /* How to start an assembler comment. */ |
596 | #ifndef ASM_COMMENT_START | |
597 | #define ASM_COMMENT_START ";#" | |
598 | #endif | |
599 | ||
017ffcef | 600 | /* How to print out a register name. */ |
601 | #ifndef PRINT_REG | |
602 | #define PRINT_REG(RTX, CODE, FILE) \ | |
603 | fprintf ((FILE), "%s", reg_names[REGNO (RTX)]) | |
604 | #endif | |
605 | ||
6ef828f9 | 606 | /* Define a macro which returns nonzero for any tagged type which is |
e8363d4c | 607 | used (directly or indirectly) in the specification of either some |
608 | function's return type or some formal parameter of some function. | |
609 | We use this macro when we are operating in "terse" mode to help us | |
610 | know what tagged types have to be represented in Dwarf (even in | |
611 | terse mode) and which ones don't. | |
612 | ||
613 | A flag bit with this meaning really should be a part of the normal | |
614 | GCC ..._TYPE nodes, but at the moment, there is no such bit defined | |
615 | for these nodes. For now, we have to just fake it. It it safe for | |
616 | us to simply return zero for all complete tagged types (which will | |
617 | get forced out anyway if they were used in the specification of some | |
6ef828f9 | 618 | formal or return type) and nonzero for all incomplete tagged types. |
e8363d4c | 619 | */ |
620 | ||
621 | #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0) | |
622 | ||
6ef828f9 | 623 | /* Define a macro which returns nonzero for a TYPE_DECL which was |
6efd403b | 624 | implicitly generated for a tagged type. |
625 | ||
626 | Note that unlike the gcc front end (which generates a NULL named | |
627 | TYPE_DECL node for each complete tagged type, each array type, and | |
628 | each function type node created) the g++ front end generates a | |
629 | _named_ TYPE_DECL node for each tagged type node created. | |
630 | These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to | |
631 | generate a DW_TAG_typedef DIE for them. */ | |
632 | #define TYPE_DECL_IS_STUB(decl) \ | |
633 | (DECL_NAME (decl) == NULL \ | |
634 | || (DECL_ARTIFICIAL (decl) \ | |
635 | && is_tagged_type (TREE_TYPE (decl)) \ | |
636 | && decl == TYPE_STUB_DECL (TREE_TYPE (decl)))) | |
637 | ||
e8363d4c | 638 | /* Maximum size (in bytes) of an artificially generated label. */ |
639 | ||
640 | #define MAX_ARTIFICIAL_LABEL_BYTES 30 | |
641 | \f | |
e8363d4c | 642 | /* Structure to keep track of source filenames. */ |
643 | ||
644 | struct filename_entry { | |
645 | unsigned number; | |
1e034a40 | 646 | const char * name; |
e8363d4c | 647 | }; |
648 | ||
649 | typedef struct filename_entry filename_entry; | |
650 | ||
a92771b8 | 651 | /* Pointer to an array of elements, each one having the structure above. */ |
e8363d4c | 652 | |
653 | static filename_entry *filename_table; | |
654 | ||
655 | /* Total number of entries in the table (i.e. array) pointed to by | |
656 | `filename_table'. This is the *total* and includes both used and | |
657 | unused slots. */ | |
658 | ||
659 | static unsigned ft_entries_allocated; | |
660 | ||
661 | /* Number of entries in the filename_table which are actually in use. */ | |
662 | ||
663 | static unsigned ft_entries; | |
664 | ||
665 | /* Size (in elements) of increments by which we may expand the filename | |
666 | table. Actually, a single hunk of space of this size should be enough | |
667 | for most typical programs. */ | |
668 | ||
669 | #define FT_ENTRIES_INCREMENT 64 | |
670 | ||
671 | /* Local pointer to the name of the main input file. Initialized in | |
672 | dwarfout_init. */ | |
673 | ||
1e034a40 | 674 | static const char *primary_filename; |
e8363d4c | 675 | |
a92771b8 | 676 | /* Counter to generate unique names for DIEs. */ |
e8363d4c | 677 | |
678 | static unsigned next_unused_dienum = 1; | |
679 | ||
680 | /* Number of the DIE which is currently being generated. */ | |
681 | ||
682 | static unsigned current_dienum; | |
683 | ||
684 | /* Number to use for the special "pubname" label on the next DIE which | |
685 | represents a function or data object defined in this compilation | |
686 | unit which has "extern" linkage. */ | |
687 | ||
07e64d6e | 688 | static int next_pubname_number = 0; |
e8363d4c | 689 | |
690 | #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1] | |
691 | ||
692 | /* Pointer to a dynamically allocated list of pre-reserved and still | |
693 | pending sibling DIE numbers. Note that this list will grow as needed. */ | |
694 | ||
695 | static unsigned *pending_sibling_stack; | |
696 | ||
697 | /* Counter to keep track of the number of pre-reserved and still pending | |
698 | sibling DIE numbers. */ | |
699 | ||
700 | static unsigned pending_siblings; | |
701 | ||
702 | /* The currently allocated size of the above list (expressed in number of | |
703 | list elements). */ | |
704 | ||
705 | static unsigned pending_siblings_allocated; | |
706 | ||
707 | /* Size (in elements) of increments by which we may expand the pending | |
708 | sibling stack. Actually, a single hunk of space of this size should | |
709 | be enough for most typical programs. */ | |
710 | ||
711 | #define PENDING_SIBLINGS_INCREMENT 64 | |
712 | ||
6ef828f9 | 713 | /* Nonzero if we are performing our file-scope finalization pass and if |
4bbea254 | 714 | we should force out Dwarf descriptions of any and all file-scope |
e8363d4c | 715 | tagged types which are still incomplete types. */ |
716 | ||
717 | static int finalizing = 0; | |
718 | ||
719 | /* A pointer to the base of a list of pending types which we haven't | |
720 | generated DIEs for yet, but which we will have to come back to | |
721 | later on. */ | |
722 | ||
723 | static tree *pending_types_list; | |
724 | ||
725 | /* Number of elements currently allocated for the pending_types_list. */ | |
726 | ||
727 | static unsigned pending_types_allocated; | |
728 | ||
729 | /* Number of elements of pending_types_list currently in use. */ | |
730 | ||
731 | static unsigned pending_types; | |
732 | ||
733 | /* Size (in elements) of increments by which we may expand the pending | |
734 | types list. Actually, a single hunk of space of this size should | |
735 | be enough for most typical programs. */ | |
736 | ||
737 | #define PENDING_TYPES_INCREMENT 64 | |
738 | ||
568cb337 | 739 | /* A pointer to the base of a list of incomplete types which might be |
740 | completed at some later time. */ | |
741 | ||
742 | static tree *incomplete_types_list; | |
743 | ||
744 | /* Number of elements currently allocated for the incomplete_types_list. */ | |
745 | static unsigned incomplete_types_allocated; | |
746 | ||
747 | /* Number of elements of incomplete_types_list currently in use. */ | |
748 | static unsigned incomplete_types; | |
749 | ||
750 | /* Size (in elements) of increments by which we may expand the incomplete | |
751 | types list. Actually, a single hunk of space of this size should | |
752 | be enough for most typical programs. */ | |
753 | #define INCOMPLETE_TYPES_INCREMENT 64 | |
754 | ||
4bbea254 | 755 | /* Pointer to an artificial RECORD_TYPE which we create in dwarfout_init. |
e8363d4c | 756 | This is used in a hack to help us get the DIEs describing types of |
757 | formal parameters to come *after* all of the DIEs describing the formal | |
758 | parameters themselves. That's necessary in order to be compatible | |
4bbea254 | 759 | with what the brain-damaged svr4 SDB debugger requires. */ |
e8363d4c | 760 | |
761 | static tree fake_containing_scope; | |
762 | ||
017ffcef | 763 | /* A pointer to the ..._DECL node which we have most recently been working |
764 | on. We keep this around just in case something about it looks screwy | |
765 | and we want to tell the user what the source coordinates for the actual | |
766 | declaration are. */ | |
767 | ||
768 | static tree dwarf_last_decl; | |
769 | ||
6efd403b | 770 | /* A flag indicating that we are emitting the member declarations of a |
771 | class, so member functions and variables should not be entirely emitted. | |
772 | This is a kludge to avoid passing a second argument to output_*_die. */ | |
773 | ||
774 | static int in_class; | |
775 | ||
e8363d4c | 776 | /* Forward declarations for functions defined in this file. */ |
777 | ||
8ec3a57b | 778 | static void dwarfout_init (const char *); |
779 | static void dwarfout_finish (const char *); | |
780 | static void dwarfout_define (unsigned int, const char *); | |
781 | static void dwarfout_undef (unsigned int, const char *); | |
782 | static void dwarfout_start_source_file (unsigned, const char *); | |
783 | static void dwarfout_start_source_file_check (unsigned, const char *); | |
784 | static void dwarfout_end_source_file (unsigned); | |
785 | static void dwarfout_end_source_file_check (unsigned); | |
786 | static void dwarfout_begin_block (unsigned, unsigned); | |
787 | static void dwarfout_end_block (unsigned, unsigned); | |
788 | static void dwarfout_end_epilogue (unsigned int, const char *); | |
789 | static void dwarfout_source_line (unsigned int, const char *); | |
790 | static void dwarfout_end_prologue (unsigned int, const char *); | |
791 | static void dwarfout_end_function (unsigned int); | |
792 | static void dwarfout_function_decl (tree); | |
793 | static void dwarfout_global_decl (tree); | |
794 | static void dwarfout_deferred_inline_function (tree); | |
795 | static void dwarfout_file_scope_decl (tree , int); | |
796 | static const char *dwarf_tag_name (unsigned); | |
797 | static const char *dwarf_attr_name (unsigned); | |
798 | static const char *dwarf_stack_op_name (unsigned); | |
799 | static const char *dwarf_typemod_name (unsigned); | |
800 | static const char *dwarf_fmt_byte_name (unsigned); | |
801 | static const char *dwarf_fund_type_name (unsigned); | |
802 | static tree decl_ultimate_origin (tree); | |
803 | static tree block_ultimate_origin (tree); | |
804 | static tree decl_class_context (tree); | |
0e93a6ac | 805 | #if 0 |
8ec3a57b | 806 | static void output_unsigned_leb128 (unsigned long); |
807 | static void output_signed_leb128 (long); | |
0e93a6ac | 808 | #endif |
8ec3a57b | 809 | static int fundamental_type_code (tree); |
810 | static tree root_type_1 (tree, int); | |
811 | static tree root_type (tree); | |
812 | static void write_modifier_bytes_1 (tree, int, int, int); | |
813 | static void write_modifier_bytes (tree, int, int); | |
814 | static inline int type_is_fundamental (tree); | |
815 | static void equate_decl_number_to_die_number (tree); | |
816 | static inline void equate_type_number_to_die_number (tree); | |
817 | static void output_reg_number (rtx); | |
818 | static void output_mem_loc_descriptor (rtx); | |
819 | static void output_loc_descriptor (rtx); | |
820 | static void output_bound_representation (tree, unsigned, char); | |
821 | static void output_enumeral_list (tree); | |
822 | static inline HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int); | |
823 | static inline tree field_type (tree); | |
824 | static inline unsigned int simple_type_align_in_bits (tree); | |
825 | static inline unsigned HOST_WIDE_INT simple_type_size_in_bits (tree); | |
826 | static HOST_WIDE_INT field_byte_offset (tree); | |
827 | static inline void sibling_attribute (void); | |
828 | static void location_attribute (rtx); | |
829 | static void data_member_location_attribute (tree); | |
830 | static void const_value_attribute (rtx); | |
831 | static void location_or_const_value_attribute (tree); | |
832 | static inline void name_attribute (const char *); | |
833 | static inline void fund_type_attribute (unsigned); | |
834 | static void mod_fund_type_attribute (tree, int, int); | |
835 | static inline void user_def_type_attribute (tree); | |
836 | static void mod_u_d_type_attribute (tree, int, int); | |
07e64d6e | 837 | #ifdef USE_ORDERING_ATTRIBUTE |
8ec3a57b | 838 | static inline void ordering_attribute (unsigned); |
07e64d6e | 839 | #endif /* defined(USE_ORDERING_ATTRIBUTE) */ |
8ec3a57b | 840 | static void subscript_data_attribute (tree); |
841 | static void byte_size_attribute (tree); | |
842 | static inline void bit_offset_attribute (tree); | |
843 | static inline void bit_size_attribute (tree); | |
844 | static inline void element_list_attribute (tree); | |
845 | static inline void stmt_list_attribute (const char *); | |
846 | static inline void low_pc_attribute (const char *); | |
847 | static inline void high_pc_attribute (const char *); | |
848 | static inline void body_begin_attribute (const char *); | |
849 | static inline void body_end_attribute (const char *); | |
850 | static inline void language_attribute (unsigned); | |
851 | static inline void member_attribute (tree); | |
cb264b86 | 852 | #if 0 |
8ec3a57b | 853 | static inline void string_length_attribute (tree); |
cb264b86 | 854 | #endif |
8ec3a57b | 855 | static inline void comp_dir_attribute (const char *); |
856 | static inline void sf_names_attribute (const char *); | |
857 | static inline void src_info_attribute (const char *); | |
858 | static inline void mac_info_attribute (const char *); | |
859 | static inline void prototyped_attribute (tree); | |
860 | static inline void producer_attribute (const char *); | |
861 | static inline void inline_attribute (tree); | |
862 | static inline void containing_type_attribute (tree); | |
863 | static inline void abstract_origin_attribute (tree); | |
07e64d6e | 864 | #ifdef DWARF_DECL_COORDINATES |
8ec3a57b | 865 | static inline void src_coords_attribute (unsigned, unsigned); |
07e64d6e | 866 | #endif /* defined(DWARF_DECL_COORDINATES) */ |
8ec3a57b | 867 | static inline void pure_or_virtual_attribute (tree); |
868 | static void name_and_src_coords_attributes (tree); | |
869 | static void type_attribute (tree, int, int); | |
870 | static const char *type_tag (tree); | |
871 | static inline void dienum_push (void); | |
872 | static inline void dienum_pop (void); | |
873 | static inline tree member_declared_type (tree); | |
874 | static const char *function_start_label (tree); | |
875 | static void output_array_type_die (void *); | |
876 | static void output_set_type_die (void *); | |
07e64d6e | 877 | #if 0 |
8ec3a57b | 878 | static void output_entry_point_die (void *); |
07e64d6e | 879 | #endif |
8ec3a57b | 880 | static void output_inlined_enumeration_type_die (void *); |
881 | static void output_inlined_structure_type_die (void *); | |
882 | static void output_inlined_union_type_die (void *); | |
883 | static void output_enumeration_type_die (void *); | |
884 | static void output_formal_parameter_die (void *); | |
885 | static void output_global_subroutine_die (void *); | |
886 | static void output_global_variable_die (void *); | |
887 | static void output_label_die (void *); | |
888 | static void output_lexical_block_die (void *); | |
889 | static void output_inlined_subroutine_die (void *); | |
890 | static void output_local_variable_die (void *); | |
891 | static void output_member_die (void *); | |
07e64d6e | 892 | #if 0 |
8ec3a57b | 893 | static void output_pointer_type_die (void *); |
894 | static void output_reference_type_die (void *); | |
07e64d6e | 895 | #endif |
8ec3a57b | 896 | static void output_ptr_to_mbr_type_die (void *); |
897 | static void output_compile_unit_die (void *); | |
898 | static void output_string_type_die (void *); | |
899 | static void output_inheritance_die (void *); | |
900 | static void output_structure_type_die (void *); | |
901 | static void output_local_subroutine_die (void *); | |
902 | static void output_subroutine_type_die (void *); | |
903 | static void output_typedef_die (void *); | |
904 | static void output_union_type_die (void *); | |
905 | static void output_unspecified_parameters_die (void *); | |
906 | static void output_padded_null_die (void *); | |
907 | static void output_die (void (*)(void *), void *); | |
908 | static void end_sibling_chain (void); | |
909 | static void output_formal_types (tree); | |
910 | static void pend_type (tree); | |
911 | static int type_ok_for_scope (tree, tree); | |
912 | static void output_pending_types_for_scope (tree); | |
913 | static void output_type (tree, tree); | |
914 | static void output_tagged_type_instantiation (tree); | |
915 | static void output_block (tree, int); | |
916 | static void output_decls_for_scope (tree, int); | |
917 | static void output_decl (tree, tree); | |
918 | static void shuffle_filename_entry (filename_entry *); | |
919 | static void generate_new_sfname_entry (void); | |
920 | static unsigned lookup_filename (const char *); | |
921 | static void generate_srcinfo_entry (unsigned, unsigned); | |
922 | static void generate_macinfo_entry (unsigned int, rtx, const char *); | |
923 | static int is_pseudo_reg (rtx); | |
924 | static tree type_main_variant (tree); | |
925 | static int is_tagged_type (tree); | |
926 | static int is_redundant_typedef (tree); | |
927 | static void add_incomplete_type (tree); | |
928 | static void retry_incomplete_types (void); | |
e8363d4c | 929 | \f |
930 | /* Definitions of defaults for assembler-dependent names of various | |
931 | pseudo-ops and section names. | |
932 | ||
933 | Theses may be overridden in your tm.h file (if necessary) for your | |
934 | particular assembler. The default values provided here correspond to | |
935 | what is expected by "standard" AT&T System V.4 assemblers. */ | |
936 | ||
937 | #ifndef FILE_ASM_OP | |
6ae8577b | 938 | #define FILE_ASM_OP "\t.file\t" |
e8363d4c | 939 | #endif |
bad5b016 | 940 | #ifndef SET_ASM_OP |
6ae8577b | 941 | #define SET_ASM_OP "\t.set\t" |
e8363d4c | 942 | #endif |
23535a0a | 943 | |
944 | /* Pseudo-ops for pushing the current section onto the section stack (and | |
945 | simultaneously changing to a new section) and for poping back to the | |
946 | section we were in immediately before this one. Note that most svr4 | |
947 | assemblers only maintain a one level stack... you can push all the | |
948 | sections you want, but you can only pop out one level. (The sparc | |
bad5b016 | 949 | svr4 assembler is an exception to this general rule.) That's |
23535a0a | 950 | OK because we only use at most one level of the section stack herein. */ |
951 | ||
952 | #ifndef PUSHSECTION_ASM_OP | |
6ae8577b | 953 | #define PUSHSECTION_ASM_OP "\t.section\t" |
23535a0a | 954 | #endif |
955 | #ifndef POPSECTION_ASM_OP | |
6ae8577b | 956 | #define POPSECTION_ASM_OP "\t.previous" |
23535a0a | 957 | #endif |
958 | ||
959 | /* The default format used by the ASM_OUTPUT_PUSH_SECTION macro (see below) | |
960 | to print the PUSHSECTION_ASM_OP and the section name. The default here | |
961 | works for almost all svr4 assemblers, except for the sparc, where the | |
962 | section name must be enclosed in double quotes. (See sparcv4.h.) */ | |
963 | ||
964 | #ifndef PUSHSECTION_FORMAT | |
17d8e118 | 965 | #define PUSHSECTION_FORMAT "%s%s\n" |
23535a0a | 966 | #endif |
967 | ||
968 | #ifndef DEBUG_SECTION | |
969 | #define DEBUG_SECTION ".debug" | |
970 | #endif | |
971 | #ifndef LINE_SECTION | |
972 | #define LINE_SECTION ".line" | |
973 | #endif | |
049aa99b | 974 | #ifndef DEBUG_SFNAMES_SECTION |
975 | #define DEBUG_SFNAMES_SECTION ".debug_sfnames" | |
23535a0a | 976 | #endif |
049aa99b | 977 | #ifndef DEBUG_SRCINFO_SECTION |
978 | #define DEBUG_SRCINFO_SECTION ".debug_srcinfo" | |
23535a0a | 979 | #endif |
049aa99b | 980 | #ifndef DEBUG_MACINFO_SECTION |
981 | #define DEBUG_MACINFO_SECTION ".debug_macinfo" | |
23535a0a | 982 | #endif |
049aa99b | 983 | #ifndef DEBUG_PUBNAMES_SECTION |
984 | #define DEBUG_PUBNAMES_SECTION ".debug_pubnames" | |
23535a0a | 985 | #endif |
049aa99b | 986 | #ifndef DEBUG_ARANGES_SECTION |
987 | #define DEBUG_ARANGES_SECTION ".debug_aranges" | |
23535a0a | 988 | #endif |
25e5d448 | 989 | #ifndef TEXT_SECTION_NAME |
990 | #define TEXT_SECTION_NAME ".text" | |
23535a0a | 991 | #endif |
25e5d448 | 992 | #ifndef DATA_SECTION_NAME |
993 | #define DATA_SECTION_NAME ".data" | |
23535a0a | 994 | #endif |
25e5d448 | 995 | #ifndef DATA1_SECTION_NAME |
996 | #define DATA1_SECTION_NAME ".data1" | |
23535a0a | 997 | #endif |
25e5d448 | 998 | #ifndef RODATA_SECTION_NAME |
999 | #define RODATA_SECTION_NAME ".rodata" | |
23535a0a | 1000 | #endif |
25e5d448 | 1001 | #ifndef RODATA1_SECTION_NAME |
1002 | #define RODATA1_SECTION_NAME ".rodata1" | |
23535a0a | 1003 | #endif |
25e5d448 | 1004 | #ifndef BSS_SECTION_NAME |
1005 | #define BSS_SECTION_NAME ".bss" | |
23535a0a | 1006 | #endif |
e8363d4c | 1007 | \f |
1008 | /* Definitions of defaults for formats and names of various special | |
1009 | (artificial) labels which may be generated within this file (when | |
1010 | the -g options is used and DWARF_DEBUGGING_INFO is in effect. | |
1011 | ||
1012 | If necessary, these may be overridden from within your tm.h file, | |
88ef61d1 | 1013 | but typically, you should never need to override these. |
1014 | ||
1015 | These labels have been hacked (temporarily) so that they all begin with | |
bad5b016 | 1016 | a `.L' sequence so as to appease the stock sparc/svr4 assembler and the |
1017 | stock m88k/svr4 assembler, both of which need to see .L at the start of | |
1018 | a label in order to prevent that label from going into the linker symbol | |
1019 | table). When I get time, I'll have to fix this the right way so that we | |
805e22b2 | 1020 | will use ASM_GENERATE_INTERNAL_LABEL and (*targetm.asm_out.internal_label) herein, |
bad5b016 | 1021 | but that will require a rather massive set of changes. For the moment, |
1022 | the following definitions out to produce the right results for all svr4 | |
1023 | and svr3 assemblers. -- rfg | |
88ef61d1 | 1024 | */ |
e8363d4c | 1025 | |
1026 | #ifndef TEXT_BEGIN_LABEL | |
0dbd1c74 | 1027 | #define TEXT_BEGIN_LABEL "*.L_text_b" |
e8363d4c | 1028 | #endif |
1029 | #ifndef TEXT_END_LABEL | |
0dbd1c74 | 1030 | #define TEXT_END_LABEL "*.L_text_e" |
e8363d4c | 1031 | #endif |
1032 | ||
1033 | #ifndef DATA_BEGIN_LABEL | |
0dbd1c74 | 1034 | #define DATA_BEGIN_LABEL "*.L_data_b" |
e8363d4c | 1035 | #endif |
1036 | #ifndef DATA_END_LABEL | |
0dbd1c74 | 1037 | #define DATA_END_LABEL "*.L_data_e" |
e8363d4c | 1038 | #endif |
1039 | ||
1040 | #ifndef DATA1_BEGIN_LABEL | |
0dbd1c74 | 1041 | #define DATA1_BEGIN_LABEL "*.L_data1_b" |
e8363d4c | 1042 | #endif |
1043 | #ifndef DATA1_END_LABEL | |
0dbd1c74 | 1044 | #define DATA1_END_LABEL "*.L_data1_e" |
e8363d4c | 1045 | #endif |
1046 | ||
1047 | #ifndef RODATA_BEGIN_LABEL | |
0dbd1c74 | 1048 | #define RODATA_BEGIN_LABEL "*.L_rodata_b" |
e8363d4c | 1049 | #endif |
1050 | #ifndef RODATA_END_LABEL | |
0dbd1c74 | 1051 | #define RODATA_END_LABEL "*.L_rodata_e" |
e8363d4c | 1052 | #endif |
1053 | ||
1054 | #ifndef RODATA1_BEGIN_LABEL | |
0dbd1c74 | 1055 | #define RODATA1_BEGIN_LABEL "*.L_rodata1_b" |
e8363d4c | 1056 | #endif |
1057 | #ifndef RODATA1_END_LABEL | |
0dbd1c74 | 1058 | #define RODATA1_END_LABEL "*.L_rodata1_e" |
e8363d4c | 1059 | #endif |
1060 | ||
1061 | #ifndef BSS_BEGIN_LABEL | |
0dbd1c74 | 1062 | #define BSS_BEGIN_LABEL "*.L_bss_b" |
e8363d4c | 1063 | #endif |
1064 | #ifndef BSS_END_LABEL | |
0dbd1c74 | 1065 | #define BSS_END_LABEL "*.L_bss_e" |
e8363d4c | 1066 | #endif |
1067 | ||
1068 | #ifndef LINE_BEGIN_LABEL | |
0dbd1c74 | 1069 | #define LINE_BEGIN_LABEL "*.L_line_b" |
e8363d4c | 1070 | #endif |
1071 | #ifndef LINE_LAST_ENTRY_LABEL | |
0dbd1c74 | 1072 | #define LINE_LAST_ENTRY_LABEL "*.L_line_last" |
e8363d4c | 1073 | #endif |
1074 | #ifndef LINE_END_LABEL | |
0dbd1c74 | 1075 | #define LINE_END_LABEL "*.L_line_e" |
e8363d4c | 1076 | #endif |
1077 | ||
1078 | #ifndef DEBUG_BEGIN_LABEL | |
0dbd1c74 | 1079 | #define DEBUG_BEGIN_LABEL "*.L_debug_b" |
e8363d4c | 1080 | #endif |
1081 | #ifndef SFNAMES_BEGIN_LABEL | |
0dbd1c74 | 1082 | #define SFNAMES_BEGIN_LABEL "*.L_sfnames_b" |
e8363d4c | 1083 | #endif |
1084 | #ifndef SRCINFO_BEGIN_LABEL | |
0dbd1c74 | 1085 | #define SRCINFO_BEGIN_LABEL "*.L_srcinfo_b" |
e8363d4c | 1086 | #endif |
1087 | #ifndef MACINFO_BEGIN_LABEL | |
0dbd1c74 | 1088 | #define MACINFO_BEGIN_LABEL "*.L_macinfo_b" |
e8363d4c | 1089 | #endif |
1090 | ||
0ebe8f79 | 1091 | #ifndef DEBUG_ARANGES_BEGIN_LABEL |
1092 | #define DEBUG_ARANGES_BEGIN_LABEL "*.L_debug_aranges_begin" | |
1093 | #endif | |
1094 | #ifndef DEBUG_ARANGES_END_LABEL | |
1095 | #define DEBUG_ARANGES_END_LABEL "*.L_debug_aranges_end" | |
1096 | #endif | |
1097 | ||
e8363d4c | 1098 | #ifndef DIE_BEGIN_LABEL_FMT |
0dbd1c74 | 1099 | #define DIE_BEGIN_LABEL_FMT "*.L_D%u" |
e8363d4c | 1100 | #endif |
1101 | #ifndef DIE_END_LABEL_FMT | |
0dbd1c74 | 1102 | #define DIE_END_LABEL_FMT "*.L_D%u_e" |
e8363d4c | 1103 | #endif |
1104 | #ifndef PUB_DIE_LABEL_FMT | |
0dbd1c74 | 1105 | #define PUB_DIE_LABEL_FMT "*.L_P%u" |
e8363d4c | 1106 | #endif |
e8363d4c | 1107 | #ifndef BLOCK_BEGIN_LABEL_FMT |
0dbd1c74 | 1108 | #define BLOCK_BEGIN_LABEL_FMT "*.L_B%u" |
e8363d4c | 1109 | #endif |
1110 | #ifndef BLOCK_END_LABEL_FMT | |
0dbd1c74 | 1111 | #define BLOCK_END_LABEL_FMT "*.L_B%u_e" |
e8363d4c | 1112 | #endif |
1113 | #ifndef SS_BEGIN_LABEL_FMT | |
0dbd1c74 | 1114 | #define SS_BEGIN_LABEL_FMT "*.L_s%u" |
e8363d4c | 1115 | #endif |
1116 | #ifndef SS_END_LABEL_FMT | |
0dbd1c74 | 1117 | #define SS_END_LABEL_FMT "*.L_s%u_e" |
e8363d4c | 1118 | #endif |
1119 | #ifndef EE_BEGIN_LABEL_FMT | |
0dbd1c74 | 1120 | #define EE_BEGIN_LABEL_FMT "*.L_e%u" |
e8363d4c | 1121 | #endif |
1122 | #ifndef EE_END_LABEL_FMT | |
0dbd1c74 | 1123 | #define EE_END_LABEL_FMT "*.L_e%u_e" |
e8363d4c | 1124 | #endif |
1125 | #ifndef MT_BEGIN_LABEL_FMT | |
0dbd1c74 | 1126 | #define MT_BEGIN_LABEL_FMT "*.L_t%u" |
e8363d4c | 1127 | #endif |
1128 | #ifndef MT_END_LABEL_FMT | |
0dbd1c74 | 1129 | #define MT_END_LABEL_FMT "*.L_t%u_e" |
e8363d4c | 1130 | #endif |
1131 | #ifndef LOC_BEGIN_LABEL_FMT | |
0dbd1c74 | 1132 | #define LOC_BEGIN_LABEL_FMT "*.L_l%u" |
e8363d4c | 1133 | #endif |
1134 | #ifndef LOC_END_LABEL_FMT | |
0dbd1c74 | 1135 | #define LOC_END_LABEL_FMT "*.L_l%u_e" |
e8363d4c | 1136 | #endif |
1137 | #ifndef BOUND_BEGIN_LABEL_FMT | |
0dbd1c74 | 1138 | #define BOUND_BEGIN_LABEL_FMT "*.L_b%u_%u_%c" |
e8363d4c | 1139 | #endif |
1140 | #ifndef BOUND_END_LABEL_FMT | |
0dbd1c74 | 1141 | #define BOUND_END_LABEL_FMT "*.L_b%u_%u_%c_e" |
e8363d4c | 1142 | #endif |
cf6a3b88 | 1143 | #ifndef BODY_BEGIN_LABEL_FMT |
0dbd1c74 | 1144 | #define BODY_BEGIN_LABEL_FMT "*.L_b%u" |
cf6a3b88 | 1145 | #endif |
1146 | #ifndef BODY_END_LABEL_FMT | |
0dbd1c74 | 1147 | #define BODY_END_LABEL_FMT "*.L_b%u_e" |
cf6a3b88 | 1148 | #endif |
e8363d4c | 1149 | #ifndef FUNC_END_LABEL_FMT |
0dbd1c74 | 1150 | #define FUNC_END_LABEL_FMT "*.L_f%u_e" |
e8363d4c | 1151 | #endif |
1152 | #ifndef TYPE_NAME_FMT | |
0dbd1c74 | 1153 | #define TYPE_NAME_FMT "*.L_T%u" |
e8363d4c | 1154 | #endif |
473cc96d | 1155 | #ifndef DECL_NAME_FMT |
0dbd1c74 | 1156 | #define DECL_NAME_FMT "*.L_E%u" |
473cc96d | 1157 | #endif |
e8363d4c | 1158 | #ifndef LINE_CODE_LABEL_FMT |
0dbd1c74 | 1159 | #define LINE_CODE_LABEL_FMT "*.L_LC%u" |
e8363d4c | 1160 | #endif |
1161 | #ifndef SFNAMES_ENTRY_LABEL_FMT | |
0dbd1c74 | 1162 | #define SFNAMES_ENTRY_LABEL_FMT "*.L_F%u" |
e8363d4c | 1163 | #endif |
1164 | #ifndef LINE_ENTRY_LABEL_FMT | |
0dbd1c74 | 1165 | #define LINE_ENTRY_LABEL_FMT "*.L_LE%u" |
e8363d4c | 1166 | #endif |
1167 | \f | |
1168 | /* Definitions of defaults for various types of primitive assembly language | |
1169 | output operations. | |
1170 | ||
1171 | If necessary, these may be overridden from within your tm.h file, | |
0a189cac | 1172 | but typically, you shouldn't need to override these. */ |
23535a0a | 1173 | |
1174 | #ifndef ASM_OUTPUT_PUSH_SECTION | |
1175 | #define ASM_OUTPUT_PUSH_SECTION(FILE, SECTION) \ | |
1176 | fprintf ((FILE), PUSHSECTION_FORMAT, PUSHSECTION_ASM_OP, SECTION) | |
1177 | #endif | |
1178 | ||
1179 | #ifndef ASM_OUTPUT_POP_SECTION | |
1180 | #define ASM_OUTPUT_POP_SECTION(FILE) \ | |
17d8e118 | 1181 | fprintf ((FILE), "%s\n", POPSECTION_ASM_OP) |
23535a0a | 1182 | #endif |
e8363d4c | 1183 | |
e8363d4c | 1184 | #ifndef ASM_OUTPUT_DWARF_DELTA2 |
1185 | #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \ | |
58356836 | 1186 | dw2_asm_output_delta (2, LABEL1, LABEL2, NULL) |
e8363d4c | 1187 | #endif |
1188 | ||
1189 | #ifndef ASM_OUTPUT_DWARF_DELTA4 | |
1190 | #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \ | |
58356836 | 1191 | dw2_asm_output_delta (4, LABEL1, LABEL2, NULL) |
e8363d4c | 1192 | #endif |
1193 | ||
1194 | #ifndef ASM_OUTPUT_DWARF_TAG | |
1195 | #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \ | |
58356836 | 1196 | dw2_asm_output_data (2, TAG, "%s", dwarf_tag_name (TAG)); |
e8363d4c | 1197 | #endif |
1198 | ||
1199 | #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE | |
88ef61d1 | 1200 | #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTR) \ |
58356836 | 1201 | dw2_asm_output_data (2, ATTR, "%s", dwarf_attr_name (ATTR)) |
e8363d4c | 1202 | #endif |
1203 | ||
1204 | #ifndef ASM_OUTPUT_DWARF_STACK_OP | |
1205 | #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \ | |
58356836 | 1206 | dw2_asm_output_data (1, OP, "%s", dwarf_stack_op_name (OP)) |
e8363d4c | 1207 | #endif |
1208 | ||
1209 | #ifndef ASM_OUTPUT_DWARF_FUND_TYPE | |
1210 | #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \ | |
58356836 | 1211 | dw2_asm_output_data (2, FT, "%s", dwarf_fund_type_name (FT)) |
e8363d4c | 1212 | #endif |
1213 | ||
1214 | #ifndef ASM_OUTPUT_DWARF_FMT_BYTE | |
1215 | #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \ | |
58356836 | 1216 | dw2_asm_output_data (1, FMT, "%s", dwarf_fmt_byte_name (FMT)); |
e8363d4c | 1217 | #endif |
1218 | ||
1219 | #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER | |
1220 | #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \ | |
58356836 | 1221 | dw2_asm_output_data (1, MOD, "%s", dwarf_typemod_name (MOD)); |
e8363d4c | 1222 | #endif |
1223 | \f | |
1224 | #ifndef ASM_OUTPUT_DWARF_ADDR | |
1225 | #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \ | |
58356836 | 1226 | dw2_asm_output_addr (4, LABEL, NULL) |
e8363d4c | 1227 | #endif |
1228 | ||
1229 | #ifndef ASM_OUTPUT_DWARF_ADDR_CONST | |
1230 | #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \ | |
58356836 | 1231 | dw2_asm_output_addr_rtx (4, RTX, NULL) |
e8363d4c | 1232 | #endif |
1233 | ||
1234 | #ifndef ASM_OUTPUT_DWARF_REF | |
1235 | #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \ | |
58356836 | 1236 | dw2_asm_output_addr (4, LABEL, NULL) |
e8363d4c | 1237 | #endif |
1238 | ||
1239 | #ifndef ASM_OUTPUT_DWARF_DATA1 | |
1240 | #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \ | |
58356836 | 1241 | dw2_asm_output_data (1, VALUE, NULL) |
e8363d4c | 1242 | #endif |
1243 | ||
1244 | #ifndef ASM_OUTPUT_DWARF_DATA2 | |
1245 | #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \ | |
58356836 | 1246 | dw2_asm_output_data (2, VALUE, NULL) |
e8363d4c | 1247 | #endif |
1248 | ||
1249 | #ifndef ASM_OUTPUT_DWARF_DATA4 | |
1250 | #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \ | |
58356836 | 1251 | dw2_asm_output_data (4, VALUE, NULL) |
e8363d4c | 1252 | #endif |
1253 | ||
1254 | #ifndef ASM_OUTPUT_DWARF_DATA8 | |
1255 | #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \ | |
58356836 | 1256 | dw2_asm_output_data (8, VALUE, NULL) |
e8363d4c | 1257 | #endif |
1258 | ||
01e45963 | 1259 | /* ASM_OUTPUT_DWARF_STRING is defined to output an ascii string, but to |
1260 | NOT issue a trailing newline. We define ASM_OUTPUT_DWARF_STRING_NEWLINE | |
1261 | based on whether ASM_OUTPUT_DWARF_STRING is defined or not. If it is | |
1262 | defined, we call it, then issue the line feed. If not, we supply a | |
3fb1e43b | 1263 | default definition of calling ASM_OUTPUT_ASCII */ |
01e45963 | 1264 | |
e8363d4c | 1265 | #ifndef ASM_OUTPUT_DWARF_STRING |
01e45963 | 1266 | #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \ |
e8363d4c | 1267 | ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1) |
01e45963 | 1268 | #else |
1269 | #define ASM_OUTPUT_DWARF_STRING_NEWLINE(FILE,P) \ | |
1eefe280 | 1270 | ASM_OUTPUT_DWARF_STRING (FILE,P), ASM_OUTPUT_DWARF_STRING (FILE,"\n") |
e8363d4c | 1271 | #endif |
01e45963 | 1272 | |
b896d81b | 1273 | \f |
c140b944 | 1274 | /* The debug hooks structure. */ |
e42f6423 | 1275 | const struct gcc_debug_hooks dwarf_debug_hooks = |
b896d81b | 1276 | { |
1277 | dwarfout_init, | |
c140b944 | 1278 | dwarfout_finish, |
1279 | dwarfout_define, | |
1280 | dwarfout_undef, | |
1281 | dwarfout_start_source_file_check, | |
1dff614c | 1282 | dwarfout_end_source_file_check, |
1283 | dwarfout_begin_block, | |
b9b7f8b4 | 1284 | dwarfout_end_block, |
b29760a8 | 1285 | debug_true_tree, /* ignore_block */ |
f76df888 | 1286 | dwarfout_source_line, /* source_line */ |
1287 | dwarfout_source_line, /* begin_prologue */ | |
1288 | dwarfout_end_prologue, | |
b9b7f8b4 | 1289 | dwarfout_end_epilogue, |
f76df888 | 1290 | debug_nothing_tree, /* begin_function */ |
c37d72e9 | 1291 | dwarfout_end_function, |
1292 | dwarfout_function_decl, | |
1293 | dwarfout_global_decl, | |
b29760a8 | 1294 | dwarfout_deferred_inline_function, |
1295 | debug_nothing_tree, /* outlining_inline_function */ | |
cf8e41a4 | 1296 | debug_nothing_rtx, /* label */ |
1297 | debug_nothing_int /* handle_pch */ | |
b896d81b | 1298 | }; |
e8363d4c | 1299 | \f |
1300 | /************************ general utility functions **************************/ | |
1301 | ||
80c9dac9 | 1302 | static inline int |
8ec3a57b | 1303 | is_pseudo_reg (rtx rtl) |
bad5b016 | 1304 | { |
1305 | return (((GET_CODE (rtl) == REG) && (REGNO (rtl) >= FIRST_PSEUDO_REGISTER)) | |
1eefe280 | 1306 | || ((GET_CODE (rtl) == SUBREG) |
701e46d0 | 1307 | && (REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER))); |
bad5b016 | 1308 | } |
1309 | ||
80c9dac9 | 1310 | static inline tree |
8ec3a57b | 1311 | type_main_variant (tree type) |
e079348f | 1312 | { |
1313 | type = TYPE_MAIN_VARIANT (type); | |
1314 | ||
1315 | /* There really should be only one main variant among any group of variants | |
1316 | of a given type (and all of the MAIN_VARIANT values for all members of | |
1317 | the group should point to that one type) but sometimes the C front-end | |
1318 | messes this up for array types, so we work around that bug here. */ | |
1319 | ||
1320 | if (TREE_CODE (type) == ARRAY_TYPE) | |
1321 | { | |
1322 | while (type != TYPE_MAIN_VARIANT (type)) | |
1eefe280 | 1323 | type = TYPE_MAIN_VARIANT (type); |
e079348f | 1324 | } |
1325 | ||
1326 | return type; | |
1327 | } | |
1328 | ||
6ef828f9 | 1329 | /* Return nonzero if the given type node represents a tagged type. */ |
1adc7e47 | 1330 | |
80c9dac9 | 1331 | static inline int |
8ec3a57b | 1332 | is_tagged_type (tree type) |
1adc7e47 | 1333 | { |
19cb6b50 | 1334 | enum tree_code code = TREE_CODE (type); |
1adc7e47 | 1335 | |
7f8a347a | 1336 | return (code == RECORD_TYPE || code == UNION_TYPE |
1337 | || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); | |
1adc7e47 | 1338 | } |
1339 | ||
12fc9462 | 1340 | static const char * |
8ec3a57b | 1341 | dwarf_tag_name (unsigned int tag) |
e8363d4c | 1342 | { |
1343 | switch (tag) | |
1344 | { | |
88ef61d1 | 1345 | case TAG_padding: return "TAG_padding"; |
1346 | case TAG_array_type: return "TAG_array_type"; | |
1347 | case TAG_class_type: return "TAG_class_type"; | |
1348 | case TAG_entry_point: return "TAG_entry_point"; | |
1349 | case TAG_enumeration_type: return "TAG_enumeration_type"; | |
1350 | case TAG_formal_parameter: return "TAG_formal_parameter"; | |
1351 | case TAG_global_subroutine: return "TAG_global_subroutine"; | |
1352 | case TAG_global_variable: return "TAG_global_variable"; | |
1353 | case TAG_label: return "TAG_label"; | |
1354 | case TAG_lexical_block: return "TAG_lexical_block"; | |
1355 | case TAG_local_variable: return "TAG_local_variable"; | |
1356 | case TAG_member: return "TAG_member"; | |
1357 | case TAG_pointer_type: return "TAG_pointer_type"; | |
1358 | case TAG_reference_type: return "TAG_reference_type"; | |
1359 | case TAG_compile_unit: return "TAG_compile_unit"; | |
1360 | case TAG_string_type: return "TAG_string_type"; | |
1361 | case TAG_structure_type: return "TAG_structure_type"; | |
1362 | case TAG_subroutine: return "TAG_subroutine"; | |
1363 | case TAG_subroutine_type: return "TAG_subroutine_type"; | |
1364 | case TAG_typedef: return "TAG_typedef"; | |
1365 | case TAG_union_type: return "TAG_union_type"; | |
e8363d4c | 1366 | case TAG_unspecified_parameters: return "TAG_unspecified_parameters"; |
88ef61d1 | 1367 | case TAG_variant: return "TAG_variant"; |
1368 | case TAG_common_block: return "TAG_common_block"; | |
1369 | case TAG_common_inclusion: return "TAG_common_inclusion"; | |
1370 | case TAG_inheritance: return "TAG_inheritance"; | |
1371 | case TAG_inlined_subroutine: return "TAG_inlined_subroutine"; | |
1372 | case TAG_module: return "TAG_module"; | |
1373 | case TAG_ptr_to_member_type: return "TAG_ptr_to_member_type"; | |
1374 | case TAG_set_type: return "TAG_set_type"; | |
1375 | case TAG_subrange_type: return "TAG_subrange_type"; | |
1376 | case TAG_with_stmt: return "TAG_with_stmt"; | |
1377 | ||
1378 | /* GNU extensions. */ | |
1379 | ||
1380 | case TAG_format_label: return "TAG_format_label"; | |
1381 | case TAG_namelist: return "TAG_namelist"; | |
1382 | case TAG_function_template: return "TAG_function_template"; | |
1383 | case TAG_class_template: return "TAG_class_template"; | |
1384 | ||
473cc96d | 1385 | default: return "TAG_<unknown>"; |
e8363d4c | 1386 | } |
1387 | } | |
1388 | ||
12fc9462 | 1389 | static const char * |
8ec3a57b | 1390 | dwarf_attr_name (unsigned int attr) |
e8363d4c | 1391 | { |
1392 | switch (attr) | |
1393 | { | |
88ef61d1 | 1394 | case AT_sibling: return "AT_sibling"; |
1395 | case AT_location: return "AT_location"; | |
1396 | case AT_name: return "AT_name"; | |
1397 | case AT_fund_type: return "AT_fund_type"; | |
1398 | case AT_mod_fund_type: return "AT_mod_fund_type"; | |
1399 | case AT_user_def_type: return "AT_user_def_type"; | |
1400 | case AT_mod_u_d_type: return "AT_mod_u_d_type"; | |
1401 | case AT_ordering: return "AT_ordering"; | |
1402 | case AT_subscr_data: return "AT_subscr_data"; | |
1403 | case AT_byte_size: return "AT_byte_size"; | |
1404 | case AT_bit_offset: return "AT_bit_offset"; | |
1405 | case AT_bit_size: return "AT_bit_size"; | |
1406 | case AT_element_list: return "AT_element_list"; | |
1407 | case AT_stmt_list: return "AT_stmt_list"; | |
1408 | case AT_low_pc: return "AT_low_pc"; | |
1409 | case AT_high_pc: return "AT_high_pc"; | |
1410 | case AT_language: return "AT_language"; | |
1411 | case AT_member: return "AT_member"; | |
1412 | case AT_discr: return "AT_discr"; | |
1413 | case AT_discr_value: return "AT_discr_value"; | |
1414 | case AT_string_length: return "AT_string_length"; | |
1415 | case AT_common_reference: return "AT_common_reference"; | |
1416 | case AT_comp_dir: return "AT_comp_dir"; | |
1417 | case AT_const_value_string: return "AT_const_value_string"; | |
1418 | case AT_const_value_data2: return "AT_const_value_data2"; | |
1419 | case AT_const_value_data4: return "AT_const_value_data4"; | |
1420 | case AT_const_value_data8: return "AT_const_value_data8"; | |
1421 | case AT_const_value_block2: return "AT_const_value_block2"; | |
e8363d4c | 1422 | case AT_const_value_block4: return "AT_const_value_block4"; |
88ef61d1 | 1423 | case AT_containing_type: return "AT_containing_type"; |
1424 | case AT_default_value_addr: return "AT_default_value_addr"; | |
1425 | case AT_default_value_data2: return "AT_default_value_data2"; | |
1426 | case AT_default_value_data4: return "AT_default_value_data4"; | |
1427 | case AT_default_value_data8: return "AT_default_value_data8"; | |
1428 | case AT_default_value_string: return "AT_default_value_string"; | |
1429 | case AT_friends: return "AT_friends"; | |
1430 | case AT_inline: return "AT_inline"; | |
1431 | case AT_is_optional: return "AT_is_optional"; | |
1432 | case AT_lower_bound_ref: return "AT_lower_bound_ref"; | |
1433 | case AT_lower_bound_data2: return "AT_lower_bound_data2"; | |
1434 | case AT_lower_bound_data4: return "AT_lower_bound_data4"; | |
1435 | case AT_lower_bound_data8: return "AT_lower_bound_data8"; | |
1436 | case AT_private: return "AT_private"; | |
1437 | case AT_producer: return "AT_producer"; | |
1438 | case AT_program: return "AT_program"; | |
1439 | case AT_protected: return "AT_protected"; | |
1440 | case AT_prototyped: return "AT_prototyped"; | |
1441 | case AT_public: return "AT_public"; | |
1442 | case AT_pure_virtual: return "AT_pure_virtual"; | |
1443 | case AT_return_addr: return "AT_return_addr"; | |
473cc96d | 1444 | case AT_abstract_origin: return "AT_abstract_origin"; |
88ef61d1 | 1445 | case AT_start_scope: return "AT_start_scope"; |
1446 | case AT_stride_size: return "AT_stride_size"; | |
1447 | case AT_upper_bound_ref: return "AT_upper_bound_ref"; | |
1448 | case AT_upper_bound_data2: return "AT_upper_bound_data2"; | |
1449 | case AT_upper_bound_data4: return "AT_upper_bound_data4"; | |
1450 | case AT_upper_bound_data8: return "AT_upper_bound_data8"; | |
1451 | case AT_virtual: return "AT_virtual"; | |
1452 | ||
1453 | /* GNU extensions */ | |
1454 | ||
1455 | case AT_sf_names: return "AT_sf_names"; | |
1456 | case AT_src_info: return "AT_src_info"; | |
1457 | case AT_mac_info: return "AT_mac_info"; | |
1458 | case AT_src_coords: return "AT_src_coords"; | |
cf6a3b88 | 1459 | case AT_body_begin: return "AT_body_begin"; |
1460 | case AT_body_end: return "AT_body_end"; | |
88ef61d1 | 1461 | |
473cc96d | 1462 | default: return "AT_<unknown>"; |
e8363d4c | 1463 | } |
1464 | } | |
1465 | ||
12fc9462 | 1466 | static const char * |
8ec3a57b | 1467 | dwarf_stack_op_name (unsigned int op) |
e8363d4c | 1468 | { |
1469 | switch (op) | |
1470 | { | |
1471 | case OP_REG: return "OP_REG"; | |
1472 | case OP_BASEREG: return "OP_BASEREG"; | |
1473 | case OP_ADDR: return "OP_ADDR"; | |
1474 | case OP_CONST: return "OP_CONST"; | |
1475 | case OP_DEREF2: return "OP_DEREF2"; | |
1476 | case OP_DEREF4: return "OP_DEREF4"; | |
1477 | case OP_ADD: return "OP_ADD"; | |
473cc96d | 1478 | default: return "OP_<unknown>"; |
e8363d4c | 1479 | } |
1480 | } | |
1481 | ||
12fc9462 | 1482 | static const char * |
8ec3a57b | 1483 | dwarf_typemod_name (unsigned int mod) |
e8363d4c | 1484 | { |
1485 | switch (mod) | |
1486 | { | |
1487 | case MOD_pointer_to: return "MOD_pointer_to"; | |
1488 | case MOD_reference_to: return "MOD_reference_to"; | |
1489 | case MOD_const: return "MOD_const"; | |
1490 | case MOD_volatile: return "MOD_volatile"; | |
473cc96d | 1491 | default: return "MOD_<unknown>"; |
e8363d4c | 1492 | } |
1493 | } | |
1494 | ||
12fc9462 | 1495 | static const char * |
8ec3a57b | 1496 | dwarf_fmt_byte_name (unsigned int fmt) |
e8363d4c | 1497 | { |
1498 | switch (fmt) | |
1499 | { | |
1500 | case FMT_FT_C_C: return "FMT_FT_C_C"; | |
1501 | case FMT_FT_C_X: return "FMT_FT_C_X"; | |
1502 | case FMT_FT_X_C: return "FMT_FT_X_C"; | |
1503 | case FMT_FT_X_X: return "FMT_FT_X_X"; | |
1504 | case FMT_UT_C_C: return "FMT_UT_C_C"; | |
1505 | case FMT_UT_C_X: return "FMT_UT_C_X"; | |
1506 | case FMT_UT_X_C: return "FMT_UT_X_C"; | |
1507 | case FMT_UT_X_X: return "FMT_UT_X_X"; | |
1508 | case FMT_ET: return "FMT_ET"; | |
473cc96d | 1509 | default: return "FMT_<unknown>"; |
e8363d4c | 1510 | } |
1511 | } | |
7bfbda1f | 1512 | |
12fc9462 | 1513 | static const char * |
8ec3a57b | 1514 | dwarf_fund_type_name (unsigned int ft) |
e8363d4c | 1515 | { |
1516 | switch (ft) | |
1517 | { | |
1518 | case FT_char: return "FT_char"; | |
1519 | case FT_signed_char: return "FT_signed_char"; | |
1520 | case FT_unsigned_char: return "FT_unsigned_char"; | |
1521 | case FT_short: return "FT_short"; | |
1522 | case FT_signed_short: return "FT_signed_short"; | |
1523 | case FT_unsigned_short: return "FT_unsigned_short"; | |
1524 | case FT_integer: return "FT_integer"; | |
1525 | case FT_signed_integer: return "FT_signed_integer"; | |
1526 | case FT_unsigned_integer: return "FT_unsigned_integer"; | |
1527 | case FT_long: return "FT_long"; | |
1528 | case FT_signed_long: return "FT_signed_long"; | |
1529 | case FT_unsigned_long: return "FT_unsigned_long"; | |
1530 | case FT_pointer: return "FT_pointer"; | |
1531 | case FT_float: return "FT_float"; | |
1532 | case FT_dbl_prec_float: return "FT_dbl_prec_float"; | |
1533 | case FT_ext_prec_float: return "FT_ext_prec_float"; | |
1534 | case FT_complex: return "FT_complex"; | |
1535 | case FT_dbl_prec_complex: return "FT_dbl_prec_complex"; | |
1536 | case FT_void: return "FT_void"; | |
1537 | case FT_boolean: return "FT_boolean"; | |
88ef61d1 | 1538 | case FT_ext_prec_complex: return "FT_ext_prec_complex"; |
1539 | case FT_label: return "FT_label"; | |
1540 | ||
1541 | /* GNU extensions. */ | |
1542 | ||
e8363d4c | 1543 | case FT_long_long: return "FT_long_long"; |
1544 | case FT_signed_long_long: return "FT_signed_long_long"; | |
1545 | case FT_unsigned_long_long: return "FT_unsigned_long_long"; | |
88ef61d1 | 1546 | |
1547 | case FT_int8: return "FT_int8"; | |
1548 | case FT_signed_int8: return "FT_signed_int8"; | |
1549 | case FT_unsigned_int8: return "FT_unsigned_int8"; | |
1550 | case FT_int16: return "FT_int16"; | |
1551 | case FT_signed_int16: return "FT_signed_int16"; | |
1552 | case FT_unsigned_int16: return "FT_unsigned_int16"; | |
1553 | case FT_int32: return "FT_int32"; | |
1554 | case FT_signed_int32: return "FT_signed_int32"; | |
1555 | case FT_unsigned_int32: return "FT_unsigned_int32"; | |
1556 | case FT_int64: return "FT_int64"; | |
1557 | case FT_signed_int64: return "FT_signed_int64"; | |
c0c5cc39 | 1558 | case FT_unsigned_int64: return "FT_unsigned_int64"; |
e2ea7e3a | 1559 | case FT_int128: return "FT_int128"; |
1560 | case FT_signed_int128: return "FT_signed_int128"; | |
1561 | case FT_unsigned_int128: return "FT_unsigned_int128"; | |
88ef61d1 | 1562 | |
1563 | case FT_real32: return "FT_real32"; | |
1564 | case FT_real64: return "FT_real64"; | |
1565 | case FT_real96: return "FT_real96"; | |
1566 | case FT_real128: return "FT_real128"; | |
1567 | ||
fbb1faac | 1568 | default: return "FT_<unknown>"; |
e8363d4c | 1569 | } |
1570 | } | |
fbb1faac | 1571 | |
1572 | /* Determine the "ultimate origin" of a decl. The decl may be an | |
1573 | inlined instance of an inlined instance of a decl which is local | |
1574 | to an inline function, so we have to trace all of the way back | |
1575 | through the origin chain to find out what sort of node actually | |
1576 | served as the original seed for the given block. */ | |
1577 | ||
1578 | static tree | |
8ec3a57b | 1579 | decl_ultimate_origin (tree decl) |
fbb1faac | 1580 | { |
1eefe280 | 1581 | #ifdef ENABLE_CHECKING |
c0671ae8 | 1582 | if (DECL_FROM_INLINE (DECL_ORIGIN (decl))) |
1583 | /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the | |
1584 | most distant ancestor, this should never happen. */ | |
1585 | abort (); | |
1586 | #endif | |
fbb1faac | 1587 | |
c0671ae8 | 1588 | return DECL_ABSTRACT_ORIGIN (decl); |
fbb1faac | 1589 | } |
1590 | ||
6eaabe2a | 1591 | /* Determine the "ultimate origin" of a block. The block may be an |
1592 | inlined instance of an inlined instance of a block which is local | |
1593 | to an inline function, so we have to trace all of the way back | |
1594 | through the origin chain to find out what sort of node actually | |
1595 | served as the original seed for the given block. */ | |
1596 | ||
1597 | static tree | |
8ec3a57b | 1598 | block_ultimate_origin (tree block) |
6eaabe2a | 1599 | { |
19cb6b50 | 1600 | tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); |
6eaabe2a | 1601 | |
1602 | if (immediate_origin == NULL) | |
1603 | return NULL; | |
1604 | else | |
1605 | { | |
19cb6b50 | 1606 | tree ret_val; |
1607 | tree lookahead = immediate_origin; | |
6eaabe2a | 1608 | |
1609 | do | |
1610 | { | |
1611 | ret_val = lookahead; | |
1612 | lookahead = (TREE_CODE (ret_val) == BLOCK) | |
1613 | ? BLOCK_ABSTRACT_ORIGIN (ret_val) | |
1614 | : NULL; | |
1615 | } | |
1616 | while (lookahead != NULL && lookahead != ret_val); | |
1617 | return ret_val; | |
1618 | } | |
1619 | } | |
1620 | ||
6efd403b | 1621 | /* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT |
1622 | of a virtual function may refer to a base class, so we check the 'this' | |
1623 | parameter. */ | |
1624 | ||
1625 | static tree | |
8ec3a57b | 1626 | decl_class_context (tree decl) |
6efd403b | 1627 | { |
1628 | tree context = NULL_TREE; | |
1629 | if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) | |
1630 | context = DECL_CONTEXT (decl); | |
1631 | else | |
1632 | context = TYPE_MAIN_VARIANT | |
1633 | (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); | |
1634 | ||
9308e976 | 1635 | if (context && !TYPE_P (context)) |
6efd403b | 1636 | context = NULL_TREE; |
1637 | ||
1638 | return context; | |
1639 | } | |
1640 | ||
0e93a6ac | 1641 | #if 0 |
fbb1faac | 1642 | static void |
8ec3a57b | 1643 | output_unsigned_leb128 (unsigned long value) |
fbb1faac | 1644 | { |
19cb6b50 | 1645 | unsigned long orig_value = value; |
fbb1faac | 1646 | |
1647 | do | |
1648 | { | |
19cb6b50 | 1649 | unsigned byte = (value & 0x7f); |
fbb1faac | 1650 | |
1651 | value >>= 7; | |
1652 | if (value != 0) /* more bytes to follow */ | |
1653 | byte |= 0x80; | |
58356836 | 1654 | dw2_asm_output_data (1, byte, "\t%s ULEB128 number - value = %lu", |
1655 | orig_value); | |
fbb1faac | 1656 | } |
1657 | while (value != 0); | |
1658 | } | |
1659 | ||
1660 | static void | |
8ec3a57b | 1661 | output_signed_leb128 (long value) |
fbb1faac | 1662 | { |
19cb6b50 | 1663 | long orig_value = value; |
1664 | int negative = (value < 0); | |
1665 | int more; | |
fbb1faac | 1666 | |
1667 | do | |
1668 | { | |
19cb6b50 | 1669 | unsigned byte = (value & 0x7f); |
fbb1faac | 1670 | |
1671 | value >>= 7; | |
1672 | if (negative) | |
1673 | value |= 0xfe000000; /* manually sign extend */ | |
1674 | if (((value == 0) && ((byte & 0x40) == 0)) | |
1eefe280 | 1675 | || ((value == -1) && ((byte & 0x40) == 1))) |
fbb1faac | 1676 | more = 0; |
1677 | else | |
1678 | { | |
1679 | byte |= 0x80; | |
1680 | more = 1; | |
1681 | } | |
58356836 | 1682 | dw2_asm_output_data (1, byte, "\t%s SLEB128 number - value = %ld", |
1683 | orig_value); | |
fbb1faac | 1684 | } |
1685 | while (more); | |
1686 | } | |
0e93a6ac | 1687 | #endif |
e8363d4c | 1688 | \f |
1689 | /**************** utility functions for attribute functions ******************/ | |
1690 | ||
1691 | /* Given a pointer to a tree node for some type, return a Dwarf fundamental | |
1692 | type code for the given type. | |
1693 | ||
1694 | This routine must only be called for GCC type nodes that correspond to | |
1695 | Dwarf fundamental types. | |
1696 | ||
1697 | The current Dwarf draft specification calls for Dwarf fundamental types | |
1698 | to accurately reflect the fact that a given type was either a "plain" | |
476e9a33 | 1699 | integral type or an explicitly "signed" integral type. Unfortunately, |
e8363d4c | 1700 | we can't always do this, because GCC may already have thrown away the |
1701 | information about the precise way in which the type was originally | |
1702 | specified, as in: | |
1703 | ||
7b52666d | 1704 | typedef signed int my_type; |
e8363d4c | 1705 | |
7b52666d | 1706 | struct s { my_type f; }; |
e8363d4c | 1707 | |
4a82352a | 1708 | Since we may be stuck here without enough information to do exactly |
e8363d4c | 1709 | what is called for in the Dwarf draft specification, we do the best |
1710 | that we can under the circumstances and always use the "plain" integral | |
1711 | fundamental type codes for int, short, and long types. That's probably | |
1712 | good enough. The additional accuracy called for in the current DWARF | |
1713 | draft specification is probably never even useful in practice. */ | |
1714 | ||
1715 | static int | |
8ec3a57b | 1716 | fundamental_type_code (tree type) |
e8363d4c | 1717 | { |
1718 | if (TREE_CODE (type) == ERROR_MARK) | |
1719 | return 0; | |
1720 | ||
1721 | switch (TREE_CODE (type)) | |
1722 | { | |
1723 | case ERROR_MARK: | |
1724 | return FT_void; | |
1725 | ||
1726 | case VOID_TYPE: | |
1727 | return FT_void; | |
1728 | ||
1729 | case INTEGER_TYPE: | |
1730 | /* Carefully distinguish all the standard types of C, | |
1731 | without messing up if the language is not C. | |
1732 | Note that we check only for the names that contain spaces; | |
1733 | other names might occur by coincidence in other languages. */ | |
1734 | if (TYPE_NAME (type) != 0 | |
1735 | && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
1736 | && DECL_NAME (TYPE_NAME (type)) != 0 | |
1737 | && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE) | |
1738 | { | |
0d95286f | 1739 | const char *const name = |
12fc9462 | 1740 | IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); |
e8363d4c | 1741 | |
1742 | if (!strcmp (name, "unsigned char")) | |
1743 | return FT_unsigned_char; | |
1744 | if (!strcmp (name, "signed char")) | |
1745 | return FT_signed_char; | |
1746 | if (!strcmp (name, "unsigned int")) | |
1747 | return FT_unsigned_integer; | |
1748 | if (!strcmp (name, "short int")) | |
1749 | return FT_short; | |
1750 | if (!strcmp (name, "short unsigned int")) | |
1751 | return FT_unsigned_short; | |
1752 | if (!strcmp (name, "long int")) | |
1753 | return FT_long; | |
1754 | if (!strcmp (name, "long unsigned int")) | |
1755 | return FT_unsigned_long; | |
1756 | if (!strcmp (name, "long long int")) | |
1757 | return FT_long_long; /* Not grok'ed by svr4 SDB */ | |
1758 | if (!strcmp (name, "long long unsigned int")) | |
1759 | return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */ | |
1760 | } | |
1761 | ||
1762 | /* Most integer types will be sorted out above, however, for the | |
1763 | sake of special `array index' integer types, the following code | |
1764 | is also provided. */ | |
1765 | ||
1766 | if (TYPE_PRECISION (type) == INT_TYPE_SIZE) | |
1767 | return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer); | |
1768 | ||
1769 | if (TYPE_PRECISION (type) == LONG_TYPE_SIZE) | |
1770 | return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long); | |
1771 | ||
1772 | if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE) | |
1773 | return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long); | |
1774 | ||
1775 | if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE) | |
1776 | return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short); | |
1777 | ||
1778 | if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE) | |
1779 | return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char); | |
1780 | ||
e2ea7e3a | 1781 | if (TYPE_MODE (type) == TImode) |
1782 | return (TREE_UNSIGNED (type) ? FT_unsigned_int128 : FT_int128); | |
1783 | ||
e9c8207a | 1784 | /* In C++, __java_boolean is an INTEGER_TYPE with precision == 1 */ |
1785 | if (TYPE_PRECISION (type) == 1) | |
1786 | return FT_boolean; | |
1787 | ||
e8363d4c | 1788 | abort (); |
1789 | ||
1790 | case REAL_TYPE: | |
1791 | /* Carefully distinguish all the standard types of C, | |
1792 | without messing up if the language is not C. */ | |
1793 | if (TYPE_NAME (type) != 0 | |
1794 | && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
1795 | && DECL_NAME (TYPE_NAME (type)) != 0 | |
1796 | && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE) | |
1797 | { | |
0d95286f | 1798 | const char *const name = |
12fc9462 | 1799 | IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); |
e8363d4c | 1800 | |
3fb1e43b | 1801 | /* Note that here we can run afoul of a serious bug in "classic" |
e8363d4c | 1802 | svr4 SDB debuggers. They don't seem to understand the |
1803 | FT_ext_prec_float type (even though they should). */ | |
1804 | ||
1805 | if (!strcmp (name, "long double")) | |
1806 | return FT_ext_prec_float; | |
1807 | } | |
1808 | ||
1809 | if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE) | |
eb1d259a | 1810 | { |
1811 | /* On the SH, when compiling with -m3e or -m4-single-only, both | |
1812 | float and double are 32 bits. But since the debugger doesn't | |
1813 | know about the subtarget, it always thinks double is 64 bits. | |
1814 | So we have to tell the debugger that the type is float to | |
1815 | make the output of the 'print' command etc. readable. */ | |
1816 | if (DOUBLE_TYPE_SIZE == FLOAT_TYPE_SIZE && FLOAT_TYPE_SIZE == 32) | |
3fe3ceae | 1817 | return FT_float; |
eb1d259a | 1818 | return FT_dbl_prec_float; |
1819 | } | |
e8363d4c | 1820 | if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE) |
1821 | return FT_float; | |
1822 | ||
3fb1e43b | 1823 | /* Note that here we can run afoul of a serious bug in "classic" |
e8363d4c | 1824 | svr4 SDB debuggers. They don't seem to understand the |
1825 | FT_ext_prec_float type (even though they should). */ | |
1826 | ||
1827 | if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE) | |
1828 | return FT_ext_prec_float; | |
1829 | abort (); | |
1830 | ||
1831 | case COMPLEX_TYPE: | |
1832 | return FT_complex; /* GNU FORTRAN COMPLEX type. */ | |
1833 | ||
1834 | case CHAR_TYPE: | |
1835 | return FT_char; /* GNU Pascal CHAR type. Not used in C. */ | |
1836 | ||
1837 | case BOOLEAN_TYPE: | |
1838 | return FT_boolean; /* GNU FORTRAN BOOLEAN type. */ | |
1839 | ||
1840 | default: | |
1841 | abort (); /* No other TREE_CODEs are Dwarf fundamental types. */ | |
1842 | } | |
1843 | return 0; | |
1844 | } | |
1845 | \f | |
1846 | /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to | |
1847 | the Dwarf "root" type for the given input type. The Dwarf "root" type | |
1848 | of a given type is generally the same as the given type, except that if | |
1849 | the given type is a pointer or reference type, then the root type of | |
1850 | the given type is the root type of the "basis" type for the pointer or | |
1851 | reference type. (This definition of the "root" type is recursive.) | |
1852 | Also, the root type of a `const' qualified type or a `volatile' | |
1853 | qualified type is the root type of the given type without the | |
1854 | qualifiers. */ | |
1855 | ||
1856 | static tree | |
8ec3a57b | 1857 | root_type_1 (tree type, int count) |
e8363d4c | 1858 | { |
214044ec | 1859 | /* Give up after searching 1000 levels, in case this is a recursive |
1860 | pointer type. Such types are possible in Ada, but it is not possible | |
1861 | to represent them in DWARF1 debug info. */ | |
1862 | if (count > 1000) | |
e8363d4c | 1863 | return error_mark_node; |
1864 | ||
1865 | switch (TREE_CODE (type)) | |
1866 | { | |
1867 | case ERROR_MARK: | |
1868 | return error_mark_node; | |
1869 | ||
1870 | case POINTER_TYPE: | |
1871 | case REFERENCE_TYPE: | |
214044ec | 1872 | return root_type_1 (TREE_TYPE (type), count+1); |
e8363d4c | 1873 | |
1874 | default: | |
214044ec | 1875 | return type; |
e8363d4c | 1876 | } |
1877 | } | |
1878 | ||
214044ec | 1879 | static tree |
8ec3a57b | 1880 | root_type (tree type) |
214044ec | 1881 | { |
1882 | type = root_type_1 (type, 0); | |
1883 | if (type != error_mark_node) | |
1884 | type = type_main_variant (type); | |
1885 | return type; | |
1886 | } | |
1887 | ||
e8363d4c | 1888 | /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence |
1889 | of zero or more Dwarf "type-modifier" bytes applicable to the type. */ | |
1890 | ||
1891 | static void | |
8ec3a57b | 1892 | write_modifier_bytes_1 (tree type, int decl_const, int decl_volatile, int count) |
e8363d4c | 1893 | { |
1894 | if (TREE_CODE (type) == ERROR_MARK) | |
1895 | return; | |
1896 | ||
214044ec | 1897 | /* Give up after searching 1000 levels, in case this is a recursive |
1898 | pointer type. Such types are possible in Ada, but it is not possible | |
1899 | to represent them in DWARF1 debug info. */ | |
1900 | if (count > 1000) | |
1901 | return; | |
1902 | ||
e8363d4c | 1903 | if (TYPE_READONLY (type) || decl_const) |
1904 | ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const); | |
1905 | if (TYPE_VOLATILE (type) || decl_volatile) | |
1906 | ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile); | |
1907 | switch (TREE_CODE (type)) | |
1908 | { | |
1909 | case POINTER_TYPE: | |
1910 | ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to); | |
214044ec | 1911 | write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1); |
e8363d4c | 1912 | return; |
1913 | ||
1914 | case REFERENCE_TYPE: | |
1915 | ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to); | |
214044ec | 1916 | write_modifier_bytes_1 (TREE_TYPE (type), 0, 0, count+1); |
e8363d4c | 1917 | return; |
1918 | ||
1919 | case ERROR_MARK: | |
1920 | default: | |
1921 | return; | |
1922 | } | |
1923 | } | |
214044ec | 1924 | |
1925 | static void | |
8ec3a57b | 1926 | write_modifier_bytes (tree type, int decl_const, int decl_volatile) |
214044ec | 1927 | { |
1928 | write_modifier_bytes_1 (type, decl_const, decl_volatile, 0); | |
1929 | } | |
e8363d4c | 1930 | \f |
6ef828f9 | 1931 | /* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the |
e8363d4c | 1932 | given input type is a Dwarf "fundamental" type. Otherwise return zero. */ |
1933 | ||
7bfbda1f | 1934 | static inline int |
8ec3a57b | 1935 | type_is_fundamental (tree type) |
e8363d4c | 1936 | { |
1937 | switch (TREE_CODE (type)) | |
1938 | { | |
1939 | case ERROR_MARK: | |
1940 | case VOID_TYPE: | |
1941 | case INTEGER_TYPE: | |
1942 | case REAL_TYPE: | |
1943 | case COMPLEX_TYPE: | |
1944 | case BOOLEAN_TYPE: | |
1945 | case CHAR_TYPE: | |
1946 | return 1; | |
1947 | ||
1948 | case SET_TYPE: | |
1949 | case ARRAY_TYPE: | |
1950 | case RECORD_TYPE: | |
1951 | case UNION_TYPE: | |
7f8a347a | 1952 | case QUAL_UNION_TYPE: |
e8363d4c | 1953 | case ENUMERAL_TYPE: |
1954 | case FUNCTION_TYPE: | |
1955 | case METHOD_TYPE: | |
1956 | case POINTER_TYPE: | |
1957 | case REFERENCE_TYPE: | |
e8363d4c | 1958 | case FILE_TYPE: |
1959 | case OFFSET_TYPE: | |
1960 | case LANG_TYPE: | |
e2ea7e3a | 1961 | case VECTOR_TYPE: |
e8363d4c | 1962 | return 0; |
1963 | ||
1964 | default: | |
1965 | abort (); | |
1966 | } | |
1967 | return 0; | |
1968 | } | |
1969 | ||
473cc96d | 1970 | /* Given a pointer to some ..._DECL tree node, generate an assembly language |
1971 | equate directive which will associate a symbolic name with the current DIE. | |
1972 | ||
1973 | The name used is an artificial label generated from the DECL_UID number | |
1974 | associated with the given decl node. The name it gets equated to is the | |
1975 | symbolic label that we (previously) output at the start of the DIE that | |
1976 | we are currently generating. | |
1977 | ||
1978 | Calling this function while generating some "decl related" form of DIE | |
1979 | makes it possible to later refer to the DIE which represents the given | |
1980 | decl simply by re-generating the symbolic name from the ..._DECL node's | |
1981 | UID number. */ | |
1982 | ||
1983 | static void | |
8ec3a57b | 1984 | equate_decl_number_to_die_number (tree decl) |
473cc96d | 1985 | { |
1986 | /* In the case where we are generating a DIE for some ..._DECL node | |
1987 | which represents either some inline function declaration or some | |
1988 | entity declared within an inline function declaration/definition, | |
1989 | setup a symbolic name for the current DIE so that we have a name | |
1990 | for this DIE that we can easily refer to later on within | |
1991 | AT_abstract_origin attributes. */ | |
1992 | ||
1993 | char decl_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1994 | char die_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
1995 | ||
1996 | sprintf (decl_label, DECL_NAME_FMT, DECL_UID (decl)); | |
1997 | sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum); | |
1998 | ASM_OUTPUT_DEF (asm_out_file, decl_label, die_label); | |
1999 | } | |
2000 | ||
e8363d4c | 2001 | /* Given a pointer to some ..._TYPE tree node, generate an assembly language |
473cc96d | 2002 | equate directive which will associate a symbolic name with the current DIE. |
e8363d4c | 2003 | |
2004 | The name used is an artificial label generated from the TYPE_UID number | |
2005 | associated with the given type node. The name it gets equated to is the | |
2006 | symbolic label that we (previously) output at the start of the DIE that | |
2007 | we are currently generating. | |
2008 | ||
2009 | Calling this function while generating some "type related" form of DIE | |
2010 | makes it easy to later refer to the DIE which represents the given type | |
2011 | simply by re-generating the alternative name from the ..._TYPE node's | |
2012 | UID number. */ | |
2013 | ||
7bfbda1f | 2014 | static inline void |
8ec3a57b | 2015 | equate_type_number_to_die_number (tree type) |
e8363d4c | 2016 | { |
2017 | char type_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2018 | char die_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2019 | ||
2020 | /* We are generating a DIE to represent the main variant of this type | |
2021 | (i.e the type without any const or volatile qualifiers) so in order | |
2022 | to get the equate to come out right, we need to get the main variant | |
2023 | itself here. */ | |
2024 | ||
e079348f | 2025 | type = type_main_variant (type); |
e8363d4c | 2026 | |
2027 | sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type)); | |
2028 | sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum); | |
2029 | ASM_OUTPUT_DEF (asm_out_file, type_label, die_label); | |
2030 | } | |
2031 | ||
017ffcef | 2032 | static void |
8ec3a57b | 2033 | output_reg_number (rtx rtl) |
017ffcef | 2034 | { |
19cb6b50 | 2035 | unsigned regno = REGNO (rtl); |
017ffcef | 2036 | |
55de61ac | 2037 | if (regno >= DWARF_FRAME_REGISTERS) |
017ffcef | 2038 | { |
8ec3a57b | 2039 | warning_with_decl (dwarf_last_decl, |
13c773a7 | 2040 | "internal regno botch: `%s' has regno = %d\n", |
017ffcef | 2041 | regno); |
2042 | regno = 0; | |
2043 | } | |
58356836 | 2044 | dw2_assemble_integer (4, GEN_INT (DBX_REGISTER_NUMBER (regno))); |
c0100b62 | 2045 | if (flag_debug_asm) |
017ffcef | 2046 | { |
2047 | fprintf (asm_out_file, "\t%s ", ASM_COMMENT_START); | |
2048 | PRINT_REG (rtl, 0, asm_out_file); | |
2049 | } | |
2050 | fputc ('\n', asm_out_file); | |
2051 | } | |
2052 | ||
e8363d4c | 2053 | /* The following routine is a nice and simple transducer. It converts the |
2054 | RTL for a variable or parameter (resident in memory) into an equivalent | |
2055 | Dwarf representation of a mechanism for getting the address of that same | |
2056 | variable onto the top of a hypothetical "address evaluation" stack. | |
2057 | ||
2058 | When creating memory location descriptors, we are effectively trans- | |
2059 | forming the RTL for a memory-resident object into its Dwarf postfix | |
2060 | expression equivalent. This routine just recursively descends an | |
2061 | RTL tree, turning it into Dwarf postfix code as it goes. */ | |
2062 | ||
2063 | static void | |
8ec3a57b | 2064 | output_mem_loc_descriptor (rtx rtl) |
e8363d4c | 2065 | { |
2066 | /* Note that for a dynamically sized array, the location we will | |
2067 | generate a description of here will be the lowest numbered location | |
2068 | which is actually within the array. That's *not* necessarily the | |
2069 | same as the zeroth element of the array. */ | |
2070 | ||
07576557 | 2071 | rtl = (*targetm.delegitimize_address) (rtl); |
eacbfaac | 2072 | |
e8363d4c | 2073 | switch (GET_CODE (rtl)) |
2074 | { | |
2075 | case SUBREG: | |
2076 | ||
2077 | /* The case of a subreg may arise when we have a local (register) | |
2078 | variable or a formal (register) parameter which doesn't quite | |
2079 | fill up an entire register. For now, just assume that it is | |
2080 | legitimate to make the Dwarf info refer to the whole register | |
2081 | which contains the given subreg. */ | |
2082 | ||
701e46d0 | 2083 | rtl = SUBREG_REG (rtl); |
e8363d4c | 2084 | /* Drop thru. */ |
2085 | ||
2086 | case REG: | |
2087 | ||
2088 | /* Whenever a register number forms a part of the description of | |
2089 | the method for calculating the (dynamic) address of a memory | |
1e19b009 | 2090 | resident object, DWARF rules require the register number to |
e8363d4c | 2091 | be referred to as a "base register". This distinction is not |
2092 | based in any way upon what category of register the hardware | |
2093 | believes the given register belongs to. This is strictly | |
75d860d6 | 2094 | DWARF terminology we're dealing with here. |
372da78f | 2095 | |
2096 | Note that in cases where the location of a memory-resident data | |
2097 | object could be expressed as: | |
2098 | ||
2099 | OP_ADD (OP_BASEREG (basereg), OP_CONST (0)) | |
2100 | ||
2101 | the actual DWARF location descriptor that we generate may just | |
2102 | be OP_BASEREG (basereg). This may look deceptively like the | |
2103 | object in question was allocated to a register (rather than | |
2104 | in memory) so DWARF consumers need to be aware of the subtle | |
1e19b009 | 2105 | distinction between OP_REG and OP_BASEREG. */ |
e8363d4c | 2106 | |
2107 | ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG); | |
017ffcef | 2108 | output_reg_number (rtl); |
e8363d4c | 2109 | break; |
2110 | ||
2111 | case MEM: | |
2112 | output_mem_loc_descriptor (XEXP (rtl, 0)); | |
2113 | ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4); | |
2114 | break; | |
2115 | ||
2116 | case CONST: | |
2117 | case SYMBOL_REF: | |
2118 | ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR); | |
2119 | ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl); | |
2120 | break; | |
2121 | ||
2122 | case PLUS: | |
2123 | output_mem_loc_descriptor (XEXP (rtl, 0)); | |
2124 | output_mem_loc_descriptor (XEXP (rtl, 1)); | |
2125 | ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD); | |
2126 | break; | |
2127 | ||
2128 | case CONST_INT: | |
2129 | ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST); | |
2130 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl)); | |
2131 | break; | |
2132 | ||
c0c5cc39 | 2133 | case MULT: |
2134 | /* If a pseudo-reg is optimized away, it is possible for it to | |
2135 | be replaced with a MEM containing a multiply. Use a GNU extension | |
2136 | to describe it. */ | |
2137 | output_mem_loc_descriptor (XEXP (rtl, 0)); | |
2138 | output_mem_loc_descriptor (XEXP (rtl, 1)); | |
2139 | ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_MULT); | |
2140 | break; | |
2141 | ||
e8363d4c | 2142 | default: |
2143 | abort (); | |
2144 | } | |
2145 | } | |
2146 | ||
2147 | /* Output a proper Dwarf location descriptor for a variable or parameter | |
2148 | which is either allocated in a register or in a memory location. For | |
2149 | a register, we just generate an OP_REG and the register number. For a | |
2150 | memory location we provide a Dwarf postfix expression describing how to | |
2151 | generate the (dynamic) address of the object onto the address stack. */ | |
2152 | ||
2153 | static void | |
8ec3a57b | 2154 | output_loc_descriptor (rtx rtl) |
e8363d4c | 2155 | { |
2156 | switch (GET_CODE (rtl)) | |
2157 | { | |
2158 | case SUBREG: | |
2159 | ||
2160 | /* The case of a subreg may arise when we have a local (register) | |
2161 | variable or a formal (register) parameter which doesn't quite | |
2162 | fill up an entire register. For now, just assume that it is | |
2163 | legitimate to make the Dwarf info refer to the whole register | |
2164 | which contains the given subreg. */ | |
2165 | ||
701e46d0 | 2166 | rtl = SUBREG_REG (rtl); |
e8363d4c | 2167 | /* Drop thru. */ |
2168 | ||
2169 | case REG: | |
2170 | ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG); | |
017ffcef | 2171 | output_reg_number (rtl); |
e8363d4c | 2172 | break; |
2173 | ||
2174 | case MEM: | |
2175 | output_mem_loc_descriptor (XEXP (rtl, 0)); | |
2176 | break; | |
2177 | ||
2178 | default: | |
2179 | abort (); /* Should never happen */ | |
2180 | } | |
2181 | } | |
2182 | ||
2183 | /* Given a tree node describing an array bound (either lower or upper) | |
8ec3a57b | 2184 | output a representation for that bound. DIM_NUM is used for |
2185 | multi-dimensional arrays and U_OR_L disgnates upper or lower | |
2186 | bound. */ | |
e8363d4c | 2187 | |
2188 | static void | |
8ec3a57b | 2189 | output_bound_representation (tree bound, unsigned int dim_num, char u_or_l) |
e8363d4c | 2190 | { |
2191 | switch (TREE_CODE (bound)) | |
2192 | { | |
2193 | ||
37e0360c | 2194 | case ERROR_MARK: |
2195 | return; | |
e8363d4c | 2196 | |
2197 | /* All fixed-bounds are represented by INTEGER_CST nodes. */ | |
2198 | ||
37e0360c | 2199 | case INTEGER_CST: |
5d844ba2 | 2200 | if (host_integerp (bound, 0)) |
2201 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, tree_low_cst (bound, 0)); | |
37e0360c | 2202 | break; |
2203 | ||
2204 | default: | |
e8363d4c | 2205 | |
2206 | /* Dynamic bounds may be represented by NOP_EXPR nodes containing | |
37e0360c | 2207 | SAVE_EXPR nodes, in which case we can do something, or as |
2208 | an expression, which we cannot represent. */ | |
2209 | { | |
2210 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2211 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2212 | ||
2213 | sprintf (begin_label, BOUND_BEGIN_LABEL_FMT, | |
2214 | current_dienum, dim_num, u_or_l); | |
2215 | ||
2216 | sprintf (end_label, BOUND_END_LABEL_FMT, | |
2217 | current_dienum, dim_num, u_or_l); | |
2218 | ||
2219 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); | |
2220 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
2221 | ||
2222 | /* If optimization is turned on, the SAVE_EXPRs that describe | |
2223 | how to access the upper bound values are essentially bogus. | |
2224 | They only describe (at best) how to get at these values at | |
2225 | the points in the generated code right after they have just | |
2226 | been computed. Worse yet, in the typical case, the upper | |
2227 | bound values will not even *be* computed in the optimized | |
2228 | code, so these SAVE_EXPRs are entirely bogus. | |
2229 | ||
2230 | In order to compensate for this fact, we check here to see | |
2231 | if optimization is enabled, and if so, we effectively create | |
2232 | an empty location description for the (unknown and unknowable) | |
2233 | upper bound. | |
2234 | ||
2235 | This should not cause too much trouble for existing (stupid?) | |
2236 | debuggers because they have to deal with empty upper bounds | |
2237 | location descriptions anyway in order to be able to deal with | |
2238 | incomplete array types. | |
2239 | ||
2240 | Of course an intelligent debugger (GDB?) should be able to | |
2241 | comprehend that a missing upper bound specification in a | |
2242 | array type used for a storage class `auto' local array variable | |
2243 | indicates that the upper bound is both unknown (at compile- | |
6312a35e | 2244 | time) and unknowable (at run-time) due to optimization. */ |
37e0360c | 2245 | |
2246 | if (! optimize) | |
2247 | { | |
2248 | while (TREE_CODE (bound) == NOP_EXPR | |
2249 | || TREE_CODE (bound) == CONVERT_EXPR) | |
2250 | bound = TREE_OPERAND (bound, 0); | |
e8363d4c | 2251 | |
8ec3a57b | 2252 | if (TREE_CODE (bound) == SAVE_EXPR |
13c773a7 | 2253 | && SAVE_EXPR_RTL (bound)) |
37e0360c | 2254 | output_loc_descriptor |
6182a80f | 2255 | (eliminate_regs (SAVE_EXPR_RTL (bound), 0, NULL_RTX)); |
37e0360c | 2256 | } |
e8363d4c | 2257 | |
37e0360c | 2258 | ASM_OUTPUT_LABEL (asm_out_file, end_label); |
2259 | } | |
2260 | break; | |
e8363d4c | 2261 | |
e8363d4c | 2262 | } |
2263 | } | |
2264 | ||
2265 | /* Recursive function to output a sequence of value/name pairs for | |
2266 | enumeration constants in reversed order. This is called from | |
2267 | enumeration_type_die. */ | |
2268 | ||
2269 | static void | |
8ec3a57b | 2270 | output_enumeral_list (tree link) |
e8363d4c | 2271 | { |
2272 | if (link) | |
2273 | { | |
2274 | output_enumeral_list (TREE_CHAIN (link)); | |
5d844ba2 | 2275 | |
2276 | if (host_integerp (TREE_VALUE (link), 0)) | |
2277 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, | |
2278 | tree_low_cst (TREE_VALUE (link), 0)); | |
2279 | ||
01e45963 | 2280 | ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, |
e8363d4c | 2281 | IDENTIFIER_POINTER (TREE_PURPOSE (link))); |
2282 | } | |
2283 | } | |
2284 | ||
ffb15922 | 2285 | /* Given an unsigned value, round it up to the lowest multiple of `boundary' |
2286 | which is not less than the value itself. */ | |
2287 | ||
5d844ba2 | 2288 | static inline HOST_WIDE_INT |
8ec3a57b | 2289 | ceiling (HOST_WIDE_INT value, unsigned int boundary) |
ffb15922 | 2290 | { |
2291 | return (((value + boundary - 1) / boundary) * boundary); | |
2292 | } | |
2293 | ||
2294 | /* Given a pointer to what is assumed to be a FIELD_DECL node, return a | |
2295 | pointer to the declared type for the relevant field variable, or return | |
2296 | `integer_type_node' if the given node turns out to be an ERROR_MARK node. */ | |
2297 | ||
7bfbda1f | 2298 | static inline tree |
8ec3a57b | 2299 | field_type (tree decl) |
ffb15922 | 2300 | { |
19cb6b50 | 2301 | tree type; |
ffb15922 | 2302 | |
2303 | if (TREE_CODE (decl) == ERROR_MARK) | |
2304 | return integer_type_node; | |
2305 | ||
2306 | type = DECL_BIT_FIELD_TYPE (decl); | |
2307 | if (type == NULL) | |
2308 | type = TREE_TYPE (decl); | |
2309 | return type; | |
2310 | } | |
2311 | ||
2312 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE | |
2313 | node, return the alignment in bits for the type, or else return | |
2314 | BITS_PER_WORD if the node actually turns out to be an ERROR_MARK node. */ | |
2315 | ||
5d844ba2 | 2316 | static inline unsigned int |
8ec3a57b | 2317 | simple_type_align_in_bits (tree type) |
ffb15922 | 2318 | { |
2319 | return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; | |
2320 | } | |
2321 | ||
2322 | /* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE | |
2323 | node, return the size in bits for the type if it is a constant, or | |
2324 | else return the alignment for the type if the type's size is not | |
2325 | constant, or else return BITS_PER_WORD if the type actually turns out | |
2326 | to be an ERROR_MARK node. */ | |
2327 | ||
5d844ba2 | 2328 | static inline unsigned HOST_WIDE_INT |
8ec3a57b | 2329 | simple_type_size_in_bits (tree type) |
ffb15922 | 2330 | { |
9c0f0e88 | 2331 | tree type_size_tree; |
2332 | ||
ffb15922 | 2333 | if (TREE_CODE (type) == ERROR_MARK) |
2334 | return BITS_PER_WORD; | |
9c0f0e88 | 2335 | type_size_tree = TYPE_SIZE (type); |
ffb15922 | 2336 | |
9c0f0e88 | 2337 | if (type_size_tree == NULL_TREE) |
2338 | return 0; | |
2339 | if (! host_integerp (type_size_tree, 1)) | |
2340 | return TYPE_ALIGN (type); | |
2341 | return tree_low_cst (type_size_tree, 1); | |
ffb15922 | 2342 | } |
2343 | ||
2344 | /* Given a pointer to what is assumed to be a FIELD_DECL node, compute and | |
2345 | return the byte offset of the lowest addressed byte of the "containing | |
2346 | object" for the given FIELD_DECL, or return 0 if we are unable to deter- | |
2347 | mine what that offset is, either because the argument turns out to be a | |
2348 | pointer to an ERROR_MARK node, or because the offset is actually variable. | |
2349 | (We can't handle the latter case just yet.) */ | |
2350 | ||
5d844ba2 | 2351 | static HOST_WIDE_INT |
8ec3a57b | 2352 | field_byte_offset (tree decl) |
ffb15922 | 2353 | { |
5d844ba2 | 2354 | unsigned int type_align_in_bytes; |
2355 | unsigned int type_align_in_bits; | |
2356 | unsigned HOST_WIDE_INT type_size_in_bits; | |
2357 | HOST_WIDE_INT object_offset_in_align_units; | |
2358 | HOST_WIDE_INT object_offset_in_bits; | |
2359 | HOST_WIDE_INT object_offset_in_bytes; | |
2360 | tree type; | |
2361 | tree field_size_tree; | |
2362 | HOST_WIDE_INT bitpos_int; | |
2363 | HOST_WIDE_INT deepest_bitpos; | |
2364 | unsigned HOST_WIDE_INT field_size_in_bits; | |
ffb15922 | 2365 | |
2366 | if (TREE_CODE (decl) == ERROR_MARK) | |
2367 | return 0; | |
2368 | ||
2369 | if (TREE_CODE (decl) != FIELD_DECL) | |
2370 | abort (); | |
2371 | ||
2372 | type = field_type (decl); | |
ffb15922 | 2373 | field_size_tree = DECL_SIZE (decl); |
2374 | ||
9c0f0e88 | 2375 | /* The size could be unspecified if there was an error, or for |
2376 | a flexible array member. */ | |
1373dc94 | 2377 | if (! field_size_tree) |
9c0f0e88 | 2378 | field_size_tree = bitsize_zero_node; |
5d844ba2 | 2379 | |
ffb15922 | 2380 | /* We cannot yet cope with fields whose positions or sizes are variable, |
2381 | so for now, when we see such things, we simply return 0. Someday, | |
2382 | we may be able to handle such cases, but it will be damn difficult. */ | |
2383 | ||
5d844ba2 | 2384 | if (! host_integerp (bit_position (decl), 0) |
2385 | || ! host_integerp (field_size_tree, 1)) | |
ffb15922 | 2386 | return 0; |
ffb15922 | 2387 | |
5d844ba2 | 2388 | bitpos_int = int_bit_position (decl); |
2389 | field_size_in_bits = tree_low_cst (field_size_tree, 1); | |
ffb15922 | 2390 | |
2391 | type_size_in_bits = simple_type_size_in_bits (type); | |
ffb15922 | 2392 | type_align_in_bits = simple_type_align_in_bits (type); |
2393 | type_align_in_bytes = type_align_in_bits / BITS_PER_UNIT; | |
2394 | ||
2395 | /* Note that the GCC front-end doesn't make any attempt to keep track | |
2396 | of the starting bit offset (relative to the start of the containing | |
2397 | structure type) of the hypothetical "containing object" for a bit- | |
2398 | field. Thus, when computing the byte offset value for the start of | |
2399 | the "containing object" of a bit-field, we must deduce this infor- | |
2400 | mation on our own. | |
2401 | ||
2402 | This can be rather tricky to do in some cases. For example, handling | |
2403 | the following structure type definition when compiling for an i386/i486 | |
2404 | target (which only aligns long long's to 32-bit boundaries) can be very | |
2405 | tricky: | |
2406 | ||
2407 | struct S { | |
2408 | int field1; | |
2409 | long long field2:31; | |
2410 | }; | |
2411 | ||
2412 | Fortunately, there is a simple rule-of-thumb which can be used in such | |
2413 | cases. When compiling for an i386/i486, GCC will allocate 8 bytes for | |
2414 | the structure shown above. It decides to do this based upon one simple | |
2415 | rule for bit-field allocation. Quite simply, GCC allocates each "con- | |
2416 | taining object" for each bit-field at the first (i.e. lowest addressed) | |
2417 | legitimate alignment boundary (based upon the required minimum alignment | |
2418 | for the declared type of the field) which it can possibly use, subject | |
2419 | to the condition that there is still enough available space remaining | |
2420 | in the containing object (when allocated at the selected point) to | |
99c2edb0 | 2421 | fully accommodate all of the bits of the bit-field itself. |
ffb15922 | 2422 | |
2423 | This simple rule makes it obvious why GCC allocates 8 bytes for each | |
2424 | object of the structure type shown above. When looking for a place to | |
2425 | allocate the "containing object" for `field2', the compiler simply tries | |
2426 | to allocate a 64-bit "containing object" at each successive 32-bit | |
2427 | boundary (starting at zero) until it finds a place to allocate that 64- | |
2428 | bit field such that at least 31 contiguous (and previously unallocated) | |
2429 | bits remain within that selected 64 bit field. (As it turns out, for | |
2430 | the example above, the compiler finds that it is OK to allocate the | |
2431 | "containing object" 64-bit field at bit-offset zero within the | |
2432 | structure type.) | |
2433 | ||
2434 | Here we attempt to work backwards from the limited set of facts we're | |
2435 | given, and we try to deduce from those facts, where GCC must have | |
2436 | believed that the containing object started (within the structure type). | |
2437 | ||
2438 | The value we deduce is then used (by the callers of this routine) to | |
2439 | generate AT_location and AT_bit_offset attributes for fields (both | |
6312a35e | 2440 | bit-fields and, in the case of AT_location, regular fields as well). */ |
ffb15922 | 2441 | |
2442 | /* Figure out the bit-distance from the start of the structure to the | |
2443 | "deepest" bit of the bit-field. */ | |
2444 | deepest_bitpos = bitpos_int + field_size_in_bits; | |
2445 | ||
2446 | /* This is the tricky part. Use some fancy footwork to deduce where the | |
2447 | lowest addressed bit of the containing object must be. */ | |
2448 | object_offset_in_bits | |
2449 | = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits; | |
2450 | ||
2451 | /* Compute the offset of the containing object in "alignment units". */ | |
2452 | object_offset_in_align_units = object_offset_in_bits / type_align_in_bits; | |
2453 | ||
2454 | /* Compute the offset of the containing object in bytes. */ | |
2455 | object_offset_in_bytes = object_offset_in_align_units * type_align_in_bytes; | |
2456 | ||
30c1e765 | 2457 | /* The above code assumes that the field does not cross an alignment |
2458 | boundary. This can happen if PCC_BITFIELD_TYPE_MATTERS is not defined, | |
2459 | or if the structure is packed. If this happens, then we get an object | |
2460 | which starts after the bitfield, which means that the bit offset is | |
2461 | negative. Gdb fails when given negative bit offsets. We avoid this | |
2462 | by recomputing using the first bit of the bitfield. This will give | |
2463 | us an object which does not completely contain the bitfield, but it | |
39173548 | 2464 | will be aligned, and it will contain the first bit of the bitfield. |
2465 | ||
2466 | However, only do this for a BYTES_BIG_ENDIAN target. For a | |
2467 | ! BYTES_BIG_ENDIAN target, bitpos_int + field_size_in_bits is the first | |
2468 | first bit of the bitfield. If we recompute using bitpos_int + 1 below, | |
2469 | then we end up computing the object byte offset for the wrong word of the | |
2470 | desired bitfield, which in turn causes the field offset to be negative | |
2471 | in bit_offset_attribute. */ | |
2472 | if (BYTES_BIG_ENDIAN | |
2473 | && object_offset_in_bits > bitpos_int) | |
30c1e765 | 2474 | { |
2475 | deepest_bitpos = bitpos_int + 1; | |
2476 | object_offset_in_bits | |
2477 | = ceiling (deepest_bitpos, type_align_in_bits) - type_size_in_bits; | |
2478 | object_offset_in_align_units = (object_offset_in_bits | |
2479 | / type_align_in_bits); | |
2480 | object_offset_in_bytes = (object_offset_in_align_units | |
2481 | * type_align_in_bytes); | |
2482 | } | |
2483 | ||
ffb15922 | 2484 | return object_offset_in_bytes; |
2485 | } | |
2486 | ||
e8363d4c | 2487 | /****************************** attributes *********************************/ |
2488 | ||
2489 | /* The following routines are responsible for writing out the various types | |
2490 | of Dwarf attributes (and any following data bytes associated with them). | |
2491 | These routines are listed in order based on the numerical codes of their | |
2492 | associated attributes. */ | |
2493 | ||
2494 | /* Generate an AT_sibling attribute. */ | |
2495 | ||
7bfbda1f | 2496 | static inline void |
8ec3a57b | 2497 | sibling_attribute (void) |
e8363d4c | 2498 | { |
2499 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2500 | ||
2501 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling); | |
2502 | sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM); | |
2503 | ASM_OUTPUT_DWARF_REF (asm_out_file, label); | |
2504 | } | |
2505 | ||
2506 | /* Output the form of location attributes suitable for whole variables and | |
2507 | whole parameters. Note that the location attributes for struct fields | |
2508 | are generated by the routine `data_member_location_attribute' below. */ | |
2509 | ||
2510 | static void | |
8ec3a57b | 2511 | location_attribute (rtx rtl) |
e8363d4c | 2512 | { |
2513 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2514 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2515 | ||
2516 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location); | |
2517 | sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum); | |
2518 | sprintf (end_label, LOC_END_LABEL_FMT, current_dienum); | |
2519 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); | |
2520 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
2521 | ||
2522 | /* Handle a special case. If we are about to output a location descriptor | |
c6396a0b | 2523 | for a variable or parameter which has been optimized out of existence, |
e8363d4c | 2524 | don't do that. Instead we output a zero-length location descriptor |
372da78f | 2525 | value as part of the location attribute. |
2526 | ||
99c2edb0 | 2527 | A variable which has been optimized out of existence will have a |
372da78f | 2528 | DECL_RTL value which denotes a pseudo-reg. |
2529 | ||
2530 | Currently, in some rare cases, variables can have DECL_RTL values | |
2531 | which look like (MEM (REG pseudo-reg#)). These cases are due to | |
2532 | bugs elsewhere in the compiler. We treat such cases | |
99c2edb0 | 2533 | as if the variable(s) in question had been optimized out of existence. |
372da78f | 2534 | |
2535 | Note that in all cases where we wish to express the fact that a | |
99c2edb0 | 2536 | variable has been optimized out of existence, we do not simply |
372da78f | 2537 | suppress the generation of the entire location attribute because |
2538 | the absence of a location attribute in certain kinds of DIEs is | |
2539 | used to indicate something else entirely... i.e. that the DIE | |
c3418f42 | 2540 | represents an object declaration, but not a definition. So saith |
372da78f | 2541 | the PLSIG. |
2542 | */ | |
e8363d4c | 2543 | |
372da78f | 2544 | if (! is_pseudo_reg (rtl) |
2545 | && (GET_CODE (rtl) != MEM || ! is_pseudo_reg (XEXP (rtl, 0)))) | |
34c82c40 | 2546 | output_loc_descriptor (rtl); |
e8363d4c | 2547 | |
2548 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
2549 | } | |
2550 | ||
2551 | /* Output the specialized form of location attribute used for data members | |
ffb15922 | 2552 | of struct and union types. |
88ef61d1 | 2553 | |
2554 | In the special case of a FIELD_DECL node which represents a bit-field, | |
2555 | the "offset" part of this special location descriptor must indicate the | |
2556 | distance in bytes from the lowest-addressed byte of the containing | |
2557 | struct or union type to the lowest-addressed byte of the "containing | |
ffb15922 | 2558 | object" for the bit-field. (See the `field_byte_offset' function above.) |
88ef61d1 | 2559 | |
2560 | For any given bit-field, the "containing object" is a hypothetical | |
2561 | object (of some integral or enum type) within which the given bit-field | |
2562 | lives. The type of this hypothetical "containing object" is always the | |
ffb15922 | 2563 | same as the declared type of the individual bit-field itself (for GCC |
2564 | anyway... the DWARF spec doesn't actually mandate this). | |
88ef61d1 | 2565 | |
2566 | Note that it is the size (in bytes) of the hypothetical "containing | |
2567 | object" which will be given in the AT_byte_size attribute for this | |
ffb15922 | 2568 | bit-field. (See the `byte_size_attribute' function below.) It is |
2569 | also used when calculating the value of the AT_bit_offset attribute. | |
a92771b8 | 2570 | (See the `bit_offset_attribute' function below.) */ |
88ef61d1 | 2571 | |
e8363d4c | 2572 | static void |
8ec3a57b | 2573 | data_member_location_attribute (tree t) |
e8363d4c | 2574 | { |
19cb6b50 | 2575 | unsigned object_offset_in_bytes; |
e8363d4c | 2576 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
2577 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
88ef61d1 | 2578 | |
7524eb42 | 2579 | if (TREE_CODE (t) == TREE_VEC) |
5d844ba2 | 2580 | object_offset_in_bytes = tree_low_cst (BINFO_OFFSET (t), 0); |
7524eb42 | 2581 | else |
2582 | object_offset_in_bytes = field_byte_offset (t); | |
2583 | ||
e8363d4c | 2584 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location); |
2585 | sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum); | |
2586 | sprintf (end_label, LOC_END_LABEL_FMT, current_dienum); | |
2587 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); | |
2588 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
2589 | ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST); | |
ffb15922 | 2590 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, object_offset_in_bytes); |
e8363d4c | 2591 | ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD); |
2592 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
2593 | } | |
2594 | ||
2595 | /* Output an AT_const_value attribute for a variable or a parameter which | |
2596 | does not have a "location" either in memory or in a register. These | |
2597 | things can arise in GNU C when a constant is passed as an actual | |
2598 | parameter to an inlined function. They can also arise in C++ where | |
2599 | declared constants do not necessarily get memory "homes". */ | |
2600 | ||
2601 | static void | |
8ec3a57b | 2602 | const_value_attribute (rtx rtl) |
e8363d4c | 2603 | { |
2604 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2605 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2606 | ||
2607 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4); | |
2608 | sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum); | |
2609 | sprintf (end_label, LOC_END_LABEL_FMT, current_dienum); | |
2610 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label); | |
2611 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
2612 | ||
2613 | switch (GET_CODE (rtl)) | |
2614 | { | |
2615 | case CONST_INT: | |
2616 | /* Note that a CONST_INT rtx could represent either an integer or | |
2617 | a floating-point constant. A CONST_INT is used whenever the | |
2618 | constant will fit into a single word. In all such cases, the | |
2619 | original mode of the constant value is wiped out, and the | |
2620 | CONST_INT rtx is assigned VOIDmode. Since we no longer have | |
2621 | precise mode information for these constants, we always just | |
2622 | output them using 4 bytes. */ | |
2623 | ||
2624 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl)); | |
2625 | break; | |
2626 | ||
2627 | case CONST_DOUBLE: | |
2628 | /* Note that a CONST_DOUBLE rtx could represent either an integer | |
2629 | or a floating-point constant. A CONST_DOUBLE is used whenever | |
2630 | the constant requires more than one word in order to be adequately | |
2631 | represented. In all such cases, the original mode of the constant | |
2632 | value is preserved as the mode of the CONST_DOUBLE rtx, but for | |
2633 | simplicity we always just output CONST_DOUBLEs using 8 bytes. */ | |
2634 | ||
2635 | ASM_OUTPUT_DWARF_DATA8 (asm_out_file, | |
5d844ba2 | 2636 | (unsigned int) CONST_DOUBLE_HIGH (rtl), |
2637 | (unsigned int) CONST_DOUBLE_LOW (rtl)); | |
e8363d4c | 2638 | break; |
2639 | ||
2640 | case CONST_STRING: | |
01e45963 | 2641 | ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, XSTR (rtl, 0)); |
e8363d4c | 2642 | break; |
2643 | ||
2644 | case SYMBOL_REF: | |
2645 | case LABEL_REF: | |
2646 | case CONST: | |
2647 | ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl); | |
2648 | break; | |
2649 | ||
2650 | case PLUS: | |
2651 | /* In cases where an inlined instance of an inline function is passed | |
2652 | the address of an `auto' variable (which is local to the caller) | |
2653 | we can get a situation where the DECL_RTL of the artificial | |
2654 | local variable (for the inlining) which acts as a stand-in for | |
2655 | the corresponding formal parameter (of the inline function) | |
2656 | will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). | |
2657 | This is not exactly a compile-time constant expression, but it | |
2658 | isn't the address of the (artificial) local variable either. | |
2659 | Rather, it represents the *value* which the artificial local | |
2660 | variable always has during its lifetime. We currently have no | |
2661 | way to represent such quasi-constant values in Dwarf, so for now | |
2662 | we just punt and generate an AT_const_value attribute with form | |
2663 | FORM_BLOCK4 and a length of zero. */ | |
2664 | break; | |
ffb15922 | 2665 | |
2666 | default: | |
2667 | abort (); /* No other kinds of rtx should be possible here. */ | |
e8363d4c | 2668 | } |
2669 | ||
2670 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
2671 | } | |
2672 | ||
2673 | /* Generate *either* an AT_location attribute or else an AT_const_value | |
2674 | data attribute for a variable or a parameter. We generate the | |
2675 | AT_const_value attribute only in those cases where the given | |
2676 | variable or parameter does not have a true "location" either in | |
2677 | memory or in a register. This can happen (for example) when a | |
2678 | constant is passed as an actual argument in a call to an inline | |
2679 | function. (It's possible that these things can crop up in other | |
2680 | ways also.) Note that one type of constant value which can be | |
2681 | passed into an inlined function is a constant pointer. This can | |
2682 | happen for example if an actual argument in an inlined function | |
2683 | call evaluates to a compile-time constant address. */ | |
2684 | ||
2685 | static void | |
8ec3a57b | 2686 | location_or_const_value_attribute (tree decl) |
e8363d4c | 2687 | { |
19cb6b50 | 2688 | rtx rtl; |
e8363d4c | 2689 | |
2690 | if (TREE_CODE (decl) == ERROR_MARK) | |
2691 | return; | |
2692 | ||
2693 | if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL)) | |
bad5b016 | 2694 | { |
ef0c6585 | 2695 | /* Should never happen. */ |
2696 | abort (); | |
2697 | return; | |
bad5b016 | 2698 | } |
e8363d4c | 2699 | |
ef0c6585 | 2700 | /* Here we have to decide where we are going to say the parameter "lives" |
2701 | (as far as the debugger is concerned). We only have a couple of choices. | |
2702 | GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. DECL_RTL | |
2703 | normally indicates where the parameter lives during most of the activa- | |
2704 | tion of the function. If optimization is enabled however, this could | |
2705 | be either NULL or else a pseudo-reg. Both of those cases indicate that | |
2706 | the parameter doesn't really live anywhere (as far as the code generation | |
2707 | parts of GCC are concerned) during most of the function's activation. | |
2708 | That will happen (for example) if the parameter is never referenced | |
2709 | within the function. | |
2710 | ||
2711 | We could just generate a location descriptor here for all non-NULL | |
2712 | non-pseudo values of DECL_RTL and ignore all of the rest, but we can | |
2713 | be a little nicer than that if we also consider DECL_INCOMING_RTL in | |
2714 | cases where DECL_RTL is NULL or is a pseudo-reg. | |
2715 | ||
2716 | Note however that we can only get away with using DECL_INCOMING_RTL as | |
2717 | a backup substitute for DECL_RTL in certain limited cases. In cases | |
2718 | where DECL_ARG_TYPE(decl) indicates the same type as TREE_TYPE(decl) | |
2719 | we can be sure that the parameter was passed using the same type as it | |
2720 | is declared to have within the function, and that its DECL_INCOMING_RTL | |
2721 | points us to a place where a value of that type is passed. In cases | |
2722 | where DECL_ARG_TYPE(decl) and TREE_TYPE(decl) are different types | |
2723 | however, we cannot (in general) use DECL_INCOMING_RTL as a backup | |
2724 | substitute for DECL_RTL because in these cases, DECL_INCOMING_RTL | |
2725 | points us to a value of some type which is *different* from the type | |
2726 | of the parameter itself. Thus, if we tried to use DECL_INCOMING_RTL | |
2727 | to generate a location attribute in such cases, the debugger would | |
2728 | end up (for example) trying to fetch a `float' from a place which | |
2729 | actually contains the first part of a `double'. That would lead to | |
2730 | really incorrect and confusing output at debug-time, and we don't | |
2731 | want that now do we? | |
2732 | ||
2733 | So in general, we DO NOT use DECL_INCOMING_RTL as a backup for DECL_RTL | |
2734 | in cases where DECL_ARG_TYPE(decl) != TREE_TYPE(decl). There are a | |
2735 | couple of cute exceptions however. On little-endian machines we can | |
2736 | get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE(decl) is | |
2737 | not the same as TREE_TYPE(decl) but only when DECL_ARG_TYPE(decl) is | |
2738 | an integral type which is smaller than TREE_TYPE(decl). These cases | |
2739 | arise when (on a little-endian machine) a non-prototyped function has | |
2740 | a parameter declared to be of type `short' or `char'. In such cases, | |
2741 | TREE_TYPE(decl) will be `short' or `char', DECL_ARG_TYPE(decl) will be | |
2742 | `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the | |
2743 | passed `int' value. If the debugger then uses that address to fetch a | |
2744 | `short' or a `char' (on a little-endian machine) the result will be the | |
2745 | correct data, so we allow for such exceptional cases below. | |
2746 | ||
2747 | Note that our goal here is to describe the place where the given formal | |
2748 | parameter lives during most of the function's activation (i.e. between | |
2749 | the end of the prologue and the start of the epilogue). We'll do that | |
2750 | as best as we can. Note however that if the given formal parameter is | |
2751 | modified sometime during the execution of the function, then a stack | |
2752 | backtrace (at debug-time) will show the function as having been called | |
2753 | with the *new* value rather than the value which was originally passed | |
2754 | in. This happens rarely enough that it is not a major problem, but it | |
2755 | *is* a problem, and I'd like to fix it. A future version of dwarfout.c | |
2756 | may generate two additional attributes for any given TAG_formal_parameter | |
2757 | DIE which will describe the "passed type" and the "passed location" for | |
2758 | the given formal parameter in addition to the attributes we now generate | |
2759 | to indicate the "declared type" and the "active location" for each | |
2760 | parameter. This additional set of attributes could be used by debuggers | |
2761 | for stack backtraces. | |
2762 | ||
2763 | Separately, note that sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL | |
2764 | can be NULL also. This happens (for example) for inlined-instances of | |
2765 | inline function formal parameters which are never referenced. This really | |
2766 | shouldn't be happening. All PARM_DECL nodes should get valid non-NULL | |
2767 | DECL_INCOMING_RTL values, but integrate.c doesn't currently generate | |
2768 | these values for inlined instances of inline function parameters, so | |
ad87de1e | 2769 | when we see such cases, we are just out-of-luck for the time |
ef0c6585 | 2770 | being (until integrate.c gets fixed). |
2771 | */ | |
2772 | ||
2773 | /* Use DECL_RTL as the "location" unless we find something better. */ | |
2774 | rtl = DECL_RTL (decl); | |
2775 | ||
2776 | if (TREE_CODE (decl) == PARM_DECL) | |
2777 | if (rtl == NULL_RTX || is_pseudo_reg (rtl)) | |
2778 | { | |
2779 | /* This decl represents a formal parameter which was optimized out. */ | |
1eefe280 | 2780 | tree declared_type = type_main_variant (TREE_TYPE (decl)); |
2781 | tree passed_type = type_main_variant (DECL_ARG_TYPE (decl)); | |
ef0c6585 | 2782 | |
2783 | /* Note that DECL_INCOMING_RTL may be NULL in here, but we handle | |
2784 | *all* cases where (rtl == NULL_RTX) just below. */ | |
2785 | ||
2786 | if (declared_type == passed_type) | |
2787 | rtl = DECL_INCOMING_RTL (decl); | |
51356f86 | 2788 | else if (! BYTES_BIG_ENDIAN) |
ef0c6585 | 2789 | if (TREE_CODE (declared_type) == INTEGER_TYPE) |
4b72716d | 2790 | /* NMS WTF? */ |
ef0c6585 | 2791 | if (TYPE_SIZE (declared_type) <= TYPE_SIZE (passed_type)) |
2792 | rtl = DECL_INCOMING_RTL (decl); | |
ef0c6585 | 2793 | } |
2794 | ||
2795 | if (rtl == NULL_RTX) | |
e8363d4c | 2796 | return; |
2797 | ||
6182a80f | 2798 | rtl = eliminate_regs (rtl, 0, NULL_RTX); |
34c82c40 | 2799 | #ifdef LEAF_REG_REMAP |
b3b67b7c | 2800 | if (current_function_uses_only_leaf_regs) |
bb83eb96 | 2801 | leaf_renumber_regs_insn (rtl); |
34c82c40 | 2802 | #endif |
2803 | ||
e8363d4c | 2804 | switch (GET_CODE (rtl)) |
2805 | { | |
0dbd1c74 | 2806 | case ADDRESSOF: |
2807 | /* The address of a variable that was optimized away; don't emit | |
2808 | anything. */ | |
2809 | break; | |
2810 | ||
e8363d4c | 2811 | case CONST_INT: |
2812 | case CONST_DOUBLE: | |
2813 | case CONST_STRING: | |
2814 | case SYMBOL_REF: | |
2815 | case LABEL_REF: | |
2816 | case CONST: | |
2817 | case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ | |
2818 | const_value_attribute (rtl); | |
2819 | break; | |
2820 | ||
2821 | case MEM: | |
2822 | case REG: | |
2823 | case SUBREG: | |
2824 | location_attribute (rtl); | |
2825 | break; | |
2826 | ||
28746cec | 2827 | case CONCAT: |
2828 | /* ??? CONCAT is used for complex variables, which may have the real | |
2829 | part stored in one place and the imag part stored somewhere else. | |
2830 | DWARF1 has no way to describe a variable that lives in two different | |
2831 | places, so we just describe where the first part lives, and hope that | |
2832 | the second part is stored after it. */ | |
2833 | location_attribute (XEXP (rtl, 0)); | |
2834 | break; | |
2835 | ||
e8363d4c | 2836 | default: |
2837 | abort (); /* Should never happen. */ | |
2838 | } | |
2839 | } | |
2840 | ||
2841 | /* Generate an AT_name attribute given some string value to be included as | |
88ef61d1 | 2842 | the value of the attribute. */ |
e8363d4c | 2843 | |
7bfbda1f | 2844 | static inline void |
8ec3a57b | 2845 | name_attribute (const char *name_string) |
e8363d4c | 2846 | { |
4e9830fe | 2847 | if (name_string && *name_string) |
2848 | { | |
2849 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name); | |
01e45963 | 2850 | ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, name_string); |
4e9830fe | 2851 | } |
e8363d4c | 2852 | } |
2853 | ||
7bfbda1f | 2854 | static inline void |
8ec3a57b | 2855 | fund_type_attribute (unsigned int ft_code) |
e8363d4c | 2856 | { |
2857 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type); | |
2858 | ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code); | |
2859 | } | |
2860 | ||
2861 | static void | |
8ec3a57b | 2862 | mod_fund_type_attribute (tree type, int decl_const, int decl_volatile) |
e8363d4c | 2863 | { |
2864 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2865 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2866 | ||
2867 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type); | |
2868 | sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum); | |
2869 | sprintf (end_label, MT_END_LABEL_FMT, current_dienum); | |
2870 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); | |
2871 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
2872 | write_modifier_bytes (type, decl_const, decl_volatile); | |
2873 | ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, | |
2874 | fundamental_type_code (root_type (type))); | |
2875 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
2876 | } | |
2877 | ||
7bfbda1f | 2878 | static inline void |
8ec3a57b | 2879 | user_def_type_attribute (tree type) |
e8363d4c | 2880 | { |
2881 | char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2882 | ||
2883 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type); | |
2884 | sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type)); | |
2885 | ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name); | |
2886 | } | |
2887 | ||
2888 | static void | |
8ec3a57b | 2889 | mod_u_d_type_attribute (tree type, int decl_const, int decl_volatile) |
e8363d4c | 2890 | { |
2891 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2892 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2893 | char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2894 | ||
2895 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type); | |
2896 | sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum); | |
2897 | sprintf (end_label, MT_END_LABEL_FMT, current_dienum); | |
2898 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); | |
2899 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
2900 | write_modifier_bytes (type, decl_const, decl_volatile); | |
2901 | sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type))); | |
2902 | ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name); | |
2903 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
2904 | } | |
2905 | ||
ffb15922 | 2906 | #ifdef USE_ORDERING_ATTRIBUTE |
7bfbda1f | 2907 | static inline void |
8ec3a57b | 2908 | ordering_attribute (unsigned ordering) |
e8363d4c | 2909 | { |
2910 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering); | |
2911 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering); | |
2912 | } | |
ffb15922 | 2913 | #endif /* defined(USE_ORDERING_ATTRIBUTE) */ |
e8363d4c | 2914 | |
2915 | /* Note that the block of subscript information for an array type also | |
2916 | includes information about the element type of type given array type. */ | |
2917 | ||
2918 | static void | |
8ec3a57b | 2919 | subscript_data_attribute (tree type) |
e8363d4c | 2920 | { |
19cb6b50 | 2921 | unsigned dimension_number; |
e8363d4c | 2922 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; |
2923 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
2924 | ||
2925 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data); | |
2926 | sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum); | |
2927 | sprintf (end_label, SS_END_LABEL_FMT, current_dienum); | |
2928 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); | |
2929 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
2930 | ||
2931 | /* The GNU compilers represent multidimensional array types as sequences | |
2932 | of one dimensional array types whose element types are themselves array | |
2933 | types. Here we squish that down, so that each multidimensional array | |
2934 | type gets only one array_type DIE in the Dwarf debugging info. The | |
2935 | draft Dwarf specification say that we are allowed to do this kind | |
2936 | of compression in C (because there is no difference between an | |
2937 | array or arrays and a multidimensional array in C) but for other | |
2938 | source languages (e.g. Ada) we probably shouldn't do this. */ | |
2939 | ||
2940 | for (dimension_number = 0; | |
2941 | TREE_CODE (type) == ARRAY_TYPE; | |
2942 | type = TREE_TYPE (type), dimension_number++) | |
2943 | { | |
19cb6b50 | 2944 | tree domain = TYPE_DOMAIN (type); |
e8363d4c | 2945 | |
2946 | /* Arrays come in three flavors. Unspecified bounds, fixed | |
2947 | bounds, and (in GNU C only) variable bounds. Handle all | |
2948 | three forms here. */ | |
2949 | ||
2950 | if (domain) | |
2951 | { | |
2952 | /* We have an array type with specified bounds. */ | |
2953 | ||
19cb6b50 | 2954 | tree lower = TYPE_MIN_VALUE (domain); |
2955 | tree upper = TYPE_MAX_VALUE (domain); | |
e8363d4c | 2956 | |
2957 | /* Handle only fundamental types as index types for now. */ | |
e8363d4c | 2958 | if (! type_is_fundamental (domain)) |
2959 | abort (); | |
2960 | ||
a92771b8 | 2961 | /* Output the representation format byte for this dimension. */ |
e8363d4c | 2962 | ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, |
f52483b5 | 2963 | FMT_CODE (1, TREE_CODE (lower) == INTEGER_CST, |
9c0f0e88 | 2964 | upper && TREE_CODE (upper) == INTEGER_CST)); |
e8363d4c | 2965 | |
2966 | /* Output the index type for this dimension. */ | |
e8363d4c | 2967 | ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, |
2968 | fundamental_type_code (domain)); | |
2969 | ||
2970 | /* Output the representation for the lower bound. */ | |
e8363d4c | 2971 | output_bound_representation (lower, dimension_number, 'l'); |
2972 | ||
2973 | /* Output the representation for the upper bound. */ | |
9c0f0e88 | 2974 | if (upper) |
2975 | output_bound_representation (upper, dimension_number, 'u'); | |
2976 | else | |
2977 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0); | |
e8363d4c | 2978 | } |
2979 | else | |
2980 | { | |
2981 | /* We have an array type with an unspecified length. For C and | |
2982 | C++ we can assume that this really means that (a) the index | |
2983 | type is an integral type, and (b) the lower bound is zero. | |
2984 | Note that Dwarf defines the representation of an unspecified | |
2985 | (upper) bound as being a zero-length location description. */ | |
2986 | ||
2987 | /* Output the array-bounds format byte. */ | |
2988 | ||
2989 | ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X); | |
2990 | ||
2991 | /* Output the (assumed) index type. */ | |
2992 | ||
2993 | ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer); | |
2994 | ||
2995 | /* Output the (assumed) lower bound (constant) value. */ | |
2996 | ||
2997 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); | |
2998 | ||
2999 | /* Output the (empty) location description for the upper bound. */ | |
3000 | ||
3001 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0); | |
3002 | } | |
3003 | } | |
3004 | ||
c3418f42 | 3005 | /* Output the prefix byte that says that the element type is coming up. */ |
e8363d4c | 3006 | |
3007 | ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET); | |
3008 | ||
3009 | /* Output a representation of the type of the elements of this array type. */ | |
3010 | ||
3011 | type_attribute (type, 0, 0); | |
3012 | ||
3013 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
3014 | } | |
3015 | ||
3016 | static void | |
8ec3a57b | 3017 | byte_size_attribute (tree tree_node) |
e8363d4c | 3018 | { |
19cb6b50 | 3019 | unsigned size; |
e8363d4c | 3020 | |
3021 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size); | |
3022 | switch (TREE_CODE (tree_node)) | |
3023 | { | |
3024 | case ERROR_MARK: | |
3025 | size = 0; | |
3026 | break; | |
3027 | ||
3028 | case ENUMERAL_TYPE: | |
3029 | case RECORD_TYPE: | |
3030 | case UNION_TYPE: | |
7f8a347a | 3031 | case QUAL_UNION_TYPE: |
399f9b5a | 3032 | case ARRAY_TYPE: |
e8363d4c | 3033 | size = int_size_in_bytes (tree_node); |
3034 | break; | |
3035 | ||
3036 | case FIELD_DECL: | |
88ef61d1 | 3037 | /* For a data member of a struct or union, the AT_byte_size is |
ffb15922 | 3038 | generally given as the number of bytes normally allocated for |
88ef61d1 | 3039 | an object of the *declared* type of the member itself. This |
3040 | is true even for bit-fields. */ | |
ffb15922 | 3041 | size = simple_type_size_in_bits (field_type (tree_node)) |
3042 | / BITS_PER_UNIT; | |
e8363d4c | 3043 | break; |
3044 | ||
3045 | default: | |
3046 | abort (); | |
3047 | } | |
88ef61d1 | 3048 | |
3049 | /* Note that `size' might be -1 when we get to this point. If it | |
3050 | is, that indicates that the byte size of the entity in question | |
3051 | is variable. We have no good way of expressing this fact in Dwarf | |
3052 | at the present time, so just let the -1 pass on through. */ | |
3053 | ||
e8363d4c | 3054 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size); |
3055 | } | |
3056 | ||
88ef61d1 | 3057 | /* For a FIELD_DECL node which represents a bit-field, output an attribute |
3058 | which specifies the distance in bits from the highest order bit of the | |
3059 | "containing object" for the bit-field to the highest order bit of the | |
3060 | bit-field itself. | |
3061 | ||
3062 | For any given bit-field, the "containing object" is a hypothetical | |
3063 | object (of some integral or enum type) within which the given bit-field | |
3064 | lives. The type of this hypothetical "containing object" is always the | |
3065 | same as the declared type of the individual bit-field itself. | |
3066 | ||
ffb15922 | 3067 | The determination of the exact location of the "containing object" for |
3068 | a bit-field is rather complicated. It's handled by the `field_byte_offset' | |
3069 | function (above). | |
3070 | ||
88ef61d1 | 3071 | Note that it is the size (in bytes) of the hypothetical "containing |
3072 | object" which will be given in the AT_byte_size attribute for this | |
7bfbda1f | 3073 | bit-field. (See `byte_size_attribute' above.) */ |
e8363d4c | 3074 | |
7bfbda1f | 3075 | static inline void |
8ec3a57b | 3076 | bit_offset_attribute (tree decl) |
e8363d4c | 3077 | { |
5d844ba2 | 3078 | HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl); |
3079 | tree type = DECL_BIT_FIELD_TYPE (decl); | |
3080 | HOST_WIDE_INT bitpos_int; | |
3081 | HOST_WIDE_INT highest_order_object_bit_offset; | |
3082 | HOST_WIDE_INT highest_order_field_bit_offset; | |
3083 | HOST_WIDE_INT bit_offset; | |
88ef61d1 | 3084 | |
7e2bfe1e | 3085 | /* Must be a bit field. */ |
3086 | if (!type | |
3087 | || TREE_CODE (decl) != FIELD_DECL) | |
3088 | abort (); | |
88ef61d1 | 3089 | |
5d844ba2 | 3090 | /* We can't yet handle bit-fields whose offsets or sizes are variable, so |
3091 | if we encounter such things, just return without generating any | |
3092 | attribute whatsoever. */ | |
88ef61d1 | 3093 | |
5d844ba2 | 3094 | if (! host_integerp (bit_position (decl), 0) |
3095 | || ! host_integerp (DECL_SIZE (decl), 1)) | |
88ef61d1 | 3096 | return; |
5d844ba2 | 3097 | |
3098 | bitpos_int = int_bit_position (decl); | |
88ef61d1 | 3099 | |
ffb15922 | 3100 | /* Note that the bit offset is always the distance (in bits) from the |
3101 | highest-order bit of the "containing object" to the highest-order | |
3102 | bit of the bit-field itself. Since the "high-order end" of any | |
3103 | object or field is different on big-endian and little-endian machines, | |
3104 | the computation below must take account of these differences. */ | |
88ef61d1 | 3105 | |
ffb15922 | 3106 | highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; |
3107 | highest_order_field_bit_offset = bitpos_int; | |
bad5b016 | 3108 | |
51356f86 | 3109 | if (! BYTES_BIG_ENDIAN) |
3110 | { | |
5d844ba2 | 3111 | highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 1); |
51356f86 | 3112 | highest_order_object_bit_offset += simple_type_size_in_bits (type); |
3113 | } | |
ffb15922 | 3114 | |
3115 | bit_offset = | |
51356f86 | 3116 | (! BYTES_BIG_ENDIAN |
3117 | ? highest_order_object_bit_offset - highest_order_field_bit_offset | |
3118 | : highest_order_field_bit_offset - highest_order_object_bit_offset); | |
e8363d4c | 3119 | |
3120 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset); | |
ffb15922 | 3121 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, bit_offset); |
e8363d4c | 3122 | } |
3123 | ||
3124 | /* For a FIELD_DECL node which represents a bit field, output an attribute | |
3125 | which specifies the length in bits of the given field. */ | |
3126 | ||
7bfbda1f | 3127 | static inline void |
8ec3a57b | 3128 | bit_size_attribute (tree decl) |
e8363d4c | 3129 | { |
7e2bfe1e | 3130 | /* Must be a field and a bit field. */ |
3131 | if (TREE_CODE (decl) != FIELD_DECL | |
3132 | || ! DECL_BIT_FIELD_TYPE (decl)) | |
3133 | abort (); | |
e8363d4c | 3134 | |
5d844ba2 | 3135 | if (host_integerp (DECL_SIZE (decl), 1)) |
3136 | { | |
3137 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size); | |
3138 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, | |
3139 | tree_low_cst (DECL_SIZE (decl), 1)); | |
3140 | } | |
e8363d4c | 3141 | } |
3142 | ||
3143 | /* The following routine outputs the `element_list' attribute for enumeration | |
3144 | type DIEs. The element_lits attribute includes the names and values of | |
3145 | all of the enumeration constants associated with the given enumeration | |
3146 | type. */ | |
3147 | ||
7bfbda1f | 3148 | static inline void |
8ec3a57b | 3149 | element_list_attribute (tree element) |
e8363d4c | 3150 | { |
3151 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3152 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3153 | ||
3154 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list); | |
3155 | sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum); | |
3156 | sprintf (end_label, EE_END_LABEL_FMT, current_dienum); | |
3157 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label); | |
3158 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
3159 | ||
3160 | /* Here we output a list of value/name pairs for each enumeration constant | |
3161 | defined for this enumeration type (as required), but we do it in REVERSE | |
3162 | order. The order is the one required by the draft #5 Dwarf specification | |
3163 | published by the UI/PLSIG. */ | |
3164 | ||
3165 | output_enumeral_list (element); /* Recursively output the whole list. */ | |
3166 | ||
3167 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
3168 | } | |
3169 | ||
3170 | /* Generate an AT_stmt_list attribute. These are normally present only in | |
3171 | DIEs with a TAG_compile_unit tag. */ | |
3172 | ||
7bfbda1f | 3173 | static inline void |
8ec3a57b | 3174 | stmt_list_attribute (const char *label) |
e8363d4c | 3175 | { |
3176 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list); | |
3177 | /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ | |
3178 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, label); | |
3179 | } | |
3180 | ||
3181 | /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or | |
3182 | for a subroutine DIE. */ | |
3183 | ||
7bfbda1f | 3184 | static inline void |
8ec3a57b | 3185 | low_pc_attribute (const char *asm_low_label) |
e8363d4c | 3186 | { |
3187 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc); | |
3188 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label); | |
3189 | } | |
3190 | ||
3191 | /* Generate an AT_high_pc attribute for a lexical_block DIE or for a | |
3192 | subroutine DIE. */ | |
3193 | ||
7bfbda1f | 3194 | static inline void |
8ec3a57b | 3195 | high_pc_attribute (const char *asm_high_label) |
e8363d4c | 3196 | { |
3197 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc); | |
3198 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label); | |
3199 | } | |
3200 | ||
cf6a3b88 | 3201 | /* Generate an AT_body_begin attribute for a subroutine DIE. */ |
3202 | ||
7bfbda1f | 3203 | static inline void |
8ec3a57b | 3204 | body_begin_attribute (const char *asm_begin_label) |
cf6a3b88 | 3205 | { |
3206 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_begin); | |
3207 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_begin_label); | |
3208 | } | |
3209 | ||
3210 | /* Generate an AT_body_end attribute for a subroutine DIE. */ | |
3211 | ||
7bfbda1f | 3212 | static inline void |
8ec3a57b | 3213 | body_end_attribute (const char *asm_end_label) |
cf6a3b88 | 3214 | { |
3215 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_body_end); | |
3216 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_end_label); | |
3217 | } | |
3218 | ||
e8363d4c | 3219 | /* Generate an AT_language attribute given a LANG value. These attributes |
3220 | are used only within TAG_compile_unit DIEs. */ | |
3221 | ||
7bfbda1f | 3222 | static inline void |
8ec3a57b | 3223 | language_attribute (unsigned int language_code) |
e8363d4c | 3224 | { |
3225 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language); | |
3226 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code); | |
3227 | } | |
3228 | ||
7bfbda1f | 3229 | static inline void |
8ec3a57b | 3230 | member_attribute (tree context) |
e8363d4c | 3231 | { |
3232 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3233 | ||
3234 | /* Generate this attribute only for members in C++. */ | |
3235 | ||
1adc7e47 | 3236 | if (context != NULL && is_tagged_type (context)) |
e8363d4c | 3237 | { |
3238 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member); | |
3239 | sprintf (label, TYPE_NAME_FMT, TYPE_UID (context)); | |
3240 | ASM_OUTPUT_DWARF_REF (asm_out_file, label); | |
3241 | } | |
3242 | } | |
3243 | ||
cb264b86 | 3244 | #if 0 |
b0acf022 | 3245 | #ifndef SL_BEGIN_LABEL_FMT |
3246 | #define SL_BEGIN_LABEL_FMT "*.L_sl%u" | |
3247 | #endif | |
3248 | #ifndef SL_END_LABEL_FMT | |
3249 | #define SL_END_LABEL_FMT "*.L_sl%u_e" | |
3250 | #endif | |
3251 | ||
7bfbda1f | 3252 | static inline void |
8ec3a57b | 3253 | string_length_attribute (tree upper_bound) |
e8363d4c | 3254 | { |
3255 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3256 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3257 | ||
3258 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length); | |
3259 | sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum); | |
3260 | sprintf (end_label, SL_END_LABEL_FMT, current_dienum); | |
3261 | ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); | |
3262 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
3263 | output_bound_representation (upper_bound, 0, 'u'); | |
3264 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
3265 | } | |
cb264b86 | 3266 | #endif |
e8363d4c | 3267 | |
7bfbda1f | 3268 | static inline void |
8ec3a57b | 3269 | comp_dir_attribute (const char *dirname) |
e8363d4c | 3270 | { |
3271 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir); | |
01e45963 | 3272 | ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname); |
e8363d4c | 3273 | } |
3274 | ||
7bfbda1f | 3275 | static inline void |
8ec3a57b | 3276 | sf_names_attribute (const char *sf_names_start_label) |
e8363d4c | 3277 | { |
3278 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names); | |
3279 | /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ | |
3280 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label); | |
3281 | } | |
3282 | ||
7bfbda1f | 3283 | static inline void |
8ec3a57b | 3284 | src_info_attribute (const char *src_info_start_label) |
e8363d4c | 3285 | { |
3286 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info); | |
3287 | /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ | |
3288 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label); | |
3289 | } | |
3290 | ||
7bfbda1f | 3291 | static inline void |
8ec3a57b | 3292 | mac_info_attribute (const char *mac_info_start_label) |
e8363d4c | 3293 | { |
3294 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info); | |
3295 | /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ | |
3296 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label); | |
3297 | } | |
3298 | ||
7bfbda1f | 3299 | static inline void |
8ec3a57b | 3300 | prototyped_attribute (tree func_type) |
e8363d4c | 3301 | { |
d19bd1f0 | 3302 | if ((strcmp (lang_hooks.name, "GNU C") == 0) |
e8363d4c | 3303 | && (TYPE_ARG_TYPES (func_type) != NULL)) |
3304 | { | |
3305 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped); | |
01e45963 | 3306 | ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, ""); |
e8363d4c | 3307 | } |
3308 | } | |
3309 | ||
7bfbda1f | 3310 | static inline void |
8ec3a57b | 3311 | producer_attribute (const char *producer) |
e8363d4c | 3312 | { |
3313 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer); | |
01e45963 | 3314 | ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, producer); |
e8363d4c | 3315 | } |
3316 | ||
7bfbda1f | 3317 | static inline void |
8ec3a57b | 3318 | inline_attribute (tree decl) |
e8363d4c | 3319 | { |
8fc7a3d0 | 3320 | if (DECL_INLINE (decl)) |
e8363d4c | 3321 | { |
3322 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline); | |
01e45963 | 3323 | ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, ""); |
e8363d4c | 3324 | } |
3325 | } | |
3326 | ||
7bfbda1f | 3327 | static inline void |
8ec3a57b | 3328 | containing_type_attribute (tree containing_type) |
e8363d4c | 3329 | { |
3330 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3331 | ||
3332 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type); | |
3333 | sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type)); | |
3334 | ASM_OUTPUT_DWARF_REF (asm_out_file, label); | |
3335 | } | |
3336 | ||
7bfbda1f | 3337 | static inline void |
8ec3a57b | 3338 | abstract_origin_attribute (tree origin) |
473cc96d | 3339 | { |
3340 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3341 | ||
3342 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_abstract_origin); | |
3343 | switch (TREE_CODE_CLASS (TREE_CODE (origin))) | |
3344 | { | |
3345 | case 'd': | |
3346 | sprintf (label, DECL_NAME_FMT, DECL_UID (origin)); | |
3347 | break; | |
3348 | ||
3349 | case 't': | |
3350 | sprintf (label, TYPE_NAME_FMT, TYPE_UID (origin)); | |
3351 | break; | |
3352 | ||
3353 | default: | |
3354 | abort (); /* Should never happen. */ | |
3355 | ||
3356 | } | |
3357 | ASM_OUTPUT_DWARF_REF (asm_out_file, label); | |
3358 | } | |
3359 | ||
3360 | #ifdef DWARF_DECL_COORDINATES | |
7bfbda1f | 3361 | static inline void |
8ec3a57b | 3362 | src_coords_attribute (unsigned src_fileno, unsigned src_lineno) |
88ef61d1 | 3363 | { |
88ef61d1 | 3364 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_coords); |
3365 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_fileno); | |
3366 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, src_lineno); | |
88ef61d1 | 3367 | } |
473cc96d | 3368 | #endif /* defined(DWARF_DECL_COORDINATES) */ |
3369 | ||
7bfbda1f | 3370 | static inline void |
8ec3a57b | 3371 | pure_or_virtual_attribute (tree func_decl) |
473cc96d | 3372 | { |
3373 | if (DECL_VIRTUAL_P (func_decl)) | |
3374 | { | |
6eaabe2a | 3375 | #if 0 /* DECL_ABSTRACT_VIRTUAL_P is C++-specific. */ |
473cc96d | 3376 | if (DECL_ABSTRACT_VIRTUAL_P (func_decl)) |
1eefe280 | 3377 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_pure_virtual); |
473cc96d | 3378 | else |
6eaabe2a | 3379 | #endif |
1eefe280 | 3380 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual); |
01e45963 | 3381 | ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, ""); |
473cc96d | 3382 | } |
3383 | } | |
88ef61d1 | 3384 | |
e8363d4c | 3385 | /************************* end of attributes *****************************/ |
3386 | ||
3387 | /********************* utility routines for DIEs *************************/ | |
3388 | ||
88ef61d1 | 3389 | /* Output an AT_name attribute and an AT_src_coords attribute for the |
3390 | given decl, but only if it actually has a name. */ | |
3391 | ||
ffb15922 | 3392 | static void |
8ec3a57b | 3393 | name_and_src_coords_attributes (tree decl) |
88ef61d1 | 3394 | { |
19cb6b50 | 3395 | tree decl_name = DECL_NAME (decl); |
88ef61d1 | 3396 | |
3397 | if (decl_name && IDENTIFIER_POINTER (decl_name)) | |
3398 | { | |
3399 | name_attribute (IDENTIFIER_POINTER (decl_name)); | |
4e9830fe | 3400 | #ifdef DWARF_DECL_COORDINATES |
3401 | { | |
3402 | register unsigned file_index; | |
3403 | ||
3404 | /* This is annoying, but we have to pop out of the .debug section | |
3405 | for a moment while we call `lookup_filename' because calling it | |
3406 | may cause a temporary switch into the .debug_sfnames section and | |
3398e91d | 3407 | most svr4 assemblers are not smart enough to be able to nest |
4e9830fe | 3408 | section switches to any depth greater than one. Note that we |
3409 | also can't skirt this issue by delaying all output to the | |
3410 | .debug_sfnames section unit the end of compilation because that | |
3411 | would cause us to have inter-section forward references and | |
3412 | Fred Fish sez that m68k/svr4 assemblers botch those. */ | |
3413 | ||
3414 | ASM_OUTPUT_POP_SECTION (asm_out_file); | |
3415 | file_index = lookup_filename (DECL_SOURCE_FILE (decl)); | |
3416 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION); | |
3417 | ||
1eefe280 | 3418 | src_coords_attribute (file_index, DECL_SOURCE_LINE (decl)); |
4e9830fe | 3419 | } |
ffb15922 | 3420 | #endif /* defined(DWARF_DECL_COORDINATES) */ |
88ef61d1 | 3421 | } |
3422 | } | |
3423 | ||
e8363d4c | 3424 | /* Many forms of DIEs contain a "type description" part. The following |
3425 | routine writes out these "type descriptor" parts. */ | |
3426 | ||
3427 | static void | |
8ec3a57b | 3428 | type_attribute (tree type, int decl_const, int decl_volatile) |
e8363d4c | 3429 | { |
19cb6b50 | 3430 | enum tree_code code = TREE_CODE (type); |
3431 | int root_type_modified; | |
e8363d4c | 3432 | |
ae1e09c2 | 3433 | if (code == ERROR_MARK) |
e8363d4c | 3434 | return; |
3435 | ||
3436 | /* Handle a special case. For functions whose return type is void, | |
3437 | we generate *no* type attribute. (Note that no object may have | |
3438 | type `void', so this only applies to function return types. */ | |
3439 | ||
ae1e09c2 | 3440 | if (code == VOID_TYPE) |
e8363d4c | 3441 | return; |
3442 | ||
ae1e09c2 | 3443 | /* If this is a subtype, find the underlying type. Eventually, |
3444 | this should write out the appropriate subtype info. */ | |
3445 | while ((code == INTEGER_TYPE || code == REAL_TYPE) | |
3446 | && TREE_TYPE (type) != 0) | |
3447 | type = TREE_TYPE (type), code = TREE_CODE (type); | |
3448 | ||
e8363d4c | 3449 | root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE |
3450 | || decl_const || decl_volatile | |
3451 | || TYPE_READONLY (type) || TYPE_VOLATILE (type)); | |
3452 | ||
3453 | if (type_is_fundamental (root_type (type))) | |
07e64d6e | 3454 | { |
3455 | if (root_type_modified) | |
e8363d4c | 3456 | mod_fund_type_attribute (type, decl_const, decl_volatile); |
07e64d6e | 3457 | else |
e8363d4c | 3458 | fund_type_attribute (fundamental_type_code (type)); |
07e64d6e | 3459 | } |
e8363d4c | 3460 | else |
07e64d6e | 3461 | { |
3462 | if (root_type_modified) | |
e8363d4c | 3463 | mod_u_d_type_attribute (type, decl_const, decl_volatile); |
07e64d6e | 3464 | else |
e079348f | 3465 | /* We have to get the type_main_variant here (and pass that to the |
0a0caad9 | 3466 | `user_def_type_attribute' routine) because the ..._TYPE node we |
3467 | have might simply be a *copy* of some original type node (where | |
3468 | the copy was created to help us keep track of typedef names) | |
3469 | and that copy might have a different TYPE_UID from the original | |
3470 | ..._TYPE node. (Note that when `equate_type_number_to_die_number' | |
3471 | is labeling a given type DIE for future reference, it always and | |
3472 | only creates labels for DIEs representing *main variants*, and it | |
3473 | never even knows about non-main-variants.) */ | |
e079348f | 3474 | user_def_type_attribute (type_main_variant (type)); |
07e64d6e | 3475 | } |
e8363d4c | 3476 | } |
3477 | ||
3478 | /* Given a tree pointer to a struct, class, union, or enum type node, return | |
3479 | a pointer to the (string) tag name for the given type, or zero if the | |
3480 | type was declared without a tag. */ | |
3481 | ||
1e034a40 | 3482 | static const char * |
8ec3a57b | 3483 | type_tag (tree type) |
e8363d4c | 3484 | { |
19cb6b50 | 3485 | const char *name = 0; |
e8363d4c | 3486 | |
3487 | if (TYPE_NAME (type) != 0) | |
3488 | { | |
19cb6b50 | 3489 | tree t = 0; |
e8363d4c | 3490 | |
3491 | /* Find the IDENTIFIER_NODE for the type name. */ | |
3492 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
3493 | t = TYPE_NAME (type); | |
e8363d4c | 3494 | |
1eefe280 | 3495 | /* The g++ front end makes the TYPE_NAME of *each* tagged type point to |
be7e1458 | 3496 | a TYPE_DECL node, regardless of whether or not a `typedef' was |
3497 | involved. */ | |
6efd403b | 3498 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL |
3499 | && ! DECL_IGNORED_P (TYPE_NAME (type))) | |
e8363d4c | 3500 | t = DECL_NAME (TYPE_NAME (type)); |
be7e1458 | 3501 | |
e8363d4c | 3502 | /* Now get the name as a string, or invent one. */ |
3503 | if (t != 0) | |
3504 | name = IDENTIFIER_POINTER (t); | |
3505 | } | |
3506 | ||
3507 | return (name == 0 || *name == '\0') ? 0 : name; | |
3508 | } | |
3509 | ||
7bfbda1f | 3510 | static inline void |
8ec3a57b | 3511 | dienum_push (void) |
e8363d4c | 3512 | { |
3513 | /* Start by checking if the pending_sibling_stack needs to be expanded. | |
3514 | If necessary, expand it. */ | |
3515 | ||
3516 | if (pending_siblings == pending_siblings_allocated) | |
3517 | { | |
3518 | pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT; | |
3519 | pending_sibling_stack | |
3520 | = (unsigned *) xrealloc (pending_sibling_stack, | |
3521 | pending_siblings_allocated * sizeof(unsigned)); | |
3522 | } | |
3523 | ||
3524 | pending_siblings++; | |
3525 | NEXT_DIE_NUM = next_unused_dienum++; | |
3526 | } | |
3527 | ||
3528 | /* Pop the sibling stack so that the most recently pushed DIEnum becomes the | |
3529 | NEXT_DIE_NUM. */ | |
3530 | ||
7bfbda1f | 3531 | static inline void |
8ec3a57b | 3532 | dienum_pop (void) |
e8363d4c | 3533 | { |
3534 | pending_siblings--; | |
3535 | } | |
3536 | ||
7bfbda1f | 3537 | static inline tree |
8ec3a57b | 3538 | member_declared_type (tree member) |
e8363d4c | 3539 | { |
3540 | return (DECL_BIT_FIELD_TYPE (member)) | |
3541 | ? DECL_BIT_FIELD_TYPE (member) | |
3542 | : TREE_TYPE (member); | |
3543 | } | |
3544 | ||
8c691ed2 | 3545 | /* Get the function's label, as described by its RTL. |
3546 | This may be different from the DECL_NAME name used | |
3547 | in the source file. */ | |
3548 | ||
9a356c3c | 3549 | static const char * |
8ec3a57b | 3550 | function_start_label (tree decl) |
8c691ed2 | 3551 | { |
3552 | rtx x; | |
9a356c3c | 3553 | const char *fnname; |
8c691ed2 | 3554 | |
3555 | x = DECL_RTL (decl); | |
3556 | if (GET_CODE (x) != MEM) | |
3557 | abort (); | |
3558 | x = XEXP (x, 0); | |
3559 | if (GET_CODE (x) != SYMBOL_REF) | |
3560 | abort (); | |
3561 | fnname = XSTR (x, 0); | |
3562 | return fnname; | |
3563 | } | |
3564 | ||
3565 | ||
e8363d4c | 3566 | /******************************* DIEs ************************************/ |
3567 | ||
3568 | /* Output routines for individual types of DIEs. */ | |
3569 | ||
3570 | /* Note that every type of DIE (except a null DIE) gets a sibling. */ | |
3571 | ||
3572 | static void | |
8ec3a57b | 3573 | output_array_type_die (void *arg) |
e8363d4c | 3574 | { |
19cb6b50 | 3575 | tree type = arg; |
e8363d4c | 3576 | |
3577 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type); | |
3578 | sibling_attribute (); | |
3579 | equate_type_number_to_die_number (type); | |
3580 | member_attribute (TYPE_CONTEXT (type)); | |
3581 | ||
3582 | /* I believe that we can default the array ordering. SDB will probably | |
3583 | do the right things even if AT_ordering is not present. It's not | |
3584 | even an issue until we start to get into multidimensional arrays | |
88ef61d1 | 3585 | anyway. If SDB is ever caught doing the Wrong Thing for multi- |
3586 | dimensional arrays, then we'll have to put the AT_ordering attribute | |
3587 | back in. (But if and when we find out that we need to put these in, | |
3588 | we will only do so for multidimensional arrays. After all, we don't | |
3589 | want to waste space in the .debug section now do we?) */ | |
e8363d4c | 3590 | |
ffb15922 | 3591 | #ifdef USE_ORDERING_ATTRIBUTE |
e8363d4c | 3592 | ordering_attribute (ORD_row_major); |
ffb15922 | 3593 | #endif /* defined(USE_ORDERING_ATTRIBUTE) */ |
e8363d4c | 3594 | |
3595 | subscript_data_attribute (type); | |
3596 | } | |
3597 | ||
3598 | static void | |
8ec3a57b | 3599 | output_set_type_die (void *arg) |
e8363d4c | 3600 | { |
19cb6b50 | 3601 | tree type = arg; |
e8363d4c | 3602 | |
3603 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type); | |
3604 | sibling_attribute (); | |
3605 | equate_type_number_to_die_number (type); | |
3606 | member_attribute (TYPE_CONTEXT (type)); | |
3607 | type_attribute (TREE_TYPE (type), 0, 0); | |
3608 | } | |
3609 | ||
3610 | #if 0 | |
3611 | /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */ | |
a92771b8 | 3612 | |
e8363d4c | 3613 | static void |
8ec3a57b | 3614 | output_entry_point_die (void *arg) |
e8363d4c | 3615 | { |
19cb6b50 | 3616 | tree decl = arg; |
3617 | tree origin = decl_ultimate_origin (decl); | |
e8363d4c | 3618 | |
3619 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point); | |
3620 | sibling_attribute (); | |
3621 | dienum_push (); | |
ffb15922 | 3622 | if (origin != NULL) |
3623 | abstract_origin_attribute (origin); | |
3624 | else | |
3625 | { | |
3626 | name_and_src_coords_attributes (decl); | |
3627 | member_attribute (DECL_CONTEXT (decl)); | |
3628 | type_attribute (TREE_TYPE (TREE_TYPE (decl)), 0, 0); | |
3629 | } | |
3630 | if (DECL_ABSTRACT (decl)) | |
3631 | equate_decl_number_to_die_number (decl); | |
3632 | else | |
8c691ed2 | 3633 | low_pc_attribute (function_start_label (decl)); |
e8363d4c | 3634 | } |
3635 | #endif | |
3636 | ||
ffb15922 | 3637 | /* Output a DIE to represent an inlined instance of an enumeration type. */ |
3638 | ||
3639 | static void | |
8ec3a57b | 3640 | output_inlined_enumeration_type_die (void *arg) |
ffb15922 | 3641 | { |
19cb6b50 | 3642 | tree type = arg; |
ffb15922 | 3643 | |
3644 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type); | |
3645 | sibling_attribute (); | |
7e2bfe1e | 3646 | if (!TREE_ASM_WRITTEN (type)) |
3647 | abort (); | |
ffb15922 | 3648 | abstract_origin_attribute (type); |
3649 | } | |
3650 | ||
3651 | /* Output a DIE to represent an inlined instance of a structure type. */ | |
3652 | ||
3653 | static void | |
8ec3a57b | 3654 | output_inlined_structure_type_die (void *arg) |
ffb15922 | 3655 | { |
19cb6b50 | 3656 | tree type = arg; |
ffb15922 | 3657 | |
3658 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type); | |
3659 | sibling_attribute (); | |
7e2bfe1e | 3660 | if (!TREE_ASM_WRITTEN (type)) |
3661 | abort (); | |
ffb15922 | 3662 | abstract_origin_attribute (type); |
3663 | } | |
3664 | ||
3665 | /* Output a DIE to represent an inlined instance of a union type. */ | |
3666 | ||
3667 | static void | |
8ec3a57b | 3668 | output_inlined_union_type_die (void *arg) |
ffb15922 | 3669 | { |
19cb6b50 | 3670 | tree type = arg; |
ffb15922 | 3671 | |
3672 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type); | |
3673 | sibling_attribute (); | |
7e2bfe1e | 3674 | if (!TREE_ASM_WRITTEN (type)) |
3675 | abort (); | |
ffb15922 | 3676 | abstract_origin_attribute (type); |
3677 | } | |
3678 | ||
e8363d4c | 3679 | /* Output a DIE to represent an enumeration type. Note that these DIEs |
3680 | include all of the information about the enumeration values also. | |
3681 | This information is encoded into the element_list attribute. */ | |
3682 | ||
3683 | static void | |
8ec3a57b | 3684 | output_enumeration_type_die (void *arg) |
e8363d4c | 3685 | { |
19cb6b50 | 3686 | tree type = arg; |
e8363d4c | 3687 | |
3688 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type); | |
3689 | sibling_attribute (); | |
3690 | equate_type_number_to_die_number (type); | |
3691 | name_attribute (type_tag (type)); | |
3692 | member_attribute (TYPE_CONTEXT (type)); | |
3693 | ||
3694 | /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the | |
3695 | given enum type is incomplete, do not generate the AT_byte_size | |
3696 | attribute or the AT_element_list attribute. */ | |
3697 | ||
4b72716d | 3698 | if (COMPLETE_TYPE_P (type)) |
e8363d4c | 3699 | { |
3700 | byte_size_attribute (type); | |
3701 | element_list_attribute (TYPE_FIELDS (type)); | |
3702 | } | |
3703 | } | |
3704 | ||
3705 | /* Output a DIE to represent either a real live formal parameter decl or | |
3706 | to represent just the type of some formal parameter position in some | |
3707 | function type. | |
3708 | ||
3709 | Note that this routine is a bit unusual because its argument may be | |
ffb15922 | 3710 | a ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which |
3711 | represents an inlining of some PARM_DECL) or else some sort of a | |
3712 | ..._TYPE node. If it's the former then this function is being called | |
3713 | to output a DIE to represent a formal parameter object (or some inlining | |
3714 | thereof). If it's the latter, then this function is only being called | |
3715 | to output a TAG_formal_parameter DIE to stand as a placeholder for some | |
3716 | formal argument type of some subprogram type. */ | |
e8363d4c | 3717 | |
3718 | static void | |
8ec3a57b | 3719 | output_formal_parameter_die (void *arg) |
e8363d4c | 3720 | { |
19cb6b50 | 3721 | tree node = arg; |
e8363d4c | 3722 | |
3723 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter); | |
3724 | sibling_attribute (); | |
ffb15922 | 3725 | |
3726 | switch (TREE_CODE_CLASS (TREE_CODE (node))) | |
e8363d4c | 3727 | { |
ffb15922 | 3728 | case 'd': /* We were called with some kind of a ..._DECL node. */ |
3729 | { | |
3730 | register tree origin = decl_ultimate_origin (node); | |
3731 | ||
3732 | if (origin != NULL) | |
3733 | abstract_origin_attribute (origin); | |
3734 | else | |
3735 | { | |
3736 | name_and_src_coords_attributes (node); | |
3737 | type_attribute (TREE_TYPE (node), | |
3738 | TREE_READONLY (node), TREE_THIS_VOLATILE (node)); | |
3739 | } | |
3740 | if (DECL_ABSTRACT (node)) | |
3741 | equate_decl_number_to_die_number (node); | |
3742 | else | |
3743 | location_or_const_value_attribute (node); | |
3744 | } | |
3745 | break; | |
3746 | ||
3747 | case 't': /* We were called with some kind of a ..._TYPE node. */ | |
3748 | type_attribute (node, 0, 0); | |
3749 | break; | |
3750 | ||
3751 | default: | |
3752 | abort (); /* Should never happen. */ | |
e8363d4c | 3753 | } |
e8363d4c | 3754 | } |
3755 | ||
3756 | /* Output a DIE to represent a declared function (either file-scope | |
3757 | or block-local) which has "external linkage" (according to ANSI-C). */ | |
3758 | ||
3759 | static void | |
8ec3a57b | 3760 | output_global_subroutine_die (void *arg) |
e8363d4c | 3761 | { |
19cb6b50 | 3762 | tree decl = arg; |
3763 | tree origin = decl_ultimate_origin (decl); | |
e8363d4c | 3764 | |
3765 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine); | |
3766 | sibling_attribute (); | |
3767 | dienum_push (); | |
ffb15922 | 3768 | if (origin != NULL) |
3769 | abstract_origin_attribute (origin); | |
3770 | else | |
e8363d4c | 3771 | { |
19cb6b50 | 3772 | tree type = TREE_TYPE (decl); |
e8363d4c | 3773 | |
ffb15922 | 3774 | name_and_src_coords_attributes (decl); |
3775 | inline_attribute (decl); | |
3776 | prototyped_attribute (type); | |
3777 | member_attribute (DECL_CONTEXT (decl)); | |
3778 | type_attribute (TREE_TYPE (type), 0, 0); | |
3779 | pure_or_virtual_attribute (decl); | |
3780 | } | |
3781 | if (DECL_ABSTRACT (decl)) | |
3782 | equate_decl_number_to_die_number (decl); | |
3783 | else | |
3784 | { | |
6efd403b | 3785 | if (! DECL_EXTERNAL (decl) && ! in_class |
3786 | && decl == current_function_decl) | |
ffb15922 | 3787 | { |
cf6a3b88 | 3788 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
ffb15922 | 3789 | |
8c691ed2 | 3790 | low_pc_attribute (function_start_label (decl)); |
4781f9b9 | 3791 | sprintf (label, FUNC_END_LABEL_FMT, current_function_funcdef_no); |
cf6a3b88 | 3792 | high_pc_attribute (label); |
6efd403b | 3793 | if (use_gnu_debug_info_extensions) |
3794 | { | |
4781f9b9 | 3795 | sprintf (label, BODY_BEGIN_LABEL_FMT, |
3796 | current_function_funcdef_no); | |
6efd403b | 3797 | body_begin_attribute (label); |
4781f9b9 | 3798 | sprintf (label, BODY_END_LABEL_FMT, current_function_funcdef_no); |
6efd403b | 3799 | body_end_attribute (label); |
3800 | } | |
ffb15922 | 3801 | } |
e8363d4c | 3802 | } |
3803 | } | |
3804 | ||
3805 | /* Output a DIE to represent a declared data object (either file-scope | |
3806 | or block-local) which has "external linkage" (according to ANSI-C). */ | |
3807 | ||
3808 | static void | |
8ec3a57b | 3809 | output_global_variable_die (void *arg) |
e8363d4c | 3810 | { |
19cb6b50 | 3811 | tree decl = arg; |
3812 | tree origin = decl_ultimate_origin (decl); | |
e8363d4c | 3813 | |
3814 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable); | |
3815 | sibling_attribute (); | |
ffb15922 | 3816 | if (origin != NULL) |
3817 | abstract_origin_attribute (origin); | |
3818 | else | |
e8363d4c | 3819 | { |
ffb15922 | 3820 | name_and_src_coords_attributes (decl); |
3821 | member_attribute (DECL_CONTEXT (decl)); | |
3822 | type_attribute (TREE_TYPE (decl), | |
3823 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); | |
3824 | } | |
3825 | if (DECL_ABSTRACT (decl)) | |
3826 | equate_decl_number_to_die_number (decl); | |
3827 | else | |
3828 | { | |
6efd403b | 3829 | if (! DECL_EXTERNAL (decl) && ! in_class |
3830 | && current_function_decl == decl_function_context (decl)) | |
ffb15922 | 3831 | location_or_const_value_attribute (decl); |
e8363d4c | 3832 | } |
3833 | } | |
e8363d4c | 3834 | |
3835 | static void | |
8ec3a57b | 3836 | output_label_die (void *arg) |
e8363d4c | 3837 | { |
19cb6b50 | 3838 | tree decl = arg; |
3839 | tree origin = decl_ultimate_origin (decl); | |
e8363d4c | 3840 | |
3841 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label); | |
3842 | sibling_attribute (); | |
ffb15922 | 3843 | if (origin != NULL) |
3844 | abstract_origin_attribute (origin); | |
3845 | else | |
3846 | name_and_src_coords_attributes (decl); | |
3847 | if (DECL_ABSTRACT (decl)) | |
3848 | equate_decl_number_to_die_number (decl); | |
3849 | else | |
3850 | { | |
19cb6b50 | 3851 | rtx insn = DECL_RTL (decl); |
e8363d4c | 3852 | |
165b3519 | 3853 | /* Deleted labels are programmer specified labels which have been |
7ef5b942 | 3854 | eliminated because of various optimizations. We still emit them |
165b3519 | 3855 | here so that it is possible to put breakpoints on them. */ |
3856 | if (GET_CODE (insn) == CODE_LABEL | |
3857 | || ((GET_CODE (insn) == NOTE | |
3858 | && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))) | |
ffb15922 | 3859 | { |
3860 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
e8363d4c | 3861 | |
ffb15922 | 3862 | /* When optimization is enabled (via -O) some parts of the compiler |
3863 | (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which | |
3864 | represent source-level labels which were explicitly declared by | |
3865 | the user. This really shouldn't be happening though, so catch | |
3866 | it if it ever does happen. */ | |
e8363d4c | 3867 | |
ffb15922 | 3868 | if (INSN_DELETED_P (insn)) |
3869 | abort (); /* Should never happen. */ | |
e8363d4c | 3870 | |
1134a028 | 3871 | ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn)); |
ffb15922 | 3872 | low_pc_attribute (label); |
3873 | } | |
e8363d4c | 3874 | } |
3875 | } | |
3876 | ||
3877 | static void | |
8ec3a57b | 3878 | output_lexical_block_die (void *arg) |
e8363d4c | 3879 | { |
19cb6b50 | 3880 | tree stmt = arg; |
e8363d4c | 3881 | |
3882 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block); | |
3883 | sibling_attribute (); | |
3884 | dienum_push (); | |
ffb15922 | 3885 | if (! BLOCK_ABSTRACT (stmt)) |
3886 | { | |
3887 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3888 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3889 | ||
5846cb0f | 3890 | sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt)); |
ffb15922 | 3891 | low_pc_attribute (begin_label); |
5846cb0f | 3892 | sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt)); |
ffb15922 | 3893 | high_pc_attribute (end_label); |
3894 | } | |
e8363d4c | 3895 | } |
3896 | ||
3897 | static void | |
8ec3a57b | 3898 | output_inlined_subroutine_die (void *arg) |
e8363d4c | 3899 | { |
19cb6b50 | 3900 | tree stmt = arg; |
e8363d4c | 3901 | |
3902 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine); | |
3903 | sibling_attribute (); | |
3904 | dienum_push (); | |
ffb15922 | 3905 | abstract_origin_attribute (block_ultimate_origin (stmt)); |
3906 | if (! BLOCK_ABSTRACT (stmt)) | |
3907 | { | |
3908 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3909 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
3910 | ||
5846cb0f | 3911 | sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, BLOCK_NUMBER (stmt)); |
ffb15922 | 3912 | low_pc_attribute (begin_label); |
5846cb0f | 3913 | sprintf (end_label, BLOCK_END_LABEL_FMT, BLOCK_NUMBER (stmt)); |
ffb15922 | 3914 | high_pc_attribute (end_label); |
3915 | } | |
e8363d4c | 3916 | } |
3917 | ||
3918 | /* Output a DIE to represent a declared data object (either file-scope | |
3919 | or block-local) which has "internal linkage" (according to ANSI-C). */ | |
3920 | ||
3921 | static void | |
8ec3a57b | 3922 | output_local_variable_die (void *arg) |
e8363d4c | 3923 | { |
19cb6b50 | 3924 | tree decl = arg; |
3925 | tree origin = decl_ultimate_origin (decl); | |
e8363d4c | 3926 | |
3927 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable); | |
3928 | sibling_attribute (); | |
ffb15922 | 3929 | if (origin != NULL) |
3930 | abstract_origin_attribute (origin); | |
3931 | else | |
3932 | { | |
3933 | name_and_src_coords_attributes (decl); | |
3934 | member_attribute (DECL_CONTEXT (decl)); | |
3935 | type_attribute (TREE_TYPE (decl), | |
3936 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); | |
3937 | } | |
3938 | if (DECL_ABSTRACT (decl)) | |
3939 | equate_decl_number_to_die_number (decl); | |
3940 | else | |
3941 | location_or_const_value_attribute (decl); | |
e8363d4c | 3942 | } |
3943 | ||
3944 | static void | |
8ec3a57b | 3945 | output_member_die (void *arg) |
e8363d4c | 3946 | { |
19cb6b50 | 3947 | tree decl = arg; |
e8363d4c | 3948 | |
3949 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member); | |
3950 | sibling_attribute (); | |
88ef61d1 | 3951 | name_and_src_coords_attributes (decl); |
e8363d4c | 3952 | member_attribute (DECL_CONTEXT (decl)); |
3953 | type_attribute (member_declared_type (decl), | |
3954 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); | |
a92771b8 | 3955 | if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */ |
e8363d4c | 3956 | { |
3957 | byte_size_attribute (decl); | |
3958 | bit_size_attribute (decl); | |
3959 | bit_offset_attribute (decl); | |
3960 | } | |
3961 | data_member_location_attribute (decl); | |
3962 | } | |
3963 | ||
3964 | #if 0 | |
ffb15922 | 3965 | /* Don't generate either pointer_type DIEs or reference_type DIEs. Use |
3966 | modified types instead. | |
e8363d4c | 3967 | |
a92771b8 | 3968 | We keep this code here just in case these types of DIEs may be |
3969 | needed to represent certain things in other languages (e.g. Pascal) | |
3970 | someday. */ | |
e8363d4c | 3971 | |
3972 | static void | |
8ec3a57b | 3973 | output_pointer_type_die (void *arg) |
e8363d4c | 3974 | { |
19cb6b50 | 3975 | tree type = arg; |
e8363d4c | 3976 | |
3977 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type); | |
3978 | sibling_attribute (); | |
3979 | equate_type_number_to_die_number (type); | |
3980 | member_attribute (TYPE_CONTEXT (type)); | |
3981 | type_attribute (TREE_TYPE (type), 0, 0); | |
3982 | } | |
3983 | ||
3984 | static void | |
8ec3a57b | 3985 | output_reference_type_die (void *arg) |
e8363d4c | 3986 | { |
19cb6b50 | 3987 | tree type = arg; |
e8363d4c | 3988 | |
3989 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type); | |
3990 | sibling_attribute (); | |
3991 | equate_type_number_to_die_number (type); | |
3992 | member_attribute (TYPE_CONTEXT (type)); | |
3993 | type_attribute (TREE_TYPE (type), 0, 0); | |
3994 | } | |
3995 | #endif | |
3996 | ||
ffb15922 | 3997 | static void |
8ec3a57b | 3998 | output_ptr_to_mbr_type_die (void *arg) |
e8363d4c | 3999 | { |
19cb6b50 | 4000 | tree type = arg; |
e8363d4c | 4001 | |
4002 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type); | |
4003 | sibling_attribute (); | |
4004 | equate_type_number_to_die_number (type); | |
4005 | member_attribute (TYPE_CONTEXT (type)); | |
4006 | containing_type_attribute (TYPE_OFFSET_BASETYPE (type)); | |
4007 | type_attribute (TREE_TYPE (type), 0, 0); | |
4008 | } | |
4009 | ||
4010 | static void | |
8ec3a57b | 4011 | output_compile_unit_die (void *arg) |
e8363d4c | 4012 | { |
19cb6b50 | 4013 | const char *main_input_filename = arg; |
d19bd1f0 | 4014 | const char *language_string = lang_hooks.name; |
e8363d4c | 4015 | |
4016 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit); | |
4017 | sibling_attribute (); | |
4018 | dienum_push (); | |
4019 | name_attribute (main_input_filename); | |
4020 | ||
4021 | { | |
4022 | char producer[250]; | |
4023 | ||
4024 | sprintf (producer, "%s %s", language_string, version_string); | |
4025 | producer_attribute (producer); | |
4026 | } | |
4027 | ||
4028 | if (strcmp (language_string, "GNU C++") == 0) | |
4029 | language_attribute (LANG_C_PLUS_PLUS); | |
e9c2f348 | 4030 | else if (strcmp (language_string, "GNU Ada") == 0) |
4031 | language_attribute (LANG_ADA83); | |
82d472f1 | 4032 | else if (strcmp (language_string, "GNU F77") == 0) |
4033 | language_attribute (LANG_FORTRAN77); | |
d6b0ef01 | 4034 | else if (strcmp (language_string, "GNU Pascal") == 0) |
4035 | language_attribute (LANG_PASCAL83); | |
af4d39d8 | 4036 | else if (strcmp (language_string, "GNU Java") == 0) |
4037 | language_attribute (LANG_JAVA); | |
e8363d4c | 4038 | else |
4039 | language_attribute (LANG_C89); | |
4040 | low_pc_attribute (TEXT_BEGIN_LABEL); | |
4041 | high_pc_attribute (TEXT_END_LABEL); | |
4042 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
4043 | stmt_list_attribute (LINE_BEGIN_LABEL); | |
e8363d4c | 4044 | |
4045 | { | |
1e034a40 | 4046 | const char *wd = getpwd (); |
c6396a0b | 4047 | if (wd) |
4048 | comp_dir_attribute (wd); | |
e8363d4c | 4049 | } |
4050 | ||
6efd403b | 4051 | if (debug_info_level >= DINFO_LEVEL_NORMAL && use_gnu_debug_info_extensions) |
e8363d4c | 4052 | { |
4053 | sf_names_attribute (SFNAMES_BEGIN_LABEL); | |
4054 | src_info_attribute (SRCINFO_BEGIN_LABEL); | |
4055 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) | |
1eefe280 | 4056 | mac_info_attribute (MACINFO_BEGIN_LABEL); |
e8363d4c | 4057 | } |
4058 | } | |
4059 | ||
4060 | static void | |
8ec3a57b | 4061 | output_string_type_die (void *arg) |
e8363d4c | 4062 | { |
19cb6b50 | 4063 | tree type = arg; |
e8363d4c | 4064 | |
4065 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type); | |
4066 | sibling_attribute (); | |
a2ad7eb8 | 4067 | equate_type_number_to_die_number (type); |
e8363d4c | 4068 | member_attribute (TYPE_CONTEXT (type)); |
a2ad7eb8 | 4069 | /* this is a fixed length string */ |
4070 | byte_size_attribute (type); | |
e8363d4c | 4071 | } |
4072 | ||
7524eb42 | 4073 | static void |
8ec3a57b | 4074 | output_inheritance_die (void *arg) |
7524eb42 | 4075 | { |
95f3173a | 4076 | tree binfo = ((tree *)arg)[0]; |
4077 | tree access = ((tree *)arg)[1]; | |
7524eb42 | 4078 | |
4079 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inheritance); | |
4080 | sibling_attribute (); | |
4081 | type_attribute (BINFO_TYPE (binfo), 0, 0); | |
4082 | data_member_location_attribute (binfo); | |
4083 | if (TREE_VIA_VIRTUAL (binfo)) | |
4084 | { | |
4085 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_virtual); | |
01e45963 | 4086 | ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, ""); |
7524eb42 | 4087 | } |
95f3173a | 4088 | if (access == access_public_node) |
7524eb42 | 4089 | { |
4090 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_public); | |
01e45963 | 4091 | ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, ""); |
7524eb42 | 4092 | } |
95f3173a | 4093 | else if (access == access_protected_node) |
7524eb42 | 4094 | { |
4095 | ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_protected); | |
01e45963 | 4096 | ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, ""); |
7524eb42 | 4097 | } |
1eefe280 | 4098 | } |
7524eb42 | 4099 | |
e8363d4c | 4100 | static void |
8ec3a57b | 4101 | output_structure_type_die (void *arg) |
e8363d4c | 4102 | { |
19cb6b50 | 4103 | tree type = arg; |
e8363d4c | 4104 | |
4105 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type); | |
4106 | sibling_attribute (); | |
4107 | equate_type_number_to_die_number (type); | |
4108 | name_attribute (type_tag (type)); | |
4109 | member_attribute (TYPE_CONTEXT (type)); | |
4110 | ||
4111 | /* If this type has been completed, then give it a byte_size attribute | |
4112 | and prepare to give a list of members. Otherwise, don't do either of | |
4113 | these things. In the latter case, we will not be generating a list | |
4114 | of members (since we don't have any idea what they might be for an | |
4115 | incomplete type). */ | |
4116 | ||
4b72716d | 4117 | if (COMPLETE_TYPE_P (type)) |
e8363d4c | 4118 | { |
4119 | dienum_push (); | |
4120 | byte_size_attribute (type); | |
4121 | } | |
4122 | } | |
4123 | ||
4124 | /* Output a DIE to represent a declared function (either file-scope | |
4125 | or block-local) which has "internal linkage" (according to ANSI-C). */ | |
4126 | ||
4127 | static void | |
8ec3a57b | 4128 | output_local_subroutine_die (void *arg) |
e8363d4c | 4129 | { |
19cb6b50 | 4130 | tree decl = arg; |
4131 | tree origin = decl_ultimate_origin (decl); | |
e8363d4c | 4132 | |
4133 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine); | |
4134 | sibling_attribute (); | |
4135 | dienum_push (); | |
ffb15922 | 4136 | if (origin != NULL) |
4137 | abstract_origin_attribute (origin); | |
4138 | else | |
4139 | { | |
19cb6b50 | 4140 | tree type = TREE_TYPE (decl); |
e8363d4c | 4141 | |
ffb15922 | 4142 | name_and_src_coords_attributes (decl); |
4143 | inline_attribute (decl); | |
4144 | prototyped_attribute (type); | |
4145 | member_attribute (DECL_CONTEXT (decl)); | |
4146 | type_attribute (TREE_TYPE (type), 0, 0); | |
4147 | pure_or_virtual_attribute (decl); | |
4148 | } | |
4149 | if (DECL_ABSTRACT (decl)) | |
4150 | equate_decl_number_to_die_number (decl); | |
4151 | else | |
e8363d4c | 4152 | { |
ffb15922 | 4153 | /* Avoid getting screwed up in cases where a function was declared |
4154 | static but where no definition was ever given for it. */ | |
4155 | ||
4156 | if (TREE_ASM_WRITTEN (decl)) | |
4157 | { | |
cf6a3b88 | 4158 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; |
8c691ed2 | 4159 | low_pc_attribute (function_start_label (decl)); |
4781f9b9 | 4160 | sprintf (label, FUNC_END_LABEL_FMT, current_function_funcdef_no); |
cf6a3b88 | 4161 | high_pc_attribute (label); |
6efd403b | 4162 | if (use_gnu_debug_info_extensions) |
4163 | { | |
4781f9b9 | 4164 | sprintf (label, BODY_BEGIN_LABEL_FMT, |
4165 | current_function_funcdef_no); | |
6efd403b | 4166 | body_begin_attribute (label); |
4781f9b9 | 4167 | sprintf (label, BODY_END_LABEL_FMT, current_function_funcdef_no); |
6efd403b | 4168 | body_end_attribute (label); |
4169 | } | |
ffb15922 | 4170 | } |
e8363d4c | 4171 | } |
4172 | } | |
4173 | ||
4174 | static void | |
8ec3a57b | 4175 | output_subroutine_type_die (void *arg) |
e8363d4c | 4176 | { |
19cb6b50 | 4177 | tree type = arg; |
4178 | tree return_type = TREE_TYPE (type); | |
e8363d4c | 4179 | |
4180 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type); | |
4181 | sibling_attribute (); | |
4182 | dienum_push (); | |
4183 | equate_type_number_to_die_number (type); | |
4184 | prototyped_attribute (type); | |
4185 | member_attribute (TYPE_CONTEXT (type)); | |
4186 | type_attribute (return_type, 0, 0); | |
4187 | } | |
4188 | ||
4189 | static void | |
8ec3a57b | 4190 | output_typedef_die (void *arg) |
e8363d4c | 4191 | { |
19cb6b50 | 4192 | tree decl = arg; |
4193 | tree origin = decl_ultimate_origin (decl); | |
e8363d4c | 4194 | |
4195 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef); | |
4196 | sibling_attribute (); | |
ffb15922 | 4197 | if (origin != NULL) |
4198 | abstract_origin_attribute (origin); | |
4199 | else | |
4200 | { | |
4201 | name_and_src_coords_attributes (decl); | |
4202 | member_attribute (DECL_CONTEXT (decl)); | |
4203 | type_attribute (TREE_TYPE (decl), | |
4204 | TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); | |
4205 | } | |
4206 | if (DECL_ABSTRACT (decl)) | |
4207 | equate_decl_number_to_die_number (decl); | |
e8363d4c | 4208 | } |
4209 | ||
4210 | static void | |
8ec3a57b | 4211 | output_union_type_die (void *arg) |
e8363d4c | 4212 | { |
19cb6b50 | 4213 | tree type = arg; |
e8363d4c | 4214 | |
4215 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type); | |
4216 | sibling_attribute (); | |
4217 | equate_type_number_to_die_number (type); | |
4218 | name_attribute (type_tag (type)); | |
4219 | member_attribute (TYPE_CONTEXT (type)); | |
4220 | ||
4221 | /* If this type has been completed, then give it a byte_size attribute | |
4222 | and prepare to give a list of members. Otherwise, don't do either of | |
4223 | these things. In the latter case, we will not be generating a list | |
4224 | of members (since we don't have any idea what they might be for an | |
4225 | incomplete type). */ | |
4226 | ||
4b72716d | 4227 | if (COMPLETE_TYPE_P (type)) |
e8363d4c | 4228 | { |
4229 | dienum_push (); | |
4230 | byte_size_attribute (type); | |
4231 | } | |
4232 | } | |
4233 | ||
4234 | /* Generate a special type of DIE used as a stand-in for a trailing ellipsis | |
4235 | at the end of an (ANSI prototyped) formal parameters list. */ | |
4236 | ||
4237 | static void | |
8ec3a57b | 4238 | output_unspecified_parameters_die (void *arg) |
e8363d4c | 4239 | { |
19cb6b50 | 4240 | tree decl_or_type = arg; |
e8363d4c | 4241 | |
4242 | ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters); | |
4243 | sibling_attribute (); | |
4244 | ||
4245 | /* This kludge is here only for the sake of being compatible with what | |
4246 | the USL CI5 C compiler does. The specification of Dwarf Version 1 | |
4247 | doesn't say that TAG_unspecified_parameters DIEs should contain any | |
4248 | attributes other than the AT_sibling attribute, but they are certainly | |
4249 | allowed to contain additional attributes, and the CI5 compiler | |
4250 | generates AT_name, AT_fund_type, and AT_location attributes within | |
4251 | TAG_unspecified_parameters DIEs which appear in the child lists for | |
4252 | DIEs representing function definitions, so we do likewise here. */ | |
4253 | ||
4254 | if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type)) | |
4255 | { | |
4256 | name_attribute ("..."); | |
4257 | fund_type_attribute (FT_pointer); | |
4258 | /* location_attribute (?); */ | |
4259 | } | |
4260 | } | |
4261 | ||
4262 | static void | |
8ec3a57b | 4263 | output_padded_null_die (void *arg ATTRIBUTE_UNUSED) |
e8363d4c | 4264 | { |
4265 | ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */ | |
4266 | } | |
4267 | ||
4268 | /*************************** end of DIEs *********************************/ | |
4269 | ||
4270 | /* Generate some type of DIE. This routine generates the generic outer | |
4271 | wrapper stuff which goes around all types of DIE's (regardless of their | |
4272 | TAGs. All forms of DIEs start with a DIE-specific label, followed by a | |
4273 | DIE-length word, followed by the guts of the DIE itself. After the guts | |
4274 | of the DIE, there must always be a terminator label for the DIE. */ | |
4275 | ||
4276 | static void | |
8ec3a57b | 4277 | output_die (void (*die_specific_output_function) (void *), void *param) |
e8363d4c | 4278 | { |
4279 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4280 | char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4281 | ||
4282 | current_dienum = NEXT_DIE_NUM; | |
4283 | NEXT_DIE_NUM = next_unused_dienum; | |
4284 | ||
4285 | sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum); | |
4286 | sprintf (end_label, DIE_END_LABEL_FMT, current_dienum); | |
4287 | ||
4288 | /* Write a label which will act as the name for the start of this DIE. */ | |
4289 | ||
4290 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
4291 | ||
4292 | /* Write the DIE-length word. */ | |
4293 | ||
4294 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label); | |
4295 | ||
4296 | /* Fill in the guts of the DIE. */ | |
4297 | ||
4298 | next_unused_dienum++; | |
4299 | die_specific_output_function (param); | |
4300 | ||
4301 | /* Write a label which will act as the name for the end of this DIE. */ | |
4302 | ||
4303 | ASM_OUTPUT_LABEL (asm_out_file, end_label); | |
4304 | } | |
4305 | ||
4306 | static void | |
8ec3a57b | 4307 | end_sibling_chain (void) |
e8363d4c | 4308 | { |
4309 | char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
4310 | ||
4311 | current_dienum = NEXT_DIE_NUM; | |
4312 | NEXT_DIE_NUM = next_unused_dienum; | |
4313 | ||
4314 | sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum); | |
4315 | ||
4316 | /* Write a label which will act as the name for the start of this DIE. */ | |
4317 | ||
4318 | ASM_OUTPUT_LABEL (asm_out_file, begin_label); | |
4319 | ||
4320 | /* Write the DIE-length word. */ | |
4321 | ||
4322 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4); | |
4323 | ||
4324 | dienum_pop (); | |
4325 | } | |
4326 | \f | |
4327 | /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a | |
4328 | TAG_unspecified_parameters DIE) to represent the types of the formal | |
4329 | parameters as specified in some function type specification (except | |
4330 | for those which appear as part of a function *definition*). | |
4331 | ||
a92771b8 | 4332 | Note that we must be careful here to output all of the parameter |
4333 | DIEs *before* we output any DIEs needed to represent the types of | |
4334 | the formal parameters. This keeps svr4 SDB happy because it | |
4335 | (incorrectly) thinks that the first non-parameter DIE it sees ends | |
4336 | the formal parameter list. */ | |
e8363d4c | 4337 | |
4338 | static void | |
8ec3a57b | 4339 | output_formal_types (tree function_or_method_type) |
e8363d4c | 4340 | { |
19cb6b50 | 4341 | tree link; |
4342 | tree formal_type = NULL; | |
4343 | tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type); | |
e8363d4c | 4344 | |
4ad6aeba | 4345 | /* Set TREE_ASM_WRITTEN while processing the parameters, lest we |
4346 | get bogus recursion when outputting tagged types local to a | |
4347 | function declaration. */ | |
4348 | int save_asm_written = TREE_ASM_WRITTEN (function_or_method_type); | |
4349 | TREE_ASM_WRITTEN (function_or_method_type) = 1; | |
4350 | ||
e8363d4c | 4351 | /* In the case where we are generating a formal types list for a C++ |
4352 | non-static member function type, skip over the first thing on the | |
4353 | TYPE_ARG_TYPES list because it only represents the type of the | |
4354 | hidden `this pointer'. The debugger should be able to figure | |
4355 | out (without being explicitly told) that this non-static member | |
4356 | function type takes a `this pointer' and should be able to figure | |
4357 | what the type of that hidden parameter is from the AT_member | |
4358 | attribute of the parent TAG_subroutine_type DIE. */ | |
4359 | ||
4360 | if (TREE_CODE (function_or_method_type) == METHOD_TYPE) | |
4361 | first_parm_type = TREE_CHAIN (first_parm_type); | |
4362 | ||
4363 | /* Make our first pass over the list of formal parameter types and output | |
4364 | a TAG_formal_parameter DIE for each one. */ | |
4365 | ||
4366 | for (link = first_parm_type; link; link = TREE_CHAIN (link)) | |
4367 | { | |
4368 | formal_type = TREE_VALUE (link); | |
4369 | if (formal_type == void_type_node) | |
4370 | break; | |
4371 | ||
4372 | /* Output a (nameless) DIE to represent the formal parameter itself. */ | |
4373 | ||
4374 | output_die (output_formal_parameter_die, formal_type); | |
4375 | } | |
4376 | ||
4377 | /* If this function type has an ellipsis, add a TAG_unspecified_parameters | |
4378 | DIE to the end of the parameter list. */ | |
4379 | ||
4380 | if (formal_type != void_type_node) | |
4381 | output_die (output_unspecified_parameters_die, function_or_method_type); | |
4382 | ||
4383 | /* Make our second (and final) pass over the list of formal parameter types | |
4384 | and output DIEs to represent those types (as necessary). */ | |
4385 | ||
4386 | for (link = TYPE_ARG_TYPES (function_or_method_type); | |
4387 | link; | |
4388 | link = TREE_CHAIN (link)) | |
4389 | { | |
4390 | formal_type = TREE_VALUE (link); | |
4391 | if (formal_type == void_type_node) | |
4392 | break; | |
4393 | ||
4394 | output_type (formal_type, function_or_method_type); | |
4395 | } | |
4ad6aeba | 4396 | |
4397 | TREE_ASM_WRITTEN (function_or_method_type) = save_asm_written; | |
e8363d4c | 4398 | } |
4399 | \f | |
4400 | /* Remember a type in the pending_types_list. */ | |
4401 | ||
4402 | static void | |
8ec3a57b | 4403 | pend_type (tree type) |
e8363d4c | 4404 | { |
4405 | if (pending_types == pending_types_allocated) | |
4406 | { | |
4407 | pending_types_allocated += PENDING_TYPES_INCREMENT; | |
4408 | pending_types_list | |
4409 | = (tree *) xrealloc (pending_types_list, | |
4410 | sizeof (tree) * pending_types_allocated); | |
4411 | } | |
4412 | pending_types_list[pending_types++] = type; | |
4413 | ||
4414 | /* Mark the pending type as having been output already (even though | |
4415 | it hasn't been). This prevents the type from being added to the | |
4416 | pending_types_list more than once. */ | |
4417 | ||
4418 | TREE_ASM_WRITTEN (type) = 1; | |
4419 | } | |
4420 | ||
6ef828f9 | 4421 | /* Return nonzero if it is legitimate to output DIEs to represent a |
e8363d4c | 4422 | given type while we are generating the list of child DIEs for some |
1adc7e47 | 4423 | DIE (e.g. a function or lexical block DIE) associated with a given scope. |
e8363d4c | 4424 | |
1adc7e47 | 4425 | See the comments within the function for a description of when it is |
4426 | considered legitimate to output DIEs for various kinds of types. | |
e8363d4c | 4427 | |
4428 | Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope) | |
4429 | or it may point to a BLOCK node (for types local to a block), or to a | |
4430 | FUNCTION_DECL node (for types local to the heading of some function | |
4431 | definition), or to a FUNCTION_TYPE node (for types local to the | |
4432 | prototyped parameter list of a function type specification), or to a | |
7f8a347a | 4433 | RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE node |
4434 | (in the case of C++ nested types). | |
e8363d4c | 4435 | |
4436 | The `scope' parameter should likewise be NULL or should point to a | |
4437 | BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE | |
7f8a347a | 4438 | node, a UNION_TYPE node, or a QUAL_UNION_TYPE node. |
e8363d4c | 4439 | |
4440 | This function is used only for deciding when to "pend" and when to | |
4441 | "un-pend" types to/from the pending_types_list. | |
4442 | ||
4443 | Note that we sometimes make use of this "type pending" feature in a | |
4444 | rather twisted way to temporarily delay the production of DIEs for the | |
4445 | types of formal parameters. (We do this just to make svr4 SDB happy.) | |
4446 | It order to delay the production of DIEs representing types of formal | |
4447 | parameters, callers of this function supply `fake_containing_scope' as | |
4448 | the `scope' parameter to this function. Given that fake_containing_scope | |
1adc7e47 | 4449 | is a tagged type which is *not* the containing scope for *any* other type, |
4450 | the desired effect is achieved, i.e. output of DIEs representing types | |
4451 | is temporarily suspended, and any type DIEs which would have otherwise | |
4452 | been output are instead placed onto the pending_types_list. Later on, | |
4453 | we force these (temporarily pended) types to be output simply by calling | |
e8363d4c | 4454 | `output_pending_types_for_scope' with an actual argument equal to the |
7bfbda1f | 4455 | true scope of the types we temporarily pended. */ |
e8363d4c | 4456 | |
7bfbda1f | 4457 | static inline int |
8ec3a57b | 4458 | type_ok_for_scope (tree type, tree scope) |
e8363d4c | 4459 | { |
1adc7e47 | 4460 | /* Tagged types (i.e. struct, union, and enum types) must always be |
4461 | output only in the scopes where they actually belong (or else the | |
4462 | scoping of their own tag names and the scoping of their member | |
4463 | names will be incorrect). Non-tagged-types on the other hand can | |
4464 | generally be output anywhere, except that svr4 SDB really doesn't | |
4465 | want to see them nested within struct or union types, so here we | |
4466 | say it is always OK to immediately output any such a (non-tagged) | |
4467 | type, so long as we are not within such a context. Note that the | |
4468 | only kinds of non-tagged types which we will be dealing with here | |
4469 | (for C and C++ anyway) will be array types and function types. */ | |
4470 | ||
4471 | return is_tagged_type (type) | |
6efd403b | 4472 | ? (TYPE_CONTEXT (type) == scope |
7c43cc0e | 4473 | /* Ignore namespaces for the moment. */ |
4474 | || (scope == NULL_TREE | |
4475 | && TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL) | |
6efd403b | 4476 | || (scope == NULL_TREE && is_tagged_type (TYPE_CONTEXT (type)) |
4477 | && TREE_ASM_WRITTEN (TYPE_CONTEXT (type)))) | |
1adc7e47 | 4478 | : (scope == NULL_TREE || ! is_tagged_type (scope)); |
e8363d4c | 4479 | } |
4480 | ||
4481 | /* Output any pending types (from the pending_types list) which we can output | |
1adc7e47 | 4482 | now (taking into account the scope that we are working on now). |
e8363d4c | 4483 | |
4484 | For each type output, remove the given type from the pending_types_list | |
4485 | *before* we try to output it. | |
4486 | ||
4487 | Note that we have to process the list in beginning-to-end order, | |
4488 | because the call made here to output_type may cause yet more types | |
4489 | to be added to the end of the list, and we may have to output some | |
a92771b8 | 4490 | of them too. */ |
e8363d4c | 4491 | |
4492 | static void | |
8ec3a57b | 4493 | output_pending_types_for_scope (tree containing_scope) |
e8363d4c | 4494 | { |
19cb6b50 | 4495 | unsigned i; |
e8363d4c | 4496 | |
4497 | for (i = 0; i < pending_types; ) | |
4498 | { | |
19cb6b50 | 4499 | tree type = pending_types_list[i]; |
e8363d4c | 4500 | |
4501 | if (type_ok_for_scope (type, containing_scope)) | |
4502 | { | |
19cb6b50 | 4503 | tree *mover; |
4504 | tree *limit; | |
e8363d4c | 4505 | |
4506 | pending_types--; | |
4507 | limit = &pending_types_list[pending_types]; | |
4508 | for (mover = &pending_types_list[i]; mover < limit; mover++) | |
4509 | *mover = *(mover+1); | |
4510 | ||
4511 | /* Un-mark the type as having been output already (because it | |
4512 | hasn't been, really). Then call output_type to generate a | |
4513 | Dwarf representation of it. */ | |
4514 | ||
4515 | TREE_ASM_WRITTEN (type) = 0; | |
4516 | output_type (type, containing_scope); | |
4517 | ||
4518 | /* Don't increment the loop counter in this case because we | |
4519 | have shifted all of the subsequent pending types down one | |
4520 | element in the pending_types_list array. */ | |
4521 | } | |
4522 | else | |
4523 | i++; | |
4524 | } | |
4525 | } | |
4526 | ||
568cb337 | 4527 | /* Remember a type in the incomplete_types_list. */ |
4528 | ||
4529 | static void | |
8ec3a57b | 4530 | add_incomplete_type (tree type) |
568cb337 | 4531 | { |
4532 | if (incomplete_types == incomplete_types_allocated) | |
4533 | { | |
4534 | incomplete_types_allocated += INCOMPLETE_TYPES_INCREMENT; | |
4535 | incomplete_types_list | |
4536 | = (tree *) xrealloc (incomplete_types_list, | |
4537 | sizeof (tree) * incomplete_types_allocated); | |
4538 | } | |
4539 | ||
4540 | incomplete_types_list[incomplete_types++] = type; | |
4541 | } | |
4542 | ||
4543 | /* Walk through the list of incomplete types again, trying once more to | |
4544 | emit full debugging info for them. */ | |
4545 | ||
4546 | static void | |
8ec3a57b | 4547 | retry_incomplete_types (void) |
568cb337 | 4548 | { |
19cb6b50 | 4549 | tree type; |
568cb337 | 4550 | |
4551 | finalizing = 1; | |
4552 | while (incomplete_types) | |
4553 | { | |
4554 | --incomplete_types; | |
4555 | type = incomplete_types_list[incomplete_types]; | |
4556 | output_type (type, NULL_TREE); | |
4557 | } | |
4558 | } | |
4559 | ||
e8363d4c | 4560 | static void |
8ec3a57b | 4561 | output_type (tree type, tree containing_scope) |
e8363d4c | 4562 | { |
4563 | if (type == 0 || type == error_mark_node) | |
4564 | return; | |
4565 | ||
4566 | /* We are going to output a DIE to represent the unqualified version of | |
3398e91d | 4567 | this type (i.e. without any const or volatile qualifiers) so get |
e8363d4c | 4568 | the main variant (i.e. the unqualified version) of this type now. */ |
4569 | ||
e079348f | 4570 | type = type_main_variant (type); |
e8363d4c | 4571 | |
4572 | if (TREE_ASM_WRITTEN (type)) | |
934b828a | 4573 | { |
4574 | if (finalizing && AGGREGATE_TYPE_P (type)) | |
4575 | { | |
19cb6b50 | 4576 | tree member; |
934b828a | 4577 | |
4578 | /* Some of our nested types might not have been defined when we | |
4579 | were written out before; force them out now. */ | |
4580 | ||
4581 | for (member = TYPE_FIELDS (type); member; | |
4582 | member = TREE_CHAIN (member)) | |
4583 | if (TREE_CODE (member) == TYPE_DECL | |
4584 | && ! TREE_ASM_WRITTEN (TREE_TYPE (member))) | |
4585 | output_type (TREE_TYPE (member), containing_scope); | |
4586 | } | |
4587 | return; | |
4588 | } | |
e8363d4c | 4589 | |
6efd403b | 4590 | /* If this is a nested type whose containing class hasn't been |
4591 | written out yet, writing it out will cover this one, too. */ | |
4592 | ||
4593 | if (TYPE_CONTEXT (type) | |
9308e976 | 4594 | && TYPE_P (TYPE_CONTEXT (type)) |
6efd403b | 4595 | && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) |
4596 | { | |
4597 | output_type (TYPE_CONTEXT (type), containing_scope); | |
4598 | return; | |
4599 | } | |
4600 | ||
e8363d4c | 4601 | /* Don't generate any DIEs for this type now unless it is OK to do so |
4602 | (based upon what `type_ok_for_scope' tells us). */ | |
4603 | ||
4604 | if (! type_ok_for_scope (type, containing_scope)) | |
4605 | { | |
4606 | pend_type (type); | |
4607 | return; | |
4608 | } | |
4609 | ||
4610 | switch (TREE_CODE (type)) | |
4611 | { | |
4612 | case ERROR_MARK: | |
4613 | break; | |
4614 | ||
e2ea7e3a | 4615 | case VECTOR_TYPE: |
4616 | output_type (TYPE_DEBUG_REPRESENTATION_TYPE (type), containing_scope); | |
4617 | break; | |
4618 | ||
e8363d4c | 4619 | case POINTER_TYPE: |
4620 | case REFERENCE_TYPE: | |
214044ec | 4621 | /* Prevent infinite recursion in cases where this is a recursive |
4622 | type. Recursive types are possible in Ada. */ | |
4623 | TREE_ASM_WRITTEN (type) = 1; | |
e8363d4c | 4624 | /* For these types, all that is required is that we output a DIE |
4be6300a | 4625 | (or a set of DIEs) to represent the "basis" type. */ |
e8363d4c | 4626 | output_type (TREE_TYPE (type), containing_scope); |
4627 | break; | |
4628 | ||
4629 | case OFFSET_TYPE: | |
4630 | /* This code is used for C++ pointer-to-data-member types. */ | |
4631 | /* Output a description of the relevant class type. */ | |
4632 | output_type (TYPE_OFFSET_BASETYPE (type), containing_scope); | |
4633 | /* Output a description of the type of the object pointed to. */ | |
4634 | output_type (TREE_TYPE (type), containing_scope); | |
4635 | /* Now output a DIE to represent this pointer-to-data-member type | |
4636 | itself. */ | |
4637 | output_die (output_ptr_to_mbr_type_die, type); | |
4638 | break; | |
4639 | ||
4640 | case SET_TYPE: | |
37651f70 | 4641 | output_type (TYPE_DOMAIN (type), containing_scope); |
e8363d4c | 4642 | output_die (output_set_type_die, type); |
4643 | break; | |
4644 | ||
4645 | case FILE_TYPE: | |
4646 | output_type (TREE_TYPE (type), containing_scope); | |
4bbea254 | 4647 | abort (); /* No way to represent these in Dwarf yet! */ |
e8363d4c | 4648 | break; |
4649 | ||
e8363d4c | 4650 | case FUNCTION_TYPE: |
4651 | /* Force out return type (in case it wasn't forced out already). */ | |
4652 | output_type (TREE_TYPE (type), containing_scope); | |
4653 | output_die (output_subroutine_type_die, type); | |
4654 | output_formal_types (type); | |
4655 | end_sibling_chain (); | |
4656 | break; | |
4657 | ||
4658 | case METHOD_TYPE: | |
4659 | /* Force out return type (in case it wasn't forced out already). */ | |
4660 | output_type (TREE_TYPE (type), containing_scope); | |
4661 | output_die (output_subroutine_type_die, type); | |
4662 | output_formal_types (type); | |
4663 | end_sibling_chain (); | |
4664 | break; | |
4665 | ||
1eefe280 | 4666 | case ARRAY_TYPE: |
11aea978 | 4667 | if (TYPE_STRING_FLAG (type) && TREE_CODE(TREE_TYPE(type)) == CHAR_TYPE) |
4668 | { | |
4669 | output_type (TREE_TYPE (type), containing_scope); | |
4670 | output_die (output_string_type_die, type); | |
4671 | } | |
4672 | else | |
4673 | { | |
19cb6b50 | 4674 | tree element_type; |
e8363d4c | 4675 | |
11aea978 | 4676 | element_type = TREE_TYPE (type); |
4677 | while (TREE_CODE (element_type) == ARRAY_TYPE) | |
4678 | element_type = TREE_TYPE (element_type); | |
e8363d4c | 4679 | |
11aea978 | 4680 | output_type (element_type, containing_scope); |
4681 | output_die (output_array_type_die, type); | |
4682 | } | |
e8363d4c | 4683 | break; |
4684 | ||
4685 | case ENUMERAL_TYPE: | |
4686 | case RECORD_TYPE: | |
4687 | case UNION_TYPE: | |
7f8a347a | 4688 | case QUAL_UNION_TYPE: |
e8363d4c | 4689 | |
4690 | /* For a non-file-scope tagged type, we can always go ahead and | |
4691 | output a Dwarf description of this type right now, even if | |
4692 | the type in question is still incomplete, because if this | |
4693 | local type *was* ever completed anywhere within its scope, | |
4694 | that complete definition would already have been attached to | |
7f8a347a | 4695 | this RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE or ENUMERAL_TYPE |
4696 | node by the time we reach this point. That's true because of the | |
4697 | way the front-end does its processing of file-scope declarations (of | |
e8363d4c | 4698 | functions and class types) within which other types might be |
4699 | nested. The C and C++ front-ends always gobble up such "local | |
4700 | scope" things en-mass before they try to output *any* debugging | |
4701 | information for any of the stuff contained inside them and thus, | |
4702 | we get the benefit here of what is (in effect) a pre-resolution | |
4703 | of forward references to tagged types in local scopes. | |
4704 | ||
4705 | Note however that for file-scope tagged types we cannot assume | |
4706 | that such pre-resolution of forward references has taken place. | |
4707 | A given file-scope tagged type may appear to be incomplete when | |
4708 | we reach this point, but it may yet be given a full definition | |
4709 | (at file-scope) later on during compilation. In order to avoid | |
4710 | generating a premature (and possibly incorrect) set of Dwarf | |
4711 | DIEs for such (as yet incomplete) file-scope tagged types, we | |
4712 | generate nothing at all for as-yet incomplete file-scope tagged | |
4713 | types here unless we are making our special "finalization" pass | |
4714 | for file-scope things at the very end of compilation. At that | |
4715 | time, we will certainly know as much about each file-scope tagged | |
4716 | type as we are ever going to know, so at that point in time, we | |
4717 | can safely generate correct Dwarf descriptions for these file- | |
6efd403b | 4718 | scope tagged types. */ |
e8363d4c | 4719 | |
4b72716d | 4720 | if (!COMPLETE_TYPE_P (type) |
a3e22dd0 | 4721 | && (TYPE_CONTEXT (type) == NULL |
53bdb86c | 4722 | || AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) |
4723 | || TREE_CODE (TYPE_CONTEXT (type)) == NAMESPACE_DECL) | |
a3e22dd0 | 4724 | && !finalizing) |
568cb337 | 4725 | { |
d6d10a79 | 4726 | /* We don't need to do this for function-local types. */ |
4727 | if (! decl_function_context (TYPE_STUB_DECL (type))) | |
a41e1595 | 4728 | add_incomplete_type (type); |
568cb337 | 4729 | return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */ |
4730 | } | |
e8363d4c | 4731 | |
4732 | /* Prevent infinite recursion in cases where the type of some | |
4733 | member of this type is expressed in terms of this type itself. */ | |
4734 | ||
4735 | TREE_ASM_WRITTEN (type) = 1; | |
4736 | ||
4737 | /* Output a DIE to represent the tagged type itself. */ | |
4738 | ||
4739 | switch (TREE_CODE (type)) | |
4740 | { | |
4741 | case ENUMERAL_TYPE: | |
4742 | output_die (output_enumeration_type_die, type); | |
4743 | return; /* a special case -- nothing left to do so just return */ | |
4744 | ||
4745 | case RECORD_TYPE: | |
4746 | output_die (output_structure_type_die, type); | |
4747 | break; | |
4748 | ||
4749 | case UNION_TYPE: | |
7f8a347a | 4750 | case QUAL_UNION_TYPE: |
e8363d4c | 4751 | output_die (output_union_type_die, type); |
4752 | break; | |
ffb15922 | 4753 | |
4754 | default: | |
4755 | abort (); /* Should never happen. */ | |
e8363d4c | 4756 | } |
4757 | ||
4758 | /* If this is not an incomplete type, output descriptions of | |
4759 | each of its members. | |
4760 | ||
4761 | Note that as we output the DIEs necessary to represent the | |
4762 | members of this record or union type, we will also be trying | |
4763 | to output DIEs to represent the *types* of those members. | |
4764 | However the `output_type' function (above) will specifically | |
4765 | avoid generating type DIEs for member types *within* the list | |
4a82352a | 4766 | of member DIEs for this (containing) type except for those |
e8363d4c | 4767 | types (of members) which are explicitly marked as also being |
4768 | members of this (containing) type themselves. The g++ front- | |
4769 | end can force any given type to be treated as a member of some | |
4770 | other (containing) type by setting the TYPE_CONTEXT of the | |
4771 | given (member) type to point to the TREE node representing the | |
4772 | appropriate (containing) type. | |
4773 | */ | |
4774 | ||
4b72716d | 4775 | if (COMPLETE_TYPE_P (type)) |
e8363d4c | 4776 | { |
95f3173a | 4777 | tree binfo = TYPE_BINFO (type); |
8ec3a57b | 4778 | |
7524eb42 | 4779 | /* First output info about the base classes. */ |
95f3173a | 4780 | if (binfo) |
7524eb42 | 4781 | { |
95f3173a | 4782 | tree bases = BINFO_BASETYPES (binfo); |
4783 | tree accesses = BINFO_BASEACCESSES (binfo); | |
4784 | register int n_bases = BINFO_N_BASETYPES (binfo); | |
7524eb42 | 4785 | register int i; |
4786 | ||
4787 | for (i = 0; i < n_bases; i++) | |
568cb337 | 4788 | { |
95f3173a | 4789 | tree arg[2]; |
4790 | ||
4791 | arg[0] = TREE_VEC_ELT (bases, i); | |
4792 | arg[1] = (accesses ? TREE_VEC_ELT (accesses, i) | |
4793 | : access_public_node); | |
568cb337 | 4794 | output_type (BINFO_TYPE (binfo), containing_scope); |
95f3173a | 4795 | output_die (output_inheritance_die, arg); |
568cb337 | 4796 | } |
7524eb42 | 4797 | } |
4798 | ||
6efd403b | 4799 | ++in_class; |
4800 | ||
88ef61d1 | 4801 | { |
19cb6b50 | 4802 | tree normal_member; |
e8363d4c | 4803 | |
7524eb42 | 4804 | /* Now output info about the data members and type members. */ |
e8363d4c | 4805 | |
88ef61d1 | 4806 | for (normal_member = TYPE_FIELDS (type); |
4807 | normal_member; | |
4808 | normal_member = TREE_CHAIN (normal_member)) | |
4809 | output_decl (normal_member, type); | |
4810 | } | |
e8363d4c | 4811 | |
88ef61d1 | 4812 | { |
19cb6b50 | 4813 | tree func_member; |
88ef61d1 | 4814 | |
4815 | /* Now output info about the function members (if any). */ | |
4816 | ||
be7e1458 | 4817 | for (func_member = TYPE_METHODS (type); |
4818 | func_member; | |
4819 | func_member = TREE_CHAIN (func_member)) | |
8f80e66d | 4820 | { |
4821 | /* Don't include clones in the member list. */ | |
4822 | if (DECL_ABSTRACT_ORIGIN (func_member)) | |
4823 | continue; | |
4824 | ||
4825 | output_decl (func_member, type); | |
4826 | } | |
88ef61d1 | 4827 | } |
e8363d4c | 4828 | |
6efd403b | 4829 | --in_class; |
4830 | ||
7f8a347a | 4831 | /* RECORD_TYPEs, UNION_TYPEs, and QUAL_UNION_TYPEs are themselves |
4832 | scopes (at least in C++) so we must now output any nested | |
4833 | pending types which are local just to this type. */ | |
1adc7e47 | 4834 | |
4835 | output_pending_types_for_scope (type); | |
4836 | ||
e8363d4c | 4837 | end_sibling_chain (); /* Terminate member chain. */ |
4838 | } | |
4839 | ||
4840 | break; | |
4841 | ||
4842 | case VOID_TYPE: | |
4843 | case INTEGER_TYPE: | |
4844 | case REAL_TYPE: | |
4845 | case COMPLEX_TYPE: | |
4846 | case BOOLEAN_TYPE: | |
4847 | case CHAR_TYPE: | |
4848 | break; /* No DIEs needed for fundamental types. */ | |
4849 | ||
4850 | case LANG_TYPE: /* No Dwarf representation currently defined. */ | |
4851 | break; | |
4852 | ||
4853 | default: | |
4854 | abort (); | |
4855 | } | |
4856 | ||
4857 | TREE_ASM_WRITTEN (type) = 1; | |
4858 | } | |
ffb15922 | 4859 | |
4860 | static void | |
8ec3a57b | 4861 | output_tagged_type_instantiation (tree type) |
ffb15922 | 4862 | { |
4863 | if (type == 0 || type == error_mark_node) | |
4864 | return; | |
4865 | ||
4866 | /* We are going to output a DIE to represent the unqualified version of | |
3398e91d | 4867 | this type (i.e. without any const or volatile qualifiers) so make |
ffb15922 | 4868 | sure that we have the main variant (i.e. the unqualified version) of |
4869 | this type now. */ | |
4870 | ||
7e2bfe1e | 4871 | if (type != type_main_variant (type)) |
4872 | abort (); | |
ffb15922 | 4873 | |
7e2bfe1e | 4874 | if (!TREE_ASM_WRITTEN (type)) |
4875 | abort (); | |
ffb15922 | 4876 | |
4877 | switch (TREE_CODE (type)) | |
4878 | { | |
4879 | case ERROR_MARK: | |
4880 | break; | |
4881 | ||
4882 | case ENUMERAL_TYPE: | |
4883 | output_die (output_inlined_enumeration_type_die, type); | |
4884 | break; | |
4885 | ||
4886 | case RECORD_TYPE: | |
4887 | output_die (output_inlined_structure_type_die, type); | |
4888 | break; | |
4889 | ||
4890 | case UNION_TYPE: | |
7f8a347a | 4891 | case QUAL_UNION_TYPE: |
ffb15922 | 4892 | output_die (output_inlined_union_type_die, type); |
4893 | break; | |
4894 | ||
4895 | default: | |
4896 | abort (); /* Should never happen. */ | |
4897 | } | |
4898 | } | |
e8363d4c | 4899 | \f |
4900 | /* Output a TAG_lexical_block DIE followed by DIEs to represent all of | |
4901 | the things which are local to the given block. */ | |
4902 | ||
4903 | static void | |
8ec3a57b | 4904 | output_block (tree stmt, int depth) |
e8363d4c | 4905 | { |
19cb6b50 | 4906 | int must_output_die = 0; |
4907 | tree origin; | |
4908 | enum tree_code origin_code; | |
e8363d4c | 4909 | |
4910 | /* Ignore blocks never really used to make RTL. */ | |
4911 | ||
7508c82b | 4912 | if (! stmt || ! TREE_USED (stmt) |
4913 | || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt))) | |
e8363d4c | 4914 | return; |
4915 | ||
6eaabe2a | 4916 | /* Determine the "ultimate origin" of this block. This block may be an |
4917 | inlined instance of an inlined instance of inline function, so we | |
4918 | have to trace all of the way back through the origin chain to find | |
4919 | out what sort of node actually served as the original seed for the | |
4920 | creation of the current block. */ | |
e8363d4c | 4921 | |
6eaabe2a | 4922 | origin = block_ultimate_origin (stmt); |
4923 | origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; | |
4924 | ||
4925 | /* Determine if we need to output any Dwarf DIEs at all to represent this | |
4926 | block. */ | |
e8363d4c | 4927 | |
6eaabe2a | 4928 | if (origin_code == FUNCTION_DECL) |
4929 | /* The outer scopes for inlinings *must* always be represented. We | |
4930 | generate TAG_inlined_subroutine DIEs for them. (See below.) */ | |
4931 | must_output_die = 1; | |
4932 | else | |
4933 | { | |
4934 | /* In the case where the current block represents an inlining of the | |
4935 | "body block" of an inline function, we must *NOT* output any DIE | |
4936 | for this block because we have already output a DIE to represent | |
4937 | the whole inlined function scope and the "body block" of any | |
4938 | function doesn't really represent a different scope according to | |
4939 | ANSI C rules. So we check here to make sure that this block does | |
4940 | not represent a "body block inlining" before trying to set the | |
4941 | `must_output_die' flag. */ | |
4942 | ||
be7e1458 | 4943 | if (! is_body_block (origin ? origin : stmt)) |
6eaabe2a | 4944 | { |
4945 | /* Determine if this block directly contains any "significant" | |
4946 | local declarations which we will need to output DIEs for. */ | |
4947 | ||
4948 | if (debug_info_level > DINFO_LEVEL_TERSE) | |
4949 | /* We are not in terse mode so *any* local declaration counts | |
4950 | as being a "significant" one. */ | |
4951 | must_output_die = (BLOCK_VARS (stmt) != NULL); | |
4952 | else | |
e8363d4c | 4953 | { |
19cb6b50 | 4954 | tree decl; |
6eaabe2a | 4955 | |
4956 | /* We are in terse mode, so only local (nested) function | |
4957 | definitions count as "significant" local declarations. */ | |
4958 | ||
4959 | for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl)) | |
4960 | if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl)) | |
4961 | { | |
4962 | must_output_die = 1; | |
4963 | break; | |
4964 | } | |
e8363d4c | 4965 | } |
6eaabe2a | 4966 | } |
4967 | } | |
e8363d4c | 4968 | |
4969 | /* It would be a waste of space to generate a Dwarf TAG_lexical_block | |
4970 | DIE for any block which contains no significant local declarations | |
4971 | at all. Rather, in such cases we just call `output_decls_for_scope' | |
4972 | so that any needed Dwarf info for any sub-blocks will get properly | |
4973 | generated. Note that in terse mode, our definition of what constitutes | |
4974 | a "significant" local declaration gets restricted to include only | |
4975 | inlined function instances and local (nested) function definitions. */ | |
4976 | ||
be7e1458 | 4977 | if (origin_code == FUNCTION_DECL && BLOCK_ABSTRACT (stmt)) |
4978 | /* We don't care about an abstract inlined subroutine. */; | |
4979 | else if (must_output_die) | |
e8363d4c | 4980 | { |
6eaabe2a | 4981 | output_die ((origin_code == FUNCTION_DECL) |
4982 | ? output_inlined_subroutine_die | |
4983 | : output_lexical_block_die, | |
e8363d4c | 4984 | stmt); |
be7e1458 | 4985 | output_decls_for_scope (stmt, depth); |
e8363d4c | 4986 | end_sibling_chain (); |
4987 | } | |
4988 | else | |
be7e1458 | 4989 | output_decls_for_scope (stmt, depth); |
e8363d4c | 4990 | } |
4991 | ||
4992 | /* Output all of the decls declared within a given scope (also called | |
4993 | a `binding contour') and (recursively) all of it's sub-blocks. */ | |
4994 | ||
4995 | static void | |
8ec3a57b | 4996 | output_decls_for_scope (tree stmt, int depth) |
e8363d4c | 4997 | { |
4998 | /* Ignore blocks never really used to make RTL. */ | |
4999 | ||
5000 | if (! stmt || ! TREE_USED (stmt)) | |
5001 | return; | |
5002 | ||
e8363d4c | 5003 | /* Output the DIEs to represent all of the data objects, functions, |
5004 | typedefs, and tagged types declared directly within this block | |
5005 | but not within any nested sub-blocks. */ | |
5006 | ||
5007 | { | |
19cb6b50 | 5008 | tree decl; |
e8363d4c | 5009 | |
5010 | for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl)) | |
5011 | output_decl (decl, stmt); | |
5012 | } | |
5013 | ||
5014 | output_pending_types_for_scope (stmt); | |
5015 | ||
5016 | /* Output the DIEs to represent all sub-blocks (and the items declared | |
5017 | therein) of this block. */ | |
5018 | ||
5019 | { | |
19cb6b50 | 5020 | tree subblocks; |
e8363d4c | 5021 | |
5022 | for (subblocks = BLOCK_SUBBLOCKS (stmt); | |
1eefe280 | 5023 | subblocks; |
5024 | subblocks = BLOCK_CHAIN (subblocks)) | |
be7e1458 | 5025 | output_block (subblocks, depth + 1); |
e8363d4c | 5026 | } |
5027 | } | |
5028 | ||
6efd403b | 5029 | /* Is this a typedef we can avoid emitting? */ |
5030 | ||
80c9dac9 | 5031 | static inline int |
8ec3a57b | 5032 | is_redundant_typedef (tree decl) |
6efd403b | 5033 | { |
5034 | if (TYPE_DECL_IS_STUB (decl)) | |
5035 | return 1; | |
5036 | if (DECL_ARTIFICIAL (decl) | |
5037 | && DECL_CONTEXT (decl) | |
5038 | && is_tagged_type (DECL_CONTEXT (decl)) | |
5039 | && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL | |
5040 | && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) | |
5041 | /* Also ignore the artificial member typedef for the class name. */ | |
5042 | return 1; | |
5043 | return 0; | |
5044 | } | |
5045 | ||
e8363d4c | 5046 | /* Output Dwarf .debug information for a decl described by DECL. */ |
5047 | ||
5048 | static void | |
8ec3a57b | 5049 | output_decl (tree decl, tree containing_scope) |
e8363d4c | 5050 | { |
017ffcef | 5051 | /* Make a note of the decl node we are going to be working on. We may |
5052 | need to give the user the source coordinates of where it appeared in | |
5053 | case we notice (later on) that something about it looks screwy. */ | |
5054 | ||
5055 | dwarf_last_decl = decl; | |
5056 | ||
d2b8625b | 5057 | if (TREE_CODE (decl) == ERROR_MARK) |
5058 | return; | |
5059 | ||
51ccfcda | 5060 | /* If a structure is declared within an initialization, e.g. as the |
5061 | operand of a sizeof, then it will not have a name. We don't want | |
5062 | to output a DIE for it, as the tree nodes are in the temporary obstack */ | |
5063 | ||
5064 | if ((TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE | |
5065 | || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE) | |
5066 | && ((DECL_NAME (decl) == 0 && TYPE_NAME (TREE_TYPE (decl)) == 0) | |
1eefe280 | 5067 | || (TYPE_FIELDS (TREE_TYPE (decl)) |
51ccfcda | 5068 | && (TREE_CODE (TYPE_FIELDS (TREE_TYPE (decl))) == ERROR_MARK)))) |
5069 | return; | |
1eefe280 | 5070 | |
ad2fe2cd | 5071 | /* If this ..._DECL node is marked to be ignored, then ignore it. */ |
d2b8625b | 5072 | |
ad2fe2cd | 5073 | if (DECL_IGNORED_P (decl)) |
d2b8625b | 5074 | return; |
5075 | ||
e8363d4c | 5076 | switch (TREE_CODE (decl)) |
5077 | { | |
e8363d4c | 5078 | case CONST_DECL: |
5079 | /* The individual enumerators of an enum type get output when we | |
5080 | output the Dwarf representation of the relevant enum type itself. */ | |
5081 | break; | |
5082 | ||
5083 | case FUNCTION_DECL: | |
5084 | /* If we are in terse mode, don't output any DIEs to represent | |
d17aae73 | 5085 | mere function declarations. Also, if we are conforming |
bad5b016 | 5086 | to the DWARF version 1 specification, don't output DIEs for |
d17aae73 | 5087 | mere function declarations. */ |
e8363d4c | 5088 | |
d17aae73 | 5089 | if (DECL_INITIAL (decl) == NULL_TREE) |
bad5b016 | 5090 | #if (DWARF_VERSION > 1) |
5091 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
5092 | #endif | |
5093 | break; | |
e8363d4c | 5094 | |
5095 | /* Before we describe the FUNCTION_DECL itself, make sure that we | |
5096 | have described its return type. */ | |
5097 | ||
5098 | output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope); | |
5099 | ||
6efd403b | 5100 | { |
5101 | /* And its containing type. */ | |
5102 | register tree origin = decl_class_context (decl); | |
5103 | if (origin) | |
5104 | output_type (origin, containing_scope); | |
5105 | } | |
5106 | ||
0dbc398a | 5107 | /* If we're emitting an out-of-line copy of an inline function, |
5108 | set up to refer to the abstract instance emitted from | |
c37d72e9 | 5109 | dwarfout_deferred_inline_function. */ |
0dbc398a | 5110 | if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl) |
5111 | && ! (containing_scope && TYPE_P (containing_scope))) | |
5112 | set_decl_origin_self (decl); | |
5113 | ||
e8363d4c | 5114 | /* If the following DIE will represent a function definition for a |
5115 | function with "extern" linkage, output a special "pubnames" DIE | |
5116 | label just ahead of the actual DIE. A reference to this label | |
5117 | was already generated in the .debug_pubnames section sub-entry | |
5118 | for this function definition. */ | |
5119 | ||
5120 | if (TREE_PUBLIC (decl)) | |
5121 | { | |
5122 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5123 | ||
5124 | sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++); | |
5125 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
5126 | } | |
5127 | ||
5128 | /* Now output a DIE to represent the function itself. */ | |
5129 | ||
8fc7a3d0 | 5130 | output_die (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl) |
e8363d4c | 5131 | ? output_global_subroutine_die |
5132 | : output_local_subroutine_die, | |
5133 | decl); | |
5134 | ||
5135 | /* Now output descriptions of the arguments for this function. | |
5136 | This gets (unnecessarily?) complex because of the fact that | |
5137 | the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate | |
5138 | cases where there was a trailing `...' at the end of the formal | |
5139 | parameter list. In order to find out if there was a trailing | |
5140 | ellipsis or not, we must instead look at the type associated | |
5141 | with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE. | |
5142 | If the chain of type nodes hanging off of this FUNCTION_TYPE node | |
5143 | ends with a void_type_node then there should *not* be an ellipsis | |
5144 | at the end. */ | |
5145 | ||
d17aae73 | 5146 | /* In the case where we are describing a mere function declaration, all |
e8363d4c | 5147 | we need to do here (and all we *can* do here) is to describe |
5148 | the *types* of its formal parameters. */ | |
5149 | ||
6efd403b | 5150 | if (decl != current_function_decl || in_class) |
e8363d4c | 5151 | output_formal_types (TREE_TYPE (decl)); |
5152 | else | |
5153 | { | |
2358393e | 5154 | /* Generate DIEs to represent all known formal parameters. */ |
1616a2ff | 5155 | |
19cb6b50 | 5156 | tree arg_decls = DECL_ARGUMENTS (decl); |
5157 | tree parm; | |
1616a2ff | 5158 | |
5159 | /* WARNING! Kludge zone ahead! Here we have a special | |
5160 | hack for svr4 SDB compatibility. Instead of passing the | |
5161 | current FUNCTION_DECL node as the second parameter (i.e. | |
5162 | the `containing_scope' parameter) to `output_decl' (as | |
5163 | we ought to) we instead pass a pointer to our own private | |
5164 | fake_containing_scope node. That node is a RECORD_TYPE | |
5165 | node which NO OTHER TYPE may ever actually be a member of. | |
5166 | ||
5167 | This pointer will ultimately get passed into `output_type' | |
5168 | as its `containing_scope' parameter. `Output_type' will | |
5169 | then perform its part in the hack... i.e. it will pend | |
5170 | the type of the formal parameter onto the pending_types | |
5171 | list. Later on, when we are done generating the whole | |
5172 | sequence of formal parameter DIEs for this function | |
5173 | definition, we will un-pend all previously pended types | |
5174 | of formal parameters for this function definition. | |
5175 | ||
5176 | This whole kludge prevents any type DIEs from being | |
5177 | mixed in with the formal parameter DIEs. That's good | |
5178 | because svr4 SDB believes that the list of formal | |
5179 | parameter DIEs for a function ends wherever the first | |
5180 | non-formal-parameter DIE appears. Thus, we have to | |
5181 | keep the formal parameter DIEs segregated. They must | |
5182 | all appear (consecutively) at the start of the list of | |
5183 | children for the DIE representing the function definition. | |
5184 | Then (and only then) may we output any additional DIEs | |
5185 | needed to represent the types of these formal parameters. | |
5186 | */ | |
e8363d4c | 5187 | |
1616a2ff | 5188 | /* |
5189 | When generating DIEs, generate the unspecified_parameters | |
5190 | DIE instead if we come across the arg "__builtin_va_alist" | |
5191 | */ | |
e8363d4c | 5192 | |
1616a2ff | 5193 | for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) |
5194 | if (TREE_CODE (parm) == PARM_DECL) | |
1eefe280 | 5195 | { |
1616a2ff | 5196 | if (DECL_NAME(parm) && |
5197 | !strcmp(IDENTIFIER_POINTER(DECL_NAME(parm)), | |
5198 | "__builtin_va_alist") ) | |
5199 | output_die (output_unspecified_parameters_die, decl); | |
5200 | else | |
5201 | output_decl (parm, fake_containing_scope); | |
5202 | } | |
e8363d4c | 5203 | |
1616a2ff | 5204 | /* |
5205 | Now that we have finished generating all of the DIEs to | |
5206 | represent the formal parameters themselves, force out | |
5207 | any DIEs needed to represent their types. We do this | |
5208 | simply by un-pending all previously pended types which | |
5209 | can legitimately go into the chain of children DIEs for | |
5210 | the current FUNCTION_DECL. | |
5211 | */ | |
e8363d4c | 5212 | |
1616a2ff | 5213 | output_pending_types_for_scope (decl); |
e8363d4c | 5214 | |
1616a2ff | 5215 | /* |
20dd417a | 5216 | Decide whether we need an unspecified_parameters DIE at the end. |
1616a2ff | 5217 | There are 2 more cases to do this for: |
5218 | 1) the ansi ... declaration - this is detectable when the end | |
5219 | of the arg list is not a void_type_node | |
5220 | 2) an unprototyped function declaration (not a definition). This | |
5221 | just means that we have no info about the parameters at all. | |
5222 | */ | |
e8363d4c | 5223 | |
5224 | { | |
19cb6b50 | 5225 | tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); |
e8363d4c | 5226 | |
5227 | if (fn_arg_types) | |
5228 | { | |
a92771b8 | 5229 | /* this is the prototyped case, check for ... */ |
1616a2ff | 5230 | if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) |
5231 | output_die (output_unspecified_parameters_die, decl); | |
1eefe280 | 5232 | } |
5233 | else | |
5234 | { | |
5235 | /* this is unprototyped, check for undefined (just declaration) */ | |
5236 | if (!DECL_INITIAL (decl)) | |
5237 | output_die (output_unspecified_parameters_die, decl); | |
5238 | } | |
e8363d4c | 5239 | } |
e8363d4c | 5240 | |
6efd403b | 5241 | /* Output Dwarf info for all of the stuff within the body of the |
5242 | function (if it has one - it may be just a declaration). */ | |
e8363d4c | 5243 | |
e8363d4c | 5244 | { |
19cb6b50 | 5245 | tree outer_scope = DECL_INITIAL (decl); |
6efd403b | 5246 | |
5247 | if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK) | |
5248 | { | |
5249 | /* Note that here, `outer_scope' is a pointer to the outermost | |
5250 | BLOCK node created to represent a function. | |
5251 | This outermost BLOCK actually represents the outermost | |
5252 | binding contour for the function, i.e. the contour in which | |
5253 | the function's formal parameters and labels get declared. | |
5254 | ||
5255 | Curiously, it appears that the front end doesn't actually | |
5256 | put the PARM_DECL nodes for the current function onto the | |
5257 | BLOCK_VARS list for this outer scope. (They are strung | |
5258 | off of the DECL_ARGUMENTS list for the function instead.) | |
5259 | The BLOCK_VARS list for the `outer_scope' does provide us | |
5260 | with a list of the LABEL_DECL nodes for the function however, | |
5261 | and we output DWARF info for those here. | |
5262 | ||
5263 | Just within the `outer_scope' there will be a BLOCK node | |
5264 | representing the function's outermost pair of curly braces, | |
5265 | and any blocks used for the base and member initializers of | |
5266 | a C++ constructor function. */ | |
5267 | ||
5268 | output_decls_for_scope (outer_scope, 0); | |
5269 | ||
5270 | /* Finally, force out any pending types which are local to the | |
5271 | outermost block of this function definition. These will | |
5272 | all have a TYPE_CONTEXT which points to the FUNCTION_DECL | |
5273 | node itself. */ | |
5274 | ||
5275 | output_pending_types_for_scope (decl); | |
5276 | } | |
e8363d4c | 5277 | } |
6efd403b | 5278 | } |
e8363d4c | 5279 | |
5280 | /* Generate a terminator for the list of stuff `owned' by this | |
5281 | function. */ | |
5282 | ||
5283 | end_sibling_chain (); | |
5284 | ||
5285 | break; | |
5286 | ||
5287 | case TYPE_DECL: | |
5288 | /* If we are in terse mode, don't generate any DIEs to represent | |
5289 | any actual typedefs. Note that even when we are in terse mode, | |
5290 | we must still output DIEs to represent those tagged types which | |
5291 | are used (directly or indirectly) in the specification of either | |
5292 | a return type or a formal parameter type of some function. */ | |
5293 | ||
5294 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
6efd403b | 5295 | if (! TYPE_DECL_IS_STUB (decl) |
5296 | || (! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl)) && ! in_class)) | |
1eefe280 | 5297 | return; |
e8363d4c | 5298 | |
6efd403b | 5299 | /* In the special case of a TYPE_DECL node representing |
5300 | the declaration of some type tag, if the given TYPE_DECL is | |
ffb15922 | 5301 | marked as having been instantiated from some other (original) |
5302 | TYPE_DECL node (e.g. one which was generated within the original | |
5303 | definition of an inline function) we have to generate a special | |
5304 | (abbreviated) TAG_structure_type, TAG_union_type, or | |
5305 | TAG_enumeration-type DIE here. */ | |
5306 | ||
6efd403b | 5307 | if (TYPE_DECL_IS_STUB (decl) && DECL_ABSTRACT_ORIGIN (decl)) |
ffb15922 | 5308 | { |
5309 | output_tagged_type_instantiation (TREE_TYPE (decl)); | |
5310 | return; | |
5311 | } | |
5312 | ||
e8363d4c | 5313 | output_type (TREE_TYPE (decl), containing_scope); |
5314 | ||
6efd403b | 5315 | if (! is_redundant_typedef (decl)) |
e8363d4c | 5316 | /* Output a DIE to represent the typedef itself. */ |
5317 | output_die (output_typedef_die, decl); | |
5318 | break; | |
5319 | ||
5320 | case LABEL_DECL: | |
5321 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
5322 | output_die (output_label_die, decl); | |
5323 | break; | |
5324 | ||
5325 | case VAR_DECL: | |
bad5b016 | 5326 | /* If we are conforming to the DWARF version 1 specification, don't |
5327 | generated any DIEs to represent mere external object declarations. */ | |
5328 | ||
5329 | #if (DWARF_VERSION <= 1) | |
8fc7a3d0 | 5330 | if (DECL_EXTERNAL (decl) && ! TREE_PUBLIC (decl)) |
bad5b016 | 5331 | break; |
5332 | #endif | |
5333 | ||
e8363d4c | 5334 | /* If we are in terse mode, don't generate any DIEs to represent |
5335 | any variable declarations or definitions. */ | |
5336 | ||
5337 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
1eefe280 | 5338 | break; |
e8363d4c | 5339 | |
5340 | /* Output any DIEs that are needed to specify the type of this data | |
5341 | object. */ | |
5342 | ||
5343 | output_type (TREE_TYPE (decl), containing_scope); | |
5344 | ||
6efd403b | 5345 | { |
5346 | /* And its containing type. */ | |
5347 | register tree origin = decl_class_context (decl); | |
5348 | if (origin) | |
5349 | output_type (origin, containing_scope); | |
5350 | } | |
5351 | ||
e8363d4c | 5352 | /* If the following DIE will represent a data object definition for a |
5353 | data object with "extern" linkage, output a special "pubnames" DIE | |
5354 | label just ahead of the actual DIE. A reference to this label | |
5355 | was already generated in the .debug_pubnames section sub-entry | |
5356 | for this data object definition. */ | |
5357 | ||
ffb15922 | 5358 | if (TREE_PUBLIC (decl) && ! DECL_ABSTRACT (decl)) |
e8363d4c | 5359 | { |
5360 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5361 | ||
5362 | sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++); | |
5363 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
5364 | } | |
5365 | ||
ffb15922 | 5366 | /* Now output the DIE to represent the data object itself. This gets |
5367 | complicated because of the possibility that the VAR_DECL really | |
5368 | represents an inlined instance of a formal parameter for an inline | |
5369 | function. */ | |
5370 | ||
5371 | { | |
8ec3a57b | 5372 | void (*func) (void *); |
ffb15922 | 5373 | register tree origin = decl_ultimate_origin (decl); |
e8363d4c | 5374 | |
ffb15922 | 5375 | if (origin != NULL && TREE_CODE (origin) == PARM_DECL) |
5376 | func = output_formal_parameter_die; | |
5377 | else | |
5378 | { | |
8fc7a3d0 | 5379 | if (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)) |
ffb15922 | 5380 | func = output_global_variable_die; |
5381 | else | |
5382 | func = output_local_variable_die; | |
5383 | } | |
5384 | output_die (func, decl); | |
5385 | } | |
e8363d4c | 5386 | break; |
5387 | ||
5388 | case FIELD_DECL: | |
5389 | /* Ignore the nameless fields that are used to skip bits. */ | |
5390 | if (DECL_NAME (decl) != 0) | |
5391 | { | |
5392 | output_type (member_declared_type (decl), containing_scope); | |
1eefe280 | 5393 | output_die (output_member_die, decl); |
e8363d4c | 5394 | } |
5395 | break; | |
5396 | ||
5397 | case PARM_DECL: | |
5398 | /* Force out the type of this formal, if it was not forced out yet. | |
3fb1e43b | 5399 | Note that here we can run afoul of a bug in "classic" svr4 SDB. |
e8363d4c | 5400 | It should be able to grok the presence of type DIEs within a list |
5401 | of TAG_formal_parameter DIEs, but it doesn't. */ | |
5402 | ||
5403 | output_type (TREE_TYPE (decl), containing_scope); | |
5404 | output_die (output_formal_parameter_die, decl); | |
5405 | break; | |
5406 | ||
0dbc398a | 5407 | case NAMESPACE_DECL: |
5408 | /* Ignore for now. */ | |
5409 | break; | |
5410 | ||
e8363d4c | 5411 | default: |
5412 | abort (); | |
5413 | } | |
5414 | } | |
5415 | \f | |
c37d72e9 | 5416 | /* Output debug information for a function. */ |
5417 | static void | |
8ec3a57b | 5418 | dwarfout_function_decl (tree decl) |
c37d72e9 | 5419 | { |
5420 | dwarfout_file_scope_decl (decl, 0); | |
5421 | } | |
5422 | ||
5423 | /* Debug information for a global DECL. Called from toplev.c after | |
5424 | compilation proper has finished. */ | |
5425 | static void | |
8ec3a57b | 5426 | dwarfout_global_decl (tree decl) |
c37d72e9 | 5427 | { |
5428 | /* Output DWARF information for file-scope tentative data object | |
5429 | declarations, file-scope (extern) function declarations (which | |
5430 | had no corresponding body) and file-scope tagged type | |
5431 | declarations and definitions which have not yet been forced out. */ | |
5432 | ||
5433 | if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)) | |
5434 | dwarfout_file_scope_decl (decl, 1); | |
5435 | } | |
5436 | ||
5437 | /* DECL is an inline function, whose body is present, but which is not | |
5438 | being output at this point. (We're putting that off until we need | |
5439 | to do it.) */ | |
5440 | static void | |
8ec3a57b | 5441 | dwarfout_deferred_inline_function (tree decl) |
c37d72e9 | 5442 | { |
5443 | /* Generate the DWARF info for the "abstract" instance of a function | |
5444 | which we may later generate inlined and/or out-of-line instances | |
5445 | of. */ | |
5446 | if ((DECL_INLINE (decl) || DECL_ABSTRACT (decl)) | |
5447 | && ! DECL_ABSTRACT_ORIGIN (decl)) | |
5448 | { | |
5449 | /* The front-end may not have set CURRENT_FUNCTION_DECL, but the | |
5450 | DWARF code expects it to be set in this case. Intuitively, | |
5451 | DECL is the function we just finished defining, so setting | |
5452 | CURRENT_FUNCTION_DECL is sensible. */ | |
5453 | tree saved_cfd = current_function_decl; | |
5454 | int was_abstract = DECL_ABSTRACT (decl); | |
5455 | current_function_decl = decl; | |
5456 | ||
5457 | /* Let the DWARF code do its work. */ | |
5458 | set_decl_abstract_flags (decl, 1); | |
5459 | dwarfout_file_scope_decl (decl, 0); | |
5460 | if (! was_abstract) | |
5461 | set_decl_abstract_flags (decl, 0); | |
5462 | ||
5463 | /* Reset CURRENT_FUNCTION_DECL. */ | |
5464 | current_function_decl = saved_cfd; | |
5465 | } | |
5466 | } | |
5467 | ||
5468 | static void | |
8ec3a57b | 5469 | dwarfout_file_scope_decl (tree decl, int set_finalizing) |
e8363d4c | 5470 | { |
d2b8625b | 5471 | if (TREE_CODE (decl) == ERROR_MARK) |
5472 | return; | |
5473 | ||
ad2fe2cd | 5474 | /* If this ..._DECL node is marked to be ignored, then ignore it. */ |
d2b8625b | 5475 | |
5476 | if (DECL_IGNORED_P (decl)) | |
ad2fe2cd | 5477 | return; |
d2b8625b | 5478 | |
e8363d4c | 5479 | switch (TREE_CODE (decl)) |
5480 | { | |
5481 | case FUNCTION_DECL: | |
5482 | ||
d2b8625b | 5483 | /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of |
5484 | a builtin function. Explicit programmer-supplied declarations of | |
5485 | these same functions should NOT be ignored however. */ | |
e8363d4c | 5486 | |
8fc7a3d0 | 5487 | if (DECL_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl)) |
1eefe280 | 5488 | return; |
e8363d4c | 5489 | |
d17aae73 | 5490 | /* What we would really like to do here is to filter out all mere |
5491 | file-scope declarations of file-scope functions which are never | |
5492 | referenced later within this translation unit (and keep all of | |
c3418f42 | 5493 | ones that *are* referenced later on) but we aren't clairvoyant, |
d17aae73 | 5494 | so we have no idea which functions will be referenced in the |
5495 | future (i.e. later on within the current translation unit). | |
5496 | So here we just ignore all file-scope function declarations | |
5497 | which are not also definitions. If and when the debugger needs | |
3fb1e43b | 5498 | to know something about these functions, it will have to hunt |
d17aae73 | 5499 | around and find the DWARF information associated with the |
5500 | *definition* of the function. | |
5501 | ||
5502 | Note that we can't just check `DECL_EXTERNAL' to find out which | |
5503 | FUNCTION_DECL nodes represent definitions and which ones represent | |
5504 | mere declarations. We have to check `DECL_INITIAL' instead. That's | |
5505 | because the C front-end supports some weird semantics for "extern | |
5506 | inline" function definitions. These can get inlined within the | |
5507 | current translation unit (an thus, we need to generate DWARF info | |
5508 | for their abstract instances so that the DWARF info for the | |
5509 | concrete inlined instances can have something to refer to) but | |
5510 | the compiler never generates any out-of-lines instances of such | |
5511 | things (despite the fact that they *are* definitions). The | |
5512 | important point is that the C front-end marks these "extern inline" | |
be7e1458 | 5513 | functions as DECL_EXTERNAL, but we need to generate DWARF for them |
d17aae73 | 5514 | anyway. |
5515 | ||
5516 | Note that the C++ front-end also plays some similar games for inline | |
5517 | function definitions appearing within include files which also | |
5518 | contain `#pragma interface' pragmas. */ | |
5519 | ||
5520 | if (DECL_INITIAL (decl) == NULL_TREE) | |
e8363d4c | 5521 | return; |
5522 | ||
ffb15922 | 5523 | if (TREE_PUBLIC (decl) |
8fc7a3d0 | 5524 | && ! DECL_EXTERNAL (decl) |
ffb15922 | 5525 | && ! DECL_ABSTRACT (decl)) |
e8363d4c | 5526 | { |
5527 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5528 | ||
5529 | /* Output a .debug_pubnames entry for a public function | |
5530 | defined in this compilation unit. */ | |
5531 | ||
5532 | fputc ('\n', asm_out_file); | |
049aa99b | 5533 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION); |
e8363d4c | 5534 | sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number); |
5535 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, label); | |
01e45963 | 5536 | ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, |
e8363d4c | 5537 | IDENTIFIER_POINTER (DECL_NAME (decl))); |
23535a0a | 5538 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 5539 | } |
5540 | ||
5541 | break; | |
5542 | ||
5543 | case VAR_DECL: | |
5544 | ||
5545 | /* Ignore this VAR_DECL if it refers to a file-scope extern data | |
5546 | object declaration and if the declaration was never even | |
5547 | referenced from within this entire compilation unit. We | |
5548 | suppress these DIEs in order to save space in the .debug section | |
5549 | (by eliminating entries which are probably useless). Note that | |
5550 | we must not suppress block-local extern declarations (whether | |
5551 | used or not) because that would screw-up the debugger's name | |
5552 | lookup mechanism and cause it to miss things which really ought | |
5553 | to be in scope at a given point. */ | |
5554 | ||
8fc7a3d0 | 5555 | if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) |
e8363d4c | 5556 | return; |
5557 | ||
4bbea254 | 5558 | if (TREE_PUBLIC (decl) |
8fc7a3d0 | 5559 | && ! DECL_EXTERNAL (decl) |
ffb15922 | 5560 | && GET_CODE (DECL_RTL (decl)) == MEM |
5561 | && ! DECL_ABSTRACT (decl)) | |
e8363d4c | 5562 | { |
5563 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5564 | ||
5565 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
5566 | { | |
5567 | /* Output a .debug_pubnames entry for a public variable | |
5568 | defined in this compilation unit. */ | |
5569 | ||
5570 | fputc ('\n', asm_out_file); | |
049aa99b | 5571 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION); |
e8363d4c | 5572 | sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number); |
5573 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, label); | |
01e45963 | 5574 | ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, |
e8363d4c | 5575 | IDENTIFIER_POINTER (DECL_NAME (decl))); |
23535a0a | 5576 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 5577 | } |
5578 | ||
5579 | if (DECL_INITIAL (decl) == NULL) | |
5580 | { | |
5581 | /* Output a .debug_aranges entry for a public variable | |
4bbea254 | 5582 | which is tentatively defined in this compilation unit. */ |
e8363d4c | 5583 | |
5584 | fputc ('\n', asm_out_file); | |
049aa99b | 5585 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION); |
e8363d4c | 5586 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, |
88ef61d1 | 5587 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); |
1eefe280 | 5588 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, |
e8363d4c | 5589 | (unsigned) int_size_in_bytes (TREE_TYPE (decl))); |
23535a0a | 5590 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 5591 | } |
5592 | } | |
5593 | ||
5594 | /* If we are in terse mode, don't generate any DIEs to represent | |
5595 | any variable declarations or definitions. */ | |
5596 | ||
5597 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
1eefe280 | 5598 | return; |
e8363d4c | 5599 | |
5600 | break; | |
5601 | ||
5602 | case TYPE_DECL: | |
4be6300a | 5603 | /* Don't bother trying to generate any DIEs to represent any of the |
5604 | normal built-in types for the language we are compiling, except | |
5605 | in cases where the types in question are *not* DWARF fundamental | |
5606 | types. We make an exception in the case of non-fundamental types | |
7ef5b942 | 5607 | for the sake of Objective-C (and perhaps C++) because the GNU |
4be6300a | 5608 | front-ends for these languages may in fact create certain "built-in" |
5609 | types which are (for example) RECORD_TYPEs. In such cases, we | |
5610 | really need to output these (non-fundamental) types because other | |
5611 | DIEs may contain references to them. */ | |
5612 | ||
7a588fdf | 5613 | /* Also ignore language dependent types here, because they are probably |
5614 | also built-in types. If we didn't ignore them, then we would get | |
5615 | references to undefined labels because output_type doesn't support | |
5616 | them. So, for now, we need to ignore them to avoid assembler | |
5617 | errors. */ | |
5618 | ||
5619 | /* ??? This code is different than the equivalent code in dwarf2out.c. | |
5620 | The dwarf2out.c code is probably more correct. */ | |
5621 | ||
4be6300a | 5622 | if (DECL_SOURCE_LINE (decl) == 0 |
7a588fdf | 5623 | && (type_is_fundamental (TREE_TYPE (decl)) |
5624 | || TREE_CODE (TREE_TYPE (decl)) == LANG_TYPE)) | |
e8363d4c | 5625 | return; |
5626 | ||
5627 | /* If we are in terse mode, don't generate any DIEs to represent | |
5628 | any actual typedefs. Note that even when we are in terse mode, | |
5629 | we must still output DIEs to represent those tagged types which | |
5630 | are used (directly or indirectly) in the specification of either | |
5631 | a return type or a formal parameter type of some function. */ | |
5632 | ||
5633 | if (debug_info_level <= DINFO_LEVEL_TERSE) | |
eae9063c | 5634 | if (! TYPE_DECL_IS_STUB (decl) |
e8363d4c | 5635 | || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl))) |
1eefe280 | 5636 | return; |
e8363d4c | 5637 | |
5638 | break; | |
5639 | ||
5640 | default: | |
5641 | return; | |
5642 | } | |
5643 | ||
5644 | fputc ('\n', asm_out_file); | |
23535a0a | 5645 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION); |
e8363d4c | 5646 | finalizing = set_finalizing; |
b572011e | 5647 | output_decl (decl, NULL_TREE); |
e8363d4c | 5648 | |
5649 | /* NOTE: The call above to `output_decl' may have caused one or more | |
5650 | file-scope named types (i.e. tagged types) to be placed onto the | |
5651 | pending_types_list. We have to get those types off of that list | |
5652 | at some point, and this is the perfect time to do it. If we didn't | |
5653 | take them off now, they might still be on the list when cc1 finally | |
5654 | exits. That might be OK if it weren't for the fact that when we put | |
5655 | types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag | |
5656 | for these types, and that causes them never to be output unless | |
5657 | `output_pending_types_for_scope' takes them off of the list and un-sets | |
5658 | their TREE_ASM_WRITTEN flags. */ | |
5659 | ||
b572011e | 5660 | output_pending_types_for_scope (NULL_TREE); |
e8363d4c | 5661 | |
1a079993 | 5662 | /* The above call should have totally emptied the pending_types_list |
5663 | if this is not a nested function or class. If this is a nested type, | |
5664 | then the remaining pending_types will be emitted when the containing type | |
5665 | is handled. */ | |
1eefe280 | 5666 | |
1a079993 | 5667 | if (! DECL_CONTEXT (decl)) |
5668 | { | |
5669 | if (pending_types != 0) | |
5670 | abort (); | |
5671 | } | |
e8363d4c | 5672 | |
23535a0a | 5673 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 5674 | } |
5675 | \f | |
5676 | /* Output a marker (i.e. a label) for the beginning of the generated code | |
5677 | for a lexical block. */ | |
5678 | ||
1dff614c | 5679 | static void |
8ec3a57b | 5680 | dwarfout_begin_block (unsigned int line ATTRIBUTE_UNUSED, |
5681 | unsigned int blocknum) | |
e8363d4c | 5682 | { |
5683 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5684 | ||
b409d58e | 5685 | function_section (current_function_decl); |
e8363d4c | 5686 | sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum); |
5687 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
5688 | } | |
5689 | ||
5690 | /* Output a marker (i.e. a label) for the end of the generated code | |
5691 | for a lexical block. */ | |
5692 | ||
1dff614c | 5693 | static void |
8ec3a57b | 5694 | dwarfout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int blocknum) |
e8363d4c | 5695 | { |
5696 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5697 | ||
b409d58e | 5698 | function_section (current_function_decl); |
e8363d4c | 5699 | sprintf (label, BLOCK_END_LABEL_FMT, blocknum); |
5700 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
5701 | } | |
5702 | ||
cf6a3b88 | 5703 | /* Output a marker (i.e. a label) for the point in the generated code where |
5704 | the real body of the function begins (after parameters have been moved | |
5705 | to their home locations). */ | |
5706 | ||
f76df888 | 5707 | static void |
8ec3a57b | 5708 | dwarfout_end_prologue (unsigned int line ATTRIBUTE_UNUSED, |
5709 | const char *file ATTRIBUTE_UNUSED) | |
cf6a3b88 | 5710 | { |
5711 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5712 | ||
6efd403b | 5713 | if (! use_gnu_debug_info_extensions) |
5714 | return; | |
f76df888 | 5715 | |
b409d58e | 5716 | function_section (current_function_decl); |
4781f9b9 | 5717 | sprintf (label, BODY_BEGIN_LABEL_FMT, current_function_funcdef_no); |
cf6a3b88 | 5718 | ASM_OUTPUT_LABEL (asm_out_file, label); |
5719 | } | |
5720 | ||
5721 | /* Output a marker (i.e. a label) for the point in the generated code where | |
5722 | the real body of the function ends (just before the epilogue code). */ | |
5723 | ||
b9b7f8b4 | 5724 | static void |
8ec3a57b | 5725 | dwarfout_end_function (unsigned int line ATTRIBUTE_UNUSED) |
cf6a3b88 | 5726 | { |
5727 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5728 | ||
6efd403b | 5729 | if (! use_gnu_debug_info_extensions) |
5730 | return; | |
b409d58e | 5731 | function_section (current_function_decl); |
4781f9b9 | 5732 | sprintf (label, BODY_END_LABEL_FMT, current_function_funcdef_no); |
cf6a3b88 | 5733 | ASM_OUTPUT_LABEL (asm_out_file, label); |
5734 | } | |
5735 | ||
e8363d4c | 5736 | /* Output a marker (i.e. a label) for the absolute end of the generated code |
5737 | for a function definition. This gets called *after* the epilogue code | |
5738 | has been generated. */ | |
5739 | ||
b9b7f8b4 | 5740 | static void |
8ec3a57b | 5741 | dwarfout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED, |
5742 | const char *file ATTRIBUTE_UNUSED) | |
e8363d4c | 5743 | { |
5744 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5745 | ||
5746 | /* Output a label to mark the endpoint of the code generated for this | |
5747 | function. */ | |
5748 | ||
4781f9b9 | 5749 | sprintf (label, FUNC_END_LABEL_FMT, current_function_funcdef_no); |
e8363d4c | 5750 | ASM_OUTPUT_LABEL (asm_out_file, label); |
5751 | } | |
5752 | ||
5753 | static void | |
8ec3a57b | 5754 | shuffle_filename_entry (filename_entry *new_zeroth) |
e8363d4c | 5755 | { |
5756 | filename_entry temp_entry; | |
19cb6b50 | 5757 | filename_entry *limit_p; |
5758 | filename_entry *move_p; | |
e8363d4c | 5759 | |
5760 | if (new_zeroth == &filename_table[0]) | |
5761 | return; | |
5762 | ||
5763 | temp_entry = *new_zeroth; | |
5764 | ||
5765 | /* Shift entries up in the table to make room at [0]. */ | |
5766 | ||
5767 | limit_p = &filename_table[0]; | |
5768 | for (move_p = new_zeroth; move_p > limit_p; move_p--) | |
5769 | *move_p = *(move_p-1); | |
5770 | ||
5771 | /* Install the found entry at [0]. */ | |
5772 | ||
5773 | filename_table[0] = temp_entry; | |
5774 | } | |
5775 | ||
5776 | /* Create a new (string) entry for the .debug_sfnames section. */ | |
5777 | ||
5778 | static void | |
8ec3a57b | 5779 | generate_new_sfname_entry (void) |
e8363d4c | 5780 | { |
5781 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5782 | ||
5783 | fputc ('\n', asm_out_file); | |
049aa99b | 5784 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION); |
e8363d4c | 5785 | sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number); |
5786 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
01e45963 | 5787 | ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, |
1eefe280 | 5788 | filename_table[0].name |
5789 | ? filename_table[0].name | |
5790 | : ""); | |
23535a0a | 5791 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 5792 | } |
5793 | ||
5794 | /* Lookup a filename (in the list of filenames that we know about here in | |
5795 | dwarfout.c) and return its "index". The index of each (known) filename | |
5796 | is just a unique number which is associated with only that one filename. | |
5797 | We need such numbers for the sake of generating labels (in the | |
5798 | .debug_sfnames section) and references to those unique labels (in the | |
5799 | .debug_srcinfo and .debug_macinfo sections). | |
5800 | ||
5801 | If the filename given as an argument is not found in our current list, | |
5802 | add it to the list and assign it the next available unique index number. | |
5803 | ||
5804 | Whatever we do (i.e. whether we find a pre-existing filename or add a new | |
5805 | one), we shuffle the filename found (or added) up to the zeroth entry of | |
5806 | our list of filenames (which is always searched linearly). We do this so | |
5807 | as to optimize the most common case for these filename lookups within | |
5808 | dwarfout.c. The most common case by far is the case where we call | |
5809 | lookup_filename to lookup the very same filename that we did a lookup | |
5810 | on the last time we called lookup_filename. We make sure that this | |
5811 | common case is fast because such cases will constitute 99.9% of the | |
5812 | lookups we ever do (in practice). | |
5813 | ||
5814 | If we add a new filename entry to our table, we go ahead and generate | |
5815 | the corresponding entry in the .debug_sfnames section right away. | |
5816 | Doing so allows us to avoid tickling an assembler bug (present in some | |
5817 | m68k assemblers) which yields assembly-time errors in cases where the | |
5818 | difference of two label addresses is taken and where the two labels | |
5819 | are in a section *other* than the one where the difference is being | |
5820 | calculated, and where at least one of the two symbol references is a | |
5821 | forward reference. (This bug could be tickled by our .debug_srcinfo | |
5822 | entries if we don't output their corresponding .debug_sfnames entries | |
7bfbda1f | 5823 | before them.) */ |
e8363d4c | 5824 | |
5825 | static unsigned | |
8ec3a57b | 5826 | lookup_filename (const char *file_name) |
e8363d4c | 5827 | { |
19cb6b50 | 5828 | filename_entry *search_p; |
5829 | filename_entry *limit_p = &filename_table[ft_entries]; | |
e8363d4c | 5830 | |
5831 | for (search_p = filename_table; search_p < limit_p; search_p++) | |
5832 | if (!strcmp (file_name, search_p->name)) | |
5833 | { | |
5834 | /* When we get here, we have found the filename that we were | |
5835 | looking for in the filename_table. Now we want to make sure | |
5836 | that it gets moved to the zero'th entry in the table (if it | |
5837 | is not already there) so that subsequent attempts to find the | |
5838 | same filename will find it as quickly as possible. */ | |
5839 | ||
5840 | shuffle_filename_entry (search_p); | |
1eefe280 | 5841 | return filename_table[0].number; |
e8363d4c | 5842 | } |
5843 | ||
5844 | /* We come here whenever we have a new filename which is not registered | |
5845 | in the current table. Here we add it to the table. */ | |
5846 | ||
5847 | /* Prepare to add a new table entry by making sure there is enough space | |
5848 | in the table to do so. If not, expand the current table. */ | |
5849 | ||
5850 | if (ft_entries == ft_entries_allocated) | |
5851 | { | |
5852 | ft_entries_allocated += FT_ENTRIES_INCREMENT; | |
5853 | filename_table | |
5854 | = (filename_entry *) | |
5855 | xrealloc (filename_table, | |
5856 | ft_entries_allocated * sizeof (filename_entry)); | |
5857 | } | |
5858 | ||
5859 | /* Initially, add the new entry at the end of the filename table. */ | |
5860 | ||
5861 | filename_table[ft_entries].number = ft_entries; | |
5862 | filename_table[ft_entries].name = xstrdup (file_name); | |
5863 | ||
5864 | /* Shuffle the new entry into filename_table[0]. */ | |
5865 | ||
5866 | shuffle_filename_entry (&filename_table[ft_entries]); | |
5867 | ||
5868 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
5869 | generate_new_sfname_entry (); | |
5870 | ||
5871 | ft_entries++; | |
5872 | return filename_table[0].number; | |
5873 | } | |
5874 | ||
5875 | static void | |
8ec3a57b | 5876 | generate_srcinfo_entry (unsigned int line_entry_num, unsigned int files_entry_num) |
e8363d4c | 5877 | { |
5878 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5879 | ||
5880 | fputc ('\n', asm_out_file); | |
049aa99b | 5881 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION); |
e8363d4c | 5882 | sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num); |
5883 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL); | |
5884 | sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num); | |
5885 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL); | |
23535a0a | 5886 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 5887 | } |
5888 | ||
b9b7f8b4 | 5889 | static void |
8ec3a57b | 5890 | dwarfout_source_line (unsigned int line, const char *filename) |
e8363d4c | 5891 | { |
ce4974e0 | 5892 | if (debug_info_level >= DINFO_LEVEL_NORMAL |
5893 | /* We can't emit line number info for functions in separate sections, | |
5894 | because the assembler can't subtract labels in different sections. */ | |
5895 | && DECL_SECTION_NAME (current_function_decl) == NULL_TREE) | |
e8363d4c | 5896 | { |
5897 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
5898 | static unsigned last_line_entry_num = 0; | |
5899 | static unsigned prev_file_entry_num = (unsigned) -1; | |
19cb6b50 | 5900 | unsigned this_file_entry_num; |
e8363d4c | 5901 | |
b409d58e | 5902 | function_section (current_function_decl); |
e8363d4c | 5903 | sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num); |
5904 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
5905 | ||
5906 | fputc ('\n', asm_out_file); | |
e8363d4c | 5907 | |
6efd403b | 5908 | if (use_gnu_debug_info_extensions) |
5909 | this_file_entry_num = lookup_filename (filename); | |
5910 | else | |
5911 | this_file_entry_num = (unsigned) -1; | |
5912 | ||
ccf55086 | 5913 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION); |
e8363d4c | 5914 | if (this_file_entry_num != prev_file_entry_num) |
1eefe280 | 5915 | { |
5916 | char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
e8363d4c | 5917 | |
1eefe280 | 5918 | sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num); |
5919 | ASM_OUTPUT_LABEL (asm_out_file, line_entry_label); | |
5920 | } | |
e8363d4c | 5921 | |
5922 | { | |
1eefe280 | 5923 | const char *tail = strrchr (filename, '/'); |
e8363d4c | 5924 | |
1eefe280 | 5925 | if (tail != NULL) |
5926 | filename = tail; | |
e8363d4c | 5927 | } |
5928 | ||
58356836 | 5929 | dw2_asm_output_data (4, line, "%s:%u", filename, line); |
e8363d4c | 5930 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff); |
5931 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL); | |
23535a0a | 5932 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 5933 | |
5934 | if (this_file_entry_num != prev_file_entry_num) | |
1eefe280 | 5935 | generate_srcinfo_entry (last_line_entry_num, this_file_entry_num); |
e8363d4c | 5936 | prev_file_entry_num = this_file_entry_num; |
5937 | } | |
5938 | } | |
5939 | ||
5940 | /* Generate an entry in the .debug_macinfo section. */ | |
5941 | ||
5942 | static void | |
8ec3a57b | 5943 | generate_macinfo_entry (unsigned int type, rtx offset, const char *string) |
e8363d4c | 5944 | { |
6efd403b | 5945 | if (! use_gnu_debug_info_extensions) |
5946 | return; | |
5947 | ||
e8363d4c | 5948 | fputc ('\n', asm_out_file); |
049aa99b | 5949 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION); |
58356836 | 5950 | assemble_integer (gen_rtx_PLUS (SImode, GEN_INT (type << 24), offset), |
5951 | 4, BITS_PER_UNIT, 1); | |
01e45963 | 5952 | ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, string); |
23535a0a | 5953 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 5954 | } |
5955 | ||
c140b944 | 5956 | /* Wrapper for toplev.c callback to check debug info level. */ |
5957 | static void | |
8ec3a57b | 5958 | dwarfout_start_source_file_check (unsigned int line, const char *filename) |
c140b944 | 5959 | { |
5960 | if (debug_info_level == DINFO_LEVEL_VERBOSE) | |
5961 | dwarfout_start_source_file (line, filename); | |
5962 | } | |
5963 | ||
5964 | static void | |
8ec3a57b | 5965 | dwarfout_start_source_file (unsigned int line ATTRIBUTE_UNUSED, |
5966 | const char *filename) | |
e8363d4c | 5967 | { |
5968 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
58356836 | 5969 | const char *label1, *label2; |
e8363d4c | 5970 | |
5971 | sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename)); | |
58356836 | 5972 | label1 = (*label == '*') + label; |
5973 | label2 = (*SFNAMES_BEGIN_LABEL == '*') + SFNAMES_BEGIN_LABEL; | |
5974 | generate_macinfo_entry (MACINFO_start, | |
5975 | gen_rtx_MINUS (Pmode, | |
5976 | gen_rtx_SYMBOL_REF (Pmode, label1), | |
5977 | gen_rtx_SYMBOL_REF (Pmode, label2)), | |
5978 | ""); | |
e8363d4c | 5979 | } |
5980 | ||
c140b944 | 5981 | /* Wrapper for toplev.c callback to check debug info level. */ |
5982 | static void | |
8ec3a57b | 5983 | dwarfout_end_source_file_check (unsigned int lineno) |
c140b944 | 5984 | { |
5985 | if (debug_info_level == DINFO_LEVEL_VERBOSE) | |
5986 | dwarfout_end_source_file (lineno); | |
5987 | } | |
5988 | ||
5989 | static void | |
8ec3a57b | 5990 | dwarfout_end_source_file (unsigned int lineno) |
e8363d4c | 5991 | { |
58356836 | 5992 | generate_macinfo_entry (MACINFO_resume, GEN_INT (lineno), ""); |
e8363d4c | 5993 | } |
5994 | ||
5995 | /* Called from check_newline in c-parse.y. The `buffer' parameter | |
5996 | contains the tail part of the directive line, i.e. the part which | |
5997 | is past the initial whitespace, #, whitespace, directive-name, | |
5998 | whitespace part. */ | |
5999 | ||
c140b944 | 6000 | static void |
8ec3a57b | 6001 | dwarfout_define (unsigned int lineno, const char *buffer) |
e8363d4c | 6002 | { |
6003 | static int initialized = 0; | |
e8363d4c | 6004 | |
6005 | if (!initialized) | |
6006 | { | |
c140b944 | 6007 | dwarfout_start_source_file (0, primary_filename); |
e8363d4c | 6008 | initialized = 1; |
6009 | } | |
58356836 | 6010 | generate_macinfo_entry (MACINFO_define, GEN_INT (lineno), buffer); |
e8363d4c | 6011 | } |
6012 | ||
6013 | /* Called from check_newline in c-parse.y. The `buffer' parameter | |
6014 | contains the tail part of the directive line, i.e. the part which | |
6015 | is past the initial whitespace, #, whitespace, directive-name, | |
6016 | whitespace part. */ | |
6017 | ||
c140b944 | 6018 | static void |
8ec3a57b | 6019 | dwarfout_undef (unsigned int lineno, const char *buffer) |
e8363d4c | 6020 | { |
58356836 | 6021 | generate_macinfo_entry (MACINFO_undef, GEN_INT (lineno), buffer); |
e8363d4c | 6022 | } |
6023 | ||
6024 | /* Set up for Dwarf output at the start of compilation. */ | |
6025 | ||
b896d81b | 6026 | static void |
8ec3a57b | 6027 | dwarfout_init (const char *main_input_filename) |
e8363d4c | 6028 | { |
a015863c | 6029 | warning ("support for the DWARF1 debugging format is deprecated"); |
6030 | ||
e8363d4c | 6031 | /* Remember the name of the primary input file. */ |
6032 | ||
6033 | primary_filename = main_input_filename; | |
6034 | ||
6035 | /* Allocate the initial hunk of the pending_sibling_stack. */ | |
6036 | ||
6037 | pending_sibling_stack | |
6038 | = (unsigned *) | |
6039 | xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned)); | |
6040 | pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT; | |
6041 | pending_siblings = 1; | |
6042 | ||
6043 | /* Allocate the initial hunk of the filename_table. */ | |
6044 | ||
6045 | filename_table | |
6046 | = (filename_entry *) | |
6047 | xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry)); | |
6048 | ft_entries_allocated = FT_ENTRIES_INCREMENT; | |
6049 | ft_entries = 0; | |
6050 | ||
6051 | /* Allocate the initial hunk of the pending_types_list. */ | |
6052 | ||
6053 | pending_types_list | |
6054 | = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree)); | |
6055 | pending_types_allocated = PENDING_TYPES_INCREMENT; | |
6056 | pending_types = 0; | |
6057 | ||
6058 | /* Create an artificial RECORD_TYPE node which we can use in our hack | |
6059 | to get the DIEs representing types of formal parameters to come out | |
6060 | only *after* the DIEs for the formal parameters themselves. */ | |
6061 | ||
6062 | fake_containing_scope = make_node (RECORD_TYPE); | |
6063 | ||
6064 | /* Output a starting label for the .text section. */ | |
6065 | ||
6066 | fputc ('\n', asm_out_file); | |
25e5d448 | 6067 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION_NAME); |
e8363d4c | 6068 | ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL); |
23535a0a | 6069 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 6070 | |
6071 | /* Output a starting label for the .data section. */ | |
6072 | ||
6073 | fputc ('\n', asm_out_file); | |
25e5d448 | 6074 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION_NAME); |
e8363d4c | 6075 | ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL); |
23535a0a | 6076 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 6077 | |
60dd82d5 | 6078 | #if 0 /* GNU C doesn't currently use .data1. */ |
e8363d4c | 6079 | /* Output a starting label for the .data1 section. */ |
6080 | ||
6081 | fputc ('\n', asm_out_file); | |
25e5d448 | 6082 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION_NAME); |
e8363d4c | 6083 | ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL); |
23535a0a | 6084 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
60dd82d5 | 6085 | #endif |
e8363d4c | 6086 | |
6087 | /* Output a starting label for the .rodata section. */ | |
6088 | ||
6089 | fputc ('\n', asm_out_file); | |
25e5d448 | 6090 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION_NAME); |
e8363d4c | 6091 | ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL); |
23535a0a | 6092 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 6093 | |
60dd82d5 | 6094 | #if 0 /* GNU C doesn't currently use .rodata1. */ |
e8363d4c | 6095 | /* Output a starting label for the .rodata1 section. */ |
6096 | ||
6097 | fputc ('\n', asm_out_file); | |
25e5d448 | 6098 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION_NAME); |
e8363d4c | 6099 | ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL); |
23535a0a | 6100 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
60dd82d5 | 6101 | #endif |
e8363d4c | 6102 | |
6103 | /* Output a starting label for the .bss section. */ | |
6104 | ||
6105 | fputc ('\n', asm_out_file); | |
25e5d448 | 6106 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION_NAME); |
e8363d4c | 6107 | ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL); |
23535a0a | 6108 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 6109 | |
6110 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
6111 | { | |
6efd403b | 6112 | if (use_gnu_debug_info_extensions) |
6113 | { | |
6114 | /* Output a starting label and an initial (compilation directory) | |
6115 | entry for the .debug_sfnames section. The starting label will be | |
6116 | referenced by the initial entry in the .debug_srcinfo section. */ | |
1eefe280 | 6117 | |
6efd403b | 6118 | fputc ('\n', asm_out_file); |
049aa99b | 6119 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SFNAMES_SECTION); |
6efd403b | 6120 | ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL); |
6121 | { | |
19cb6b50 | 6122 | const char *pwd = getpwd (); |
6123 | char *dirname; | |
6efd403b | 6124 | |
6efd403b | 6125 | if (!pwd) |
d07c9932 | 6126 | fatal_error ("can't get current directory: %m"); |
f060a027 | 6127 | |
713829e9 | 6128 | dirname = concat (pwd, "/", NULL); |
01e45963 | 6129 | ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, dirname); |
6efd403b | 6130 | free (dirname); |
6131 | } | |
6132 | ASM_OUTPUT_POP_SECTION (asm_out_file); | |
6133 | } | |
1eefe280 | 6134 | |
6efd403b | 6135 | if (debug_info_level >= DINFO_LEVEL_VERBOSE |
6136 | && use_gnu_debug_info_extensions) | |
e8363d4c | 6137 | { |
1eefe280 | 6138 | /* Output a starting label for the .debug_macinfo section. This |
e8363d4c | 6139 | label will be referenced by the AT_mac_info attribute in the |
6140 | TAG_compile_unit DIE. */ | |
1eefe280 | 6141 | |
6142 | fputc ('\n', asm_out_file); | |
6143 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION); | |
6144 | ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL); | |
6145 | ASM_OUTPUT_POP_SECTION (asm_out_file); | |
e8363d4c | 6146 | } |
6147 | ||
6148 | /* Generate the initial entry for the .line section. */ | |
1eefe280 | 6149 | |
e8363d4c | 6150 | fputc ('\n', asm_out_file); |
23535a0a | 6151 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION); |
e8363d4c | 6152 | ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL); |
6153 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL); | |
6154 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL); | |
23535a0a | 6155 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
1eefe280 | 6156 | |
6efd403b | 6157 | if (use_gnu_debug_info_extensions) |
6158 | { | |
6159 | /* Generate the initial entry for the .debug_srcinfo section. */ | |
6160 | ||
6161 | fputc ('\n', asm_out_file); | |
049aa99b | 6162 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION); |
6efd403b | 6163 | ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL); |
6164 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL); | |
6165 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL); | |
6166 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL); | |
6167 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL); | |
e8363d4c | 6168 | #ifdef DWARF_TIMESTAMPS |
6efd403b | 6169 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL)); |
e8363d4c | 6170 | #else |
6efd403b | 6171 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1); |
e8363d4c | 6172 | #endif |
6efd403b | 6173 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
6174 | } | |
1eefe280 | 6175 | |
e8363d4c | 6176 | /* Generate the initial entry for the .debug_pubnames section. */ |
1eefe280 | 6177 | |
e8363d4c | 6178 | fputc ('\n', asm_out_file); |
049aa99b | 6179 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION); |
e8363d4c | 6180 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL); |
23535a0a | 6181 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
1eefe280 | 6182 | |
e8363d4c | 6183 | /* Generate the initial entry for the .debug_aranges section. */ |
1eefe280 | 6184 | |
e8363d4c | 6185 | fputc ('\n', asm_out_file); |
049aa99b | 6186 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION); |
0ebe8f79 | 6187 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, |
6188 | DEBUG_ARANGES_END_LABEL, | |
6189 | DEBUG_ARANGES_BEGIN_LABEL); | |
6190 | ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_BEGIN_LABEL); | |
6191 | ASM_OUTPUT_DWARF_DATA1 (asm_out_file, 1); | |
e8363d4c | 6192 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL); |
23535a0a | 6193 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 6194 | } |
6195 | ||
6196 | /* Setup first DIE number == 1. */ | |
6197 | NEXT_DIE_NUM = next_unused_dienum++; | |
6198 | ||
6199 | /* Generate the initial DIE for the .debug section. Note that the | |
6200 | (string) value given in the AT_name attribute of the TAG_compile_unit | |
6201 | DIE will (typically) be a relative pathname and that this pathname | |
6202 | should be taken as being relative to the directory from which the | |
6203 | compiler was invoked when the given (base) source file was compiled. */ | |
6204 | ||
6205 | fputc ('\n', asm_out_file); | |
23535a0a | 6206 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION); |
e8363d4c | 6207 | ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL); |
b9a7cc69 | 6208 | output_die (output_compile_unit_die, (void *) main_input_filename); |
23535a0a | 6209 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 6210 | |
6211 | fputc ('\n', asm_out_file); | |
6212 | } | |
6213 | ||
6214 | /* Output stuff that dwarf requires at the end of every file. */ | |
6215 | ||
b896d81b | 6216 | static void |
8ec3a57b | 6217 | dwarfout_finish (const char *main_input_filename ATTRIBUTE_UNUSED) |
e8363d4c | 6218 | { |
6219 | char label[MAX_ARTIFICIAL_LABEL_BYTES]; | |
6220 | ||
6221 | fputc ('\n', asm_out_file); | |
23535a0a | 6222 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SECTION); |
5a999c47 | 6223 | retry_incomplete_types (); |
6224 | fputc ('\n', asm_out_file); | |
e8363d4c | 6225 | |
6226 | /* Mark the end of the chain of siblings which represent all file-scope | |
6227 | declarations in this compilation unit. */ | |
6228 | ||
6229 | /* The (null) DIE which represents the terminator for the (sibling linked) | |
6230 | list of file-scope items is *special*. Normally, we would just call | |
6231 | end_sibling_chain at this point in order to output a word with the | |
6232 | value `4' and that word would act as the terminator for the list of | |
6233 | DIEs describing file-scope items. Unfortunately, if we were to simply | |
6234 | do that, the label that would follow this DIE in the .debug section | |
6235 | (i.e. `..D2') would *not* be properly aligned (as it must be on some | |
6236 | machines) to a 4 byte boundary. | |
6237 | ||
6238 | In order to force the label `..D2' to get aligned to a 4 byte boundary, | |
6239 | the trick used is to insert extra (otherwise useless) padding bytes | |
4bbea254 | 6240 | into the (null) DIE that we know must precede the ..D2 label in the |
e8363d4c | 6241 | .debug section. The amount of padding required can be anywhere between |
6242 | 0 and 3 bytes. The length word at the start of this DIE (i.e. the one | |
6243 | with the padding) would normally contain the value 4, but now it will | |
6244 | also have to include the padding bytes, so it will instead have some | |
6245 | value in the range 4..7. | |
6246 | ||
6247 | Fortunately, the rules of Dwarf say that any DIE whose length word | |
6248 | contains *any* value less than 8 should be treated as a null DIE, so | |
6249 | this trick works out nicely. Clever, eh? Don't give me any credit | |
6250 | (or blame). I didn't think of this scheme. I just conformed to it. | |
6251 | */ | |
6252 | ||
a92771b8 | 6253 | output_die (output_padded_null_die, (void *) 0); |
e8363d4c | 6254 | dienum_pop (); |
6255 | ||
6256 | sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM); | |
6257 | ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */ | |
23535a0a | 6258 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 6259 | |
6260 | /* Output a terminator label for the .text section. */ | |
6261 | ||
6262 | fputc ('\n', asm_out_file); | |
25e5d448 | 6263 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, TEXT_SECTION_NAME); |
e8363d4c | 6264 | ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL); |
23535a0a | 6265 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 6266 | |
6267 | /* Output a terminator label for the .data section. */ | |
6268 | ||
6269 | fputc ('\n', asm_out_file); | |
25e5d448 | 6270 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA_SECTION_NAME); |
e8363d4c | 6271 | ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL); |
23535a0a | 6272 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 6273 | |
60dd82d5 | 6274 | #if 0 /* GNU C doesn't currently use .data1. */ |
e8363d4c | 6275 | /* Output a terminator label for the .data1 section. */ |
6276 | ||
6277 | fputc ('\n', asm_out_file); | |
25e5d448 | 6278 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DATA1_SECTION_NAME); |
e8363d4c | 6279 | ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL); |
23535a0a | 6280 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
60dd82d5 | 6281 | #endif |
e8363d4c | 6282 | |
6283 | /* Output a terminator label for the .rodata section. */ | |
6284 | ||
6285 | fputc ('\n', asm_out_file); | |
25e5d448 | 6286 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA_SECTION_NAME); |
e8363d4c | 6287 | ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL); |
23535a0a | 6288 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 6289 | |
60dd82d5 | 6290 | #if 0 /* GNU C doesn't currently use .rodata1. */ |
e8363d4c | 6291 | /* Output a terminator label for the .rodata1 section. */ |
6292 | ||
6293 | fputc ('\n', asm_out_file); | |
25e5d448 | 6294 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, RODATA1_SECTION_NAME); |
e8363d4c | 6295 | ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL); |
23535a0a | 6296 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
60dd82d5 | 6297 | #endif |
e8363d4c | 6298 | |
6299 | /* Output a terminator label for the .bss section. */ | |
6300 | ||
6301 | fputc ('\n', asm_out_file); | |
25e5d448 | 6302 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, BSS_SECTION_NAME); |
e8363d4c | 6303 | ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL); |
23535a0a | 6304 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 6305 | |
6306 | if (debug_info_level >= DINFO_LEVEL_NORMAL) | |
6307 | { | |
6308 | /* Output a terminating entry for the .line section. */ | |
1eefe280 | 6309 | |
e8363d4c | 6310 | fputc ('\n', asm_out_file); |
23535a0a | 6311 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, LINE_SECTION); |
e8363d4c | 6312 | ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL); |
6313 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); | |
6314 | ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff); | |
6315 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL); | |
6316 | ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL); | |
23535a0a | 6317 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
1eefe280 | 6318 | |
6efd403b | 6319 | if (use_gnu_debug_info_extensions) |
6320 | { | |
6321 | /* Output a terminating entry for the .debug_srcinfo section. */ | |
6322 | ||
6323 | fputc ('\n', asm_out_file); | |
049aa99b | 6324 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_SRCINFO_SECTION); |
6efd403b | 6325 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, |
6326 | LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL); | |
6327 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1); | |
6328 | ASM_OUTPUT_POP_SECTION (asm_out_file); | |
6329 | } | |
e8363d4c | 6330 | |
6331 | if (debug_info_level >= DINFO_LEVEL_VERBOSE) | |
6332 | { | |
6333 | /* Output terminating entries for the .debug_macinfo section. */ | |
1eefe280 | 6334 | |
c140b944 | 6335 | dwarfout_end_source_file (0); |
e8363d4c | 6336 | |
6337 | fputc ('\n', asm_out_file); | |
049aa99b | 6338 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_MACINFO_SECTION); |
e8363d4c | 6339 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); |
01e45963 | 6340 | ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, ""); |
23535a0a | 6341 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 6342 | } |
1eefe280 | 6343 | |
e8363d4c | 6344 | /* Generate the terminating entry for the .debug_pubnames section. */ |
1eefe280 | 6345 | |
e8363d4c | 6346 | fputc ('\n', asm_out_file); |
049aa99b | 6347 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_PUBNAMES_SECTION); |
e8363d4c | 6348 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); |
01e45963 | 6349 | ASM_OUTPUT_DWARF_STRING_NEWLINE (asm_out_file, ""); |
23535a0a | 6350 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
1eefe280 | 6351 | |
e8363d4c | 6352 | /* Generate the terminating entries for the .debug_aranges section. |
6353 | ||
6354 | Note that we want to do this only *after* we have output the end | |
6355 | labels (for the various program sections) which we are going to | |
6356 | refer to here. This allows us to work around a bug in the m68k | |
6357 | svr4 assembler. That assembler gives bogus assembly-time errors | |
6358 | if (within any given section) you try to take the difference of | |
6359 | two relocatable symbols, both of which are located within some | |
6360 | other section, and if one (or both?) of the symbols involved is | |
6361 | being forward-referenced. By generating the .debug_aranges | |
6362 | entries at this late point in the assembly output, we skirt the | |
6363 | issue simply by avoiding forward-references. | |
6364 | */ | |
1eefe280 | 6365 | |
e8363d4c | 6366 | fputc ('\n', asm_out_file); |
049aa99b | 6367 | ASM_OUTPUT_PUSH_SECTION (asm_out_file, DEBUG_ARANGES_SECTION); |
e8363d4c | 6368 | |
6369 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL); | |
6370 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL); | |
6371 | ||
6372 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL); | |
6373 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL); | |
6374 | ||
60dd82d5 | 6375 | #if 0 /* GNU C doesn't currently use .data1. */ |
e8363d4c | 6376 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL); |
6377 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL, | |
6378 | DATA1_BEGIN_LABEL); | |
60dd82d5 | 6379 | #endif |
e8363d4c | 6380 | |
6381 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL); | |
6382 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL, | |
6383 | RODATA_BEGIN_LABEL); | |
6384 | ||
60dd82d5 | 6385 | #if 0 /* GNU C doesn't currently use .rodata1. */ |
e8363d4c | 6386 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL); |
6387 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL, | |
6388 | RODATA1_BEGIN_LABEL); | |
60dd82d5 | 6389 | #endif |
e8363d4c | 6390 | |
6391 | ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL); | |
6392 | ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL); | |
6393 | ||
6394 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); | |
6395 | ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); | |
6396 | ||
0ebe8f79 | 6397 | ASM_OUTPUT_LABEL (asm_out_file, DEBUG_ARANGES_END_LABEL); |
23535a0a | 6398 | ASM_OUTPUT_POP_SECTION (asm_out_file); |
e8363d4c | 6399 | } |
1a079993 | 6400 | |
6401 | /* There should not be any pending types left at the end. We need | |
6402 | this now because it may not have been checked on the last call to | |
6403 | dwarfout_file_scope_decl. */ | |
6404 | if (pending_types != 0) | |
6405 | abort (); | |
e8363d4c | 6406 | } |
6407 | ||
be6eb971 | 6408 | #endif /* DWARF_DEBUGGING_INFO */ |