I have libc6 & libc6-dbg installed.
(gdb) b
reak freeifaddrs
(gdb) run
Breakpoint 1, __freeifaddrs (ifa=0xa822e0) at ../sysdeps/unix/sysv/linux/ifaddrs.c:840
840 ../sysdeps/unix/sysv/linux/ifaddrs.c: No such file or directory.
(gdb) list
835 in ../sysdeps/unix/sysv/linux/ifaddrs.c
(gdb) disassemble
Dump of assembler code for function __freeifaddrs:
=> 0x00007ffff7912fd0 <+0>: jmpq 0x7ffff780f8a8
End of assembler dump.
(gdb) where
#0 __freeifaddrs (ifa=0xa822e0) at ../sysdeps/unix/sysv/linux/ifaddrs.c:840
However, gdb refuse to get me any info about ifaddrs.c, although it knows it is on line 840
What happened here?
The debugging information in the libc6-dbg package includes the names of the source files for the C library, and a mapping from assembly instructions to specific lines within those source files, but it does not include the source files themselves. So gdb can tell you that your breakpoint is associated with line 840 of a file named sysdeps/unix/sysv/linux/ifaddrs.c, but it can't show you what's actually on that line. (The leading ../ is an artifact of glibc's terrifyingly complicated build system.)
If you know where to find the Git repository for the source code for the GNU C Library, then you can look up that specific file and line by hand in a web browser. This is relatively quick and easy once you know how to do it, but probably won't show you the exact same version of the code that was used to build your copy of the library (this file in particular doesn't change very often, but others do), and it doesn't get you access to the code inside gdb.
To get the code visible inside gdb, you would need to download the source package that matches the C library on your system. Based on the package name libc6-dbg I am guessing you are using a Linux distribution in the Debian family; if that's right, the command
apt-get source glibc
will do the job. Then you can use the GDB command directory to tell GDB where to look for the source files. It will probably take a bit of fiddling to get everything working just so.
Related
So, I am working with QEMU, and I have a system of plugins for it, that are using bunch of symbols from the main executable. Everything is working fine in Linux, but porting plugins to windows caused many inconveniences (expectedly).
At first, i struggled with linking against executable. In Linux all you need is an option -rdynamic, that is not presented in windows. Eventually, I found a solution to this problem here. So, I used --export-all-symbols linking option, and I was linking my plugins against an import library generated with -Wl,--out-implib. The result is a working qemu executable, and working plugins at the same time, all working as intended, except for gdb.
I am running gdb from MinGW64 shell like this: $ gdb --args ./qemu-system-i386w testdisk.qcow2 -monitor stdio
(gdb) break tcg-plugin.c:164
Breakpoint 1 at 0x410f1c: file C:/fromgit/plugins_test/qemu-work/tcg/tcg-plugin.c, line 164.
(gdb) run
But then i either get the following error: Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x410f1c
Command aborted.
Or it will start working, but none of breakpoints will be triggered, despite they definetely should.
I thought, that this may be caused by exporting all the symbols from qemu executable, so instead of using --export-all-symbols I qualified needed export symbols with __declspec(dllexport) attribute, but that didn't change anything. Furthermore, I discovered, that adding any export symbols at all to the executable will cause gdb to act faulty, the same way as described earlier.
It should be mentioned, that if I'm building just qemu, without any export symbols, I get an executable that works fine, and gdb is working fine with it.
So the question is - am I missing something? What can possibly cause gdb to not work?
I wanted to start cross compiling for raspberry pi2 on Ubuntu 32bit (in virtual box), so I downloaded the toolchain on the github site (https://github.com/raspberrypi/tools) and tried to compile a simple hello world program with the command (I've included the path to the bin folder that contains arm-linux-gnueabihf-gcc-4.8.3 to the PATH variable.):
arm-linux-gnueabihf-gcc-4.8.3 HelloWorld.c
However, I always get the following error message:
path/to/the/linker/in/the/toolchain/ld:/path/to/the/libc.so.6file/in/the/toolchain/libc.so.6: file format not recognized; treating as linker script
and subsequently a syntax error.
When I look into libc.so.6, I see a single line containing:
libc-2.13.so
The libc-2.13.so file is present in the same folder as the libc.so.6 file. When I invoke
file libc-2.13.so
I get:
libc-2.13.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), BuildID[sha1]=dbd0cdca5a677bea1417be1272f4c5ef43bd3e22, for GNU/Linux 2.6.26, stripped
I don't know what could cause this error since obviously the linker from the toolchain and the libc.so.6 file from the toolchain are processed so the file format should be recognized, right?
Can someone point me in the right direction here? Thanks!
I will suggest you alternate way to do Cross compilation. I tried it and it works. You can use crosstool-NG. It gives you graphical way to setup your toolchain for cross compilation. There are lot of option for setting up toolchain. You can explore that.
Now you are doing for ARM-RPi but tomorrow if your Target CPU changed then it will be very easy to reconfigure the toolchain again.
You can find easy steps given in this article. I hope this works for you.
When I look into libc.so.6, I see a single line containing:
libc-2.13.so
I just ran into this.
The problem is way simpler than you think. When you un-gz'd and untar'd the toolchain, what happened is that libc.so.6 became a text file. It is supposed to be a "symbolic link" file pointing at the correct file "libc-2.13.so".
If you are using windows and 7-Zip, make sure to click "Run AS Administrator" when you start 7-zip. If you simply drag and drop, the error is not so obvious.
In my first effort, I had to include the path to gcc in the command. Then I just compiled programs on the RPi.
~/toolchain/raspbian-toolchain-gcc-4.7.2-linux32/bin/arm-linux-gnueabihf-gcc whets.c
I want to know what libraries, external code were actually used during a program's execution. I am working with Inkscape's source code and interested in its command line function that converts svg to png. I want to strip out all its dependencies that's not needed in this execution path.
I am currently using gcov, but so far that only tells me about the Inkscape's code.
My development environment is Windows 2008, mingw gcc package.
Thanks.
Process Explorer will show you all the libraries loaded at runtime, both static and dynamic. It will also show you any handles actively touched during runtime.
You can also spawn and monitor processes from the UI, provided you have your path setup correctly.
Granted, if you have the source code, you can just search for link options during compile time, check the makefiles. For runtime, break point the LoadLibrary method in gdb. In addition, gdb also has an 'info sharedlibrary' command you can use.
If you have ldd under MinGW just use it:
ldd executable or you may use
objdump -p | grep DLL or even
gprof
I try to debug some native code on Android with GBD. The code wasn't created by me and is not in an Android project, so I can't use the ndk-gdb tool. I use gdbserver on the android machine and connect to it from my mac with the normal GDB program. I try to load all the libraries (which should have symbols according to objdump tool), but gdb tells me that it does not load the symbols (according to the gdb command “info sharedLibrary”). These are the steps I took:
start gdbserver on Android machine
start GDB with the debug version of the binary
gdb symbols/system/bin/mediaserver
the following commands are executed in gdb itself
tell gdb where to look for the libraries with symbols
(gdb) set solib-search-path symbols/system/lib
tell gdb where to find the source files
(gdb) directory /sources
connect to remote target (Android machine)
(gdb) target remote 192.168.1.10:5039
GDB connects successfully to the running binary and I can pause and continue the execution. But it does not show me any debug information like function names or line numbers. It only shows adresses. When I check the status of the used libraries, I see that gdb thinks, they don’t have any symbols:
command in gdb:
(gdb) info sharedLibrary
From To Syms Read Shared Object Library
0x00003700 0x0000ff0c Yes /symbols/system/bin/linker
No libc.so
No libstdc++.so
No libm.so
No liblog.so
No libcutils.so
No libspeexresampler.so
No libaudioutils.so
No libgccdemangle.so
No libamplayer.so
Now for example the last library. When I check with the file command (not in gdb), it tells me that it is a not stripped library (the library is located in the "symbols/system/lib" folder).
file libamplayer.so
Output:
libamplayer.so: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked, not stripped
objdump command shows a lot of symbols in it (I don’t show the output because it’s very long). So why does gdb not recognise the symbols in this libraries? I thought, at least line numbers and function names are present in not stripped versions of libraries. Or am I wrong? It would be very nice if someone could give me more insight.
Thanks!
System info:
GDB Version: 7.3.1-gg2 on Mac OS X Mavericks
The code wasn't created by me and is not in an Android project, so I can't use the ndk-gdb tool.
Your conclusion does not at all follow. ndk-gdb should be able to debug any Android program, whether created as a "project" or via other means.
I use gdbserver on the android machine and connect to it from my mac with the normal GDB program.
The normal GDB is likely not configured for cross-debugging, and thus doesn't understand ARM binaries at all. I am surprised you get as far using it as you do.
I'm cross-compiling a project from Linux to target Windows (using mingw). The output is a DLL and p-invoking into it from C# works, but debugging is very difficult. The build outputs a .o file, which can provide symbols to gdb, but basically all I can do there is break on exceptions and find the name of the function that was executing when the exception happened; not even the full stack trace. I can't debug with WinDbg because I don't have .pdb files.
This is an open source project set up to build on Linux; I believe their build process relies on several installed Linux packages to work.
Do I have any options here? Is there a utility that can convert .o files into .pdb? Or some program that can give me more information than gdb when debugging?
Try a IDE that support mingw. For example the open source Code::blocks.
Another possibility is to do it manually: compile it with debug symbols, start you application and attach the GDB debugger to it. It is also part of the MingW32 distribution. Then you can set your breakpoints and debug your application
But I guess using Code::Block is more comfortable
By the way, the GCC compiler does not generate pdb files because it is a propietary format
What xpol means is maybe: if you have a complete mingw installation then Code::blocks can use gdb to visualize a debugging session like it is done in Visual Studio or Eclipse. See chapter "Debugger" at http://www.codeblocks.org/features
You can generate a .pdb file using cv2pdb.exe from Visual D. This works even for programs not written in D if they were compiled with mingw. Once you've downloaded and installed Visual D cv2pdb.exe can be found at C:\Program Files (x86)\VisualD\cv2pdb\cv2pdb.exe.
You can run cv2pdb.exe against an executable like this:
cv2pdb.exe -n target.exe
This will produce a file called target.pdb. Assuming both target.pdb and target.exe are in the current director, you can then use windbg like this:
windbg -sflags 0x80030377 -y . -z target.dmp
In this case I'm also passing a minidump file as target.dmp. This can be omitted. The -sflags 0x80030377 option tells windbg to load target.pdb even though it thinks it doesn't match target.exe.
Note, that it can take windbg a very long time to load target.pdb. Just wait until it no longer says *BUSY* to the left of the command entry box.
Alternatively you can try DrMinGW.