Tag Archives: gdb

How do you do debug using primitive Linux or UNIX using GDB? C++ job interview hint

How do you do debug using primitive Linux or UNIX using GDB? C++ job interview hint
GDB is old but I have heard some more advanced interviews do ask these questions so be prepared on how to do the basics within GDB at a shell command line at a Linux terminal session. It is meant for C++ debugging and make sure you set your GCC compile mode to debug to enable this.
As you would, you need to enter on the shell command line:
GDB interaction:
Gdb convdoll
This will load up your biary n execute program. .
break main
This will set breakpoint in your method like main.
run convdoll
Once set, you need execute program the program using ‘run’.
next
This will then move to the next call within your executable file.
print userInput
This will display any variable values GDB may have access to the point at which it is executing.
There are numerous settings in which you would want to run GDB. If you have a process which is being run by your program , it may strangely hang. All you need to do is the get the process id (PID) it is running on. This can be known by executing ‘ps –ef|grep xxx’ where xxx is your program that hung.
gdb convdoll 9198
9198 would obviously be the process id you want to query on.
Sometimes C++ programs that leak memory may terminate abnormally and generate core files. You can always run through the program’s session by debugging it with GDB. Just do on the command line against a dumped core file.
gdb /system/location/convdoll core
Hope this helps you get past those gnarly questions posed at c++ job interview.

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

C++ interview questions on database, debugging, gdb, arrays

Database:
Suppose your software requires the client to enter information into a database. What do you do if data insertion takes too long?
I said, improve the hardware. Not what he was looking for, but the answer worke
Debugging
in unix one task/process is stuck. How will debug it ?
Attach it to GDB via gdb -p PID and see where its stuck. Now examine various parameter values, to see what they are at the moment (this is convenient the process and libraries were compiled with -g i.e. with debugging information. Otherwise disassemble current (or previous frames) via gdb, and get ready for long session of reading assembly).

Simple function to add two numbers – try to think of all possible ways to debug it –
int range overflow (how to detect) , incorrect inputs, error codes and return values etc.
Arrays:
what all errors is possible if u write past the array bounds?
memory corruption, call stack corruption. In unix, scope is limited to these 2 inside a process. In RTOS, the corruption can span across multiple tasks/processes
you inadvertently overwrite some portion of memory that some pointer or a variable is pointing to when you write past array bounds

HOW DO YOU START A PROFITABLE TRADING BUSINESS? Read more NOW >>>

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!