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

# 调试概述

子系统在 Qualcomm<sup>®</sup> SoC 上其自身的执行环境中独立处理任务。本节介绍针对受影响子系统的工具、示例日志和故障排查方法。了解子系统中的异常以及检查错误的方法，有助于诊断和排查此类异常。

下表列出了 SoC 上的重要子系统。

**表：SoC 上的子系统**

|                     **子系统**                    |                                                                          **描述**                                                                         |
| :--------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------: |
|                 应用处理器子系统（APSS）                 |                                            此主要子系统将 Qualcomm<sup>®</sup> Linux<sup>®</sup> 内核作为高级操作系统（HLOS）运行。                                           |
|                 应用数字信号处理器（aDSP）                |                                                     此子系统也称为低功耗音频子系统（LPASS），处理数字信号处理任务，例如音频编解码和语音识别。                                                     |
|                 计算数字信号处理器（cDSP）                |                                                               此子系统执行计算密集型任务，例如与神经网络相关的计算。                                                               |
| Qualcomm<sup>®</sup> 可信执行环境（TEE）/TrustZone（TZ） | 此子系统执行安全操作，并利用 Arm<sup>®</sup> TrustZone<sup>®</sup> 架构。有关更多信息，请参阅 [Qualcomm Linux 安全指南](https://dragonwingdocs.qualcomm.com/System/Security/overview)。 |
|                无线局域网处理器子系统（WPSS）               |  此子系统连接 Wi-Fi 网络、发送和接收数据包、处理安全协议并确保稳定的网络性能。有关更多信息，请参阅 [Qualcomm Linux Wi-Fi 指南](https://dragonwingdocs.qualcomm.com/Technologies/Wi-Fi/wi-fi-overview)。 |
|                   常开处理器（AOP）                   |                                                                       此子系统调节设备的电源。                                                                      |

<Note>
  术语"非 HLOS"是指除应用处理器之外所有子系统的软件。

  要了解子系统的引导流程，请参阅 [Qualcomm Linux 引导指南](https://dragonwingdocs.qualcomm.com/System/Boot/boot-overview)。
</Note>

<Note>
  请参阅 Qualcomm<sup>®</sup> Linux<sup>®</sup> 支持的[硬件 SoC](https://dragonwingdocs.qualcomm.com/Hardware-SoCs/IQ-9075)。
</Note>

## **调试工作流**

首先确定问题最先出现的子系统，因为 Qualcomm SoC 拥有许多子系统。这有助于您调试正确的子系统。

作为主要子系统的应用处理器可以检测到其他子系统的崩溃。例如，如果 aDSP 处理器子系统崩溃，内核日志会捕获子系统重启（SSR）崩溃错误日志。因此，要确定需要调试的子系统，请先检查内核调试消息。

下图显示了识别错误以及需要调试的组件的工作流。

<Frame caption="图：识别受影响子系统的工作流">
  <img src="https://mintcdn.com/qualcomm-staging/uWQLnBcS9sxlZhgB/System/Debug-Subsystem/media/qli-support/Debug-workflow.svg?fit=max&auto=format&n=uWQLnBcS9sxlZhgB&q=85&s=d70e842fc0c6d4ef4f3d1ecb15e756d0" alt="诊断内核 panic、软件 bug 和子系统崩溃问题的工作流。" width="1059" height="501" data-path="System/Debug-Subsystem/media/qli-support/Debug-workflow.svg" />
</Frame>

当内核 dmesg 日志未显示 panic 特征时，请检查 Qualcomm TEE 诊断（diag）日志中的错误，例如非安全看门狗 bite 和片上网络（NoC）错误。以下章节描述了表明内核 panic、bug 和子系统崩溃问题的示例内核消息。

### **识别内核 panic 和 bug**

您可以从内核 dmesg 日志中判断复位是内核 panic 还是 bug。以下示例日志表明内核 panic 或 bug：

* Panic（模式：一般错误）
  18.800936: \<6> Kernel panic - not syncing: Fatal exception
  18.800938: \<6> SMP: stopping secondary CPUs
  18.800947: \<6> CPU0: stopping
  Kernel panic - not syncing: Apps watchdog Bark received!
* Bug（模式 1：由内存损坏引起的强制崩溃）
  12.899532: \<6> BUG kmalloc-128 (Not tainted): Redzone overwritten
  12.905418: \<6> -----------------------------------------------------------------------------
* Bug（模式 2：来自驱动程序的强制崩溃）
  320.510769: \<6> ------------\[ cut here ]------------
  320.510781: \<6> kernel BUG at /local/mnt/workspace/lnxbuild/project/trees\_in\_use/free\_tree\_platform\_manifest\_refs\_tags/drivers/platform/msm/ipa/ipa\_v3/ipa\_qmi\_service.c:955!
* Bug（模式 3：由锁死问题导致的强制崩溃）
  \[ 180.993861] BUG: spinlock lockup suspected on CPU#0, swapper/0/0
  \[ 180.993883] lock: stop\_lock+0x0/0x18, .magic: dead4ead, .owner: swapper/6/0, .owner\_cpu: 6
  \[ 181.015629] Causing a watchdog bite!

<Note>
  大多数 bug 通常会导致内核 panic。有关调试内核问题的更多信息，请参阅 [Qualcomm Linux 内核指南](https://docs.qualcomm.com/bundle/publicresource/topics/80-80021-3/kernel_landing_page.html)。
</Note>

### **识别子系统崩溃问题**

您可以检查内核 dmesg 日志，以确定重启是否由子系统崩溃引起。例如，根据 `sc7280.dtsi`（节点：`remoteproc_adsp: remoteproc@3700000`），以下日志表明 aDSP 子系统崩溃：

0x000000000A27652C | 5198.790423: qcom\_q6v5\_pas 3700000.remoteproc: fatal error received: err\_inject\_crash.c:413:Crash injected via Diag

0x000000000A276689 | 5198.801061: remoteproc remoteproc2: crash detected in 3000000.remoteproc: type fatal error

0x000000000A2767A1 | 5198.809602: remoteproc remoteproc2: handling crash #1 in 3000000.remoteproc

0x000000000A27688E | 5198.816837: remoteproc remoteproc2: recovering 3000000.remoteproc

0x000000000A276971 | 5198.823784: qcom\_q6v5\_pas 8a00000.remoteproc: subsystem event rejected

### **从 Qualcomm TEE 日志中识别系统问题**

此功能仅面向拥有授权访问权限的许可开发者。有关表明 Qualcomm TEE 中错误的示例日志，请参阅 [Qualcomm Linux Debug Guide - Addendum](https://docs.qualcomm.com/bundle/resource/topics/80-80023-12A/identify_subsystem_to_be_debugged.html#identify_and_debug_errors_in_tz)。

如果 Qualcomm TEE diag 日志未显示错误，则问题可能是由安全看门狗 bite 引起的。有关看门狗问题的更多信息，请参阅[硬件复位](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/debug-common-system-issues#identify-the-cause-of-hardware-reset)。

有关调试 Qualcomm TEE 中问题的更多信息，请参阅 [Qualcomm Linux 安全指南](https://dragonwingdocs.qualcomm.com/System/Security/debug-qualcomm-tee-and-secure-devices#debug-qualcomm-tee-and-secure-devices)。

## **调试方法**

以下是两种调试方式：

* **在目标设备上调试（On-target debugging）**
  在目标设备上调试可解决软件问题。此方式允许直接从运行中的设备获取大部分信息。使用 SSH 将 Linux 主机连接到运行中的设备。要设置 SSH，请参阅[使用 SSH 登录](https://docs.qualcomm.com/bundle/publicresource/topics/80-80021-254/how_to.html#use-ssh)。
  有关各种在目标设备上调试功能的更多信息，请参阅[在目标设备上调试功能](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/debug-overview#debug-methods)。
* \*\*离线调试（Off-target debugging）\*\*i
  此方式使用日志而不是实际设备，是一种高效的调试方法。您可以使用内存转储或日志工具以及各种类型的日志进行离线调试。虽然 RAM 转储捕获了大部分内存区域，但它仅包含有限的硬件寄存器信息，因此调试与硬件相关的问题可能是一项挑战。
  有关各种离线调试功能的更多信息，请参阅[离线调试功能](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/debug-overview#debug-methods)。

### **在目标设备上调试功能**

您可以在运行时于设备上使用以下调试功能：

* [Perf 实用工具](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/debug-overview#perf-utility)
* [子系统重启](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/debug-overview#subsystem-restart)
* [强制子系统复位](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/debug-overview#debug-methods)

#### **Perf 实用工具**

Linux 中的 Perf 实用工具便于性能分析和性能剖析。Linux 内核在 `tools/perf` 目录中包含 Perf 实用工具。

您可以使用 Perf 实用工具调试系统行为的各个方面，包括 CPU 性能计数器、tracepoint、kprobe 和 uprobe（用于动态跟踪）。下表列出了 Perf 实用工具的主要功能。

**表：Perf 实用工具的主要功能**

|   **功能**   |                                       **描述**                                       |
| :--------: | :--------------------------------------------------------------------------------: |
|  CPU 性能计数器 |       这些 CPU 硬件寄存器跟踪各种事件，例如已执行的指令、缓存未命中和分支预测错误。这些事件构成了对应用程序进行性能剖析和识别性能瓶颈的基础。       |
| Tracepoint | 您可以将这些 tracepoint 放置在代码中的逻辑位置，例如系统调用、网络事件和文件系统操作。这些 tracepoint 以最小的开销提供时间戳和栈跟踪等信息。 |
|    动态跟踪    |             此功能使用 kprobe 和 uprobe 框架动态创建 tracepoint，允许在内核空间和用户空间中进行跟踪。             |

有关 Perf 实用工具的更多信息，请参阅以下资源：

* [Perf 主页](https://perf.wiki.kernel.org/index.php/Main_Page)
* [HOWTO](https://github.com/Linaro/OpenCSD/blob/master/HOWTO.md)
* [CoreSight](https://docs.kernel.org/trace/coresight/index.html)
* [CoreSight - Perf](https://docs.kernel.org/trace/coresight/coresight-perf.html)

#### **子系统重启**

子系统在崩溃时可以独立重启而无需重启设备，这称为子系统重启（SSR）。SSR 功能使用 Linux 内核中可用的 remoteproc 框架。

要启用完整内存转储以进行调试，请默认禁用 SSR 功能。

<Note>
  建议在商用设备上使用 SSR 功能，而不要在开发阶段使用。
</Note>

有关 SSR 功能的更多信息，请参阅[配置远程处理器子系统](https://dragonwingdocs.qualcomm.com/System/Kernel/configure-the-remoteprocessor-remoteproc-subsystems#configure-the-remoteprocessor-remoteproc-subsystems)。

启用 SSR 功能可在子系统重启时生成 SSR 转储。考虑使用 SSR 转储进行调试，因为它的大小比完整内存转储小。但是，调试某些子系统崩溃需要完整的 RAM 转储。

有关如何启用和捕获子系统转储的更多信息，请参阅[捕获子系统转储](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/collect-and-parse-ram-dump#capture-the-subsystem-dumps)。

#### **强制子系统复位**

使用此功能可调试需要重启子系统的用例。

<Note>
  此功能仅面向拥有授权访问权限的许可开发者。
</Note>

要强制子系统复位，您可以使用 QXDM Professional<sup>™</sup> 工具运行 `diag` 命令。有关 QXDM Professional 命令及其用法的更多信息，请参阅 [Qualcomm Linux Debug Guide - Addendum](https://docs.qualcomm.com/bundle/resource/topics/80-80021-12A/debug-non-hlos-subsystems.html#qxdm_professional)。

### **离线调试功能**

您可以使用 RAM 转储或 QXDM Professional 进行离线调试。

#### **RAM 转储**

RAM 转储是故障发生时整个内存的快照。您可以使用各种工具分析 RAM 转储，包括 Qualcomm<sup>®</sup> 崩溃分析门户（QCAP）、RAMParser、Lauterbach TRACE32 模拟器和 crash 实用工具。

有关如何收集和解析 RAM 转储的更多信息，请参阅[收集并解析 RAM 转储](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/collect-and-parse-ram-dump#collect-and-parse-ram-dump)。

#### **QXDM Professional**

使用 QXDM Professional 调试各种子系统。此工具仅面向拥有授权访问权限的许可开发者。有关 QXDM Professional 命令及其用法的更多信息，请参阅 [Qualcomm Linux Debug Guide - Addendum](https://docs.qualcomm.com/bundle/resource/topics/80-80021-12A/debug-non-hlos-subsystems.html#qxdm_professional)。

## **常见系统问题**

您可以将系统问题归入以下类型之一：

> * [Linux 内核空间问题](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/debug-addendum-overview#debug-linux-kernel-space-issues)
> * [系统问题](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/debug-common-system-issues#debug-common-system-issues)
>   > * [看门狗问题](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/debug-common-system-issues#debug-watchdog-timeout-issues)
>   > * [总线挂起和超时问题](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/debug-common-system-issues#debug-common-system-issues)
>   > * [硬件复位问题](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/debug-common-system-issues#identify-the-cause-of-hardware-reset)

## **其他问题**

您可能会遇到以下其他问题：

* 由软件 bug 导致的设备死机问题
* 与 Linux 应用相关的问题
* 与 PCB 相关的硬件问题导致的随机复位

## **后续步骤**

> * 要调试与 Linux 应用相关的问题，请参阅[调试 Linux 用户空间问题](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/Debug%20linux%20userspace%20issues#debug-linux-user-space-issues)。
> * 要调试与 Linux 内核相关的问题，请参阅[调试 Linux 内核空间问题](https://dragonwingdocs.qualcomm.com/System/Debug-Subsystem/Debug%20linux%20userspace%20issues)。
