1 /* listing.c - maintain assembly listings
2 Copyright (C) 1991-2014 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"
93 #include "safe-ctype.h"
94 #include "input-file.h"
102 #ifndef LISTING_HEADER
103 #define LISTING_HEADER "GAS LISTING"
105 #ifndef LISTING_WORD_SIZE
106 #define LISTING_WORD_SIZE 4
108 #ifndef LISTING_LHS_WIDTH
109 #define LISTING_LHS_WIDTH ((LISTING_WORD_SIZE) > 4 ? 1 : 4 / (LISTING_WORD_SIZE))
111 #ifndef LISTING_LHS_WIDTH_SECOND
112 #define LISTING_LHS_WIDTH_SECOND LISTING_LHS_WIDTH
114 #ifndef LISTING_RHS_WIDTH
115 #define LISTING_RHS_WIDTH 100
117 #ifndef LISTING_LHS_CONT_LINES
118 #define LISTING_LHS_CONT_LINES 4
120 #define MAX_DATELEN 30
122 /* This structure remembers which .s were used. */
123 typedef struct file_info_struct
125 struct file_info_struct * next;
128 unsigned int linenum;
147 struct list_message *next;
150 /* This structure remembers which line from which file goes into which
152 struct list_info_struct
154 /* Frag which this line of source is nearest to. */
157 /* The actual line in the source file. */
160 /* Pointer to the file info struct for the file which this line
162 file_info_type *file;
164 /* The expanded text of any macro that may have been executing. */
168 struct list_info_struct *next;
170 /* Pointer to the file info struct for the high level language
171 source line that belongs here. */
172 file_info_type *hll_file;
174 /* High level language source line. */
175 unsigned int hll_line;
177 /* Pointers to linked list of messages associated with this line. */
178 struct list_message *messages, *last_message;
180 enum edict_enum edict;
183 /* Nonzero if this line is to be omitted because it contains
184 debugging information. This can become a flags field if we come
185 up with more information to store here. */
189 typedef struct list_info_struct list_info_type;
191 int listing_lhs_width = LISTING_LHS_WIDTH;
192 int listing_lhs_width_second = LISTING_LHS_WIDTH_SECOND;
193 int listing_lhs_cont_lines = LISTING_LHS_CONT_LINES;
194 int listing_rhs_width = LISTING_RHS_WIDTH;
196 struct list_info_struct * listing_tail;
198 static file_info_type * file_info_head;
199 static file_info_type * last_open_file_info;
200 static FILE * last_open_file;
201 static struct list_info_struct * head;
202 static int paper_width = 200;
203 static int paper_height = 60;
207 /* File to output listings to. */
208 static FILE *list_file;
210 /* This static array is used to keep the text of data to be printed
211 before the start of the line. */
214 (((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width \
215 + ((((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width_second) \
216 * listing_lhs_cont_lines) \
219 static char *data_buffer;
222 static void listing_message (const char *, const char *);
223 static file_info_type *file_info (const char *);
224 static void new_frag (void);
225 static void listing_page (list_info_type *);
226 static unsigned int calc_hex (list_info_type *);
227 static void print_lines (list_info_type *, unsigned int, char *, unsigned int);
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 unsigned int l = strlen (name) + strlen (message) + 1;
238 char *n = (char *) xmalloc (l);
239 struct list_message *lm = xmalloc (sizeof *lm);
245 if (listing_tail->last_message)
246 listing_tail->last_message->next = lm;
248 listing_tail->messages = lm;
249 listing_tail->last_message = lm;
254 listing_warning (const char *message)
256 listing_message (_("Warning: "), message);
260 listing_error (const char *message)
262 listing_message (_("Error: "), message);
265 static file_info_type *
266 file_info (const char *file_name)
268 /* Find an entry with this file name. */
269 file_info_type *p = file_info_head;
271 while (p != (file_info_type *) NULL)
273 if (filename_cmp (p->filename, file_name) == 0)
278 /* Make new entry. */
279 p = (file_info_type *) xmalloc (sizeof (file_info_type));
280 p->next = file_info_head;
282 p->filename = xstrdup (file_name);
293 frag_wane (frag_now);
298 listing_newline (char *ps)
302 static unsigned int last_line = 0xffff;
303 static char *last_file = NULL;
304 list_info_type *new_i = NULL;
309 if (now_seg == absolute_section)
313 /* In ELF, anything in a section beginning with .debug or .line is
314 considered to be debugging information. This includes the
315 statement which switches us into the debugging section, which we
316 can only set after we are already in the debugging section. */
317 if ((listing & LISTING_NODEBUG) != 0
318 && listing_tail != NULL
319 && ! listing_tail->debugging)
323 segname = segment_name (now_seg);
324 if (strncmp (segname, ".debug", sizeof ".debug" - 1) == 0
325 || strncmp (segname, ".line", sizeof ".line" - 1) == 0)
326 listing_tail->debugging = 1;
330 as_where (&file, &line);
333 if (line == last_line
334 && !(last_file && file && filename_cmp (file, last_file)))
337 new_i = (list_info_type *) xmalloc (sizeof (list_info_type));
339 /* Detect if we are reading from stdin by examining the file
340 name returned by as_where().
342 [FIXME: We rely upon the name in the strcmp below being the
343 same as the one used by input_scrub_new_file(), if that is
344 not true, then this code will fail].
346 If we are reading from stdin, then we need to save each input
347 line here (assuming of course that we actually have a line of
348 input to read), so that it can be displayed in the listing
349 that is produced at the end of the assembly. */
350 if (strcmp (file, _("{standard input}")) == 0
351 && input_line_pointer != NULL)
358 for (copy = input_line_pointer;
360 || is_end_of_line [(unsigned char) *copy] != 1);
365 else if (*copy == '\\')
367 else if (*copy == '"')
368 seen_quote = !seen_quote;
371 len = copy - input_line_pointer + 1;
373 copy = (char *) xmalloc (len);
377 char *src = input_line_pointer;
382 unsigned char c = *src++;
384 /* Omit control characters in the listing. */
392 new_i->line_contents = copy;
395 new_i->line_contents = NULL;
399 new_i = (list_info_type *) xmalloc (sizeof (list_info_type));
400 new_i->line_contents = ps;
409 listing_tail->next = new_i;
413 listing_tail = new_i;
415 new_i->frag = frag_now;
417 new_i->file = file_info (file);
418 new_i->next = (list_info_type *) NULL;
419 new_i->messages = NULL;
420 new_i->last_message = NULL;
421 new_i->edict = EDICT_NONE;
422 new_i->hll_file = (file_info_type *) NULL;
424 new_i->debugging = 0;
429 /* In ELF, anything in a section beginning with .debug or .line is
430 considered to be debugging information. */
431 if ((listing & LISTING_NODEBUG) != 0)
435 segname = segment_name (now_seg);
436 if (strncmp (segname, ".debug", sizeof ".debug" - 1) == 0
437 || strncmp (segname, ".line", sizeof ".line" - 1) == 0)
438 new_i->debugging = 1;
443 /* Attach all current frags to the previous line instead of the
444 current line. This is called by the MIPS backend when it discovers
445 that it needs to add some NOP instructions; the added NOP
446 instructions should go with the instruction that has the delay, not
447 with the new instruction. */
450 listing_prev_line (void)
455 if (head == (list_info_type *) NULL
456 || head == listing_tail)
461 for (l = head; l->next != listing_tail; l = l->next)
464 for (f = frchain_now->frch_root; f != (fragS *) NULL; f = f->fr_next)
465 if (f->line == listing_tail)
468 listing_tail->frag = frag_now;
472 /* This function returns the next source line from the file supplied,
473 truncated to size. It appends a fake line to the end of each input
474 file to make using the returned buffer simpler. */
477 buffer_line (file_info_type *file, char *line, unsigned int size)
479 unsigned int count = 0;
483 /* If we couldn't open the file, return an empty line. */
487 /* Check the cache and see if we last used this file. */
488 if (!last_open_file_info || file != last_open_file_info)
492 last_open_file_info->pos = ftell (last_open_file);
493 fclose (last_open_file);
496 /* Open the file in the binary mode so that ftell above can
497 return a reliable value that we can feed to fseek below. */
498 last_open_file_info = file;
499 last_open_file = fopen (file->filename, FOPEN_RB);
500 if (last_open_file == NULL)
506 /* Seek to where we were last time this file was open. */
508 fseek (last_open_file, file->pos, SEEK_SET);
511 /* Leave room for null. */
514 c = fgetc (last_open_file);
516 while (c != EOF && c != '\n' && c != '\r')
522 c = fgetc (last_open_file);
525 /* If '\r' is followed by '\n', swallow that. Likewise, if '\n'
526 is followed by '\r', swallow that as well. */
527 if (c == '\r' || c == '\n')
529 int next = fgetc (last_open_file);
531 if ((c == '\r' && next != '\n')
532 || (c == '\n' && next != '\r'))
533 ungetc (next, last_open_file);
539 if (count + 2 < size)
552 /* This function rewinds the requested file back to the line requested,
553 reads it in again into the buffer provided and then restores the file
554 back to its original location. Returns the buffer pointer upon success
555 or an empty string if an error occurs. */
558 rebuffer_line (file_info_type * file,
559 unsigned int linenum,
563 unsigned int count = 0;
564 unsigned int current_line;
569 bfd_boolean found = FALSE;
572 if (file == NULL || buffer == NULL || size <= 1 || file->linenum <= linenum)
575 /* Check the cache and see if we last used this file. */
576 if (last_open_file_info == NULL || file != last_open_file_info)
580 last_open_file_info->pos = ftell (last_open_file);
581 fclose (last_open_file);
584 /* Open the file in the binary mode so that ftell above can
585 return a reliable value that we can feed to fseek below. */
586 last_open_file_info = file;
587 last_open_file = fopen (file->filename, FOPEN_RB);
588 if (last_open_file == NULL)
594 /* Seek to where we were last time this file was open. */
596 fseek (last_open_file, file->pos, SEEK_SET);
599 /* Remember where we are in the current file. */
600 pos2 = pos = ftell (last_open_file);
603 current_line = file->linenum;
605 /* Leave room for the nul at the end of the buffer. */
609 /* Increment the current line count by one.
610 This is to allow for the fact that we are searching for the
611 start of a previous line, but we do this by detecting end-of-line
612 character(s) not start-of-line characters. */
615 while (pos2 > 0 && ! found)
619 /* Move backwards through the file, looking for earlier lines. */
620 pos2 = (long) size > pos2 ? 0 : pos2 - size;
621 fseek (last_open_file, pos2, SEEK_SET);
623 /* Our caller has kindly provided us with a buffer, so we use it. */
624 if (fread (buffer, 1, size, last_open_file) != size)
626 as_warn (_("unable to rebuffer file: %s\n"), file->filename);
630 for (ptr = buffer + size; ptr >= buffer; -- ptr)
636 if (current_line == linenum)
638 /* We have found the start of the line we seek. */
641 /* FIXME: We could skip the read-in-the-line code
642 below if we know that we already have the whole
643 line in the buffer. */
645 /* Advance pos2 to the newline character we have just located. */
646 pos2 += (ptr - buffer);
648 /* Skip the newline and, if present, the carriage return. */
649 if (ptr + 1 == buffer + size)
652 if (fgetc (last_open_file) == '\r')
656 pos2 += (ptr[1] == '\r' ? 2 : 1);
658 /* Move the file pointer to this location. */
659 fseek (last_open_file, pos2, SEEK_SET);
666 /* Read in the line. */
667 c = fgetc (last_open_file);
669 while (c != EOF && c != '\n' && c != '\r')
675 c = fgetc (last_open_file);
678 /* If '\r' is followed by '\n', swallow that. Likewise, if '\n'
679 is followed by '\r', swallow that as well. */
680 if (c == '\r' || c == '\n')
682 int next = fgetc (last_open_file);
684 if ((c == '\r' && next != '\n')
685 || (c == '\n' && next != '\r'))
686 ungetc (next, last_open_file);
689 /* Terminate the line. */
692 /* Reset the file position. */
693 fseek (last_open_file, pos, SEEK_SET);
698 static const char *fn;
700 static unsigned int eject; /* Eject pending */
701 static unsigned int page; /* Current page number */
702 static char *title; /* Current title */
703 static char *subtitle; /* Current subtitle */
704 static unsigned int on_page; /* Number of lines printed on current page */
707 listing_page (list_info_type *list)
709 /* Grope around, see if we can see a title or subtitle edict coming up
710 soon. (we look down 10 lines of the page and see if it's there) */
711 if ((eject || (on_page >= (unsigned int) paper_height))
712 && paper_height != 0)
716 int had_subtitle = 0;
720 while (c != 0 && list)
722 if (list->edict == EDICT_SBTTL && !had_subtitle)
725 subtitle = list->edict_arg;
727 if (list->edict == EDICT_TITLE && !had_title)
730 title = list->edict_arg;
738 fprintf (list_file, "\f");
741 fprintf (list_file, "%s %s \t\t\tpage %d\n", LISTING_HEADER, fn, page);
742 fprintf (list_file, "%s\n", title);
743 fprintf (list_file, "%s\n", subtitle);
749 /* Print a line into the list_file. Update the line count
750 and if necessary start a new page. */
753 emit_line (list_info_type * list, const char * format, ...)
757 va_start (args, format);
759 vfprintf (list_file, format, args);
767 calc_hex (list_info_type *list)
769 int data_buffer_size;
770 list_info_type *first = list;
771 unsigned int address = ~(unsigned int) 0;
774 unsigned int octet_in_frag;
776 /* Find first frag which says it belongs to this line. */
778 while (frag && frag->line != list)
779 frag = frag->fr_next;
783 data_buffer_size = 0;
785 /* Dump all the frags which belong to this line. */
786 while (frag_ptr != (fragS *) NULL && frag_ptr->line == first)
788 /* Print as many bytes from the fixed part as is sensible. */
790 while ((offsetT) octet_in_frag < frag_ptr->fr_fix
791 && data_buffer_size < MAX_BYTES - 3)
793 if (address == ~(unsigned int) 0)
794 address = frag_ptr->fr_address / OCTETS_PER_BYTE;
796 sprintf (data_buffer + data_buffer_size,
798 (frag_ptr->fr_literal[octet_in_frag]) & 0xff);
799 data_buffer_size += 2;
802 if (frag_ptr->fr_type == rs_fill)
804 unsigned int var_rep_max = octet_in_frag;
805 unsigned int var_rep_idx = octet_in_frag;
807 /* Print as many bytes from the variable part as is sensible. */
808 while (((offsetT) octet_in_frag
809 < (frag_ptr->fr_fix + frag_ptr->fr_var * frag_ptr->fr_offset))
810 && data_buffer_size < MAX_BYTES - 3)
812 if (address == ~(unsigned int) 0)
813 address = frag_ptr->fr_address / OCTETS_PER_BYTE;
815 sprintf (data_buffer + data_buffer_size,
817 (frag_ptr->fr_literal[var_rep_idx]) & 0xff);
818 data_buffer_size += 2;
823 if ((offsetT) var_rep_idx >= frag_ptr->fr_fix + frag_ptr->fr_var)
824 var_rep_idx = var_rep_max;
828 frag_ptr = frag_ptr->fr_next;
830 data_buffer[data_buffer_size] = '\0';
835 print_lines (list_info_type *list, unsigned int lineno,
836 char *string, unsigned int address)
841 unsigned int octet_in_word = 0;
842 char *src = data_buffer;
844 struct list_message *msg;
846 /* Print the stuff on the first line. */
848 nchars = (LISTING_WORD_SIZE * 2 + 1) * listing_lhs_width;
850 /* Print the hex for the first line. */
851 if (address == ~(unsigned int) 0)
853 fprintf (list_file, "% 4d ", lineno);
854 for (idx = 0; idx < nchars; idx++)
855 fprintf (list_file, " ");
857 emit_line (NULL, "\t%s\n", string ? string : "");
862 fprintf (list_file, "% 4d ???? ", lineno);
864 fprintf (list_file, "% 4d %04x ", lineno, address);
866 /* And the data to go along with it. */
869 while (src[cur] && idx < nchars)
873 fprintf (list_file, "%c%c", src[offset], src[offset + 1]);
877 if (octet_in_word == LISTING_WORD_SIZE)
879 fprintf (list_file, " ");
887 for (; idx < nchars; idx++)
888 fprintf (list_file, " ");
890 emit_line (list, "\t%s\n", string ? string : "");
892 for (msg = list->messages; msg; msg = msg->next)
893 emit_line (list, "**** %s\n", msg->message);
896 lines < (unsigned int) listing_lhs_cont_lines
900 nchars = ((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width_second - 1;
903 /* Print any more lines of data, but more compactly. */
904 fprintf (list_file, "% 4d ", lineno);
906 while (src[cur] && idx < nchars)
910 fprintf (list_file, "%c%c", src[offset], src[offset + 1]);
915 if (octet_in_word == LISTING_WORD_SIZE)
917 fprintf (list_file, " ");
923 emit_line (list, "\n");
928 list_symbol_table (void)
930 extern symbolS *symbol_rootP;
937 for (ptr = symbol_rootP; ptr != (symbolS *) NULL; ptr = symbol_next (ptr))
939 if (SEG_NORMAL (S_GET_SEGMENT (ptr))
940 || S_GET_SEGMENT (ptr) == absolute_section)
942 /* Don't report section symbols. They are not interesting. */
943 if (symbol_section_p (ptr))
946 if (S_GET_NAME (ptr))
948 char buf[30], fmt[8];
949 valueT val = S_GET_VALUE (ptr);
951 /* @@ Note that this is dependent on the compilation options,
952 not solely on the target characteristics. */
953 if (sizeof (val) == 4 && sizeof (int) == 4)
954 sprintf (buf, "%08lx", (unsigned long) val);
955 else if (sizeof (val) <= sizeof (unsigned long))
957 sprintf (fmt, "%%0%lulx",
958 (unsigned long) (sizeof (val) * 2));
959 sprintf (buf, fmt, (unsigned long) val);
962 else if (sizeof (val) > 4)
963 sprintf_vma (buf, val);
970 fprintf (list_file, "DEFINED SYMBOLS\n");
975 if (symbol_get_frag (ptr) && symbol_get_frag (ptr)->line)
977 fprintf (list_file, "%20s:%-5d %s:%s %s\n",
978 symbol_get_frag (ptr)->line->file->filename,
979 symbol_get_frag (ptr)->line->line,
980 segment_name (S_GET_SEGMENT (ptr)),
981 buf, S_GET_NAME (ptr));
985 fprintf (list_file, "%33s:%s %s\n",
986 segment_name (S_GET_SEGMENT (ptr)),
987 buf, S_GET_NAME (ptr));
998 fprintf (list_file, "NO DEFINED SYMBOLS\n");
1001 emit_line (NULL, "\n");
1005 for (ptr = symbol_rootP; ptr != (symbolS *) NULL; ptr = symbol_next (ptr))
1007 if (S_GET_NAME (ptr) && strlen (S_GET_NAME (ptr)) != 0)
1009 if (S_GET_SEGMENT (ptr) == undefined_section)
1015 emit_line (NULL, "UNDEFINED SYMBOLS\n");
1018 emit_line (NULL, "%s\n", S_GET_NAME (ptr));
1024 emit_line (NULL, "NO UNDEFINED SYMBOLS\n");
1027 typedef struct cached_line
1029 file_info_type * file;
1031 char buffer [LISTING_RHS_WIDTH];
1035 print_source (file_info_type * current_file,
1036 list_info_type * list,
1039 #define NUM_CACHE_LINES 3
1040 static cached_line cached_lines[NUM_CACHE_LINES];
1041 static int next_free_line = 0;
1042 cached_line * cache = NULL;
1044 if (current_file->linenum > list->hll_line
1045 && list->hll_line > 0)
1047 /* This can happen with modern optimizing compilers. The source
1048 lines from the high level language input program are split up
1049 and interleaved, meaning the line number we want to display
1050 (list->hll_line) can have already been displayed. We have
1053 a. Do nothing, since we have already displayed the source
1054 line. This was the old behaviour.
1056 b. Display the particular line requested again, but only
1057 that line. This is the new behaviour.
1059 c. Display the particular line requested again and reset
1060 the current_file->line_num value so that we redisplay
1061 all the following lines as well the next time we
1062 encounter a larger line number. */
1065 /* Check the cache, maybe we already have the line saved. */
1066 for (i = 0; i < NUM_CACHE_LINES; i++)
1067 if (cached_lines[i].file == current_file
1068 && cached_lines[i].line == list->hll_line)
1070 cache = cached_lines + i;
1074 if (i == NUM_CACHE_LINES)
1076 cache = cached_lines + next_free_line;
1078 if (next_free_line == NUM_CACHE_LINES)
1081 cache->file = current_file;
1082 cache->line = list->hll_line;
1083 cache->buffer[0] = 0;
1084 rebuffer_line (current_file, cache->line, cache->buffer, width);
1087 emit_line (list, "%4u:%-13s **** %s\n",
1088 cache->line, cache->file->filename, cache->buffer);
1092 if (!current_file->at_end)
1094 int num_lines_shown = 0;
1096 while (current_file->linenum < list->hll_line
1097 && !current_file->at_end)
1101 cache = cached_lines + next_free_line;
1102 cache->file = current_file;
1103 cache->line = current_file->linenum + 1;
1104 cache->buffer[0] = 0;
1105 p = buffer_line (current_file, cache->buffer, width);
1107 /* Cache optimization: If printing a group of lines
1108 cache the first and last lines in the group. */
1109 if (num_lines_shown == 0)
1112 if (next_free_line == NUM_CACHE_LINES)
1116 emit_line (list, "%4u:%-13s **** %s\n",
1117 cache->line, cache->file->filename, p);
1123 /* Sometimes the user doesn't want to be bothered by the debugging
1124 records inserted by the compiler, see if the line is suspicious. */
1127 debugging_pseudo (list_info_type *list, const char *line)
1130 static int in_debug;
1134 if (list->debugging)
1142 was_debug = in_debug;
1146 while (ISSPACE (*line))
1152 /* The ELF compiler sometimes emits blank lines after switching
1153 out of a debugging section. If the next line drops us back
1154 into debugging information, then don't print the blank line.
1155 This is a hack for a particular compiler behaviour, not a
1159 && list->next != NULL
1160 && list->next->debugging)
1172 if (strncmp (line, "def", 3) == 0)
1174 if (strncmp (line, "val", 3) == 0)
1176 if (strncmp (line, "scl", 3) == 0)
1178 if (strncmp (line, "line", 4) == 0)
1180 if (strncmp (line, "endef", 5) == 0)
1182 if (strncmp (line, "ln", 2) == 0)
1184 if (strncmp (line, "type", 4) == 0)
1186 if (strncmp (line, "size", 4) == 0)
1188 if (strncmp (line, "dim", 3) == 0)
1190 if (strncmp (line, "tag", 3) == 0)
1192 if (strncmp (line, "stabs", 5) == 0)
1194 if (strncmp (line, "stabn", 5) == 0)
1201 listing_listing (char *name ATTRIBUTE_UNUSED)
1203 list_info_type *list = head;
1204 file_info_type *current_hll_file = (file_info_type *) NULL;
1207 int show_listing = 1;
1210 buffer = (char *) xmalloc (listing_rhs_width);
1211 data_buffer = (char *) xmalloc (MAX_BYTES);
1217 unsigned int list_line;
1219 width = listing_rhs_width > paper_width ? paper_width :
1222 list_line = list->line;
1223 switch (list->edict)
1226 /* Skip all lines up to the current. */
1232 case EDICT_NOLIST_NEXT:
1233 if (show_listing == 0)
1241 title = list->edict_arg;
1244 subtitle = list->edict_arg;
1250 if (show_listing <= 0)
1252 while (list->file->linenum < list_line
1253 && !list->file->at_end)
1254 p = buffer_line (list->file, buffer, width);
1257 if (list->edict == EDICT_LIST
1258 || (list->edict == EDICT_NOLIST_NEXT && show_listing == 0))
1260 /* Enable listing for the single line that caused the enable. */
1265 if (show_listing > 0)
1267 /* Scan down the list and print all the stuff which can be done
1268 with this line (or lines). */
1270 current_hll_file = list->hll_file;
1272 if (current_hll_file && list->hll_line && (listing & LISTING_HLL))
1273 print_source (current_hll_file, list, width);
1275 if (list->line_contents)
1277 if (!((listing & LISTING_NODEBUG)
1278 && debugging_pseudo (list, list->line_contents)))
1280 list->file->linenum == 0 ? list->line : list->file->linenum,
1281 list->line_contents, calc_hex (list));
1283 free (list->line_contents);
1284 list->line_contents = NULL;
1288 while (list->file->linenum < list_line
1289 && !list->file->at_end)
1291 unsigned int address;
1293 p = buffer_line (list->file, buffer, width);
1295 if (list->file->linenum < list_line)
1296 address = ~(unsigned int) 0;
1298 address = calc_hex (list);
1300 if (!((listing & LISTING_NODEBUG)
1301 && debugging_pseudo (list, p)))
1302 print_lines (list, list->file->linenum, p, address);
1306 if (list->edict == EDICT_EJECT)
1310 if (list->edict == EDICT_NOLIST_NEXT && show_listing == 1)
1321 /* Print time stamp in ISO format: yyyy-mm-ddThh:mm:ss.ss+/-zzzz. */
1324 print_timestamp (void)
1326 const time_t now = time (NULL);
1327 struct tm * timestamp;
1328 char stampstr[MAX_DATELEN];
1330 /* Any portable way to obtain subsecond values??? */
1331 timestamp = localtime (&now);
1332 strftime (stampstr, MAX_DATELEN, "%Y-%m-%dT%H:%M:%S.000%z", timestamp);
1333 fprintf (list_file, _("\n time stamp \t: %s\n\n"), stampstr);
1337 print_single_option (char * opt, int *pos)
1339 int opt_len = strlen (opt);
1341 if ((*pos + opt_len) < paper_width)
1343 fprintf (list_file, _("%s "), opt);
1344 *pos = *pos + opt_len;
1348 fprintf (list_file, _("\n\t%s "), opt);
1353 /* Print options passed to as. */
1356 print_options (char ** argv)
1358 const char *field_name = _("\n options passed\t: ");
1359 int pos = strlen (field_name);
1362 fputs (field_name, list_file);
1363 for (p = &argv[1]; *p != NULL; p++)
1367 if (strcmp (*p, "-o") == 0)
1373 if (strcmp (*p, "-v") == 0)
1376 print_single_option (*p, &pos);
1380 /* Print a first section with basic info like file names, as version,
1381 options passed, target, and timestamp.
1382 The format of this section is as follows:
1386 fieldname TAB ':' fieldcontents
1387 { TAB fieldcontents-cont } */
1390 listing_general_info (char ** argv)
1392 /* Print the stuff on the first line. */
1394 listing_page (NULL);
1397 _(" GNU assembler version %s (%s)\n\t using BFD version %s."),
1398 VERSION, TARGET_ALIAS, BFD_VERSION_STRING);
1399 print_options (argv);
1400 fprintf (list_file, _("\n input file \t: %s"), fn);
1401 fprintf (list_file, _("\n output file \t: %s"), out_file_name);
1402 fprintf (list_file, _("\n target \t: %s"), TARGET_CANONICAL);
1407 listing_print (char *name, char **argv)
1421 list_file = fopen (name, FOPEN_WT);
1422 if (list_file != NULL)
1426 as_warn (_("can't open %s: %s"), name, xstrerror (errno));
1432 if (listing & LISTING_NOFORM)
1435 if (listing & LISTING_GENERAL)
1436 listing_general_info (argv);
1438 if (listing & LISTING_LISTING)
1439 listing_listing (name);
1441 if (listing & LISTING_SYMBOLS)
1442 list_symbol_table ();
1446 if (fclose (list_file) == EOF)
1447 as_warn (_("can't close %s: %s"), name, xstrerror (errno));
1451 fclose (last_open_file);
1455 listing_file (const char *name)
1461 listing_eject (int ignore ATTRIBUTE_UNUSED)
1464 listing_tail->edict = EDICT_EJECT;
1467 /* Turn listing on or off. An argument of 0 means to turn off
1468 listing. An argument of 1 means to turn on listing. An argument
1469 of 2 means to turn off listing, but as of the next line; that is,
1470 the current line should be listed, but the next line should not. */
1473 listing_list (int on)
1480 if (listing_tail->edict == EDICT_LIST)
1481 listing_tail->edict = EDICT_NONE;
1483 listing_tail->edict = EDICT_NOLIST;
1486 if (listing_tail->edict == EDICT_NOLIST
1487 || listing_tail->edict == EDICT_NOLIST_NEXT)
1488 listing_tail->edict = EDICT_NONE;
1490 listing_tail->edict = EDICT_LIST;
1493 listing_tail->edict = EDICT_NOLIST_NEXT;
1502 listing_psize (int width_only)
1506 paper_height = get_absolute_expression ();
1508 if (paper_height < 0 || paper_height > 1000)
1511 as_warn (_("strange paper height, set to no form"));
1514 if (*input_line_pointer != ',')
1516 demand_empty_rest_of_line ();
1520 ++input_line_pointer;
1523 paper_width = get_absolute_expression ();
1525 demand_empty_rest_of_line ();
1529 listing_nopage (int ignore ATTRIBUTE_UNUSED)
1535 listing_title (int depth)
1540 unsigned int length;
1543 if (*input_line_pointer != '\"')
1548 ++input_line_pointer;
1551 start = input_line_pointer;
1553 while (*input_line_pointer)
1556 ? *input_line_pointer == '\"'
1557 : is_end_of_line[(unsigned char) *input_line_pointer])
1561 length = input_line_pointer - start;
1562 ttl = (char *) xmalloc (length + 1);
1563 memcpy (ttl, start, length);
1565 listing_tail->edict = depth ? EDICT_SBTTL : EDICT_TITLE;
1566 listing_tail->edict_arg = ttl;
1569 input_line_pointer++;
1570 demand_empty_rest_of_line ();
1573 else if (*input_line_pointer == '\n')
1575 as_bad (_("new line in title"));
1576 demand_empty_rest_of_line ();
1581 input_line_pointer++;
1587 listing_source_line (unsigned int line)
1592 listing_tail->hll_line = line;
1598 listing_source_file (const char *file)
1601 listing_tail->hll_file = file_info (file);
1606 /* Dummy functions for when compiled without listing enabled. */
1609 listing_list (int on)
1615 listing_eject (int ignore)
1621 listing_psize (int ignore)
1627 listing_nopage (int ignore)
1633 listing_title (int depth)
1639 listing_file (const char *name)
1644 listing_newline (char *name)
1649 listing_source_line (unsigned int n)
1654 listing_source_file (const char *n)