[CRIU] [PATCH] show: protobuf -- Fix rendering of repeated messages

Cyrill Gorcunov gorcunov at openvz.org
Fri Feb 7 08:07:19 PST 2014


Repeated custom entries are presented as an array
of pointers in the memory, so once we fetch the
first entry we are to continue iterating pointers
instead.

Before

	| vmas: {
	|         start: 0x00000000400000
	|         end: 0x00000000406000
	|         pgoff: 0000000000000000
	|         shmid: 0x0000000000000b
	|         prot: 0x5
	|         flags: 0x2
	|         status: 0x41
	|         fd: 0xffffffffffffffff
	| }
	| :{
	|         start: 0x00000000462d00
	|         end: 0000000000000000
	|         pgoff: 0000000000000000
	|         shmid: 0x00000000605000
	|         prot: 0x606000
	|         flags: 0
	|         status: 0x5000
	|         fd: 0x0000000000000b
	|         madv: 0x00000000000041
	| }

After

	| vmas: {
	|         start: 0x00000000400000
	|         end: 0x00000000406000
	|         pgoff: 0000000000000000
	|         shmid: 0x0000000000000b
	|         prot: 0x5
	|         flags: 0x2
	|         status: 0x41
	|         fd: 0xffffffffffffffff
	| }
	| :{
	|         start: 0x00000000605000
	|         end: 0x00000000606000
	|         pgoff: 0x00000000005000
	|         shmid: 0x0000000000000b
	|         prot: 0x1
	|         flags: 0x2
	|         status: 0x41
	|         fd: 0xffffffffffffffff
	| }

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 protobuf.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/protobuf.c b/protobuf.c
index 5e62b085f478..e6abe942061b 100644
--- a/protobuf.c
+++ b/protobuf.c
@@ -160,7 +160,6 @@ static int show_bytes(pb_pr_field_t *field)
 static size_t pb_show_prepare_field_context(const ProtobufCFieldDescriptor *fd,
 					  pb_pr_ctl_t *ctl)
 {
-	pb_pr_field_t *field = &ctl->cur;
 	size_t fsize = 0;
 
 	switch (fd->type) {
@@ -184,8 +183,6 @@ static size_t pb_show_prepare_field_context(const ProtobufCFieldDescriptor *fd,
 		break;
 	case PROTOBUF_C_TYPE_MESSAGE:
 		ctl->arg = (void *)fd->descriptor;
-		if (field->data)
-			field->data = (void *)(*(long *)field->data);
 	case PROTOBUF_C_TYPE_STRING:
 		fsize = sizeof (void *);
 		break;
@@ -349,7 +346,7 @@ static pb_pr_show_t get_show_function(const ProtobufCFieldDescriptor *fd, pb_pr_
 	return get_pb_show_function(fd->type, fd->label);
 }
 
-static void pb_show_repeated(pb_pr_ctl_t *ctl, int nr_fields, pb_pr_show_t show,
+static void pb_show_repeated(const ProtobufCFieldDescriptor *fd, pb_pr_ctl_t *ctl, int nr_fields, pb_pr_show_t show,
 			  size_t fsize)
 {
 	pb_pr_field_t *field = &ctl->cur;
@@ -361,6 +358,23 @@ static void pb_show_repeated(pb_pr_ctl_t *ctl, int nr_fields, pb_pr_show_t show,
 		return;
 	}
 
+	if (fd->type == PROTOBUF_C_TYPE_MESSAGE) {
+		void *p = field->data;
+
+		field->count = nr_fields;
+		field->data = (void *)(*(long *)p);
+		done = show(field);
+		if (done)
+			return;
+
+		for (p += fsize, counter = 0; counter < nr_fields - 1; counter++, p += fsize) {
+			pr_msg(":");
+			field->data = (void *)(*(long *)p);
+			show(field);
+		}
+		return;
+	}
+
 	field->count = nr_fields;
 	done = show(field);
 	if (done)
@@ -384,7 +398,7 @@ static void pb_show_field(const ProtobufCFieldDescriptor *fd,
 
 	show = get_show_function(fd, ctl);
 
-	pb_show_repeated(ctl, nr_fields, show, pb_show_prepare_field_context(fd, ctl));
+	pb_show_repeated(fd, ctl, nr_fields, show, pb_show_prepare_field_context(fd, ctl));
 
 	if (ctl->single_entry)
 		pr_msg("\n");
-- 
1.8.3.1



More information about the CRIU mailing list