Products > Programming

Show definitions + autocomplete function parameters for C (text editor over ssh)

(1/6) > >>

What editor/setup to use when writing C code remotely, after connecting with ssh to a headless Raspberry Pi (RPi)?

The remote PC is a small SBC, a Raspberry Pi 1B running Debian 12 Bookworm.  Though, that's a RPi model from long time ago, its hardware is very modest:  700MHz single core ARM v6 (32-bit) with 256MB RAM.

For now, I am logging in to the RPi remotely, in text mode, using screen+ssh from a Desktop, and edit the sources with vim.  Apart from the gazillion keyboard shortcuts that I keep forgetting, I can only get autocomplete suggestions for names, but it does not show the function parameters, and CTRL+] doesn't jump to definition.

Stackoferflow tells that, to see definitions with vim, I will need first to create a tags database with ctags -R, for each project.  OK, but isn't this a little cumbersome?  Should I use something else for editing C?  This setup is for learning only, many projects but all very small, usually just a single .c and a Makefile.

Do I use the right setup?  Is it maybe something else other than vim?  It must be light with the hardware requests, but with syntax coloring and decent autocomplete.

I've read the other alternative to ctags is a client server architecture, with background services indexing the sources and running at all times, something invented by Microsoft and open sourced, but that seems heavy for my RPi.  I've tried to install neovim with the kickstart setup on top (this setup has the client-server style for code autocomplete, plus some other goodies like fuzzy search, all pitched up in this 30 minutes video):
The Only Video You Need to Get Started with Neovim
TJ DeVries

Well, following the installation steps for neovim + kickstart, on my RPi it failed with segmentation fault.  ???  I've dd-ed the RPi SD card with the stock OS image again, for just in case the segmentation fault was caused by some malicious attempt (it probably wasn't that, but anyway).

The question is, what setup to use when editing small/hobby C projects on a headless RPi with ssh?

If the RPi is on the LAN where you have a Linux desktop you could export a directory to the RPi with NFS and do your editing on the desktop but the compile on the RPi. This will also backup your work with the desktop backup.

Interesting, didn't thought of doing that.  Looks like a clever hack, but I'm not sure what directories from RPi to mount.  I will need to build kernel modules, so for autocomplete to work properly, I would need the kernel headers from RPi.  I've noticed (during make) the kernel headers are accessed through a link in /lib/modules/build

--- Code: ---ls -l /lib/modules/5.15.84+
total 2472
lrwxrwxrwx  1 root root     31 Mar  6  2023 build -> /usr/src/linux-headers-5.15.84+
drwxr-xr-x 11 root root   4096 Apr 14 13:50 kernel
-rw-r--r--  1 root root 582872 Mar  6  2023 modules.alias
-rw-r--r--  1 root root 612415 Mar  6  2023 modules.alias.bin
-rw-r--r--  1 root root  13930 Mar  6  2023 modules.builtin
-rw-r--r--  1 root root  25034 Mar  6  2023 modules.builtin.alias.bin
-rw-r--r--  1 root root  15282 Mar  6  2023 modules.builtin.bin
-rw-r--r--  1 root root  77245 Mar  6  2023 modules.builtin.modinfo
-rw-r--r--  1 root root 221390 Mar  6  2023 modules.dep
-rw-r--r--  1 root root 298899 Mar  6  2023 modules.dep.bin
-rw-r--r--  1 root root    324 Mar  6  2023 modules.devname
-rw-r--r--  1 root root  66966 Mar  6  2023 modules.order
-rw-r--r--  1 root root    913 Mar  6  2023 modules.softdep
-rw-r--r--  1 root root 262276 Mar  6  2023 modules.symbols
-rw-r--r--  1 root root 318778 Mar  6  2023 modules.symbols.bin
--- End code ---

I don't know how the autocomplete works, and if it is blindly indexing any symbols it sees in any source file, or if the symbols indexing is made context aware.

For example here, do I mount /usr/src/linux-headers-5.15.84+, or /lib/modules/5.15.84+/build?  Or it doesn't matter at all from which point the sources are mounted, as long as they are all seen by the symbols indexer?


--- Quote from: retiredfeline on April 17, 2024, 07:48:16 am ---you could export a directory to the RPi with NFS and do your editing on the desktop but the compile on the RPi
--- End quote ---

Starting from your NFS export idea, next wish was to not wear out the SD card, so thought of exporting a directory from the PC instead, a directory where the RPi can write on a spinning rust HDD.  At this point, why not using the PC for compilation, too, to cross-compile for ARM 32-bit and just copy the binaries back to the RPi's SD card?

The setup to crosscompile for RPi is documented in

So I've brought the kernel sources from the RPi github repo, and clone from the tag with the same kernel version I was using on the RPi and cross-compile the kernel in order to have the right version of RPi kernel-headers on the PC.  Since now it all happens on the PC, I don't need NFS, and instead just copy the cross-compiled binaries from the PC to the RPi, using scp to copy over SSH.

Then, I've added -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- to the make commands, and now, instead of 1-2 minutes for a compilation on RPi, cross-compiling the same thing on the PC only takes 1-2 seconds.  :D

As for code snippets and autocomplete, on the RPi the choice was very limited because of its modest hardware, but on the PC it can be almost anything.  I am tempted to try some of those fuzzy-search suggest as you type.  Not sure yet which one.

Sure, go for it, as you're evidently capable of installing a cross toolchain.


[0] Message Index

[#] Next page

There was an error while thanking
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod