Hacking:Tools: Difference between revisions

From Seamly
Content added Content deleted
 
(19 intermediate revisions by 4 users not shown)
Line 1: Line 1:
__TOC__
__TOC__
== hg-git Extension ==
== Git ==
For export to github and launchpad we use hg-git extension. Please read these two articles for more details: [https://hg-git.github.io/ the Hg-Git mercurial plugin] and [http://mercurial.selenic.com/wiki/HgGit hg-git Extension].<br />


The Seamly2D code repository is on Github: https://github.com/FashionFreedom/Seamly2D
'''Warning!''' ''Because service Launchpad doesn't use git repository directly and converts to Bazaar we can't use hg-git version higher than 0.6.1.''<br />


Please learn Git and workflow guidelines:
For our work we use code from repository http://bitbucket.org/durin42/hg-git/<br />
# 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 ==
Usage: For working extension need to create a bookmark. Command
<source lang="bash">
hg bookmark -f master
</source>
will set a bookmark for current branch. Most actively we export 'develop' and 'default'.


Launchpad automatically mirrors the Seamly2D git repo here: https://launchpad.net/~susan-spencer/+archive/ubuntu/seamly2d
Before pushing create path 'github' in .hgrc file.
<source lang="ini">
[extensions]
hgext.bookmarks =
hggit = /home/dismine/hg-git/hggit

[paths]
github = git+ssh://git@github.com/<user_name>/<repository_name>.git
</source>

Run
<source lang="bash">
hg push github
</source>
for pushing changes to github.

'''Note''' the command can hang. You can wait finish or close terminal without losing data.


== Qt Creator ==
== Qt Creator ==
When you use Qt you have two IDE to choose: Qt Creator and Visual Studio. Yes, last information what i have says that Eclipse doesn't have support for Qt5.
When you use Qt you have two IDE to choose: Qt Creator and Visual Studio.


First look better begin from [https://www.qt.io/ide/ the official website].
from [https://www.qt.io/ide/ the official website].


For effective using Qt Creator you will need know some stuff.
For effective use of Qt Creator you will need to know some stuff.
* Qt Creator supports Mercurial, so creating and deleting files better to do from the IDE.
* 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.
* [https://doc.qt.io/qtcreator/creator-keyboard-shortcuts.html Keyboard Shortcuts].
* [https://doc.qt.io/qtcreator/creator-keyboard-shortcuts.html Keyboard Shortcuts].
* [https://doc.qt.io/qtcreator/creator-editor-refactoring.html Refactoring].
* [https://doc.qt.io/qtcreator/creator-editor-refactoring.html Refactoring].
* [https://doc.qt.io/qtcreator/creator-code-style-settings.html Specifying Code Style Settings]. Valentina's code style file for Qt Creator you can find in '''<root>/share''' directory.
* [https://doc.qt.io/qtcreator/creator-code-style-settings.html 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 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'''.
* 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.
* 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 support two release mode: 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.
* 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|Hacking:Tools:QtCreator:Windows10]]''' for description of installing and configuring Qt on 64-bit Windows 10.


== Address Sanitizer ==
== Address Sanitizer ==
Line 67: Line 54:
</source>
</source>


In '''debug mode''' Valentina already use this flags, so no need set them manually.
In '''debug mode''' Seamly2D already use this flags, so no need set them manually.


=== How to use it? ===
=== How to use it? ===
Just run Valentina! 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 [https://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py asan_symbolize.py] to get the symbols, and then maybe c++filt to de-mangle the C++ symbols.
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 [https://llvm.org/svn/llvm-project/compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py asan_symbolize.py] to get the symbols, and then maybe c++filt to de-mangle the C++ symbols.


asan_symbolize.py also awailible in Valentina/scripts/asan_symbolize.py folder.
asan_symbolize.py also awailible in Seamly2D/scripts/asan_symbolize.py folder.


=== Example of use ===
=== Example of use ===
After program abort we will get a stack trace.
After program abort we will get a stack trace.
<source lang=bash>
<source lang="bash">
=================================================================
=================================================================
==26506== ERROR: AddressSanitizer: heap-buffer-overflow on address 0xa9f5b808 at pc 0x80b94ff bp 0xbf9b0b38 sp 0xbf9b0b2c
==26506== ERROR: AddressSanitizer: heap-buffer-overflow on address 0xa9f5b808 at pc 0x80b94ff bp 0xbf9b0b38 sp 0xbf9b0b2c
READ of size 4 at 0xa9f5b808 thread T0
READ of size 4 at 0xa9f5b808 thread T0
#0 0x80b94fe (/home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+0x80b94fe)
#0 0x80b94fe (/home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/bin/seamly2d+0x80b94fe)
#1 0x80af9d0 (/home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+0x80af9d0)
#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)
#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)
#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)
#4 0xb56a7800 (/usr/lib/i386-linux-gnu/libQt5Widgets.so.5.2.1+0xdd800)
#5 0x8424abc (/home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+0x8424abc)
#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)
#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)
#7 0xb4ef1f7a (/usr/lib/i386-linux-gnu/libQt5Core.so.5.2.1+0x252f7a)
Line 100: Line 87:
#18 0xb51e2db3 (/usr/lib/i386-linux-gnu/libQt5Gui.so.5.2.1+0xaddb3)
#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)
#19 0xb56a0613 (/usr/lib/i386-linux-gnu/libQt5Widgets.so.5.2.1+0xd6613)
#20 0x845578f (/home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+0x845578f)
#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)
#21 0xb4979a82 (/lib/i386-linux-gnu/libc-2.19.so+0x19a82)
#22 0x806b8f0 (/home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+0x806b8f0)
#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)
0xa9f5b808 is located 12 bytes to the right of 12-byte region [0xa9f5b7f0,0xa9f5b7fc)
allocated by thread T0 here:
allocated by thread T0 here:
Line 108: Line 95:
#1 0xb56e6a31 (/usr/lib/i386-linux-gnu/libQt5Widgets.so.5.2.1+0x11ca31)
#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)
#2 0xb56e6df4 (/usr/lib/i386-linux-gnu/libQt5Widgets.so.5.2.1+0x11cdf4)
#3 0x814e382 (/home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+0x814e382)
#3 0x814e382 (/home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/bin/seamly2d+0x814e382)
#4 0x84a6e10 (/home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+0x84a6e10)
#4 0x84a6e10 (/home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/bin/seamly2d+0x84a6e10)
#5 0x84606bc (/home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+0x84606bc)
#5 0x84606bc (/home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/bin/seamly2d+0x84606bc)
#6 0x84d2372 (/home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+0x84d2372)
#6 0x84d2372 (/home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/bin/seamly2d+0x84d2372)
#7 0x84d1925 (/home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+0x84d1925)
#7 0x84d1925 (/home/''<you>''/CAD/build-Seamly2D-Desktop-Debug/src/app/bin/seamly2d+0x84d1925)
#8 0x84d0364 (/home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+0x84d0364)
#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)
#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)
#10 0xb4f1a0ea (/usr/lib/i386-linux-gnu/libQt5Core.so.5.2.1+0x27b0ea)
Line 157: Line 144:
Result will looks like:
Result will looks like:


<source lang=bash>
<source lang="bash">
=================================================================
=================================================================
==26506== ERROR: AddressSanitizer: heap-buffer-overflow on address 0xa9f5b808 at pc 0x80b94ff bp 0xbf9b0b38 sp 0xbf9b0b2c
==26506== ERROR: AddressSanitizer: heap-buffer-overflow on address 0xa9f5b808 at pc 0x80b94ff bp 0xbf9b0b38 sp 0xbf9b0b2c
READ of size 4 at 0xa9f5b808 thread T0
READ of size 4 at 0xa9f5b808 thread T0
#0 0x80b94fe in QKeyEvent::key() const /usr/include/qt5/QtGui/qevent.h:309
#0 0x80b94fe in QKeyEvent::key() const /usr/include/qt5/QtGui/qevent.h:309
#1 0x80af9d0 in DialogTool::eventFilter(QObject*, QEvent*) /home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/../../../Valentina/src/app/dialogs/tools/dialogtool.cpp:416
#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*) ??:?
#2 0xb4eefd0b in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) ??:?
#3 0xb56a1e00 in QApplicationPrivate::notify_helper(QObject*, QEvent*) ??:?
#3 0xb56a1e00 in QApplicationPrivate::notify_helper(QObject*, QEvent*) ??:?
#4 0xb56a7800 in QApplication::notify(QObject*, QEvent*) ??:?
#4 0xb56a7800 in QApplication::notify(QObject*, QEvent*) ??:?
#5 0x8424abc in VApplication::notify(QObject*, QEvent*) /home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/../../../Valentina/src/app/core/vapplication.cpp:253
#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*) ??:?
#6 0xb4eefae9 in QCoreApplication::notifyInternal(QObject*, QEvent*) ??:?
#7 0xb4ef1f7a in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) ??:?
#7 0xb4ef1f7a in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) ??:?
Line 181: Line 168:
#18 0xb51e2db3 in QGuiApplication::exec() ??:?
#18 0xb51e2db3 in QGuiApplication::exec() ??:?
#19 0xb56a0613 in QApplication::exec() ??:?
#19 0xb56a0613 in QApplication::exec() ??:?
#20 0x845578f in main /home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/../../../Valentina/src/app/main.cpp:129
#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
#21 0xb4979a82 in __libc_start_main /build/buildd/eglibc-2.19/csu/libc-start.c:287
#22 0x806b8f0 in _start ??:?
#22 0x806b8f0 in _start ??:?
Line 189: Line 176:
#1 0xb56e6a31 in QWidgetPrivate::init(QWidget*, QFlags<Qt::WindowType>) ??:?
#1 0xb56e6a31 in QWidgetPrivate::init(QWidget*, QFlags<Qt::WindowType>) ??:?
#2 0xb56e6df4 in QWidget::QWidget(QWidgetPrivate&, 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/dismine/CAD/build-Valentina-Desktop-Debug/src/app/../../../Valentina/src/app/dialogs/tools/dialogendline.cpp:50 (discriminator 1)
#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/dismine/CAD/build-Valentina-Desktop-Debug/src/app/../../../Valentina/src/app/mainwindow.cpp:346 (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/dismine/CAD/build-Valentina-Desktop-Debug/src/app/../../../Valentina/src/app/mainwindow.cpp:446 (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)
#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
#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
Line 229: Line 216:


=== Known issue ===
=== 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 Valentina without Address Sanitizer. For this run qmake with argument ''CONFIG+=noAddressSanitizer''.
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.
Have fun hunting down memory issues.

== Mercurial ==

Better place to start to get acquainted with the tool is the [http://hgbook.red-bean.com/ official guide].

Some people love to use only command line other will prefer GUI. For the second group we highly recommend [http://tortoisehg.bitbucket.org/ TortoiseHG].

Below we will show several useful commands you will need to know for begin work with mercurial.

* <code>hg update develop</code> - update to '''develop''' branch.
* <code>hg branch</code> - to see what branch is current.
* <code>hg branch feature</code> - say to commit to '''feature''' branch .
* <code>hg branch -f feature</code> - say to commit to '''feature''' branch even it is already exists. Reopen the branch in another place.
* <code>hg commit -m "Fixed issue #XXX. Title of issue in the issue tracker."</code> - make a commit with message.
* <code>hg push -b feature</code> - push your changes from branch '''feature'''.
* <code>hg push</code> - push all your changes.
* <code>hg bookmark -f master</code> - create a bookmark.

Latest revision as of 09:13, 16 December 2022

Git[edit | edit source]

The Seamly2D code repository is on Github: https://github.com/FashionFreedom/Seamly2D

Please learn Git and workflow guidelines:

  1. Basic Git: https://zaiste.net/git_for_busy_people/
  2. The Git Flow method: https://datasift.github.io/gitflow/IntroducingGitFlow.html/
  3. Using semantic commit messages: https://seesparkbox.com/foundry/semantic_commit_messages/

Canonical/Ubuntu Launchpad and Bazaar[edit | edit source]

Launchpad automatically mirrors the Seamly2D git repo here: https://launchpad.net/~susan-spencer/+archive/ubuntu/seamly2d

Qt Creator[edit | edit source]

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 to 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[edit | edit source]

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?[edit | edit source]

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?[edit | edit source]

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?[edit | edit source]

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[edit | edit source]

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[edit | edit source]

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.