mercredi 1 août 2018

Introspection in C++

 

A useful beginner video from handmade hero which implements a quick way to start adding reflection to your c++ project.

You parse the C++ structure with you custom parser. This means it is a add hoc solution (you don't want to support everything c++ syntax can throw at you) but it is sufficient in 99% of the case where you need reflection in your project.

See: https://www.youtube.com/watch?v=1IwYEJsvdcs

 Using private Github repos with Yocto

 Really useful for bitbake builds !

Make sure you have SSH keys for Github setup so that you can do this from a command line on the build machine
git clone git@github.com:scottellis/private-repo.git
You should run that clone command at least once. If the github server keys are new you’ll need to answer the prompt from ssh to accept the new key. If this happens when running bitbake the process will hang on the fetch stage.
The SRC_URI to use in the bitbake recipe is
SRC_URI="git://git@github.com/scottellis/private-repo.git;protocol=ssh" 

Sources:
This comes in its entirety from http://www.jumpnowtek.com/yocto/Yocto-and-Github-private-repos.html
 
 

lundi 13 juin 2016

[debug] getting valgrind full backtrace when debugging a dynamically loaded library

Little tip:

If you are getting something like this in valgrind while debugging a dynamically loaded library, it is because the symbols from the library have been deleted when the program called dl_close.


==23759==
==23759== HEAP SUMMARY:
==23759== in use at exit: 39,684 bytes in 23 blocks
==23759== total heap usage: 2,433 allocs, 2,410 frees, 6,965,904 bytes allocated
==23759==
==23759== 24 bytes in 1 blocks are definitely lost in loss record 4 of 15
==23759== at 0x402C1BC: malloc (vg_replace_malloc.c:299)
==23759== by 0x4873C87: ???
==23759== by 0x4873DD7: ???
==23759== by 0x48662E5: ???
==23759== by 0x4866324: ???
==23759== by 0x486625D: ???
==23759== by 0x485F5A8: ???
==23759== by 0x485CC73: ???
==23759== by 0x485BCF5: ???
==23759== by 0x804BCE3: setPortParameters() (main.cpp:147)
==23759== by 0x805070D: safeMain(int, char**) (main.cpp:588)
==23759== by 0x8051E8A: main (main.cpp:661)


You need to remove the dl_close call to get a full stack trace.

lundi 4 avril 2016

[Kernel] Initramfs is too big ...


Kernel is not booting...

You then realize that your initramfs is very big : 200MB ...

A normal initramfs can range between 2MB to ~20MB in general.
If your initramfs is too big, then the kernel will not be able to map it in memory and it won't boot.

You can remove all the things your computer won't use anyway from the bloated initramfs.

Edit /etc/initramfs-tools/initramfs.conf
and set MODULES=dep instead of MODULES=most

You can then rebuild your kernel.

Sources

http://askubuntu.com/questions/299396/how-to-reduce-the-size-of-initrd-img-on-ubuntu-13-04

[cmdline] MoreUtils

The errno util


Just a quick note to praise the moreutils package.

When programming userspace application that communicate with drivers, you will always get some errno number or somme perror formated strings.

errno is just the tool that make it easy to get the information about the error.

$ errno 12
ENOMEM 12 Cannot allocate memory



$ errno -s memory
ENOMEM 12 Cannot allocate memory
EHWPOISON 133 Memory page has hardware error



You don't need this site anymore.

Source:

https://joeyh.name/code/moreutils/

samedi 6 juin 2015

[android] Building the android kernel for the x86_64 emulator

See previous post for more details: Here

my avd is Nexus_5_API_22
export my_avd=Nexus_5_API_22
What is the version of linux running on the x86_64 emulator ?
adb shell dmesg| grep "Linux version"

<5>[    0.000000] Linux version 3.10.0+ (tic@debian) (gcc version 4.9.2 (Debian 4.9.2-10) ) #2 PREEMPT Fri Jun 5 15:07:50 CEST 2015
Oh it's a more recent one than the i386 version!
git checkout remotes/origin/android-goldfish-3.10 -b emu_x86_64
ls arch/x86/configs
i386_defconfig      i386_ranchu_defconfig  x86_64_emu_defconfig
i386_emu_defconfig  x86_64_defconfig       x86_64_ranchu_defconfig
There are more config than before, great it means it is actively developped :)

Ranchu is the successor of goldfish, based on a more resent version of qemu. Linaro team is working on it, It should replace Goldfish in due time. (It even support the android arm64 platform :) )

But for now the emulator which ships with android is goldfish so let's stay with that.
ARCH=x86_64
make x86_64_emu_defconfig
make -j`nproc`
Give it a try:
emulator -kernel arch/x86/bzImage -avd $my_avd -qemu -enable-kvm
I couldn't get it to work with this exact commandline, so I used
emulator64-x86 -kernel arch/x86/boot/bzImage -avd $my_avd -gpu off -qemu --enable-kvm 
That's all! Now developp you own modules ;)

[android] Building the android kernel for the i386 emulator

To build for x86-64, check this article:
http://tic-le-polard.blogspot.fr/2015/06/android-building-android-kernel-for_6.html

Get the goldfish kernel.
git clone https://android.googlesource.com/kernel/goldfish
The master branch is empty, you need to find a commit where arch/x86/configs/goldfish_defconfig exist because the CONFIG options you need to build the kernel correctly for the emulation platform are in it.
Let's list all the different branch of the kernel
git branch -a 
 
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/android-3.10
  remotes/origin/android-3.4
  remotes/origin/android-goldfish-2.6.29
  remotes/origin/android-goldfish-3.10
  remotes/origin/android-goldfish-3.4
  remotes/origin/linux-goldfish-3.0-wip
  remotes/origin/master

Now check what version of the kernel the emulator is running:
Follow the android guide to get android studio : http://developer.android.com/tools/studio/index.html

Create a hello world app and run it in the emulator and create an x86 avd.
(You can also directly use the sdk tools to create them, but here everything is pretty much automated and the configuration is done for you.)

Use adb to connect to the emulator.
Add to your path the platform-tools and tools directory from the sdk directory.
adb devices # list all emulator instances
adb shell dmesg| grep "Linux version"

<5>[    0.000000] Linux version 3.4.67+ (digit@tyrion.par.corp.google.com) (gcc version 4.8 (GCC) ) #3 PREEMPT Tue Sep 16 19:46:22 CEST 2014
Let's get the 3.4 version of the goldfish kernel. It is proved to work :)
git checkout remotes/origin/android-goldfish-3.4 -b emu_x86

ls arch/x86/configs
goldfish_defconfig  i386_defconfig  x86_64_defconfig
Yeah, there is a goldfish config
export ARCH=x86
make goldfish_defconfig
make -j`nproc`
That's it you should have a working kernel for the emulator to test it:
emulator -list-avds
emulator -kernel arch/x86/bzImage -avd $your_avd -qemu -enable-kvm
You are now using your own kernel, you can compile your own modules for it, etc.