C ++ソースコードの変更と生成のための完全なオープンソース、強力なソリューション。 C ++プロジェクトのボイラープレートコードの量を減らします。
メインプロジェクトページ:https://blockspacer.github.io/flex_docs/
Ubuntu 20.04.2 LTSでテスト。
わずかな変更を加えた他のプラットフォームで動作する場合があります。
依存関係リモートのリストを追加できるようにするには、次のコマンドを入力してください。
cmake -E time conan config install conan/remotes/
# OR:
# cmake -E time conan config install conan/remotes_disabled_ssl/ インストールガイド
コナンパッケージ
注:LLVMビルドで固執するには数時間かかる場合があります。
以下のコマンドを使用します--profile clang12_compiler12_compiler 。
CONANプロフィールの例~/.conan/profiles/clang :
[ settings ]
# We are building in Ubuntu Linux
os_build=Linux
os=Linux
arch_build=x86_64
arch=x86_64
compiler=clang
compiler.version=10
compiler.libcxx=libstdc++11
[ env ]
CC=/usr/bin/clang-10
CXX=/usr/bin/clang++-10
[ build_requires ]
cmake_installer/3.15.5@conan/stableclang12_compilerプロファイルを作成します:
[settings]
# We are building in Ubuntu Linux
os_build=Linux
os=Linux
arch_build=x86_64
arch=x86_64
compiler=clang
compiler.version=12
compiler.libcxx=libstdc++11
compiler.cppstd=17
llvm_9:build_type=Release
[env]
CC=/usr/bin/clang-12
CXX=/usr/bin/clang++-12
[build_requires]
cmake_installer/3.15.5@conan/stableコナンプロファイルファイルを作成する前に、https://docs.conan.io/en/latest/using_packages/using_profiles.htmlを参照してください。
.cmakeスクリプトを使用して、Conanパッケージをダウンロードしてインストールします。
git clone https://github.com/blockspacer/conan_github_downloader.git ~ /conan_github_downloader
cmake
-DSCRIPT_PATH= " $PWD /get_conan_dependencies.cmake "
-DENABLE_CLING=TRUE
-DENABLE_LLVM=TRUE
-DENABLE_LLVM_INSTALLER=FALSE
-DEXTRA_CONAN_OPTS= " --profile;clang12_compiler
;-s;build_type=Debug
;-s;cling_conan:build_type=Release
;-s;llvm_12:build_type=Release
;--build;missing "
-P ~ /conan_github_downloader/conan_github_downloader.cmake
# clean build cache
conan remove " * " --build --forceflextoolとそのプラグインを単一コマンドにインストールする場合は、 tools/buildConanThirdparty.cmakeに提供されているオプションを変更します。
注: tools/buildConanThirdparty.cmake完全な再構築を実行します。数時間かかる場合があります。
以下のコマンドを使用します--profile clang12_compiler12_compiler 。コナンプロファイルファイルを作成する前に、https://docs.conan.io/en/latest/using_packages/using_profiles.htmlを参照してください。
buildConanThirdparty.cmakeスクリプトを使用して、Conanパッケージをダウンロードしてインストールします。
注:set -DENABLE_CLING=FALSE上記のtools/buildConanThirdparty.cmakeを使用してclingを既にインストールしている場合。
git clone https://github.com/blockspacer/conan_github_downloader.git ~ /conan_github_downloader
cmake
-DSCRIPT_PATH= " $PWD /get_conan_dependencies.cmake "
-DENABLE_CLING=TRUE
-DENABLE_LLVM=TRUE
-DENABLE_LLVM_INSTALLER=FALSE
-DENABLE_FLEXTOOL=TRUE
-DENABLE_BASIS_PLUGIN_HELPER=TRUE
-DENABLE_FLEX_REFLECT_PLUGIN=TRUE
-DENABLE_SQUARETS=TRUE
-DENABLE_FLEX_SQUARETS_PLUGIN=TRUE
-DENABLE_FLEX_PIMPL_PLUGIN=TRUE
-DENABLE_FLEX_TYPECLASS_PLUGIN=TRUE
-DENABLE_FLEX_META_PLUGIN=TRUE
-DENABLE_FLEX_META_DEMO=TRUE
-DEXTRA_CONAN_OPTS= " --profile;clang12_compiler
;-s;build_type=Debug
;-s;cling_conan:build_type=Release
;-s;llvm_12:build_type=Release
;--build;missing "
-P ~ /conan_github_downloader/conan_github_downloader.cmake
# clean build cache
conan remove " * " --build --force以下のコマンドを使用して、flextoolを再構築します(プラグインは個別にインストールする必要があります)。
以下のコマンドを使用します--profile clang12_compiler12_compiler 。コナンプロファイルファイルを作成する前に、https://docs.conan.io/en/latest/using_packages/using_profiles.htmlを参照してください
export VERBOSE=1
export CONAN_REVISIONS_ENABLED=1
export CONAN_VERBOSE_TRACEBACK=1
export CONAN_PRINT_RUN_COMMANDS=1
export CONAN_LOGGING_LEVEL=10
# NOTE: change `build_type=Debug` to `build_type=Release` in production
# NOTE: use --build=missing if you got error `ERROR: Missing prebuilt package`
cmake -E time
conan create . conan/stable
-s build_type=Debug
-s cling_conan:build_type=Release
-s llvm_tools:build_type=Release
--profile clang12_compiler
-e flextool:enable_tests=True
-e flextool:enable_llvm_tools=True
# clean build cache
conan remove " * " --build --forcecompile_commands.jsonと互換性がありませんflextoolを使用するときに、コンパイルデータベースの生成を無効にします。
cmakeを使用している場合は、 CMAKE_EXPORT_COMPILE_COMMANDSをFALSEに設定します。
compile_commands.jsonビルドフォルダー(または親フォルダー)に存在する場合、flextoolは失敗する可能性があります。
このプロジェクトは、FlexFerrumのautoprogrammerのために可能です。
メディアにおけるFlexFerrumのautoprogrammerに関する記事:
find . -type f -name " *_buildflags.h " -exec rm {} ;
find . -type f -name " *_buildflags.tmp " -exec rm {} ;
(rm -rf local_build || true)
export CONAN_REVISIONS_ENABLED=1
export CONAN_VERBOSE_TRACEBACK=1
export CONAN_PRINT_RUN_COMMANDS=1
export CONAN_LOGGING_LEVEL=10
export PKG_NAME=flextool/master@conan/stable
(CONAN_REVISIONS_ENABLED=1
conan remove --force $PKG_NAME || true)
# NOTE: use --build=missing if you got error `ERROR: Missing prebuilt package`
cmake -E time
conan install .
--install-folder local_build
-s build_type=Debug
-s cling_conan:build_type=Release
-s llvm_12:build_type=Release
-o openssl:shared=True
-e basis:enable_tests=True
-o chromium_base:shared=True
-e chromium_base:enable_tests=True
-o perfetto:is_hermetic_clang=False
--profile clang12_compiler
-e flexlib:enable_tests=True
-o flexlib:shared=False
-o perfetto:is_hermetic_clang=False
-o flexlib:enable_cling=True
-e flextool:enable_tests=True
-o flextool:enable_cling=True
(rm local_build/CMakeCache.txt || true)
cmake -E time
conan source .
--source-folder .
--install-folder local_build
# You can use `cmake --build . -- -j14` on second run.
cmake -E time
conan build .
--build-folder local_build
--source-folder .
--install-folder local_build
conan package .
--build-folder local_build
--package-folder local_build/package_dir
--source-folder .
--install-folder local_build
cmake -E time
conan export-pkg . conan/stable
--package-folder local_build/package_dir
-s build_type=Debug
--force
-s cling_conan:build_type=Release
-s llvm_12:build_type=Release
-o openssl:shared=True
-e basis:enable_tests=True
-o chromium_base:shared=True
-e chromium_base:enable_tests=True
-o perfetto:is_hermetic_clang=False
--profile clang12_compiler
-e flexlib:enable_tests=True
-o flexlib:shared=False
-o perfetto:is_hermetic_clang=False
-o flexlib:enable_cling=True
-e flextool:enable_tests=True
-o flextool:enable_cling=True
cmake -E time
conan test test_package
flextool/master@conan/stable
-s build_type=Debug
-s cling_conan:build_type=Release
-s llvm_12:build_type=Release
-o openssl:shared=True
-e basis:enable_tests=True
-o chromium_base:shared=True
-e chromium_base:enable_tests=True
-o perfetto:is_hermetic_clang=False
--profile clang12_compiler
-e flexlib:enable_tests=True
-o flexlib:shared=False
-o perfetto:is_hermetic_clang=False
-o flexlib:enable_cling=True
-e flextool:enable_tests=True
-o flextool:enable_cling=True編集可能なパッケージを使用すると、地元の作業ディレクトリでヘッダーとアーティファクトを消費できる場所を見つける場所をコナンに伝えることができます。 conan createまたはconan export-pkgを実行する必要はありません。
詳細については、https://docs.conan.io/en/latest/developing_packages/editable_packages.htmlを参照してください
ローカルに構築:
export VERBOSE=1
export CONAN_REVISIONS_ENABLED=1
export CONAN_VERBOSE_TRACEBACK=1
export CONAN_PRINT_RUN_COMMANDS=1
export CONAN_LOGGING_LEVEL=10
cmake -E time
conan install .
--install-folder local_build
-s build_type=Debug
-s cling_conan:build_type=Release
-s llvm_tools:build_type=Release
--profile clang12_compiler
-e flextool:enable_tests=True
-e flextool:enable_llvm_tools=True
cmake -E time
conan source .
--source-folder local_build
--install-folder local_build
conan build .
--build-folder local_build
--source-folder local_build
--install-folder local_build
conan package .
--build-folder local_build
--package-folder local_build/package_dir
--source-folder local_build
--install-folder local_buildパッケージを編集モードに設定します。
conan editable add local_build/package_dir
flextool/master@conan/stable conanfile.py self.in_local_cacheを介してローカルビルドを検出するように変更されていることに注意してください。
フォルダの変更ソースの後、local_build(ソースパッケージフォルダーでコマンドを実行):
conan build .
--build-folder local_build
--source-folder local_build
--install-folder local_build
conan package .
--build-folder local_build
--package-folder local_build/package_dir
--source-folder local_build
--install-folder local_build
テストプロジェクトを構築します。
編集可能なモードを元に戻すには、以下を使用してリンクを削除するだけです。
conan editable remove
flextool/master@conan/stable一度に複数のプロジェクトを構築できます。各パッケージフォルダーを指すadd_subdirectoryを使用してCMakeLists.txtを作成するだけです。
注:通常のCmakeベースのプロジェクトとしてIDEでワークスペースを開くことができます(Build DirectoryをWorkSpaceProject Pathに変更)!
詳細については、https://docs.conan.io/en/latest/developing_packages/workspaces.htmlを参照してください
たとえば、FlextoolとFlexLibの両方を同時に構築する必要があります(FlextoolにはFlexLibが必要です)。
# change ~ to desired build folder
cd ~
# Replace paths to yours!
# Make sure each project in NOT in editable mode!
cat << EOF > ~/conanws.yml
editables:
flexlib/master@conan/stable:
path: /......../flexlib
flextool/master@conan/stable:
path: /......../flextool
layout: layout_flex
workspace_generator: cmake
root:
- flextool/master@conan/stable
EOF
cat << EOF > ~/layout_flex
# This helps to define the location of CMakeLists.txt within package
[source_folder]
.
# This defines where the conanbuildinfo.cmake will be written to
[build_folder]
build/{{settings.build_type}}
EOF mkdir build_flex
cd build_flex
cat << EOF > CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(WorkspaceProject)
include( $ {CMAKE_BINARY_DIR}/conanworkspace.cmake)
list(PREPEND CMAKE_MODULE_PATH " $ {PACKAGE_flexlib_SRC}/cmake")
list(PREPEND CMAKE_MODULE_PATH " $ {PACKAGE_flextool_SRC}/cmake")
conan_workspace_subdirectories()
add_dependencies(flextool flexlib)
EOF
# must contain `include(${CMAKE_BINARY_DIR}/conanworkspace.cmake)` without slash `` (slash added for bash cat command)
cat CMakeLists.txt
# combines options from all projects
conan workspace install
../conanws.yml
--profile=clang
-s build_type=Debug
-s cling_conan:build_type=Release
-s llvm_tools:build_type=Release
-o openssl:shared=True
-o chromium_base:shared=True
-e basis:enable_tests=True
-e abseil:enable_llvm_tools=True
-o chromium_base:use_alloc_shim=True
-o chromium_tcmalloc:use_alloc_shim=True
-o perfetto:is_hermetic_clang=False
-e flextool:enable_tests=True
-e flextool:enable_llvm_tools=True
-o flexlib:shared=False
-o flexlib:enable_clang_from_conan=False
-e flexlib:enable_tests=True conan workspace installによって作成されたフォルダーにビルド:
# NOTE: change `build_type=Debug` to `build_type=Release` in production
export build_type=Debug
# optional
# remove old CMakeCache
(rm CMakeCache.txt || true)
# configure via cmake
cmake -E time cmake .
-DCMAKE_VERBOSE_MAKEFILE=TRUE
-DENABLE_TESTS=TRUE
-DBASE_NEED_GEN_BUILD_DATE=FALSE
-DENABLE_DOCTEST=ON
-DBUILD_SHARED_LIBS=FALSE
-DCONAN_AUTO_INSTALL=OFF
-DCMAKE_BUILD_TYPE= ${build_type}
# remove generated files
# change paths to yours
# rm ~/flex_typeclass_plugin/build/Debug/*generated*
# build code
cmake -E time cmake --build .
--config ${build_type}
-- -j8
# run unit tests for flexlib
cmake -E time cmake --build .
--config ${build_type}
--target flexlib_run_all_tests
# run unit tests for flextool
cmake -E time cmake --build .
--config ${build_type}
--target flextool_run_all_testsWorkspaceを使用すると、既存のソースファイルをすばやく変更できます。
self.in_local_cacheを使用して、コナン編集モードを検出します。
# Local build
# see https://docs.conan.io/en/latest/developing_packages/editable_packages.html
if not self . in_local_cache :
self . copy ( "conanfile.py" , dst = "." , keep_path = False )すべてのターゲットにグローバルに一意の名前があることを確認してください。
たとえば、各プロジェクトに「テスト」と同じ名前のターゲットを持つことはできません。 「$ {root_project_name} -test_main_gtest」など、各ターゲットの名前にプロジェクト固有のプレフィックスを追加することで、その問題を解決できます。
CMAKE_BINARY_DIR 、 conan workspace installによって作成されたフォルダーを指すため、 CMAKE_CURRENT_BINARY_DIR CMAKE_BINARY_DIRなどに希望することを確認してください。
インストール前:プラグインには、事前に構築されたflextool(同じワークスペース)が必要です。プラグインなしでワークスペースを構築する必要があります。そうして初めて、プラグインで再構築することができます。
YMLファイルにプラグインを追加します:
editables :
chromium_base/master@conan/stable :
path : /........./chromium_base
basis/master@conan/stable :
path : /........./basis
flex_support_headers/master@conan/stable :
path : /........./flex_support_headers
flexlib/master@conan/stable :
path : /........./flexlib
flextool/master@conan/stable :
path : /........./flextool
flex_reflect_plugin/master@conan/stable :
path : /........./flex_reflect_plugin
squarets/master@conan/stable :
path : /........./squarets
flex_squarets_plugin/master@conan/stable :
path : /........./flex_squarets_plugin
flex_typeclass_plugin/master@conan/stable :
path : /........./flex_typeclass_plugin
flex_pimpl_plugin/master@conan/stable :
path : /........./flex_pimpl_plugin
flex_meta_plugin/master@conan/stable :
path : /........./flex_meta_plugin
flex_meta_demo/master@conan/stable :
path : /........./flex_meta_demo
layout : layout_flex
workspace_generator : cmake
root :
- flex_reflect_plugin/master@conan/stable
- squarets/master@conan/stable
- flex_squarets_plugin/master@conan/stable
- flex_typeclass_plugin/master@conan/stable
- flex_pimpl_plugin/master@conan/stable
- flex_meta_plugin/master@conan/stable
- flex_meta_demo/master@conan/stable CMakeLists.txtでadd_dependenciesを使用してください:
mkdir build_flex
cd build_flex
cat << EOF > CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(WorkspaceProject)
include( $ {CMAKE_BINARY_DIR}/conanworkspace.cmake)
list(PREPEND CMAKE_MODULE_PATH " $ {PACKAGE_chromium_base_SRC}/cmake")
list(PREPEND CMAKE_MODULE_PATH " $ {PACKAGE_basis_SRC}/cmake")
list(PREPEND CMAKE_MODULE_PATH " $ {PACKAGE_flex_support_headers_SRC}/cmake")
list(PREPEND CMAKE_MODULE_PATH " $ {PACKAGE_flexlib_SRC}/cmake")
list(PREPEND CMAKE_MODULE_PATH " $ {PACKAGE_flex_reflect_plugin_SRC}/cmake")
list(PREPEND CMAKE_MODULE_PATH " $ {PACKAGE_squarets_SRC}/cmake")
list(PREPEND CMAKE_MODULE_PATH " $ {PACKAGE_flex_squarets_plugin_SRC}/cmake")
list(PREPEND CMAKE_MODULE_PATH " $ {PACKAGE_flex_typeclass_plugin_SRC}/cmake")
list(PREPEND CMAKE_MODULE_PATH " $ {PACKAGE_flex_meta_plugin_SRC}/cmake")
list(PREPEND CMAKE_MODULE_PATH " $ {PACKAGE_flex_meta_demo_SRC}/cmake")
list(PREPEND CMAKE_MODULE_PATH " $ {PACKAGE_flex_pimpl_plugin_SRC}/cmake")
list(PREPEND CMAKE_MODULE_PATH " $ {PACKAGE_flextool_SRC}/cmake")
conan_workspace_subdirectories()
add_dependencies(basis chromium_base-static)
add_dependencies(flexlib basis)
add_dependencies(flextool flexlib basis flex_support_headers)
add_dependencies(flex_reflect_plugin flextool)
add_dependencies(flex_squarets_plugin squarets)
add_dependencies(flex_squarets_plugin flextool)
add_dependencies(flex_pimpl_plugin flextool)
add_dependencies(flex_pimpl_plugin flex_reflect_plugin)
add_dependencies(flex_pimpl_plugin flex_squarets_plugin)
add_dependencies(flex_typeclass_plugin flextool)
add_dependencies(flex_typeclass_plugin flex_squarets_plugin)
add_dependencies(flex_meta_demo flex_meta_plugin)
add_dependencies(flex_meta_demo flex_typeclass_plugin)
add_dependencies(flex_meta_demo flex_pimpl_plugin)
add_dependencies(flex_meta_demo flex_squarets_plugin)
EOF conan workspace installにプラグインオプションを追加します。
# combines options from all projects
conan workspace install
../conanws.yml
--profile=clang
-s build_type=Debug
-s cling_conan:build_type=Release
-s llvm_tools:build_type=Release
-e basis:enable_tests=True
-o openssl:shared=True
-o chromium_base:shared=True
-o chromium_base:use_alloc_shim=True
-o perfetto:is_hermetic_clang=False
-o chromium_tcmalloc:use_alloc_shim=True
-e flextool:enable_tests=True
-e flextool:enable_llvm_tools=True
-o flexlib:shared=False
-o flexlib:enable_clang_from_conan=False
-e flexlib:enable_tests=True
-o flex_reflect_plugin:shared=True
-o flex_reflect_plugin:enable_clang_from_conan=False
-e flex_reflect_plugin:enable_tests=True
-o squarets:shared=False
-o squarets:enable_clang_from_conan=False
-e squarets:enable_tests=True
-o flex_squarets_plugin:shared=False
-o flex_squarets_plugin:enable_clang_from_conan=False
-e flex_squarets_plugin:enable_tests=True
-o flex_meta_plugin:shared=False
-o flex_meta_plugin:enable_clang_from_conan=False
-e flex_meta_plugin:enable_tests=True
-o flex_typeclass_plugin:shared=False
-o flex_typeclass_plugin:enable_clang_from_conan=False
-e flex_typeclass_plugin:enable_tests=True
-o flex_pimpl_plugin:shared=False
-o flex_pimpl_plugin:enable_clang_from_conan=False
-e flex_pimpl_plugin:enable_tests=True
-o flex_meta_demo:enable_clang_from_conan=False
-e flex_meta_demo:enable_tests=Trueワークスペースの構築とテスト:
# NOTE: change `build_type=Debug` to `build_type=Release` in production
export build_type=Debug
# optional
# remove old CMakeCache
(rm CMakeCache.txt || true)
# configure via cmake
cmake -E time cmake .
-DCMAKE_VERBOSE_MAKEFILE=TRUE
-DENABLE_TESTS=TRUE
-DBASE_NEED_GEN_BUILD_DATE=FALSE
-DENABLE_DOCTEST=ON
-DBUILD_SHARED_LIBS=FALSE
-DCONAN_AUTO_INSTALL=OFF
-DCMAKE_BUILD_TYPE= ${build_type}
# remove generated files
# change paths to yours
# rm ~/flex_typeclass_plugin/build/Debug/*generated*
# build code
cmake -E time cmake --build .
--config ${build_type}
-- -j8
# run unit tests for flexlib
cmake -E time cmake --build .
--config ${build_type}
--target flexlib_run_all_tests
# run unit tests for flextool
cmake -E time cmake --build .
--config ${build_type}
--target flextool_run_all_tests
# run unit tests for flex_reflect_plugin
cmake -E time cmake --build .
--config ${build_type}
--target flex_reflect_plugin_run_all_tests
# run unit tests for squarets
cmake -E time cmake --build .
--config ${build_type}
--target squarets_run_all_tests
# run unit tests for flex_squarets_plugin
cmake -E time cmake --build .
--config ${build_type}
--target flex_squarets_plugin_run_all_tests
# run unit tests for flex_squarets_plugin
cmake -E time cmake --build .
--config ${build_type}
--target flex_meta_plugin_run_all_tests
# run unit tests for flex_squarets_plugin
cmake -E time cmake --build .
--config ${build_type}
--target flex_typeclass_plugin_run_all_tests
# run unit tests for flex_squarets_plugin
cmake -E time cmake --build .
--config ${build_type}
--target flex_pimpl_plugin_run_all_tests
# run unit tests for flex_squarets_plugin
cmake -E time cmake --build .
--config ${build_type}
--target flex_meta_demo_run_all_tests -e flextool:enable_llvm_tools=TrueでDebugビルドを使用してください。
CONAN経由でCPPCheckをインストールします。
cd /tmp
git clone -b testing/1.90 https://github.com/bincrafters/conan-cppcheck_installer.git
cd conan-cppcheck_installer
export VERBOSE=1
export CONAN_REVISIONS_ENABLED=1
export CONAN_VERBOSE_TRACEBACK=1
export CONAN_PRINT_RUN_COMMANDS=1
export CONAN_LOGGING_LEVEL=10
# NOTE: change `build_type=Debug` to `build_type=Release` in production
# NOTE: use --build=missing if you got error `ERROR: Missing prebuilt package`
cmake -E time
conan create . conan/stable
-s build_type=Release
# clean build cache
conan remove " * " --build --force使用( -DENABLE_CPPCHECK=ONでcmakeを実行):
# creates local build in separate folder and runs cmake targets
# NOTE: -DCLEAN_OLD="OFF" to keep generated html report
cmake -DCPPCHECK= " ON " -DCLEAN_OLD= " OFF " -P tools/run_tool.cmake # `index.html` must exist
# find $PWD -name index.html「index.html」を開いて結果を確認します。
複数のスクリプトを管理および実行するための単一のコンテキストを提供するデスクトップアプリケーション。
ローカル開発環境のセットアップを簡素化します。これにより、多くのシェル端子を開くことができません。
package.jsonまたはplugin/vue-cli-plugin/ui.jsにカスタムコマンドを追加できます。
# Before: Install Latest Node.js and NPM
# see https://tecadmin.net/install-latest-nodejs-npm-on-ubuntu/
node --version
npm --versionNPM経由でプロジェクトを構築します。
npm installsudo npm install -g @vue/cli
sudo vue ui --dev --port 8061 http://localhost:8061/を開きます。
プロジェクトディレクトリをインポートします。
ビルド/テストなどのTasksを選択してください...
タスクはpackage.jsonで変更される場合があります。
注:タスクにのみpackage.jsonを使用します。コナンは、conanfile.txtというファイルによって制御されます。
便利なリンク:
.gdbinit add 'add-auto-load-safe-pathを使用します。
.gdbinitの詳細については、https://metricpanda.com/tips-for-productive-debugging-with-gdbをお読みください
gdbの詳細については、http://www.yolinux.com/tutorials/gdb-commands.htmlをお読みください
GDBデバッグセッションは、そうであるように自動化できます。
# see https://gist.github.com/williballenthin/8bd6e29ad8504b9cb308039f675ee889
gdb
-ex " run "
-ex " set pagination off "
-ex " bt "
-ex " set confirm off "
-ex " quit "
--args
${APP_EXE}
${APP_CMD_ARGS} -e flextool:enable_llvm_tools=TrueでDebugビルドを使用してください。
詳細については、以下を参照してください。
Valgrindをインストール:
sudo apt install valgrind # Ubuntu, Debian, etc.
# OR
sudo yum install valgrind # RHEL, CentOS, Fedora, etc.注: use_alloc_shim=Falseとenable_valgrind=True (以下を参照)を設定してください。
cmake経由でValgrindを実行します:
export VERBOSE=1
export CONAN_REVISIONS_ENABLED=1
export CONAN_VERBOSE_TRACEBACK=1
export CONAN_PRINT_RUN_COMMANDS=1
export CONAN_LOGGING_LEVEL=10
# NOTE: set `use_alloc_shim=False` and `enable_valgrind=True` for valgrind support
cmake -E time
conan install .
--install-folder local_build_valgrind
-s build_type=Debug
-s cling_conan:build_type=Release
-s llvm_tools:build_type=Release
--profile clang12_compiler
-o flextool:enable_valgrind=True
-e flextool:enable_tests=True
-e flextool:enable_llvm_tools=True
-e abseil:enable_llvm_tools=True
-o chromium_base:enable_valgrind=True
-e chromium_base:enable_llvm_tools=True
-o chromium_base:use_alloc_shim=False
-o perfetto:is_hermetic_clang=False
-o basis:enable_valgrind=True
-e basis:enable_llvm_tools=True
-o flexlib:enable_valgrind=True
-e flexlib:enable_llvm_tools=True
-o flexlib:enable_clang_from_conan=False
-o chromium_tcmalloc:use_alloc_shim=False
--build chromium_base
--build chromium_tcmalloc
--build basis
--build flexlib
cd ~ /flextool
# see section about `conan editable mode`
cd local_build_valgrind
# optional
# remove old CMakeCache
(rm CMakeCache.txt || true)
# remove old build artifacts
rm -rf flextool
rm -rf bin
find . -iname ' *.o ' -exec rm {} ;
find . -iname ' *.a ' -exec rm {} ;
find . -iname ' *.dll ' -exec rm {} ;
find . -iname ' *.lib ' -exec rm {} ;
# NOTE: -DENABLE_VALGRIND=ON
cmake ..
-DCMAKE_VERBOSE_MAKEFILE=TRUE
-DENABLE_VALGRIND=ON
-DENABLE_TESTS=TRUE
-DBASE_NEED_GEN_BUILD_DATE=FALSE
-DENABLE_DOCTEST=ON
-DENABLE_VALGRIND_TESTS=TRUE
-DBUILD_SHARED_LIBS=FALSE
-DCONAN_AUTO_INSTALL=OFF
-DCMAKE_BUILD_TYPE=Debug
# NOTE: to run some tests under valgrind
# use `-DENABLE_VALGRIND_TESTS=TRUE`
cmake -E time cmake --build .
--target flextool-gmock_run_valgrind
# Cmake will print valgrind command that was executed.
# You can copy executed command and add custom command-line arguments:
# --gtest_filter=ToolsSanityTest.DISABLED_ValgrindTest
# --gtest_also_run_disabled_tests
# search for valgrind log file
find $PWD -name * valgrind * .logリークを見つけるために、ログファイルでdefinitely lostためにseachすることができます。
注: cmake/valgrind.cfgにValgrind抑制を追加できます。
注:デバッグフラグを使用してプログラムをコンパイルして、Valgrindの下で実行します。
注: valgrind --tool=helgrindを使用して、潜在的なデッドロックとデータレースを検出します。
注: valgrind --tool=massif --massif-out-file=massif_file --stacks=true使用します。参照:https://kde.org/applications/development/org.kde.massif-visualizer
詳細については、https://stackoverflow.com/a/44989219を参照してください
TODO:Valgrind and Clang 10 https://stackoverflow.com/questions/40509986/valgrind-reporting-mismatched-free-delete-delete
TODO:ValgrindはChromium Base、Fixmeをサポートできない場合があります。 gtest_no_suiteを削除します
-e flextool:enable_llvm_tools=TrueでDebugビルドを使用してください
Clang-Tidyをインストール:
sudo apt-get install clang-tidy # Ubuntu, Debian, etc.
# OR
sudo yum install clang-tidy # RHEL, CentOS, Fedora, etc.使用法( -DENABLE_CLANG_TIDY=ONでcmakeを実行):
# creates local build in separate folder and runs cmake targets
cmake -DCLANG_TIDY= " ON " -DCLEAN_OLD= " ON " -P tools/run_tool.cmake-e flextool:enable_llvm_tools=TrueでDebugビルドを使用してください
詳細については、https://chromium.googleSource.com/chromium/src.git/+/master/docs/clang_static_analyzer.mdおよびhttps://clang-analyzer.llvm.org/scan-build.htmlを参照してください
プログラムCCC-Analyzerは偽のコンパイラのように機能し、コマンドラインの引数をコンパイラに転送し、定期的なコンピレーションとClangを実行して静的分析を実行します。
通常、configureを実行すると、コンパイラへのハードワイヤードパスを持つメイクファイルが生成され、スキャンビルドを介して構成を実行することにより、そのパスがCCC-analyzerに設定されます。
# must exist
ccc-analyzer -v
# must exist
c++-analyzer -v
# must exist
scan-build -v
export VERBOSE=1
export CONAN_REVISIONS_ENABLED=1
export CONAN_VERBOSE_TRACEBACK=1
export CONAN_PRINT_RUN_COMMANDS=1
export CONAN_LOGGING_LEVEL=10
cmake -E time
conan install .
--install-folder local_build_scan_build
-s build_type=Debug
-s cling_conan:build_type=Release
-s llvm_tools:build_type=Release
--profile clang12_compiler
-e flextool:enable_tests=True
-e flextool:enable_llvm_tools=True
cmake -E time
conan source .
--source-folder local_build_scan_build
--install-folder local_build_scan_build
# see section about `conan editable mode`
cd local_build_scan_build
# NOTE: change `build_type=Debug` to `build_type=Release` in production
export build_type=Debug
# optional
# remove old CMakeCache
(rm CMakeCache.txt || true)
# NOTE: changed CMAKE_C_COMPILER to ccc-analyzer (!!!)
# configure via cmake
scan-build
--use-cc=clang-10
--use-c++=clang++-10
-o ./scanbuildout/
cmake ..
-DCMAKE_VERBOSE_MAKEFILE=TRUE
-DCMAKE_C_COMPILER=ccc-analyzer
-DCMAKE_CXX_COMPILER=c++-analyzer
-DENABLE_TESTS=FALSE
-DBASE_NEED_GEN_BUILD_DATE=FALSE
-DENABLE_DOCTEST=OFF
-DBUILD_SHARED_LIBS=FALSE
-DCONAN_AUTO_INSTALL=OFF
-DCMAKE_BUILD_TYPE= ${build_type}
# remove old build artifacts
(make clean || true)
rm -rf bin
# NOTE: requires project configured in debug build
# disable other static analyzers
# run from build directory
scan-build
-maxloop 8
-enable-checker alpha.security.taint.TaintPropagation
-enable-checker alpha.core.BoolAssignment
-enable-checker alpha.core.CastSize
-enable-checker alpha.core.DynamicTypeChecker
-enable-checker alpha.core.FixedAddr
-enable-checker alpha.core.IdenticalExpr
-enable-checker alpha.core.PointerArithm
-enable-checker alpha.core.PointerSub
-enable-checker alpha.core.SizeofPtr
-enable-checker alpha.core.TestAfterDivZero
-enable-checker alpha.deadcode.UnreachableCode
-enable-checker alpha.security.ArrayBoundV2
-enable-checker alpha.security.MallocOverflow
-enable-checker alpha.security.ReturnPtrRange
-enable-checker alpha.unix.PthreadLock
-enable-checker alpha.unix.Stream
-enable-checker alpha.unix.cstring.BufferOverlap
-enable-checker alpha.unix.cstring.NotNullTerminated
-enable-checker alpha.unix.cstring.OutOfBounds
-enable-checker nullability.NullableDereferenced
-enable-checker optin.performance.Padding
-enable-checker security.insecureAPI.rand
-enable-checker security.insecureAPI.strcpy
--use-cc=clang-10
--use-c++=clang++-10
-o ./scanbuildout/
make
-j8結果として生じるscanbuildout/...../index.htmlファイルを開きます
-e flextool:enable_llvm_tools=TrueでDebugビルドを使用してください
詳細については、https://github.com/myint/cppcleanを参照してください
インストール:
pip install --index-url=https://pypi.python.org/simple/ --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --upgrade cppclean使用( -DENABLE_CPPCLEAN=ONでcmakeを実行):
# creates local build in separate folder and runs cmake targets
cmake -DCPPCLEAN= " ON " -DCLEAN_OLD= " ON " -P tools/run_tool.cmake注:cppcleanはUTF-8 without BOMファイルエンコーディングを必要とします(ascii)
-e flextool:enable_llvm_tools=TrueでDebugビルドを使用してください
include-what-you-use(iwyu)は、最適化を目的としたプロジェクトです。
必要なヘッダーを計算し、必要に応じて追加 /削除を削除します。
詳細については、https://include-what-you-use.org/を参照してください。
使用( -DENABLE_IWYU=ONでcmakeを実行):
# creates local build in separate folder and runs cmake targets
cmake -DIWYU= " ON " -DCLEAN_OLD= " ON " -P tools/run_tool.cmake CodeStyle:使用// IWYU pragma: associated 。
注:Iwyu Pragmas:https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/iwyupragmas.mdについて読んでください
注:「bits/」または「/details/*」を使用しないでください。
詳細については、以下を参照してください。
-DUSE_CCACHE=ONを使用します
gcc -v
export CC=gcc
export CXX=g++
# NOTE: -DUSE_CCACHE=ON
cmake ..
-DCMAKE_VERBOSE_MAKEFILE=TRUE
-DUSE_CCACHE=ON
-DENABLE_TESTS=FALSE
-DBASE_NEED_GEN_BUILD_DATE=FALSE
-DENABLE_DOCTEST=OFF
-DBUILD_SHARED_LIBS=FALSE
-DCONAN_AUTO_INSTALL=OFF
-DCMAKE_BUILD_TYPE=Debug詳細については、https://www.virag.si/2015/07/use-ccache-with-cmake-for-faster-compilation/を参照してください。
ccacheを最大限に活用するには、次のようなものを入れます: ~/.ccache/ccache.conf :
max_size = 50.0G # or whatever cache size you prefer; default is 5G; 0 means unlimited
base_dir = /home/yourname # or wherever you keep your source files注:ccacheが異なるリポジトリ /パスで同じファイルのキャッシュコンパイルを共有するには、 base_dir必要です。 base_dirの下のパスに対してのみこれを行います。したがって、このオプションは、Git Worktreeを使用したCCacheを効果的に使用するために必要です(以下で説明)。
base_dir "/"に設定したり、システムヘッダーを含む場所に設定してはなりません(CCACHEドキュメントによると)。
インストール:
sudo apt-get install ccache
# On OS X use homebrew:
# brew install ccache
ccache --version -DUSE_LD_GOLD=ON使用します
gcc -v
export CC=gcc
export CXX=g++
# NOTE: -DUSE_LD_GOLD=ON
cmake ..
-DCMAKE_VERBOSE_MAKEFILE=TRUE
-DUSE_LD_GOLD=ON
-DENABLE_TESTS=FALSE
-DBASE_NEED_GEN_BUILD_DATE=FALSE
-DENABLE_DOCTEST=OFF
-DBUILD_SHARED_LIBS=FALSE
-DCONAN_AUTO_INSTALL=OFF
-DCMAKE_BUILD_TYPE=Debug詳細については、https://cristianadam.eu/20170709/speeding-up-cmake/を参照してください。
注:デフォルトでねじれないゴールド、「-Enable-Threads」で構成
注:デフォルトでスレッドが付けられたLLDは、金よりも速い場合があります
-e flextool:enable_llvm_tools=TrueでDebugビルドを使用してください
詳細については、https://oclint-docs.readthedocs.io/en/stable/devel/codingstandards.htmlを参照してください
インストール:
cd ~
wget --no-check-certificate https://github.com/oclint/oclint/releases/download/v0.13.1/oclint-0.13.1-x86_64-linux-4.4.0-112-generic.tar.gz
# mirror 1: http://github.strcpy.cn/oclint/oclint/releases/download/v0.13.1/oclint-0.13.1-x86_64-linux-4.4.0-112-generic.tar.gz
# mirror 2: http://archives.oclint.org/releases/0.8/oclint-0.8.1-x86_64-linux-3.13.0-35-generic.tar.gz
tar -xzvf oclint-0.13.1-x86_64-linux-4.4.0-112-generic.tar.gz
rm -rf oclint-0.13.1-x86_64-linux-4.4.0-112-generic.tar.gz
export OCLINT_HOME= ~ /oclint-0.13.1
export PATH= $OCLINT_HOME /bin: $PATH
oclint -version使用( -DENABLE_OCLINT=ONでcmakeを実行):
# NOTE: -DCLEAN_OLD="OFF" to keep generated html report
# creates local build in separate folder and runs cmake targets
cmake -DOCLINT= " ON " -DCLEAN_OLD= " OFF " -P tools/run_tool.cmake # `report.html` must exist
# find $PWD -name report.htmlOpen Report.html
oclintチュートリアル:http://docs.oclint.org/en/stable/intro/tutorial.htmlを参照してください
oclintルールのリスト:https://oclint-docs.readthedocs.io/en/stable/rules/
注:oclint警告http://docs.oclint.org/en/stable/hohhowto/suppress.html#oclint-commentを抑制できます
詳細については、https://clang.llvm.org/docs/clangformat.htmlを参照してください
使用( -DENABLE_CLANG_FORMAT=ONでcmakeを実行):
# creates local build in separate folder and runs cmake targets
cmake -DCLANG_FORMAT= " ON " -DCLEAN_OLD= " ON " -P tools/run_tool.cmake .clang-formatファイルを使用します。詳細については、https://clang.llvm.org/docs/clangformatstyleoptions.htmlを参照してください
注: DisableFormatを使用するため、Clang-formatはSortIncludesに基づいて順序のみを変更します。
残念ながら、 clang-format十分に構成できないため、含まれる分類にのみ使用できます。参照:https://stackoverflow.com/a/32191189
Uncrustify Bacuase Clang-formatを使用し、Astyleは多くのオプションをサポートしていません。
詳細については、https://patrickhenson.com/2018/06/07/uncrustify-configuration.htmlを参照してください
インストール:
cd ~
git clone https://github.com/uncrustify/uncrustify.git
cd uncrustify
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build .
export UNCRUSTIFY_HOME= ~ /uncrustify/build
export PATH= $UNCRUSTIFY_HOME : $PATH
# OR sudo make install
uncrustify --version使用( -DENABLE_UNCRUSTIFY=ONでcmakeを実行):
# creates local build in separate folder and runs cmake targets
cmake -DUNCRUSTIFY= " ON " -DCLEAN_OLD= " ON " -P tools/run_tool.cmake uncrustify.cfgファイルを使用します。詳細については、https://patrickhenson.com/2018/06/07/uncrustify-configuration.htmlを参照してください
利用可能なすべてのオプションのリストを取得するには、使用してください。
uncrustify --show-configUncrustifyには、構成可能なオプションがたくさんあります。おそらく、Universal Indent GUI(Konstantinの返信)が必要です。
/* *INDENT-OFF* */ and /* *INDENT-ON* */を含むコメントを使用して、ソースファイルの部分の処理を無効にします。
uncrustify.cfgのdisable_processing_cmt参照してください:
# Specify the marker used in comments to disable processing of part of the
# file.
# The comment should be used alone in one line.
#
# Default: *INDENT-OFF*
disable_processing_cmt = " *INDENT-OFF* " # string
# Specify the marker used in comments to (re)enable processing in a file.
# The comment should be used alone in one line.
#
# Default: *INDENT-ON*
enable_processing_cmt = " *INDENT-ON* " # string uncrustify IDEと統合できます。
https://github.com/blockspacer/llvm_9_installer#how-to-use-with-sanitizersを参照してください
必要なのは、 enable_llvm_tools=True 、 compile_with_llvm_tools=True 、およびllvm_tools:build_type=Release :llvm_tools:
-s llvm_tools:build_type=Release
-e flextool:enable_llvm_tools=True
-e flextool:compile_with_llvm_tools=True
-o llvm_tools:include_what_you_use=True
...enable_llvm_tools 、ConanからClang 10をインストールしますcompile_with_llvm_toolsセットcmake変数をCONANからClang 10を使用するために必要な変数を設定しますconan install実行するか、 conan create :
# OR create conan profile https://docs.conan.io/en/latest/reference/profiles.html
-s compiler=clang
-s compiler.version=10
-s compiler.libcxx=libc++注:コンパイラの変更では、すべてのDEPの再構築が必要になる場合があります( --build=missing )。
現地ビルドの場合の例:
export CC= $( find ~ /.conan/data/llvm_tools/master/conan/stable/package/ -path " *bin/clang " | head -n 1 )
export CXX= $( find ~ /.conan/data/llvm_tools/master/conan/stable/package/ -path " *bin/clang++ " | head -n 1 )
export VERBOSE=1
export CONAN_REVISIONS_ENABLED=1
export CONAN_VERBOSE_TRACEBACK=1
export CONAN_PRINT_RUN_COMMANDS=1
export CONAN_LOGGING_LEVEL=10
# NOTE: NO `--profile` argument cause we use `CXX` env. var
# NOTE: you may want to re-build `cling_conan` with clang 10
cmake -E time
conan install .
--install-folder local_build_clang_10
-s build_type=Debug
-s cling_conan:build_type=Release
-s llvm_tools:build_type=Release
--build missing
--build cascade
-s cling_conan:compiler=clang
-s cling_conan:compiler.version=10
-s cling_conan:compiler.libcxx=libstdc++11
-o llvm_tools:include_what_you_use=True
-s llvm_tools:compiler=clang
-s llvm_tools:compiler.version=10
-s llvm_tools:compiler.libcxx=libstdc++11
-e flextool:enable_tests=True
-e flextool:enable_llvm_tools=True
-e flextool:compile_with_llvm_tools=True
-e boost:enable_llvm_tools=True
-e boost:compile_with_llvm_tools=True
-s compiler=clang
-s compiler.version=10
-s compiler.libcxx=libc++
cmake -E time
conan source .
--source-folder local_build_clang_10
--install-folder local_build_clang_10
# remove old CMakeCache
(rm local_build_clang_10/CMakeCache.txt || true)
# see section about `conan editable mode`
conan build .
--build-folder local_build_clang_10
--source-folder local_build_clang_10
--install-folder local_build_clang_10チェックを実行します:
# check that `libcpp` symbol exists
nm -an EXECUTABLE_PATH | grep libcpp
# list linked dynamic libs
ldd EXECUTABLE_PATH MCSS_ROOT_DIR_FOR_DOCS 、以下のようなm.cssソースを指す必要があります。
cd ~
git clone https://github.com/mosra/m.css.git
pip3 install jinja2 Pygments
sudo apt install
texlive-base
texlive-latex-extra
texlive-fonts-extra
texlive-fonts-recommended
sudo apt-get install doxygen
sudo apt install python3-pip
# /usr/bin/python must point to python3
/usr/bin/python --version
# NOTE: switch to python3 for doxygen or use -DPYTHON_EXECUTABLE=/usr/bin/python3
alias python= ' /usr/bin/python3 '
# You may need sudo here
pip3 install jinja2 Pygments
sudo apt install
texlive-base
texlive-latex-extra
texlive-fonts-extra
texlive-fonts-recommended '-target doxydoc'と-DBUILD_DOXY_DOC=ONでcmakeビルドを使用します
cd ~ /flextool
# see section about `conan editable mode`
cd local_build_clang_10
# optional
# remove old CMakeCache
(rm CMakeCache.txt || true)
# remove old build artifacts
rm -rf flextool
rm -rf bin
find . -iname ' *.o ' -exec rm {} ;
find . -iname ' *.a ' -exec rm {} ;
find . -iname ' *.dll ' -exec rm {} ;
find . -iname ' *.lib ' -exec rm {} ;
# remove old build docs
rm -rf doc-mcss
rm -rf docs
cmake -E make_directory " doc-mcss "
# NOTE: you can change python version like so: -DPYTHON_EXECUTABLE=/usr/bin/python3
cmake ..
-DCMAKE_VERBOSE_MAKEFILE=TRUE
-DMCSS_ROOT_DIR_FOR_DOCS= $HOME /m.css
-DPYTHON_EXECUTABLE=/usr/bin/python3
-DENABLE_TESTS=TRUE
-DBASE_NEED_GEN_BUILD_DATE=FALSE
-DENABLE_DOCTEST=ON
-DBUILD_DOXY_DOC=ON
-DBUILD_SHARED_LIBS=FALSE
-DCONAN_AUTO_INSTALL=OFF
-DCMAKE_BUILD_TYPE=Debug
-DDOXY_ROOT_DIR= $PWD /doc-mcss
-DDOXY_DOC_COMMON_IMG_PATH= $PWD /..
-DPROJECT_SOURCES_DIR_FOR_DOCS= $PWD /../src
cmake -E time cmake --build .
--target doxyDoc_notheme
cmake -E time cmake --build .
--target doxyDoc
# Use to find index.html
find $PWD -name * .htmlDoxydoc/html/index.htmlを開きます
注:Docs/namespaces.doxのドキュメント名空間
注:ドキュメントのないファイル、ディレクトリ、シンボルは出力にまったく存在しません
使用済みコメントスタイル:
/ **
* @brief Path utils
*
* Example usage:
*
* @code{.cpp}
* const ::fs::path workdir = storage::getThisBinaryDirectoryPath ();
* @endcode
** /見る:
詳細については、https://afl-1.readthedocs.io/en/latest/index.htmlを参照してください
注:github.com/google/aflまたはaflplus.plusをlcamt lcamtuf.coredump.cx/aflから更新しないこと
ファジングは、ブラックボックスソフトウェアテスト手法です。
ファジングは、自動化された方法で奇形/半変形のデータインジェクションを使用した実装バグを見つけることにあります。
Fuzzerは、入力を変更しようとして、プログラムコードのできるだけ多くの行に到達できるようにします。
したがって、ファジングにより、通常の使用法で到達するのが難しいコードパスにある脆弱性の発見が可能になります。
以下のコマンドを使用してソースコードをインストール +コンパイルします。
# optional
# sudo apt-get update
# optional
# sudo apt-get -y install autoconf automake bison build-essential
ca-certificates llvm-dev libtool libtool-bin
libglib2.0-dev make nasm wget
# Tested with clang 10 and gcc 7
sudo apt-get -y install clang-10 g++-7 gcc-7
export CXX=g++-7
export CC=gcc-7
export PATH=/usr/bin/: $PATH
$CC -v
# llvm-config binary that coresponds to the same clang you are using to compile
export LLVM_CONFIG=/usr/bin/llvm-config-10
$LLVM_CONFIG --cxxflags
cd ~
git clone -b v2.56b https://github.com/google/AFL.git --recursive
# NOTE: original AFL not updated since November 2017,
# so prefer `google/AFL.git` to `lcamtuf.coredump.cx/afl`
# wget http://lcamtuf.coredump.cx/afl/releases/afl-latest.tgz
# tar -xf afl-latest.tgz
# rm afl-latest.tgz
# cd afl*
cd AFL
make
# build llvm using the sample compiler as afl code uses
# see https://groups.google.com/forum/#!topic/afl-users/1WqZpGXvYY0
make
-C llvm_mode
LLVM_CONFIG= $LLVM_CONFIG
CC=clang-10
CXX=clang++-10
#
# optional
# cd qemu_mode
# ./build_qemu_support.sh
# cd ..
#
make
-C libdislocator
make
-C libtokencap
sudo make install
# OR add to PATH via export PATH=$PATH:...
# do not forget to reset CC and LLVM_CONFIG
unset CXX
unset CC
unset LLVM_CONFIG AFLコンパイラを使用してコードをコンパイルします: -DCMAKE_C_COMPILER=afl-clang-fast 、 -DCMAKE_CXX_COMPILER=afl-clang-fast++ 、および-DCMAKE_LINKER=afl-clang-fast 。
バイナリがAFLコンパイラを使用しているかどうかを確認するには: nm BINARY_PATH | grep afl
いくつかのサニタイザーとデバッグ情報を使用してアプリケーションを構築するには:( -DENABLE_ASAN=ONなど):
注:アドレス消毒剤を使用する際に考慮すべきことがいくつかあります。 Asanがメモリアクセス違反を見つけたとしても、アプリケーションが自動的にクラッシュしません。これは、自動化されたファジングツールを使用する場合の問題です。これは、通常、返品コードをチェックしてセグフォルトを検出しようとするためです。ただし、ファジング前に環境変数ASAN_OPTIONSでエラーが発生した場合export ASAN_OPTIONS='abort_on_error=1' ASANにソフトウェアをクラッシュさせることができます。
注:カスタムメモリ割り当て関数を無効にします。これにより、メモリアクセスバグを非表示にし、メモリアクセスエラーの検出を防ぐことができます。
# see https://afl-1.readthedocs.io/en/latest/instrumenting.html
# Setting AFL_HARDEN automatically adds code hardening options
# when invoking the downstream compiler.
# This includes -D_FORTIFY_SOURCE=2 and -fstack-protector-all.
# NOTE: _FORTIFY_SOURCE not compatible with ASAN
# export AFL_HARDEN=1
# see https://aflplus.plus/docs/env_variables/
export AFL_EXIT_WHEN_DONE=1
# By default, the wrapper appends -O3 to optimize builds.
export AFL_DONT_OPTIMIZE=1
# or AFL_USE_MSAN, etc.
# READ https://aflplus.plus/docs/notes_for_asan/
NOTE: if you run several slaves only one should run the
# target compiled with ASAN (and UBSAN, CFISAN),
# the others should run the target with no sanitizers compiled in.
export AFL_USE_UBSAN=1
export AFL_USE_ASAN=1
# AFL_PRELOAD causes AFL to set LD_PRELOAD for the target binary
# without disrupting the afl-fuzz process itself.
# This is useful, among other things, for bootstrapping libdislocator.so.
# see __AFL_LOOP
# export AFL_PERSISTENT=1
# make sure you compile app with `-fsanitize=address` or `-fsanitize=memory` etc.注: AFL_DONT_OPTIMIZE=1使用します。読む:http://moyix.blogspot.com/2016/07/fuzzing-with-afl-is-an-art.html
詳細については、ASANを使用してASANを使用してください
プログラムをファジングする前に、core_patternをアレンジするためにルートユーザーに切り替える必要がある場合があります。ルートとしてログインし、次のコマンドを入力します。
# see https://afl-1.readthedocs.io/en/latest/tips.html#check-os-configuration
sudo su
# disable core dumps and CPU frequency scaling on your system (AFL will warn you if you should do this)
echo core > /proc/sys/kernel/core_pattern
# afl-fuzz will usually complain that you should change your `CPUFREQ` settings to performance because the automatic frequency scaling by the Linux kernel doesn't work well with afl.
echo performance | tee /sys/devices/system/cpu/cpu * /cpufreq/scaling_governor
exit注:ルートアクセスでファッツァーを実行しないでください
注:ファッツァー用の堅実な環境を取得します。低く構成されたハイパーバイザーでファザーを実行しないでください。
afl-fuzz AFLの実行に使用されます。実際の構文は次のとおりです。
# see https://afl-1.readthedocs.io/en/latest/fuzzing.html#fuzzing-binaries
# -i is a directory of files to use as fuzz input "seeds"
# -o is a directory to write the results (including inputs that provoke crashes or hangs)
# -m is the memory allowed to use. Example: -m500
# You can use -m none to disable memory limit
# -t is the maximum time that a run is allowed to take before being declared a "hang"
# Timeout of 10 seconds: -t 10000
# @@ is fuzzer input file name
# if you skip @@ it will pass the fuzzed file on the standard input
AFL_PERSISTENT=1 afl-fuzz -i [TESTCASE DIR] -o [RESULT_DIR] [TARGET_BINARY] [BINARY_PARAMS] @@
# Example 1: runs `tar` with arguments `xfJ @@ -C fuzz-garbage/ --force-local`
# where @@ is fuzzer input file name
./afl-1.56b/afl-fuzz -i fuzz-input/ -o fuzz-state/ -t 10000 ~ /tar-1.28/src/tar xfJ @@ -C fuzz-garbage/ --force-local
# Example 2: server is dual core, so we can run one AFL instance per core
AFL_PERSISTENT=1 afl-fuzz -i inputs -o multi_sync -M master ./fuzz_capstone
# In another terminal
AFL_PERSISTENT=1 afl-fuzz -i inputs -o multi_sync -S slave1 ./fuzz_capstoneAFLステータス画面を理解するには、https://afl-1.readthedocs.io/en/latest/user_guide.html#status-screenをお読みください
注: total paths 1にとどまる場合、おそらく何か間違ったものを設定しています。
注: -m none好む。 AddressSanitizerを使用しています。これにより、シャドウメモリ用の多くのページがマッピングされるため、メモリの制限を削除して稼働させる必要があります。
注: -m noneで、ファズ化されたソフトウェアは、ファズされたサンプルのために実際に多くのメモリを割り当てて使用しようとする可能性があります。これにより、システムがランダムにクラッシュする可能性があります。そうしている間、重要な仕事をしてはいけません。
注: ASAN_OPTIONS=hard_rss_limit_mb=2000を試して、 -m noneを避けることができます。参照:https://countuponsecurity.com/category/fuzzing/
afl-fuzzを使用して実行されるカスタムバイナリを書くことができます。そのようにテストしたい関数をラップするかもしれません:
// harness is simply a C program that makes use of certain methods from
// a library, allowing you to indirectly fuzz it
# include < cstdio >
# include < cstdlib >
# include < string >
# include < iostream >
# include < ifstream >
int main ( int argc, char *argv[]) {
{
// init resources here
if (argc > 1 ) {
std::ifstream fin;
fin. open (argv[ 1 ]);
parse (fin); // custom logic
} else {
// / note requires AFL_PERSISTENT=1
// __AFL_LOOP is the way that we have to tell AFL
// that we want persistent mode.
// Each fuzzing iteration,
// instead of to fork and re-execute the target with a different input,
// is just an execution of this loop.
// Force AFL to run 1000 times,
// with 1000 different inputs fed to the library.
// After that, the process is restarted by AFL.
// This ensures we regularly replace the process to avoid memory leaks.
// see https://toastedcornflakes.github.io/articles/fuzzing_capstone_with_afl.html
while ( __AFL_LOOP ( 1000 )) {
parse (std::cin); // custom logic
}
}
// free resources here
return 0 ;
}注:__afl_loop()により、AFLは、テストするすべての新しいテストケースの新しいプロセスを起動するのではなく、メモリウィザードリーを介してプロセスでバイナリのファジングを実行できます。 AFL_PERSISTENT=1が必要です。
デフォルトでは、AFLは、異なる入力をテストするたびにプロセスを分散します。 AFLを制御して、すべてのテストサンプルでプログラム状態を戻すのではなく、プログラムの単一のインスタンスで複数のファズケースを実行できます。これにより、カーネル空間で費やされる時間が短縮され、ファジング速度が向上します。これはAFL_PERSISTENTモードと呼ばれます。テストハーネスに__afl_loop(1000)マクロを含めることで、それを行うことができます。
注:__afl_initに興味があるかもしれません。ご覧
提供されたテストケースに基づいて最大コード実行パスを生成するため、ファッツァーを数時間または数日間実行します。
AFL統計画面の全体的な結果のin the section ctrl+c' observing合計パスand UNIQクラッシュの発行を停止します。
プログラムバイナリで見つかったすべての定数と文字列を取得し、それらを辞書に追加する辞書を作成します。スクリプトコードについては、http://moyix.blogspot.com/2016/07/fuzzing-with-afl-is-an-art.htmlを参照してください
#! /bin/bash
# see http://moyix.blogspot.com/2016/07/fuzzing-with-afl-is-an-art.html
objdump -d " ${1} " | grep -Eo ' $0x[0-9a-f]+ ' | cut -c 2- | sort -u | while read const ; do echo $const | python -c ' import sys, struct; sys.stdout.write("".join(struct.pack("<I" if len(l) <= 11 else "<Q", int(l,0)) for l in sys.stdin.readlines())) ' > testcases/ $const ; done
i=0 ; strings " ${1} " | while read line ; do echo -n " $line " > testcases/string_ ${i} ; i=$[ $i + 1 ] ; done辞書/readme.dictionaryで説明されている2つの形式のいずれかで辞書を作成し、コマンドラインの-xオプションを介してファッツァーを指す必要があります。読む:https://afl-1.readthedocs.io/en/latest/fuzzing.html#fuzzing-binariesおよびhttps://github.com/mirrorer/afl/blob/master/dictionaries/readme.dictionaries
libtokencapを使用して辞書を作成することもできます。参照:https://github.com/mirrorer/afl/blob/master/libtokencap/readme.tokencap
作成したresultsフォルダーにクラッシュを引き起こすテストケースを見つけることができます。フォルダーのresultsに移動すると、生成されるフォルダーはほとんどありません。
注:入力データファイルを小さく保ちます。 1 kb未満が理想的です。
afl-cminを使用して、入力データファイルの数を最小限に抑えます。
afl-tminを使用して、各入力データファイルを最小限に抑えます(取得したコードパスに影響しないバイトを削除します)。
afl-ptminを使用して、 afl-tminを並行して実行します。詳細については、https://foxglovesecurity.com/2016/03/15/fuzzing-workflows-a-fuzz-job-from-start-to-finish/
見つかったクラッシュを再現するには、 crashwalk (GDBプラグインです)を使用できます。https://ritcsec.wordpress.com/2018/05/10/vulnerability-discovery-by-fuzzing/
apt-get install gdb golang
mkdir src
cd src
git clone https://github.com/jfoote/exploitable.git
cd && mkdir go
export GOPATH= ~ /go
# crashwalk installed in $GOPATH/bin/
go get -u github.com/bnagy/crashwalk/cmd/...
# USAGE
~ /go/bin/cwtriage -root syncdir/fuzzer1/crashes/ -match id -- ~ /parse @@AFLファズによって見つかったクラッシュを再現できない場合、最も可能性の高い原因は、ツールで使用されているのと同じメモリ制限を設定していないことです。読む:https://afl-1.readthedocs.io/en/latest/fuzzing.html#fuzzing-binaries
注: afl-covを使用して、バイナリで利用可能なコードパスをどの程度行使しているかを定量化できます。詳細については、https://foxglovesecurity.com/2016/03/15/fuzzing-workflows-a-fuzz-job-from-start-to-finish/
注:AFL作業ディレクトリをRAMディスクに置くと、追加の速度を獲得し、同時にディスクを摩耗させない可能性があります。詳細については、https://bananamafia.dev/post/gb-fuzz/を参照してください。
# Fuzzing involves billions of reads and writes to the filesystem (!!!)
# Use RAMdisks for input since, we don't want to destroy harddrives
# Make a 1GB ramdisk file from which AFL can read input
sudo mkdir -p /mnt/inputfiles
sudo chown -R $USER : $( id -gn $USER ) /mnt/inputfiles
sudo mount -t tmpfs -o size=1024M tmpfs /mnt/inputfiles/注: -fvisibility-inlines-hiddenフラグは、AFLの計装を破る可能性があります
AFLはexperimental/crash_triage/triage_crashes.shのクラッシュ探査スクリプトを提供します
実行すると、トリアージスクリプトは/out/crashesディレクトリの各クラッシュファイルを循環し、結果のクラッシュデータを画面に印刷します。
triage_crashes usage: ./triage_crashes.sh ~/targets/out/ ~/targets/target-app/target-app_binary詳細については、https://research.aurainfosec.io/hunting-for-bugs-101/を参照してください。
注:AFL付き機器実際に、実際に1つずつストレステストしたいライブラリだけです。プログラムは、実際にファズしたくない機能に対して、システム全体の非文書化ライブラリを使用させます。
注: -C経由でcrash exploration modeを有効にすることができます。参照:https://lcamtuf.blogspot.com/2014/11/afl-fuzz-crash-exploration-mode.html
注:AFLは、信号(Sigsegv、Sigabrtなど)のために死にかけている最初の生成プロセスをチェックすることにより、障害を検出します。これらの信号にカスタムハンドラーをインストールするプログラムは、関連するコードをコメントアウトする必要がある場合があります。
詳細については、以下を参照してください。
LibfuzzerはLLVMコンパイラインフラストラクチャプロジェクトの一部であり、Clangコンパイラが組み込まれています。
その後、Libfuzzerは、リンク段階で-fsanitize=fuzzerを渡すことにより、目的のドライバーにリンクできます。
注: -fsanitize=fuzzerツァーリンク。
注:ほとんどの場合、LibfuzzerとAddressSanitizer(ASAN)、未定義のBehaviorSanitizer(UBSAN)、またはその両方を組み合わせることができます。 MemorySanitizer(MSAN)で構築することもできますが、サポートは実験的です: -fsanitize=undefined,address,fuzzer 。
実行可能ファイルは、次の関数を繰り返し呼び出します。
extern " C " int LLVMFuzzerTestOneInput ( const uint8_t *Data, size_t Size ) {
// DoStuffWithYourAPI(Data, Size);
return 0 ;
} -fsanitize=address,fuzzer使用します。消毒剤(住所、メモリ、スレッドなど)を変更できることに注意してください。
注:ターゲットにメモリが漏れていると思われる場合は-runs=Nまたは-max_total_time=Nを使用してLibfuzzerを実行する必要があります。ターゲットに大規模な漏れがある場合、最終的にRAMが不足します。 OOMの死からマシンを保護するには、使用することができます: ASAN_OPTIONS=hard_rss_limit_mb=2000 (addresssanitizerを使用)。
Libfuzzerにはシードコーパスが必要です。詳細については、https://github.com/google/fuzzing/blob/master/tutorial/libfuzzortutorial.mdを参照してください
詳細については、以下を参照してください。
Clangはスレッドの安全アノテーション(Guarded_by)をサポートしています
-Wthread-safety-analysis有効にしますbase/thread_annotations.h https://github.com/chromium/chromium/blob/master/base/thread_annotations.hを使用してください。詳細については、以下を参照してください。Clang Fas Sanitizersのファーストクラスのサポート。ドキュメントのMSAN、ASAN、TSANなどの詳細を参照してください。
Clangは生涯プロファイルでビルドできます:
-Wlifetimeを有効にしてください。すべてのオープンソースコンポーネントは、関連するオープンソースライセンスの下で使用されます。
使用済みオープンソースコンポーネント:
ライセンスファイルを参照してください
MITライセンス
ライセンスの完全な内容については、ライセンスを参照してください。
Google Chromiumプロジェクトに基づくオープンソースプロジェクト。
これは公式のGoogle製品ではありません。
Portions Copyright(C)Google Inc.
ライセンスファイルを参照してください。