Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ add_library(${LIB_NAME} STATIC ${LIB_SOURCES})
target_include_directories(${LIB_NAME} PUBLIC include)

add_subdirectory(src)
add_subdirectory(debugger)
18 changes: 18 additions & 0 deletions debugger/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# STEPS TO SET UP ENVIRONMENT:
# 1. Install lldb and liblldb-dev
# 2. Check if you get "error: unable to locate lldb-server-14.0.0" when running
# 3. If you get the above error, create a symlink from lldb-server-14.0.0 to lldb-server


cmake_minimum_required(VERSION 3.15)
project(debugger)

# Set LLDB include and library paths manually
include_directories(/usr/include/lldb)
link_directories(/usr/lib/liblldb.so)

# Add executable
add_executable(my_lldb_app debugger.cpp)

# Link LLDB dynamically
target_link_libraries(my_lldb_app PRIVATE lldb)
40 changes: 40 additions & 0 deletions debugger/debugger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <lldb/API/LLDB.h>
#include <iostream>

using namespace lldb;

int main() {
SBDebugger::Initialize();
auto debugger = SBDebugger::Create(true);
debugger.SetAsync(false);

auto target = debugger.CreateTarget("a.out");
if (!target.IsValid()) {
std::cerr << "Failed to create target.\n";
return 1;
}

auto breakpoint = target.BreakpointCreateByLocation("main.cpp", 5); // Breakpoint location in the program being debugged
if (!breakpoint.IsValid()) {
std::cerr << "Failed to create breakpoint.\n";
return 1;
}

std::cout << "Printing works" << std::endl;

auto process = target.LaunchSimple(nullptr, nullptr, nullptr);
if (!process.IsValid()) {
std::cerr << "Failed to launch process.\n";
return 1;
}

std::cout << "Printing works" << std::endl;

auto info = process.GetProcessInfo();
std::cout << "ProcessID: " << info.GetProcessID() << std::endl;
std::cout << "Name: " << info.GetName() << std::endl;

SBDebugger::Terminate();
return 0;
}

Loading