Skip to contentSkip to conversation

linux-user strace

PATCH In review Stuart Anderson 2 participants 5 messages Jul 20, 2007 – Jul 21, 2007 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user strace

An update to the strace patch. Since this hasn't beencommmitted yet, I took the opportunity to rename the new files from syscall_names.* to strace.*. This version also starts to decode IPC calls tp make them easier to read.

This patch is in good shape, and is ready to be included.

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 strace.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 +10 -0
Index: qemu/linux-user/syscall.c
===================================================================
@@ -312,6 +312,11 @@
     return (unsigned long)ret >= (unsigned long)(-4096);
 }
 
+char *target_strerror(int err)
+{
+	return strerror(host_to_target_errno(err));
+}
+
 static target_ulong target_brk;
 static target_ulong target_original_brk;
 
@@ -2550,6 +2555,9 @@
 #ifdef DEBUG
     gemu_log("syscall %d", num);
 #endif
+    if(do_strace)
+        print_syscall(num, arg1, arg2, arg3, arg4, arg5, arg6);
+
     switch(num) {
     case TARGET_NR_exit:
 #ifdef HAVE_GPROF
@@ -4734,6 +4742,8 @@
 #ifdef DEBUG
     gemu_log(" = %ld\n", ret);
 #endif
+    if(do_strace)
+        print_syscall_ret(num, ret);
     return ret;
 }
 
linux-user/main.c +4 -0
Index: qemu/linux-user/main.c
===================================================================
@@ -1880,6 +1880,10 @@
        putenv("LD_LIBRARY_PATH=/usr/lib/libfakeroot:/usr/lib64/libfakeroot:/usr/lib32/libfakeroot");
     }
 
+    if(getenv("QEMU_STRACE") ){
+      do_strace=1;
+    }
+
     wrk = environ;
     while (*(wrk++))
         environ_count++;
linux-user/qemu.h +6 -0
Index: qemu/linux-user/qemu.h
===================================================================
@@ -138,10 +138,16 @@
 void cpu_loop(CPUState *env);
 void init_paths(const char *prefix);
 const char *path(const char *pathname);
+char *target_strerror(int err);
 
 extern int loglevel;
 extern FILE *logfile;
 
+/* strace.c */
+void print_syscall(int num, long arg1, long arg2, long arg3, long arg4, long arg5, long arg6);
+void print_syscall_ret(int num, long arg1);
+extern int do_strace;
+
 /* signal.c */
 void process_pending_signals(void *cpu_env);
 void signal_init(void);
linux-user/strace.c new file +187 -0

187 lines not on this page · raw message

linux-user/strace.list new file +1509 -0

1,509 lines not on this page · raw message

#1 lore raw

linux-user/syscall.c line 319

Quoted 13 lines · Stuart Anderson

Index: qemu/linux-user/syscall.c
===================================================================

linux-user/syscall.c +5 -0
@@ -312,6 +312,11 @@
     return (unsigned long)ret >= (unsigned long)(-4096);
 }
 
+char *target_strerror(int err)
+{
+	return strerror(host_to_target_errno(err));
+}
+

That looks backwards. strerror surely expects a host errno value, but host_to_target_errno returns the errno value for the target, doesn't it?

Andreas.

Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected]
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#2 lore raw
Quoted 10 lines · Andreas Schwab
Quoted 8 lines · Stuart Anderson

Index: qemu/linux-user/syscall.c
===================================================================

linux-user/syscall.c +0 -0
@@ -312,6 +312,11 @@
     return (unsigned long)ret >= (unsigned long)(-4096);
 }
 
Quoted 8 lines

linux-user/syscall.c line 319

Quoted 5 lines
linux-user/syscall.c +5 -0
+char *target_strerror(int err)
+{
+	return strerror(host_to_target_errno(err));
+}
+

That looks backwards. strerror surely expects a host errno value, but host_to_target_errno returns the errno value for the target, doesn't it?

The function is called target_strerror() 8-). It is used to display the errno string for the target, not the host. strerror() is just a simple map, so it doesn't really care. Regular strace on qemu itself will give the host error strings. This is used for gettign the error string of the target.

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
#3 lore raw
Quoted 21 lines · Stuart Anderson
Quoted 10 lines · Andreas Schwab
Quoted 8 lines · Stuart Anderson

Index: qemu/linux-user/syscall.c
===================================================================

linux-user/syscall.c +0 -0
@@ -312,6 +312,11 @@
     return (unsigned long)ret >= (unsigned long)(-4096);
 }
 
Quoted 8 lines

linux-user/syscall.c line 319

Quoted 5 lines
linux-user/syscall.c +5 -0
+char *target_strerror(int err)
+{
+	return strerror(host_to_target_errno(err));
+}
+

That looks backwards. strerror surely expects a host errno value, but host_to_target_errno returns the errno value for the target, doesn't it?

Quoted 1 line

The function is called target_strerror() 8-).

That's the problem. It does not return the string associated with the target errno, but something else.

Quoted 2 lines

It is used to display the errno string for the target, not the host.

But strerror interprets its argument as the host's errno value. If host_to_target_error maps ELOOP to TARGET_ELOOP, and TARGET_ELOOP happens have be the same value as EBADFD, the function wil return "Bad file descriptor" instead of "Too many levels of symbolic links".

Andreas.

Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected]
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#4 lore raw
Quoted 2 lines · Andreas Schwab

That's the problem. It does not return the string associated with the target errno, but something else.

It depends on what is being passed in to it. Looking over it again this morning, I can see some paths where it is passed the host errno, and some paths where it is passed a target errno via "ret". So in the later case, it would be double mapping the errno, which would be wrong.

I had suspected there may be a bit more work left in mapping errno values, but I wasn't yet sure what was needed where. I'd like to clear up the use of target_strerr() as part of that fix if that's ok with everyone.

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