From nobody@FreeBSD.org  Sat Mar  3 08:18:45 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 3D6A9106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Sat,  3 Mar 2012 08:18:45 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 13CB78FC12
	for <freebsd-gnats-submit@FreeBSD.org>; Sat,  3 Mar 2012 08:18:45 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q238IiNa006935
	for <freebsd-gnats-submit@FreeBSD.org>; Sat, 3 Mar 2012 08:18:44 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q238IinM006934;
	Sat, 3 Mar 2012 08:18:44 GMT
	(envelope-from nobody)
Message-Id: <201203030818.q238IinM006934@red.freebsd.org>
Date: Sat, 3 Mar 2012 08:18:44 GMT
From: Vitaly Magerya <vmagerya@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] make /usr/sbin/pmcannotate work on amd64
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         165654
>Category:       bin
>Synopsis:       [patch] make pmcannotate(8) work on amd64
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    hiren
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Mar 03 08:20:09 UTC 2012
>Closed-Date:    
>Last-Modified:  Mon May  6 18:40:01 UTC 2013
>Originator:     Vitaly Magerya
>Release:        FreeBSD 8.2-RELEASE amd64
>Organization:
>Environment:
>Description:
pmcannotate does not print out source code or assembly code on my
system. This seems to be caused by isasminline function at line 116
fail to recognize objdump source dump output: it expects the second
character of assembly line to be a hex number, while at least on
amd64 objdump seems to ident asm lines by two spaces.
>How-To-Repeat:
Create a simple C program:

  cat > test.c <<EOF
  int main() {
    int i;
    for (i = 1000000; i >= 0; i--);
    return i;
  }
  EOF

Compile it with debug info:
  cc -g -o test test.c

Load hwpmc module (if not already):
  kldload hwpmc

Collect statistics:
  pmcstat -O test.log -P instructions ./test

Now pmcannotate should show C source annotated with profile statistics:
  pmcannotate test.log test

.. or the same, but with disassembly:
  pmcannotate -a test.log test

In both cases I see output like this:
  [...]
  Profile trace for function: main() [81.48%]

  Profile trace for function: get_pv_entry() [3.70%]
  [...]

While I'd like to see something like this:
  [...]
  Profile trace for function: main() [81.48%]
           |   400530: 55                      push   %rbp
           |   400531: 48 89 e5                mov    %rsp,%rbp
           |   400534: c7 45 fc 40 42 0f 00    movl   $0xf4240,-4(%rbp)
           |   40053b: eb 04                   jmp    400541 <main+0x11>
   59.09%  |   40053d: 83 6d fc 01             subl   $0x1,-4(%rbp)
   22.73%  |   400541: 83 7d fc 00             cmpl   $0x0,-4(%rbp)
   18.18%  |   400545: 79 f6                   jns    40053d <main+0xd>
           |   400547: 8b 45 fc                mov    -4(%rbp),%eax
           |   40054a: c9                      leaveq
           |   40054b: c3                      retq
           |   40054c: 90                      nop

  Profile trace for function: get_pv_entry() [3.70%]
  [...]

Or like this (for C source annotation):
  [...]
  Profile trace for function: main() [81.48%]
          |   int main() {
  100.00% |     int i;
          |     for (i = 1000000; i >= 0; i--);
          |     return i;
          |   }
  [...]

(It annotates the wrong line when no-op lines are encountered; still 
better than no output).
>Fix:
Just remove the test for second character being a hex number. The 
sscanf call on the next line will check that anyway, but it will
skip any amount of spaces too.

Note that I only tested this on amd64.
I don't know how i386 is affected.

Patch attached with submission follows:

--- pmcannotate.c.orig	2012-03-03 09:16:30.000000000 +0200
+++ pmcannotate.c	2012-03-03 09:18:32.000000000 +0200
@@ -118,8 +118,6 @@
 	void *ptr;
 	int nbytes;
 
-	if (isxdigit(str[1]) == 0)
-		return (0);
 	if (sscanf(str, " %p%n", &ptr, &nbytes) != 1)
 		return (0);
 	if (str[nbytes] != ':' || isspace(str[nbytes + 1]) == 0)


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Mon Jul 9 00:25:59 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=165654 
Responsible-Changed-From-To: eadler->freebsd-bugs 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Thu Nov 8 20:54:39 UTC 2012 
Responsible-Changed-Why:  
I won't be dealing with this PR for some time, so give it back to the 
pool 

http://www.freebsd.org/cgi/query-pr.cgi?pr=165654 
Responsible-Changed-From-To: freebsd-bugs->hiren 
Responsible-Changed-By: hiren 
Responsible-Changed-When: Fri May 3 22:10:26 UTC 2013 
Responsible-Changed-Why:  
Grab. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=165654 

From: hiren panchasara <hiren@FreeBSD.org>
To: bug-followup@FreeBSD.org, vmagerya@gmail.com
Cc:  
Subject: Re: bin/165654: [patch] make pmcannotate(8) work on amd64
Date: Sat, 4 May 2013 23:59:49 -0700

 Proposed patch seems okay to me. Patch worked well on this i386 box.
 
 $ uname -a
 FreeBSD myhomebsd 9.0-RC1 FreeBSD 9.0-RC1 #9: Tue Oct 18 16:57:56 UTC
 2011     root@build9x64.pcbsd.org:/usr/obj/pcbsd-build90/fbsd-source/9.0/sys/GENERIC
  i386
 
 On this machine, I found that asm indents lines by only 1 space.
 
 $ objdump -d test
 
 test:     file format elf32-i386-freebsd
 
 Disassembly of section .init:
 
 080482b4 <_init>:
  80482b4:       83 ec 0c                sub    $0xc,%esp
  80482b7:       e8 44 01 00 00          call   8048400 <frame_dummy>
  80482bc:       e8 9f 01 00 00          call   8048460 <__do_global_ctors_aux>
  80482c1:       83 c4 0c                add    $0xc,%esp
  80482c4:       c3                      ret
 Disassembly of section .plt:
 
 As we are removing that check altogether, this does not matter.
 
 cheers,
 Hiren

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/165654: commit references a PR
Date: Mon,  6 May 2013 18:30:58 +0000 (UTC)

 Author: hiren
 Date: Mon May  6 18:30:49 2013
 New Revision: 250304
 URL: http://svnweb.freebsd.org/changeset/base/250304
 
 Log:
   objdump output changed indentation from 1 space to 2 spaces somewhere between
   FreeBSD9 and CURRENT. Removing this rather unnecessary check which expects the
   second character of assembly line to be a hex number to make pmcannotate
   actually annotate the code and assembly.
   
   PR: 165654
   Submitted by:	Vitaly Magerya <vmagerya@gmail.com>
   Reviewed by:	attilio
   Approved by:	sbruno (mentor)
   MFC after:	3 weeks
 
 Modified:
   head/usr.sbin/pmcannotate/pmcannotate.c
 
 Modified: head/usr.sbin/pmcannotate/pmcannotate.c
 ==============================================================================
 --- head/usr.sbin/pmcannotate/pmcannotate.c	Mon May  6 17:44:12 2013	(r250303)
 +++ head/usr.sbin/pmcannotate/pmcannotate.c	Mon May  6 18:30:49 2013	(r250304)
 @@ -118,8 +118,6 @@ isasminline(const char *str)
  	void *ptr;
  	int nbytes;
  
 -	if (isxdigit(str[1]) == 0)
 -		return (0);
  	if (sscanf(str, " %p%n", &ptr, &nbytes) != 1)
  		return (0);
  	if (str[nbytes] != ':' || isspace(str[nbytes + 1]) == 0)
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
