From 2dfa833d5a60487e2affab296a2696d09be4ceee Mon Sep 17 00:00:00 2001 From: Sergey Samoylenko Date: Mon, 14 Feb 2022 12:18:49 +0300 Subject: [PATCH 2/2] sbitmapq: add '-p' option The -p option says, an associated with sbitmap_queue array contains the pointers on a structure. This allows the sbitmapq command works correctly with the array of pointers attached to the sbitmap_queue. Signed-off-by: Sergey Samoylenko --- help.c | 4 +++- sbitmap.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/help.c b/help.c index 679a46e5a2f7..3eefa5e12ec6 100644 --- a/help.c +++ b/help.c @@ -965,7 +965,7 @@ NULL char *help_sbitmapq[] = { "sbitmapq", "sbitmap_queue struct contents", -"[-s struct[.member[,member]] -a address [-v]] -[x|d] address", +"[-s struct[.member[,member]] -a address [-p] [-v]] -[x|d] address", " The command dumps the contents of the sbitmap_queue structure and", " the used bits in the bitmap. Also, it shows the dump of a structure", " array associated with the sbitmap_queue.", @@ -979,6 +979,8 @@ char *help_sbitmapq[] = { " -a address address of a structure array associated with sbitmap_queue", " structure. The set bits in sbitmap are used for the index", " in an associated array.", +" -p associated with sbitmap_queue array contains the points of", +" structure." " -x override default output format with hexadecimal format.", " -d override default output format with decimal format.", " -v By default, the sbitmap command shows only a used sbitmap", diff --git a/sbitmap.c b/sbitmap.c index 4d8feb931237..91a52741141c 100644 --- a/sbitmap.c +++ b/sbitmap.c @@ -34,6 +34,7 @@ struct sbitmapq_data { #define SBITMAPQ_DATA_FLAG_STRUCT_NAME (VERBOSE << 1) #define SBITMAPQ_DATA_FLAG_STRUCT_MEMBER (VERBOSE << 2) #define SBITMAPQ_DATA_FLAG_ARRAY_ADDR (VERBOSE << 3) +#define SBITMAPQ_DATA_FLAG_ARRAY_OF_POINTS (VERBOSE << 4) ulong flags; int radix; /* sbitmap_queue info */ @@ -442,9 +443,22 @@ static bool sbitmap_data_print(unsigned int idx, ulong addr, void *p) const struct sbitmapq_data *sd = p; bool verbose = !!(sd->flags & VERBOSE); bool members = !!(sd->flags & SBITMAPQ_DATA_FLAG_STRUCT_MEMBER); + bool points = !!(sd->flags & SBITMAPQ_DATA_FLAG_ARRAY_OF_POINTS); if (verbose) { fprintf(fp, "%d (0x%08lx):\n", idx, addr); + + if (points) { + ulong p_addr; + + if (!readmem(addr, KVADDR, &p_addr, sizeof(void *), + "read point of data", RETURN_ON_ERROR)) { + error(INFO, "Failed to read the point of data: 0x%08lx\n", addr); + return false; + } + addr = p_addr; + } + if (members) dump_struct_members(sd->data_name, addr, sd->radix); else @@ -459,7 +473,7 @@ static void sbitmap_queue_data_dump(struct sbitmapq_data *sd) { struct sbitmapq_ops ops = { .addr = sd->data_addr, - .size = sd->data_size, + .size = (sd->flags & SBITMAPQ_DATA_FLAG_ARRAY_OF_POINTS) ? sizeof(void *) : sd->data_size, .fn = sbitmap_data_print, .p = sd }; @@ -556,7 +570,7 @@ void cmd_sbitmapq(void) struct sbitmapq_data sd = {0}; int c; - while ((c = getopt(argcnt, args, "s:a:xdv")) != EOF) { + while ((c = getopt(argcnt, args, "s:a:pxdv")) != EOF) { switch (c) { case 's': if (sd.flags & SBITMAPQ_DATA_FLAG_STRUCT_NAME) @@ -580,6 +594,10 @@ void cmd_sbitmapq(void) break; + case 'p': + sd.flags |= SBITMAPQ_DATA_FLAG_ARRAY_OF_POINTS; + break; + case 'v': sd.flags |= VERBOSE; break; @@ -629,6 +647,12 @@ void cmd_sbitmapq(void) cmd_usage(pc->curcmd, SYNOPSIS); } + if ((sd.flags & SBITMAPQ_DATA_FLAG_ARRAY_OF_POINTS) && + !(sd.flags & SBITMAPQ_DATA_FLAG_ARRAY_ADDR)) { + error(INFO, "-p option requires -a option\n"); + cmd_usage(pc->curcmd, SYNOPSIS); + } + if (sd.flags & SBITMAPQ_DATA_FLAG_STRUCT_NAME) { if (count_chars(sd.data_name, '.') > 0) sd.flags |= SBITMAPQ_DATA_FLAG_STRUCT_MEMBER; -- 2.27.0