Qt Creator - Add source directories for reverse engineering - qt-creator

I'm using Qt creator as a visual interface for gdb to reverse engineer an open source app running on a remote (embedded) device.
The app is build using automake and doesn't have a .pro file and neither do the libraries it uses.
I would like to do static analysis of the code and am looking for a simple way to jump to function declarations for the library functions.
For example, I find a library function call press F2 (Shotcut for follow symbol under cursor) and that brings me to the header file.
Is there a way to include the library source directories without creating a .pro file for each of them?

You can import a Autotools project into QtCreator as explained in the documentation:
Enable the Autotools Plugin: Help > About Plugins > Build Systems > AutotoolsProjectManager
Restart QtCreator
Open Makefile.am throught File > Open File or Project

Related

How do cmake configuration and default build task configuration play together in VSCode?

I'm compiling this PCL Library example. For reference, it consists of a simple cpp file that includes some PCL headers and does some basic data manipulation, and a CMakeLists.txt file.
Using the command line, I am able to build it using cmake -> make. I want to build it also using VSCode IDE. When I open this project on VSCode, it detects I'm using cmake, and if I clean/build it using the cmake extension, everything seems to work as expected (including autocompletion by intellisense, etc).
However, this takes some time as it builds the whole project in the same way you would do it from the command line, only from VSCode. I wanted to understand if I can also configure a "default build task" (via the tasks.json file) to build files using Ctrl + Shift + B, and be able to build individual files, and have a more IDE-Like experience (something like the incremental compiler of Eclipse with Java, for example).
If I add a C++ configuration, it fails to find .h files, and errors are highlighted on the open file, until I clean/rebuild via de cmake extension.
My question is, are this two options (cmake extension vs build tasks) compatible or mutually exclusive? Is defining and compiling via a task in fact more agile than building via the cmake extension?
Thanks!

Building GLFW for codeblocks

I'm trying to build GLFW from source for Code Blocks. I used Cmake and it made a directory and I opened the Code blocks project file and clicked the gear to build. The only thing new in src is libglfw3.a and I'm not sure what to do with it.
I think you're following the LearnOpenGL tutorial. Actually, i tried to do the same as he recommended, but i ended up following this tutorial which is way more simple to apply https://www.youtube.com/watch?v=0WrSGMuU964&t=0s . It's using the pre-compiled binaries folder, that's why it is not using Cmake. To make it short (under windows), you only need to copy/paste the include and lib-mingw folders in your project folder. Then open your project with Code::Blocks and go in Project/Build options... . In Search directories under the compiler tab, you need to add the include directory you just copy/pasted and under the linker tab, you do the same thing with the lib-mingw dir. Now in the linker settings tab (next to search directories) you need to add glw3, gdi32, and opengl32, and that's all it should be working now :) I only wrote the tutorial in case one day it disappears from youtube :p
This was posted a while ago but I think I built the static GLFW library for linux with WSL CMake instead of Windows CMake.

How to setup meson with Qt creator

