<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Andres Granada</title>
    <description>The latest articles on DEV Community by Andres Granada (@ogranada).</description>
    <link>https://dev.to/ogranada</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F80743%2F328d44c2-fcc0-4781-b2ac-70638a39fac4.png</url>
      <title>DEV Community: Andres Granada</title>
      <link>https://dev.to/ogranada</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ogranada"/>
    <language>en</language>
    <item>
      <title>How to debug rust applications with VIM</title>
      <dc:creator>Andres Granada</dc:creator>
      <pubDate>Wed, 23 Dec 2020 05:08:52 +0000</pubDate>
      <link>https://dev.to/ogranada/how-to-debug-rust-applications-with-vim-58b1</link>
      <guid>https://dev.to/ogranada/how-to-debug-rust-applications-with-vim-58b1</guid>
      <description>&lt;p&gt;Some time ago a started to learn Rust language, but recently I changed my edition tool. I migrated from Visual Studio Code to VIM (Neo Vim actually) and the most difficult thing was learning how to debug my Rust code using my new editor. Happily, I found a package to debug Rust applications, its name is &lt;a href="https://github.com/puremourning/vimspector"&gt;Vimspector&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;According to your operative system, you would need to install different packages.&lt;/p&gt;

&lt;p&gt;For Mac OS X:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Install LLDB application&lt;/span&gt;
xcode-select &lt;span class="nt"&gt;--install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Installing [Neo]Vim package
&lt;/h2&gt;

&lt;p&gt;Package installation depends on the package manager you have been using. In my case, I've been using &lt;a href="https://github.com/junegunn/vim-plug"&gt;VIM-Plug&lt;/a&gt;, the installation could be done by adding the dependency to the configuration file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight viml"&gt;&lt;code&gt;&lt;span class="c"&gt;" Using vim-plug&lt;/span&gt;
Plug &lt;span class="s1"&gt;'puremourning/vimspector'&lt;/span&gt;

&lt;span class="c"&gt;" Using NeoBundle&lt;/span&gt;
NeoBundle &lt;span class="s1"&gt;'puremourning/vimspector'&lt;/span&gt;

&lt;span class="c"&gt;" Using Vundle&lt;/span&gt;
Plugin &lt;span class="s1"&gt;'puremourning/vimspector'&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To enable the plugin shortcuts easily you can add the next line to your configuration file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight viml"&gt;&lt;code&gt;&lt;span class="c"&gt;" You can use 'VISUAL_STUDIO' or 'HUMAN'&lt;/span&gt;
&lt;span class="c"&gt;" Visual Studio config avoid to the mapping of &amp;lt;F3&amp;gt; key, sometimes used to map file explorer buffer.&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;g:vimspector_enable_mappings&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'VISUAL_STUDIO'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To know the fast config key mappings you can use &lt;a href="https://github.com/puremourning/vimspector#mappings"&gt;this link&lt;/a&gt; or directly from &lt;a href="https://github.com/puremourning/vimspector/blob/61179b7670491a70b40cb34ddeefe793bee7fcb8/plugin/vimspector.vim#L63"&gt;the code&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Before using the debugger you need to prepare the general debugging configuration file, that file is located at &lt;code&gt;&amp;lt;/path/to/vim/plugins&amp;gt;/vimspector/gadgets/&amp;lt;os&amp;gt;/.gadgets.d&lt;/code&gt; and its name is &lt;code&gt;lldb-vscode.json&lt;/code&gt;, where the &lt;code&gt;/path/to/vim/plugins&lt;/code&gt; is the path in your file system where the [Neo]Vim plugins are installed. example paths are &lt;code&gt;/Users/andres/.config/nvim/plugins&lt;/code&gt; and &lt;code&gt;/home/andres/.config/nvim/plugins&lt;/code&gt; for Mac and Linux respectively.&lt;/p&gt;

&lt;p&gt;The content of the file &lt;code&gt;lldb-vscode.json&lt;/code&gt; is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"adapters"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"lldb-vscode"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"variables"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"LLVM"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"shell"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"brew --prefix llvm"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"attach"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"pidProperty"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pid"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"pidSelect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"none"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"${LLVM}/bin/lldb-vscode"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"env"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"YES"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"lldb"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, you need to add your project configuration file &lt;code&gt;.vimspector.json&lt;/code&gt; in the root of your Rust project (at the same level as your &lt;code&gt;Cargo.toml&lt;/code&gt; file). The initial content could be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"configurations"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Rust - Test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"adapter"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"CodeLLDB"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"configuration"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"request"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"launch"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"program"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"${workspaceRoot}/target/debug/&amp;lt;project name&amp;gt;"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, you can create breakpoints in your code, Using VISUAL_STUDIO mode you can create a breakpoint with &lt;code&gt;&amp;lt;F9&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Finally, this post is only a way to debug in Mac OS X, in a future post I will go deep on how to do it on Linux operative systems.&lt;/p&gt;

&lt;p&gt;Read, Enjoy, Share...&lt;/p&gt;

</description>
      <category>rust</category>
      <category>vim</category>
      <category>debug</category>
      <category>lldb</category>
    </item>
  </channel>
</rss>
