]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
log: enable filtering on functions
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Fri, 17 Jan 2025 00:09:53 +0000 (01:09 +0100)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sun, 26 Jan 2025 10:06:56 +0000 (11:06 +0100)
Up to now we could only use log level, category, and file for filtering.
Allow filtering on a list of functions.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
cmd/log.c
common/log.c
include/log.h
test/log/log_filter.c
test/log/log_test.c

index 519ec76f3b5100338991bee570616ec8f32dc00a..64add6d8b5a7e7cb872a7fe25b364b9d2416ebd5 100644 (file)
--- a/cmd/log.c
+++ b/cmd/log.c
@@ -115,30 +115,27 @@ static int do_log_filter_list(struct cmd_tbl *cmdtp, int flag, int argc,
                return CMD_RET_FAILURE;
        }
 
-       /*      <3> < 6  > <2+1 + 7 > <      16      > < unbounded... */
-       printf("num policy level            categories files\n");
        list_for_each_entry(filt, &ldev->filter_head, sibling_node) {
-               printf("%3d %6.6s %s %-7.7s ", filt->filter_num,
-                      filt->flags & LOGFF_DENY ? "deny" : "allow",
+               printf("%-3d: %s %s %s\n", filt->filter_num,
+                      filt->flags & LOGFF_DENY ? "DENY" : "ALLOW",
                       filt->flags & LOGFF_LEVEL_MIN ? ">=" : "<=",
                       log_get_level_name(filt->level));
 
                if (filt->flags & LOGFF_HAS_CAT) {
-                       int i;
-
-                       if (filt->cat_list[0] != LOGC_END)
-                               printf("%16.16s %s\n",
-                                      log_get_cat_name(filt->cat_list[0]),
-                                      filt->file_list ? filt->file_list : "");
-
-                       for (i = 1; i < LOGF_MAX_CATEGORIES &&
-                                   filt->cat_list[i] != LOGC_END; i++)
-                               printf("%21c %16.16s\n", ' ',
+                       printf("     Categories:");
+                       for (int i = 0;
+                            i < LOGF_MAX_CATEGORIES &&
+                            filt->cat_list[i] != LOGC_END;
+                            ++i) {
+                               printf(" %s",
                                       log_get_cat_name(filt->cat_list[i]));
-               } else {
-                       printf("%16c %s\n", ' ',
-                              filt->file_list ? filt->file_list : "");
+                       }
+                       printf("\n");
                }
+               if (filt->file_list)
+                       printf("     Files: %s\n", filt->file_list);
+               if (filt->func_list)
+                       printf("     Functions: %s\n", filt->func_list);
        }
 
        return CMD_RET_SUCCESS;
@@ -151,6 +148,7 @@ static int do_log_filter_add(struct cmd_tbl *cmdtp, int flag, int argc,
        bool print_num = false;
        bool type_set = false;
        char *file_list = NULL;
+       char *func_list = NULL;
        const char *drv_name = "console";
        int opt, err;
        int cat_count = 0;
@@ -160,7 +158,7 @@ static int do_log_filter_add(struct cmd_tbl *cmdtp, int flag, int argc,
        struct getopt_state gs;
 
        getopt_init_state(&gs);
-       while ((opt = getopt(&gs, argc, argv, "Ac:d:Df:l:L:p")) > 0) {
+       while ((opt = getopt(&gs, argc, argv, "Ac:d:Df:F:l:L:p")) > 0) {
                switch (opt) {
                case 'A':
 #define do_type() do { \
@@ -199,6 +197,9 @@ static int do_log_filter_add(struct cmd_tbl *cmdtp, int flag, int argc,
                case 'f':
                        file_list = gs.arg;
                        break;
+               case 'F':
+                       func_list = gs.arg;
+                       break;
                case 'l':
 #define do_level() do { \
                        if (level_set) { \
@@ -229,7 +230,7 @@ static int do_log_filter_add(struct cmd_tbl *cmdtp, int flag, int argc,
 
        cat_list[cat_count] = LOGC_END;
        err = log_add_filter_flags(drv_name, cat_count ? cat_list : NULL, level,
-                                  file_list, flags);
+                                  file_list, func_list, flags);
        if (err < 0) {
                printf("Could not add filter (err = %d)\n", err);
                return CMD_RET_FAILURE;
@@ -388,7 +389,8 @@ U_BOOT_LONGHELP(log,
        "\t-d <driver> - Specify the log driver to add the filter to; defaults\n"
        "\t              to console\n"
        "\t-D - Deny messages matching this filter; mutually exclusive with -A\n"
-       "\t-f <files_list> - A comma-separated list of files to match\n"
+       "\t-f <file_list> - A comma-separated list of files to match\n"
+       "\t-F <func_list> - A comma-separated list of functions to match\n"
        "\t-l <level> - Match log levels less than or equal to <level>;\n"
        "\t             mutually-exclusive with -L\n"
        "\t-L <level> - Match log levels greather than or equal to <level>;\n"
index b2b5f3c81baab79a37ec7f5a0588065e2675b40e..b75e404420bf9e45cfaac284f27cbbfb6d57ad7d 100644 (file)
@@ -192,6 +192,10 @@ static bool log_passes_filters(struct log_device *ldev, struct log_rec *rec)
                    !log_has_member(filt->file_list, rec->file))
                        continue;
 
+               if (filt->func_list &&
+                   !log_has_member(filt->func_list, rec->func))
+                       continue;
+
                if (filt->flags & LOGFF_DENY)
                        return false;
                else
@@ -329,7 +333,7 @@ int _log_buffer(enum log_category_t cat, enum log_level_t level,
 
 int log_add_filter_flags(const char *drv_name, enum log_category_t cat_list[],
                         enum log_level_t level, const char *file_list,
-                        int flags)
+                        const char *func_list, int flags)
 {
        struct log_filter *filt;
        struct log_device *ldev;
@@ -364,6 +368,13 @@ int log_add_filter_flags(const char *drv_name, enum log_category_t cat_list[],
                        goto err;
                }
        }
+       if (func_list) {
+               filt->func_list = strdup(func_list);
+               if (!filt->func_list) {
+                       ret = -ENOMEM;
+                       goto err;
+               }
+       }
        filt->filter_num = ldev->next_filter_num++;
        /* Add deny filters to the beginning of the list */
        if (flags & LOGFF_DENY)
index 3f9023ae0d2df0aa4f0a5313c9eee64d9d6cc1a8..dd44badc36119adbff17ac8450c133bc198975ba 100644 (file)
@@ -500,6 +500,7 @@ enum log_filter_flags {
  * @level: Maximum (or minimum, if %LOGFF_MIN_LEVEL) log level to allow
  * @file_list: List of files to allow, separated by comma. If NULL then all
  *     files are permitted
+ * @func_list: Comma separated list of functions or NULL.
  * @sibling_node: Next filter in the list of filters for this log device
  */
 struct log_filter {
@@ -508,6 +509,7 @@ struct log_filter {
        enum log_category_t cat_list[LOGF_MAX_CATEGORIES];
        enum log_level_t level;
        const char *file_list;
+       const char *func_list;
        struct list_head sibling_node;
 };
 
@@ -599,13 +601,14 @@ int do_log_test(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
  * @level: Maximum (or minimum, if %LOGFF_LEVEL_MIN) log level to allow
  * @file_list: List of files to allow, separated by comma. If NULL then all
  *     files are permitted
+ * @func_list: Comma separated list of functions or NULL.
  * Return:
  *   the sequence number of the new filter (>=0) if the filter was added, or a
  *   -ve value on error
  */
 int log_add_filter_flags(const char *drv_name, enum log_category_t cat_list[],
                         enum log_level_t level, const char *file_list,
-                        int flags);
+                        const char *func_list, int flags);
 
 /**
  * log_add_filter() - Add a new filter to a log device
@@ -628,7 +631,7 @@ static inline int log_add_filter(const char *drv_name,
                                 const char *file_list)
 {
        return log_add_filter_flags(drv_name, cat_list, max_level, file_list,
-                                   0);
+                                   NULL, 0);
 }
 
 /**
index d36e9d9714ef32801255a3a5e74a5554579e4d91..8622dcf29130f6f6eb70536e042c2ed51ad61893 100644 (file)
@@ -39,7 +39,6 @@ static int log_test_filter(struct unit_test_state *uts)
 
 #define create_filter(args, filter_num) do {\
        ut_assertok(run_command("log filter-add -p " args, 0)); \
-       ut_assert_skipline(); \
        ut_assertok(strict_strtoul(uts->actual_str, 10, &(filter_num))); \
        ut_assert_console_end(); \
 } while (0)
index 1c89df4ef188284410cfa6795be47d8a4125d0b1..8686b1cbef3100d38ef1f4863de36a2b0872a435 100644 (file)
@@ -320,7 +320,7 @@ int log_test_cat_deny(struct unit_test_state *uts)
        filt1 = log_add_filter("console", cat_list, LOGL_MAX, NULL);
        ut_assert(filt1 >= 0);
        filt2 = log_add_filter_flags("console", cat_list, LOGL_MAX, NULL,
-                                    LOGFF_DENY);
+                                    NULL, LOGFF_DENY);
        ut_assert(filt2 >= 0);
 
        log_run_cat(UCLASS_SPI);
@@ -340,7 +340,7 @@ int log_test_file_deny(struct unit_test_state *uts)
        filt1 = log_add_filter("console", NULL, LOGL_MAX, "file");
        ut_assert(filt1 >= 0);
        filt2 = log_add_filter_flags("console", NULL, LOGL_MAX, "file",
-                                    LOGFF_DENY);
+                                    NULL, LOGFF_DENY);
        ut_assert(filt2 >= 0);
 
        log_run_file("file");
@@ -360,7 +360,7 @@ int log_test_level_deny(struct unit_test_state *uts)
        filt1 = log_add_filter("console", NULL, LOGL_INFO, NULL);
        ut_assert(filt1 >= 0);
        filt2 = log_add_filter_flags("console", NULL, LOGL_WARNING, NULL,
-                                    LOGFF_DENY);
+                                    NULL, LOGFF_DENY);
        ut_assert(filt2 >= 0);
 
        log_run();
@@ -380,10 +380,10 @@ int log_test_min(struct unit_test_state *uts)
        int filt1, filt2;
 
        filt1 = log_add_filter_flags("console", NULL, LOGL_WARNING, NULL,
-                                    LOGFF_LEVEL_MIN);
+                                    NULL, LOGFF_LEVEL_MIN);
        ut_assert(filt1 >= 0);
        filt2 = log_add_filter_flags("console", NULL, LOGL_INFO, NULL,
-                                    LOGFF_DENY | LOGFF_LEVEL_MIN);
+                                    NULL, LOGFF_DENY | LOGFF_LEVEL_MIN);
        ut_assert(filt2 >= 0);
 
        log_run();