1 /* listing.c - maintain assembly listings
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 /* Contributed by Steve Chamberlain <sac@cygnus.com>
25 A listing page looks like:
27 LISTING_HEADER sourcefilename pagenumber
30 linenumber address data source
31 linenumber address data source
32 linenumber address data source
33 linenumber address data source
35 If not overridden, the listing commands are:
38 Put "stuff" onto the title line
40 Put stuff onto the subtitle line
42 If these commands come within 10 lines of the top of the page, they
43 will affect the page they are on, as well as any subsequent page
48 Increment the enable listing counter
50 Decrement the enable listing counter
53 Set the paper size to X wide and Y high. Setting a psize Y of
54 zero will suppress form feeds except where demanded by .eject
56 If the counter goes below zero, listing is suppressed.
58 Listings are a maintained by read calling various listing_<foo>
59 functions. What happens most is that the macro NO_LISTING is not
60 defined (from the Makefile), then the macro LISTING_NEWLINE expands
61 into a call to listing_newline. The call is done from read.c, every
62 time it sees a newline, and -l is on the command line.
64 The function listing_newline remembers the frag associated with the
65 newline, and creates a new frag - note that this is wasteful, but not
66 a big deal, since listing slows things down a lot anyway. The
67 function also remembers when the filename changes.
69 When all the input has finished, and gas has had a chance to settle
70 down, the listing is output. This is done by running down the list of
71 frag/source file records, and opening the files as needed and printing
72 out the bytes and chars associated with them.
74 The only things which the architecture can change about the listing
75 are defined in these macros:
77 LISTING_HEADER The name of the architecture
78 LISTING_WORD_SIZE The make of the number of bytes in a word, this determines
79 the clumping of the output data. eg a value of
80 2 makes words look like 1234 5678, whilst 1
81 would make the same value look like 12 34 56
83 LISTING_LHS_WIDTH Number of words of above size for the lhs
85 LISTING_LHS_WIDTH_SECOND Number of words for the data on the lhs
88 LISTING_LHS_CONT_LINES Max number of lines to use up for a continuation
89 LISTING_RHS_WIDTH Number of chars from the input file to print
94 #include "safe-ctype.h"
95 #include "input-file.h"
103 #ifndef LISTING_HEADER
104 #define LISTING_HEADER "GAS LISTING"
106 #ifndef LISTING_WORD_SIZE
107 #define LISTING_WORD_SIZE 4
109 #ifndef LISTING_LHS_WIDTH
110 #define LISTING_LHS_WIDTH ((LISTING_WORD_SIZE) > 4 ? 1 : 4 / (LISTING_WORD_SIZE))
112 #ifndef LISTING_LHS_WIDTH_SECOND
113 #define LISTING_LHS_WIDTH_SECOND LISTING_LHS_WIDTH
115 #ifndef LISTING_RHS_WIDTH
116 #define LISTING_RHS_WIDTH 100
118 #ifndef LISTING_LHS_CONT_LINES
119 #define LISTING_LHS_CONT_LINES 4
121 #define MAX_DATELEN 30
123 /* This structure remembers which .s were used. */
124 typedef struct file_info_struct
126 struct file_info_struct
* next
;
129 unsigned int linenum
;
145 /* This structure remembers which line from which file goes into which
147 struct list_info_struct
149 /* Frag which this line of source is nearest to. */
152 /* The actual line in the source file. */
155 /* Pointer to the file info struct for the file which this line
157 file_info_type
*file
;
159 /* The expanded text of any macro that may have been executing. */
163 struct list_info_struct
*next
;
165 /* Pointer to the file info struct for the high level language
166 source line that belongs here. */
167 file_info_type
*hll_file
;
169 /* High level language source line. */
170 unsigned int hll_line
;
172 /* Pointer to any error message associated with this line. */
175 enum edict_enum edict
;
178 /* Nonzero if this line is to be omitted because it contains
179 debugging information. This can become a flags field if we come
180 up with more information to store here. */
184 typedef struct list_info_struct list_info_type
;
186 int listing_lhs_width
= LISTING_LHS_WIDTH
;
187 int listing_lhs_width_second
= LISTING_LHS_WIDTH_SECOND
;
188 int listing_lhs_cont_lines
= LISTING_LHS_CONT_LINES
;
189 int listing_rhs_width
= LISTING_RHS_WIDTH
;
191 struct list_info_struct
* listing_tail
;
193 static file_info_type
* file_info_head
;
194 static file_info_type
* last_open_file_info
;
195 static FILE * last_open_file
;
196 static struct list_info_struct
* head
;
197 static int paper_width
= 200;
198 static int paper_height
= 60;
202 /* File to output listings to. */
203 static FILE *list_file
;
205 /* This static array is used to keep the text of data to be printed
206 before the start of the line. */
209 (((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width \
210 + ((((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width_second) \
211 * listing_lhs_cont_lines) \
214 static char *data_buffer
;
217 static void listing_message (const char *, const char *);
218 static file_info_type
*file_info (const char *);
219 static void new_frag (void);
220 static void listing_page (list_info_type
*);
221 static unsigned int calc_hex (list_info_type
*);
222 static void print_lines (list_info_type
*, unsigned int, char *, unsigned int);
223 static void list_symbol_table (void);
224 static int debugging_pseudo (list_info_type
*, const char *);
225 static void listing_listing (char *);
228 listing_message (const char *name
, const char *message
)
230 if (listing_tail
!= (list_info_type
*) NULL
)
232 unsigned int l
= strlen (name
) + strlen (message
) + 1;
233 char *n
= (char *) xmalloc (l
);
236 listing_tail
->message
= n
;
241 listing_warning (const char *message
)
243 listing_message (_("Warning:"), message
);
247 listing_error (const char *message
)
249 listing_message (_("Error:"), message
);
252 static file_info_type
*
253 file_info (const char *file_name
)
255 /* Find an entry with this file name. */
256 file_info_type
*p
= file_info_head
;
258 while (p
!= (file_info_type
*) NULL
)
260 if (strcmp (p
->filename
, file_name
) == 0)
265 /* Make new entry. */
266 p
= (file_info_type
*) xmalloc (sizeof (file_info_type
));
267 p
->next
= file_info_head
;
269 p
->filename
= xstrdup (file_name
);
280 frag_wane (frag_now
);
285 listing_newline (char *ps
)
289 static unsigned int last_line
= 0xffff;
290 static char *last_file
= NULL
;
291 list_info_type
*new_i
= NULL
;
296 if (now_seg
== absolute_section
)
300 /* In ELF, anything in a section beginning with .debug or .line is
301 considered to be debugging information. This includes the
302 statement which switches us into the debugging section, which we
303 can only set after we are already in the debugging section. */
304 if ((listing
& LISTING_NODEBUG
) != 0
305 && listing_tail
!= NULL
306 && ! listing_tail
->debugging
)
310 segname
= segment_name (now_seg
);
311 if (strncmp (segname
, ".debug", sizeof ".debug" - 1) == 0
312 || strncmp (segname
, ".line", sizeof ".line" - 1) == 0)
313 listing_tail
->debugging
= 1;
317 as_where (&file
, &line
);
320 if (line
== last_line
321 && !(last_file
&& file
&& strcmp (file
, last_file
)))
324 new_i
= (list_info_type
*) xmalloc (sizeof (list_info_type
));
326 /* Detect if we are reading from stdin by examining the file
327 name returned by as_where().
329 [FIXME: We rely upon the name in the strcmp below being the
330 same as the one used by input_scrub_new_file(), if that is
331 not true, then this code will fail].
333 If we are reading from stdin, then we need to save each input
334 line here (assuming of course that we actually have a line of
335 input to read), so that it can be displayed in the listing
336 that is produced at the end of the assembly. */
337 if (strcmp (file
, _("{standard input}")) == 0
338 && input_line_pointer
!= NULL
)
345 for (copy
= input_line_pointer
;
347 || is_end_of_line
[(unsigned char) *copy
] != 1);
352 else if (*copy
== '\\')
354 else if (*copy
== '"')
355 seen_quote
= !seen_quote
;
358 len
= copy
- input_line_pointer
+ 1;
360 copy
= (char *) xmalloc (len
);
364 char *src
= input_line_pointer
;
369 unsigned char c
= *src
++;
371 /* Omit control characters in the listing. */
379 new_i
->line_contents
= copy
;
382 new_i
->line_contents
= NULL
;
386 new_i
= (list_info_type
*) xmalloc (sizeof (list_info_type
));
387 new_i
->line_contents
= ps
;
396 listing_tail
->next
= new_i
;
400 listing_tail
= new_i
;
402 new_i
->frag
= frag_now
;
404 new_i
->file
= file_info (file
);
405 new_i
->next
= (list_info_type
*) NULL
;
406 new_i
->message
= (char *) NULL
;
407 new_i
->edict
= EDICT_NONE
;
408 new_i
->hll_file
= (file_info_type
*) NULL
;
410 new_i
->debugging
= 0;
415 /* In ELF, anything in a section beginning with .debug or .line is
416 considered to be debugging information. */
417 if ((listing
& LISTING_NODEBUG
) != 0)
421 segname
= segment_name (now_seg
);
422 if (strncmp (segname
, ".debug", sizeof ".debug" - 1) == 0
423 || strncmp (segname
, ".line", sizeof ".line" - 1) == 0)
424 new_i
->debugging
= 1;
429 /* Attach all current frags to the previous line instead of the
430 current line. This is called by the MIPS backend when it discovers
431 that it needs to add some NOP instructions; the added NOP
432 instructions should go with the instruction that has the delay, not
433 with the new instruction. */
436 listing_prev_line (void)
441 if (head
== (list_info_type
*) NULL
442 || head
== listing_tail
)
447 for (l
= head
; l
->next
!= listing_tail
; l
= l
->next
)
450 for (f
= frchain_now
->frch_root
; f
!= (fragS
*) NULL
; f
= f
->fr_next
)
451 if (f
->line
== listing_tail
)
454 listing_tail
->frag
= frag_now
;
458 /* This function returns the next source line from the file supplied,
459 truncated to size. It appends a fake line to the end of each input
460 file to make using the returned buffer simpler. */
463 buffer_line (file_info_type
*file
, char *line
, unsigned int size
)
465 unsigned int count
= 0;
469 /* If we couldn't open the file, return an empty line. */
473 /* Check the cache and see if we last used this file. */
474 if (!last_open_file_info
|| file
!= last_open_file_info
)
478 last_open_file_info
->pos
= ftell (last_open_file
);
479 fclose (last_open_file
);
482 /* Open the file in the binary mode so that ftell above can
483 return a reliable value that we can feed to fseek below. */
484 last_open_file_info
= file
;
485 last_open_file
= fopen (file
->filename
, FOPEN_RB
);
486 if (last_open_file
== NULL
)
492 /* Seek to where we were last time this file was open. */
494 fseek (last_open_file
, file
->pos
, SEEK_SET
);
497 /* Leave room for null. */
500 c
= fgetc (last_open_file
);
502 while (c
!= EOF
&& c
!= '\n' && c
!= '\r')
508 c
= fgetc (last_open_file
);
511 /* If '\r' is followed by '\n', swallow that. Likewise, if '\n'
512 is followed by '\r', swallow that as well. */
513 if (c
== '\r' || c
== '\n')
515 int next
= fgetc (last_open_file
);
517 if ((c
== '\r' && next
!= '\n')
518 || (c
== '\n' && next
!= '\r'))
519 ungetc (next
, last_open_file
);
525 if (count
+ 2 < size
)
538 /* This function rewinds the requested file back to the line requested,
539 reads it in again into the buffer provided and then restores the file
540 back to its original location. */
543 rebuffer_line (file_info_type
* file
,
544 unsigned int linenum
,
548 unsigned int count
= 0;
549 unsigned int current_line
= 1;
555 if (file
== NULL
|| buffer
== NULL
|| size
== 0 || file
->linenum
<= linenum
)
558 /* Check the cache and see if we last used this file. */
559 if (last_open_file_info
== NULL
|| file
!= last_open_file_info
)
563 last_open_file_info
->pos
= ftell (last_open_file
);
564 fclose (last_open_file
);
567 /* Open the file in the binary mode so that ftell above can
568 return a reliable value that we can feed to fseek below. */
569 last_open_file_info
= file
;
570 last_open_file
= fopen (file
->filename
, FOPEN_RB
);
571 if (last_open_file
== NULL
)
577 /* Seek to where we were last time this file was open. */
579 fseek (last_open_file
, file
->pos
, SEEK_SET
);
582 /* Remember where we are in the current file. */
583 pos
= ftell (last_open_file
);
585 /* Go back to the beginning. */
586 fseek (last_open_file
, 0, SEEK_SET
);
588 /* Skip lines prior to the one we are interested in. */
589 while (current_line
< linenum
)
591 /* fgets only stops on newlines and has a size limit,
592 so we read one character at a time instead. */
595 c
= fgetc (last_open_file
);
597 while (c
!= EOF
&& c
!= '\n' && c
!= '\r');
601 if (c
== '\r' || c
== '\n')
603 int next
= fgetc (last_open_file
);
605 /* If '\r' is followed by '\n', swallow that. Likewise, if '\n'
606 is followed by '\r', swallow that as well. */
607 if ((c
== '\r' && next
!= '\n')
608 || (c
== '\n' && next
!= '\r'))
609 ungetc (next
, last_open_file
);
613 /* Leave room for the nul at the end of the buffer. */
616 /* Read in the line. */
617 c
= fgetc (last_open_file
);
619 while (c
!= EOF
&& c
!= '\n' && c
!= '\r')
625 c
= fgetc (last_open_file
);
628 /* If '\r' is followed by '\n', swallow that. Likewise, if '\n'
629 is followed by '\r', swallow that as well. */
630 if (c
== '\r' || c
== '\n')
632 int next
= fgetc (last_open_file
);
634 if ((c
== '\r' && next
!= '\n')
635 || (c
== '\n' && next
!= '\r'))
636 ungetc (next
, last_open_file
);
639 /* Terminate the line. */
642 /* Reset the file position. */
643 fseek (last_open_file
, pos
, SEEK_SET
);
648 static const char *fn
;
650 static unsigned int eject
; /* Eject pending */
651 static unsigned int page
; /* Current page number */
652 static char *title
; /* Current title */
653 static char *subtitle
; /* Current subtitle */
654 static unsigned int on_page
; /* Number of lines printed on current page */
657 listing_page (list_info_type
*list
)
659 /* Grope around, see if we can see a title or subtitle edict coming up
660 soon. (we look down 10 lines of the page and see if it's there) */
661 if ((eject
|| (on_page
>= (unsigned int) paper_height
))
662 && paper_height
!= 0)
666 int had_subtitle
= 0;
670 while (c
!= 0 && list
)
672 if (list
->edict
== EDICT_SBTTL
&& !had_subtitle
)
675 subtitle
= list
->edict_arg
;
677 if (list
->edict
== EDICT_TITLE
&& !had_title
)
680 title
= list
->edict_arg
;
688 fprintf (list_file
, "\f");
691 fprintf (list_file
, "%s %s \t\t\tpage %d\n", LISTING_HEADER
, fn
, page
);
692 fprintf (list_file
, "%s\n", title
);
693 fprintf (list_file
, "%s\n", subtitle
);
699 /* Print a line into the list_file. Update the line count
700 and if necessary start a new page. */
703 emit_line (list_info_type
* list
, const char * format
, ...)
707 va_start (args
, format
);
709 vfprintf (list_file
, format
, args
);
717 calc_hex (list_info_type
*list
)
719 int data_buffer_size
;
720 list_info_type
*first
= list
;
721 unsigned int address
= ~(unsigned int) 0;
724 unsigned int octet_in_frag
;
726 /* Find first frag which says it belongs to this line. */
728 while (frag
&& frag
->line
!= list
)
729 frag
= frag
->fr_next
;
733 data_buffer_size
= 0;
735 /* Dump all the frags which belong to this line. */
736 while (frag_ptr
!= (fragS
*) NULL
&& frag_ptr
->line
== first
)
738 /* Print as many bytes from the fixed part as is sensible. */
740 while ((offsetT
) octet_in_frag
< frag_ptr
->fr_fix
741 && data_buffer_size
< MAX_BYTES
- 3)
743 if (address
== ~(unsigned int) 0)
744 address
= frag_ptr
->fr_address
/ OCTETS_PER_BYTE
;
746 sprintf (data_buffer
+ data_buffer_size
,
748 (frag_ptr
->fr_literal
[octet_in_frag
]) & 0xff);
749 data_buffer_size
+= 2;
752 if (frag_ptr
->fr_type
== rs_fill
)
754 unsigned int var_rep_max
= octet_in_frag
;
755 unsigned int var_rep_idx
= octet_in_frag
;
757 /* Print as many bytes from the variable part as is sensible. */
758 while (((offsetT
) octet_in_frag
759 < (frag_ptr
->fr_fix
+ frag_ptr
->fr_var
* frag_ptr
->fr_offset
))
760 && data_buffer_size
< MAX_BYTES
- 3)
762 if (address
== ~(unsigned int) 0)
763 address
= frag_ptr
->fr_address
/ OCTETS_PER_BYTE
;
765 sprintf (data_buffer
+ data_buffer_size
,
767 (frag_ptr
->fr_literal
[var_rep_idx
]) & 0xff);
768 data_buffer_size
+= 2;
773 if ((offsetT
) var_rep_idx
>= frag_ptr
->fr_fix
+ frag_ptr
->fr_var
)
774 var_rep_idx
= var_rep_max
;
778 frag_ptr
= frag_ptr
->fr_next
;
780 data_buffer
[data_buffer_size
] = '\0';
785 print_lines (list_info_type
*list
, unsigned int lineno
,
786 char *string
, unsigned int address
)
791 unsigned int octet_in_word
= 0;
792 char *src
= data_buffer
;
795 /* Print the stuff on the first line. */
797 nchars
= (LISTING_WORD_SIZE
* 2 + 1) * listing_lhs_width
;
799 /* Print the hex for the first line. */
800 if (address
== ~(unsigned int) 0)
802 fprintf (list_file
, "% 4d ", lineno
);
803 for (idx
= 0; idx
< nchars
; idx
++)
804 fprintf (list_file
, " ");
806 emit_line (NULL
, "\t%s\n", string
? string
: "");
811 fprintf (list_file
, "% 4d ???? ", lineno
);
813 fprintf (list_file
, "% 4d %04x ", lineno
, address
);
815 /* And the data to go along with it. */
818 while (src
[cur
] && idx
< nchars
)
822 fprintf (list_file
, "%c%c", src
[offset
], src
[offset
+ 1]);
826 if (octet_in_word
== LISTING_WORD_SIZE
)
828 fprintf (list_file
, " ");
836 for (; idx
< nchars
; idx
++)
837 fprintf (list_file
, " ");
839 emit_line (list
, "\t%s\n", string
? string
: "");
842 emit_line (list
, "**** %s\n", list
->message
);
845 lines
< (unsigned int) listing_lhs_cont_lines
849 nchars
= ((LISTING_WORD_SIZE
* 2) + 1) * listing_lhs_width_second
- 1;
852 /* Print any more lines of data, but more compactly. */
853 fprintf (list_file
, "% 4d ", lineno
);
855 while (src
[cur
] && idx
< nchars
)
859 fprintf (list_file
, "%c%c", src
[offset
], src
[offset
+ 1]);
864 if (octet_in_word
== LISTING_WORD_SIZE
)
866 fprintf (list_file
, " ");
872 emit_line (list
, "\n");
877 list_symbol_table (void)
879 extern symbolS
*symbol_rootP
;
886 for (ptr
= symbol_rootP
; ptr
!= (symbolS
*) NULL
; ptr
= symbol_next (ptr
))
888 if (SEG_NORMAL (S_GET_SEGMENT (ptr
))
889 || S_GET_SEGMENT (ptr
) == absolute_section
)
891 /* Don't report section symbols. They are not interesting. */
892 if (symbol_section_p (ptr
))
895 if (S_GET_NAME (ptr
))
897 char buf
[30], fmt
[8];
898 valueT val
= S_GET_VALUE (ptr
);
900 /* @@ Note that this is dependent on the compilation options,
901 not solely on the target characteristics. */
902 if (sizeof (val
) == 4 && sizeof (int) == 4)
903 sprintf (buf
, "%08lx", (unsigned long) val
);
904 else if (sizeof (val
) <= sizeof (unsigned long))
906 sprintf (fmt
, "%%0%lulx",
907 (unsigned long) (sizeof (val
) * 2));
908 sprintf (buf
, fmt
, (unsigned long) val
);
911 else if (sizeof (val
) > 4)
912 sprintf_vma (buf
, val
);
919 fprintf (list_file
, "DEFINED SYMBOLS\n");
924 if (symbol_get_frag (ptr
) && symbol_get_frag (ptr
)->line
)
926 fprintf (list_file
, "%20s:%-5d %s:%s %s\n",
927 symbol_get_frag (ptr
)->line
->file
->filename
,
928 symbol_get_frag (ptr
)->line
->line
,
929 segment_name (S_GET_SEGMENT (ptr
)),
930 buf
, S_GET_NAME (ptr
));
934 fprintf (list_file
, "%33s:%s %s\n",
935 segment_name (S_GET_SEGMENT (ptr
)),
936 buf
, S_GET_NAME (ptr
));
947 fprintf (list_file
, "NO DEFINED SYMBOLS\n");
950 emit_line (NULL
, "\n");
954 for (ptr
= symbol_rootP
; ptr
!= (symbolS
*) NULL
; ptr
= symbol_next (ptr
))
956 if (S_GET_NAME (ptr
) && strlen (S_GET_NAME (ptr
)) != 0)
958 if (S_GET_SEGMENT (ptr
) == undefined_section
)
964 emit_line (NULL
, "UNDEFINED SYMBOLS\n");
967 emit_line (NULL
, "%s\n", S_GET_NAME (ptr
));
973 emit_line (NULL
, "NO UNDEFINED SYMBOLS\n");
976 typedef struct cached_line
978 file_info_type
* file
;
980 char buffer
[LISTING_RHS_WIDTH
];
984 print_source (file_info_type
* current_file
,
985 list_info_type
* list
,
988 #define NUM_CACHE_LINES 3
989 static cached_line cached_lines
[NUM_CACHE_LINES
];
990 static int next_free_line
= 0;
991 cached_line
* cache
= NULL
;
993 if (current_file
->linenum
> list
->hll_line
994 && list
->hll_line
> 0)
996 /* This can happen with modern optimizing compilers. The source
997 lines from the high level language input program are split up
998 and interleaved, meaning the line number we want to display
999 (list->hll_line) can have already been displayed. We have
1002 a. Do nothing, since we have already displayed the source
1003 line. This was the old behaviour.
1005 b. Display the particular line requested again, but only
1006 that line. This is the new behaviour.
1008 c. Display the particular line requested again and reset
1009 the current_file->line_num value so that we redisplay
1010 all the following lines as well the next time we
1011 encounter a larger line number. */
1014 /* Check the cache, maybe we already have the line saved. */
1015 for (i
= 0; i
< NUM_CACHE_LINES
; i
++)
1016 if (cached_lines
[i
].file
== current_file
1017 && cached_lines
[i
].line
== list
->hll_line
)
1019 cache
= cached_lines
+ i
;
1023 if (i
== NUM_CACHE_LINES
)
1025 cache
= cached_lines
+ next_free_line
;
1027 if (next_free_line
== NUM_CACHE_LINES
)
1030 cache
->file
= current_file
;
1031 cache
->line
= list
->hll_line
;
1032 cache
->buffer
[0] = 0;
1033 rebuffer_line (current_file
, cache
->line
, cache
->buffer
, width
);
1036 emit_line (list
, "%4u:%-13s **** %s\n",
1037 cache
->line
, cache
->file
->filename
, cache
->buffer
);
1041 if (!current_file
->at_end
)
1043 int num_lines_shown
= 0;
1045 while (current_file
->linenum
< list
->hll_line
1046 && !current_file
->at_end
)
1050 cache
= cached_lines
+ next_free_line
;
1051 cache
->file
= current_file
;
1052 cache
->line
= current_file
->linenum
+ 1;
1053 cache
->buffer
[0] = 0;
1054 p
= buffer_line (current_file
, cache
->buffer
, width
);
1056 /* Cache optimization: If printing a group of lines
1057 cache the first and last lines in the group. */
1058 if (num_lines_shown
== 0)
1061 if (next_free_line
== NUM_CACHE_LINES
)
1065 emit_line (list
, "%4u:%-13s **** %s\n",
1066 cache
->line
, cache
->file
->filename
, p
);
1072 /* Sometimes the user doesn't want to be bothered by the debugging
1073 records inserted by the compiler, see if the line is suspicious. */
1076 debugging_pseudo (list_info_type
*list
, const char *line
)
1078 static int in_debug
;
1081 if (list
->debugging
)
1087 was_debug
= in_debug
;
1090 while (ISSPACE (*line
))
1096 /* The ELF compiler sometimes emits blank lines after switching
1097 out of a debugging section. If the next line drops us back
1098 into debugging information, then don't print the blank line.
1099 This is a hack for a particular compiler behaviour, not a
1103 && list
->next
!= NULL
1104 && list
->next
->debugging
)
1116 if (strncmp (line
, "def", 3) == 0)
1118 if (strncmp (line
, "val", 3) == 0)
1120 if (strncmp (line
, "scl", 3) == 0)
1122 if (strncmp (line
, "line", 4) == 0)
1124 if (strncmp (line
, "endef", 5) == 0)
1126 if (strncmp (line
, "ln", 2) == 0)
1128 if (strncmp (line
, "type", 4) == 0)
1130 if (strncmp (line
, "size", 4) == 0)
1132 if (strncmp (line
, "dim", 3) == 0)
1134 if (strncmp (line
, "tag", 3) == 0)
1136 if (strncmp (line
, "stabs", 5) == 0)
1138 if (strncmp (line
, "stabn", 5) == 0)
1145 listing_listing (char *name ATTRIBUTE_UNUSED
)
1147 list_info_type
*list
= head
;
1148 file_info_type
*current_hll_file
= (file_info_type
*) NULL
;
1152 int show_listing
= 1;
1155 buffer
= (char *) xmalloc (listing_rhs_width
);
1156 data_buffer
= (char *) xmalloc (MAX_BYTES
);
1162 unsigned int list_line
;
1164 width
= listing_rhs_width
> paper_width
? paper_width
:
1167 list_line
= list
->line
;
1168 switch (list
->edict
)
1171 /* Skip all lines up to the current. */
1177 case EDICT_NOLIST_NEXT
:
1178 if (show_listing
== 0)
1186 title
= list
->edict_arg
;
1189 subtitle
= list
->edict_arg
;
1195 if (show_listing
<= 0)
1197 while (list
->file
->linenum
< list_line
1198 && !list
->file
->at_end
)
1199 p
= buffer_line (list
->file
, buffer
, width
);
1202 if (list
->edict
== EDICT_LIST
1203 || (list
->edict
== EDICT_NOLIST_NEXT
&& show_listing
== 0))
1205 /* Enable listing for the single line that caused the enable. */
1210 if (show_listing
> 0)
1212 /* Scan down the list and print all the stuff which can be done
1213 with this line (or lines). */
1217 current_hll_file
= list
->hll_file
;
1219 if (current_hll_file
&& list
->hll_line
&& (listing
& LISTING_HLL
))
1220 print_source (current_hll_file
, list
, width
);
1222 if (list
->line_contents
)
1224 if (!((listing
& LISTING_NODEBUG
)
1225 && debugging_pseudo (list
, list
->line_contents
)))
1227 list
->file
->linenum
== 0 ? list
->line
: list
->file
->linenum
,
1228 list
->line_contents
, calc_hex (list
));
1230 free (list
->line_contents
);
1231 list
->line_contents
= NULL
;
1235 while (list
->file
->linenum
< list_line
1236 && !list
->file
->at_end
)
1238 unsigned int address
;
1240 p
= buffer_line (list
->file
, buffer
, width
);
1242 if (list
->file
->linenum
< list_line
)
1243 address
= ~(unsigned int) 0;
1245 address
= calc_hex (list
);
1247 if (!((listing
& LISTING_NODEBUG
)
1248 && debugging_pseudo (list
, p
)))
1249 print_lines (list
, list
->file
->linenum
, p
, address
);
1253 if (list
->edict
== EDICT_EJECT
)
1257 if (list
->edict
== EDICT_NOLIST_NEXT
&& show_listing
== 1)
1268 /* Print time stamp in ISO format: yyyy-mm-ddThh:mm:ss.ss+/-zzzz. */
1271 print_timestamp (void)
1273 const time_t now
= time (NULL
);
1274 struct tm
* timestamp
;
1275 char stampstr
[MAX_DATELEN
];
1277 /* Any portable way to obtain subsecond values??? */
1278 timestamp
= localtime (&now
);
1279 strftime (stampstr
, MAX_DATELEN
, "%Y-%m-%dT%H:%M:%S.000%z", timestamp
);
1280 fprintf (list_file
, _("\n time stamp \t: %s\n\n"), stampstr
);
1284 print_single_option (char * opt
, int *pos
)
1286 int opt_len
= strlen (opt
);
1288 if ((*pos
+ opt_len
) < paper_width
)
1290 fprintf (list_file
, _("%s "), opt
);
1291 *pos
= *pos
+ opt_len
;
1295 fprintf (list_file
, _("\n\t%s "), opt
);
1300 /* Print options passed to as. */
1303 print_options (char ** argv
)
1305 const char *field_name
= _("\n options passed\t: ");
1306 int pos
= strlen (field_name
);
1309 fputs (field_name
, list_file
);
1310 for (p
= &argv
[1]; *p
!= NULL
; p
++)
1314 if (strcmp (*p
, "-o") == 0)
1320 if (strcmp (*p
, "-v") == 0)
1323 print_single_option (*p
, &pos
);
1327 /* Print a first section with basic info like file names, as version,
1328 options passed, target, and timestamp.
1329 The format of this section is as follows:
1333 fieldname TAB ':' fieldcontents
1334 { TAB fieldcontents-cont } */
1337 listing_general_info (char ** argv
)
1339 /* Print the stuff on the first line. */
1341 listing_page (NULL
);
1344 _(" GNU assembler version %s (%s)\n\t using BFD version %s."),
1345 VERSION
, TARGET_ALIAS
, BFD_VERSION_STRING
);
1346 print_options (argv
);
1347 fprintf (list_file
, _("\n input file \t: %s"), fn
);
1348 fprintf (list_file
, _("\n output file \t: %s"), out_file_name
);
1349 fprintf (list_file
, _("\n target \t: %s"), TARGET_CANONICAL
);
1354 listing_print (char *name
, char **argv
)
1368 list_file
= fopen (name
, FOPEN_WT
);
1369 if (list_file
!= NULL
)
1373 as_warn (_("can't open %s: %s"), name
, xstrerror (errno
));
1379 if (listing
& LISTING_NOFORM
)
1382 if (listing
& LISTING_GENERAL
)
1383 listing_general_info (argv
);
1385 if (listing
& LISTING_LISTING
)
1386 listing_listing (name
);
1388 if (listing
& LISTING_SYMBOLS
)
1389 list_symbol_table ();
1393 if (fclose (list_file
) == EOF
)
1394 as_warn (_("can't close %s: %s"), name
, xstrerror (errno
));
1398 fclose (last_open_file
);
1402 listing_file (const char *name
)
1408 listing_eject (int ignore ATTRIBUTE_UNUSED
)
1411 listing_tail
->edict
= EDICT_EJECT
;
1414 /* Turn listing on or off. An argument of 0 means to turn off
1415 listing. An argument of 1 means to turn on listing. An argument
1416 of 2 means to turn off listing, but as of the next line; that is,
1417 the current line should be listed, but the next line should not. */
1420 listing_list (int on
)
1427 if (listing_tail
->edict
== EDICT_LIST
)
1428 listing_tail
->edict
= EDICT_NONE
;
1430 listing_tail
->edict
= EDICT_NOLIST
;
1433 if (listing_tail
->edict
== EDICT_NOLIST
1434 || listing_tail
->edict
== EDICT_NOLIST_NEXT
)
1435 listing_tail
->edict
= EDICT_NONE
;
1437 listing_tail
->edict
= EDICT_LIST
;
1440 listing_tail
->edict
= EDICT_NOLIST_NEXT
;
1449 listing_psize (int width_only
)
1453 paper_height
= get_absolute_expression ();
1455 if (paper_height
< 0 || paper_height
> 1000)
1458 as_warn (_("strange paper height, set to no form"));
1461 if (*input_line_pointer
!= ',')
1463 demand_empty_rest_of_line ();
1467 ++input_line_pointer
;
1470 paper_width
= get_absolute_expression ();
1472 demand_empty_rest_of_line ();
1476 listing_nopage (int ignore ATTRIBUTE_UNUSED
)
1482 listing_title (int depth
)
1487 unsigned int length
;
1490 if (*input_line_pointer
!= '\"')
1495 ++input_line_pointer
;
1498 start
= input_line_pointer
;
1500 while (*input_line_pointer
)
1503 ? *input_line_pointer
== '\"'
1504 : is_end_of_line
[(unsigned char) *input_line_pointer
])
1508 length
= input_line_pointer
- start
;
1509 ttl
= (char *) xmalloc (length
+ 1);
1510 memcpy (ttl
, start
, length
);
1512 listing_tail
->edict
= depth
? EDICT_SBTTL
: EDICT_TITLE
;
1513 listing_tail
->edict_arg
= ttl
;
1516 input_line_pointer
++;
1517 demand_empty_rest_of_line ();
1520 else if (*input_line_pointer
== '\n')
1522 as_bad (_("new line in title"));
1523 demand_empty_rest_of_line ();
1528 input_line_pointer
++;
1534 listing_source_line (unsigned int line
)
1539 listing_tail
->hll_line
= line
;
1545 listing_source_file (const char *file
)
1548 listing_tail
->hll_file
= file_info (file
);
1553 /* Dummy functions for when compiled without listing enabled. */
1556 listing_list (int on
)
1562 listing_eject (int ignore
)
1568 listing_psize (int ignore
)
1574 listing_nopage (int ignore
)
1580 listing_title (int depth
)
1586 listing_file (const char *name
)
1591 listing_newline (char *name
)
1596 listing_source_line (unsigned int n
)
1601 listing_source_file (const char *n
)