Subversion Repositories Kolibri OS

Rev

Rev 5217 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5217 Rev 6324
1
/* wrstabs.c -- Output stabs debugging information
1
/* wrstabs.c -- Output stabs debugging information
2
   Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006,
-
 
3
   2007, 2009   Free Software Foundation, Inc.
2
   Copyright (C) 1996-2015 Free Software Foundation, Inc.
4
   Written by Ian Lance Taylor .
3
   Written by Ian Lance Taylor .
5
 
4
 
6
   This file is part of GNU Binutils.
5
   This file is part of GNU Binutils.
7
 
6
 
8
   This program is free software; you can redistribute it and/or modify
7
   This program is free software; you can redistribute it and/or modify
9
   it under the terms of the GNU General Public License as published by
8
   it under the terms of the GNU General Public License as published by
10
   the Free Software Foundation; either version 3 of the License, or
9
   the Free Software Foundation; either version 3 of the License, or
11
   (at your option) any later version.
10
   (at your option) any later version.
12
 
11
 
13
   This program is distributed in the hope that it will be useful,
12
   This program is distributed in the hope that it will be useful,
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
   GNU General Public License for more details.
15
   GNU General Public License for more details.
17
 
16
 
18
   You should have received a copy of the GNU General Public License
17
   You should have received a copy of the GNU General Public License
19
   along with this program; if not, write to the Free Software
18
   along with this program; if not, write to the Free Software
20
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
19
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
21
   02110-1301, USA.  */
20
   02110-1301, USA.  */
22
 
21
 
23
/* This file contains code which writes out stabs debugging
22
/* This file contains code which writes out stabs debugging
24
   information.  */
23
   information.  */
25
 
24
 
26
#include "sysdep.h"
25
#include "sysdep.h"
27
#include 
26
#include 
28
#include "bfd.h"
27
#include "bfd.h"
29
#include "libiberty.h"
28
#include "libiberty.h"
30
#include "filenames.h"
29
#include "filenames.h"
31
#include "safe-ctype.h"
30
#include "safe-ctype.h"
32
#include "bucomm.h"
31
#include "bucomm.h"
33
#include "debug.h"
32
#include "debug.h"
34
#include "budbg.h"
33
#include "budbg.h"
35
#include "aout/aout64.h"
34
#include "aout/aout64.h"
36
#include "aout/stab_gnu.h"
35
#include "aout/stab_gnu.h"
37
 
36
 
38
/* The size of a stabs symbol.  This presumes 32 bit values.  */
37
/* The size of a stabs symbol.  This presumes 32 bit values.  */
39
 
38
 
40
#define STAB_SYMBOL_SIZE (12)
39
#define STAB_SYMBOL_SIZE (12)
41
 
40
 
42
/* An entry in a string hash table.  */
41
/* An entry in a string hash table.  */
43
 
42
 
44
struct string_hash_entry
43
struct string_hash_entry
45
{
44
{
46
  struct bfd_hash_entry root;
45
  struct bfd_hash_entry root;
47
  /* Next string in this table.  */
46
  /* Next string in this table.  */
48
  struct string_hash_entry *next;
47
  struct string_hash_entry *next;
49
  /* Index in string table.  */
48
  /* Index in string table.  */
50
  long index;
49
  long index;
51
  /* Size of type if this is a typedef.  */
50
  /* Size of type if this is a typedef.  */
52
  unsigned int size;
51
  unsigned int size;
53
};
52
};
54
 
53
 
55
/* A string hash table.  */
54
/* A string hash table.  */
56
 
55
 
57
struct string_hash_table
56
struct string_hash_table
58
{
57
{
59
  struct bfd_hash_table table;
58
  struct bfd_hash_table table;
60
};
59
};
61
 
60
 
62
/* The type stack.  Each element on the stack is a string.  */
61
/* The type stack.  Each element on the stack is a string.  */
63
 
62
 
64
struct stab_type_stack
63
struct stab_type_stack
65
{
64
{
66
  /* The next element on the stack.  */
65
  /* The next element on the stack.  */
67
  struct stab_type_stack *next;
66
  struct stab_type_stack *next;
68
  /* This element as a string.  */
67
  /* This element as a string.  */
69
  char *string;
68
  char *string;
70
  /* The type index of this element.  */
69
  /* The type index of this element.  */
71
  long index;
70
  long index;
72
  /* The size of the type.  */
71
  /* The size of the type.  */
73
  unsigned int size;
72
  unsigned int size;
74
  /* Whether type string defines a new type.  */
73
  /* Whether type string defines a new type.  */
75
  bfd_boolean definition;
74
  bfd_boolean definition;
76
  /* String defining struct fields.  */
75
  /* String defining struct fields.  */
77
  char *fields;
76
  char *fields;
78
  /* NULL terminated array of strings defining base classes for a
77
  /* NULL terminated array of strings defining base classes for a
79
     class.  */
78
     class.  */
80
  char **baseclasses;
79
  char **baseclasses;
81
  /* String defining class methods.  */
80
  /* String defining class methods.  */
82
  char *methods;
81
  char *methods;
83
  /* String defining vtable pointer for a class.  */
82
  /* String defining vtable pointer for a class.  */
84
  char *vtable;
83
  char *vtable;
85
};
84
};
86
 
