3 Copyright 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 #include "libiberty.h"
23 #include "safe-ctype.h"
25 #include "search_list.h"
34 char *spec
; /* Parsing modifies this. */
40 int prev_index
; /* Index of prev match. */
41 Sym
*prev_match
; /* Previous match. */
42 Sym
*first_match
; /* Chain of all matches. */
49 Sym_Table syms
[NUM_TABLES
];
52 const char *table_name
[] =
54 "INCL_GRAPH", "EXCL_GRAPH",
55 "INCL_ARCS", "EXCL_ARCS",
56 "INCL_FLAT", "EXCL_FLAT",
57 "INCL_TIME", "EXCL_TIME",
58 "INCL_ANNO", "EXCL_ANNO",
59 "INCL_EXEC", "EXCL_EXEC"
63 /* This is the table in which we keep all the syms that match
64 the right half of an arc id. It is NOT sorted according
65 to the addresses, because it is accessed only through
66 the left half's CHILDREN pointers (so it's crucial not
67 to reorder this table once pointers into it exist). */
68 static Sym_Table right_ids
;
70 static Source_File non_existent_file
=
72 0, "<non-existent-file>", 0, 0, 0, NULL
77 DEFUN (sym_id_add
, (spec
, which_table
),
78 const char *spec AND Table_Id which_table
)
81 int len
= strlen (spec
);
83 id
= (struct sym_id
*) xmalloc (sizeof (*id
) + len
+ 1);
84 memset (id
, 0, sizeof (*id
));
86 id
->spec
= (char *) id
+ sizeof (*id
);
87 strcpy (id
->spec
, spec
);
88 id
->which_table
= which_table
;
95 /* A spec has the syntax FILENAME:(FUNCNAME|LINENUM). As a convenience
96 to the user, a spec without a colon is interpreted as:
98 (i) a FILENAME if it contains a dot
99 (ii) a FUNCNAME if it starts with a non-digit character
100 (iii) a LINENUM if it starts with a digit
102 A FUNCNAME containing a dot can be specified by :FUNCNAME, a
103 FILENAME not containing a dot can be specified by FILENAME. */
106 DEFUN (parse_spec
, (spec
, sym
), char *spec AND Sym
* sym
)
111 colon
= strrchr (spec
, ':');
119 sym
->file
= source_file_lookup_name (spec
);
122 sym
->file
= &non_existent_file
;
129 if (ISDIGIT (spec
[0]))
130 sym
->line_num
= atoi (spec
);
135 else if (strlen (spec
))
137 /* No colon: spec is a filename if it contains a dot. */
138 if (strchr (spec
, '.'))
140 sym
->file
= source_file_lookup_name (spec
);
143 sym
->file
= &non_existent_file
;
145 else if (ISDIGIT (*spec
))
147 sym
->line_num
= atoi (spec
);
149 else if (strlen (spec
))
157 /* A symbol id has the syntax SPEC[/SPEC], where SPEC is is defined
161 DEFUN (parse_id
, (id
), struct sym_id
*id
)
165 DBG (IDDEBUG
, printf ("[parse_id] %s -> ", id
->spec
));
167 slash
= strchr (id
->spec
, '/');
170 parse_spec (slash
+ 1, &id
->right
.sym
);
172 id
->has_right
= TRUE
;
174 parse_spec (id
->spec
, &id
->left
.sym
);
177 if (debug_level
& IDDEBUG
)
179 printf ("%s:", id
->left
.sym
.file
? id
->left
.sym
.file
->name
: "*");
181 if (id
->left
.sym
.name
)
182 printf ("%s", id
->left
.sym
.name
);
183 else if (id
->left
.sym
.line_num
)
184 printf ("%d", id
->left
.sym
.line_num
);
191 id
->right
.sym
.file
? id
->right
.sym
.file
->name
: "*");
193 if (id
->right
.sym
.name
)
194 printf ("%s", id
->right
.sym
.name
);
195 else if (id
->right
.sym
.line_num
)
196 printf ("%d", id
->right
.sym
.line_num
);
207 /* Return TRUE iff PATTERN matches SYM. */
210 DEFUN (match
, (pattern
, sym
), Sym
* pattern AND Sym
* sym
)
212 return (pattern
->file
? pattern
->file
== sym
->file
: TRUE
)
213 && (pattern
->line_num
? pattern
->line_num
== sym
->line_num
: TRUE
)
215 ? strcmp (pattern
->name
,
216 sym
->name
+(discard_underscores
&& sym
->name
[0] == '_')) == 0
222 DEFUN (extend_match
, (m
, sym
, tab
, second_pass
),
223 struct match
*m AND Sym
* sym AND Sym_Table
* tab AND
bool second_pass
)
225 if (m
->prev_match
!= sym
- 1)
227 /* Discontinuity: add new match to table. */
230 tab
->base
[tab
->len
] = *sym
;
231 m
->prev_index
= tab
->len
;
233 /* Link match into match's chain. */
234 tab
->base
[tab
->len
].next
= m
->first_match
;
235 m
->first_match
= &tab
->base
[tab
->len
];
241 /* Extend match to include this symbol. */
243 tab
->base
[m
->prev_index
].end_addr
= sym
->end_addr
;
249 /* Go through sym_id list produced by option processing and fill
250 in the various symbol tables indicating what symbols should
251 be displayed or suppressed for the various kinds of outputs.
253 This can potentially produce huge tables and in particulars
254 tons of arcs, but this happens only if the user makes silly
255 requests---you get what you ask for! */
258 DEFUN_VOID (sym_id_parse
)
260 Sym
*sym
, *left
, *right
;
264 /* Convert symbol ids into Syms, so we can deal with them more easily. */
265 for (id
= id_list
; id
; id
= id
->next
)
268 /* First determine size of each table. */
269 for (sym
= symtab
.base
; sym
< symtab
.limit
; ++sym
)
271 for (id
= id_list
; id
; id
= id
->next
)
273 if (match (&id
->left
.sym
, sym
))
274 extend_match (&id
->left
, sym
, &syms
[id
->which_table
], FALSE
);
276 if (id
->has_right
&& match (&id
->right
.sym
, sym
))
277 extend_match (&id
->right
, sym
, &right_ids
, FALSE
);
281 /* Create tables of appropriate size and reset lengths. */
282 for (tab
= syms
; tab
< &syms
[NUM_TABLES
]; ++tab
)
286 tab
->base
= (Sym
*) xmalloc (tab
->len
* sizeof (Sym
));
287 tab
->limit
= tab
->base
+ tab
->len
;
294 right_ids
.base
= (Sym
*) xmalloc (right_ids
.len
* sizeof (Sym
));
295 right_ids
.limit
= right_ids
.base
+ right_ids
.len
;
299 /* Make a second pass through symtab, creating syms as necessary. */
300 for (sym
= symtab
.base
; sym
< symtab
.limit
; ++sym
)
302 for (id
= id_list
; id
; id
= id
->next
)
304 if (match (&id
->left
.sym
, sym
))
305 extend_match (&id
->left
, sym
, &syms
[id
->which_table
], TRUE
);
307 if (id
->has_right
&& match (&id
->right
.sym
, sym
))
308 extend_match (&id
->right
, sym
, &right_ids
, TRUE
);
312 /* Go through ids creating arcs as needed. */
313 for (id
= id_list
; id
; id
= id
->next
)
317 for (left
= id
->left
.first_match
; left
; left
= left
->next
)
319 for (right
= id
->right
.first_match
; right
; right
= right
->next
)
323 "[sym_id_parse]: arc %s:%s(%lx-%lx) -> %s:%s(%lx-%lx) to %s\n",
324 left
->file
? left
->file
->name
: "*",
325 left
->name
? left
->name
: "*",
326 (unsigned long) left
->addr
,
327 (unsigned long) left
->end_addr
,
328 right
->file
? right
->file
->name
: "*",
329 right
->name
? right
->name
: "*",
330 (unsigned long) right
->addr
,
331 (unsigned long) right
->end_addr
,
332 table_name
[id
->which_table
]));
334 arc_add (left
, right
, (unsigned long) 0);
340 /* Finally, we can sort the tables and we're done. */
341 for (tab
= &syms
[0]; tab
< &syms
[NUM_TABLES
]; ++tab
)
343 DBG (IDDEBUG
, printf ("[sym_id_parse] syms[%s]:\n",
344 table_name
[tab
- &syms
[0]]));
345 symtab_finalize (tab
);
350 /* Symbol tables storing the FROM symbols of arcs do not necessarily
351 have distinct address ranges. For example, somebody might request
352 -k /_mcount to suppress any arcs into _mcount, while at the same
353 time requesting -k a/b. Fortunately, those symbol tables don't get
354 very big (the user has to type them!), so a linear search is probably
357 DEFUN (sym_id_arc_is_present
, (symtab
, from
, to
),
358 Sym_Table
* symtab AND Sym
* from AND Sym
* to
)
362 for (sym
= symtab
->base
; sym
< symtab
->limit
; ++sym
)
364 if (from
->addr
>= sym
->addr
&& from
->addr
<= sym
->end_addr
365 && arc_lookup (sym
, to
))