aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2016-11-12 14:09:49 +0200
committerSergey Poznyakoff <gray@gnu.org>2016-11-14 23:34:33 +0200
commit614eabb225a9f62d1dbfe50fe44e7b9db9c0467d (patch)
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')
-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
@@ -189,24 +189,25 @@ void delete_statics(void);
void delete_parms(int level);
void move_parms(int level);
size_t collect_symbols(Symbol ***, int (*sel)(), size_t rescnt);
size_t collect_functions(Symbol ***return_sym);
struct linked_list *linked_list_create(linked_list_free_data_fp fun);
void linked_list_destroy(struct linked_list **plist);
void linked_list_append(struct linked_list **plist, void *data);
void linked_list_prepend(struct linked_list **plist, void *data);
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);
int get_token(void);
int source(char *name);
void init_lex(int debug_level);
void set_preprocessor(const char *arg);
void pp_option(const char *arg);
void init_parse(void);
int yyparse(void);
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
@@ -8,25 +8,25 @@
GNU cflow is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#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));
list->free_data = NULL;
list->head = list->tail = NULL;
*plist = list;
}
return *plist;
}
struct linked_list *
@@ -135,12 +135,25 @@ linked_list_iterate(struct linked_list **plist,
}
int
data_in_list(void *data, struct linked_list *list)
{
struct linked_list_entry *p;
for (p = linked_list_head(list); p; p = p->next)
if (p->data == data)
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
@@ -638,24 +638,25 @@ parse_opt (int key, char *arg, struct argp_state *state)
break;
case 's':
symbol_override(arg);
break;
case 'v':
verbose = 1;
break;
case OPT_NO_VERBOSE:
verbose = 0;
break;
case 'x':
print_option = PRINT_XREF;
+ SYMBOL_EXCLUDE('s'); /* Exclude static symbols by default */
break;
case OPT_PREPROCESS:
preprocess_option = 1;
set_preprocessor(arg ? arg : CFLOW_PREPROC);
break;
case OPT_NO_PREPROCESS:
preprocess_option = 0;
break;
case ARGP_KEY_ARG:
add_name(arg);
break;
case 'I':
diff --git a/src/symbol.c b/src/symbol.c
index 460f954..5f7dec2 100644
--- a/src/symbol.c
+++ b/src/symbol.c
@@ -288,55 +288,66 @@ collect_processor(void *data, void *proc_data)
struct collect_data *cd = proc_data;
Symbol *s;
for (s = t->sym; s; s = s->next) {
if (cd->sel(s)) {
if (cd->sym)
cd->sym[cd->index] = s;
cd->index++;
}
}
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;
}
size_t
collect_functions(Symbol ***return_sym)
{
Symbol **symbols;
size_t num, snum;
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);
/* Collect static functions */
if (snum)
for (p = linked_list_head(static_func_list); p; p = p->next)
symbols[num++] = p->data;
*return_sym = symbols;
return num;
}

Return to:

Send suggestions and report system problems to the System administrator.