85
 
87
/* This structure is used to keep track of type indices for tagged
86
/* This structure is used to keep track of type indices for tagged
88
   types.  */
87
   types.  */
89
 
88
 
90
struct stab_tag
89
struct stab_tag
91
{
90
{
92
  /* The type index.  */
91
  /* The type index.  */
93
  long index;
92
  long index;
94
  /* The tag name.  */
93
  /* The tag name.  */
95
  const char *tag;
94
  const char *tag;
96
  /* The kind of type.  This is set to DEBUG_KIND_ILLEGAL when the
95
  /* The kind of type.  This is set to DEBUG_KIND_ILLEGAL when the
97
     type is defined.  */
96
     type is defined.  */
98
  enum debug_type_kind kind;
97
  enum debug_type_kind kind;
99
  /* The size of the struct.  */
98
  /* The size of the struct.  */
100
  unsigned int size;
99
  unsigned int size;
101
};
100
};
102
 
101
 
103
/* We remember various sorts of type indices.  They are not related,
102
/* We remember various sorts of type indices.  They are not related,
104
   but, for convenience, we keep all the information in this
103
   but, for convenience, we keep all the information in this
105
   structure.  */
104
   structure.  */
106
 
105
 
107
struct stab_type_cache
106
struct stab_type_cache
108
{
107
{
109
  /* The void type index.  */
108
  /* The void type index.  */
110
  long void_type;
109
  long void_type;
111
  /* Signed integer type indices, indexed by size - 1.  */
110
  /* Signed integer type indices, indexed by size - 1.  */
112
  long signed_integer_types[8];
111
  long signed_integer_types[8];
113
  /* Unsigned integer type indices, indexed by size - 1.  */
112
  /* Unsigned integer type indices, indexed by size - 1.  */
114
  long unsigned_integer_types[8];
113
  long unsigned_integer_types[8];
115
  /* Floating point types, indexed by size - 1.  */
114
  /* Floating point types, indexed by size - 1.  */
116
  long float_types[16];
115
  long float_types[16];
117
  /* Pointers to types, indexed by the type index.  */
116
  /* Pointers to types, indexed by the type index.  */
118
  long *pointer_types;
117
  long *pointer_types;
119
  size_t pointer_types_alloc;
118
  size_t pointer_types_alloc;
120
  /* Functions returning types, indexed by the type index.  */
119
  /* Functions returning types, indexed by the type index.  */
121
  long *function_types;
120
  long *function_types;
122
  size_t function_types_alloc;
121
  size_t function_types_alloc;
123
  /* References to types, indexed by the type index.  */
122
  /* References to types, indexed by the type index.  */
124
  long *reference_types;
123
  long *reference_types;
125
  size_t reference_types_alloc;
124
  size_t reference_types_alloc;
126
  /* Struct/union/class type indices, indexed by the struct id.  */
125
  /* Struct/union/class type indices, indexed by the struct id.  */
127
  struct stab_tag *struct_types;
126
  struct stab_tag *struct_types;
128
  size_t struct_types_alloc;
127
  size_t struct_types_alloc;
129
};
128
};
130
 
129
 
131
/* This is the handle passed through debug_write.  */
130
/* This is the handle passed through debug_write.  */
132
 
131
 
133
struct stab_write_handle
132
struct stab_write_handle
134
{
133
{
135
  /* The BFD.  */
134
  /* The BFD.  */
136
  bfd *abfd;
135
  bfd *abfd;
137
  /* This buffer holds the symbols.  */
136
  /* This buffer holds the symbols.  */
138
  bfd_byte *symbols;
137
  bfd_byte *symbols;
139
  size_t symbols_size;
138
  size_t symbols_size;
140
  size_t symbols_alloc;
139
  size_t symbols_alloc;
141
  /* This is a list of hash table entries for the strings.  */
140
  /* This is a list of hash table entries for the strings.  */
142
  struct string_hash_entry *strings;
141
  struct string_hash_entry *strings;
143
  /* The last string hash table entry.  */
142
  /* The last string hash table entry.  */
144
  struct string_hash_entry *last_string;
143
  struct string_hash_entry *last_string;
145
  /* The size of the strings.  */
144
  /* The size of the strings.  */
146
  size_t strings_size;
145
  size_t strings_size;
147
  /* This hash table eliminates duplicate strings.  */
146
  /* This hash table eliminates duplicate strings.  */
148
  struct string_hash_table strhash;
147
  struct string_hash_table strhash;
149
  /* The type stack.  */
148
  /* The type stack.  */
150
  struct stab_type_stack *type_stack;
149
  struct stab_type_stack *type_stack;
151
  /* The next type index.  */
150
  /* The next type index.  */
152
  long type_index;
151
  long type_index;
153
  /* The type cache.  */
152
  /* The type cache.  */
154
  struct stab_type_cache type_cache;
153
  struct stab_type_cache type_cache;
155
  /* A mapping from typedef names to type indices.  */
154
  /* A mapping from typedef names to type indices.  */
156
  struct string_hash_table typedef_hash;
155
  struct string_hash_table typedef_hash;
157
  /* If this is not -1, it is the offset to the most recent N_SO
156
  /* If this is not -1, it is the offset to the most recent N_SO
158
     symbol, and the value of that symbol needs to be set.  */
157
     symbol, and the value of that symbol needs to be set.  */
159
  long so_offset;
158
  long so_offset;
160
  /* If this is not -1, it is the offset to the most recent N_FUN
159
  /* If this is not -1, it is the offset to the most recent N_FUN
161
     symbol, and the value of that symbol needs to be set.  */
160
     symbol, and the value of that symbol needs to be set.  */
162
  long fun_offset;
161
  long fun_offset;
163
  /* The last text section address seen.  */
162
  /* The last text section address seen.  */
164
  bfd_vma last_text_address;
163
  bfd_vma last_text_address;
165
  /* The block nesting depth.  */
164
  /* The block nesting depth.  */
166
  unsigned int nesting;
165
  unsigned int nesting;
167
  /* The function address.  */
166
  /* The function address.  */
168
  bfd_vma fnaddr;
167
  bfd_vma fnaddr;
169
  /* A pending LBRAC symbol.  */
168
  /* A pending LBRAC symbol.  */
170
  bfd_vma pending_lbrac;
169
  bfd_vma pending_lbrac;
171
  /* The current line number file name.  */
170
  /* The current line number file name.  */
172
  const char *lineno_filename;
171
  const char *lineno_filename;
173
};
172
};
174
 
