How to debug C code with lldb in macOS Mojave? - macos

I was using gdb in Linux but now I have switched to Mac and read that lldb is the alternative to gdb in Apple devices. However, I'm getting an error when I try to use lldb (I also tried gdb but it does not recognize the files as executable). When I try to use it I get the following errors:
sanad#Sanads-MBP  ~/Desktop/cppLab  lldb ./a.out  ✔  623  01:43:54
(lldb) target create "./a.out"
Traceback (most recent call last):
File "", line 1, in
File "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/Python/lldb/__init__.py", line 98, in
import six
ImportError: No module named six
Traceback (most recent call last):
File "", line 1, in
NameError: name 'run_one_line' is not defined
Traceback (most recent call last):
File "", line 1, in
NameError: name 'run_one_line' is not defined
…and a dozen more NameErrors exactly like this until the output ends with:
Current executable set to './a.out' (x86_64).
(lldb)

lldb links to the System Python.framework, and can only load other python modules if they were built along with that Python library. Turns out, the way Python works if you don't explicitly tell it where to find Python modules it will look alongside the "python" binary that it finds in your PATH. So if you've installed another python and have it in your PATH, then lldb's python will try to load Python modules that won't actually load properly. The current workaround is just to clear you hand-installed Python from your PATH environment variable in whatever Terminal window you want to run lldb from
This was recently fixed (r356819 on llvm.org) and will make it into the Xcode release in the near future.

Related

Create .app / .dmg with Esky

I'm developing a GUI app in Python. I use cx_Freeze to turn my app into .app/ / .dmg files for OS X users. So, for instance I can use python setup.py bdist_dmg to make cx_Freeze create a .dmg file that my users can use to install my app.
I now want my app to update itself automatically. Esky seems to be a promising framework for doing this. I can do python setup.py bdist_esky to create a version of my app that updates itself. It produces the following directory structure:
myapp
myapp-0.1/
myapp
...
...
The top-level myapp is Esky's bootstrapping executable. It looks in the current directory, finds myapp-0.1/ as the latest version and then launches myapp-0.1/myapp.
How do I package this into a .dmg file which I can ship to my users? After my modifications to setup.py to get bdist_esky to work, bdist_dmg no longer works. The impression I get is that Esky is simply not meant to be used with bdist_dmg. Its documentation doesn't mention DMG files at all and I also couldn't find anything on Google.
As a first step, I tried to manually turn the files generated by Esky into an OS X .app/ bundle:
myapp.app/
Contents/
Info.plist
MacOS/
myapp
myapp-0.1/
myapp
...
...
Info.plist contains the minimum amount of necessary information to get OS X to run myapp. When I try to run myapp.app however, I get:
Traceback (most recent call last):
File "<string>", line 318, in bootstrap
File "<string>", line 442, in get_best_version
FileNotFoundError: [Errno 2] No such file or directory: '/Users/michael/Temp/myapp.app/appdata'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 689, in <module>
File "<string>", line 335, in bootstrap
RuntimeError: no usable frozen versions were found
Looking at Esky's source code, it appears to have some special handling for OS X bundles in its appdir_from_executable(...) function. To make Esky happy, I tried to rearrange my files so appdata/ actually exists:
myapp.app/
appdata/
myapp-0.1/
myapp
...
Contents/
Info.plist
MacOS/
myapp
...
Unfortunately, this results in another error:
Traceback (most recent call last):
File "<string>", line 689, in <module>
File "<string>", line 336, in bootstrap
File "<string>", line 363, in chainload
File "<string>", line 425, in _chainload
UnboundLocalError: local variable 'exc_value' referenced before assignment
Is this really that difficult? Am I the only one who wants to use Esky and ship files to users in the (standard) .dmg format? What am I missing?
Michael, I saw your comment in the github issue as well. Let me answer it here.
I had the same requirement and resolved in a similar way but I think I didn't use cx_Freeze. Another difference could be that I used Python 2.7.x. The best way to help you is to show you a few relevant files which worked well for me for creating .app and .dmg.
1) The main setup file of the python project:
https://dl.dropboxusercontent.com/u/13110611/temp/package_esky/setup_esky.py
2) The utility script I used to prepare some data files etc
https://dl.dropboxusercontent.com/u/13110611/temp/package_esky/prepare_setup.py
3) The main shell script I used to create app and DMG. That is, this script will call everything else, and it's the only script I used from command line directly.
https://dl.dropboxusercontent.com/u/13110611/temp/package_esky/package.sh
4) The dmg-setup script which will create DMS from .app file. It's just a simple wrapper script to call create-dmg, an open souce project.
https://dl.dropboxusercontent.com/u/13110611/temp/package_esky/dmg-setup
Please try and let me know in case you have any other questions or issues.

