Friday, July 19, 2013

LLDB Project Notes

This has been moved to: https://bitbucket.org/mikesart/lldb_branch/wiki/LLDB%20Project%20Notes

#
# Useful links
#

Subversion Commit Access: http://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access

lldb build page: http://lldb.llvm.org/build.html

lldb Linux buglist: http://llvm.org/bugs/buglist.cgi?cmdtype=runnamed&namedcmd=lldb-linux&list_id=40756

lldb-dev archives: http://lists.cs.uiuc.edu/pipermail/lldb-dev/
lldb-commits archives: http://lists.cs.uiuc.edu/pipermail/lldb-commits/

LLDB Reference Documentation: http://lldb.llvm.org/docs.html
GDB commands in LLDB: http://lldb.llvm.org/lldb-gdb.html

Code reviews with Phabricator: http://llvm.org/docs/Phabricator.html
 - This phabricator thing produces easy to read diffs so I can submit patches like this:
     http://lists.cs.uiuc.edu/pipermail/lldb-dev/2013-July/002027.html
 - "arc diff" and "arc submit" are the two main commands.
   Warning: they can be a bit of a pain when working with multiple patches.

Rad's working lldb branch: https://bitbucket.org/mikesart/lldb_branch
 - has a couple fixes not merged into lldb svn branch yet (largest is libedit 3.1).

Rad's bugs/work list: https://bitbucket.org/mikesart/lldb_branch/issues?status=new&status=open

I've set up two lldb enlistments:
 - Our working mercurial branch: ~/data/src/lldb.hg
     (tools/lldb is from our Mercurial branch)
 - Official Subversion branch: ~/data/src/lldb.svn
     (tools/lldb is from lld Subversion branch)

Each branch looks like this on my machine:

  lldb.hg
  |
  `-- build
      |
      llvm
      |
      `-- tools
          |
          +-- clang
          |
          `-- lldb

I test individual patches, submit, test official tree from lldb.svn, and work out of lldb.hg.

#
# Tools
#

cmake version 2.8.10.2
ninja 1.3.3
Mercurial Distributed SCM (version 2.6)
svn, version 1.7.9 (r1462340), compiled Apr 6 2013, 21:23:46
Clang 3.3 (http://linux-debugger-bits.blogspot.com/2013/07/clang-33-with-64-bit-ubuntu-1204.html)

# Other useful tools:
TortoiseHg Dialogs (version 2.8), Mercurial (version 2.6)
meld 1.7.3
CGDB 20130523 (cgdb built from http://cgdb.github.io/)
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04

#
# internal patch to get lldb build warnings down (until these can be fixed).
#

Index: ../../cmake/modules/HandleLLVMOptions.cmake
===================================================================
--- ../../cmake/modules/HandleLLVMOptions.cmake (revision 186469)
+++ ../../cmake/modules/HandleLLVMOptions.cmake (working copy)
@@ -206,6 +206,12 @@
   if (LLVM_ENABLE_WARNINGS)
     append("-Wall -W -Wno-unused-parameter -Wwrite-strings" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)

+       # option(RAD_EXTRA_CFLAGS "View the TERM environment var" OFF)
+    if(RAD_EXTRA_CFLAGS)
+        message(RAD_EXTRA_CFLAGS " environment variable is ${RAD_EXTRA_CFLAGS}")
+        append(${RAD_EXTRA_CFLAGS} CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+    endif(RAD_EXTRA_CFLAGS)
+
     # Turn off missing field initializer warnings for gcc to avoid noise from
     # false positives with empty {}. Turn them on otherwise (they're off by
     # default for clang).

#
# My bash aliases for working with lldb project
#
# Can run following from lldb build directories:
#   ninja lldb
#   ninja check-lldb
# To run individual tests, something like this from lldb/test directory:
#   ./dotest.py -C clang -v -t -f PlatformCommandTestCase.test_process_list

# cd lldb_src_hg, etc. will work if "shopt -s cdable_vars" is set.
export lldb_src_hg=~/data/src/llvm.hg/llvm/tools/lldb
export lldb_src_svn=~/data/src/llvm.svn/llvm/tools/lldb
export lldb_build_hg=~/data/src/llvm.hg/build
export lldb_build_svn=~/data/src/llvm.svn/build

path_append ()  { path_remove $1; export PATH="$PATH:$1"; }
path_prepend () { path_remove $1; export PATH="$1:$PATH"; }
path_remove ()  { export PATH=`echo -n $PATH | awk -v RS=: -v ORS=: '$0 != "'$1'"' | sed 's/:$//'`; }

lldb_setenv_svn()
{
    path_remove "/home/mikesart/data/src/llvm.hg/build/bin"
    path_prepend "/home/mikesart/data/src/llvm.svn/build/bin"
}
lldb_setenv_hg()
{
    path_remove "/home/mikesart/data/src/llvm.svn/build/bin"
    path_prepend "/home/mikesart/data/src/llvm.hg/build/bin"
}
lldb_cmake_debug()
{
    # run from lldb build directory to create ninja build files
    CC=clang cmake -DRAD_EXTRA_CFLAGS="-Wno-c99-extensions -Wno-sign-compare -Wno-four-char-constants -Wno-extended-offsetof -Wno-unused-function" -DCMAKE_CXX_FLAGS="-fcolor-diagnostics" -DCMAKE_BUILD_TYPE=Debug -C ../llvm -G Ninja
}

#
# Faster debugging with gdb...
#

Gdb with lldb is super slow loading the symbols. Connecting can take ~15 seconds. I run this alias after building (takes about 19 seconds) and loading symbols with gdb drops to less than 1 second.

mikesart@mikesart-rad:~/data/src/llvm.hg/llvm/tools/lldb/test$ type lldb_gdb_add_index
lldb_gdb_add_index is a function
lldb_gdb_add_index ()
{
    echo gdb-add-index $(readlink -f $(dirname $(which lldb))/../lib/liblldb.so);
    time gdb-add-index $(readlink -f $(dirname $(which lldb))/../lib/liblldb.so)
}

mikesart@mikesart-rad:~/data/src/llvm.hg/llvm/tools/lldb/test$ cat ~/bin/gdb-add-index
#! /bin/sh

# Add a .gdb_index section to a file.

# Copyright (C) 2010 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

file="$1"
dir="${file%/*}"

# We don't care if gdb gives an error.
/home/mikesart/data/src/gdb-7.6/gdb/gdb --data-directory=/home/mikesart/data/src/gdb-7.6/gdb/data-directory -nx --batch-silent -ex "file $file" -ex "save gdb-index $dir"

if test -f "${file}.gdb-index"; then
   objcopy --add-section .gdb_index="${file}.gdb-index" --set-section-flags .gdb_index=readonly "$file" "$file"
   rm -f "${file}.gdb-index"
fi

exit 0

No comments:

Post a Comment