Skip to content
Advertisement

Can’t launch debug – C in VS code on Linux

Let me preface this, I am very new to linux and to working on a non-IDE based setup.

I am trying to debug a very simple C program using vs code version 1.55 I unloaded all modules beforehand, so vs code can load appropriate default gcc & gdb versions (which it did, GCC 8.2) I am following the VS code getting started documentation for setting up and everything seems very straight forward until I try to debug. I use the default settings as instructed, the file builds successfully but then I get the below

/usr/bin/gdb: symbol lookup error: /usr/bin/gdb: undefined symbol: PyUnicodeUCS4_FromEncodedObject

please note that I cannot rebuild python with ucs4 enabled as suggested in another thread as I have no root access. however I can change VS code version to an earlier one if this will help.

Thanks.

Advertisement

Answer

I think this issue is specific to my environment but I will post the answer anyway as it may face someone else.

So this for me was 2 separate issues:
First gdb doesn’t start and second vs code can’t start gdb.
To check if this is the case try to launch gdb from terminal (not vs code) by typing gdb in the terminal (after loading gdb if needed), I was receiving the error above

Solution to this part is this as T0maas thankfully suggested above
Steps for linux newbies:

  1. ldd gdb (or /usr/bin/gdb) (with vs_code loaded) from step one get the python library path
  2. unload all modules
  3. load gdb
  4. LD_PRELOAD=<python path from 1>
  5. bash -c “export LD_PRELOAD”
  6. load vs_code
  7. load gdb

After the above steps writing gdb in the terminal should start gdb

Part 2:
The rest of the problem was when I tried to launch debugging session through the GUI of vs_code (still produced the same error)
In the terminal (after loading gdb) type whereis gdb
For me this produced multiple directories the first of which was /usr/bin/gdb (this is the default used in vs_code launch.json)
Changing that directory in the launch.json file to a different one of the other directories solved the second part of the problem for me.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement