Long Story (This is X)
I need to start CLion with
sudo
so that I can attachgdb
to the running process from CLion (for a debugging purpose). The reason is because when I run CLion withoutsudo
, and trying to attach to a process (CLion GUI), I receive:
com.jetbrains.cidr.execution.debugger.backend.gdb.GDBDriver$GDBCommandException: ptrace: Operation not permitted.
As a second check, I tried runninggdb
in the terminal manually withoutsudo
:
gdb -p 16741
...
Could not attach to process. If your uid matches the uid of the target process, check the setting of "/proc/sys/kernel/yama/ptrace_scope", or try again as the root user. For more details, see "/etc/sysctl.d/10-ptrace.conf"
ptrace: Operation not permitted.
However, if I rungdb
withsudo
:
sudo gdb -p 16714
...
Attaching to process 16714
So I think I should run CLion as root.
TLDR / The Problem (This is Y)
Now, if running sh /opt/clion/bin/clion.sh
from the Ubuntu terminal, CLion does pick up the environment variables sourced in the ~/.bashrc
file, and my program compiles with no error.
But because without sudo
, I can't attach gdb
to the process from within CLion
for my debugging purpose, so I need to run the clion.sh
startup script as root.
The problem is that when running sudo sh /opt/clion/bin/clion.sh
, CLion doesn't seem to pick up the environment variables, leading to "CMake cannot find package ..." error, which makes my program not runnable—worse.
CMake Error at CMakeLists.txt:64 (message):
find_package(catkin) failed. catkin was neither found in the workspace nor
in the CMAKE_PREFIX_PATH. One reason may be that no ROS setup.sh was
sourced before.
Question
How do I run the CLion startup script with sudo
, and preserve the environment variables that are sourced in ~/.bashrc
?
If relevant
I think CLion doesn't pick up the following variables. To be very specific, I have this line in my
~/.bashrc
file:source /opt/ros/kinetic/setup.bash
whose content is
#!/usr/bin/env bash # generated from catkin/cmake/templates/setup.bash.in CATKIN_SHELL=bash # source setup.sh from same directory as this file _CATKIN_SETUP_DIR=$(builtin cd "`dirname "${BASH_SOURCE[0]}"`" > /dev/null && pwd) . "$_CATKIN_SETUP_DIR/setup.sh"
Perhaps, there might be a way to add this directly to the startup script of CLion?
- XY Problem
- I am running Ubuntu 16.04