ARM Cortex-Mマイクロコントローラからコード・カバレッジを取得
4月 16, 2024 by Qt Group 日本オフィス | Comments
このブログは「Retrieving Code Coverage from ARM Cortex-M Microcontrollers」を翻訳・一部加筆したものです。
はじめに
前回の記事では、ARM Cortex-Mマイクロコントローラのコード・カバレッジを測定する方法としてSquish Cocoをご紹介しました。今回の記事では、これらのマイクロコントローラーからコード・カバレッジ・データを取得する方法に焦点を当て、GDBの使用法を詳しく解説します。この記事を読む前に、前回の記事をご一読いただくことをお勧めします。
ご紹介するのは簡単な方法で、ホスト・コンピューターにRS232やその他の接続がない場合に便利です。
Atmel Studioのセットアップ
GDBを使用するために、まずAtmel Studioが正しく設定されているかを確認しましょう。メニューの Tools > Options をクリックし、Debugger options で GDB Settings を選択します。ARM アーキテクチャが選択され、GDB 実行ファイルへのパスが有効であることを確認してください。
サンプル アプリケーション
コード・カバレッジ・データのデモンストレーションには、サンプル・アプリケーション GccApplication1.zip を使用します。これは、前述のブログ記事で提供されたものと同じアプリケーションです。このアプリケーションは単純で、指定された整数引数の絶対値を返す関数 abs(x) をテストします。また、意図的に入力引数の負の値を1つだけテストすることで、テストでカバーされなかったコードを見ることができます。
#include "sam.h"
static int abs(int x) { // simple function which we want to test
if (x <= 0) {
return x;
}
return -x;
}
static int testAbs() { // simple test case
return abs(-1) == 1 ? 1 : 0;
}
#ifdef __COVERAGESCANNER__ // Coco IO functions
// Code coverage of the rest of the code is not that important for this example
#pragma CoverageScanner(cov-off)
char coverage[256]; // execution report
static int csfputs(const char *s, void *stream) {
char **buffer_p = (char**)(stream);
do {
**buffer_p = *s;
(*buffer_p)++;
s++;
} while (*s);
return 1;
}
static void *csfopenappend(const char *path) {
int i;
static char * pp = 0 ;
for (i = 0 ; i < sizeof( coverage )/sizeof( coverage[0] ); i++)
coverage[i] = '\n';
pp = coverage ;
return (void*)( & pp );
}
static int csfclose(void *fp) {
return 1;
}
static void saveCov() {
__coveragescanner_set_custom_io(0, csfputs, csfopenappend,
0, 0, csfclose, 0);
__coveragescanner_save();
}
#endif
int main(void) {
SystemInit(); // initialize the SAM system
testAbs(); // execute test case
#ifdef __COVERAGESCANNER__
saveCov();
#endif
while (1) {} // no exit - this is an MCU
}
ここで使用するCocoのカスタムIO関数は、「リモート・デバッガ接続でコード・カバレッジ・データを取得する」の記事とほぼ同じです。画面表示時のスペースを節約するため、少し密なフォーマットになっています。
GDBコンソールの使用
サンプルをコンパイルした後、62行目(whileループのある行)にブレークポイントを設定し、アプリケーションをデプロイしてデバッグを開始します。デバッガがブレークポイントで停止したら、Atmel StudioでGDBコンソールを開きます(menu View > Other Windows > GDB Console)。
まず、変数coverageの内容をコンソール・ウィンドウに表示してみよう:
p coverage
この後、GDBの作業ディレクトリを、Squish Cocoが.csmesファイル(ここではGccApplication1.elf.csmes)を生成したプロジェクトのディレクトリに変更します。次のコマンドを実行してください:
cd "C:¥Users¥autotest¥Documents¥Atmel Studio¥7.0¥GccApplication1¥Debug"
これにより、カバレッジ変数のファイルへのダンプがより便利になります。デフォルトでは(現在のバージョンのAtmel Studioでは)、GDBの作業ディレクトリは %LOCALAPPDATA%\VirtualStore\Program Files (x86)\Atmel\Studio\7.0\atbackend にあります。また、CocoのCoverageBrowserは、ダンプファイルがそこに置かれている場合、インポートのために自動的にダンプファイルを提供しません。
それでは、変数coverageの値をファイルにダンプしてみましょう。そのためには、GDBコンソールで以下のコマンドを実行します:
dump value GccApplication1.elf.csexe coverage
これは、C:¥Users¥autotest¥Documents¥Atmel Studio¥7.0¥GccApplication1¥Debugに作成されるファイルGccApplication1.elf.csexeに変数coverageの値を "ダンプ "します。
結果を確認する
カバレッジデータファイル(GccApplication1.elf.csexe)を入手したら、それをCoverageBrowserにインポートすることができます。
このためには、CoverageBrowserからGccApplication1.elf.csmesファイル(注意:.csexeとは異なる拡張子です)を開きます。.csmesファイルは、プロジェクトビルドのDebugフォルダにあります。例えば、C:¥Users¥autotest¥Documents¥Atmel Studio¥7.0¥GccApplication1¥Debug のような場所にあります。その後、CoverageBrowserのメニューから File > Load Execution Report を選択し、GccApplication1.elf.csmesファイルを選択します。
Blog Topics:
Comments
Subscribe to our newsletter
Subscribe Newsletter
Try Qt 6.8 Now!
Download the latest release here: www.qt.io/download.
Qt 6.8 release focuses on technology trends like spatial computing & XR, complex data visualization in 2D & 3D, and ARM-based development for desktop.
We're Hiring
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.
Commenting for this post has ended.
Just want to remind you that qtcreator Git project is still missing v4.8.0-beta2 tag (-;
I think the code navigation and Clang-based code model gets worse with each release, unfortunately.
With the current 4.8 b2, I can no longer ctrl+click on many symbols to "follow symbol" - nothing happens, basically.
Also, the Clang-based code model infests my editor with very many false semantic issues, e.g. "
auto
type specifier is a C++11 extension", while my project is clearly setup correctly for C++11 features in CMake.I'm using CMake + Ninja + MSVC 2017 on Windows 10.
I know the correct way to approach this is to use the bug tracker, but I feel the UI of the tracker is very bad and doesn't really allow for proper searching of duplicates. Googling the issue brings up many hits but no real answers, unfortunately.
Thanks for the great IDE, otherwise - I wish the above issues could be somehow resolved, as I feel they've become more and more of a blocker for me (VS Code starts to look pretty good at this point, as an alternative).
I don't get these warnings for a dummy CMake project (Qt Quick Application from the wizard, CMake project, adding some code to the main.cpp, CMake 3.13, Windows 7, MSVC2017).
https://wiki.qt.io/Qt_Creat... describes some debugging methods to find out what flags are passed to Clang and what it does otherwise, maybe that sheds some light on your issue.
Thanks for the debugging tips.
DebugView shows me some interesting data, such as:
[14192] qtc.clangcodemodel.ipc: ====> DocumentsOpenedMessage(FileContainer(pathtomyfile.cpp, Utf8StringVector(-nostdinc, -nostdlibinc, -c, -m64, -target, x8664-pc-windows-msvc, -std=c++98
The above is followed by a very long list of include paths, up to 4100 characters - is there an upper limit to the string and will it handle include paths with spaces (such as Windows SDK default install locations) correctly? Also, is the -std=c++98 defined on purpose?
Can you reproduce this with a small example? Can you create a bug report with all available data?
Before trying to debug why Clang code model does not work properly (i.e. why there is -std=98 in command line) you have to know how to specify proper C++ standard for your project. Apparently there is no such option. The Internet is full of topics about the same question without an answer: How to specify C++ standard for Clang code model for your project in Qt Creator?
I am talking about generic project without a build system.
You specify the C++ standard in the build system files of your project, which is used for building. If Qt Creator does not pick that up correctly for a directly supported build tool (qmake/cmake/qbs/...), it is a bug.
That said, "Generic Projects" in Qt Creator do not define a build system, and do not provide a way to set any compiler flags.
So we just found a root cause. In reality typical project does not need to have a build system known to the IDE. And even if some project, lets say, CMake-based, in major cases it could not be opened in QtCreator as is without issues.
Authors of the generic projects in QtCreator were understanding this, providing full featured IDE for such cases: Kits, build configuration with command sequence, run configurations, environment setup, build output parser connected to the issues list, debugger. Common include directories and defines. Per-project coding style and Clang code model parameters.
But this does not make much sense without trivial option: C++ standard.
I really don't understand whether this was intentional, to make Clang code model inoperable for generic projects. Or this feature is missing by mistake or lack of attention.
Do you need help to implement that?
macOS: seemingly introducing something new to each widget without asking - man what work to delete it each time.
> no member named 'PlaceholderText' in 'QPalette'
palette.setBrush(QPalette::Active, QPalette::PlaceholderText, brush9);
~~~~~~~~~~^
Can you please tell us: 1) what you did exactly, 2) what you expected, 3) what happened instead?
1) working on a project, using the ui-edit-view, example: moving a widget there out of current position
2) expected that the project and the values / entries stay the same except new xy-values on that particular widget moved
3) magically the new setBrush/...'PlaceholderText' is a new entry on all widgets and has to be deleted manually (ui.xy* files) to compile the project without errors on each widget implemented.
also part of rc
I fail to reproduce with a simple example here.
Can you please create a bugreport and attach a small example project / ui file that exposes your issue?
Is QtCreator Can be build for android device? Samsung DeX service allows you to use your tablet like a computer, and i want to be able programming by using it.
No.
You can build it for aarch64 and install it on Linux on DeX
https://news.samsung.com/gl...
I think it's a mad idea to release Qt Creator without support for the latest iOS devices: https://bugreports.qt.io/br...
(TL;TR) The new iOS devices UUID contain hyphens that break the ability to use them with QtCreator. All the new phone models from the XS and XR lines do not work, you can only use XCode with them.
Maybe this can be addressed in a bug fix release so we don't have to wait 6 months?
Did you check if the fix that we did for Qt Creator 4.7.2 (and released) works for you?
https://codereview.qt-proje... has a +1 from you. If it doesn't work, I'd appreciate a comment on the bug report https://bugreports.qt.io/br... .
Note that https://bugreports.qt.io/br... is a task to improve the interaction between components in Qt Creator, which probably would have avoided the issue in the first place, so we avoid similar issues in the future.