欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 社会 > CTF系列2:LTTng C API 起步之环境搭建

CTF系列2:LTTng C API 起步之环境搭建

2025/12/7 10:12:31 来源:https://blog.csdn.net/haoyujie/article/details/144299006  浏览:    关键词:CTF系列2:LTTng C API 起步之环境搭建

LTTng C API 起步之环境搭建

  • 前言
  • 环境的搭建
    • ununtu的版本
    • 安装和试用lttng
    • 检查和验证
      • 1. **Check for LTTng Packages**
        • Check Installed Packages with `dpkg`
      • 2. **Check for LTTng C API Library (`liblttng-ust`)**
      • 3. **Check for Development Headers (`liblttng-ust-dev`)**
      • 4. **Search for the Libraries with `ldconfig`**
      • 5. **If LTTng is Not Installed: Install LTTng**
      • 6. **Verify Installation**
      • 7. **Test the LTTng C API**
      • Summary
  • 我的实际操作的笔记
    • lttng-modules lttng-ust无法安装
    • 关于: 7. Test the LTTng C API
    • 我的环境的部分情况
  • CMake工程
    • CMakeList.txt
    • test_lttng.c
    • 编译

前言

前面的贴文做了一些工作,下面开始准备编程。
方向选择了LTTng C API

环境的搭建

ununtu的版本

如果您还没装,最好装这个版本:
ubuntu-22.04.2-live-server-amd64.iso
这个我释解释一下:
1。 这个版本,的确能装上lttng的大部分组件。kernel的部分特性没有开,这没关系,我们可以自己编kernel.
2. 如果需要桌面UI,可以装同版本的desktop.
3. 安装时选normal或minal均可,建议选minal。我选的是默认的normal装了cloud服务,好不容易把它删除了。还有dhcp也处理了一下,否则ssh非常慢。

安装和试用lttng

这个略过,网上相关的信息很多。

检查和验证

To check if the LTTng C API library is installed on your Ubuntu 24.04.1 system, you can follow these steps:

1. Check for LTTng Packages

LTTng provides multiple packages that contain the tools and libraries for both users and developers. You can check if the relevant LTTng packages are installed on your system by using the following commands:

Check Installed Packages with dpkg

Open a terminal and run:

dpkg -l | grep lttng

This will list all installed packages related to LTTng. The output might include packages like:

  • lttng-tools: The LTTng user tools (includes babeltrace for reading CTF traces).
  • lttng-modules: Kernel modules for LTTng.
  • liblttng-ctl: C library for interacting with LTTng.
  • liblttng-ust: User-space tracing library for LTTng.

If you don’t see any of these packages, it’s possible LTTng is not installed yet, or you might have to install the development libraries.

2. Check for LTTng C API Library (liblttng-ust)

The core C API for LTTng is in the liblttng-ust library. To check if it’s installed, use the dpkg command to see if the package is present:

dpkg -l | grep liblttng-ust

This should show you if the liblttng-ust library is installed. If it’s installed, you should be able to link against it when compiling your programs.

3. Check for Development Headers (liblttng-ust-dev)

In order to develop with LTTng, you’ll also need the development headers. You can check if the development package is installed by running:

dpkg -l | grep liblttng-ust-dev

This package provides the headers necessary to include LTTng functionality in your code (#include <lttng/tracef.h> and so on).

4. Search for the Libraries with ldconfig

You can also use ldconfig to search for the installed libraries on your system. Run:

ldconfig -p | grep lttng

This command will list the installed libraries that the linker can find. You should see libraries like:

  • /lib/x86_64-linux-gnu/liblttng-ust.so
  • /lib/x86_64-linux-gnu/liblttng-ctl.so

5. If LTTng is Not Installed: Install LTTng

If you don’t have LTTng installed yet, you can install it using apt. You’ll need to install the user-space tools and the development libraries. Here’s how you can install them:

sudo apt update
sudo apt install lttng-tools lttng-modules lttng-ust liblttng-ust-dev liblttng-ctl-dev

This will install the necessary libraries, tools, and headers to get started with LTTng on your system.

6. Verify Installation

Once installed, you can check if LTTng tools are available by running:

lttng --version

This should print the installed version of the LTTng tools.

7. Test the LTTng C API

Finally, to test if the C API is ready, you can try compiling a small program that includes the LTTng headers. Here’s a simple example:

#include <lttng/tracef.h>int main() {tracef("my_event", "Hello, LTTng!");return 0;
}

To compile this code, you can use the following gcc command (make sure to link the LTTng library):

gcc -o test_lttng test_lttng.c -llttng-ust

