Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Add backtraces for debugging.
Browse files Browse the repository at this point in the history
I've directly copied the code from backward-cpp for now,
as it is also MIT licensed, and this seemed
simpler than having to futz more with CMake and/or submodules.
  • Loading branch information
varungandhi-src committed Jul 6, 2022
1 parent 0e53ad5 commit 379061f
Show file tree
Hide file tree
Showing 7 changed files with 4,518 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ubuntu:22.04 as build

RUN apt update && apt install -y llvm-11 clang-11 libclang-11-dev cmake
RUN apt update && apt install -y llvm-11 clang-11 libclang-11-dev cmake libdwarf-dev

WORKDIR /lsif-clang

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ See the [examples](docs/examples.md) of producing LSIF indexes for a variety of
# Testing the output

You can use the [lsif-validate](https://github.com/sourcegraph/lsif-test) tool for basic sanity checking, or [upload the index to a Sourcegraph instance](https://docs.sourcegraph.com/user/code_intelligence/lsif_quickstart) to see the hovers, definitions, and references in action.

# Additional licensing notes

We use the [backwards-cpp](https://github.com/bombela/backward-cpp) code
which is [MIT licensed](https://github.com/bombela/backward-cpp/blob/master/LICENSE.txt).
34 changes: 30 additions & 4 deletions clang-tools-extra/lsif-clang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ add_executable(lsif-clang

# Make other directories available to us in clang-tools-extra
include_directories("../clangd/")
include_directories("../../clang/include/")
# add_subdirectory("../clangd/indexer/")


Expand Down Expand Up @@ -133,9 +134,34 @@ else()
)
endif()

target_link_libraries(lsif-clang
stdc++
clangDaemonMinimal
)
if (UNIX AND NOT APPLE)
find_path(DWARF_INCLUDE_DIR dwarf.h
/usr/include
/usr/local/include
/usr/include/libdwarf)
if (NOT DWARF_INCLUDE_DIR)
message(FATAL_ERROR "Couldn't find libdwarf, maybe you forgot to install libdwarf-dev(el)?")
endif()
message(STATUS "Using libdwarf in: ${DWARF_INCLUDE_DIR}")
target_include_directories(lsif-clang PRIVATE "${DWARF_INCLUDE_DIR}")
# libdwarf is not available on macOS AFAIK
target_link_libraries(lsif-clang
stdc++
clangDaemonMinimal
dwarf
# Linking libelf and libdl explicitly seems to be necessary after linking libdwarf
# Otherwise, we get errors like:
# /lib/aarch64-linux-gnu/libelf.so.1: error adding symbols: DSO missing from command line
# /lib/aarch64-linux-gnu/libdl.so.2: error adding symbols: DSO missing from command line
# See also: https://stackoverflow.com/a/38375709/2682729
elf
dl
)
else()
target_link_libraries(lsif-clang
stdc++
clangDaemonMinimal
)
endif()

install(TARGETS lsif-clang)
4 changes: 2 additions & 2 deletions clang-tools-extra/lsif-clang/LSIFClangMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "index/Symbol.h"
#include "index/SymbolCollector.h"
#include "clang/Index/IndexingOptions.h"
#include "clang/Tooling/Backward.hpp"
#include "clang/Tooling/AllTUsExecution.h"
#include "clang/Tooling/ArgumentsAdjusters.h"
#include "clang/Tooling/CommonOptionsParser.h"
Expand All @@ -30,8 +31,6 @@
#include "llvm/Support/raw_ostream.h"
#include <system_error>

#define BACKWARD_HAS_DWARF 1

using namespace clang::tooling;
using namespace llvm;

Expand Down Expand Up @@ -123,6 +122,7 @@ class IndexActionFactory : public FrontendActionFactory {

int main(int argc, const char **argv) {
// sys::PrintStackTraceOnErrorSignal(argv[0]);
backward::SignalHandling sh;

CommonOptionsParser OptionsParser(argc, argv, LSIFClangCategory,
cl::OneOrMore);
Expand Down
Loading

0 comments on commit 379061f

Please sign in to comment.