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. */
21 #include "libiberty.h"
25 /* We need this, despite the apparent object format dependency, since
26 it defines stab types, which all object formats can use now. */
28 #include "aout/stab_gnu.h"
30 /* Allow backends to override the names used for the stab sections. */
31 #ifndef STAB_SECTION_NAME
32 #define STAB_SECTION_NAME ".stab"
35 #ifndef STAB_STRING_SECTION_NAME
36 #define STAB_STRING_SECTION_NAME ".stabstr"
40 * Handle .stabX directives, which used to be open-coded.
41 * So much creeping featurism overloaded the semantics that we decided
42 * to put all .stabX thinking in one place. Here.
44 * We try to make any .stabX directive legal. Other people's AS will often
45 * do assembly-time consistency checks: eg assigning meaning to n_type bits
46 * and "protecting" you from setting them to certain values. (They also zero
47 * certain bits before emitting symbols. Tut tut.)
49 * If an expression is not absolute we either gripe or use the relocation
50 * information. Other people's assemblers silently forget information they
51 * don't need and invent information they need that you didn't supply.
55 * Build a string dictionary entry for a .stabX symbol.
56 * The symbol is added to the .<secname>str section.
59 #ifndef SEPARATE_STAB_SECTIONS
60 #define SEPARATE_STAB_SECTIONS 0
64 get_stab_string_offset (string, stabstr_secname)
66 const char *stabstr_secname;
71 if (! SEPARATE_STAB_SECTIONS)
75 length = strlen (string);
77 { /* Ordinary case. */
84 save_subseg = now_subseg;
86 /* Create the stab string section. */
87 seg = subseg_new (stabstr_secname, 0);
89 retval = seg_info (seg)->stabu.stab_string_size;
92 /* Make sure the first string is empty. */
95 retval = seg_info (seg)->stabu.stab_string_size = 1;
97 bfd_set_section_flags (stdoutput, seg, SEC_READONLY | SEC_DEBUGGING);
98 if (seg->name == stabstr_secname)
99 seg->name = xstrdup (stabstr_secname);
103 p = frag_more (length + 1);
106 seg_info (seg)->stabu.stab_string_size += length + 1;
108 subseg_set (save_seg, save_subseg);
115 #ifndef OBJ_PROCESS_STAB
116 #define OBJ_PROCESS_STAB(SEG,W,S,T,O,D) aout_process_stab(W,S,T,O,D)
120 aout_process_stab (what, string, type, other, desc)
123 int type, other, desc;
125 /* Put the stab information in the symbol table. */
128 /* Create the symbol now, but only insert it into the symbol chain
129 after any symbols mentioned in the value expression get into the
130 symbol chain. This is to avoid "continuation symbols" (where one
131 ends in "\" and the debug info is continued in the next .stabs
132 directive) from being separated by other random symbols. */
133 symbol = symbol_create (string, undefined_section, 0,
134 (struct frag *) NULL);
135 if (what == 's' || what == 'n')
137 /* Pick up the value from the input line. */
138 symbol->sy_frag = &zero_address_frag;
143 /* .stabd sets the name to NULL. Why? */
144 S_SET_NAME (symbol, NULL);
145 symbol->sy_frag = frag_now;
146 S_SET_VALUE (symbol, (valueT) frag_now_fix ());
149 symbol_append (symbol, symbol_lastP, &symbol_rootP, &symbol_lastP);
151 S_SET_TYPE (symbol, type);
152 S_SET_OTHER (symbol, other);
153 S_SET_DESC (symbol, desc);
157 /* This can handle different kinds of stabs (s,n,d) and different
158 kinds of stab sections. */
161 s_stab_generic (what, stab_secname, stabstr_secname)
164 char *stabstr_secname;
172 /* The general format is:
173 .stabs "STRING",TYPE,OTHER,DESC,VALUE
174 .stabn TYPE,OTHER,DESC,VALUE
175 .stabd TYPE,OTHER,DESC
176 At this point input_line_pointer points after the pseudo-op and
177 any trailing whitespace. The argument what is one of 's', 'n' or
178 'd' indicating which type of .stab this is. */
186 string = demand_copy_C_string (&length);
188 if (*input_line_pointer == ',')
189 input_line_pointer++;
192 as_warn (".stabs: Missing comma");
193 ignore_rest_of_line ();
198 if (get_absolute_expression_and_terminator (&longint) != ',')
200 as_warn (".stab%c: Missing comma", what);
201 ignore_rest_of_line ();
206 if (get_absolute_expression_and_terminator (&longint) != ',')
208 as_warn (".stab%c: Missing comma", what);
209 ignore_rest_of_line ();
214 desc = get_absolute_expression ();
215 if (what == 's' || what == 'n')
217 if (*input_line_pointer != ',')
219 as_warn (".stab%c: Missing comma", what);
220 ignore_rest_of_line ();
223 input_line_pointer++;
227 /* We have now gathered the type, other, and desc information. For
228 .stabs or .stabn, input_line_pointer is now pointing at the
231 if (SEPARATE_STAB_SECTIONS)
232 /* Output the stab information in a separate section. This is used
233 at least for COFF and ELF. */
235 segT saved_seg = now_seg;
236 subsegT saved_subseg = now_subseg;
237 fragS *saved_frag = frag_now;
243 static segT cached_sec;
244 static char *cached_secname;
246 dot = frag_now_fix ();
248 if (cached_secname && !strcmp (cached_secname, stab_secname))
255 seg = subseg_new (stab_secname, 0);
257 free (cached_secname);
258 cached_secname = xstrdup (stab_secname);
262 if (! seg_info (seg)->hadone)
265 bfd_set_section_flags (stdoutput, seg,
266 SEC_READONLY | SEC_RELOC | SEC_DEBUGGING);
268 #ifdef INIT_STAB_SECTION
269 INIT_STAB_SECTION (seg);
271 seg_info (seg)->hadone = 1;
274 stroff = get_stab_string_offset (string, stabstr_secname);
277 /* release the string */
278 obstack_free (¬es, string);
281 /* At least for now, stabs in a special stab section are always
282 output as 12 byte blocks of information. */
284 md_number_to_chars (p, (valueT) stroff, 4);
285 md_number_to_chars (p + 4, (valueT) type, 1);
286 md_number_to_chars (p + 5, (valueT) other, 1);
287 md_number_to_chars (p + 6, (valueT) desc, 2);
289 if (what == 's' || what == 'n')
291 /* Pick up the value from the input line. */
293 input_line_pointer--;
301 /* Arrange for a value representing the current location. */
302 fake = FAKE_LABEL_NAME;
303 symbol = symbol_new (fake, saved_seg, dot, saved_frag);
306 exp.X_add_symbol = symbol;
307 exp.X_add_number = 0;
312 #ifdef OBJ_PROCESS_STAB
313 OBJ_PROCESS_STAB (seg, what, string + stroff, type, other, desc);
316 subseg_set (saved_seg, saved_subseg);
320 #ifdef OBJ_PROCESS_STAB
321 OBJ_PROCESS_STAB (0, what, string, type, other, desc);
333 listing_source_line ((unsigned int) desc);
337 listing_source_file (string);
341 #endif /* ! NO_LISTING */
343 demand_empty_rest_of_line ();
346 /* Regular stab directive. */
352 s_stab_generic (what, STAB_SECTION_NAME, STAB_STRING_SECTION_NAME);
355 /* "Extended stabs", used in Solaris only now. */
362 char *stab_secname, *stabstr_secname;
363 static char *saved_secname, *saved_strsecname;
365 /* @@ MEMORY LEAK: This allocates a copy of the string, but in most
366 cases it will be the same string, so we could release the storage
367 back to the obstack it came from. */
368 stab_secname = demand_copy_C_string (&length);
370 if (*input_line_pointer == ',')
371 input_line_pointer++;
374 as_bad ("comma missing in .xstabs");
375 ignore_rest_of_line ();
379 /* To get the name of the stab string section, simply add "str" to
380 the stab section name. */
381 if (saved_secname == 0 || strcmp (saved_secname, stab_secname))
383 stabstr_secname = (char *) xmalloc (strlen (stab_secname) + 4);
384 strcpy (stabstr_secname, stab_secname);
385 strcat (stabstr_secname, "str");
388 free (saved_secname);
389 free (saved_strsecname);
391 saved_secname = stab_secname;
392 saved_strsecname = stabstr_secname;
394 s_stab_generic (what, saved_secname, saved_strsecname);
399 /* Frob invented at RMS' request. Set the n_desc of a symbol. */
411 name = input_line_pointer;
412 c = get_symbol_end ();
413 p = input_line_pointer;
416 if (*input_line_pointer != ',')
419 as_bad ("Expected comma after name \"%s\"", name);
421 ignore_rest_of_line ();
425 input_line_pointer++;
426 temp = get_absolute_expression ();
428 symbolP = symbol_find_or_make (name);
430 S_SET_DESC (symbolP, temp);
432 demand_empty_rest_of_line ();
435 #endif /* defined (S_SET_DESC) */