Saturday, July 7, 2012

gdb tutorial

Sometimes when you build a project in C++, it might become necessary that the code needs to be changed/added. In such cases, debugging the entire project becomes really very important because you need to ensure that the program flow is correct and no regression takes place.

In this post, we will debug the case study which we implemented in C++ demonstrating the employee register with the help of vectors. To know about how this case study is implemented, read the following posts:
1. Vector Operations - API
2. Vector Operations - Implementation
3. Vector Operations - Implementation part 2

We will use GNU C debugger in order to debug the case study. To start debugging of the case study, first we need to type the following command:

g++ -g "files.cpp"

which in our case transforms to be:

g++ -g EmployeeRegister.cpp Employee.cpp Display.cpp main.cpp

To start debugging, invoke gdb with the following command:

gdb a.out

To debug the entire case study, we will set a breakpoint in main.cpp from the beginning of main function. If you need to debug only a part of a huge project, you can specify that particular file with line number. The idea of this breakpoint is to run the project till that particular breakpoint and from there on, we can inspect or evaluate what each programming statement is actually doing.

break file.cpp:line_no

which in our case is:

break main.cpp:3

Now we want to start running the code line by line with the following command.

run

To go to the next line for debugging, execute the n command in gdb prompt. When you encounter any function and you want to get inside the function definition, use the s command. This is similar to the Step Into functionality in debugging.

In between when you want to check the value of any variable, use the following command:

p variable_name

To exit the GNU C debugger, use the q or quit command.

Now let us use all the above mentioned gdb commands in the case study.



Related Posts:

Vector Operations - API
Vector Operations - Implementation
Vector Operations - Implementation part 2


Sunday, July 1, 2012

Using Eclipse Database Tools -- Access Database from Eclipse IDE


Know Java?? Used Eclipse?? Bored with Database command interface?? Want to access database from Eclipse?? Then this post is for you...
We can access database from the Eclipse IDE itself whenever you want to check some database tables in the middle of a Java or PHP project. So, life becomes easier when you can do everything related to a project in a single tool.

To configure Database access in Eclipse IDE, first we need to open the Database Development perspective. In the Data Source Explorer, you can add a database connection by right-clicking on Database Connection > New.


The list of all the DBMS will be listed in the next wizard as shown below.


Click on the new Driver definition button as indicated in the below figure.


Specify the Driver type > JAR file > Username, Password and Other Database Server details.




You can Test the connection by clicking on the Test Connection Button available in the below wizard. If ping gets succeeded, then click on Next.

Verify whether all the details are correctly filled in and click on Finish.
 

You can see that the new connection added is listed in the Data Source Emplorer view.

The database development perspective in general has Data Source Emplorer, SQL Results, Execution Plan and Bookmarks Views.

The Schemas, Users and Roles on a connected database management system can be viewed in the same Data Source Explorer view.

The SQL Scrapbook can be used to type in SQL commands in Eclipse. You can execute a command by right-clicking on it and selecting the relevant Execute option. Also you can get suggestions as you type in a SQL command in the SQL scrapbook provided by Eclipse.
You can also use SQL Query Builder which is very similar to that of the SQL Scrapbook.

Related Posts Plugin for WordPress, Blogger...