> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 使用 Valgrind 调试

Valgrind 工具有助于检测 C 和 C++ 程序中常见的与内存相关的错误。这些错误可能导致崩溃和不可预测的行为,例如内存泄漏和内存损坏。默认情况下,构建包含 Valgrind 工具。

## **前提条件**

设置 SSH。有关说明,请参阅[使用 SSH 登录](https://docs.qualcomm.com/bundle/publicresource/topics/80-80021-254/how_to.html#use-ssh)。

## **使用 Valgrind 调试**

1. 将调试符号推送到设备。有关说明,请参阅[配置调试符号](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/configure-debug-symbols#configure-debug-symbols)。
2. 在设备上运行以下 Valgrind 命令:
   ```text theme={null}
   valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes /usr/bin/tqftpserv
   ```
   **示例输出:**
   ```text theme={null}
   ==622== Memcheck, a memory error detector
   ==622== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
   ==622== Command: /usr/bin/tqftpserv
   ==622==
   ^C==622==
   ==622== Process terminating with default action of signal 2 (SIGINT)
   ==622== at 0x498EF38: select (select.c:69)
   ==622== by 0x4013CB: ??? (in /usr/bin/tqftpserv)
   ==622== by 0x48DB1AF: (below main) (libc_start_call_main.h:58)
   ==622==
   ==622== FILE DESCRIPTORS: 4 open (3 std) at exit.
   ==622== Open pf-42 socket 3:
   ==622== at 0x49984CC: socket (syscall-template.S:120)
   ==622== by 0x4891293: qrtr_open (in /usr/lib/libqrtr.so.1.0)
   ==622== by 0x40129B: ??? (in /usr/bin/tqftpserv)
   ==622== by 0x48DB1AF: (below main) (libc_start_call_main.h:58)
   ==622==
   ==622==
   ==622== HEAP SUMMARY:
   ==622== in use at exit: 0 bytes in 0 blocks
   ==622== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
   ==622==
   ==622== All heap blocks were freed -- no leaks are possible
   ==622==
   ==622== For lists of detected and suppressed errors, rerun with: -s
   ==622== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
   ==622== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
   ```

有关更多信息,请参阅 [Valgrind](https://valgrind.org/)。
