# HG changeset patch # User Michael Spacefalcon # Date 1404491871 0 # Node ID 928ed52930aae704f9c7849b829c81c0cb6e4e53 # Parent 10c0cdc18208a521e44d317968c81b0d71b71338 objgrep-fe: works after fixing a buglet diff -r 10c0cdc18208 -r 928ed52930aa objgrep/frontend.c --- a/objgrep/frontend.c Fri Jul 04 08:46:32 2014 +0000 +++ b/objgrep/frontend.c Fri Jul 04 16:37:51 2014 +0000 @@ -30,6 +30,7 @@ struct symbol *flash_symbols, *ram_symbols; unsigned num_flash_symbols, num_ram_symbols; char *binfilename; +int verbose; enter_symbol(name, valstr, symsrc) char *name, *valstr; @@ -68,6 +69,8 @@ "This module's symbols deduced from section relocs:"; sprintf(cmdline, "objgrep -rs %s %s %s", objfile, secname, binfilename); + if (verbose) + printf("Running %s\n", cmdline); f = popen(cmdline, "r"); if (!f) { perror("popen"); @@ -192,7 +195,7 @@ p = buf; for (sym = head; sym; sym = sym->next) - *p = sym; + *p++ = sym; } unsigned @@ -251,20 +254,32 @@ struct symbol **input, **output; unsigned final_count; + if (verbose) + printf("Total symbols to process: %u\n", total); input = malloc(sizeof(void *) * total); if (!input) { perror("malloc"); exit(1); } + if (verbose) + printf("Turning linked list into linear array\n"); fill_input_array(head, input); + if (verbose) + printf("Sorting by name\n"); qsort(input, total, sizeof(void *), sort_by_name); + if (verbose) + printf("Allocating output array\n"); output = malloc(sizeof(void *) * total); if (!output) { perror("malloc"); exit(1); } + if (verbose) + printf("Processing duplicates\n"); final_count = dedup_symbols(input, output, total); free(input); + if (verbose) + printf("%u symbols left, sorting by value\n", final_count); qsort(output, final_count, sizeof(void *), sort_by_value); emit_final_symbols(output, final_count); free(output); @@ -274,12 +289,25 @@ main(argc, argv) char **argv; { - if (argc != 3) { - fprintf(stderr, "usage: %s listfile binfile\n", argv[0]); - exit(1); - } - binfilename = argv[2]; - process_list_file(argv[1]); + int c; + extern int optind; + + while ((c = getopt(argc, argv, "v")) != EOF) + switch (c) { + case 'v': + verbose++; + continue; + default: + usage: + fprintf(stderr, "usage: %s [-v] listfile binfile\n", + argv[0]); + exit(1); + } + if (argc - optind != 2) + goto usage; + + binfilename = argv[optind+1]; + process_list_file(argv[optind]); if (flash_symbols) { printf("Flash symbols:\n\n"); sort_and_emit_symbols(flash_symbols, num_flash_symbols);