I'm trying to read an ARM core file on my Linux desktop, but it seems not to be able to figure out my core file. Is there any way I can instruct gdb what type my core file is?
$ file ~/daemon
./daemon: ELF 32-bit LSB executable, ARM, version 1, dynamically linked (uses shared libs), for GNU/Linux 2.0.0, not stripped
$ file ~/core
./core: ELF 32-bit LSB core file ARM, version 1 (SYSV), SVR4-style, from './daemon -v -v -v -v -e 10 -t foo'
$ gdb-multiarch ~/daemon ~/core
GNU gdb (GDB) 7.5-ubuntu
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from ./daemon...done.
"./core" is not a core dump: File format is ambiguous
(gdb) core-file ~/core
"./core" is not a core dump: File format is ambiguous
The generating platform is armv4, which gdb-multiarch claim to support, according to the "set architecture" list.
EDIT: To clarify, my desktop machine running gdb is "x86_64-linux-gnu", namely an 64-bit Intel Ubuntu box.
This may help:
$ gdb-multiarch
...
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) set gnutarget elf32-littlearm
(gdb) file daemon
...
(gdb) target core core
...
(gdb)
The following is relevant only if your desktop (where you are trying to run gdb-multiarch) is x86.
Gdb is a debugger. As such it will not be able to debug a foreign architecture executable on your x86 desktop machine because you cannot run arm code on x86 processor. You can however debug it remotely using gdb-server which will run on arm machine.
Is your desktop arm or x86?
Related
This is an XY question because I still haven't found a solution for my initial question.
However, I'd like to know (at least out of curiosity) the answer. This might help to understand how gdbserver works.
Given a mingw-w64 compiled binary to run on Windows, can a GCC gdbserver (launched on WSL) debug this binary? It seems that it can: see UPDATE
Will it work with WSL's mingw-w64 gdb? (run CLion on WSL to remotelly debug Windows app)
Can I "cheat" mingw-w64 to connect to the GCC gdbserver? Obviously, it refuses to work:
(gdb) target remote 192.168.0.101:1234
Remote debugging using 192.168.0.101:1234
warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration
of GDB. Attempting to continue with the default i386:x86-64 settings.
warning: Architecture rejected target-supplied description
Reading /init from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration
of GDB. Attempting to continue with the default i386:x86-64 settings.
warning: Architecture of file not recognized.
Reading /init from remote target...
Reading symbols from target:/init...(no debugging symbols found)...done.
Remote register badly formatted: T0506:0000000000000000;07:a0e5feffff7f0000;10:0060220000000000;thread:p1007.1007;core:0;
here: 00000000;07:a0e5feffff7f0000;10:0060220000000000;thread:p1007.1007;core:0;
msys64/mingw64/gdbserver.exe is a bad option:
CLion does not want to connect when CLion is the one to start the server
the server constantly crashes
And I couldn't find an alternative for gdbserver on Windows.
So far I have a configuration:
Windows with MinGW-w64 compiler to build an app (using CLion as an IDE)
Remote Virtual Windows machine to remotelly debug the app (CLion does not support MSVC's remote debugger)
WSL Ubuntu on Virtual Windows (bruh) - this is needed for a proper shell with sshd (git bash/msys64 bash/mingw64 mintty do not work as Windows OpenSSH shells. No matter how hard i tried).
UPDATE
So I launched WSL /usr/bin/gdbserver :1234 test on my Virtual Windows. Then I launched WSL /usr/bin/gdb from my local Windows machine.
And it didn't show any errors:
eld#RU-AI000174:~$ gdb
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) target remote 192.168.0.101:1234
Remote debugging using 192.168.0.101:1234
Reading /init from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
Reading /init from remote target...
Reading symbols from target:/init...
(No debugging symbols found in target:/init)
0x0000000000226000 in ?? ()
(gdb) continue
Continuing.
[Inferior 1 (process 1202) exited normally]
Is this an expected and/or reliable behavior?
I am trying to debug a simple "hello world" C++ program on Ubuntu 16.04 but gdb is not able to recognize the executable file format. However, I am able to successfully run the executable on the command line.
Here is the code
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
I compile the program file TestProject.cpp using the command
g++ -g TestProject.cpp -o hello
Then to debug, I give the command
gdb ./hello
I get the following error message
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.5) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
"/home/<home>/./hello": not in executable format: File format not recognized
Something seems to be corrupt with the Ubuntu machine. Because I am able to debug the same program on another Ubuntu 16.04 virtual machine.
It is almost certain that ks1322's comment is correct one:
You've installed a 64-bit GCC, so your ./hello is a 64-bit binary (use file ./hello to confirm).
You've installed a 32-bit only GDB, so it doesn't know how to debug x86_64 binaries.
The fix is simple: install 64-bit GDB (which is capable of debugging both 32 and 64-bit binaries), or build hello in 32-bit mode (with g++ -m32 ...).
I had the same issue on mac os.
there is a bug in gdb: https://sourceware.org/bugzilla/show_bug.cgi?id=23746
their git repository has already had the fix. Unfortunately, the bins in homebrew have not had it yet. So, I had to git clone git://sourceware.org/git/binutils-gdb.git, compiled it and installed as it is described in the readme file.
I do believe this will fix yours on ubuntu.
P.S. it works on my machine but I have to run eclipse as root:
sudo /.../MacOS/eclipse. Otherwise, I have Launching : Configuring GDB Aborting configuring GDB. Cause I do not know how to fix it (
I'm tried to debug my binary file (called click) with gdb.
When I run
gdb ./click
I have the following error
GNU gdb (Ubuntu 7.10-1ubuntu2) 7.10
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
"/home/student/Desktop/./click": not in executable format: File format not recognized
The outupt of:
uname -a
is
Linux student 4.2.0-36-lowlatency #42-Ubuntu SMP PREEMPT Thu May 12 23:39:42 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
And if I run
file click
I get this output:
click: ERROR: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2 error reading (Invalid argument)
Any ideas?
click: ERROR: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2 error reading (Invalid argument)
Your file is simply corrupt.
Possibly it is truncated (did you run out of disk space when linking it?), or you transferred it over FTP from another machine in ASCII mode (use binary mode instead).
I am using GDB executable in my linux machine to debug my executable(rild).
My Executable details are as below :-
rild: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked (uses shared libs), BuildID[md5/uuid]=d100d90599eb3764018356c9ef3e1840, not stripped
however when I am running the command
./arm-linux-androideabi-gdb ~/android_gdb/system_bin/rild
I am getting follwing error:-
GNU gdb (GDB) 7.6
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-linux-android".
For bug reporting instructions, please see:
<http://source.android.com/source/report-bugs.html>...
"/home/user/android_gdb/system_bin/rild": not in executable format: File format not recognized
I can see that GDB is also 64 bit version and the executable ELF is also unstripped, 64 bit. but still its not working.
rild: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV),
This is an aarch64 64-bit ARM binary.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-linux-android"
This GDB is a 64-bit x86_64 binary, configured to debug 32-bit ARM binaries.
The fact that GDB itself is a 64-bit binary is irrelevant. What matters is what target it is configured to debug. You need a different GDB, configured with --target=aarch64-linux-android.
Can 32bit gdb debug 64bit binary?
The answer above is incorrect. You need a 64-bit debugger to debug a 64-bit process. That's precisely the reason why gdb forks a 64-bit copy of itself behind the scenes.
Yes. A 32 bit gdb debugs 64 bit binaries fine on Solaris, at least on the latest release.
$ cat /etc/release
Oracle Solaris 11 Express snv_151a X86
Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
Assembled 04 November 2010
$ file /usr/bin/gdb
/usr/bin/gdb: ELF 32-bit LSB executable 80386 Version 1 [FPU], dynamically linked, not stripped, no debugging information available
$ file a
a: ELF 64-bit LSB executable AMD64 Version 1, dynamically linked, not stripped
$ gdb a
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-pc-solaris2.11"...
(gdb) b main
Breakpoint 1 at 0x400e9c: file a.c, line 3.
(gdb) run
Starting program: /tmp/a
Breakpoint 1, main () at a.c:3
3 printf("hello world !");
(gdb) quit
The program is running. Exit anyway? (y or n) y
$
However, if you look closer, this 32 gdb is launching a 64 bit gdb under the hood:
$ truss -f -t execve /usr/bin/gdb a
1793: execve("/usr/bin/gdb", 0x0804755C, 0x08047568) argc = 2
1793: execve("/usr/bin/amd64/gdb", 0x0804755C, 0x08047568) argc = 2
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-pc-solaris2.11"...
(gdb)
It does it regardless of whether the binary debugged is 32 or 64 bit.
I still think the way a debugger interact with a process under Solaris is size independent so technically, a 32 bit only binary debugger should be able to debug a 64 bit program.
A 64 bit gdb is able to debug both 32 bit and 64 bit binaries but a 32 bit gdb cannot debug 64 bit ones. This is what you are experiencing.