summaryrefslogtreecommitdiff
path: root/doc/dlt_howto_debug.txt
blob: 380f49b3c335c80a80bb0815989cddf2911d9557 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
////
# SPDX license identifier: MPL-2.0
#
# Copyright (C) 2011-2015, BMW AG
#
# This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
#
# This Source Code Form is subject to the terms of the
# Mozilla Public License (MPL), v. 2.0.
# If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# For further information see http://www.genivi.org/.
////

How To - Debug DLT Daemon
=========================
Lassi Marttala <Lassi.LM.Marttala@partner.bmw.de>
0.0.1, 2013/03/18: Initial version

image::images/genivi_chrome_1_transparent.png[width=128]

== How to set up Eclipse, tools and project for debugging dlt-daemon
This document describes how to set up an Eclipse development environment with minimal tool set and set up a project to compile and debug dlt-daemon.

This document was written using KUbuntu 12.10 desktop. Any dpkg based Linux distribution should work equally well.

The purpose is to provide the user with a clean working environment, where:

* Build directory can be completely separated from source directory
* There is no need to create need project files every time a user wishes to clean their working tree
* dlt-daemon, library and all tools can be compiled from Eclipse UI without command line
* Debugger can be easily launched for any of the binaries in dlt-daemon project

Anything in
----
code
----
in this document is considered a command line command. Please use your preferred terminal emulator.

=== Prerequisites
Instructions on how to install needed base tools for compilation.

==== Linux Desktop
You can use any Linux Desktop environment that provides the needed packages for compilation of dlt-daemon and for running Eclipse. This document assumes you already have a dpkg-based Linux Desktop running, such as Debian, Ubuntu, Kubuntu or Xubuntu.

==== C/C++ Compilers and Linker
----
sudo apt-get install gcc g++
----
This will install GNU C and C++ compilers, the linker and basic libraries for compilation.

Purpose: Needed for compilation of C and C++ programs.

==== Zlib-devel
----
sudo apt-get install zlib1g-dev
----
This will install the zlib compression library and development headers.

Purpose: Needed for compiling dlt-system with file compression support.

==== CMake
----
sudo apt-get install cmake
----
This will install cmake and any needed dependencies.

Purpose: DLT utilizes cmake for build management.

==== Git
----
sudo apt-get install git
----
This will install git version control tool.

Purpose: dlt-daemon version control is managed using git. Git is needed to clone the source code repository.

==== Java
----
sudo apt-get install default-jdk
----
This will install the default Java Development Kit for you Linux Distribution. For Kubuntu this is OpenJDK 7.

Purpose: Eclipse needs Java to run. JDK is not strictly needed. You might be able to substitute with _*default-jre*_. This is untested, thought.

=== Install Eclipse
Download _"Eclipse IDE for C/C++ Developers"_  from http://www.eclipse.org/.

At the time of writing, _"Eclipse CDT Juno"_ was the latest version.

Extract the package to a directory. You should now have directory named "eclipse", which contains a binary called "eclipse". You should be able to start Eclipse by double clicking on the binary. In case there are problems, make sure you have proper permissions for the directory, sub-directories and that the binary has "executable"-flag set.
----
chmod u+x eclipse
----
if required.

On first start-up, Eclipse will ask for a workspace directory. Select a directory, under which you want to keep your Eclipse project directories.

image:images/eclipse-workspace.png[]

After the startup, you are greeted with a "Welcome"-screen. Dismiss the window and you should be now in an empty C/C++ development perspective:
image:images/eclipse-cpp-perspective.png[]

You have a working Eclipse now. Next we need to get the source code for dlt-daemon.

=== Acquire dlt-daemon Source
Create a directory under which you want to store your source code. Then change to it.
----
mkdir ~/git
cd ~/git
----

Clone the dlt-daemon repository, from the OSS server:
----
git clone http://git.projects.genivi.org/dlt-daemon.git
----