"./toolchain build kivy" gives an error on Mac OX X 10.8 despite following the tutorial

I'm trying to build kivy for iOS. Following the tutorial in kivy's guide, I enter command:
$./toolchain.py build kivy
But it outputs this error message:
Traceback (most recent call last):
File "./toolchain.py", line 173, in <module>
class ArchSimulator(Arch):
File "./toolchain.py", line 178, in ArchSimulator
sysroot = sh.xcrun("--sdk", "iphonesimulator", "--show-sdk- path").strip()
File "./tools/external/sh.py", line 1021, in __call__
return RunningCommand(cmd, call_args, stdin, stdout, stderr)
File "./tools/external/sh.py", line 486, in __init__
self.wait()
File "./tools/external/sh.py", line 500, in wait
self.handle_command_exit_code(exit_code)
File "./tools/external/sh.py", line 516, in handle_command_exit_code
raise exc(self.ran, self.process.stdout, self.process.stderr)
sh.ErrorReturnCode_64:
RAN: '/usr/bin/xcrun --sdk iphonesimulator --show-sdk-path'
STDOUT:
STDERR:
xcrun: error: unrecognized option: --show-sdk-path
Usage: xcrun [options] <utility> ... arguments ...
Find and execute the named command line utility from
the installed Xcode.
Options:
-h, --help show this help message and exit
-v, --verbose show verbose logging output
--sdk <sdk name> find the tool for the given SDK name
--toolchain <name> find the tool for the given toolchain
-l, --log show commands to be executed (with --run)
-f, --find only find and print the utility path
-r, --run find and execute the utility (this is the default behavior)
-n, --no-cache do not use the lookup cache
-k, --kill-cache remove any existing cache file (and perhaps recreate)
I'm using Mac 10.8 (on vmware) + Xcode 4.6.
The iOS prerequisites for kivy states that it assumes you have Mac OS X 10.9 and Xcode 5.1 or better in order to proceed.
I suspect this os's version of Python won't run cython properly.
Try running cython and tools/cythonize to check that cython is up and running.
Lastly I think the kivy user's group would be best able to diagnose this issue.

TypeError when downloading rapidsms using pip in django-tables2

I'm a total python newbie. I installed python 3.3.1 on a 32 bit windows 7 professional. I'm trying to install RapidSMS, and it should be as easy as "pip install rapidsms" and it does start the process, but it doesn't complete and I'm left with the below error message.
I've been trying to google it, but I haven't been able to find this specific problem, for the error I find fixes for people who have written the code themselves, and I haven't seen anyone mention this problem about rapidsms themselves. Since it stops in Django-tables, I wonder if I messed up that installation somehow or if there's a problem with the python version compatibility. I've used pip when installing some other software, so I don't think that's the problem.
So if anyone's encountered this error when installing pyhton packages or really have any idea what the cause might be I'd really appreciate it! (I also plan to post this in the RapidSMS mailing list when I get approved, but wanted to see if this was a more general problem that might have a fix.)
Downloading/unpacking django-tables2==0.13.0 (from rapidsms)
Running setup.py egg_info for package django-tables2
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "c:\users\mhealth1\appdata\local\temp\pip-build-mhealth1\django-tables2\setup.py", line 7, in <module>
version = re.search('__version__ = "(.+?)"', f.read()).group(1)
File "C:\Python33\lib\re.py", line 161, in search
return _compile(pattern, flags).search(string)
TypeError: can't use a string pattern on a bytes-like object
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "c:\users\mhealth1\appdata\local\temp\pip-build-mhealth1\django-tables2\setup.py", line 7, in <module>
version = re.search('__version__ = "(.+?)"', f.read()).group(1)
File "C:\Python33\lib\re.py", line 161, in search
return _compile(pattern, flags).search(string)
TypeError: can't use a string pattern on a bytes-like object
----------------------------------------
Command python setup.py egg_info failed with error code 1 in c:\users\mhealth1\a
ppdata\local\temp\pip-build-mhealth1\django-tables2
Storing complete log in C:\Users\mhealth1\pip\pip.log
Django-tables2 fails to install in Python3 because of the following code from line 7 of setup.py in the traceback:
version = re.search('__version__ = "(.+?)"', f.read()).group(1)
This should work if the search pattern was a bytes object. A byte literal can be created by simply pre-pending the string literal with a b like the following:
version = re.search(b'__version__ = "(.+?)"', f.read()).group(1)
This is why Python is throwing a TypeError with the message "Can't use a string pattern on a bytes-like object". The file contents are being read in as bytes.
I don't think RapidSMS currently supports Python3 yet based on its list of environments that are tested. This can be seen in the tox environments list of the project seen here, in which only Python 2.6 and 2.7 are listed: https://github.com/rapidsms/rapidsms/blob/develop/tox.ini#L2
To solve the immediate problem, you'll want to install RapidSMS in a virtual environment with Python 2.6 or 2.7. The documentation for RapidSMS describes virtual environment setup briefly here: http://www.rapidsms.org/en/develop/topics/virtualenv.html
You'll want to install Python 2.6 or 2.7 on your system and specify which Python for the virtualenv to use, using the -p or --python argument. The following is taken from the RapidSMS docs linked above, but ammended to specify using Python 2.7:
mkvirtualenv --distribute --no-site-packages rapidsms --python=python2.7

I can't import igraph on mac 10.6

I installed igraph for python in my mac but I can't import it. First I installed C core library, then I proceeded with the instalation for python, by doing:
python setup.py build
python setup.py install
Everything seemed to work fine but I can't import igraph from python shell. Just to clear up, I'm not inside igraph source code's folder. And I got this error:
import igraph
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.3-fat/egg/igraph/__init__.py", line 30, in <module>
File "build/bdist.macosx-10.3-fat/egg/igraph/core.py", line 7, in <module>
File "build/bdist.macosx-10.3-fat/egg/igraph/core.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/*****/.python-eggs/python_igraph-0.5.4-py2.7-macosx-10.3-fat.egg-tmp/igraph/core.so, 2): Symbol not found: _igraph_vector_destroy
Referenced from: /Users/*****/.python-eggs/python_igraph-0.5.4-py2.7-macosx-10.3-fat.egg-tmp/igraph/core.so
Expected in: dynamic lookup
I replaced my folder's name for *, so don't consider it.
I'm running python 2.7 over OS 10.6.7. So there's no pre-compiled version of igraph avaliable (2.5 and 2.6 only). Has this error anything to do with the python version I'm running?
If possible, how can I work this out?
I think the problem is that igraph is installed in /usr/local/lib/libigraph.dylib, but the linker cannot find it when Python tries to load the C core of the igraph module because /usr/local/lib is not on the default library path in Mac OS X. (At least I think so).
First, please check whether libigraph.dylib is really in /usr/local/lib - it should be there. After that, try this:
DYLD_LIBRARY_PATH=/usr/local/lib python -m igraph.test.__init__
This should instruct the linker to look around in /usr/local/lib as well as the default places, and then run Python with the entire igraph test suite.

Debugging with Pydev 1.5

I am trying to debug my application with Pydev 1.5
I have done almost everything that's mentioned in the docs to start the debugger.
I get this error when I try to start the debugging:
pydev debugger: warning: psyco not available for speedups (the debugger will still work correctly, but a bit slower)
pydev debugger: starting
Traceback (most recent call last):
File "C:\Documents and Settings\mkallat\Desktop\eclipse\plugins\org.python.pydev.debug_1.5.0.1251989166\pysrc\pydevd.py", line 953, in <module>
debugger.run(setup['file'], None, None)
File "C:\Documents and Settings\mkallat\Desktop\eclipse\plugins\org.python.pydev.debug_1.5.0.1251989166\pysrc\pydevd.py", line 780, in run
execfile(file, globals, locals) #execute the script
File "Z:\dev\hfholidays\urls.py", line 1, in <module>
from django.conf.urls.defaults import *
ImportError: No module named django.conf.urls.defaults
Please suggest me what's the best solution to this. Or am I missing something?
Thanks in advance.
You are missing django - pydev cannot find the django modules
You need to have all the python modules you need accessible to python this is usually done by having the environment variable PYTHONPATH include the directory of the module.
In pydev go to project->Properties->Pydev-PYTHONPATH choose the External libraries tab. You need to add the django package to your path.
Alternatively the normal Djano install should have put django into python's site-packages and so should be available on PYTHONPATH

Resources