Visual Studio 2017 Linux remote debugging (gdbserver) - c++

After I installed gdbserver on my remote machine (Ubuntu 16.04.4 LTS), I tested the following c++ code by making a "cross-platform console application (linux)" project in Visual Studio 2017:
#include <cstdio>
int main()
{
printf("hello from testLinuxDebug!\n");
return 0;
}
I added the connection information (ip address, id, password) of my Ubuntu machine to connection manager and selected "gdbserver" for debugging mode.
Then I started debugging and got the following message:
Unable to start debugging. Unexpected GDB output from command
"-interpreter-exec console "target remote localhost63361"". Remote
connection closed.
Message after starting to debugging (Image captured from VS2017)
By the way, I got the following message from the Linux Console Window of debug menu of Visual Studio 2017:
Process /home/.../projects/testLinuxDebug/bin/x64/Debug/testLinuxDebug.out
created; pid = 29277 Listening on port 4444 Remote debugging from host
127.0.0.1 /build/gdb-9un5Xp/gdb-7.11.1/gdb/gdbserver/regcache.c:264: A problem > internal to GDBserver has been detected. Unknown register ymm0h requested
Message from Linux Console Window (Image captured from VS2017)
Could anybody help me with this problem?

I was having this exact same problem on my Ubuntu 16.04 machine.
I went through the source code on gdbserver, and it appears to be a problem with a processor register (ymm0h) which is only available to i386 processors.
The thing is, I don't know how to fix gdbserver to not use this register in particular, but you can solve the error by upgrading your gdb & gdbserver to version 8.3 on the Ubuntu machine. If my guess is correct, version 8.1 was the one that fixed this issue, but by default, Ubuntu 16.04 has version 7.11.1 for both gdb & gdbserver.
You can run these commands on the linux machine to do that:
wget "http://ftp.gnu.org/gnu/gdb/gdb-8.3.tar.gz"
tar xzf gdb-8.3.tar.gz
cd gdb-8.3
./configure --prefix=/usr --with-system-readline
make
sudo make install
You may need to install some extra packages in order to compile the gdb:
sudo apt-get install libreadline6-dev texinfo
If you still have problems trying to install gdb, try this example from Linux from Scratch.
Good luck!

I encountered the same problem as you, although for me the issue was on Microsoft's Visual Studio Online platform - I couldn't use pwntools' gdb.debug/gdb.attach functionality (that relies on gdbserver) due to this very same error in VSOnline's docker environment.
Leaving this answer here for people who might encounter the same issues that I have.
The issue and the steps are pretty similar to what Canella described - the root of the problem is indeed the old GDB version in the environment (7.12 at the time of writing).
I've compiled my GDB with python3 bindings, and you might want to do that too if you're planning to use GEF or similar GDB extensions.
Here's how to do that in your VSOnline environment's terminal:
# I needed to get rid of the apt-provided gdb for it to work properly
sudo apt remove gdb
# VSOnline has a weird way of handling python versions
# you're better off installing python3 from apt, if it's not installed yet
sudo apt update
sudo apt install libreadline6-dev texinfo python3 python3-dev
wget "http://ftp.gnu.org/gnu/gdb/gdb-8.3.tar.gz"
tar xzf gdb-8.3.tar.gz
cd gdb-8.3
mkdir build && cd build
../configure --prefix=/usr --with-system-readline --with-python=/usr/bin/python3
make
sudo make install

Related

I can't run the gcc compiler in VScode even though I have everything set up

I'm new to programming and I'm trying to set up C and C++,
I have the C/C++ extension pack installed and enabled on VScode,
I have mysys64 installed on the C:\ drive,
I added the Mingw-w64 destination folder path, with \mingw64\bin appended, to the system path in Edit environment variables for your account (windows settings).
The problem is that I can't run the g++ compiler (checking the version also doesn't run) and I'm very sure the address at system path is correct because I've checked it more than 6 times and I've also followed every single step on https://code.visualstudio.com/docs/languages/cpp until Check your MinGW installation (because it doesn't work).
The error messages I get are:
Command 'g++' not found, but can be installed with: sudo apt install g++,
and when I try: "Build Hello World" on https://code.visualstudio.com/docs/languages/cpp
I get:
/image/
Notes:
I run Windows 10 Pro, version: 21H2, OS build: 19044.1826
I already had WSL(ubuntu) installed before mysys64
Edit: I used a different machine and followed the same steps, it works there now. Looks like the problem is with the machine
Install WSL extension in VSCode, run VSCode from WSL (WSL2 better because its faster), then install g++ (sudo apt install g++) from WSL; MingW is evil :)

How do I perform a remote gdb session on a PC for ARM gdbserver WITH GDB GUI frontend?

