libgui中的BufferQueueProducer加入堆栈CallStack编译报错问题-大厂企业实战项目难题

devtools/2024/11/24 11:08:40/

背景:

针对调试和分析某个模块的源码时候,经常需要对某个方法进行堆栈的打印,java相关的代码都没啥问题,大家都可以很正常的打印出来,但是一些native的模块就不是那么顺利了。

大家可能会说,马哥你不是介绍过native有CallStack可以搞定native层面的调用堆栈么?
哈哈,确实CallStack是可以实现对c++代码堆栈的打印,不过这个只是对一般的c++代码可能没问题,真正在实际开发过程中还是会遇到很多问题,比如下面这个同学的堆栈打印问题:

在这里插入图片描述
总结一下这个同学的问题:

学员朋友想要在BufferQueueProducer.cpp中的queueBuffer中加入堆栈打印,看看整个调用链路
在这里插入图片描述

也按套路加入了如下代码:

#include <utils/CallStack.h> android::CallStack cs("INTEL-MESA");cs.update();cs.log("INTEL-MESA");

而且对应的bp也引入了相关的库
在这里插入图片描述
但是编译的时候发现如下报错:

[  1% 11/917] //frameworks/av/media/module/bqhelper:libstagefright_bufferqueue_helper link libstagefright_bufferqueue_helper.so
FAILED: out/soong/.intermediates/frameworks/av/media/module/bqhelper/libstagefright_bufferqueue_helper/android_vendor.34_x86_64_shared/unstripped/libstagefright_bufferqueue_helper.so
prebuilts/clang/host/linux-x86/clang-r487747c/bin/clang++ out/soong/.intermediates/bionic/libc/crtbegin_so/android_vendor.34_x86_64/crtbegin_so.o @out/soong/.intermediates/frameworks/av/media/module/bqhe
lper/libstagefright_bufferqueue_helper/android_vendor.34_x86_64_shared/unstripped/libstagefright_bufferqueue_helper.so.rsp out/soong/.intermediates/bionic/libc/crtend_so/android_vendor.34_x86_64/crtend_s
o.o -o out/soong/.intermediates/frameworks/av/media/module/bqhelper/libstagefright_bufferqueue_helper/android_vendor.34_x86_64_shared/unstripped/libstagefright_bufferqueue_helper.so -target x86_64-linux-
android29 -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--build-id=md5 -Wl,--fatal-warnings -Wl,--no-undefined-version -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_stripped.a -Wl,--exclude-libs
,libunwind_llvm.a -Wl,--exclude-libs,libunwind.a -fuse-ld=lld -Wl,--icf=safe -Wl,--pack-dyn-relocs=android+relr -Wl,--use-android-relr-tags -Wl,--no-undefined -Wl,--hash-style=gnu -m64 -nostdlib -Wl,--gc
-sections -shared -Wl,-soname,libstagefright_bufferqueue_helper.so -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fno-sanitize-link-runtime -Wl,--exclude-libs=libclang_rt.builtins-x86_64-a
ndroid.a -Wl,--exclude-libs=libclang_rt.ubsan_minimal-x86_64-android.a 
ld.lld: error: undefined symbol: android::CallStack::CallStack(char const*, int)
>>> referenced by BufferQueueProducer.cpp:927 (frameworks/native/libs/gui/BufferQueueProducer.cpp:927)
>>>               BufferQueueProducer.o:(android::BufferQueueProducer::queueBuffer(int, android::IGraphicBufferProducer::QueueBufferInput const&, android::IGraphicBufferProducer::QueueBufferOutput*)) in 
archive out/soong/.intermediates/frameworks/native/libs/gui/libgui_bufferqueue_static/android_vendor.34_x86_64_static/libgui_bufferqueue_static.ald.lld: error: undefined symbol: android::CallStack::update(int, int)
>>> referenced by BufferQueueProducer.cpp:928 (frameworks/native/libs/gui/BufferQueueProducer.cpp:928)
>>>               BufferQueueProducer.o:(android::BufferQueueProducer::queueBuffer(int, android::IGraphicBufferProducer::QueueBufferInput const&, android::IGraphicBufferProducer::QueueBufferOutput*)) in 
archive out/soong/.intermediates/frameworks/native/libs/gui/libgui_bufferqueue_static/android_vendor.34_x86_64_static/libgui_bufferqueue_static.ald.lld: error: undefined symbol: android::CallStack::log(char const*, android_LogPriority, char const*) const
>>> referenced by BufferQueueProducer.cpp:929 (frameworks/native/libs/gui/BufferQueueProducer.cpp:929)
>>>               BufferQueueProducer.o:(android::BufferQueueProducer::queueBuffer(int, android::IGraphicBufferProducer::QueueBufferInput const&, android::IGraphicBufferProducer::QueueBufferOutput*)) in 
archive out/soong/.intermediates/frameworks/native/libs/gui/libgui_bufferqueue_static/android_vendor.34_x86_64_static/libgui_bufferqueue_static.ald.lld: error: undefined symbol: android::CallStack::~CallStack()
>>> referenced by BufferQueueProducer.cpp:930 (frameworks/native/libs/gui/BufferQueueProducer.cpp:930)
>>>               BufferQueueProducer.o:(android::BufferQueueProducer::queueBuffer(int, android::IGraphicBufferProducer::QueueBufferInput const&, android::IGraphicBufferProducer::QueueBufferOutput*)) in 
archive out/soong/.intermediates/frameworks/native/libs/gui/libgui_bufferqueue_static/android_vendor.34_x86_64_static/libgui_bufferqueue_static.a
clang-17: error: linker command failed with exit code 1 (use -v to see invocation)
[  1% 12/917] //frameworks/av/media/module/bqhelper:libstagefright_bufferqueue_helper link libstagefright_bufferqueue_helper.so [x86]
FAILED: out/soong/.intermediates/frameworks/av/media/module/bqhelper/libstagefright_bufferqueue_helper/android_vendor.34_x86_x86_64_shared/unstripped/libstagefright_bufferqueue_helper.so
prebuilts/clang/host/linux-x86/clang-r487747c/bin/clang++ out/soong/.intermediates/bionic/libc/crtbegin_so/android_vendor.34_x86_x86_64/crtbegin_so.o @out/soong/.intermediates/frameworks/av/media/module/
bqhelper/libstagefright_bufferqueue_helper/android_vendor.34_x86_x86_64_shared/unstripped/libstagefright_bufferqueue_helper.so.rsp out/soong/.intermediates/bionic/libc/crtend_so/android_vendor.34_x86_x86
_64/crtend_so.o -o out/soong/.intermediates/frameworks/av/media/module/bqhelper/libstagefright_bufferqueue_helper/android_vendor.34_x86_x86_64_shared/unstripped/libstagefright_bufferqueue_helper.so -targ
et i686-linux-android29 -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--build-id=md5 -Wl,--fatal-warnings -Wl,--no-undefined-version -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_stripped.a -Wl,
--exclude-libs,libunwind_llvm.a -Wl,--exclude-libs,libunwind.a -fuse-ld=lld -Wl,--icf=safe -Wl,--pack-dyn-relocs=android+relr -Wl,--use-android-relr-tags -Wl,--no-undefined -Wl,--hash-style=gnu -m32 -nos
tdlib -Wl,--gc-sections -shared -Wl,-soname,libstagefright_bufferqueue_helper.so -fsanitize=signed-integer-overflow,unsigned-integer-overflow -fno-sanitize-link-runtime -Wl,--exclude-libs=libclang_rt.bui
ltins-i686-android.a -Wl,--exclude-libs=libclang_rt.ubsan_minimal-i686-android.a 
ld.lld: error: undefined symbol: android::CallStack::CallStack(char const*, int)
>>> referenced by BufferQueueProducer.cpp:927 (frameworks/native/libs/gui/BufferQueueProducer.cpp:927)
>>>               BufferQueueProducer.o:(android::BufferQueueProducer::queueBuffer(int, android::IGraphicBufferProducer::QueueBufferInput const&, android::IGraphicBufferProducer::QueueBufferOutput*)) in 
archive out/soong/.intermediates/frameworks/native/libs/gui/libgui_bufferqueue_static/android_vendor.34_x86_x86_64_static/libgui_bufferqueue_static.ald.lld: error: undefined symbol: android::CallStack::update(int, int)
>>> referenced by BufferQueueProducer.cpp:928 (frameworks/native/libs/gui/BufferQueueProducer.cpp:928)
>>>               BufferQueueProducer.o:(android::BufferQueueProducer::queueBuffer(int, android::IGraphicBufferProducer::QueueBufferInput const&, android::IGraphicBufferProducer::QueueBufferOutput*)) in 
archive out/soong/.intermediates/frameworks/native/libs/gui/libgui_bufferqueue_static/android_vendor.34_x86_x86_64_static/libgui_bufferqueue_static.ald.lld: error: undefined symbol: android::CallStack::log(char const*, android_LogPriority, char const*) const
>>> referenced by BufferQueueProducer.cpp:929 (frameworks/native/libs/gui/BufferQueueProducer.cpp:929)
>>>               BufferQueueProducer.o:(android::BufferQueueProducer::queueBuffer(int, android::IGraphicBufferProducer::QueueBufferInput const&, android::IGraphicBufferProducer::QueueBufferOutput*)) in 
archive out/soong/.intermediates/frameworks/native/libs/gui/libgui_bufferqueue_static/android_vendor.34_x86_x86_64_static/libgui_bufferqueue_static.ald.lld: error: undefined symbol: android::CallStack::~CallStack()
>>> referenced by BufferQueueProducer.cpp:930 (frameworks/native/libs/gui/BufferQueueProducer.cpp:930)
>>>               BufferQueueProducer.o:(android::BufferQueueProducer::queueBuffer(int, android::IGraphicBufferProducer::QueueBufferInput const&, android::IGraphicBufferProducer::QueueBufferOutput*)) in 
archive out/soong/.intermediates/frameworks/native/libs/gui/libgui_bufferqueue_static/android_vendor.34_x86_x86_64_static/libgui_bufferqueue_static.a
clang-17: error: linker command failed with exit code 1 (use -v to see invocation)
[  1% 15/917] //frameworks/av/media/module/bqhelper:libstagefright_bufferqueue_helper_novndk link libstagefright_bufferqueue_helper_novndk.so [apex31]
FAILED: out/soong/.intermediates/frameworks/av/media/module/bqhelper/libstagefright_bufferqueue_helper_novndk/android_x86_64_shared_cfi_apex31/unstripped/libstagefright_bufferqueue_helper_novndk.so
prebuilts/clang/host/linux-x86/clang-r487747c/bin/clang++ out/soong/.intermediates/bionic/libc/crtbegin_so/android_x86_64_apex31/crtbegin_so.o @out/soong/.intermediates/frameworks/av/media/module/bqhelpe
r/libstagefright_bufferqueue_helper_novndk/android_x86_64_shared_cfi_apex31/unstripped/libstagefright_bufferqueue_helper_novndk.so.rsp out/soong/.intermediates/bionic/libc/crtend_so/android_x86_64_apex31
/crtend_so.o -o out/soong/.intermediates/frameworks/av/media/module/bqhelper/libstagefright_bufferqueue_helper_novndk/android_x86_64_shared_cfi_apex31/unstripped/libstagefright_bufferqueue_helper_novndk.
so -target x86_64-linux-android29 -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--build-id=md5 -Wl,--fatal-warnings -Wl,--no-undefined-version -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_strip
ped.a -Wl,--exclude-libs,libunwind_llvm.a -Wl,--exclude-libs,libunwind.a -fuse-ld=lld -Wl,--icf=safe -Wl,--pack-dyn-relocs=android+relr -Wl,--use-android-relr-tags -Wl,--no-undefined -Wl,--hash-style=gnu-m64 -nostdlib -Wl,--gc-sections -shared -Wl,-soname,libstagefright_bufferqueue_helper_novndk.so -flto -fsanitize-cfi-cross-dso -fsanitize=cfi -Wl,-plugin-opt,O1 -fsanitize=signed-integer-overflow,unsig
ned-integer-overflow,cfi -fno-sanitize-link-runtime -Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a -Wl,--exclude-libs=libclang_rt.ubsan_minimal-x86_64-android.a 
ld.lld: error: undefined symbol: android::CallStack::CallStack(char const*, int)
>>> referenced by BufferQueueProducer.cpp:927 (frameworks/native/libs/gui/BufferQueueProducer.cpp:927)
>>>               lto.tmp:(android::BufferQueueProducer::queueBuffer(int, android::IGraphicBufferProducer::QueueBufferInput const&, android::IGraphicBufferProducer::QueueBufferOutput*))ld.lld: error: undefined symbol: android::CallStack::update(int, int)
>>> referenced by BufferQueueProducer.cpp:928 (frameworks/native/libs/gui/BufferQueueProducer.cpp:928)
>>>               lto.tmp:(android::BufferQueueProducer::queueBuffer(int, android::IGraphicBufferProducer::QueueBufferInput const&, android::IGraphicBufferProducer::QueueBufferOutput*))ld.lld: error: undefined symbol: android::CallStack::log(char const*, android_LogPriority, char const*) const
>>> referenced by BufferQueueProducer.cpp:929 (frameworks/native/libs/gui/BufferQueueProducer.cpp:929)
>>>               lto.tmp:(android::BufferQueueProducer::queueBuffer(int, android::IGraphicBufferProducer::QueueBufferInput const&, android::IGraphicBufferProducer::QueueBufferOutput*))ld.lld: error: undefined symbol: android::CallStack::~CallStack()
>>> referenced by BufferQueueProducer.cpp:930 (frameworks/native/libs/gui/BufferQueueProducer.cpp:930)
>>>               lto.tmp:(android::BufferQueueProducer::queueBuffer(int, android::IGraphicBufferProducer::QueueBufferInput const&, android::IGraphicBufferProducer::QueueBufferOutput*))
clang-17: error: linker command failed with exit code 1 (use -v to see invocation)
11:21:00 ninja failed with: exit status 1

