VS Code + clang + lldb

 

The Remote Debug configuration | CLion Documentation (jetbrains.com)

 

https://github.com/microsoft/vscode-cpptools/issues/5415

 

https://rob-blackbourn.github.io/blog/vscode/clang/llvm/ubuntu/20.04/2021/07/04/howto-llvm-vscode-ubuntu.html

 

1. Install the following packages via apt

sudo apt install clang-10 llvm-10-dev liblldb-10-dev

 

2. Create soft links for executable files so things can work as expected

sudo ln -s /usr/bin/clang-10 /usr/bin/clang
sudo ln -s /usr/bin/clang++-10 /usr/bin/clang++
sudo ln -s /usr/bin/lldb-10 /usr/bin/lldb
# This one is a bit strange but VSCode only looks for the name `lldb-server-10.0.0` but not `lldb-server-10`
sudo ln -s /usr/bin/lldb-server-10 /usr/bin/lldb-server-10.0.0

 

llvm-devel    lldb-devel

3. Build the lldb-mi executable from source

git clone https://github.com/lldb-tools/lldb-mi.git
cd lldb-mi
cmake -B build
make -C buildsudo make -C build install

 

These should be it. And here's my launch.json. Basically just the default one from clang++ preset and changed nothing if I remember it correctly.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "clang-10 - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/hello-world",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "miDebuggerPath": "/usr/bin/lldb-mi"
        }
    ]
}

 

 

生成map文件

SET(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-Map=${CMAKE_PROJECT_NAME}.map")

SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} -Wl,-Map=${CMAKE_PROJECT_NAME}.map")

 



https://blog.csdn.net/tanmx219/article/details/86681167

 

cmake_minimum_required( VERSION 2.6.3 )
set(CMAKE_SYSTEM_NAME Linux )
set(CMAKE_BUILD_TYPE DEBUG)

SET (CMAKE_C_COMPILER             "/usr/bin/clang")
SET (CMAKE_C_FLAGS                "-Wall -std=c99")
SET (CMAKE_C_FLAGS_DEBUG          "-O0 -g")
SET (CMAKE_C_FLAGS_MINSIZEREL     "-Os -DNDEBUG")
SET (CMAKE_C_FLAGS_RELEASE        "-O3 -DNDEBUG")
SET (CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
 
SET (CMAKE_CXX_COMPILER             "/usr/bin/clang++")
SET (CMAKE_CXX_FLAGS                "-Wall")
SET (CMAKE_CXX_FLAGS_DEBUG          "-O0 -g")
SET (CMAKE_CXX_FLAGS_MINSIZEREL     "-Os -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELEASE        "-O3 -DNDEBUG")
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
 
SET (CMAKE_AR      "/usr/bin/llvm-ar-10")
SET (CMAKE_LINKER  "/usr/bin/llvm-ld-10")
SET (CMAKE_NM      "/usr/bin/llvm-nm-10")
SET (CMAKE_OBJDUMP "/usr/bin/llvm-objdump-10")
SET (CMAKE_RANLIB  "/usr/bin/llvm-ranlib-10")

 

cmake_minimum_required(VERSION 3.7.1)
 
project(hello-world)
 
find_package(LLVM REQUIRED CONFIG)
 
set(SOURCE_FILES main.c)
 
message(STATUS "This is BINARY dir " ${PROJECT_BINARY_DIR})
message(STATUS "This is SOURCE dir " ${PROJECT_SOURCE_DIR})
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
 
# Set your project compile flags.
# E.g. if using the C++ header files
# you will need to enable C++11 support
# for your compiler.
 
include_directories(${LLVM_INCLUDE_DIRS})
add_definitions(${LLVM_DEFINITIONS})
 
# Now build our tools
add_executable(hello-world ${SOURCE_FILES})
 
 
# Find the libraries that correspond to the LLVM components
# that we wish to use
llvm_map_components_to_libnames(llvm_libs support core irreader)
 
# Link against LLVM libraries
target_link_libraries(hello-world ${llvm_libs})

 

cmake  -DCMAKE_TOOLCHAIN_FILE=./linux.toolchain.cmake -Bbuild -GNinja
ninja -Cbuild -v

 

 

 

 

cmake_minimum_required(VERSION 2.6.3)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR mips64el)

set(CROSS_COMPILER_PREFIX "/usr/bin/mips64el-linux-gnuabi64")

set(CMAKE_C_COMPILER             ${CROSS_COMPILER_PREFIX}-gcc)
set(CMAKE_C_FLAGS                "-O3 -fPIC" CACHE INTERNAL "")
set(CMAKE_C_FLAGS_DEBUG          "${CMAKE_C_FLAGS} -g -Wall" CACHE INTERNAL "")
set(CMAKE_C_FLAGS_MINSIZEREL     "${CMAKE_C_FLAGS} -Os -DNDEBUG" CACHE INTERNAL "")
set(CMAKE_C_FLAGS_RELEASE        "${CMAKE_C_FLAGS} -O4 -DNDEBUG" CACHE INTERNAL "")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -O2 -g" CACHE INTERNAL "")

set(CMAKE_CXX_COMPILER             ${CROSS_COMPILER_PREFIX}-g++)
set(CMAKE_CXX_FLAGS                "-O3 -fPIC" CACHE INTERNAL "")
set(CMAKE_CXX_FLAGS_DEBUG          "${CMAKE_CXX_FLAGS} -g -Wall" CACHE INTERNAL "")
set(CMAKE_CXX_FLAGS_MINSIZEREL     "${CMAKE_CXX_FLAGS} -Os -DNDEBUG" CACHE INTERNAL "")
set(CMAKE_CXX_FLAGS_RELEASE        "${CMAKE_CXX_FLAGS} -O4 -DNDEBUG" CACHE INTERNAL "")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS} -O2 -g" CACHE INTERNAL "")

set(CMAKE_AR      ${CROSS_COMPILER_PREFIX}-ar)
set(CMAKE_LINKER  ${CROSS_COMPILER_PREFIX}-ld)
set(CMAKE_NM      ${CROSS_COMPILER_PREFIX}-nm)
set(CMAKE_OBJDUMP ${CROSS_COMPILER_PREFIX}-objdump)
set(CMAKE_RANLIB  ${CROSS_COMPILER_PREFIX}-ranlib)

 

posted @ 2021-09-29 16:24  sinferwu  阅读(600)  评论(0编辑  收藏  举报