Changelog: change save file pointer to the pc->tmpfile2 Signed-off-by: Lei Wen <leiwen@xxxxxxxxxxx> --- help.c | 4 +++- memory.c | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/help.c b/help.c index b8db00a..e073fde 100755 --- a/help.c +++ b/help.c @@ -1396,7 +1396,7 @@ NULL char *help_rd[] = { "rd", "read memory", -"[-adDsSupxmfN][-8|-16|-32|-64][-o offs][-e addr] [address|symbol] [count]", +"[-adDsSupxmfN][-8|-16|-32|-64][-o offs][-e addr][-r [image]] [address|symbol] [count]", " This command displays the contents of memory, with the output formatted", " in several different manners. The starting address may be entered either", " symbolically or by address. The default output size is the size of a long", @@ -1427,6 +1427,8 @@ char *help_rd[] = { " -N display output in network byte order (only valid for 16- and 32-bit", " values)", " -o offs offset the starting address by offs.", +" -r image directly dump to the image file by raw data, it require either count", +" option, or -e addr option.", " -e addr display memory until reaching specified ending hexadecimal address.", " address starting hexadecimal address:", " 1 the default presumes a kernel virtual address.", diff --git a/memory.c b/memory.c index 9575d8e..4d44679 100755 --- a/memory.c +++ b/memory.c @@ -264,7 +264,9 @@ static void dump_page_flags(ulonglong); #define SLAB_CACHE (0x1000) #define DISPLAY_ASCII (0x2000) #define NET_ENDIAN (0x4000) -#define DISPLAY_TYPES (DISPLAY_ASCII|DISPLAY_8|DISPLAY_16|DISPLAY_32|DISPLAY_64) +#define DISPLAY_RAW (0x8000) +#define DISPLAY_TYPES (DISPLAY_RAW|DISPLAY_ASCII|DISPLAY_8|\ + DISPLAY_16|DISPLAY_32|DISPLAY_64) #define ASCII_UNLIMITED ((ulong)(-1) >> 1) @@ -966,6 +968,8 @@ cmd_rd(void) ulonglong addr, endaddr; ulong offset; struct syment *sp; + FILE *tmpfp = NULL; + char *dumpfile; flag = HEXADECIMAL|DISPLAY_DEFAULT; endaddr = 0; @@ -973,7 +977,7 @@ cmd_rd(void) memtype = KVADDR; count = -1; - while ((c = getopt(argcnt, args, "axme:pfudDusSNo:81:3:6:")) != EOF) { + while ((c = getopt(argcnt, args, "axme:r:pfudDusSNo:81:3:6:")) != EOF) { switch(c) { case 'a': @@ -1023,6 +1027,17 @@ cmd_rd(void) endaddr = htoll(optarg, FAULT_ON_ERROR, NULL); break; + case 'r': + flag &= ~DISPLAY_TYPES; + flag |= DISPLAY_RAW; + dumpfile = optarg; + tmpfp = fopen(dumpfile, "w"); + if (tmpfp == NULL) + error(FATAL, "cannot open dump image\n"); + else + pc->tmpfile2 = tmpfp; + + break; case 's': case 'S': if (flag & DISPLAY_DEFAULT) { @@ -1137,6 +1152,7 @@ cmd_rd(void) count = bcnt/2; break; case DISPLAY_8: + case DISPLAY_RAW: case DISPLAY_ASCII: count = bcnt; break; @@ -1160,6 +1176,12 @@ cmd_rd(void) } display_memory(addr, count, flag, memtype); + if (tmpfp) { + fclose(tmpfp); + pc->tmpfile2 = NULL; + printf("%d bytes written from 0x%llx to %s\n", + count, addr, dumpfile); + } } /* @@ -1239,6 +1261,18 @@ display_memory(ulonglong addr, long count, ulong flag, int memtype) fprintf(fp, "<addr: %llx count: %ld flag: %lx (%s)>\n", addr, count, flag, addrtype); + if (flag & DISPLAY_RAW) { + for (i = 0; i < count;){ + a = (BUFSIZE > count - i) ? (count - i) : BUFSIZE; + readmem(addr + i, memtype, buf, a, + "raw dump to file", FAULT_ON_ERROR); + for (j = 0; j < a; j ++) + fputc(buf[j], pc->tmpfile2); + i += a; + } + return; + } + BZERO(&mem, sizeof(struct memloc)); hx = linelen = typesz = per_line = ascii_start = 0; location = NULL; -- 1.7.0.4 -- Crash-utility mailing list Crash-utility@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/crash-utility