Debugging Big Sur kernel on inter-based macbook from Monterey on m1

HI devs, help me please, i want to debug Big Sur kernel on inter-based macbook from Monterey on m1, i have installed KDK_11.6.4_20G417.kdk in Monterey system on m1 macmini, then launch lldb, have created target and got this message : WARNING! Python version 3 is not supported for xnu lldbmacros.

(lldb) target create /Library/Developer/KDKs/KDK_11.6.4_20G417.kdk/System/Library/Kernels/kernel
warning: 'kernel' contains a debug script. To run this script in this debug session:

  command script import "/Library/Developer/KDKs/KDK_11.6.4_20G417.kdk/System/Library/Kernels/kernel.dSYM/Contents/Resources/Python/kernel.py"

To run all discovered debug scripts in this session:

  settings set target.load-script-from-symbol-file true

Current executable set to '/Library/Developer/KDKs/KDK_11.6.4_20G417.kdk/System/Library/Kernels/kernel' (x86_64).
(lldb) settings set target.load-script-from-symbol-file true
##############################
WARNING! Python version 3 is not supported for xnu lldbmacros.
Please restart your debugging session with the following workaround

defaults write com.apple.dt.lldb DefaultPythonVersion 2

##############################


Loading kernel debugging from /Library/Developer/KDKs/KDK_11.6.4_20G417.kdk/System/Library/Kernels/kernel.dSYM/Contents/Resources/Python/kernel.py
LLDB version lldb-1300.0.42.3
Swift version 5.5.2-dev
settings set target.process.python-os-plugin-path "/Library/Developer/KDKs/KDK_11.6.4_20G417.kdk/System/Library/Kernels/kernel.dSYM/Contents/Resources/Python/lldbmacros/core/operating_system.py"
settings set target.trap-handler-names hndl_allintrs hndl_alltraps trap_from_kernel hndl_double_fault hndl_machine_check _fleh_prefabt _ExceptionVectorsBase _ExceptionVectorsTable _fleh_undef _fleh_dataabt _fleh_irq _fleh_decirq _fleh_fiq_generic _fleh_dec
command script import "/Library/Developer/KDKs/KDK_11.6.4_20G417.kdk/System/Library/Kernels/kernel.dSYM/Contents/Resources/Python/lldbmacros/xnu.py"
error: module importing failed: Traceback (most recent call last):
 File "<string>", line 1, in <module>
 File "/Library/Developer/KDKs/KDK_11.6.4_20G417.kdk/System/Library/Kernels/kernel.dSYM/Contents/Resources/Python/lldbmacros/xnu.py", line 123
  print "Execution interrupted by user"
     ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("Execution interrupted by user")?

settings set target.process.optimization-warnings false

How can i solve this problem? lldb linked with python 3, but kdk uses python 2, also command line tools version 12.5.1 which uses python 2 i can not install on monterey too.

Hi,did u solve your problem?

Hi, unfortunately, I did not solve this problem.

I ran into this issue today when debugging with 10.15.7 Catalina target with newer host machine Sonoma.

These python scripts are very important. When they are not loaded successfully, kdp related commands like showallkexts are missing.

So, in order to run these python scripts, we can either install python2 or modified these python scripts in HOST machine.

I chose to modify the scripts.

First, install 2to3 python tools by:

pip3 install 2to3

Second, add 2to3 directory to PATH variable if not yet or using absoulte path to call 2to3 command

Third, run 2to3 to convert all python scripts under directory /Library/Developer/KDKs/KDK_10.15.7_19H1824.kdk/System/Library/Kernels/kernel.development.dSYM/Contents/Resources/Python(Change to fit your enviroment)

sudo 2to3 -w <Python path>

Last, solve any Python problems if occur during debugging.

Forget about what I have said earlier. I tried to migrate the python scripts from 2 to 3, and I tested the showallkexts command, it won't work.

I managed to do it by simply DELETE the old python scripts folder, and copy the newer python tools from my Sonoma KDK to Catalina dSYM folders.


sudo cp -r /Library/Developer/KDKs/KDK_14.2_23C5047e.kdk/System/Library/Kernels/kernel.development.dSYM/Contents/Resources/Python /Library/Developer/KDKs/KDK_10.15.7_19H1824.kdk/System/Library/Kernels/kernel.development.dSYM/Contents/Resources/

The showallkexts command works now with python3

Debugging Big Sur kernel on inter-based macbook from Monterey on m1
 
 
Q