我正在爲基於ARM Cortex-M的MCU開發「裸機」C/C++應用程序。 我想將Clang靜態分析器加入到我的構建系統中。如何在Cortex-M項目中使用Clang靜態分析器?
所以不是
arm-none-eabi-g++ ....
我現在用
scan-build arm-none-eabi-g++ ...
這似乎是工作好,但我得到了一堆關於CMSIS頭文件和,我從拿到的東西消息芯片製造商:
- 錯誤:從指針轉換爲較小的類型'uint32_t'(又名'unsigned int')丟失信息
我同意,他們應該有使用uintptr_t
代替int32_t
但不能重寫他們的整個代碼庫和CMSIS頭爲好。我可以告訴scan-build
這個平臺上的指針實際上是32位的,所以不會丟失任何信息?
我試着告訴它考慮使用哪個平臺。但是,如果使用scan-build --analyzer-target=arm-none-eabi
,我得到:
- 致命錯誤: 'CString的' 找不到文件
- 錯誤:未知的寄存器名 'vfpcc' 在ASM
再次,在CMSIS頭。
我的問題是:
- 爲什麼不能分析發現
cstring
頭,當我使用--analyzer-target=arm-none-eabi
? - 如何告訴分析儀我的指針是真正的32位?
- 它爲什麼會給我那個未知寄存器的錯誤?
或者:
- 我怎麼能沉默了CMSIS頭的警告?
編輯
我也試過以下建議,但沒有奏效,結果是相同的errros:
scan-build
--use-cc=/usr/bin/arm-none-eabi-gcc
--use-c++=/usr/bin/arm-none-eabi-g++
--analyzer-target=arm-none-eabi
arm-none-eabi-g++ ...
注:我用的是qbs構建系統,並使用我的.qbs
文件中的cpp.compilerWrapper
屬性生成scan-build
來電。
一個典型的命令如下:
/usr/bin/scan-build --use-cc=/usr/bin/arm-none-eabi-gcc --use-c++=/usr/bin/arm-none-eabi-g++ --analyzer-target=arm-none-eabi /usr/bin/arm-none-eabi-g++ -g -O0 -Wall -Wextra -mcpu=cortex-m4 -mfloat-abi=hard -mthumb -mabi=aapcs -mno-sched-prolog -mabort-on-noreturn -fdata-sections -ffunction-sections -fno-strict-aliasing -fno-builtin -specs=nosys.specs -specs=nano.specs -static -nodefaultlibs -Wdouble-promotion -ggdb -g3 -mfpu=fpv4-sp-d16 -pipe -frandom-seed=0x633bf14c -Wdate-time -fno-exceptions -fno-rtti -fvisibility=default -Wall -Wextra -Wpedantic -Wno-unused-function -DS1_USE_SEGGER_RTT -DEFM32WG940F256 -D__HEAP_SIZE=0 -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/common/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/config -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/dmadrv/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/dmadrv/config -I/home/Timur/Projects/MyProject/my-software/dependencies/hardware/kit/common/drivers -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/gpiointerrupt/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/nvm/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/nvm/config -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/rtcdrv/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/rtcdrv/config -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/sleep/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/spidrv/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/spidrv/config -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/uartdrv/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/uartdrv/config -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/ustimer/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/ustimer/config -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emlib/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/CMSIS/Include -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/Device/SiliconLabs/EFM32WG/Include -I/home/Timur/Projects/MyProject/my-software/dependencies/RTT -std=c++0x -o /home/Timur/Projects/MyProject/build-myproject-my-software-arm_none_eabi-Debug/qtc_arm_none_a793425c-debug/myproject-my-software.qtc-arm-none-a793425c.7e216384/.obj/e6c416981c959a66/efm32-serial-port.cpp.o -c /home/Timur/Projects/MyProject/my-software/source/utilities/hal/efm32-serial-port.cpp
In file included from /home/Timur/Projects/MyProject/my-software/source/utilities/hal/efm32-serial-port.cpp:24:
In file included from /home/Timur/Projects/MyProject/my-software/source/utilities/hal/efm32-serial-port.h:27:
In file included from /home/Timur/Projects/MyProject/my-software/source/utilities/hal/abstract-serial-port.h:32:
/home/Timur/Projects/MyProject/my-software/source/utilities/hal/../core/callback.h:32:10: fatal error: 'cstddef' file not found
#include <cstddef>
^~~~~~~~~
1 error generated.
scan-build: Using '/usr/bin/clang-4.0' for static analysis
scan-build: 0 bugs found.
scan-build: The analyzer encountered problems on some source files.
scan-build: Preprocessed versions of these sources were deposited in '/tmp/scan-build-2017-07-27-194505-8969-1/failures'.
scan-build: Please consider submitting a bug report using these files:
scan-build: http://clang-analyzer.llvm.org/filing_bugs.html
嗨Venemo,你成功了嗎?我使用Segger嵌入式工作室和nRF52 DK板有同樣的問題。 – alcor
@alcor不,我還在等待這個答案。 – Venemo
感謝哥們,還在這裏試試 – alcor