1 /* listing.c - maintain assembly listings
2 Copyright (C) 1991-2016 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 /* Contributed by Steve Chamberlain <sac@cygnus.com>
23 A listing page looks like:
25 LISTING_HEADER sourcefilename pagenumber
28 linenumber address data source
29 linenumber address data source
30 linenumber address data source
31 linenumber address data source
33 If not overridden, the listing commands are:
36 Put "stuff" onto the title line
38 Put stuff onto the subtitle line
40 If these commands come within 10 lines of the top of the page, they
41 will affect the page they are on, as well as any subsequent page
46 Increment the enable listing counter
48 Decrement the enable listing counter
51 Set the paper size to X wide and Y high. Setting a psize Y of
52 zero will suppress form feeds except where demanded by .eject
54 If the counter goes below zero, listing is suppressed.
56 Listings are a maintained by read calling various listing_<foo>
57 functions. What happens most is that the macro NO_LISTING is not
58 defined (from the Makefile), then the macro LISTING_NEWLINE expands
59 into a call to listing_newline. The call is done from read.c, every
60 time it sees a newline, and -l is on the command line.
62 The function listing_newline remembers the frag associated with the
63 newline, and creates a new frag - note that this is wasteful, but not
64 a big deal, since listing slows things down a lot anyway. The
65 function also remembers when the filename changes.
67 When all the input has finished, and gas has had a chance to settle
68 down, the listing is output. This is done by running down the list of
69 frag/source file records, and opening the files as needed and printing
70 out the bytes and chars associated with them.
72 The only things which the architecture can change about the listing
73 are defined in these macros:
75 LISTING_HEADER The name of the architecture
76 LISTING_WORD_SIZE The make of the number of bytes in a word, this determines
77 the clumping of the output data. eg a value of
78 2 makes words look like 1234 5678, whilst 1
79 would make the same value look like 12 34 56
81 LISTING_LHS_WIDTH Number of words of above size for the lhs
83 LISTING_LHS_WIDTH_SECOND Number of words for the data on the lhs
86 LISTING_LHS_CONT_LINES Max number of lines to use up for a continuation
87 LISTING_RHS_WIDTH Number of chars from the input file to print
91 #include "filenames.h"
92 #include "safe-ctype.h"
93 #include "input-file.h"
101 #ifndef LISTING_HEADER
102 #define LISTING_HEADER "GAS LISTING"
104 #ifndef LISTING_WORD_SIZE
105 #define LISTING_WORD_SIZE 4
107 #ifndef LISTING_LHS_WIDTH
108 #define LISTING_LHS_WIDTH ((LISTING_WORD_SIZE) > 4 ? 1 : 4 / (LISTING_WORD_SIZE))
110 #ifndef LISTING_LHS_WIDTH_SECOND
111 #define LISTING_LHS_WIDTH_SECOND LISTING_LHS_WIDTH
113 #ifndef LISTING_RHS_WIDTH
114 #define LISTING_RHS_WIDTH 100
116 #ifndef LISTING_LHS_CONT_LINES
117 #define LISTING_LHS_CONT_LINES 4
119 #define MAX_DATELEN 30
121 /* This structure remembers which .s were used. */
122 typedef struct file_info_struct
124 struct file_info_struct * next;
127 unsigned int linenum;
146 struct list_message *next;
149 /* This structure remembers which line from which file goes into which
151 struct list_info_struct
153 /* Frag which this line of source is nearest to. */
156 /* The actual line in the source file. */
159 /* Pointer to the file info struct for the file which this line
161 file_info_type *file;
163 /* The expanded text of any macro that may have been executing. */
167 struct list_info_struct *next;
169 /* Pointer to the file info struct for the high level language
170 source line that belongs here. */
171 file_info_type *hll_file;
173 /* High level language source line. */
174 unsigned int hll_line;
176 /* Pointers to linked list of messages associated with this line. */
177 struct list_message *messages, *last_message;
179 enum edict_enum edict;
182 /* Nonzero if this line is to be omitted because it contains
183 debugging information. This can become a flags field if we come
184 up with more information to store here. */
188 typedef struct list_info_struct list_info_type;
190 int listing_lhs_width = LISTING_LHS_WIDTH;
191 int listing_lhs_width_second = LISTING_LHS_WIDTH_SECOND;
192 int listing_lhs_cont_lines = LISTING_LHS_CONT_LINES;
193 int listing_rhs_width = LISTING_RHS_WIDTH;
195 struct list_info_struct * listing_tail;
197 static file_info_type * file_info_head;
198 static file_info_type * last_open_file_info;
199 static FILE * last_open_file;
200 static struct list_info_struct * head;
201 static int paper_width = 200;
202 static int paper_height = 60;
206 /* File to output listings to. */
207 static FILE *list_file;
209 /* This static array is used to keep the text of data to be printed
210 before the start of the line. */
213 (((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width \
214 + ((((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width_second) \
215 * listing_lhs_cont_lines) \
218 static char *data_buffer;
221 static void listing_message (const char *, const char *);
222 static file_info_type *file_info (const char *);
223 static void new_frag (void);
224 static void listing_page (list_info_type *);
225 static unsigned int calc_hex (list_info_type *);
226 static void print_lines (list_info_type *, unsigned int, const char *,
228 static void list_symbol_table (void);
229 static int debugging_pseudo (list_info_type *, const char *);
230 static void listing_listing (char *);
233 listing_message (const char *name, const char *message)
235 if (listing_tail != (list_info_type *) NULL)
237 char *n = concat (name, message, (char *) NULL);
238 struct list_message *lm = XNEW (struct list_message);
242 if (listing_tail->last_message)
243 listing_tail->last_message->next = lm;
245 listing_tail->messages = lm;
246 listing_tail->last_message = lm;
251 listing_warning (const char *message)
253 listing_message (_("Warning: "), message);
257 listing_error (const char *message)
259 listing_message (_("Error: "), message);
262 static file_info_type *
263 file_info (const char *file_name)
265 /* Find an entry with this file name. */
266 file_info_type *p = file_info_head;
268 while (p != (file_info_type *) NULL)
270 if (filename_cmp (p->filename, file_name) == 0)
275 /* Make new entry. */
276 p = XNEW (file_info_type);
277 p->next = file_info_head;
279 p->filename = xstrdup (file_name);
290 frag_wane (frag_now);
295 listing_newline (char *ps)
299 static unsigned int last_line = 0xffff;
300 static const char *last_file = NULL;
301 list_info_type *new_i = NULL;
306 if (now_seg == absolute_section)
310 /* In ELF, anything in a section beginning with .debug or .line is
311 considered to be debugging information. This includes the
312 statement which switches us into the debugging section, which we
313 can only set after we are already in the debugging section. */
314 if ((listing & LISTING_NODEBUG) != 0
315 && listing_tail != NULL
316 && ! listing_tail->debugging)
320 segname = segment_name (now_seg);
321 if (strncmp (segname, ".debug", sizeof ".debug" - 1) == 0
322 || strncmp (segname, ".line", sizeof ".line" - 1) == 0)
323 listing_tail->debugging = 1;
327 file = as_where (&line);
330 if (line == last_line
331 && !(last_file && file && filename_cmp (file, last_file)))
334 new_i = XNEW (list_info_type);
336 /* Detect if we are reading from stdin by examining the file
337 name returned by as_where().
339 [FIXME: We rely upon the name in the strcmp below being the
340 same as the one used by input_scrub_new_file(), if that is
341 not true, then this code will fail].
343 If we are reading from stdin, then we need to save each input
344 line here (assuming of course that we actually have a line of
345 input to read), so that it can be displayed in the listing
346 that is produced at the end of the assembly. */
347 if (strcmp (file, _("{standard input}")) == 0
348 && input_line_pointer != NULL)
350 char *copy, *src, *dest;
355 for (copy = input_line_pointer;
357 || is_end_of_line [(unsigned char) *copy] != 1);
362 else if (*copy == '\\')
364 else if (*copy == '"')
365 seen_quote = !seen_quote;
368 len = copy - input_line_pointer + 1;
370 copy = XNEWVEC (char, len);
372 src = input_line_pointer;
377 unsigned char c = *src++;
379 /* Omit control characters in the listing. */
386 new_i->line_contents = copy;
389 new_i->line_contents = NULL;
393 new_i = XNEW (list_info_type);
394 new_i->line_contents = ps;
403 listing_tail->next = new_i;
407 listing_tail = new_i;
409 new_i->frag = frag_now;
411 new_i->file = file_info (file);
412 new_i->next = (list_info_type *) NULL;
413 new_i->messages = NULL;
414 new_i->last_message = NULL;
415 new_i->edict = EDICT_NONE;
416 new_i->hll_file = (file_info_type *) NULL;
418 new_i->debugging = 0;
423 /* In ELF, anything in a section beginning with .debug or .line is
424 considered to be debugging information. */
425 if ((listing & LISTING_NODEBUG) != 0)
429 segname = segment_name (now_seg);
430 if (strncmp (segname, ".debug", sizeof ".debug" - 1) == 0
431 || strncmp (segname, ".line", sizeof ".line" - 1) == 0)
432 new_i->debugging = 1;
437 /* Attach all current frags to the previous line instead of the
438 current line. This is called by the MIPS backend when it discovers
439 that it needs to add some NOP instructions; the added NOP
440 instructions should go with the instruction that has the delay, not
441 with the new instruction. */
444 listing_prev_line (void)
449 if (head == (list_info_type *) NULL
450 || head == listing_tail)
455 for (l = head; l->next != listing_tail; l = l->next)
458 for (f = frchain_now->frch_root; f != (fragS *) NULL; f = f->fr_next)
459 if (f->line == listing_tail)
462 listing_tail->frag = frag_now;
466 /* This function returns the next source line from the file supplied,
467 truncated to size. It appends a fake line to the end of each input
468 file to make using the returned buffer simpler. */
471 buffer_line (file_info_type *file, char *line, unsigned int size)
473 unsigned int count = 0;
477 /* If we couldn't open the file, return an empty line. */
481 /* Check the cache and see if we last used this file. */
482 if (!last_open_file_info || file != last_open_file_info)
486 last_open_file_info->pos = ftell (last_open_file);
487 fclose (last_open_file);
490 /* Open the file in the binary mode so that ftell above can
491 return a reliable value that we can feed to fseek below. */
492 last_open_file_info = file;
493 last_open_file = fopen (file->filename, FOPEN_RB);
494 if (last_open_file == NULL)
500 /* Seek to where we were last time this file was open. */
502 fseek (last_open_file, file->pos, SEEK_SET);
505 /* Leave room for null. */
508 c = fgetc (last_open_file);
510 while (c != EOF && c != '\n' && c != '\r')
516 c = fgetc (last_open_file);
519 /* If '\r' is followed by '\n', swallow that. Likewise, if '\n'
520 is followed by '\r', swallow that as well. */
521 if (c == '\r' || c == '\n')
523 int next = fgetc (last_open_file);
525 if ((c == '\r' && next != '\n')
526 || (c == '\n' && next != '\r'))
527 ungetc (next, last_open_file);
533 if (count + 2 < size)
546 /* This function rewinds the requested file back to the line requested,
547 reads it in again into the buffer provided and then restores the file
548 back to its original location. */
551 rebuffer_line (file_info_type * file,
552 unsigned int linenum,
556 unsigned int count = 0;
557 unsigned int current_line;
562 bfd_boolean found = FALSE;
565 if (file == NULL || buffer == NULL || size <= 1 || file->linenum <= linenum)
568 /* Check the cache and see if we last used this file. */
569 if (last_open_file_info == NULL || file != last_open_file_info)
573 last_open_file_info->pos = ftell (last_open_file);
574 fclose (last_open_file);
577 /* Open the file in the binary mode so that ftell above can
578 return a reliable value that we can feed to fseek below. */
579 last_open_file_info = file;
580 last_open_file = fopen (file->filename, FOPEN_RB);
581 if (last_open_file == NULL)
587 /* Seek to where we were last time this file was open. */
589 fseek (last_open_file, file->pos, SEEK_SET);
592 /* Remember where we are in the current file. */
593 pos2 = pos = ftell (last_open_file);
596 current_line = file->linenum;
598 /* Leave room for the nul at the end of the buffer. */
602 /* Increment the current line count by one.
603 This is to allow for the fact that we are searching for the
604 start of a previous line, but we do this by detecting end-of-line
605 character(s) not start-of-line characters. */
608 while (pos2 > 0 && ! found)
612 /* Move backwards through the file, looking for earlier lines. */
613 pos2 = (long) size > pos2 ? 0 : pos2 - size;
614 fseek (last_open_file, pos2, SEEK_SET);
616 /* Our caller has kindly provided us with a buffer, so we use it. */
617 if (fread (buffer, 1, size, last_open_file) != size)
619 as_warn (_("unable to rebuffer file: %s\n"), file->filename);
623 for (ptr = buffer + size; ptr >= buffer; -- ptr)
629 if (current_line == linenum)
631 /* We have found the start of the line we seek. */
634 /* FIXME: We could skip the read-in-the-line code
635 below if we know that we already have the whole
636 line in the buffer. */
638 /* Advance pos2 to the newline character we have just located. */
639 pos2 += (ptr - buffer);
641 /* Skip the newline and, if present, the carriage return. */
642 if (ptr + 1 == buffer + size)
645 if (fgetc (last_open_file) == '\r')
649 pos2 += (ptr[1] == '\r' ? 2 : 1);
651 /* Move the file pointer to this location. */
652 fseek (last_open_file, pos2, SEEK_SET);
659 /* Read in the line. */
660 c = fgetc (last_open_file);
662 while (c != EOF && c != '\n' && c != '\r')
668 c = fgetc (last_open_file);
671 /* If '\r' is followed by '\n', swallow that. Likewise, if '\n'
672 is followed by '\r', swallow that as well. */
673 if (c == '\r' || c == '\n')
675 int next = fgetc (last_open_file);
677 if ((c == '\r' && next != '\n')
678 || (c == '\n' && next != '\r'))
679 ungetc (next, last_open_file);
682 /* Terminate the line. */
685 /* Reset the file position. */
686 fseek (last_open_file, pos, SEEK_SET);
689 static const char *fn;
690 static unsigned int eject; /* Eject pending. */
691 static unsigned int page; /* Current page number. */
692 static const char *title; /* Current title. */
693 static const char *subtitle; /* Current subtitle. */
694 static unsigned int on_page; /* Number of lines printed on current page. */
697 listing_page (list_info_type *list)
699 /* Grope around, see if we can see a title or subtitle edict coming up
700 soon. (we look down 10 lines of the page and see if it's there) */
701 if ((eject || (on_page >= (unsigned int) paper_height))
702 && paper_height != 0)
706 int had_subtitle = 0;
710 while (c != 0 && list)
712 if (list->edict == EDICT_SBTTL && !had_subtitle)
715 subtitle = list->edict_arg;
717 if (list->edict == EDICT_TITLE && !had_title)
720 title = list->edict_arg;
728 fprintf (list_file, "\f");
731 fprintf (list_file, "%s %s \t\t\tpage %d\n", LISTING_HEADER, fn, page);
732 fprintf (list_file, "%s\n", title);
733 fprintf (list_file, "%s\n", subtitle);
739 /* Print a line into the list_file. Update the line count
740 and if necessary start a new page. */
743 emit_line (list_info_type * list, const char * format, ...)
747 va_start (args, format);
749 vfprintf (list_file, format, args);
757 calc_hex (list_info_type *list)
759 int data_buffer_size;
760 list_info_type *first = list;
761 unsigned int address = ~(unsigned int) 0;
764 unsigned int octet_in_frag;
766 /* Find first frag which says it belongs to this line. */
768 while (frag && frag->line != list)
769 frag = frag->fr_next;
773 data_buffer_size = 0;
775 /* Dump all the frags which belong to this line. */
776 while (frag_ptr != (fragS *) NULL && frag_ptr->line == first)
778 /* Print as many bytes from the fixed part as is sensible. */
780 while ((offsetT) octet_in_frag < frag_ptr->fr_fix
781 && data_buffer_size < MAX_BYTES - 3)
783 if (address == ~(unsigned int) 0)
784 address = frag_ptr->fr_address / OCTETS_PER_BYTE;
786 sprintf (data_buffer + data_buffer_size,
788 (frag_ptr->fr_literal[octet_in_frag]) & 0xff);
789 data_buffer_size += 2;
792 if (frag_ptr->fr_type == rs_fill)
794 unsigned int var_rep_max = octet_in_frag;
795 unsigned int var_rep_idx = octet_in_frag;
797 /* Print as many bytes from the variable part as is sensible. */
798 while (((offsetT) octet_in_frag
799 < (frag_ptr->fr_fix + frag_ptr->fr_var * frag_ptr->fr_offset))
800 && data_buffer_size < MAX_BYTES - 3)
802 if (address == ~(unsigned int) 0)
803 address = frag_ptr->fr_address / OCTETS_PER_BYTE;
805 sprintf (data_buffer + data_buffer_size,
807 (frag_ptr->fr_literal[var_rep_idx]) & 0xff);
808 data_buffer_size += 2;
813 if ((offsetT) var_rep_idx >= frag_ptr->fr_fix + frag_ptr->fr_var)
814 var_rep_idx = var_rep_max;
818 frag_ptr = frag_ptr->fr_next;
820 data_buffer[data_buffer_size] = '\0';
825 print_lines (list_info_type *list, unsigned int lineno,
826 const char *string, unsigned int address)
831 unsigned int octet_in_word = 0;
832 char *src = data_buffer;
834 struct list_message *msg;
836 /* Print the stuff on the first line. */
838 nchars = (LISTING_WORD_SIZE * 2 + 1) * listing_lhs_width;
840 /* Print the hex for the first line. */
841 if (address == ~(unsigned int) 0)
843 fprintf (list_file, "% 4d ", lineno);
844 for (idx = 0; idx < nchars; idx++)
845 fprintf (list_file, " ");
847 emit_line (NULL, "\t%s\n", string ? string : "");
852 fprintf (list_file, "% 4d ???? ", lineno);
854 fprintf (list_file, "% 4d %04x ", lineno, address);
856 /* And the data to go along with it. */
859 while (src[cur] && idx < nchars)
863 fprintf (list_file, "%c%c", src[offset], src[offset + 1]);
867 if (octet_in_word == LISTING_WORD_SIZE)
869 fprintf (list_file, " ");
877 for (; idx < nchars; idx++)
878 fprintf (list_file, " ");
880 emit_line (list, "\t%s\n", string ? string : "");
882 for (msg = list->messages; msg; msg = msg->next)
883 emit_line (list, "**** %s\n", msg->message);
886 lines < (unsigned int) listing_lhs_cont_lines
890 nchars = ((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width_second - 1;
893 /* Print any more lines of data, but more compactly. */
894 fprintf (list_file, "% 4d ", lineno);
896 while (src[cur] && idx < nchars)
900 fprintf (list_file, "%c%c", src[offset], src[offset + 1]);
905 if (octet_in_word == LISTING_WORD_SIZE)
907 fprintf (list_file, " ");
913 emit_line (list, "\n");
918 list_symbol_table (void)
920 extern symbolS *symbol_rootP;
927 for (ptr = symbol_rootP; ptr != (symbolS *) NULL; ptr = symbol_next (ptr))
929 if (SEG_NORMAL (S_GET_SEGMENT (ptr))
930 || S_GET_SEGMENT (ptr) == absolute_section)
932 /* Don't report section symbols. They are not interesting. */
933 if (symbol_section_p (ptr))
936 if (S_GET_NAME (ptr))
938 char buf[30], fmt[8];
939 valueT val = S_GET_VALUE (ptr);
941 /* @@ Note that this is dependent on the compilation options,
942 not solely on the target characteristics. */
943 if (sizeof (val) == 4 && sizeof (int) == 4)
944 sprintf (buf, "%08lx", (unsigned long) val);
945 else if (sizeof (val) <= sizeof (unsigned long))
947 sprintf (fmt, "%%0%lulx",
948 (unsigned long) (sizeof (val) * 2));
949 sprintf (buf, fmt, (unsigned long) val);
952 else if (sizeof (val) > 4)
953 sprintf_vma (buf, val);
960 fprintf (list_file, "DEFINED SYMBOLS\n");
965 if (symbol_get_frag (ptr) && symbol_get_frag (ptr)->line)
967 fprintf (list_file, "%20s:%-5d %s:%s %s\n",
968 symbol_get_frag (ptr)->line->file->filename,
969 symbol_get_frag (ptr)->line->line,
970 segment_name (S_GET_SEGMENT (ptr)),
971 buf, S_GET_NAME (ptr));
975 fprintf (list_file, "%33s:%s %s\n",
976 segment_name (S_GET_SEGMENT (ptr)),
977 buf, S_GET_NAME (ptr));
988 fprintf (list_file, "NO DEFINED SYMBOLS\n");
991 emit_line (NULL, "\n");
995 for (ptr = symbol_rootP; ptr != (symbolS *) NULL; ptr = symbol_next (ptr))
997 if (S_GET_NAME (ptr) && strlen (S_GET_NAME (ptr)) != 0)
999 if (S_GET_SEGMENT (ptr) == undefined_section)
1005 emit_line (NULL, "UNDEFINED SYMBOLS\n");
1008 emit_line (NULL, "%s\n", S_GET_NAME (ptr));
1014 emit_line (NULL, "NO UNDEFINED SYMBOLS\n");
1017 typedef struct cached_line
1019 file_info_type * file;
1021 char buffer [LISTING_RHS_WIDTH];
1025 print_source (file_info_type * current_file,
1026 list_info_type * list,
1029 #define NUM_CACHE_LINES 3
1030 static cached_line cached_lines[NUM_CACHE_LINES];
1031 static int next_free_line = 0;
1032 cached_line * cache = NULL;
1034 if (current_file->linenum > list->hll_line
1035 && list->hll_line > 0)
1037 /* This can happen with modern optimizing compilers. The source
1038 lines from the high level language input program are split up
1039 and interleaved, meaning the line number we want to display
1040 (list->hll_line) can have already been displayed. We have
1043 a. Do nothing, since we have already displayed the source
1044 line. This was the old behaviour.
1046 b. Display the particular line requested again, but only
1047 that line. This is the new behaviour.
1049 c. Display the particular line requested again and reset
1050 the current_file->line_num value so that we redisplay
1051 all the following lines as well the next time we
1052 encounter a larger line number. */
1055 /* Check the cache, maybe we already have the line saved. */
1056 for (i = 0; i < NUM_CACHE_LINES; i++)
1057 if (cached_lines[i].file == current_file
1058 && cached_lines[i].line == list->hll_line)
1060 cache = cached_lines + i;
1064 if (i == NUM_CACHE_LINES)
1066 cache = cached_lines + next_free_line;
1068 if (next_free_line == NUM_CACHE_LINES)
1071 cache->file = current_file;
1072 cache->line = list->hll_line;
1073 cache->buffer[0] = 0;
1074 rebuffer_line (current_file, cache->line, cache->buffer, width);
1077 emit_line (list, "%4u:%-13s **** %s\n",
1078 cache->line, cache->file->filename, cache->buffer);
1082 if (!current_file->at_end)
1084 int num_lines_shown = 0;
1086 while (current_file->linenum < list->hll_line
1087 && !current_file->at_end)
1091 cache = cached_lines + next_free_line;
1092 cache->file = current_file;
1093 cache->line = current_file->linenum + 1;
1094 cache->buffer[0] = 0;
1095 p = buffer_line (current_file, cache->buffer, width);
1097 /* Cache optimization: If printing a group of lines
1098 cache the first and last lines in the group. */
1099 if (num_lines_shown == 0)
1102 if (next_free_line == NUM_CACHE_LINES)
1106 emit_line (list, "%4u:%-13s **** %s\n",
1107 cache->line, cache->file->filename, p);
1113 /* Sometimes the user doesn't want to be bothered by the debugging
1114 records inserted by the compiler, see if the line is suspicious. */
1117 debugging_pseudo (list_info_type *list, const char *line)
1120 static int in_debug;
1124 if (list->debugging)
1132 was_debug = in_debug;
1136 while (ISSPACE (*line))
1142 /* The ELF compiler sometimes emits blank lines after switching
1143 out of a debugging section. If the next line drops us back
1144 into debugging information, then don't print the blank line.
1145 This is a hack for a particular compiler behaviour, not a
1149 && list->next != NULL
1150 && list->next->debugging)
1162 if (strncmp (line, "def", 3) == 0)
1164 if (strncmp (line, "val", 3) == 0)
1166 if (strncmp (line, "scl", 3) == 0)
1168 if (strncmp (line, "line", 4) == 0)
1170 if (strncmp (line, "endef", 5) == 0)
1172 if (strncmp (line, "ln", 2) == 0)
1174 if (strncmp (line, "type", 4) == 0)
1176 if (strncmp (line, "size", 4) == 0)
1178 if (strncmp (line, "dim", 3) == 0)
1180 if (strncmp (line, "tag", 3) == 0)
1182 if (strncmp (line, "stabs", 5) == 0)
1184 if (strncmp (line, "stabn", 5) == 0)
1191 listing_listing (char *name ATTRIBUTE_UNUSED)
1193 list_info_type *list = head;
1194 file_info_type *current_hll_file = (file_info_type *) NULL;
1197 int show_listing = 1;
1200 buffer = XNEWVEC (char, listing_rhs_width);
1201 data_buffer = XNEWVEC (char, MAX_BYTES);
1207 unsigned int list_line;
1209 width = listing_rhs_width > paper_width ? paper_width :
1212 list_line = list->line;
1213 switch (list->edict)
1216 /* Skip all lines up to the current. */
1222 case EDICT_NOLIST_NEXT:
1223 if (show_listing == 0)
1231 title = list->edict_arg;
1234 subtitle = list->edict_arg;
1240 if (show_listing <= 0)
1242 while (list->file->linenum < list_line
1243 && !list->file->at_end)
1244 p = buffer_line (list->file, buffer, width);
1247 if (list->edict == EDICT_LIST
1248 || (list->edict == EDICT_NOLIST_NEXT && show_listing == 0))
1250 /* Enable listing for the single line that caused the enable. */
1255 if (show_listing > 0)
1257 /* Scan down the list and print all the stuff which can be done
1258 with this line (or lines). */
1260 current_hll_file = list->hll_file;
1262 if (current_hll_file && list->hll_line && (listing & LISTING_HLL))
1263 print_source (current_hll_file, list, width);
1265 if (list->line_contents)
1267 if (!((listing & LISTING_NODEBUG)
1268 && debugging_pseudo (list, list->line_contents)))
1270 list->file->linenum == 0 ? list->line : list->file->linenum,
1271 list->line_contents, calc_hex (list));
1273 free (list->line_contents);
1274 list->line_contents = NULL;
1278 while (list->file->linenum < list_line
1279 && !list->file->at_end)
1281 unsigned int address;
1283 p = buffer_line (list->file, buffer, width);
1285 if (list->file->linenum < list_line)
1286 address = ~(unsigned int) 0;
1288 address = calc_hex (list);
1290 if (!((listing & LISTING_NODEBUG)
1291 && debugging_pseudo (list, p)))
1292 print_lines (list, list->file->linenum, p, address);
1296 if (list->edict == EDICT_EJECT)
1300 if (list->edict == EDICT_NOLIST_NEXT && show_listing == 1)
1311 /* Print time stamp in ISO format: yyyy-mm-ddThh:mm:ss.ss+/-zzzz. */
1314 print_timestamp (void)
1316 const time_t now = time (NULL);
1317 struct tm * timestamp;
1318 char stampstr[MAX_DATELEN];
1320 /* Any portable way to obtain subsecond values??? */
1321 timestamp = localtime (&now);
1322 strftime (stampstr, MAX_DATELEN, "%Y-%m-%dT%H:%M:%S.000%z", timestamp);
1323 fprintf (list_file, _("\n time stamp \t: %s\n\n"), stampstr);
1327 print_single_option (char * opt, int *pos)
1329 int opt_len = strlen (opt);
1331 if ((*pos + opt_len) < paper_width)
1333 fprintf (list_file, _("%s "), opt);
1334 *pos = *pos + opt_len;
1338 fprintf (list_file, _("\n\t%s "), opt);
1343 /* Print options passed to as. */
1346 print_options (char ** argv)
1348 const char *field_name = _("\n options passed\t: ");
1349 int pos = strlen (field_name);
1352 fputs (field_name, list_file);
1353 for (p = &argv[1]; *p != NULL; p++)
1357 if (strcmp (*p, "-o") == 0)
1363 if (strcmp (*p, "-v") == 0)
1366 print_single_option (*p, &pos);
1370 /* Print a first section with basic info like file names, as version,
1371 options passed, target, and timestamp.
1372 The format of this section is as follows:
1376 fieldname TAB ':' fieldcontents
1377 { TAB fieldcontents-cont } */
1380 listing_general_info (char ** argv)
1382 /* Print the stuff on the first line. */
1384 listing_page (NULL);
1387 _(" GNU assembler version %s (%s)\n\t using BFD version %s."),
1388 VERSION, TARGET_ALIAS, BFD_VERSION_STRING);
1389 print_options (argv);
1390 fprintf (list_file, _("\n input file \t: %s"), fn);
1391 fprintf (list_file, _("\n output file \t: %s"), out_file_name);
1392 fprintf (list_file, _("\n target \t: %s"), TARGET_CANONICAL);
1397 listing_print (char *name, char **argv)
1411 list_file = fopen (name, FOPEN_WT);
1412 if (list_file != NULL)
1416 as_warn (_("can't open %s: %s"), name, xstrerror (errno));
1422 if (listing & LISTING_NOFORM)
1425 if (listing & LISTING_GENERAL)
1426 listing_general_info (argv);
1428 if (listing & LISTING_LISTING)
1429 listing_listing (name);
1431 if (listing & LISTING_SYMBOLS)
1432 list_symbol_table ();
1436 if (fclose (list_file) == EOF)
1437 as_warn (_("can't close %s: %s"), name, xstrerror (errno));
1441 fclose (last_open_file);
1445 listing_file (const char *name)
1451 listing_eject (int ignore ATTRIBUTE_UNUSED)
1454 listing_tail->edict = EDICT_EJECT;
1457 /* Turn listing on or off. An argument of 0 means to turn off
1458 listing. An argument of 1 means to turn on listing. An argument
1459 of 2 means to turn off listing, but as of the next line; that is,
1460 the current line should be listed, but the next line should not. */
1463 listing_list (int on)
1470 if (listing_tail->edict == EDICT_LIST)
1471 listing_tail->edict = EDICT_NONE;
1473 listing_tail->edict = EDICT_NOLIST;
1476 if (listing_tail->edict == EDICT_NOLIST
1477 || listing_tail->edict == EDICT_NOLIST_NEXT)
1478 listing_tail->edict = EDICT_NONE;
1480 listing_tail->edict = EDICT_LIST;
1483 listing_tail->edict = EDICT_NOLIST_NEXT;
1492 listing_psize (int width_only)
1496 paper_height = get_absolute_expression ();
1498 if (paper_height < 0 || paper_height > 1000)
1501 as_warn (_("strange paper height, set to no form"));
1504 if (*input_line_pointer != ',')
1506 demand_empty_rest_of_line ();
1510 ++input_line_pointer;
1513 paper_width = get_absolute_expression ();
1515 demand_empty_rest_of_line ();
1519 listing_nopage (int ignore ATTRIBUTE_UNUSED)
1525 listing_title (int depth)
1530 unsigned int length;
1533 if (*input_line_pointer != '\"')
1538 ++input_line_pointer;
1541 start = input_line_pointer;
1543 while (*input_line_pointer)
1546 ? *input_line_pointer == '\"'
1547 : is_end_of_line[(unsigned char) *input_line_pointer])
1551 length = input_line_pointer - start;
1552 ttl = xmemdup0 (start, length);
1553 listing_tail->edict = depth ? EDICT_SBTTL : EDICT_TITLE;
1554 listing_tail->edict_arg = ttl;
1557 input_line_pointer++;
1558 demand_empty_rest_of_line ();
1561 else if (*input_line_pointer == '\n')
1563 as_bad (_("new line in title"));
1564 demand_empty_rest_of_line ();
1569 input_line_pointer++;
1575 listing_source_line (unsigned int line)
1580 listing_tail->hll_line = line;
1586 listing_source_file (const char *file)
1589 listing_tail->hll_file = file_info (file);
1594 /* Dummy functions for when compiled without listing enabled. */
1597 listing_list (int on)
1603 listing_eject (int ignore)
1609 listing_psize (int ignore)
1615 listing_nopage (int ignore)
1621 listing_title (int depth)
1627 listing_file (const char *name)
1632 listing_newline (char *name)
1637 listing_source_line (unsigned int n)
1642 listing_source_file (const char *n)