+/* Numeric formatting helper macro. Note that this does not handle
+ hexadecimal. */
+#define NUMBER_FMT_LOOP(P, NUM, BASE) \
+ do \
+ { \
+ int digit = NUM % BASE; \
+ NUM /= BASE; \
+ *--P = digit + '0'; \
+ } \
+ while (NUM > 0)
+
+/* Utility: write a decimal integer NUM to asm_out_file. */
+void
+dbxout_int (int num)
+{
+ char buf[64];
+ char *p = buf + sizeof buf;
+ unsigned int unum;
+
+ if (num == 0)
+ {
+ putc ('0', asm_out_file);
+ return;
+ }
+ if (num < 0)
+ {
+ putc ('-', asm_out_file);
+ unum = -num;
+ }
+ else
+ unum = num;
+
+ NUMBER_FMT_LOOP (p, unum, 10);
+
+ while (p < buf + sizeof buf)
+ {
+ putc (*p, asm_out_file);
+ p++;
+ }
+}
+
+\f
+/* Primitives for emitting simple stabs directives. All other stabs
+ routines should use these functions instead of directly emitting
+ stabs. They are exported because machine-dependent code may need
+ to invoke them, e.g. in a DBX_OUTPUT_* macro whose definition
+ forwards to code in CPU.c. */
+
+/* The following functions should all be called immediately after one
+ of the dbxout_begin_stab* functions (below). They write out
+ various things as the value of a stab. */
+
+/* Write out a literal zero as the value of a stab. */
+void
+dbxout_stab_value_zero (void)
+{
+ fputs ("0\n", asm_out_file);
+}
+
+/* Write out the label LABEL as the value of a stab. */
+void
+dbxout_stab_value_label (const char *label)
+{
+ assemble_name (asm_out_file, label);
+ putc ('\n', asm_out_file);
+}
+
+/* Write out the difference of two labels, LABEL - BASE, as the value
+ of a stab. */
+void
+dbxout_stab_value_label_diff (const char *label, const char *base)
+{
+ assemble_name (asm_out_file, label);
+ putc ('-', asm_out_file);
+ assemble_name (asm_out_file, base);
+ putc ('\n', asm_out_file);
+}
+
+/* Write out an internal label as the value of a stab, and immediately
+ emit that internal label. This should be used only when
+ dbxout_stabd will not work. STEM is the name stem of the label,
+ COUNTERP is a pointer to a counter variable which will be used to
+ guarantee label uniqueness. */
+void
+dbxout_stab_value_internal_label (const char *stem, int *counterp)
+{
+ char label[100];
+ int counter = counterp ? (*counterp)++ : 0;
+
+ ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
+ dbxout_stab_value_label (label);
+ targetm.asm_out.internal_label (asm_out_file, stem, counter);
+}
+
+/* Write out the difference between BASE and an internal label as the
+ value of a stab, and immediately emit that internal label. STEM and
+ COUNTERP are as for dbxout_stab_value_internal_label. */
+void
+dbxout_stab_value_internal_label_diff (const char *stem, int *counterp,
+ const char *base)
+{
+ char label[100];
+ int counter = counterp ? (*counterp)++ : 0;
+
+ ASM_GENERATE_INTERNAL_LABEL (label, stem, counter);
+ dbxout_stab_value_label_diff (label, base);
+ targetm.asm_out.internal_label (asm_out_file, stem, counter);
+}
+
+/* The following functions produce specific kinds of stab directives. */
+
+/* Write a .stabd directive with type STYPE and desc SDESC to asm_out_file. */
+void
+dbxout_stabd (int stype, int sdesc)
+{
+ fputs (ASM_STABD_OP, asm_out_file);
+ dbxout_int (stype);
+ fputs (",0,", asm_out_file);
+ dbxout_int (sdesc);
+ putc ('\n', asm_out_file);
+}
+
+/* Write a .stabn directive with type STYPE. This function stops
+ short of emitting the value field, which is the responsibility of
+ the caller (normally it will be either a symbol or the difference
+ of two symbols). */
+
+void
+dbxout_begin_stabn (int stype)
+{
+ fputs (ASM_STABN_OP, asm_out_file);
+ dbxout_int (stype);
+ fputs (",0,0,", asm_out_file);
+}
+
+/* Write a .stabn directive with type N_SLINE and desc LINE. As above,
+ the value field is the responsibility of the caller. */
+void
+dbxout_begin_stabn_sline (int lineno)
+{
+ fputs (ASM_STABN_OP, asm_out_file);
+ dbxout_int (N_SLINE);
+ fputs (",0,", asm_out_file);
+ dbxout_int (lineno);
+ putc (',', asm_out_file);
+}
+
+/* Begin a .stabs directive with string "", type STYPE, and desc and
+ other fields 0. The value field is the responsibility of the
+ caller. This function cannot be used for .stabx directives. */
+void
+dbxout_begin_empty_stabs (int stype)
+{
+ fputs (ASM_STABS_OP, asm_out_file);
+ fputs ("\"\",", asm_out_file);
+ dbxout_int (stype);
+ fputs (",0,0,", asm_out_file);
+}
+
+/* Begin a .stabs directive with string STR, type STYPE, and desc 0.
+ The value field is the responsibility of the caller. */
+void
+dbxout_begin_simple_stabs (const char *str, int stype)
+{
+ fputs (ASM_STABS_OP, asm_out_file);
+ output_quoted_string (asm_out_file, str);
+ putc (',', asm_out_file);
+ dbxout_int (stype);
+ fputs (",0,0,", asm_out_file);
+}
+
+/* As above but use SDESC for the desc field. */
+void
+dbxout_begin_simple_stabs_desc (const char *str, int stype, int sdesc)
+{
+ fputs (ASM_STABS_OP, asm_out_file);
+ output_quoted_string (asm_out_file, str);
+ putc (',', asm_out_file);
+ dbxout_int (stype);
+ fputs (",0,", asm_out_file);
+ dbxout_int (sdesc);
+ putc (',', asm_out_file);
+}
+
+/* The next set of functions are entirely concerned with production of
+ "complex" .stabs directives: that is, .stabs directives whose
+ strings have to be constructed piecemeal. dbxout_type,
+ dbxout_symbol, etc. use these routines heavily. The string is queued
+ up in an obstack, then written out by dbxout_finish_complex_stabs, which
+ is also responsible for splitting it up if it exceeds DBX_CONTIN_LENGTH.
+ (You might think it would be more efficient to go straight to stdio
+ when DBX_CONTIN_LENGTH is 0 (i.e. no length limit) but that turns
+ out not to be the case, and anyway this needs fewer #ifdefs.) */
+
+/* Begin a complex .stabs directive. If we can, write the initial
+ ASM_STABS_OP to the asm_out_file. */
+
+static void
+dbxout_begin_complex_stabs (void)
+{
+ emit_pending_bincls_if_required ();
+ FORCE_TEXT;
+ fputs (ASM_STABS_OP, asm_out_file);
+ putc ('"', asm_out_file);
+ gcc_assert (stabstr_last_contin_point == 0);
+}
+
+/* As above, but do not force text or emit pending bincls. This is
+ used by dbxout_symbol_location, which needs to do something else. */
+static void
+dbxout_begin_complex_stabs_noforcetext (void)
+{
+ fputs (ASM_STABS_OP, asm_out_file);
+ putc ('"', asm_out_file);
+ gcc_assert (stabstr_last_contin_point == 0);
+}
+
+/* Add CHR, a single character, to the string being built. */
+#define stabstr_C(chr) obstack_1grow (&stabstr_ob, chr)
+
+/* Add STR, a normal C string, to the string being built. */
+#define stabstr_S(str) obstack_grow (&stabstr_ob, str, strlen(str))
+
+/* Add the text of ID, an IDENTIFIER_NODE, to the string being built. */
+#define stabstr_I(id) obstack_grow (&stabstr_ob, \
+ IDENTIFIER_POINTER (id), \
+ IDENTIFIER_LENGTH (id))
+
+/* Add NUM, a signed decimal number, to the string being built. */
+static void
+stabstr_D (HOST_WIDE_INT num)
+{
+ char buf[64];
+ char *p = buf + sizeof buf;
+ unsigned int unum;
+
+ if (num == 0)
+ {
+ stabstr_C ('0');
+ return;
+ }
+ if (num < 0)
+ {
+ stabstr_C ('-');
+ unum = -num;
+ }
+ else
+ unum = num;
+
+ NUMBER_FMT_LOOP (p, unum, 10);
+
+ obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
+}
+
+/* Add NUM, an unsigned decimal number, to the string being built. */
+static void
+stabstr_U (unsigned HOST_WIDE_INT num)
+{
+ char buf[64];
+ char *p = buf + sizeof buf;
+ if (num == 0)
+ {
+ stabstr_C ('0');
+ return;
+ }
+ NUMBER_FMT_LOOP (p, num, 10);
+ obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
+}
+
+/* Add CST, an INTEGER_CST tree, to the string being built as an
+ unsigned octal number. This routine handles values which are
+ larger than a single HOST_WIDE_INT. */
+static void
+stabstr_O (tree cst)
+{
+ unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (cst);
+ unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (cst);
+
+ char buf[128];
+ char *p = buf + sizeof buf;
+
+ /* GDB wants constants with no extra leading "1" bits, so
+ we need to remove any sign-extension that might be
+ present. */
+ {
+ const unsigned int width = TYPE_PRECISION (TREE_TYPE (cst));
+ if (width == HOST_BITS_PER_WIDE_INT * 2)
+ ;
+ else if (width > HOST_BITS_PER_WIDE_INT)
+ high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
+ else if (width == HOST_BITS_PER_WIDE_INT)
+ high = 0;
+ else
+ high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
+ }
+
+ /* Leading zero for base indicator. */
+ stabstr_C ('0');
+
+ /* If the value is zero, the base indicator will serve as the value
+ all by itself. */
+ if (high == 0 && low == 0)
+ return;
+
+ /* If the high half is zero, we need only print the low half normally. */
+ if (high == 0)
+ NUMBER_FMT_LOOP (p, low, 8);
+ else
+ {
+ /* When high != 0, we need to print enough zeroes from low to
+ give the digits from high their proper place-values. Hence
+ NUMBER_FMT_LOOP cannot be used. */
+ const int n_digits = HOST_BITS_PER_WIDE_INT / 3;
+ int i;
+
+ for (i = 1; i <= n_digits; i++)
+ {
+ unsigned int digit = low % 8;
+ low /= 8;
+ *--p = '0' + digit;
+ }
+
+ /* Octal digits carry exactly three bits of information. The
+ width of a HOST_WIDE_INT is not normally a multiple of three.
+ Therefore, the next digit printed probably needs to carry
+ information from both low and high. */
+ if (HOST_BITS_PER_WIDE_INT % 3 != 0)
+ {
+ const int n_leftover_bits = HOST_BITS_PER_WIDE_INT % 3;
+ const int n_bits_from_high = 3 - n_leftover_bits;
+
+ const unsigned HOST_WIDE_INT
+ low_mask = (((unsigned HOST_WIDE_INT)1) << n_leftover_bits) - 1;
+ const unsigned HOST_WIDE_INT
+ high_mask = (((unsigned HOST_WIDE_INT)1) << n_bits_from_high) - 1;
+
+ unsigned int digit;
+
+ /* At this point, only the bottom n_leftover_bits bits of low
+ should be set. */
+ gcc_assert (!(low & ~low_mask));
+
+ digit = (low | ((high & high_mask) << n_leftover_bits));
+ high >>= n_bits_from_high;
+
+ *--p = '0' + digit;
+ }
+
+ /* Now we can format high in the normal manner. However, if
+ the only bits of high that were set were handled by the
+ digit split between low and high, high will now be zero, and
+ we don't want to print extra digits in that case. */
+ if (high)
+ NUMBER_FMT_LOOP (p, high, 8);
+ }
+
+ obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p);
+}
+
+/* Called whenever it is safe to break a stabs string into multiple
+ .stabs directives. If the current string has exceeded the limit
+ set by DBX_CONTIN_LENGTH, mark the current position in the buffer
+ as a continuation point by inserting DBX_CONTIN_CHAR (doubled if
+ it is a backslash) and a null character. */
+static inline void
+stabstr_continue (void)
+{
+ if (DBX_CONTIN_LENGTH > 0
+ && obstack_object_size (&stabstr_ob) - stabstr_last_contin_point
+ > DBX_CONTIN_LENGTH)
+ {
+ if (DBX_CONTIN_CHAR == '\\')
+ obstack_1grow (&stabstr_ob, '\\');
+ obstack_1grow (&stabstr_ob, DBX_CONTIN_CHAR);
+ obstack_1grow (&stabstr_ob, '\0');
+ stabstr_last_contin_point = obstack_object_size (&stabstr_ob);
+ }
+}
+#define CONTIN stabstr_continue ()
+
+/* Macro subroutine of dbxout_finish_complex_stabs, which emits
+ all of the arguments to the .stabs directive after the string.
+ Overridden by xcoffout.h. CODE is the stabs code for this symbol;
+ LINE is the source line to write into the desc field (in extended
+ mode); SYM is the symbol itself.
+
+ ADDR, LABEL, and NUMBER are three different ways to represent the
+ stabs value field. At most one of these should be nonzero.
+
+ ADDR is used most of the time; it represents the value as an
+ RTL address constant.
+
+ LABEL is used (currently) only for N_CATCH stabs; it represents
+ the value as a string suitable for assemble_name.
+
+ NUMBER is used when the value is an offset from an implicit base
+ pointer (e.g. for a stack variable), or an index (e.g. for a
+ register variable). It represents the value as a decimal integer. */
+
+#ifndef DBX_FINISH_STABS
+#define DBX_FINISH_STABS(SYM, CODE, LINE, ADDR, LABEL, NUMBER) \
+do { \
+ int line_ = use_gnu_debug_info_extensions ? LINE : 0; \
+ \
+ dbxout_int (CODE); \
+ fputs (",0,", asm_out_file); \
+ dbxout_int (line_); \
+ putc (',', asm_out_file); \
+ if (ADDR) \
+ output_addr_const (asm_out_file, ADDR); \
+ else if (LABEL) \
+ assemble_name (asm_out_file, LABEL); \
+ else \
+ dbxout_int (NUMBER); \
+ putc ('\n', asm_out_file); \
+} while (0)
+#endif
+
+/* Finish the emission of a complex .stabs directive. When DBX_CONTIN_LENGTH
+ is zero, this has only to emit the close quote and the remainder of
+ the arguments. When it is nonzero, the string has been marshalled in
+ stabstr_ob, and this routine is responsible for breaking it up into
+ DBX_CONTIN_LENGTH-sized chunks.
+
+ SYM is the DECL of the symbol under consideration; it is used only
+ for its DECL_SOURCE_LINE. The other arguments are all passed directly
+ to DBX_FINISH_STABS; see above for details. */
+
+static void
+dbxout_finish_complex_stabs (tree sym, STAB_CODE_TYPE code,
+ rtx addr, const char *label, int number)
+{
+ int line ATTRIBUTE_UNUSED;
+ char *str;
+ size_t len;
+
+ line = sym ? DECL_SOURCE_LINE (sym) : 0;
+ if (DBX_CONTIN_LENGTH > 0)
+ {
+ char *chunk;
+ size_t chunklen;
+
+ /* Nul-terminate the growing string, then get its size and
+ address. */
+ obstack_1grow (&stabstr_ob, '\0');
+
+ len = obstack_object_size (&stabstr_ob);
+ chunk = str = XOBFINISH (&stabstr_ob, char *);
+
+ /* Within the buffer are a sequence of NUL-separated strings,
+ each of which is to be written out as a separate stab
+ directive. */
+ for (;;)
+ {
+ chunklen = strlen (chunk);
+ fwrite (chunk, 1, chunklen, asm_out_file);
+ fputs ("\",", asm_out_file);
+
+ /* Must add an extra byte to account for the NUL separator. */
+ chunk += chunklen + 1;
+ len -= chunklen + 1;
+
+ /* Only put a line number on the last stab in the sequence. */
+ DBX_FINISH_STABS (sym, code, len == 0 ? line : 0,
+ addr, label, number);
+ if (len == 0)
+ break;
+
+ fputs (ASM_STABS_OP, asm_out_file);
+ putc ('"', asm_out_file);
+ }
+ stabstr_last_contin_point = 0;
+ }
+ else
+ {
+ /* No continuations - we can put the whole string out at once.
+ It is faster to augment the string with the close quote and
+ comma than to do a two-character fputs. */
+ obstack_grow (&stabstr_ob, "\",", 2);
+ len = obstack_object_size (&stabstr_ob);
+ str = XOBFINISH (&stabstr_ob, char *);
+
+ fwrite (str, 1, len, asm_out_file);
+ DBX_FINISH_STABS (sym, code, line, addr, label, number);
+ }
+ obstack_free (&stabstr_ob, str);
+}
+