Skip to content

Instantly share code, notes, and snippets.

@rhelmer
Last active August 29, 2015 14:07
Show Gist options
  • Save rhelmer/60bc81c6cee9c507008a to your computer and use it in GitHub Desktop.
Save rhelmer/60bc81c6cee9c507008a to your computer and use it in GitHub Desktop.
freebsd dxr howto

Install requirements for DXR

$ sudo pkg install clang33 git py27-virtualenv npm gmake bash

Clone DXR git repo and build virtualenv

$ git clone https://github.com/mozilla/dxr.git
$ cd dxr
$ git checkout es
$ virtualenv ./env
$ . env/bin/activate
$ pip install -r requirements.txt
$ python setup.py develop

Set up environment for building with the right version of clang

$ export CC=clang33
$ export CXX=clang++33
$ export LLVM_CONFIG=llvm-config33

FIXME this shouldn't be necessary, lockdown fails for some reason

$ npm install lockdown phantomjs

Apply no-rtti patch for clang plugin

$ git diff dxr/plugins/clang/makefile
diff --git a/dxr/plugins/clang/makefile b/dxr/plugins/clang/makefile
index e75a5ad..326c6a2 100644
--- a/dxr/plugins/clang/makefile
+++ b/dxr/plugins/clang/makefile
@@ -1,7 +1,7 @@
 LLVM_CONFIG ?= llvm-config
 LLVM_LDFLAGS := $(shell ${LLVM_CONFIG} --ldflags)
 CXXFLAGS := $(shell ${LLVM_CONFIG} --cxxflags) -Wall -Wno-strict-aliasing \
-       $(if $(DEBUG),-O0 -g)
+       $(if $(DEBUG),-O0 -g) -fno-rtti
 LDFLAGS := -fPIC -g -Wl,-R -Wl,'$$ORIGIN' $(LLVM_LDFLAGS) -shared
 
 build: libclang-index-plugin.so

FIXME make this configurable in dxr.conf

$ git diff dxr/plugins/clang/indexers.py

diff --git a/dxr/plugins/clang/indexers.py b/dxr/plugins/clang/indexers.py
index 11582d0..70b99e7 100644
--- a/dxr/plugins/clang/indexers.py
+++ b/dxr/plugins/clang/indexers.py
@@ -252,8 +252,8 @@ class TreeToIndex(TreeToIndexBase):
         flags_str = " ".join(imap('-Xclang {}'.format, flags))
 
         env = {
-            'CC': "clang %s" % flags_str,
-            'CXX': "clang++ %s" % flags_str,
+            'CC': "/usr/local/bin/clang33 %s" % flags_str,
+            'CXX': "/usr/local/bin/clang++33 %s" % flags_str,
             'DXR_CLANG_FLAGS': flags_str,
             'DXR_CXX_CLANG_OBJECT_FOLDER': tree.object_folder,
             'DXR_CXX_CLANG_TEMP_FOLDER': temp_folder,

FIXME make default CSV field size larger for DXR

$ git diff dxr/plugins/clang/condense.py

diff --git a/dxr/plugins/clang/condense.py b/dxr/plugins/clang/condense.py
index 77aca86..c155f8d 100644
--- a/dxr/plugins/clang/condense.py
+++ b/dxr/plugins/clang/condense.py
@@ -6,6 +6,7 @@ reason to keep this IR.]
 
 """
 import csv
+import sys
 from functools import partial
 from glob import glob
 from hashlib import sha1
@@ -16,6 +17,7 @@ from funcy import decorator, identity, select_keys, imap, ifilter, remove
 
 from dxr.indexers import FuncSig, Position, Extent
 
+csv.field_size_limit(sys.maxsize)
 
 class UselessLine(Exception):
     """A CSV line isn't suitable for getting anything useful out of."""

Build DXR

$ gmake

Download FreeBSD 10.0 source code

$ cd /
$ curl 'ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/10.0-RELEASE/src.txz' | sudo tar zxf - 

Become root and activate virtualenv

$ sudo su - 
# bash
# . ~vagrant/dxr/env/bin/activate

Create DXR configuration

# cd /usr/src
# cat dxr.config
[DXR]
enabled_plugins     = pygmentize clang
temp_folder         = /tmp/dxr-temp
target_folder       = /home/vagrant/freebsd
nb_jobs             = 4
es_index            = dxr_freebsd_{format}_{tree}_{unique}
es_alias            = dxr_freebsd_{format}_{tree}

[freebsd]
source_folder       = /usr/src
object_folder       = /usr/src
build_command       = make clean; make -j $jobs buildkernel # FIXME buildworld

Modify /etc/make.conf:

# Comment these out for DXR, otherwise can't override with env
# Use clang as the default compiler
#CC= clang
#CXX= clang++
#CPP= clang-cpp

# This setting to build world without -Werror, for DXR:
NO_WERROR=
# This setting to build kernel without -Werror, for DXR:
WERROR=

Run DXR build (as root)

# cd /usr/src && dxr-build.py
@rhelmer
Copy link
Author

rhelmer commented Nov 30, 2014

A worker failed while indexing /usr/src/sys/netgraph/atm/sscop/ng_sscop_cust.h:
Traceback (most recent call last):
  File "/usr/home/dxr/dxr/dxr/build.py", line 549, in index_chunk
    index_file(tree, tree_indexers, path, es, index, jinja_env)
  File "/usr/home/dxr/dxr/dxr/build.py", line 460, in index_file
    refs.extend(file_to_index.refs())
  File "/usr/home/dxr/dxr/dxr/plugins/clang/indexers.py", line 180, in _refs_fro
m_view
    yield (self.char_offset(start.row, start.col),
  File "/usr/home/dxr/dxr/dxr/indexers.py", line 241, in char_offset
    return self._line_offsets()[row - 1] + col
IndexError: list index out of range

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment