1 /* Generic stabs parsing for gas.
2 Copyright (C) 1989, 1990, 1991, 1993 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2,
9 or (at your option) any later version.
11 GAS is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public
17 License along with GAS; see the file COPYING. If not, write
18 to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 /* We need this, despite the apparent object format dependency, since
25 it defines stab types, which all object formats can use now. */
27 #include "aout/stab_gnu.h"
29 /* Allow backends to override the names used for the stab sections. */
30 #ifndef STAB_SECTION_NAME
31 #define STAB_SECTION_NAME ".stab"
34 #ifndef STAB_STRING_SECTION_NAME
35 #define STAB_STRING_SECTION_NAME ".stabstr"
39 * Handle .stabX directives, which used to be open-coded.
40 * So much creeping featurism overloaded the semantics that we decided
41 * to put all .stabX thinking in one place. Here.
43 * We try to make any .stabX directive legal. Other people's AS will often
44 * do assembly-time consistency checks: eg assigning meaning to n_type bits
45 * and "protecting" you from setting them to certain values. (They also zero
46 * certain bits before emitting symbols. Tut tut.)
48 * If an expression is not absolute we either gripe or use the relocation
49 * information. Other people's assemblers silently forget information they
50 * don't need and invent information they need that you didn't supply.
54 * Build a string dictionary entry for a .stabX symbol.
55 * The symbol is added to the .<secname>str section.
58 #ifndef SEPARATE_STAB_SECTIONS
59 #define SEPARATE_STAB_SECTIONS 0
63 get_stab_string_offset (string
, stabstr_secname
)
65 const char *stabstr_secname
;
70 if (! SEPARATE_STAB_SECTIONS
)
74 length
= strlen (string
);
76 { /* Ordinary case. */
84 save_subseg
= now_subseg
;
86 /* Create the stab string section. */
87 newsecname
= xmalloc ((unsigned long) (strlen (stabstr_secname
) + 1));
88 strcpy (newsecname
, stabstr_secname
);
90 seg
= subseg_new (newsecname
, 0);
92 retval
= seg_info (seg
)->stabu
.stab_string_size
;
97 /* Make sure the first string is empty. */
100 retval
= seg_info (seg
)->stabu
.stab_string_size
= 1;
102 bfd_set_section_flags (stdoutput
, seg
, SEC_READONLY
| SEC_DEBUGGING
);
108 p
= frag_more (length
+ 1);
111 seg_info (seg
)->stabu
.stab_string_size
+= length
+ 1;
113 subseg_set (save_seg
, save_subseg
);
120 #ifndef OBJ_PROCESS_STAB
121 #define OBJ_PROCESS_STAB(SEG,W,S,T,O,D) aout_process_stab(W,S,T,O,D)
125 aout_process_stab (what
, string
, type
, other
, desc
)
128 int type
, other
, desc
;
130 /* Put the stab information in the symbol table. */
133 /* Create the symbol now, but only insert it into the symbol chain
134 after any symbols mentioned in the value expression get into the
135 symbol chain. This is to avoid "continuation symbols" (where one
136 ends in "\" and the debug info is continued in the next .stabs
137 directive) from being separated by other random symbols. */
138 symbol
= symbol_create (string
, undefined_section
, 0,
139 (struct frag
*) NULL
);
140 if (what
== 's' || what
== 'n')
142 /* Pick up the value from the input line. */
143 symbol
->sy_frag
= &zero_address_frag
;
148 /* .stabd sets the name to NULL. Why? */
149 S_SET_NAME (symbol
, NULL
);
150 symbol
->sy_frag
= frag_now
;
151 S_SET_VALUE (symbol
, (valueT
) frag_now_fix ());
154 symbol_append (symbol
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
156 S_SET_TYPE (symbol
, type
);
157 S_SET_OTHER (symbol
, other
);
158 S_SET_DESC (symbol
, desc
);
162 /* This can handle different kinds of stabs (s,n,d) and different
163 kinds of stab sections. */
166 s_stab_generic (what
, stab_secname
, stabstr_secname
)
169 char *stabstr_secname
;
177 /* The general format is:
178 .stabs "STRING",TYPE,OTHER,DESC,VALUE
179 .stabn TYPE,OTHER,DESC,VALUE
180 .stabd TYPE,OTHER,DESC
181 At this point input_line_pointer points after the pseudo-op and
182 any trailing whitespace. The argument what is one of 's', 'n' or
183 'd' indicating which type of .stab this is. */
191 string
= demand_copy_C_string (&length
);
193 if (*input_line_pointer
== ',')
194 input_line_pointer
++;
197 as_warn (".stabs: Missing comma");
198 ignore_rest_of_line ();
203 if (get_absolute_expression_and_terminator (&longint
) != ',')
205 as_warn (".stab%c: Missing comma", what
);
206 ignore_rest_of_line ();
211 if (get_absolute_expression_and_terminator (&longint
) != ',')
213 as_warn (".stab%c: Missing comma", what
);
214 ignore_rest_of_line ();
219 desc
= get_absolute_expression ();
220 if (what
== 's' || what
== 'n')
222 if (*input_line_pointer
!= ',')
224 as_warn (".stab%c: Missing comma", what
);
225 ignore_rest_of_line ();
228 input_line_pointer
++;
232 /* We have now gathered the type, other, and desc information. For
233 .stabs or .stabn, input_line_pointer is now pointing at the
236 if (SEPARATE_STAB_SECTIONS
)
237 /* Output the stab information in a separate section. This is used
238 at least for COFF and ELF. */
240 segT saved_seg
= now_seg
;
241 subsegT saved_subseg
= now_subseg
;
242 fragS
*saved_frag
= frag_now
;
248 dot
= frag_now_fix ();
250 seg
= subseg_new (stab_secname
, 0);
252 if (! seg_info (seg
)->hadone
)
255 bfd_set_section_flags (stdoutput
, seg
,
256 SEC_READONLY
| SEC_RELOC
| SEC_DEBUGGING
);
258 #ifdef INIT_STAB_SECTION
259 INIT_STAB_SECTION (seg
);
261 seg_info (seg
)->hadone
= 1;
264 stroff
= get_stab_string_offset (string
, stabstr_secname
);
266 /* At least for now, stabs in a special stab section are always
267 output as 12 byte blocks of information. */
269 md_number_to_chars (p
, (valueT
) stroff
, 4);
270 md_number_to_chars (p
+ 4, (valueT
) type
, 1);
271 md_number_to_chars (p
+ 5, (valueT
) other
, 1);
272 md_number_to_chars (p
+ 6, (valueT
) desc
, 2);
274 if (what
== 's' || what
== 'n')
276 /* Pick up the value from the input line. */
278 input_line_pointer
--;
286 /* Arrange for a value representing the current location. */
287 fake
= FAKE_LABEL_NAME
;
288 symbol
= symbol_new (fake
, saved_seg
, dot
, saved_frag
);
291 exp
.X_add_symbol
= symbol
;
292 exp
.X_add_number
= 0;
297 #ifdef OBJ_PROCESS_STAB
298 OBJ_PROCESS_STAB (seg
, what
, string
+ stroff
, type
, other
, desc
);
301 subseg_set (saved_seg
, saved_subseg
);
305 #ifdef OBJ_PROCESS_STAB
306 OBJ_PROCESS_STAB (0, what
, string
, type
, other
, desc
);
318 listing_source_line ((unsigned int) desc
);
322 listing_source_file (string
);
326 #endif /* ! NO_LISTING */
328 demand_empty_rest_of_line ();
331 /* Regular stab directive. */
337 s_stab_generic (what
, STAB_SECTION_NAME
, STAB_STRING_SECTION_NAME
);
340 /* "Extended stabs", used in Solaris only now. */
347 char *stab_secname
, *stabstr_secname
;
349 stab_secname
= demand_copy_C_string (&length
);
351 if (*input_line_pointer
== ',')
352 input_line_pointer
++;
355 as_bad ("comma missing in .xstabs");
356 ignore_rest_of_line ();
360 /* To get the name of the stab string section, simply add "str" to
361 the stab section name. */
362 stabstr_secname
= (char *) xmalloc (strlen (stab_secname
) + 4);
363 strcpy (stabstr_secname
, stab_secname
);
364 strcat (stabstr_secname
, "str");
365 s_stab_generic (what
, stab_secname
, stabstr_secname
);
366 free (stabstr_secname
);
371 /* Frob invented at RMS' request. Set the n_desc of a symbol. */
383 name
= input_line_pointer
;
384 c
= get_symbol_end ();
385 p
= input_line_pointer
;
388 if (*input_line_pointer
!= ',')
391 as_bad ("Expected comma after name \"%s\"", name
);
393 ignore_rest_of_line ();
397 input_line_pointer
++;
398 temp
= get_absolute_expression ();
400 symbolP
= symbol_find_or_make (name
);
402 S_SET_DESC (symbolP
, temp
);
404 demand_empty_rest_of_line ();
407 #endif /* defined (S_SET_DESC) */
This page took 0.059029 seconds and 4 git commands to generate.