stabs.c

来自「基于4个mips核的noc设计」· C语言 代码 · 共 679 行 · 第 1/2 页

C
679
字号
      stroff = get_stab_string_offset (string, stabstr_secname);      if (what == 's')	{	  /* Release the string, if nobody else has used the obstack.  */	  if (saved_string_obstack_end == notes.next_free) 	    obstack_free (&notes, string);	}      /* At least for now, stabs in a special stab section are always	 output as 12 byte blocks of information.  */      p = frag_more (8);      md_number_to_chars (p, (valueT) stroff, 4);      md_number_to_chars (p + 4, (valueT) type, 1);      md_number_to_chars (p + 5, (valueT) other, 1);      md_number_to_chars (p + 6, (valueT) desc, 2);      if (what == 's' || what == 'n')	{	  /* Pick up the value from the input line.  */	  cons (4);	  input_line_pointer--;	}      else	{	  const char *fake;	  symbolS *symbol;	  expressionS exp;	  /* Arrange for a value representing the current location.  */	  fake = FAKE_LABEL_NAME;	  symbol = symbol_new (fake, saved_seg, dot, saved_frag);	  exp.X_op = O_symbol;	  exp.X_add_symbol = symbol;	  exp.X_add_number = 0;	  emit_expr (&exp, 4);	}#ifdef OBJ_PROCESS_STAB      OBJ_PROCESS_STAB (seg, what, string, type, other, desc);#endif      subseg_set (saved_seg, saved_subseg);    }  else    {#ifdef OBJ_PROCESS_STAB      OBJ_PROCESS_STAB (0, what, string, type, other, desc);#else      abort ();#endif    }  demand_empty_rest_of_line ();}/* Regular stab directive.  */voids_stab (what)     int what;{  s_stab_generic (what, STAB_SECTION_NAME, STAB_STRING_SECTION_NAME);}/* "Extended stabs", used in Solaris only now.  */voids_xstab (what)     int what;{  int length;  char *stab_secname, *stabstr_secname;  static char *saved_secname, *saved_strsecname;  /* @@ MEMORY LEAK: This allocates a copy of the string, but in most     cases it will be the same string, so we could release the storage     back to the obstack it came from.  */  stab_secname = demand_copy_C_string (&length);  SKIP_WHITESPACE ();  if (*input_line_pointer == ',')    input_line_pointer++;  else    {      as_bad (_("comma missing in .xstabs"));      ignore_rest_of_line ();      return;    }  /* To get the name of the stab string section, simply add "str" to     the stab section name.  */  if (saved_secname == 0 || strcmp (saved_secname, stab_secname))    {      stabstr_secname = (char *) xmalloc (strlen (stab_secname) + 4);      strcpy (stabstr_secname, stab_secname);      strcat (stabstr_secname, "str");      if (saved_secname)	{	  free (saved_secname);	  free (saved_strsecname);	}      saved_secname = stab_secname;      saved_strsecname = stabstr_secname;    }  s_stab_generic (what, saved_secname, saved_strsecname);}#ifdef S_SET_DESC/* Frob invented at RMS' request. Set the n_desc of a symbol.  */voids_desc (ignore)     int ignore ATTRIBUTE_UNUSED;{  char *name;  char c;  char *p;  symbolS *symbolP;  int temp;  name = input_line_pointer;  c = get_symbol_end ();  p = input_line_pointer;  *p = c;  SKIP_WHITESPACE ();  if (*input_line_pointer != ',')    {      *p = 0;      as_bad (_("Expected comma after name \"%s\""), name);      *p = c;      ignore_rest_of_line ();    }  else    {      input_line_pointer++;      temp = get_absolute_expression ();      *p = 0;      symbolP = symbol_find_or_make (name);      *p = c;      S_SET_DESC (symbolP, temp);    }  demand_empty_rest_of_line ();}				/* s_desc() */#endif /* defined (S_SET_DESC) *//* Generate stabs debugging information to denote the main source file.  */voidstabs_generate_asm_file (){  char *file;  unsigned int lineno;  as_where (&file, &lineno);  generate_asm_file (N_SO, file);}/* Generate stabs debugging information to denote the source file.   TYPE is one of N_SO, N_SOL.  */static voidgenerate_asm_file (type, file)     int type;     char *file;{  static char *last_file;  static int label_count;  char *hold;  char sym[30];  char *buf;  char *tmp = file;  char *endp = file + strlen (file);  char *bufp = buf;  if (last_file != NULL      && strcmp (last_file, file) == 0)    return;  /* Rather than try to do this in some efficient fashion, we just     generate a string and then parse it again.  That lets us use the     existing stabs hook, which expect to see a string, rather than     inventing new ones.  */  hold = input_line_pointer;  sprintf (sym, "%sF%d", FAKE_LABEL_NAME, label_count);  ++label_count;  /* Allocate enough space for the file name (possibly extended with     doubled up backslashes), the symbol name, and the other characters     that make up a stabs file directive.  */  bufp = buf = xmalloc (2 * strlen (file) + strlen (sym) + 12);  *bufp++ = '"';  while (tmp < endp)    {      char *bslash = strchr (tmp, '\\');      int len = (bslash ? (bslash - tmp + 1) : strlen (tmp));      /* Double all backslashes, since demand_copy_C_string (used by	 s_stab to extract the part in quotes) will try to replace them as	 escape sequences.  backslash may appear in a filespec.  */      strncpy (bufp, tmp, len);      tmp += len;      bufp += len;      if (bslash != NULL)	*bufp++ = '\\';    }  sprintf (bufp, "\",%d,0,0,%s\n", type, sym);  input_line_pointer = buf;  s_stab ('s');  colon (sym);  if (last_file != NULL)    free (last_file);  last_file = xstrdup (file);  free (buf);  input_line_pointer = hold;}/* Generate stabs debugging information for the current line.  This is   used to produce debugging information for an assembler file.  */voidstabs_generate_asm_lineno (){  static int label_count;  char *hold;  char *file;  unsigned int lineno;  char *buf;  char sym[30];  /* Let the world know that we are in the middle of generating a     piece of stabs line debugging information.  */  outputting_stabs_line_debug = 1;  /* Rather than try to do this in some efficient fashion, we just     generate a string and then parse it again.  That lets us use the     existing stabs hook, which expect to see a string, rather than     inventing new ones.  */  hold = input_line_pointer;  as_where (&file, &lineno);  generate_asm_file (N_SOL, file);  sprintf (sym, "%sL%d", FAKE_LABEL_NAME, label_count);  ++label_count;  if (in_dot_func_p)    {      buf = (char *) alloca (100 + strlen (current_function_label));      sprintf (buf, "%d,0,%d,%s-%s\n", N_SLINE, lineno,	       sym, current_function_label);    }  else    {      buf = (char *) alloca (100);      sprintf (buf, "%d,0,%d,%s\n", N_SLINE, lineno, sym);    }  input_line_pointer = buf;  s_stab ('n');  colon (sym);  input_line_pointer = hold;  outputting_stabs_line_debug = 0;}/* Emit a function stab.   All assembler functions are assumed to have return type `void'.  */voidstabs_generate_asm_func (funcname, startlabname)     const char *funcname;     const char *startlabname;{  static int void_emitted_p;  char *hold = input_line_pointer;  char *buf;  char *file;  unsigned int lineno;  if (! void_emitted_p)    {      input_line_pointer = "\"void:t1=1\",128,0,0,0";      s_stab ('s');      void_emitted_p = 1;    }  as_where (&file, &lineno);  asprintf (&buf, "\"%s:F1\",%d,0,%d,%s",	    funcname, N_FUN, lineno + 1, startlabname);  input_line_pointer = buf;  s_stab ('s');  free (buf);  input_line_pointer = hold;  current_function_label = xstrdup (startlabname);  in_dot_func_p = 1;}/* Emit a stab to record the end of a function.  */voidstabs_generate_asm_endfunc (funcname, startlabname)     const char *funcname ATTRIBUTE_UNUSED;     const char *startlabname;{  static int label_count;  char *hold = input_line_pointer;  char *buf;  char sym[30];  sprintf (sym, "%sendfunc%d", FAKE_LABEL_NAME, label_count);  ++label_count;  colon (sym);  asprintf (&buf, "\"\",%d,0,0,%s-%s", N_FUN, sym, startlabname);  input_line_pointer = buf;  s_stab ('s');  free (buf);  input_line_pointer = hold;  in_dot_func_p = 0;  current_function_label = NULL;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?