大面积报ld.lld: error: undefined symbol: android::CallStack错误,明明已经引入了相关库,
一看到这些报其实大家可能都一脸懵,不知道为啥会有这种错误。。。。。

分析报错大概原因

仔细看看对应的报错
在这里插入图片描述
在这里插入图片描述
明显都不是编译libgui时候的报错,都是报错在编译

frameworks/av/media/module/bqhelper:libstagefright_bufferqueue_helper

等库的时候有问题,简单说就是这些库其实也对我们修改的BufferQueueProducer.cpp有依赖,从bp中也可以发现:

BufferQueueProducer.cpp是在libgui_bufferqueue_sources中
在这里插入图片描述
libgui_bufferqueue_sources由被2个地方使用

libgui_bufferqueue_static静态库
在这里插入图片描述
libgui的动态库
在这里插入图片描述
但是在libstagefright_bufferqueue_helper编译时候有依赖这个libgui_bufferqueue_static库

在这里插入图片描述
这个也就是为啥会报错的原因,那么清楚了原来libstagefright_bufferqueue_helper,libstagefright_bufferqueue_helper_novndk对这个有依赖,那么是否可以直接在这个bp加入 libutilscallstack呢?

尝试一下:
在这里插入图片描述

突然发现又报错如下:

Consider adding "com.android.media.swcodec" to 'apex_available' property of "liblzma"
error: frameworks/av/apex/Android.bp:248:1: module "com.android.media.swcodec" variant "android_common_cfi_com.android.media.swcodec_image": "liblzma" requires "liblzma" that doesn't list the APEX under 
'apex_available'.Dependency path:via tag apex.dependencyTag{"executable"}-> mediaswcodec{os:android,image:,arch:x86_64,sdk:,apex:apex31}via tag cc.libraryDependencyTag: { Kind:sharedLibraryDependency Order:normalLibraryDependency wholeStatic:false reexportFlags:false explicitlyVersioned:false dataLib:false ndk:false staticUnwi
nder:false makeSuffix: skipApexAllowedDependenciesCheck:false excludeInApex:false unexportedSymbols:false}-> libmedia_codecserviceregistrant{os:android,image:,arch:x86_64,sdk:,link:shared,version:,apex:apex31}via tag cc.libraryDependencyTag: { Kind:sharedLibraryDependency Order:normalLibraryDependency wholeStatic:false reexportFlags:false explicitlyVersioned:false dataLib:false ndk:false staticUnwi
nder:false makeSuffix: skipApexAllowedDependenciesCheck:false excludeInApex:false unexportedSymbols:false}-> libcodec2_hidl@1.1{os:android,image:,arch:x86_64,sdk:,link:shared,version:,apex:apex31}via tag cc.libraryDependencyTag: { Kind:sharedLibraryDependency Order:normalLibraryDependency wholeStatic:false reexportFlags:true explicitlyVersioned:false dataLib:false ndk:false staticUnwin
der:false makeSuffix: skipApexAllowedDependenciesCheck:false excludeInApex:false unexportedSymbols:false}-> libcodec2_hidl@1.0{os:android,image:,arch:x86_64,sdk:,link:shared,version:,apex:apex31}via tag cc.libraryDependencyTag: { Kind:sharedLibraryDependency Order:normalLibraryDependency wholeStatic:false reexportFlags:false explicitlyVersioned:false dataLib:false ndk:false staticUnwi
nder:false makeSuffix: skipApexAllowedDependenciesCheck:false excludeInApex:false unexportedSymbols:false}-> libstagefright_bufferqueue_helper_novndk{os:android,image:,arch:x86_64,sdk:,link:shared,version:,apex:apex31}via tag cc.libraryDependencyTag: { Kind:sharedLibraryDependency Order:normalLibraryDependency wholeStatic:false reexportFlags:false explicitlyVersioned:false dataLib:false ndk:false staticUnwi
nder:false makeSuffix: skipApexAllowedDependenciesCheck:false excludeInApex:false unexportedSymbols:false}-> libutilscallstack{os:android,image:,arch:x86_64,sdk:,link:shared,version:,apex:apex31}via tag cc.libraryDependencyTag: { Kind:sharedLibraryDependency Order:normalLibraryDependency wholeStatic:false reexportFlags:false explicitlyVersioned:false dataLib:false ndk:false staticUnwi
nder:false makeSuffix: skipApexAllowedDependenciesCheck:false excludeInApex:false unexportedSymbols:false}-> libunwindstack{os:android,image:,arch:x86_64,sdk:,link:shared,version:,apex:apex31}via tag cc.libraryDependencyTag: { Kind:sharedLibraryDependency Order:normalLibraryDependency wholeStatic:false reexportFlags:false explicitlyVersioned:false dataLib:false ndk:false staticUnwi
nder:false makeSuffix: skipApexAllowedDependenciesCheck:false excludeInApex:false unexportedSymbols:false}-> liblzma{os:android,image:,arch:x86_64,sdk:,link:shared,version:,apex:apex31}via tag cc.dependencyTag: { name:reuse objects}-> liblzma{os:android,image:,arch:x86_64,sdk:,link:static,afdo:,lto:,apex:apex31}Consider adding "com.android.media.swcodec" to 'apex_available' property of "liblzma"