I am using Ubuntu 16.04 on x86_64 workstation, and I'm cross-compiling a small demo program in C++, and deploying it to an embedded linux target running ARM architecture (environment-setup-cortexa9hf-neon-poky-linux-gnueabi, arm-poky-linux-gnueabi-g++).
I am able to successfully do this which gives me a debug session on commandline:
Target:
rpm -ivh gdbserver-7.10.1-r0.cortexa9hf_neon.rpm
gdbserver :9091 ${APPNAME}
Host:
sudo apt-get install gdb-multiarch
gdb-multiarch $APPNAME
target remote 192.168.0.212:9091
...
I can now use gdb-multiarch on commandline!
However from here... I really want to be able to use one of the many gdb frontend tools to provide a GUI to set breakpoints and step through the code (akin to gdbgui, or using vscode and configuring for a debugger). Are there any gdb frontend tools that specifically support gdb-multiarch?
Any tool I try, I believe no matter what it uses base gdb executable and gives this error because of mismatched architecture:
target remote 192.168.0.212:9091
Remote debugging using 192.168.0.212:9091
warning: Architecture rejected target-supplied description
Remote 'g' packet reply is too long: 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000070fdff7e00000000c0fafc76100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
UPDATE 1 --
I can kinda sorta get this to work using ddd tool:
ddd --eval-command="target remote $MY_TARGET_IP:9091" --debugger gdb-multiarch
However! This is ancient and buggy, and I can't set breakpoints in loaded .so's right now with this.
I tried gdbgui with its options to specify debugger, but that's not currently working either. I filed a feature request report here:
https://github.com/cs01/gdbgui/issues/237
I found a way using gdbgui, but it required me to rebuild gdb from source code against my specific remote target architecture. Details of how I got it to work are here:
https://github.com/cs01/gdbgui/issues/237
Important bits in case the above link breaks:
TLDR Solution:
I was trying to rely on a prebuild gdb-multiarch from ubuntu apt repos, which didn't work. When I decided to download gdb and rebuild from source while configuring for arm-linux-gnuabi target arch.
Build method:
downloaded latest gdb source code
unzip it, go into folder, and build it like this:
./configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --target=arm-linux-gnuabi && make -j8 && sudo make install
Important to note that for my particular remote gdb server it's running on ARM so i had to say target=arm-linux-gnuabi in configure. GDB is building for my PC x86 arch, but it knows when debugging to recognize the target as ARM!
Now, arm-linux-gnuabi-gdb is installed by default to /usr/local/bin ... but you can instead provide prefix=<path> to where you want it to install in ./configure script above.
Using this, I was able to build a secondary copy of gdb called arm-linux-gnuabi-gdb which i could feed to gdbgui like this:
gdbgui -g arm-linux-gnuabi-gdb
From there, I can give gdb commands to connect to my remote gdbserver. I'm having to set breakpoints beforehand. My gdb commands are like this to set a few breakpoints:
set breakpoint pending on
break my_object.cpp:<line number for breakpoint>
b example_function_name
target remote <remote arm machine IP>:<gdbserver port>
c
Works great! This is leaps and bounds better than running gdb on commandline on my remote target.

Valgrind on bash for Windows 10 [duplicate]

When I installed WSL for my computer I was very excited to have a more natively supported Linux system rather than using VirtualBox. However I get this error when I try to run it. Is there a reason why?
I am happy to give more information as required.
--4364:0:aspacem -1: ANON 0038000000-00383d5fff 4022272 r-x-- SmFixed d=0x000 i=25365 o=0 (0) m=0 /usr/lib/valgrind/memcheck-amd64-linux
--4364:0:aspacem Valgrind: FATAL: aspacem assertion failed:
--4364:0:aspacem segment_is_sane
--4364:0:aspacem at m_aspacemgr/aspacemgr-linux.c:1502 (add_segment)
--4364:0:aspacem Exiting now.
It's definitely possible
I've encountered some problems installing it directly with apt, however it can be installed manually with some very simple steps:
Download the source file: wget http://valgrind.org/downloads/valgrind-3.12.0.tar.bz2 (by the time you read this there could be a newer version)
Extract the archive: tar -xvjf valgrind-3.12.0.tar.bz2
Configure the installation process: cd into the exctracted folder valgrind-3.12.0 and then launch ./configure
Make: simply launch make while in the valgrind-3.12.0 folder
Check the dependencies: launch make check to see whether all the dependencies necessary for the installation are satisfied (e.g: you'll have to install g++, just launch sudo apt install g++)
Install valgrind: type sudo make install to install it
I had the same problem, the solution was to install Windows 10 creators update (version 1703), and reinstall Bash/WSL. Valgrind now works fine :)

Netbeans "Resolve missing debugger command" C++

