]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* Generic stabs parsing for gas. |
a2c58332 | 2 | Copyright (C) 1989-2022 Free Software Foundation, Inc. |
252b5132 | 3 | |
ec2655a6 | 4 | This file is part of GAS, the GNU Assembler. |
252b5132 | 5 | |
ec2655a6 NC |
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 3, | |
9 | or (at your option) any later version. | |
252b5132 | 10 | |
ec2655a6 NC |
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. | |
252b5132 | 15 | |
ec2655a6 NC |
16 | You should have received a copy of the GNU General Public License |
17 | along with GAS; see the file COPYING. If not, write to the Free | |
18 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA | |
19 | 02110-1301, USA. */ | |
252b5132 RH |
20 | |
21 | #include "as.h" | |
8b6efd89 | 22 | #include "filenames.h" |
252b5132 RH |
23 | #include "obstack.h" |
24 | #include "subsegs.h" | |
25 | #include "ecoff.h" | |
26 | ||
27 | /* We need this, despite the apparent object format dependency, since | |
f0e652b4 | 28 | it defines stab types, which all object formats can use now. */ |
252b5132 RH |
29 | |
30 | #include "aout/stab_gnu.h" | |
31 | ||
bccba5f0 NC |
32 | /* Holds whether the assembler is generating stabs line debugging |
33 | information or not. Potentially used by md_cleanup function. */ | |
34 | ||
92eb7b32 | 35 | int outputting_stabs_line_debug = 0; |
bccba5f0 | 36 | |
3b4dbbbf | 37 | static void generate_asm_file (int, const char *); |
252b5132 RH |
38 | |
39 | /* Allow backends to override the names used for the stab sections. */ | |
40 | #ifndef STAB_SECTION_NAME | |
41 | #define STAB_SECTION_NAME ".stab" | |
42 | #endif | |
43 | ||
44 | #ifndef STAB_STRING_SECTION_NAME | |
45 | #define STAB_STRING_SECTION_NAME ".stabstr" | |
46 | #endif | |
47 | ||
1181551e | 48 | /* True if we're in the middle of a .func function, in which case |
252b5132 RH |
49 | stabs_generate_asm_lineno emits function relative line number stabs. |
50 | Otherwise it emits line number stabs with absolute addresses. Note that | |
51 | both cases only apply to assembler code assembled with -gstabs. */ | |
5b7c81bd | 52 | static bool in_dot_func_p = false; |
252b5132 | 53 | |
1181551e | 54 | /* Label at start of current function if in_dot_func_p != FALSE. */ |
252b5132 RH |
55 | static const char *current_function_label; |
56 | ||
57 | /* | |
58 | * Handle .stabX directives, which used to be open-coded. | |
59 | * So much creeping featurism overloaded the semantics that we decided | |
60 | * to put all .stabX thinking in one place. Here. | |
61 | * | |
62 | * We try to make any .stabX directive legal. Other people's AS will often | |
63 | * do assembly-time consistency checks: eg assigning meaning to n_type bits | |
64 | * and "protecting" you from setting them to certain values. (They also zero | |
65 | * certain bits before emitting symbols. Tut tut.) | |
66 | * | |
67 | * If an expression is not absolute we either gripe or use the relocation | |
68 | * information. Other people's assemblers silently forget information they | |
69 | * don't need and invent information they need that you didn't supply. | |
70 | */ | |
71 | ||
72 | /* | |
73 | * Build a string dictionary entry for a .stabX symbol. | |
74 | * The symbol is added to the .<secname>str section. | |
75 | */ | |
76 | ||
77 | #ifndef SEPARATE_STAB_SECTIONS | |
78 | #define SEPARATE_STAB_SECTIONS 0 | |
79 | #endif | |
80 | ||
81 | unsigned int | |
0acc7632 | 82 | get_stab_string_offset (const char *string, const char *stabstr_secname, |
5b7c81bd | 83 | bool free_stabstr_secname) |
252b5132 RH |
84 | { |
85 | unsigned int length; | |
86 | unsigned int retval; | |
87 | segT save_seg; | |
88 | subsegT save_subseg; | |
89 | segT seg; | |
90 | char *p; | |
91 | ||
92 | if (! SEPARATE_STAB_SECTIONS) | |
93 | abort (); | |
94 | ||
95 | length = strlen (string); | |
96 | ||
97 | save_seg = now_seg; | |
98 | save_subseg = now_subseg; | |
99 | ||
0acc7632 | 100 | /* Create the stab string section, if it doesn't already exist. */ |
252b5132 | 101 | seg = subseg_new (stabstr_secname, 0); |
0acc7632 AM |
102 | if (free_stabstr_secname && seg->name != stabstr_secname) |
103 | free ((char *) stabstr_secname); | |
252b5132 RH |
104 | |
105 | retval = seg_info (seg)->stabu.stab_string_size; | |
106 | if (retval <= 0) | |
107 | { | |
108 | /* Make sure the first string is empty. */ | |
109 | p = frag_more (1); | |
110 | *p = 0; | |
111 | retval = seg_info (seg)->stabu.stab_string_size = 1; | |
fd361982 | 112 | bfd_set_section_flags (seg, SEC_READONLY | SEC_DEBUGGING); |
252b5132 RH |
113 | } |
114 | ||
115 | if (length > 0) | |
f0e652b4 | 116 | { /* Ordinary case. */ |
252b5132 RH |
117 | p = frag_more (length + 1); |
118 | strcpy (p, string); | |
119 | ||
120 | seg_info (seg)->stabu.stab_string_size += length + 1; | |
121 | } | |
122 | else | |
123 | retval = 0; | |
124 | ||
125 | subseg_set (save_seg, save_subseg); | |
126 | ||
127 | return retval; | |
128 | } | |
129 | ||
130 | #ifdef AOUT_STABS | |
131 | #ifndef OBJ_PROCESS_STAB | |
132 | #define OBJ_PROCESS_STAB(SEG,W,S,T,O,D) aout_process_stab(W,S,T,O,D) | |
133 | #endif | |
134 | ||
0aa5d426 HPN |
135 | /* Here instead of obj-aout.c because other formats use it too. */ |
136 | void | |
e046cf80 | 137 | aout_process_stab (int what, const char *string, int type, int other, int desc) |
252b5132 RH |
138 | { |
139 | /* Put the stab information in the symbol table. */ | |
140 | symbolS *symbol; | |
141 | ||
142 | /* Create the symbol now, but only insert it into the symbol chain | |
143 | after any symbols mentioned in the value expression get into the | |
144 | symbol chain. This is to avoid "continuation symbols" (where one | |
145 | ends in "\" and the debug info is continued in the next .stabs | |
146 | directive) from being separated by other random symbols. */ | |
e01e1cee | 147 | symbol = symbol_create (string, undefined_section, &zero_address_frag, 0); |
252b5132 RH |
148 | if (what == 's' || what == 'n') |
149 | { | |
150 | /* Pick up the value from the input line. */ | |
252b5132 RH |
151 | pseudo_set (symbol); |
152 | } | |
153 | else | |
154 | { | |
155 | /* .stabd sets the name to NULL. Why? */ | |
156 | S_SET_NAME (symbol, NULL); | |
49309057 | 157 | symbol_set_frag (symbol, frag_now); |
252b5132 RH |
158 | S_SET_VALUE (symbol, (valueT) frag_now_fix ()); |
159 | } | |
160 | ||
161 | symbol_append (symbol, symbol_lastP, &symbol_rootP, &symbol_lastP); | |
162 | ||
df98fa7d AM |
163 | symbol_get_bfdsym (symbol)->flags |= BSF_DEBUGGING; |
164 | ||
252b5132 RH |
165 | S_SET_TYPE (symbol, type); |
166 | S_SET_OTHER (symbol, other); | |
167 | S_SET_DESC (symbol, desc); | |
168 | } | |
169 | #endif | |
170 | ||
171 | /* This can handle different kinds of stabs (s,n,d) and different | |
0acc7632 AM |
172 | kinds of stab sections. If STAB_SECNAME_OBSTACK_END is non-NULL, |
173 | then STAB_SECNAME and STABSTR_SECNAME will be freed if possible | |
174 | before this function returns (the former by obstack_free). */ | |
252b5132 | 175 | |
f0e652b4 | 176 | static void |
0acc7632 AM |
177 | s_stab_generic (int what, |
178 | const char *stab_secname, | |
179 | const char *stabstr_secname, | |
180 | const char *stab_secname_obstack_end) | |
252b5132 RH |
181 | { |
182 | long longint; | |
b37283a6 NC |
183 | const char *string; |
184 | char *saved_string_obstack_end; | |
252b5132 RH |
185 | int type; |
186 | int other; | |
187 | int desc; | |
188 | ||
189 | /* The general format is: | |
190 | .stabs "STRING",TYPE,OTHER,DESC,VALUE | |
191 | .stabn TYPE,OTHER,DESC,VALUE | |
192 | .stabd TYPE,OTHER,DESC | |
193 | At this point input_line_pointer points after the pseudo-op and | |
194 | any trailing whitespace. The argument what is one of 's', 'n' or | |
195 | 'd' indicating which type of .stab this is. */ | |
196 | ||
197 | if (what != 's') | |
d68d4570 DD |
198 | { |
199 | string = ""; | |
200 | saved_string_obstack_end = 0; | |
201 | } | |
252b5132 RH |
202 | else |
203 | { | |
204 | int length; | |
205 | ||
206 | string = demand_copy_C_string (&length); | |
c77852c8 NC |
207 | if (string == NULL) |
208 | { | |
209 | as_warn (_(".stab%c: missing string"), what); | |
210 | ignore_rest_of_line (); | |
211 | return; | |
212 | } | |
d68d4570 DD |
213 | /* FIXME: We should probably find some other temporary storage |
214 | for string, rather than leaking memory if someone else | |
215 | happens to use the notes obstack. */ | |
0acc7632 | 216 | saved_string_obstack_end = obstack_next_free (¬es); |
252b5132 RH |
217 | SKIP_WHITESPACE (); |
218 | if (*input_line_pointer == ',') | |
219 | input_line_pointer++; | |
220 | else | |
221 | { | |
0e389e77 | 222 | as_warn (_(".stab%c: missing comma"), what); |
252b5132 RH |
223 | ignore_rest_of_line (); |
224 | return; | |
225 | } | |
226 | } | |
227 | ||
228 | if (get_absolute_expression_and_terminator (&longint) != ',') | |
229 | { | |
0e389e77 | 230 | as_warn (_(".stab%c: missing comma"), what); |
252b5132 RH |
231 | ignore_rest_of_line (); |
232 | return; | |
233 | } | |
234 | type = longint; | |
235 | ||
236 | if (get_absolute_expression_and_terminator (&longint) != ',') | |
237 | { | |
0e389e77 | 238 | as_warn (_(".stab%c: missing comma"), what); |
252b5132 RH |
239 | ignore_rest_of_line (); |
240 | return; | |
241 | } | |
242 | other = longint; | |
243 | ||
244 | desc = get_absolute_expression (); | |
6360824b NC |
245 | |
246 | if ((desc > 0xffff) || (desc < -0x8000)) | |
247 | /* This could happen for example with a source file with a huge | |
248 | number of lines. The only cure is to use a different debug | |
249 | format, probably DWARF. */ | |
7193a0e7 | 250 | as_warn (_(".stab%c: description field '%x' too big, try a different debug format"), |
6360824b | 251 | what, desc); |
411863a4 | 252 | |
252b5132 RH |
253 | if (what == 's' || what == 'n') |
254 | { | |
255 | if (*input_line_pointer != ',') | |
256 | { | |
0e389e77 | 257 | as_warn (_(".stab%c: missing comma"), what); |
252b5132 RH |
258 | ignore_rest_of_line (); |
259 | return; | |
260 | } | |
261 | input_line_pointer++; | |
262 | SKIP_WHITESPACE (); | |
263 | } | |
264 | ||
265 | #ifdef TC_PPC | |
266 | #ifdef OBJ_ELF | |
267 | /* Solaris on PowerPC has decided that .stabd can take 4 arguments, so if we were | |
268 | given 4 arguments, make it a .stabn */ | |
269 | else if (what == 'd') | |
270 | { | |
271 | char *save_location = input_line_pointer; | |
272 | ||
273 | SKIP_WHITESPACE (); | |
274 | if (*input_line_pointer == ',') | |
275 | { | |
276 | input_line_pointer++; | |
277 | what = 'n'; | |
278 | } | |
279 | else | |
280 | input_line_pointer = save_location; | |
281 | } | |
282 | #endif /* OBJ_ELF */ | |
283 | #endif /* TC_PPC */ | |
284 | ||
285 | #ifndef NO_LISTING | |
286 | if (listing) | |
287 | { | |
288 | switch (type) | |
289 | { | |
290 | case N_SLINE: | |
291 | listing_source_line ((unsigned int) desc); | |
292 | break; | |
293 | case N_SO: | |
294 | case N_SOL: | |
295 | listing_source_file (string); | |
296 | break; | |
297 | } | |
298 | } | |
299 | #endif /* ! NO_LISTING */ | |
300 | ||
301 | /* We have now gathered the type, other, and desc information. For | |
302 | .stabs or .stabn, input_line_pointer is now pointing at the | |
303 | value. */ | |
304 | ||
305 | if (SEPARATE_STAB_SECTIONS) | |
306 | /* Output the stab information in a separate section. This is used | |
307 | at least for COFF and ELF. */ | |
308 | { | |
309 | segT saved_seg = now_seg; | |
310 | subsegT saved_subseg = now_subseg; | |
311 | fragS *saved_frag = frag_now; | |
312 | valueT dot; | |
313 | segT seg; | |
314 | unsigned int stroff; | |
315 | char *p; | |
316 | ||
317 | static segT cached_sec; | |
252b5132 RH |
318 | |
319 | dot = frag_now_fix (); | |
320 | ||
321 | #ifdef md_flush_pending_output | |
322 | md_flush_pending_output (); | |
323 | #endif | |
324 | ||
0acc7632 | 325 | if (cached_sec && strcmp (cached_sec->name, stab_secname) == 0) |
252b5132 RH |
326 | { |
327 | seg = cached_sec; | |
328 | subseg_set (seg, 0); | |
329 | } | |
330 | else | |
331 | { | |
332 | seg = subseg_new (stab_secname, 0); | |
252b5132 RH |
333 | cached_sec = seg; |
334 | } | |
335 | ||
336 | if (! seg_info (seg)->hadone) | |
337 | { | |
fd361982 | 338 | bfd_set_section_flags (seg, |
252b5132 | 339 | SEC_READONLY | SEC_RELOC | SEC_DEBUGGING); |
252b5132 RH |
340 | #ifdef INIT_STAB_SECTION |
341 | INIT_STAB_SECTION (seg); | |
342 | #endif | |
343 | seg_info (seg)->hadone = 1; | |
344 | } | |
345 | ||
0acc7632 AM |
346 | stroff = get_stab_string_offset (string, stabstr_secname, |
347 | stab_secname_obstack_end != NULL); | |
348 | ||
349 | /* Release the string, if nobody else has used the obstack. */ | |
350 | if (saved_string_obstack_end != NULL | |
351 | && saved_string_obstack_end == obstack_next_free (¬es)) | |
352 | obstack_free (¬es, string); | |
353 | /* Similarly for the section name. This must be done before | |
354 | creating symbols below, which uses the notes obstack. */ | |
355 | if (seg->name != stab_secname | |
356 | && stab_secname_obstack_end != NULL | |
357 | && stab_secname_obstack_end == obstack_next_free (¬es)) | |
358 | obstack_free (¬es, stab_secname); | |
252b5132 RH |
359 | |
360 | /* At least for now, stabs in a special stab section are always | |
361 | output as 12 byte blocks of information. */ | |
362 | p = frag_more (8); | |
363 | md_number_to_chars (p, (valueT) stroff, 4); | |
364 | md_number_to_chars (p + 4, (valueT) type, 1); | |
365 | md_number_to_chars (p + 5, (valueT) other, 1); | |
366 | md_number_to_chars (p + 6, (valueT) desc, 2); | |
367 | ||
368 | if (what == 's' || what == 'n') | |
369 | { | |
370 | /* Pick up the value from the input line. */ | |
371 | cons (4); | |
372 | input_line_pointer--; | |
373 | } | |
374 | else | |
375 | { | |
252b5132 RH |
376 | symbolS *symbol; |
377 | expressionS exp; | |
378 | ||
379 | /* Arrange for a value representing the current location. */ | |
e01e1cee | 380 | symbol = symbol_temp_new (saved_seg, saved_frag, dot); |
252b5132 RH |
381 | |
382 | exp.X_op = O_symbol; | |
383 | exp.X_add_symbol = symbol; | |
384 | exp.X_add_number = 0; | |
385 | ||
386 | emit_expr (&exp, 4); | |
387 | } | |
388 | ||
389 | #ifdef OBJ_PROCESS_STAB | |
390 | OBJ_PROCESS_STAB (seg, what, string, type, other, desc); | |
391 | #endif | |
392 | ||
393 | subseg_set (saved_seg, saved_subseg); | |
394 | } | |
395 | else | |
396 | { | |
0acc7632 AM |
397 | if (stab_secname_obstack_end != NULL) |
398 | { | |
399 | free ((char *) stabstr_secname); | |
400 | if (stab_secname_obstack_end == obstack_next_free (¬es)) | |
401 | obstack_free (¬es, stab_secname); | |
402 | } | |
252b5132 RH |
403 | #ifdef OBJ_PROCESS_STAB |
404 | OBJ_PROCESS_STAB (0, what, string, type, other, desc); | |
405 | #else | |
406 | abort (); | |
407 | #endif | |
408 | } | |
409 | ||
410 | demand_empty_rest_of_line (); | |
411 | } | |
412 | ||
f0e652b4 | 413 | /* Regular stab directive. */ |
252b5132 RH |
414 | |
415 | void | |
24361518 | 416 | s_stab (int what) |
252b5132 | 417 | { |
0acc7632 | 418 | s_stab_generic (what, STAB_SECTION_NAME, STAB_STRING_SECTION_NAME, NULL); |
252b5132 RH |
419 | } |
420 | ||
f0e652b4 | 421 | /* "Extended stabs", used in Solaris only now. */ |
252b5132 RH |
422 | |
423 | void | |
24361518 | 424 | s_xstab (int what) |
252b5132 RH |
425 | { |
426 | int length; | |
0acc7632 | 427 | char *stab_secname, *stabstr_secname, *stab_secname_obstack_end; |
252b5132 | 428 | |
252b5132 | 429 | stab_secname = demand_copy_C_string (&length); |
0acc7632 | 430 | stab_secname_obstack_end = obstack_next_free (¬es); |
252b5132 RH |
431 | SKIP_WHITESPACE (); |
432 | if (*input_line_pointer == ',') | |
433 | input_line_pointer++; | |
434 | else | |
435 | { | |
436 | as_bad (_("comma missing in .xstabs")); | |
437 | ignore_rest_of_line (); | |
438 | return; | |
439 | } | |
440 | ||
441 | /* To get the name of the stab string section, simply add "str" to | |
442 | the stab section name. */ | |
0acc7632 AM |
443 | stabstr_secname = concat (stab_secname, "str", (char *) NULL); |
444 | s_stab_generic (what, stab_secname, stabstr_secname, | |
445 | stab_secname_obstack_end); | |
252b5132 RH |
446 | } |
447 | ||
448 | #ifdef S_SET_DESC | |
449 | ||
450 | /* Frob invented at RMS' request. Set the n_desc of a symbol. */ | |
451 | ||
f0e652b4 | 452 | void |
e046cf80 | 453 | s_desc (int ignore ATTRIBUTE_UNUSED) |
252b5132 RH |
454 | { |
455 | char *name; | |
456 | char c; | |
457 | char *p; | |
458 | symbolS *symbolP; | |
459 | int temp; | |
460 | ||
d02603dc | 461 | c = get_symbol_name (&name); |
252b5132 RH |
462 | p = input_line_pointer; |
463 | *p = c; | |
d02603dc | 464 | SKIP_WHITESPACE_AFTER_NAME (); |
252b5132 RH |
465 | if (*input_line_pointer != ',') |
466 | { | |
467 | *p = 0; | |
0e389e77 | 468 | as_bad (_("expected comma after \"%s\""), name); |
252b5132 RH |
469 | *p = c; |
470 | ignore_rest_of_line (); | |
471 | } | |
472 | else | |
473 | { | |
474 | input_line_pointer++; | |
475 | temp = get_absolute_expression (); | |
476 | *p = 0; | |
477 | symbolP = symbol_find_or_make (name); | |
478 | *p = c; | |
479 | S_SET_DESC (symbolP, temp); | |
480 | } | |
481 | demand_empty_rest_of_line (); | |
482 | } /* s_desc() */ | |
483 | ||
484 | #endif /* defined (S_SET_DESC) */ | |
485 | ||
486 | /* Generate stabs debugging information to denote the main source file. */ | |
487 | ||
488 | void | |
24361518 | 489 | stabs_generate_asm_file (void) |
252b5132 | 490 | { |
3b4dbbbf | 491 | const char *file; |
252b5132 RH |
492 | unsigned int lineno; |
493 | ||
3b4dbbbf | 494 | file = as_where (&lineno); |
05da4302 NC |
495 | if (use_gnu_debug_info_extensions) |
496 | { | |
3d6b762c JM |
497 | const char *dir; |
498 | char *dir2; | |
05da4302 | 499 | |
3d6b762c | 500 | dir = remap_debug_filename (getpwd ()); |
e1fa0163 | 501 | dir2 = concat (dir, "/", NULL); |
05da4302 | 502 | generate_asm_file (N_SO, dir2); |
e1fa0163 | 503 | free (dir2); |
502df130 | 504 | xfree ((char *) dir); |
05da4302 | 505 | } |
252b5132 RH |
506 | generate_asm_file (N_SO, file); |
507 | } | |
508 | ||
509 | /* Generate stabs debugging information to denote the source file. | |
510 | TYPE is one of N_SO, N_SOL. */ | |
511 | ||
512 | static void | |
3b4dbbbf | 513 | generate_asm_file (int type, const char *file) |
252b5132 RH |
514 | { |
515 | static char *last_file; | |
516 | static int label_count; | |
252b5132 | 517 | char sym[30]; |
604d524f | 518 | char *buf; |
3b4dbbbf TS |
519 | const char *tmp = file; |
520 | const char *file_endp = file + strlen (file); | |
2f01ffbf | 521 | char *bufp; |
43ad3147 | 522 | |
604d524f | 523 | if (last_file != NULL |
8b6efd89 | 524 | && filename_cmp (last_file, file) == 0) |
604d524f | 525 | return; |
43ad3147 | 526 | |
252b5132 RH |
527 | /* Rather than try to do this in some efficient fashion, we just |
528 | generate a string and then parse it again. That lets us use the | |
529 | existing stabs hook, which expect to see a string, rather than | |
530 | inventing new ones. */ | |
604d524f NC |
531 | sprintf (sym, "%sF%d", FAKE_LABEL_NAME, label_count); |
532 | ++label_count; | |
533 | ||
534 | /* Allocate enough space for the file name (possibly extended with | |
535 | doubled up backslashes), the symbol name, and the other characters | |
536 | that make up a stabs file directive. */ | |
add39d23 | 537 | bufp = buf = XNEWVEC (char, 2 * strlen (file) + strlen (sym) + 12); |
43ad3147 | 538 | |
604d524f NC |
539 | *bufp++ = '"'; |
540 | ||
91d6fa6a | 541 | while (tmp < file_endp) |
252b5132 | 542 | { |
82b8a785 | 543 | const char *bslash = strchr (tmp, '\\'); |
5a6312e8 | 544 | size_t len = bslash != NULL ? bslash - tmp + 1 : file_endp - tmp; |
43ad3147 | 545 | |
604d524f NC |
546 | /* Double all backslashes, since demand_copy_C_string (used by |
547 | s_stab to extract the part in quotes) will try to replace them as | |
548 | escape sequences. backslash may appear in a filespec. */ | |
5a6312e8 | 549 | memcpy (bufp, tmp, len); |
43ad3147 | 550 | |
604d524f NC |
551 | tmp += len; |
552 | bufp += len; | |
553 | ||
554 | if (bslash != NULL) | |
555 | *bufp++ = '\\'; | |
252b5132 RH |
556 | } |
557 | ||
604d524f NC |
558 | sprintf (bufp, "\",%d,0,0,%s\n", type, sym); |
559 | ||
1181551e | 560 | temp_ilp (buf); |
604d524f | 561 | s_stab ('s'); |
1181551e NC |
562 | restore_ilp (); |
563 | ||
604d524f NC |
564 | colon (sym); |
565 | ||
9fbb53c7 | 566 | free (last_file); |
604d524f | 567 | last_file = xstrdup (file); |
43ad3147 | 568 | |
210dcc61 | 569 | free (buf); |
252b5132 RH |
570 | } |
571 | ||
572 | /* Generate stabs debugging information for the current line. This is | |
573 | used to produce debugging information for an assembler file. */ | |
574 | ||
575 | void | |
24361518 | 576 | stabs_generate_asm_lineno (void) |
252b5132 RH |
577 | { |
578 | static int label_count; | |
3b4dbbbf | 579 | const char *file; |
252b5132 RH |
580 | unsigned int lineno; |
581 | char *buf; | |
582 | char sym[30]; | |
d1a6c242 | 583 | /* Remember the last file/line and avoid duplicates. */ |
1ea5c325 MS |
584 | static unsigned int prev_lineno = -1; |
585 | static char *prev_file = NULL; | |
bccba5f0 | 586 | |
252b5132 RH |
587 | /* Rather than try to do this in some efficient fashion, we just |
588 | generate a string and then parse it again. That lets us use the | |
589 | existing stabs hook, which expect to see a string, rather than | |
590 | inventing new ones. */ | |
591 | ||
3b4dbbbf | 592 | file = as_where (&lineno); |
252b5132 | 593 | |
d1a6c242 | 594 | /* Don't emit sequences of stabs for the same line. */ |
1ea5c325 MS |
595 | if (prev_file == NULL) |
596 | { | |
2b0f3761 | 597 | /* First time through. */ |
1ea5c325 MS |
598 | prev_file = xstrdup (file); |
599 | prev_lineno = lineno; | |
600 | } | |
601 | else if (lineno == prev_lineno | |
8b6efd89 | 602 | && filename_cmp (file, prev_file) == 0) |
1ea5c325 | 603 | { |
d1a6c242 | 604 | /* Same file/line as last time. */ |
1ea5c325 MS |
605 | return; |
606 | } | |
607 | else | |
608 | { | |
d1a6c242 | 609 | /* Remember file/line for next time. */ |
1ea5c325 | 610 | prev_lineno = lineno; |
8b6efd89 | 611 | if (filename_cmp (file, prev_file) != 0) |
1ea5c325 MS |
612 | { |
613 | free (prev_file); | |
614 | prev_file = xstrdup (file); | |
615 | } | |
616 | } | |
617 | ||
618 | /* Let the world know that we are in the middle of generating a | |
619 | piece of stabs line debugging information. */ | |
620 | outputting_stabs_line_debug = 1; | |
621 | ||
252b5132 RH |
622 | generate_asm_file (N_SOL, file); |
623 | ||
624 | sprintf (sym, "%sL%d", FAKE_LABEL_NAME, label_count); | |
625 | ++label_count; | |
626 | ||
627 | if (in_dot_func_p) | |
628 | { | |
add39d23 | 629 | buf = XNEWVEC (char, 100 + strlen (current_function_label)); |
252b5132 RH |
630 | sprintf (buf, "%d,0,%d,%s-%s\n", N_SLINE, lineno, |
631 | sym, current_function_label); | |
632 | } | |
633 | else | |
634 | { | |
add39d23 | 635 | buf = XNEWVEC (char, 100); |
252b5132 RH |
636 | sprintf (buf, "%d,0,%d,%s\n", N_SLINE, lineno, sym); |
637 | } | |
1181551e NC |
638 | |
639 | temp_ilp (buf); | |
252b5132 | 640 | s_stab ('n'); |
1181551e NC |
641 | restore_ilp (); |
642 | ||
252b5132 RH |
643 | colon (sym); |
644 | ||
bccba5f0 | 645 | outputting_stabs_line_debug = 0; |
e1fa0163 | 646 | free (buf); |
252b5132 RH |
647 | } |
648 | ||
649 | /* Emit a function stab. | |
650 | All assembler functions are assumed to have return type `void'. */ | |
651 | ||
652 | void | |
24361518 | 653 | stabs_generate_asm_func (const char *funcname, const char *startlabname) |
252b5132 | 654 | { |
5b7c81bd | 655 | static bool void_emitted_p = false; |
252b5132 | 656 | char *buf; |
252b5132 RH |
657 | unsigned int lineno; |
658 | ||
659 | if (! void_emitted_p) | |
660 | { | |
1181551e | 661 | temp_ilp ((char *) "\"void:t1=1\",128,0,0,0"); |
252b5132 | 662 | s_stab ('s'); |
1181551e | 663 | restore_ilp (); |
5b7c81bd | 664 | void_emitted_p = true; |
252b5132 RH |
665 | } |
666 | ||
3b4dbbbf | 667 | as_where (&lineno); |
05f4ab67 AM |
668 | if (asprintf (&buf, "\"%s:F1\",%d,0,%d,%s", |
669 | funcname, N_FUN, lineno + 1, startlabname) == -1) | |
670 | as_fatal ("%s", xstrerror (errno)); | |
1181551e NC |
671 | |
672 | temp_ilp (buf); | |
252b5132 | 673 | s_stab ('s'); |
1181551e | 674 | restore_ilp (); |
252b5132 RH |
675 | free (buf); |
676 | ||
252b5132 | 677 | current_function_label = xstrdup (startlabname); |
5b7c81bd | 678 | in_dot_func_p = true; |
252b5132 RH |
679 | } |
680 | ||
681 | /* Emit a stab to record the end of a function. */ | |
682 | ||
683 | void | |
24361518 KH |
684 | stabs_generate_asm_endfunc (const char *funcname ATTRIBUTE_UNUSED, |
685 | const char *startlabname) | |
252b5132 RH |
686 | { |
687 | static int label_count; | |
252b5132 RH |
688 | char *buf; |
689 | char sym[30]; | |
690 | ||
691 | sprintf (sym, "%sendfunc%d", FAKE_LABEL_NAME, label_count); | |
692 | ++label_count; | |
693 | colon (sym); | |
694 | ||
05f4ab67 AM |
695 | if (asprintf (&buf, "\"\",%d,0,0,%s-%s", N_FUN, sym, startlabname) == -1) |
696 | as_fatal ("%s", xstrerror (errno)); | |
1181551e NC |
697 | |
698 | temp_ilp (buf); | |
252b5132 | 699 | s_stab ('s'); |
1181551e | 700 | restore_ilp (); |
252b5132 RH |
701 | free (buf); |
702 | ||
5b7c81bd | 703 | in_dot_func_p = false; |
252b5132 RH |
704 | current_function_label = NULL; |
705 | } |