diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b46c15ee790..c60991ff913 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2007-06-12 Seongbae Park + + * opts.c (common_handle_option): Handle new option -fdbg-cnt-list. + * dbgcnt.c (dbg_cnt_set_limit_by_name): Return value + to indicate an error. + (dbg_cnt_process_single_pair, dbg_cnt_list_all_counters): New functions + (dbg_cnt_process_opt): Print an error on a bad argument. + * dbgcnt.h (dbg_cnt_list_all_counters): New function declaration. + * common.opt (-fdbg-cnt-list): New. + * doc/invoke.texi (-fdbg-cnt-list,-fdbg-cnt=): New. + 2007-06-12 Eric Botcazou * tree-ssa-alias.c (finalize_ref_all_pointers): Clear pt_anything diff --git a/gcc/common.opt b/gcc/common.opt index 726c3509758..d03652c0ad3 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -392,9 +392,13 @@ fdata-sections Common Report Var(flag_data_sections) Optimization Place data items into their own section +fdbg-cnt-list +Common Report +List all available debugging counters with their limits and counts. + fdbg-cnt= Common RejectNegative Joined --fdbg-cnt=: Set the debug counter limit. +-fdbg-cnt=:[,:,...] Set the debug counter limit. ; Nonzero for -fdefer-pop: don't pop args after each function call ; instead save them up to pop many calls' args with one insns. diff --git a/gcc/dbgcnt.c b/gcc/dbgcnt.c index df021112064..660428e1968 100644 --- a/gcc/dbgcnt.c +++ b/gcc/dbgcnt.c @@ -23,6 +23,7 @@ See dbgcnt.def for usage information. */ #include "config.h" #include "system.h" #include "coretypes.h" +#include "errors.h" #include "dbgcnt.h" @@ -70,7 +71,7 @@ dbg_cnt_set_limit_by_index (enum debug_counter index, int value) fprintf (stderr, "dbg_cnt '%s' set to %d\n", map[index].name, value); } -static void +static bool dbg_cnt_set_limit_by_name (const char *name, int len, int value) { int i; @@ -79,29 +80,66 @@ dbg_cnt_set_limit_by_name (const char *name, int len, int value) break; if (i < 0) - return; + return false; dbg_cnt_set_limit_by_index (i, value); + return true; +} + + +/* Process a single "name:value" pair. + Returns NULL if there's no valid pair is found. + Otherwise returns a pointer to the end of the pair. */ + +static const char * +dbg_cnt_process_single_pair (const char *arg) +{ + char *colon = strchr (arg, ':'); + char *endptr = NULL; + int value; + + if (colon == NULL) + return NULL; + + value = strtol (colon + 1, &endptr, 10); + + if (endptr != NULL && endptr != colon + 1 + && dbg_cnt_set_limit_by_name (arg, colon - arg, value)) + return endptr; + + return NULL; } void dbg_cnt_process_opt (const char *arg) { - char *colon = strchr (arg, ':'); - char *comma; - - if (colon == NULL) - return; + const char *start = arg; + const char *next; + do { + next = dbg_cnt_process_single_pair (arg); + if (next == NULL) + break; + } while (*next == ',' && (arg = next + 1)); - dbg_cnt_set_limit_by_name (arg, colon - arg, atoi (colon + 1)); - - comma = strchr (colon + 1, ','); - while (comma) + if (next == NULL || *next != 0) { - colon = strchr (comma + 1, ':'); - if (colon == NULL || !(colon[1] >= '0' && colon[1] <= '9')) - return; - dbg_cnt_set_limit_by_name (comma + 1, colon - (comma + 1), atoi (colon + 1)); - comma = strchr (colon + 1, ','); + char *buffer = alloca (arg - start + 2); + sprintf (buffer, "%*c", (int)(1 + (arg - start)), '^'); + error ("Can not find a valid counter:value pair:"); + error ("-fdbg-cnt=%s", start); + error (" %s", buffer); } } + +/* Print name, limit and count of all counters. */ + +void dbg_cnt_list_all_counters (void) +{ + int i; + printf (" %-30s %-5s %-5s\n", "counter name", "limit", "value"); + printf ("----------------------------------------------\n"); + for (i = 0; i < debug_counter_number_of_counters; i++) + printf (" %-30s %5d %5u\n", + map[i].name, limit[map[i].counter], count[map[i].counter]); + printf ("\n"); +} diff --git a/gcc/dbgcnt.h b/gcc/dbgcnt.h index 38591e9b2ed..aafa6663ac8 100644 --- a/gcc/dbgcnt.h +++ b/gcc/dbgcnt.h @@ -35,5 +35,6 @@ enum debug_counter { extern bool dbg_cnt_is_enabled (enum debug_counter index); extern bool dbg_cnt (enum debug_counter index); extern void dbg_cnt_process_opt (const char *arg); +extern void dbg_cnt_list_all_counters (void); #endif /* GCC_DBGCNT_H */ diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 3675ebdc73a..dddb37da84e 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -269,6 +269,7 @@ Objective-C and Objective-C++ Dialects}. @item Debugging Options @xref{Debugging Options,,Options for Debugging Your Program or GCC}. @gccoptlist{-d@var{letters} -dumpspecs -dumpmachine -dumpversion @gol +-fdbg-cnt-list -fdbg-cnt=@var{counter-value-list} @gol -fdump-noaddr -fdump-unnumbered -fdump-translation-unit@r{[}-@var{n}@r{]} @gol -fdump-class-hierarchy@r{[}-@var{n}@r{]} @gol -fdump-ipa-all -fdump-ipa-cgraph @gol @@ -4211,6 +4212,21 @@ above for a description of @var{auxname} and instructions on how to generate test coverage data. Coverage data will match the source files more closely, if you do not optimize. +@item -fdbg-cnt-list +@opindex fdbg-cnt-list +Print the name and the counter upperbound for all debug counters. + +@item -fdbg-cnt=@var{counter-value-list} +@opindex fdbg-cnt +Set the internal debug counter upperbound. @var{counter-value-list} +is a comma-separated list of @var{name}:@var{value} pairs +which sets the upperbound of each debug counter @var{name} to @var{value}. +All debug counters have the initial upperbound of @var{UINT_MAX}, +thus dbg_cnt() returns true always unless the upperbound is set by this option. +e.g. With -fdbg-cnt=dce:10,tail_call:0 +dbg_cnt(dce) will return true only for first 10 invocations +and dbg_cnt(tail_call) will return false always. + @item -d@var{letters} @item -fdump-rtl-@var{pass} @opindex d diff --git a/gcc/opts.c b/gcc/opts.c index aac35583fce..974c19b3765 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -1434,6 +1434,10 @@ common_handle_option (size_t scode, const char *arg, int value, dbg_cnt_process_opt (arg); break; + case OPT_fdbg_cnt_list: + dbg_cnt_list_all_counters (); + break; + case OPT_fdiagnostics_show_location_: if (!strcmp (arg, "once")) diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;