I normally use Qt creator with cmake to program C++ projects. Lately I read quite a bit about meson and it's simplicity and I like to test it. This example explains how to setup meson.
When using meson, I like however to still use Qt creators shortcuts for building (ctrl + B) or running (ctrl + R). How can I configure Qt creator to build a meson project, when I'm using a "generic project"?
Meson is currently not directly supported by Qt Creator. There is a bug report requesting that: https://bugreports.qt.io/browse/QTCREATORBUG-18117 and I am considering to actually implement that.
For the time being I use meson via the "Generic Project". Go to "New File or Project", "Import Project" and there "Import Existing Project". That gets you a dialog where you can select the files that your project consists of.
After that is done you will need to edit "projectname.includes" and add the include directories (one per line) into that file. Then you need to edit "projectname.config" and add defines (one per line) there.
Finally you will need to edit the build configuration and call ninja instead of make there.
With that it works reasonably well for my small project.
Until the QtCreator supports directly meson.build project files, I find this python2 script useful to create QtCreator generic project files: https://github.com/mbitsnbites/meson2ide
with meson and ninja in your PATH, this should work:
$ meson builddir
$ python2 meson2ide.py builddir
this generates a .creator project file in builddir (if you get an error about "mesonintrospect" not found, try this PR: https://github.com/mbitsnbites/meson2ide/pull/1)
To make CTRL+B work properly, In QtCreator build settings, remove the make build step and add a custom build step with the path to the ninja executable, and add the command line arguments
3>&1 1>&2 2>&3
Those redirect allow QtCreator to capture build errors in the "issue" panel.

Adding Bonjour (dns_sd.h) library to Qt in Windows

I've been trying to properly add the open source dns_sd.h library provided by Apple. I am writing a program that uses the BonjourRegistrar class as demonstrated here:
link text
I've already written my program on the Mac environment and now I am trying to port it to Windows. The Bonjour SDK comes with several classes, and I am quite confused onto how to correctly add the class to my Qt project. I have tried add the line:
win32:LIBS += c:\dnsssd.lib
in the .pro file with no success. Also, I attempted to add the dns_sd.h and dns_sd.c files into my project and got a couple of errors such as:
'UINT8': does not name a type
'INT8': does not name a type
'UINT16' does not name a type
'INT16' does not name a type
Finally, I am now trying to modify the lib file as described by xcimo in this link
link text
I do not know if I am using the correct command to properly modify these files.
The .lib distributed by Apple can be used only if you are compiling the Qt application with the MSVC compiler.
Otherwise, like you said, you need a GCC-compatible library (.a). To do that you need to do the following steps:
Run the reimp tool [0] on the .lib: reimp dnssd.lib. A file DLLStub.obj will be generated.
Run the gendef tool [1] on the .dll: gendef dnssd.dll. A file dnssd.def will be generated. The .dll can be obtained from: C:\Windows\System32 if you are using the 32 bit or from C:\Windows\SysWOW64 for the 64 bit version.
Assemble the final .a: dlltool -k -d dnssd.def -l libdnssd.a.
Add the right path int the .pro file, to the newly created library: LIBS += -L"/path/to/the/library/file" -ldnssd
[0] - http://sourceforge.net/projects/mingw/files/MinGW/Extension/mingw-utils/mingw-utils-0.4-1/
[1] - http://sourceforge.net/projects/mingw/files/MinGW/Extension/gendef/gendef-1.0.1346/ - gendef is a better alternative to pexports, because it can convert the stdcall-type libraries from MSVC to the GCC ones, so you can get a proper .def file.
PS: I know the author got it working, but I felt there should be some more detailed instructions on how to get it done -- the information is scattered around the internet.
Try adding
DEFINES += _WIN32
to your project file.
I figured it out, you need to use reimp and dll tool to modify the lib library to a .a

setting up qt for xcode debugging

I just installed QT 4.6 on snow leopard 10.6.3. I wrote a really simple program. I can generate a xcode project using qmake, but I can't step into QT function. How can I set it up?
By default, qt is built with a debug and a non-debug library. This is my understanding. For example,
% ls /Library/Frameworks/QtCore.framework/
Contents/ Headers# QtCore# QtCore.prl QtCore_debug# QtCore_debug.dSYM/ QtCore_debug.prl Versions/
Also, my default from source build of Qt 4.7 branch also has the *_debug libs.
Setting up for Xcode is cake, you just set up your project and
% qmake -spec macx-xcode
This -spec is the default for the official mac distribution, but if you build your own from source the default is macx-g++ which creates a Makefile project.
This generates a MyProject.xcodeproj that comes preconfigured to link all the necessary Qt frameworks, sets up paths, and has a Release and Debug build target set to the same options as the official SDK's.
This is all assuming you have your qt project file set up, if you need to generate that first from a raw source directory:
% qmake -project
Debugging works "out of the box" for these generated *.xcodeproj files. However, there's one little "hitch". Since Qt is full of custom data types, Xcode doesn't know how to display their "values" in the debugger's summary pane. So you can't see what value a QString has, for example.
There's a method of entering custom macros for display, but I've found these often (always?) don't work for QObjects.
To get that working, I've started a project that uses xcode's debugger c callbacks (also mentioned in the above linked article, though their example doesn't even work o.O). I call it Qt4DataFormatters.
I've just started it and have been adding types as the need arises. It's dirt simple to create one using the existing functions as a template though.
I haven't tried this on Mac, but on Linux you need to take the following process:
First, you need to setup Qt so that it has debugging symbols available to you:
./configure -debug-and-release separate-debug-info # other options
With the debugging symbols available, you should now be able to get valid stack traces.
When building your application with qmake, you need to have the debug (or debug_and_release) flag set in your project file:
CONFIG += debug
Once you've done that, you should only need to tell the debugger where the Qt source is located:
(gdb) dir /path/to/qt/src
After that, list should show you the actual Qt source code. You may need to add additional directories under the src directory for the debugger to pick it all up.

Resources