Github ssh keys on Windows

1) Install git client

choco install git -Y

2) generate ssh key for your email

ssh-keygen -t rsa -b 4096 -C "[email protected]"

3) enable `OpenSSH Authentication Agent` in Services management

4) add key to agent

ssh-add  C:\Users\USER\.ssh\id_ed25519

5) add key to github

type "C:\Users\USER\.ssh\id_ed25519.pub"

6) test key

ssh -T [email protected]
Hi USER! You've successfully authenticated, but GitHub does not provide shell access.

Other links

Google breakpad 2020

Get breakpad

git clone https://chromium.googlesource.com/breakpad/breakpad
git clone https://chromium.googlesource.com/external/gyp

Prepare windows

gyp\gyp.bat --no-circular-check breakpad\src\tools\windows\tools_windows.gyp
gyp\gyp.bat --no-circular-check src\client\windows\breakpad_client.gyp

Prepare linux

  • add src/third_party/lss/linux_syscall_support.h

Fix few things in VS studio in tools_windows

– library output from $(OutDir)lib\$(ProjectName).lib to $(OutDir)\$(ProjectName).lib
– add missing dependency lib Pathcch.lib
– unload gtest, gmock and dump_syms_unittest

Fix few things in VS studio in breakpad_client

– library output from $(OutDir)lib\$(ProjectName).lib to $(OutDir)\$(ProjectName).lib
– unload all unittests projects
– for crash_Generation_client, crash_generation_server, exception_handler, common, crash_generation_app
– c++ -> language -> enable RTTI YES
– c++ -> codegeneration ->runtime library -> MD/MDd

How to extract symbols

The simplest way is to use

dump_syms.exe APP_PATH\APP.exe > app.sym

but this doesn’t prepare correct structure for automatic dmp file evaluation, so we need to use symbolstore.py

Other links

 

Windows 8.1 tuning (to look and behave like win7)

Use Windows 8.1 in default configuration as developer machine is hell on the earth. So, here are the steps how to turn Windows 8.1 back to classic…

 

  • Configure your user as TRUE administrator (link)
  • Replace metro by classic start menu (link)
  • split monitor to more areas (WinSplit revolution, alternative ownload link)
  • Windows firewall extension to notify about outgoing connections (link)
  • Disable local http server on port 80 (after visual studio installation!!) (link) HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\start =  4
  • Enable administrative sharing for c$,d$, … (superuserHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\LocalAccountTokenFilterPolicy=
  • Disable top left/right corner clip HKEY_CURRENT_USER\Control Panel\Desktop\MouseCornerClipLength=0

Qt5 application crashed with error 0xc0000005

This is very interesting crash and I think it should be considered as Qt bug. This problem arise only under very special circumstances. But one after another.

You will identify this problem when your application stopped/exited immediately after the start without any visible error message. It looks like the application isn’t executed at all. When you check application log (Computer -> manage -> Event viewer -> Windows logs -> Application), you will see Error logs:

Windows applications logs

The most interesting part of this log is crash location: ntdll.dll

Faulting application name: Skipper.exe, version: 3.0.1.1120, time stamp: 0x53e9c8d7
Faulting module name: ntdll.dll, version: 6.1.7601.18247, time stamp: 0x521ea8e7
Exception code: 0xc0000005
Fault offset: 0x0002e3be
Faulting process id: 0x1c88
Faulting application start time: 0x01cfb606553e594b
Faulting application path: T:\S2\Skipper.exe
Faulting module path: C:\Windows\SysWOW64\ntdll.dll
Report Id: 98cc8228-21f9-11e4-ab5d-005056c00008

At first sight it seems like some problem inside the windows. But the opposite is true, the problem (as almost always) is inside your app ;-).

As the next step, you can try to debug this executable via Visual Studio to see what happens inside. Simply open executable as project together with .pdb files and execute it. Now you can see that application is correctly executed but crashes as soon as it touches Qt library. The location of crash is inside ntdll.dll in RtlHeapFree() function.