Whenever I try to debug any program (i.e. a welcome message), I get this prompt. Any ideas how to run the debugger for C++ program?
I am using Macbook Pro OS X El Capitan (10.11.3)
For Mac OSX 10.5 and above,
Install Homebrew (if you don't have it already)
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Install GDB
brew install gdb
Go to https://sourceware.org/gdb/wiki/BuildingOnDarwin and follow the instructions to code sign the gdb binary.
If you're on Sierra, run the following command in your terminal
echo "set startup-with-shell off" >> ~/.gdbinit
Finally, run the following comamnd in your terminal
which gdb
Copy the output path from that command, (mine was /usr/local/bin/gdb) into the Debugger Command box in Netbeans and start debugging!
On Linux systems derived from debian, you have to install gdb
sudo apt-get install gdb
Then in debbuger command type
/usr/bin/gdb
More information of gdb can be found in GDB: The GNU Project Debugger
Make sure gdb is installed in your machine. you can do this by following
C:\cygwin64>setup-x86_64.exe -q -P gdb
after this, select gdb as a debugger in netbeans
gdb location
Use Synaptic to install gdb. This debugger is required for Netbeans.
On a Mac, I installed HomeBrew first, then followed this exactly on the Sierra OS. Worked perfectly. After Homebrew is installed, you have to create then sign your gdb certificate. Then select it in your IDE debugger section.
The instructions show how to select gdb in Eclipse, but I got it working in NetBeans by pushing the debugger button and typing in the file path in the popup (as mentioned in this document).
https://www.ics.uci.edu/~pattis/common/handouts/macmingweclipse/allexperimental/mac-gdb-install.html

How to build and install Valgrind on Mac?

I am on Mac OS X using codeblocks 10.05
I downloaded Valgrind, and extracted a folder. I am completely lost from there, and have no idea how to build it.
I do not know ANY terminal/console commands and am generally new to programming, so I have no idea how to "build" or "compile" it. I just have a folder called Valgrind with a bunch of random files in it.
Could someone please tell me how to proceed? I already checked the website/documentation but it didn't really give me installation instructions, just usage instructions.
Thanks
PS: I know I already posted this question, but the previous question was shut down, for being too vague. I reposted this one with more info.
PSS: All that I am basically asking is what do I do to install Valgrind right after I download it from the website and extract the files?
Recommended:
Use brew: brew install valgrind
Manual Install:
Here's what worked on my Mac (10.6). Double-check you have the latest version, then change into the uncompressed directory
cd /users/(insert username here)/downloads/valgrind-3.17.0
I suggest you do as another posted and read the readme.
nano README
Commence the build; /usr/local is the place on the filesystem that the program will be installed to. There are many arguments like prefix that are available to customize the installation to your particular system if it doesn't work by default. Normally just using ./configure works perfectly well though.
./configure --prefix=/usr/local
make
sudo make install
Or you could probably get it from fink or macports or homebrew.
You can install it through brew for Mac:
brew install valgrind
You might have to manually link the entry to /usr/local/bin as brew refused to do it in my case:
$ ln /usr/local/Cellar/valgrind/3.8.1/bin/vgdb /usr/local/bin/vgdb
ln: /usr/local/bin/vgdb: Permission denied
$ sudo ln /usr/local/Cellar/valgrind/3.8.1/bin/vgdb /usr/local/bin/vgdb
On MacOS High Sierra
If you have the following error message:
brew install valgrind
valgrind: This formula either does not compile or function as expected on macOS
versions newer than Sierra due to an upstream incompatibility.
Fix
(1) To correctly install it, first, type the following command at the Terminal (which opens Valgrind’s formulae)
brew edit valgrind
And change the URL in head section
https://sourceware.org/git/valgrind.git
to
git://sourceware.org/git/valgrind.git
(2) Do an update for Homebrew:
brew update
(3) Finally, use the following command to install Valgrind from the HEAD:
brew install --HEAD valgrind
Sources
https://www.gungorbudak.com/blog/2018/04/28/how-to-install-valgrind-on-macos-high-sierra/
https://github.com/Homebrew/homebrew-core/issues/18998
For macOS Big Sur / Monterey:
brew tap LouisBrunner/valgrind
brew install --HEAD LouisBrunner/valgrind/valgrind
The core process is pretty simple:
Make sure you are in the correct directory.
First run:
./configure
when that is finished, run:
make
at this point you will need to su into root (this is relatively tricky to do, see the note at the end). As root, run:
make install
When this is finished you will have a working valgrind installation. Test it by running
valgrind ls -l
To su into root, you will need to have set up a root account. If you have not done this in the past, see the instructions from apple here.
To perform the actual su, you will first have to be running an account with administrator privileges. If you are not already doing so, you can switch users with the following:
su admin
where admin is the name of an user with administrator privileges (you will need to enter the password for this account). From there, you can then run su to go into root:
su
You will need to enter the root password that you set up earlier.
You may find it easier to use something like macports. How to install that is probably beyond the scope of this question, but they have a page dedicated to it on their site.
Once you have macports installed, you need to type:
sudo port install valgrind +universal
As you say you don't have any experience of command lines, let's just briefly go through the different parts of this command:
sudo means the rest of the command will run as root, and will ask for your password. This is needed for the installer to have the correct permissions
port is the command line tool for managing macports
install is a command for port. Try port help to see a list of commands.
valgrind tells macports what it should be installing
+universal is a variant. This tells macports to configure valgrind to support 32 bit and 64 bit support.