目录

Debugging Third-Party Library Source Code

Third-party shared packages can be classified into two types: Harmony Archive (HAR) and Harmony Shared Package (HSP). The source code debugging methods for these two types of packages are different.

Distinguishing Between Bytecode HAR and Source Code HAR

HAR packages are categorized into bytecode HARs and source code HARs. A HAR package is a bytecode HAR if it meets both of the following conditions. Otherwise, it is a source code HAR. For more guidance on building source code HAR and bytecode HAR, see Building HAR.

  1. The .abc file exists in the ets directory of the HAR package.
  2. The oh-package.json5 file of the HAR package contains the byteCodeHar field and the value is true.

Debugging the Bytecode HAR

[h2]Debugging C++ Code

If the HAP/HSP references a bytecode HAR package that contains C++ code, perform the following steps to debug the HAR package:

  1. Choose Run > Edit Configurations > Debugger, select the Symbol Directories tab, and click + to add the .so file with debugging information, which is stored in {ProjectPath}/{ModuleName}/build/{product}/intermediates/libs/default/arm64-v8a.

    To generate the .so file with debugging information, add the strip field to the project- or module-level build-profile.json5 file and set it to false. For details, see Configuring for C++ Builds.

  2. When you debug an app, DevEco Studio loads the configured .so files preferentially. If these .so files contain debugging information, you can debug the source code. Since the source code file information embedded in the .so file refers to the file path at compile time, if it does not match the local source code file path, you need to associate the source files using either of the following methods:
    • Method 1: Add a command in the LLDB Startup Commands tab to create a mapping. Example:
      settings set -- target.source-map {old-path} {new-path}
      • old-path: file path at compile time.
      • new-path: local source code file path.

    • Method 2: After the debugger steps into the assembly code, a message is displayed asking you to select the source code. Click Select File and select the local C++ source code.

[h2]Debugging ArkTS Code

If a bytecode HAR package is compiled in debug mode in Project A (HAR package project), and Project B (host project) references this bytecode HAR package with local access to the source code of the HAR package. To debug this bytecode HAR, there are two methods: debugging in the host project or debugging in the HAR package project.

The bytecode HARs compiled in release mode do not support debugging.

Debugging the Source Code HAR

[h2]Debugging C++ Code

If the HAP/HSP references a source code HAR package and the HAR package contains C++ code, perform debugging by referring to Debugging the Bytecode HAR.

[h2]Debugging ArkTS Code

If a project references a source code HAR package, debug this HAR package. The debugging methods vary depending on whether there is local source code.

Debugging HSP Source Code

To debug the HSP source code, place the source code in the local project module and debug it by referring to Method 1: Debugging in the host project.