3 Copyright 2000, 2001, 2002 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. */
36 bfd_boolean has_right
;
40 int prev_index
; /* Index of prev match. */
41 Sym
*prev_match
; /* Previous match. */
42 Sym
*first_match
; /* Chain of all matches. */
49 static void parse_spec
50 PARAMS ((char *, Sym
*));
52 PARAMS ((struct sym_id
*));
53 static bfd_boolean match
54 PARAMS ((Sym
*, Sym
*));
55 static void extend_match
56 PARAMS ((struct match
*, Sym
*, Sym_Table
*, bfd_boolean
));
59 Sym_Table syms
[NUM_TABLES
];
62 const char *table_name
[] =
64 "INCL_GRAPH", "EXCL_GRAPH",
65 "INCL_ARCS", "EXCL_ARCS",
66 "INCL_FLAT", "EXCL_FLAT",
67 "INCL_TIME", "EXCL_TIME",
68 "INCL_ANNO", "EXCL_ANNO",
69 "INCL_EXEC", "EXCL_EXEC"
73 /* This is the table in which we keep all the syms that match
74 the right half of an arc id. It is NOT sorted according
75 to the addresses, because it is accessed only through
76 the left half's CHILDREN pointers (so it's crucial not
77 to reorder this table once pointers into it exist). */
78 static Sym_Table right_ids
;
80 static Source_File non_existent_file
=
82 0, "<non-existent-file>", 0, 0, 0, NULL
87 sym_id_add (spec
, which_table
)
92 int len
= strlen (spec
);
94 id
= (struct sym_id
*) xmalloc (sizeof (*id
) + len
+ 1);
95 memset (id
, 0, sizeof (*id
));
97 id
->spec
= (char *) id
+ sizeof (*id
);
98 strcpy (id
->spec
, spec
);
99 id
->which_table
= which_table
;
106 /* A spec has the syntax FILENAME:(FUNCNAME|LINENUM). As a convenience
107 to the user, a spec without a colon is interpreted as:
109 (i) a FILENAME if it contains a dot
110 (ii) a FUNCNAME if it starts with a non-digit character
111 (iii) a LINENUM if it starts with a digit
113 A FUNCNAME containing a dot can be specified by :FUNCNAME, a
114 FILENAME not containing a dot can be specified by FILENAME. */
117 parse_spec (spec
, sym
)
124 colon
= strrchr (spec
, ':');
132 sym
->file
= source_file_lookup_name (spec
);
135 sym
->file
= &non_existent_file
;
142 if (ISDIGIT (spec
[0]))
143 sym
->line_num
= atoi (spec
);
148 else if (strlen (spec
))
150 /* No colon: spec is a filename if it contains a dot. */
151 if (strchr (spec
, '.'))
153 sym
->file
= source_file_lookup_name (spec
);
156 sym
->file
= &non_existent_file
;
158 else if (ISDIGIT (*spec
))
160 sym
->line_num
= atoi (spec
);
162 else if (strlen (spec
))
170 /* A symbol id has the syntax SPEC[/SPEC], where SPEC is is defined
179 DBG (IDDEBUG
, printf ("[parse_id] %s -> ", id
->spec
));
181 slash
= strchr (id
->spec
, '/');
184 parse_spec (slash
+ 1, &id
->right
.sym
);
186 id
->has_right
= TRUE
;
188 parse_spec (id
->spec
, &id
->left
.sym
);
191 if (debug_level
& IDDEBUG
)
193 printf ("%s:", id
->left
.sym
.file
? id
->left
.sym
.file
->name
: "*");
195 if (id
->left
.sym
.name
)
196 printf ("%s", id
->left
.sym
.name
);
197 else if (id
->left
.sym
.line_num
)
198 printf ("%d", id
->left
.sym
.line_num
);
205 id
->right
.sym
.file
? id
->right
.sym
.file
->name
: "*");
207 if (id
->right
.sym
.name
)
208 printf ("%s", id
->right
.sym
.name
);
209 else if (id
->right
.sym
.line_num
)
210 printf ("%d", id
->right
.sym
.line_num
);
221 /* Return TRUE iff PATTERN matches SYM. */
228 return (pattern
->file
? pattern
->file
== sym
->file
: TRUE
)
229 && (pattern
->line_num
? pattern
->line_num
== sym
->line_num
: TRUE
)
231 ? strcmp (pattern
->name
,
232 sym
->name
+(discard_underscores
&& sym
->name
[0] == '_')) == 0
238 extend_match (m
, sym
, tab
, second_pass
)
242 bfd_boolean second_pass
;
244 if (m
->prev_match
!= sym
- 1)
246 /* Discontinuity: add new match to table. */
249 tab
->base
[tab
->len
] = *sym
;
250 m
->prev_index
= tab
->len
;
252 /* Link match into match's chain. */
253 tab
->base
[tab
->len
].next
= m
->first_match
;
254 m
->first_match
= &tab
->base
[tab
->len
];
260 /* Extend match to include this symbol. */
262 tab
->base
[m
->prev_index
].end_addr
= sym
->end_addr
;
268 /* Go through sym_id list produced by option processing and fill
269 in the various symbol tables indicating what symbols should
270 be displayed or suppressed for the various kinds of outputs.
272 This can potentially produce huge tables and in particulars
273 tons of arcs, but this happens only if the user makes silly
274 requests---you get what you ask for! */
279 Sym
*sym
, *left
, *right
;
283 /* Convert symbol ids into Syms, so we can deal with them more easily. */
284 for (id
= id_list
; id
; id
= id
->next
)
287 /* First determine size of each table. */
288 for (sym
= symtab
.base
; sym
< symtab
.limit
; ++sym
)
290 for (id
= id_list
; id
; id
= id
->next
)
292 if (match (&id
->left
.sym
, sym
))
293 extend_match (&id
->left
, sym
, &syms
[id
->which_table
], FALSE
);
295 if (id
->has_right
&& match (&id
->right
.sym
, sym
))
296 extend_match (&id
->right
, sym
, &right_ids
, FALSE
);
300 /* Create tables of appropriate size and reset lengths. */
301 for (tab
= syms
; tab
< &syms
[NUM_TABLES
]; ++tab
)
305 tab
->base
= (Sym
*) xmalloc (tab
->len
* sizeof (Sym
));
306 tab
->limit
= tab
->base
+ tab
->len
;
313 right_ids
.base
= (Sym
*) xmalloc (right_ids
.len
* sizeof (Sym
));
314 right_ids
.limit
= right_ids
.base
+ right_ids
.len
;
318 /* Make a second pass through symtab, creating syms as necessary. */
319 for (sym
= symtab
.base
; sym
< symtab
.limit
; ++sym
)
321 for (id
= id_list
; id
; id
= id
->next
)
323 if (match (&id
->left
.sym
, sym
))
324 extend_match (&id
->left
, sym
, &syms
[id
->which_table
], TRUE
);
326 if (id
->has_right
&& match (&id
->right
.sym
, sym
))
327 extend_match (&id
->right
, sym
, &right_ids
, TRUE
);
331 /* Go through ids creating arcs as needed. */
332 for (id
= id_list
; id
; id
= id
->next
)
336 for (left
= id
->left
.first_match
; left
; left
= left
->next
)
338 for (right
= id
->right
.first_match
; right
; right
= right
->next
)
342 "[sym_id_parse]: arc %s:%s(%lx-%lx) -> %s:%s(%lx-%lx) to %s\n",
343 left
->file
? left
->file
->name
: "*",
344 left
->name
? left
->name
: "*",
345 (unsigned long) left
->addr
,
346 (unsigned long) left
->end_addr
,
347 right
->file
? right
->file
->name
: "*",
348 right
->name
? right
->name
: "*",
349 (unsigned long) right
->addr
,
350 (unsigned long) right
->end_addr
,
351 table_name
[id
->which_table
]));
353 arc_add (left
, right
, (unsigned long) 0);
359 /* Finally, we can sort the tables and we're done. */
360 for (tab
= &syms
[0]; tab
< &syms
[NUM_TABLES
]; ++tab
)
362 DBG (IDDEBUG
, printf ("[sym_id_parse] syms[%s]:\n",
363 table_name
[tab
- &syms
[0]]));
364 symtab_finalize (tab
);
369 /* Symbol tables storing the FROM symbols of arcs do not necessarily
370 have distinct address ranges. For example, somebody might request
371 -k /_mcount to suppress any arcs into _mcount, while at the same
372 time requesting -k a/b. Fortunately, those symbol tables don't get
373 very big (the user has to type them!), so a linear search is probably
376 sym_id_arc_is_present (sym_tab
, from
, to
)
383 for (sym
= sym_tab
->base
; sym
< sym_tab
->limit
; ++sym
)
385 if (from
->addr
>= sym
->addr
&& from
->addr
<= sym
->end_addr
386 && arc_lookup (sym
, to
))