Debuging crash in VisualStudio 2013

So the problem is inside the Qt, right? Almost true, but not for the 100%. When I tried to run this application on computers of my colleagues, everything works ok. So why the application doesn’t work on my computer too?

Resolution

The problem is in new Qt5 plugin system. Besides the common Qt5*.dll files which are loaded immediately after the application start, Qt5 is also loading plugins/platform-plugins dynamically when the application is executed. To locate this plugins, Qt5 uses following method to identify directories where to search for plugins:

QStringList QCoreApplication::libraryPaths()

For some strange reason this library returns as first directory path where Qt5 libraries were compiled and after that location based on the executable. So if your Qt5 path is C:\Qt5, this will be the first path where all plugins are searched for, no matter if the correct version of plugin is located in APP\plugins or APP\platforms. I think this is serious bug in Qt5.

Where is the problem?

And here we’re getting to the core of the whole problem.

If application is compiled on computer with one compiler and used on second  computer which contains the same path to which original computer has installed Qt, the application will load all plugins from your folder instead of itself folder.

In case your computer will contain different version of Qt, different compiler or different platform, application loads incorrect libraries and crashes. Completely, silently and without easy way to determine what’s wrong.

Solution?

The solution is simple, but it isn’t achievable from outside of the Qt library. It would be necessary to Qt as first tried to load libraries from application directory. And only if no plugins were found in application directory, the application would try to search for plugins in Qt directory.

Qt change solution

The simplest way how to fix this issue inside the Qt library would be to rename/update appendApplicationPathToLibraryPaths  function to prependApplicationPathToLibraryPaths and change

void QCoreApplicationPrivate::prependApplicationPathToLibraryPaths()
{
#ifndef QT_NO_LIBRARY
    QStringList *app_libpaths = coreappdata()->app_libpaths;
    if (!app_libpaths)
        coreappdata()->app_libpaths = app_libpaths = new QStringList;
    QString app_location = QCoreApplication::applicationFilePath();
    app_location.truncate(app_location.lastIndexOf(QLatin1Char('/')));
#ifdef Q_OS_WINRT
    if (app_location.isEmpty())
        app_location.append(QLatin1Char('/'));
#endif
    app_location = QDir(app_location).canonicalPath();
    if (QFile::exists(app_location) && !app_libpaths->contains(app_location))
        //CHANGE THIS ROW: app_libpaths->append(app_location);
        //TO FOLLOWING
        app_libpaths->prepend(app_location);
#endif
}

InApp solution

Unfortunately it isn’t possible to simply change this behavior from your app. All of these operations happen directly in QCoreApplication constructor so if you try to change it after, it’s too late.

The temporary solution before this problem will be resolved is to reinitialize library paths before QCoreApplication is initialized. It’s necessary to clean libray paths, compute new paths and re-initialize QCoreApplication::libraryPaths before QCoreApplication object is initialized. This can be done in main.cpp of your application before you will create QApplication/QCoreApplication object.

  QString executable = argv[0];
  QString executablePath = executable.mid(0,executable.lastIndexOf("\\"));
  QString installPathPlugins = QLibraryInfo::location(QLibraryInfo::PluginsPath);
  QCoreApplication::removeLibraryPath(installPathPlugins);
  QCoreApplication::addLibraryPath(installPathPlugins);
  QCoreApplication::addLibraryPath(executablePath);

It’s not a nice solution, but it works. I tried  to report this issue also to bugreports.QtProject, so maybe in later version this will be fixed.

How to create .pdb files also for Release version of Qt library

For debugging purposes it’s a good idea to keep .pdb files also for release version of your libraries. Unfortunately in default configuration Qt library doesn’t generate .pdb files. It’s a not big deal, create .pdb files for release version it’s pretty simple.

1) Add compilation flags to .pro file

The easiest way how to create pdb files is pass /Zi switch to compiler and /Debug to linker.