error: frameworks/av/apex/Android.bp:248:1: module “com.android.media.swcodec” variant “android_common_cfi_com.android.media.swcodec_image”: “libunwindstack” requires “liblzma” that doesn’t list the APEX
under ‘apex_available’.

有点感觉进入了无底洞,涉及的依赖有点多,要把"libunwindstack" requires “liblzma” 也加入相关的apex_available,对这块不是那么深入了解,所以也不敢在继续改了

问题如何解决思路:

因为上面有编译报错,所以对queueBuffer的堆栈打印暂时没有成功

1、继续按照编译提示正面进行修改解决,这个可能需要更加深入系统这些库依赖关系等,感觉影响波及较大,这里如果有网友知道正面修改如何解决的请留言联系哈

2、是否可以考虑其他方法可以实现对这个queueBuffer的堆栈打印呢?
比如我们产生anr时候有对应的trace文件,trace文件里面既可以有详细的堆栈CallStack,那么是否可以考虑从这个角度修改呢?

更多framework技术干货,请关注下面“千里马学框架”


http://www.ppmy.cn/devtools/136533.html

相关文章

I.MX6U 裸机开发18.GPT定时器实现高精度延时

I.MX6U 裸机开发18.GPT定时器实现高精度延时 一、GPT定时器简介1. GPT 功能2. 时钟源3. 框图4. 运行模式&#xff08;1&#xff09;Restart mode&#xff08;2&#xff09;Free-Run Mode 5. 中断类型&#xff08;1&#xff09;溢出中断 Rollover Interrupt&#xff08;2&#x…

