Using gdb 7.12-6 - (on debian linux in a virtualbox) I have the problems described below using step
strangely using gdb 7.4.1-debian everything seems to be fine and there are no issues (debian linux in an older virtualbox on a different computer)
I am trying to step through code. I don't want to use next because I want to go into the subroutines I have written.
I am having a problem with it going into malloc.c, s_sin.c and a whole host of other library routines.
I have checked that step-mode is off
I have tried using skip /usr/include/*, skip /usr/include/*/*, skip /usr/include/*/*/*
I already looked at the questions below and didn't find the answer to my question
Preventing GDB from stepping into a function (or file)
gdb - skip further step in of certain file by predefined rule?
Any help would be much appreciated
[I am compiling with gcc -g -o program program.c -lm]
Related
Let me preface this, I am very new to linux and to working on a non-IDE based setup.
I am trying to debug a very simple C program using vs code version 1.55
I unloaded all modules beforehand, so vs code can load appropriate default gcc & gdb versions (which it did, GCC 8.2)
I am following the VS code getting started documentation for setting up and everything seems very straight forward until I try to debug.
I use the default settings as instructed, the file builds successfully but then I get the below
/usr/bin/gdb: symbol lookup error: /usr/bin/gdb: undefined symbol: PyUnicodeUCS4_FromEncodedObject
please note that I cannot rebuild python with ucs4 enabled as suggested in another thread as I have no root access. however I can change VS code version to an earlier one if this will help.
Thanks.
I think this issue is specific to my environment but I will post the answer anyway as it may face someone else.
So this for me was 2 separate issues:
First gdb doesn't start and second vs code can't start gdb.
To check if this is the case try to launch gdb from terminal (not vs code) by typing gdb in the terminal (after loading gdb if needed), I was receiving the error above
Solution to this part is this as T0maas thankfully suggested above
Steps for linux newbies:
ldd gdb (or /usr/bin/gdb) (with vs_code loaded)
from step one get the python library path
unload all modules
load gdb
LD_PRELOAD=<python path from 1>
bash -c "export LD_PRELOAD"
load vs_code
load gdb
After the above steps writing gdb in the terminal should start gdb
Part 2:
The rest of the problem was when I tried to launch debugging session through the GUI of vs_code (still produced the same error)
In the terminal (after loading gdb) type whereis gdb
For me this produced multiple directories the first of which was /usr/bin/gdb (this is the default used in vs_code launch.json)
Changing that directory in the launch.json file to a different one of the other directories solved the second part of the problem for me.
I built a bunch of simple C programs for school on my Mac (OSX). I had compiled all of the programs and tested them all on my Mac with a Makefile. Everything worked well.
To prep for an assignment tomorrow, I decided to transfer all of these files (compiled and source code) via SSH to the class network (OS is Ubuntu). I wanted to make sure everything worked as expected there.
Once I transferred everything, when I tried to use the Emacs shell to run the compiled programs, I got a Cannot execute binary file error. Then, once I recompiled via my Makefile over SSH on the Ubuntu machine, it worked fine. But why not before?
I know this is obvious to some of you, but I don't know why a compiled C program will run fine on my machine, but then have to be recompiled on a different machine even with the operating systems being different?
Here is an example of my Makefile compile commands:
example: example.c
gcc -Wall -pedantic -ansi example.c -o example
I'm pretty new to C (obviously). This question, Why does my program run on Ubuntu gcc but not OSX gcc?, seems similar but I don't understand the answer.
Like other have mentioned the C code might be compatible but Linux and OSX use different binary formats which are not compatible. Thus you will need to recompile to make your code run on the other platform.
Linux uses a binary format called ELF
OSX uses a binary format called Mach-O
See Is a Linux executable “compatible” with OS X? for a more in depth explanation.
so to add to Marius's very good explanation:
they actually use the same x86-64 (amd64) calling convention (ABI) so they are compatible on another level, deeper than just C... but they are packaged in different object file formats (as described by Marius).
The other major difference is the linker... so while they both implement std C functions, they are in different libraries so if they are dynamically linked the symbols are in the wrong place.
I'm trying to compile a simple C program on mac However I can't ever seem to get Xcode to work so I want something else. I also want to check the code for errors while I'm running it anyone got a good idea?
open Terminal, cd to your source directory,
then type gcc -Wall yourProgram.c -o YourProgram and if everything is good, you will be able to execute the program typing ./YourProgram
Also, if you are just learning C, then do not use IDEs just yet. get used to the terminal and as your experience builds, move to an IDE.]
Also there are tools like lint that analyze your code statically. Use gdb and if available, use valgrind as well for runtime debugging. I am not sure if valgrind is available on mac. Have a look at dtrace and how to use it.
I am trying to run a MPI program with C language.
I have installed GCC compiler and the openmpi libraries. I am running ubuntu Linux and Netbeans IDE. My challenge is that after including ‘mpi.h’ in my header file and compiling the application, I still get ‘fatal error : cannot find file mpi.c’. I have the files in home/user/lib/openmpi/include, but I cant get it too work.
Can anyone help?
You could try to change the compiler to /path/mpicc and the debugger to mpirun. This should work, although I did not test it, but probably the best way to compile MPI code is via terminal.
If you really depend on the IDE you cound try writing your code with it (to take advantage of auto-completion and such) and compile it in terminal using mpicc -o main.exe main.cpp [other .cpp files] and run it with mpirun -np number_of_processes_to_use ./main.exe [args]. You could write a small script or a Makefile to do it all in one command.
Good luck!
to save yourself some sanity, I'd recommend opening up a terminal and going from there (at least until you figure out what's what).
Also, using the mpi compiler to do things would simplify your life. (and likely automatically solve the missing source issue, as it should know where they are by default).
If you still can't locate them during compile then I'd look at adding the location where mpi.c & mpi.h are located to your C Include Path: How to add a default include path for gcc in linux?
I just started learning C, and I am looking for a simple tool for debugging in gcc environment. Such tool would print a stack trace, and indicate where a segmentation fault occurs.
Try gdb; or a frontend like ddd or kdgb.
Compile with the -g flag.
GDB does it all - you need to compile your program with debug information (use -g switch) and then open it with GDB. To print stack trace use command bt.
To investigate segfaults you need to pass path to core file to GDB as well, like this:
gdb yourprogram core
If your system by default doesn't generate core files in case of segfault, you can switch it on using command:
ulimit -c unlimited
GDB is what you are looking for. In particular, the backtrace command in GDB will show you a stack trace. http://www.cs.cmu.edu/~gilpin/tutorial/
If you use X try "ddd"
Whether you use the command line gdb, or one of the front-ends such as DDD, you should definitely take a look at the gdb manual, which is also (like many GNU manuals) a very good tutorial.
I would also advise to look at valgrind.
There's also a nice integration of gdb in kdevelop (the emacs binding is fine too..)