QMAKE_CXXFLAGS+=/Zi
QMAKE_LFLAGS+= /INCREMENTAL:NO /Debug

2) Solution via mkspec

As pointed out in this QtProject article, another way is to edit mkspec so any future compilations will have this option turned on. It’s necessary to modify correct mkspec file, for example

Qt</span>\mkspecs\win32-msvc2005\qmake.conf

and add following lines (it should be sufficient to add only /Zi and /Debug switch):

QMAKE_CFLAGS_RELEASE += /Zi
QMAKE_LFLAGS_RELEASE += /INCREMENTAL:NO /DEBUG

Visual Studio 2013 – Visualizers

One of very useful feature of Visual Studio is custom variables views. It’s possible to configure own views to each of your class. For this, VS2013 (and VS2012) uses .natvis files located in following directories:

%VSINSTALLDIR%\Common7\Packages\Debugger\Visualizers
%USERPROFILE%\My Documents\Visual Studio 2013\Visualizers

Files are stored in common .xml format and has following format:

<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
  <Type Name="String::CStringHolder&lt;String::string_trait&lt;char&gt; &gt;">
    <DisplayString>{m_pszData,s8}</DisplayString>
    <StringView>m_pszData</StringView>
    <Expand>
      <Item Name="[m_pszData]">m_pszData</Item>
      <Item Name="[nDataLength]">m_pStringData->nDataLength</Item>
      <Item Name="[nAllocLength]">m_pStringData->nAllocLength</Item>
      <Item Name="[nRefs]">m_pStringData->nRefs</Item>
    </Expand>
  </Type>
</AutoVisualizer>

Debugging .natvis files

Visual studio contains a way how to catch syntax and logical errors in natvis format. All warnings/errors can be displayed to Visual Studio output panel by specifying following registry key to “1”.

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0_Config\Debugger
"EnableNatvisDiagnostics"=dword:00000001

Note: It’s necessary to restart Visual studio to turn on this feature

Other usefull links

nginx and fast-cgi – tips and tricks

How to pass full path to fast-cgi app

It’s necessary to configure which parameters are passed to fast-cgi application from nginx server. For this purposes serves fastcgi_param keyword. It’s a good practice to keeps all fastcgi params together. For this purposes nginx has fastcgi.conf file. This file already contains most of useful fastcgi_param bindings.

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
...

To include this file use include statement:

location / {
   include fastcgi_params;
   fastcgi_pass 127.0.0.1:9345;
 }

How to pass custom headers to fast-cgi app

Default configuration pass only default headers to fast-cgi. It’s necessary to add few more configurations statements:

fastcgi_pass_request_headers on;

After that headers are passed as HTTP_* parameters:

HTTP_HEADER1=2222

External links

How to run fastcgi and nginx on windows

Step by step guide how to configure nginx on windows….

Download and installation

Download nginx package from nginx site. Unpack it and installation is done 😉

Example of fast-cgi application

No create and complie fast-cgi application. (How to compile fast-cgi on windows)

    #include "fcgi_stdio.h"
    #include &lt;stdlib.h&gt;

    void main(void)
    {
        int count = 0;
        while(FCGI_Accept() &gt;= 0)
            printf("Content-type: text/html\r\n"
                   "\r\n"
                   "&lt;title&gt;FastCGI Hello!&lt;/title&gt;"
                   "&lt;h1&gt;FastCGI Hello!&lt;/h1&gt;"
                   "Request number %d running on host &lt;i&gt;%s&lt;/i&gt;\n",
                    ++count, getenv("SERVER_NAME"));
    }

How to connect fast-cgi with web-server

There are two ways. When web-server supports fast-cgi you will be able to connect fast-cgi directly with web-server via configuration files. In all other cases fast-cgi offers cgi-fcgi  executable as bridge between webserver and your app. More info about both these approaches you can find here http://www.fastcgi.com/devkit/doc/fcgi-devel-kit.htm#S4.

Working way how to get fastcgi apps working

