I used to use GDB to debug my C/C++ program. But after the server crashed and reinstalled, the GDB is not working properly. After the program reports a 'core dumped', actually the core file is not found. My flags to compile is:
CFLAGS= -ggdb -g -pg -Wall -O2 $(shell pkg-config --libs glib-2.0 gthread-2.0 --cflags glib-2.0)
And I also set this:
ulimit -c unlimited
I already remove all object/executable files and recompile. But the core file is simply missing. Could anybody tell what is other probable reason? Thanks.
On my machine (Ubuntu 12.04), the file /proc/sys/kernel/core_pattern pipes the core dumped result to /usr/share/apport/apport:
|/usr/share/apport/apport %p %s %c
So changed to pattern:
sudo bash -c 'echo core.%e.%p > /proc/sys/kernel/core_pattern'
It works.
Reference: Unable to create a core file for my crashed program
Related
I am trying to use gdb to debug an hdf5 C++ application that I have written. The h5 package that I am using was installed using conda. The command that I am using is:
h5c++ hdf5.cpp
This generates an executable which I then run with gdb as follows:
gdb a.out
gdb launches alright. But when I add breakpoint using:
b 10
or any line number, it gives a message: No line 10 in file "init.c"
When I press run, it runs the whole program at once (which I don't want) and exits. The h5c++ -show command gives the following output:
x86_64-conda_cos6-linux-gnu-c++ -I/i3c/hpcl/sms821/software/tensorflow/anaconda2/include -D_FORTIFY_SOURCE=2 -O2 -g -fvisibility-inlines-hidden -std=c++17 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -I/i3c/hpcl/sms821/software/tensorflow/anaconda2/include -fdebug-prefix-map==/usr/local/src/conda/- -fdebug-prefix-map==/usr/local/src/conda-prefix -L/i3c/hpcl/sms821/software/tensorflow/anaconda2/lib /i3c/hpcl/sms821/software/tensorflow/anaconda2/lib/libhdf5_hl_cpp.a /i3c/hpcl/sms821/software/tensorflow/anaconda2/lib/libhdf5_cpp.a /i3c/hpcl/sms821/software/tensorflow/anaconda2/lib/libhdf5_hl.a /i3c/hpcl/sms821/software/tensorflow/anaconda2/lib/libhdf5.a -L/i3c/hpcl/sms821/software/tensorflow/anaconda2/lib -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-rpath,/i3c/hpcl/sms821/software/tensorflow/anaconda2/lib -L/i3c/hpcl/sms821/software/tensorflow/anaconda2/lib -g -lrt -lpthread -lz -ldl -lm -Wl,-rpath -Wl,/i3c/hpcl/sms821/software/tensorflow/anaconda2/lib
I think this has to do with the compiler the compiler that it is using. I tried replacing x86_64-conda_cos6-linux-gnu-c++ with my native g++ compiler in the h5c++ script but that gives linker error.
Please suggest how should make my h5 application work with gdb. Should I install hdf5 from source since I don't have sudo access? I am working on a Linux machine.
I simply installed hdf5 from the source files. While configuring the installation I turned the --enable-build-mode and --enable-symbol switches. Hdf5 has a dependency on szip which I also installed from source code. My exact configuration was as follows:
./configure --prefix=<hdf5 install directory> --enable-cxx --enable-build-mode=debug --enable-symbols=yes --enable-profiling=yes --with-szlib=<szip install directory>
The above solution worked and I was able to compile my h5 application using h5c++ hdf5.cpp and also use gdb to debug it.
In many tutorials I saw sdl-config for compile a sdl c program. In c++ examples I have seen too.
Here is an example from here.
g++ sdlExample.cpp `sdl-config --cflags --libs` -o sdlExample
What does the sdl-config --cflags --libs mean ? Why inside accent ?
In a shell, where your command is executed, the reverse quotes imply command substitution. So, basically, whatever is within reverse quotes is executed as a command, and its output is substituted.
Example:
echo Today is `date`
Will first execute the date command, and substitute it's output.
echo Today is Sat Dec 19 14:32:13 EST 2015
Which is then executed to produce:
Today is Sat Dec 19 14:32:13 EST 2015
So, in your command,
g++ sdlExample.cpp `sdl-config --cflags --libs` -o sdlExample
The shell will first execute,
sdl-config --cflags --libs
And substitute its output,
g++ sdlExample.cpp <output of the above command> -o sdlExample
And then finally execute the resulting command line.
To see what is actually executed after command substitution, just add echo in the front.
echo g++ sdlExample.cpp `sdl-config --cflags --libs` -o sdlExample
This will show you the resulting command line.
Note that there is an alternative syntax for command substitution as well, which is preferred when you have complex, nested substitutions.
echo g++ sdlExample.cpp $(sdl-config --cflags --libs) -o sdlExample
This is a pretty standard technique to generate proper command line options for a library / framework, where the options depend on installation etc. In this case, the sdl-config command generates the necessary compiler options (cflags and libs) for the sdl package. You can experiment with what else it can do by executing it directly on the command line.
sdl-config --cflags --libs
sdl-config man page
It just outputs appropriate flags to pass on to the compiler, similar to what pkg-config does with its .pc files (located in /usr/lib/pkgconfig).
I've written a program, saved it on the desktop under the name 'Swap.cpp' and when I run gdb (the first time), I get the error:
"/Users/myname/Desktop/Swap": not in executable format: File format
not recognized.
I have no idea what I'm doing wrong. Any help will be appreciated.
Sorry I should've given more information:
I am using Mac OS.
I've already compiled the program and have the Swap.o file that I can see on my desktop.And here are the commands that I enter while trying to run the debugger from bash:
$ clang++ -g Swap.cpp -o Swap
$ ./Swap
this runs Swap and then I try to access the debugger using:
$ gdb Swap
that then gives me the aforesaid message. I tried doing what Rakholiya Jenish suggested but to no avail.
To run gdb on windows:
path_to_gdb.exe program_to_debug
If the compilation was not proper, either compile it with your IDE (if you are using) or with g++ using cmd.exe as:
g++ -g Swap.cpp -o output -lm
I figured out how to use lldb instead of gdb. lldb works just fine. Here is what I did:
$ clang++ -g -o Swap Swap.cpp
$ lldb Swap
Thank you all for your help.
new update
I think I should edit the title now.
To make sure I got a clean environment, I
download qt5.1.1 src code from qt-prject.
export QNX_TARGET, QNX_HOST, AND add QNX_HOST into PATH.
then Run the script
./configure -opensource -confirm-license -xplatform qnx-armv7le-qcc -v
so in here, -opensource -confirm-license just avoid the Q&A -v is to show full message.
a lot of error message.
Creating qmake...
make: Nothing to be done for `first'.
Running configuration tests...
Determining architecture... ()
qcc -Vgcc_ntoarmv7le -c -Wno-psabi -lang-c++ -g -Wall -W -fPIE -DQT_NO_CLIPBOARD -I../../mkspecs/qnx-armv7le-qcc -I. -I/opt/qnx650/target/qnx6/usr/include -I/opt/qnx650/target/qnx6/usr/include/freetype2 -o arch.o arch.cpp
Unable to determine architecture!
Could not determine the target architecture!
Turn on verbose messaging (-v) to see the final report.
Determining architecture... ()
g++ -c -pipe -g -Wall -W -fPIE -I../../mkspecs/linux-g++ -I. -o arch.o arch.cpp
g++ -o arch arch.o { test -n "" && DESTDIR="" || DESTDIR=.; } && test $(gdb --version | sed -e 's,[^0-9]\+\([0-9]\)\.\([0-9]\).*,\1\2,;q') -gt 72 && gdb --nx --batch --quiet -ex 'set confirm off' -ex "save gdb-index $DESTDIR" -ex quit 'arch' && test -f arch.gdb-index && objcopy --add-section '.gdb_index=arch.gdb-index' --set-section-flags '.gdb_index=readonly' 'arch' 'arch' && rm -f arch.gdb-index || true
Found architecture in binary
CFG_HOST_ARCH="x86_64"
CFG_HOST_CPUFEATURES=" mmx sse sse2"
System architecture: 'unknown'
Host architecture: 'x86_64'
C++11 auto-detection... ()
qcc -Vgcc_ntoarmv7le -c -Wno-psabi -lang-c++ -O2 -Wc,-std=gnu++0x -Wall -W -fPIE-DQT_NO_CLIPBOARD -I../../../mkspecs/qnx-armv7le-qcc -I. -I/opt/qnx650/target/qnx6/usr/include -I/opt/qnx650/target/qnx6/usr/include/freetype2 -o c++11.o c++11.cpp
C++11 disabled.
floatmath auto-detection... ()
qcc -Vgcc_ntoarmv7le -c -Wno-psabi -lang-c++ -O2 -Wall -W -fPIE -DQT_NO_CLIPBOARD-I../../../mkspecs/qnx-armv7le-qcc -I. -I/opt/qnx650/target/qnx6/usr/include -I/opt/qnx650/target/qnx6/usr/include/freetype2 -o floatmath.o floatmath.cpp
qcc -Vgcc_ntoarmv7le -c -Wno-psabi -lang-c++ -O2 -Wall -W -fPIE -DQT_NO_CLIPBOARD -I../../../mkspecs/qnx-armv7le-qcc -I. -I/opt/qnx650/target/qnx6/usr/include -I/opt/qnx650/target/qnx6/usr/include/freetype2 -o freetype.o freetype.cpp
FreeType disabled.
STL auto-detection... ()
qcc -Vgcc_ntoarmv7le -c -Wno-psabi -lang-c++ -O2 -Wall -W -fPIE -DQT_NO_CLIPBOARD -I../../../mkspecs/qnx-armv7le-qcc -I. -I/opt/qnx650/target/qnx6/usr/include -I/opt/qnx650/target/qnx6/usr/include/freetype2 -o stltest.o stltest.cpp
STL disabled.
STL functionality check failed! Cannot build Qt with this STL library.
Turn on verbose messaging (-v) to /home/pasadeveloper/qt-everywhere-opensourcesrc-5.1.1/qtbase/configure to see the final report.
UPDATE:
I am working on QNX for ARM, target is an arm platform device.
Thing is getting weird. in Env Var, I put
$QNX_CONFIGURATION=/etc/qnx
$QNX_JAVAHOME=/opt/qnx650/_jvm
$QNX_TARGET=/opt/qnx650/target/qnx6
$QNX_HOST=/opt/qnx650/host/linux/x86
but when I do qmake qmake.conf mkspecs/qnx-armv7le-qcc folder
it returns an error message Project ERROR: QNX_TARGET environment variable not set
Have no clue what is going on now.
not just qmake qmake.conf
I try to build qt 5.1.2 at another host, ubuntu 12.04-64bit.
also get the same error message. Project ERROR: QNX_TARGET environment variable not set
I was working at Qt development under linux(FYI Ubuntu 12.04 -64bits), but I need to compile this program to binary for QNX.
I install QNX MOmentics IDE which provide QNX-gcc for me.
but I can't find the qmake-qnx.
Under the QT/gcc_64/mkspecs/qnx-armv7le-qcc, there is a file call qmake.conf. I guess this is where I can generate my qmake-qnx. after I run qmake -o Makefile qmake.conf, there is a Makefile generated.
However, when I run make, error occured.
qcc -Vgcc_ntoarmv7le -lang-c++ -Wl,-rpath-link,/opt/qnx650/target/qnx6/armle-v7/lib -Wl,-rpath-link,/opt/qnx650/target/qnx6/armle-v7/usr/lib -Wl,-O1 -Wl,-O1 -Wl,-rpath,/home/pasadeveloper/Qt5.1.0/5.1.0/gcc_64 -Wl,-rpath,/home/pasadeveloper/Qt5.1.0/5.1.0/gcc_64/lib -o qmake -L/opt/qnx650/target/qnx6/armle-v7/lib -L/opt/qnx650/target/qnx6/armle-v7/usr/lib -lm -L/home/pasadeveloper/Qt5.1.0//5.1.0/gcc_64/lib -lQt5Gui -lQt5Core -lGL -lpthread
cc: no files to process
make: *** [qmake] Error 1
pasadeveloper#ubuntu:~/Qt5.1.0/5.1.0/gcc_64/mkspecs/qnx-armv7le-qcc$
You do not "generate" your qmake-qnx like that. You are supposed to use the native qmake for generating proper makefiles for your target to aid the cross-compilation. Also, running qmake qmake.conf in the relevant mkspecs folder is wrong because that is not a project file as you may think.
When building Qt itself for instance, you should be using the proper mkspecs files for the target in which case, it is the one you also mentioned above if it is built for that particular arm qnx variant, called qnx-armv7le-qcc.
Here is the exact command you need to run after downloading the relevant Qt sources, like 5.1.1:
./configure -opensource -confirm-license -xplatform qnx-armv7le-qcc -v
For this QNX version, the bottom line is, if you do not have SP1 and libscreen, it will not work. The QPA plugin would link against it. This library provides the API to the graphics server on newer QNX variants. You need to talk to your QNX representatives.
Here you can find further information about the topic.
$QNX_TARGET=/opt/qnx650/target/qnx6
is probably not doing what you want. In shell scripts, you don't put a "$" in front of a variable when you are defining the variable, only when you access the variable:
X=hello
echo $X
I've got some server in c++ (commands acquired from build-system):
g++ -o obj/server.o -c -m64 -isystem/opt/boost/include -Wall -Werror -march=core2 -ftest-coverage -fprofile-arcs -DGCOV_ENABLED= -Iinclude -I/opt/hydraOST/lzopro/include -I/usr/include/libxml2 -Idaemon/include src/server.cpp
g++ -o bin/server.exe -rdynamic -ftest-coverage -fprofile-arcs -m64 -Wl,-rpath=\$ORIGIN -Wl,-rpath=/opt/hydraOST/lzopro/lib obj/server.o (+ other libs)
As it's daemon and I'm stopping it with signal but to enforce dumping gcov data before kill $PID I'm using gdb:
gdb -p $PID -batch -x gcov/dumpGcovData
where contents of gcov/dumpGcovData:
call __gcov_flush()
thread apply all call __gcov_flush()
I know that linking should be with -lgcov but as it was working in that way so I didn't change it in build system. The problem occured just after added -rdynamic flag (without that flag it worked properly).
I know that linking should be with -lgcov
That is incorrect: gcc will add -lgcov automatically given your flags; no explicit -lgcov needed.
The problem occured just after added -rdynamic flag (without that flag it worked properly).
I can't imagine what -rdynamic may have to do with the problem. A trivial test case shows that it works either way, so either your claim of "it stopped working with addition of -rdynamic" is wrong, or there is some more complicated interaction going on (which I am not reproducing in my trivial test).
You may want to begin by
Verifying that in fact re-linking server.exe without -rdynamic as the only change makes it work again.
Showing the output from g++ -o bin/server.exe ... -Wl,-y,__gcov_flush and readelf -s bin/server.exe | grep __gcov_flush. Here is what it should look like:
g++ -ftest-coverage -fprofile-arcs cov.c -g -rdynamic -Wl,-y,__gcov_flush
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/libgcov.a(_gcov.o): definition of __gcov_flush
readelf -s a.out | grep gcov_fl
66: 00000000004023c0 131 FUNC LOCAL HIDDEN 14 __gcov_flush
After added -Wl,-y,__gcov_flush it printed out line (and flag -rdynamic does not matter):
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/libgcov.a(_gcov.o): definition of __gcov_flush
Unfortunately, looks like -rdynamic flag does not afftect the output:
with -rdynamic:
readelf -s server.exe | grep gcov_flush
1203: 0000000000808370 107 FUNC LOCAL HIDDEN 12 __gcov_flush
and without -rdynamic:
readelf -s server.exe | grep gcov_flush
1203: 0000000000808380 107 FUNC LOCAL HIDDEN 12 __gcov_flush
Anyway, I've got very simple solution (or rather workaround): add -rdynamic ONLY if its build not for gcov:
if CONFIG == gcov:
addFlags(["-ftest-coverage", "-fprofile-arcs"])
else:
addFlags(["-rdynamic"])
So, main problem seems to be not solved, anyway got some workaround (works for me, because I rather don't use gcov config for debugging - just for generating coverage report). Anyway, thanks for help!