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++;
229 /* Solaris on PowerPC has decided that .stabd takes 4 arguments, so emulate it. */
230 else if (what == 'd')
232 char *save_location = input_line_pointer;
235 if (*input_line_pointer == ',')
239 input_line_pointer++;
242 dummy = get_absolute_expression ();
245 as_warn (".stabd: Fourth field must be 0");
246 ignore_rest_of_line ();
252 input_line_pointer = save_location;
263 listing_source_line ((unsigned int) desc);
267 listing_source_file (string);
271 #endif /* ! NO_LISTING */
273 /* We have now gathered the type, other, and desc information. For
274 .stabs or .stabn, input_line_pointer is now pointing at the
277 if (SEPARATE_STAB_SECTIONS)
278 /* Output the stab information in a separate section. This is used
279 at least for COFF and ELF. */
281 segT saved_seg = now_seg;
282 subsegT saved_subseg = now_subseg;
283 fragS *saved_frag = frag_now;
289 static segT cached_sec;
290 static char *cached_secname;
292 dot = frag_now_fix ();
294 if (cached_secname && !strcmp (cached_secname, stab_secname))
301 seg = subseg_new (stab_secname, 0);
303 free (cached_secname);
304 cached_secname = xstrdup (stab_secname);
308 if (! seg_info (seg)->hadone)
311 bfd_set_section_flags (stdoutput, seg,
312 SEC_READONLY | SEC_RELOC | SEC_DEBUGGING);
314 #ifdef INIT_STAB_SECTION
315 INIT_STAB_SECTION (seg);
317 seg_info (seg)->hadone = 1;
320 stroff = get_stab_string_offset (string, stabstr_secname);
323 /* release the string */
324 obstack_free (¬es, string);
327 /* At least for now, stabs in a special stab section are always
328 output as 12 byte blocks of information. */
330 md_number_to_chars (p, (valueT) stroff, 4);
331 md_number_to_chars (p + 4, (valueT) type, 1);
332 md_number_to_chars (p + 5, (valueT) other, 1);
333 md_number_to_chars (p + 6, (valueT) desc, 2);
335 if (what == 's' || what == 'n')
337 /* Pick up the value from the input line. */
339 input_line_pointer--;
347 /* Arrange for a value representing the current location. */
348 fake = FAKE_LABEL_NAME;
349 symbol = symbol_new (fake, saved_seg, dot, saved_frag);
352 exp.X_add_symbol = symbol;
353 exp.X_add_number = 0;
358 #ifdef OBJ_PROCESS_STAB
359 OBJ_PROCESS_STAB (seg, what, string, type, other, desc);
362 subseg_set (saved_seg, saved_subseg);
366 #ifdef OBJ_PROCESS_STAB
367 OBJ_PROCESS_STAB (0, what, string, type, other, desc);
373 demand_empty_rest_of_line ();
376 /* Regular stab directive. */
382 s_stab_generic (what, STAB_SECTION_NAME, STAB_STRING_SECTION_NAME);
385 /* "Extended stabs", used in Solaris only now. */
392 char *stab_secname, *stabstr_secname;
393 static char *saved_secname, *saved_strsecname;
395 /* @@ MEMORY LEAK: This allocates a copy of the string, but in most
396 cases it will be the same string, so we could release the storage
397 back to the obstack it came from. */
398 stab_secname = demand_copy_C_string (&length);
400 if (*input_line_pointer == ',')
401 input_line_pointer++;
404 as_bad ("comma missing in .xstabs");
405 ignore_rest_of_line ();
409 /* To get the name of the stab string section, simply add "str" to
410 the stab section name. */
411 if (saved_secname == 0 || strcmp (saved_secname, stab_secname))
413 stabstr_secname = (char *) xmalloc (strlen (stab_secname) + 4);
414 strcpy (stabstr_secname, stab_secname);
415 strcat (stabstr_secname, "str");
418 free (saved_secname);
419 free (saved_strsecname);
421 saved_secname = stab_secname;
422 saved_strsecname = stabstr_secname;
424 s_stab_generic (what, saved_secname, saved_strsecname);
429 /* Frob invented at RMS' request. Set the n_desc of a symbol. */
441 name = input_line_pointer;
442 c = get_symbol_end ();
443 p = input_line_pointer;
446 if (*input_line_pointer != ',')
449 as_bad ("Expected comma after name \"%s\"", name);
451 ignore_rest_of_line ();
455 input_line_pointer++;
456 temp = get_absolute_expression ();
458 symbolP = symbol_find_or_make (name);
460 S_SET_DESC (symbolP, temp);
462 demand_empty_rest_of_line ();
465 #endif /* defined (S_SET_DESC) */