None of two ways described in previous article and in official documentation works for me on windows. I wasn’t able to get cgi-fcgi or spawn-fcgi running. First mentioned crashed everytime app tries to initialize STD_OUT, the second one isn’t possible to compile it because of missing unistd.h header.

Fortunately there is one more way. FCGI library offers one more way how to utilize FCGI mechanism. It’s necessary add two more lines to example above and everything works perfectly.

    #include "fcgi_stdio.h"
    #include &lt;stdlib.h&gt;

    void main(void)
    {
        //initialize library &amp; open listening socket at port 9345
        FCGX_Init();
        FCGX_OpenSocket(":9345",500);

        //rest is the same as in example above
        while(FCGI_Accept() &gt;= 0) ...
    }

After this change application initialize listening port and waits for incoming data. All you need to do is directly execute the app.

Configure nginx to connect with fast-cgi

This step compared to previous ones is pretty easy. You need to tell nginx server what and where to pass. Open file nginx.conf and add following statement:

http {
  server {
    location / {
      fastcgi_pass 127.0.0.1:9345;
     }
  }
}

fastcgi_pass statement forward all requests to localhost:9345 address. Now when you start your nginx server, everything should work as expected.

nginx server cfg

Troubleshooting

bind() to 0.0.0.0:80 failed

This error is caused by another application which uses port 80. In my case it was Skype which automatically uses port 80.

nginx: [emerg] bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions)

External links

How to compile FastCGI library in Visual Studio 2010 C++

FastCGI comes with Win32 project for VisualStudio6. Unfortunately when you try to open it in VisualStudio2010 the project will be corrupted. To correctly compile it for VS2010 it’s necessary to download library sources, get patches from cybozu.co.jp site and apply it.

Download library

Download latest version of Development Kit here and extract it to standalone directory.

FastCGI

Get and update patches

Download all five patches from Cybozu site. Now when you have patches it’s necessary to convert all files to correct windows-ending format. This can be done for example in Notepad++.

Convert to windows EOL

Get patch.exe application

Now you need some application capable to apply the patches. Unfortunately windows doesn’t contain any application for this task and also lot of comparing/merging applications can’t do that.

The simplest way is to download windows conversion of linux patch.exe app. Get it from gnuwin32 site – patch for windows.

Apply patch to project files

Apply patches

Open directory with fastcgi library, copy all patch files to this directory and open command line. As next run patch command for all fives patches:

...\fcgi-2.4.1-SNAP-0311112127>patch -Np1 < 4-vc9.patch
patching file Win32/FastCGI.sln
patching file Win32/authorizer.vcproj
patching file Win32/cgifcgi.vcproj
patching file Win32/config_h.vcproj
patching file Win32/echo-cpp.vcproj
patching file Win32/echo.vcproj
patching file Win32/echox.vcproj
patching file Win32/libfcgi.vcproj
patching file Win32/logdump.vcproj
patching file Win32/size.vcproj
patching file Win32/threaded.vcproj

In case you will see following error message:

patching file Win32/FastCGI.sln
Assertion failed: hunk, file ../patch-2.5.9-src/patch.c, line 354

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

it’s necessary to convert ALL patch files to correct Windows format (correct EOL) as mentioned in previous section.

More patches…

When you apply patches by cybozu it’s time to apply my own patches ;-).

Manually updated rejected file

As first, it’s probably that you will see following message:

1 out of 26 hunks FAILED -- saving rejects to file libfcgi/os_win32.c.rej

It’s because original patch is for older version of library and file os_win32.c  is slightly different. To fix that, edit this file at line 841 and manually update following line:

//original
int len = p - bindPath + 1;

//updated line
intptr_t len = p - bindPath + 1;

Update VS project file

Now turn off generating the Map Files in project configuration. These files aren’t necessary and it isn’t possible to compile project correctly with this settings.

Turn off .map files

DONE

And that’s all. Now you will be able to sucesfully compile fast-cgi library.

Compilation complete

External links