summaryrefslogtreecommitdiffabout
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) (side-by-side diff)
treeed0ae264afb6e4dc4b7bc3f3f908281ebd50f220
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 (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,
int (*itr) (void *, void *), void *data);
void linked_list_unlink(struct linked_list *list,
struct linked_list_entry *ent);
+size_t linked_list_size(struct linked_list *list);
int data_in_list(void *data, struct linked_list *list);
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 @@
#include <cflow.h>
static struct linked_list *
-deref_linked_list (struct linked_list **plist)
+deref_linked_list(struct linked_list **plist)
{
if (!*plist) {
struct linked_list *list = xmalloc(sizeof(*list));
@@ -144,3 +144,16 @@ data_in_list(void *data, struct linked_list *list)
return 1;
return 0;
}
+
+size_t
+linked_list_size(struct linked_list *list)
+{
+ size_t size = 0;
+ if (list) {
+ struct linked_list_entry *p;
+ for (p = linked_list_head(list); p; p = p->next)
+ size++;
+ }
+ return size;
+}
+
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)
break;
case 'x':
print_option = PRINT_XREF;
+ SYMBOL_EXCLUDE('s'); /* Exclude static symbols by default */
break;
case OPT_PREPROCESS:
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)
return true;
}
+static int
+collect_list_entry(void *item, void *proc_data)
+{
+ Symbol *s = item;
+ struct collect_data *cd = proc_data;
+ if (cd->sel(s)) {
+ cd->sym[cd->index] = s;
+ cd->index++;
+ }
+ return 0;
+}
+
size_t
collect_symbols(Symbol ***return_sym, int (*sel)(Symbol *p),
size_t reserved_slots)
{
struct collect_data cdata;
-
- cdata.sym = NULL;
+ size_t size;
+
+ size = hash_get_n_entries(symbol_table)
+ + linked_list_size(static_func_list);
+ cdata.sym = xcalloc(size + reserved_slots, sizeof(*cdata.sym));
cdata.index = 0;
cdata.sel = sel;
- hash_do_for_each (symbol_table, collect_processor, &cdata);
- cdata.sym = calloc(cdata.index + reserved_slots, sizeof(*cdata.sym));
- if (!cdata.sym)
- xalloc_die();
- cdata.index = 0;
- hash_do_for_each (symbol_table, collect_processor, &cdata);
+ hash_do_for_each(symbol_table, collect_processor, &cdata);
+ linked_list_iterate(&static_func_list, collect_list_entry, &cdata);
+
+ cdata.sym = xrealloc(cdata.sym,
+ (cdata.index + reserved_slots) * sizeof(*cdata.sym));
*return_sym = cdata.sym;
return cdata.index;
}
@@ -324,10 +338,7 @@ collect_functions(Symbol ***return_sym)
struct linked_list_entry *p;
/* Count static functions */
- snum = 0;
- if (static_func_list)
- for (p = linked_list_head(static_func_list); p; p = p->next)
- snum++;
+ snum = linked_list_size(static_func_list);
/* Collect global functions */
num = collect_symbols(&symbols, symbol_is_function, snum);

Return to:

Send suggestions and report system problems to the System administrator.