Commit 7ab8a326 authored by Pavel Emelyanov's avatar Pavel Emelyanov

show: Implement simple images filtering

The -F|--fields option specifies which fields (by name, comma
separated) should be printed.

For nested fields all names in path should be specified.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 73b689f8
...@@ -98,7 +98,7 @@ int main(int argc, char *argv[]) ...@@ -98,7 +98,7 @@ int main(int argc, char *argv[])
return 1; return 1;
while (1) { while (1) {
static const char short_opts[] = "dsRf:t:p:hcD:o:n:v::xVr:jlW:L:"; static const char short_opts[] = "dsRf:F:t:p:hcD:o:n:v::xVr:jlW:L:";
static struct option long_opts[] = { static struct option long_opts[] = {
{ "tree", required_argument, 0, 't' }, { "tree", required_argument, 0, 't' },
{ "pid", required_argument, 0, 'p' }, { "pid", required_argument, 0, 'p' },
...@@ -108,6 +108,7 @@ int main(int argc, char *argv[]) ...@@ -108,6 +108,7 @@ int main(int argc, char *argv[])
{ "daemon", no_argument, 0, 'd' }, { "daemon", no_argument, 0, 'd' },
{ "contents", no_argument, 0, 'c' }, { "contents", no_argument, 0, 'c' },
{ "file", required_argument, 0, 'f' }, { "file", required_argument, 0, 'f' },
{ "fields", required_argument, 0, 'F' },
{ "images-dir", required_argument, 0, 'D' }, { "images-dir", required_argument, 0, 'D' },
{ "work-dir", required_argument, 0, 'W' }, { "work-dir", required_argument, 0, 'W' },
{ "log-file", required_argument, 0, 'o' }, { "log-file", required_argument, 0, 'o' },
...@@ -163,6 +164,9 @@ int main(int argc, char *argv[]) ...@@ -163,6 +164,9 @@ int main(int argc, char *argv[])
case 'f': case 'f':
opts.show_dump_file = optarg; opts.show_dump_file = optarg;
break; break;
case 'F':
opts.show_fmt = optarg;
break;
case 'r': case 'r':
opts.root = optarg; opts.root = optarg;
break; break;
...@@ -451,6 +455,7 @@ usage: ...@@ -451,6 +455,7 @@ usage:
"\n" "\n"
"Show options:\n" "Show options:\n"
" -f|--file FILE show contents of a checkpoint file\n" " -f|--file FILE show contents of a checkpoint file\n"
" -F|--fields FIELDS show specified fields (comma separated)\n"
" -D|--images-dir DIR directory where to get images from\n" " -D|--images-dir DIR directory where to get images from\n"
" -c|--contents show contents of pages dumped in hexdump format\n" " -c|--contents show contents of pages dumped in hexdump format\n"
" -p|--pid PID show files relevant to PID (filter -D flood)\n" " -p|--pid PID show files relevant to PID (filter -D flood)\n"
......
...@@ -13,6 +13,7 @@ struct script { ...@@ -13,6 +13,7 @@ struct script {
struct cr_options { struct cr_options {
int final_state; int final_state;
char *show_dump_file; char *show_dump_file;
char *show_fmt;
bool check_ms_kernel; bool check_ms_kernel;
bool show_pages_content; bool show_pages_content;
bool restore_detach; bool restore_detach;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "util.h" #include "util.h"
#include "string.h" #include "string.h"
#include "sockets.h" #include "sockets.h"
#include "cr_options.h"
#include "protobuf.h" #include "protobuf.h"
...@@ -408,6 +409,29 @@ static int pb_optional_field_present(const ProtobufCFieldDescriptor *field, ...@@ -408,6 +409,29 @@ static int pb_optional_field_present(const ProtobufCFieldDescriptor *field,
return 1; return 1;
} }
static bool should_show_field(const char *name)
{
char *s, *e;
int len;
if (!opts.show_fmt)
return true;
len = strlen(name);
s = opts.show_fmt;
while (1) {
e = strchrnul(s, ',');
if (e - s == len) {
if (!strncmp(name, s, len))
return true;
}
if (*e == '\0')
return false;
s = e + 1;
}
}
static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl) static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl)
{ {
int i; int i;
...@@ -428,6 +452,9 @@ static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl) ...@@ -428,6 +452,9 @@ static void pb_show_msg(const void *msg, pb_pr_ctl_t *ctl)
continue; continue;
} }
if (!should_show_field(fd.name))
continue;
if (fd.label == PROTOBUF_C_LABEL_REPEATED) { if (fd.label == PROTOBUF_C_LABEL_REPEATED) {
nr_fields = *(size_t *)(msg + fd.quantifier_offset); nr_fields = *(size_t *)(msg + fd.quantifier_offset);
data = (unsigned long *)*data; data = (unsigned long *)*data;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment