gdb not found

Hello,

I am having problem with debugging my code. I am writing a C code and then I compile it with the Makefile. I make a target file and then copy it in my Robot(Khepera III) and then run the program over there.

I compile it ofcorse on my machine and then copy the compiled file in the robot.

I am having problem with debugging the code. I am writing it the code on the vi editor and wants to run GDB debugger to debug the code , as I have no other way to do it.

But the GDB debugger seem to run on the executable file. I compile it using the target file , n then if am using the .o file to run in the gdb debugger, it says:

"executable file not found"

I am having hard time to debug this code :frowning:

Can anyone please suggest me, how I cna efficiently debug my code, as other wise am using printf statements to do that.

But am having hard time to do that way.

I will be really glad if someone can suggest me other way or some solution to it.

Thanks a tonn in advance.

Regards

If I understand your post, you are not using gdb correctly.
With no robot, compile your code.
cd to that directory, where your code and source currently are.

gdb mycode
gdb> br main           <- start debugging at the first line in main
gdb> r  [any arguments to the code go here just like you would type them on the command line]

At this point you are in the code. Use the step, list, print to move thru the code, print a variable, show the surrounding lines of code.

IF you have a problem line

br [problem line num]

. If you have a problem function br

[function name]

Any time you want to quit: type q and answer y, for help: type help.

.o files are not executable files. You can't run them in any fashion, gdb or not. They're just intermediate files the linker uses to build the actual executable.

Thank you Jim for replying.

I am running the gdb debugger as u said, but the gdb says the following:

gdb>
Starting program:
No executable file specified.

(I make a Makefile in which it is getting compiled n then it make a target file which gets copied to the robot. I had to do so....coz it had some libraries which needed to be compiled for the robots which were not supported by gnu)

So now after that it sees the file, but it doesn't see the executable file.

So am not sure if this debugger would even work in this case or not.

So you copy the executable file to the robot, and run the debugger on the robot? Can you ldd filename on the robot to see if there's perhaps any shared libraries missing, etc?

You should be able to gdb anything, though symbols may not be available for proprietary things not built with debugging support.

"no executable file specified" is an odd error. Are you specifying the file on the commandline? "gdb ./filename", not just "gdb"? Sometimes weird error messages can happen from dynamic link problems, but...

@Corona688:

I tried to run gdb both on my machine and on the robot.

ON my machine it is giving me the problem, I just talked about and on the robot it is saying the following:

-sh: gdb: not found.

so am prob. thinking of installing gdb on my robot, if there is any way, but not sure if it will work at all.

and also am running gdb by : gdb filename

to run an executable

gdb myprogram

What function would running it on your local machine serve? They're probably not even the same architecture.

"file not found" can sometimes, and bafflingly, mean "incorrect architecture". You can't run or debug ARM executables on an x86 machine.

This is what you have to do. I don't see why it wouldn't be possible, the robot you're using is a linux machine at core. You might end up needing to build it yourself in your ARM cross-compiler.

@Corona688:

I tried to install gdb on my robot but it has total of 12 MB hard drive whereas, gdb needs atleast 15MB.

So it is giving me "not enough space" error. So i guess would need to debug only with the printf statements :frowning:

By 'gdb needs 15 megabytes' do you mean 'the source tarball is 15 megabytes'? You don't need to copy over the whole source tarball. Build it on your PC system with your cross compiler and copy over only the executable, and the files it needs to run.

Or if there's some harebrained binary package available that somehow wastes 15 megs of space, extract it manually on your PC and copy over only the minimum things it needs to run. The gdb executable on my system is 3.4 megs in size, and the things it needs under /usr/share/gdb/syscalls/ only a few kilobytes in size.

If you end up printf-ing, try 'fprintf(stderr, "string%d", 4); instead of plain printf, printing to stderr will ensure that it prints unbuffered, i.e. printf("the result is: "); code_that_crashes; ...will probably print nothing, while fprintf(stderr, "the result is: "); code_that_crashes; will print "the result is:" before crashing.

@Corona688:not sure how to copy the executables to the robot.....bt. tried fprintf and definitely it's lotttt better than printf.

Thank you so much, it helped a lott!!!!!