How to debug a CMake target that needs root privileges with vscode - c++

I am trying to debug a CMake target that needs root privileges on vscode, but when I replaced my gdb executable with a script to launch it using sudo, vscode won't start the debugger anymore.
This was my attempt to make gdb run with sudo:
echo '#!/bin/sh
sudo gdb-orig $#' >/usr/sbin/gdb
sudo chmod 0755 /usr/sbin/gdb
I don't get any error on vscode, it just won't start debugging my executable. Also, I can run the script without any problems from the terminal.
What am I missing? Is there any alternative to debug targets that need root privileges?

Related

gdbserver remote target: Target description specified unknown architecture "arm" Where is gdb binary for ARMv7?

I have a target machine, raspberry pi ARMv7, that I want to debug remotely from my windows machine.
I want to use gdb gdbserver with 'target remote' to debug the docker container remotely.
My executable is compiled c++ src code.
Dockerfile that I run on raspberry pi
FROM arm32v7/ubuntu:latest
# Install necessary packages and cross-compiling toolchain
RUN apt-get update && apt-get install -y gdb gdbserver g++ bash
RUN apt-get install -y crossbuild-essential-armhf gdb-multiarch
ENV CC=arm-linux-gnueabihf-gcc
ENV CXX=arm-linux-gnueabihf-g++
ENV AR=arm-linux-gnueabihf-ar
# Copy the source code
COPY . /app
# Set the working directory
WORKDIR /app
# Compile the source code
RUN ${CXX} -g -o testapp2 testapp2.cpp
# Run the executable
CMD ["./testapp2"]
I believe my windows machine needs a pre-built binary of gdb for the ARMv7 architecture.
I looked through linaro.org and developer.arm.com but I haven't been able to find a download for this.
Do I need to build it myself on my windows machine?
I was able to successfully target remote by using
gdb-multiarch -ex "target remote Enter-Ip-Address-Here:Enter-TCP-Port-Here" /path/to/executable/in/the/docker/container/here
in Windows Subsystem Linux

Run Ganache GUI on ubuntu

I want to run ganache Gui app on ubuntu 22.04. After downloading AppImage I run it using command
ganache-2.5.4-linux-x86_64.AppImage --appimage-extract
It generates new folder and then I execute ./Ganache inside that folder.
I get this message
[50883:0717/002902.307174:FATAL:gpu_data_manager_impl_private.cc(1034)] The display compositor is frequently crashing. Goodbye.
Trace/breakpoint trap (core dumped)
How can I fix this ?
You should chmod +x ganache-2.5.4-linux-x86_64.AppImage and turn it into an executable. Then you can run it double clicking it.
You could also move it into the opt folder to be available to all users with the command sudo mv ganache-2.5.4-linux-x86_64.AppImag /opt/
And then, you could create a desktop link to be used in the menu, creating a file with the contents like this:
[Desktop Entry]
Name=Ganache
Exec=/opt/ganache-2.5.4-linux-x86_64.AppImage
comment=cloud
Type=Application
Terminal=false
Encoding=UTF-8
Categories=Utility;
Then, when you run it, you can pin it to your panel! :D
I found a solution for ubuntu 22.04 here: https://github.com/AppImage/AppImageKit/wiki/FUSE
just run these commands:
sudo add-apt-repository universe && sudo apt install libfuse2

Error while setting up Movesense platform with Cmake commands

I've been trying to set up movesense platform in my windows 10 machine and facing issues with cmake commands.
I pulled the movesense container using docker
docker pull movesense/sensor-build-env:latest
I cloned the movesense repo using the below code
git clone git#bitbucket.org:suunto/movesense-device-lib.git
Then I moved to the cloned folder
cd movesense-device-lib
Then I started the docker image on the terminal
docker run -it --rm -v c:/My/Project/Folder/movesense-device-lib:/movesense:delegated movesense/sensor-build-env:latest
The docker prompted and I followed the below commands
cd /movesense
mkdir myBuild
cd myBuild
Now, I ran the CMake "Run the CMake (needs to be done only once unless you add files to the project). It's possible to build both the debug and release version. In both cases the command will contain the following:" by the following command
cmake -G Ninja -DMOVESENSE_CORE_LIBRARY=../MovesenseCoreLib/ -DCMAKE_TOOLCHAIN_FILE=../MovesenseCoreLib/toolchain/gcc-nrf52.cmake <sample_directory>
I created a sample folder as build1 and saved. In the place of sample_directory, I pasted "build" and executed the command.
But in return I get an error as
CMake Error: The source directory "/movesense/myBuild/build" does not appear to contain CMakeLists.txt. Specify --help for usage, or press the help button on the CMake GUI.
The objective is to create a project as zip file and run it in visual studio. Please help me to solve the issue. I've attached the links of the documents which I followed from movesense.
Movesense Set up document
The "<sample_directory>" should be a path to the folder where the firmware source code is (i.e. the sample app folder). If you create the build folder as /movesense/myBuild and cd into it, the path would be ../samples/blinky_app if you are building the blinky_app -sample.
Full disclosure: I work for the movesense team

VS2019 - Sudo Remote Debugging on Linux with Cmake project

I have a cmake c++ Linux project that is using Remote Debugging from a windows computer. The program accesses the GPIO pins on Raspberry pi so it needs to run under sudo on the remote machine. Everything is building and working but it crashes on the first line that needs admin access. I have not been able to figure out how to launch the newly compiled application under sudo. I have tried different settings in the launch_schema.json but no luck so far.
I found this and it worked for me.
Unable to launch debugger (gdb) with root permissions.
Basically you decorate the existing gdb binary on the Pi with a bash script and then use the script.
The steps on the Pi are:
cd /usr/bin
sudo mv gdb gdborig
Now create a bash script named gdb with following content.
sudo nano gdb
Content of the bash is;
#!/bin/sh
sudo gdborig $#
Finally, make the script runnable with.
sudo chmod 0755 gdb
Thanks goes to Buğra Aydoğar

Compiling a file leaves files in my home directory when doing vagrant provision

I am using Vagrant to setup a linux box. I need to add a file I compiled to the system and I do so using the following commands -
sudo git clone https://github.com/thewtex/tmux-mem-cpu-load.git /tmp/tmuxcpu
sudo cmake /tmp/tmuxcpu
sudo make clean /tmp/tmuxcpu
sudo make install clean /tmp/tmuxcpu
However, this leaves tons of files including a makefile, config files, and other garbage inside the /home/vagrant/ folder. How do I make and install from tmp without littering the home directory with garbage?
The above commands work, but it leaves tons of files in the /home/vagrant folder that I don't want there. Is it possible to cmake, make, and make install without leaving 'trash'?
I have solved my issue with the help of Etan Reisner and reinierpost.
## CPU LOAD
sudo git clone https://github.com/thewtex/tmux-mem-cpu-load.git /tmp/tmuxcpu
sudo sh -c "cd /tmp/tmuxcpu && sudo cmake . && sudo make && sudo make install";
My install script now uses the above commands and this has resolved my issue. By keeping the files in /tmp, they are removed the moment I reboot the box. I am using this technique for several other items during the vagrant setup now and it works perfectly. This has solved numerous issues for me.