From owner-freebsd-arch@FreeBSD.ORG Wed Sep 5 20:54:10 2012 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5BA7E106564A; Wed, 5 Sep 2012 20:54:10 +0000 (UTC) (envelope-from gnn@neville-neil.com) Received: from vps.hungerhost.com (vps.hungerhost.com [216.38.53.176]) by mx1.freebsd.org (Postfix) with ESMTP id 2AF558FC0C; Wed, 5 Sep 2012 20:54:09 +0000 (UTC) Received: from [209.249.190.124] (port=63358 helo=gnnmac.hudson-trading.com) by vps.hungerhost.com with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.77) (envelope-from ) id 1T9Mbx-0001L9-DY; Wed, 05 Sep 2012 16:54:09 -0400 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.0 \(1486\)) From: George Neville-Neil In-Reply-To: Date: Wed, 5 Sep 2012 16:54:09 -0400 Content-Transfer-Encoding: 7bit Message-Id: <1135E0EA-319C-4AB9-B282-59CDEA9020C8@neville-neil.com> References: To: Jonathan Anderson X-Mailer: Apple Mail (2.1486) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vps.hungerhost.com X-AntiAbuse: Original Domain - freebsd.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - neville-neil.com Cc: freebsd-arch@freebsd.org Subject: Re: Call graphs with bsd.obj.mk X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Sep 2012 20:54:10 -0000 On Sep 5, 2012, at 11:28 , Jonathan Anderson wrote: > Hi all, > > While doing some hacking recently, I really wanted a call graph. Clang > and LLVM make this pretty easy, assuming you have the right CFLAGS, so > a little build system integration seemed to be in order. I did this, > it's pretty small and modular, and I find it useful, so I'm sharing > this work with the list in the hope of putting it into -CURRENT. > > I've attached two BSD makefiles that let me produce call graphs from > any directory that includes bsd.obj.mk (which notably includes > binaries and libraries in src): > > - bsd.analysis.mk contains a 'callgraph' target that produces > ${.OBJDIR}/_callgraph_.dot > - bsd.llvm.mk contains a few LLVM helpers (e.g. to generate LLVM IR) > > If you have clang, llvm-link and opt installed, this allows you to > generate a complete call graph for C code; assembler files are ignored > because we don't currently have assembly -> IR transformations. The > resulting graph can be pretty large and ugly (e.g. LLVM shows an > "external node" pseudo-function that calls everything), but it can be > filtered with scripts like those found at > https://github.com/trombonehero/dot-tools to produce really useful > graphs. > > llvm-link and opt aren't included in the bootstrap tools, so I'm > currently doing this by installing the llvm-devel package. Perhaps we > might copy llvm-link and opt over to /usr/obj/usr/src/tmp, possibly > governed by a WITH_LLVM_TOOLS flag in src.conf or something? > This would be great to have in the tree as a real build target. Best, George