forked from acidanthera/OpenCorePkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
efidebug.tool
executable file
·156 lines (136 loc) · 4.27 KB
/
efidebug.tool
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
#
# Configuration variables:
# LLDB - path to LLDB debugger
# defaults to finding in PATH
# GDB - path to GDB debugger
# defaults to finding in PATH
# EFI_ARCH - architecture to debug
# defaults to X64
# EFI_PORT - debugger TCP connection port
# defaults to 8864 for X64 and 8832 for IA32
# EFI_HOST - debugger TCP connection host
# defaults to localhost
# EFI_DEBUGGER - debugger to use
# defaults to LLDB on macOS and GDB otherwise, fallbacks to other when missing
# EFI_TOOLCHAIN - toolchain to use
# defaults to XCODE5 on macOS and GCC5 otherwise
# EFI_SYMS - symbols to use
# defaults to files in GdbSyms/Bin
# EFI_SYMS_PDB - optional PDB symbols for LLDB
# defaults to "-s GdbSyms/Bin/${EFI_ARCH}_CLANGPDB/GdbSyms.pdb" for CLANGPDB
# EFI_TRIPLE - optional target triple for LLDB
# defaults to x86_64-apple-macosx for XCODE5, x86_64-pc-windows-msvc for CLANGDWARF/CLANGPDB,
# x86_64-linux-gnu otherwise.
#
RUNDIR=$(dirname "$0")
pushd "${RUNDIR}" >/dev/null
RUNDIR=$(pwd)
popd >/dev/null
cd "$RUNDIR"
find_gdb() {
if [ "${GDB}" = "" ]; then
GDB=$(which ggdb)
fi
if [ "${GDB}" = "" ]; then
GDB=$(which gdb-multiarch)
fi
if [ "${GDB}" = "" ]; then
GDB=$(which gdb)
fi
}
find_lldb() {
if [ "${LLDB}" = "" ]; then
LLDB=$(ls /opt/local/bin/lldb-mp* 2>/dev/null)
fi
if [ "${LLDB}" = "" ]; then
LLDB=$(which lldb)
fi
}
choose_debugger() {
find_gdb
find_lldb
if [ "${EFI_ARCH}" = "" ]; then
EFI_ARCH="X64"
fi
if [ "${EFI_HOST}" = "" ]; then
EFI_HOST="localhost"
fi
if [ "${EFI_PORT}" = "" ]; then
if [ "${EFI_ARCH}" = "IA32" ]; then
EFI_PORT=8832
else
EFI_PORT=8864
fi
fi
if [ "${EFI_DEBUGGER}" = "" ]; then
if [ "${LLDB}" != "" ] && [ "$(uname)" = "Darwin" ]; then
EFI_DEBUGGER="LLDB"
elif [ "${GDB}" != "" ]; then
EFI_DEBUGGER="GDB"
elif [ "${LLDB}" != "" ]; then
EFI_DEBUGGER="LLDB"
else
echo "Cannot find installed GDB or LLDB debugger!"
echo "Hint: set GDB or LLDB variables to debugger path."
exit 1
fi
fi
if [ "${EFI_TOOLCHAIN}" = "" ]; then
if [ "$(uname)" = "Darwin" ]; then
EFI_TOOLCHAIN="XCODE5"
else
EFI_TOOLCHAIN="GCC5"
fi
fi
if [ "${EFI_SYMS}" = "" ]; then
if [ "${EFI_TOOLCHAIN}" = "XCODE5" ]; then
EFI_SYMS="GdbSyms/Bin/${EFI_ARCH}_XCODE5/GdbSyms.dll"
elif [ "${EFI_TOOLCHAIN}" = "CLANGPDB" ]; then
EFI_SYMS_PDB="-s GdbSyms/Bin/${EFI_ARCH}_CLANGPDB/GdbSyms.pdb"
EFI_SYMS="GdbSyms/Bin/${EFI_ARCH}_CLANGPDB/GdbSyms.dll"
else
EFI_SYMS="GdbSyms/Bin/${EFI_ARCH}_${EFI_TOOLCHAIN}/GdbSyms.debug"
fi
fi
if [ ! -f "${EFI_SYMS}" ]; then
echo "Cannot find symbols: ${EFI_SYMS}!"
echo "Hint: compile this file or set EFI_SYMS variable."
exit 1
fi
if [ "${EFI_TRIPLE}" = "" ]; then
if [ "${EFI_ARCH}" = "IA32" ]; then
triple_arch=i386
else
triple_arch=x86_64
fi
if [ "${EFI_TOOLCHAIN}" = "XCODE5" ]; then
export EFI_TRIPLE="${triple_arch}-apple-macosx"
elif [ "${EFI_TOOLCHAIN}" = "CLANGPDB" ] || [ "${EFI_TOOLCHAIN}" = "CLANGDWARF" ]; then
export EFI_TRIPLE="${triple_arch}-pc-windows-msvc"
else
export EFI_TRIPLE="${triple_arch}-linux-gnu"
fi
fi
}
choose_debugger
if [ "${EFI_DEBUGGER}" = "GDB" ] || [ "${EFI_DEBUGGER}" = "gdb" ]; then
"${GDB}" -ex "target remote ${EFI_HOST}:${EFI_PORT}" \
-ex "source Scripts/gdb_uefi.py" \
-ex "set pagination off" \
-ex "reload-uefi" \
-ex "b DebugBreak" \
"${EFI_SYMS}"
elif [ "${EFI_DEBUGGER}" = "LLDB" ] || [ "${EFI_DEBUGGER}" = "lldb" ]; then
"$LLDB" -o "settings set plugin.process.gdb-remote.target-definition-file Scripts/x86_64_target_definition.py" \
-o "gdb-remote ${EFI_HOST}:${EFI_PORT}" \
-o "target create ${EFI_SYMS_PDB} ${EFI_SYMS}" \
-o "command script import Scripts/lldb_uefi.py" \
-o "command script add -c lldb_uefi.ReloadUefi reload-uefi" \
-o "reload-uefi" \
-o "b DebugBreak"
else
echo "Unsupported debugger ${EFI_DEBUGGER}!"
echo "Hint: use GDB or LLDB in EFI_DEBUGGER variable."
exit 1
fi