gdb 之 attach

参考链接

https://cloud.tencent.com/developer/article/1521208

csharp 复制代码
thread 266
set scheduler-locking step
csharp 复制代码
(gdb) bt
#0  facebook::velox::HdfsReadFile::pread (this=0x7f3670186010, offset=18513484, length=16305, buf=0x7f37651cf540,
    stats=0x7f3670192600)
    at /work/gluten/ep/build-velox/build/velox_ep/velox/connectors/hive/storage_adapters/hdfs/HdfsReadFile.cpp:168
#1  0x00007f36d39af1ea in facebook::velox::ReadFile::preadv (this=0x7f3670186010, offset=18513484,
    buffers=std::vector of length 73, capacity 128 = {...}, stats=0x7f3670192600)
    at /work/gluten/ep/build-velox/build/velox_ep/velox/common/file/File.cpp:84
#2  0x00007f36d3e59837 in facebook::velox::dwio::common::ReadFileInputStream::read (this=0x7f36701b9980,
    buffers=std::vector of length 73, capacity 128 = {...}, offset=4,
    logType=facebook::velox::dwio::common::MetricsLog::MetricsType::FILE)
    at /work/gluten/ep/build-velox/build/velox_ep/velox/dwio/common/InputStream.cpp:105
#3  0x00007f36da96f918 in facebook::velox::dwio::common::DirectCoalescedLoad::loadData (this=0x7f3670194ce0, prefetch=true)
    at /work/gluten/ep/build-velox/build/velox_ep/velox/dwio/common/DirectBufferedInput.cpp:321
#4  0x00007f36d39451af in facebook::velox::cache::CoalescedLoad::loadOrFuture (this=0x7f3670194ce0, wait=0x0,
    ssdSavable=true) at /work/gluten/ep/build-velox/build/velox_ep/velox/common/caching/AsyncDataCache.cpp:302
#5  0x00007f36da96ee5c in operator() (__closure=0x7f36697e9800)
    at /work/gluten/ep/build-velox/build/velox_ep/velox/dwio/common/DirectBufferedInput.cpp:226
#6  0x00007f36da970ed0 in folly::detail::function::call_<facebook::velox::dwio::common::DirectBufferedInput::readRegions(const std::vector<facebook::velox::dwio::common::LoadRequest*>&, bool, const std::vector<int>&)::<lambda()>, true, false, void>(folly::detail::function::Data &) (p=...) at /work/gluten/dev/vcpkg/vcpkg_installed/x64-linux-avx/include/folly/Function.h:341
#7  0x00007f36db04f634 in folly::detail::function::FunctionTraits<void ()>::operator()() (this=0x7f36697e9800)
    at /work/dev/vcpkg/.vcpkg/buildtrees/folly/src/4.07.01.00-4ae9f6791f.clean/folly/Function.h:368
#8  folly::catch_exception<folly::Function<void ()>&, void (&)(char const*) noexcept, char const*&, void>(folly::Function<void ()>&, void (&)(char const*) noexcept, char const*&) (c=<optimized out>, t=...)
    at /work/dev/vcpkg/.vcpkg/buildtrees/folly/src/4.07.01.00-4ae9f6791f.clean/folly/lang/Exception.h:290
#9  folly::Executor::invokeCatchingExns<folly::Function<void ()> >(char const*, folly::Function<void ()>) (f=...,
    p=0x7f36e17f9cd5 "ThreadPoolExecutor: func")
    at /work/dev/vcpkg/.vcpkg/buildtrees/folly/src/4.07.01.00-4ae9f6791f.clean/folly/Executor.h:234
#10 folly::ThreadPoolExecutor::runTask (this=0x7f3ad0311e00, thread=std::shared_ptr (count 6, weak 0) 0x7f36701c22c0,
    task=...)
    at /work/dev/vcpkg/.vcpkg/buildtrees/folly/src/4.07.01.00-4ae9f6791f.clean/folly/executors/ThreadPoolExecutor.cpp:142
#11 0x00007f36db0454bb in operator() (__closure=0x7f3670185dd0)
    at /opt/rh/devtoolset-11/root/usr/include/c++/11/ext/atomicity.h:109
单步调试运行

参考链接:

csharp 复制代码
thread 266
set scheduler-locking step

# 让 GDB 不因 SIGSEGV 而停止
(gdb) handle SIGSEGV nostop noprint pass
csharp 复制代码
# 或完全忽略
(gdb) handle SIGSEGV ignore

handle SIGPIPE nostop noprint pass
统计 breakpoint 命中次数
csharp 复制代码
commands
continue
end
csharp 复制代码
(gdb) bt
#0  hdfsRead (fs=<optimized out>, f=0x7f4bdf4b8350, buffer=0x7f4bdc05b83c, length=720900)
    at /build/source/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c:1514
#1  0x00007f4c66b6bf71 in facebook::velox::filesystems::arrow::io::internal::LibHdfsShim::Read (
    this=0x7f4c73f33560 <facebook::velox::filesystems::arrow::io::internal::(anonymous namespace)::libhdfs_shim>,
    fs=0x7f5062475510, file=0x7f4bdf4b8350, buffer=0x7f4bdc05b83c, length=720900)
    at /work/gluten/ep/build-velox/build/velox_ep/velox/external/hdfs/ArrowHdfsInternal.cpp:447
