Compiling OpenSSH on 64-bit machine with debugging symbols - debugging

I am trying to compile openssh with debugging symbols, but it is not happening and i have no idea why.
wget "https://ftp.nluug.nl/security/OpenSSH/openssh-7.2p2.tar.gz"
tar xfz openssh-7.2p2.tar.gz
cd openssh-7.2p2
autoconf
./configure --with-audit=debug
make
sudo make install
objdump --syms bin/ssh
bin/ssh: file format elf64-x86-64
SYMBOL TABLE: no symbols
any thoughts why the debugging symbols are not there? please note that when I execute this command as below:
objdump --syms bin/ssh.o
I can see that symbols have been added to the object file, but not in the final executable file when the linker finish up the file.
Thanks in advance.

If you look at what make install does, you'll see
/usr/bin/install -c -m 0755 -s ssh /usr/local/bin/ssh
The -s option causes debug symbols to be stripped, just like the strip command.
Maybe there's a way to disable that?
$ ./configure --help |grep strip
--disable-strip Disable calling strip(1) on install
Oh, there we go.

Related

Cygwin doesn't make an executable when expected

I'm running Cygwin on Windows 7 and trying to build a program I downloaded. I cd to where I have my file.tar.gz and type
tar -xvf file.tar.gz
and Cygwin successfully spits out a list of what's in there. (point of confusion: for some reason, -xvzf doesn't work, even though the file claims to be zipped. Also, I expected there to be an untarred folder put somewhere in my directory, but there's not.)
Then I type
make
and get
c++ -O -c gmm.c -o gmm.o
make: c++: No such file or directory
make: *** [makefile:19: gmm.o] Error 127
I expected this to create a gmm.exe (according to the documentation of this program). What's going on?
As #stark mentioned you are missing the C++ compiler.
To find in which package is, use cygcheck -p to ask the Cygwin Webserver
$ cygcheck -p bin/c++
Found 17 matches for bin/c++
...
binutils-2.35.2-1 - binutils: GNU assembler, linker, and similar utilities
...
gcc-g++-10.2.0-1 - gcc-g++: GNU Compiler Collection (C++)
gcc-g++-7.4.0-1 - gcc-g++: GNU Compiler Collection (C++)
...
After you install the gcc-g++ package, you will have the program c++
in the standard directory for programs
$ cygcheck -l "gcc-g++" |grep "usr/bin/c++"
/usr/bin/c++.exe

How to Instruct mingw64-gcc to use Specific mingw-w64-headers/crt

I have compiled mingw-w64-headers and mingw-w64-crt as described here.
My issue is how to get gcc to use them.
I have tried the following to no avail:
SET mingw_dir=C:\msys64\mingw-w64
gcc -g -L %mingw_dir%\lib^
-I %mingw_dir%\include^
-Wl,--rpath=%mingw_dir%\lib^
test.c -o test
It fails to compile giving:
../lib/crt2.o: in function 'pre_c_init':
crt/crtexe.c:145: undefined reference to '__p__commode'
This seems to be an issue with ld, however I'm not sure how to solve it.
Seems that simply setting an environment variable LIBRARY_PATH=C:\msys64\mingw-w64\lib;%LIBRARY_PATH% solves the issue.
With this set, the command line invocation reduces to this:
gcc -g test.c -o test
Although this will use the headers installed by pacman -S $MINGW_PACKAGE_PREFIX-toolchain, this simply means I just have to compile mingw-w64-crt to get debug information.

CoqIDE Make on Windows

I have GnuWin32 Make and GnuWin32 Coreutils, installed and on my PATH. This works:
coq_makefile -f _CoqProject -o Makefile.coq
make -f Makefile.coq Frap.vo
But if I open Frap.v in CoqIDE, and do Compile > Make, the only output I see is this:
Compilation output:
Is this expected? How can I get Coq to build this?

Can't output anything using cygwin 1.7 gcc under windows

I just installed cygwin 1.7, and wrote a simple Hello world in test.c
but when I complie, nothing happens, even no error messages
gcc-4 -o test.exe test.c
And there's nothing generated under my folder.
I have included C:\cygwin;C:\cygwin\bin in my PATH
Did I miss something?
EDIT:
for more information, I installed Qt4, tortoiseHg, and mingw before.
Now I had removed mingw. but still got Qt4 and tortoiseHg, is this a problem?
Try doing this from the Cygwin Terminal, not cmd.exe:
$ cd `cygpath -u "$USERPROFILE"`/Desktop/UT
$ gcc -o foo foo.c
$ ls -l foo
-rwxr-xr-x+ 1 yourlogin None 19618 May 10 05:15 foo*
If that works, there's some bogus remnant lying around.
You'll find that the Cygwin experience is generally better running under Bash, in a MinTTY terminal anyway. cmd.exe doesn't understand Cygwinisms, and is a DOS throwback besides.
Note that you don't need to say gcc-4 to get GCC 4.x. gcc is GCC 4.x on Cygwin, and has been for quite some time now.
Also note that you don't need to include .exe in the GCC -o flag, because Cygwin GCC knows to add that already.

How to do source level debugging of x86 code with GDB inside QEMU?

I wrote a x86 assembly program for MBR section.
I compile it as follows:
nasm hellombr.asm -f bin -o hellombr.img
Then I run it in qemu:
qemu -fda hellombr.img -boot a
The question is how can I debug my program at source level?
You should let nasm create the debugging symbols in an ELF file and then dump this to a flat binary to be used in the MBR. You can then instruct GDB to read the necessary symbols from the ELF file.
The complete procedure would then become something like this:
$ nasm hellombr.asm -f elf -g -o hellombr.elf
$ objcopy -O binary hellombr.elf hellombr.img
$ qemu -s -S -fda hellombr.img -boot a
$ gdb
(gdb) symbol-file hellombr.elf
(gdb) target remote localhost:1234
For an explanation of the flags I pass to qemu see this answer.
Instead of using qemu, use bochs. It is completely compatible, albeit slower. It is also an emulator but if you make it from sources, using these flags and build it like this:
./configure --enable-debugger --enable-disasm --disable-docbook
make
make install
you can place breakpoints in your code, step through it, view GDT, IDT and everything you needed to know.
A really good (and simple) way is to use IDA with bochs, you find an excellent blog post on it here, along with some other hints/suggestions for bootloader development.

Resources