Signed-off-by: Lei Wen <[email protected]>
---
 help.c   |    3 ++-
 memory.c |   29 ++++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/help.c b/help.c
index b8db00a..cb9e79a 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,7 @@ 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",
 "  -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..073a4d4 100755
--- a/memory.c
+++ b/memory.c
@@ -264,6 +264,7 @@ static void dump_page_flags(ulonglong);
 #define SLAB_CACHE    (0x1000)
 #define DISPLAY_ASCII (0x2000)
 #define NET_ENDIAN    (0x4000)
+#define DISPLAY_RAW   (0x8000)
 #define DISPLAY_TYPES 
(DISPLAY_ASCII|DISPLAY_8|DISPLAY_16|DISPLAY_32|DISPLAY_64)
 
 #define ASCII_UNLIMITED ((ulong)(-1) >> 1)
@@ -966,6 +967,7 @@ cmd_rd(void)
        ulonglong addr, endaddr;
        ulong offset;
        struct syment *sp;
+       FILE *tmp = NULL;
 
        flag = HEXADECIMAL|DISPLAY_DEFAULT;
        endaddr = 0;
@@ -973,7 +975,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 +1025,14 @@ cmd_rd(void)
                        endaddr = htoll(optarg, FAULT_ON_ERROR, NULL);
                        break;
 
+               case 'r':
+                       flag |= DISPLAY_RAW;
+                       tmp = fp;
+                       fp = fopen(optarg, "w");
+                       if (fp == NULL)
+                               error(FATAL, "cannot open dump image\n");
+
+                       break;
                case 's':
                case 'S':
                        if (flag & DISPLAY_DEFAULT) {
@@ -1160,6 +1170,10 @@ cmd_rd(void)
        }
 
        display_memory(addr, count, flag, memtype);
+       if (tmp) {
+               fclose(fp);
+               fp = tmp;
+       }
 }
 
 /*
@@ -1288,6 +1302,19 @@ display_memory(ulonglong addr, long count, ulong flag, 
int memtype)
                break;
        }
 
+       if (flag & DISPLAY_RAW) {
+               count *= typesz;
+               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], fp);
+                       i += a;
+               }
+               return;
+       }
+
        for (i = a = 0; i < count; i++) {
                readmem(addr, memtype, location, typesz, 
                        readtype, FAULT_ON_ERROR);
-- 
1.7.0.4

--
Crash-utility mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/crash-utility

Reply via email to