#2  0x00007f4c66950de4 in facebook::velox::HdfsFile::read (this=0x7f4bdcb9e960, pos=0x7f4bdc05b83c "", length=720900)
    at /work/gluten/ep/build-velox/build/velox_ep/velox/connectors/hive/storage_adapters/hdfs/HdfsReadFile.cpp:57
#3  0x00007f4c66951326 in facebook::velox::HdfsReadFile::Impl::preadInternal (this=0x7f4d081a1170, offset=4, length=1048576,
    pos=0x7f4bdc05b83c "")
    at /work/gluten/ep/build-velox/build/velox_ep/velox/connectors/hive/storage_adapters/hdfs/HdfsReadFile.cpp:100
#4  0x00007f4c6695137a in facebook::velox::HdfsReadFile::Impl::pread (this=0x7f4d081a1170, offset=4, length=1048576,
    buf=0x7f4bdc00b840)
    at /work/gluten/ep/build-velox/build/velox_ep/velox/connectors/hive/storage_adapters/hdfs/HdfsReadFile.cpp:107
#5  0x00007f4c66950871 in facebook::velox::HdfsReadFile::pread (this=0x7f4d08180920, offset=4, length=1048576,
    buf=0x7f4bdc00b840, stats=0x7f4d0818b550)
    at /work/gluten/ep/build-velox/build/velox_ep/velox/connectors/hive/storage_adapters/hdfs/HdfsReadFile.cpp:167
#6  0x00007f4c639af1ea in facebook::velox::ReadFile::preadv (this=0x7f4d08180920, offset=4,
    buffers=std::vector of length 73, capacity 128 = {...}, stats=0x7f4d0818b550)
    at /work/gluten/ep/build-velox/build/velox_ep/velox/common/file/File.cpp:84
#7  0x00007f4c63e59837 in facebook::velox::dwio::common::ReadFileInputStream::read (this=0x7f4d081a1af0,
    buffers=std::vector of length 73, capacity 128 = {...}, offset=4,
    logType=facebook::velox::dwio::common::MetricsLog::MetricsType::FILE)
    at /work/gluten/ep/build-velox/build/velox_ep/velox/dwio/common/InputStream.cpp:105
#8  0x00007f4c6a96f918 in facebook::velox::dwio::common::DirectCoalescedLoad::loadData (this=0x7f4d0818dc30, prefetch=true)
    at /work/gluten/ep/build-velox/build/velox_ep/velox/dwio/common/DirectBufferedInput.cpp:321
#9  0x00007f4c639451af in facebook::velox::cache::CoalescedLoad::loadOrFuture (this=0x7f4d0818dc30, wait=0x0, ssdSavable=true)
    at /work/gluten/ep/build-velox/build/velox_ep/velox/common/caching/AsyncDataCache.cpp:302
#10 0x00007f4c6a96ee5c in operator() (__closure=0x7f4bf8be5800)
    at /work/gluten/ep/build-velox/build/velox_ep/velox/dwio/common/DirectBufferedInput.cpp:226
案例
csharp 复制代码
1472 /**
1473  * If the underlying stream supports the ByteBufferReadable interface then
1474  * this method will transparently use read(ByteBuffer). This can help
1475  * improve performance as it avoids unnecessarily copying data on to the Java
1476  * heap. Instead the data will be directly copied from kernel space to the C
1477  * heap.
1478  */
1479 tSize hdfsRead(hdfsFS fs, hdfsFile f, void* buffer, tSize length)
1480 {
1481     jobject jInputStream;
1482     jbyteArray jbRarray;
1483     jvalue jVal;
1484     jthrowable jthr;
1485     JNIEnv* env;
1486
1487     if (length == 0) {
1488         return 0;
1489     } else if (length < 0) {
1490         errno = EINVAL;
1491         return -1;
1492     }
1493     if (f->flags & HDFS_FILE_SUPPORTS_DIRECT_READ) {
1494       return readDirect(fs, f, buffer, length);
1495     }
csharp 复制代码
1508     //Parameters
1509     if (readPrepare(env, fs, f, &jInputStream) == -1) {
1510       return -1;
1511     }
1512
1513     //Read the requisite bytes
1514     jbRarray = (*env)->NewByteArray(env, length);
1515     if (!jbRarray) {
1516         errno = printPendingExceptionAndFree(env, PRINT_EXC_ALL,
1517             "hdfsRead: NewByteArray");
1518         return -1;
1519     }
相关推荐
2401_873204652 小时前
C++中的组合模式实战
开发语言·c++·算法
2401_831824962 小时前
高性能压缩库实现
开发语言·c++·算法
2401_874732532 小时前
C++中的策略模式进阶
开发语言·c++·算法
steins_甲乙2 小时前
C# 通过共享内存与 C++ 宿主协同捕获软件窗口
开发语言·c++·c#·内存共享
j_xxx404_2 小时前
蓝桥杯基础--时间复杂度
数据结构·c++·算法·蓝桥杯·排序算法
学嵌入式的小杨同学2 小时前
STM32 进阶封神之路(二十五):ESP8266 深度解析 —— 从 WiFi 通信原理到 AT 指令开发(底层逻辑 + 实战基础)
c++·vscode·stm32·单片机·嵌入式硬件·mcu·智能硬件
2501_945423542 小时前
C++跨平台开发实战
开发语言·c++·算法
Oueii2 小时前
分布式系统监控工具
开发语言·c++·算法
haibindev3 小时前
把近5万个源文件喂给AI之前,我先做了一件事
java·前端·c++·ai编程·代码审计·架构分析