Test that the current software is compilable.
----
cd dlt-daemon
mkdir build
cd build
cmake ..
make
----

If these commands succeeded, you can continue. If there were errors, please remedy them before proceeding.

Clean up the git directory. The following command will delete all files that are not part of the repository. Please use caution.
----
git clean -fdx
----

Now you have a working source directory. We can proceed to setting up the Eclipse project.

Your source directory will be called DLT_GIT_DIR from now on in this document.

=== Eclipse Project
Now, return to your Eclipse. You should have the default C/C++ perspective open.

Click on "File -> New -> C Project"

A new dialogue will open:

image:images/eclipse-create-c-project.png[]

Name the project _"dlt-daemon"_.

Select: _"Makefile project -> Empty Project"_ from the left and _"-- Other Toolchain --"_ from the right.

Make a note of the project location. This will be know *DLT_PROJECT_DIR* from now on in this document.

Click _"Next"._

Click _"Advanced settings..."_ in the following dialog.

image:images/eclipse-project-props-1.png[]

In the _"C/C++ Build"_-page, set build directory to *$\{workspace_loc:/dlt-daemon\}/build

image:images/eclipse-project-props-3.png[]

In the _"C/C++ Build -> Settings"_-page, _"Binary Parsers"_-tab *Check* _"Elf Parser"_

image:images/eclipse-project-props-4.png[]

In the _"C/C++ General -> Preprocessor Includes"_-page, _"Providers"_-tab, *check* both _"CDT GCC"_-options.

*Click* "OK".

*Click* "Finish"

We still need to define a new custom tool, to generate the needed makefiles, from cmake-files:

From the main menu of Eclipse, *click* _"Run -> External Tools External Tools Configurations."_.

In the new window, *click* in the top-left small icon _"New Launch Configuration"_.

image:images/eclipse-external-tools-props-1.png[]

Name the new tool "cmake".

Point it to the cmake binary.

Working directory should be DLT_PROJECT_DIR/build

Arguments should include "-DCMAKE_BUILD_TYPE=DEBUG" and final argument should be your DLT_GIT_DIR

image:images/eclipse-external-tools-props-2.png[]

In the _"Build"_-tab, *uncheck* _"Build before launch"_

*Click* _"Apply"_ +
*Click* _"Close"_

At this point, make sure that DLT_PROJECT_DIR/build, exists. If it doesn', create an empty directory. +
Refresh the project by selecting the project from the left and hit "F5".

Let's test it!

Click _"Run -> External Tools -> cmake"_. cmake should now configure the project and finish with:

_"Build files have been written to: DLT_PROJECT_DIR/build"_

Click _"Project -> Build All"_. The normal "make" progress should commence and you should be left with build project.

Click _"Run -> Debug"_. You should be greeted with dialog like this:

image:images/eclipse-debug-which.png[]

Select _"dlt-daemon"_ from the list and *click* _"OK"_.

Select _"gdb/mi"_ from the following dialog, and *click* _"OK"_.

Click _"Yes"_ when Eclipse asks if you want to switch to the debug perspective.

image:images/eclipse-debug-perspective.png[]

*Congratulations! You are now in debugger.*

*Click* the red square to terminate the application, and click the _"C/C++ Perspective"_ from the top right.

There's one more thing we need to do, to make your life easier.

*Right click* on the _"dlt-daemon"_-project and select _"Import"_ .

In the following dialog, select _"General -> File system"_ and *click* _"Next"_

image:images/eclipse-import-links.png[]

*Click* _"Browse"_ and navigate to your DLT_GIT_DIR.

*Check* _"dlt-daemon"_ root directory.

*Click* _"Advanced"_ and *Check* _"Create links"_ and _"Create virtual folders"_.

*Click* _"Filter types..."_ and only check the file types you want to see _"*.c, *.h"_ is sufficient for most cases.

*Click* _"Finish"_

You now have the source code also easily accessible from the project tree:

image:images/eclipse-cpp-perspective-2.png[]

*All done!*