Tips & Tricks

More power to debug: Attach to local process

Hi,

With the recent 1.5 EAP build we’ve announced a new feature called Attach to local process. Let’s take a closer look at it.

In general, you can find the information about debugging in CLion in the corresponding blog post, it also includes a short demo. So in case you are interested in various breakpoints types supported in CLion, built-in debugger UI, ways to evaluate and view variables, please, refer to the post to learn the details. These topics are also covered in our webhelp in details.

Since the first CLion Public Early Access preview build we’ve been getting questions on remote toolchains support, including remote debugging. To make the very first step in that direction we’ve started with attaching to local process functionality. In a nutshell, it allows you to debug processes, run on the same machine as CLion, by attaching to them using their pid or process name.

Currently in CLion attach to local process is available for GDB on Linux and Windows and LLDB on OS X (so not available for GDB on OS X). You can find the corresponding action in the Run menu of the IDE:
attach_to_local_process_menu
or call it via Find Action dialog (Shift+Ctrl+A on Linux/Windows, ⇧⌘A on OS X). All the processes will be listed in the dialog (Rem. Please, mind two problems we are currently aware of here – IDEA-150592 and IDEA-150591):
attach_full_list

To simplify the search, just start typing either the name of the process:
attach_search_name
or its pid:
attach_search_pid

Select process to attach with CLion and now you can debug it with all the usual staff available in the IDE, including breakpoints, stepping, variable views, etc.
debugger_variables

To detach click the ‘Stop the process’ button in the debugger toolwindow in the IDE (we’ll make the name more accurate in the later builds, since currently it detaches and doesn’t stop the process of course – CPP-5629).

Upd. Find the prerequisites for Ubuntu users in our webhelp.

In the end, let us also share feature requests related to the topic that you can find interesting. Feel free to leave comments, upvote and share your personal use cases (they really help us to figure out the proper implementation and UI, so thank you in advance!):

  • Debug forked child processes (CPP-955).
  • Debug arbitrary binary (CPP-1313).
  • Attach to Existing Process: add re-run button (OC-3352).
  • Remote debug (CPP-5539).

That’s it! Download the build and give it a try.

Sincerely yours,
The CLion Team

image description