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
;
149 struct list_message
*next
;
152 /* This structure remembers which line from which file goes into which
154 struct list_info_struct
156 /* Frag which this line of source is nearest to. */
159 /* The actual line in the source file. */
162 /* Pointer to the file info struct for the file which this line
164 file_info_type
*file
;
166 /* The expanded text of any macro that may have been executing. */
170 struct list_info_struct
*next
;
172 /* Pointer to the file info struct for the high level language
173 source line that belongs here. */
174 file_info_type
*hll_file
;
176 /* High level language source line. */
177 unsigned int hll_line
;
179 /* Pointers to linked list of messages associated with this line. */
180 struct list_message
*messages
, *last_message
;
182 enum edict_enum edict
;
185 /* Nonzero if this line is to be omitted because it contains
186 debugging information. This can become a flags field if we come
187 up with more information to store here. */
191 typedef struct list_info_struct list_info_type
;
193 int listing_lhs_width
= LISTING_LHS_WIDTH
;
194 int listing_lhs_width_second
= LISTING_LHS_WIDTH_SECOND
;
195 int listing_lhs_cont_lines
= LISTING_LHS_CONT_LINES
;
196 int listing_rhs_width
= LISTING_RHS_WIDTH
;
198 struct list_info_struct
* listing_tail
;
200 static file_info_type
* file_info_head
;
201 static file_info_type
* last_open_file_info
;
202 static FILE * last_open_file
;
203 static struct list_info_struct
* head
;
204 static int paper_width
= 200;
205 static int paper_height
= 60;
209 /* File to output listings to. */
210 static FILE *list_file
;
212 /* This static array is used to keep the text of data to be printed
213 before the start of the line. */
216 (((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width \
217 + ((((LISTING_WORD_SIZE * 2) + 1) * listing_lhs_width_second) \
218 * listing_lhs_cont_lines) \
221 static char *data_buffer
;
224 static void listing_message (const char *, const char *);
225 static file_info_type
*file_info (const char *);
226 static void new_frag (void);
227 static void listing_page (list_info_type
*);
228 static unsigned int calc_hex (list_info_type
*);
229 static void print_lines (list_info_type
*, unsigned int, char *, unsigned int);
230 static void list_symbol_table (void);
231 static int debugging_pseudo (list_info_type
*, const char *);
232 static void listing_listing (char *);
235 listing_message (const char *name
, const char *message
)
237 if (listing_tail
!= (list_info_type
*) NULL
)
239 unsigned int l
= strlen (name
) + strlen (message
) + 1;
240 char *n
= (char *) xmalloc (l
);
241 struct list_message
*lm
= xmalloc (sizeof *lm
);
247 if (listing_tail
->last_message
)
248 listing_tail
->last_message
->next
= lm
;
250 listing_tail
->messages
= lm
;
251 listing_tail
->last_message
= lm
;
256 listing_warning (const char *message
)
258 listing_message (_("Warning:"), message
);
262 listing_error (const char *message
)
264 listing_message (_("Error:"), message
);
267 static file_info_type
*
268 file_info (const char *file_name
)
270 /* Find an entry with this file name. */
271 file_info_type
*p
= file_info_head
;
273 while (p
!= (file_info_type
*) NULL
)
275 if (filename_cmp (p
->filename
, file_name
) == 0)
280 /* Make new entry. */
281 p
= (file_info_type
*) xmalloc (sizeof (file_info_type
));
282 p
->next
= file_info_head
;
284 p
->filename
= xstrdup (file_name
);
295 frag_wane (frag_now
);
300 listing_newline (char *ps
)
304 static unsigned int last_line
= 0xffff;
305 static char *last_file
= NULL
;
306 list_info_type
*new_i
= NULL
;
311 if (now_seg
== absolute_section
)
315 /* In ELF, anything in a section beginning with .debug or .line is
316 considered to be debugging information. This includes the
317 statement which switches us into the debugging section, which we
318 can only set after we are already in the debugging section. */
319 if ((listing
& LISTING_NODEBUG
) != 0
320 && listing_tail
!= NULL
321 && ! listing_tail
->debugging
)
325 segname
= segment_name (now_seg
);
326 if (strncmp (segname
, ".debug", sizeof ".debug" - 1) == 0
327 || strncmp (segname
, ".line", sizeof ".line" - 1) == 0)
328 listing_tail
->debugging
= 1;
332 as_where (&file
, &line
);
335 if (line
== last_line
336 && !(last_file
&& file
&& filename_cmp (file
, last_file
)))
339 new_i
= (list_info_type
*) xmalloc (sizeof (list_info_type
));
341 /* Detect if we are reading from stdin by examining the file
342 name returned by as_where().
344 [FIXME: We rely upon the name in the strcmp below being the
345 same as the one used by input_scrub_new_file(), if that is
346 not true, then this code will fail].
348 If we are reading from stdin, then we need to save each input
349 line here (assuming of course that we actually have a line of
350 input to read), so that it can be displayed in the listing
351 that is produced at the end of the assembly. */
352 if (strcmp (file
, _("{standard input}")) == 0
353 && input_line_pointer
!= NULL
)
360 for (copy
= input_line_pointer
;
362 || is_end_of_line
[(unsigned char) *copy
] != 1);
367 else if (*copy
== '\\')
369 else if (*copy
== '"')
370 seen_quote
= !seen_quote
;
373 len
= copy
- input_line_pointer
+ 1;
375 copy
= (char *) xmalloc (len
);
379 char *src
= input_line_pointer
;
384 unsigned char c
= *src
++;
386 /* Omit control characters in the listing. */
394 new_i
->line_contents
= copy
;
397 new_i
->line_contents
= NULL
;
401 new_i
= (list_info_type
*) xmalloc (sizeof (list_info_type
));
402 new_i
->line_contents
= ps
;
411 listing_tail
->next
= new_i
;
415 listing_tail
= new_i
;
417 new_i
->frag
= frag_now
;
419 new_i
->file
= file_info (file
);
420 new_i
->next
= (list_info_type
*) NULL
;
421 new_i
->messages
= NULL
;
422 new_i
->last_message
= NULL
;
423 new_i
->edict
= EDICT_NONE
;
424 new_i
->hll_file
= (file_info_type
*) NULL
;
426 new_i
->debugging
= 0;
431 /* In ELF, anything in a section beginning with .debug or .line is
432 considered to be debugging information. */
433 if ((listing
& LISTING_NODEBUG
) != 0)
437 segname
= segment_name (now_seg
);
438 if (strncmp (segname
, ".debug", sizeof ".debug" - 1) == 0
439 || strncmp (segname
, ".line", sizeof ".line" - 1) == 0)
440 new_i
->debugging
= 1;
445 /* Attach all current frags to the previous line instead of the
446 current line. This is called by the MIPS backend when it discovers
447 that it needs to add some NOP instructions; the added NOP
448 instructions should go with the instruction that has the delay, not
449 with the new instruction. */
452 listing_prev_line (void)
457 if (head
== (list_info_type
*) NULL
458 || head
== listing_tail
)
463 for (l
= head
; l
->next
!= listing_tail
; l
= l
->next
)
466 for (f
= frchain_now
->frch_root
; f
!= (fragS
*) NULL
; f
= f
->fr_next
)
467 if (f
->line
== listing_tail
)
470 listing_tail
->frag
= frag_now
;
474 /* This function returns the next source line from the file supplied,
475 truncated to size. It appends a fake line to the end of each input
476 file to make using the returned buffer simpler. */
479 buffer_line (file_info_type
*file
, char *line
, unsigned int size
)
481 unsigned int count
= 0;
485 /* If we couldn't open the file, return an empty line. */
489 /* Check the cache and see if we last used this file. */
490 if (!last_open_file_info
|| file
!= last_open_file_info
)
494 last_open_file_info
->pos
= ftell (last_open_file
);
495 fclose (last_open_file
);
498 /* Open the file in the binary mode so that ftell above can
499 return a reliable value that we can feed to fseek below. */
500 last_open_file_info
= file
;
501 last_open_file
= fopen (file
->filename
, FOPEN_RB
);
502 if (last_open_file
== NULL
)
508 /* Seek to where we were last time this file was open. */
510 fseek (last_open_file
, file
->pos
, SEEK_SET
);
513 /* Leave room for null. */
516 c
= fgetc (last_open_file
);
518 while (c
!= EOF
&& c
!= '\n' && c
!= '\r')
524 c
= fgetc (last_open_file
);
527 /* If '\r' is followed by '\n', swallow that. Likewise, if '\n'
528 is followed by '\r', swallow that as well. */
529 if (c
== '\r' || c
== '\n')
531 int next
= fgetc (last_open_file
);
533 if ((c
== '\r' && next
!= '\n')
534 || (c
== '\n' && next
!= '\r'))
535 ungetc (next
, last_open_file
);
541 if (count
+ 2 < size
)
554 /* This function rewinds the requested file back to the line requested,
555 reads it in again into the buffer provided and then restores the file
556 back to its original location. */
559 rebuffer_line (file_info_type
* file
,
560 unsigned int linenum
,
564 unsigned int count
= 0;
565 unsigned int current_line
= 1;
571 if (file
== NULL
|| buffer
== NULL
|| size
== 0 || file
->linenum
<= linenum
)
574 /* Check the cache and see if we last used this file. */
575 if (last_open_file_info
== NULL
|| file
!= last_open_file_info
)
579 last_open_file_info
->pos
= ftell (last_open_file
);
580 fclose (last_open_file
);
583 /* Open the file in the binary mode so that ftell above can
584 return a reliable value that we can feed to fseek below. */
585 last_open_file_info
= file
;
586 last_open_file
= fopen (file
->filename
, FOPEN_RB
);
587 if (last_open_file
== NULL
)
593 /* Seek to where we were last time this file was open. */
595 fseek (last_open_file
, file
->pos
, SEEK_SET
);
598 /* Remember where we are in the current file. */
599 pos
= ftell (last_open_file
);
601 /* Go back to the beginning. */
602 fseek (last_open_file
, 0, SEEK_SET
);
604 /* Skip lines prior to the one we are interested in. */
605 while (current_line
< linenum
)
607 /* fgets only stops on newlines and has a size limit,
608 so we read one character at a time instead. */
611 c
= fgetc (last_open_file
);
613 while (c
!= EOF
&& c
!= '\n' && c
!= '\r');
617 if (c
== '\r' || c
== '\n')
619 int next
= fgetc (last_open_file
);
621 /* If '\r' is followed by '\n', swallow that. Likewise, if '\n'
622 is followed by '\r', swallow that as well. */
623 if ((c
== '\r' && next
!= '\n')
624 || (c
== '\n' && next
!= '\r'))
625 ungetc (next
, last_open_file
);
629 /* Leave room for the nul at the end of the buffer. */
632 /* Read in the line. */
633 c
= fgetc (last_open_file
);
635 while (c
!= EOF
&& c
!= '\n' && c
!= '\r')
641 c
= fgetc (last_open_file
);
644 /* If '\r' is followed by '\n', swallow that. Likewise, if '\n'
645 is followed by '\r', swallow that as well. */
646 if (c
== '\r' || c
== '\n')
648 int next
= fgetc (last_open_file
);
650 if ((c
== '\r' && next
!= '\n')
651 || (c
== '\n' && next
!= '\r'))
652 ungetc (next
, last_open_file
);
655 /* Terminate the line. */
658 /* Reset the file position. */
659 fseek (last_open_file
, pos
, SEEK_SET
);
664 static const char *fn
;
666 static unsigned int eject
; /* Eject pending */
667 static unsigned int page
; /* Current page number */
668 static char *title
; /* Current title */
669 static char *subtitle
; /* Current subtitle */
670 static unsigned int on_page
; /* Number of lines printed on current page */
673 listing_page (list_info_type
*list
)
675 /* Grope around, see if we can see a title or subtitle edict coming up
676 soon. (we look down 10 lines of the page and see if it's there) */
677 if ((eject
|| (on_page
>= (unsigned int) paper_height
))
678 && paper_height
!= 0)
682 int had_subtitle
= 0;
686 while (c
!= 0 && list
)
688 if (list
->edict
== EDICT_SBTTL
&& !had_subtitle
)
691 subtitle
= list
->edict_arg
;
693 if (list
->edict
== EDICT_TITLE
&& !had_title
)
696 title
= list
->edict_arg
;
704 fprintf (list_file
, "\f");
707 fprintf (list_file
, "%s %s \t\t\tpage %d\n", LISTING_HEADER
, fn
, page
);
708 fprintf (list_file
, "%s\n", title
);
709 fprintf (list_file
, "%s\n", subtitle
);
715 /* Print a line into the list_file. Update the line count
716 and if necessary start a new page. */
719 emit_line (list_info_type
* list
, const char * format
, ...)
723 va_start (args
, format
);
725 vfprintf (list_file
, format
, args
);
733 calc_hex (list_info_type
*list
)
735 int data_buffer_size
;
736 list_info_type
*first
= list
;
737 unsigned int address
= ~(unsigned int) 0;
740 unsigned int octet_in_frag
;
742 /* Find first frag which says it belongs to this line. */
744 while (frag
&& frag
->line
!= list
)
745 frag
= frag
->fr_next
;
749 data_buffer_size
= 0;
751 /* Dump all the frags which belong to this line. */
752 while (frag_ptr
!= (fragS
*) NULL
&& frag_ptr
->line
== first
)
754 /* Print as many bytes from the fixed part as is sensible. */
756 while ((offsetT
) octet_in_frag
< frag_ptr
->fr_fix
757 && data_buffer_size
< MAX_BYTES
- 3)
759 if (address
== ~(unsigned int) 0)
760 address
= frag_ptr
->fr_address
/ OCTETS_PER_BYTE
;
762 sprintf (data_buffer
+ data_buffer_size
,
764 (frag_ptr
->fr_literal
[octet_in_frag
]) & 0xff);
765 data_buffer_size
+= 2;
768 if (frag_ptr
->fr_type
== rs_fill
)
770 unsigned int var_rep_max
= octet_in_frag
;
771 unsigned int var_rep_idx
= octet_in_frag
;
773 /* Print as many bytes from the variable part as is sensible. */
774 while (((offsetT
) octet_in_frag
775 < (frag_ptr
->fr_fix
+ frag_ptr
->fr_var
* frag_ptr
->fr_offset
))
776 && data_buffer_size
< MAX_BYTES
- 3)
778 if (address
== ~(unsigned int) 0)
779 address
= frag_ptr
->fr_address
/ OCTETS_PER_BYTE
;
781 sprintf (data_buffer
+ data_buffer_size
,
783 (frag_ptr
->fr_literal
[var_rep_idx
]) & 0xff);
784 data_buffer_size
+= 2;
789 if ((offsetT
) var_rep_idx
>= frag_ptr
->fr_fix
+ frag_ptr
->fr_var
)
790 var_rep_idx
= var_rep_max
;
794 frag_ptr
= frag_ptr
->fr_next
;
796 data_buffer
[data_buffer_size
] = '\0';
801 print_lines (list_info_type
*list
, unsigned int lineno
,
802 char *string
, unsigned int address
)
807 unsigned int octet_in_word
= 0;
808 char *src
= data_buffer
;
810 struct list_message
*msg
;
812 /* Print the stuff on the first line. */
814 nchars
= (LISTING_WORD_SIZE
* 2 + 1) * listing_lhs_width
;
816 /* Print the hex for the first line. */
817 if (address
== ~(unsigned int) 0)
819 fprintf (list_file
, "% 4d ", lineno
);
820 for (idx
= 0; idx
< nchars
; idx
++)
821 fprintf (list_file
, " ");
823 emit_line (NULL
, "\t%s\n", string
? string
: "");
828 fprintf (list_file
, "% 4d ???? ", lineno
);
830 fprintf (list_file
, "% 4d %04x ", lineno
, address
);
832 /* And the data to go along with it. */
835 while (src
[cur
] && idx
< nchars
)
839 fprintf (list_file
, "%c%c", src
[offset
], src
[offset
+ 1]);
843 if (octet_in_word
== LISTING_WORD_SIZE
)
845 fprintf (list_file
, " ");
853 for (; idx
< nchars
; idx
++)
854 fprintf (list_file
, " ");
856 emit_line (list
, "\t%s\n", string
? string
: "");
858 for (msg
= list
->messages
; msg
; msg
= msg
->next
)
859 emit_line (list
, "**** %s\n", msg
->message
);
862 lines
< (unsigned int) listing_lhs_cont_lines
866 nchars
= ((LISTING_WORD_SIZE
* 2) + 1) * listing_lhs_width_second
- 1;
869 /* Print any more lines of data, but more compactly. */
870 fprintf (list_file
, "% 4d ", lineno
);
872 while (src
[cur
] && idx
< nchars
)
876 fprintf (list_file
, "%c%c", src
[offset
], src
[offset
+ 1]);
881 if (octet_in_word
== LISTING_WORD_SIZE
)
883 fprintf (list_file
, " ");
889 emit_line (list
, "\n");
894 list_symbol_table (void)
896 extern symbolS
*symbol_rootP
;
903 for (ptr
= symbol_rootP
; ptr
!= (symbolS
*) NULL
; ptr
= symbol_next (ptr
))
905 if (SEG_NORMAL (S_GET_SEGMENT (ptr
))
906 || S_GET_SEGMENT (ptr
) == absolute_section
)
908 /* Don't report section symbols. They are not interesting. */
909 if (symbol_section_p (ptr
))
912 if (S_GET_NAME (ptr
))
914 char buf
[30], fmt
[8];
915 valueT val
= S_GET_VALUE (ptr
);
917 /* @@ Note that this is dependent on the compilation options,
918 not solely on the target characteristics. */
919 if (sizeof (val
) == 4 && sizeof (int) == 4)
920 sprintf (buf
, "%08lx", (unsigned long) val
);
921 else if (sizeof (val
) <= sizeof (unsigned long))
923 sprintf (fmt
, "%%0%lulx",
924 (unsigned long) (sizeof (val
) * 2));
925 sprintf (buf
, fmt
, (unsigned long) val
);
928 else if (sizeof (val
) > 4)
929 sprintf_vma (buf
, val
);
936 fprintf (list_file
, "DEFINED SYMBOLS\n");
941 if (symbol_get_frag (ptr
) && symbol_get_frag (ptr
)->line
)
943 fprintf (list_file
, "%20s:%-5d %s:%s %s\n",
944 symbol_get_frag (ptr
)->line
->file
->filename
,
945 symbol_get_frag (ptr
)->line
->line
,
946 segment_name (S_GET_SEGMENT (ptr
)),
947 buf
, S_GET_NAME (ptr
));
951 fprintf (list_file
, "%33s:%s %s\n",
952 segment_name (S_GET_SEGMENT (ptr
)),
953 buf
, S_GET_NAME (ptr
));
964 fprintf (list_file
, "NO DEFINED SYMBOLS\n");
967 emit_line (NULL
, "\n");
971 for (ptr
= symbol_rootP
; ptr
!= (symbolS
*) NULL
; ptr
= symbol_next (ptr
))
973 if (S_GET_NAME (ptr
) && strlen (S_GET_NAME (ptr
)) != 0)
975 if (S_GET_SEGMENT (ptr
) == undefined_section
)
981 emit_line (NULL
, "UNDEFINED SYMBOLS\n");
984 emit_line (NULL
, "%s\n", S_GET_NAME (ptr
));
990 emit_line (NULL
, "NO UNDEFINED SYMBOLS\n");
993 typedef struct cached_line
995 file_info_type
* file
;
997 char buffer
[LISTING_RHS_WIDTH
];
1001 print_source (file_info_type
* current_file
,
1002 list_info_type
* list
,
1005 #define NUM_CACHE_LINES 3
1006 static cached_line cached_lines
[NUM_CACHE_LINES
];
1007 static int next_free_line
= 0;
1008 cached_line
* cache
= NULL
;
1010 if (current_file
->linenum
> list
->hll_line
1011 && list
->hll_line
> 0)
1013 /* This can happen with modern optimizing compilers. The source
1014 lines from the high level language input program are split up
1015 and interleaved, meaning the line number we want to display
1016 (list->hll_line) can have already been displayed. We have
1019 a. Do nothing, since we have already displayed the source
1020 line. This was the old behaviour.
1022 b. Display the particular line requested again, but only
1023 that line. This is the new behaviour.
1025 c. Display the particular line requested again and reset
1026 the current_file->line_num value so that we redisplay
1027 all the following lines as well the next time we
1028 encounter a larger line number. */
1031 /* Check the cache, maybe we already have the line saved. */
1032 for (i
= 0; i
< NUM_CACHE_LINES
; i
++)
1033 if (cached_lines
[i
].file
== current_file
1034 && cached_lines
[i
].line
== list
->hll_line
)
1036 cache
= cached_lines
+ i
;
1040 if (i
== NUM_CACHE_LINES
)
1042 cache
= cached_lines
+ next_free_line
;
1044 if (next_free_line
== NUM_CACHE_LINES
)
1047 cache
->file
= current_file
;
1048 cache
->line
= list
->hll_line
;
1049 cache
->buffer
[0] = 0;
1050 rebuffer_line (current_file
, cache
->line
, cache
->buffer
, width
);
1053 emit_line (list
, "%4u:%-13s **** %s\n",
1054 cache
->line
, cache
->file
->filename
, cache
->buffer
);
1058 if (!current_file
->at_end
)
1060 int num_lines_shown
= 0;
1062 while (current_file
->linenum
< list
->hll_line
1063 && !current_file
->at_end
)
1067 cache
= cached_lines
+ next_free_line
;
1068 cache
->file
= current_file
;
1069 cache
->line
= current_file
->linenum
+ 1;
1070 cache
->buffer
[0] = 0;
1071 p
= buffer_line (current_file
, cache
->buffer
, width
);
1073 /* Cache optimization: If printing a group of lines
1074 cache the first and last lines in the group. */
1075 if (num_lines_shown
== 0)
1078 if (next_free_line
== NUM_CACHE_LINES
)
1082 emit_line (list
, "%4u:%-13s **** %s\n",
1083 cache
->line
, cache
->file
->filename
, p
);
1089 /* Sometimes the user doesn't want to be bothered by the debugging
1090 records inserted by the compiler, see if the line is suspicious. */
1093 debugging_pseudo (list_info_type
*list
, const char *line
)
1096 static int in_debug
;
1100 if (list
->debugging
)
1108 was_debug
= in_debug
;
1112 while (ISSPACE (*line
))
1118 /* The ELF compiler sometimes emits blank lines after switching
1119 out of a debugging section. If the next line drops us back
1120 into debugging information, then don't print the blank line.
1121 This is a hack for a particular compiler behaviour, not a
1125 && list
->next
!= NULL
1126 && list
->next
->debugging
)
1138 if (strncmp (line
, "def", 3) == 0)
1140 if (strncmp (line
, "val", 3) == 0)
1142 if (strncmp (line
, "scl", 3) == 0)
1144 if (strncmp (line
, "line", 4) == 0)
1146 if (strncmp (line
, "endef", 5) == 0)
1148 if (strncmp (line
, "ln", 2) == 0)
1150 if (strncmp (line
, "type", 4) == 0)
1152 if (strncmp (line
, "size", 4) == 0)
1154 if (strncmp (line
, "dim", 3) == 0)
1156 if (strncmp (line
, "tag", 3) == 0)
1158 if (strncmp (line
, "stabs", 5) == 0)
1160 if (strncmp (line
, "stabn", 5) == 0)
1167 listing_listing (char *name ATTRIBUTE_UNUSED
)
1169 list_info_type
*list
= head
;
1170 file_info_type
*current_hll_file
= (file_info_type
*) NULL
;
1173 int show_listing
= 1;
1176 buffer
= (char *) xmalloc (listing_rhs_width
);
1177 data_buffer
= (char *) xmalloc (MAX_BYTES
);
1183 unsigned int list_line
;
1185 width
= listing_rhs_width
> paper_width
? paper_width
:
1188 list_line
= list
->line
;
1189 switch (list
->edict
)
1192 /* Skip all lines up to the current. */
1198 case EDICT_NOLIST_NEXT
:
1199 if (show_listing
== 0)
1207 title
= list
->edict_arg
;
1210 subtitle
= list
->edict_arg
;
1216 if (show_listing
<= 0)
1218 while (list
->file
->linenum
< list_line
1219 && !list
->file
->at_end
)
1220 p
= buffer_line (list
->file
, buffer
, width
);
1223 if (list
->edict
== EDICT_LIST
1224 || (list
->edict
== EDICT_NOLIST_NEXT
&& show_listing
== 0))
1226 /* Enable listing for the single line that caused the enable. */
1231 if (show_listing
> 0)
1233 /* Scan down the list and print all the stuff which can be done
1234 with this line (or lines). */
1236 current_hll_file
= list
->hll_file
;
1238 if (current_hll_file
&& list
->hll_line
&& (listing
& LISTING_HLL
))
1239 print_source (current_hll_file
, list
, width
);
1241 if (list
->line_contents
)
1243 if (!((listing
& LISTING_NODEBUG
)
1244 && debugging_pseudo (list
, list
->line_contents
)))
1246 list
->file
->linenum
== 0 ? list
->line
: list
->file
->linenum
,
1247 list
->line_contents
, calc_hex (list
));
1249 free (list
->line_contents
);
1250 list
->line_contents
= NULL
;
1254 while (list
->file
->linenum
< list_line
1255 && !list
->file
->at_end
)
1257 unsigned int address
;
1259 p
= buffer_line (list
->file
, buffer
, width
);
1261 if (list
->file
->linenum
< list_line
)
1262 address
= ~(unsigned int) 0;
1264 address
= calc_hex (list
);
1266 if (!((listing
& LISTING_NODEBUG
)
1267 && debugging_pseudo (list
, p
)))
1268 print_lines (list
, list
->file
->linenum
, p
, address
);
1272 if (list
->edict
== EDICT_EJECT
)
1276 if (list
->edict
== EDICT_NOLIST_NEXT
&& show_listing
== 1)
1287 /* Print time stamp in ISO format: yyyy-mm-ddThh:mm:ss.ss+/-zzzz. */
1290 print_timestamp (void)
1292 const time_t now
= time (NULL
);
1293 struct tm
* timestamp
;
1294 char stampstr
[MAX_DATELEN
];
1296 /* Any portable way to obtain subsecond values??? */
1297 timestamp
= localtime (&now
);
1298 strftime (stampstr
, MAX_DATELEN
, "%Y-%m-%dT%H:%M:%S.000%z", timestamp
);
1299 fprintf (list_file
, _("\n time stamp \t: %s\n\n"), stampstr
);
1303 print_single_option (char * opt
, int *pos
)
1305 int opt_len
= strlen (opt
);
1307 if ((*pos
+ opt_len
) < paper_width
)
1309 fprintf (list_file
, _("%s "), opt
);
1310 *pos
= *pos
+ opt_len
;
1314 fprintf (list_file
, _("\n\t%s "), opt
);
1319 /* Print options passed to as. */
1322 print_options (char ** argv
)
1324 const char *field_name
= _("\n options passed\t: ");
1325 int pos
= strlen (field_name
);
1328 fputs (field_name
, list_file
);
1329 for (p
= &argv
[1]; *p
!= NULL
; p
++)
1333 if (strcmp (*p
, "-o") == 0)
1339 if (strcmp (*p
, "-v") == 0)
1342 print_single_option (*p
, &pos
);
1346 /* Print a first section with basic info like file names, as version,
1347 options passed, target, and timestamp.
1348 The format of this section is as follows:
1352 fieldname TAB ':' fieldcontents
1353 { TAB fieldcontents-cont } */
1356 listing_general_info (char ** argv
)
1358 /* Print the stuff on the first line. */
1360 listing_page (NULL
);
1363 _(" GNU assembler version %s (%s)\n\t using BFD version %s."),
1364 VERSION
, TARGET_ALIAS
, BFD_VERSION_STRING
);
1365 print_options (argv
);
1366 fprintf (list_file
, _("\n input file \t: %s"), fn
);
1367 fprintf (list_file
, _("\n output file \t: %s"), out_file_name
);
1368 fprintf (list_file
, _("\n target \t: %s"), TARGET_CANONICAL
);
1373 listing_print (char *name
, char **argv
)
1387 list_file
= fopen (name
, FOPEN_WT
);
1388 if (list_file
!= NULL
)
1392 as_warn (_("can't open %s: %s"), name
, xstrerror (errno
));
1398 if (listing
& LISTING_NOFORM
)
1401 if (listing
& LISTING_GENERAL
)
1402 listing_general_info (argv
);
1404 if (listing
& LISTING_LISTING
)
1405 listing_listing (name
);
1407 if (listing
& LISTING_SYMBOLS
)
1408 list_symbol_table ();
1412 if (fclose (list_file
) == EOF
)
1413 as_warn (_("can't close %s: %s"), name
, xstrerror (errno
));
1417 fclose (last_open_file
);
1421 listing_file (const char *name
)
1427 listing_eject (int ignore ATTRIBUTE_UNUSED
)
1430 listing_tail
->edict
= EDICT_EJECT
;
1433 /* Turn listing on or off. An argument of 0 means to turn off
1434 listing. An argument of 1 means to turn on listing. An argument
1435 of 2 means to turn off listing, but as of the next line; that is,
1436 the current line should be listed, but the next line should not. */
1439 listing_list (int on
)
1446 if (listing_tail
->edict
== EDICT_LIST
)
1447 listing_tail
->edict
= EDICT_NONE
;
1449 listing_tail
->edict
= EDICT_NOLIST
;
1452 if (listing_tail
->edict
== EDICT_NOLIST
1453 || listing_tail
->edict
== EDICT_NOLIST_NEXT
)
1454 listing_tail
->edict
= EDICT_NONE
;
1456 listing_tail
->edict
= EDICT_LIST
;
1459 listing_tail
->edict
= EDICT_NOLIST_NEXT
;
1468 listing_psize (int width_only
)
1472 paper_height
= get_absolute_expression ();
1474 if (paper_height
< 0 || paper_height
> 1000)
1477 as_warn (_("strange paper height, set to no form"));
1480 if (*input_line_pointer
!= ',')
1482 demand_empty_rest_of_line ();
1486 ++input_line_pointer
;
1489 paper_width
= get_absolute_expression ();
1491 demand_empty_rest_of_line ();
1495 listing_nopage (int ignore ATTRIBUTE_UNUSED
)
1501 listing_title (int depth
)
1506 unsigned int length
;
1509 if (*input_line_pointer
!= '\"')
1514 ++input_line_pointer
;
1517 start
= input_line_pointer
;
1519 while (*input_line_pointer
)
1522 ? *input_line_pointer
== '\"'
1523 : is_end_of_line
[(unsigned char) *input_line_pointer
])
1527 length
= input_line_pointer
- start
;
1528 ttl
= (char *) xmalloc (length
+ 1);
1529 memcpy (ttl
, start
, length
);
1531 listing_tail
->edict
= depth
? EDICT_SBTTL
: EDICT_TITLE
;
1532 listing_tail
->edict_arg
= ttl
;
1535 input_line_pointer
++;
1536 demand_empty_rest_of_line ();
1539 else if (*input_line_pointer
== '\n')
1541 as_bad (_("new line in title"));
1542 demand_empty_rest_of_line ();
1547 input_line_pointer
++;
1553 listing_source_line (unsigned int line
)
1558 listing_tail
->hll_line
= line
;
1564 listing_source_file (const char *file
)
1567 listing_tail
->hll_file
= file_info (file
);
1572 /* Dummy functions for when compiled without listing enabled. */
1575 listing_list (int on
)
1581 listing_eject (int ignore
)
1587 listing_psize (int ignore
)
1593 listing_nopage (int ignore
)
1599 listing_title (int depth
)
1605 listing_file (const char *name
)
1610 listing_newline (char *name
)
1615 listing_source_line (unsigned int n
)
1620 listing_source_file (const char *n
)