Skip to contentSkip to conversation

strace-like output for user-linux

RFC In review Stuart Anderson 2 participants 3 messages Jun 2, 2007 – Jun 3, 2007 Kbuild

lore
Share & tools
lore
#0 lore raw

RFC 1/1 strace-like output for user-linux

I'm sending this patch out for comments. It adds the capability to get strace(1) like output from the target executable in user-linux mode.

A couple of things that should probably be done before calling it done is to fill in more call specific format strings, and using a technique similar to how the format strings are handled, add the ability to have syscall specific output functions that could decode flags, etc to give more detailed output.

Any feedback would be appreciated.

Stuart

Stuart R. Anderson                               [email protected]
Network & Software Engineering                   http://www.netsweng.com/
1024D/37A79149:                                  0791 D3B8 9A4C 2CDC A31F
                                                 BD03 0A62 E534 37A7 9149
Makefile.target +1 -1
Index: qemu/Makefile.target
===================================================================
@@ -240,7 +240,7 @@
 endif
 
 ifdef CONFIG_LINUX_USER
-OBJS= main.o syscall.o mmap.o signal.o path.o osdep.o thunk.o \
+OBJS= main.o syscall.o syscall_names.o mmap.o signal.o path.o osdep.o thunk.o \
       elfload.o linuxload.o
 LIBS+= $(AIOLIBS)
 ifdef TARGET_HAS_BFLT
linux-user/syscall.c +2 -0
Index: qemu/linux-user/syscall.c
===================================================================
@@ -2724,6 +2724,7 @@
     
 #ifdef DEBUG
     gemu_log("syscall %d", num);
+    print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
 #endif
     switch(num) {
     case TARGET_NR_exit:
@@ -4906,6 +4907,7 @@
     }
  fail:
 #ifdef DEBUG
+    /* use this to end lines output by print_syscall() above */
     gemu_log(" = %ld\n", ret);
 #endif
     return ret;
linux-user/syscall_names.c new file +30 -0
Index: qemu/linux-user/syscall_names.c
===================================================================
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include "qemu.h"
+
+struct syscallname {
+	int nr;
+	char *name;
+	char *format;
+};
+
+static struct syscallname scnames[] = {
+#include "syscall_names.list"
+};
+
+static int nsyscalls = sizeof(scnames)/sizeof(struct syscallname);
+
+void
+print_syscall(int num, long arg1, long arg2, long arg3,
+                long arg4, long arg5, long arg6)
+{
+int i;
+char *format="%s(%ld,%ld,%ld,%ld,%ld,%ld)";
+
+for(i=0;i<nsyscalls;i++)
+	if( scnames[i].nr == num ) {
+		if( scnames[i].format != NULL )
+			format = scnames[i].format;
+		gemu_log(format,scnames[i].name, arg1,arg2,arg3,arg4,arg5,arg6);
+	}
+}
+
linux-user/syscall_names.list new file +1509 -0

1,509 lines not on this page · raw message

#1 lore raw

Hi Stuart

I hope my little advice is correct... but overall, I think you add a nice usefuk feature here.

Quoted 3 lines

I'm sending this patch out for comments. It adds the capability to get strace(1) like output from the target executable in user-linux mode.

+char *format="%s(%ld,%ld,%ld,%ld,%ld,%ld)";
+
+for(i=0;i<nsyscalls;i++)
+ if( scnames[i].nr == num ) {
+ if( scnames[i].format != NULL )
+ format = scnames[i].format;
+ gemu_log(format,scnames[i].name, arg1,arg2,arg3,arg4,arg5,arg6);
+ }--> don't you think we should break() here since we already found correct syscall num? otherwise we will continue the loop
+}
+

regards,

Mulyadi

#2 lore raw
Quoted 6 lines · Mulyadi Santosa

Hi Stuart

I hope my little advice is correct... but overall, I think you add a nice usefuk feature here.

+ }--> don't you think we should break() here since we already found
correct syscall num? otherwise we will continue the loop

Yes indeed. Thanks for catching that.

Stuart

Stuart R. Anderson                               [email protected]
Network & Software Engineering                   http://www.netsweng.com/
1024D/37A79149:                                  0791 D3B8 9A4C 2CDC A31F
                                                 BD03 0A62 E534 37A7 9149