Skip to content

Commit

Permalink
Debug: Add support for 32-bit on 32-bit under GDB
Browse files Browse the repository at this point in the history
In addition to existing support for 32-bit on 64-bit
  • Loading branch information
mikebeaton committed Oct 26, 2023
1 parent 5a7edbe commit 379db0c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ OpenCore Changelog
#### v0.9.6
- Updated builtin firmware versions for SMBIOS and the rest
- Fixed hang while generating boot entries on some systems
- Add `efidebug.tool` support for 32-bit on 32-bit using GDB (in addition to existing 32-bit on 64-bit support)

#### v0.9.5
- Fixed GUID formatting for legacy NVRAM saving
Expand Down
35 changes: 30 additions & 5 deletions Debug/efidebug.tool
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
# GDB - path to GDB debugger
# defaults to finding in PATH
# EFI_ARCH - architecture to debug
# defaults to X64
# defaults to X64; use EFI_ARCH=IA32 to debug 32-bit firmware on 64-bit CPU
# CPU_ARCH - CPU architecture of target
# defaults to X64; use CPU_ARCH=IA32 to debug 32-bit firmware on 32-bit CPU
# GDB_ARCH - GDB `set arch` value
# defaults to correct value for CPU_ARCH
# EFI_PORT - debugger TCP connection port
# defaults to 8864 for X64 and 8832 for IA32
# EFI_HOST - debugger TCP connection host
Expand All @@ -24,6 +28,8 @@
# defaults to x86_64-apple-macosx for XCODE5, x86_64-pc-windows-msvc for CLANGDWARF/CLANGPDB,
# x86_64-linux-gnu otherwise.
#
# Note: This script's support for 32-bit UEFI debugging on LLDB is incomplete, GDB is recommended in that case.
#

RUNDIR=$(dirname "$0")
pushd "${RUNDIR}" >/dev/null || exit 1
Expand Down Expand Up @@ -60,16 +66,35 @@ choose_debugger() {
find_gdb
find_lldb

if [ "${CPU_ARCH}" = "Ia32" ]; then
CPU_ARCH="IA32"
elif [ "${CPU_ARCH}" = "" ]; then
CPU_ARCH="X64"
fi

if [ "${GDB_ARCH}" = "" ]; then
if [ "${CPU_ARCH}" = "X64" ]; then
GDB_ARCH="i386:x86-64:intel"
else
GDB_ARCH="i386"
fi
fi

if [ "${EFI_ARCH}" = "" ]; then
EFI_ARCH="X64"
EFI_ARCH="${CPU_ARCH}"
elif [ "${EFI_ARCH}" = "Ia32" ]; then
EFI_ARCH="IA32"
elif [ "${CPU_ARCH}" = "IA32" ] && [ "${EFI_ARCH}" = "X64" ] ; then
echo "Invalid CPU_ARCH/EFI_ARCH combination!"
exit 1
fi

if [ "${EFI_HOST}" = "" ]; then
EFI_HOST="localhost"
fi

if [ "${EFI_PORT}" = "" ]; then
if [ "${EFI_ARCH}" = "Ia32" ]; then
if [ "${EFI_ARCH}" = "IA32" ]; then
EFI_PORT=8832
else
EFI_PORT=8864
Expand Down Expand Up @@ -116,7 +141,7 @@ choose_debugger() {
fi

if [ "${EFI_TRIPLE}" = "" ]; then
if [ "${EFI_ARCH}" = "Ia32" ]; then
if [ "${EFI_ARCH}" = "IA32" ]; then
triple_arch=i386
else
triple_arch=x86_64
Expand All @@ -135,7 +160,7 @@ choose_debugger() {
choose_debugger

if [ "${EFI_DEBUGGER}" = "GDB" ] || [ "${EFI_DEBUGGER}" = "gdb" ]; then
"${GDB}" -ex "set arch i386:x86-64:intel" \
"${GDB}" -ex "set arch ${GDB_ARCH}" \
-ex "target remote ${EFI_HOST}:${EFI_PORT}" \
-ex "source Scripts/gdb_uefi.py" \
-ex "set pagination off" \
Expand Down

0 comments on commit 379db0c

Please sign in to comment.