Last active
July 1, 2020 06:17
-
-
Save 3096/ed531b0a929d5c07659e2d4f30d6e61f to your computer and use it in GitHub Desktop.
my gdb convenience script for using https://github.com/misson20000/twili-gdb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (c) 2020 3096 | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
define conn | |
target extended-remote | twib gdb | |
end | |
define wait_with_tid | |
conn | |
monitor wait title $arg0 | |
conn | |
end | |
# Pokemon Sword 1.1.0 | |
define sword | |
set $main_offset = 0x4000 | |
set $sdk_offset = 0x37b3000 | |
wait_with_tid 0x0100ABF008968000 | |
end | |
# Pokemon Shield 1.1.0 | |
define shield | |
set $main_offset = 0x4000 | |
set $sdk_offset = 0x37b3000 | |
wait_with_tid 0x01008DB008C2C000 | |
end | |
# Animal Crossing: New Horizon 1.1.0 | |
define park | |
set $main_offset = 0x4000 | |
set $sdk_offset = 0x4346000 | |
wait_with_tid 0x01006F8002326000 | |
end | |
# DRAGON QUEST® XI S: Echoes of an Elusive Age – Definitive Edition 1.0.3 | |
define jack | |
set $main_offset = 0x4000 | |
set $sdk_offset = 0x9572000 | |
wait_with_tid 0x01006C300E9F0000 | |
end | |
# more wait for titles can be added like the examples | |
# twib list devices | |
define ls | |
shell twib list-devices | |
end | |
# twib ps | |
define ps | |
shell twib ps | |
end | |
# attach to process, $arg0 = process id | |
define atp | |
attach $arg0 | |
i threads | |
set $rtld_base = (long)$pc | |
set $main_base = (long)$pc+$main_offset | |
set $sdk_base = (long)$pc+$sdk_offset | |
end | |
# continue to breakpoint from SIGTRAP | |
define cb | |
i threads | |
c | |
end | |
define print_addr | |
# $arg0 = raw address | |
# $arg1 = print raw | |
if $arg1 | |
p $arg0 | |
else | |
if $arg0 < $main_base | |
set $addr_in_nso = $arg0 - $rtld_base + 0x7100000000 | |
eval "set $addr_in_nso = \"rtld %lx\"", $addr_in_nso | |
else | |
if $arg0 > $sdk_base | |
set $addr_in_nso = $arg0 - $sdk_base + 0x7100000000 | |
eval "set $addr_in_nso = \"sdk %lx\"", $addr_in_nso | |
else | |
set $addr_in_nso = $arg0 - $main_base + 0x7100000000 | |
eval "set $addr_in_nso = \"main %lx\"", $addr_in_nso | |
end | |
end | |
p $addr_in_nso | |
end | |
end | |
define print_register_bt | |
echo $pc = | |
print_addr $pc $arg0 | |
set $cur_frame_fp = (void **)$x29 | |
set $cur_frame_lr = (void *)$x30 | |
print_addr ($cur_frame_lr-4) $arg0 | |
while $cur_frame_fp != 0 | |
set $cur_frame_lr = $cur_frame_fp[1] | |
if $cur_frame_lr != 0 | |
print_addr ($cur_frame_lr-4) $arg0 | |
end | |
set $cur_frame_fp = (void **)$cur_frame_fp[0] | |
end | |
end | |
# print register based back trace | |
define xbt | |
print_register_bt 0 | |
end | |
# print register based back trace (raw addresses) | |
define xbt_raw | |
print_register_bt 1 | |
end | |
# add breakpoint in main, $arg0 = address (without 0x7100000000) | |
define bm | |
b *($arg0+$main_base) | |
end | |
# add breakpoint in sdb, $arg0 = address (without 0x7100000000) | |
define bsdk | |
b *($arg0+$sdk_base) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment