[PATCH 3/3] Allow hex/dec override for "percpu"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add standard options to override the default decimal/hexadecimal output
format.

Signed-off-by: Petr Tesarik <ptesarik@xxxxxxx>

---
 help.c    |    5 ++++-
 symbols.c |   22 +++++++++++++++++++++-
 2 files changed, 25 insertions(+), 2 deletions(-)
Allow hex/dec override for "percpu"

Add standard options to override the default decimal/hexadecimal output
format.

Signed-off-by: Petr Tesarik <ptesarik@xxxxxxx>

---
 help.c    |    5 ++++-
 symbols.c |   22 +++++++++++++++++++++-
 2 files changed, 25 insertions(+), 2 deletions(-)

--- a/help.c
+++ b/help.c
@@ -1150,7 +1150,7 @@ NULL
 char *help_percpu[] = {
 "percpu",
 "percpu variables",
-"[-a] [-c cpu] [cpu]... [struct|union|*] [struct_name] [address|symbol]",
+"[-dx][-a] [-c cpu] [cpu]... [struct|union|*] [struct_name] [address|symbol]",
 "  This command displays a formatted display of the contents of a per-cpu",
 "  variable for a given set of CPUs.",
 " ",
@@ -1158,6 +1158,9 @@ char *help_percpu[] = {
 "        -a  show all CPUs.",
 "    -c cpu  specify cpu set, e.g. \"1,3,5\", \"1-3\", or \"1,3,5-7,10\".",
 "       cpu  show for a specific CPU (numeric only, can be repeated).",
+"  Other options:",
+"        -d  override default output format with decimal format.",
+"        -x  override default output format with hexadecimal format.",
 " ",
 "  If no CPU specifiers are present, percpu will use the CPU of the",
 "  currently selected task.",
--- a/symbols.c
+++ b/symbols.c
@@ -6019,6 +6019,7 @@ cmd_percpu(void)
 	int cpulen;
 	ulong *cpus;
 	int cflag;
+	unsigned int radix, restore_radix;
 	ulong flags;
 	char *structname, *typename;
         struct datatype_member datatype_member, *dm = &datatype_member;
@@ -6027,12 +6028,13 @@ cmd_percpu(void)
 	char buf[BUFSIZE];
 
 	cflag = 0;
+	radix = 0;
 
 	if ((cpulen = STRUCT_SIZE("cpumask_t")) < 0)
 		cpulen = DIV_ROUND_UP(kt->cpus, BITS_PER_LONG) * sizeof(ulong);
 	cpus = (ulong *)GETBUF(cpulen);
 
-	while ((c = getopt(argcnt, args, "ac:")) != EOF) {
+	while ((c = getopt(argcnt, args, "ac:dx")) != EOF) {
 		switch (c)
 		{
 		case 'a':
@@ -6046,6 +6048,20 @@ cmd_percpu(void)
 			cflag = 1;
 			break;
 
+		case 'd':
+			if (radix == 16)
+				error(FATAL,
+				    "-d and -x are mutually exclusive\n");
+			radix = 10;
+			break;
+
+		case 'x':
+			if (radix == 10)
+				error(FATAL,
+				    "-d and -x are mutually exclusive\n");
+			radix = 16;
+			break;
+
 		default:
 			argerrs++;
 			break;
@@ -6150,6 +6166,8 @@ cmd_percpu(void)
 		goto freebuf;
 	}
 
+	set_temporary_radix(radix, &restore_radix);
+
 	for (i = 0; i < kt->cpus; i++) {
 		ulong cpuaddr;
 
@@ -6181,6 +6199,8 @@ cmd_percpu(void)
 		fprintf(fp, "\n");
 	}
 
+	restore_current_radix(restore_radix);
+
 freebuf:
 	free(typename);
 	FREEBUF(cpus);
--
Crash-utility mailing list
Crash-utility@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/crash-utility

[Index of Archives]     [Fedora Development]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [KDE Users]     [Fedora Tools]

 

Powered by Linux