Hacking:Tools: Difference between revisions
Added link to Hacking:Tools:QtCreator:Ubuntu |
|||
Line 46: | Line 46: | ||
* 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 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. |
||
See '''[[Hacking:Tools:QtCreator:Ubuntu]]''' for description of installing and configuring Qt on Ubuntu 14.04. |
|||
== Address Sanitizer == |
== Address Sanitizer == |
Revision as of 22:50, 21 November 2016
hg-git Extension
For export to github and launchpad we use hg-git extension. Please read these two articles for more details: the Hg-Git mercurial plugin and hg-git Extension.
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.
For our work we use code from repository http://bitbucket.org/durin42/hg-git/
Usage: For working extension need to create a bookmark. Command
hg bookmark -f master
will set a bookmark for current branch. Most actively we export 'develop' and 'default'.
Before pushing create path 'github' in .hgrc file.
[extensions]
hgext.bookmarks =
hggit = /home/dismine/hg-git/hggit
[paths]
github = git+ssh://git@github.com/<user_name>/<repository_name>.git
Run
hg push github
for pushing changes to github.
Note the command can hang. You can wait finish or close terminal without losing data.
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.
First look better begin from the official website.
For effective using Qt Creator you will need know some stuff.
- Qt Creator supports Mercurial, 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. Valentina'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 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.
See Hacking:Tools:QtCreator:Ubuntu for description of installing and configuring Qt on Ubuntu 14.04.
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 Valentina already use this flags, so no need set them manually.
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 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.
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/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+0x80b94fe)
#1 0x80af9d0 (/home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+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/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+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/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+0x845578f)
#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)
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/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+0x814e382)
#4 0x84a6e10 (/home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+0x84a6e10)
#5 0x84606bc (/home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+0x84606bc)
#6 0x84d2372 (/home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+0x84d2372)
#7 0x84d1925 (/home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+0x84d1925)
#8 0x84d0364 (/home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/bin/valentina+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/dismine/CAD/build-Valentina-Desktop-Debug/src/app/../../../Valentina/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/dismine/CAD/build-Valentina-Desktop-Debug/src/app/../../../Valentina/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/dismine/CAD/build-Valentina-Desktop-Debug/src/app/../../../Valentina/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/dismine/CAD/build-Valentina-Desktop-Debug/src/app/../../../Valentina/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)
#5 0x84606bc in MainWindow::ToolEndLine(bool) /home/dismine/CAD/build-Valentina-Desktop-Debug/src/app/../../../Valentina/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 Valentina without Address Sanitizer. For this run qmake with argument CONFIG+=noAddressSanitizer.
Have fun hunting down memory issues.
Mercurial
Better place to start to get acquainted with the tool is the official guide. Also read A Guide to Branching in Mercurial.
Some people love to use only command line other will prefer GUI. For the second group we highly recommend TortoiseHG.
Below we will show several useful commands you will need to know for begin work with mercurial.
hg clone https://bitbucket.org/dismine/valentina
- clonning the main repository.hg pull
- pull updates.hg update develop
- update to develop branch.hg branch
- to see what branch is current.hg branch feature
- say to commit to feature branch .hg branch -f feature
- say to commit to feature branch even it is already exists. Reopen the branch in another place.hg commit -m "Fixed issue #XXX. Title of issue in the issue tracker."
- make a commit with message.hg push -b feature
- push your changes from branch feature.hg push
- push all your changes.hg bookmark -f master
- create a bookmark.