If the code compiles and runs without issues, your LTTng C API installation is working correctly!

Summary

To check if the LTTng C API is installed:

  1. Check the installed packages with dpkg -l | grep lttng.
  2. Check for liblttng-ust and liblttng-ust-dev libraries.
  3. If not installed, run sudo apt install lttng-tools lttng-modules lttng-ust liblttng-ust-dev liblttng-ctl-dev.
  4. Verify by compiling a small test program.

我的实际操作的笔记

lttng-modules lttng-ust无法安装

下面的指令,
sudo apt install lttng-tools lttng-modules lttng-ust liblttng-ust-dev liblttng-ctl-dev
改为
sudo apt install lttng-tools liblttng-ust-dev liblttng-ctl-dev

关于: 7. Test the LTTng C API

这段没有问题。

ldd ./test_lttnglinux-vdso.so.1 (0x00007fff751cc000)liblttng-ust.so.1 => /lib/x86_64-linux-gnu/liblttng-ust.so.1 (0x00007f35f4b30000)libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f35f4907000)libnuma.so.1 => /lib/x86_64-linux-gnu/libnuma.so.1 (0x00007f35f48fa000)liblttng-ust-common.so.1 => /lib/x86_64-linux-gnu/liblttng-ust-common.so.1 (0x00007f35f48ec000)liblttng-ust-tracepoint.so.1 => /lib/x86_64-linux-gnu/liblttng-ust-tracepoint.so.1 (0x00007f35f48ce000)/lib64/ld-linux-x86-64.so.2 (0x00007f35f4bc3000)

我的环境的部分情况

dpkg -l | grep liblttng-ust-dev

# dpkg -l | grep liblttng-ust-dev
ii  liblttng-ust-dev:amd64                 2.13.1-1ubuntu1                         amd64        LTTng 2.0 Userspace Tracer (development files)

ldconfig -p | grep lttng

# ldconfig -p | grep lttngliblttng-ust.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust.so.1liblttng-ust.so (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust.soliblttng-ust-tracepoint.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-tracepoint.so.1liblttng-ust-tracepoint.so (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-tracepoint.soliblttng-ust-python-agent.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-python-agent.so.1liblttng-ust-python-agent.so (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-python-agent.soliblttng-ust-pthread-wrapper.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-pthread-wrapper.so.1liblttng-ust-pthread-wrapper.so (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-pthread-wrapper.soliblttng-ust-libc-wrapper.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-libc-wrapper.so.1liblttng-ust-libc-wrapper.so (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-libc-wrapper.soliblttng-ust-fork.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-fork.so.1liblttng-ust-fork.so (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-fork.soliblttng-ust-fd.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-fd.so.1liblttng-ust-fd.so (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-fd.soliblttng-ust-dl.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-dl.so.1liblttng-ust-dl.so (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-dl.soliblttng-ust-cyg-profile.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-cyg-profile.so.1liblttng-ust-cyg-profile.so (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-cyg-profile.soliblttng-ust-cyg-profile-fast.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-cyg-profile-fast.so.1liblttng-ust-cyg-profile-fast.so (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-cyg-profile-fast.soliblttng-ust-ctl.so.5 (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-ctl.so.5liblttng-ust-ctl.so (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-ctl.soliblttng-ust-common.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-common.so.1liblttng-ust-common.so (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ust-common.soliblttng-ctl.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ctl.so.0liblttng-ctl.so (libc6,x86-64) => /lib/x86_64-linux-gnu/liblttng-ctl.solibbabeltrace-lttng-live.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libbabeltrace-lttng-live.so.1

CMake工程

CMakeList.txt

cmake_minimum_required(VERSION 3.10)
project(ctfgen)set(CMAKE_CXX_STANDARD 11)# Find LTTng UST library
find_library(LTTNG_UST_LIBRARY NAMES lttng-ust REQUIRED)
find_path(LTTNG_UST_INCLUDE_DIR NAMES lttng/tracef.h REQUIRED)# Add the executable
add_executable(test_lttng test_lttng.c)# Include the LTTng header files
target_include_directories(test_lttng PRIVATE ${LTTNG_UST_INCLUDE_DIR})# Link the LTTng UST library
target_link_libraries(test_lttng PRIVATE ${LTTNG_UST_LIBRARY})# Ensure the correct linking paths
link_directories("/lib/x86_64-linux-gnu")  # Or wherever the LTTng UST library is located

test_lttng.c

#include <lttng/tracef.h>int main() {tracef("my_event", "Hello, LTTng!");return 0;
}

编译

#!/bin/bash
rm -rf ./build
mkdir build
cd build
cmake ..
make
cd ..

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词