0

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.

5
  • Try this solution with LD_PRELOAD. Set it as env variable before launching vscode. Commented Nov 28, 2021 at 21:30
  • Thank you. when I try to run "LD_PRELOAD=/lib64/libpython2.7.so.1.0 gdb -ex 'set environ LD_PRELOAD' --args my-program-to-debug" in my terminal I get "LD_PRELOAD=/lib64/libpython2.7.so.1.0: Command not found." Should I add set or export before it? Commented Nov 29, 2021 at 6:57
  • Yes export it. When it is exported you Can use just gdb without prepending LD_PRELOAD. Commented Nov 29, 2021 at 8:29
  • I tried setting it to the libpython path in ldd /user/gdb then export then launch vs code but I still getting the same error message note: I tried to echo $LD_PRELOAD before I launched vs code but it returned nothing. so maybe I am doing something wrong in setting it? Commented Nov 29, 2021 at 12:29
  • @T0maas it turned to be a 2 part problem where your help solved the first part. Thank you. Commented Dec 7, 2021 at 12:48

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.