From slaven@rezic.de  Tue Oct  8 03:37:37 2002
Return-Path: <slaven@rezic.de>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 73CB537B401
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  8 Oct 2002 03:37:37 -0700 (PDT)
Received: from mail.netbeat.de (mail.netbeat.de [62.208.140.19])
	by mx1.FreeBSD.org (Postfix) with SMTP id EFDDD43E77
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  8 Oct 2002 03:37:35 -0700 (PDT)
	(envelope-from slaven@rezic.de)
Received: (qmail 2804 invoked from network); 8 Oct 2002 10:37:56 -0000
Received: from bb8a0.pppool.de (HELO vran.herceg.de) (213.7.184.160)
  by mail.netbeat.de with SMTP; 8 Oct 2002 10:37:56 -0000
Received: (from eserte@localhost)
	by vran.herceg.de (8.12.4/8.12.4/Submit) id g98AVlSS006536;
	Tue, 8 Oct 2002 12:31:47 +0200 (CEST)
	(envelope-from eserte)
Message-Id: <200210081031.g98AVlSS006536@vran.herceg.de>
Date: Tue, 8 Oct 2002 12:31:47 +0200 (CEST)
From: Slaven Rezic <eserte@vran.herceg.de>
Reply-To: slaven.rezic@berlin.de
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: changed truss output for utrace calls
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         43819
>Category:       bin
>Synopsis:       [patch] changed truss(1) output for utrace calls
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Oct 08 03:40:03 PDT 2002
>Closed-Date:    
>Last-Modified:  Sat Jun 16 00:02:02 GMT 2007
>Originator:     Slaven Rezic
>Release:        FreeBSD 4.6-STABLE i386
>Organization:
www.rezic.de
>Environment:
System: FreeBSD vran.herceg.de 4.6-STABLE FreeBSD 4.6-STABLE #15: Sat Jul 27 09:32:28 CEST 2002 root@vran.herceg.de:/usr/local/src/FreeBSD-4/src/sys/compile/VRAN i386


>Description:

	FreeBSD's malloc has a feature to emit utrace syscalls for
	debugging when MALLOC_OPTIONS contains the "U" character.
	Using ktrace, one can find the following entries with kdump:
	
  4059 perl5.8.0 CALL  utrace(0xbfbff2a4,0xc)
  4059 perl5.8.0 USER  12  00 00 00 00 01 00 00 00 30 90 11 08
  4059 perl5.8.0 RET   utrace 0

	These lines can easily be converted into malloc/free/realloc
	calls. 

	However, with truss the output looks as follows:

utrace(0xbfbff2a4,0xc)                           = 0 (0x0)

	That is, the first argument is only a pointer to the utrace
	buffer. I propose to change truss to dump the contents
	of the buffer instead:

utrace(0x000000005000000000b01108)               = 0 (0x0)

	The second parameter (the size of the buffer) has gone,
	because	it can be determined by the length of the buffer
	string.

>How-To-Repeat:
	
>Fix:

	This patch should be applied in the /usr/src/usr.bin/truss
	directory:

--- syscalls.c.orig	Tue Oct  8 11:21:24 2002
+++ syscalls.c	Tue Oct  8 11:53:36 2002
@@ -101,6 +101,8 @@ struct syscall syscalls[] = {
 	  { { Hex, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } },
 	{ "getsockname", 1, 3,
 	  { { Hex, 0 }, { Sockaddr | OUT, 1 }, { Ptr | OUT, 2 } } },
+	{ "utrace", 1, 1,
+	  { { Utrace, 0 } } },
 	{ 0, 0, 0, { { 0, 0 }}},
 };
 
@@ -341,6 +343,23 @@ print_arg(int fd, struct syscall_args *s
       }
     }
     break;
+  case Utrace:
+    {
+      int i, len;
+      unsigned char *p;
+      unsigned char *utrace_buffer;
+      len = args[sc->offset+1];
+      tmp = malloc(len*2+2+1);
+      utrace_buffer = malloc(len);
+      if (get_struct(fd, (void *)args[sc->offset], (void *)utrace_buffer,
+		     len) == -1)
+	err(1, "get_struct %p", (void *)args[sc->offset]);
+      strcpy(tmp, "0x");
+      for(i = 0; i < len; i++) {
+	sprintf(tmp+2+i*2, "%02x", *(utrace_buffer+i));
+      }
+      free(utrace_buffer);
+    }
   }
   return tmp;
 }



>Release-Note:
>Audit-Trail:
>Unformatted:
