2

Error on running code to debug using gdb: https://pastebin.ubuntu.com/p/PxrKVGmmTQ/

(gdb) run demo.py
Starting program: /usr/bin/python3 demo.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff39aa2a9 in GlobalError::PushToStack() ()
   from /usr/lib/x86_64-linux-gnu/libapt-pkg.so.5.0

Python stack trace: https://pastebin.ubuntu.com/p/zWz5KBdhSZ/

(gdb) py-bt
Traceback (most recent call first):
  <built-in method init_config of module object at remote 0x7ffff41c70e8>
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 34, in <module>
    apt_pkg.init_config()
  <built-in method exec of module object at remote 0x7ffff7fd4638>
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
    import apt
  <built-in method exec of module object at remote 0x7ffff7fd4638>
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  <built-in method exec of module object at remote 0x7ffff7fd4638>
---Type <return> to continue, or q <return> to quit---

Thread info: https://pastebin.ubuntu.com/p/TYBnd3RG78/

(gdb) info threads
  Id   Target Id         Frame 
* 1    Thread 0x7ffff7fdb740 (LWP 3104) "python3" 0x00007ffff39aa2a9 in GlobalError::PushToStack() () from /usr/lib/x86_64-linux-gnu/libapt-pkg.so.5.0

Current thread in python code: https://pastebin.ubuntu.com/p/TjvGGvGGYG/

(gdb) py-list
  29    ProblemResolver  # pyflakes
  30    from apt.cdrom import Cdrom
  31    
  32    # init the package system, but do not re-initialize config
  33    if "APT" not in apt_pkg.config:  # type: ignore
 >34        apt_pkg.init_config()
  35    apt_pkg.init_system()
  36    
  37    __all__ = ['Cache', 'Cdrom', 'Package']

GDB functions used to debug (in-order) :

gdb python3

run <filename>.py

py-bt

info threads

py-list

I am running a custom c++ library with python bindings. A .so (shared object) file is being dynamically linked to the python program. The python file is importing the custom c++ library . When I run the python file using python3 filename.py I receive the error : Segmentation fault(core dumped) I tried debugging this error using gdb for python. I need help in understanding what the above links are pointing to and how this issue can be resolved.

  • 1
    Where's the code? – Roy2511 May 20 '20 at 05:24
  • Did run your code in a **debugger** to see where that error occurs, then run it again with a breakpoint near that failure so you can step carefully ahead and watch what happens leading up to that point? – tadman May 20 '20 at 05:30
  • You need to make your question more self-contained. External links are a big problem for a lot of people, and may expire or become unavailable. – tadman May 20 '20 at 05:31
  • @Roy2511 The only thing that the code does is import a custom library. – biancaAngelo May 20 '20 at 05:48
  • @tadman All that the code does is import a custom library and that's when it seg-faults. When i tried debugging using gdb for python the result is as given in the question which i am unable to comprehend. Also will make the question more self-contained. Appreciate the advice! – biancaAngelo May 20 '20 at 05:53
  • `py-bt` command won't help at all, you need the plain `bt` for the native part of the stack. For that end, you will also need to ensure that you have full debug symbols for the native library. – Ext3h May 20 '20 at 06:08

0 Answers0