summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org>2016-11-12 12:09:49 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2016-11-14 21:34:33 (GMT)
commit614eabb225a9f62d1dbfe50fe44e7b9db9c0467d (patch) (unidiff)
treeed0ae264afb6e4dc4b7bc3f3f908281ebd50f220 /src
parentb92047ed10c4da784c296dfcf09da250b7b637c7 (diff)
downloadcflow-614eabb225a9f62d1dbfe50fe44e7b9db9c0467d.tar.gz
cflow-614eabb225a9f62d1dbfe50fe44e7b9db9c0467d.tar.bz2
Include static symbols as root points in inverted graphs.
* src/cflow.h (linked_list_size): New function. * src/linked-list.c (linked_list_size): New function. * src/symbol.c (collect_symbols): Include static symbols, if allowed by sel. * src/main.c (parse_opt): Exclude static symbols for --xref
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/cflow.h1
-rw-r--r--src/linked-list.c15
-rw-r--r--src/main.c1
-rw-r--r--src/symbol.c35
4 files changed, 39 insertions, 13 deletions
diff --git a/src/cflow.h b/src/cflow.h
index 5867a18..0e3ee44 100644
--- a/src/cflow.h
+++ b/src/cflow.h
@@ -198,6 +198,7 @@ void linked_list_iterate(struct linked_list **plist,
198 int (*itr) (void *, void *), void *data); 198 int (*itr) (void *, void *), void *data);
199void linked_list_unlink(struct linked_list *list, 199void linked_list_unlink(struct linked_list *list,
200 struct linked_list_entry *ent); 200 struct linked_list_entry *ent);
201size_t linked_list_size(struct linked_list *list);
201 202
202int data_in_list(void *data, struct linked_list *list); 203int data_in_list(void *data, struct linked_list *list);
203 204
diff --git a/src/linked-list.c b/src/linked-list.c
index 095b63e..3c57bf0 100644
--- a/src/linked-list.c
+++ b/src/linked-list.c
@@ -17,7 +17,7 @@
17#include <cflow.h> 17#include <cflow.h>
18 18
19static struct linked_list * 19static struct linked_list *
20deref_linked_list (struct linked_list **plist) 20deref_linked_list(struct linked_list **plist)
21{ 21{
22 if (!*plist) { 22 if (!*plist) {
23 struct linked_list *list = xmalloc(sizeof(*list)); 23 struct linked_list *list = xmalloc(sizeof(*list));
@@ -144,3 +144,16 @@ data_in_list(void *data, struct linked_list *list)
144 return 1; 144 return 1;
145 return 0; 145 return 0;
146} 146}
147
148size_t
149linked_list_size(struct linked_list *list)
150{
151 size_t size = 0;
152 if (list) {
153 struct linked_list_entry *p;
154 for (p = linked_list_head(list); p; p = p->next)
155 size++;
156 }
157 return size;
158}
159
diff --git a/src/main.c b/src/main.c
index e034439..b70384f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -647,6 +647,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
647 break; 647 break;
648 case 'x': 648 case 'x':
649 print_option = PRINT_XREF; 649 print_option = PRINT_XREF;
650 SYMBOL_EXCLUDE('s'); /* Exclude static symbols by default */
650 break; 651 break;
651 case OPT_PREPROCESS: 652 case OPT_PREPROCESS:
652 preprocess_option = 1; 653 preprocess_option = 1;
diff --git a/src/symbol.c b/src/symbol.c
index 460f954..5f7dec2 100644
--- a/src/symbol.c
+++ b/src/symbol.c
@@ -297,21 +297,35 @@ collect_processor(void *data, void *proc_data)
297 return true; 297 return true;
298} 298}
299 299
300static int
301collect_list_entry(void *item, void *proc_data)
302{
303 Symbol *s = item;
304 struct collect_data *cd = proc_data;
305 if (cd->sel(s)) {
306 cd->sym[cd->index] = s;
307 cd->index++;
308 }
309 return 0;
310}
311
300size_t 312size_t
301collect_symbols(Symbol ***return_sym, int (*sel)(Symbol *p), 313collect_symbols(Symbol ***return_sym, int (*sel)(Symbol *p),
302 size_t reserved_slots) 314 size_t reserved_slots)
303{ 315{
304 struct collect_data cdata; 316 struct collect_data cdata;
305 317 size_t size;
306 cdata.sym = NULL; 318
319 size = hash_get_n_entries(symbol_table)
320 + linked_list_size(static_func_list);
321 cdata.sym = xcalloc(size + reserved_slots, sizeof(*cdata.sym));
307 cdata.index = 0; 322 cdata.index = 0;
308 cdata.sel = sel; 323 cdata.sel = sel;
309 hash_do_for_each (symbol_table, collect_processor, &cdata); 324 hash_do_for_each(symbol_table, collect_processor, &cdata);
310 cdata.sym = calloc(cdata.index + reserved_slots, sizeof(*cdata.sym)); 325 linked_list_iterate(&static_func_list, collect_list_entry, &cdata);
311 if (!cdata.sym) 326
312 xalloc_die(); 327 cdata.sym = xrealloc(cdata.sym,
313 cdata.index = 0; 328 (cdata.index + reserved_slots) * sizeof(*cdata.sym));
314 hash_do_for_each (symbol_table, collect_processor, &cdata);
315 *return_sym = cdata.sym; 329 *return_sym = cdata.sym;
316 return cdata.index; 330 return cdata.index;
317} 331}
@@ -324,10 +338,7 @@ collect_functions(Symbol ***return_sym)
324 struct linked_list_entry *p; 338 struct linked_list_entry *p;
325 339
326 /* Count static functions */ 340 /* Count static functions */
327 snum = 0; 341 snum = linked_list_size(static_func_list);
328 if (static_func_list)
329 for (p = linked_list_head(static_func_list); p; p = p->next)
330 snum++;
331 342
332 /* Collect global functions */ 343 /* Collect global functions */
333 num = collect_symbols(&symbols, symbol_is_function, snum); 344 num = collect_symbols(&symbols, symbol_is_function, snum);

Return to:

Send suggestions and report system problems to the System administrator.