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
93 #include "filenames.h"
95 #include "safe-ctype.h"
96 #include "input-file.h"
104 #ifndef LISTING_HEADER
105 #define LISTING_HEADER "GAS LISTING"
107 #ifndef LISTING_WORD_SIZE
108 #define LISTING_WORD_SIZE 4
110 #ifndef LISTING_LHS_WIDTH
111 #define LISTING_LHS_WIDTH ((LISTING_WORD_SIZE) > 4 ? 1 : 4 / (LISTING_WORD_SIZE))
113 #ifndef LISTING_LHS_WIDTH_SECOND
114 #define LISTING_LHS_WIDTH_SECOND LISTING_LHS_WIDTH
116 #ifndef LISTING_RHS_WIDTH
117 #define LISTING_RHS_WIDTH 100
119 #ifndef LISTING_LHS_CONT_LINES
120 #define LISTING_LHS_CONT_LINES 4
122 #define MAX_DATELEN 30
124 /* This structure remembers which .s were used. */
125 typedef struct file_info_struct
127 struct file_info_struct
* next
;
130 unsigned int linenum
;
146 /* This structure remembers which line from which file goes into which
148 struct list_info_struct
150 /* Frag which this line of source is nearest to. */
153 /* The actual line in the source file. */
156 /* Pointer to the file info struct for the file which this line
158 file_info_type
*file
;
160 /* The expanded text of any macro that may have been executing. */
164 struct list_info_struct
*next
;
166 /* Pointer to the file info struct for the high level language
167 source line that belongs here. */
168 file_info_type
*hll_file
;
170 /* High level language source line. */
171 unsigned int hll_line
;
173 /* Pointer to any error message associated with this line. */
176 enum edict_enum edict
;
179 /* Nonzero if this line is to be omitted because it contains
180 debugging information. This can become a flags field if we come
181 up with more information to store here. */
185 typedef struct list_info_struct list_info_type
;
187 int listing_lhs_width
= LISTING_LHS_WIDTH
;
188 int listing_lhs_width_second
= LISTING_LHS_WIDTH_SECOND
;
189 int listing_lhs_cont_lines
= LISTING_LHS_CONT_LINES
;
190 int listing_rhs_width
= LISTING_RHS_WIDTH
;
192 struct list_info_struct
* listing_tail
;
194 static file_info_type
* file_info_head
;
195 static file_info_type
* last_open_file_info
;
196 static FILE * last_open_file
;
197 static struct list_info_struct
* head
;
198 static int paper_width
= 200;
199 static int paper_height
= 60;
203 /* File to output listings to. */
204 static FILE *list_file
;
206 /* This static array is used to keep the text of data to be printed
207 before the start of the line. */
210 (((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width \
211 + ((((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width_second) \
212 * listing_lhs_cont_lines) \
215 static char *data_buffer
;
218 static void listing_message (const char *, const char *);
219 static file_info_type
*file_info (const char *);
220 static void new_frag (void);
221 static void listing_page (list_info_type
*);
222 static unsigned int calc_hex (list_info_type
*);
223 static void print_lines (list_info_type
*, unsigned int, char *, unsigned int);
224 static void list_symbol_table (void);
225 static int debugging_pseudo (list_info_type
*, const char *);
226 static void listing_listing (char *);
229 listing_message (const char *name
, const char *message
)
231 if (listing_tail
!= (list_info_type
*) NULL
)
233 unsigned int l
= strlen (name
) + strlen (message
) + 1;
234 char *n
= (char *) xmalloc (l
);
237 listing_tail
->message
= n
;
242 listing_warning (const char *message
)
244 listing_message (_("Warning:"), message
);
248 listing_error (const char *message
)
250 listing_message (_("Error:"), message
);
253 static file_info_type
*
254 file_info (const char *file_name
)
256 /* Find an entry with this file name. */
257 file_info_type
*p
= file_info_head
;
259 while (p
!= (file_info_type
*) NULL
)
261 if (filename_cmp (p
->filename
, file_name
) == 0)
266 /* Make new entry. */
267 p
= (file_info_type
*) xmalloc (sizeof (file_info_type
));
268 p
->next
= file_info_head
;
270 p
->filename
= xstrdup (file_name
);
281 frag_wane (frag_now
);
286 listing_newline (char *ps
)
290 static unsigned int last_line
= 0xffff;
291 static char *last_file
= NULL
;
292 list_info_type
*new_i
= NULL
;
297 if (now_seg
== absolute_section
)
301 /* In ELF, anything in a section beginning with .debug or .line is
302 considered to be debugging information. This includes the
303 statement which switches us into the debugging section, which we
304 can only set after we are already in the debugging section. */
305 if ((listing
& LISTING_NODEBUG
) != 0
306 && listing_tail
!= NULL
307 && ! listing_tail
->debugging
)
311 segname
= segment_name (now_seg
);
312 if (strncmp (segname
, ".debug", sizeof ".debug" - 1) == 0
313 || strncmp (segname
, ".line", sizeof ".line" - 1) == 0)
314 listing_tail
->debugging
= 1;
318 as_where (&file
, &line
);
321 if (line
== last_line
322 && !(last_file
&& file
&& filename_cmp (file
, last_file
)))
325 new_i
= (list_info_type
*) xmalloc (sizeof (list_info_type
));
327 /* Detect if we are reading from stdin by examining the file
328 name returned by as_where().
330 [FIXME: We rely upon the name in the strcmp below being the
331 same as the one used by input_scrub_new_file(), if that is
332 not true, then this code will fail].
334 If we are reading from stdin, then we need to save each input
335 line here (assuming of course that we actually have a line of
336 input to read), so that it can be displayed in the listing
337 that is produced at the end of the assembly. */
338 if (strcmp (file
, _("{standard input}")) == 0
339 && input_line_pointer
!= NULL
)
346 for (copy
= input_line_pointer
;
348 || is_end_of_line
[(unsigned char) *copy
] != 1);
353 else if (*copy
== '\\')
355 else if (*copy
== '"')
356 seen_quote
= !seen_quote
;
359 len
= copy
- input_line_pointer
+ 1;
361 copy
= (char *) xmalloc (len
);
365 char *src
= input_line_pointer
;
370 unsigned char c
= *src
++;
372 /* Omit control characters in the listing. */
380 new_i
->line_contents
= copy
;
383 new_i
->line_contents
= NULL
;
387 new_i
= (list_info_type
*) xmalloc (sizeof (list_info_type
));
388 new_i
->line_contents
= ps
;
397 listing_tail
->next
= new_i
;
401 listing_tail
= new_i
;
403 new_i
->frag
= frag_now
;
405 new_i
->file
= file_info (file
);
406 new_i
->next
= (list_info_type
*) NULL
;
407 new_i
->message
= (char *) NULL
;
408 new_i
->edict
= EDICT_NONE
;
409 new_i
->hll_file
= (file_info_type
*) NULL
;
411 new_i
->debugging
= 0;
416 /* In ELF, anything in a section beginning with .debug or .line is
417 considered to be debugging information. */
418 if ((listing
& LISTING_NODEBUG
) != 0)
422 segname
= segment_name (now_seg
);
423 if (strncmp (segname
, ".debug", sizeof ".debug" - 1) == 0
424 || strncmp (segname
, ".line", sizeof ".line" - 1) == 0)
425 new_i
->debugging
= 1;
430 /* Attach all current frags to the previous line instead of the
431 current line. This is called by the MIPS backend when it discovers
432 that it needs to add some NOP instructions; the added NOP
433 instructions should go with the instruction that has the delay, not
434 with the new instruction. */
437 listing_prev_line (void)
442 if (head
== (list_info_type
*) NULL
443 || head
== listing_tail
)
448 for (l
= head
; l
->next
!= listing_tail
; l
= l
->next
)
451 for (f
= frchain_now
->frch_root
; f
!= (fragS
*) NULL
; f
= f
->fr_next
)
452 if (f
->line
== listing_tail
)
455 listing_tail
->frag
= frag_now
;
459 /* This function returns the next source line from the file supplied,
460 truncated to size. It appends a fake line to the end of each input
461 file to make using the returned buffer simpler. */
464 buffer_line (file_info_type
*file
, char *line
, unsigned int size
)
466 unsigned int count
= 0;
470 /* If we couldn't open the file, return an empty line. */
474 /* Check the cache and see if we last used this file. */
475 if (!last_open_file_info
|| file
!= last_open_file_info
)
479 last_open_file_info
->pos
= ftell (last_open_file
);
480 fclose (last_open_file
);
483 /* Open the file in the binary mode so that ftell above can
484 return a reliable value that we can feed to fseek below. */
485 last_open_file_info
= file
;
486 last_open_file
= fopen (file
->filename
, FOPEN_RB
);
487 if (last_open_file
== NULL
)
493 /* Seek to where we were last time this file was open. */
495 fseek (last_open_file
, file
->pos
, SEEK_SET
);
498 /* Leave room for null. */
501 c
= fgetc (last_open_file
);
503 while (c
!= EOF
&& c
!= '\n' && c
!= '\r')
509 c
= fgetc (last_open_file
);
512 /* If '\r' is followed by '\n', swallow that. Likewise, if '\n'
513 is followed by '\r', swallow that as well. */
514 if (c
== '\r' || c
== '\n')
516 int next
= fgetc (last_open_file
);
518 if ((c
== '\r' && next
!= '\n')
519 || (c
== '\n' && next
!= '\r'))
520 ungetc (next
, last_open_file
);
526 if (count
+ 2 < size
)
539 /* This function rewinds the requested file back to the line requested,
540 reads it in again into the buffer provided and then restores the file
541 back to its original location. */
544 rebuffer_line (file_info_type
* file
,
545 unsigned int linenum
,
549 unsigned int count
= 0;
550 unsigned int current_line
= 1;
556 if (file
== NULL
|| buffer
== NULL
|| size
== 0 || file
->linenum
<= linenum
)
559 /* Check the cache and see if we last used this file. */
560 if (last_open_file_info
== NULL
|| file
!= last_open_file_info
)
564 last_open_file_info
->pos
= ftell (last_open_file
);
565 fclose (last_open_file
);
568 /* Open the file in the binary mode so that ftell above can
569 return a reliable value that we can feed to fseek below. */
570 last_open_file_info
= file
;
571 last_open_file
= fopen (file
->filename
, FOPEN_RB
);
572 if (last_open_file
== NULL
)
578 /* Seek to where we were last time this file was open. */
580 fseek (last_open_file
, file
->pos
, SEEK_SET
);
583 /* Remember where we are in the current file. */
584 pos
= ftell (last_open_file
);
586 /* Go back to the beginning. */
587 fseek (last_open_file
, 0, SEEK_SET
);
589 /* Skip lines prior to the one we are interested in. */
590 while (current_line
< linenum
)
592 /* fgets only stops on newlines and has a size limit,
593 so we read one character at a time instead. */
596 c
= fgetc (last_open_file
);
598 while (c
!= EOF
&& c
!= '\n' && c
!= '\r');
602 if (c
== '\r' || c
== '\n')
604 int next
= fgetc (last_open_file
);
606 /* If '\r' is followed by '\n', swallow that. Likewise, if '\n'
607 is followed by '\r', swallow that as well. */
608 if ((c
== '\r' && next
!= '\n')
609 || (c
== '\n' && next
!= '\r'))
610 ungetc (next
, last_open_file
);
614 /* Leave room for the nul at the end of the buffer. */
617 /* Read in the line. */
618 c
= fgetc (last_open_file
);
620 while (c
!= EOF
&& c
!= '\n' && c
!= '\r')
626 c
= fgetc (last_open_file
);
629 /* If '\r' is followed by '\n', swallow that. Likewise, if '\n'
630 is followed by '\r', swallow that as well. */
631 if (c
== '\r' || c
== '\n')
633 int next
= fgetc (last_open_file
);
635 if ((c
== '\r' && next
!= '\n')
636 || (c
== '\n' && next
!= '\r'))
637 ungetc (next
, last_open_file
);
640 /* Terminate the line. */
643 /* Reset the file position. */
644 fseek (last_open_file
, pos
, SEEK_SET
);
649 static const char *fn
;
651 static unsigned int eject
; /* Eject pending */
652 static unsigned int page
; /* Current page number */
653 static char *title
; /* Current title */
654 static char *subtitle
; /* Current subtitle */
655 static unsigned int on_page
; /* Number of lines printed on current page */
658 listing_page (list_info_type
*list
)
660 /* Grope around, see if we can see a title or subtitle edict coming up
661 soon. (we look down 10 lines of the page and see if it's there) */
662 if ((eject
|| (on_page
>= (unsigned int) paper_height
))
663 && paper_height
!= 0)
667 int had_subtitle
= 0;
671 while (c
!= 0 && list
)
673 if (list
->edict
== EDICT_SBTTL
&& !had_subtitle
)
676 subtitle
= list
->edict_arg
;
678 if (list
->edict
== EDICT_TITLE
&& !had_title
)
681 title
= list
->edict_arg
;
689 fprintf (list_file
, "\f");
692 fprintf (list_file
, "%s %s \t\t\tpage %d\n", LISTING_HEADER
, fn
, page
);
693 fprintf (list_file
, "%s\n", title
);
694 fprintf (list_file
, "%s\n", subtitle
);
700 /* Print a line into the list_file. Update the line count
701 and if necessary start a new page. */
704 emit_line (list_info_type
* list
, const char * format
, ...)
708 va_start (args
, format
);
710 vfprintf (list_file
, format
, args
);
718 calc_hex (list_info_type
*list
)
720 int data_buffer_size
;
721 list_info_type
*first
= list
;
722 unsigned int address
= ~(unsigned int) 0;
725 unsigned int octet_in_frag
;
727 /* Find first frag which says it belongs to this line. */
729 while (frag
&& frag
->line
!= list
)
730 frag
= frag
->fr_next
;
734 data_buffer_size
= 0;
736 /* Dump all the frags which belong to this line. */
737 while (frag_ptr
!= (fragS
*) NULL
&& frag_ptr
->line
== first
)
739 /* Print as many bytes from the fixed part as is sensible. */
741 while ((offsetT
) octet_in_frag
< frag_ptr
->fr_fix
742 && data_buffer_size
< MAX_BYTES
- 3)
744 if (address
== ~(unsigned int) 0)
745 address
= frag_ptr
->fr_address
/ OCTETS_PER_BYTE
;
747 sprintf (data_buffer
+ data_buffer_size
,
749 (frag_ptr
->fr_literal
[octet_in_frag
]) & 0xff);
750 data_buffer_size
+= 2;
753 if (frag_ptr
->fr_type
== rs_fill
)
755 unsigned int var_rep_max
= octet_in_frag
;
756 unsigned int var_rep_idx
= octet_in_frag
;
758 /* Print as many bytes from the variable part as is sensible. */
759 while (((offsetT
) octet_in_frag
760 < (frag_ptr
->fr_fix
+ frag_ptr
->fr_var
* frag_ptr
->fr_offset
))
761 && data_buffer_size
< MAX_BYTES
- 3)
763 if (address
== ~(unsigned int) 0)
764 address
= frag_ptr
->fr_address
/ OCTETS_PER_BYTE
;
766 sprintf (data_buffer
+ data_buffer_size
,
768 (frag_ptr
->fr_literal
[var_rep_idx
]) & 0xff);
769 data_buffer_size
+= 2;
774 if ((offsetT
) var_rep_idx
>= frag_ptr
->fr_fix
+ frag_ptr
->fr_var
)
775 var_rep_idx
= var_rep_max
;
779 frag_ptr
= frag_ptr
->fr_next
;
781 data_buffer
[data_buffer_size
] = '\0';
786 print_lines (list_info_type
*list
, unsigned int lineno
,
787 char *string
, unsigned int address
)
792 unsigned int octet_in_word
= 0;
793 char *src
= data_buffer
;
796 /* Print the stuff on the first line. */
798 nchars
= (LISTING_WORD_SIZE
* 2 + 1) * listing_lhs_width
;
800 /* Print the hex for the first line. */
801 if (address
== ~(unsigned int) 0)
803 fprintf (list_file
, "% 4d ", lineno
);
804 for (idx
= 0; idx
< nchars
; idx
++)
805 fprintf (list_file
, " ");
807 emit_line (NULL
, "\t%s\n", string
? string
: "");
812 fprintf (list_file
, "% 4d ???? ", lineno
);
814 fprintf (list_file
, "% 4d %04x ", lineno
, address
);
816 /* And the data to go along with it. */
819 while (src
[cur
] && idx
< nchars
)
823 fprintf (list_file
, "%c%c", src
[offset
], src
[offset
+ 1]);
827 if (octet_in_word
== LISTING_WORD_SIZE
)
829 fprintf (list_file
, " ");
837 for (; idx
< nchars
; idx
++)
838 fprintf (list_file
, " ");
840 emit_line (list
, "\t%s\n", string
? string
: "");
843 emit_line (list
, "**** %s\n", list
->message
);
846 lines
< (unsigned int) listing_lhs_cont_lines
850 nchars
= ((LISTING_WORD_SIZE
* 2) + 1) * listing_lhs_width_second
- 1;
853 /* Print any more lines of data, but more compactly. */
854 fprintf (list_file
, "% 4d ", lineno
);
856 while (src
[cur
] && idx
< nchars
)
860 fprintf (list_file
, "%c%c", src
[offset
], src
[offset
+ 1]);
865 if (octet_in_word
== LISTING_WORD_SIZE
)
867 fprintf (list_file
, " ");
873 emit_line (list
, "\n");
878 list_symbol_table (void)
880 extern symbolS
*symbol_rootP
;
887 for (ptr
= symbol_rootP
; ptr
!= (symbolS
*) NULL
; ptr
= symbol_next (ptr
))
889 if (SEG_NORMAL (S_GET_SEGMENT (ptr
))
890 || S_GET_SEGMENT (ptr
) == absolute_section
)
892 /* Don't report section symbols. They are not interesting. */
893 if (symbol_section_p (ptr
))
896 if (S_GET_NAME (ptr
))
898 char buf
[30], fmt
[8];
899 valueT val
= S_GET_VALUE (ptr
);
901 /* @@ Note that this is dependent on the compilation options,
902 not solely on the target characteristics. */
903 if (sizeof (val
) == 4 && sizeof (int) == 4)
904 sprintf (buf
, "%08lx", (unsigned long) val
);
905 else if (sizeof (val
) <= sizeof (unsigned long))
907 sprintf (fmt
, "%%0%lulx",
908 (unsigned long) (sizeof (val
) * 2));
909 sprintf (buf
, fmt
, (unsigned long) val
);
912 else if (sizeof (val
) > 4)
913 sprintf_vma (buf
, val
);
920 fprintf (list_file
, "DEFINED SYMBOLS\n");
925 if (symbol_get_frag (ptr
) && symbol_get_frag (ptr
)->line
)
927 fprintf (list_file
, "%20s:%-5d %s:%s %s\n",
928 symbol_get_frag (ptr
)->line
->file
->filename
,
929 symbol_get_frag (ptr
)->line
->line
,
930 segment_name (S_GET_SEGMENT (ptr
)),
931 buf
, S_GET_NAME (ptr
));
935 fprintf (list_file
, "%33s:%s %s\n",
936 segment_name (S_GET_SEGMENT (ptr
)),
937 buf
, S_GET_NAME (ptr
));
948 fprintf (list_file
, "NO DEFINED SYMBOLS\n");
951 emit_line (NULL
, "\n");
955 for (ptr
= symbol_rootP
; ptr
!= (symbolS
*) NULL
; ptr
= symbol_next (ptr
))
957 if (S_GET_NAME (ptr
) && strlen (S_GET_NAME (ptr
)) != 0)
959 if (S_GET_SEGMENT (ptr
) == undefined_section
)
965 emit_line (NULL
, "UNDEFINED SYMBOLS\n");
968 emit_line (NULL
, "%s\n", S_GET_NAME (ptr
));
974 emit_line (NULL
, "NO UNDEFINED SYMBOLS\n");
977 typedef struct cached_line
979 file_info_type
* file
;
981 char buffer
[LISTING_RHS_WIDTH
];
985 print_source (file_info_type
* current_file
,
986 list_info_type
* list
,
989 #define NUM_CACHE_LINES 3
990 static cached_line cached_lines
[NUM_CACHE_LINES
];
991 static int next_free_line
= 0;
992 cached_line
* cache
= NULL
;
994 if (current_file
->linenum
> list
->hll_line
995 && list
->hll_line
> 0)
997 /* This can happen with modern optimizing compilers. The source
998 lines from the high level language input program are split up
999 and interleaved, meaning the line number we want to display
1000 (list->hll_line) can have already been displayed. We have
1003 a. Do nothing, since we have already displayed the source
1004 line. This was the old behaviour.
1006 b. Display the particular line requested again, but only
1007 that line. This is the new behaviour.
1009 c. Display the particular line requested again and reset
1010 the current_file->line_num value so that we redisplay
1011 all the following lines as well the next time we
1012 encounter a larger line number. */
1015 /* Check the cache, maybe we already have the line saved. */
1016 for (i
= 0; i
< NUM_CACHE_LINES
; i
++)
1017 if (cached_lines
[i
].file
== current_file
1018 && cached_lines
[i
].line
== list
->hll_line
)
1020 cache
= cached_lines
+ i
;
1024 if (i
== NUM_CACHE_LINES
)
1026 cache
= cached_lines
+ next_free_line
;
1028 if (next_free_line
== NUM_CACHE_LINES
)
1031 cache
->file
= current_file
;
1032 cache
->line
= list
->hll_line
;
1033 cache
->buffer
[0] = 0;
1034 rebuffer_line (current_file
, cache
->line
, cache
->buffer
, width
);
1037 emit_line (list
, "%4u:%-13s **** %s\n",
1038 cache
->line
, cache
->file
->filename
, cache
->buffer
);
1042 if (!current_file
->at_end
)
1044 int num_lines_shown
= 0;
1046 while (current_file
->linenum
< list
->hll_line
1047 && !current_file
->at_end
)
1051 cache
= cached_lines
+ next_free_line
;
1052 cache
->file
= current_file
;
1053 cache
->line
= current_file
->linenum
+ 1;
1054 cache
->buffer
[0] = 0;
1055 p
= buffer_line (current_file
, cache
->buffer
, width
);
1057 /* Cache optimization: If printing a group of lines
1058 cache the first and last lines in the group. */
1059 if (num_lines_shown
== 0)
1062 if (next_free_line
== NUM_CACHE_LINES
)
1066 emit_line (list
, "%4u:%-13s **** %s\n",
1067 cache
->line
, cache
->file
->filename
, p
);
1073 /* Sometimes the user doesn't want to be bothered by the debugging
1074 records inserted by the compiler, see if the line is suspicious. */
1077 debugging_pseudo (list_info_type
*list
, const char *line
)
1080 static int in_debug
;
1084 if (list
->debugging
)
1092 was_debug
= in_debug
;
1096 while (ISSPACE (*line
))
1102 /* The ELF compiler sometimes emits blank lines after switching
1103 out of a debugging section. If the next line drops us back
1104 into debugging information, then don't print the blank line.
1105 This is a hack for a particular compiler behaviour, not a
1109 && list
->next
!= NULL
1110 && list
->next
->debugging
)
1122 if (strncmp (line
, "def", 3) == 0)
1124 if (strncmp (line
, "val", 3) == 0)
1126 if (strncmp (line
, "scl", 3) == 0)
1128 if (strncmp (line
, "line", 4) == 0)
1130 if (strncmp (line
, "endef", 5) == 0)
1132 if (strncmp (line
, "ln", 2) == 0)
1134 if (strncmp (line
, "type", 4) == 0)
1136 if (strncmp (line
, "size", 4) == 0)
1138 if (strncmp (line
, "dim", 3) == 0)
1140 if (strncmp (line
, "tag", 3) == 0)
1142 if (strncmp (line
, "stabs", 5) == 0)
1144 if (strncmp (line
, "stabn", 5) == 0)
1151 listing_listing (char *name ATTRIBUTE_UNUSED
)
1153 list_info_type
*list
= head
;
1154 file_info_type
*current_hll_file
= (file_info_type
*) NULL
;
1157 int show_listing
= 1;
1160 buffer
= (char *) xmalloc (listing_rhs_width
);
1161 data_buffer
= (char *) xmalloc (MAX_BYTES
);
1167 unsigned int list_line
;
1169 width
= listing_rhs_width
> paper_width
? paper_width
:
1172 list_line
= list
->line
;
1173 switch (list
->edict
)
1176 /* Skip all lines up to the current. */
1182 case EDICT_NOLIST_NEXT
:
1183 if (show_listing
== 0)
1191 title
= list
->edict_arg
;
1194 subtitle
= list
->edict_arg
;
1200 if (show_listing
<= 0)
1202 while (list
->file
->linenum
< list_line
1203 && !list
->file
->at_end
)
1204 p
= buffer_line (list
->file
, buffer
, width
);
1207 if (list
->edict
== EDICT_LIST
1208 || (list
->edict
== EDICT_NOLIST_NEXT
&& show_listing
== 0))
1210 /* Enable listing for the single line that caused the enable. */
1215 if (show_listing
> 0)
1217 /* Scan down the list and print all the stuff which can be done
1218 with this line (or lines). */
1220 current_hll_file
= list
->hll_file
;
1222 if (current_hll_file
&& list
->hll_line
&& (listing
& LISTING_HLL
))
1223 print_source (current_hll_file
, list
, width
);
1225 if (list
->line_contents
)
1227 if (!((listing
& LISTING_NODEBUG
)
1228 && debugging_pseudo (list
, list
->line_contents
)))
1230 list
->file
->linenum
== 0 ? list
->line
: list
->file
->linenum
,
1231 list
->line_contents
, calc_hex (list
));
1233 free (list
->line_contents
);
1234 list
->line_contents
= NULL
;
1238 while (list
->file
->linenum
< list_line
1239 && !list
->file
->at_end
)
1241 unsigned int address
;
1243 p
= buffer_line (list
->file
, buffer
, width
);
1245 if (list
->file
->linenum
< list_line
)
1246 address
= ~(unsigned int) 0;
1248 address
= calc_hex (list
);
1250 if (!((listing
& LISTING_NODEBUG
)
1251 && debugging_pseudo (list
, p
)))
1252 print_lines (list
, list
->file
->linenum
, p
, address
);
1256 if (list
->edict
== EDICT_EJECT
)
1260 if (list
->edict
== EDICT_NOLIST_NEXT
&& show_listing
== 1)
1271 /* Print time stamp in ISO format: yyyy-mm-ddThh:mm:ss.ss+/-zzzz. */
1274 print_timestamp (void)
1276 const time_t now
= time (NULL
);
1277 struct tm
* timestamp
;
1278 char stampstr
[MAX_DATELEN
];
1280 /* Any portable way to obtain subsecond values??? */
1281 timestamp
= localtime (&now
);
1282 strftime (stampstr
, MAX_DATELEN
, "%Y-%m-%dT%H:%M:%S.000%z", timestamp
);
1283 fprintf (list_file
, _("\n time stamp \t: %s\n\n"), stampstr
);
1287 print_single_option (char * opt
, int *pos
)
1289 int opt_len
= strlen (opt
);
1291 if ((*pos
+ opt_len
) < paper_width
)
1293 fprintf (list_file
, _("%s "), opt
);
1294 *pos
= *pos
+ opt_len
;
1298 fprintf (list_file
, _("\n\t%s "), opt
);
1303 /* Print options passed to as. */
1306 print_options (char ** argv
)
1308 const char *field_name
= _("\n options passed\t: ");
1309 int pos
= strlen (field_name
);
1312 fputs (field_name
, list_file
);
1313 for (p
= &argv
[1]; *p
!= NULL
; p
++)
1317 if (strcmp (*p
, "-o") == 0)
1323 if (strcmp (*p
, "-v") == 0)
1326 print_single_option (*p
, &pos
);
1330 /* Print a first section with basic info like file names, as version,
1331 options passed, target, and timestamp.
1332 The format of this section is as follows:
1336 fieldname TAB ':' fieldcontents
1337 { TAB fieldcontents-cont } */
1340 listing_general_info (char ** argv
)
1342 /* Print the stuff on the first line. */
1344 listing_page (NULL
);
1347 _(" GNU assembler version %s (%s)\n\t using BFD version %s."),
1348 VERSION
, TARGET_ALIAS
, BFD_VERSION_STRING
);
1349 print_options (argv
);
1350 fprintf (list_file
, _("\n input file \t: %s"), fn
);
1351 fprintf (list_file
, _("\n output file \t: %s"), out_file_name
);
1352 fprintf (list_file
, _("\n target \t: %s"), TARGET_CANONICAL
);
1357 listing_print (char *name
, char **argv
)
1371 list_file
= fopen (name
, FOPEN_WT
);
1372 if (list_file
!= NULL
)
1376 as_warn (_("can't open %s: %s"), name
, xstrerror (errno
));
1382 if (listing
& LISTING_NOFORM
)
1385 if (listing
& LISTING_GENERAL
)
1386 listing_general_info (argv
);
1388 if (listing
& LISTING_LISTING
)
1389 listing_listing (name
);
1391 if (listing
& LISTING_SYMBOLS
)
1392 list_symbol_table ();
1396 if (fclose (list_file
) == EOF
)
1397 as_warn (_("can't close %s: %s"), name
, xstrerror (errno
));
1401 fclose (last_open_file
);
1405 listing_file (const char *name
)
1411 listing_eject (int ignore ATTRIBUTE_UNUSED
)
1414 listing_tail
->edict
= EDICT_EJECT
;
1417 /* Turn listing on or off. An argument of 0 means to turn off
1418 listing. An argument of 1 means to turn on listing. An argument
1419 of 2 means to turn off listing, but as of the next line; that is,
1420 the current line should be listed, but the next line should not. */
1423 listing_list (int on
)
1430 if (listing_tail
->edict
== EDICT_LIST
)
1431 listing_tail
->edict
= EDICT_NONE
;
1433 listing_tail
->edict
= EDICT_NOLIST
;
1436 if (listing_tail
->edict
== EDICT_NOLIST
1437 || listing_tail
->edict
== EDICT_NOLIST_NEXT
)
1438 listing_tail
->edict
= EDICT_NONE
;
1440 listing_tail
->edict
= EDICT_LIST
;
1443 listing_tail
->edict
= EDICT_NOLIST_NEXT
;
1452 listing_psize (int width_only
)
1456 paper_height
= get_absolute_expression ();
1458 if (paper_height
< 0 || paper_height
> 1000)
1461 as_warn (_("strange paper height, set to no form"));
1464 if (*input_line_pointer
!= ',')
1466 demand_empty_rest_of_line ();
1470 ++input_line_pointer
;
1473 paper_width
= get_absolute_expression ();
1475 demand_empty_rest_of_line ();
1479 listing_nopage (int ignore ATTRIBUTE_UNUSED
)
1485 listing_title (int depth
)
1490 unsigned int length
;
1493 if (*input_line_pointer
!= '\"')
1498 ++input_line_pointer
;
1501 start
= input_line_pointer
;
1503 while (*input_line_pointer
)
1506 ? *input_line_pointer
== '\"'
1507 : is_end_of_line
[(unsigned char) *input_line_pointer
])
1511 length
= input_line_pointer
- start
;
1512 ttl
= (char *) xmalloc (length
+ 1);
1513 memcpy (ttl
, start
, length
);
1515 listing_tail
->edict
= depth
? EDICT_SBTTL
: EDICT_TITLE
;
1516 listing_tail
->edict_arg
= ttl
;
1519 input_line_pointer
++;
1520 demand_empty_rest_of_line ();
1523 else if (*input_line_pointer
== '\n')
1525 as_bad (_("new line in title"));
1526 demand_empty_rest_of_line ();
1531 input_line_pointer
++;
1537 listing_source_line (unsigned int line
)
1542 listing_tail
->hll_line
= line
;
1548 listing_source_file (const char *file
)
1551 listing_tail
->hll_file
= file_info (file
);
1556 /* Dummy functions for when compiled without listing enabled. */
1559 listing_list (int on
)
1565 listing_eject (int ignore
)
1571 listing_psize (int ignore
)
1577 listing_nopage (int ignore
)
1583 listing_title (int depth
)
1589 listing_file (const char *name
)
1594 listing_newline (char *name
)
1599 listing_source_line (unsigned int n
)
1604 listing_source_file (const char *n
)