Skip to content

Instantly share code, notes, and snippets.

@rhelmer
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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

HAX:

  • Swallowing Bad Extent exception in dxr/indexers.py
  • ES exception while indexing share/examples/BSD_daemon/FreeBSD.pfa
    • tried removing the file as a hackaround
java.lang.IllegalArgumentException: Document contains at least one immense term in field="content" (whose UTF8 encoding is longer than the max length 32766), all of which were skipped.  Please correct the analyzer to not produce such terms.  The prefix of the first immense term is: '[66 30 66 30 66 30 66 30 31 31 65 65 38 33 38 32 34 31 61 30 63 65 63 35 32 35 61 36 30 63]...'
        at org.apache.lucene.index.DocInverterPerField.processFields(DocInverterPerField.java:199)
        at org.apache.lucene.index.DocFieldProcessor.processDocument(DocFieldProcessor.java:248)
        at org.apache.lucene.index.DocumentsWriterPerThread.updateDocument(DocumentsWriterPerThread.java:253)
        at org.apache.lucene.index.DocumentsWriter.updateDocument(DocumentsWriter.java:465)
        at org.apache.lucene.index.IndexWriter.updateDocument(IndexWriter.java:1537)
        at org.apache.lucene.index.IndexWriter.addDocument(IndexWriter.java:1207)
        at org.elasticsearch.index.engine.internal.InternalEngine.innerCreate(InternalEngine.java:459)
        at org.elasticsearch.index.engine.internal.InternalEngine.create(InternalEngine.java:386)
        at org.elasticsearch.index.shard.service.InternalIndexShard.create(InternalIndexShard.java:384)
        at org.elasticsearch.action.bulk.TransportShardBulkAction.shardIndexOperation(TransportShardBulkAction.java:427)
        at org.elasticsearch.action.bulk.TransportShardBulkAction.shardOperationOnPrimary(TransportShardBulkAction.java:155)
        at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:534)
        at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:433)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)

@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