Hacking:Tools: Difference between revisions
m phrasing |
m Formatting |
||
Line 5: | Line 5: | ||
Please learn Git and workflow guidelines: |
Please learn Git and workflow guidelines: |
||
# Basic Git: https://zaiste.net/git_for_busy_people/ |
|||
# The Git Flow method: https://datasift.github.io/gitflow/IntroducingGitFlow.html/ |
|||
# Using semantic commit messages: https://seesparkbox.com/foundry/semantic_commit_messages/ |
|||
== Canonical/Ubuntu Launchpad and Bazaar == |
== Canonical/Ubuntu Launchpad and Bazaar == |
Revision as of 03:40, 12 August 2018
Git
The Seamly2D code repository is on Github: https://github.com/FashionFreedom/Seamly2D
Please learn Git and workflow guidelines:
- Basic Git: https://zaiste.net/git_for_busy_people/
- The Git Flow method: https://datasift.github.io/gitflow/IntroducingGitFlow.html/
- Using semantic commit messages: https://seesparkbox.com/foundry/semantic_commit_messages/
Canonical/Ubuntu Launchpad and Bazaar
Launchpad mirrors the Seamly2D git repo here: https://launchpad.net/~susan-spencer/+archive/ubuntu/seamly2d
Qt Creator
When you use Qt you have two IDE to choose: Qt Creator and Visual Studio.
from the official website.
For effective use of Qt Creator you will need know some stuff.
- Qt Creator supports Git so creating and deleting files better to do from the IDE. Be sure to to choose appropriate .pri file.
- Qt Creator's file wizard allow you to select correct file where it add files.
- Keyboard Shortcuts.
- Refactoring.
- Specifying Code Style Settings. Seamly2D's code style file for Qt Creator you can find in <root>/share directory.
- Set path to License template. Tools->Options->C++->File Naming. Example of license template for project you can find in <root>/share directory. Move it to another directory outside of the project directory and then change name of an author.
- Set max length of source code line equal 120 characters. Tools->Options->Text Editor->Display.
- Compile faster. For this use -j key for make. Projects->Build Steps->Make add -jX - where X number of cpu in your system.
- Don't forget Qt Creator supports two release modes: Release and Debug. Project will be compile with different keys in different modes. Qt team recommended developing to do in debug mode. Also debugging works only in debug mode. Plus Qt will show additional warning information if something happened.
See Hacking:Tools:QtCreator:Ubuntu for description of installing and configuring Qt on 64-bit Ubuntu 14.04.
See Hacking:Tools:QtCreator:Windows10 for description of installing and configuring Qt on 64-bit Windows 10.
Address Sanitizer
See original article Using gcc’s 4.8.0 Address Sanitizer with Qt.
One of the cool new features since release of gcc 4.8 is the built in “Address Sanitizer”: a memory error detector for C/C++ that will tell you instantly when you e.g. access already deleted memory. This is actually a Google project from Clang/LLVM.
How does it work?
It basically overwrites malloc and free, and does check the memory before every access. Apparently it does that in a very efficient manner, since the slow down is only about 2x compared to uninstrumented execution! This allow us more effective seek bugs.
Be warned though that it only works so far on Linux and Mac.
How to enable it?
Since it is part of the compiler suite enabling it is easy: just add -fsanitize=address -fno-omit-frame-pointer to the compiler calls, and -fsanitize=address to the linker calls.
All you need it set QMAKE_CXXFLAGS, QMAKE_CFLAGS, and QMAKE_LFLAGS manually in each subproject:
QMAKE_CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer
QMAKE_CFLAGS += -fsanitize=address -fno-omit-frame-pointer
QMAKE_LFLAGS += -fsanitize=address
In debug mode Seamly2D already use this flags, so no need set them manually.
How to use it?
Just run Seamly2D! If you happen to hit a memory issue program will abort immediately, and show you a stack trace with module names and addresses. You will need a separate tool called asan_symbolize.py to get the symbols, and then maybe c++filt to de-mangle the C++ symbols.
asan_symbolize.py also awailible in Seamly2D/scripts/asan_symbolize.py folder.
Example of use
After program abort we will get a stack trace.
=================================================================
==26506== ERROR: AddressSanitizer: heap-buffer-overflow on address 0xa9f5b808 at pc 0x80b94ff bp 0xbf9b0b38 sp 0xbf9b0b2c
READ of size 4 at 0xa9f5b808 thread T0
#0 0x80b94fe (/home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/bin/seamly2d+0x80b94fe)
#1 0x80af9d0 (/home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/bin/seamly2d+0x80af9d0)
#2 0xb4eefd0b (/usr/lib/i386-linux-gnu/libQt5Core.so.5.2.1+0x250d0b)
#3 0xb56a1e00 (/usr/lib/i386-linux-gnu/libQt5Widgets.so.5.2.1+0xd7e00)
#4 0xb56a7800 (/usr/lib/i386-linux-gnu/libQt5Widgets.so.5.2.1+0xdd800)
#5 0x8424abc (/home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/bin/seamly2d+0x8424abc)
#6 0xb4eefae9 (/usr/lib/i386-linux-gnu/libQt5Core.so.5.2.1+0x250ae9)
#7 0xb4ef1f7a (/usr/lib/i386-linux-gnu/libQt5Core.so.5.2.1+0x252f7a)
#8 0xb4ef26fb (/usr/lib/i386-linux-gnu/libQt5Core.so.5.2.1+0x2536fb)
#9 0xb4f42c8d (/usr/lib/i386-linux-gnu/libQt5Core.so.5.2.1+0x2a3c8d)
#10 0xb46e31e2 (/lib/i386-linux-gnu/libglib-2.0.so.0.4002.0+0x471e2)
#11 0xb46e3467 (/lib/i386-linux-gnu/libglib-2.0.so.0.4002.0+0x47467)
#12 0xb46e3527 (/lib/i386-linux-gnu/libglib-2.0.so.0.4002.0+0x47527)
#13 0xb4f4286c (/usr/lib/i386-linux-gnu/libQt5Core.so.5.2.1+0x2a386c)
#14 0xb286d835 (/usr/lib/i386-linux-gnu/qt5/plugins/platforms/libqxcb.so+0x47835)
#15 0xb4eee205 (/usr/lib/i386-linux-gnu/libQt5Core.so.5.2.1+0x24f205)
#16 0xb4eee61b (/usr/lib/i386-linux-gnu/libQt5Core.so.5.2.1+0x24f61b)
#17 0xb4ef5615 (/usr/lib/i386-linux-gnu/libQt5Core.so.5.2.1+0x256615)
#18 0xb51e2db3 (/usr/lib/i386-linux-gnu/libQt5Gui.so.5.2.1+0xaddb3)
#19 0xb56a0613 (/usr/lib/i386-linux-gnu/libQt5Widgets.so.5.2.1+0xd6613)
#20 0x845578f (/home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/bin/seamly2d+0x845578f)
#21 0xb4979a82 (/lib/i386-linux-gnu/libc-2.19.so+0x19a82)
#22 0x806b8f0 (/home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/bin/sealmy2d+0x806b8f0)
0xa9f5b808 is located 12 bytes to the right of 12-byte region [0xa9f5b7f0,0xa9f5b7fc)
allocated by thread T0 here:
#0 0xb61db624 (/usr/lib/i386-linux-gnu/libasan.so.0.0.0+0x11624)
#1 0xb56e6a31 (/usr/lib/i386-linux-gnu/libQt5Widgets.so.5.2.1+0x11ca31)
#2 0xb56e6df4 (/usr/lib/i386-linux-gnu/libQt5Widgets.so.5.2.1+0x11cdf4)
#3 0x814e382 (/home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/bin/seamly2d+0x814e382)
#4 0x84a6e10 (/home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/bin/seamly2d+0x84a6e10)
#5 0x84606bc (/home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/bin/seamly2d+0x84606bc)
#6 0x84d2372 (/home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/bin/seamly2d+0x84d2372)
#7 0x84d1925 (/home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/bin/seamly2d+0x84d1925)
#8 0x84d0364 (/home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/bin/seamly2d+0x84d0364)
#9 0xb4f1964d (/usr/lib/i386-linux-gnu/libQt5Core.so.5.2.1+0x27a64d)
#10 0xb4f1a0ea (/usr/lib/i386-linux-gnu/libQt5Core.so.5.2.1+0x27b0ea)
Shadow bytes around the buggy address:
0x353eb6b0: fa fa fd fa fa fa fd fa fa fa fd fa fa fa fd fd
0x353eb6c0: fa fa fd fa fa fa fd fd fa fa fd fd fa fa fd fa
0x353eb6d0: fa fa fd fd fa fa fd fa fa fa fd fd fa fa fd fa
0x353eb6e0: fa fa fd fd fa fa 00 04 fa fa 00 00 fa fa 00 04
0x353eb6f0: fa fa 00 04 fa fa 00 04 fa fa 00 04 fa fa 00 04
=>0x353eb700: fa[fa]fd fd fa fa fd fa fa fa fd fa fa fa fd fa
0x353eb710: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fa
0x353eb720: fa fa fd fd fa fa fd fd fa fa fd fa fa fa fd fd
0x353eb730: fa fa fd fa fa fa fd fd fa fa fd fd fa fa fd fd
0x353eb740: fa fa fd fa fa fa fd fa fa fa fd fd fa fa fd fd
0x353eb750: fa fa fd fd fa fa fd fa fa fa fd fd fa fa fd fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap righ redzone: fb
Freed Heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
ASan internal: fe
==26506== ABORTING
Save this stack trace in file error.txt.
Run:
cat error.txt | ./asan_symbolize.py | c++filt > error-log.txt
Result will looks like:
=================================================================
==26506== ERROR: AddressSanitizer: heap-buffer-overflow on address 0xa9f5b808 at pc 0x80b94ff bp 0xbf9b0b38 sp 0xbf9b0b2c
READ of size 4 at 0xa9f5b808 thread T0
#0 0x80b94fe in QKeyEvent::key() const /usr/include/qt5/QtGui/qevent.h:309
#1 0x80af9d0 in DialogTool::eventFilter(QObject*, QEvent*) /home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/../../../Seamly2D/src/app/dialogs/tools/dialogtool.cpp:416
#2 0xb4eefd0b in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) ??:?
#3 0xb56a1e00 in QApplicationPrivate::notify_helper(QObject*, QEvent*) ??:?
#4 0xb56a7800 in QApplication::notify(QObject*, QEvent*) ??:?
#5 0x8424abc in VApplication::notify(QObject*, QEvent*) /home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/../../../Seamly2D/src/app/core/vapplication.cpp:253
#6 0xb4eefae9 in QCoreApplication::notifyInternal(QObject*, QEvent*) ??:?
#7 0xb4ef1f7a in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) ??:?
#8 0xb4ef26fb in QCoreApplication::sendPostedEvents(QObject*, int) ??:?
#9 0xb4f42c8d in QEventDispatcherGlibPrivate::runTimersOnceWithNormalPriority() ??:?
#10 0xb46e31e2 in g_main_context_dispatch ??:?
#11 0xb46e3467 in g_main_context_dispatch ??:?
#12 0xb46e3527 in g_main_context_iteration ??:?
#13 0xb4f4286c in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ??:?
#14 0xb286d835 in QByteArray const* std::__find<QByteArray const*, QByteArray>(QByteArray const*, QByteArray const*, QByteArray const&, std::random_access_iterator_tag) ??:?
#15 0xb4eee205 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ??:?
#16 0xb4eee61b in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) ??:?
#17 0xb4ef5615 in QCoreApplication::exec() ??:?
#18 0xb51e2db3 in QGuiApplication::exec() ??:?
#19 0xb56a0613 in QApplication::exec() ??:?
#20 0x845578f in main /home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/../../../Seamly2D/src/app/main.cpp:129
#21 0xb4979a82 in __libc_start_main /build/buildd/eglibc-2.19/csu/libc-start.c:287
#22 0x806b8f0 in _start ??:?
0xa9f5b808 is located 12 bytes to the right of 12-byte region [0xa9f5b7f0,0xa9f5b7fc)
allocated by thread T0 here:
#0 0xb61db624 in operator new(unsigned int) ??:?
#1 0xb56e6a31 in QWidgetPrivate::init(QWidget*, QFlags<Qt::WindowType>) ??:?
#2 0xb56e6df4 in QWidget::QWidget(QWidgetPrivate&, QWidget*, QFlags<Qt::WindowType>) ??:?
#3 0x814e382 in DialogEndLine::DialogEndLine(VContainer const*, unsigned int const&, QWidget*) /home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/../../../Seamly2D/src/app/dialogs/tools/dialogendline.cpp:50 (discriminator 1)
#4 0x84a6e10 in void MainWindow::SetToolButtonWithApply<DialogEndLine, void (MainWindow::*)(int), void (MainWindow::*)()>(bool, Tool, QString const&, QString const&, void (MainWindow::*)(int), void (MainWindow::*)()) /home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/../../../Seamly2D/src/app/mainwindow.cpp:346 (discriminator 1)
#5 0x84606bc in MainWindow::ToolEndLine(bool) /home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/../../../Seamly2D/src/app/mainwindow.cpp:446 (discriminator 1)
#6 0x84d2372 in QtPrivate::FunctorCall<QtPrivate::IndexesList<0>, QtPrivate::List<bool>, void, void (MainWindow::*)(bool)>::call(void (MainWindow::*)(bool), MainWindow*, void**) /usr/include/qt5/QtCore/qobjectdefs_impl.h:508 (discriminator 3)
#7 0x84d1925 in void QtPrivate::FunctionPointer<void (MainWindow::*)(bool)>::call<QtPrivate::List<bool>, void>(void (MainWindow::*)(bool), MainWindow*, void**) /usr/include/qt5/QtCore/qobjectdefs_impl.h:527
#8 0x84d0364 in QtPrivate::QSlotObject<void (MainWindow::*)(bool), QtPrivate::List<bool>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) /usr/include/qt5/QtCore/qobject_impl.h:149
#9 0xb4f1964d in QMetaObject::activate(QObject*, int, int, void**) ??:?
#10 0xb4f1a0ea in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) ??:?
Shadow bytes around the buggy address:
0x353eb6b0: fa fa fd fa fa fa fd fa fa fa fd fa fa fa fd fd
0x353eb6c0: fa fa fd fa fa fa fd fd fa fa fd fd fa fa fd fa
0x353eb6d0: fa fa fd fd fa fa fd fa fa fa fd fd fa fa fd fa
0x353eb6e0: fa fa fd fd fa fa 00 04 fa fa 00 00 fa fa 00 04
0x353eb6f0: fa fa 00 04 fa fa 00 04 fa fa 00 04 fa fa 00 04
=>0x353eb700: fa[fa]fd fd fa fa fd fa fa fa fd fa fa fa fd fa
0x353eb710: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fa
0x353eb720: fa fa fd fd fa fa fd fd fa fa fd fa fa fa fd fd
0x353eb730: fa fa fd fa fa fa fd fd fa fa fd fd fa fa fd fd
0x353eb740: fa fa fd fa fa fa fd fa fa fa fd fd fa fa fd fd
0x353eb750: fa fa fd fd fa fa fd fa fa fa fd fd fa fa fd fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Heap righ redzone: fb
Freed Heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack partial redzone: f4
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
ASan internal: fe
==26506== ABORTING
Known issue
For debug creation a layout need allocate big size of memory for images. Address Sanitizer doesn't support this. For avoiding this bug we recommend build Seamly2D without Address Sanitizer. For this run qmake with argument CONFIG+=noAddressSanitizer.
Have fun hunting down memory issues.