home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / dwarfout.c < prev    next >
C/C++ Source or Header  |  1991-06-03  |  111KB  |  3,651 lines

  1. /* This file contains code written by Ron Guilmette (rfg@ncd.com) for
  2.    Network Computing Devices, August, September, October, November 1990.
  3.  
  4.    Output DWARF format symbol table information from the GNU C compiler.
  5.    Copyright (C) 1990, 1991 Free Software Foundation, Inc.
  6.  
  7. This file is part of GNU CC.
  8.  
  9. GNU CC is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2, or (at your option)
  12. any later version.
  13.  
  14. GNU CC is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with GNU CC; see the file COPYING.  If not, write to
  21. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  22.  
  23. #include "config.h"
  24.  
  25. #ifdef DWARF_DEBUGGING_INFO
  26. #include <stdio.h>
  27. #include <dwarf.h>
  28. #include "tree.h"
  29. #include "flags.h"
  30. #include "rtl.h"
  31. #include "output.h"
  32.  
  33. #define NDEBUG 1
  34. #include <assert.h>
  35.  
  36. #ifdef USG
  37. #include <string.h>
  38. #else
  39. #include <strings.h>
  40. #endif
  41.  
  42. #if 0 /* Probably not needed, now that we don't want MAXPATHLEN.  */
  43. #include <sys/param.h>
  44. #endif
  45.  
  46. /* IMPORTANT NOTE: Please see the file README.DWARF for important details
  47.    regarding the GNU implementation of DWARF.  */
  48.  
  49. /* NOTE: In the comments in this file, many references are made to
  50.    so called "Debugging Information Entries".  For the sake of brevity,
  51.    this term is abbreviated to `DIE' throughout the remainder of this
  52.    file.  */
  53.  
  54. /* Define GPLUSPLUS if this file is being used with the g++ compiler.  Note
  55.    that the implementation of C++ support herein is (as yet) unfinished.
  56.    If you want to use it, you're on your own.  */
  57.  
  58. /* Define DWARF_DESCRIBE_USED_EXTERNS if you want the GNU DWARF produced
  59.    by the code in this file to include descriptions of things (i.e. data
  60.    objects and functions) which are explicitly declared as `extern' and
  61.    which are also referenced within the current compilation.  This optional
  62.    feature will only be useful if you have a `smart linker' which is capable
  63.    of doing type checking across object files (based upon DWARF type
  64.    specifications).
  65.  
  66.    When this option is enabled, the descriptions of the external items
  67.    are placed into the (special) section called `.externs'.
  68.  
  69.    Please note that DWARF_DESCRIBE_USED_EXTERNS cannot be enabled unless
  70.    you have definitions for the attribute symbols AT_file, AT_line, and
  71.    AT_src_info in your dwarf.h file.
  72. */
  73.  
  74. /* Other extended features of GNU DWARF are enabled (as described below)
  75.    based upon the presence of #defines for various GNU DWARF extended
  76.    attributes in your dwarf.h file.  To disable these features, you will
  77.    have to either remove the applicable #defines from your dwarf.h file
  78.    or else you will have to #undef the relevant extended attribute names
  79.    somewhere (early) within this file.
  80. */
  81.  
  82. /* If the symbols AT_file and AT_line are defined, then the DWARF debugging
  83.    information produced by the code herein will include additional attribute
  84.    information which specifies the source file and source line for all kinds
  85.    of named entities.
  86.  
  87.    There are two cases in which the presence of these extended attributes
  88.    (in the DWARF debugging information) may be useful.
  89.  
  90.    First, as noted above in the description of the DWARF_DESCRIBE_USED_EXTERNS
  91.    option, if you have a `smart linker' which can do cross-module type
  92.    checking (based upon DWARF typing information) then the presence of AT_file
  93.    and AT_line attributes can give the `smart linker' the ability to pinpoint
  94.    (for the user) the file and line where a conflicting declaration of some
  95.    named entity occurs.
  96.  
  97.    Second, the presence of AT_file and AT_line attributes may be useful if
  98.    your debugger supports a command which will tell the user the exact
  99.    source location associated with a declaration (or definition) of some
  100.    named entity.
  101.  
  102.    Please note that in order for these additional attributes to be produced,
  103.    the symbol AT_src_info must also be defined in your dwarf.h file.
  104. */
  105.  
  106. /* If the symbol AT_src_info is defined in your dwarf.h file, then the DWARF
  107.    debugging information produced by the code herein will include additional
  108.    information (in the .srcfile and .srcinfo sections) giving the names of
  109.    all source files which contributed one or more lines of executable code
  110.    to the current compilation unit.
  111.  
  112.    It is STRONGLY recommended that this extended GNU DWARF feature always
  113.    be used because (a) it typically takes up very little additional space
  114.    in the object file and because (b) without it there is insufficient
  115.    information available to the debugger to allow it to understand and know
  116.    about code which was brought into the current compilation unit from an
  117.    include file.
  118.  
  119.    See the README.DWARF file for more information about AT_src_info attributes.
  120. */
  121.  
  122. /* If the symbol AT_comp_dir is defined in your dwarf.h file, then the DWARF
  123.    debugging information produced by the code herein will include one
  124.    additional attribute in each TAG_source_file DIE, namely the AT_comp_dir
  125.    attribute.  This is a string valued attribute which specifies the name
  126.    of the directory from whence the compiler was invoked when the compilation
  127.    unit in question was compiled.
  128. */
  129.  
  130. /* If the symbol AT_addr_ranges is defined within your dwarf.h file, then the
  131.    DWARF debugging information produced by the code herein will include one
  132.    additional attribute in each TAG_source_file DIE, namely the AT_addr_ranges
  133.    attribute.
  134.  
  135.    The AT_addr_ranges attribute is a FORM_BLOCK2 attribute whose value is a
  136.    set of low/high pairs of addresses.  Each pair of addresses consists of
  137.    two 32-bit numbers.  In each pair, the first of the two numbers is the
  138.    low address of the range and the second one is the high address of the
  139.    range plus one.  When present (as part of an AT_addr_ranges attribute)
  140.    these address pairs must give the address ranges for ALL of the sections
  141.    of the compilation unit which can contain entities (e.g. functions and
  142.    data objects) which were declared by the user.  This usually includes the
  143.    .text, .data, .bss, and .rodata sections.
  144.  
  145.    When present, at AT_addr_ranges attribute for a compilation unit can aid
  146.    the debugger in quickly finding the debug information for some named
  147.    entity.  Basically, when forced to lookup a name, the debugger can first
  148.    lookup the name in the linker symbol table (of the executable file) and
  149.    then, armed with the named entity's corresponding address (from the
  150.    linker symbol table), the debugger can quickly find out which compilation
  151.    unit contains the debugging information for the named entity.
  152. */
  153.  
  154. /* If the symbol AT_prototyped is defined within your dwarf.h file, then the
  155.    DWARF debugging information produced by the code herein will include one
  156.    additional attribute (namely the AT_prototyped attribute) for each
  157.    TAG_global_subroutine, TAG_inline_subroutine, TAG_member_function,
  158.    TAG_subroutine, or TAG_subroutine_type which is associated with an
  159.    entity for which a formal parameter list in prototype form was given.
  160.  
  161.    The AT_prototyped attribute is a flag attribute, and it has the form
  162.    FORM_NONE.
  163.  
  164.    This information may be essential to the debugger if the debugger allows
  165.    the user to make calls to functions which are part of the process being
  166.    debugged (as GDB does).  The reason that this information is important
  167.    is that when such calls are made to prototyped functions, the debugger
  168.    must properly coerce the types of any passed parameters to the exact
  169.    types listed in the function's prototype.
  170. */
  171.  
  172. #if defined(AT_file) && defined(AT_line)
  173. #ifndef AT_src_info
  174. You need the AT_src_info attribute if you have AT_file and AT_line attributes!
  175. #endif
  176. #define HAVE_SRC_LOCATION_ATTRIBUTES
  177. #endif
  178.  
  179. #if defined(DWARF_DESCRIBE_USED_EXTERNS) && !defined (HAVE_SRC_LOCATION_ATTRIBUTES)
  180. You need the AT_file and AT_line attributes to describe used externs!
  181. #endif
  182.  
  183. #ifndef USG
  184. #define getcwd(s,len) getwd(s)
  185. #endif
  186.  
  187. #ifndef FT_long_long
  188. #define FT_long_long        0x0015
  189. #endif
  190. #ifndef FT_signed_long_long
  191. #define FT_signed_long_long    0x0016
  192. #endif
  193. #ifndef FT_unsigned_long_long
  194. #define FT_unsigned_long_long    0x0017
  195. #endif
  196.  
  197. #define TREE_UID(TREE) ((unsigned) (TREE))
  198.  
  199. #ifndef CLASSTYPE_BASECLASS
  200. #define CLASSTYPE_BASECLASS(classtype, index) ((tree) 0)
  201. #endif
  202. #ifndef CLASSTYPE_N_BASECLASSES
  203. #define CLASSTYPE_N_BASECLASSES(classtype) 0
  204. #endif
  205.  
  206. #define BITFIELD_OFFSET_BITS(DECL) (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (DECL)))
  207. #define BITFIELD_OFFSET_UNITS(DECL) (BITFIELD_OFFSET_BITS(DECL) / BITS_PER_UNIT)
  208. #define BITFIELD_OFFSET_WORDS_IN_UNITS(DECL) \
  209.     ((BITFIELD_OFFSET_BITS(DECL) / BITS_PER_WORD) * UNITS_PER_WORD)
  210.  
  211. #if 0  /* No good: this variable is C-specific and may not exist in other
  212.       languages.  */
  213. /* External data objects defined in other files of GCC.  */
  214.  
  215. extern tree named_labels;        /* From c-decl.c */
  216. #endif
  217.  
  218. /* Maximum size (in bytes) of an artificially generated label.    */
  219.  
  220. #define MAX_ARTIFICIAL_LABEL_BYTES    30
  221.  
  222. #ifndef DWARF_REGISTER_NUMBER
  223. #define DWARF_REGISTER_NUMBER(REGNO) DBX_REGISTER_NUMBER(REGNO)
  224. #endif
  225.  
  226. /* Make sure we know the sizes of the various types dwarf can describe.  */
  227.  
  228. #ifndef CHAR_TYPE_SIZE
  229. #define CHAR_TYPE_SIZE BITS_PER_UNIT
  230. #endif
  231.  
  232. #ifndef SHORT_TYPE_SIZE
  233. #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
  234. #endif
  235.  
  236. #ifndef INT_TYPE_SIZE
  237. #define INT_TYPE_SIZE BITS_PER_WORD
  238. #endif
  239.  
  240. #ifndef LONG_TYPE_SIZE
  241. #define LONG_TYPE_SIZE BITS_PER_WORD
  242. #endif
  243.  
  244. #ifndef LONG_LONG_TYPE_SIZE
  245. #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
  246. #endif
  247.  
  248. #ifndef WCHAR_TYPE_SIZE
  249. #define WCHAR_TYPE_SIZE INT_TYPE_SIZE
  250. #endif
  251.  
  252. #ifndef WCHAR_UNSIGNED
  253. #define WCHAR_UNSIGNED 0
  254. #endif
  255.  
  256. #ifndef FLOAT_TYPE_SIZE
  257. #define FLOAT_TYPE_SIZE BITS_PER_WORD
  258. #endif
  259.  
  260. #ifndef DOUBLE_TYPE_SIZE
  261. #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  262. #endif
  263.  
  264. #ifndef LONG_DOUBLE_TYPE_SIZE
  265. #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  266. #endif
  267.  
  268. #ifdef AT_src_info
  269.  
  270. /* Structure to keep track of source filenames.  */
  271.  
  272. struct filename_entry
  273. {
  274.   unsigned    number;
  275.   char *    name;
  276. };
  277.  
  278. typedef struct filename_entry filename_entry_t;
  279.  
  280. /* Pointer to an array of elements, each one having the structure above. */
  281.  
  282. static filename_entry_t *filename_table = 0;
  283.  
  284. /* Total number of entries in the table (i.e. array) pointed to by
  285.    `filename_table'.  This is the *total* and includes both used and
  286.    unused slots.  */
  287.  
  288. static unsigned total_ft_entries = 0;
  289.  
  290. /* Number of entries in the table pointed to by `filename_table' which are
  291.    actually in use at the moment.  The used entries always start with
  292.    the zero'th element of the table and range up to (valid_ft_entries-1).  */
  293.  
  294. static unsigned valid_ft_entries = 0;
  295.  
  296. #endif
  297.  
  298. /* Pointer to a list of TREE_LIST nodes, each of whose TREE_VALUEs is either
  299.    NULL (indicating a scope boundary marker) or else points to a pending
  300.    STRUCT_TYPE, UNION_TYPE, or ENUMERATION_TYPE node which has yet to be
  301.    described (with DWARF info) for some pending scope.    */
  302.  
  303. static tree pending_tagged_types = 0;
  304.  
  305. #ifdef DWARF_DESCRIBE_USED_EXTERNS
  306.  
  307. /* Pointer to a list of TREE_LIST nodes, each of whose TREE_VALUEs is a
  308.    pointer to either a VAR_DECL node or a FUNCTION_DECL node.  This list
  309.    is maintained so that, at the end of compilation, we can write DWARF
  310.    descriptions of these (used) extern declarations to the .externs
  311.    section.  */
  312.  
  313. static tree pending_extern_decls = 0;
  314.  
  315. /* Flag which says whether or not we are generating entries in the .externs
  316.    section for variables and function declared external.  */
  317.  
  318. static int finalizing = FALSE;
  319.  
  320. #endif
  321.  
  322. /* Pointer to the most recent filename for which we produced some line info.  */
  323.  
  324. static char *last_filename;
  325.  
  326. /* For DWARF output, we must assign lexical-blocks id numbers
  327.    in the order in which their beginnings are encountered.
  328.    We output DWARF debugging info that refers to the beginnings
  329.    and ends of the ranges of code for each lexical block with
  330.    assembler labels ..Bn and ..Bn.e, where n is the block number.
  331.    The labels themselves are generated in final.c, which assigns
  332.    numbers to the blocks in the same way.  */
  333.  
  334. static int next_block_number = 1;
  335.  
  336. /* Counter to generate unique names for DIEs. */
  337.  
  338. static unsigned next_unused_dienum = 1;
  339.  
  340. /* Number of the DIE which is currently being generated.  */
  341.  
  342. static unsigned current_dienum;
  343.  
  344. #define NEXT_DIE_NUM pending_sibling_stack[pending_sibling_stack_depth-1]
  345.  
  346. /* Counter to keep track of the number of pre-reserved and still pending
  347.    sibling DIE numbers.     */
  348.  
  349. static unsigned pending_sibling_stack_depth = 0;
  350.  
  351. /* Pointer to a dynamically allocated list of pre-reserved and still
  352.    pending sibling DIE numbers.     Note that this list will grow as needed.  */
  353.  
  354. static unsigned *pending_sibling_stack;
  355.  
  356. /* The currently allocated size of the above list (expressed in number of
  357.    list elements).  */
  358.  
  359. static unsigned pending_sibling_stack_size = 0;
  360.  
  361. /* Size (in elements) of increments by which we may expand the pending
  362.    sibling stack.  Actually, a single hunk of space of this size should
  363.    be enough for most typical programs.     */
  364.  
  365. #define PENDING_SIBLING_STACK_INCREMENT 64
  366.  
  367. /* Forward declarations for functions defined in this file.  */
  368.  
  369. static void output_dies_for_type ();
  370. static void type_attribute ();
  371. static void output_symbol ();
  372. static unsigned lookup_filename ();
  373.  
  374. /* Definitions of defaults for assembler-dependent names of various
  375.    pseudo-ops and section names.
  376.  
  377.    Theses may be overridden in your tm.h file (if necessary) for your
  378.    particular assembler.  The default values provided here correspond to
  379.    what is expected by "standard" AT&T System V.4 assemblers.  */
  380.  
  381. #ifndef FILE_ASM_OP
  382. #define FILE_ASM_OP        "\t.file"
  383. #endif
  384. #ifndef VERSION_ASM_OP
  385. #define VERSION_ASM_OP        "\t.version"
  386. #endif
  387. #ifndef SECTION_ASM_OP
  388. #define SECTION_ASM_OP        "\t.section"
  389. #endif
  390. #ifndef PREVIOUS_ASM_OP
  391. #define PREVIOUS_ASM_OP        "\t.previous"
  392. #endif
  393. #ifndef CHAR_ASM_OP
  394. #define CHAR_ASM_OP        "\t.byte"
  395. #endif
  396. #ifndef UNALIGNED_SHORT_ASM_OP
  397. #define UNALIGNED_SHORT_ASM_OP    "\t.2byte"
  398. #endif
  399. #ifndef UNALIGNED_INT_ASM_OP
  400. #define UNALIGNED_INT_ASM_OP    "\t.4byte"
  401. #endif
  402. #ifndef DEF_ASM_OP
  403. #define DEF_ASM_OP        "\t.set"
  404. #endif
  405. #ifndef DEBUG_SECTION
  406. #define DEBUG_SECTION        ".debug"
  407. #endif
  408. #ifndef LINE_SECTION
  409. #define LINE_SECTION        ".line"
  410. #endif
  411.  
  412. #ifdef AT_src_info
  413. #ifndef SOURCES_SECTION
  414. #define SOURCES_SECTION        ".sources"
  415. #endif
  416. #ifndef SRCINFO_SECTION
  417. #define SRCINFO_SECTION        ".srcinfo"
  418. #endif
  419. #endif
  420.  
  421. #ifdef AT_addr_ranges
  422. #ifndef DATA_SECTION
  423. #define DATA_SECTION        ".data"
  424. #endif
  425. #ifndef BSS_SECTION
  426. #define BSS_SECTION        ".bss"
  427. #endif
  428. #ifndef RODATA_SECTION
  429. #define RODATA_SECTION        ".rodata"
  430. #endif
  431. #endif
  432.  
  433. #ifdef DWARF_DESCRIBE_USED_EXTERNS
  434. #ifndef EXTERNS_SECTION
  435. #define EXTERNS_SECTION        ".externs"
  436. #endif
  437. #endif
  438.  
  439. /* Definitions of defaults for formats and names of various special
  440.    (artificial) labels which may be generated within this file (when
  441.    the -g options is used and DWARF_DEBUGGING_INFO is in effect.
  442.  
  443.    If necessary, these may be overridden from within your tm-*.h file,
  444.    but typically, you should never need to override these.  */
  445.  
  446. #ifndef TEXT_BEGIN_LABEL
  447. #define TEXT_BEGIN_LABEL    "..text.b"
  448. #endif
  449. #ifndef TEXT_END_LABEL
  450. #define TEXT_END_LABEL        "..text.e"
  451. #endif
  452. #ifndef LINE_BEGIN_LABEL
  453. #define LINE_BEGIN_LABEL    "..line.b"
  454. #endif
  455. #ifndef LINE_END_LABEL
  456. #define LINE_END_LABEL        "..line.e"
  457. #endif
  458.  
  459. #ifdef AT_src_info
  460. #ifndef SRCINFO_BEGIN_LABEL
  461. #define SRCINFO_BEGIN_LABEL    "..srcinfo.b"
  462. #endif
  463. #endif
  464.  
  465. #ifdef AT_addr_ranges
  466. #ifndef DATA_BEGIN_LABEL
  467. #define DATA_BEGIN_LABEL    "..data.b"
  468. #endif
  469. #ifndef DATA_END_LABEL
  470. #define DATA_END_LABEL        "..data.e"
  471. #endif
  472. #ifndef BSS_BEGIN_LABEL
  473. #define BSS_BEGIN_LABEL        "..bss.b"
  474. #endif
  475. #ifndef BSS_END_LABEL
  476. #define BSS_END_LABEL        "..bss.e"
  477. #endif
  478. #ifndef RODATA_BEGIN_LABEL
  479. #define RODATA_BEGIN_LABEL    "..rodata.b"
  480. #endif
  481. #ifndef RODATA_END_LABEL
  482. #define RODATA_END_LABEL    "..rodata.e"
  483. #endif
  484. #endif
  485.  
  486. #ifndef DIE_BEGIN_LABEL_FMT
  487. #define DIE_BEGIN_LABEL_FMT    "..D%u"
  488. #endif
  489. #ifndef DIE_END_LABEL_FMT
  490. #define DIE_END_LABEL_FMT    "..D%u.e"
  491. #endif
  492. #ifndef INSN_LABEL_FMT
  493. #define INSN_LABEL_FMT        "..I%u.%u"
  494. #endif
  495. #ifndef BLOCK_BEGIN_LABEL_FMT
  496. #define BLOCK_BEGIN_LABEL_FMT    "..B%u"
  497. #endif
  498. #ifndef BLOCK_END_LABEL_FMT
  499. #define BLOCK_END_LABEL_FMT    "..B%u.e"
  500. #endif
  501. #ifndef SS_BEGIN_LABEL_FMT
  502. #define SS_BEGIN_LABEL_FMT    "..s%u"
  503. #endif
  504. #ifndef SS_END_LABEL_FMT
  505. #define SS_END_LABEL_FMT    "..s%u.e"
  506. #endif
  507. #ifndef EE_BEGIN_LABEL_FMT
  508. #define EE_BEGIN_LABEL_FMT    "..e%u"
  509. #endif
  510. #ifndef EE_END_LABEL_FMT
  511. #define EE_END_LABEL_FMT    "..e%u.e"
  512. #endif
  513. #ifndef MT_BEGIN_LABEL_FMT
  514. #define MT_BEGIN_LABEL_FMT    "..t%u"
  515. #endif
  516. #ifndef MT_END_LABEL_FMT
  517. #define MT_END_LABEL_FMT    "..t%u.e"
  518. #endif
  519. #ifndef LOC_BEGIN_LABEL_FMT
  520. #define LOC_BEGIN_LABEL_FMT    "..l%u"
  521. #endif
  522. #ifndef LOC_END_LABEL_FMT
  523. #define LOC_END_LABEL_FMT    "..l%u.e"
  524. #endif
  525. #ifndef BOUND_BEGIN_LABEL_FMT
  526. #define BOUND_BEGIN_LABEL_FMT    "..b%u.%u.%c"
  527. #endif
  528. #ifndef BOUND_END_LABEL_FMT
  529. #define BOUND_END_LABEL_FMT    "..b%u.%u.%c.e"
  530. #endif
  531. #ifndef DERIV_BEGIN_LABEL_FMT
  532. #define DERIV_BEGIN_LABEL_FMT    "..d%u"
  533. #endif
  534. #ifndef DERIV_END_LABEL_FMT
  535. #define DERIV_END_LABEL_FMT    "..d%u.e"
  536. #endif
  537. #ifndef FUNC_END_LABEL_FMT
  538. #define FUNC_END_LABEL_FMT    "..f%u.pchi"
  539. #endif
  540. #ifndef TYPE_NAME_FMT
  541. #define TYPE_NAME_FMT        "..T%u"
  542. #endif
  543. #ifndef LINE_CODE_LABEL_FMT
  544. #define LINE_CODE_LABEL_FMT    "..LC%u"
  545. #endif
  546. #ifdef AT_src_info
  547. #ifndef FILE_ENTRY_LABEL_FMT
  548. #define FILE_ENTRY_LABEL_FMT    "..F%u"
  549. #endif
  550. #ifndef LINE_ENTRY_LABEL_FMT
  551. #define LINE_ENTRY_LABEL_FMT    "..LE%u"
  552. #endif
  553. #endif
  554.  
  555. /* Definitions of defaults for various types of primitive assembly language
  556.    output operations.
  557.  
  558.    If necessary, these may be overridden from within your tm-*.h file,
  559.    but typically, you should never need to override these.  */
  560.    
  561. #ifndef ASM_OUTPUT_SOURCE_FILENAME
  562. #define ASM_OUTPUT_SOURCE_FILENAME(FILE,NAME) \
  563.   fprintf ((FILE), "%s\t\"%s\"\n", FILE_ASM_OP, NAME)
  564. #endif
  565.  
  566. #ifndef ASM_OUTPUT_DEF
  567. #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \
  568.   fprintf ((FILE), "%s\t%s,%s\n", DEF_ASM_OP, LABEL1, LABEL2)
  569. #endif
  570.  
  571. #ifndef ASM_CHANGE_SECTION
  572. #define ASM_CHANGE_SECTION(FILE,SECTION_NAME) \
  573.   fprintf ((FILE), "%s\t%s\n", SECTION_ASM_OP, SECTION_NAME)
  574. #endif
  575.  
  576. #ifndef ASM_PREVIOUS_SECTION
  577. #define ASM_PREVIOUS_SECTION(FILE) \
  578.   fprintf ((FILE), "%s\n", PREVIOUS_ASM_OP)
  579. #endif
  580.  
  581. #ifndef ASM_OUTPUT_DWARF_BLOCK2
  582. #define ASM_OUTPUT_DWARF_BLOCK2(FILE,LABEL1,LABEL2) \
  583.   fprintf ((FILE), "%s\t%s-%s\n", UNALIGNED_SHORT_ASM_OP, LABEL1, LABEL2)
  584. #endif
  585.  
  586. #ifndef ASM_OUTPUT_DWARF_BLOCK4
  587. #define ASM_OUTPUT_DWARF_BLOCK4(FILE,LABEL1,LABEL2) \
  588.   fprintf ((FILE), "%s\t%s-%s\n", UNALIGNED_INT_ASM_OP, LABEL1, LABEL2)
  589. #endif
  590.  
  591. #ifndef ASM_OUTPUT_DWARF_TAG
  592. #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \
  593.   fprintf ((FILE), "%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, TAG)
  594. #endif
  595.  
  596. #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE
  597. #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTRIBUTE) \
  598.   fprintf ((FILE), "%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, ATTRIBUTE)
  599. #endif
  600.  
  601. #ifndef ASM_OUTPUT_DWARF_ADDR
  602. #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \
  603.   fprintf ((FILE), "%s\t%s\n", UNALIGNED_INT_ASM_OP, LABEL)
  604. #endif
  605.  
  606. #ifndef ASM_OUTPUT_DWARF_ADDR_CONST
  607. #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \
  608.   fprintf ((FILE), "%s\t", UNALIGNED_INT_ASM_OP); \
  609.   output_addr_const ((FILE), (RTX)); \
  610.   fputc ('\n', (FILE))
  611. #endif
  612.  
  613. #ifndef ASM_OUTPUT_DWARF_REF
  614. #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \
  615.   fprintf ((FILE), "%s\t%s\n", UNALIGNED_INT_ASM_OP, LABEL)
  616. #endif
  617.  
  618. #ifndef ASM_OUTPUT_DWARF_DATA1
  619. #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \
  620.   fprintf ((FILE), "%s\t0x%x\n", CHAR_ASM_OP, VALUE)
  621. #endif
  622.  
  623. #ifndef ASM_OUTPUT_DWARF_DATA2
  624. #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \
  625.   fprintf ((FILE), "%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, VALUE)
  626. #endif
  627.  
  628. #ifndef ASM_OUTPUT_DWARF_DATA4
  629. #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \
  630.   fprintf ((FILE), "%s\t0x%x\n", UNALIGNED_INT_ASM_OP, VALUE)
  631. #endif
  632.  
  633. #ifndef ASM_OUTPUT_DWARF_DATA8
  634. #define ASM_OUTPUT_DWARF_DATA8(FILE,VALUE) \
  635.   fprintf ((FILE), "%s\t0x%x\n", UNALIGNED_8BYTE_ASM_OP, VALUE)
  636. #endif
  637.  
  638. #ifndef ASM_OUTPUT_DWARF_STRING
  639. #define ASM_OUTPUT_DWARF_STRING(FILE,P) \
  640.   ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1)
  641. #endif
  642.  
  643. /************************ general utility functions **************************/
  644.  
  645. static char *
  646. xstrdup (s)
  647.      char *s;
  648. {
  649.   char *p = (char *) xmalloc (strlen (s) + 1);
  650.   strcpy (p, s);
  651.   return p;
  652. }
  653.  
  654. /**************** utility functions for attribute functions ******************/
  655.  
  656. /* Given a pointer to a tree node for some type, return a DWARF fundamental
  657.    type code for the given type.
  658.  
  659.    This routine must only be called for GCC type nodes that correspond to
  660.    DWARF fundamental types.
  661.  
  662.    Note that in some non-GNU implementations of DWARF, there may be an
  663.    attempt made to promulgate the (incorrect) notion that an integral
  664.    type which is explicitly declared as `signed' and an (otherwise
  665.    identical) `plain' integral are somehow different.  In fact, ANSI C
  666.    and GCC believe that they are *not* different types, but rather are
  667.    exactly the same type.  (Note that there is an exception in case of
  668.    `char' types, and that a `char' and a `signed char' are in fact
  669.    different.)
  670.  
  671.    Here, we rely on the ANSI C and GCC interpretation.    Thus, this routine
  672.    *never* returns any of the three (bogus) fundamental type codes
  673.    FT_signed_integer, FT_signed_long, or FT_signed_short.  */
  674.  
  675. static int
  676. fundamental_type_code (type)
  677.      register tree type;
  678. {
  679.   type = TYPE_MAIN_VARIANT (type);
  680.   switch (TREE_CODE (type))
  681.     {
  682.       case ERROR_MARK:
  683.     return FT_void;
  684.  
  685.       case VOID_TYPE:
  686.     return FT_void;
  687.  
  688.       case INTEGER_TYPE:
  689.     /* Carefully distinguish all the standard types of C,
  690.        without messing up if the language is not C.
  691.        Note that we check only for the names that contain spaces;
  692.        other names might occur by coincidence in other languages.  */
  693.     if (TYPE_NAME (type) != 0
  694.         && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  695.         && DECL_NAME (TYPE_NAME (type)) != 0
  696.         && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
  697.       {
  698.         char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
  699.  
  700.         if (!strcmp (name, "unsigned char"))
  701.           return FT_unsigned_char;
  702.         if (!strcmp (name, "signed char"))
  703.           return FT_signed_char;
  704.         if (!strcmp (name, "unsigned int"))
  705.           return FT_unsigned_integer;
  706.         if (!strcmp (name, "short int"))
  707.           return FT_short;
  708.         if (!strcmp (name, "short unsigned int"))
  709.           return FT_unsigned_short;
  710.         if (!strcmp (name, "long int"))
  711.           return FT_long;
  712.         if (!strcmp (name, "long unsigned int"))
  713.           return FT_unsigned_long;
  714.         if (!strcmp (name, "long long int"))
  715.           return FT_long_long;
  716.         if (!strcmp (name, "long long unsigned int"))
  717.           return FT_unsigned_long_long;
  718.       }
  719.         
  720.     /* Most integer types will be sorted out above, however, for the
  721.        sake of special `array index' integer types, the following code
  722.        is also provided.  */
  723.  
  724.     if (TYPE_PRECISION (type) == INT_TYPE_SIZE)
  725.       return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer);
  726.  
  727.     if (TYPE_PRECISION (type) == LONG_TYPE_SIZE)
  728.       return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long);
  729.  
  730.     if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE)
  731.       return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long);
  732.  
  733.     if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE)
  734.       return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short);
  735.  
  736.     if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE)
  737.       return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char);
  738.  
  739.     abort ();
  740.   
  741.       case REAL_TYPE:
  742.     /* Carefully distinguish all the standard types of C,
  743.        without messing up if the language is not C.  */
  744.     if (TYPE_NAME (type) != 0
  745.         && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
  746.         && DECL_NAME (TYPE_NAME (type)) != 0
  747.         && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
  748.       {
  749.         char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
  750.  
  751.         if (!strcmp (name, "long double"))
  752.           return FT_ext_prec_float;
  753.       }
  754.  
  755.     if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE)
  756.       return FT_dbl_prec_float;
  757.     if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE)
  758.       return FT_float;
  759.     if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE)
  760.       return FT_ext_prec_float;
  761.     abort ();
  762.  
  763.       case COMPLEX_TYPE:
  764.     return FT_complex;    /* GNU FORTRAN COMPLEX type.  */
  765.  
  766.       case CHAR_TYPE:
  767.     return FT_char;        /* GNU Pascal CHAR type.  Not used in C.  */
  768.  
  769.       case SET_TYPE:
  770.     return FT_set;        /* GNU Pascal SET type.     */
  771.  
  772.       case BOOLEAN_TYPE:
  773.     return FT_integer;    /* GNU FORTRAN BOOLEAN type.  */
  774.  
  775.       case FILE_TYPE:        /* GNU Pascal FILE type.  */
  776.       case STRING_TYPE:        /* GNU Pascal/FORTRAN/Ada STRING type. */
  777.       case OFFSET_TYPE:        /* GNU C++ member pointer type.     */
  778.       case LANG_TYPE:        /* GNU generic language-specific type.    */
  779.       default:
  780.     abort ();    /* No DWARF representation currently defined.  */
  781.     }
  782. }
  783.  
  784. /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to
  785.    the DWARF "root" type for the given input type.  The DWARF "root" type
  786.    of a given type is generally the same as the given type, except that if
  787.    the    given type is a pointer or reference type, then the root type of
  788.    that type is the root type of the referenced type for the pointer or
  789.    reference type.  (This definition of the "root" type is recursive.)    */
  790.  
  791. static tree
  792. root_type (type)
  793.      register tree type;
  794. {
  795.   type = TYPE_MAIN_VARIANT (type);
  796.   switch (TREE_CODE (type))
  797.     {
  798.       case POINTER_TYPE:
  799.       case REFERENCE_TYPE:
  800.     return root_type (TREE_TYPE (type));
  801.  
  802.       default:
  803.     return type;
  804.     }
  805. }
  806.  
  807. /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence
  808.    of zero or more DWARF "type-modifier" bytes applicable to the type.    */
  809.  
  810. static void
  811. write_modifier_bytes (type)
  812.      register tree type;
  813. {
  814.   type = TYPE_MAIN_VARIANT (type);
  815.   switch (TREE_CODE (type))
  816.     {
  817.       case POINTER_TYPE:
  818.     ASM_OUTPUT_DWARF_DATA1 (asm_out_file, MOD_pointer_to);
  819.     write_modifier_bytes (TREE_TYPE (type));
  820.     return;
  821.  
  822.       case REFERENCE_TYPE:
  823.     ASM_OUTPUT_DWARF_DATA1 (asm_out_file, MOD_reference_to);
  824.     write_modifier_bytes (TREE_TYPE (type));
  825.     return;
  826.  
  827.       default:
  828.     return;
  829.     }
  830. }
  831.  
  832. /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the
  833.    given input type is a DWARF "fundamental" type.  Otherwise return zero.  */
  834.  
  835. static int
  836. type_is_fundamental (type)
  837.      register tree type;
  838. {
  839.   switch (TREE_CODE (type))
  840.     {
  841.       case ERROR_MARK:
  842.       case VOID_TYPE:
  843.       case INTEGER_TYPE:
  844.       case REAL_TYPE:
  845.       case COMPLEX_TYPE:
  846.       case BOOLEAN_TYPE:
  847.       case CHAR_TYPE:
  848.       case SET_TYPE:
  849.     return 1;
  850.  
  851.       case ARRAY_TYPE:
  852.       case RECORD_TYPE:
  853.       case UNION_TYPE:
  854.       case ENUMERAL_TYPE:
  855.       case FUNCTION_TYPE:
  856.       case METHOD_TYPE:
  857.       case POINTER_TYPE:
  858.       case REFERENCE_TYPE:
  859.     return 0;
  860.  
  861.       case FILE_TYPE:        /* No DWARF fundamental type code defined. */
  862.       case STRING_TYPE:        /* No DWARF fundamental type code defined. */
  863.       case OFFSET_TYPE:        /* No DWARF fundamental type code defined. */
  864.       case LANG_TYPE:        /* No DWARF fundamental type code defined. */
  865.       default:
  866.     abort ();
  867.     }
  868. }
  869.  
  870. /* Given a pointer to some ..._TYPE tree node, generate an assembly language
  871.    equate directive which will associate an easily remembered symbolic name
  872.    with the current DIE.
  873.  
  874.    The name used is an artificial label generated from the TREE_UID number
  875.    associated with the given type node.     The name is gest equated to is the
  876.    symbolic lable that we (previously) output at the start of the DIE that
  877.    we are currently generating.
  878.  
  879.    Calling this function while generating some "type related" form of DIE
  880.    makes it easy to later refer to the DIE which represents the given type
  881.    simply by re-generating the alternative name from the ..._TYPE node's
  882.    UID number.    */
  883.  
  884. static void
  885. equate_type_number_to_die_number (type)
  886.      register tree type;
  887. {
  888.   char type_label[MAX_ARTIFICIAL_LABEL_BYTES];
  889.   char die_label[MAX_ARTIFICIAL_LABEL_BYTES];
  890.  
  891.   sprintf (type_label, TYPE_NAME_FMT, TREE_UID (type));
  892.   sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum);
  893.   ASM_OUTPUT_DEF (asm_out_file, type_label, die_label);
  894. }
  895.  
  896. /* The following routine is a nice and simple transducer.  It converts an RTL
  897.    representation of a mechanism for getting the value of a given variable
  898.    into an equivalent DWARF representation of a mechanism for getting the
  899.    value of that same variable.
  900.  
  901.    Note that the output from this routine will deviate in some respects
  902.    from the DWARF location descriptions which may be produced by some
  903.    other C compilers.  THIS IS BY INTENT!
  904.  
  905.    In particular, some C compilers may produce DWARF location descriptions
  906.    for memory-resident variables which only describe how to get the *address*
  907.    of the given variable.  That's inconsistant with the way location
  908.    descriptions are generated for register-resident variables, in which the
  909.    access mechanism described by the location description actually describes
  910.    how to obtain the *value* of the variable (and not the variable's address).
  911.  
  912.    In GNU DWARF, location descriptions for variables always describe a mechanism
  913.    which (if executed) would leave the *value* of the variable on top of the
  914.    stack.  Thus, for memory-resident variables, the last byte in GNU DWARF
  915.    location descriptions will always be OP_DEREF4.
  916.  
  917.    Using this more consistant approach makes the DWARF location descriptions
  918.    produced here more rational, and it also helps to simplify the following
  919.    routine dramatically.
  920. */
  921.  
  922. static void
  923. output_location_description (rtl, suppress_trailing_deref)
  924.       register rtx rtl;
  925.       register int suppress_trailing_deref;
  926. {
  927.   /* Note that for a dynamically sized array, the location we will
  928.      generate a description of here will be the lowest numbered location
  929.      which is actually within the array.  */
  930.  
  931.   switch (GET_CODE (rtl))
  932.     {
  933.       case REG:
  934.  
  935.     /* This is kinda silly, but some debuggers may want to see OP_BASEREG
  936.        rather than OP_REG when the register in question is the frame
  937.        pointer.  I personally would prefer that the OP_BASEREG code were
  938.        never used, but some debuggers stupidly insist that some registers
  939.        be called `base registers' rather than simply `registers'.  */
  940.  
  941.     ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
  942.             (rtl == frame_pointer_rtx) ? OP_BASEREG : OP_REG);
  943.  
  944.     /* The case of a pseudo register happens when an argument is not
  945.        used at all and the function is optimized.  In such cases, we
  946.        generate a reference to register zero here.    This may be truly
  947.        incorrect on some non-RISC machines, but let's not even worry
  948.        about that.    If the user has optimized his code, and if he is
  949.        debugging, and if he happens to be looking at a variable that
  950.        has been optimized away, then he will not see anything meaningful,
  951.        but who cares.  */
  952.  
  953.     ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
  954.                 (REGNO (rtl) < FIRST_PSEUDO_REGISTER)
  955.                   ? DWARF_REGISTER_NUMBER (REGNO (rtl))
  956.                   : 0);
  957.     break;
  958.  
  959.       case SUBREG:
  960.  
  961.     /* The case of a subreg may arise when we have a local (register)
  962.        variable or a formal (register) parameter which doesn't quite
  963.        fill up an entire register.    For now, just assume that it is
  964.        legitimate to make the DWARF info refer to the whole register
  965.        which contains the given subreg.  */
  966.  
  967.     output_location_description (XEXP (rtl, 0), FALSE);
  968.     break;
  969.  
  970.       case MEM:
  971.     output_location_description (XEXP (rtl, 0), FALSE);
  972.  
  973.     /* This is really a kludge.  When creating location descriptions,
  974.        we are normally trying to produce a description of a procedure
  975.        by which debuggers can *read* the *value* of the item in question.
  976.        Unfortunately, the way DWARF is produced by existing compilers,
  977.        this simple and consistant definition doesn't always match what
  978.        these other compilers actually do.
  979.  
  980.        When the item in question is a value in memory, existing compilers
  981.        omit the final OP_DEREF4 that really should be there.  Here we will
  982.        be consistant with those (broken?) implementations.
  983.     */
  984.  
  985.     if (! suppress_trailing_deref)
  986.       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, OP_DEREF4);
  987.  
  988.     break;
  989.  
  990.       case SYMBOL_REF:
  991.     ASM_OUTPUT_DWARF_DATA1 (asm_out_file, OP_ADDR);
  992.     ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl);
  993.     break;
  994.  
  995.       case PLUS:
  996.     output_location_description (XEXP (rtl, 0), FALSE);
  997.     output_location_description (XEXP (rtl, 1), FALSE);
  998.     ASM_OUTPUT_DWARF_DATA1 (asm_out_file, OP_ADD);
  999.     break;
  1000.  
  1001.       case CONST_INT:
  1002.     ASM_OUTPUT_DWARF_DATA1 (asm_out_file, OP_CONST);
  1003.     ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl));
  1004.     break;
  1005.  
  1006.       default:
  1007.     abort ();
  1008.     }
  1009. }
  1010.  
  1011. /* Given a tree node describing an array bound (either lower or upper)
  1012.    output a representation for that bound.  */
  1013.  
  1014. static void
  1015. output_bound_representation (bound, dim_num, u_or_l)
  1016.      register tree bound;
  1017.      register unsigned dim_num; /* For multi-dimensional arrays.  */
  1018.      register char u_or_l;    /* Designates upper or lower bound.  */
  1019. {
  1020.   switch (TREE_CODE (bound))
  1021.     {
  1022.  
  1023.       case ERROR_MARK:
  1024.     break;
  1025.  
  1026.       /* All fixed-bounds are represented by INTEGER_CST nodes.     */
  1027.  
  1028.       case INTEGER_CST:
  1029.     ASM_OUTPUT_DWARF_DATA4 (asm_out_file, TREE_INT_CST_LOW (bound));
  1030.     break;
  1031.  
  1032.       /* All dynamic bounds are represented by NOP_EXPR nodes.    */
  1033.  
  1034.       case NOP_EXPR:
  1035.     {
  1036.       char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1037.       char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1038.  
  1039.       sprintf (begin_label, BOUND_BEGIN_LABEL_FMT,
  1040.                 current_dienum, dim_num, u_or_l);
  1041.  
  1042.       sprintf (end_label,    BOUND_END_LABEL_FMT,
  1043.                 current_dienum, dim_num, u_or_l);
  1044.  
  1045.       ASM_OUTPUT_DWARF_BLOCK2 (asm_out_file, end_label, begin_label);
  1046.       ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  1047.  
  1048.       /* If we are working on a bound for a dynamic dimension in C,
  1049.          the dynamic dimension in question had better have a static
  1050.          (zero) lower bound and a dynamic *upper* bound.  */
  1051.  
  1052.       if (u_or_l != 'u')
  1053.         abort ();
  1054.  
  1055.       /* If optimization is turned on, the SAVE_EXPRs that describe
  1056.          how to access the upper bound values are essentially bogus.
  1057.          They only describe (at best) how to get at these values at
  1058.          the points in the generated code right after they have just
  1059.          been computed.  Worse yet, in the typical case, the upper
  1060.          bound values will not even *be* computed in the optimized
  1061.          code, so these SAVE_EXPRs are entirely bogus.
  1062.  
  1063.          In order to compensate for this fact, we check here to see
  1064.          if optimization is enabled, and if so, we effectively create
  1065.          an empty location description for the (unknown and unknowable)
  1066.          upper bound.
  1067.  
  1068.          This should not cause too much trouble for existing (stupid?)
  1069.          debuggers because they have to deal with empty upper bounds
  1070.          location descriptions anyway in order to be able to deal with
  1071.          incomplete array types.
  1072.  
  1073.          Of course an intelligent debugger (GDB?) should be able to
  1074.          comprehend that a missing upper bound specification in a
  1075.          array type used for a stroage class `auto' local array variable
  1076.          indicates that the upper bound is both unknown (at compile-
  1077.          time) and unknowable (at run-time) due to optimization.
  1078.       */
  1079.  
  1080.       if (! optimize)
  1081.         output_location_description (
  1082.         (rtx) TREE_OPERAND (TREE_OPERAND (bound, 0), 1),
  1083.         TRUE);
  1084.  
  1085.       ASM_OUTPUT_LABEL (asm_out_file, end_label);
  1086.     }
  1087.     break;
  1088.  
  1089.       default:
  1090.     abort ();
  1091.     }
  1092. }
  1093.  
  1094. /* Recursive function to output a sequence of value/name pairs for
  1095.    enumeration constants in reversed order.  This is called from
  1096.    enumeration_type_die().  */
  1097.  
  1098. static void
  1099. output_enumeral_list (link)
  1100.      register tree link;
  1101. {
  1102.   if (link)
  1103.     {
  1104.       output_enumeral_list (TREE_CHAIN (link));
  1105.       ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
  1106.                   TREE_INT_CST_LOW (TREE_VALUE (link)));
  1107.       ASM_OUTPUT_DWARF_STRING (asm_out_file,
  1108.                    IDENTIFIER_POINTER (TREE_PURPOSE (link)));
  1109.     }
  1110. }
  1111.  
  1112. /****************************** attributes *********************************/
  1113.  
  1114. /* The following routines are responsible for writing out the various types
  1115.    of DWARF attributes (and any following data bytes associated with them).
  1116.    These routines are listed in order based on the numerical codes of their
  1117.    associated attributes.  */
  1118.  
  1119. /* Generate an AT_sibling attribute.  */
  1120.  
  1121. static void
  1122. sibling_attribute ()
  1123. {
  1124.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  1125.  
  1126.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling);
  1127.   sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
  1128.   ASM_OUTPUT_DWARF_REF (asm_out_file, label);
  1129. }
  1130.  
  1131. static void
  1132. location_attribute (decl)
  1133.      register tree decl;
  1134. {
  1135.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1136.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1137.  
  1138.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location);
  1139.   sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum);
  1140.   sprintf (end_label, LOC_END_LABEL_FMT, current_dienum);
  1141.   ASM_OUTPUT_DWARF_BLOCK2 (asm_out_file, end_label, begin_label);
  1142.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  1143.   switch (TREE_CODE (decl))
  1144.     {
  1145.       case ERROR_MARK:
  1146.     break;
  1147.  
  1148.       case VAR_DECL:
  1149.       case PARM_DECL:
  1150.     output_location_description (DECL_RTL (decl), TRUE);
  1151.     break;
  1152.  
  1153.       case FIELD_DECL:
  1154.     ASM_OUTPUT_DWARF_DATA1 (asm_out_file, OP_CONST);
  1155.  
  1156.     /* This is pretty strange, but existing compilers producing DWARF
  1157.        apparently calculate the byte offset of a field differently
  1158.        depending upon whether or not it is a bit-field.  If the given
  1159.        field is *not* a bit-field, then the offset is simply the
  1160.        the byte offset of the given field from the beginning of the
  1161.        struct.  For bit-fields however, the offset is the offset (in
  1162.        bytes) of the beginning of the *containing word* from the
  1163.        beginning of the whole struct.  */
  1164.  
  1165.     ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
  1166.         (DECL_BIT_FIELD (decl))
  1167.           ? BITFIELD_OFFSET_WORDS_IN_UNITS (decl)
  1168.           : BITFIELD_OFFSET_UNITS (decl));
  1169.     ASM_OUTPUT_DWARF_DATA1 (asm_out_file, OP_ADD);
  1170.     break;
  1171.  
  1172.       default:
  1173.     /* FUNCTION_DECLs don't get location attributes because their
  1174.        low_pc attributes are sufficient to determine their locations. */
  1175.  
  1176.     /* LABEL_DECLs don't get location attributes because their low_pc
  1177.        attributes serve this purpose.  */
  1178.  
  1179.     /* TYPE_DECLs and TAG_DECLs don't get location attributes because
  1180.        these things just don't exist at run-time.  */
  1181.  
  1182.     /* RESULT_DECLs don't get location attributes because it is not
  1183.        even clear what the debugger would be able to do with such
  1184.        information.     */
  1185.  
  1186.     abort ();
  1187.     }
  1188.   ASM_OUTPUT_LABEL (asm_out_file, end_label);
  1189. }
  1190.  
  1191. /* Generate an AT_name attribute given some string value to be included as
  1192.    the value of the attribute.    If the name is null, don't do anything.     */
  1193.  
  1194. static void
  1195. name_attribute (name_string)
  1196.      register char *name_string;
  1197. {
  1198.   if (name_string && *name_string)
  1199.     {
  1200.       ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name);
  1201.       ASM_OUTPUT_DWARF_STRING (asm_out_file, name_string);
  1202.     }
  1203. }
  1204.  
  1205. #if 0
  1206. /* I'm still trying to figure out when (or if) this type of attribute is
  1207.    ever actually used for anything.  If you find out, please let me know.  */
  1208. static void
  1209. dimension_attribute (type)
  1210.      register tree type;
  1211. {
  1212.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_dimension);
  1213.   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ?);
  1214. }
  1215. #endif
  1216.  
  1217. static void
  1218. fund_type_attribute (type)
  1219.      register tree type;
  1220. {
  1221.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type);
  1222.   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, fundamental_type_code (type));
  1223. }
  1224.  
  1225. static void
  1226. mod_fund_type_attribute (type)
  1227.      register tree type;
  1228. {
  1229.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1230.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1231.  
  1232.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type);
  1233.   sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
  1234.   sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
  1235.   ASM_OUTPUT_DWARF_BLOCK2 (asm_out_file, end_label, begin_label);
  1236.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  1237.   write_modifier_bytes (type);
  1238.   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, fundamental_type_code (root_type (type)));
  1239.   ASM_OUTPUT_LABEL (asm_out_file, end_label);
  1240. }
  1241.  
  1242. static void
  1243. user_def_type_attribute (type)
  1244.      register tree type;
  1245. {
  1246.   char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
  1247.  
  1248.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type);
  1249.   sprintf (ud_type_name, TYPE_NAME_FMT, TREE_UID (type));
  1250.   ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
  1251. }
  1252.  
  1253. static void
  1254. mod_u_d_type_attribute (type)
  1255.      register tree type;
  1256. {
  1257.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1258.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1259.   char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
  1260.  
  1261.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type);
  1262.   sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum);
  1263.   sprintf (end_label, MT_END_LABEL_FMT, current_dienum);
  1264.   ASM_OUTPUT_DWARF_BLOCK2 (asm_out_file, end_label, begin_label);
  1265.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  1266.   write_modifier_bytes (type);
  1267.   sprintf (ud_type_name, TYPE_NAME_FMT, TREE_UID (root_type (type)));
  1268.   ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name);
  1269.   ASM_OUTPUT_LABEL (asm_out_file, end_label);
  1270. }
  1271.  
  1272. static void
  1273. ordering_attribute (ordering)
  1274.      register int ordering;
  1275. {
  1276.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering);
  1277.   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering);
  1278. }
  1279.  
  1280. /* Note that the block of subscript information for an array type also
  1281.    includes information about the element type of type given array type.  */
  1282.  
  1283. static void
  1284. subscript_data_attribute (type)
  1285.      register tree type;
  1286. {
  1287.   register unsigned dimension_number;
  1288.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1289.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1290.  
  1291.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data);
  1292.   sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum);
  1293.   sprintf (end_label, SS_END_LABEL_FMT, current_dienum);
  1294.   ASM_OUTPUT_DWARF_BLOCK2 (asm_out_file, end_label, begin_label);
  1295.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  1296.  
  1297.   /* The GNU compilers represent multidimensional array types as sequences
  1298.      of one dimensional array types whose element types are themselves array
  1299.      types.  Here we squish that down, so that each multidimensional array
  1300.      type gets only one array_type DIE in the DWARF debugging info.  */
  1301.  
  1302.   for (type = TYPE_MAIN_VARIANT (type), dimension_number = 0;
  1303.     TREE_CODE (type) == ARRAY_TYPE;
  1304.     type = TYPE_MAIN_VARIANT (TREE_TYPE (type)), dimension_number++)
  1305.     {
  1306.       register tree domain = TYPE_DOMAIN (type);
  1307.  
  1308.       /* Arrays come in three flavors.    Unspecified bounds, fixed
  1309.      bounds, and (in GNU C only) variable bounds.  Handle all
  1310.      three forms here.  */
  1311.  
  1312.       if (domain)
  1313.     {
  1314.       /* We have an array type with specified bounds.  */
  1315.  
  1316.       register tree lower = TYPE_MIN_VALUE (domain);
  1317.       register tree upper = TYPE_MAX_VALUE (domain);
  1318.       register unsigned upper_bound_representation;
  1319.       register unsigned lower_bound_representation;
  1320.       register unsigned index_type_representation;
  1321.  
  1322.       /* Start by categorizing each bound as either fixed or variable.  */
  1323.  
  1324.       lower_bound_representation =
  1325.         (TREE_CODE (lower) == INTEGER_CST) ? FMT_CONST : FMT_EXPR;
  1326.       upper_bound_representation =
  1327.         (TREE_CODE (lower) == INTEGER_CST) ? FMT_CONST : FMT_EXPR;
  1328.  
  1329.       /* Now categorize the index range type as either a DWARF
  1330.          `fundamental' type or as a user defined type.  */
  1331.  
  1332.       index_type_representation =
  1333.         type_is_fundamental (domain) ? FMT_FT : FMT_UDT;
  1334.  
  1335.       /* Handle only fundamental types as index types for now.  */
  1336.  
  1337.       if (index_type_representation != FMT_FT)
  1338.         abort ();
  1339.  
  1340.       /* Output the representation format byte for this dimension. */
  1341.  
  1342.       ASM_OUTPUT_DWARF_DATA1 (asm_out_file,
  1343.                      (index_type_representation<<2)
  1344.                   || (lower_bound_representation<<1)
  1345.                   || (upper_bound_representation));
  1346.  
  1347.       /* Output the index type for this dimension.    */
  1348.  
  1349.       ASM_OUTPUT_DWARF_DATA2 (asm_out_file,
  1350.                   fundamental_type_code (domain));
  1351.  
  1352.       /* Output the representation for the lower bound.  */
  1353.  
  1354.       output_bound_representation (lower, dimension_number, 'l');
  1355.  
  1356.       /* Output the representation for the upper bound.  */
  1357.  
  1358.       output_bound_representation (upper, dimension_number, 'u');
  1359.     }
  1360.       else
  1361.     {
  1362.       /* We have an array type with an unspecified length.    For C and
  1363.          C++ we can assume that this really means that (a) the index
  1364.          type is an integral type, and (b) the lower bound is zero.
  1365.          Note that DWARF defines the representation of an unspecified
  1366.          (upper) bound as being a zero-length location description.     */
  1367.  
  1368.       /* Output the array-bounds format byte.  */
  1369.  
  1370.       ASM_OUTPUT_DWARF_DATA1 (asm_out_file, FMT_FT_C_X);
  1371.  
  1372.       /* Output the (assumed) index type.  */
  1373.  
  1374.       ASM_OUTPUT_DWARF_DATA2 (asm_out_file, FT_integer);
  1375.  
  1376.       /* Output the (assumed) lower bound (constant) value.     */
  1377.  
  1378.       ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
  1379.  
  1380.       /* Output the (empty) location description for the upper bound.  */
  1381.  
  1382.       ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0);
  1383.     }
  1384.     }
  1385.  
  1386.   /* Output the prefix byte that says that the element type is comming up.  */
  1387.  
  1388.   ASM_OUTPUT_DWARF_DATA1 (asm_out_file, FMT_ET);
  1389.  
  1390.   /* Output a representation of the type of the elements of this array type.  */
  1391.  
  1392.   type_attribute (type);
  1393.  
  1394.   ASM_OUTPUT_LABEL (asm_out_file, end_label);
  1395. }
  1396.  
  1397. static void
  1398. byte_size_attribute (tree_node)
  1399.      register tree tree_node;
  1400. {
  1401.   register unsigned size;
  1402.  
  1403.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size);
  1404.   switch (TREE_CODE (tree_node))
  1405.     {
  1406.       case ERROR_MARK:
  1407.     size = 0;
  1408.     break;
  1409.  
  1410.       case ENUMERAL_TYPE:
  1411.       case RECORD_TYPE:
  1412.       case UNION_TYPE:
  1413.     size = int_size_in_bytes (tree_node);
  1414.     break;
  1415.  
  1416.       case FIELD_DECL:
  1417.     {
  1418.       register unsigned words;
  1419.       register unsigned bits;
  1420.  
  1421.       bits = TREE_INT_CST_LOW(DECL_SIZE(tree_node));
  1422.       words = (bits + (BITS_PER_WORD-1)) / BITS_PER_WORD;
  1423.       size = words * (BITS_PER_WORD / BITS_PER_UNIT);
  1424.     }
  1425.     break;
  1426.  
  1427.       default:
  1428.     abort ();
  1429.     }
  1430.   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size);
  1431. }
  1432.  
  1433. /* For a FIELD_DECL node which represents a bit field, output an attribute
  1434.    which specifies the distance in bits from the start of the *word*
  1435.    containing the given field to the first bit of the field.  */
  1436.  
  1437. static void
  1438. bit_offset_attribute (decl)
  1439.     register tree decl;
  1440. {
  1441.   assert (TREE_CODE (decl) == FIELD_DECL);    /* Must be a field.  */
  1442.   assert (DECL_BIT_FIELD (decl));        /* Must be a bit field.     */
  1443.  
  1444.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset);
  1445.   ASM_OUTPUT_DWARF_DATA2 (asm_out_file,
  1446.     BITFIELD_OFFSET_BITS (decl) % BITS_PER_WORD);
  1447. }
  1448.  
  1449. /* For a FIELD_DECL node which represents a bit field, output an attribute
  1450.    which specifies the length in bits of the given field.  */
  1451.  
  1452. static void
  1453. bit_size_attribute (decl)
  1454.     register tree decl;
  1455. {
  1456.   assert (TREE_CODE (decl) == FIELD_DECL);    /* Must be a field.  */
  1457.   assert (DECL_BIT_FIELD (decl));        /* Must be a bit field.     */
  1458.  
  1459.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size);
  1460.   ASM_OUTPUT_DWARF_DATA4 (asm_out_file,
  1461.       TREE_INT_CST_LOW (DECL_SIZE (decl)));
  1462. }
  1463.  
  1464. static void
  1465. deriv_list_attribute (type)
  1466.     register tree type;
  1467. {
  1468.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1469.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1470.   register unsigned basenum;
  1471.  
  1472.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_deriv_list);
  1473.   sprintf (begin_label, DERIV_BEGIN_LABEL_FMT, current_dienum);
  1474.   sprintf (end_label, DERIV_END_LABEL_FMT, current_dienum);
  1475.   ASM_OUTPUT_DWARF_BLOCK2 (asm_out_file, end_label, begin_label);
  1476.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  1477.   for (basenum = CLASSTYPE_N_BASECLASSES (type); basenum > 0; basenum--)
  1478.     {
  1479.       char baseclass_type_name[MAX_ARTIFICIAL_LABEL_BYTES];
  1480.  
  1481.       sprintf (baseclass_type_name, TYPE_NAME_FMT,
  1482.            TREE_UID (CLASSTYPE_BASECLASS (type, basenum)));
  1483.       ASM_OUTPUT_DWARF_REF (asm_out_file, baseclass_type_name);
  1484.     }
  1485.   ASM_OUTPUT_LABEL (asm_out_file, end_label);
  1486. }
  1487.  
  1488. /* The following routine outputs the `element_list' attribute for enumeration
  1489.    type DIEs.  The element_lits attribute includes the names and values of
  1490.    all of the enumeration constants associated with the given enumeration
  1491.    type.  */
  1492.  
  1493. static void
  1494. element_list_attribute (element)
  1495.      register tree element;
  1496. {
  1497.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1498.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1499.  
  1500.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list);
  1501.   sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum);
  1502.   sprintf (end_label, EE_END_LABEL_FMT, current_dienum);
  1503.   ASM_OUTPUT_DWARF_BLOCK2 (asm_out_file, end_label, begin_label);
  1504.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  1505.  
  1506.   /* This is a kludge whose only purpose is to be compatible with what
  1507.      existing `traditional DWARF' compilers do.
  1508.  
  1509.      Here we output a list of value/name pairs for each enumeration constant
  1510.      defined for this enumeration type (as required), but we do it in REVERSE
  1511.      order.  The order isn't really defined for DWARF, but existing compilers
  1512.      use this order, so we do likewise, even if it seems stupid and
  1513.      even if debuggers don't give a darn about the order.  */
  1514.  
  1515.   output_enumeral_list (element);   /* Recursively output the whole list.  */
  1516.  
  1517.   ASM_OUTPUT_LABEL (asm_out_file, end_label);
  1518. }
  1519.  
  1520. /* Generate an AT_stmt_list attribute.    These are normally present only in
  1521.    DIEs with a TAG_source_file tag.  */
  1522.  
  1523. static void
  1524. stmt_list_attribute (label)
  1525.     register char *label;
  1526. {
  1527.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list);
  1528.   /* Don't use ASM_OUTPUT_DWARF_DATA4() here.  */
  1529.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
  1530. }
  1531.  
  1532. /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or
  1533.    for a subroutine DIE.  */
  1534.  
  1535. static void
  1536. low_pc_attribute (asm_low_label)
  1537.      register char *asm_low_label;
  1538. {
  1539.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc);
  1540.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label);
  1541. }
  1542.  
  1543. /* Generate an AT_high_pc attribute for a lexical_block DIE or for a
  1544.    subroutine DIE.  */
  1545.  
  1546. static void
  1547. high_pc_attribute (asm_high_label)
  1548.     register char *asm_high_label;
  1549. {
  1550.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc);
  1551.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label);
  1552. }
  1553.  
  1554. /* Generate an AT_language attribute given a LANG value.  These attributes
  1555.    are used only within TAG_source_file DIEs.  */
  1556.  
  1557. static void
  1558. language_attribute (language_code)
  1559.      register LANG language_code;
  1560. {
  1561.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language);
  1562.   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (int) language_code);
  1563. }
  1564.  
  1565. static void
  1566. member_attribute (decl)
  1567.     register tree decl;
  1568. {
  1569.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  1570.  
  1571.   /* Use this attribute only for member functions/objects in C++.  */
  1572.   assert (TREE_CODE (decl) == METHOD_DECL || TREE_CODE (decl) == FIELD_DECL);
  1573.  
  1574.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member);
  1575.   sprintf (label, TYPE_NAME_FMT, TREE_UID (DECL_CONTEXT (decl)));
  1576.   ASM_OUTPUT_DWARF_REF (asm_out_file, label);
  1577. }
  1578.  
  1579. #if 0
  1580. /* The AT_discr attribute is used only for variant records in languages like
  1581.    Ada or Pascal or Modula.  It identifies the member whose value determines
  1582.    which variant is currently selected.     */
  1583. static void
  1584. discr_attribute (decl)
  1585.     register tree decl;
  1586. {
  1587.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  1588.  
  1589.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_discr);
  1590.   sprintf (label, TYPE_NAME_FMT, TREE_UID (decl));
  1591.   ASM_OUTPUT_DWARF_REF (asm_out_file, label);
  1592. }
  1593.  
  1594. static void
  1595. discr_value (value)
  1596.     register tree value;
  1597. {
  1598.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1599.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1600.  
  1601.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_discr_value);
  1602.   sprintf (begin_label, DISC_BEGIN_LABEL_FMT, current_dienum);
  1603.   sprintf (end_label, DISC_END_LABEL_FMT, current_dienum);
  1604.   ASM_OUTPUT_DWARF_BLOCK2 (asm_out_file, end_label, begin_label);
  1605.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  1606.   ?
  1607.   ASM_OUTPUT_LABEL (asm_out_file, end_label);
  1608. }
  1609. #endif
  1610.  
  1611. /* Visibility attributes are generated for all entities (both functions and
  1612.    data objects) which have `internal' linkage. (See the ANSI C standard for
  1613.    a precise definition of internal linkage.)  Things which have internal
  1614.    linkage are (only) those things which are declared at file-scope with
  1615.    the `static' type modifier.    */
  1616.  
  1617. static void
  1618. visibility_attribute (visibility)
  1619.      register int visibility;
  1620. {
  1621.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_visibility);
  1622.   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, visibility);
  1623. }
  1624.  
  1625. #if 0
  1626. /* Add this when there is a GNU Modula-{2,3} front end.     */
  1627. static void
  1628. import_attribute (decl)
  1629.      register tree decl;
  1630. {
  1631.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  1632.  
  1633.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_import);
  1634.   sprintf (label, TYPE_NAME_FMT, TREE_UID (decl));
  1635.   ASM_OUTPUT_DWARF_REF (asm_out_file, label);
  1636. }
  1637. #endif
  1638.  
  1639. #if 0
  1640. /* Implement this when there is a GNU FORTRAN or GNU Ada front end.  */
  1641. static void
  1642. string_length_attribute (decl)
  1643.      register tree decl;
  1644. {
  1645.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1646.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  1647.  
  1648.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length);
  1649.   sprintf (begin_label, DISC_BEGIN_LABEL_FMT, current_dienum);
  1650.   sprintf (end_label, DISC_END_LABEL_FMT, current_dienum);
  1651.   ASM_OUTPUT_DWARF_BLOCK2 (asm_out_file, end_label, begin_label);
  1652.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  1653.   ?
  1654.   ASM_OUTPUT_LABEL (asm_out_file, end_label);
  1655. }
  1656. #endif
  1657.  
  1658. #ifdef AT_file
  1659. static void
  1660. file_attribute (filename)
  1661.      char *filename;
  1662. {
  1663.   unsigned file_number = lookup_filename (filename);
  1664.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  1665.  
  1666.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_file);
  1667.   sprintf (label, FILE_ENTRY_LABEL_FMT, file_number);
  1668.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
  1669. }
  1670. #endif
  1671.  
  1672. #ifdef AT_line
  1673. static void
  1674. line_attribute (line)
  1675.      unsigned line;
  1676. {
  1677.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_line);
  1678.   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, line);
  1679. }
  1680. #endif
  1681.  
  1682. #ifdef AT_comp_dir
  1683. static void
  1684. comp_dir_attribute (dirname)
  1685.      char *dirname;
  1686. {
  1687.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir);
  1688.   ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname);
  1689. }
  1690. #endif
  1691.  
  1692. #ifdef AT_src_info
  1693. static void
  1694. src_info_attribute (src_info_start_label)
  1695.      char *src_info_start_label;
  1696. {
  1697.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info);
  1698.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label);
  1699. }
  1700. #endif
  1701.  
  1702. #ifdef AT_addr_ranges
  1703. static void
  1704. addr_ranges_attribute ()
  1705. {
  1706.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_addr_ranges);
  1707.   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, (2 * 4) * 4);
  1708.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
  1709.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL);
  1710.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL);
  1711.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_END_LABEL);
  1712.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL);
  1713.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_END_LABEL);
  1714.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL);
  1715.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_END_LABEL);
  1716. }
  1717. #endif
  1718.  
  1719. #ifdef AT_prototyped
  1720. static void
  1721. prototyped_attribute ()
  1722. {
  1723.   ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped);
  1724. }
  1725. #endif
  1726.  
  1727. /************************* end of attributes *****************************/
  1728.  
  1729. /********************* utility routines for DIEs *************************/
  1730.  
  1731. static void
  1732. source_location_attributes (decl)
  1733.      register tree decl;
  1734. {
  1735. #ifdef AT_file
  1736.   file_attribute (DECL_SOURCE_FILE (decl));
  1737. #endif
  1738. #ifdef AT_line
  1739.   line_attribute (DECL_SOURCE_LINE (decl));
  1740. #endif
  1741. }
  1742.  
  1743. /* Many forms of DIEs contain a "type description" part.  The following
  1744.    routine writes out these "type descriptor" parts.  */
  1745.  
  1746. static void
  1747. type_attribute (type)
  1748.      register tree type;
  1749. {
  1750.   register enum tree_code code;
  1751.   register int root_type_modified;
  1752.  
  1753.   type = TYPE_MAIN_VARIANT (type);
  1754.   code = TREE_CODE (type);
  1755.   root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE);
  1756.   if (type_is_fundamental (root_type (type)))
  1757.     if (root_type_modified)
  1758.     mod_fund_type_attribute (type);
  1759.     else
  1760.     fund_type_attribute (type);
  1761.   else
  1762.     if (root_type_modified)
  1763.     mod_u_d_type_attribute (type);
  1764.     else
  1765.     user_def_type_attribute (type);
  1766. }
  1767.  
  1768. /* Given a pointer to a FUNCTION_TYPE node or a METHOD_TYPE node, return
  1769.    non-zero if the given FUNCTION_TYPE or METHOD_TYPE represents a
  1770.    prototyped type.  */
  1771.  
  1772. int
  1773. is_prototyped (func_type)
  1774.      register tree func_type;
  1775. {
  1776.   return (TYPE_ARG_TYPES (func_type) != (tree) 0);
  1777. }
  1778.  
  1779. /* Given a tree pointer to a struct, class, union, or enum type node, return
  1780.    a pointer to the (string) tag name for the given type, or zero if the
  1781.    type was declared without a tag.  */
  1782.  
  1783. static char *
  1784. type_tag (type)
  1785.      register tree type;
  1786. {
  1787.   register char *name = 0;
  1788.  
  1789.   if (TYPE_NAME (type) != 0) 
  1790.     {
  1791.       register tree t = 0;
  1792.  
  1793.       /* Find the IDENTIFIER_NODE for the type name.  */
  1794.       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  1795.     t = TYPE_NAME (type);
  1796.       /* Now get the name as a string, or invent one.  */
  1797.       if (t != 0)
  1798.     name = IDENTIFIER_POINTER (t);
  1799.     }
  1800.  
  1801.   return (name == 0 || *name == '\0') ? 0 : name;
  1802. }
  1803.  
  1804. static void
  1805. dienum_push ()
  1806. {
  1807.   /* Start by checking if the pending_sibling_stack needs to be expanded.
  1808.      If necessary, expand it.  */
  1809.  
  1810.   if (pending_sibling_stack_depth+1 > pending_sibling_stack_size)
  1811.     {
  1812.       pending_sibling_stack_size += PENDING_SIBLING_STACK_INCREMENT;
  1813.       pending_sibling_stack
  1814.     = (unsigned *) xrealloc (pending_sibling_stack,
  1815.                  pending_sibling_stack_size * sizeof (unsigned));
  1816.     }
  1817.  
  1818.   pending_sibling_stack_depth++;
  1819.   NEXT_DIE_NUM = next_unused_dienum++;
  1820. }
  1821.  
  1822. /* Pop the sibling stack so that the most recently pushed DIEnum becomes the
  1823.    NEXT_DIE_NUM.  */
  1824.  
  1825. static void
  1826. dienum_pop ()
  1827. {
  1828.   pending_sibling_stack_depth--;
  1829. }
  1830.  
  1831. static tree
  1832. member_declared_type (member)
  1833.      register tree member;
  1834. {
  1835.   return (DECL_BIT_FIELD (member))
  1836.        ? DECL_BIT_FIELD_TYPE (member)
  1837.        : TREE_TYPE (member);
  1838. }
  1839.  
  1840. /******************************* DIEs ************************************/
  1841.  
  1842. /* Output routines for individual types of DIEs.  These are arranged here in
  1843.    order of the numeric codes for the associated TAG_... constants.  */
  1844.  
  1845. /* Note that (contrary to popular belief) every type of DIE gets a sibling.  */
  1846.    
  1847. static void
  1848. output_array_type_die (arg)
  1849.      register void *arg;
  1850. {
  1851.   register tree type = arg;
  1852.  
  1853.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type);
  1854.   sibling_attribute ();
  1855.   equate_type_number_to_die_number (type);
  1856.  
  1857.   /* This is a kludge put here only for the sake of being compatible with
  1858.      what other `traditional DWARF' compilers do.  The definition of
  1859.      traditional DWARF only says that we have to include an ordering
  1860.      attribute in cases of multi-dimensional arrays, but existing
  1861.      compilers output an ordering attribute for all arrays, regardless
  1862.      of their dimensionality.  */
  1863.  
  1864.   ordering_attribute (ORD_row_major);
  1865.  
  1866.   subscript_data_attribute (type);
  1867. }
  1868.  
  1869. #if 0
  1870. /* This routine is not used because GCC & G++ treat classes pretty much the
  1871.    same as structs.  */
  1872. static void
  1873. output_class_type_die (arg)
  1874.      register void *arg;
  1875. {
  1876.   register tree type = arg;
  1877.  
  1878.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_class_type);
  1879.   sibling_attribute ();
  1880.   dienum_push ();
  1881.   equate_type_number_to_die_number (type);
  1882.   name_attribute (type_tag (type));
  1883.   byte_size_attribute (type);
  1884. }
  1885. #endif
  1886.  
  1887. #if 0
  1888. /* Implement this when there is a GNU FORTRAN or GNU Ada front end.  */
  1889. static void
  1890. output_entry_point_die (arg)
  1891.      register void *arg;
  1892. {
  1893.   register tree decl = arg;
  1894.   register tree type = TREE_TYPE (decl);
  1895.   register tree return_type = TREE_TYPE (type);
  1896.  
  1897.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point);
  1898.   sibling_attribute ();
  1899.   dienum_push ();
  1900.   if (DECL_NAME (decl))
  1901.     name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
  1902. #ifdef AT_prototyped
  1903.   if (is_prototyped (type))
  1904.     prototyped_attribute ();
  1905. #endif
  1906.   if (TREE_CODE (return_type) != VOID_TYPE)
  1907.     type_attribute (return_type);
  1908.   if (TREE_PUBLIC (decl) || TREE_EXTERNAL (decl))
  1909.     source_location_attributes (decl);
  1910. }
  1911. #endif
  1912.  
  1913. /* Output a DIE to represent an enumeration type.  Note that these DIEs
  1914.    include all of the information about the enumeration values also.
  1915.    This information is encoded into the element_list attribute.     */
  1916.  
  1917. static void
  1918. output_enumeration_type_die (arg)
  1919.      register void *arg;
  1920. {
  1921.   register tree type = arg;
  1922.  
  1923.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type);
  1924.   sibling_attribute ();
  1925.   equate_type_number_to_die_number (type);
  1926.   name_attribute (type_tag (type));
  1927.   byte_size_attribute (type);
  1928.   element_list_attribute (TYPE_FIELDS (type));
  1929. }
  1930.  
  1931. /* There are two routines here to output DIEs for formal parameters.  The
  1932.    first one is used to create DIEs for the formal parameters associated
  1933.    with function *types*.  For function types, GCC maintains only lists
  1934.    of the types of the formal parameters.  For actual functions, GCC
  1935.    maintains lists of PARM_DECL tree nodes.  The following two functions
  1936.    handle these two separate cases.  */
  1937.  
  1938. static void
  1939. output_formal_parameter_die_for_type (arg)
  1940.      register void *arg;
  1941. {
  1942.   register tree type = arg;
  1943.  
  1944.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
  1945.   sibling_attribute ();
  1946.  
  1947.   /* Note that here we only have information about the type of some
  1948.      particular formal parameter for some particular function type.
  1949.      Thus, we do not produce a name_attribute here because there is
  1950.      no particular name which is uniquely associated with the formal
  1951.      parameter type that we are describing.  */
  1952.  
  1953.   type_attribute (type);
  1954. }
  1955.  
  1956. /* Output a description of an authentic formal parameter for an actual
  1957.    function (not merely a function type).  */
  1958.  
  1959. static void
  1960. output_formal_parameter_die_for_decl (arg)
  1961.      register void *arg;
  1962. {
  1963.   register tree decl = arg;
  1964.   tree type = TREE_TYPE (decl);
  1965.  
  1966.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter);
  1967.   sibling_attribute ();
  1968.   if (DECL_NAME (decl))
  1969.     name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
  1970.   type_attribute (type);
  1971.   location_attribute (decl);
  1972. }
  1973.  
  1974. static void
  1975. output_global_subroutine_die (arg)
  1976.      register void *arg;
  1977. {
  1978.   register tree decl = arg;
  1979.   register tree type = TREE_TYPE (decl);
  1980.   register tree return_type = TREE_TYPE (type);
  1981.  
  1982.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine);
  1983.   sibling_attribute ();
  1984.   dienum_push ();
  1985.   if (DECL_NAME (decl))
  1986.     name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
  1987. #ifdef AT_prototyped
  1988.   if (is_prototyped (type))
  1989.     prototyped_attribute ();
  1990. #endif
  1991.   if (TREE_CODE (return_type) != VOID_TYPE)
  1992.     type_attribute (return_type);
  1993.   if (!TREE_PUBLIC (decl))
  1994.     visibility_attribute (VIS_local);
  1995. #ifdef DWARF_DESCRIBE_USED_EXTERNS
  1996.   if (!TREE_EXTERNAL (decl))
  1997. #endif
  1998.     {
  1999.       char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2000.  
  2001.       low_pc_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
  2002.       sprintf (func_end_label, FUNC_END_LABEL_FMT, TREE_UID (decl));
  2003.       high_pc_attribute (func_end_label);
  2004.     }
  2005.   if (TREE_PUBLIC (decl) || TREE_EXTERNAL (decl))
  2006.     source_location_attributes (decl);
  2007. }
  2008.  
  2009. static void
  2010. output_global_variable_die (arg)
  2011.      register void *arg;
  2012. {
  2013.   register tree decl = arg;
  2014.   register tree type = TREE_TYPE (decl);
  2015.  
  2016.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable);
  2017.   sibling_attribute ();
  2018.   if (DECL_NAME (decl))
  2019.     name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
  2020.   type_attribute (type);
  2021.   if (!TREE_PUBLIC (decl))
  2022.     visibility_attribute (VIS_local);
  2023. #ifdef DWARF_DESCRIBE_USED_EXTERNS
  2024.   if (!TREE_EXTERNAL (decl))
  2025. #endif
  2026.     location_attribute (decl);
  2027.   if (TREE_PUBLIC (decl) || TREE_EXTERNAL (decl))
  2028.     source_location_attributes (decl);
  2029. }
  2030.  
  2031. #if 0
  2032. /* Implement this routine when there is a GNU Modula front-end.     */
  2033. static void
  2034. output_imported_declaration_die (arg)
  2035.      register void *arg;
  2036. {
  2037.   register tree decl = arg;
  2038.  
  2039.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_imported_declaration);
  2040.   sibling_attribute ();
  2041. }
  2042. #endif
  2043.  
  2044. static void
  2045. output_inline_subroutine_die (arg)
  2046.      register void *arg;
  2047. {
  2048.   register tree decl = arg;
  2049.   register tree type = TREE_TYPE (decl);
  2050.   register tree return_type = TREE_TYPE (type);
  2051.  
  2052.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inline_subroutine);
  2053.   sibling_attribute ();
  2054.   dienum_push ();
  2055.   if (DECL_NAME (decl))
  2056.     name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
  2057. #ifdef AT_prototyped
  2058.   if (is_prototyped (type))
  2059.     prototyped_attribute ();
  2060. #endif
  2061.   if (TREE_CODE (return_type) != VOID_TYPE)
  2062.     type_attribute (return_type);
  2063.   if (!TREE_PUBLIC (decl))
  2064.     visibility_attribute (VIS_local);
  2065. #ifdef DWARF_DESCRIBE_USED_EXTERNS
  2066.   if (!TREE_EXTERNAL (decl))
  2067. #endif
  2068.     {
  2069.       char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2070.  
  2071.       low_pc_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
  2072.       sprintf (func_end_label, FUNC_END_LABEL_FMT, TREE_UID (decl));
  2073.       high_pc_attribute (func_end_label);
  2074.     }
  2075.   if (TREE_PUBLIC (decl) || TREE_EXTERNAL (decl))
  2076.     source_location_attributes (decl);
  2077. }
  2078.  
  2079. static void
  2080. output_label_die (arg)
  2081.      register void *arg;
  2082. {
  2083.   register tree decl = arg;
  2084.   register rtx insn = DECL_RTL (decl);
  2085.  
  2086.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label);
  2087.   sibling_attribute ();
  2088.   name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
  2089.  
  2090.   /* When optimization is enabled (with -O) the code in jump.c and in flow.c
  2091.      may cause insns representing one of more of the user's own labels to
  2092.      be deleted.  This happens whenever it is determined that a given label
  2093.      is unreachable.
  2094.  
  2095.      In such cases, we here generate an abbreviated form of a label DIE.
  2096.      This abbreviated version does *not* have a low_pc attribute.  This
  2097.      should signify to the debugger that the label has been optimized away.
  2098.  
  2099.      Note that a CODE_LABEL can get deleted either by begin converted into
  2100.      a NOTE_INSN_DELETED note, or by simply having its INSN_DELETED_P flag
  2101.      set to true.  We handle both cases here.
  2102.   */
  2103.  
  2104.   if (GET_CODE (insn) == CODE_LABEL && ! INSN_DELETED_P (insn))
  2105.     {
  2106.       char label[MAX_ARTIFICIAL_LABEL_BYTES];
  2107.  
  2108.       sprintf (label, INSN_LABEL_FMT, TREE_UID (current_function_decl),
  2109.                       INSN_UID (insn));
  2110.       low_pc_attribute (label);
  2111.     }
  2112. }
  2113.  
  2114. static void
  2115. output_lexical_block_die (arg)
  2116.      register void *arg;
  2117. {
  2118.   register tree stmt = arg;
  2119.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2120.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2121.  
  2122.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block);
  2123.   sibling_attribute ();
  2124.   dienum_push ();
  2125.   sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number);
  2126.   low_pc_attribute (begin_label);
  2127.   sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number);
  2128.   high_pc_attribute (end_label);
  2129. }
  2130.  
  2131. static void
  2132. output_local_variable_die (arg)
  2133.      register void *arg;
  2134. {
  2135.   register tree decl = arg;
  2136.   register tree type = TREE_TYPE (decl);
  2137.  
  2138.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable);
  2139.   sibling_attribute ();
  2140.   if (DECL_NAME (decl))
  2141.     name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
  2142.   type_attribute (type);
  2143. #ifdef DWARF_DESCRIBE_USED_EXTERNS
  2144.   if (!TREE_EXTERNAL (decl))
  2145. #endif
  2146.     location_attribute (decl);
  2147.   if (TREE_EXTERNAL (decl))
  2148.     source_location_attributes (decl);
  2149. }
  2150.  
  2151. static void
  2152. output_member_die (arg)
  2153.      register void *arg;
  2154. {
  2155.   register tree decl = arg;
  2156.  
  2157.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member);
  2158.   sibling_attribute ();
  2159.   if (DECL_NAME (decl))
  2160.     name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
  2161.   type_attribute (member_declared_type (decl));
  2162.   if (DECL_BIT_FIELD (decl))    /* If this is a bit field... */
  2163.     {
  2164.       byte_size_attribute (decl);
  2165.       bit_size_attribute (decl);
  2166.       bit_offset_attribute (decl);
  2167.     }
  2168.   location_attribute (decl);
  2169. }
  2170.  
  2171. static void
  2172. output_member_function_die (arg)
  2173.      register void *arg;
  2174. {
  2175.   register tree decl = arg;
  2176.   register tree type = TREE_TYPE (decl);
  2177.   register tree return_type = TREE_TYPE (type);
  2178.  
  2179.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member_function);
  2180.   sibling_attribute ();
  2181.   dienum_push ();
  2182.   if (DECL_NAME (decl))
  2183.     name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
  2184. #ifdef AT_prototyped
  2185.   if (is_prototyped (type))
  2186.     prototyped_attribute ();
  2187. #endif
  2188.   if (TREE_CODE (return_type) != VOID_TYPE)
  2189.     type_attribute (return_type);
  2190.   if (!TREE_PUBLIC (decl))
  2191.     visibility_attribute (VIS_local);
  2192. #ifdef DWARF_DESCRIBE_USED_EXTERNS
  2193.   if (!TREE_EXTERNAL (decl))
  2194. #endif
  2195.     {
  2196.       char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2197.  
  2198.       low_pc_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
  2199.       sprintf (func_end_label, FUNC_END_LABEL_FMT, TREE_UID (decl));
  2200.       high_pc_attribute (func_end_label);
  2201.     }
  2202.   if (TREE_PUBLIC (decl) || TREE_EXTERNAL (decl))
  2203.     source_location_attributes (decl);
  2204. }
  2205.  
  2206. #if 0
  2207. /* Don't generate either pointer_type DIEs or reference_type DIEs.  According
  2208.    to the 4-4-90 DWARF draft spec (just after requirement #47):
  2209.  
  2210.     These two type entries are not currently generated by any compiler.
  2211.     Since the only way to name a pointer (or reference) type is C or C++
  2212.     is via a "typedef", an entry with the "typedef" tag is generated
  2213.     instead.
  2214. */
  2215.  
  2216. static void
  2217. output_pointer_type_die (arg)
  2218.      register void *arg;
  2219. {
  2220.   register tree type = arg;
  2221.  
  2222.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type);
  2223.   sibling_attribute ();
  2224.   type_attribute (TREE_TYPE (type));
  2225. }
  2226.  
  2227. static void
  2228. output_reference_type_die (arg)
  2229.      register void *arg;
  2230. {
  2231.   register tree type = arg;
  2232.  
  2233.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type);
  2234.   sibling_attribute ();
  2235.   type_attribute (TREE_TYPE (type));
  2236. }
  2237. #endif
  2238.  
  2239. static void
  2240. output_source_file_die (arg)
  2241.      register void *arg;
  2242. {
  2243.   register char *main_input_filename = arg;
  2244.  
  2245.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_source_file);
  2246.   sibling_attribute ();
  2247.   dienum_push ();
  2248.   name_attribute (main_input_filename);
  2249.  
  2250.   /* If we are producing the source_file_die for the .externs section, then
  2251.      produce only the abbreviated version.  */
  2252.  
  2253. #ifdef DWARF_DESCRIBE_USED_EXTERNS
  2254.   if (! finalizing)
  2255. #endif
  2256.     {
  2257.       language_attribute (LANG_ANSI_C_V1);
  2258.       low_pc_attribute (TEXT_BEGIN_LABEL);
  2259.       high_pc_attribute (TEXT_END_LABEL);
  2260.       stmt_list_attribute (LINE_BEGIN_LABEL);
  2261.       last_filename = xstrdup (main_input_filename);
  2262.     }
  2263.  
  2264.   /* Produce some specialized GNU DWARF attributes if needed.  */
  2265.  
  2266. #ifdef AT_comp_dir
  2267.   {
  2268.     int len = 500;
  2269.     char *dirname = (char *) xmalloc (len + 1);
  2270.  
  2271.     /* We don't know how much space the dirname needs,
  2272.        so try bigger and bigger buffers until it fits.  */
  2273.     while (1)
  2274.       {
  2275.     getcwd (dirname, len);    /* Being conservative here. */
  2276.     if (strlen (dirname) < len - 1)    /* Being conservative here. */
  2277.       break;
  2278.     len *= 2;
  2279.     dirname = (char *) xrealloc (dirname, len + 1);
  2280.       }
  2281.  
  2282.     comp_dir_attribute (dirname);
  2283.     free (dirname);
  2284.   }
  2285. #endif
  2286.  
  2287. #ifdef AT_src_info
  2288.   src_info_attribute (SRCINFO_BEGIN_LABEL);
  2289. #endif
  2290.  
  2291. #ifdef AT_addr_ranges
  2292.   addr_ranges_attribute ();
  2293. #endif
  2294. }
  2295.  
  2296. #if 0
  2297. /* Implement this when there is a GNU FORTRAN or GNU Ada front end.  */
  2298. static void
  2299. output_string_type_die (arg)
  2300.      register void *arg;
  2301. {
  2302.   register tree type = arg;
  2303.  
  2304.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type);
  2305.   sibling_attribute ();
  2306.   string_length_attribute (?);
  2307. }
  2308. #endif
  2309.  
  2310. static void
  2311. output_structure_type_die (arg)
  2312.      register void *arg;
  2313. {
  2314.   register tree type = arg;
  2315.  
  2316.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type);
  2317.   sibling_attribute ();
  2318.   equate_type_number_to_die_number (type);
  2319.   name_attribute (type_tag (type));
  2320.  
  2321.   /* If this type has been completed, then give it a byte_size attribute
  2322.      and prepare to give a list of members.  Otherwise, don't do either of
  2323.      these things.  In the latter case, we will not be generating a list
  2324.      of members (since we don't have any idea what they might be for an
  2325.      incomplete type).    */
  2326.  
  2327.   if (TYPE_SIZE (type))
  2328.     {
  2329.       dienum_push ();
  2330.       byte_size_attribute (type);
  2331.     }
  2332.  
  2333. #ifdef GPLUSPLUS
  2334.   if (CLASSTYPE_N_BASECLASSES (type) > 0)
  2335.     deriv_list_attribute (type);
  2336. #endif
  2337. }
  2338.  
  2339. #if 0
  2340. /* Don't use this.  It was a dumb idea on the part of the DWARF designers to
  2341.    try to support non-global (i.e. local functions & procedures in languages
  2342.    other than C and C++.  It would have been better to use an attribute for
  2343.    the "local" aspect of such functions/procedures or (better still) just
  2344.    have the debugger figure out that a function is either local or global
  2345.    depending upon what sibling chain it is on.    */
  2346. static void
  2347. output_subroutine_die (arg)
  2348.      register void *arg;
  2349. {
  2350.   register tree decl = arg;
  2351.  
  2352.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine);
  2353.   sibling_attribute ();
  2354.   dienum_push ();
  2355. }
  2356. #endif
  2357.  
  2358. static void
  2359. output_subroutine_type_die (arg)
  2360.      register void *arg;
  2361. {
  2362.   register tree type = arg;
  2363.   register tree return_type = TREE_TYPE (type);
  2364.  
  2365.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type);
  2366.   sibling_attribute ();
  2367.   dienum_push ();
  2368.   equate_type_number_to_die_number (type);
  2369. #ifdef AT_prototyped
  2370.   if (is_prototyped (type))
  2371.     prototyped_attribute ();
  2372. #endif
  2373.   if (TREE_CODE (return_type) != VOID_TYPE)
  2374.     type_attribute (return_type);
  2375. }
  2376.  
  2377. static void
  2378. output_typedef_die (arg)
  2379.      register void *arg;
  2380. {
  2381.   register tree decl = arg;
  2382.   register tree type = TREE_TYPE (decl);
  2383.  
  2384.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef);
  2385.   sibling_attribute ();
  2386.   equate_type_number_to_die_number (decl);
  2387.   if (DECL_NAME (decl))
  2388.     name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl)));
  2389.   type_attribute (type);
  2390. }
  2391.  
  2392. static void
  2393. output_union_type_die (arg)
  2394.      register void *arg;
  2395. {
  2396.   register tree type = arg;
  2397.  
  2398.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type);
  2399.   sibling_attribute ();
  2400.   equate_type_number_to_die_number (type);
  2401.   name_attribute (type_tag (type));
  2402.  
  2403.   /* If this type has been completed, then give it a byte_size attribute
  2404.      and prepare to give a list of members.  Otherwise, don't do either of
  2405.      these things.  In the latter case, we will not be generating a list
  2406.      of members (since we don't have any idea what they might be for an
  2407.      incomplete type).    */
  2408.  
  2409.   if (TYPE_SIZE (type))
  2410.     {
  2411.       dienum_push ();
  2412.       byte_size_attribute (type);
  2413.     }
  2414. }
  2415.  
  2416. /* Generate a special type of DIE used as a stand-in for a trailing ellipsis
  2417.    at the end of an (ANSI prototyped) formal parameters list.  */
  2418.  
  2419. static void
  2420. output_unspecified_parameters_die (arg)
  2421.      register void *arg;
  2422. {
  2423.   register int generate_name = (int) arg;
  2424.  
  2425.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters);
  2426.   sibling_attribute ();
  2427.  
  2428.   /* This kludge is here only for the sake of being compatible with what
  2429.      other `traditional DWARF' compilers do.  The definition of traditional
  2430.      DWARF doesn't even allow unspecified_parameters DIEs to contain any
  2431.      sort of name attribute, but existing compilers output one containing
  2432.      `...' for function declarations (but not for function types) so we do
  2433.      likewise here.  */
  2434.  
  2435.   if (generate_name)
  2436.     name_attribute ("...");
  2437. }
  2438.  
  2439. #if 0
  2440. /* Implement this when there is a GNU Pascal or Modula or Ada front-end.  */
  2441. static void
  2442. output_variant_die (arg)
  2443.      register void *arg;
  2444. {
  2445.   register tree type = arg;
  2446.  
  2447.   ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_variant);
  2448.   sibling_attribute ();
  2449.   dienum_push ();
  2450. }
  2451. #endif
  2452.  
  2453. static void
  2454. output_padded_null_die (arg)
  2455.      register void *arg;
  2456. {
  2457.   ASM_OUTPUT_ALIGN (asm_out_file, 2);    /* 2**2 == 4 */
  2458. }
  2459.  
  2460. /*************************** end of DIEs *********************************/
  2461.  
  2462. /* Generate some type of DIE.  This routine generates the generic outer
  2463.    wrapper stuff which goes around all types of DIE's (regardless of their
  2464.    TAGs.  All forms of DIEs start with a DIE-specific label, followed by a
  2465.    DIE-length word, followed by the guts of the DIE itself.  After the guts
  2466.    of the DIE, there must always be a terminator label for the DIE.  */
  2467.  
  2468. static void
  2469. output_die (die_specific_output_function, param)
  2470.      register void (*die_specific_output_function)();
  2471.      register void *param;
  2472. {
  2473.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2474.   char end_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2475.  
  2476.   current_dienum = NEXT_DIE_NUM;
  2477.   NEXT_DIE_NUM = next_unused_dienum;
  2478.  
  2479.   sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
  2480.   sprintf (end_label, DIE_END_LABEL_FMT, current_dienum);
  2481.  
  2482.   /* Write a label which will act as the name for the start of this DIE.  */
  2483.  
  2484.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  2485.  
  2486.   /* Write the DIE-length word.     */
  2487.  
  2488.   ASM_OUTPUT_DWARF_BLOCK4 (asm_out_file, end_label, begin_label);
  2489.  
  2490.   /* Fill in the guts of the DIE.  */
  2491.  
  2492.   next_unused_dienum++;
  2493.   die_specific_output_function (param);
  2494.  
  2495.   /* Write a label which will act as the name for the end of this DIE.    */
  2496.  
  2497.   ASM_OUTPUT_LABEL (asm_out_file, end_label);
  2498. }
  2499.  
  2500. static void
  2501. end_sibling_chain ()
  2502. {
  2503.   char begin_label[MAX_ARTIFICIAL_LABEL_BYTES];
  2504.  
  2505.   current_dienum = NEXT_DIE_NUM;
  2506.   NEXT_DIE_NUM = next_unused_dienum;
  2507.  
  2508.   sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum);
  2509.  
  2510.   /* Write a label which will act as the name for the start of this DIE.  */
  2511.  
  2512.   ASM_OUTPUT_LABEL (asm_out_file, begin_label);
  2513.  
  2514.   /* Write the DIE-length word.     */
  2515.  
  2516.   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4);
  2517.  
  2518.   dienum_pop ();
  2519. }
  2520.  
  2521. static void
  2522. output_member_list_types (mbr)
  2523.      register tree mbr;
  2524. {
  2525.   for ( ; mbr; mbr = TREE_CHAIN (mbr))
  2526.     /* Omit here the nameless fields that are used to skip bits.  */
  2527.     if (DECL_NAME (mbr) != 0)
  2528.       output_dies_for_type (member_declared_type (mbr));
  2529. }
  2530.  
  2531. static void
  2532. output_member_list (mbr)
  2533.      register tree mbr;
  2534. {
  2535.   for ( ; mbr; mbr = TREE_CHAIN (mbr))
  2536.     /* Omit here the nameless fields that are used to skip bits.  */
  2537.     if (DECL_NAME (mbr) != 0)
  2538.       output_die (output_member_die, mbr);
  2539.   end_sibling_chain (); /* End of member chain.     */
  2540. }
  2541.  
  2542. static void
  2543. output_formals_for_type (func_type)
  2544.      register tree func_type;
  2545. {
  2546.   register tree link;
  2547.  
  2548.   for (link = TYPE_ARG_TYPES (func_type); link; link = TREE_CHAIN (link))
  2549.     {
  2550.       register tree formal_type = TREE_VALUE (link);
  2551.  
  2552.       if (formal_type == void_type_node)
  2553.     return;
  2554.  
  2555.       /* Output a (nameless) DIE to represent the formal parameter itself.  */
  2556.  
  2557.       output_die (output_formal_parameter_die_for_type, formal_type);
  2558.     }
  2559.  
  2560.   /* This function type has an ellipsis.  So add a TAG_unspecified_parameters
  2561.      DIE to the end of the parameter list.  */
  2562.  
  2563.   output_die (output_unspecified_parameters_die, (void*) FALSE);
  2564. }
  2565.  
  2566. static void
  2567. output_dies_for_types_of_formals (func_type)
  2568.      register tree func_type;
  2569. {
  2570.   register tree link;
  2571.  
  2572.   for (link = TYPE_ARG_TYPES (func_type); link; link = TREE_CHAIN (link))
  2573.     {
  2574.       register tree formal_type = TREE_VALUE (link);
  2575.  
  2576.       if (formal_type == void_type_node)
  2577.     break;
  2578.  
  2579.       output_dies_for_type (formal_type);
  2580.     }
  2581. }
  2582.  
  2583. static void
  2584. output_dies_for_type (type)
  2585.      register tree type;
  2586. {
  2587.   if (type == 0 || type == error_mark_node)
  2588.     return;
  2589.  
  2590.   type = TYPE_MAIN_VARIANT (type);
  2591.  
  2592.   if (TREE_ASM_WRITTEN (type))
  2593.     return;
  2594.  
  2595.   switch (TREE_CODE (type))
  2596.     {
  2597.       case ERROR_MARK:
  2598.     break;
  2599.  
  2600.       case POINTER_TYPE:
  2601.       case REFERENCE_TYPE:
  2602.     output_dies_for_type (TREE_TYPE (type));
  2603.     break;
  2604.  
  2605.       case ARRAY_TYPE:
  2606.     {
  2607.       register tree element_type;
  2608.  
  2609.       element_type = TYPE_MAIN_VARIANT(TREE_TYPE(TYPE_MAIN_VARIANT(type)));
  2610.       while (TREE_CODE (element_type) == ARRAY_TYPE)
  2611.         element_type = TYPE_MAIN_VARIANT (TREE_TYPE (element_type));
  2612.     
  2613.       output_dies_for_type (element_type);
  2614.       output_die (output_array_type_die, type);
  2615.     }
  2616.     break;
  2617.  
  2618.       case RECORD_TYPE:
  2619.       case UNION_TYPE:
  2620.       case ENUMERAL_TYPE:
  2621.  
  2622.     /* Basically, don't do anything for tagged types now.  They will be
  2623.        output later on when we see their associated TAG_DECLs in the
  2624.        set of ..._DECL nodes for the current scope.     Note however that
  2625.        it is possible that we might never see such a TAG_DECL later in
  2626.        the current scope.  This can happen in those (rare?) cases where
  2627.        there was a declaration in the current scope for something (e.g.
  2628.        a pointer variable or a pointer typedef) which made reference to
  2629.        a tagged type (i.e. a struct, union, or enum type) which never
  2630.        actually gets completed within the current scope.  For the sake
  2631.        of such cases, we must keep track here of each (still unprocessed)
  2632.        tag type for the current scope.  At the end of the scope, we must
  2633.        revisit the list that we made of these unprocessed taggged types
  2634.        and output descriptions of any of them which have not yet been
  2635.        described.  (These will all be incomplete tagged types.)  */
  2636.  
  2637.     pending_tagged_types = perm_tree_cons (0, type, pending_tagged_types);
  2638.  
  2639.     /* EARLY EXIT!    Avoid setting TREE_ASM_WRITTEN because we haven't
  2640.        necessarily written out the full info for this tagged type yet.  */
  2641.  
  2642.     return;
  2643.  
  2644.       case FUNCTION_TYPE:
  2645.     /* Force out return type (in case it wasn't forced out already).  */
  2646.     output_dies_for_type (TREE_TYPE (type));
  2647.     output_dies_for_types_of_formals (type);
  2648.     output_die (output_subroutine_type_die, type);
  2649.     output_formals_for_type (type);
  2650.     end_sibling_chain ();
  2651.     break;
  2652.  
  2653.       case METHOD_TYPE:
  2654.     /* Force out return type (in case it wasn't forced out already).  */
  2655.     output_dies_for_type (TREE_TYPE (type));
  2656.     output_dies_for_types_of_formals (type);
  2657.     output_die (output_subroutine_type_die, type);
  2658.     output_formals_for_type (type);
  2659.     end_sibling_chain ();
  2660.     break;
  2661.  
  2662.       case VOID_TYPE:
  2663.       case INTEGER_TYPE:
  2664.       case REAL_TYPE:
  2665.       case COMPLEX_TYPE:
  2666.       case BOOLEAN_TYPE:
  2667.       case CHAR_TYPE:
  2668.       case SET_TYPE:
  2669.     break;        /* No DIEs needed for fundamental types.  */
  2670.  
  2671.       case FILE_TYPE:    /* No DWARF representation currently defined.  */
  2672.       case STRING_TYPE: /* No DWARF representation currently defined.  */
  2673.       case OFFSET_TYPE: /* No DWARF representation currently defined.  */
  2674.       case LANG_TYPE:    /* No DWARF representation currently defined.  */
  2675.       default:
  2676.     abort ();
  2677.     }
  2678.  
  2679.   TREE_ASM_WRITTEN (type) = 1;
  2680. }
  2681.  
  2682. static void
  2683. output_dies_for_tagged_type (type)
  2684.      register tree type;
  2685. {
  2686.   if (type == 0 || type == error_mark_node)
  2687.     return;
  2688.  
  2689.   assert (type == TYPE_MAIN_VARIANT (type));
  2690.  
  2691.   if (TREE_ASM_WRITTEN (type))
  2692.     return;
  2693.  
  2694.   switch (TREE_CODE (type))
  2695.     {
  2696.       case RECORD_TYPE:
  2697.  
  2698.     /* If this is not an incomplete type, output descriptions of the
  2699.        types of each of its members.  */
  2700.  
  2701.     if (TYPE_SIZE (type))
  2702.       output_member_list_types (TYPE_FIELDS (type));
  2703.  
  2704.     output_die (output_structure_type_die, type);
  2705.  
  2706.     /* If this is not an incomplete type, output descriptions of each of
  2707.        its members.     */
  2708.  
  2709.     if (TYPE_SIZE (type))
  2710.       output_member_list (TYPE_FIELDS (type));
  2711.  
  2712.     break;
  2713.  
  2714.       case UNION_TYPE:
  2715.  
  2716.     /* If this is not an incomplete type, output descriptions of the
  2717.        types of each of its members.  */
  2718.  
  2719.     if (TYPE_SIZE (type))
  2720.       output_member_list_types (TYPE_FIELDS (type));
  2721.  
  2722.     output_die (output_union_type_die, type);
  2723.  
  2724.     /* If this is not an incomplete type, output descriptions of each of
  2725.        its members.     */
  2726.  
  2727.     if (TYPE_SIZE (type))
  2728.       output_member_list (TYPE_FIELDS (type));
  2729.  
  2730.     break;
  2731.  
  2732.       case ENUMERAL_TYPE:
  2733.     output_die (output_enumeration_type_die, type);
  2734.     break;
  2735.  
  2736.       default:
  2737.     abort ();
  2738.     }
  2739.  
  2740.   TREE_ASM_WRITTEN (type) = 1;
  2741. }
  2742.  
  2743. static void
  2744. output_pending_tagged_types ()
  2745. {
  2746.   /* Output DIEs to represent any tagged types which are declared within the
  2747.      current scope but which were never completed within the current scope.  */
  2748.  
  2749.   while (TREE_VALUE (pending_tagged_types) != NULL)
  2750.     {
  2751.       output_dies_for_tagged_type (TREE_VALUE (pending_tagged_types));
  2752.       pending_tagged_types = TREE_CHAIN (pending_tagged_types);
  2753.     }
  2754.  
  2755.   /* Throw away the scope marker.  */
  2756.  
  2757.   pending_tagged_types = TREE_CHAIN (pending_tagged_types);
  2758. }
  2759.  
  2760. /* Output all of the symbols declared within a given lexical block (also
  2761.    called a `binding contour') and (recursively) all of it's sub-blocks.  */
  2762.  
  2763. static void
  2764. output_symbols_for_block (stmt, labels)
  2765.      register tree stmt;
  2766.      register tree labels;
  2767. {
  2768.   tree subblocks;
  2769.  
  2770.   /* Ignore BLOCKs for blocks never really used to make RTL.     */
  2771.  
  2772.   if ((! stmt || ! TREE_USED (stmt)) && ! labels)
  2773.     return;
  2774.  
  2775.   /* Output a DIE to represent this block itself.  */
  2776.  
  2777.   next_block_number++;
  2778.   output_die (output_lexical_block_die, stmt);
  2779.  
  2780.   /* Output DWARF info for all of the labels within this block.     */
  2781.  
  2782.   {
  2783.     register tree link;
  2784.  
  2785.     for (link = labels; link; link = TREE_CHAIN (link))
  2786.       output_die (output_label_die, TREE_VALUE (link));
  2787.   }
  2788.  
  2789.   /* Place a scope marker on the list of pending tagged types.    */
  2790.  
  2791.   pending_tagged_types = perm_tree_cons (NULL, NULL, pending_tagged_types);
  2792.  
  2793.   /* Output the DIEs to represent all of the items declared
  2794.      directly within this block (but not within any nested
  2795.      sub-blocks).  */
  2796.  
  2797.   {
  2798.     register tree symbol;
  2799.  
  2800.     for (symbol = BLOCK_VARS (stmt); symbol; symbol = TREE_CHAIN (symbol))
  2801.       output_symbol (symbol, 1);
  2802.   }
  2803.  
  2804.   output_pending_tagged_types ();
  2805.  
  2806.   /* Output the DIEs to represent all sub-blocks of this block.     */
  2807.  
  2808.   for (subblocks = BLOCK_SUBBLOCKS (stmt) ; stmt; stmt = BLOCK_CHAIN (stmt))
  2809.     output_symbols_for_block (subblocks, 0);
  2810.  
  2811.   /* Terminate the list of `owned' items for this lexical block.  */
  2812.  
  2813.   end_sibling_chain ();
  2814. }
  2815.  
  2816. /* Output DWARF information for a symbol described by DECL.
  2817.    LOCAL is nonzero if the symbol is not file-scope.  */
  2818.  
  2819. static void
  2820. output_symbol (decl, local)
  2821.      register tree decl;
  2822.      register int local;
  2823. {
  2824.   switch (TREE_CODE (decl))
  2825.     {
  2826.     case ERROR_MARK:
  2827.       break;
  2828.  
  2829.     case CONST_DECL:
  2830.       /* Enum values are defined by defining the enum type.  */
  2831.       break;
  2832.  
  2833.     case FUNCTION_DECL:
  2834. #ifdef DWARF_DESCRIBE_USED_EXTERNS
  2835.       /* Even if we are describing externals, don't describe ones which are
  2836.      never even used.  They may be totally bogus and nonexistant.  */
  2837.       if (TREE_EXTERNAL (decl) && ! TREE_USED (decl))
  2838.     break;
  2839. #else
  2840.       /* Don't mention functions that are external.  Rather, assume that
  2841.      these functions will be described in the debugging information
  2842.      for the compilation units in which these function get defined.     */
  2843.       if (TREE_EXTERNAL (decl))
  2844.     break;
  2845. #endif
  2846.       if (GET_CODE (DECL_RTL (decl)) != MEM
  2847.       || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
  2848.     break;
  2849.  
  2850.       /* Before we describe the FUNCTION_DECL itself, make sure that we
  2851.      have already described its return type and the types of each of
  2852.      each of its parameters.  */
  2853.  
  2854.       output_dies_for_type (TREE_TYPE (TREE_TYPE (decl)));
  2855.       output_dies_for_types_of_formals (TREE_TYPE (decl));
  2856.  
  2857.       /* Not that the call above to output_dies_for_types_of_formals()
  2858.      is only sufficient to force out the types of all of the formal
  2859.      parameters when the current function is prototyped.  For the sake
  2860.      of non-prototyped functions we also need the following code to
  2861.      be sure of getting the types of all formal parameters adequately
  2862.      represented in the DWARF output.  */
  2863.  
  2864.       {
  2865.     register tree parm;
  2866.  
  2867.     for (parm = DECL_ARGUMENTS (decl); parm; parm = TREE_CHAIN (parm))
  2868.       output_dies_for_type (TREE_TYPE (parm));
  2869.       }
  2870.  
  2871. #ifdef DWARF_DESCRIBE_USED_EXTERNS
  2872.  
  2873.       if (TREE_EXTERNAL (decl) && ! finalizing)
  2874.     {
  2875.       /* Remember this function if it is *not* a builtin.  */
  2876.  
  2877.       if (! DECL_FUNCTION_CODE (decl))
  2878.         {
  2879.           /* Remember this FUNCTION_DECL on the pending_extern_decls list.
  2880.          We will output a description of it later, at the end of
  2881.          compilation, to the .externs section.  */
  2882.  
  2883.           pending_extern_decls = perm_tree_cons (0, decl, pending_extern_decls);
  2884.  
  2885.           /* Make sure that nested extern declarations are not thrown
  2886.          away until we have had a fair chance to finalize them.  */
  2887.  
  2888.           if (DECL_CONTEXT (decl))
  2889.         preserve_data ();
  2890.         }
  2891.       break;
  2892.     }
  2893. #endif
  2894.  
  2895.       /* Now output a DIE to represent the function itself.  */
  2896.  
  2897.       if (TREE_INLINE (decl))
  2898.     output_die (output_inline_subroutine_die, decl);
  2899.       else
  2900.     output_die (output_global_subroutine_die, decl);
  2901.  
  2902.       /* Now output descriptions of the arguments for this function.
  2903.      This gets (unnecessarily?) complex because of the fact that
  2904.      the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate
  2905.      cases where there was a trailing `...' at the end of the formal
  2906.      parameter list.  In order to find out if there was a trailing
  2907.      ellipsis or not, we must instead look at the type associated
  2908.      with the FUNCTION_DECL.  This will be a node of type FUNCTION_TYPE.
  2909.      If the chain of type nodes hanging of of this FUNCTION_TYPE node
  2910.      ends with a void_type_node then there should not be an ellipsis
  2911.      at the end.  */
  2912.  
  2913. #ifdef DWARF_DESCRIBE_USED_EXTERNS
  2914.  
  2915.       /* In the case where we are describing an external function, all we can
  2916.      do here is to describe the *types* of its formal parameters.  */
  2917.  
  2918.       if (TREE_EXTERNAL (decl))
  2919.     output_formals_for_type (TREE_TYPE (decl));
  2920.       else
  2921.  
  2922. #endif
  2923.     {
  2924.       register tree arg_decls = DECL_ARGUMENTS (decl);
  2925.  
  2926.       /* Generate DIEs to represent all known formal parameters, but
  2927.          don't do it if this looks like a varargs function.     */
  2928.  
  2929.       if (! arg_decls
  2930.           || ! DECL_NAME (arg_decls)
  2931.           || strcmp (IDENTIFIER_POINTER (DECL_NAME (arg_decls)),
  2932.              "__builtin_va_alist"))
  2933.         {
  2934.           register tree parm;
  2935.  
  2936.           for (parm = arg_decls; parm; parm = TREE_CHAIN (parm))
  2937.         if (TREE_CODE(parm) == PARM_DECL)
  2938.           output_die (output_formal_parameter_die_for_decl, parm);
  2939.         }
  2940.  
  2941.       /* Now try to decide if we should put an ellipsis at the end. */
  2942.  
  2943.       {
  2944.         register int has_ellipsis = TRUE;    /* default assumption */
  2945.         register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl));
  2946.  
  2947.         if (fn_arg_types)
  2948.           {
  2949.         /* This function declaration/definition was prototyped.     */
  2950.  
  2951.         /* If the list of formal argument types ends with a
  2952.            void_type_node, then the formals list did *not* end
  2953.            with an ellipsis.  */
  2954.  
  2955.         if (TREE_VALUE (tree_last (fn_arg_types)) == void_type_node)
  2956.           has_ellipsis = FALSE;
  2957.           }
  2958.         else
  2959.           {
  2960.         /* This function declaration/definition was not prototyped.  */
  2961.  
  2962.         /* Note that all non-prototyped function *declarations* are
  2963.            assumed to represent varargs functions (until proven
  2964.            otherwise).    */
  2965.  
  2966.         if (DECL_INITIAL (decl)) /* if this is a func definition */
  2967.           {
  2968.             if (!arg_decls)
  2969.               has_ellipsis = FALSE; /* no args == (void) */
  2970.             else
  2971.               {
  2972.             /* For a non-prototyped function definition which
  2973.                declares one or more formal parameters, if the name
  2974.                of the first formal parameter is *not*
  2975.                __builtin_va_alist then we must assume that this
  2976.                is *not* a varargs function.     */
  2977.  
  2978.             if (DECL_NAME (arg_decls)
  2979.               && strcmp (IDENTIFIER_POINTER (DECL_NAME (arg_decls)),
  2980.                      "__builtin_va_alist"))
  2981.               has_ellipsis = FALSE;
  2982.               }
  2983.           }
  2984.           }
  2985.  
  2986.         if (has_ellipsis)
  2987.           output_die (output_unspecified_parameters_die, (void*) TRUE);
  2988.       }
  2989.     }
  2990.  
  2991.       /* Output DWARF info for all of the stuff within the body of the
  2992.      function (if it has one - it may be just a declaration).
  2993.  
  2994.      Note that some implementations of DWARF may not really recognize
  2995.      the fact that the outermost block of a function definition is
  2996.      itself a lexical block (with all of the rights & privledges which
  2997.      apply thereto).  At this point, these other (broken?) DWARF
  2998.      implementations would just go ahead and output a sequence of DIEs
  2999.      to represent the things declared directly within the outermost
  3000.      lexical block of the function definition without first generating
  3001.      a lexical block DIE.
  3002.  
  3003.      We don't do that here though.    Rather we create a lexical_block
  3004.      DIE which will `own' all of the things declared within it.
  3005.       */
  3006.  
  3007.       {
  3008.     register tree outer_let = DECL_INITIAL (decl);
  3009.  
  3010.     if (outer_let)    /* if this is a function definition */
  3011.       {
  3012.         /* Note that here, `outer_let' is a pointer to the outermost
  3013.            BLOCK node created to represent the body of a function.
  3014.            This outermost BLOCK actually represents the outermost
  3015.            binding contour for the function, i.e. the contour in which
  3016.            the function's formal parameters get declared.  Just within
  3017.            this contour, there will be another (nested) BLOCK which
  3018.            represents the function's outermost block.  Whenever the
  3019.            symbol DWARF_DEBUGGING_INFO is defined, this nested BLOCK
  3020.            should be created by the compiler whether or not it would
  3021.            otherwise seem to be needed.  It is useful to have this
  3022.            particular BLOCK exist because it provides us with pointers
  3023.            to the first and last instructions which are actually a part
  3024.            of the body of the function (i.e. *not* a part of the prologue
  3025.            or epilogue code).  */
  3026.  
  3027. #if 0
  3028.         output_symbols_for_block (BLOCK_SUBBLOCKS (outer_let), named_labels);
  3029. #else
  3030.         output_symbols_for_block (BLOCK_SUBBLOCKS (outer_let), 0);
  3031. #endif
  3032.  
  3033.         /* Clear out the named label list in case the next following
  3034.            FUNCTION_DECL is a function declaration but not a function
  3035.            definition.  */
  3036.  
  3037. #if 0
  3038.         named_labels = NULL;
  3039. #endif
  3040.       }
  3041.       }
  3042.  
  3043.       /* Generate a terminator for the list of stuff `owned' by this
  3044.      function.  */
  3045.  
  3046.       end_sibling_chain ();
  3047.  
  3048.       break;
  3049.  
  3050.     case TYPE_DECL:
  3051.       output_dies_for_type (TREE_TYPE (decl));
  3052.       /* Output a DIE for the typedef itself.  */
  3053.       if (DECL_NAME (decl))
  3054.         output_die (output_typedef_die, decl);
  3055.       break;
  3056.  
  3057.     case LABEL_DECL:
  3058.       abort (); /* These are on a separate chain - see named_labels above.  */
  3059.  
  3060.     case FIELD_DECL:
  3061.       /* Field declarations come in chains which are attached to
  3062.      struct & union declarations.  The field declarations are output
  3063.      when their associated struct & union declarations are output.    */
  3064.       fatal ("In output_symbol a parameter was found on the wrong chain");
  3065.       break;
  3066.       
  3067.     case PARM_DECL:
  3068.       /* Parmeter declarations come in chains which are attached to
  3069.      function declarations.     The parameter declarations are output
  3070.      when their associated function declarations are output.  */
  3071.       fatal ("In output_symbol a parameter was found on the wrong chain");
  3072.       break;
  3073.  
  3074.     case VAR_DECL:
  3075. #ifdef DWARF_DESCRIBE_USED_EXTERNS
  3076.       /* Even if we are describing externals, don't describe ones which are
  3077.      never even used.  They may be totally bogus and nonexistant.  */
  3078.       if (TREE_EXTERNAL (decl) && ! TREE_USED (decl))
  3079.     break;
  3080. #else
  3081.       /* Don't mention data objects that are external.    Rather, assume that
  3082.      these data objects will be described in the debugging information
  3083.      for the compilation units in which these function get defined.     */
  3084.       if (TREE_EXTERNAL (decl))
  3085.     break;
  3086. #endif
  3087.  
  3088.       /* If there was an error in the declaration, then there will be
  3089.      no RTL associated with the variable.  In that case, avoid
  3090.      possible segfaults by just ignoring this variable.  */
  3091.  
  3092.       if (DECL_RTL (decl) == 0)
  3093.     break;
  3094.  
  3095. #if 0
  3096.       /* Don't mention a variable at all if it was completely optimized
  3097.      into nothingness.  */
  3098.  
  3099.       if (GET_CODE (DECL_RTL (decl)) == REG
  3100.       && (REGNO (DECL_RTL (decl)) < 0
  3101.           || REGNO (DECL_RTL (decl)) >= FIRST_PSEUDO_REGISTER))
  3102.     break;
  3103. #endif
  3104.  
  3105.       /* Defer DWARF information for top-level initialized variables!
  3106.      These are handled separately by dwarfout_toplevel_data later on.  */
  3107.  
  3108.       if (!local && GET_CODE (DECL_RTL (decl)) == MEM && DECL_INITIAL (decl))
  3109.     break;
  3110.  
  3111.       /* Output any DIEs that are needed to specify the type of this data
  3112.      object.  */
  3113.  
  3114.       output_dies_for_type (TREE_TYPE (decl));
  3115.  
  3116. #ifdef DWARF_DESCRIBE_USED_EXTERNS
  3117.  
  3118.       if (TREE_EXTERNAL (decl) && ! finalizing)
  3119.     {
  3120.       /* Remember this VAR_DECL on the pending_extern_decls list.  We
  3121.          will output a description of it later, at the end of compilation,
  3122.          to the .externs section.  */
  3123.  
  3124.       pending_extern_decls = perm_tree_cons (0, decl, pending_extern_decls);
  3125.  
  3126.       /* Make sure that nested extern declarations are not thrown away
  3127.          until we have had a fair chance to finalize them.  */
  3128.  
  3129.       if (DECL_CONTEXT (decl))
  3130.         preserve_data ();
  3131.  
  3132.       break;
  3133.     }
  3134. #endif
  3135.  
  3136.       /* Output the DIE for the data object itself.  */
  3137.  
  3138.       output_die ((local)
  3139.            ? output_local_variable_die : output_global_variable_die,
  3140.           decl);
  3141.       break;
  3142.  
  3143.     default:
  3144.       abort ();
  3145.     }
  3146. }
  3147.  
  3148.  
  3149. /* Output any necessary DWARF information for things declared at file-scope
  3150.    which have not yet been described with DWARF info.  */
  3151.  
  3152. void
  3153. dwarfout_file_scope_delayed_symbol (decl)
  3154.      register tree decl;
  3155. {
  3156.   switch (TREE_CODE (decl))
  3157.     {
  3158.       case ERROR_MARK:
  3159.     break;
  3160.  
  3161.       case VAR_DECL:
  3162.     if ((DECL_INITIAL (decl) && GET_CODE (DECL_RTL (decl)) == MEM)
  3163. #ifdef DWARF_DESCRIBE_USED_EXTERNS
  3164.         || (TREE_EXTERNAL (decl) && TREE_USED (decl))
  3165. #endif
  3166.     )
  3167.       {
  3168.         fputc ('\n', asm_out_file);
  3169.         ASM_CHANGE_SECTION (asm_out_file, DEBUG_SECTION);
  3170.         output_symbol (decl, FALSE);
  3171.         ASM_PREVIOUS_SECTION (asm_out_file);
  3172.       }
  3173.     break;
  3174.  
  3175. #ifdef DWARF_DESCRIBE_USED_EXTERNS
  3176.       case FUNCTION_DECL:
  3177.     if (TREE_EXTERNAL (decl) && TREE_USED (decl))
  3178.       {
  3179.         fputc ('\n', asm_out_file);
  3180.         ASM_CHANGE_SECTION (asm_out_file, DEBUG_SECTION);
  3181.         output_symbol (decl, FALSE);
  3182.         ASM_PREVIOUS_SECTION (asm_out_file);
  3183.       }
  3184.     break;
  3185. #endif
  3186.  
  3187.       default:
  3188.     break;        /* Ignore others.  */
  3189.     }
  3190. }
  3191.  
  3192. void
  3193. dwarfout_file_scope_symbol (decl)
  3194.      register tree decl;
  3195. {
  3196.   fputc ('\n', asm_out_file);
  3197.   ASM_CHANGE_SECTION (asm_out_file, DEBUG_SECTION);
  3198.   output_symbol (decl, FALSE);
  3199.   ASM_PREVIOUS_SECTION (asm_out_file);
  3200. }
  3201.  
  3202. /* Output a marker (i.e. a label) for the beginning of the generated code
  3203.    for a lexical block.     */
  3204.  
  3205. void
  3206. dwarfout_begin_block (blocknum)
  3207.      register int blocknum;
  3208. {
  3209.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  3210.  
  3211.   text_section ();
  3212.   sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum);
  3213.   ASM_OUTPUT_LABEL (asm_out_file, label);
  3214. }
  3215.  
  3216. /* Output a marker (i.e. a label) for the end of the generated code
  3217.    for a lexical block.     */
  3218.  
  3219. void
  3220. dwarfout_end_block (blocknum)
  3221.      register int blocknum;
  3222. {
  3223.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  3224.  
  3225.   text_section ();
  3226.   sprintf (label, BLOCK_END_LABEL_FMT, blocknum);
  3227.   ASM_OUTPUT_LABEL (asm_out_file, label);
  3228. }
  3229.  
  3230. /* Output a marker (i.e. a label) at a point in the assembly code which
  3231.    corresponds to a given source level label.  */
  3232.  
  3233. void
  3234. dwarfout_label (insn)
  3235.      register rtx insn;
  3236. {
  3237.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  3238.  
  3239.   text_section ();
  3240.   sprintf (label, INSN_LABEL_FMT, TREE_UID (current_function_decl),
  3241.                   INSN_UID (insn));
  3242.   ASM_OUTPUT_LABEL (asm_out_file, label);
  3243. }
  3244.  
  3245. /* Output a marker (i.e. a label) for the absoulute end of the generated code
  3246.    for a function definition.  This gets called *after* the epilogue code
  3247.    has been generated.    */
  3248.  
  3249. void
  3250. dwarfout_end_epilogue ()
  3251. {
  3252.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  3253.  
  3254.   /* Output a label to mark the endpoint of the code generated for this
  3255.      function.    */
  3256.  
  3257.   sprintf (label, FUNC_END_LABEL_FMT, TREE_UID (current_function_decl));
  3258.   ASM_OUTPUT_LABEL (asm_out_file, label);
  3259. }
  3260.  
  3261. #ifdef AT_src_info
  3262. static unsigned
  3263. lookup_filename (func_name)
  3264.      char *func_name;
  3265. {
  3266.   if (filename_table)
  3267.     {
  3268.       register filename_entry_t *search_p;
  3269.       register filename_entry_t *limit_p = &filename_table[valid_ft_entries];
  3270.  
  3271.       for (search_p = filename_table; search_p < limit_p; search_p++)
  3272.         if (!strcmp (func_name, search_p->name))
  3273.       {
  3274.         /* When we get here, we have found the filename that we were
  3275.            looking for in the filename_table.  Now we want to make sure
  3276.            that it gets moved to the zero'th entry in the table (if it
  3277.            is not already there) so that subsequent attempts to find the
  3278.            same filename will find it as quickly as possible.  */
  3279.  
  3280.         if (search_p)
  3281.           {
  3282.             filename_entry_t temp_entry;
  3283.             register filename_entry_t *move_p;
  3284.  
  3285.             temp_entry = *search_p;
  3286.  
  3287.             /* Shift entries up to make room at [0] for the found entry.  */
  3288.  
  3289.             limit_p = &filename_table[0];
  3290.             for (move_p = search_p; move_p > limit_p; move_p--)
  3291.           *move_p = *(move_p-1);
  3292.  
  3293.             /* Install the found entry at [0].  */
  3294.  
  3295.             filename_table[0] = temp_entry;
  3296.           }
  3297.  
  3298.             return filename_table[0].number;
  3299.       }
  3300.     }
  3301.   else
  3302.     {
  3303.       /* When we get here, we have never looked up a filename before.  There
  3304.          is no filename table yet, so we have to create one from scratch.  */
  3305.  
  3306.       total_ft_entries = 64;
  3307.       filename_table
  3308.     = (filename_entry_t *) xmalloc (total_ft_entries
  3309.                     * sizeof (filename_entry_t));
  3310.       valid_ft_entries = 0;
  3311.     }
  3312.  
  3313.   /* We come here whenever we have a new filename which is not registered
  3314.      in the current table.  Here we add it to the table.  */
  3315.  
  3316.   /* Prepare to add a new table entry by making sure there is enough space
  3317.      in the table to do so.  If not, expand the current table by doubling
  3318.      its current size (whatever that is).  */
  3319.  
  3320.   if ((valid_ft_entries + 1) > total_ft_entries)
  3321.     {
  3322.       total_ft_entries <<= 1;
  3323.       filename_table
  3324.     = (filename_entry_t *) xrealloc (filename_table,
  3325.                      (total_ft_entries
  3326.                       * sizeof (filename_entry_t)));
  3327.     }
  3328.  
  3329.   /* Shift all existing table entries up so that we can install the new
  3330.      entry at filename_table[0].  */
  3331.  
  3332.   {
  3333.     register filename_entry_t *move_p;
  3334.     register filename_entry_t *limit_p = &filename_table[0];
  3335.  
  3336.     for (move_p = &filename_table[valid_ft_entries]; move_p > limit_p; move_p--)
  3337.       *move_p = *(move_p-1);
  3338.   }
  3339.  
  3340.   /* Now create the new entry at filename_table[0].  */
  3341.  
  3342.   filename_table[0].name = xstrdup (func_name);
  3343.   return filename_table[0].number = ++valid_ft_entries;
  3344. }
  3345.  
  3346. static void
  3347. generate_srcinfo_entry (line_entry_num, files_entry_num)
  3348.      unsigned line_entry_num;
  3349.      unsigned files_entry_num;
  3350. {
  3351.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  3352.  
  3353.   fputc ('\n', asm_out_file);
  3354.   ASM_CHANGE_SECTION (asm_out_file, SRCINFO_SECTION);
  3355.   sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num);
  3356.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
  3357.   sprintf (label, FILE_ENTRY_LABEL_FMT, files_entry_num);
  3358.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, label);
  3359.   ASM_PREVIOUS_SECTION (asm_out_file);
  3360. }
  3361. #endif
  3362.  
  3363. void
  3364. dwarfout_line (filename, line)
  3365.      register char *filename;
  3366.      register unsigned line;
  3367. {
  3368.   static unsigned last_line_entry_num = 0;
  3369.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  3370.  
  3371. #ifdef AT_src_info
  3372.  
  3373.   static unsigned prev_file_entry_num = 0;
  3374.   unsigned this_file_entry_num = lookup_filename (filename);
  3375.  
  3376. #endif
  3377.  
  3378.   text_section ();
  3379.   sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num);
  3380.   ASM_OUTPUT_LABEL (asm_out_file, label);
  3381.  
  3382.   fputc ('\n', asm_out_file);
  3383.   ASM_CHANGE_SECTION (asm_out_file, LINE_SECTION);
  3384.  
  3385. #ifdef AT_src_info
  3386.   if (this_file_entry_num != prev_file_entry_num)
  3387.     {
  3388.       char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES];
  3389.  
  3390.       sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num);
  3391.       ASM_OUTPUT_LABEL (asm_out_file, line_entry_label);
  3392.     }
  3393. #endif
  3394.  
  3395.   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, line);
  3396.   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
  3397.   ASM_OUTPUT_DWARF_BLOCK4 (asm_out_file, label, TEXT_BEGIN_LABEL);
  3398.   ASM_PREVIOUS_SECTION (asm_out_file);
  3399.  
  3400. #ifdef AT_src_info
  3401.   if (this_file_entry_num != prev_file_entry_num)
  3402.     generate_srcinfo_entry (last_line_entry_num, this_file_entry_num);
  3403.   prev_file_entry_num = this_file_entry_num;
  3404. #endif
  3405.  
  3406. }
  3407.  
  3408. /* Set up for DWARF output at the start of compilation.     */
  3409.  
  3410. void
  3411. dwarfout_init (asm_out_file, main_input_filename)
  3412.      register FILE *asm_out_file;
  3413.      register char *main_input_filename;
  3414. {
  3415. #ifdef AT_src_info
  3416.   unsigned first_file_entry_num;
  3417. #endif
  3418.  
  3419.   /* allocate the initial hunk of the pending_sibling_stack.  */
  3420.   pending_sibling_stack = (unsigned *) xmalloc (PENDING_SIBLING_STACK_INCREMENT
  3421.                         * sizeof (unsigned));
  3422.   pending_sibling_stack_size = PENDING_SIBLING_STACK_INCREMENT;
  3423.   pending_sibling_stack_depth = 1;
  3424.  
  3425.   /* Output a starting label for the .text section.  */
  3426.  
  3427.   fputc ('\n', asm_out_file);
  3428.   text_section ();
  3429.   ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL);
  3430.  
  3431. #ifdef AT_src_info
  3432.  
  3433.   /* Output a starting label for the .srcinfo section.  This label will be
  3434.      referenced by the AT_src_info attribute in the TAG_source_file DIE.  */
  3435.  
  3436.   fputc ('\n', asm_out_file);
  3437.   ASM_CHANGE_SECTION (asm_out_file, SRCINFO_SECTION);
  3438.   ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL);
  3439.   ASM_PREVIOUS_SECTION (asm_out_file);
  3440.  
  3441. #endif
  3442.  
  3443. #ifdef AT_addr_ranges
  3444.  
  3445.   /* Output a starting label for the .data section.  */
  3446.  
  3447.   fputc ('\n', asm_out_file);
  3448.   ASM_CHANGE_SECTION (asm_out_file, DATA_SECTION);
  3449.   ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL);
  3450.   ASM_PREVIOUS_SECTION (asm_out_file);
  3451.  
  3452.   /* Output a starting label for the .bss section.  */
  3453.  
  3454.   fputc ('\n', asm_out_file);
  3455.   ASM_CHANGE_SECTION (asm_out_file, BSS_SECTION);
  3456.   ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL);
  3457.   ASM_PREVIOUS_SECTION (asm_out_file);
  3458.  
  3459.   /* Output a starting label for the .rodata section.  */
  3460.  
  3461.   fputc ('\n', asm_out_file);
  3462.   ASM_CHANGE_SECTION (asm_out_file, RODATA_SECTION);
  3463.   ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL);
  3464.   ASM_PREVIOUS_SECTION (asm_out_file);
  3465.  
  3466. #endif
  3467.  
  3468.   /* Setup first DIE number == 1.  */
  3469.   NEXT_DIE_NUM = next_unused_dienum++;
  3470.  
  3471.   /* Generate the initial DIE for the .debug section.  Note that the
  3472.      (string) value given in the AT_name attribute of the TAG_source_file
  3473.      DIE will (typically) be a relative pathname and that this pathname
  3474.      should be taken as being relative to the directory from which the
  3475.      compiler was invoked when the given (base) source file was compiled.  */
  3476.  
  3477.   fputc ('\n', asm_out_file);
  3478.   ASM_CHANGE_SECTION (asm_out_file, DEBUG_SECTION);
  3479.   output_die (output_source_file_die, main_input_filename);
  3480.   ASM_PREVIOUS_SECTION (asm_out_file);
  3481.  
  3482.   /* Generate the initial (special) entry for the .line section.  */
  3483.  
  3484.   fputc ('\n', asm_out_file);
  3485.   ASM_CHANGE_SECTION (asm_out_file, LINE_SECTION);
  3486.   ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL);
  3487.   ASM_OUTPUT_DWARF_BLOCK4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL);
  3488.   ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL);
  3489.   ASM_PREVIOUS_SECTION (asm_out_file);
  3490.  
  3491.   /* Place a scope marker on the list of pending tagged types.    This will
  3492.      represent the global scope.  */
  3493.  
  3494.   pending_tagged_types = perm_tree_cons (NULL, NULL, pending_tagged_types);
  3495.  
  3496.   fputc ('\n', asm_out_file);
  3497. }
  3498.  
  3499. /* Output stuff that dwarf requires at the end of every file.  */
  3500.  
  3501. void
  3502. dwarfout_finalize ()
  3503. {
  3504.   char label[MAX_ARTIFICIAL_LABEL_BYTES];
  3505.  
  3506.   /* Output DIEs to represent any tagged types which are declared within the
  3507.      current scope but which were never completed within the current scope.  */
  3508.  
  3509.   fputc ('\n', asm_out_file);
  3510.   ASM_CHANGE_SECTION (asm_out_file, DEBUG_SECTION);
  3511.  
  3512.   output_pending_tagged_types ();
  3513.  
  3514.   /* Mark the end of the chain of siblings which represent all file-scope
  3515.      declarations in this compilation unit.  */
  3516.  
  3517.   /* The (null) DIE which represents the terminator for the (sibling linked)
  3518.      list of file-scope items is *special*.  Normally, we would just call
  3519.      end_sibling_chain() at this point in order to output a word with the
  3520.      value `4' and that word would act as the terminator for the list of
  3521.      DIEs describing file-scope items.  Unfortunately, if we were to simply
  3522.      do that, the label that would follow this DIE in the .debug section
  3523.      (i.e. `..D2') would *not* be properly aligned (as it must be on some
  3524.      machines) to a 4 byte boundary.
  3525.  
  3526.      In order to force the label `..D2' to get aligned to a 4 byte boundary,
  3527.      the trick used is to insert extra (otherwise useless) padding bytes
  3528.      into the (null) DIE that we know must preceed the ..D2 label in the
  3529.      .debug section.  The amount of padding required can be anywhere between
  3530.      0 and 3 bytes.  The length word at the start of this DIE (i.e. the one
  3531.      with the padding) would normally contain the value 4, but now it will
  3532.      also have to include the padding bytes, so it will instead have some
  3533.      value in the range 4..7.
  3534.  
  3535.      Fortunately, the rules of DWARF say that any DIE whose length word
  3536.      contains *any* value less than 8 should be treated as a null DIE, so
  3537.      this trick works out nicely.  Clever, eh?  Don't give me any credit
  3538.      (or blame).  I didn't think of this scheme.  I just conformed to it.
  3539.   */
  3540.  
  3541.   output_die (output_padded_null_die, (void *)0);
  3542.   dienum_pop ();
  3543.  
  3544.   sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
  3545.   ASM_OUTPUT_LABEL (asm_out_file, label);    /* should be ..D2 */
  3546.   ASM_PREVIOUS_SECTION (asm_out_file);
  3547.  
  3548. #ifdef DWARF_DESCRIBE_USED_EXTERNS
  3549.  
  3550.   /* Setup first DIE number for the .externs section.  */
  3551.   NEXT_DIE_NUM = next_unused_dienum++;
  3552.  
  3553.   /* Generate the entire .externs section.  */
  3554.  
  3555.   fputc ('\n', asm_out_file);
  3556.   ASM_CHANGE_SECTION (asm_out_file, EXTERNS_SECTION);
  3557.   finalizing = TRUE;
  3558.   output_die (output_source_file_die, main_input_filename);
  3559.  
  3560.   {
  3561.     register tree link;
  3562.  
  3563.     for (link = pending_extern_decls; link; link = TREE_CHAIN (link))
  3564.       output_symbol (TREE_VALUE (link),
  3565.              DECL_CONTEXT (TREE_VALUE (link)) != 0);
  3566.   }
  3567.   end_sibling_chain ();
  3568.   sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM);
  3569.   ASM_OUTPUT_LABEL (asm_out_file, label);
  3570.   ASM_PREVIOUS_SECTION (asm_out_file);
  3571.  
  3572. #endif
  3573.  
  3574.   /* Output a terminator label for the .text section.  */
  3575.  
  3576.   fputc ('\n', asm_out_file);
  3577.   text_section ();
  3578.   ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL);
  3579.  
  3580. #ifdef AT_addr_ranges
  3581.  
  3582.   /* Output a terminating entry for the .data section.  */
  3583.  
  3584.   fputc ('\n', asm_out_file);
  3585.   ASM_CHANGE_SECTION (asm_out_file, DATA_SECTION);
  3586.   ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL);
  3587.   ASM_PREVIOUS_SECTION (asm_out_file);
  3588.  
  3589.   /* Output a terminating entry for the .bss section.  */
  3590.  
  3591.   fputc ('\n', asm_out_file);
  3592.   ASM_CHANGE_SECTION (asm_out_file, BSS_SECTION);
  3593.   ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL);
  3594.   ASM_PREVIOUS_SECTION (asm_out_file);
  3595.  
  3596.   /* Output a terminating entry for the .rodata section.  */
  3597.  
  3598.   fputc ('\n', asm_out_file);
  3599.   ASM_CHANGE_SECTION (asm_out_file, RODATA_SECTION);
  3600.   ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL);
  3601.   ASM_PREVIOUS_SECTION (asm_out_file);
  3602.  
  3603. #endif
  3604.  
  3605.   /* Output a terminating entry for the .line section.  */
  3606.  
  3607.   fputc ('\n', asm_out_file);
  3608.   ASM_CHANGE_SECTION (asm_out_file, LINE_SECTION);
  3609.   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0);
  3610.   ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff);
  3611.   ASM_OUTPUT_DWARF_BLOCK4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL);
  3612.   ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL);
  3613.   ASM_PREVIOUS_SECTION (asm_out_file);
  3614.  
  3615. #ifdef AT_src_info
  3616.  
  3617.   /* Create all of the (string) entries for the .sources section.  */
  3618.  
  3619.   fputc ('\n', asm_out_file);
  3620.   ASM_CHANGE_SECTION (asm_out_file, SOURCES_SECTION);
  3621.  
  3622.   {
  3623.     register filename_entry_t *print_p;
  3624.     register filename_entry_t *limit_p = &filename_table[valid_ft_entries];
  3625.  
  3626.     for (print_p = &filename_table[0]; print_p < limit_p; print_p++)
  3627.       {
  3628.         char label[MAX_ARTIFICIAL_LABEL_BYTES];
  3629.  
  3630.         sprintf (label, FILE_ENTRY_LABEL_FMT, print_p->number);
  3631.         ASM_OUTPUT_LABEL (asm_out_file, label);
  3632.         ASM_OUTPUT_DWARF_STRING (asm_out_file, print_p->name);
  3633.       }
  3634.   }
  3635.  
  3636.   ASM_PREVIOUS_SECTION (asm_out_file);
  3637.  
  3638.   /* Output a terminating entry for the .srcinfo section.  */
  3639.  
  3640.   fputc ('\n', asm_out_file);
  3641.   ASM_CHANGE_SECTION (asm_out_file, SRCINFO_SECTION);
  3642.   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
  3643.   ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1);
  3644.   ASM_PREVIOUS_SECTION (asm_out_file);
  3645.  
  3646. #endif
  3647.  
  3648. }
  3649.  
  3650. #endif /* DWARF_DEBUGGING_INFO */
  3651.