This is what helped me out(If any beginner is out here and searching for the solution)
Assumptions: Ubuntu(17.04)-> Host & Raspberry Pi (Model-3b) -> Target, My executable (.o) file-> dowhile
Step 1: Make executable file (.o) file for your target from your host machine. Please find follow command:
arm-linux-gnueabihf-gcc -g dowhile.c -o dowhile
Please download respective libraries to run this command successfully.
Step 2: Copy the generated executable file (dowhile.o) to the target machine like stated below:
scp dowhile root@10.x.y.z:/xxxx/yyyy/
(Please fill x and y details according to your target and source)
Also, check the copied executable is working fine:
./dowhile
Step 3: Run gdbserver
on your target machine:
gdbserver localhost:2000 dowhile
(Keep 2000 or any number for your port, it will work anyway)
Step 4: Run gdb
on your host machine:
gdb-multiarch dowhile
Step 5: Set architecture as arm
(gdb) set architecture armv5te
Step 6: Connect your target remotely
(gdb) target remote 10.x.y.z:2000
And you are done :)
Happy debugging!!!