websocket消息的实现

1. 创建 WebSocket 连接 WebSocket 是通过 WebSocket 对象建立的。连接成功后&#xff0c;前端可以与服务器双向通信。 const socket new WebSocket(ws://your-server-url);// 监听连接建立 socket.onopen () > {console.log(WebSocket connection established);// 可以…

SELinux知识点

SELinux 软件安全性 《关于UNIX的安全》中Dennis Ritchie提到&#xff1a;“首先要面对的事实是&#xff0c;UNIX的开发者并没有考虑安全问题&#xff0c;单这一点就单会引发大量的漏洞”。主要是因为防火墙通常不具备查杀病毒的能力&#xff0c;只能对数据包过滤&#xff0c…

Mac设置java环境变量

Mac电脑中存在多个jdk版本,如何配置java环境变量为指定版本jdk? 一、查看所有已安装的 JDK 版本 /usr/libexec/java_home -V二、临时设置 export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)三、永久设置 如果需要永久使用指定版

计算机网络的初步认识

文章目录 一、初识计算机网络1.1、基本概念和特点1.1.1、基本概念1.1.2、特点1.2、分类1.3、性能指标1.4、体系结构1.4.1、体系结构的基本认识1.4.2、TCP/IP的深入认识二、初始互联网2.1、互联网概念和特点2.1.1、概念2.1.2、特点2.2、互联网组成2.2.1、边缘部分2.2.2、核心部分…

微网能量管理研究

微网能量管理研究的重点 微网系统的建模 建立分布式能源单元模型以及微网系统的整体运行、协调控制和优化配置等方面的模型 分布式电源控制策略 微网内分布式电源及储能系统运行依赖于电力电子接口技术&#xff0c;需要相应的充放电控制策略 再生能源发电预测 准确预测太阳能…

Redis分布式锁的原理与Redisson实现

Redis分布式锁的原理与Redisson实现 目录 引言Redis分布式锁的基本原理Redisson实现Redis分布式锁Redisson分布式锁的使用示例小结 引言 在分布式系统中&#xff0c;多个服务实例同时访问共享资源时&#xff0c;可能会导致数据不一致或竞争条件。为了解决这些问题&#xff…

CANDENCE: 原理图中如何批量修改元件封装

原理图中如何批量修改元件封装 一、选中一部分元件更换封装 更换下图中的几个电阻的封装 选中这几个电阻&#xff0c;点击 “edit properties” 弹出以下对话框 点击“pivot”, 找到封装一栏 可以单个修改 也可以多个一起修改 修改完成 二、选中一页原理图中的元件更换封装…