Updated GDB ini file to load binding symbols directly from SDK
[apps/agl-service-unicens.git] / README.md
1 ------------------------------------------------------------------------
2 AGL-Unicens binding expose Unicens-V2 APIs through AGL framework
3 ------------------------------------------------------------------------
4
5
6 AFB_daemon dependency on Standard Linux Distributions
7 -------------------------------------------------------
8     # handle dependencies > (OpenSuse-42.2, Fedora-25, Ubuntu 16.04.2LTS)
9     gcc > 4.8
10     systemd-devel (libsystemd-dev>=222) 
11     libuuid-devel
12     file-devel(OpenSuSe) or libmagic-dev(Ubuntu)
13     libjson-c-devel
14     alsa-devel
15     ElectricFence (BUG should not be mandatory)
16     libopenssl-devel libgcrypt-devel libgnutls-devel (optional but requested by libmicrohttpd for https)
17
18     OpenSuse >=42.2 
19       zypper in gcc5 gdb gcc5-c++ git make ElectricFence systemd-devel libopenssl-devel  libuuid-devel alsa-devel libgcrypt-devel libgnutls-devel libjson-c-devel file-devel 
20
21     Ubuntu >= 16.4 libuuid-devel
22       apt-get install cmake git electric-fence libsystemd-dev libssl-dev uuid-dev libasound2-dev libgcrypt20-dev libgnutls-dev libgnutls-dev libjson-c-dev libmagic-dev
23
24     libmicrohttpd>=0.9.54 (as today OpenSuse-42.2 or Ubuntu-.16.4 ship older versions)
25     afb-daemon from AGL Gerrit git clone https://gerrit.automotivelinux.org/gerrit/src/app-framework-binder
26
27 ```
28     # Might want to add following variables into ~/.bashrc
29     echo "#----------  AGL options Start ---------" >>~/.bashrc
30     echo "# Object: AGL cmake option for  binder/bindings" >>~/.bashrc
31     echo "# Date: `date`" >>~/.bashrc
32     echo 'export CC=gcc-5; export CXX=g++-5' >>~/.bashrc   # if using gcc5 
33     echo 'export INSTALL_PREFIX=$HOME/opt' >>~/.bashrc
34     echo 'export LD_LIBRARY_PATH=$INSTALL_PREFIX/lib64:$INSTALL_PREFIX/lib' >>~/.bashrc
35     echo 'export LIBRARY_PATH=$INSTALL_PREFIX/lib64:$INSTALL_PREFIX/lib' >>~/.bashrc
36     echo 'export PKG_CONFIG_PATH=$INSTALL_PREFIX/lib64/pkgconfig:$INSTALL_PREFIX/lib/pkgconfig' >>~/.bashrc
37     echo 'export PATH=$INSTALL_PREFIX/bin:$PATH' >>~/.bashrc
38     echo 'export RSYNC_TARGET=MY_TARGET_HOSTNAME' >>~/.bashrc
39     echo 'export RSYNC_PREFIX=./opt' >>~/.bashrc
40
41     echo "#----------  AGL options End ---------" >>~/.bashrc
42     source ~/.bashrc
43
44     # install LibMicroHttpd
45     wget https://ftp.gnu.org/gnu/libmicrohttpd/libmicrohttpd-0.9.54.tar.gz
46     tar -xzf libmicrohttpd-0.9.54.tar.gz
47     cd libmicrohttpd-0.9.54
48     ./configure --prefix=$INSTALL_PREFIX
49     make
50     make install-strip
51
52     # retrieve last AFB_daemon from AGL
53     git clone https://gerrit.automotivelinux.org/gerrit/src/app-framework-binder
54
55     # Warning: previous GCC options should be set before initial cmake (clean Build/*)
56     cd app-framework-binder; mkdir build; cd build 
57     cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX ..
58     make
59     make install 
60 ```
61
62
63 # Compile binding
64
65 ```
66     source ~/.bashrc  # or any other file where your have place your compilation preferences
67     mkdir build
68     cd build
69     cmake -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX ..
70     make
71
72     afb-daemon --workdir=.. --ldpaths=build --port=1234  --roothttp=./htdocs --token="" --verbose
73
74     speaker-test -twav -D hw:ep01 -c 2
75     firefox http://localhost:1234
76 ```
77
78 # Local Source Debug with GDB
79
80 Warning: technically AGL bindings are shared libraries loaded thought 'dlopen'. GDB supports source debug of dynamically
81 loaded libraries, but user should be warn that the actual path to sharelib symbols is directly inherited from DLOPEN.
82 As a result if you change your directory after binder start with --workdir=xxx then GDB will not find symbols anymore
83
84
85 ```
86     Examples:
87     
88     # WORK when running in direct
89     afb-daemon --workdir=.. --ldpaths=build --port=1234 --roothttp=./htdocs
90
91     # FAIL when using GDB with warning: Could not load shared library ....
92     gdb -args afb-daemon --workdir=.. --ldpaths=build --port=1234 --roothttp=./htdocs
93     ...
94     warning: Could not load shared library symbols for ./build/ucs2-afb/afb-ucs2.so.
95     Do you need "set solib-search-path" or "set sysroot"?
96     ...
97 ```
98
99 To debug sharelib symbol path: start your binder under GDB. Then break your session after the binder has
100 loaded its bindings. Finally use "info sharedlibrary" and check 'SymsRead'. If equal to 'No' then either you start GDB
101 from the wrong relative directory, either you have to use 'set solib-search-path' to force the path.
102
103 ```
104     gdb -args afb-daemon --workdir=.. --ldpaths=build --port=1234 --roothttp=./htdocs
105     run
106         ...
107         NOTICE: API unicens added
108         NOTICE: Waiting port=1234 rootdir=.
109         NOTICE: Browser URL= http://localhost:1234
110     (hit Ctrl-C to break the execution)
111     info sharedlibrary afb-*
112 ```
113
114
115 # Running an debugging on a target
116
117 ```
118 export RSYNC_TARGET=root@xx.xx.xx.xx
119 export RSYNC_PREFIX=/opt    # WARNING: installation directory should exist
120
121 mkdir $RSYNC_TARGET
122 cd    $RSYNC_TARGET
123
124 cmake -DRSYNC_TARGET=$RSYNC_TARGET -DRSYNC_PREFIX=$RSYNC_PREFIX ..
125 make remote-target-populate
126
127     ./build/target/start-${RSYNC_TARGET}.sh
128     firefox http://localhost:1234    # WARNING: do not forget firewall if any
129
130     ssh -tt ${RSYNC_TARGET} speaker-test -twav -D hw:ep01 -c 2
131 ```
132
133 Note: remote-target-populate will
134  - create a script to remotely start the binder on the target in ./build/target/start-on-target-name.sh
135  - create a gdbinit file to transparently debug remotely in source code with gdb -x ./build/target/gdb-on-target-name.ini
136  - to run and debug directly from your IDE just configure the run and debug properties with the corresponding filename
137
138 Note that Netbeans impose to set debug directory to ./build/pkgout or it won't find binding symbols for source debugging
139
140