173
 
175
static struct bfd_hash_entry *string_hash_newfunc
174
static struct bfd_hash_entry *string_hash_newfunc
176
  (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
175
  (struct bfd_hash_entry *, struct bfd_hash_table *, const char *);
177
static bfd_boolean stab_write_symbol
176
static bfd_boolean stab_write_symbol
178
  (struct stab_write_handle *, int, int, bfd_vma, const char *);
177
  (struct stab_write_handle *, int, int, bfd_vma, const char *);
179
static bfd_boolean stab_push_string
178
static bfd_boolean stab_push_string
180
  (struct stab_write_handle *, const char *, long, bfd_boolean, unsigned int);
179
  (struct stab_write_handle *, const char *, long, bfd_boolean, unsigned int);
181
static bfd_boolean stab_push_defined_type
180
static bfd_boolean stab_push_defined_type
182
  (struct stab_write_handle *, long, unsigned int);
181
  (struct stab_write_handle *, long, unsigned int);
183
static char *stab_pop_type (struct stab_write_handle *);
182
static char *stab_pop_type (struct stab_write_handle *);
184
static bfd_boolean stab_modify_type
183
static bfd_boolean stab_modify_type
185
  (struct stab_write_handle *, int, unsigned int, long **, size_t *);
184
  (struct stab_write_handle *, int, unsigned int, long **, size_t *);
186
static long stab_get_struct_index
185
static long stab_get_struct_index
187
  (struct stab_write_handle *, const char *, unsigned int,
186
  (struct stab_write_handle *, const char *, unsigned int,
188
   enum debug_type_kind, unsigned int *);
187
   enum debug_type_kind, unsigned int *);
189
static bfd_boolean stab_class_method_var
188
static bfd_boolean stab_class_method_var
190
  (struct stab_write_handle *, const char *, enum debug_visibility,
189
  (struct stab_write_handle *, const char *, enum debug_visibility,
191
   bfd_boolean, bfd_boolean, bfd_boolean, bfd_vma, bfd_boolean);
190
   bfd_boolean, bfd_boolean, bfd_boolean, bfd_vma, bfd_boolean);
192
static bfd_boolean stab_start_compilation_unit (void *, const char *);
191
static bfd_boolean stab_start_compilation_unit (void *, const char *);
193
static bfd_boolean stab_start_source (void *, const char *);
192
static bfd_boolean stab_start_source (void *, const char *);
194
static bfd_boolean stab_empty_type (void *);
193
static bfd_boolean stab_empty_type (void *);
195
static bfd_boolean stab_void_type (void *);
194
static bfd_boolean stab_void_type (void *);
196
static bfd_boolean stab_int_type (void *, unsigned int, bfd_boolean);
195
static bfd_boolean stab_int_type (void *, unsigned int, bfd_boolean);
197
static bfd_boolean stab_float_type (void *, unsigned int);
196
static bfd_boolean stab_float_type (void *, unsigned int);
198
static bfd_boolean stab_complex_type (void *, unsigned int);
197
static bfd_boolean stab_complex_type (void *, unsigned int);
199
static bfd_boolean stab_bool_type (void *, unsigned int);
198
static bfd_boolean stab_bool_type (void *, unsigned int);
200
static bfd_boolean stab_enum_type
199
static bfd_boolean stab_enum_type
201
  (void *, const char *, const char **, bfd_signed_vma *);
200
  (void *, const char *, const char **, bfd_signed_vma *);
202
static bfd_boolean stab_pointer_type (void *);
201
st